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

Commit 0337629

Browse files
committed
add tests for v3 and v4 respectively
1 parent 0bacbe3 commit 0337629

22 files changed

+259
-2
lines changed

scripts/test.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
function exp {
99
echo "$(dirname $1)/expected/$(basename $1).txt"
1010
}
11+
function exp2 {
12+
echo "$(dirname $1)/expected/$(basename $1)$2.txt"
13+
}
1114

1215
taskCount=0
1316
function maybeWait {
@@ -35,10 +38,22 @@ while read file; do
3538
rescript $file &> $(exp $file) & maybeWait
3639
done <temp/files.txt
3740

38-
# printing with ppx
41+
# printing with ppx v3
42+
find tests/ppx/react -name "*.res" -o -name "*.resi" >temp/files.txt
43+
while read file; do
44+
rescript -ppx jsx3 $file &> $(exp2 $file "_v3") & maybeWait
45+
done <temp/files.txt
46+
47+
# printing with ppx v4 classic
48+
find tests/ppx/react -name "*.res" -o -name "*.resi" >temp/files.txt
49+
while read file; do
50+
rescript -ppx jsx4 -jsx-runtime classic $file &> $(exp2 $file "_v4_cls") & maybeWait
51+
done <temp/files.txt
52+
53+
# printing with ppx v4 automatic
3954
find tests/ppx/react -name "*.res" -o -name "*.resi" >temp/files.txt
4055
while read file; do
41-
rescript -ppx jsx $file &> $(exp $file) & maybeWait
56+
rescript -ppx jsx4 -jsx-runtime automatic $file &> $(exp2 $file "_v4_auto") & maybeWait
4257
done <temp/files.txt
4358

4459
wait
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@obj external makeProps: (~msg: 'msg, ~key: string=?, unit) => {"msg": 'msg} = "" // test React JSX file
2+
3+
let make =
4+
(@warning("-16") ~msg) => {
5+
ReactDOMRe.createDOMElementVariadic("div", [{msg->React.string}])
6+
}
7+
let make = {
8+
let \"CommentAtTop" = (\"Props": {"msg": 'msg}) => make(~msg=\"Props"["msg"])
9+
\"CommentAtTop"
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type props<'msg> = {@optional key: string, msg: 'msg} // test React JSX file
2+
3+
let make = ({msg}: props<'msg>) => {
4+
ReactDOMRe.createDOMElementVariadic("div", [{msg->React.string}])
5+
}
6+
let make = {
7+
let \"CommentAtTop" = (props: props<_>) => make(props)
8+
\"CommentAtTop"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Foo = {
2+
@obj
3+
external componentProps: (~a: int, ~b: string, ~key: string=?, unit) => {"a": int, "b": string} =
4+
""
5+
@module("Foo")
6+
external component: React.componentLike<{"a": int, "b": string}, React.element> = "component"
7+
}
8+
9+
let t = React.createElement(Foo.component, Foo.componentProps(~a=1, ~b={"1"}, ()))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Foo = {
2+
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
3+
@module("Foo")
4+
external component: React.componentLike<props<'a, 'b>, React.element> = "component"
5+
}
6+
7+
let t = React.jsx(Foo.component, {a: 1, b: "1"})
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module FancyInput = {
2+
@obj
3+
external makeProps: (
4+
~className: 'className=?,
5+
~children: 'children,
6+
~key: string=?,
7+
~ref: 'ref=?,
8+
unit,
9+
) => {"className": option<'className>, "children": 'children} = ""
10+
let make =
11+
(@warning("-16") ~className=?, @warning("-16") ~children) =>
12+
@warning("-16")
13+
ref =>
14+
ReactDOMRe.createDOMElementVariadic(
15+
"div",
16+
[
17+
ReactDOMRe.createDOMElementVariadic(
18+
"input",
19+
~props=ReactDOMRe.domProps(
20+
~type_="text",
21+
~className?,
22+
~ref=?{Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)},
23+
(),
24+
),
25+
[],
26+
),
27+
children,
28+
],
29+
)
30+
let make = React.forwardRef({
31+
let \"ForwardRef$FancyInput" = (
32+
\"Props": {"className": option<'className>, "children": 'children},
33+
ref,
34+
) => make(~children=\"Props"["children"], ~className=?\"Props"["className"], ref)
35+
\"ForwardRef$FancyInput"
36+
})
37+
}
38+
@obj external makeProps: (~key: string=?, unit) => {.} = ""
39+
40+
let make = () => {
41+
let input = React.useRef(Js.Nullable.null)
42+
43+
ReactDOMRe.createDOMElementVariadic(
44+
"div",
45+
[
46+
React.createElement(
47+
FancyInput.make,
48+
FancyInput.makeProps(~ref=input, ~children={React.string("Click to focus")}, ()),
49+
),
50+
],
51+
)
52+
}
53+
let make = {
54+
let \"ForwardRef" = (\"Props": {.}) => make()
55+
\"ForwardRef"
56+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module FancyInput = {
2+
type props<'className, 'children> = {
3+
@optional key: string,
4+
@optional className: 'className,
5+
children: 'children,
6+
@optional ref: ReactDOM.Ref.currentDomRef,
7+
}
8+
let make = ({className, children, ref}: props<'className, 'children>) => {
9+
let ref = Js.Nullable.fromOption(ref)
10+
let _ = ref
11+
12+
ReactDOMRe.createDOMElementVariadic(
13+
"div",
14+
[
15+
ReactDOMRe.createDOMElementVariadic(
16+
"input",
17+
~props=ReactDOMRe.domProps(
18+
~type_="text",
19+
~className?,
20+
~ref=?{Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)},
21+
(),
22+
),
23+
[],
24+
),
25+
children,
26+
],
27+
)
28+
}
29+
let make = React.forwardRef({
30+
let \"ForwardRef$FancyInput" = (props: props<_>, ref) =>
31+
make({...props, ref: @optional Js.Nullable.toOption(ref)})
32+
\"ForwardRef$FancyInput"
33+
})
34+
}
35+
type props = {@optional key: string}
36+
37+
let make = (_: props) => {
38+
let input = React.useRef(Js.Nullable.null)
39+
40+
ReactDOMRe.createDOMElementVariadic(
41+
"div",
42+
[React.jsx(FancyInput.make, {ref: input, children: {React.string("Click to focus")}})],
43+
)
44+
}
45+
let make = {
46+
let \"ForwardRef" = props => make(props)
47+
\"ForwardRef"
48+
}

0 commit comments

Comments
 (0)