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

Commit

Permalink
Fix parsing not atomic expression in spread props of JSX (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
mununki authored Dec 7, 2022
1 parent 2a017ca commit 51e4e16
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- Fix issue where async as an id cannot be used with application and labelled arguments https://github.com/rescript-lang/syntax/issues/707
- Treat await as almost-unary operator weaker than pipe so `await foo->bar` means `await (foo->bar)` https://github.com/rescript-lang/syntax/pull/711
- Fix build error where aliasing arguments to `_` in the make function with JSX V4. https://github.com/rescript-lang/syntax/pull/720
- Fix parsing of spread props as an expression in JSX V4 https://github.com/rescript-lang/syntax/pull/721

#### :eyeglasses: Spec Compliance

Expand Down
2 changes: 1 addition & 1 deletion src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2630,7 +2630,7 @@ and parseJsxProp p =
(Location.mkloc "ns.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 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 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} />

0 comments on commit 51e4e16

Please sign in to comment.