@@ -11,6 +11,18 @@ module ts {
11
11
var nextNodeId = 1 ;
12
12
var nextMergeId = 1 ;
13
13
14
+ export function getDeclarationOfKind ( symbol : Symbol , kind : SyntaxKind ) : Declaration {
15
+ var declarations = symbol . declarations ;
16
+ for ( var i = 0 ; i < declarations . length ; i ++ ) {
17
+ var declaration = declarations [ i ] ;
18
+ if ( declaration . kind === kind ) {
19
+ return declaration ;
20
+ }
21
+ }
22
+
23
+ return undefined ;
24
+ }
25
+
14
26
/// fullTypeCheck denotes if this instance of the typechecker will be used to get semantic diagnostics.
15
27
/// If fullTypeCheck === true - then typechecker should do every possible check to produce all errors
16
28
/// If fullTypeCheck === false - typechecker can shortcut and skip checks that only produce errors.
@@ -49,7 +61,9 @@ module ts {
49
61
getApparentType : getApparentType ,
50
62
typeToString : typeToString ,
51
63
symbolToString : symbolToString ,
52
- getAugmentedPropertiesOfApparentType : getAugmentedPropertiesOfApparentType
64
+ getAugmentedPropertiesOfApparentType : getAugmentedPropertiesOfApparentType ,
65
+ getRootSymbol : getRootSymbol ,
66
+ getContextualType : getContextualType
53
67
} ;
54
68
55
69
var undefinedSymbol = createSymbol ( SymbolFlags . Property | SymbolFlags . Transient , "undefined" ) ;
@@ -568,18 +582,6 @@ module ts {
568
582
return false ;
569
583
}
570
584
571
- function getDeclarationOfKind ( symbol : Symbol , kind : SyntaxKind ) : Declaration {
572
- var declarations = symbol . declarations ;
573
- for ( var i = 0 ; i < declarations . length ; i ++ ) {
574
- var declaration = declarations [ i ] ;
575
- if ( declaration . kind === kind ) {
576
- return declaration ;
577
- }
578
- }
579
-
580
- return undefined ;
581
- }
582
-
583
585
function findConstructorDeclaration ( node : ClassDeclaration ) : ConstructorDeclaration {
584
586
var members = node . members ;
585
587
for ( var i = 0 ; i < members . length ; i ++ ) {
@@ -3148,6 +3150,7 @@ module ts {
3148
3150
symbol . declarations = p . declarations ;
3149
3151
symbol . parent = p . parent ;
3150
3152
symbol . type = widenedTypes [ index ++ ] ;
3153
+ symbol . target = p ;
3151
3154
if ( p . valueDeclaration ) symbol . valueDeclaration = p . valueDeclaration ;
3152
3155
members [ symbol . name ] = symbol ;
3153
3156
} ) ;
@@ -3821,6 +3824,7 @@ module ts {
3821
3824
prop . parent = member . parent ;
3822
3825
if ( member . valueDeclaration ) prop . valueDeclaration = member . valueDeclaration ;
3823
3826
prop . type = type ;
3827
+ prop . target = member ;
3824
3828
member = prop ;
3825
3829
}
3826
3830
else {
@@ -6584,24 +6588,6 @@ module ts {
6584
6588
( < Declaration > name . parent ) . name === name ;
6585
6589
}
6586
6590
6587
- // True if the given identifier, string literal, or number literal is the name of a declaration node
6588
- function isDeclarationOrFunctionExpressionOrCatchVariableName ( name : Node ) : boolean {
6589
- if ( name . kind !== SyntaxKind . Identifier && name . kind !== SyntaxKind . StringLiteral && name . kind !== SyntaxKind . NumericLiteral ) {
6590
- return false ;
6591
- }
6592
-
6593
- var parent = name . parent ;
6594
- if ( isDeclaration ( parent ) || parent . kind === SyntaxKind . FunctionExpression ) {
6595
- return ( < Declaration > parent ) . name === name ;
6596
- }
6597
-
6598
- if ( parent . kind === SyntaxKind . CatchBlock ) {
6599
- return ( < CatchBlock > parent ) . variable === name ;
6600
- }
6601
-
6602
- return false ;
6603
- }
6604
-
6605
6591
function isTypeDeclaration ( node : Node ) : boolean {
6606
6592
switch ( node . kind ) {
6607
6593
case SyntaxKind . TypeParameter :
@@ -6612,28 +6598,6 @@ module ts {
6612
6598
}
6613
6599
}
6614
6600
6615
- function isDeclaration ( node : Node ) : boolean {
6616
- switch ( node . kind ) {
6617
- case SyntaxKind . TypeParameter :
6618
- case SyntaxKind . Parameter :
6619
- case SyntaxKind . VariableDeclaration :
6620
- case SyntaxKind . Property :
6621
- case SyntaxKind . PropertyAssignment :
6622
- case SyntaxKind . EnumMember :
6623
- case SyntaxKind . Method :
6624
- case SyntaxKind . FunctionDeclaration :
6625
- case SyntaxKind . GetAccessor :
6626
- case SyntaxKind . SetAccessor :
6627
- case SyntaxKind . ClassDeclaration :
6628
- case SyntaxKind . InterfaceDeclaration :
6629
- case SyntaxKind . EnumDeclaration :
6630
- case SyntaxKind . ModuleDeclaration :
6631
- case SyntaxKind . ImportDeclaration :
6632
- return true ;
6633
- }
6634
- return false ;
6635
- }
6636
-
6637
6601
// True if the given identifier is part of a type reference
6638
6602
function isTypeReferenceIdentifier ( entityName : EntityName ) : boolean {
6639
6603
var node : Node = entityName ;
@@ -6852,6 +6816,17 @@ module ts {
6852
6816
}
6853
6817
6854
6818
function getSymbolInfo ( node : Node ) {
6819
+ if ( isDeclarationOrFunctionExpressionOrCatchVariableName ( node ) ) {
6820
+ // This is a declaration, call getSymbolOfNode
6821
+ return getSymbolOfNode ( node . parent ) ;
6822
+ }
6823
+
6824
+ if ( node . kind === SyntaxKind . Identifier && isInRightSideOfImportOrExportAssignment ( node ) ) {
6825
+ return node . parent . kind === SyntaxKind . ExportAssignment
6826
+ ? getSymbolOfEntityName ( < Identifier > node )
6827
+ : getSymbolOfPartOfRightHandSideOfImport ( node ) ;
6828
+ }
6829
+
6855
6830
switch ( node . kind ) {
6856
6831
case SyntaxKind . Identifier :
6857
6832
case SyntaxKind . PropertyAccess :
@@ -6862,7 +6837,7 @@ module ts {
6862
6837
case SyntaxKind . SuperKeyword :
6863
6838
var type = checkExpression ( node ) ;
6864
6839
return type . symbol ;
6865
-
6840
+
6866
6841
case SyntaxKind . ConstructorKeyword :
6867
6842
// constructor keyword for an overload, should take us to the definition if it exist
6868
6843
var constructorDeclaration = node . parent ;
@@ -6872,23 +6847,22 @@ module ts {
6872
6847
return undefined ;
6873
6848
6874
6849
case SyntaxKind . StringLiteral :
6875
- // Property access
6876
- if ( node . parent . kind === SyntaxKind . IndexedAccess && ( < IndexedAccess > node . parent ) . index === node ) {
6877
- var objectType = checkExpression ( ( < IndexedAccess > node . parent ) . object ) ;
6878
- if ( objectType === unknownType ) return undefined ;
6879
- var apparentType = getApparentType ( objectType ) ;
6880
- if ( < Type > apparentType === unknownType ) return undefined ;
6881
- return getPropertyOfApparentType ( apparentType , ( < LiteralExpression > node ) . text ) ;
6882
- }
6883
6850
// External module name in an import declaration
6884
- else if ( node . parent . kind === SyntaxKind . ImportDeclaration && ( < ImportDeclaration > node . parent ) . externalModuleName === node ) {
6851
+ if ( node . parent . kind === SyntaxKind . ImportDeclaration && ( < ImportDeclaration > node . parent ) . externalModuleName === node ) {
6885
6852
var importSymbol = getSymbolOfNode ( node . parent ) ;
6886
6853
var moduleType = getTypeOfSymbol ( importSymbol ) ;
6887
6854
return moduleType ? moduleType . symbol : undefined ;
6888
6855
}
6889
- // External module name in an ambient declaration
6890
- else if ( node . parent . kind === SyntaxKind . ModuleDeclaration ) {
6891
- return getSymbolOfNode ( node . parent ) ;
6856
+
6857
+ // Intentinal fallthrough
6858
+ case SyntaxKind . NumericLiteral :
6859
+ // index access
6860
+ if ( node . parent . kind == SyntaxKind . IndexedAccess && ( < IndexedAccess > node . parent ) . index === node ) {
6861
+ var objectType = checkExpression ( ( < IndexedAccess > node . parent ) . object ) ;
6862
+ if ( objectType === unknownType ) return undefined ;
6863
+ var apparentType = getApparentType ( objectType ) ;
6864
+ if ( < Type > apparentType === unknownType ) return undefined ;
6865
+ return getPropertyOfApparentType ( apparentType , ( < LiteralExpression > node ) . text ) ;
6892
6866
}
6893
6867
break ;
6894
6868
}
@@ -6978,6 +6952,10 @@ module ts {
6978
6952
}
6979
6953
}
6980
6954
6955
+ function getRootSymbol ( symbol : Symbol ) {
6956
+ return ( symbol . flags & SymbolFlags . Transient ) ? getSymbolLinks ( symbol ) . target : symbol ;
6957
+ }
6958
+
6981
6959
// Emitter support
6982
6960
6983
6961
function isExternalModuleSymbol ( symbol : Symbol ) : boolean {
0 commit comments