Skip to content

Commit 0ab2074

Browse files
committed
Add broken make_fn test and keep logic as before
1 parent f963715 commit 0ab2074

File tree

4 files changed

+79
-43
lines changed

4 files changed

+79
-43
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module X_as_main_function = {
2+
[@react.component]
3+
let x = () => <div />;
4+
};
5+
6+
module Create_element_as_main_function = {
7+
[@react.component]
8+
let createElement = (~lola) => <div> {React.string(lola)} </div>;
9+
};
10+
11+
/* This isn't valid running code, since Foo gets transformed into Foo.make, not createElement. */
12+
module Invalid_case = {
13+
[@react.component]
14+
let make = (~lola) => {
15+
<Create_element_as_main_function lola />;
16+
};
17+
};
18+
19+
/* If main function is not make, neither createElement, then it can be explicitly annotated */
20+
/* NOTE: If you use `createElement` refmt removes it */
21+
module Valid_case = {
22+
[@react.component]
23+
let make = () => {
24+
<Component_with_x_as_main_function.x />;
25+
};
26+
};
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Since we generate invalid syntax for the argument of the make fn `(Props : <>)`
2+
We need to output ML syntax here, otherwise refmt could not parse it.
3+
$ ../ppx.sh --output ml input.re
4+
module X_as_main_function =
5+
struct
6+
external xProps : ?key:string -> unit -> < > Js.t = ""[@@mel.obj ]
7+
let x () = ReactDOM.jsx "div" (((ReactDOM.domProps)[@merlin.hide ]) ())
8+
let x =
9+
let Output$X_as_main_function$x (Props : < > Js.t) = x () in
10+
Output$X_as_main_function$x
11+
end
12+
module Create_element_as_main_function =
13+
struct
14+
external createElementProps :
15+
lola:'lola -> ?key:string -> unit -> < lola: 'lola > Js.t = ""
16+
[@@mel.obj ]
17+
let createElement =
18+
((fun ~lola ->
19+
ReactDOM.jsx "div"
20+
(((ReactDOM.domProps)[@merlin.hide ])
21+
~children:(React.string lola) ()))
22+
[@warning "-16"])
23+
let createElement =
24+
let Output$Create_element_as_main_function$createElement
25+
(Props : < lola: 'lola > Js.t) =
26+
createElement ~lola:(Props ## lola) in
27+
Output$Create_element_as_main_function$createElement
28+
end
29+
module Invalid_case =
30+
struct
31+
external makeProps :
32+
lola:'lola -> ?key:string -> unit -> < lola: 'lola > Js.t = ""
33+
[@@mel.obj ]
34+
let make =
35+
((fun ~lola ->
36+
React.jsx Create_element_as_main_function.make
37+
(Create_element_as_main_function.makeProps ~lola ()))
38+
[@warning "-16"])
39+
let make =
40+
let Output$Invalid_case (Props : < lola: 'lola > Js.t) =
41+
make ~lola:(Props ## lola) in
42+
Output$Invalid_case
43+
end
44+
module Valid_case =
45+
struct
46+
external makeProps : ?key:string -> unit -> < > Js.t = ""[@@mel.obj ]
47+
let make () =
48+
React.jsx Component_with_x_as_main_function.x
49+
(Component_with_x_as_main_function.xProps ())
50+
let make =
51+
let Output$Valid_case (Props : < > Js.t) = make () in
52+
Output$Valid_case
53+
end

ppx/test/create-element.t/input.re

-12
This file was deleted.

ppx/test/create-element.t/run.t

-31
This file was deleted.

0 commit comments

Comments
 (0)