mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-17 00:34:47 -05:00
do not offer refactoring for tagged templates
This commit is contained in:
@@ -9,7 +9,6 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
const toStringConcatenationDescription = getLocaleSpecificMessage(Diagnostics.Convert_to_string_concatenation);
|
||||
|
||||
// TODO let a = 45 - 45 + " ee" - 33;
|
||||
// TODO let a = tag `aaa`;
|
||||
|
||||
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
|
||||
|
||||
@@ -17,13 +16,14 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
const { file, startPosition } = context;
|
||||
const node = getTokenAtPosition(file, startPosition);
|
||||
const maybeBinary = getParentBinaryExpression(node); containsString(maybeBinary);
|
||||
const maybeTemplateExpression = findAncestor(node, n => isTemplateExpression(n));
|
||||
const actions: RefactorActionInfo[] = [];
|
||||
|
||||
if ((isBinaryExpression(maybeBinary) || isStringLiteral(maybeBinary)) && containsString(maybeBinary)) {
|
||||
actions.push({ name: toTemplateLiteralActionName, description: toTemplateLiteralDescription });
|
||||
}
|
||||
|
||||
if (isNoSubstitutionTemplateLiteral(node) || isTemplateHead(node) || isTemplateSpan(node.parent)) {
|
||||
if ((isNoSubstitutionTemplateLiteral(node) && !isTaggedTemplateExpression(node.parent)) || (maybeTemplateExpression && !isTaggedTemplateExpression(maybeTemplateExpression.parent))) {
|
||||
actions.push({ name: toStringConcatenationActionName, description: toStringConcatenationDescription });
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
case toStringConcatenationActionName:
|
||||
if (isNoSubstitutionTemplateLiteral(node)) {
|
||||
const stringLiteral = createStringLiteral(node.text);
|
||||
|
||||
return { edits: textChanges.ChangeTracker.with(context, t => t.replaceNode(file, node, stringLiteral)) };
|
||||
return { edits: textChanges.ChangeTracker.with(context, t => t.replaceNode(file, node, stringLiteral)) };
|
||||
|
||||
}
|
||||
if (isTemplateExpression(node.parent) || isTemplateSpan(node.parent)) {
|
||||
|
||||
@@ -27,4 +27,3 @@ verify.not.refactorAvailable("Convert string concatenation or template literal",
|
||||
goTo.select("p", "o");
|
||||
verify.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// function tag(literals: TemplateStringsArray, ...placeholders: string[]) { return "tagged" }
|
||||
//// const alpha = tag/*z*/`/*y*/foobar`
|
||||
//// const beta = tag/*x*/`/*w*/foobar ${/*v*/4/*u*/2}`
|
||||
|
||||
goTo.select("z", "y");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
|
||||
|
||||
goTo.select("x", "w");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
|
||||
|
||||
goTo.select("v", "u");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*x*/4/*y*/2 + 6 + 23 + 12 +" years old"
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to template literal",
|
||||
actionDescription: "Convert to template literal",
|
||||
newContent:
|
||||
`const foo = \`\${42 + 6 + 23 + 12} years old\``,
|
||||
});
|
||||
Reference in New Issue
Block a user