remove parentheses also when expression at ending

This commit is contained in:
BigAru
2018-12-07 12:14:23 +01:00
parent 7d9e8f4e21
commit 74e3cd758e
2 changed files with 13 additions and 2 deletions

View File

@@ -164,15 +164,14 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
i++;
}
if (isParenthesizedExpression(current)) current = current.expression;
text = cleanString(text);
templatePart = i === nodes.length - 1 ? createTemplateTail(text) : createTemplateMiddle(text);
}
else {
templatePart = i === nodes.length - 1 ? createTemplateTail("") : createTemplateMiddle("");
}
if (isParenthesizedExpression(current)) current = current.expression;
spans.push(createTemplateSpan(current as Expression, templatePart));
}

View File

@@ -0,0 +1,12 @@
/// <reference path='fourslash.ts' />
//// const foo = "/*x*/f/*y*/oobar is " + (42 + 6)
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert string concatenation or template literal",
actionName: "Convert to template literal",
actionDescription: "Convert to template literal",
newContent:
"const foo = `foobar is \${42 + 6}`",
});