Skip to content

Commit d762534

Browse files
authored
fix(54383): Declare method quick fix not returned for #private method (#54400)
1 parent 98ed0eb commit d762534

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/services/codefixes/fixAddMissingMember.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,6 @@ function getActionsForMissingMethodDeclaration(context: CodeFixContext, info: Ty
538538
return undefined;
539539
}
540540

541-
// Private methods are not implemented yet.
542-
if (isPrivateIdentifier(token)) {
543-
return undefined;
544-
}
545-
546541
const methodName = token.text;
547542
const addMethodDeclarationChanges = (modifierFlags: ModifierFlags) => textChanges.ChangeTracker.with(context, t => addMethodDeclaration(context, t, call, token, modifierFlags, parentDeclaration, declSourceFile));
548543
const actions = [createCodeFixAction(fixMissingMember, addMethodDeclarationChanges(modifierFlags & ModifierFlags.Static), [modifierFlags & ModifierFlags.Static ? Diagnostics.Declare_static_method_0 : Diagnostics.Declare_method_0, methodName], fixMissingMember, Diagnostics.Add_all_missing_members)];
@@ -556,7 +551,7 @@ function addMethodDeclaration(
556551
context: CodeFixContextBase,
557552
changes: textChanges.ChangeTracker,
558553
callExpression: CallExpression,
559-
name: Identifier,
554+
name: Identifier | PrivateIdentifier,
560555
modifierFlags: ModifierFlags,
561556
parentDeclaration: ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode,
562557
sourceFile: SourceFile,

src/services/codefixes/helpers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import {
6969
ObjectLiteralExpression,
7070
ObjectType,
7171
ParameterDeclaration,
72+
PrivateIdentifier,
7273
Program,
7374
PropertyAssignment,
7475
PropertyDeclaration,
@@ -464,7 +465,7 @@ export function createSignatureDeclarationFromCallExpression(
464465
context: CodeFixContextBase,
465466
importAdder: ImportAdder,
466467
call: CallExpression,
467-
name: Identifier | string,
468+
name: Identifier | PrivateIdentifier | string,
468469
modifierFlags: ModifierFlags,
469470
contextNode: Node
470471
): MethodDeclaration | FunctionDeclaration | MethodSignature {
@@ -517,6 +518,7 @@ export function createSignatureDeclarationFromCallExpression(
517518
type === undefined ? factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword) : type
518519
);
519520
case SyntaxKind.FunctionDeclaration:
521+
Debug.assert(typeof name === "string" || isIdentifier(name), "Unexpected name");
520522
return factory.createFunctionDeclaration(
521523
modifiers,
522524
asteriskToken,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class C {
4+
//// constructor() {
5+
//// this.#foo();
6+
//// }
7+
////}
8+
9+
verify.codeFix({
10+
description: [ts.Diagnostics.Declare_method_0.message, "#foo"],
11+
index: 0,
12+
newFileContent:
13+
`class C {
14+
constructor() {
15+
this.#foo();
16+
}
17+
#foo() {
18+
throw new Error("Method not implemented.");
19+
}
20+
}`,
21+
});

0 commit comments

Comments
 (0)