Skip to content

Commit 54a5b2b

Browse files
committed
Fix recursive @react.componentWithProps
1 parent 0f33de2 commit 54a5b2b

3 files changed

Lines changed: 15 additions & 19 deletions

File tree

compiler/syntax/src/jsx_v4.ml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ let vb_match_expr named_arg_list expr =
531531
in
532532
aux (List.rev named_arg_list)
533533

534-
let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
534+
let map_binding ~config ~empty_loc ~pstr_loc ~file_name binding =
535535
(* Traverse the component body and force every reachable return expression to
536536
be annotated as `Jsx.element`. This walks through the wrapper constructs the
537537
PPX introduces (fun/newtype/let/sequence) so that the constraint ends up on
@@ -801,7 +801,6 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
801801
}
802802
in
803803
let fn_name = get_fn_name modified_binding.pvb_pat in
804-
let internal_fn_name = fn_name ^ "$Internal" in
805804
let full_module_name =
806805
make_module_name file_name config.nested_modules fn_name
807806
in
@@ -850,15 +849,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
850849
in
851850
let applied_expression =
852851
Exp.apply
853-
(Exp.ident
854-
{
855-
txt =
856-
Lident
857-
(match rec_flag with
858-
| Recursive -> internal_fn_name
859-
| Nonrecursive -> fn_name);
860-
loc;
861-
})
852+
(Exp.ident {txt = Lident fn_name; loc})
862853
[(Nolabel, Exp.ident {txt = Lident "props"; loc})]
863854
in
864855
let applied_expression =
@@ -884,11 +875,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
884875
in
885876

886877
let new_binding =
887-
match rec_flag with
888-
| Recursive -> None
889-
| Nonrecursive ->
890-
Some
891-
(make_new_binding ~loc:empty_loc ~full_module_name modified_binding)
878+
Some (make_new_binding ~loc:empty_loc ~full_module_name modified_binding)
892879
in
893880
let binding_expr =
894881
{
@@ -994,7 +981,7 @@ let transform_structure_item ~config item =
994981
let empty_loc = Location.in_file file_name in
995982
let process_binding binding (new_items, bindings, new_bindings) =
996983
let new_item, binding, new_binding =
997-
map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding
984+
map_binding ~config ~empty_loc ~pstr_loc ~file_name binding
998985
in
999986
let new_items =
1000987
match new_item with

tests/build_tests/react_ppx/src/recursive_explicit_component_test.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ module ComponentWithProps = {
2020
React.createElement(React.component(make), {foo: props.foo - 1})
2121
}
2222
}
23+
24+
let componentWithPropsElement = React.createElement(ComponentWithProps.make, {foo: 1})

tests/build_tests/react_ppx/src/recursive_explicit_component_test.res.js

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)