mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 16:38:46 -05:00
fix(52418): "Convert to named function" breaks on concise return of async function (#52434)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 () => { };
|
||||
}`,
|
||||
});
|
||||
@@ -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() { };
|
||||
}`,
|
||||
});
|
||||
@@ -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*() { };
|
||||
}`,
|
||||
});
|
||||
Reference in New Issue
Block a user