Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[babel 8] Disallow sequence expressions in JSX expression containers#12447

Merged
nicolo-ribaudo merged 4 commits into
babel:mainfrom
nicolo-ribaudo:breaking/disallow-sequence-expression-in-jsx
Dec 8, 2020
Merged

[babel 8] Disallow sequence expressions in JSX expression containers#12447
nicolo-ribaudo merged 4 commits into
babel:mainfrom
nicolo-ribaudo:breaking/disallow-sequence-expression-in-jsx

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo commented Dec 4, 2020

Q                       A
Fixed Issues? Fixes #8604
Patch: Bug Fix? Yes
Major: Breaking Change? Yes
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This is a "backport" of #8787 from next-8-dev to main. It's disabled by default, unless you run (if working in the monorepo) or build (if publishing) babel with BABEL_8_BREAKING=true.
This cannot be enabled by Babel consumers.


Original PR: #8787 (already reviewed)

Original PR description:

Following #8604, we should not allow codes like these

<div key={console.log('foo'), JSON.stringify(props)} />
<div>{console.log('foo'), JSON.stringify(props)}</div>

But we should allow codes like

<div key={(console.log('foo'), JSON.stringify(props))} />
<div>{(console.log('foo'), JSON.stringify(props))}</div>

This PR fixes it, raising an exception with this message: Sequence of values at JSX must be parenthesized.
But, since we currently allow the wrong code, this fix is a breaking change.

⚠️ The last commit (Throw a recoverable error) was not in the original PR.

* jsx: fix sequence expression at JSXAttributeValue

* Change logic for detecting unparenthesized expressions

* use parseMaybeAssign instead of custom error handling

Co-authored-by: Daniel Tschinder <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Dec 4, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a052169:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

Comment thread babel.config.js
// env vars from the cli are always strings, so !!ENV_VAR returns true for "false"
function bool(value) {
return value && value === "false" && value === "0";
return value && value !== "false" && value !== "0";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was a stupid error 😁

"true" -> true
"false" -> false
"0" -> false
"1" -> true
undefined -> undefined

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Dec 4, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/34069/

node.expression = this.parseExpression();
node.expression = process.env.BABEL_8_BREAKING
? this.parseMaybeAssign()
: this.parseExpression();
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung Dec 4, 2020

Choose a reason for hiding this comment

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

Consider throw recoverable error if node.expression is an unparenthesized SequenceExpression.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Could we do that as a follow up? 🙏
I'd like to keep the PR as similar as possible to the one I'm backporting from next-8-dev

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nah, I can do it here

Copy link
Copy Markdown
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Did you mean JSXChildren? JSXAttributes exist in open/close JSX element only.

@nicolo-ribaudo nicolo-ribaudo changed the title [babel 8] Disallow sequence expressions in JSX attributes [babel 8] Disallow sequence expressions in JSX expression containers Dec 4, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit b422c7f into babel:main Dec 8, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the breaking/disallow-sequence-expression-in-jsx branch December 8, 2020 09:15
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Mar 10, 2021
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 10, 2021
@nicolo-ribaudo nicolo-ribaudo added babel 8 PR: Spec Compliance (next major) 👓 A type of pull request used for our changelog categories for next major release and removed babel-8-dev → main babel 8 labels Aug 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Spec Compliance (next major) 👓 A type of pull request used for our changelog categories for next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comma expression (Sequence expression) incorrectly allowed as JSXAttributeValue

5 participants