@@ -2296,6 +2296,12 @@ module ts {
2296
2296
return getTypeFromArrayTypeNode ( < ArrayTypeNode > node ) ;
2297
2297
case SyntaxKind . TypeLiteral :
2298
2298
return getTypeFromTypeLiteralNode ( < TypeLiteralNode > node ) ;
2299
+ // This function assumes that an identifier or qualified name is a type expression
2300
+ // Callers should first ensure this by calling isTypeNode
2301
+ case SyntaxKind . Identifier :
2302
+ case SyntaxKind . QualifiedName :
2303
+ var symbol = getSymbolInfo ( node ) ;
2304
+ return getDeclaredTypeOfSymbol ( symbol ) ;
2299
2305
default :
2300
2306
return unknownType ;
2301
2307
}
@@ -6544,13 +6550,15 @@ module ts {
6544
6550
return mapToArray ( symbols ) ;
6545
6551
}
6546
6552
6547
- // True if the given identifier, string literal, or number literal is the name of a declaration node
6553
+ // True if the given identifier is the name of a type declaration node (class, interface, enum, type parameter, etc)
6548
6554
function isTypeDeclarationName ( name : Node ) : boolean {
6549
- return name . kind == SyntaxKind . Identifier && isTypeDeclaration ( name . parent ) ;
6555
+ return name . kind == SyntaxKind . Identifier &&
6556
+ isTypeDeclaration ( name . parent ) &&
6557
+ ( < Declaration > name . parent ) . name === name ;
6550
6558
}
6551
6559
6552
6560
// True if the given identifier, string literal, or number literal is the name of a declaration node
6553
- function isDeclarationName ( name : Node ) : boolean {
6561
+ function isDeclarationOrFunctionExpressionOrCatchVariableName ( name : Node ) : boolean {
6554
6562
if ( name . kind !== SyntaxKind . Identifier && name . kind !== SyntaxKind . StringLiteral && name . kind !== SyntaxKind . NumericLiteral ) {
6555
6563
return false ;
6556
6564
}
@@ -6607,7 +6615,6 @@ module ts {
6607
6615
}
6608
6616
6609
6617
function isExpression ( node : Node ) : boolean {
6610
- // Omitted expression?
6611
6618
switch ( node . kind ) {
6612
6619
case SyntaxKind . ThisKeyword :
6613
6620
case SyntaxKind . SuperKeyword :
@@ -6629,6 +6636,7 @@ module ts {
6629
6636
case SyntaxKind . PostfixOperator :
6630
6637
case SyntaxKind . BinaryExpression :
6631
6638
case SyntaxKind . ConditionalExpression :
6639
+ case SyntaxKind . OmittedExpression :
6632
6640
return true ;
6633
6641
case SyntaxKind . QualifiedName :
6634
6642
while ( node . parent . kind === SyntaxKind . QualifiedName ) node = node . parent ;
@@ -6641,14 +6649,6 @@ module ts {
6641
6649
case SyntaxKind . NumericLiteral :
6642
6650
case SyntaxKind . StringLiteral :
6643
6651
var parent = node . parent ;
6644
- if ( parent . kind === SyntaxKind . TypeAssertion ) {
6645
- return node === ( < TypeAssertion > parent ) . operand ;
6646
- }
6647
-
6648
- if ( isExpression ( parent ) ) {
6649
- return true ;
6650
- }
6651
-
6652
6652
switch ( parent . kind ) {
6653
6653
case SyntaxKind . VariableDeclaration :
6654
6654
case SyntaxKind . Parameter :
@@ -6667,10 +6667,18 @@ module ts {
6667
6667
case SyntaxKind . SwitchStatement :
6668
6668
return ( < ExpressionStatement > parent ) . expression === node ;
6669
6669
case SyntaxKind . ForStatement :
6670
- return ( < ForStatement > parent ) . initializer === node || ( < ForStatement > parent ) . condition === node ||
6670
+ return ( < ForStatement > parent ) . initializer === node ||
6671
+ ( < ForStatement > parent ) . condition === node ||
6671
6672
( < ForStatement > parent ) . iterator === node ;
6672
6673
case SyntaxKind . ForInStatement :
6673
- return ( < ForInStatement > parent ) . variable === node || ( < ForInStatement > parent ) . expression === node ;
6674
+ return ( < ForInStatement > parent ) . variable === node ||
6675
+ ( < ForInStatement > parent ) . expression === node ;
6676
+ case SyntaxKind . TypeAssertion :
6677
+ return node === ( < TypeAssertion > parent ) . operand ;
6678
+ default :
6679
+ if ( isExpression ( parent ) ) {
6680
+ return true ;
6681
+ }
6674
6682
}
6675
6683
}
6676
6684
return false ;
@@ -6690,6 +6698,7 @@ module ts {
6690
6698
case SyntaxKind . VoidKeyword :
6691
6699
return node . parent . kind !== SyntaxKind . PrefixOperator ;
6692
6700
case SyntaxKind . StringLiteral :
6701
+ // Specialized signatures can have string literals as their parameters' type names
6693
6702
return node . parent . kind === SyntaxKind . Parameter ;
6694
6703
// Identifiers and qualified names may be type nodes, depending on their context. Climb
6695
6704
// above them to find the lowest container
@@ -6700,6 +6709,7 @@ module ts {
6700
6709
}
6701
6710
// Fall through
6702
6711
case SyntaxKind . QualifiedName :
6712
+ // At this point, node is either a qualified name or an identifier
6703
6713
var parent = node . parent ;
6704
6714
if ( parent . kind === SyntaxKind . TypeQuery ) {
6705
6715
return false ;
@@ -6710,7 +6720,7 @@ module ts {
6710
6720
//
6711
6721
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
6712
6722
// A.B.C is a type node.
6713
- if ( node . kind >= SyntaxKind . FirstTypeNode && node . kind <= SyntaxKind . LastTypeNode ) {
6723
+ if ( parent . kind >= SyntaxKind . FirstTypeNode && parent . kind <= SyntaxKind . LastTypeNode ) {
6714
6724
return true ;
6715
6725
}
6716
6726
switch ( parent . kind ) {
@@ -6764,7 +6774,7 @@ module ts {
6764
6774
}
6765
6775
6766
6776
function getSymbolOfIdentifier ( identifier : Identifier ) {
6767
- if ( isDeclarationName ( identifier ) ) {
6777
+ if ( isDeclarationOrFunctionExpressionOrCatchVariableName ( identifier ) ) {
6768
6778
return getSymbolOfNode ( identifier . parent ) ;
6769
6779
}
6770
6780
@@ -6852,10 +6862,6 @@ module ts {
6852
6862
return getTypeOfExpression ( < Expression > node ) ;
6853
6863
}
6854
6864
if ( isTypeNode ( node ) ) {
6855
- if ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . QualifiedName ) {
6856
- var symbol = getSymbolInfo ( node ) ;
6857
- return getDeclaredTypeOfSymbol ( symbol ) ;
6858
- }
6859
6865
return getTypeFromTypeNode ( < TypeNode > node ) ;
6860
6866
}
6861
6867
@@ -6876,7 +6882,7 @@ module ts {
6876
6882
return getTypeOfSymbol ( symbol ) ;
6877
6883
}
6878
6884
6879
- if ( isDeclarationName ( node ) ) {
6885
+ if ( isDeclarationOrFunctionExpressionOrCatchVariableName ( node ) ) {
6880
6886
var symbol = getSymbolInfo ( node ) ;
6881
6887
return getTypeOfSymbol ( symbol ) ;
6882
6888
}
0 commit comments