fix(43298): copy comments on converting from arrow function to anonymous function (#44236)

This commit is contained in:
Oleksandr T
2021-06-09 01:22:23 +03:00
committed by GitHub
parent 591be7bece
commit 147d721136
3 changed files with 39 additions and 1 deletions

View File

@@ -177,7 +177,11 @@ namespace ts.refactor.convertArrowFunctionOrFunctionExpression {
function convertToBlock(body: ConciseBody): Block {
if (isExpression(body)) {
return factory.createBlock([factory.createReturnStatement(body)], /* multiLine */ true);
const returnStatement = factory.createReturnStatement(body);
const file = body.getSourceFile();
suppressLeadingAndTrailingTrivia(returnStatement);
copyTrailingAsLeadingComments(body, returnStatement, file, /* commentKind */ undefined, /* hasTrailingNewLine */ true);
return factory.createBlock([returnStatement], /* multiLine */ true);
}
else {
return body;