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

Commit ead4831

Browse files
committed
add test example for optional prop value
1 parent 6975f8e commit ead4831

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Parens = {
2+
type props<'id> = {key?: string, id?: 'id}
3+
@react.component
4+
let make = ({?id, _}: props<'id>) => {
5+
ReactDOM.jsx(
6+
"div",
7+
{
8+
id: ?{
9+
let _ = ()
10+
id->Option.map(x => x)
11+
},
12+
},
13+
)
14+
}
15+
let make = {
16+
let \"OptionalPropValue$Parens" = (props: props<_>) => make(props)
17+
\"OptionalPropValue$Parens"
18+
}
19+
}
20+
21+
module WithoutParens = {
22+
type props<'id> = {key?: string, id?: 'id}
23+
24+
@react.component
25+
let make = ({?id, _}: props<'id>) => {
26+
ReactDOM.jsx("div", {id: ?id->Option.map(x => x)})
27+
}
28+
let make = {
29+
let \"OptionalPropValue$WithoutParens" = (props: props<_>) => make(props)
30+
\"OptionalPropValue$WithoutParens"
31+
}
32+
}

tests/ppx/react/optionalPropValue.res

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Parens = {
2+
@react.component
3+
let make = (~id=?) => {
4+
<div
5+
id=?{
6+
let _ = ()
7+
id->Option.map(x => x)
8+
}
9+
/>
10+
}
11+
}
12+
13+
module WithoutParens = {
14+
@react.component
15+
let make = (~id=?) => {
16+
<div id=?{id->Option.map(x => x)} />
17+
}
18+
}

0 commit comments

Comments
 (0)