No template refactor on plain strings (#36785)

* Add/convert to failing tests.

* Stop offering to convert single string literals to template expressions.

* Ensure we're actually testing for single quotes.
This commit is contained in:
Daniel Rosenwasser 2020-02-13 12:22:53 -08:00 committed by GitHub
parent 19c3bcb9a9
commit 210090b483
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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);