mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-24 20:44:53 -05:00
fix(55404): Remove braces from arrow function" generates invalid code in JavaScript (#55429)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
@@ -12,11 +12,13 @@ import {
|
||||
factory,
|
||||
first,
|
||||
getContainingFunction,
|
||||
getLeftmostExpression,
|
||||
getLocaleSpecificMessage,
|
||||
getTokenAtPosition,
|
||||
isArrowFunction,
|
||||
isBlock,
|
||||
isExpression,
|
||||
isObjectLiteralExpression,
|
||||
isReturnStatement,
|
||||
needsParentheses,
|
||||
rangeContainsRange,
|
||||
@@ -147,7 +149,8 @@ function getConvertibleArrowFunctionAtPosition(file: SourceFile, startPosition:
|
||||
else if (refactorKindBeginsWith(removeBracesAction.kind, kind) && isBlock(func.body) && func.body.statements.length === 1) {
|
||||
const firstStatement = first(func.body.statements);
|
||||
if (isReturnStatement(firstStatement)) {
|
||||
return { func, addBraces: false, expression: firstStatement.expression, returnStatement: firstStatement };
|
||||
const expression = firstStatement.expression && isObjectLiteralExpression(getLeftmostExpression(firstStatement.expression, /*stopAtCallExpressions*/ false)) ? factory.createParenthesizedExpression(firstStatement.expression) : firstStatement.expression;
|
||||
return { func, addBraces: false, expression, returnStatement: firstStatement };
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user