Addressing CR feedback
This commit is contained in:
parent
ce6b6234ef
commit
4aa04a93b3
|
@ -2713,12 +2713,12 @@ module ts {
|
||||||
if (sourceProp === targetProp) {
|
if (sourceProp === targetProp) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var sourcePropVisibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private || NodeFlags.Protected);
|
var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private | NodeFlags.Protected);
|
||||||
var targetPropVisibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private || NodeFlags.Protected);
|
var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected);
|
||||||
if (sourcePropVisibility !== targetPropVisibility) {
|
if (sourcePropAccessibility !== targetPropAccessibility) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (sourcePropVisibility) {
|
if (sourcePropAccessibility) {
|
||||||
return getTargetSymbol(sourceProp) === getTargetSymbol(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
|
return getTargetSymbol(sourceProp) === getTargetSymbol(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -4011,26 +4011,35 @@ module ts {
|
||||||
|
|
||||||
function isClassPropertyAccessible(node: PropertyAccess, type: Type, prop: Symbol): boolean {
|
function isClassPropertyAccessible(node: PropertyAccess, type: Type, prop: Symbol): boolean {
|
||||||
var flags = getDeclarationFlagsFromSymbol(prop);
|
var flags = getDeclarationFlagsFromSymbol(prop);
|
||||||
|
// Public properties are always accessible
|
||||||
if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) {
|
if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// Property is known to be private or protected at this point
|
||||||
|
// Private and protected properties are never accessible outside a class declaration
|
||||||
var enclosingClassDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration);
|
var enclosingClassDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration);
|
||||||
if (!enclosingClassDeclaration) {
|
if (!enclosingClassDeclaration) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Get the declaring and enclosing class instance types
|
||||||
var declaringClass = <InterfaceType>getDeclaredTypeOfSymbol(prop.parent);
|
var declaringClass = <InterfaceType>getDeclaredTypeOfSymbol(prop.parent);
|
||||||
var enclosingClass = <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration));
|
var enclosingClass = <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration));
|
||||||
|
// Private property is accessible if declaring and enclosing class are the same
|
||||||
if (flags & NodeFlags.Private) {
|
if (flags & NodeFlags.Private) {
|
||||||
return declaringClass === enclosingClass;
|
return declaringClass === enclosingClass;
|
||||||
}
|
}
|
||||||
|
// Property is known to be protected at this point
|
||||||
|
// All protected properties of a supertype are accessible in a super access
|
||||||
if (node.left.kind === SyntaxKind.SuperKeyword) {
|
if (node.left.kind === SyntaxKind.SuperKeyword) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// An instance property must be accessed through an instance of the enclosing class
|
||||||
if (!(flags & NodeFlags.Static)) {
|
if (!(flags & NodeFlags.Static)) {
|
||||||
if (!(getTargetType(type).flags & (TypeFlags.Class | TypeFlags.Interface) && hasBaseType(<InterfaceType>type, enclosingClass))) {
|
if (!(getTargetType(type).flags & (TypeFlags.Class | TypeFlags.Interface) && hasBaseType(<InterfaceType>type, enclosingClass))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// A protected property is accessible in the declaring class and classes derived from it
|
||||||
return hasBaseType(enclosingClass, declaringClass);
|
return hasBaseType(enclosingClass, declaringClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1012,18 +1012,18 @@
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 2441
|
"code": 2441
|
||||||
},
|
},
|
||||||
"Types have separate declarations of a private property '{0}'.": {
|
"Types have separate declarations of a private property '{0}'.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 2442
|
"code": 2442
|
||||||
},
|
},
|
||||||
"Property '{0}' is protected but type '{1}' is not derived from type '{2}'.": {
|
"Property '{0}' is protected but type '{1}' is not a class derived from type '{2}'.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 2443
|
"code": 2443
|
||||||
},
|
},
|
||||||
"Property '{0}' is protected in type '{1}' but public in type '{2}'.": {
|
"Property '{0}' is protected in type '{1}' but public in type '{2}'.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 2444
|
"code": 2444
|
||||||
},
|
},
|
||||||
|
|
||||||
"Import declaration '{0}' is using private name '{1}'.": {
|
"Import declaration '{0}' is using private name '{1}'.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
|
|
Loading…
Reference in a new issue