Skip to content

Commit

Permalink
fix(43006): skip trivia in a function name (#43021)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed Mar 3, 2021
1 parent c497b48 commit f1c911b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/services/codefixes/fixAddMissingMember.ts
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/services/codefixes/helpers.ts
Expand Up @@ -252,7 +252,7 @@ namespace ts.codefix {
context: CodeFixContextBase,
importAdder: ImportAdder,
call: CallExpression,
name: Identifier,
name: Identifier | string,
modifierFlags: ModifierFlags,
contextNode: Node
) {
Expand Down
17 changes: 17 additions & 0 deletions tests/cases/fourslash/codeFixAddMissingFunctionDeclaration17.ts
@@ -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.");
}
`
});
21 changes: 21 additions & 0 deletions tests/cases/fourslash/codeFixAddMissingFunctionDeclaration18.ts
@@ -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.");
}
`
});

0 comments on commit f1c911b

Please sign in to comment.