[T7047]Consider arrow functions when parenthesizing object expressions

This commit is contained in:
Amjad Masad
2016-02-02 16:26:31 -08:00
parent 82bab2847b
commit 3d3b30eb45
4 changed files with 8 additions and 12 deletions

View File

@@ -50,7 +50,7 @@ export function ObjectExpression(node: Object, parent: Object, printStack: Array
return true;
}
return isFirstInStatement(printStack);
return isFirstInStatement(printStack, true);
}
export function Binary(node: Object, parent: Object): boolean {
@@ -233,7 +233,7 @@ export function AssignmentExpression(node: Object): boolean {
// Walk up the print stack to deterimine if our node can come first
// in statement.
function isFirstInStatement(printStack: Array<Object>): boolean {
function isFirstInStatement(printStack: Array<Object>, considerArrow: bool = false): boolean {
let i = printStack.length - 1;
let node = printStack[i];
i--;
@@ -243,6 +243,10 @@ function isFirstInStatement(printStack: Array<Object>): boolean {
return true;
}
if (considerArrow && t.isArrowFunctionExpression(parent, { body: node })) {
return true;
}
if ((t.isCallExpression(parent, { callee: node })) ||
(t.isSequenceExpression(parent) && parent.expressions[0] === node) ||
(t.isMemberExpression(parent, { object: node })) ||