Skip to content

Commit aaf818b

Browse files
committed
Treat negative numbers as non-dynamic names
1 parent 17f6f77 commit aaf818b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/compiler/binder.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ namespace ts {
274274
if (isStringOrNumericLiteralLike(nameExpression)) {
275275
return escapeLeadingUnderscores(nameExpression.text);
276276
}
277+
if (isSignedNumericLiteral(nameExpression)) {
278+
return tokenToString(nameExpression.operator) + nameExpression.operand.text as __String;
279+
}
277280

278281
Debug.assert(isWellKnownSymbolSyntactically(nameExpression));
279282
return getPropertyNameForKnownSymbolName(idText((<PropertyAccessExpression>nameExpression).name));

src/compiler/utilities.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,11 +2705,19 @@ namespace ts {
27052705
return isStringLiteralLike(node) || isNumericLiteral(node);
27062706
}
27072707

2708+
export function isSignedNumericLiteral(node: Node): node is PrefixUnaryExpression & { operand: NumericLiteral } {
2709+
return isPrefixUnaryExpression(node) && (node.operator === SyntaxKind.PlusToken || node.operator === SyntaxKind.MinusToken) && isNumericLiteral(node.operand);
2710+
}
2711+
27082712
/**
2709-
* A declaration has a dynamic name if both of the following are true:
2710-
* 1. The declaration has a computed property name
2711-
* 2. The computed name is *not* expressed as Symbol.<name>, where name
2712-
* is a property of the Symbol constructor that denotes a built in
2713+
* A declaration has a dynamic name if all of the following are true:
2714+
* 1. The declaration has a computed property name.
2715+
* 2. The computed name is *not* expressed as a StringLiteral.
2716+
* 3. The computed name is *not* expressed as a NumericLiteral.
2717+
* 4. The computed name is *not* expressed as a PlusToken or MinusToken
2718+
* immediately followed by a NumericLiteral.
2719+
* 5. The computed name is *not* expressed as `Symbol.<name>`, where `<name>`
2720+
* is a property of the Symbol constructor that denotes a built-in
27132721
* Symbol.
27142722
*/
27152723
export function hasDynamicName(declaration: Declaration): declaration is DynamicNamedDeclaration {
@@ -2720,6 +2728,7 @@ namespace ts {
27202728
export function isDynamicName(name: DeclarationName): boolean {
27212729
return name.kind === SyntaxKind.ComputedPropertyName &&
27222730
!isStringOrNumericLiteralLike(name.expression) &&
2731+
!isSignedNumericLiteral(name.expression) &&
27232732
!isWellKnownSymbolSyntactically(name.expression);
27242733
}
27252734

0 commit comments

Comments
 (0)