-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix react-jsx spread children invalid emit #46565
Conversation
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
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.
Seems reasonable, but just out of curiosity, why do we even allow this? I tried this in the Babel playground and they just error with
Spread children are not supported in React.
🤷
I specifically mean since the JSX emit mode has “react” in its name—should we also be emitting a grammar error in that mode? |
The If those options are unset/set to |
Not a priority right now since this syntax has been allowed but broken for some time, but maybe something we should think about next cycle. |
@sandersn or @weswigham can one of you double check this real quick, whoever gets here first? Hit merge if it looks good to you. Thanks! |
src/compiler/transformers/jsx.ts
Outdated
tagName, | ||
objectProperties, | ||
keyAttr, | ||
(nonWhitespaceChildren[0] as JsxExpression)?.dotDotDotToken ? 2 : length(nonWhitespaceChildren), |
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.
sigh if we're gunna manipulate the number like this, we should change the parameter to a isStaticChildren
boolean flag instead. Don't want someone revisiting this in the future and question why it's sometimes not actually the length of the children.
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.
💯
7dcfc96
to
6f38b96
Compare
* Fix react-jsx spread children invalid emit * Update Baselines and/or Applied Lint Fixes * Change childrenLength parameter -> isStaticChildren Co-authored-by: TypeScript Bot <[email protected]>
Since #45693 react-jsx transforms:
<div>{...a}{...b}</div>
->vs.
but a single spread child
<div>{...a}</div>
->The classic react transform isn't affected (handles a single spread child), FYI:
<div>{...a}</div>
->This PR fixes the react-jsx transform in case of a single spread child:
<div>{...a}</div>
->