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

Commit 619ba70

Browse files
committed
Fix location issue in make function in JSX V4 that breaks dead code elimination
1 parent e3dcc3f commit 619ba70

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- Fix printing of optional fields in records https://github.com/rescript-lang/rescript-compiler/issues/5654
3030
- Fix printing of comments inside empty blocks https://github.com/rescript-lang/syntax/pull/647
3131
- Fix location issue in error messages with JSX V4 where the multiple props types are defined https://github.com/rescript-lang/syntax/pull/655
32+
- Fix location issue in make function in JSX V4 that breaks dead code elimination
3233

3334
## ReScript 10.0
3435

cli/reactjs_jsx_v4.ml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
378378
let keyProp =
379379
args |> List.filter (fun (arg_label, _) -> "key" = getLabel arg_label)
380380
in
381+
let makeID =
382+
Exp.ident ~loc:callExprLoc {txt = ident ~suffix:"make"; loc = callExprLoc}
383+
in
381384
match config.mode with
382385
(* The new jsx transform *)
383386
| "automatic" ->
@@ -397,12 +400,7 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
397400
( Exp.ident {loc = Location.none; txt = Ldot (Lident "React", "jsxs")},
398401
[] )
399402
in
400-
Exp.apply ~attrs jsxExpr
401-
([
402-
(nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc});
403-
(nolabel, props);
404-
]
405-
@ key)
403+
Exp.apply ~attrs jsxExpr ([(nolabel, makeID); (nolabel, props)] @ key)
406404
| _ -> (
407405
match (!childrenArg, keyProp) with
408406
| None, (_, keyExpr) :: _ ->
@@ -412,19 +410,12 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
412410
loc = Location.none;
413411
txt = Ldot (Lident "React", "createElementWithKey");
414412
})
415-
[
416-
(nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc});
417-
(nolabel, props);
418-
(nolabel, keyExpr);
419-
]
413+
[(nolabel, makeID); (nolabel, props); (nolabel, keyExpr)]
420414
| None, [] ->
421415
Exp.apply ~attrs
422416
(Exp.ident
423417
{loc = Location.none; txt = Ldot (Lident "React", "createElement")})
424-
[
425-
(nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc});
426-
(nolabel, props);
427-
]
418+
[(nolabel, makeID); (nolabel, props)]
428419
| Some children, (_, keyExpr) :: _ ->
429420
Exp.apply ~attrs
430421
(Exp.ident
@@ -433,7 +424,7 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
433424
txt = Ldot (Lident "React", "createElementVariadicWithKey");
434425
})
435426
[
436-
(nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc});
427+
(nolabel, makeID);
437428
(nolabel, props);
438429
(nolabel, children);
439430
(nolabel, keyExpr);
@@ -445,11 +436,7 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
445436
loc = Location.none;
446437
txt = Ldot (Lident "React", "createElementVariadic");
447438
})
448-
[
449-
(nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc});
450-
(nolabel, props);
451-
(nolabel, children);
452-
])
439+
[(nolabel, makeID); (nolabel, props); (nolabel, children)])
453440

454441
let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
455442
callArguments id =

0 commit comments

Comments
 (0)