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

Fix location issue in make function in JSX V4 that breaks dead code e… #660

Merged
merged 2 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 https://github.com/rescript-lang/syntax/pull/660

## ReScript 10.0

Expand Down
29 changes: 8 additions & 21 deletions cli/reactjs_jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ->
Expand All @@ -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) :: _ ->
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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 =
Expand Down