Skip to content

Commit 6400d53

Browse files
committed
Fix handling of default class
1 parent d8b359f commit 6400d53

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ namespace ts {
18011801
}
18021802
}
18031803

1804-
export function getAncestor(node: Node, kind: SyntaxKind): Node {
1804+
export function getAncestor(node: Node | undefined, kind: SyntaxKind): Node {
18051805
while (node) {
18061806
if (node.kind === kind) {
18071807
return node;

src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ namespace ts.codefix {
88
const token = getTokenAtPosition(sourceFile, start);
99
const checker = context.program.getTypeChecker();
1010

11-
if (!(token.kind === SyntaxKind.Identifier && isClassLike(token.parent))) {
11+
const classDecl = getAncestor(token, SyntaxKind.ClassDeclaration) as ClassDeclaration;
12+
if (!(classDecl && isClassLike(classDecl))) {
1213
return undefined;
1314
}
14-
const classDecl = <ClassDeclaration>token.parent;
15+
1516
const startPos: number = classDecl.members.pos;
1617

1718
const implementedTypeNodes = getClassImplementsHeritageClauseElements(classDecl);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// interface I { x: number; }
4+
////
5+
//// export default class implements I {[| |]}
6+
7+
verify.rangeAfterCodeFix(`
8+
x: number;
9+
`);

0 commit comments

Comments
 (0)