Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 10, 2025

This PR removes support for JSX children spread syntax while preserving props spread functionality.

What was removed

Children spread syntax like this is no longer supported:

<div> ...children </div>
<Component> ...rest </Component>
<> ...items </>

What still works

Props spread continues to work as before:

<Button {...buttonProps} />
<div className="wrapper" {...divProps} />
<MyComponent id="test" {...rest} onClick={handler} />

Normal JSX children also continue to work:

<div> {text} {otherElement} </div>
<Container> <span>child</span> </Container>

Implementation details

The changes remove the JSXChildrenSpreading variant from the jsx_children type and update all related code:

  • Parser: Updated parse_jsx_children to no longer recognize ... syntax in children context
  • Type system: Removed JSXChildrenSpreading of expression from jsx_children type
  • Processing: Updated all AST mappers, iterators, printers, and analysis tools
  • Tests: Removed children spread examples from test files

The implementation is minimal and surgical - only the children spread functionality is removed while all other JSX features remain unchanged.

Files changed

  • Core type definition in parsetree.ml
  • Parser logic in res_core.ml and printer in res_printer.ml
  • AST processing across 8 files in compiler/ml/
  • Syntax processing in 3 files in compiler/syntax/src/
  • Frontend and analysis support files
  • Test cases updated to remove children spread examples

This change makes the JSX syntax more consistent by having spread syntax only available in props context.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] remove the support of children spread inside JSX Remove support for children spread inside JSX Sep 10, 2025
@Copilot Copilot AI requested a review from tsnobip September 10, 2025 12:38
Copilot finished work on behalf of tsnobip September 10, 2025 12:38
@tsnobip tsnobip force-pushed the copilot/fix-9d6739a1-3b68-4f3e-95ca-e12077bb6fdc branch from d7ba92c to 4b8a0c5 Compare September 10, 2025 12:52
@tsnobip tsnobip changed the title Remove support for children spread inside JSX Remove support of children spread inside JSX Sep 10, 2025
Copy link

pkg-pr-new bot commented Sep 10, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7869

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7869

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7869

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7869

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7869

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7869

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7869

commit: 605b78d

@tsnobip tsnobip requested review from zth and nojaf September 10, 2025 13:34
@tsnobip tsnobip marked this pull request as ready for review September 10, 2025 13:34
@nojaf
Copy link
Member

nojaf commented Sep 10, 2025

Looks good at a glance. Can we add a test to check which parsing error we now get for ...? If that’s too cryptic, I’d raise a custom parser error that clearly states child spreading was removed.

and jsx_children =
| JSXChildrenSpreading of expression
| JSXChildrenItems of expression list
and jsx_children = JSXChildrenItems of expression list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed now as well, right? Should probably do that in the same PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

@tsnobip
Copy link
Member

tsnobip commented Sep 10, 2025

Looks good at a glance. Can we add a test to check which parsing error we now get for ...? If that’s too cryptic, I’d raise a custom parser error that clearly states child spreading was removed.

@nojaf that's a good point, unfortunately the error is indeed quite cryptic!

  Syntax error!
  syntax_tests/data/parsing/errors/expressions/jsx.res:18:15-17

  16 │ 
  17 │ // spread children
  18 │ let x = <div> ...c </div>

  Did you forget a `</` here?


  Syntax error!
  syntax_tests/data/parsing/errors/expressions/jsx.res:18:15-17

  16 │ 
  17 │ // spread children
  18 │ let x = <div> ...c </div>

  I'm not sure what to parse here when looking at "...".


  Syntax error!
  syntax_tests/data/parsing/errors/expressions/jsx.res:18:22-25

  16 │ 
  17 │ // spread children
  18 │ let x = <div> ...c </div>

  unterminated regex

Parsetree.JSXChildrenItems children
in
children
List.rev (loop p [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsnobip inside the loop you probably want to match ... and give a better parse error.

Comment on lines +120 to +129

Syntax error!
syntax_tests/data/parsing/errors/expressions/jsx.res:18:15-17

16 │
17 │ // spread children
18 │ let x = <div> ...c </div>

Spreading JSX children is no longer supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nojaf is it better like that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, does wrapping it {...c} do anything?
Syntax-wise probably that is going to be valid.
Would surprise me if that type-checks though.

@tsnobip tsnobip requested review from nojaf and zth September 10, 2025 14:36
Copy link
Member

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants