Skip to content

Commit 576271e

Browse files
committed
catch empty head of template literal
1 parent 2b29994 commit 576271e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/services/refactors/convertStringOrTemplateLiteral.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
99
const toStringConcatenationDescription = getLocaleSpecificMessage(Diagnostics.Convert_to_string_concatenation);
1010

1111
// TODO let a = 45 + 45 + " ee" + 33;
12+
// TODO let a = tag `aaa`;
1213

1314
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
1415

@@ -58,7 +59,8 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
5859
const templateLiteralExpression = node.parent;
5960
const nodesArray: Expression[] = [];
6061

61-
nodesArray.push(createStringLiteral(templateLiteralExpression.head.text));
62+
if (templateLiteralExpression.head.text.length !== 0) nodesArray.push(createStringLiteral(templateLiteralExpression.head.text));
63+
6264
templateLiteralExpression.templateSpans.forEach(ts => {
6365
nodesArray.push(ts.expression);
6466
const str = ts.literal.text;

tests/cases/fourslash/refactorConvertStringOrTemplateLiteral_ToStringMultiExpr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ edit.applyRefactor({
1212
newContent:
1313
`const age = 22
1414
const name = "Eddy"
15-
const foo = "" + name + " is " + age + " years old"`,
15+
const foo = name + " is " + age + " years old"`,
1616
});

0 commit comments

Comments
 (0)