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

Remove Caml_option.some from jsx mode #669

Merged
merged 2 commits into from
Oct 4, 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
12 changes: 11 additions & 1 deletion cli/reactjs_jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,17 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
recursivelyTransformedArgsForMake
@
match childrenExpr with
| Exact children -> [(labelled "children", children)]
| Exact children ->
[
( labelled "children",
Exp.apply ~attrs:optionalAttr
(Exp.ident
{
txt = Ldot (Lident "ReactDOM", "someElement");
loc = Location.none;
})
[(Nolabel, children)] );
]
| ListLiteral {pexp_desc = Pexp_array list} when list = [] -> []
| ListLiteral expression ->
(* this is a hack to support react components that introspect into their children *)
Expand Down
2 changes: 1 addition & 1 deletion tests/ppx/react/expected/commentAtTop.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type props<'msg> = { // test React JSX file

@react.component
let make = ({msg, _}: props<'msg>) => {
ReactDOM.jsx("div", {children: {msg->React.string}})
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({msg->React.string})})
}
let make = {
let \"CommentAtTop" = (props: props<_>) => make(props)
Expand Down
2 changes: 1 addition & 1 deletion tests/ppx/react/expected/fileLevelConfig.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module V4A = {

@react.component
let make = ({msg, _}: props<'msg>) => {
ReactDOM.jsx("div", {children: {msg->React.string}})
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({msg->React.string})})
}
let make = {
let \"FileLevelConfig$V4A" = (props: props<_>) => make(props)
Expand Down
5 changes: 2 additions & 3 deletions tests/ppx/react/expected/forwardRef.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ module V4A = {
ReactDOM.jsx(
"div",
{
children: React.jsx(
FancyInput.make,
{ref: input, children: {React.string("Click to focus")}},
children: ?ReactDOM.someElement(
React.jsx(FancyInput.make, {ref: input, children: {React.string("Click to focus")}}),
),
},
)
Expand Down
20 changes: 20 additions & 0 deletions tests/ppx/react/expected/optimizeAutomaticMode.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@@jsxConfig({version: 4, mode: "automatic"})

module User = {
type t = {firstName: string, lastName: string}

let format = user => "Dr." ++ user.lastName
type props<'doctor> = {
doctor: 'doctor,
}

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

\"OptimizeAutomaticMode$User"
}
}
12 changes: 12 additions & 0 deletions tests/ppx/react/optimizeAutomaticMode.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@@jsxConfig({version: 4, mode: "automatic"})

module User = {
type t = {firstName: string, lastName: string}

let format = user => "Dr." ++ user.lastName

@react.component
let make = (~doctor) => {
<h1 id="h1"> {React.string(format(doctor))} </h1>
}
}