Skip to content

Commit 210090b

Browse files
No template refactor on plain strings (microsoft#36785)
* Add/convert to failing tests. * Stop offering to convert single string literals to template expressions. * Ensure we're actually testing for single quotes.
1 parent 19c3bcb commit 210090b

6 files changed

+22
-22
lines changed

src/services/refactors/convertStringOrTemplateLiteral.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
1111
const maybeBinary = getParentBinaryExpression(node);
1212
const refactorInfo: ApplicableRefactorInfo = { name: refactorName, description: refactorDescription, actions: [] };
1313

14-
if ((isBinaryExpression(maybeBinary) || isStringLiteral(maybeBinary)) && isStringConcatenationValid(maybeBinary)) {
14+
if (isBinaryExpression(maybeBinary) && isStringConcatenationValid(maybeBinary)) {
1515
refactorInfo.actions.push({ name: refactorName, description: refactorDescription });
1616
return [refactorInfo];
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////import { x } from /*x*/"foo"/*y*/;
4+
5+
goTo.select("x", "y");
6+
verify.not.refactorAvailable(ts.Diagnostics.Convert_to_template_string.message);

tests/cases/fourslash/refactorConvertStringOrTemplateLiteral_ToTemplateBackTick.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@
33
//// const foo = "/*x*/w/*y*/ith back`tick"
44

55
goTo.select("x", "y");
6-
edit.applyRefactor({
7-
refactorName: "Convert to template string",
8-
actionName: "Convert to template string",
9-
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
10-
newContent:
11-
"const foo = `with back\\`tick`",
12-
});
6+
verify.not.refactorAvailable(ts.Diagnostics.Convert_to_template_string.message);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// const foo = '/*x*/f/*y*/oobar is ' + (42 + 6) + ' years old'
4+
5+
goTo.select("x", "y");
6+
edit.applyRefactor({
7+
refactorName: "Convert to template string",
8+
actionName: "Convert to template string",
9+
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
10+
newContent:
11+
`const foo = \`foobar is \${42 + 6} years old\``,
12+
});

tests/cases/fourslash/refactorConvertStringOrTemplateLiteral_ToTemplateSimple.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@
33
//// const foo = "/*x*/f/*y*/oobar rocks"
44

55
goTo.select("x", "y");
6-
edit.applyRefactor({
7-
refactorName: "Convert to template string",
8-
actionName: "Convert to template string",
9-
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
10-
newContent:
11-
`const foo = \`foobar rocks\``,
12-
});
6+
verify.not.refactorAvailable(ts.Diagnostics.Convert_to_template_string.message);

tests/cases/fourslash/refactorConvertStringOrTemplateLiteral_ToTemplateSingleQuote.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@
33
//// const foo = '/*x*/f/*y*/oobar rocks'
44

55
goTo.select("x", "y");
6-
edit.applyRefactor({
7-
refactorName: "Convert to template string",
8-
actionName: "Convert to template string",
9-
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
10-
newContent:
11-
`const foo = \`foobar rocks\``,
12-
});
6+
verify.not.refactorAvailable(ts.Diagnostics.Convert_to_template_string.message);

0 commit comments

Comments
 (0)