Skip to content

fix(46366): Escaped notation in an enum's computed property shows as non-escaped on hover #46431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6127,12 +6127,8 @@ namespace ts {
firstChar = symbolName.charCodeAt(0);
}
let expression: Expression | undefined;
if (isSingleOrDoubleQuote(firstChar)) {
expression = factory.createStringLiteral(
symbolName
.substring(1, symbolName.length - 1)
.replace(/\\./g, s => s.substring(1)),
firstChar === CharacterCodes.singleQuote);
if (isSingleOrDoubleQuote(firstChar) && !(symbol.flags & SymbolFlags.EnumMember)) {
expression = factory.createStringLiteral(stripQuotes(symbolName).replace(/\\./g, s => s.substring(1)), firstChar === CharacterCodes.singleQuote);
}
else if (("" + +symbolName) === symbolName) {
expression = factory.createNumericLiteral(+symbolName);
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/enumWithUnicodeEscape1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ enum E {
>E : Symbol(E, Decl(enumWithUnicodeEscape1.ts, 0, 0))

'gold \u2730'
>'gold \u2730' : Symbol(E['gold u2730'], Decl(enumWithUnicodeEscape1.ts, 0, 8))
>'gold \u2730' : Symbol(E['gold \u2730'], Decl(enumWithUnicodeEscape1.ts, 0, 8))
}

24 changes: 12 additions & 12 deletions tests/baselines/reference/quickInfoDisplayPartsEnum2.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
{
"text": "\"e1\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -135,7 +135,7 @@
},
{
"text": "'e2'",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -201,7 +201,7 @@
},
{
"text": "\"e3\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -411,7 +411,7 @@
},
{
"text": "\"e1\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -549,7 +549,7 @@
},
{
"text": "'e2'",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -687,7 +687,7 @@
},
{
"text": "\"e3\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -791,7 +791,7 @@
},
{
"text": "\"e1\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -857,7 +857,7 @@
},
{
"text": "'e2'",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -923,7 +923,7 @@
},
{
"text": "\"e3\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -1149,7 +1149,7 @@
},
{
"text": "\"e1\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -1295,7 +1295,7 @@
},
{
"text": "'e2'",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -1441,7 +1441,7 @@
},
{
"text": "\"e3\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down
24 changes: 12 additions & 12 deletions tests/baselines/reference/quickInfoDisplayPartsEnum3.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
{
"text": "\"e1\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -135,7 +135,7 @@
},
{
"text": "'e2'",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -201,7 +201,7 @@
},
{
"text": "\"e3\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -411,7 +411,7 @@
},
{
"text": "\"e1\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -549,7 +549,7 @@
},
{
"text": "'e2'",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -687,7 +687,7 @@
},
{
"text": "\"e3\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -791,7 +791,7 @@
},
{
"text": "\"e1\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -857,7 +857,7 @@
},
{
"text": "'e2'",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -923,7 +923,7 @@
},
{
"text": "\"e3\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -1149,7 +1149,7 @@
},
{
"text": "\"e1\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -1295,7 +1295,7 @@
},
{
"text": "'e2'",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down Expand Up @@ -1441,7 +1441,7 @@
},
{
"text": "\"e3\"",
"kind": "stringLiteral"
"kind": "enumMemberName"
},
{
"text": "]",
Expand Down
134 changes: 134 additions & 0 deletions tests/baselines/reference/quickInfoDisplayPartsEnum4.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoDisplayPartsEnum4.ts",
"position": 51,
"name": "1"
},
"quickInfo": {
"kind": "enum member",
"kindModifiers": "",
"textSpan": {
"start": 51,
"length": 4
},
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "enum member",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Foo",
"kind": "enumName"
},
{
"text": "[",
"kind": "punctuation"
},
{
"text": "\"\\t\"",
"kind": "enumMemberName"
},
{
"text": "]",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=",
"kind": "operator"
},
{
"text": " ",
"kind": "space"
},
{
"text": "9",
"kind": "numericLiteral"
}
],
"documentation": []
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoDisplayPartsEnum4.ts",
"position": 61,
"name": "2"
},
"quickInfo": {
"kind": "enum member",
"kindModifiers": "",
"textSpan": {
"start": 61,
"length": 8
},
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "enum member",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Foo",
"kind": "enumName"
},
{
"text": "[",
"kind": "punctuation"
},
{
"text": "\"\\u007f\"",
"kind": "enumMemberName"
},
{
"text": "]",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=",
"kind": "operator"
},
{
"text": " ",
"kind": "space"
},
{
"text": "127",
"kind": "numericLiteral"
}
],
"documentation": []
}
}
]
10 changes: 10 additions & 0 deletions tests/cases/fourslash/quickInfoDisplayPartsEnum4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference path='fourslash.ts'/>

////const enum Foo {
//// "\t" = 9,
//// "\u007f" = 127,
////}
////Foo[/*1*/"\t"]
////Foo[/*2*/"\u007f"]

verify.baselineQuickInfo();