diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2df80926c14..b817d9b965a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21909,11 +21909,13 @@ namespace ts { // 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)); - markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference. - if (parent.initializer && property) { - checkPropertyAccessibility(parent, parent.initializer, parentType, property); + const name = node.propertyName || node.name; + if (!isBindingPattern(name)) { + const property = getPropertyOfType(parentType, getTextOfPropertyName(name)); + markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference. + if (parent.initializer && property) { + checkPropertyAccessibility(parent, parent.initializer, parentType, property); + } } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9023e1e62f3..4e5b5700d29 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -570,17 +570,15 @@ namespace ts { export function getTextOfPropertyName(name: PropertyName): __String { switch (name.kind) { case SyntaxKind.Identifier: - return (name).escapedText; + return name.escapedText; case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: - return escapeLeadingUnderscores((name).text); + return escapeLeadingUnderscores(name.text); case SyntaxKind.ComputedPropertyName: - if (isStringOrNumericLiteral((name).expression)) { - return escapeLeadingUnderscores(((name).expression).text); - } + return isStringOrNumericLiteral(name.expression) ? escapeLeadingUnderscores(name.expression.text) : undefined; + default: + Debug.assertNever(name); } - - return undefined; } export function entityNameToString(name: EntityNameOrEntityNameExpression): string {