Skip to content
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 parsing of < after object literals with the jsx plugin #14557

Merged
merged 2 commits into from May 17, 2022

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented May 16, 2022

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

When parsing ({}<x) with jsx plugin, Babel incorrectly marks <x as a jsxTagStart token. In token definitions we have }'s beforeExpr set to true, which then causes state.canStartJSXElement be true in the updateContext hook. In this PR we explicitly set state.canStartJSXElement to be true immediately before } is consumed as the boundary between JS expression and jsx elements. Now in the ({}<x), the < token after } can be correctly tokenized as tt.lt because it is parsed within normal JS routines.

@babel-bot
Copy link
Collaborator

babel-bot commented May 16, 2022

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

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser i: regression area: jsx labels May 17, 2022
@nicolo-ribaudo
Copy link
Member

Rebased on top of #14558

@nicolo-ribaudo nicolo-ribaudo changed the title fix: manipulate state.canStartJSXElement before eating braceR Fix parsing of < after object literals with the jsx plugin May 17, 2022
@nicolo-ribaudo nicolo-ribaudo merged commit 9156230 into babel:main May 17, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the fix-14552 branch May 17, 2022 14:02
@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 Aug 17, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: jsx i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Comparison with object literal fails to parse since 7.14.5
4 participants