Fix handling of default class

This commit is contained in:
Arthur Ozga 2016-11-14 15:43:24 -08:00
parent d8b359f67b
commit 6400d53394
3 changed files with 13 additions and 3 deletions

View File

@ -1801,7 +1801,7 @@ namespace ts {
}
}
export function getAncestor(node: Node, kind: SyntaxKind): Node {
export function getAncestor(node: Node | undefined, kind: SyntaxKind): Node {
while (node) {
if (node.kind === kind) {
return node;

View File

@ -8,10 +8,11 @@ namespace ts.codefix {
const token = getTokenAtPosition(sourceFile, start);
const checker = context.program.getTypeChecker();
if (!(token.kind === SyntaxKind.Identifier && isClassLike(token.parent))) {
const classDecl = getAncestor(token, SyntaxKind.ClassDeclaration) as ClassDeclaration;
if (!(classDecl && isClassLike(classDecl))) {
return undefined;
}
const classDecl = <ClassDeclaration>token.parent;
const startPos: number = classDecl.members.pos;
const implementedTypeNodes = getClassImplementsHeritageClauseElements(classDecl);

View File

@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
//// interface I { x: number; }
////
//// export default class implements I {[| |]}
verify.rangeAfterCodeFix(`
x: number;
`);