When emitting an arrow function, parenthesize the body if it could be interpreted as a block instead of an object literal.

This commit is contained in:
Cyrus Najmabadi
2015-03-07 01:30:45 -08:00
parent 241cee0879
commit c76f71cfae
13 changed files with 72 additions and 2 deletions

View File

@@ -4202,9 +4202,19 @@ module ts {
return;
}
// For es6 and higher we can emit the expression as is.
// For es6 and higher we can emit the expression as is. However, in the case
// where the expression might end up looking like a block when down-leveled, we'll
// also wrap it in parentheses first. For example if you have: a => <foo>{}
// then we need to generate: a => ({})
write(" ");
emit(body);
// Unwrap all type assertions.
var current = body;
while (current.kind === SyntaxKind.TypeAssertionExpression) {
current = (<TypeAssertion>current).expression;
}
emitParenthesizedIf(body, current.kind === SyntaxKind.ObjectLiteralExpression);
}
function emitDownLevelExpressionFunctionBody(node: FunctionLikeDeclaration, body: Expression) {