mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user