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

Commit 7eda2db

Browse files
committed
use ReactPPX4Support module from compiler
1 parent 54118b3 commit 7eda2db

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

cli/reactjs_jsx_v4.ml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
401401
let makeID =
402402
Exp.ident ~loc:callExprLoc {txt = ident ~suffix:"make"; loc = callExprLoc}
403403
in
404+
let makeReactCreateElement name =
405+
Exp.ident {txt = Ldot (Lident "React", name); loc = Location.none}
406+
in
404407
match config.mode with
405408
(* The new jsx transform *)
406409
| "automatic" ->
@@ -428,9 +431,14 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
428431
(Exp.ident
429432
{
430433
loc = Location.none;
431-
txt = Ldot (Lident "React", "createElementWithKey");
434+
txt = Ldot (Lident "ReactPPX4Support", "createElementWithKey");
432435
})
433-
[key; (nolabel, makeID); (nolabel, props)]
436+
[
437+
key;
438+
(nolabel, makeReactCreateElement "createElement");
439+
(nolabel, makeID);
440+
(nolabel, props);
441+
]
434442
| None, [] ->
435443
Exp.apply ~attrs
436444
(Exp.ident
@@ -441,9 +449,16 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
441449
(Exp.ident
442450
{
443451
loc = Location.none;
444-
txt = Ldot (Lident "React", "createElementVariadicWithKey");
452+
txt =
453+
Ldot (Lident "ReactPPX4Support", "createElementVariadicWithKey");
445454
})
446-
[key; (nolabel, makeID); (nolabel, props); (nolabel, children)]
455+
[
456+
key;
457+
(nolabel, makeReactCreateElement "createElementVariadicWithKey");
458+
(nolabel, makeID);
459+
(nolabel, props);
460+
(nolabel, children);
461+
]
447462
| Some children, [] ->
448463
Exp.apply ~attrs
449464
(Exp.ident

tests/ppx/react/expected/noPropsWithKey.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ module V4C = {
2626
ReactDOM.createElement(
2727
React.fragment,
2828
[
29-
React.createElementWithKey(~key="k", V4CA.make, {}),
30-
React.createElementWithKey(~key="k", V4CB.make, {}),
29+
ReactPPX4Support.createElementWithKey(~key="k", React.createElement, V4CA.make, {}),
30+
ReactPPX4Support.createElementWithKey(~key="k", React.createElement, V4CB.make, {}),
3131
],
3232
)
3333
let make = {

tests/ppx/react/expected/optionalKeyType.res.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ let _ = ReactDOMRe.createDOMElementVariadic(
3030

3131
@@jsxConfig({version: 4, mode: "classic"})
3232

33-
let _ = React.createElementWithKey(~key="k", C.make, {})
34-
let _ = React.createElementWithKey(~key=?Some("k"), C.make, {})
35-
let _ = React.createElementWithKey(~key?, C.make, {})
33+
let _ = ReactPPX4Support.createElementWithKey(~key="k", React.createElement, C.make, {})
34+
let _ = ReactPPX4Support.createElementWithKey(~key=?Some("k"), React.createElement, C.make, {})
35+
let _ = ReactPPX4Support.createElementWithKey(~key?, React.createElement, C.make, {})
3636
let _ = ReactDOM.createDOMElementVariadic("div", ~props={key: "k"}, [])
3737
let _ = ReactDOM.createDOMElementVariadic("div", ~props={key: ?Some("k")}, [])
3838
let _ = ReactDOM.createDOMElementVariadic("div", ~props={key: ?key}, [])

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ let make = (_: props) =>
3434
ReactDOM.createElement(
3535
React.fragment,
3636
[
37-
React.createElementWithKey(~key="k", Foo.make, {x: "x", y: "y"}),
37+
ReactPPX4Support.createElementWithKey(
38+
~key="k",
39+
React.createElement,
40+
Foo.make,
41+
{x: "x", y: "y"},
42+
),
3843
React.createElement(Foo.make, {x: "x", y: "y"}),
39-
React.createElementWithKey(
44+
ReactPPX4Support.createElementWithKey(
4045
~key="k",
46+
React.createElement,
4147
HasChildren.make,
4248
{
4349
children: React.createElement(Foo.make, {x: "x", y: "y"}),

0 commit comments

Comments
 (0)