Merge pull request #10749 from fabiancook/master

Allow Infinity and NaN to be used as an Enum property identifier
This commit is contained in:
Nathan Shively-Sanders
2016-09-07 15:50:18 -07:00
committed by GitHub
13 changed files with 96 additions and 1 deletions
+5 -1
View File
@@ -10033,6 +10033,10 @@ namespace ts {
return isTypeAny(type) || isTypeOfKind(type, kind);
}
function isInfinityOrNaNString(name: string): boolean {
return name === "Infinity" || name === "-Infinity" || name === "NaN";
}
function isNumericLiteralName(name: string) {
// The intent of numeric names is that
// - they are names with text in a numeric form, and that
@@ -16848,7 +16852,7 @@ namespace ts {
}
else {
const text = getTextOfPropertyName(<PropertyName>member.name);
if (isNumericLiteralName(text)) {
if (isNumericLiteralName(text) && !isInfinityOrNaNString(text)) {
error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
}
}
@@ -0,0 +1,11 @@
//// [enumWithInfinityProperty.ts]
enum A {
Infinity = 1
}
//// [enumWithInfinityProperty.js]
var A;
(function (A) {
A[A["Infinity"] = 1] = "Infinity";
})(A || (A = {}));
@@ -0,0 +1,8 @@
=== tests/cases/compiler/enumWithInfinityProperty.ts ===
enum A {
>A : Symbol(A, Decl(enumWithInfinityProperty.ts, 0, 0))
Infinity = 1
>Infinity : Symbol(A.Infinity, Decl(enumWithInfinityProperty.ts, 0, 8))
}
@@ -0,0 +1,9 @@
=== tests/cases/compiler/enumWithInfinityProperty.ts ===
enum A {
>A : A
Infinity = 1
>Infinity : A
>1 : number
}
@@ -0,0 +1,11 @@
//// [enumWithNaNProperty.ts]
enum A {
NaN = 1
}
//// [enumWithNaNProperty.js]
var A;
(function (A) {
A[A["NaN"] = 1] = "NaN";
})(A || (A = {}));
@@ -0,0 +1,8 @@
=== tests/cases/compiler/enumWithNaNProperty.ts ===
enum A {
>A : Symbol(A, Decl(enumWithNaNProperty.ts, 0, 0))
NaN = 1
>NaN : Symbol(A.NaN, Decl(enumWithNaNProperty.ts, 0, 8))
}
@@ -0,0 +1,9 @@
=== tests/cases/compiler/enumWithNaNProperty.ts ===
enum A {
>A : A
NaN = 1
>NaN : A
>1 : number
}
@@ -0,0 +1,11 @@
//// [enumWithNegativeInfinityProperty.ts]
enum A {
"-Infinity" = 1
}
//// [enumWithNegativeInfinityProperty.js]
var A;
(function (A) {
A[A["-Infinity"] = 1] = "-Infinity";
})(A || (A = {}));
@@ -0,0 +1,7 @@
=== tests/cases/compiler/enumWithNegativeInfinityProperty.ts ===
enum A {
>A : Symbol(A, Decl(enumWithNegativeInfinityProperty.ts, 0, 0))
"-Infinity" = 1
}
@@ -0,0 +1,8 @@
=== tests/cases/compiler/enumWithNegativeInfinityProperty.ts ===
enum A {
>A : A
"-Infinity" = 1
>1 : number
}
@@ -0,0 +1,3 @@
enum A {
Infinity = 1
}
@@ -0,0 +1,3 @@
enum A {
NaN = 1
}
@@ -0,0 +1,3 @@
enum A {
"-Infinity" = 1
}