mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
clean test cases
This commit is contained in:
@@ -175,27 +175,20 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
return createTemplateExpression(head, templateSpans);
|
||||
}
|
||||
|
||||
const hexToUnicode = (_match: string, grp: string) => String.fromCharCode(parseInt(grp, 16));
|
||||
const octalToUnicode = (_match: string, grp: string) => String.fromCharCode(parseInt(grp, 8));
|
||||
|
||||
function decodeRawString(content: string) {
|
||||
const outerQuotes = /["']((.|\s)*)["']/;
|
||||
const unicodeEscape = /\\u(\w+)/gi;
|
||||
const unicodeEscapeWithBraces = /\\u\{(\w+)\}/gi;
|
||||
const hexEscape = /\\x(\w+)/gi;
|
||||
const octalEscape = /\\([0-7]+)/g;
|
||||
const octalEscape = /\\((?:[1-7][0-7]{0,2}|[0-7]{2,3}))/g;
|
||||
|
||||
return content.replace(outerQuotes, (_match, grp) => grp)
|
||||
.replace(unicodeEscape, hexToUnicode)
|
||||
.replace(unicodeEscapeWithBraces, hexToUnicode)
|
||||
.replace(hexEscape, hexToUnicode)
|
||||
.replace(octalEscape, octalToUnicode);
|
||||
|
||||
}
|
||||
|
||||
function escapeText(content: string) {
|
||||
return content.replace("`", "\`") // back-tick
|
||||
.replace("\${", `$\\{`); // placeholder alike beginning
|
||||
.replace("${", "$\\{"); // placeholder alike beginning
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// function tag(literals: TemplateStringsArray, ...placeholders: string[]) { return "tagged" }
|
||||
//// function tag(literals: TemplateStringsArray, ...placeholders: any[]) { return "tagged" }
|
||||
//// const alpha = tag/*z*/`/*y*/foobar`
|
||||
//// const beta = tag/*x*/`/*w*/foobar ${/*v*/4/*u*/2}`
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/w/*y*/ith back\`tick`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
"const foo = \"with back`tick\"",
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/w/*y*/ith \${dollar}`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
"const foo = \"with \${dollar}\"",
|
||||
});
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
debugger;
|
||||
//// const foo = "/*x*/U/*y*/nicode \u0023 \u{0023} " + "Hex \x23 " + "Octal \43";
|
||||
//// const foo = "/*x*/O/*y*/ctal \43";
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
@@ -9,5 +8,5 @@ edit.applyRefactor({
|
||||
actionName: "Convert to template literal",
|
||||
actionDescription: "Convert to template literal",
|
||||
newContent:
|
||||
"const foo = `Unicode # # Hex # Octal #\`;",
|
||||
"const foo = `Octal #`;",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user