Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
}
`
});