mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 17:30:04 -05:00
fix(refactor): keep comments after refactor (#35937)
* add two tests: Refactor: Remove braces from arrow function * refactor: simplify test and add another test * fix: copyTrailingAsLeadingComments in addOrRemoveBracesToArrowFunction * test: add additional test * fix: clean up changes * fix: add check for newEdit * fix: add function for semi colon modifier * feat: grab all comments during refactor * refactor: update addOrRemoveBraces logic * fix: remove duplicate function call * Update src/services/refactors/addOrRemoveBracesToArrowFunction.ts * remove blank line remove blank line Co-authored-by: Jesse Trinity <42591254+jessetrinity@users.noreply.github.com>
This commit is contained in:
@@ -44,6 +44,7 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
|
||||
const { expression, returnStatement, func } = info;
|
||||
|
||||
let body: ConciseBody;
|
||||
|
||||
if (actionName === addBracesActionName) {
|
||||
const returnStatement = createReturn(expression);
|
||||
body = createBlock([returnStatement], /* multiLine */ true);
|
||||
@@ -54,13 +55,18 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
|
||||
const actualExpression = expression || createVoidZero();
|
||||
body = needsParentheses(actualExpression) ? createParen(actualExpression) : actualExpression;
|
||||
suppressLeadingAndTrailingTrivia(body);
|
||||
copyTrailingAsLeadingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
|
||||
copyLeadingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
|
||||
copyTrailingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
|
||||
}
|
||||
else {
|
||||
Debug.fail("invalid action");
|
||||
}
|
||||
|
||||
const edits = textChanges.ChangeTracker.with(context, t => t.replaceNode(file, func.body, body));
|
||||
const edits = textChanges.ChangeTracker.with(context, t => {
|
||||
t.replaceNode(file, func.body, body);
|
||||
});
|
||||
|
||||
return { renameFilename: undefined, renameLocation: undefined, edits };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user