-
Notifications
You must be signed in to change notification settings - Fork 469
Fix issue with JSX V4 when components are nested #6031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,8 @@ let getMapper ~config = | |
| Pstr_attribute attr -> processConfigAttribute attr config | ||
| _ -> ()); | ||
let item = default_mapper.structure_item mapper item in | ||
if config.version = 3 then transformStructureItem3 mapper item | ||
else if config.version = 4 then transformStructureItem4 mapper item | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was applying the JSX transformation recursively again, to some parts of the structure item. |
||
if config.version = 3 then transformStructureItem3 item | ||
else if config.version = 4 then transformStructureItem4 item | ||
else [item]) | ||
items | ||
|> List.flatten | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -446,8 +446,7 @@ let jsxMapper ~config = | |
args | ||
in | ||
|
||
let rec recursivelyTransformNamedArgsForMake mapper expr args newtypes = | ||
let expr = mapper.expr mapper expr in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would apply the entire JSX transform again, to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why I didn't realize it didn't need this. |
||
let rec recursivelyTransformNamedArgsForMake expr args newtypes = | ||
match expr.pexp_desc with | ||
(* TODO: make this show up with a loc. *) | ||
| Pexp_fun (Labelled "key", _, _, _) | Pexp_fun (Optional "key", _, _, _) -> | ||
|
@@ -494,7 +493,7 @@ let jsxMapper ~config = | |
| _ -> None | ||
in | ||
|
||
recursivelyTransformNamedArgsForMake mapper expression | ||
recursivelyTransformNamedArgsForMake expression | ||
((arg, default, pattern, alias, pattern.ppat_loc, type_) :: args) | ||
newtypes | ||
| Pexp_fun | ||
|
@@ -517,10 +516,9 @@ let jsxMapper ~config = | |
"React: react.component refs only support plain arguments and type \ | ||
annotations." | ||
| Pexp_newtype (label, expression) -> | ||
recursivelyTransformNamedArgsForMake mapper expression args | ||
(label :: newtypes) | ||
recursivelyTransformNamedArgsForMake expression args (label :: newtypes) | ||
| Pexp_constraint (expression, _typ) -> | ||
recursivelyTransformNamedArgsForMake mapper expression args newtypes | ||
recursivelyTransformNamedArgsForMake expression args newtypes | ||
| _ -> (args, newtypes, None) | ||
in | ||
|
||
|
@@ -586,7 +584,7 @@ let jsxMapper ~config = | |
in | ||
|
||
let nestedModules = ref [] in | ||
let transformStructureItem mapper item = | ||
let transformStructureItem item = | ||
match item with | ||
(* external *) | ||
| { | ||
|
@@ -825,7 +823,7 @@ let jsxMapper ~config = | |
let props = getPropsAttr payload in | ||
(* do stuff here! *) | ||
let namedArgList, newtypes, forwardRef = | ||
recursivelyTransformNamedArgsForMake mapper | ||
recursivelyTransformNamedArgsForMake | ||
(modifiedBindingOld binding) | ||
[] [] | ||
in | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Outer = { | ||
type props = {} | ||
let make = (_: props) => { | ||
module Inner = { | ||
type props = {} | ||
|
||
let make = (_: props) => ReactDOM.jsx("div", {}) | ||
let make = { | ||
let \"Nested$Outer" = props => make(props) | ||
|
||
\"Nested$Outer" | ||
} | ||
} | ||
|
||
React.jsx(Inner.make, {}) | ||
} | ||
let make = { | ||
let \"Nested$Outer" = props => make(props) | ||
\"Nested$Outer" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies the JSX transformation recursively to the structure item.