@@ -36,7 +36,6 @@ export class StringConcatToTemplate implements QuickFix {
3636 backTickCharacter = '`' ;
3737 backTick = new RegExp ( this . backTickCharacter , 'g' ) ;
3838 $regex = / \$ / g;
39- finalOutput : string [ ] = [ ] ;
4039 key = StringConcatToTemplate . name ;
4140
4241 canProvideFix ( info : QuickFixQueryInformation ) : CanProvideFixResponse {
@@ -53,6 +52,8 @@ export class StringConcatToTemplate implements QuickFix {
5352 }
5453
5554 provideFix ( info : QuickFixQueryInformation ) : Refactoring [ ] {
55+ const finalOutput : string [ ] = [ ] ;
56+
5657 var strRoot = isAPartOfAChainOfStringAdditions ( info . positionNode , info . typeChecker ) ;
5758 let current : ts . Node = strRoot ;
5859
@@ -61,19 +62,19 @@ export class StringConcatToTemplate implements QuickFix {
6162 // if we are still in some sequence of additions
6263 if ( current . kind == ts . SyntaxKind . BinaryExpression ) {
6364 let binary = < ts . BinaryExpression > current ;
64- this . appendToFinal ( binary . right ) ;
65+ this . appendToFinal ( finalOutput , binary . right ) ;
6566
6667 // Continue with left
6768 current = binary . left ;
6869 }
6970 else {
70- this . appendToFinal ( current ) ;
71+ this . appendToFinal ( finalOutput , current ) ;
7172 break ;
7273 }
7374 }
7475
7576 let newText = this . backTickCharacter +
76- this . finalOutput . join ( '' ) +
77+ finalOutput . join ( '' ) +
7778 this . backTickCharacter ;
7879
7980 var refactoring : Refactoring = {
@@ -88,7 +89,7 @@ export class StringConcatToTemplate implements QuickFix {
8889 return [ refactoring ] ;
8990 }
9091
91- private appendToFinal ( node : ts . Node ) {
92+ private appendToFinal ( finalOutput : string [ ] , node : ts . Node ) {
9293 // Each string literal needs :
9394 // to be checked that it doesn't contain (`) and those need to be escaped.
9495 // Also `$` needs escaping
@@ -106,17 +107,17 @@ export class StringConcatToTemplate implements QuickFix {
106107 . replace ( this . $regex , '\\$' ) ;
107108
108109 newText = newText . substr ( 1 , newText . length - 2 ) ;
109- this . finalOutput . unshift ( newText ) ;
110+ finalOutput . unshift ( newText ) ;
110111 }
111112 else if ( node . kind == ts . SyntaxKind . TemplateExpression || node . kind == ts . SyntaxKind . NoSubstitutionTemplateLiteral ) {
112113 let text = node . getText ( ) ;
113114 text = text . trim ( ) ;
114115 text = text . substr ( 1 , text . length - 2 ) ;
115- this . finalOutput . unshift ( text ) ;
116+ finalOutput . unshift ( text ) ;
116117 }
117118 // Each expression that isn't a string literal will just be escaped `${}`
118119 else {
119- this . finalOutput . unshift ( '${' + node . getText ( ) + '}' ) ;
120+ finalOutput . unshift ( '${' + node . getText ( ) + '}' ) ;
120121 }
121122 }
122123}
0 commit comments