fix(52418): "Convert to named function" breaks on concise return of async function (#52434)

This commit is contained in:
Oleksandr T
2023-02-02 23:03:52 +02:00
committed by GitHub
parent 87b6fcd895
commit 0f41b7a390
4 changed files with 47 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ import {
RefactorContext,
RefactorEditInfo,
ReturnStatement,
setTextRange,
SourceFile,
Statement,
suppressLeadingAndTrailingTrivia,
@@ -237,6 +238,7 @@ function convertToBlock(body: ConciseBody): Block {
if (isExpression(body)) {
const returnStatement = factory.createReturnStatement(body);
const file = body.getSourceFile();
setTextRange(returnStatement, body);
suppressLeadingAndTrailingTrivia(returnStatement);
copyTrailingAsLeadingComments(body, returnStatement, file, /* commentKind */ undefined, /* hasTrailingNewLine */ true);
return factory.createBlock([returnStatement], /* multiLine */ true);

View File

@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
/////*a*/const fn = () =>
//// async () => { };/*b*/
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to named function",
actionDescription: "Convert to named function",
newContent:
`function fn() {
return async () => { };
}`,
});

View File

@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
/////*a*/const fn = () =>
//// async function() { }/*b*/
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to named function",
actionDescription: "Convert to named function",
newContent:
`function fn() {
return async function() { };
}`,
});

View File

@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
/////*a*/const fn = () =>
//// async function*() { }/*b*/
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to named function",
actionDescription: "Convert to named function",
newContent:
`function fn() {
return async function*() { };
}`,
});