Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}`
});
Original file line number Diff line number Diff line change
@@ -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;
}`
});