Skip to content

Commit cff0a81

Browse files
authored
correctly print exotic JSX names (#6451)
* correctly print exotic JSX names * update changelog
1 parent 02f84a1 commit cff0a81

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Fix using dynamic import of module in block instead of async function https://github.com/rescript-lang/rescript-compiler/pull/6434
2626
- Fix issue with using dynamic import of module in uncurried mode https://github.com/rescript-lang/rescript-compiler/pull/6434
2727
- Fix build error where JSX v4 transformation of the discouraged forwardRef in uncurried mode https://github.com/rescript-lang/rescript-compiler/pull/6447
28+
- Fix printing of exotic JSX names https://github.com/rescript-lang/rescript-compiler/pull/6451
2829

2930
#### :nail_care: Polish
3031

jscomp/syntax/src/res_printer.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4354,19 +4354,19 @@ and printJsxProp ~state arg cmtTbl =
43544354
* Navabar.createElement -> Navbar
43554355
* Staff.Users.createElement -> Staff.Users *)
43564356
and printJsxName {txt = lident} =
4357+
let printIdent = printIdentLike ~allowUident:true in
43574358
let rec flatten acc lident =
43584359
match lident with
4359-
| Longident.Lident txt -> txt :: acc
4360-
| Ldot (lident, txt) ->
4361-
let acc = if txt = "createElement" then acc else txt :: acc in
4362-
flatten acc lident
4360+
| Longident.Lident txt -> printIdent txt :: acc
4361+
| Ldot (lident, "createElement") -> flatten acc lident
4362+
| Ldot (lident, txt) -> flatten (printIdent txt :: acc) lident
43634363
| _ -> acc
43644364
in
43654365
match lident with
4366-
| Longident.Lident txt -> Doc.text txt
4366+
| Longident.Lident txt -> printIdent txt
43674367
| _ as lident ->
43684368
let segments = flatten [] lident in
4369-
Doc.join ~sep:Doc.dot (List.map Doc.text segments)
4369+
Doc.join ~sep:Doc.dot segments
43704370

43714371
and printArgumentsWithCallbackInFirstPosition ~dotted ~state args cmtTbl =
43724372
(* Because the same subtree gets printed twice, we need to copy the cmtTbl.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ 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" />
79

810
// https://github.com/rescript-lang/syntax/issues/570
911
let x =
@@ -35,6 +37,16 @@ let x =
3537
{a}
3638
{b}
3739
</A>
40+
let x =
41+
<\"custom-tag" className="container">
42+
{a}
43+
<B />
44+
</\"custom-tag">
45+
let x =
46+
<Foo.\"custom-tag" className="container">
47+
{a}
48+
<B />
49+
</Foo.\"custom-tag">
3850

3951
let x = <div className="container" className2="container2" className3="container3" onClick />
4052

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ 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" />
911

1012
// https://github.com/rescript-lang/syntax/issues/570
1113
let x = <A> <B> <C> <D /> <E /> </C> <F> <G /> <H /> </F> </B> </A>
1214
let x = <A> {children} <B/> </A>
1315
let x = <A> <B/> {children} </A>
1416
let x = <A> {a} </A>
1517
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">
1620

1721
let x =
1822
<div

0 commit comments

Comments
 (0)