Merge pull request #3121 from amasad/fix-T6736

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:50:06 -08:00
commit 27252b2039
3 changed files with 17 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,9 @@
1 && 1;
1 + +1;
x + ++y;
(a+(+b)*2);
a + +b * 2 * 2 * 2;
a - -b;
1 + -b;
1 - --b;
a - -b * 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;a- -b;1+-b;1- --b;a- -b*2;