Skip to content
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

Fix parsing not atomic expression in spread props of JSX #5885

Merged
merged 4 commits into from
Dec 8, 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 @@ -63,6 +63,7 @@ These are only breaking changes for unformatted code.

- Prevent inlining of async functions in additional cases https://github.com/rescript-lang/rescript-compiler/issues/5860
- Fix build error where aliasing arguments to `_` in the make function with JSX V4. https://github.com/rescript-lang/rescript-compiler/pull/5881
- Fix parsing of spread props as an expression in JSX V4 https://github.com/rescript-lang/rescript-compiler/pull/5885

# 10.1.0

Expand Down
2 changes: 1 addition & 1 deletion res_syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2724,7 +2724,7 @@ and parseJsxProp p =
(Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr [])
in
let attrExpr =
let e = parsePrimaryExpr ~operand:(parseAtomicExpr p) p in
let e = parsePrimaryExpr ~operand:(parseExpr p) p in
{e with pexp_attributes = propLocAttr :: e.pexp_attributes}
in
(* using label "spreadProps" to distinguish from others *)
Expand Down
14 changes: 14 additions & 0 deletions res_syntax/tests/ppx/react/expected/spreadProps.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ let c4 = ReactDOM.createDOMElementVariadic(
[ReactDOM.createDOMElementVariadic("br", []), ReactDOM.createDOMElementVariadic("br", [])],
)

let c5 = ReactDOM.createDOMElementVariadic(
"div",
~props={...p, key: "k"},
[ReactDOM.createDOMElementVariadic("br", []), ReactDOM.createDOMElementVariadic("br", [])],
)

// both need to be parsed
let c6 = React.createElement(A.make, params->Obj.magic)
let c7 = React.createElement(A.make, params->Obj.magic)

@@jsxConfig({version: 4, mode: "automatic"})
// Error: spreadProps should be first in order than other props
// let c0 = <A x="x" {...p} />
Expand All @@ -44,3 +54,7 @@ let c5 = ReactDOM.jsxsKeyed(
~key="k",
(),
)

// both need to be parsed
let c6 = React.jsx(A.make, params->Obj.magic)
let c7 = React.jsx(A.make, params->Obj.magic)
12 changes: 11 additions & 1 deletion res_syntax/tests/ppx/react/spreadProps.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ let c4 = <div {...p} x="x" key="k" />

let c4 = <div {...p} key="k"><br /><br /></div>

let c5 = <div {...p} key="k"><br /><br /></div>

// both need to be parsed
let c6 = <A {...(params->Obj.magic)} />
let c7 = <A {...params->Obj.magic} />

@@jsxConfig({version:4, mode: "automatic"})
// Error: spreadProps should be first in order than other props
// let c0 = <A x="x" {...p} />
Expand All @@ -34,4 +40,8 @@ let c3 = <div {...p} />

let c4 = <div {...p} x="x" key="k" />

let c5 = <div {...p} key="k"><br /><br /></div>
let c5 = <div {...p} key="k"><br /><br /></div>

// both need to be parsed
let c6 = <A {...(params->Obj.magic)} />
let c7 = <A {...params->Obj.magic} />