mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 16:39:46 -05:00
Escape string literal before looking it up in enum's symbol table (#17441)
This commit is contained in:
@@ -21517,7 +21517,7 @@ namespace ts {
|
||||
else {
|
||||
const argument = ex.argumentExpression;
|
||||
Debug.assert(isLiteralExpression(argument));
|
||||
name = (argument as LiteralExpression).text as __String; // TODO: GH#17348
|
||||
name = escapeLeadingUnderscores((argument as LiteralExpression).text);
|
||||
}
|
||||
return evaluateEnumMember(expr, type.symbol, name);
|
||||
}
|
||||
|
||||
13
tests/baselines/reference/underscoreEscapedNameInEnum.js
Normal file
13
tests/baselines/reference/underscoreEscapedNameInEnum.js
Normal file
@@ -0,0 +1,13 @@
|
||||
//// [underscoreEscapedNameInEnum.ts]
|
||||
enum E {
|
||||
"__foo" = 1,
|
||||
bar = E["__foo"] + 1
|
||||
}
|
||||
|
||||
|
||||
//// [underscoreEscapedNameInEnum.js]
|
||||
var E;
|
||||
(function (E) {
|
||||
E[E["__foo"] = 1] = "__foo";
|
||||
E[E["bar"] = 2] = "bar";
|
||||
})(E || (E = {}));
|
||||
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/compiler/underscoreEscapedNameInEnum.ts ===
|
||||
enum E {
|
||||
>E : Symbol(E, Decl(underscoreEscapedNameInEnum.ts, 0, 0))
|
||||
|
||||
"__foo" = 1,
|
||||
bar = E["__foo"] + 1
|
||||
>bar : Symbol(E.bar, Decl(underscoreEscapedNameInEnum.ts, 1, 16))
|
||||
>E : Symbol(E, Decl(underscoreEscapedNameInEnum.ts, 0, 0))
|
||||
}
|
||||
|
||||
16
tests/baselines/reference/underscoreEscapedNameInEnum.types
Normal file
16
tests/baselines/reference/underscoreEscapedNameInEnum.types
Normal file
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/underscoreEscapedNameInEnum.ts ===
|
||||
enum E {
|
||||
>E : E
|
||||
|
||||
"__foo" = 1,
|
||||
>1 : 1
|
||||
|
||||
bar = E["__foo"] + 1
|
||||
>bar : E
|
||||
>E["__foo"] + 1 : number
|
||||
>E["__foo"] : E
|
||||
>E : typeof E
|
||||
>"__foo" : "__foo"
|
||||
>1 : 1
|
||||
}
|
||||
|
||||
4
tests/cases/compiler/underscoreEscapedNameInEnum.ts
Normal file
4
tests/cases/compiler/underscoreEscapedNameInEnum.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
"__foo" = 1,
|
||||
bar = E["__foo"] + 1
|
||||
}
|
||||
Reference in New Issue
Block a user