fix(54383): Declare method quick fix not returned for #private method (#54400)

This commit is contained in:
Oleksandr T 2023-05-26 20:06:20 +03:00 committed by GitHub
parent 98ed0eb94c
commit d762534463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 7 deletions

View File

@ -538,11 +538,6 @@ function getActionsForMissingMethodDeclaration(context: CodeFixContext, info: Ty
return undefined;
}
// Private methods are not implemented yet.
if (isPrivateIdentifier(token)) {
return undefined;
}
const methodName = token.text;
const addMethodDeclarationChanges = (modifierFlags: ModifierFlags) => textChanges.ChangeTracker.with(context, t => addMethodDeclaration(context, t, call, token, modifierFlags, parentDeclaration, declSourceFile));
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(
context: CodeFixContextBase,
changes: textChanges.ChangeTracker,
callExpression: CallExpression,
name: Identifier,
name: Identifier | PrivateIdentifier,
modifierFlags: ModifierFlags,
parentDeclaration: ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode,
sourceFile: SourceFile,

View File

@ -69,6 +69,7 @@ import {
ObjectLiteralExpression,
ObjectType,
ParameterDeclaration,
PrivateIdentifier,
Program,
PropertyAssignment,
PropertyDeclaration,
@ -464,7 +465,7 @@ export function createSignatureDeclarationFromCallExpression(
context: CodeFixContextBase,
importAdder: ImportAdder,
call: CallExpression,
name: Identifier | string,
name: Identifier | PrivateIdentifier | string,
modifierFlags: ModifierFlags,
contextNode: Node
): MethodDeclaration | FunctionDeclaration | MethodSignature {
@ -517,6 +518,7 @@ export function createSignatureDeclarationFromCallExpression(
type === undefined ? factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword) : type
);
case SyntaxKind.FunctionDeclaration:
Debug.assert(typeof name === "string" || isIdentifier(name), "Unexpected name");
return factory.createFunctionDeclaration(
modifiers,
asteriskToken,

View File

@ -0,0 +1,21 @@
/// <reference path='fourslash.ts' />
////class C {
//// constructor() {
//// this.#foo();
//// }
////}
verify.codeFix({
description: [ts.Diagnostics.Declare_method_0.message, "#foo"],
index: 0,
newFileContent:
`class C {
constructor() {
this.#foo();
}
#foo() {
throw new Error("Method not implemented.");
}
}`,
});