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 some missing parens cases with OptionalMemberExpression in generator #8751

Merged
merged 2 commits into from Sep 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/babel-generator/src/node/parentheses.js
Expand Up @@ -209,6 +209,7 @@ export function ConditionalExpression(node: Object, parent: Object): boolean {
t.isBinary(parent) ||
t.isConditionalExpression(parent, { test: node }) ||
t.isAwaitExpression(parent) ||
t.isOptionalMemberExpression(parent) ||
t.isTaggedTemplateExpression(parent) ||
t.isTSTypeAssertion(parent) ||
t.isTSAsExpression(parent)
Expand All @@ -219,6 +220,13 @@ export function ConditionalExpression(node: Object, parent: Object): boolean {
return UnaryLike(node, parent);
}

export function OptionalMemberExpression(
node: Object,
parent: Object,
): boolean {
return t.isMemberExpression(parent);
Copy link
Member

Choose a reason for hiding this comment

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

Aren't parentheses also needed when the parent is a CallExpression? ((a?.b)())

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated!

}

export function AssignmentExpression(node: Object): boolean {
if (t.isObjectPattern(node.left)) {
return true;
Expand Down
Expand Up @@ -14,3 +14,6 @@ foo?.["bar"]?.foo;
0.?.toString();
0.5?.toString();
1.000?.toString();

(a?.b).c;
(a ? b : c)?.d;
Expand Up @@ -11,4 +11,6 @@ foo?.["bar"].foo;
foo?.["bar"]?.foo;
0.?.toString();
0.5?.toString();
1.000?.toString();
1.000?.toString();
(a?.b).c;
(a ? b : c)?.d;