@@ -96,7 +96,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
96
96
return expr ;
97
97
}
98
98
99
- function arrayToTree ( nodes : Expression [ ] , accumulator ?: BinaryExpression ) : BinaryExpression {
99
+ function arrayToTree ( nodes : ReadonlyArray < Expression > , accumulator ?: BinaryExpression ) : BinaryExpression {
100
100
if ( nodes . length === 0 ) return accumulator ! ;
101
101
102
102
if ( ! accumulator ) {
@@ -113,31 +113,33 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
113
113
}
114
114
115
115
function isStringConcatenationValid ( node : Node ) : boolean {
116
- const [ , containsString , areOperatorsValid ] = treeToArray ( node ) ;
116
+ const { containsString, areOperatorsValid } = treeToArray ( node ) ;
117
117
return containsString && areOperatorsValid ;
118
118
}
119
119
120
- function transformTreeToArray ( node : Node ) : Expression [ ] {
121
- return treeToArray ( node ) [ 0 ] ;
120
+ function transformTreeToArray ( node : Node ) : ReadonlyArray < Expression > {
121
+ return treeToArray ( node ) . nodes ;
122
122
}
123
123
124
- function treeToArray ( node : Node ) : [ Expression [ ] , /* containsString */ boolean , /* areOperatorsValid */ boolean ] {
124
+ function treeToArray ( node : Node ) : { nodes : ReadonlyArray < Expression > , containsString : boolean , areOperatorsValid : boolean } {
125
125
if ( isBinaryExpression ( node ) ) {
126
- const [ leftNodes , leftHasString , leftOperatorValid ] = treeToArray ( node . left ) ;
127
- const [ rightNodes , rightHasString , rightOperatorValid ] = treeToArray ( node . right ) ;
126
+ const { nodes : leftNodes , containsString : leftHasString , areOperatorsValid : leftOperatorValid } = treeToArray ( node . left ) ;
127
+ const { nodes : rightNodes , containsString : rightHasString , areOperatorsValid : rightOperatorValid } = treeToArray ( node . right ) ;
128
128
129
- if ( ! leftHasString && ! rightHasString ) return [ [ node ] , false , true ] ;
129
+ if ( ! leftHasString && ! rightHasString ) {
130
+ return { nodes : [ node ] , containsString : false , areOperatorsValid : true } ;
131
+ }
130
132
131
133
const nodeOperatorValid = node . operatorToken . kind === SyntaxKind . PlusToken ;
132
134
const isPlus = leftOperatorValid && nodeOperatorValid && rightOperatorValid ;
133
135
134
- return [ leftNodes . concat ( rightNodes ) , true , isPlus ] ;
136
+ return { nodes : leftNodes . concat ( rightNodes ) , containsString : true , areOperatorsValid : isPlus } ;
135
137
}
136
138
137
- return [ [ node as Expression ] , isStringLiteral ( node ) , true ] ;
139
+ return { nodes : [ node as Expression ] , containsString : isStringLiteral ( node ) , areOperatorsValid : true } ;
138
140
}
139
141
140
- function createHead ( nodes : Node [ ] ) : [ number , TemplateHead ] {
142
+ function createHead ( nodes : ReadonlyArray < Expression > ) : [ number , TemplateHead ] {
141
143
let begin = 0 ;
142
144
const head = createTemplateHead ( "" ) ;
143
145
@@ -151,7 +153,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
151
153
return [ begin , head ] ;
152
154
}
153
155
154
- function nodesToTemplate ( nodes : Expression [ ] ) {
156
+ function nodesToTemplate ( nodes : ReadonlyArray < Expression > ) {
155
157
const templateSpans : TemplateSpan [ ] = [ ] ;
156
158
const [ begin , head ] = createHead ( nodes ) ;
157
159
0 commit comments