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

Commit d9c2649

Browse files
committed
fix support for recursive components in JSX4
1 parent 913aa08 commit d9c2649

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

cli/reactjs_jsx_v4.ml

+8-2
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
@@ -1228,7 +1233,8 @@ let transformStructureItem ~config mapper item =
12281233
List.fold_right otherStructures structuresAndBinding ([], [], [])
12291234
in
12301235
types
1231-
@ [{pstr_loc; pstr_desc = Pstr_value (recFlag, bindings)}]
1236+
(* No need to be Recursive as internal representation is called *)
1237+
@ [{pstr_loc; pstr_desc = Pstr_value (Nonrecursive, bindings)}]
12321238
@
12331239
match newBindings with
12341240
| [] -> []

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

+19-2
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,33 @@ module AnotherName = {
2020
module Rec = {
2121
type props = {}
2222

23-
let rec make = {
23+
let make = {
2424
@merlin.focus
2525
let rec \"make$Internal" = (_: props) => {
2626
make(({}: props))
2727
}
2828
and make = {
29-
let \"V4$Rec" = props => make(props)
29+
let \"V4$Rec" = props => \"make$Internal"(props)
3030

3131
\"V4$Rec"
3232
}
3333
make
3434
}
3535
}
36+
37+
module Rec1 = {
38+
type props = {}
39+
40+
let make = {
41+
@merlin.focus
42+
let rec \"make$Internal" = (_: props) => {
43+
React.null
44+
}
45+
and make = {
46+
let \"V4$Rec1" = props => \"make$Internal"(props)
47+
48+
\"V4$Rec1"
49+
}
50+
make
51+
}
52+
}

tests/ppx/react/v4.res

+7
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ module Rec = {
1313
let rec make = () => {
1414
make({}:props)
1515
}
16+
}
17+
18+
module Rec1 = {
19+
@react.component
20+
let rec make = () => {
21+
React.null
22+
}
1623
}

0 commit comments

Comments
 (0)