diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 660b19a5872..38d5ed24eae 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -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((nameExpression).name)); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ae5b60cd864..f1cee2d118a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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., 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.`, where `` + * 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); }