mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
fixClassDoesnotImplementInheritedAbstractMember: Don't perform fix for same class twice (#22073)
This commit is contained in:
@@ -14,18 +14,22 @@ namespace ts.codefix {
|
||||
return changes.length === 0 ? undefined : [{ description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class), changes, fixId }];
|
||||
},
|
||||
fixIds: [fixId],
|
||||
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => {
|
||||
addMissingMembers(getClass(diag.file!, diag.start!), context.sourceFile, context.program.getTypeChecker(), changes);
|
||||
}),
|
||||
getAllCodeActions: context => {
|
||||
const seenClassDeclarations = createMap<true>();
|
||||
return codeFixAll(context, errorCodes, (changes, diag) => {
|
||||
const classDeclaration = getClass(diag.file!, diag.start!);
|
||||
if (addToSeen(seenClassDeclarations, getNodeId(classDeclaration))) {
|
||||
addMissingMembers(classDeclaration, context.sourceFile, context.program.getTypeChecker(), changes);
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
function getClass(sourceFile: SourceFile, pos: number): ClassLikeDeclaration {
|
||||
// This is the identifier in the case of a class declaration
|
||||
// Token is the identifier in the case of a class declaration
|
||||
// or the class keyword token in the case of a class expression.
|
||||
const token = getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false);
|
||||
const classDeclaration = token.parent;
|
||||
Debug.assert(isClassLike(classDeclaration));
|
||||
return classDeclaration as ClassLikeDeclaration;
|
||||
return cast(token.parent, isClassLike);
|
||||
}
|
||||
|
||||
function addMissingMembers(classDeclaration: ClassLikeDeclaration, sourceFile: SourceFile, checker: TypeChecker, changeTracker: textChanges.ChangeTracker): void {
|
||||
|
||||
@@ -31,9 +31,7 @@ namespace ts.codefix {
|
||||
});
|
||||
|
||||
function getClass(sourceFile: SourceFile, pos: number): ClassLikeDeclaration {
|
||||
const classDeclaration = getContainingClass(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false));
|
||||
Debug.assert(!!classDeclaration);
|
||||
return classDeclaration!;
|
||||
return Debug.assertDefined(getContainingClass(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false)));
|
||||
}
|
||||
|
||||
function addMissingDeclarations(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
////abstract class A {
|
||||
//// abstract m(): void;
|
||||
//// abstract n(): void;
|
||||
////}
|
||||
////class B extends A {}
|
||||
////class C extends A {}
|
||||
@@ -11,15 +12,22 @@ verify.codeFixAll({
|
||||
newFileContent:
|
||||
`abstract class A {
|
||||
abstract m(): void;
|
||||
abstract n(): void;
|
||||
}
|
||||
class B extends A {
|
||||
m(): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
n(): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
class C extends A {
|
||||
m(): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
n(): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}`,
|
||||
});
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
verify.codeFixAll({
|
||||
fixId: "fixClassIncorrectlyImplementsInterface",
|
||||
// TODO: GH#20073
|
||||
newFileContent:
|
||||
`interface I { i(): void; }
|
||||
interface J { j(): void; }
|
||||
|
||||
Reference in New Issue
Block a user