Cleaned up refactoring names, descriptions.

This commit is contained in:
Daniel Rosenwasser
2020-01-02 16:32:06 -08:00
parent ad0f0064ce
commit ff4fa1feb9
24 changed files with 72 additions and 79 deletions

View File

@@ -5341,14 +5341,10 @@
"category": "Message",
"code": 95095
},
"Convert string concatenation or template literal": {
"Convert to template string": {
"category": "Message",
"code": 95096
},
"Convert to template literal": {
"category": "Message",
"code": 95097
},
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
"category": "Error",

View File

@@ -1,10 +1,7 @@
/* @internal */
namespace ts.refactor.convertStringOrTemplateLiteral {
const refactorName = "Convert string concatenation or template literal";
const toTemplateLiteralActionName = "Convert to template literal";
const refactorDescription = getLocaleSpecificMessage(Diagnostics.Convert_string_concatenation_or_template_literal);
const toTemplateLiteralDescription = getLocaleSpecificMessage(Diagnostics.Convert_to_template_literal);
const refactorName = "Convert to template string";
const refactorDescription = getLocaleSpecificMessage(Diagnostics.Convert_to_template_string);
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
@@ -15,7 +12,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
const refactorInfo: ApplicableRefactorInfo = { name: refactorName, description: refactorDescription, actions: [] };
if ((isBinaryExpression(maybeBinary) || isStringLiteral(maybeBinary)) && isStringConcatenationValid(maybeBinary)) {
refactorInfo.actions.push({ name: toTemplateLiteralActionName, description: toTemplateLiteralDescription });
refactorInfo.actions.push({ name: refactorName, description: refactorDescription });
return [refactorInfo];
}
return emptyArray;
@@ -36,12 +33,12 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
return node;
}
function getEditsForAction(context: RefactorContext, actionName: typeof toTemplateLiteralActionName): RefactorEditInfo | undefined {
function getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined {
const { file, startPosition } = context;
const node = getNodeOrParentOfParentheses(file, startPosition);
switch (actionName) {
case toTemplateLiteralActionName:
case refactorDescription:
return { edits: getEditsForToTemplateLiteral(context, node) };
default:
return Debug.fail("invalid action");

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`console.log(\`foobar is \${32} years old\`)`,
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
"const foo = `with back\\`tick`",
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
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\``,
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
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}`",
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
"const foo = /* C0 */ `foo is\${ /* C1 */ /* C2 */42 /* C3 */} and bar is\${ /* C4 */ /* C5 */52 /* C6 */}`",
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
"const foo = /* C0 */ `foo is\${ /* C1 */ /* C2 */42 /* C3 */} and bar is\${ /* C4 */ /* C5 */52 /* C6 */}`",
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
"const foo = /* C0 */ `foo is` /* C1 */ /* C2 */ /* C3 */",
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
"const foo = `foobar is\${/* C1 */ 42 /* C2 */ /* C3 */} years old`",
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
"const foo = /* C0 */ `foo is\${ /* C1 */ /* C2 */42 /* C3 */}`",
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
"const foo = /* C0 */ `foo is\${ /* C1 */ /* C2 */42} years old` /* C3 */",
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`const foo = \`foobar is \${42} years old and \${6} cars are missing\``,
});

View File

@@ -6,9 +6,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`const age = 22
const name = "Eddy"

View File

@@ -5,9 +5,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`const age = 42
const foo = \`foobar is \${age} years old\``,

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
"const foo = `foobar rocks fantastically`",
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
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 / 4} years old\``,
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
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\``,
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
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\``,
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
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}str\`) + " years old"`,
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
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\``,
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`const foo = \`\${42 - 6 * 4 + 23 / 12} years old\``,
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`const foo = \`foobar rocks\``,
});

View File

@@ -4,9 +4,9 @@
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent:
`const foo = \`foobar rocks\``,
});