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 authored Mar 3, 2021
1 parent 7b14d41 commit 47b2632
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 47b2632

Please sign in to comment.