mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Remove refactoring from template expression to string concatenation.
This commit is contained in:
parent
88795e2a2e
commit
ad0f0064ce
@ -5349,10 +5349,6 @@
|
||||
"category": "Message",
|
||||
"code": 95097
|
||||
},
|
||||
"Convert to string concatenation": {
|
||||
"category": "Message",
|
||||
"code": 95098
|
||||
},
|
||||
|
||||
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
|
||||
"category": "Error",
|
||||
|
||||
@ -2,11 +2,9 @@
|
||||
namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
const refactorName = "Convert string concatenation or template literal";
|
||||
const toTemplateLiteralActionName = "Convert to template literal";
|
||||
const toStringConcatenationActionName = "Convert to string concatenation";
|
||||
|
||||
const refactorDescription = getLocaleSpecificMessage(Diagnostics.Convert_string_concatenation_or_template_literal);
|
||||
const toTemplateLiteralDescription = getLocaleSpecificMessage(Diagnostics.Convert_to_template_literal);
|
||||
const toStringConcatenationDescription = getLocaleSpecificMessage(Diagnostics.Convert_to_string_concatenation);
|
||||
|
||||
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
|
||||
|
||||
@ -20,14 +18,6 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
refactorInfo.actions.push({ name: toTemplateLiteralActionName, description: toTemplateLiteralDescription });
|
||||
return [refactorInfo];
|
||||
}
|
||||
|
||||
const templateLiteral = findAncestor(node, n => isTemplateLiteral(n));
|
||||
|
||||
if (templateLiteral && !isTaggedTemplateExpression(templateLiteral.parent)) {
|
||||
refactorInfo.actions.push({ name: toStringConcatenationActionName, description: toStringConcatenationDescription });
|
||||
return [refactorInfo];
|
||||
}
|
||||
|
||||
return emptyArray;
|
||||
}
|
||||
|
||||
@ -46,17 +36,13 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
return node;
|
||||
}
|
||||
|
||||
function getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined {
|
||||
function getEditsForAction(context: RefactorContext, actionName: typeof toTemplateLiteralActionName): RefactorEditInfo | undefined {
|
||||
const { file, startPosition } = context;
|
||||
const node = getNodeOrParentOfParentheses(file, startPosition);
|
||||
|
||||
switch (actionName) {
|
||||
case toTemplateLiteralActionName:
|
||||
return { edits: getEditsForToTemplateLiteral(context, node) };
|
||||
|
||||
case toStringConcatenationActionName:
|
||||
return { edits: getEditsForToStringConcatenation(context, node) };
|
||||
|
||||
default:
|
||||
return Debug.fail("invalid action");
|
||||
}
|
||||
@ -85,33 +71,6 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
}
|
||||
}
|
||||
|
||||
const templateSpanToExpressions = (file: SourceFile) => (templateSpan: TemplateSpan): Expression[] => {
|
||||
const { expression, literal } = templateSpan;
|
||||
const text = literal.text;
|
||||
copyTrailingAsLeadingComments(templateSpan, expression, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
|
||||
return text.length === 0 ? [expression] : [expression, createStringLiteral(text)];
|
||||
};
|
||||
|
||||
function getEditsForToStringConcatenation(context: RefactorContext, node: Node) {
|
||||
const templateLiteral = findAncestor(node, n => isTemplateLiteral(n))! as TemplateLiteral;
|
||||
|
||||
if (isTemplateExpression(templateLiteral)) {
|
||||
const { head, templateSpans } = templateLiteral;
|
||||
const spanToExpressionWithComment = templateSpanToExpressions(context.file);
|
||||
const arrayOfNodes = templateSpans.map(spanToExpressionWithComment)
|
||||
.reduce((accumulator, nextArray) => accumulator.concat(nextArray));
|
||||
|
||||
if (head.text.length !== 0) arrayOfNodes.unshift(createStringLiteral(head.text));
|
||||
|
||||
const singleExpressionOrBinary = makeSingleExpressionOrBinary(arrayOfNodes);
|
||||
return textChanges.ChangeTracker.with(context, t => t.replaceNode(context.file, templateLiteral, singleExpressionOrBinary));
|
||||
}
|
||||
else {
|
||||
const stringLiteral = createStringLiteral(templateLiteral.text);
|
||||
return textChanges.ChangeTracker.with(context, t => t.replaceNode(context.file, node, stringLiteral));
|
||||
}
|
||||
}
|
||||
|
||||
function isNotEqualsOperator(node: BinaryExpression) {
|
||||
return node.operatorToken.kind !== SyntaxKind.EqualsToken;
|
||||
}
|
||||
@ -123,26 +82,6 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
return expr;
|
||||
}
|
||||
|
||||
function makeSingleExpressionOrBinary(nodes: readonly Expression[]): Expression {
|
||||
if (nodes.length > 1) {
|
||||
const left = nodes[0];
|
||||
const right = nodes[1];
|
||||
|
||||
const binary = createBinary(left, SyntaxKind.PlusToken, right);
|
||||
return arrayToTree(nodes, 2, binary);
|
||||
}
|
||||
|
||||
return nodes[0];
|
||||
}
|
||||
|
||||
function arrayToTree(nodes: readonly Expression[], index: number, accumulator: BinaryExpression): Expression {
|
||||
if (nodes.length === index) return accumulator;
|
||||
|
||||
const right = nodes[index];
|
||||
const binary = createBinary(accumulator, SyntaxKind.PlusToken, right);
|
||||
return arrayToTree(nodes, index + 1, binary);
|
||||
}
|
||||
|
||||
function isStringConcatenationValid(node: Node): boolean {
|
||||
const { containsString, areOperatorsValid } = treeToArray(node);
|
||||
return containsString && areOperatorsValid;
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// console.log(`/*x*/f/*y*/oobar is ${ 32 } 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:
|
||||
`console.log("foobar is " + 32 + " years old")`,
|
||||
});
|
||||
@ -1,39 +0,0 @@
|
||||
/// <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 + 34 } 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");
|
||||
|
||||
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 = "Mr " + name + " is " + (age + 34) + " years old"`,
|
||||
});
|
||||
@ -1,17 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// function tag(literals: TemplateStringsArray, ...placeholders: any[]) { 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");
|
||||
@ -1,12 +0,0 @@
|
||||
/// <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 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /* H */ `/*x*/H/*y*/EAD ${ /* C0 */ 42 /* C1 */} Span1 ${ /* C2 */ 43 /* C3 */} Span2 ${ /* C4 */ 44 /* C5 */} Span3` /* T */
|
||||
|
||||
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 = /* H */ "HEAD " + /* C0 */ 42 /* C1 */ + " Span1 " + /* C2 */ 43 /* C3 */ + " Span2 " + /* C4 */ 44 /* C5 */ + " Span3" /* T */`,
|
||||
});
|
||||
@ -1,12 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = /*x*/`/*y*/${/* C0 */ 42 /* C1 */}`
|
||||
|
||||
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 = /* C0 */ 42 /* C1 */`,
|
||||
});
|
||||
@ -1,12 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/H/*y*/EAD | ${ /* C0 */ 42 /* C1 */}${ /* C2 */ 43 /* C3 */}${ /* C4 */ 44 /* C5 */}`
|
||||
|
||||
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 = "HEAD | " + /* C0 */ 42 /* C1 */ + /* C2 */ 43 /* C3 */ + /* C4 */ 44 /* C5 */`,
|
||||
});
|
||||
@ -1,16 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const foo = `/*x*/$/*y*/{ name } 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 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = `foobar is a ${ age < 18 ? 'child' : /*x*/`/*y*/grown-up ${ age > 40 ? 'who needs probably 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 probably assistance' : '') }\``,
|
||||
});
|
||||
@ -1,14 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = `foobar is a ${ `/*x*/3/*y*/4` }`
|
||||
|
||||
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 \${ "34" }\``,
|
||||
});
|
||||
@ -1,14 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = `foobar is a ${ /*x*/a/*y*/ge < 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 +0,0 @@
|
||||
/// <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 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/$/*y*/{42}`
|
||||
|
||||
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 = 42`,
|
||||
});
|
||||
@ -1,12 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = `/*x*/f/*y*/oobar is ${ 42 * 6 % 4} 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 % 4 + " years old"`,
|
||||
});
|
||||
@ -1,12 +0,0 @@
|
||||
/// <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,14 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = `foobar is ${ /*x*/a/*y*/ge } 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,14 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 42
|
||||
//// const foo = `foobar is ${ age } /*x*/y/*y*/ears old ${ false }`
|
||||
|
||||
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 " + false`,
|
||||
});
|
||||
@ -1,12 +0,0 @@
|
||||
/// <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,39 +0,0 @@
|
||||
/// <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 * 4 / 2 + " 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");
|
||||
|
||||
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 = \`Mr \${name} is \${age * 4 / 2} years old\``,
|
||||
});
|
||||
@ -1,25 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const name = "Eddy"
|
||||
//// const /*z*/f/*y*/oo = /*x*/"/*w*/M/*v*/r/*u*/ " /*t*/+/*s*/ name + " is " - /*r*/a/*q*/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.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");
|
||||
|
||||
goTo.select("t", "s");
|
||||
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("r", "q");
|
||||
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");
|
||||
@ -1,19 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const /*z*/f/*y*/oo = /*x*/4/*w*/2 /*v*/-/*u*/ 56 + /*t*/2/*s*/2 * 4 / 33
|
||||
|
||||
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");
|
||||
|
||||
goTo.select("t", "s");
|
||||
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");
|
||||
@ -1,33 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const age = 22
|
||||
//// const /*z*/f/*y*/oo = /*x*/a/*w*/ge * 4 /*v*/-/*u*/ 2 / 4 /*t*/+/*s*/ " /*r*/y/*q*/ears 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");
|
||||
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to template literal",
|
||||
actionDescription: "Convert to template literal",
|
||||
newContent:
|
||||
`const age = 22
|
||||
const foo = \`\${age * 4 - 2 / 4} years old\``,
|
||||
});
|
||||
@ -1,25 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// let foo = ""
|
||||
//// /*z*/f/*y*/oo = "/*x*/M/*w*/r Bar" + " is" + /*v*/4/*u*/2 + " 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");
|
||||
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to template literal",
|
||||
actionDescription: "Convert to template literal",
|
||||
newContent:
|
||||
`let foo = ""
|
||||
foo = \`Mr Bar is\${42} years old\``,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user