Skip to content

Commit 41b981c

Browse files
authored
fix(47853): Convert to template string issue (#47976)
1 parent 0043abe commit 41b981c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/services/refactors/convertStringOrTemplateLiteral.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
215215
const isLastSpan = index === currentNode.templateSpans.length - 1;
216216
const text = span.literal.text + (isLastSpan ? subsequentText : "");
217217
const rawText = getRawTextOfTemplate(span.literal) + (isLastSpan ? rawSubsequentText : "");
218-
return factory.createTemplateSpan(span.expression, isLast
218+
return factory.createTemplateSpan(span.expression, isLast && isLastSpan
219219
? factory.createTemplateTail(text, rawText)
220220
: factory.createTemplateMiddle(text, rawText));
221221
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////fetch(/*start*/process.env.API_URL + `/foo/bar?id=${id}&token=${token}`/*end*/);
4+
5+
goTo.select("start", "end");
6+
edit.applyRefactor({
7+
refactorName: "Convert to template string",
8+
actionName: "Convert to template string",
9+
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
10+
newContent: "fetch(`${process.env.API_URL}/foo/bar?id=${id}&token=${token}`);",
11+
});

0 commit comments

Comments
 (0)