Skip to content

Commit b21afdc

Browse files
a-tarasyukmprobst
authored andcommitted
fix(46366): handle enum string access as enumMemberName (microsoft#46431)
1 parent c02e6ab commit b21afdc

6 files changed

+171
-31
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6223,12 +6223,8 @@ namespace ts {
62236223
firstChar = symbolName.charCodeAt(0);
62246224
}
62256225
let expression: Expression | undefined;
6226-
if (isSingleOrDoubleQuote(firstChar)) {
6227-
expression = factory.createStringLiteral(
6228-
symbolName
6229-
.substring(1, symbolName.length - 1)
6230-
.replace(/\\./g, s => s.substring(1)),
6231-
firstChar === CharacterCodes.singleQuote);
6226+
if (isSingleOrDoubleQuote(firstChar) && !(symbol.flags & SymbolFlags.EnumMember)) {
6227+
expression = factory.createStringLiteral(stripQuotes(symbolName).replace(/\\./g, s => s.substring(1)), firstChar === CharacterCodes.singleQuote);
62326228
}
62336229
else if (("" + +symbolName) === symbolName) {
62346230
expression = factory.createNumericLiteral(+symbolName);

tests/baselines/reference/enumWithUnicodeEscape1.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ enum E {
33
>E : Symbol(E, Decl(enumWithUnicodeEscape1.ts, 0, 0))
44

55
'gold \u2730'
6-
>'gold \u2730' : Symbol(E['gold u2730'], Decl(enumWithUnicodeEscape1.ts, 0, 8))
6+
>'gold \u2730' : Symbol(E['gold \u2730'], Decl(enumWithUnicodeEscape1.ts, 0, 8))
77
}
88

tests/baselines/reference/quickInfoDisplayPartsEnum2.baseline

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
},
7070
{
7171
"text": "\"e1\"",
72-
"kind": "stringLiteral"
72+
"kind": "enumMemberName"
7373
},
7474
{
7575
"text": "]",
@@ -135,7 +135,7 @@
135135
},
136136
{
137137
"text": "'e2'",
138-
"kind": "stringLiteral"
138+
"kind": "enumMemberName"
139139
},
140140
{
141141
"text": "]",
@@ -201,7 +201,7 @@
201201
},
202202
{
203203
"text": "\"e3\"",
204-
"kind": "stringLiteral"
204+
"kind": "enumMemberName"
205205
},
206206
{
207207
"text": "]",
@@ -411,7 +411,7 @@
411411
},
412412
{
413413
"text": "\"e1\"",
414-
"kind": "stringLiteral"
414+
"kind": "enumMemberName"
415415
},
416416
{
417417
"text": "]",
@@ -549,7 +549,7 @@
549549
},
550550
{
551551
"text": "'e2'",
552-
"kind": "stringLiteral"
552+
"kind": "enumMemberName"
553553
},
554554
{
555555
"text": "]",
@@ -687,7 +687,7 @@
687687
},
688688
{
689689
"text": "\"e3\"",
690-
"kind": "stringLiteral"
690+
"kind": "enumMemberName"
691691
},
692692
{
693693
"text": "]",
@@ -791,7 +791,7 @@
791791
},
792792
{
793793
"text": "\"e1\"",
794-
"kind": "stringLiteral"
794+
"kind": "enumMemberName"
795795
},
796796
{
797797
"text": "]",
@@ -857,7 +857,7 @@
857857
},
858858
{
859859
"text": "'e2'",
860-
"kind": "stringLiteral"
860+
"kind": "enumMemberName"
861861
},
862862
{
863863
"text": "]",
@@ -923,7 +923,7 @@
923923
},
924924
{
925925
"text": "\"e3\"",
926-
"kind": "stringLiteral"
926+
"kind": "enumMemberName"
927927
},
928928
{
929929
"text": "]",
@@ -1149,7 +1149,7 @@
11491149
},
11501150
{
11511151
"text": "\"e1\"",
1152-
"kind": "stringLiteral"
1152+
"kind": "enumMemberName"
11531153
},
11541154
{
11551155
"text": "]",
@@ -1295,7 +1295,7 @@
12951295
},
12961296
{
12971297
"text": "'e2'",
1298-
"kind": "stringLiteral"
1298+
"kind": "enumMemberName"
12991299
},
13001300
{
13011301
"text": "]",
@@ -1441,7 +1441,7 @@
14411441
},
14421442
{
14431443
"text": "\"e3\"",
1444-
"kind": "stringLiteral"
1444+
"kind": "enumMemberName"
14451445
},
14461446
{
14471447
"text": "]",

tests/baselines/reference/quickInfoDisplayPartsEnum3.baseline

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
},
7070
{
7171
"text": "\"e1\"",
72-
"kind": "stringLiteral"
72+
"kind": "enumMemberName"
7373
},
7474
{
7575
"text": "]",
@@ -135,7 +135,7 @@
135135
},
136136
{
137137
"text": "'e2'",
138-
"kind": "stringLiteral"
138+
"kind": "enumMemberName"
139139
},
140140
{
141141
"text": "]",
@@ -201,7 +201,7 @@
201201
},
202202
{
203203
"text": "\"e3\"",
204-
"kind": "stringLiteral"
204+
"kind": "enumMemberName"
205205
},
206206
{
207207
"text": "]",
@@ -411,7 +411,7 @@
411411
},
412412
{
413413
"text": "\"e1\"",
414-
"kind": "stringLiteral"
414+
"kind": "enumMemberName"
415415
},
416416
{
417417
"text": "]",
@@ -549,7 +549,7 @@
549549
},
550550
{
551551
"text": "'e2'",
552-
"kind": "stringLiteral"
552+
"kind": "enumMemberName"
553553
},
554554
{
555555
"text": "]",
@@ -687,7 +687,7 @@
687687
},
688688
{
689689
"text": "\"e3\"",
690-
"kind": "stringLiteral"
690+
"kind": "enumMemberName"
691691
},
692692
{
693693
"text": "]",
@@ -791,7 +791,7 @@
791791
},
792792
{
793793
"text": "\"e1\"",
794-
"kind": "stringLiteral"
794+
"kind": "enumMemberName"
795795
},
796796
{
797797
"text": "]",
@@ -857,7 +857,7 @@
857857
},
858858
{
859859
"text": "'e2'",
860-
"kind": "stringLiteral"
860+
"kind": "enumMemberName"
861861
},
862862
{
863863
"text": "]",
@@ -923,7 +923,7 @@
923923
},
924924
{
925925
"text": "\"e3\"",
926-
"kind": "stringLiteral"
926+
"kind": "enumMemberName"
927927
},
928928
{
929929
"text": "]",
@@ -1149,7 +1149,7 @@
11491149
},
11501150
{
11511151
"text": "\"e1\"",
1152-
"kind": "stringLiteral"
1152+
"kind": "enumMemberName"
11531153
},
11541154
{
11551155
"text": "]",
@@ -1295,7 +1295,7 @@
12951295
},
12961296
{
12971297
"text": "'e2'",
1298-
"kind": "stringLiteral"
1298+
"kind": "enumMemberName"
12991299
},
13001300
{
13011301
"text": "]",
@@ -1441,7 +1441,7 @@
14411441
},
14421442
{
14431443
"text": "\"e3\"",
1444-
"kind": "stringLiteral"
1444+
"kind": "enumMemberName"
14451445
},
14461446
{
14471447
"text": "]",
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoDisplayPartsEnum4.ts",
5+
"position": 51,
6+
"name": "1"
7+
},
8+
"quickInfo": {
9+
"kind": "enum member",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 51,
13+
"length": 4
14+
},
15+
"displayParts": [
16+
{
17+
"text": "(",
18+
"kind": "punctuation"
19+
},
20+
{
21+
"text": "enum member",
22+
"kind": "text"
23+
},
24+
{
25+
"text": ")",
26+
"kind": "punctuation"
27+
},
28+
{
29+
"text": " ",
30+
"kind": "space"
31+
},
32+
{
33+
"text": "Foo",
34+
"kind": "enumName"
35+
},
36+
{
37+
"text": "[",
38+
"kind": "punctuation"
39+
},
40+
{
41+
"text": "\"\\t\"",
42+
"kind": "enumMemberName"
43+
},
44+
{
45+
"text": "]",
46+
"kind": "punctuation"
47+
},
48+
{
49+
"text": " ",
50+
"kind": "space"
51+
},
52+
{
53+
"text": "=",
54+
"kind": "operator"
55+
},
56+
{
57+
"text": " ",
58+
"kind": "space"
59+
},
60+
{
61+
"text": "9",
62+
"kind": "numericLiteral"
63+
}
64+
],
65+
"documentation": []
66+
}
67+
},
68+
{
69+
"marker": {
70+
"fileName": "/tests/cases/fourslash/quickInfoDisplayPartsEnum4.ts",
71+
"position": 61,
72+
"name": "2"
73+
},
74+
"quickInfo": {
75+
"kind": "enum member",
76+
"kindModifiers": "",
77+
"textSpan": {
78+
"start": 61,
79+
"length": 8
80+
},
81+
"displayParts": [
82+
{
83+
"text": "(",
84+
"kind": "punctuation"
85+
},
86+
{
87+
"text": "enum member",
88+
"kind": "text"
89+
},
90+
{
91+
"text": ")",
92+
"kind": "punctuation"
93+
},
94+
{
95+
"text": " ",
96+
"kind": "space"
97+
},
98+
{
99+
"text": "Foo",
100+
"kind": "enumName"
101+
},
102+
{
103+
"text": "[",
104+
"kind": "punctuation"
105+
},
106+
{
107+
"text": "\"\\u007f\"",
108+
"kind": "enumMemberName"
109+
},
110+
{
111+
"text": "]",
112+
"kind": "punctuation"
113+
},
114+
{
115+
"text": " ",
116+
"kind": "space"
117+
},
118+
{
119+
"text": "=",
120+
"kind": "operator"
121+
},
122+
{
123+
"text": " ",
124+
"kind": "space"
125+
},
126+
{
127+
"text": "127",
128+
"kind": "numericLiteral"
129+
}
130+
],
131+
"documentation": []
132+
}
133+
}
134+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////const enum Foo {
4+
//// "\t" = 9,
5+
//// "\u007f" = 127,
6+
////}
7+
////Foo[/*1*/"\t"]
8+
////Foo[/*2*/"\u007f"]
9+
10+
verify.baselineQuickInfo();

0 commit comments

Comments
 (0)