Use the leftMost from the right to check if we need spaces in BinaryExpressions
This commit is contained in:
parent
7b25b33ac6
commit
007ef5cdbb
@ -174,13 +174,14 @@ export function AssignmentExpression(node: Object, parent: Object) {
|
|||||||
// http://javascript.spec.whatwg.org/#comment-syntax
|
// http://javascript.spec.whatwg.org/#comment-syntax
|
||||||
spaces = node.operator === "<" &&
|
spaces = node.operator === "<" &&
|
||||||
t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) &&
|
t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) &&
|
||||||
t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" }) ||
|
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.isBinaryExpression(node.right) &&
|
|
||||||
t.isUnaryExpression(getLeftMost(node.right), { prefix: true, operator: node.operator }));
|
|
||||||
|
|
||||||
|
// Need spaces for operators of the same kind to avoid: `a+++b`
|
||||||
|
if (!spaces) {
|
||||||
|
let right = getLeftMost(node.right);
|
||||||
|
spaces = t.isUnaryExpression(right, { prefix: true, operator: node.operator }) ||
|
||||||
|
t.isUpdateExpression(right, { prefix: true, operator: node.operator + node.operator });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spaces) this.push(" ");
|
if (spaces) this.push(" ");
|
||||||
|
|||||||
@ -7,4 +7,6 @@ a + +b * 2 * 2 * 2;
|
|||||||
a - -b;
|
a - -b;
|
||||||
1 + -b;
|
1 + -b;
|
||||||
1 - --b;
|
1 - --b;
|
||||||
a - -b * 2
|
a - -b * 2;
|
||||||
|
1 - (--t) * t;
|
||||||
|
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
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;
|
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;1- --t*t;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user