mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Don't assume the class declaration will occur first, and that it is *only* a class declaration.
This commit is contained in:
parent
9eef4b8f47
commit
9f3c99e392
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user