Skip to content

Commit b70aa22

Browse files
author
Andy
authored
getTextOfPropertyName: Assert input value is a PropertyName (#21981)
1 parent cfc234f commit b70aa22

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21909,11 +21909,13 @@ namespace ts {
2190921909
// check private/protected variable access
2191021910
const parent = node.parent.parent;
2191121911
const parentType = getTypeForBindingElementParent(parent);
21912-
const name = node.propertyName || <Identifier>node.name;
21913-
const property = getPropertyOfType(parentType, getTextOfPropertyName(name));
21914-
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
21915-
if (parent.initializer && property) {
21916-
checkPropertyAccessibility(parent, parent.initializer, parentType, property);
21912+
const name = node.propertyName || node.name;
21913+
if (!isBindingPattern(name)) {
21914+
const property = getPropertyOfType(parentType, getTextOfPropertyName(name));
21915+
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
21916+
if (parent.initializer && property) {
21917+
checkPropertyAccessibility(parent, parent.initializer, parentType, property);
21918+
}
2191721919
}
2191821920
}
2191921921

src/compiler/utilities.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,17 +570,15 @@ namespace ts {
570570
export function getTextOfPropertyName(name: PropertyName): __String {
571571
switch (name.kind) {
572572
case SyntaxKind.Identifier:
573-
return (<Identifier>name).escapedText;
573+
return name.escapedText;
574574
case SyntaxKind.StringLiteral:
575575
case SyntaxKind.NumericLiteral:
576-
return escapeLeadingUnderscores((<LiteralExpression>name).text);
576+
return escapeLeadingUnderscores(name.text);
577577
case SyntaxKind.ComputedPropertyName:
578-
if (isStringOrNumericLiteral((<ComputedPropertyName>name).expression)) {
579-
return escapeLeadingUnderscores((<LiteralExpression>(<ComputedPropertyName>name).expression).text);
580-
}
578+
return isStringOrNumericLiteral(name.expression) ? escapeLeadingUnderscores(name.expression.text) : undefined;
579+
default:
580+
Debug.assertNever(name);
581581
}
582-
583-
return undefined;
584582
}
585583

586584
export function entityNameToString(name: EntityNameOrEntityNameExpression): string {

0 commit comments

Comments
 (0)