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

Commit 5a54a86

Browse files
committed
using cast function to optimize
1 parent 0e664cc commit 5a54a86

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

cli/reactjs_jsx_v4.ml

+11-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,17 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
459459
recursivelyTransformedArgsForMake
460460
@
461461
match childrenExpr with
462-
| Exact children -> [(labelled "children", children)]
462+
| Exact children ->
463+
[
464+
( labelled "children",
465+
Exp.apply ~attrs:optionalAttr
466+
(Exp.ident
467+
{
468+
txt = Ldot (Lident "ReactDOM", "someElement");
469+
loc = Location.none;
470+
})
471+
[(Nolabel, children)] );
472+
]
463473
| ListLiteral {pexp_desc = Pexp_array list} when list = [] -> []
464474
| ListLiteral expression ->
465475
(* this is a hack to support react components that introspect into their children *)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type props<'msg> = { // test React JSX file
44

55
@react.component
66
let make = ({msg, _}: props<'msg>) => {
7-
ReactDOM.jsx("div", {children: {msg->React.string}})
7+
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({msg->React.string})})
88
}
99
let make = {
1010
let \"CommentAtTop" = (props: props<_>) => make(props)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module V4A = {
4141

4242
@react.component
4343
let make = ({msg, _}: props<'msg>) => {
44-
ReactDOM.jsx("div", {children: {msg->React.string}})
44+
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({msg->React.string})})
4545
}
4646
let make = {
4747
let \"FileLevelConfig$V4A" = (props: props<_>) => make(props)

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,8 @@ module V4A = {
167167
ReactDOM.jsx(
168168
"div",
169169
{
170-
children: React.jsx(
171-
FancyInput.make,
172-
{ref: input, children: {React.string("Click to focus")}},
170+
children: ?ReactDOM.someElement(
171+
React.jsx(FancyInput.make, {ref: input, children: {React.string("Click to focus")}}),
173172
),
174173
},
175174
)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module User = {
1010

1111
@react.component
1212
let make = ({doctor, _}: props<'doctor>) => {
13-
ReactDOM.jsx("h1", {id: "h1", children: {React.string(format(doctor))}})
13+
ReactDOM.jsx("h1", {id: "h1", children: ?ReactDOM.someElement({React.string(format(doctor))})})
1414
}
1515
let make = {
1616
let \"OptimizeAutomaticMode$User" = (props: props<_>) => make(props)

0 commit comments

Comments
 (0)