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

Handle exprAllowed before ObjectLike is parsed #12267

Merged
merged 2 commits into from Oct 28, 2020
Merged

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Oct 27, 2020

Q                       A
Fixed Issues? Fixes #11353
Patch: Bug Fix? Y
Tests Added + Pass? Yes
License MIT

This PR includes 2 commits. The first commits fixes #11353 by correctly handling exprAllowed.

Currently we use braceIsBlock to determine whether { starts an object literal or a blocked statement. However, this approach can not differentiate 0 ? a : {} to a : {} because we do not track ternary in token context. Thus we incorrectly classify {} as a statement block here.

This PR fixes it on the parser level. It is not ideal but I think it is difficult to track it in tokenizing level performantly.

The second commit is to avoid accessing this.prodParam in token context update, because of the timing issues.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser labels Oct 27, 2020
@babel-bot
Copy link
Collaborator

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

@codesandbox-ci
Copy link

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 811ac29:

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

Copy link
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

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

👍

@JLHwung JLHwung merged commit a8c66f4 into babel:main Oct 28, 2020
@JLHwung JLHwung deleted the fix-11353 branch October 28, 2020 00:25
sosukesuzuki added a commit to prettier/prettier that referenced this pull request Nov 6, 2020
@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 Jan 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2021
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: 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.

Fails to parse object division in ternary alternate: weird ? true : {}/2
4 participants