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:
commit
27252b2039
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user