Ensure arrow function bodies are wrapped in parens if needed.

Closes #1214.
This commit is contained in:
Brian Donovan 2015-04-09 11:50:52 -07:00
parent 77c72bb5a6
commit 80f109efeb
3 changed files with 19 additions and 0 deletions

View File

@ -75,5 +75,16 @@ export function ArrowFunctionExpression(node, print) {
}
this.push(" => ");
const bodyNeedsParens = t.isObjectExpression(node.body);
if (bodyNeedsParens) {
this.push("(");
}
print(node.body);
if (bodyNeedsParens) {
this.push(")");
}
}

View File

@ -0,0 +1,4 @@
var foo = arr.map(v => ({
x: v.bar,
y: v.bar*2
}));

View File

@ -0,0 +1,4 @@
var foo = arr.map(v => ({
x: v.bar,
y: v.bar * 2
}));