Skip to content

Commit d715bfd

Browse files
authored
Fix parsing not atomic expression in spread props of JSX (#5885)
1 parent 0f8a590 commit d715bfd

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ These are only breaking changes for unformatted code.
6363

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

6768
# 10.1.0
6869

res_syntax/src/res_core.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2724,7 +2724,7 @@ and parseJsxProp p =
27242724
(Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr [])
27252725
in
27262726
let attrExpr =
2727-
let e = parsePrimaryExpr ~operand:(parseAtomicExpr p) p in
2727+
let e = parsePrimaryExpr ~operand:(parseExpr p) p in
27282728
{e with pexp_attributes = propLocAttr :: e.pexp_attributes}
27292729
in
27302730
(* using label "spreadProps" to distinguish from others *)

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

+14
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)

res_syntax/tests/ppx/react/spreadProps.res

+11-1
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)