Skip to content

Commit 6b778f1

Browse files
committed
Handle type declaration nodes
1 parent 12a0909 commit 6b778f1

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/compiler/checker.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6543,6 +6543,11 @@ module ts {
65436543
return mapToArray(symbols);
65446544
}
65456545

6546+
// True if the given identifier, string literal, or number literal is the name of a declaration node
6547+
function isTypeDeclarationName(name: Node): boolean {
6548+
return name.kind == SyntaxKind.Identifier && isTypeDeclaration(name.parent);
6549+
}
6550+
65466551
// True if the given identifier, string literal, or number literal is the name of a declaration node
65476552
function isDeclarationName(name: Node): boolean {
65486553
if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) {
@@ -6561,6 +6566,16 @@ module ts {
65616566
return false;
65626567
}
65636568

6569+
function isTypeDeclaration(node: Node): boolean {
6570+
switch (node.kind) {
6571+
case SyntaxKind.TypeParameter:
6572+
case SyntaxKind.ClassDeclaration:
6573+
case SyntaxKind.InterfaceDeclaration:
6574+
case SyntaxKind.EnumDeclaration:
6575+
return true;
6576+
}
6577+
}
6578+
65646579
function isDeclaration(node: Node): boolean {
65656580
switch (node.kind) {
65666581
case SyntaxKind.TypeParameter:
@@ -6817,17 +6832,35 @@ module ts {
68176832
return getTypeFromTypeNode(<TypeNode>node);
68186833
}
68196834

6835+
if (isTypeDeclaration(node)) {
6836+
// In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration
6837+
var symbol = getSymbolOfNode(node);
6838+
return getDeclaredTypeOfSymbol(symbol);
6839+
}
6840+
6841+
if (isTypeDeclarationName(node)) {
6842+
var symbol = getSymbolInfo(node);
6843+
return getDeclaredTypeOfSymbol(symbol);
6844+
}
6845+
68206846
if (isDeclaration(node)) {
68216847
// In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration
68226848
var symbol = getSymbolOfNode(node);
68236849
return getTypeOfSymbol(symbol);
68246850
}
68256851

6826-
var isExportAssignment = node.kind === SyntaxKind.Identifier && node.parent.kind === SyntaxKind.ExportAssignment;
6827-
if (isDeclarationName(node) || isExportAssignment) {
6852+
if (isDeclarationName(node)) {
68286853
var symbol = getSymbolInfo(node);
68296854
return getTypeOfSymbol(symbol);
68306855
}
6856+
6857+
if (node.kind === SyntaxKind.Identifier && node.parent.kind === SyntaxKind.ExportAssignment) {
6858+
var symbol = getSymbolInfo(node);
6859+
var declaredType = getDeclaredTypeOfSymbol(symbol);
6860+
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
6861+
}
6862+
6863+
Debug.fail("Unhandled case in getTypeOfNode");
68316864
}
68326865

68336866
function getTypeOfExpression(expr: Expression): Type {

0 commit comments

Comments
 (0)