-
Notifications
You must be signed in to change notification settings - Fork 471
Remove support of children spread inside JSX #7869
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: tsnobip <[email protected]>
d7ba92c
to
4b8a0c5
Compare
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
Looks good at a glance. Can we add a test to check which parsing error we now get for |
compiler/ml/parsetree.ml
Outdated
and jsx_children = | ||
| JSXChildrenSpreading of expression | ||
| JSXChildrenItems of expression list | ||
and jsx_children = JSXChildrenItems of expression list |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
@nojaf that's a good point, unfortunately the error is indeed quite cryptic!
|
compiler/syntax/src/res_core.ml
Outdated
Parsetree.JSXChildrenItems children | ||
in | ||
children | ||
List.rev (loop p []) |
There was a problem hiding this comment.
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.
|
||
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. | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
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:
What still works
Props spread continues to work as before:
Normal JSX children also continue to work:
Implementation details
The changes remove the
JSXChildrenSpreading
variant from thejsx_children
type and update all related code:parse_jsx_children
to no longer recognize...
syntax in children contextJSXChildrenSpreading of expression
fromjsx_children
typeThe implementation is minimal and surgical - only the children spread functionality is removed while all other JSX features remain unchanged.
Files changed
parsetree.ml
res_core.ml
and printer inres_printer.ml
compiler/ml/
compiler/syntax/src/
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.