mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
fix(54383): Declare method quick fix not returned for #private method (#54400)
This commit is contained in:
parent
98ed0eb94c
commit
d762534463
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
21
tests/cases/fourslash/codeFixAddMissingMember29.ts
Normal file
21
tests/cases/fourslash/codeFixAddMissingMember29.ts
Normal 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.");
|
||||
}
|
||||
}`,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user