Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Parse <Foo.bar /> elements #125

Merged
merged 2 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ let verifyJsxOpeningClosingName p nameExpr =
let closing = match p.Parser.token with
| Lident lident -> Parser.next p; Longident.Lident lident
| Uident _ ->
(parseModuleLongIdent ~lowercase:false p).txt
(parseModuleLongIdent ~lowercase:true p).txt
| _ -> Longident.Lident ""
in
match nameExpr.Parsetree.pexp_desc with
Expand Down Expand Up @@ -2422,7 +2422,7 @@ and parseJsxName p =
let loc = mkLoc identStart identEnd in
Location.mkloc (Longident.Lident ident) loc
| Uident _ ->
let longident = parseModuleLongIdent ~lowercase:false p in
let longident = parseModuleLongIdent ~lowercase:true p in
Location.mkloc (Longident.Ldot (longident.txt, "createElement")) longident.loc
| _ ->
let msg = "A jsx name should start with a lowercase or uppercase identifier, like: div in <div /> or Navbar in <Navbar />"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ let _ =
[@JSX ])
let _ = ((Navbar.createElement ~children:[] ())[@JSX ])
let _ = ((Nav.Navbar.createElement ~children:[] ())[@JSX ])
let _ = ((Nav.navbar.createElement ~children:[] ())[@JSX ])
let _ = ((el ~punned:((punned)[@ns.namedArgLoc ]) ~children:[] ())[@JSX ])
let _ = ((el ?punned:((punned)[@ns.namedArgLoc ]) ~children:[] ())[@JSX ])
let _ = ((el ~punned:((punned)[@ns.namedArgLoc ]) ~children:[] ())[@JSX ])
Expand Down
1 change: 1 addition & 0 deletions tests/parsing/grammar/expressions/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let _ = <div className="menu" onClick={_ => Js.log("click")}></div>

let _ = <Navbar> </Navbar>
let _ = <Nav.Navbar> </Nav.Navbar>
let _ = <Nav.navbar> </Nav.navbar>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add more test cases? Nested, self closing etc.
Can you also test cases for the printer in tests/printer/expr/jsx.js?
Can you also add a test case in tests/parsing/errors/expression/jsx with an error in the closing "name"?
<Nav.navbar> </Nav.foo>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @IwanKaramazow, added in 6987427.


// punning
let _ = <el punned> </el>
Expand Down