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

Commit 51e4e16

Browse files
authored
Fix parsing not atomic expression in spread props of JSX (#721)
1 parent 2a017ca commit 51e4e16

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- Fix issue where async as an id cannot be used with application and labelled arguments https://github.com/rescript-lang/syntax/issues/707
5353
- 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
5454
- Fix build error where aliasing arguments to `_` in the make function with JSX V4. https://github.com/rescript-lang/syntax/pull/720
55+
- Fix parsing of spread props as an expression in JSX V4 https://github.com/rescript-lang/syntax/pull/721
5556

5657
#### :eyeglasses: Spec Compliance
5758

src/res_core.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,7 @@ and parseJsxProp p =
26302630
(Location.mkloc "ns.namedArgLoc" loc, Parsetree.PStr [])
26312631
in
26322632
let attrExpr =
2633-
let e = parsePrimaryExpr ~operand:(parseAtomicExpr p) p in
2633+
let e = parsePrimaryExpr ~operand:(parseExpr p) p in
26342634
{e with pexp_attributes = propLocAttr :: e.pexp_attributes}
26352635
in
26362636
(* using label "spreadProps" to distinguish from others *)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ let c4 = ReactDOM.createDOMElementVariadic(
2121
[ReactDOM.createDOMElementVariadic("br", []), ReactDOM.createDOMElementVariadic("br", [])],
2222
)
2323

24+
let c5 = ReactDOM.createDOMElementVariadic(
25+
"div",
26+
~props={...p, key: "k"},
27+
[ReactDOM.createDOMElementVariadic("br", []), ReactDOM.createDOMElementVariadic("br", [])],
28+
)
29+
30+
// both need to be parsed
31+
let c6 = React.createElement(A.make, params->Obj.magic)
32+
let c7 = React.createElement(A.make, params->Obj.magic)
33+
2434
@@jsxConfig({version: 4, mode: "automatic"})
2535
// Error: spreadProps should be first in order than other props
2636
// let c0 = <A x="x" {...p} />
@@ -44,3 +54,7 @@ let c5 = ReactDOM.jsxsKeyed(
4454
~key="k",
4555
(),
4656
)
57+
58+
// both need to be parsed
59+
let c6 = React.jsx(A.make, params->Obj.magic)
60+
let c7 = React.jsx(A.make, params->Obj.magic)

tests/ppx/react/spreadProps.res

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ let c4 = <div {...p} x="x" key="k" />
1717

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

20+
let c5 = <div {...p} key="k"><br /><br /></div>
21+
22+
// both need to be parsed
23+
let c6 = <A {...(params->Obj.magic)} />
24+
let c7 = <A {...params->Obj.magic} />
25+
2026
@@jsxConfig({version:4, mode: "automatic"})
2127
// Error: spreadProps should be first in order than other props
2228
// let c0 = <A x="x" {...p} />
@@ -34,4 +40,8 @@ let c3 = <div {...p} />
3440

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

37-
let c5 = <div {...p} key="k"><br /><br /></div>
43+
let c5 = <div {...p} key="k"><br /><br /></div>
44+
45+
// both need to be parsed
46+
let c6 = <A {...(params->Obj.magic)} />
47+
let c7 = <A {...params->Obj.magic} />

0 commit comments

Comments
 (0)