Skip to content

Commit 3cdee84

Browse files
committed
make hyphen work in jsx tag names
1 parent edea94e commit 3cdee84

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

jscomp/syntax/src/res_core.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,8 @@ and parseJsxOpeningOrSelfClosingElement ~startPos p =
26242624
Parser.next p;
26252625
let spread, children = parseJsxChildren p in
26262626
let childrenEndPos = p.Parser.startPos in
2627+
Scanner.popMode p.scanner Jsx;
2628+
Scanner.setJsxMode p.scanner;
26272629
let () =
26282630
match p.token with
26292631
| LessThanSlash -> Parser.next p
@@ -2688,6 +2690,8 @@ and parseJsxOpeningOrSelfClosingElement ~startPos p =
26882690
* jsx-children ::= primary-expr* * => 0 or more
26892691
*)
26902692
and parseJsx p =
2693+
Scanner.popMode p.scanner Jsx;
2694+
Scanner.setJsxMode p.Parser.scanner;
26912695
Parser.leaveBreadcrumb p Grammar.Jsx;
26922696
let startPos = p.Parser.startPos in
26932697
Parser.expect LessThan p;
@@ -2699,6 +2703,7 @@ and parseJsx p =
26992703
parseJsxFragment p
27002704
| _ -> parseJsxName p
27012705
in
2706+
Scanner.popMode p.scanner Jsx;
27022707
Parser.eatBreadcrumb p;
27032708
{jsxExpr with pexp_attributes = [jsxAttr]}
27042709

@@ -2709,12 +2714,12 @@ and parseJsx p =
27092714
*)
27102715
and parseJsxFragment p =
27112716
let childrenStartPos = p.Parser.startPos in
2712-
Scanner.setJsxMode p.scanner;
27132717
Parser.expect GreaterThan p;
27142718
let _spread, children = parseJsxChildren p in
27152719
let childrenEndPos = p.Parser.startPos in
27162720
Parser.expect LessThanSlash p;
27172721
Parser.expect GreaterThan p;
2722+
Scanner.popMode p.scanner Jsx;
27182723
let loc = mkLoc childrenStartPos childrenEndPos in
27192724
makeListExpression loc children None
27202725

@@ -2769,6 +2774,7 @@ and parseJsxProp p =
27692774
Parser.next p;
27702775
match p.Parser.token with
27712776
| DotDotDot -> (
2777+
Scanner.popMode p.scanner Jsx;
27722778
Parser.next p;
27732779
let loc = mkLoc p.Parser.startPos p.prevEndPos in
27742780
let propLocAttr =

jscomp/syntax/tests/parsing/errors/expressions/expected/jsx.res.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11

2-
Syntax error!
3-
tests/parsing/errors/expressions/jsx.res:1:12
4-
5-
1 │ let x = <di-v />
6-
2 │ let x = <Unclosed >;
7-
3 │ let x = <Foo.Bar></Free.Will>;
8-
9-
I'm not sure what to parse here when looking at "-".
10-
11-
122
Syntax error!
133
tests/parsing/errors/expressions/jsx.res:2:20
144

@@ -66,7 +56,7 @@
6656

6757
I'm not sure what to parse here when looking at ".".
6858

69-
let x = ((di ~children:[] ())[@JSX ]) - (v / ([%rescript.exprhole ]))
59+
let x = ((di-v ~children:[] ())[@JSX ])
7060
let x = ((Unclosed.createElement ~children:[] ())[@JSX ])
7161
let x =
7262
((Foo.Bar.createElement ~children:[] ())[@JSX ]) > ([%rescript.exprhole ])

jscomp/syntax/tests/printer/expr/expected/jsx.res.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ let x = <Foo.Bar className="container" />
44
let x = <Foo.Bar.Baz className="container" />
55
let x = <Foo.bar className="container" />
66
let x = <Foo.baz className="multiline" />
7-
let x = <\"custom-tag" className="container" />
8-
let x = <Foo.\"custom-tag" className="container" />
7+
let x = <custom-tag className="container" />
98

109
// https://github.com/rescript-lang/syntax/issues/570
1110
let x =
@@ -38,15 +37,10 @@ let x =
3837
{b}
3938
</A>
4039
let x =
41-
<\"custom-tag" className="container">
40+
<custom-tag className="container">
4241
{a}
4342
<B />
44-
</\"custom-tag">
45-
let x =
46-
<Foo.\"custom-tag" className="container">
47-
{a}
48-
<B />
49-
</Foo.\"custom-tag">
43+
</custom-tag>
5044

5145
let x = <div className="container" className2="container2" className3="container3" onClick />
5246

jscomp/syntax/tests/printer/expr/jsx.res

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ let x = <Foo.bar className="container" />
66
let x = <Foo.baz
77
className="multiline"
88
/>
9-
let x = <\"custom-tag" className="container" />
10-
let x = <Foo.\"custom-tag" className="container" />
9+
let x = <custom-tag className="container" />
1110

1211
// https://github.com/rescript-lang/syntax/issues/570
1312
let x = <A> <B> <C> <D /> <E /> </C> <F> <G /> <H /> </F> </B> </A>
1413
let x = <A> {children} <B/> </A>
1514
let x = <A> <B/> {children} </A>
1615
let x = <A> {a} </A>
1716
let x = <A> {a} {b} </A>
18-
let x = <\"custom-tag" className="container" > {a} <B/> </\"custom-tag">
19-
let x = <Foo.\"custom-tag" className="container" > {a} <B/> </Foo.\"custom-tag">
17+
let x = <custom-tag className="container" > {a} <B/> </custom-tag>
2018

2119
let x =
2220
<div

0 commit comments

Comments
 (0)