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:
parent
19c3bcb9a9
commit
210090b483
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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);
|
|
@ -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);
|
||||
|
|
|
@ -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\``,
|
||||
});
|
|
@ -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);
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue