catch empty head of template literal

This commit is contained in:
BigAru
2018-12-06 16:09:43 +01:00
parent 2b299943f9
commit 576271ef55
2 changed files with 4 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ 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 });
@@ -58,7 +59,8 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
const templateLiteralExpression = node.parent;
const nodesArray: Expression[] = [];
nodesArray.push(createStringLiteral(templateLiteralExpression.head.text));
if (templateLiteralExpression.head.text.length !== 0) nodesArray.push(createStringLiteral(templateLiteralExpression.head.text));
templateLiteralExpression.templateSpans.forEach(ts => {
nodesArray.push(ts.expression);
const str = ts.literal.text;

View File

@@ -12,5 +12,5 @@ edit.applyRefactor({
newContent:
`const age = 22
const name = "Eddy"
const foo = "" + name + " is " + age + " years old"`,
const foo = name + " is " + age + " years old"`,
});