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

Skip to content

jsx: fix sequence expression at JSXAttributeValue#8787

Merged
nicolo-ribaudo merged 3 commits intobabel:next-8-devfrom
macabeus:fix/jsx-comma-expression
Feb 4, 2020
Merged

jsx: fix sequence expression at JSXAttributeValue#8787
nicolo-ribaudo merged 3 commits intobabel:next-8-devfrom
macabeus:fix/jsx-comma-expression

Conversation

@macabeus
Copy link
Contributor

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.

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

@babel-bot
Copy link
Collaborator

babel-bot commented Sep 30, 2018

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

@nicolo-ribaudo
Copy link
Member

Instead of parsing an Expression and then throw if it is a SequenceExpression, we can parse an AssignmentExpression since the beginning.

@macabeus
Copy link
Contributor Author

macabeus commented Oct 1, 2018

@nicolo-ribaudo Where is the AssignmentExpression at JSX plugin, to add this logic? I tried to find it, but I can't.

@nicolo-ribaudo
Copy link
Member

You can use this.parseMaybeAssign (defined it src/parser/expression.js) instead of this.parseExpression at line 329.

@macabeus macabeus force-pushed the fix/jsx-comma-expression branch from f36c6ee to 80478f8 Compare October 2, 2018 02:11
@macabeus
Copy link
Contributor Author

macabeus commented Oct 2, 2018

@nicolo-ribaudo I updated the code 😄

Copy link
Member

@danez danez left a comment

Choose a reason for hiding this comment

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

Thanks for the fix.

@danez danez added area: jsx pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories awaiting reply labels Nov 6, 2018
@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Nov 18, 2018

Since in a past meeting we had concerns that this PR could break someone's code, here is a summary of what other parsers do when parsing <div>{console.log('foo'), JSON.stringify(props)}</div>:

Parser Parsed? Error
Acorn (same as Babylon) ✔️
TypeScript '}' expected.
Flow ✔️
Espree - ESLint (Uses acorn) ✔️
Esprima Unexpected token ,

Bonus: Pretter prints it as <div>{(console.log('foo'), JSON.stringify(props))}</div>

@xtuc xtuc mentioned this pull request Nov 19, 2018
6 tasks
@xtuc
Copy link
Member

xtuc commented Nov 19, 2018

We discussed about flag, breaking change, warning etc during our Babel meeting. We'll follow back.

@macabeus
Copy link
Contributor Author

Sorry for not being at the meeting. I'm very busy at last days 😞

@xtuc What were the outputs of the meeting?

@nicolo-ribaudo
Copy link
Member

For now we are not merging this PR since, as shown in #8787 (comment), many tools allow sequence expression and thus some people may rely on it.
We will merge this in Babel 8, and in the meantime we will investigate about an opt-in flag to enable warnings about "things that will break in the next major release".

@nicolo-ribaudo nicolo-ribaudo added the PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release label Nov 24, 2018
@nicolo-ribaudo nicolo-ribaudo added this to the Babel 8.x milestone Nov 24, 2018
@nicolo-ribaudo nicolo-ribaudo mentioned this pull request Nov 21, 2019
34 tasks
@nicolo-ribaudo nicolo-ribaudo changed the base branch from master to next-8-dev February 4, 2020 00:33
@nicolo-ribaudo nicolo-ribaudo added the PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release label Feb 4, 2020
@nicolo-ribaudo
Copy link
Member

I'm merging this to the next-8-dev branch. It will take some time before it's released!

@nicolo-ribaudo nicolo-ribaudo merged commit 2c0d7b6 into babel:next-8-dev Feb 4, 2020
nicolo-ribaudo pushed a commit that referenced this pull request Feb 4, 2020
* 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]>
@macabeus macabeus deleted the fix/jsx-comma-expression branch February 5, 2020 01:57
nicolo-ribaudo pushed a commit that referenced this pull request Feb 6, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Feb 6, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Feb 9, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Feb 13, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Feb 20, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Feb 23, 2020
* 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]>
JLHwung pushed a commit to JLHwung/babel that referenced this pull request Feb 27, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Feb 27, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Mar 3, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Mar 10, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Mar 11, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Mar 13, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Mar 22, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Apr 11, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Apr 20, 2020
* 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]>
arku pushed a commit to arku/babel that referenced this pull request Apr 20, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Apr 21, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Apr 21, 2020
* 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]>
nicolo-ribaudo pushed a commit that referenced this pull request Apr 22, 2020
* 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]>
@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 May 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2020
@nicolo-ribaudo nicolo-ribaudo removed this from the Babel 8.0 milestone Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: jsx outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comma expression (Sequence expression) incorrectly allowed as JSXAttributeValue

5 participants