fix(47853): Convert to template string issue (#47976)

This commit is contained in:
Zzzen 2022-03-01 02:40:48 +08:00 committed by GitHub
parent 0043abe982
commit 41b981c998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -215,7 +215,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
const isLastSpan = index === currentNode.templateSpans.length - 1;
const text = span.literal.text + (isLastSpan ? subsequentText : "");
const rawText = getRawTextOfTemplate(span.literal) + (isLastSpan ? rawSubsequentText : "");
return factory.createTemplateSpan(span.expression, isLast
return factory.createTemplateSpan(span.expression, isLast && isLastSpan
? factory.createTemplateTail(text, rawText)
: factory.createTemplateMiddle(text, rawText));
});

View File

@ -0,0 +1,11 @@
/// <reference path='fourslash.ts' />
////fetch(/*start*/process.env.API_URL + `/foo/bar?id=${id}&token=${token}`/*end*/);
goTo.select("start", "end");
edit.applyRefactor({
refactorName: "Convert to template string",
actionName: "Convert to template string",
actionDescription: ts.Diagnostics.Convert_to_template_string.message,
newContent: "fetch(`${process.env.API_URL}/foo/bar?id=${id}&token=${token}`);",
});