@@ -677,7 +677,7 @@ module ts {
677677 }
678678
679679 // 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 ) ) ) {
681681 return symbol ;
682682 }
683683
@@ -700,7 +700,7 @@ module ts {
700700 var qualify = false ;
701701 forEachSymbolTableInScope ( enclosingDeclaration , symbolTable => {
702702 // 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 ) ) {
704704 // Continue to the next symbol table
705705 return false ;
706706 }
@@ -725,6 +725,52 @@ module ts {
725725 return qualify ;
726726 }
727727
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+
728774 // Enclosing declaration is optional when we dont want to get qualified name in the enclosing declaration scope
729775 // Meaning needs to be specified if the enclosing declaration is given
730776 function symbolToString ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) {
@@ -760,10 +806,15 @@ module ts {
760806 return getSymbolName ( symbol ) ;
761807 }
762808
809+ function writeSymbolToTextWriter ( symbol : Symbol , enclosingDeclaration : Node , meaning : SymbolFlags , writer : TextWriter ) {
810+ writer . write ( symbolToString ( symbol , enclosingDeclaration , meaning ) ) ;
811+ }
812+
763813 function createSingleLineTextWriter ( ) {
764814 var result = "" ;
765815 return {
766816 write ( s : string ) { result += s ; } ,
817+ writeSymbol ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) { writeSymbolToTextWriter ( symbol , enclosingDeclaration , meaning , this ) ; } ,
767818 writeLine ( ) { result += " " ; } ,
768819 increaseIndent ( ) { } ,
769820 decreaseIndent ( ) { } ,
@@ -790,7 +841,7 @@ module ts {
790841 writeTypeReference ( < TypeReference > type ) ;
791842 }
792843 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 ) ;
794845 }
795846 else if ( type . flags & TypeFlags . Anonymous ) {
796847 writeAnonymousType ( < ObjectType > type , allowFunctionOrConstructorTypeLiteral ) ;
@@ -812,7 +863,7 @@ module ts {
812863 writer . write ( "[]" ) ;
813864 }
814865 else {
815- writer . write ( symbolToString ( type . target . symbol , enclosingDeclaration , SymbolFlags . Type ) ) ;
866+ writer . writeSymbol ( type . target . symbol , enclosingDeclaration , SymbolFlags . Type ) ;
816867 writer . write ( "<" ) ;
817868 for ( var i = 0 ; i < type . typeArguments . length ; i ++ ) {
818869 if ( i > 0 ) {
@@ -846,7 +897,7 @@ module ts {
846897
847898 function writeTypeofSymbol ( type : ObjectType ) {
848899 writer . write ( "typeof " ) ;
849- writer . write ( symbolToString ( type . symbol , enclosingDeclaration , SymbolFlags . Value ) ) ;
900+ writer . writeSymbol ( type . symbol , enclosingDeclaration , SymbolFlags . Value ) ;
850901 }
851902
852903 function writeLiteralType ( type : ObjectType , allowFunctionOrConstructorTypeLiteral : boolean ) {
@@ -902,7 +953,7 @@ module ts {
902953 if ( p . flags & ( SymbolFlags . Function | SymbolFlags . Method ) && ! getPropertiesOfType ( t ) . length ) {
903954 var signatures = getSignaturesOfType ( t , SignatureKind . Call ) ;
904955 for ( var j = 0 ; j < signatures . length ; j ++ ) {
905- writer . write ( symbolToString ( p ) ) ;
956+ writer . writeSymbol ( p ) ;
906957 if ( isOptionalProperty ( p ) ) {
907958 writer . write ( "?" ) ;
908959 }
@@ -912,7 +963,7 @@ module ts {
912963 }
913964 }
914965 else {
915- writer . write ( symbolToString ( p ) ) ;
966+ writer . writeSymbol ( p ) ;
916967 if ( isOptionalProperty ( p ) ) {
917968 writer . write ( "?" ) ;
918969 }
@@ -934,7 +985,7 @@ module ts {
934985 writer . write ( ", " ) ;
935986 }
936987 var tp = signature . typeParameters [ i ] ;
937- writer . write ( symbolToString ( tp . symbol ) ) ;
988+ writer . writeSymbol ( tp . symbol ) ;
938989 var constraint = getConstraintOfTypeParameter ( tp ) ;
939990 if ( constraint ) {
940991 writer . write ( " extends " ) ;
@@ -952,7 +1003,7 @@ module ts {
9521003 if ( getDeclarationFlagsFromSymbol ( p ) & NodeFlags . Rest ) {
9531004 writer . write ( "..." ) ;
9541005 }
955- writer . write ( symbolToString ( p ) ) ;
1006+ writer . writeSymbol ( p ) ;
9561007 if ( p . valueDeclaration . flags & NodeFlags . QuestionMark || ( < VariableDeclaration > p . valueDeclaration ) . initializer ) {
9571008 writer . write ( "?" ) ;
9581009 }
@@ -6695,7 +6746,9 @@ module ts {
66956746 isDeclarationVisible : isDeclarationVisible ,
66966747 isImplementationOfOverload : isImplementationOfOverload ,
66976748 writeTypeAtLocation : writeTypeAtLocation ,
6698- writeReturnTypeOfSignatureDeclaration : writeReturnTypeOfSignatureDeclaration
6749+ writeReturnTypeOfSignatureDeclaration : writeReturnTypeOfSignatureDeclaration ,
6750+ writeSymbol : writeSymbolToTextWriter ,
6751+ isSymbolAccessible : isSymbolAccessible
66996752 } ;
67006753 checkProgram ( ) ;
67016754 return emitFiles ( resolver ) ;
0 commit comments