Skip to content

Commit

Permalink
catch empty head of template literal
Browse files Browse the repository at this point in the history
  • Loading branch information
bigaru committed Mar 24, 2019
1 parent 2b29994 commit 576271e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/services/refactors/convertStringOrTemplateLiteral.ts
Expand Up @@ -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 });

Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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"`,
});

0 comments on commit 576271e

Please sign in to comment.