getTextOfPropertyName: Assert input value is a PropertyName (#21981)

This commit is contained in:
Andy
2018-02-16 10:48:57 -08:00
committed by GitHub
parent cfc234f959
commit b70aa229c6
2 changed files with 12 additions and 12 deletions
+7 -5
View File
@@ -21909,11 +21909,13 @@ namespace ts {
// check private/protected variable access
const parent = node.parent.parent;
const parentType = getTypeForBindingElementParent(parent);
const name = node.propertyName || <Identifier>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);
}
}
}
+5 -7
View File
@@ -570,17 +570,15 @@ namespace ts {
export function getTextOfPropertyName(name: PropertyName): __String {
switch (name.kind) {
case SyntaxKind.Identifier:
return (<Identifier>name).escapedText;
return name.escapedText;
case SyntaxKind.StringLiteral:
case SyntaxKind.NumericLiteral:
return escapeLeadingUnderscores((<LiteralExpression>name).text);
return escapeLeadingUnderscores(name.text);
case SyntaxKind.ComputedPropertyName:
if (isStringOrNumericLiteral((<ComputedPropertyName>name).expression)) {
return escapeLeadingUnderscores((<LiteralExpression>(<ComputedPropertyName>name).expression).text);
}
return isStringOrNumericLiteral(name.expression) ? escapeLeadingUnderscores(name.expression.text) : undefined;
default:
Debug.assertNever(name);
}
return undefined;
}
export function entityNameToString(name: EntityNameOrEntityNameExpression): string {