Skip to content

Commit 1bcd8da

Browse files
committed
clean test cases
1 parent d2ab0bd commit 1bcd8da

5 files changed

+5
-37
lines changed

src/services/refactors/convertStringOrTemplateLiteral.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,20 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
175175
return createTemplateExpression(head, templateSpans);
176176
}
177177

178-
const hexToUnicode = (_match: string, grp: string) => String.fromCharCode(parseInt(grp, 16));
179178
const octalToUnicode = (_match: string, grp: string) => String.fromCharCode(parseInt(grp, 8));
180179

181180
function decodeRawString(content: string) {
182181
const outerQuotes = /["']((.|\s)*)["']/;
183-
const unicodeEscape = /\\u(\w+)/gi;
184-
const unicodeEscapeWithBraces = /\\u\{(\w+)\}/gi;
185-
const hexEscape = /\\x(\w+)/gi;
186-
const octalEscape = /\\([0-7]+)/g;
182+
const octalEscape = /\\((?:[1-7][0-7]{0,2}|[0-7]{2,3}))/g;
187183

188184
return content.replace(outerQuotes, (_match, grp) => grp)
189-
.replace(unicodeEscape, hexToUnicode)
190-
.replace(unicodeEscapeWithBraces, hexToUnicode)
191-
.replace(hexEscape, hexToUnicode)
192185
.replace(octalEscape, octalToUnicode);
193186

194187
}
195188

196189
function escapeText(content: string) {
197190
return content.replace("`", "\`") // back-tick
198-
.replace("\${", `$\\{`); // placeholder alike beginning
191+
.replace("${", "$\\{"); // placeholder alike beginning
199192
}
200193

201194
}

tests/cases/fourslash/refactorConvertStringOrTemplateLiteral_ToStringAvailabilityTagged.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference path='fourslash.ts' />
22

3-
//// function tag(literals: TemplateStringsArray, ...placeholders: string[]) { return "tagged" }
3+
//// function tag(literals: TemplateStringsArray, ...placeholders: any[]) { return "tagged" }
44
//// const alpha = tag/*z*/`/*y*/foobar`
55
//// const beta = tag/*x*/`/*w*/foobar ${/*v*/4/*u*/2}`
66

tests/cases/fourslash/refactorConvertStringOrTemplateLiteral_ToStringBackTick.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/cases/fourslash/refactorConvertStringOrTemplateLiteral_ToStringDollar.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/// <reference path='fourslash.ts' />
22

3-
debugger;
4-
//// const foo = "/*x*/U/*y*/nicode \u0023 \u{0023} " + "Hex \x23 " + "Octal \43";
3+
//// const foo = "/*x*/O/*y*/ctal \43";
54

65
goTo.select("x", "y");
76
edit.applyRefactor({
87
refactorName: "Convert string concatenation or template literal",
98
actionName: "Convert to template literal",
109
actionDescription: "Convert to template literal",
1110
newContent:
12-
"const foo = `Unicode # # Hex # Octal #\`;",
11+
"const foo = `Octal #`;",
1312
});

0 commit comments

Comments
 (0)