Skip to content

Commit

Permalink
Add broken make_fn test and keep logic as before
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Nov 25, 2024
1 parent 4a1298b commit 9049b39
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 43 deletions.
26 changes: 26 additions & 0 deletions ppx/test/component-without-make.t/input.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module X_as_main_function = {
[@react.component]
let x = () => <div />;
};

module Create_element_as_main_function = {
[@react.component]
let createElement = (~lola) => <div> {React.string(lola)} </div>;
};

/* This isn't valid running code, since Foo gets transformed into Foo.make, not createElement. */
module Invalid_case = {
[@react.component]
let make = (~lola) => {
<Create_element_as_main_function lola />;
};
};

/* If main function is not make, neither createElement, then it can be explicitly annotated */
/* NOTE: If you use `createElement` refmt removes it */
module Valid_case = {
[@react.component]
let make = () => {
<Component_with_x_as_main_function.x />;
};
};
53 changes: 53 additions & 0 deletions ppx/test/component-without-make.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Since we generate invalid syntax for the argument of the make fn `(Props : <>)`
We need to output ML syntax here, otherwise refmt could not parse it.
$ ../ppx.sh --output ml input.re
module X_as_main_function =
struct
external xProps : ?key:string -> unit -> < > Js.t = ""[@@mel.obj ]
let x () = ReactDOM.jsx "div" (((ReactDOM.domProps)[@merlin.hide ]) ())
let x =
let Output$X_as_main_function$x (Props : < > Js.t) = x () in
Output$X_as_main_function$x
end
module Create_element_as_main_function =
struct
external createElementProps :
lola:'lola -> ?key:string -> unit -> < lola: 'lola > Js.t = ""
[@@mel.obj ]
let createElement =
((fun ~lola ->
ReactDOM.jsx "div"
(((ReactDOM.domProps)[@merlin.hide ])
~children:(React.string lola) ()))
[@warning "-16"])
let createElement =
let Output$Create_element_as_main_function$createElement
(Props : < lola: 'lola > Js.t) =
createElement ~lola:(Props ## lola) in
Output$Create_element_as_main_function$createElement
end
module Invalid_case =
struct
external makeProps :
lola:'lola -> ?key:string -> unit -> < lola: 'lola > Js.t = ""
[@@mel.obj ]
let make =
((fun ~lola ->
React.jsx Create_element_as_main_function.make
(Create_element_as_main_function.makeProps ~lola ()))
[@warning "-16"])
let make =
let Output$Invalid_case (Props : < lola: 'lola > Js.t) =
make ~lola:(Props ## lola) in
Output$Invalid_case
end
module Valid_case =
struct
external makeProps : ?key:string -> unit -> < > Js.t = ""[@@mel.obj ]
let make () =
React.jsx Component_with_x_as_main_function.x
(Component_with_x_as_main_function.xProps ())
let make =
let Output$Valid_case (Props : < > Js.t) = make () in
Output$Valid_case
end
12 changes: 0 additions & 12 deletions ppx/test/create-element.t/input.re

This file was deleted.

31 changes: 0 additions & 31 deletions ppx/test/create-element.t/run.t

This file was deleted.

0 comments on commit 9049b39

Please sign in to comment.