mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 07:07:09 -05:00
fix(43298): copy comments on converting from arrow function to anonymous function (#44236)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const foo = /*a*/()/*b*/ => /**
|
||||
//// * comment
|
||||
//// */
|
||||
////1
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert arrow function or function expression",
|
||||
actionName: "Convert to anonymous function",
|
||||
actionDescription: "Convert to anonymous function",
|
||||
newContent: `const foo = function() {
|
||||
/**
|
||||
* comment
|
||||
*/
|
||||
return 1;
|
||||
}`
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const foo = /*a*/()/*b*/ => // comment
|
||||
////1
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert arrow function or function expression",
|
||||
actionName: "Convert to anonymous function",
|
||||
actionDescription: "Convert to anonymous function",
|
||||
newContent: `const foo = function() {
|
||||
// comment
|
||||
return 1;
|
||||
}`
|
||||
});
|
||||
Reference in New Issue
Block a user