mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-26 10:43:51 -05:00
Treat negative numbers as non-dynamic names
This commit is contained in:
@@ -274,6 +274,9 @@ namespace ts {
|
||||
if (isStringOrNumericLiteralLike(nameExpression)) {
|
||||
return escapeLeadingUnderscores(nameExpression.text);
|
||||
}
|
||||
if (isSignedNumericLiteral(nameExpression)) {
|
||||
return tokenToString(nameExpression.operator) + nameExpression.operand.text as __String;
|
||||
}
|
||||
|
||||
Debug.assert(isWellKnownSymbolSyntactically(nameExpression));
|
||||
return getPropertyNameForKnownSymbolName(idText((<PropertyAccessExpression>nameExpression).name));
|
||||
|
||||
@@ -2705,11 +2705,19 @@ namespace ts {
|
||||
return isStringLiteralLike(node) || isNumericLiteral(node);
|
||||
}
|
||||
|
||||
export function isSignedNumericLiteral(node: Node): node is PrefixUnaryExpression & { operand: NumericLiteral } {
|
||||
return isPrefixUnaryExpression(node) && (node.operator === SyntaxKind.PlusToken || node.operator === SyntaxKind.MinusToken) && isNumericLiteral(node.operand);
|
||||
}
|
||||
|
||||
/**
|
||||
* A declaration has a dynamic name if both of the following are true:
|
||||
* 1. The declaration has a computed property name
|
||||
* 2. The computed name is *not* expressed as Symbol.<name>, where name
|
||||
* is a property of the Symbol constructor that denotes a built in
|
||||
* A declaration has a dynamic name if all of the following are true:
|
||||
* 1. The declaration has a computed property name.
|
||||
* 2. The computed name is *not* expressed as a StringLiteral.
|
||||
* 3. The computed name is *not* expressed as a NumericLiteral.
|
||||
* 4. The computed name is *not* expressed as a PlusToken or MinusToken
|
||||
* immediately followed by a NumericLiteral.
|
||||
* 5. The computed name is *not* expressed as `Symbol.<name>`, where `<name>`
|
||||
* is a property of the Symbol constructor that denotes a built-in
|
||||
* Symbol.
|
||||
*/
|
||||
export function hasDynamicName(declaration: Declaration): declaration is DynamicNamedDeclaration {
|
||||
@@ -2720,6 +2728,7 @@ namespace ts {
|
||||
export function isDynamicName(name: DeclarationName): boolean {
|
||||
return name.kind === SyntaxKind.ComputedPropertyName &&
|
||||
!isStringOrNumericLiteralLike(name.expression) &&
|
||||
!isSignedNumericLiteral(name.expression) &&
|
||||
!isWellKnownSymbolSyntactically(name.expression);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user