Merge pull request #3245 from babel/assig-parenth

Revert #3217 and add tests
This commit is contained in:
Amjad Masad 2016-01-06 18:24:38 -06:00
commit c415c00179
5 changed files with 10 additions and 6 deletions

View File

@ -155,10 +155,8 @@ export function AssignmentPattern(node: Object) {
export function AssignmentExpression(node: Object, parent: Object) {
// Somewhere inside a for statement `init` node but doesn't usually
// needs a paren except for `in` expressions: `for (a in b ? a : b;;)`
// and for `ObjectPattern`: `({ f } = { f: 2 };`
let parens = this._inForStatementInit && node.operator === "in" &&
!n.needsParens(node, parent) ||
t.isObjectPattern(node.left);
!n.needsParens(node, parent);
if (parens) {
this.push("(");

View File

@ -66,7 +66,7 @@ export function Binary(node: Object, parent: Object): boolean {
return true;
}
if (t.isBinary(parent) && !t.isAssignmentExpression(parent)) {
if (t.isBinary(parent)) {
let parentOp = parent.operator;
let parentPos = PRECEDENCE[parentOp];
@ -216,7 +216,7 @@ export function ConditionalExpression(node: Object, parent: Object): boolean {
return true;
}
if (t.isBinary(parent) && !t.isAssignmentExpression(parent)) {
if (t.isBinary(parent)) {
return true;
}

View File

@ -0,0 +1,3 @@
1 + (a = 2);
1 + (a += 2);
a = a || (a = {});

View File

@ -0,0 +1,3 @@
1 + (a = 2);
1 + (a += 2);
a = a || (a = {});

View File

@ -42,7 +42,7 @@ defineType("AssignmentExpression", {
},
builder: ["operator", "left", "right"],
visitor: ["left", "right"],
aliases: ["Binary", "Expression"]
aliases: ["Expression"]
});
defineType("BinaryExpression", {