@@ -6,7 +6,7 @@ namespace ts {
6
6
interface FlattenContext {
7
7
context : TransformationContext ;
8
8
level : FlattenLevel ;
9
- doNotRecordTempVariablesInLine : boolean ;
9
+ hoistTempVariables : boolean ;
10
10
emitExpression : ( value : Expression ) => void ;
11
11
emitBindingOrAssignment : ( target : BindingOrAssignmentElementTarget , value : Expression , location : TextRange , original : Node ) => void ;
12
12
createArrayBindingOrAssignmentPattern : ( elements : BindingOrAssignmentElement [ ] ) => ArrayBindingOrAssignmentPattern ;
@@ -57,7 +57,7 @@ namespace ts {
57
57
const flattenContext : FlattenContext = {
58
58
context,
59
59
level,
60
- doNotRecordTempVariablesInLine : true ,
60
+ hoistTempVariables : true ,
61
61
emitExpression,
62
62
emitBindingOrAssignment,
63
63
createArrayBindingOrAssignmentPattern : makeArrayAssignmentPattern ,
@@ -126,7 +126,7 @@ namespace ts {
126
126
* @param context The transformation context.
127
127
* @param boundValue The value bound to the declaration.
128
128
* @param skipInitializer A value indicating whether to ignore the initializer of `node`.
129
- * @param doNotRecordTempVariablesInLine Indicates whether temporary variables should not be recored in-line.
129
+ * @param hoistTempVariables Indicates whether temporary variables should not be recorded in-line.
130
130
* @param level Indicates the extent to which flattening should occur.
131
131
*/
132
132
export function flattenDestructuringBinding (
@@ -135,29 +135,26 @@ namespace ts {
135
135
context : TransformationContext ,
136
136
level : FlattenLevel ,
137
137
rval ?: Expression ,
138
- doNotRecordTempVariablesInLine ?: boolean ,
138
+ hoistTempVariables ?: boolean ,
139
139
skipInitializer ?: boolean ) : VariableDeclaration [ ] {
140
-
141
140
let pendingExpressions : Expression [ ] ;
142
141
const pendingDeclarations : { pendingExpressions ?: Expression [ ] , name : BindingName , value : Expression , location ?: TextRange , original ?: Node ; } [ ] = [ ] ;
143
142
const declarations : VariableDeclaration [ ] = [ ] ;
144
143
const flattenContext : FlattenContext = {
145
144
context,
146
145
level,
147
- doNotRecordTempVariablesInLine ,
146
+ hoistTempVariables ,
148
147
emitExpression,
149
148
emitBindingOrAssignment,
150
149
createArrayBindingOrAssignmentPattern : makeArrayBindingPattern ,
151
150
createObjectBindingOrAssignmentPattern : makeObjectBindingPattern ,
152
151
createArrayBindingOrAssignmentElement : makeBindingElement ,
153
152
visitor
154
153
} ;
155
-
156
154
flattenBindingOrAssignmentElement ( flattenContext , node , rval , node , skipInitializer ) ;
157
-
158
155
if ( pendingExpressions ) {
159
156
const temp = createTempVariable ( /*recordTempVariable*/ undefined ) ;
160
- if ( doNotRecordTempVariablesInLine ) {
157
+ if ( hoistTempVariables ) {
161
158
const value = inlineExpressions ( pendingExpressions ) ;
162
159
pendingExpressions = undefined ;
163
160
emitBindingOrAssignment ( temp , value , /*location*/ undefined , /*original*/ undefined ) ;
@@ -173,7 +170,6 @@ namespace ts {
173
170
pendingDeclaration . value = temp ;
174
171
}
175
172
}
176
-
177
173
for ( const { pendingExpressions, name, value, location, original } of pendingDeclarations ) {
178
174
const variable = createVariableDeclaration (
179
175
name ,
@@ -187,7 +183,6 @@ namespace ts {
187
183
aggregateTransformFlags ( variable ) ;
188
184
declarations . push ( variable ) ;
189
185
}
190
-
191
186
return declarations ;
192
187
193
188
function emitExpression ( value : Expression ) {
@@ -330,7 +325,7 @@ namespace ts {
330
325
// can perform the ObjectRest destructuring in a different declaration
331
326
if ( element . transformFlags & TransformFlags . ContainsObjectRest ) {
332
327
const temp = createTempVariable ( /*recordTempVariable*/ undefined ) ;
333
- if ( flattenContext . doNotRecordTempVariablesInLine ) {
328
+ if ( flattenContext . hoistTempVariables ) {
334
329
flattenContext . context . hoistVariableDeclaration ( temp ) ;
335
330
}
336
331
@@ -419,7 +414,7 @@ namespace ts {
419
414
}
420
415
else {
421
416
const temp = createTempVariable ( /*recordTempVariable*/ undefined ) ;
422
- if ( flattenContext . doNotRecordTempVariablesInLine ) {
417
+ if ( flattenContext . hoistTempVariables ) {
423
418
flattenContext . context . hoistVariableDeclaration ( temp ) ;
424
419
flattenContext . emitExpression ( createAssignment ( temp , value , location ) ) ;
425
420
}
@@ -430,46 +425,28 @@ namespace ts {
430
425
}
431
426
}
432
427
433
- /**
434
- * Creates an ArrayBindingPattern from an array of BindingOrAssignmentElement nodes.
435
- */
436
428
function makeArrayBindingPattern ( elements : BindingOrAssignmentElement [ ] ) {
437
429
Debug . assertEachNode ( elements , isArrayBindingElement ) ;
438
430
return createArrayBindingPattern ( < ArrayBindingElement [ ] > elements ) ;
439
431
}
440
432
441
- /**
442
- * Creates an ArrayLiteralExpression assignment pattern from an array of BindingOrAssignmentElement nodes.
443
- */
444
433
function makeArrayAssignmentPattern ( elements : BindingOrAssignmentElement [ ] ) {
445
434
return createArrayLiteral ( map ( elements , convertToArrayAssignmentElement ) ) ;
446
435
}
447
436
448
- /**
449
- * Creates an ObjectBindingPattern from an array of BindingOrAssignmentElement nodes.
450
- */
451
437
function makeObjectBindingPattern ( elements : BindingOrAssignmentElement [ ] ) {
452
438
Debug . assertEachNode ( elements , isBindingElement ) ;
453
439
return createObjectBindingPattern ( < BindingElement [ ] > elements ) ;
454
440
}
455
441
456
- /**
457
- * Creates an ObjectLiteralExpression assignment pattern from an array of BindingOrAssignmentElement nodes.
458
- */
459
442
function makeObjectAssignmentPattern ( elements : BindingOrAssignmentElement [ ] ) {
460
443
return createObjectLiteral ( map ( elements , convertToObjectAssignmentElement ) ) ;
461
444
}
462
445
463
- /**
464
- * Creates a BindingElement for a name.
465
- */
466
446
function makeBindingElement ( name : Identifier ) {
467
447
return createBindingElement ( /*propertyName*/ undefined , /*dotDotDotToken*/ undefined , name ) ;
468
448
}
469
449
470
- /**
471
- * Creates an assignment element for a name.
472
- */
473
450
function makeAssignmentElement ( name : Identifier ) {
474
451
return name ;
475
452
}
0 commit comments