Fix spacing in binary expression when right is a binary expression and has a unary on the left

This commit is contained in:
Amjad Masad 2015-12-01 10:37:58 -08:00
parent 2f5b953066
commit 54a2a47030
3 changed files with 13 additions and 2 deletions

View File

@ -172,7 +172,9 @@ export function AssignmentExpression(node: Object, parent: Object) {
t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" }) ||
// Need spaces for operators of the same kind to avoid: `a+++b`
t.isUnaryExpression(node.right, { prefix: true, operator: node.operator }) ||
t.isUpdateExpression(node.right, { prefix: true, operator: node.operator + node.operator });
t.isUpdateExpression(node.right, { prefix: true, operator: node.operator + node.operator }) ||
(t.isBinaryExpression(node.right) &&
t.isUnaryExpression(getLeftMost(node.right), { prefix: true, operator: node.operator }));
}
@ -230,3 +232,10 @@ export function MetaProperty(node: Object) {
this.push(".");
this.print(node.property, node);
}
function getLeftMost(binaryExpr) {
if (!t.isBinaryExpression(binaryExpr)) {
return binaryExpr;
}
return getLeftMost(binaryExpr.left);
}

View File

@ -2,3 +2,5 @@
1 && 1;
1 + +1;
x + ++y;
(a+(+b)*2);
a + + b * 2 * 2 * 2;

View File

@ -1 +1 @@
1*1;1&&1;1+ +1;x+ ++y;
1*1;1&&1;1+ +1;x+ ++y;a+ +b*2;a+ +b*2*2*2;