Skip to content

Remove extraneous string escape from convert to template string refactor #37743

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 3 commits into from
Apr 9, 2020
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
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3441,7 +3441,7 @@ namespace ts {
const doubleQuoteEscapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
const singleQuoteEscapedCharsRegExp = /[\\\'\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
// Template strings should be preserved as much as possible
const backtickQuoteEscapedCharsRegExp = /[\\\`]/g;
const backtickQuoteEscapedCharsRegExp = /[\\`]/g;
const escapedCharsMap = createMapFromTemplate({
"\t": "\\t",
"\v": "\\v",
Expand Down
1 change: 0 additions & 1 deletion src/services/refactors/convertStringOrTemplateLiteral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
index++;
}

text = escapeString(text);
return [index, text, indexes];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />

//// console.log(/*0*/"\\[[" + text + "](" + link + ")\\]"/*1*/)

goTo.select("0", "1");
edit.applyRefactor({
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
// Four backslashes here
// = two backslashes in the expected file content
// = one backslash in the string data sent to console.log
// (which is the same as what the user started with)
newContent: 'console.log(`\\\\[[${text}](${link})\\\\]`)',
});