mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
support case when variable is re-assigned
This commit is contained in:
@@ -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;
|
||||
|
||||
+16
@@ -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}`",
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user