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

Commit 623f196

Browse files
authored
Fix support for recursive components in JSX4 (#733)
1 parent 2ed49ea commit 623f196

File tree

4 files changed

+90
-9
lines changed

4 files changed

+90
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
- Fix issue where error messages related to non-existent props were displayed without location information https://github.com/rescript-lang/syntax/pull/730
6060
- Fix issue where uncurried functions were incorrectly converting the type of a prop given as a default value to curried https://github.com/rescript-lang/syntax/pull/731
6161
- Fix issue with printing async functions with locally abstract types https://github.com/rescript-lang/syntax/pull/732
62+
- Fix support for recursive components in JSX V4 https://github.com/rescript-lang/syntax/pull/733
6263

6364
#### :eyeglasses: Spec Compliance
6465

cli/reactjs_jsx_v4.ml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,12 @@ let transformStructureItem ~config mapper item =
10431043
in
10441044
let innerExpression =
10451045
Exp.apply
1046-
(Exp.ident (Location.mknoloc @@ Lident fnName))
1046+
(Exp.ident
1047+
(Location.mknoloc
1048+
@@ Lident
1049+
(match recFlag with
1050+
| Recursive -> internalFnName
1051+
| Nonrecursive -> fnName)))
10471052
([(Nolabel, Exp.ident (Location.mknoloc @@ Lident "props"))]
10481053
@
10491054
match hasForwardRef with
@@ -1185,14 +1190,15 @@ let transformStructureItem ~config mapper item =
11851190
| Recursive ->
11861191
( [
11871192
bindingWrapper
1188-
(Exp.let_ ~loc:emptyLoc Recursive
1189-
[
1190-
makeNewBinding binding expression internalFnName;
1191-
Vb.mk
1192-
(Pat.var {loc = emptyLoc; txt = fnName})
1193-
fullExpression;
1194-
]
1195-
(Exp.ident {loc = emptyLoc; txt = Lident fnName}));
1193+
(Exp.let_ ~loc:emptyLoc Nonrecursive
1194+
[makeNewBinding binding expression internalFnName]
1195+
(Exp.let_ ~loc:emptyLoc Nonrecursive
1196+
[
1197+
Vb.mk
1198+
(Pat.var {loc = emptyLoc; txt = fnName})
1199+
fullExpression;
1200+
]
1201+
(Exp.ident {loc = emptyLoc; txt = Lident fnName})));
11961202
],
11971203
None )
11981204
| Nonrecursive ->

tests/ppx/react/expected/v4.res.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,55 @@ module AnotherName = {
1616
\"V4$AnotherName$anotherName"
1717
}
1818
}
19+
20+
module Rec = {
21+
type props = {}
22+
23+
let rec make = {
24+
@merlin.focus
25+
let \"make$Internal" = (_: props) => {
26+
make(({}: props))
27+
}
28+
let make = {
29+
let \"V4$Rec" = props => \"make$Internal"(props)
30+
31+
\"V4$Rec"
32+
}
33+
make
34+
}
35+
}
36+
37+
module Rec1 = {
38+
type props = {}
39+
40+
let rec make = {
41+
@merlin.focus
42+
let \"make$Internal" = (_: props) => {
43+
React.null
44+
}
45+
let make = {
46+
let \"V4$Rec1" = props => \"make$Internal"(props)
47+
48+
\"V4$Rec1"
49+
}
50+
make
51+
}
52+
}
53+
54+
module Rec2 = {
55+
type props = {}
56+
57+
let rec make = {
58+
@merlin.focus
59+
let \"make$Internal" = (_: props) => {
60+
mm(({}: props))
61+
}
62+
let make = {
63+
let \"V4$Rec2" = props => \"make$Internal"(props)
64+
65+
\"V4$Rec2"
66+
}
67+
make
68+
}
69+
and mm = x => make(x)
70+
}

tests/ppx/react/v4.res

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,25 @@ module AnotherName = {
77
@react.component
88
let anotherName = (~x) => React.string(x)
99
}
10+
11+
module Rec = {
12+
@react.component
13+
let rec make = () => {
14+
make({}:props)
15+
}
16+
}
17+
18+
module Rec1 = {
19+
@react.component
20+
let rec make = () => {
21+
React.null
22+
}
23+
}
24+
25+
module Rec2 = {
26+
@react.component
27+
let rec make = () => {
28+
mm(({}: props))
29+
}
30+
and mm = (x) => make(x)
31+
}

0 commit comments

Comments
 (0)