Skip to content

Commit ffdd439

Browse files
committed
fix(43006): skip trivia in a function name
1 parent c44b3ba commit ffdd439

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/services/codefixes/fixAddMissingMember.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ namespace ts.codefix {
402402

403403
function addFunctionDeclaration(changes: textChanges.ChangeTracker, context: CodeFixContextBase, info: FunctionInfo) {
404404
const importAdder = createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
405-
const functionDeclaration = createSignatureDeclarationFromCallExpression(SyntaxKind.FunctionDeclaration, context, importAdder, info.call, info.token, info.modifierFlags, info.parentDeclaration) as FunctionDeclaration;
405+
const functionDeclaration = createSignatureDeclarationFromCallExpression(SyntaxKind.FunctionDeclaration, context, importAdder, info.call, idText(info.token), info.modifierFlags, info.parentDeclaration) as FunctionDeclaration;
406406
changes.insertNodeAtEndOfScope(info.sourceFile, info.parentDeclaration, functionDeclaration);
407407
}
408408
}

src/services/codefixes/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ namespace ts.codefix {
252252
context: CodeFixContextBase,
253253
importAdder: ImportAdder,
254254
call: CallExpression,
255-
name: Identifier,
255+
name: Identifier | string,
256256
modifierFlags: ModifierFlags,
257257
contextNode: Node
258258
) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////// comment
4+
////foo();
5+
6+
verify.codeFix({
7+
index: 0,
8+
description: [ts.Diagnostics.Add_missing_function_declaration_0.message, "foo"],
9+
newFileContent:
10+
`// comment
11+
foo();
12+
13+
function foo() {
14+
throw new Error("Function not implemented.");
15+
}
16+
`
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
/////**
4+
//// * comment
5+
//// */
6+
////foo();
7+
8+
verify.codeFix({
9+
index: 0,
10+
description: [ts.Diagnostics.Add_missing_function_declaration_0.message, "foo"],
11+
newFileContent:
12+
`/**
13+
* comment
14+
*/
15+
foo();
16+
17+
function foo() {
18+
throw new Error("Function not implemented.");
19+
}
20+
`
21+
});

0 commit comments

Comments
 (0)