fix(43006): skip trivia in a function name (#43021)

This commit is contained in:
Oleksandr T 2021-03-03 02:32:28 +02:00 committed by GitHub
parent 7b14d41642
commit 47b2632ddd
4 changed files with 40 additions and 2 deletions

View File

@ -402,7 +402,7 @@ namespace ts.codefix {
function addFunctionDeclaration(changes: textChanges.ChangeTracker, context: CodeFixContextBase, info: FunctionInfo) {
const importAdder = createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
const functionDeclaration = createSignatureDeclarationFromCallExpression(SyntaxKind.FunctionDeclaration, context, importAdder, info.call, info.token, info.modifierFlags, info.parentDeclaration) as FunctionDeclaration;
const functionDeclaration = createSignatureDeclarationFromCallExpression(SyntaxKind.FunctionDeclaration, context, importAdder, info.call, idText(info.token), info.modifierFlags, info.parentDeclaration) as FunctionDeclaration;
changes.insertNodeAtEndOfScope(info.sourceFile, info.parentDeclaration, functionDeclaration);
}
}

View File

@ -252,7 +252,7 @@ namespace ts.codefix {
context: CodeFixContextBase,
importAdder: ImportAdder,
call: CallExpression,
name: Identifier,
name: Identifier | string,
modifierFlags: ModifierFlags,
contextNode: Node
) {

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
////// comment
////foo();
verify.codeFix({
index: 0,
description: [ts.Diagnostics.Add_missing_function_declaration_0.message, "foo"],
newFileContent:
`// comment
foo();
function foo() {
throw new Error("Function not implemented.");
}
`
});

View File

@ -0,0 +1,21 @@
/// <reference path='fourslash.ts' />
/////**
//// * comment
//// */
////foo();
verify.codeFix({
index: 0,
description: [ts.Diagnostics.Add_missing_function_declaration_0.message, "foo"],
newFileContent:
`/**
* comment
*/
foo();
function foo() {
throw new Error("Function not implemented.");
}
`
});