Skip to content

Commit 5c6a007

Browse files
committed
Move checkClassPropertyAccess call to checkVariableLikeDeclaration
1 parent a1c0486 commit 5c6a007

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,8 +2607,7 @@ namespace ts {
26072607
// Return the inferred type for a binding element
26082608
function getTypeForBindingElement(declaration: BindingElement): Type {
26092609
const pattern = <BindingPattern>declaration.parent;
2610-
const parent = <VariableLikeDeclaration>pattern.parent;
2611-
const parentType = getTypeForBindingElementParent(parent);
2610+
const parentType = getTypeForBindingElementParent(<VariableLikeDeclaration>pattern.parent);
26122611
// If parent has the unknown (error) type, then so does this binding element
26132612
if (parentType === unknownType) {
26142613
return unknownType;
@@ -2643,11 +2642,6 @@ namespace ts {
26432642
error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name));
26442643
return unknownType;
26452644
}
2646-
2647-
const property = getPropertyOfType(parentType, text);
2648-
if (parent && parent.initializer && property && getParentOfSymbol(property)) {
2649-
checkClassPropertyAccess(parent, parent.initializer, parentType, property);
2650-
}
26512645
}
26522646
else {
26532647
// This elementType will be used if the specific property corresponding to this index is not
@@ -13314,6 +13308,15 @@ namespace ts {
1331413308
if (node.propertyName && node.propertyName.kind === SyntaxKind.ComputedPropertyName) {
1331513309
checkComputedPropertyName(<ComputedPropertyName>node.propertyName);
1331613310
}
13311+
13312+
// check private/protected variable access
13313+
const parent = <VariableLikeDeclaration>(<BindingPattern>node.parent).parent;
13314+
const parentType = getTypeForBindingElementParent(parent);
13315+
const name = node.propertyName || <Identifier>node.name;
13316+
const property = getPropertyOfType(parentType, getTextOfPropertyName(name));
13317+
if (parent.initializer && property && getParentOfSymbol(property)) {
13318+
checkClassPropertyAccess(parent, parent.initializer, parentType, property);
13319+
}
1331713320
}
1331813321

1331913322
// For a binding pattern, check contained binding elements

0 commit comments

Comments
 (0)