@@ -122,6 +122,7 @@ namespace ts {
122
122
getDeclaredTypeOfSymbol,
123
123
getPropertiesOfType,
124
124
getPropertyOfType: (type, name) => getPropertyOfType(type, escapeLeadingUnderscores(name)),
125
+ getPropertyForPrivateName,
125
126
getTypeOfPropertyOfType: (type, name) => getTypeOfPropertyOfType(type, escapeLeadingUnderscores(name)),
126
127
getIndexInfoOfType,
127
128
getSignaturesOfType,
@@ -18447,38 +18448,40 @@ namespace ts {
18447
18448
return checkPropertyAccessExpressionOrQualifiedName(node, node.left, node.right);
18448
18449
}
18449
18450
18450
- function getPropertyByPrivateName (apparentType: Type, leftType: Type, right: PrivateName): Symbol | undefined {
18451
+ function getPropertyForPrivateName (apparentType: Type, leftType: Type, right: PrivateName, errorNode: Node | undefined ): Symbol | undefined {
18451
18452
let classWithShadowedPrivateName;
18452
- let klass = getContainingClass(right);
18453
- while (klass ) {
18454
- const symbolTableKey = getPropertyNameForPrivateNameDescription(klass .symbol, right.escapedText);
18453
+ let container = getContainingClass(right);
18454
+ while (container ) {
18455
+ const symbolTableKey = getPropertyNameForPrivateNameDescription(container .symbol, right.escapedText);
18455
18456
if (symbolTableKey) {
18456
18457
const prop = getPropertyOfType(apparentType, symbolTableKey);
18457
18458
if (prop) {
18458
18459
if (classWithShadowedPrivateName) {
18459
- error(
18460
- right,
18461
- Diagnostics.This_usage_of_0_refers_to_the_private_member_declared_in_its_enclosing_class_While_type_1_has_a_private_member_with_the_same_spelling_its_declaration_and_accessibility_are_distinct,
18462
- diagnosticName(right),
18463
- diagnosticName(classWithShadowedPrivateName.name || ("(anonymous)" as __String))
18464
- );
18460
+ if (errorNode) {
18461
+ error(
18462
+ errorNode,
18463
+ Diagnostics.This_usage_of_0_refers_to_the_private_member_declared_in_its_enclosing_class_While_type_1_has_a_private_member_with_the_same_spelling_its_declaration_and_accessibility_are_distinct,
18464
+ diagnosticName(right),
18465
+ diagnosticName(classWithShadowedPrivateName.name || ("(anonymous)" as __String))
18466
+ );
18467
+ }
18465
18468
return undefined;
18466
18469
}
18467
18470
return prop;
18468
18471
}
18469
18472
else {
18470
- classWithShadowedPrivateName = klass ;
18473
+ classWithShadowedPrivateName = container ;
18471
18474
}
18472
18475
}
18473
- klass = getContainingClass(klass );
18476
+ container = getContainingClass(container );
18474
18477
}
18475
18478
// If this isn't a case of shadowing, and the lhs has a property with the same
18476
18479
// private name description, then there is a privacy violation
18477
18480
if (leftType.symbol.members) {
18478
18481
const symbolTableKey = getPropertyNameForPrivateNameDescription(leftType.symbol, right.escapedText);
18479
- if ( symbolTableKey) {
18480
- const prop = getPropertyOfType(apparentType, symbolTableKey);
18481
- if (prop ) {
18482
+ const prop = getPropertyOfType(apparentType, symbolTableKey);
18483
+ if (prop) {
18484
+ if (errorNode ) {
18482
18485
error(right, Diagnostics.Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_name, symbolToString(prop), typeToString(getDeclaringClass(prop)!));
18483
18486
}
18484
18487
}
@@ -18499,7 +18502,7 @@ namespace ts {
18499
18502
return apparentType;
18500
18503
}
18501
18504
const assignmentKind = getAssignmentTargetKind(node);
18502
- const prop = isPrivateName(right) ? getPropertyByPrivateName (apparentType, leftType, right) : getPropertyOfType(apparentType, right.escapedText);
18505
+ const prop = isPrivateName(right) ? getPropertyForPrivateName (apparentType, leftType, right, /* errorNode */ right) : getPropertyOfType(apparentType, right.escapedText);
18503
18506
if (isIdentifier(left) && parentSymbol && !(prop && isConstEnumOrConstEnumOnlyModule(prop))) {
18504
18507
markAliasReferenced(parentSymbol, node);
18505
18508
}
0 commit comments