mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Allow Infinity and NaN to be used as an Enum property identifier
This commit is contained in:
parent
4685646281
commit
088da9ea9d
@ -10033,6 +10033,10 @@ namespace ts {
|
||||
return isTypeAny(type) || isTypeOfKind(type, kind);
|
||||
}
|
||||
|
||||
function isInfinityOrNaNString(name: string) : boolean {
|
||||
return 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);
|
||||
}
|
||||
}
|
||||
|
||||
11
tests/baselines/reference/enumWithInfinityProperty.js
Normal file
11
tests/baselines/reference/enumWithInfinityProperty.js
Normal file
@ -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))
|
||||
}
|
||||
|
||||
9
tests/baselines/reference/enumWithInfinityProperty.types
Normal file
9
tests/baselines/reference/enumWithInfinityProperty.types
Normal file
@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/enumWithInfinityProperty.ts ===
|
||||
enum A {
|
||||
>A : A
|
||||
|
||||
Infinity = 1
|
||||
>Infinity : A
|
||||
>1 : number
|
||||
}
|
||||
|
||||
11
tests/baselines/reference/enumWithNaNProperty.js
Normal file
11
tests/baselines/reference/enumWithNaNProperty.js
Normal file
@ -0,0 +1,11 @@
|
||||
//// [enumWithNaNProperty.ts]
|
||||
enum A {
|
||||
NaN = 1
|
||||
}
|
||||
|
||||
|
||||
//// [enumWithNaNProperty.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
A[A["NaN"] = 1] = "NaN";
|
||||
})(A || (A = {}));
|
||||
8
tests/baselines/reference/enumWithNaNProperty.symbols
Normal file
8
tests/baselines/reference/enumWithNaNProperty.symbols
Normal file
@ -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))
|
||||
}
|
||||
|
||||
9
tests/baselines/reference/enumWithNaNProperty.types
Normal file
9
tests/baselines/reference/enumWithNaNProperty.types
Normal file
@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/enumWithNaNProperty.ts ===
|
||||
enum A {
|
||||
>A : A
|
||||
|
||||
NaN = 1
|
||||
>NaN : A
|
||||
>1 : number
|
||||
}
|
||||
|
||||
3
tests/cases/compiler/enumWithInfinityProperty.ts
Normal file
3
tests/cases/compiler/enumWithInfinityProperty.ts
Normal file
@ -0,0 +1,3 @@
|
||||
enum A {
|
||||
Infinity = 1
|
||||
}
|
||||
3
tests/cases/compiler/enumWithNaNProperty.ts
Normal file
3
tests/cases/compiler/enumWithNaNProperty.ts
Normal file
@ -0,0 +1,3 @@
|
||||
enum A {
|
||||
NaN = 1
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user