@@ -2713,12 +2713,12 @@ module ts {
2713
2713
if ( sourceProp === targetProp ) {
2714
2714
return true ;
2715
2715
}
2716
- var sourcePropVisibility = getDeclarationFlagsFromSymbol ( sourceProp ) & ( NodeFlags . Private | | NodeFlags . Protected ) ;
2717
- var targetPropVisibility = getDeclarationFlagsFromSymbol ( targetProp ) & ( NodeFlags . Private | | NodeFlags . Protected ) ;
2718
- if ( sourcePropVisibility !== targetPropVisibility ) {
2716
+ var sourcePropAccessibility = getDeclarationFlagsFromSymbol ( sourceProp ) & ( NodeFlags . Private | NodeFlags . Protected ) ;
2717
+ var targetPropAccessibility = getDeclarationFlagsFromSymbol ( targetProp ) & ( NodeFlags . Private | NodeFlags . Protected ) ;
2718
+ if ( sourcePropAccessibility !== targetPropAccessibility ) {
2719
2719
return false ;
2720
2720
}
2721
- if ( sourcePropVisibility ) {
2721
+ if ( sourcePropAccessibility ) {
2722
2722
return getTargetSymbol ( sourceProp ) === getTargetSymbol ( targetProp ) && relate ( getTypeOfSymbol ( sourceProp ) , getTypeOfSymbol ( targetProp ) , reportErrors ) ;
2723
2723
}
2724
2724
else {
@@ -4011,26 +4011,35 @@ module ts {
4011
4011
4012
4012
function isClassPropertyAccessible ( node : PropertyAccess , type : Type , prop : Symbol ) : boolean {
4013
4013
var flags = getDeclarationFlagsFromSymbol ( prop ) ;
4014
+ // Public properties are always accessible
4014
4015
if ( ! ( flags & ( NodeFlags . Private | NodeFlags . Protected ) ) ) {
4015
4016
return true ;
4016
4017
}
4018
+ // Property is known to be private or protected at this point
4019
+ // Private and protected properties are never accessible outside a class declaration
4017
4020
var enclosingClassDeclaration = getAncestor ( node , SyntaxKind . ClassDeclaration ) ;
4018
4021
if ( ! enclosingClassDeclaration ) {
4019
4022
return false ;
4020
4023
}
4024
+ // Get the declaring and enclosing class instance types
4021
4025
var declaringClass = < InterfaceType > getDeclaredTypeOfSymbol ( prop . parent ) ;
4022
4026
var enclosingClass = < InterfaceType > getDeclaredTypeOfSymbol ( getSymbolOfNode ( enclosingClassDeclaration ) ) ;
4027
+ // Private property is accessible if declaring and enclosing class are the same
4023
4028
if ( flags & NodeFlags . Private ) {
4024
4029
return declaringClass === enclosingClass ;
4025
4030
}
4031
+ // Property is known to be protected at this point
4032
+ // All protected properties of a supertype are accessible in a super access
4026
4033
if ( node . left . kind === SyntaxKind . SuperKeyword ) {
4027
4034
return true ;
4028
4035
}
4036
+ // An instance property must be accessed through an instance of the enclosing class
4029
4037
if ( ! ( flags & NodeFlags . Static ) ) {
4030
4038
if ( ! ( getTargetType ( type ) . flags & ( TypeFlags . Class | TypeFlags . Interface ) && hasBaseType ( < InterfaceType > type , enclosingClass ) ) ) {
4031
4039
return false ;
4032
4040
}
4033
4041
}
4042
+ // A protected property is accessible in the declaring class and classes derived from it
4034
4043
return hasBaseType ( enclosingClass , declaringClass ) ;
4035
4044
}
4036
4045
0 commit comments