Parenthesize object expression when it could end up at the start of an expression T6811

This commit is contained in:
Amjad Masad 2015-12-11 18:04:16 -08:00
parent 740604f268
commit 07df8515b9
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;