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 printing parentheses around optional chains #11190

Merged
merged 1 commit into from Feb 28, 2020
Merged

Fix printing parentheses around optional chains #11190

merged 1 commit into from Feb 28, 2020

Conversation

sag1v
Copy link
Contributor

@sag1v sag1v commented Feb 28, 2020

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

Updated OptionalMemberExpression to compare the callee for callExpression or object for memberExpression against the node.
This should fix a case such as:

foo[bar?.baz];

That transforms to:

foo[(bar?.baz)];

Added a OptionalCallExpression as well with the same checks as OptionalMemberExpression.

Should solve cases of:

(foo?.())();
(foo?.()).baz;

@jridgewell jridgewell added PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Optional Chaining labels Feb 28, 2020
@jridgewell jridgewell changed the title resolve 11187 Fix printing parentheses around optional chains Feb 28, 2020
@existentialism
Copy link
Member

@sag1v nice work!

@JLHwung JLHwung merged commit a39beda into babel:master Feb 28, 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 May 30, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2020
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 Spec: Optional Chaining
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Forced calls of OptionalCalls do not print correctly
4 participants