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 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 🐛 pkg: parser i: regression area: jsx labels May 17, 2022
@nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented May 17, 2022

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
34 of 35 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the fix-14552 branch May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: jsx i: regression pkg: parser PR: Bug Fix 🐛
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants