Fix spacing in binary expression when right is a binary expression and has a unary on the left
This commit is contained in:
parent
2f5b953066
commit
54a2a47030
@ -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,5 @@
|
||||
1 && 1;
|
||||
1 + +1;
|
||||
x + ++y;
|
||||
(a+(+b)*2);
|
||||
a + + b * 2 * 2 * 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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user