Don't assume the class declaration will occur first, and that it is *only* a class declaration.

This commit is contained in:
Daniel Rosenwasser 2015-08-26 16:19:55 -07:00
parent 9eef4b8f47
commit 9f3c99e392
2 changed files with 14 additions and 5 deletions

View File

@ -611,11 +611,11 @@ namespace ts {
return false;
}
export function isAccessor(node: Node): boolean {
export function isAccessor(node: Node): node is AccessorDeclaration {
return node && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor);
}
export function isClassLike(node: Node): boolean {
export function isClassLike(node: Node): node is ClassLikeDeclaration {
return node && (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression);
}

View File

@ -4480,10 +4480,19 @@ namespace ts {
// and in either case the symbol has a construct signature definition, i.e. class
if (isNewExpressionTarget(location) || location.kind === SyntaxKind.ConstructorKeyword) {
if (symbol.flags & SymbolFlags.Class) {
let classDeclaration = <ClassDeclaration>symbol.getDeclarations()[0];
Debug.assert(classDeclaration && classDeclaration.kind === SyntaxKind.ClassDeclaration);
// Find the first class-like declaration and try to get the construct signature.
for (let declaration of symbol.getDeclarations()) {
if (isClassLike(declaration)) {
return tryAddSignature(declaration.members,
/*selectConstructors*/ true,
symbolKind,
symbolName,
containerName,
result);
}
}
return tryAddSignature(classDeclaration.members, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result);
Debug.fail("Expected declaration to have at least one class-like declaration");
}
}
return false;