Skip to content

Commit 98d9854

Browse files
committed
record of children for fragment
1 parent 05b459d commit 98d9854

File tree

4 files changed

+46
-37
lines changed

4 files changed

+46
-37
lines changed

jscomp/syntax/src/reactjs_jsx_v4.ml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,17 +1364,14 @@ let expr ~config mapper expression =
13641364
let args =
13651365
[
13661366
(nolabel, fragment);
1367-
(match config.mode with
1368-
| "automatic" -> (
1369-
( nolabel,
1370-
match childrenExpr with
1371-
| {pexp_desc = Pexp_array children} -> (
1372-
match children with
1373-
| [] -> emptyRecord ~loc:Location.none
1374-
| [child] -> recordOfChildren child
1375-
| _ -> recordOfChildren childrenExpr)
1376-
| _ -> recordOfChildren childrenExpr ))
1377-
| "classic" | _ -> (nolabel, childrenExpr));
1367+
( nolabel,
1368+
match childrenExpr with
1369+
| {pexp_desc = Pexp_array children} -> (
1370+
match children with
1371+
| [] -> emptyRecord ~loc:Location.none
1372+
| [child] -> recordOfChildren child
1373+
| _ -> recordOfChildren childrenExpr)
1374+
| _ -> recordOfChildren childrenExpr );
13781375
]
13791376
in
13801377
let countOfChildren = function

jscomp/syntax/tests/ppx/react/expected/fragment.res.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
@@jsxConfig({version: 4, mode: "classic"})
22

3-
let _ = React.createElement(React.fragment, [])
4-
let _ = React.createElement(React.fragment, [ReactDOM.createDOMElementVariadic("div", [])])
3+
let _ = React.createElement(React.fragment, {})
4+
let _ = React.createElement(
5+
React.fragment,
6+
{children: ReactDOM.createDOMElementVariadic("div", [])},
7+
)
58
let _ = React.createElementVariadic(
69
React.fragment,
7-
[ReactDOM.createDOMElementVariadic("div", []), ReactDOM.createDOMElementVariadic("div", [])],
10+
{
11+
children: [
12+
ReactDOM.createDOMElementVariadic("div", []),
13+
ReactDOM.createDOMElementVariadic("div", []),
14+
],
15+
},
816
)
9-
let _ = React.createElement(React.fragment, [React.createElement(React.fragment, [])])
17+
let _ = React.createElement(React.fragment, {children: React.createElement(React.fragment, {})})
1018
let _ = React.createElement(Z.make, {})
1119
let _ = React.createElement(Z.make, {children: ReactDOM.createDOMElementVariadic("div", [])})
1220
let _ = React.createElementVariadic(

jscomp/syntax/tests/ppx/react/expected/noPropsWithKey.res.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ module V4C = {
2424
let make = (_: props) =>
2525
React.createElementVariadic(
2626
React.fragment,
27-
[
28-
JsxPPXReactSupport.createElementWithKey(~key="k", V4CA.make, {}),
29-
JsxPPXReactSupport.createElementWithKey(~key="k", V4CB.make, {}),
30-
],
27+
{
28+
children: [
29+
JsxPPXReactSupport.createElementWithKey(~key="k", V4CA.make, {}),
30+
JsxPPXReactSupport.createElementWithKey(~key="k", V4CB.make, {}),
31+
],
32+
},
3133
)
3234
let make = {
3335
let \"NoPropsWithKey$V4C" = props => make(props)

jscomp/syntax/tests/ppx/react/expected/removedKeyProp.res.txt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Foo = {
1414
module HasChildren = {
1515
type props<'children> = {children: 'children}
1616

17-
let make = ({children, _}: props<_>) => React.createElement(React.fragment, [children])
17+
let make = ({children, _}: props<_>) => React.createElement(React.fragment, {children: children})
1818
let make = {
1919
let \"RemovedKeyProp$HasChildren" = (props: props<_>) => make(props)
2020

@@ -26,23 +26,25 @@ type props = {}
2626
let make = (_: props) =>
2727
React.createElementVariadic(
2828
React.fragment,
29-
[
30-
JsxPPXReactSupport.createElementWithKey(~key="k", Foo.make, {x: "x", y: "y"}),
31-
React.createElement(Foo.make, {x: "x", y: "y"}),
32-
JsxPPXReactSupport.createElementWithKey(
33-
~key="k",
34-
HasChildren.make,
35-
{
36-
children: React.createElement(Foo.make, {x: "x", y: "y"}),
37-
},
38-
),
39-
React.createElement(
40-
HasChildren.make,
41-
{
42-
children: React.createElement(Foo.make, {x: "x", y: "y"}),
43-
},
44-
),
45-
],
29+
{
30+
children: [
31+
JsxPPXReactSupport.createElementWithKey(~key="k", Foo.make, {x: "x", y: "y"}),
32+
React.createElement(Foo.make, {x: "x", y: "y"}),
33+
JsxPPXReactSupport.createElementWithKey(
34+
~key="k",
35+
HasChildren.make,
36+
{
37+
children: React.createElement(Foo.make, {x: "x", y: "y"}),
38+
},
39+
),
40+
React.createElement(
41+
HasChildren.make,
42+
{
43+
children: React.createElement(Foo.make, {x: "x", y: "y"}),
44+
},
45+
),
46+
],
47+
},
4648
)
4749
let make = {
4850
let \"RemovedKeyProp" = props => make(props)

0 commit comments

Comments
 (0)