@@ -677,7 +677,7 @@ module ts {
677
677
}
678
678
679
679
// If symbol is directly available by its name in the symbol table
680
- if ( isAccessible ( symbols [ symbol . name ] ) ) {
680
+ if ( isAccessible ( lookUp ( symbols , symbol . name ) ) ) {
681
681
return symbol ;
682
682
}
683
683
@@ -700,7 +700,7 @@ module ts {
700
700
var qualify = false ;
701
701
forEachSymbolTableInScope ( enclosingDeclaration , symbolTable => {
702
702
// If symbol of this name is not available in the symbol table we are ok
703
- if ( ! symbolTable [ symbol . name ] ) {
703
+ if ( ! hasProperty ( symbolTable , symbol . name ) ) {
704
704
// Continue to the next symbol table
705
705
return false ;
706
706
}
@@ -725,6 +725,52 @@ module ts {
725
725
return qualify ;
726
726
}
727
727
728
+ function isSymbolAccessible ( symbol : Symbol , enclosingDeclaration : Node , meaning : SymbolFlags ) : SymbolAccessiblityResult {
729
+ if ( symbol && enclosingDeclaration && ! ( symbol . flags & SymbolFlags . TypeParameter ) ) {
730
+ var initialSymbol = symbol ;
731
+ var meaningToLook = meaning ;
732
+ while ( symbol ) {
733
+ // Symbol is accessible if it by itself is accessible
734
+ var accessibleSymbol = getAccessibleSymbol ( symbol , enclosingDeclaration , meaningToLook ) ;
735
+ if ( accessibleSymbol ) {
736
+ if ( forEach ( accessibleSymbol . declarations , declaration => ! isDeclarationVisible ( declaration ) ) ) {
737
+ return {
738
+ accessibility : SymbolAccessibility . NotAccessible ,
739
+ errorSymbolName : symbolToString ( initialSymbol , enclosingDeclaration , meaning ) ,
740
+ errorModuleName : symbol !== initialSymbol ? symbolToString ( symbol , enclosingDeclaration , SymbolFlags . Namespace ) : undefined
741
+ } ;
742
+ }
743
+ return { accessibility : SymbolAccessibility . Accessible } ;
744
+ }
745
+
746
+ // TODO(shkamat): Handle static method of class
747
+
748
+ // If we havent got the accessible symbol doesnt mean the symbol is actually inaccessible.
749
+ // It could be qualified symbol and hence verify the path
750
+ // eg:
751
+ // module m {
752
+ // export class c {
753
+ // }
754
+ // }
755
+ // var x: typeof m.c
756
+ // In the above example when we start with checking if typeof m.c symbol is accessible,
757
+ // we are going to see if c can be accessed in scope directly.
758
+ // But it cant, hence the accessible is going to be undefined, but that doesnt mean m.c is accessible
759
+ // It is accessible if the parent m is accessible because then m.c can be accessed through qualification
760
+ meaningToLook = SymbolFlags . Namespace ;
761
+ symbol = symbol . parent ;
762
+ }
763
+
764
+ // This is a local symbol that cannot be named
765
+ return {
766
+ accessibility : SymbolAccessibility . CannotBeNamed ,
767
+ errorSymbolName : symbolToString ( initialSymbol , enclosingDeclaration , meaning ) ,
768
+ } ;
769
+ }
770
+
771
+ return { accessibility : SymbolAccessibility . Accessible } ;
772
+ }
773
+
728
774
// Enclosing declaration is optional when we dont want to get qualified name in the enclosing declaration scope
729
775
// Meaning needs to be specified if the enclosing declaration is given
730
776
function symbolToString ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) {
@@ -760,10 +806,15 @@ module ts {
760
806
return getSymbolName ( symbol ) ;
761
807
}
762
808
809
+ function writeSymbolToTextWriter ( symbol : Symbol , enclosingDeclaration : Node , meaning : SymbolFlags , writer : TextWriter ) {
810
+ writer . write ( symbolToString ( symbol , enclosingDeclaration , meaning ) ) ;
811
+ }
812
+
763
813
function createSingleLineTextWriter ( ) {
764
814
var result = "" ;
765
815
return {
766
816
write ( s : string ) { result += s ; } ,
817
+ writeSymbol ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) { writeSymbolToTextWriter ( symbol , enclosingDeclaration , meaning , this ) ; } ,
767
818
writeLine ( ) { result += " " ; } ,
768
819
increaseIndent ( ) { } ,
769
820
decreaseIndent ( ) { } ,
@@ -790,7 +841,7 @@ module ts {
790
841
writeTypeReference ( < TypeReference > type ) ;
791
842
}
792
843
else if ( type . flags & ( TypeFlags . Class | TypeFlags . Interface | TypeFlags . Enum | TypeFlags . TypeParameter ) ) {
793
- writer . write ( symbolToString ( type . symbol , enclosingDeclaration , SymbolFlags . Type ) ) ;
844
+ writer . writeSymbol ( type . symbol , enclosingDeclaration , SymbolFlags . Type ) ;
794
845
}
795
846
else if ( type . flags & TypeFlags . Anonymous ) {
796
847
writeAnonymousType ( < ObjectType > type , allowFunctionOrConstructorTypeLiteral ) ;
@@ -812,7 +863,7 @@ module ts {
812
863
writer . write ( "[]" ) ;
813
864
}
814
865
else {
815
- writer . write ( symbolToString ( type . target . symbol , enclosingDeclaration , SymbolFlags . Type ) ) ;
866
+ writer . writeSymbol ( type . target . symbol , enclosingDeclaration , SymbolFlags . Type ) ;
816
867
writer . write ( "<" ) ;
817
868
for ( var i = 0 ; i < type . typeArguments . length ; i ++ ) {
818
869
if ( i > 0 ) {
@@ -846,7 +897,7 @@ module ts {
846
897
847
898
function writeTypeofSymbol ( type : ObjectType ) {
848
899
writer . write ( "typeof " ) ;
849
- writer . write ( symbolToString ( type . symbol , enclosingDeclaration , SymbolFlags . Value ) ) ;
900
+ writer . writeSymbol ( type . symbol , enclosingDeclaration , SymbolFlags . Value ) ;
850
901
}
851
902
852
903
function writeLiteralType ( type : ObjectType , allowFunctionOrConstructorTypeLiteral : boolean ) {
@@ -902,7 +953,7 @@ module ts {
902
953
if ( p . flags & ( SymbolFlags . Function | SymbolFlags . Method ) && ! getPropertiesOfType ( t ) . length ) {
903
954
var signatures = getSignaturesOfType ( t , SignatureKind . Call ) ;
904
955
for ( var j = 0 ; j < signatures . length ; j ++ ) {
905
- writer . write ( symbolToString ( p ) ) ;
956
+ writer . writeSymbol ( p ) ;
906
957
if ( isOptionalProperty ( p ) ) {
907
958
writer . write ( "?" ) ;
908
959
}
@@ -912,7 +963,7 @@ module ts {
912
963
}
913
964
}
914
965
else {
915
- writer . write ( symbolToString ( p ) ) ;
966
+ writer . writeSymbol ( p ) ;
916
967
if ( isOptionalProperty ( p ) ) {
917
968
writer . write ( "?" ) ;
918
969
}
@@ -934,7 +985,7 @@ module ts {
934
985
writer . write ( ", " ) ;
935
986
}
936
987
var tp = signature . typeParameters [ i ] ;
937
- writer . write ( symbolToString ( tp . symbol ) ) ;
988
+ writer . writeSymbol ( tp . symbol ) ;
938
989
var constraint = getConstraintOfTypeParameter ( tp ) ;
939
990
if ( constraint ) {
940
991
writer . write ( " extends " ) ;
@@ -952,7 +1003,7 @@ module ts {
952
1003
if ( getDeclarationFlagsFromSymbol ( p ) & NodeFlags . Rest ) {
953
1004
writer . write ( "..." ) ;
954
1005
}
955
- writer . write ( symbolToString ( p ) ) ;
1006
+ writer . writeSymbol ( p ) ;
956
1007
if ( p . valueDeclaration . flags & NodeFlags . QuestionMark || ( < VariableDeclaration > p . valueDeclaration ) . initializer ) {
957
1008
writer . write ( "?" ) ;
958
1009
}
@@ -6695,7 +6746,9 @@ module ts {
6695
6746
isDeclarationVisible : isDeclarationVisible ,
6696
6747
isImplementationOfOverload : isImplementationOfOverload ,
6697
6748
writeTypeAtLocation : writeTypeAtLocation ,
6698
- writeReturnTypeOfSignatureDeclaration : writeReturnTypeOfSignatureDeclaration
6749
+ writeReturnTypeOfSignatureDeclaration : writeReturnTypeOfSignatureDeclaration ,
6750
+ writeSymbol : writeSymbolToTextWriter ,
6751
+ isSymbolAccessible : isSymbolAccessible
6699
6752
} ;
6700
6753
checkProgram ( ) ;
6701
6754
return emitFiles ( resolver ) ;
0 commit comments