Fix some missing parens cases with OptionalMemberExpression in generator (#8751)

This commit is contained in:
Brian Ng
2018-09-23 10:54:13 -05:00
committed by GitHub
parent 3b0f9a9f1e
commit 9f407e0735
3 changed files with 16 additions and 1 deletions

View File

@@ -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)
@@ -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;

View File

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

View File

@@ -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)();