@@ -1358,28 +1358,43 @@ let expr ~config mapper expression =
1358
1358
in
1359
1359
let childrenExpr = transformChildrenIfList ~mapper listItems in
1360
1360
let recordOfChildren children =
1361
+ (* FIXME: missing loc *)
1361
1362
Exp. record [(Location. mknoloc (Lident " children" ), children)] None
1362
1363
in
1363
- let args =
1364
- [
1365
- (nolabel, fragment);
1366
- (match config.mode with
1367
- | "automatic" -> (
1368
- ( nolabel,
1369
- match childrenExpr with
1370
- | {pexp_desc = Pexp_array children } -> (
1371
- match children with
1372
- | [] -> emptyRecord ~loc: Location. none
1373
- | [child] -> recordOfChildren child
1374
- | _ -> recordOfChildren childrenExpr)
1375
- | _ -> recordOfChildren childrenExpr ))
1376
- | "classic" | _ -> (nolabel, childrenExpr));
1377
- ]
1364
+ let applyReactArray expr =
1365
+ Exp. apply
1366
+ (Exp. ident
1367
+ {txt = Ldot (Lident " React" , " array" ); loc = Location. none})
1368
+ [(Nolabel , expr)]
1378
1369
in
1379
1370
let countOfChildren = function
1380
1371
| {pexp_desc = Pexp_array children } -> List. length children
1381
1372
| _ -> 0
1382
1373
in
1374
+ let transformChildrenToProps childrenExpr =
1375
+ match childrenExpr with
1376
+ | {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
+ | _ -> (
1385
+ match config.mode with
1386
+ | "automatic" -> recordOfChildren @@ applyReactArray childrenExpr
1387
+ | "classic" | _ -> emptyRecord ~loc: Location. none)
1388
+ in
1389
+ let args =
1390
+ (nolabel, fragment)
1391
+ :: (nolabel, transformChildrenToProps childrenExpr)
1392
+ ::
1393
+ (match config.mode with
1394
+ | "classic" when countOfChildren childrenExpr > 1 ->
1395
+ [(nolabel, childrenExpr)]
1396
+ | _ -> [] )
1397
+ in
1383
1398
Exp. apply
1384
1399
~loc (* throw away the [@JSX] attribute and keep the others, if any *)
1385
1400
~attrs: nonJSXAttributes
@@ -1390,7 +1405,11 @@ let expr ~config mapper expression =
1390
1405
Exp. ident ~loc {loc; txt = Ldot (Lident " React" , " jsxs" )}
1391
1406
else Exp. ident ~loc {loc; txt = Ldot (Lident " React" , " jsx" )}
1392
1407
| "classic" | _ ->
1393
- Exp. ident ~loc {loc; txt = Ldot (Lident " ReactDOM" , " createElement" )})
1408
+ if countOfChildren childrenExpr > 1 then
1409
+ Exp. ident ~loc
1410
+ {loc; txt = Ldot (Lident " React" , " createElementVariadic" )}
1411
+ else
1412
+ Exp. ident ~loc {loc; txt = Ldot (Lident " React" , " createElement" )})
1394
1413
args)
1395
1414
(* Delegate to the default mapper, a deep identity traversal *)
1396
1415
| e -> default_mapper.expr mapper e
0 commit comments