Merge pull request #3158 from babel/paren-object

Parenthesize object expression when it may end up at the start of an expression
This commit is contained in:
Amjad Masad 2015-12-12 20:43:46 -08:00
commit 4e82edb6d0
3 changed files with 11 additions and 0 deletions

View File

@ -55,6 +55,13 @@ export function ObjectExpression(node: Object, parent: Object): boolean {
return true;
}
if ((t.isBinaryExpression(parent) || t.isLogicalExpression(parent)) && parent.left === node) {
// We'd need to check that the parent's parent is an ExpressionStatement. But this
// code doesn't make any sense to begin with and should be rare.
// `({}) === foo`
return true;
}
return false;
}

View File

@ -0,0 +1,2 @@
({}) === foo;
({}) && foo;

View File

@ -0,0 +1,2 @@
({}) === foo;
({}) && foo;