Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(43006): 'Add missing function decoration' quick fix can duplicate //@ts-check comment #43021

Merged
merged 1 commit into from Mar 3, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.");
}
`
});