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

Print parentheses around identifier let where necessary #13269

Merged
merged 3 commits into from May 6, 2021

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented May 6, 2021

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

If we detect that the identifier let would be printed in a location that forbids it (either unconditionally or when followed by [), print parentheses around the identifier so that it remains legal and correct.

The forbidden locations are:

  • ExpressionStatement (let [)
  • ForStatement (let [)
  • ForInStatement (let [)
  • ForOfStatement (let) (regular and await)

@babel-bot
Copy link
Collaborator

babel-bot commented May 6, 2021

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 6, 2021

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 1aea906:

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

@nicolo-ribaudo nicolo-ribaudo added pkg: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels May 6, 2021
@Zalathar
Copy link
Contributor Author

Zalathar commented May 6, 2021

Ah, I just remembered that OptionalMemberExpression can also print a left bracket if { computed: true, optional: false }.

I don't think this can occur in head position in a freshly-parsed AST, but it can occur if a transform rearranges nodes and also sets node.optional = false.

Adding the appropriate check is easy enough, but I'll need to write a non-fixture test to get coverage.

@nicolo-ribaudo
Copy link
Member

Ideally we should add some validation to ensure that optional: false can only happen if it has a (deep) child with optional: true, but adding the generator check is a good idea.

@nicolo-ribaudo nicolo-ribaudo merged commit 68bc4df into babel:main May 6, 2021
@nicolo-ribaudo
Copy link
Member

Thanks!

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: generator 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]: Generator prints the identifier let in some forbidden places
5 participants