From 5c6a007715b7fc6848c0c7db6d974fadda9f244d Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 26 Feb 2016 14:40:30 -0800 Subject: [PATCH] Move `checkClassPropertyAccess` call to `checkVariableLikeDeclaration` --- src/compiler/checker.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 64c21c0b638..c2a14e5b9a0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2607,8 +2607,7 @@ namespace ts { // Return the inferred type for a binding element function getTypeForBindingElement(declaration: BindingElement): Type { const pattern = declaration.parent; - const parent = pattern.parent; - const parentType = getTypeForBindingElementParent(parent); + const parentType = getTypeForBindingElementParent(pattern.parent); // If parent has the unknown (error) type, then so does this binding element if (parentType === unknownType) { return unknownType; @@ -2643,11 +2642,6 @@ namespace ts { error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name)); return unknownType; } - - const property = getPropertyOfType(parentType, text); - if (parent && parent.initializer && property && getParentOfSymbol(property)) { - checkClassPropertyAccess(parent, parent.initializer, parentType, property); - } } else { // This elementType will be used if the specific property corresponding to this index is not @@ -13314,6 +13308,15 @@ namespace ts { if (node.propertyName && node.propertyName.kind === SyntaxKind.ComputedPropertyName) { checkComputedPropertyName(node.propertyName); } + + // check private/protected variable access + const parent = (node.parent).parent; + const parentType = getTypeForBindingElementParent(parent); + const name = node.propertyName || node.name; + const property = getPropertyOfType(parentType, getTextOfPropertyName(name)); + if (parent.initializer && property && getParentOfSymbol(property)) { + checkClassPropertyAccess(parent, parent.initializer, parentType, property); + } } // For a binding pattern, check contained binding elements