From 79be3c0abe36f40222da5b0571c6f49c9a81a3fd Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 28 Sep 2022 05:41:43 +0200 Subject: [PATCH 1/2] Fix location issue in make function in JSX V4 that breaks dead code elimination --- CHANGELOG.md | 1 + cli/reactjs_jsx_v4.ml | 29 ++++++++--------------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6446214..9c8af1bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Fix printing of optional fields in records https://github.com/rescript-lang/rescript-compiler/issues/5654 - Fix printing of comments inside empty blocks https://github.com/rescript-lang/syntax/pull/647 - Fix location issue in error messages with JSX V4 where the multiple props types are defined https://github.com/rescript-lang/syntax/pull/655 +- Fix location issue in make function in JSX V4 that breaks dead code elimination ## ReScript 10.0 diff --git a/cli/reactjs_jsx_v4.ml b/cli/reactjs_jsx_v4.ml index e11b6f96..a7a016d7 100644 --- a/cli/reactjs_jsx_v4.ml +++ b/cli/reactjs_jsx_v4.ml @@ -378,6 +378,9 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc let keyProp = args |> List.filter (fun (arg_label, _) -> "key" = getLabel arg_label) in + let makeID = + Exp.ident ~loc:callExprLoc {txt = ident ~suffix:"make"; loc = callExprLoc} + in match config.mode with (* The new jsx transform *) | "automatic" -> @@ -397,12 +400,7 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc ( Exp.ident {loc = Location.none; txt = Ldot (Lident "React", "jsxs")}, [] ) in - Exp.apply ~attrs jsxExpr - ([ - (nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc}); - (nolabel, props); - ] - @ key) + Exp.apply ~attrs jsxExpr ([(nolabel, makeID); (nolabel, props)] @ key) | _ -> ( match (!childrenArg, keyProp) with | None, (_, keyExpr) :: _ -> @@ -412,19 +410,12 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc loc = Location.none; txt = Ldot (Lident "React", "createElementWithKey"); }) - [ - (nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc}); - (nolabel, props); - (nolabel, keyExpr); - ] + [(nolabel, makeID); (nolabel, props); (nolabel, keyExpr)] | None, [] -> Exp.apply ~attrs (Exp.ident {loc = Location.none; txt = Ldot (Lident "React", "createElement")}) - [ - (nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc}); - (nolabel, props); - ] + [(nolabel, makeID); (nolabel, props)] | Some children, (_, keyExpr) :: _ -> Exp.apply ~attrs (Exp.ident @@ -433,7 +424,7 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc txt = Ldot (Lident "React", "createElementVariadicWithKey"); }) [ - (nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc}); + (nolabel, makeID); (nolabel, props); (nolabel, children); (nolabel, keyExpr); @@ -445,11 +436,7 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc loc = Location.none; txt = Ldot (Lident "React", "createElementVariadic"); }) - [ - (nolabel, Exp.ident {txt = ident ~suffix:"make"; loc = callExprLoc}); - (nolabel, props); - (nolabel, children); - ]) + [(nolabel, makeID); (nolabel, props); (nolabel, children)]) let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs callArguments id = From 512fde07cd660a1a0e4001c65bc0001b151f0a2a Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 28 Sep 2022 05:43:05 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c8af1bf..8c576e5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ - Fix printing of optional fields in records https://github.com/rescript-lang/rescript-compiler/issues/5654 - Fix printing of comments inside empty blocks https://github.com/rescript-lang/syntax/pull/647 - Fix location issue in error messages with JSX V4 where the multiple props types are defined https://github.com/rescript-lang/syntax/pull/655 -- Fix location issue in make function in JSX V4 that breaks dead code elimination +- Fix location issue in make function in JSX V4 that breaks dead code elimination https://github.com/rescript-lang/syntax/pull/660 ## ReScript 10.0