Fix parens issues with exponentiation in generator (#5830)

This commit is contained in:
Brian Ng 2017-06-09 10:10:16 -05:00 committed by Henry Zhu
parent f1303aa54c
commit cce83a0cea
3 changed files with 27 additions and 1 deletions

View File

@ -47,6 +47,13 @@ export function DoExpression(node: Object, parent: Object, printStack: Array<Obj
}
export function Binary(node: Object, parent: Object): boolean {
if (
node.operator === "**" &&
t.isBinaryExpression(parent, { operator: "**" })
) {
return parent.left === node;
}
if (
((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) ||
t.isUnaryLike(parent) ||
@ -124,7 +131,8 @@ export function ClassExpression(node: Object, parent: Object, printStack: Array<
export function UnaryLike(node: Object, parent: Object): boolean {
return t.isMemberExpression(parent, { object: node }) ||
t.isCallExpression(parent, { callee: node }) ||
t.isNewExpression(parent, { callee: node });
t.isNewExpression(parent, { callee: node }) ||
t.isBinaryExpression(parent, { operator: "**", left: node });
}
export function FunctionExpression(node: Object, parent: Object, printStack: Array<Object>): boolean {

View File

@ -0,0 +1,9 @@
Math.sqrt(3**2 + (-5)**2);
a ** b ** c;
(a ** b) ** c;
a.b ** c;
(-a) ** b;
a ** -b;
-(a**b);
(a * b) ** c;
a ** (b * c);

View File

@ -0,0 +1,9 @@
Math.sqrt(3 ** 2 + (-5) ** 2);
a ** b ** c;
(a ** b) ** c;
a.b ** c;
(-a) ** b;
a ** -b;
-(a ** b);
(a * b) ** c;
a ** (b * c);