Escape string literal before looking it up in enum's symbol table (#17441)

This commit is contained in:
Andy
2017-07-26 16:00:34 -07:00
committed by GitHub
parent b080aa9440
commit cc8399dc41
5 changed files with 44 additions and 1 deletions

View File

@@ -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);
}

View 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 = {}));

View File

@@ -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))
}

View 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
}

View File

@@ -0,0 +1,4 @@
enum E {
"__foo" = 1,
bar = E["__foo"] + 1
}