Skip to content

Commit 8075e6e

Browse files
committed
Add test for enum unicode case
1 parent 8b4d191 commit 8075e6e

4 files changed

Lines changed: 279 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//// [tests/cases/compiler/enumMemberNameNonIdentifier.ts] ////
2+
3+
//// [enumMemberNameNonIdentifier.ts]
4+
// Enum members with names that are not valid ES5 identifiers
5+
// should use indexed access syntax in declaration emit
6+
7+
export const enum E {
8+
regular = 0,
9+
"hyphen-member" = 1,
10+
"123startsWithNumber" = 2,
11+
"has space" = 3,
12+
// Greek Capital Yot (U+037F) - valid identifier in ES2015+ but NOT in ES5
13+
Ϳ = 4,
14+
}
15+
16+
// These should infer types that use indexed access syntax
17+
// because the member names are not valid ES5 identifiers
18+
export const a = E["hyphen-member"];
19+
export const b = E["123startsWithNumber"];
20+
export const c = E["has space"];
21+
22+
// This should use dot notation since "regular" is a valid identifier
23+
export const d = E.regular;
24+
25+
// Greek Capital Yot (U+037F) - valid in ES2015+ but NOT in ES5
26+
// Because isIdentifierText uses ES5, this will use indexed access syntax
27+
export const e = E.Ϳ;
28+
29+
// Function returning specific enum member type
30+
export function getHyphenMember(): typeof E["hyphen-member"] {
31+
return E["hyphen-member"];
32+
}
33+
34+
35+
//// [enumMemberNameNonIdentifier.js]
36+
// Enum members with names that are not valid ES5 identifiers
37+
// should use indexed access syntax in declaration emit
38+
// These should infer types that use indexed access syntax
39+
// because the member names are not valid ES5 identifiers
40+
export const a = 1 /* E["hyphen-member"] */;
41+
export const b = 2 /* E["123startsWithNumber"] */;
42+
export const c = 3 /* E["has space"] */;
43+
// This should use dot notation since "regular" is a valid identifier
44+
export const d = 0 /* E.regular */;
45+
// Greek Capital Yot (U+037F) - valid in ES2015+ but NOT in ES5
46+
// Because isIdentifierText uses ES5, this will use indexed access syntax
47+
export const e = 4 /* E.Ϳ */;
48+
// Function returning specific enum member type
49+
export function getHyphenMember() {
50+
return 1 /* E["hyphen-member"] */;
51+
}
52+
53+
54+
//// [enumMemberNameNonIdentifier.d.ts]
55+
export declare const enum E {
56+
regular = 0,
57+
"hyphen-member" = 1,
58+
"123startsWithNumber" = 2,
59+
"has space" = 3,
60+
Ϳ = 4
61+
}
62+
export declare const a = E["hyphen-member"];
63+
export declare const b = E["123startsWithNumber"];
64+
export declare const c = E["has space"];
65+
export declare const d = E.regular;
66+
export declare const e = E.Ϳ;
67+
export declare function getHyphenMember(): typeof E["hyphen-member"];
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//// [tests/cases/compiler/enumMemberNameNonIdentifier.ts] ////
2+
3+
=== enumMemberNameNonIdentifier.ts ===
4+
// Enum members with names that are not valid ES5 identifiers
5+
// should use indexed access syntax in declaration emit
6+
7+
export const enum E {
8+
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
9+
10+
regular = 0,
11+
>regular : Symbol(E.regular, Decl(enumMemberNameNonIdentifier.ts, 3, 21))
12+
13+
"hyphen-member" = 1,
14+
>"hyphen-member" : Symbol(E["hyphen-member"], Decl(enumMemberNameNonIdentifier.ts, 4, 16))
15+
16+
"123startsWithNumber" = 2,
17+
>"123startsWithNumber" : Symbol(E["123startsWithNumber"], Decl(enumMemberNameNonIdentifier.ts, 5, 24))
18+
19+
"has space" = 3,
20+
>"has space" : Symbol(E["has space"], Decl(enumMemberNameNonIdentifier.ts, 6, 30))
21+
22+
// Greek Capital Yot (U+037F) - valid identifier in ES2015+ but NOT in ES5
23+
Ϳ = 4,
24+
>Ϳ : Symbol(E.Ϳ, Decl(enumMemberNameNonIdentifier.ts, 7, 20))
25+
}
26+
27+
// These should infer types that use indexed access syntax
28+
// because the member names are not valid ES5 identifiers
29+
export const a = E["hyphen-member"];
30+
>a : Symbol(a, Decl(enumMemberNameNonIdentifier.ts, 14, 12))
31+
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
32+
>"hyphen-member" : Symbol(E["hyphen-member"], Decl(enumMemberNameNonIdentifier.ts, 4, 16))
33+
34+
export const b = E["123startsWithNumber"];
35+
>b : Symbol(b, Decl(enumMemberNameNonIdentifier.ts, 15, 12))
36+
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
37+
>"123startsWithNumber" : Symbol(E["123startsWithNumber"], Decl(enumMemberNameNonIdentifier.ts, 5, 24))
38+
39+
export const c = E["has space"];
40+
>c : Symbol(c, Decl(enumMemberNameNonIdentifier.ts, 16, 12))
41+
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
42+
>"has space" : Symbol(E["has space"], Decl(enumMemberNameNonIdentifier.ts, 6, 30))
43+
44+
// This should use dot notation since "regular" is a valid identifier
45+
export const d = E.regular;
46+
>d : Symbol(d, Decl(enumMemberNameNonIdentifier.ts, 19, 12))
47+
>E.regular : Symbol(E.regular, Decl(enumMemberNameNonIdentifier.ts, 3, 21))
48+
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
49+
>regular : Symbol(E.regular, Decl(enumMemberNameNonIdentifier.ts, 3, 21))
50+
51+
// Greek Capital Yot (U+037F) - valid in ES2015+ but NOT in ES5
52+
// Because isIdentifierText uses ES5, this will use indexed access syntax
53+
export const e = E.Ϳ;
54+
>e : Symbol(e, Decl(enumMemberNameNonIdentifier.ts, 23, 12))
55+
>E.Ϳ : Symbol(E.Ϳ, Decl(enumMemberNameNonIdentifier.ts, 7, 20))
56+
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
57+
>Ϳ : Symbol(E.Ϳ, Decl(enumMemberNameNonIdentifier.ts, 7, 20))
58+
59+
// Function returning specific enum member type
60+
export function getHyphenMember(): typeof E["hyphen-member"] {
61+
>getHyphenMember : Symbol(getHyphenMember, Decl(enumMemberNameNonIdentifier.ts, 23, 21))
62+
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
63+
64+
return E["hyphen-member"];
65+
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
66+
>"hyphen-member" : Symbol(E["hyphen-member"], Decl(enumMemberNameNonIdentifier.ts, 4, 16))
67+
}
68+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//// [tests/cases/compiler/enumMemberNameNonIdentifier.ts] ////
2+
3+
=== enumMemberNameNonIdentifier.ts ===
4+
// Enum members with names that are not valid ES5 identifiers
5+
// should use indexed access syntax in declaration emit
6+
7+
export const enum E {
8+
>E : E
9+
> : ^
10+
11+
regular = 0,
12+
>regular : E.regular
13+
> : ^^^^^^^^^
14+
>0 : 0
15+
> : ^
16+
17+
"hyphen-member" = 1,
18+
>"hyphen-member" : (typeof E)["hyphen-member"]
19+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
>1 : 1
21+
> : ^
22+
23+
"123startsWithNumber" = 2,
24+
>"123startsWithNumber" : (typeof E)["123startsWithNumber"]
25+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
>2 : 2
27+
> : ^
28+
29+
"has space" = 3,
30+
>"has space" : (typeof E)["has space"]
31+
> : ^^^^^^^^^^^^^^^^^^^^^^^
32+
>3 : 3
33+
> : ^
34+
35+
// Greek Capital Yot (U+037F) - valid identifier in ES2015+ but NOT in ES5
36+
Ϳ = 4,
37+
>Ϳ : (typeof E)["\u037F"]
38+
> : ^^^^^^^^^^^^^^^^^^^^
39+
>4 : 4
40+
> : ^
41+
}
42+
43+
// These should infer types that use indexed access syntax
44+
// because the member names are not valid ES5 identifiers
45+
export const a = E["hyphen-member"];
46+
>a : (typeof E)["hyphen-member"]
47+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
48+
>E["hyphen-member"] : (typeof E)["hyphen-member"]
49+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
>E : typeof E
51+
> : ^^^^^^^^
52+
>"hyphen-member" : "hyphen-member"
53+
> : ^^^^^^^^^^^^^^^
54+
55+
export const b = E["123startsWithNumber"];
56+
>b : (typeof E)["123startsWithNumber"]
57+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
58+
>E["123startsWithNumber"] : (typeof E)["123startsWithNumber"]
59+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
>E : typeof E
61+
> : ^^^^^^^^
62+
>"123startsWithNumber" : "123startsWithNumber"
63+
> : ^^^^^^^^^^^^^^^^^^^^^
64+
65+
export const c = E["has space"];
66+
>c : (typeof E)["has space"]
67+
> : ^^^^^^^^^^^^^^^^^^^^^^^
68+
>E["has space"] : (typeof E)["has space"]
69+
> : ^^^^^^^^^^^^^^^^^^^^^^^
70+
>E : typeof E
71+
> : ^^^^^^^^
72+
>"has space" : "has space"
73+
> : ^^^^^^^^^^^
74+
75+
// This should use dot notation since "regular" is a valid identifier
76+
export const d = E.regular;
77+
>d : E.regular
78+
> : ^^^^^^^^^
79+
>E.regular : E.regular
80+
> : ^^^^^^^^^
81+
>E : typeof E
82+
> : ^^^^^^^^
83+
>regular : E.regular
84+
> : ^^^^^^^^^
85+
86+
// Greek Capital Yot (U+037F) - valid in ES2015+ but NOT in ES5
87+
// Because isIdentifierText uses ES5, this will use indexed access syntax
88+
export const e = E.Ϳ;
89+
>e : (typeof E)["\u037F"]
90+
> : ^^^^^^^^^^^^^^^^^^^^
91+
>E.Ϳ : (typeof E)["\u037F"]
92+
> : ^^^^^^^^^^^^^^^^^^^^
93+
>E : typeof E
94+
> : ^^^^^^^^
95+
>Ϳ : (typeof E)["\u037F"]
96+
> : ^^^^^^^^^^^^^^^^^^^^
97+
98+
// Function returning specific enum member type
99+
export function getHyphenMember(): typeof E["hyphen-member"] {
100+
>getHyphenMember : () => (typeof E)["hyphen-member"]
101+
> : ^^^^^^^ ^
102+
>E : typeof E
103+
> : ^^^^^^^^
104+
105+
return E["hyphen-member"];
106+
>E["hyphen-member"] : (typeof E)["hyphen-member"]
107+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
108+
>E : typeof E
109+
> : ^^^^^^^^
110+
>"hyphen-member" : "hyphen-member"
111+
> : ^^^^^^^^^^^^^^^
112+
}
113+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @declaration: true
2+
3+
// Enum members with names that are not valid ES5 identifiers
4+
// should use indexed access syntax in declaration emit
5+
6+
export const enum E {
7+
regular = 0,
8+
"hyphen-member" = 1,
9+
"123startsWithNumber" = 2,
10+
"has space" = 3,
11+
// Greek Capital Yot (U+037F) - valid identifier in ES2015+ but NOT in ES5
12+
Ϳ = 4,
13+
}
14+
15+
// These should infer types that use indexed access syntax
16+
// because the member names are not valid ES5 identifiers
17+
export const a = E["hyphen-member"];
18+
export const b = E["123startsWithNumber"];
19+
export const c = E["has space"];
20+
21+
// This should use dot notation since "regular" is a valid identifier
22+
export const d = E.regular;
23+
24+
// Greek Capital Yot (U+037F) - valid in ES2015+ but NOT in ES5
25+
// Because isIdentifierText uses ES5, this will use indexed access syntax
26+
export const e = E.Ϳ;
27+
28+
// Function returning specific enum member type
29+
export function getHyphenMember(): typeof E["hyphen-member"] {
30+
return E["hyphen-member"];
31+
}

0 commit comments

Comments
 (0)