@@ -51,11 +51,12 @@ export function VariableDeclaration(node, context) {
51
51
init ?. type === 'AwaitExpression' &&
52
52
context . state . analysis . instance ?. scope === context . state . scope
53
53
) {
54
+ const current_chunk = context . state . current_parallelized_chunk ;
54
55
const parallelize = can_be_parallelized (
55
56
init . argument ,
56
57
context . state . scope ,
57
58
context . state . analysis ,
58
- [ ...( context . state . current_parallelized_chunk ?. bindings ?? [ ] ) , ...bindings ]
59
+ [ ...( current_chunk ?. bindings ?? [ ] ) , ...bindings ]
59
60
) ;
60
61
if ( parallelize ) {
61
62
const { id, init : visited_init } = /** @type {VariableDeclarator } */ (
@@ -68,15 +69,10 @@ export function VariableDeclaration(node, context) {
68
69
id,
69
70
init : /** @type {Expression } */ ( visited_init )
70
71
} ;
71
- if (
72
- context . state . current_parallelized_chunk &&
73
- context . state . current_parallelized_chunk . kind === node . kind
74
- ) {
75
- context . state . current_parallelized_chunk . declarators . push ( _declarator ) ;
76
- context . state . current_parallelized_chunk . bindings . push ( ...bindings ) ;
77
- context . state . current_parallelized_chunk . position = /** @type {Program } */ (
78
- parent
79
- ) . body . indexOf ( node ) ;
72
+ if ( current_chunk && current_chunk . kind === node . kind ) {
73
+ current_chunk . declarators . push ( _declarator ) ;
74
+ current_chunk . bindings . push ( ...bindings ) ;
75
+ current_chunk . position = /** @type {Program } */ ( parent ) . body . indexOf ( node ) ;
80
76
} else {
81
77
/** @type {ParallelizedChunk } */
82
78
const chunk = {
@@ -251,6 +247,7 @@ export function VariableDeclaration(node, context) {
251
247
/** @type {CallExpression } */ ( init )
252
248
) ;
253
249
let parallelize = false ;
250
+ const current_chunk = context . state . current_parallelized_chunk ;
254
251
if (
255
252
is_async &&
256
253
context . state . analysis . instance &&
@@ -259,7 +256,7 @@ export function VariableDeclaration(node, context) {
259
256
declarator . id . type === 'Identifier'
260
257
) {
261
258
parallelize = can_be_parallelized ( value , context . state . scope , context . state . analysis , [
262
- ...( context . state . current_parallelized_chunk ?. bindings ?? [ ] ) ,
259
+ ...( current_chunk ?. bindings ?? [ ] ) ,
263
260
...context . state . scope . get_bindings ( declarator )
264
261
] ) ;
265
262
}
@@ -369,18 +366,14 @@ export function VariableDeclaration(node, context) {
369
366
if ( ! parallelize ) {
370
367
declarations . push ( ...derived_declarators ) ;
371
368
} else if ( derived_declarators . length > 0 ) {
372
- /** @type {ParallelizedChunk['declarators'] } */
373
369
const declarators = derived_declarators . map ( ( { id, init } ) => ( {
374
370
id,
375
371
init : /** @type {Expression } */ ( init )
376
372
} ) ) ;
377
- if (
378
- context . state . current_parallelized_chunk &&
379
- context . state . current_parallelized_chunk . kind === node . kind
380
- ) {
381
- context . state . current_parallelized_chunk . declarators . push ( ...declarators ) ;
382
- context . state . current_parallelized_chunk . bindings . push ( ...bindings ) ;
383
- context . state . current_parallelized_chunk . position = position ;
373
+ if ( current_chunk && current_chunk . kind === node . kind ) {
374
+ current_chunk . declarators . push ( ...declarators ) ;
375
+ current_chunk . bindings . push ( ...bindings ) ;
376
+ current_chunk . position = position ;
384
377
} else {
385
378
/** @type {ParallelizedChunk } */
386
379
const chunk = {
0 commit comments