Skip to content

Commit 78a94cc

Browse files
committed
fix shorthand fragment transformation
1 parent ced87d1 commit 78a94cc

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

jscomp/syntax/src/reactjs_jsx_v4.ml

+10-12
Original file line numberDiff line numberDiff line change
@@ -1374,24 +1374,22 @@ let expr ~config mapper expression =
13741374
let transformChildrenToProps childrenExpr =
13751375
match childrenExpr with
13761376
| {pexp_desc = Pexp_array children} -> (
1377-
match children with
1378-
| [] -> emptyRecord ~loc:Location.none
1379-
| [child] -> recordOfChildren child
1380-
| _ -> (
1381-
match config.mode with
1382-
| "automatic" -> recordOfChildren @@ applyReactArray childrenExpr
1383-
| "classic" | _ -> emptyRecord ~loc:Location.none))
1384-
| _ -> (
13851377
match config.mode with
1386-
| "automatic" -> recordOfChildren @@ applyReactArray childrenExpr
1387-
| "classic" | _ -> emptyRecord ~loc:Location.none)
1378+
| "automatic" -> (
1379+
match children with
1380+
| [] -> emptyRecord ~loc:Location.none
1381+
| [child] -> recordOfChildren child
1382+
| _ -> recordOfChildren @@ applyReactArray childrenExpr)
1383+
| "classic" -> emptyRecord ~loc:Location.none
1384+
| _ -> recordOfChildren @@ applyReactArray childrenExpr)
1385+
| _ -> recordOfChildren @@ applyReactArray childrenExpr
13881386
in
13891387
let args =
13901388
(nolabel, fragment)
13911389
:: (nolabel, transformChildrenToProps childrenExpr)
13921390
::
13931391
(match config.mode with
1394-
| "classic" when countOfChildren childrenExpr > 1 ->
1392+
| "classic" when countOfChildren childrenExpr > 0 ->
13951393
[(nolabel, childrenExpr)]
13961394
| _ -> [])
13971395
in
@@ -1405,7 +1403,7 @@ let expr ~config mapper expression =
14051403
Exp.ident ~loc {loc; txt = Ldot (Lident "React", "jsxs")}
14061404
else Exp.ident ~loc {loc; txt = Ldot (Lident "React", "jsx")}
14071405
| "classic" | _ ->
1408-
if countOfChildren childrenExpr > 1 then
1406+
if countOfChildren childrenExpr > 0 then
14091407
Exp.ident ~loc
14101408
{loc; txt = Ldot (Lident "React", "createElementVariadic")}
14111409
else

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
@@jsxConfig({version: 4, mode: "classic"})
22

33
let _ = React.createElement(React.fragment, {})
4-
let _ = React.createElement(
4+
let _ = React.createElementVariadic(
55
React.fragment,
6-
{children: ReactDOM.createDOMElementVariadic("div", [])},
6+
{},
7+
[ReactDOM.createDOMElementVariadic("div", [])],
78
)
89
let _ = React.createElementVariadic(
910
React.fragment,
1011
{},
1112
[ReactDOM.createDOMElementVariadic("div", []), ReactDOM.createDOMElementVariadic("div", [])],
1213
)
13-
let _ = React.createElement(React.fragment, {children: React.createElement(React.fragment, {})})
14+
let _ = React.createElementVariadic(React.fragment, {}, [React.createElement(React.fragment, {})])
1415
let _ = React.createElement(Z.make, {})
1516
let _ = React.createElement(Z.make, {children: ReactDOM.createDOMElementVariadic("div", [])})
1617
let _ = React.createElement(

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module Foo = {
1414
module HasChildren = {
1515
type props<'children> = {children: 'children}
1616

17-
let make = ({children, _}: props<_>) => React.createElement(React.fragment, {children: children})
17+
let make = ({children, _}: props<_>) =>
18+
React.createElementVariadic(React.fragment, {}, [children])
1819
let make = {
1920
let \"RemovedKeyProp$HasChildren" = (props: props<_>) => make(props)
2021

0 commit comments

Comments
 (0)