Skip to content

Commit 9f3c99e

Browse files
Don't assume the class declaration will occur first, and that it is *only* a class declaration.
1 parent 9eef4b8 commit 9f3c99e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,11 @@ namespace ts {
611611
return false;
612612
}
613613

614-
export function isAccessor(node: Node): boolean {
614+
export function isAccessor(node: Node): node is AccessorDeclaration {
615615
return node && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor);
616616
}
617617

618-
export function isClassLike(node: Node): boolean {
618+
export function isClassLike(node: Node): node is ClassLikeDeclaration {
619619
return node && (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression);
620620
}
621621

src/services/services.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4480,10 +4480,19 @@ namespace ts {
44804480
// and in either case the symbol has a construct signature definition, i.e. class
44814481
if (isNewExpressionTarget(location) || location.kind === SyntaxKind.ConstructorKeyword) {
44824482
if (symbol.flags & SymbolFlags.Class) {
4483-
let classDeclaration = <ClassDeclaration>symbol.getDeclarations()[0];
4484-
Debug.assert(classDeclaration && classDeclaration.kind === SyntaxKind.ClassDeclaration);
4483+
// Find the first class-like declaration and try to get the construct signature.
4484+
for (let declaration of symbol.getDeclarations()) {
4485+
if (isClassLike(declaration)) {
4486+
return tryAddSignature(declaration.members,
4487+
/*selectConstructors*/ true,
4488+
symbolKind,
4489+
symbolName,
4490+
containerName,
4491+
result);
4492+
}
4493+
}
44854494

4486-
return tryAddSignature(classDeclaration.members, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result);
4495+
Debug.fail("Expected declaration to have at least one class-like declaration");
44874496
}
44884497
}
44894498
return false;

0 commit comments

Comments
 (0)