Skip to content

Commit

Permalink
Fix ppx for uppercase components
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Aug 2, 2023
1 parent 8111643 commit 16fac6c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
8 changes: 7 additions & 1 deletion packages/server-reason-react-ppx/ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,13 @@ let jsxMapper () =
(Invalid_argument
"JSX name can't be the result of function applications")
in
Exp.apply ~attrs ~loc (Exp.ident ~loc { loc; txt = makeFnIdentifier }) args
[%expr
React.Upper_case_component
(fun () ->
[%e
Exp.apply ~attrs ~loc
(Exp.ident ~loc { loc; txt = makeFnIdentifier })
args])]
in
let transformLowercaseCall ~loc mapper attrs callArguments id callLoc =
let children, nonChildrenProps =
Expand Down
68 changes: 43 additions & 25 deletions packages/server-reason-react-ppx/test_snapshot/reason.expected
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let lower_children_multiple foo bar =
let lower_child_with_upper_as_children =
React.createElement "div"
((([||] |> Array.to_list) |> (List.filter_map (fun a -> a))) |>
Array.of_list) [App.make ()]
Array.of_list) [React.Upper_case_component ((fun () -> App.make ()))]
let lower_children_nested =
React.createElement "div"
((([|(Some
Expand Down Expand Up @@ -146,31 +146,45 @@ let fragment_as_a_child =
((([||] |> Array.to_list) |>
(List.filter_map (fun a -> a)))
|> Array.of_list) []]) ()]
let upper = Upper.make ()
let upper_prop = Upper.make ~count ()
let upper_children_single foo = Upper.make ~children:foo ()
let upper = React.Upper_case_component (fun () -> Upper.make ())
let upper_prop = React.Upper_case_component (fun () -> Upper.make ~count ())
let upper_children_single foo =
React.Upper_case_component (fun () -> Upper.make ~children:foo ())
let upper_children_multiple foo bar =
Upper.make ~children:(React.list [foo; bar]) ()
React.Upper_case_component
(fun () -> Upper.make ~children:(React.list [foo; bar]) ())
let upper_children =
Page.make ~moreProps:"hgalo"
~children:(React.createElement "h1"
((([||] |> Array.to_list) |> (List.filter_map (fun a -> a)))
|> Array.of_list) [React.string "Yep"]) ()
let upper_nested_module = Foo.Bar.make ~a:1 ~b:"1" ()
let upper_child_expr = Div.make ~children:(React.int 1) ()
let upper_child_ident = Div.make ~children:lola ()
React.Upper_case_component
(fun () ->
Page.make ~moreProps:"hgalo"
~children:(React.createElement "h1"
((([||] |> Array.to_list) |>
(List.filter_map (fun a -> a)))
|> Array.of_list) [React.string "Yep"]) ())
let upper_nested_module =
React.Upper_case_component (fun () -> Foo.Bar.make ~a:1 ~b:"1" ())
let upper_child_expr =
React.Upper_case_component (fun () -> Div.make ~children:(React.int 1) ())
let upper_child_ident =
React.Upper_case_component (fun () -> Div.make ~children:lola ())
let upper_all_kinds_of_props =
MyComponent.make ~booleanAttribute:true ~stringAttribute:"string"
~intAttribute:1 ?forcedOptional:((Some "hello")[@explicit_arity ])
~onClick:(send handleClick)
~children:(React.createElement "div"
((([||] |> Array.to_list) |> (List.filter_map (fun a -> a)))
|> Array.of_list) ["hello"]) ()
React.Upper_case_component
(fun () ->
MyComponent.make ~booleanAttribute:true ~stringAttribute:"string"
~intAttribute:1 ?forcedOptional:((Some "hello")[@explicit_arity ])
~onClick:(send handleClick)
~children:(React.createElement "div"
((([||] |> Array.to_list) |>
(List.filter_map (fun a -> a)))
|> Array.of_list) ["hello"]) ())
let upper_ref_with_children =
FancyButton.make ~ref:buttonRef
~children:(React.createElement "div"
((([||] |> Array.to_list) |> (List.filter_map (fun a -> a)))
|> Array.of_list) []) ()
React.Upper_case_component
(fun () ->
FancyButton.make ~ref:buttonRef
~children:(React.createElement "div"
((([||] |> Array.to_list) |>
(List.filter_map (fun a -> a)))
|> Array.of_list) []) ())
let lower_ref_with_children =
React.createElement "button"
((([|(Some (React.Attribute.Ref ref));(Some
Expand Down Expand Up @@ -242,7 +256,8 @@ module React_component_with_props =
[@warning "-16"][@warning "-16"])
end
let react_component_with_props =
React_component_with_props.make ~lola:"flores" ()
React.Upper_case_component
(fun () -> React_component_with_props.make ~lola:"flores" ())
module Upper_case_with_fragment_as_root =
struct
let make ?key =
Expand All @@ -255,8 +270,11 @@ module Upper_case_with_fragment_as_root =
(List.filter_map (fun a -> a)))
|> Array.of_list)
[React.string ("First " ^ name)];
Hello.make ~one:"1"
~children:(React.string ("2nd " ^ name)) ()]) ())
React.Upper_case_component
((fun () ->
Hello.make ~one:"1"
~children:(React.string ("2nd " ^ name))
()))]) ())
[@warning "-16"][@warning "-16"])
end
module Using_React_memo =
Expand Down

0 comments on commit 16fac6c

Please sign in to comment.