@@ -11,6 +11,18 @@ module ts {
1111 var nextNodeId = 1 ;
1212 var nextMergeId = 1 ;
1313
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+
1426 /// fullTypeCheck denotes if this instance of the typechecker will be used to get semantic diagnostics.
1527 /// If fullTypeCheck === true - then typechecker should do every possible check to produce all errors
1628 /// If fullTypeCheck === false - typechecker can shortcut and skip checks that only produce errors.
@@ -49,7 +61,9 @@ module ts {
4961 getApparentType : getApparentType ,
5062 typeToString : typeToString ,
5163 symbolToString : symbolToString ,
52- getAugmentedPropertiesOfApparentType : getAugmentedPropertiesOfApparentType
64+ getAugmentedPropertiesOfApparentType : getAugmentedPropertiesOfApparentType ,
65+ getRootSymbol : getRootSymbol ,
66+ getContextualType : getContextualType
5367 } ;
5468
5569 var undefinedSymbol = createSymbol ( SymbolFlags . Property | SymbolFlags . Transient , "undefined" ) ;
@@ -568,18 +582,6 @@ module ts {
568582 return false ;
569583 }
570584
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-
583585 function findConstructorDeclaration ( node : ClassDeclaration ) : ConstructorDeclaration {
584586 var members = node . members ;
585587 for ( var i = 0 ; i < members . length ; i ++ ) {
@@ -3148,6 +3150,7 @@ module ts {
31483150 symbol . declarations = p . declarations ;
31493151 symbol . parent = p . parent ;
31503152 symbol . type = widenedTypes [ index ++ ] ;
3153+ symbol . target = p ;
31513154 if ( p . valueDeclaration ) symbol . valueDeclaration = p . valueDeclaration ;
31523155 members [ symbol . name ] = symbol ;
31533156 } ) ;
@@ -3821,6 +3824,7 @@ module ts {
38213824 prop . parent = member . parent ;
38223825 if ( member . valueDeclaration ) prop . valueDeclaration = member . valueDeclaration ;
38233826 prop . type = type ;
3827+ prop . target = member ;
38243828 member = prop ;
38253829 }
38263830 else {
@@ -6584,24 +6588,6 @@ module ts {
65846588 ( < Declaration > name . parent ) . name === name ;
65856589 }
65866590
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-
66056591 function isTypeDeclaration ( node : Node ) : boolean {
66066592 switch ( node . kind ) {
66076593 case SyntaxKind . TypeParameter :
@@ -6612,28 +6598,6 @@ module ts {
66126598 }
66136599 }
66146600
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-
66376601 // True if the given identifier is part of a type reference
66386602 function isTypeReferenceIdentifier ( entityName : EntityName ) : boolean {
66396603 var node : Node = entityName ;
@@ -6852,6 +6816,17 @@ module ts {
68526816 }
68536817
68546818 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+
68556830 switch ( node . kind ) {
68566831 case SyntaxKind . Identifier :
68576832 case SyntaxKind . PropertyAccess :
@@ -6862,7 +6837,7 @@ module ts {
68626837 case SyntaxKind . SuperKeyword :
68636838 var type = checkExpression ( node ) ;
68646839 return type . symbol ;
6865-
6840+
68666841 case SyntaxKind . ConstructorKeyword :
68676842 // constructor keyword for an overload, should take us to the definition if it exist
68686843 var constructorDeclaration = node . parent ;
@@ -6872,23 +6847,22 @@ module ts {
68726847 return undefined ;
68736848
68746849 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- }
68836850 // 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 ) {
68856852 var importSymbol = getSymbolOfNode ( node . parent ) ;
68866853 var moduleType = getTypeOfSymbol ( importSymbol ) ;
68876854 return moduleType ? moduleType . symbol : undefined ;
68886855 }
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 ) ;
68926866 }
68936867 break ;
68946868 }
@@ -6978,6 +6952,10 @@ module ts {
69786952 }
69796953 }
69806954
6955+ function getRootSymbol ( symbol : Symbol ) {
6956+ return ( symbol . flags & SymbolFlags . Transient ) ? getSymbolLinks ( symbol ) . target : symbol ;
6957+ }
6958+
69816959 // Emitter support
69826960
69836961 function isExternalModuleSymbol ( symbol : Symbol ) : boolean {
0 commit comments