🤖 Cherry-pick PR #36785 into release-3.8 (#36786)

Component commits:
206d39e9b5 Add/convert to failing tests.

11e827ba84 Stop offering to convert single string literals to template expressions.

7d3ad0c8f6 Ensure we're actually testing for single quotes.

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
TypeScript Bot
2020-02-13 12:23:16 -08:00
committed by GitHub
parent 1986a5faa3
commit e7fec6d565
6 changed files with 22 additions and 22 deletions

View File

@@ -11,7 +11,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
const maybeBinary = getParentBinaryExpression(node);
const refactorInfo: ApplicableRefactorInfo = { name: refactorName, description: refactorDescription, actions: [] };
if ((isBinaryExpression(maybeBinary) || isStringLiteral(maybeBinary)) && isStringConcatenationValid(maybeBinary)) {
if (isBinaryExpression(maybeBinary) && isStringConcatenationValid(maybeBinary)) {
refactorInfo.actions.push({ name: refactorName, description: refactorDescription });
return [refactorInfo];
}

View File

@@ -0,0 +1,6 @@
/// <reference path='fourslash.ts' />
////import { x } from /*x*/"foo"/*y*/;
goTo.select("x", "y");
verify.not.refactorAvailable(ts.Diagnostics.Convert_to_template_string.message);

View File

@@ -3,10 +3,4 @@
//// const foo = "/*x*/w/*y*/ith back`tick"
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
"const foo = `with back\\`tick`",
});
verify.not.refactorAvailable(ts.Diagnostics.Convert_to_template_string.message);

View File

@@ -0,0 +1,12 @@
/// <reference path='fourslash.ts' />
//// const foo = '/*x*/f/*y*/oobar is ' + (42 + 6) + ' years old'
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`const foo = \`foobar is \${42 + 6} years old\``,
});

View File

@@ -3,10 +3,4 @@
//// const foo = "/*x*/f/*y*/oobar rocks"
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`const foo = \`foobar rocks\``,
});
verify.not.refactorAvailable(ts.Diagnostics.Convert_to_template_string.message);

View File

@@ -3,10 +3,4 @@
//// const foo = '/*x*/f/*y*/oobar rocks'
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`const foo = \`foobar rocks\``,
});
verify.not.refactorAvailable(ts.Diagnostics.Convert_to_template_string.message);