@@ -36,7 +36,6 @@ export class StringConcatToTemplate implements QuickFix {
36
36
backTickCharacter = '`' ;
37
37
backTick = new RegExp ( this . backTickCharacter , 'g' ) ;
38
38
$regex = / \$ / g;
39
- finalOutput : string [ ] = [ ] ;
40
39
key = StringConcatToTemplate . name ;
41
40
42
41
canProvideFix ( info : QuickFixQueryInformation ) : CanProvideFixResponse {
@@ -53,6 +52,8 @@ export class StringConcatToTemplate implements QuickFix {
53
52
}
54
53
55
54
provideFix ( info : QuickFixQueryInformation ) : Refactoring [ ] {
55
+ const finalOutput : string [ ] = [ ] ;
56
+
56
57
var strRoot = isAPartOfAChainOfStringAdditions ( info . positionNode , info . typeChecker ) ;
57
58
let current : ts . Node = strRoot ;
58
59
@@ -61,19 +62,19 @@ export class StringConcatToTemplate implements QuickFix {
61
62
// if we are still in some sequence of additions
62
63
if ( current . kind == ts . SyntaxKind . BinaryExpression ) {
63
64
let binary = < ts . BinaryExpression > current ;
64
- this . appendToFinal ( binary . right ) ;
65
+ this . appendToFinal ( finalOutput , binary . right ) ;
65
66
66
67
// Continue with left
67
68
current = binary . left ;
68
69
}
69
70
else {
70
- this . appendToFinal ( current ) ;
71
+ this . appendToFinal ( finalOutput , current ) ;
71
72
break ;
72
73
}
73
74
}
74
75
75
76
let newText = this . backTickCharacter +
76
- this . finalOutput . join ( '' ) +
77
+ finalOutput . join ( '' ) +
77
78
this . backTickCharacter ;
78
79
79
80
var refactoring : Refactoring = {
@@ -88,7 +89,7 @@ export class StringConcatToTemplate implements QuickFix {
88
89
return [ refactoring ] ;
89
90
}
90
91
91
- private appendToFinal ( node : ts . Node ) {
92
+ private appendToFinal ( finalOutput : string [ ] , node : ts . Node ) {
92
93
// Each string literal needs :
93
94
// to be checked that it doesn't contain (`) and those need to be escaped.
94
95
// Also `$` needs escaping
@@ -106,17 +107,17 @@ export class StringConcatToTemplate implements QuickFix {
106
107
. replace ( this . $regex , '\\$' ) ;
107
108
108
109
newText = newText . substr ( 1 , newText . length - 2 ) ;
109
- this . finalOutput . unshift ( newText ) ;
110
+ finalOutput . unshift ( newText ) ;
110
111
}
111
112
else if ( node . kind == ts . SyntaxKind . TemplateExpression || node . kind == ts . SyntaxKind . NoSubstitutionTemplateLiteral ) {
112
113
let text = node . getText ( ) ;
113
114
text = text . trim ( ) ;
114
115
text = text . substr ( 1 , text . length - 2 ) ;
115
- this . finalOutput . unshift ( text ) ;
116
+ finalOutput . unshift ( text ) ;
116
117
}
117
118
// Each expression that isn't a string literal will just be escaped `${}`
118
119
else {
119
- this . finalOutput . unshift ( '${' + node . getText ( ) + '}' ) ;
120
+ finalOutput . unshift ( '${' + node . getText ( ) + '}' ) ;
120
121
}
121
122
}
122
123
}
0 commit comments