Skip to content

Commit

Permalink
Fix some missing parens cases with OptionalMemberExpression in genera…
Browse files Browse the repository at this point in the history
…tor (#8751)
  • Loading branch information
existentialism committed Sep 23, 2018
1 parent 3b0f9a9 commit 9f407e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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.isCallExpression(parent) || t.isMemberExpression(parent);
}

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

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

0 comments on commit 9f407e0

Please sign in to comment.