support case when variable is re-assigned

This commit is contained in:
BigAru
2019-03-24 12:26:58 +01:00
parent 1bcd8da415
commit 29fc8c30ba
3 changed files with 22 additions and 1 deletions
@@ -83,8 +83,12 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
return text.length === 0 ? [expression] : [expression, createStringLiteral(text)];
}
function isNotEqualsOperator(node: BinaryExpression) {
return node.operatorToken.kind !== SyntaxKind.EqualsToken;
}
function getParentBinaryExpression(expr: Node) {
while (isBinaryExpression(expr.parent)) {
while (isBinaryExpression(expr.parent) && isNotEqualsOperator(expr.parent)) {
expr = expr.parent;
}
return expr;
@@ -0,0 +1,16 @@
/// <reference path='fourslash.ts' />
//// let foo = ""
//// /*z*/f/*y*/oo = "/*x*/M/*w*/r Bar" + " is" + /*v*/4/*u*/2 + " years old"
goTo.select("z", "y");
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
goTo.select("x", "w");
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
verify.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
goTo.select("v", "u");
verify.not.refactorAvailable("Convert string concatenation or template literal", "Convert to string concatenation");
verify.refactorAvailable("Convert string concatenation or template literal", "Convert to template literal");
@@ -10,3 +10,4 @@ edit.applyRefactor({
newContent:
"const foo = `with $\\\\{dollar}`",
});