mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-16 15:51:35 -05:00
add test cases
This commit is contained in:
@@ -3,6 +3,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
const refactorName = "Convert string concatenation or template literal";
|
||||
const toTemplateLiteralActionName = "Convert to template literal";
|
||||
// const toStringConcatenationActionName = "Convert to string concatenation";
|
||||
// let str = ""; str;
|
||||
|
||||
const refactorDescription = getLocaleSpecificMessage(Diagnostics.Convert_string_concatenation_or_template_literal);
|
||||
const toTemplateLiteralDescription = getLocaleSpecificMessage(Diagnostics.Convert_to_template_literal);
|
||||
@@ -11,8 +12,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
|
||||
|
||||
function getAvailableActions(context: RefactorContext): ReadonlyArray<ApplicableRefactorInfo> {
|
||||
const { file, startPosition } = context; file; startPosition;
|
||||
|
||||
const { file, startPosition } = context;
|
||||
const node = getTokenAtPosition(file, startPosition);
|
||||
const maybeBinary = getParentBinaryExpression(node); containsString(maybeBinary);
|
||||
if (!(isBinaryExpression(maybeBinary) || isStringLiteral(maybeBinary)) || !containsString(maybeBinary)) return emptyArray;
|
||||
@@ -34,24 +34,23 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
}
|
||||
|
||||
function getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined {
|
||||
const { file, startPosition } = context; file; startPosition; actionName;
|
||||
const { file, startPosition } = context;
|
||||
const node = getTokenAtPosition(file, startPosition);
|
||||
|
||||
|
||||
switch (actionName) {
|
||||
case toTemplateLiteralActionName:
|
||||
const maybeBinary = getParentBinaryExpression(node);
|
||||
let templateLiteral: TemplateExpression | NoSubstitutionTemplateLiteral;
|
||||
if (isStringLiteral(maybeBinary)) {
|
||||
templateLiteral = createNoSubstitutionTemplateLiteral(maybeBinary.text);
|
||||
templateLiteral = createNoSubstitutionTemplateLiteral(cleanString(maybeBinary.text));
|
||||
}
|
||||
else {
|
||||
const arrayOfNodes = treeToArray(maybeBinary); arrayOfNodes;
|
||||
const arrayOfNodes = treeToArray(maybeBinary);
|
||||
templateLiteral = nodesToTemplate(arrayOfNodes);
|
||||
}
|
||||
|
||||
const edits = textChanges.ChangeTracker.with(context, t => t.replaceNode(file, maybeBinary, templateLiteral));
|
||||
return {edits};
|
||||
return { edits };
|
||||
|
||||
default:
|
||||
return Debug.fail("invalid action");
|
||||
@@ -76,7 +75,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
|
||||
function treeToArray(node: Node): Node[] {
|
||||
if (isBinaryExpression(node)) {
|
||||
return treeToArray(node.left).concat(treeToArray(node.right))
|
||||
return treeToArray(node.left).concat(treeToArray(node.right));
|
||||
}
|
||||
return [node];
|
||||
}
|
||||
@@ -88,46 +87,56 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
const firstNode = nodes[0];
|
||||
const spans: TemplateSpan[] = [];
|
||||
|
||||
if (isStringLiteral(firstNode)){
|
||||
if (isStringLiteral(firstNode)) {
|
||||
head.text = firstNode.text;
|
||||
begin++;
|
||||
|
||||
while(begin < nodes.length && isStringLiteral(nodes[begin])){
|
||||
while (begin < nodes.length && isStringLiteral(nodes[begin])) {
|
||||
|
||||
let next = nodes[begin] as StringLiteral;
|
||||
const next = nodes[begin] as StringLiteral;
|
||||
head.text = head.text + next.text;
|
||||
begin++;
|
||||
}
|
||||
|
||||
head.text = cleanString(head.text);
|
||||
}
|
||||
|
||||
if(begin === nodes.length){
|
||||
if (begin === nodes.length) {
|
||||
return createNoSubstitutionTemplateLiteral(head.text);
|
||||
}
|
||||
|
||||
for(let i = begin; i < nodes.length; i++){
|
||||
const current = nodes[i];
|
||||
for (let i = begin; i < nodes.length; i++) {
|
||||
let current = nodes[i];
|
||||
let templatePart: TemplateMiddle | TemplateTail;
|
||||
|
||||
if (i+1 < nodes.length && isStringLiteral(nodes[i+1])){
|
||||
let next = nodes[i+1] as StringLiteral;
|
||||
if (i + 1 < nodes.length && isStringLiteral(nodes[i + 1])) {
|
||||
let next = nodes[i + 1] as StringLiteral;
|
||||
let text = next.text;
|
||||
i++;
|
||||
|
||||
while(i+1 < nodes.length && isStringLiteral(nodes[i+1])){
|
||||
next = nodes[i+1] as StringLiteral;
|
||||
while (i + 1 < nodes.length && isStringLiteral(nodes[i + 1])) {
|
||||
next = nodes[i + 1] as StringLiteral;
|
||||
text = text + next.text;
|
||||
i++;
|
||||
}
|
||||
|
||||
const templatePart = i === nodes.length-1 ? createTemplateTail(text) : createTemplateMiddle(text);
|
||||
spans.push(createTemplateSpan(current as Expression, templatePart));
|
||||
if (isParenthesizedExpression(current)) current = current.expression;
|
||||
text = cleanString(text);
|
||||
|
||||
templatePart = i === nodes.length - 1 ? createTemplateTail(text) : createTemplateMiddle(text);
|
||||
}
|
||||
else {
|
||||
const templatePart = i === nodes.length-1 ? createTemplateTail("") : createTemplateMiddle("");
|
||||
spans.push(createTemplateSpan(current as Expression, templatePart));
|
||||
templatePart = i === nodes.length - 1 ? createTemplateTail("") : createTemplateMiddle("");
|
||||
}
|
||||
|
||||
spans.push(createTemplateSpan(current as Expression, templatePart));
|
||||
}
|
||||
|
||||
return createTemplateExpression(head, spans);
|
||||
}
|
||||
|
||||
function cleanString(content: string) {
|
||||
return content.replace("`", "\`").replace("\${", `$\\{`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const /*z*/f/*y*/oo = /*x*/`/*w*/M/*v*/r/*u*/ /*t*/$/*s*/{ /*r*/n/*q*/ame } is $/*p*/{/*o*/ age } years old`
|
||||
|
||||
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.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.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("t", "s");
|
||||
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")
|
||||
|
||||
goTo.select("r", "q");
|
||||
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")
|
||||
|
||||
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")
|
||||
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const /*z*/f/*y*/oo = /*x*/`/*w*/M/*v*/r/*u*/ /*t*/$/*s*/{ /*r*/n/*q*/ame } is $/*p*/{/*o*/ age } years old`
|
||||
|
||||
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.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.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("t", "s");
|
||||
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")
|
||||
|
||||
goTo.select("r", "q");
|
||||
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")
|
||||
|
||||
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")
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/w/*y*/ith back\`tick`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
"const foo = \"with back`tick\"",
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/w/*y*/ith back\`tick`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
"const foo = \"with back`tick\"",
|
||||
});
|
||||
|
||||
@@ -1,12 +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 string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const foo = "foobar is " + (42 + 6) + " years old"`,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/f/*y*/oobar is ${ 42 + 6 } years old`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const foo = "foobar is " + (42 + 6) + " years old"`,
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/w/*y*/ith \${dollar}`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
"const foo = \"with ${dollar}\"",
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/w/*y*/ith \${dollar}`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
"const foo = \"with ${dollar}\"",
|
||||
});
|
||||
|
||||
@@ -1,12 +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 string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const foo = "foobar is " + 42 + 6 + " years old"`,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/f/*y*/oobar is ${ 42 }${ 6 } years old`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const foo = "foobar is " + 42 + 6 + " years old"`,
|
||||
});
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const foo = `${ /*x*/n/*y*/ame } is ${ age } years old`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const age = 22
|
||||
const name = "Eddy"
|
||||
const foo = name + " is " + age + " years old"`,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const foo = `${ /*x*/n/*y*/ame } is ${ age } years old`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const age = 22
|
||||
const name = "Eddy"
|
||||
const foo = name + " is " + age + " years old"`,
|
||||
});
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = `/*x*/f/*y*/oobar is a ${ age < 18 ? 'child' : `grown-up ${ age > 40 ? 'who needs probaply assistance': ''}` }`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const age = 42
|
||||
const foo = "foobar is a " + ( age < 18 ? 'child' : \`grown-up \${ age > 40 ? 'who needs probaply assistance': ''}\` ) `,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = `/*x*/f/*y*/oobar is a ${ age < 18 ? 'child' : `grown-up ${ age > 40 ? 'who needs probaply assistance': ''}` }`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const age = 42
|
||||
const foo = "foobar is a " + ( age < 18 ? 'child' : \`grown-up \${ age > 40 ? 'who needs probaply assistance': ''}\` ) `,
|
||||
});
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = `/*x*/f/*y*/oobar is ${ age } years old`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const age = 42
|
||||
const foo = "foobar is " + age + " years old"`,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = `/*x*/f/*y*/oobar is ${ age } years old`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const age = 42
|
||||
const foo = "foobar is " + age + " years old"`,
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/f/*y*/oobar rocks`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const foo = "foobar rocks"`,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/f/*y*/oobar rocks`
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to string concatenation",
|
||||
actionDescription: "Convert to string concatenation",
|
||||
newContent:
|
||||
`const foo = "foobar rocks"`,
|
||||
});
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const /*z*/f/*y*/oo = /*x*/"/*w*/M/*v*/r/*u*/ " /*t*/+/*s*/ /*r*/n/*q*/ame + " is " + /*p*/a/*o*/ge + " years old"
|
||||
|
||||
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.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.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal")
|
||||
|
||||
goTo.select("t", "s");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation")
|
||||
verify.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal")
|
||||
|
||||
goTo.select("r", "q");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation")
|
||||
verify.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal")
|
||||
|
||||
goTo.select("p", "o");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation")
|
||||
verify.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal")
|
||||
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const /*z*/f/*y*/oo = /*x*/"/*w*/M/*v*/r/*u*/ " /*t*/+/*s*/ /*r*/n/*q*/ame + " is " + /*p*/a/*o*/ge + " years old"
|
||||
|
||||
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.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.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
|
||||
|
||||
goTo.select("t", "s");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
|
||||
verify.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
|
||||
|
||||
goTo.select("r", "q");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
|
||||
verify.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
|
||||
|
||||
goTo.select("p", "o");
|
||||
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
|
||||
verify.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/w/*y*/ith back`tick"
|
||||
|
||||
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 = `with back\`tick`",
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/w/*y*/ith back`tick"
|
||||
|
||||
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 = `with back\\`tick`",
|
||||
});
|
||||
|
||||
@@ -1,12 +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 string concatenation or template literal",
|
||||
actionName: "Convert to template literal",
|
||||
actionDescription: "Convert to template literal",
|
||||
newContent:
|
||||
`const foo = \`foobar is \${ 42 + 6 } years old\``,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/f/*y*/oobar is " + (42 + 6) + " 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 = \`foobar is \${42 + 6} years old\``,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/f/*y*/oobar is " + 42 + " years" + " old" + " and " + 6 + " cars" + " are" + " missing"
|
||||
|
||||
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 = \`foobar is \${42} years old and \${6} cars are missing\``,
|
||||
});
|
||||
@@ -1,12 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/w/*y*/ith ${dollar}"
|
||||
|
||||
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 = `with \${dollar}`",
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/w/*y*/ith ${dollar}"
|
||||
|
||||
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 = `with $\\{dollar}`",
|
||||
});
|
||||
|
||||
@@ -1,12 +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 string concatenation or template literal",
|
||||
actionName: "Convert to template literal",
|
||||
actionDescription: "Convert to template literal",
|
||||
newContent:
|
||||
`const foo = \`foobar is \${ 42 }\${ 6 } years old\``,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/f/*y*/oobar is " + 42 + 6 + " 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 = \`foobar is \${42}\${6} years old\``,
|
||||
});
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const foo = /*x*/n/*y*/ame + " is " + age + " 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 age = 22
|
||||
const name = "Eddy"
|
||||
const foo = \`\${ name } is \${ age } years old\``,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const foo = /*x*/n/*y*/ame + " is " + age + " 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 age = 22
|
||||
const name = "Eddy"
|
||||
const foo = \`\${name} is \${age} years old\``,
|
||||
});
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/w/*y*/ait for others\n"
|
||||
//// + "D'oh!\n"
|
||||
//// + ""Yada, yada, yada\n"
|
||||
//// + "Hasta la vista, baby!"
|
||||
|
||||
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 = \`wait for others
|
||||
D'oh!
|
||||
Yada, yada, yada
|
||||
Hasta la vista, baby!\``,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/w/*y*/ait for others\n"
|
||||
//// + "D'oh!\n"
|
||||
//// + ""Yada, yada, yada\n"
|
||||
//// + "Hasta la vista, baby!"
|
||||
|
||||
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 = \`wait for others
|
||||
D'oh!
|
||||
Yada, yada, yada
|
||||
Hasta la vista, baby!\``,
|
||||
});
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/w/*y*/ait for new line\n"
|
||||
//// + "bada bum!"
|
||||
|
||||
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 = \`wait for new line
|
||||
bada bum!\``,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/w/*y*/ait for new line\n"
|
||||
//// + "bada bum!"
|
||||
|
||||
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 = \`wait for new line
|
||||
bada bum!\``,
|
||||
});
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = "/*x*/f/*y*/oobar is " + age + " 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 age = 42
|
||||
const foo = \`foobar is \${ age } years old\``,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = "/*x*/f/*y*/oobar is " + age + " 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 age = 42
|
||||
const foo = \`foobar is \${age} years old\``,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/f/*y*/oobar " + "rocks" + " fantastically"
|
||||
|
||||
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 = `foobar rocks fantastically`",
|
||||
});
|
||||
@@ -1,12 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/f/*y*/oobar rocks"
|
||||
|
||||
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 = \`foobar rocks\``,
|
||||
});
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "/*x*/f/*y*/oobar rocks"
|
||||
|
||||
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 = \`foobar rocks\``,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user