@@ -661,38 +661,52 @@ module ts {
661
661
return callback ( globals ) ;
662
662
}
663
663
664
- function getAccessibleSymbol ( symbol : Symbol , enclosingDeclaration : Node , meaning : SymbolFlags ) {
665
- function getAccessibleSymbolFromSymbolTable ( symbols : SymbolTable ) {
664
+ function getAccessibleSymbolChain ( symbol : Symbol , enclosingDeclaration : Node , meaning : SymbolFlags ) : Symbol [ ] {
665
+ function getAccessibleSymbolChainFromSymbolTable ( symbols : SymbolTable ) : Symbol [ ] {
666
+ function canQualifySymbol ( symbolFromSymbolTable : Symbol , meaning : SymbolFlags ) {
667
+ // If the symbol is equivalent and doesnt need futher qualification, this symbol is accessible
668
+ if ( ! needsQualification ( symbolFromSymbolTable , enclosingDeclaration , meaning ) ) {
669
+ return true ;
670
+ }
671
+
672
+ // If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too
673
+ var accessibleParent = getAccessibleSymbolChain ( symbolFromSymbolTable . parent , enclosingDeclaration , SymbolFlags . Namespace ) ;
674
+ return ! ! accessibleParent ;
675
+ }
676
+
666
677
function isAccessible ( symbolFromSymbolTable : Symbol , resolvedAliasSymbol ?: Symbol ) {
667
678
if ( symbol === ( resolvedAliasSymbol || symbolFromSymbolTable ) ) {
668
- // If the symbol is equivalent and doesnt need futher qualification, this symbol is accessible
669
- if ( ! needsQualification ( symbolFromSymbolTable , enclosingDeclaration , meaning ) ) {
670
- return true ;
671
- }
672
-
673
- // If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too
674
- var accessibleParent = getAccessibleSymbol ( symbolFromSymbolTable . parent , enclosingDeclaration , SymbolFlags . Namespace ) ;
675
- return ! ! accessibleParent ;
679
+ // if symbolfrom symbolTable or alias resolution matches the symbol,
680
+ // check the symbol can be qualified, it is only then this symbol is accessible
681
+ return canQualifySymbol ( symbolFromSymbolTable , meaning ) ;
676
682
}
677
683
}
678
684
679
685
// If symbol is directly available by its name in the symbol table
680
686
if ( isAccessible ( lookUp ( symbols , symbol . name ) ) ) {
681
- return symbol ;
687
+ return [ symbol ] ;
682
688
}
683
689
684
690
// Check if symbol is any of the alias
685
691
return forEachValue ( symbols , symbolFromSymbolTable => {
686
692
if ( symbolFromSymbolTable . flags & SymbolFlags . Import ) {
693
+ var resolvedImportedSymbol = resolveImport ( symbolFromSymbolTable ) ;
687
694
if ( isAccessible ( symbolFromSymbolTable , resolveImport ( symbolFromSymbolTable ) ) ) {
688
- return symbolFromSymbolTable ;
695
+ return [ symbolFromSymbolTable ] ;
696
+ }
697
+
698
+ // Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain
699
+ // but only if the symbolFromSymbolTable can be qualified
700
+ var accessibleSymbolsFromExports = resolvedImportedSymbol . exports ? getAccessibleSymbolChainFromSymbolTable ( resolvedImportedSymbol . exports ) : undefined ;
701
+ if ( accessibleSymbolsFromExports && canQualifySymbol ( symbolFromSymbolTable , SymbolFlags . Namespace ) ) {
702
+ return [ symbolFromSymbolTable ] . concat ( accessibleSymbolsFromExports ) ;
689
703
}
690
704
}
691
705
} ) ;
692
706
}
693
707
694
708
if ( symbol ) {
695
- return forEachSymbolTableInScope ( enclosingDeclaration , getAccessibleSymbolFromSymbolTable ) ;
709
+ return forEachSymbolTableInScope ( enclosingDeclaration , getAccessibleSymbolChainFromSymbolTable ) ;
696
710
}
697
711
}
698
712
@@ -732,9 +746,9 @@ module ts {
732
746
var meaningToLook = meaning ;
733
747
while ( symbol ) {
734
748
// Symbol is accessible if it by itself is accessible
735
- var accessibleSymbol = getAccessibleSymbol ( symbol , enclosingDeclaration , meaningToLook ) ;
736
- if ( accessibleSymbol ) {
737
- if ( forEach ( accessibleSymbol . declarations , declaration => ! getIsDeclarationVisible ( declaration ) ) ) {
749
+ var accessibleSymbolChain = getAccessibleSymbolChain ( symbol , enclosingDeclaration , meaningToLook ) ;
750
+ if ( accessibleSymbolChain ) {
751
+ if ( forEach ( accessibleSymbolChain [ 0 ] . declarations , declaration => ! getIsDeclarationVisible ( declaration ) ) ) {
738
752
return {
739
753
accessibility : SymbolAccessibility . NotAccessible ,
740
754
errorSymbolName : symbolToString ( initialSymbol , enclosingDeclaration , meaning ) ,
@@ -819,12 +833,13 @@ module ts {
819
833
while ( symbol ) {
820
834
var isFirstName = ! symbolName ;
821
835
var meaningToLook = isFirstName ? meaning : SymbolFlags . Namespace ;
822
- var accessibleSymbol = getAccessibleSymbol ( symbol , enclosingDeclaration , meaningToLook ) ;
823
- symbolName = getSymbolName ( accessibleSymbol || symbol ) + ( isFirstName ? "" : ( "." + symbolName ) ) ;
824
- if ( accessibleSymbol && ! needsQualification ( accessibleSymbol , enclosingDeclaration , meaningToLook ) ) {
836
+ var accessibleSymbolChain = getAccessibleSymbolChain ( symbol , enclosingDeclaration , meaningToLook ) ;
837
+ var currentSymbolName = accessibleSymbolChain ? ts . map ( accessibleSymbolChain , accessibleSymbol => getSymbolName ( accessibleSymbol ) ) . join ( "." ) : getSymbolName ( symbol ) ;
838
+ symbolName = currentSymbolName + ( isFirstName ? "" : ( "." + symbolName ) ) ;
839
+ if ( accessibleSymbolChain && ! needsQualification ( accessibleSymbolChain [ 0 ] , enclosingDeclaration , accessibleSymbolChain . length === 1 ? meaningToLook : SymbolFlags . Namespace ) ) {
825
840
break ;
826
841
}
827
- symbol = accessibleSymbol ? accessibleSymbol . parent : symbol . parent ;
842
+ symbol = accessibleSymbolChain ? accessibleSymbolChain [ 0 ] . parent : symbol . parent ;
828
843
}
829
844
830
845
return symbolName ;
0 commit comments