@@ -226,21 +226,23 @@ function compound(
226
226
dynamic ,
227
227
{ name, anchor, params, hasElse, if_name }
228
228
) {
229
- const get_block = block . getUniqueName ( `get_block ` ) ;
230
- const current_block = block . getUniqueName ( `current_block ` ) ;
231
- const current_block_and = hasElse ? '' : `${ current_block } && ` ;
229
+ const select_block_type = generator . getUniqueName ( `select_block_type ` ) ;
230
+ const current_block_type = block . getUniqueName ( `current_block_type ` ) ;
231
+ const current_block_type_and = hasElse ? '' : `${ current_block_type } && ` ;
232
232
233
- block . builders . init . addBlock ( deindent `
234
- function ${ get_block } ( ${ params } ) {
233
+ generator . blocks . push ( deindent `
234
+ function ${ select_block_type } ( ${ params } ) {
235
235
${ branches
236
236
. map ( ( { condition, block } ) => {
237
237
return `${ condition ? `if ( ${ condition } ) ` : '' } return ${ block } ;` ;
238
238
} )
239
239
. join ( '\n' ) }
240
240
}
241
+ ` ) ;
241
242
242
- var ${ current_block } = ${ get_block } ( ${ params } );
243
- var ${ name } = ${ current_block_and } ${ current_block } ( ${ params } , #component );
243
+ block . builders . init . addBlock ( deindent `
244
+ var ${ current_block_type } = ${ select_block_type } ( ${ params } );
245
+ var ${ name } = ${ current_block_type_and } ${ current_block_type } ( ${ params } , #component );
244
246
` ) ;
245
247
246
248
const isTopLevel = ! state . parentNode ;
@@ -265,22 +267,22 @@ function compound(
265
267
${ name } .unmount();
266
268
${ name } .destroy();
267
269
}` }
268
- ${ name } = ${ current_block_and } ${ current_block } ( ${ params } , #component );
270
+ ${ name } = ${ current_block_type_and } ${ current_block_type } ( ${ params } , #component );
269
271
${ if_name } ${ name } .create();
270
272
${ if_name } ${ name } .${ mountOrIntro } ( ${ parentNode } , ${ anchor } );
271
273
` ;
272
274
273
275
if ( dynamic ) {
274
276
block . builders . update . addBlock ( deindent `
275
- if ( ${ current_block } === ( ${ current_block } = ${ get_block } ( ${ params } ) ) && ${ name } ) {
277
+ if ( ${ current_block_type } === ( ${ current_block_type } = ${ select_block_type } ( ${ params } ) ) && ${ name } ) {
276
278
${ name } .update( changed, ${ params } );
277
279
} else {
278
280
${ changeBlock }
279
281
}
280
282
` ) ;
281
283
} else {
282
284
block . builders . update . addBlock ( deindent `
283
- if ( ${ current_block } !== ( ${ current_block } = ${ get_block } ( ${ params } ) ) ) {
285
+ if ( ${ current_block_type } !== ( ${ current_block_type } = ${ select_block_type } ( ${ params } ) ) ) {
284
286
${ changeBlock }
285
287
}
286
288
` ) ;
@@ -302,17 +304,17 @@ function compoundWithOutros(
302
304
dynamic ,
303
305
{ name, anchor, params, hasElse }
304
306
) {
305
- const get_block = block . getUniqueName ( `get_block ` ) ;
306
- const current_block_index = block . getUniqueName ( `current_block_index ` ) ;
307
+ const select_block_type = block . getUniqueName ( `select_block_type ` ) ;
308
+ const current_block_type_index = block . getUniqueName ( `current_block_type_index ` ) ;
307
309
const previous_block_index = block . getUniqueName ( `previous_block_index` ) ;
308
310
const if_block_creators = block . getUniqueName ( `if_block_creators` ) ;
309
311
const if_blocks = block . getUniqueName ( `if_blocks` ) ;
310
312
311
- const if_current_block_index = hasElse
313
+ const if_current_block_type_index = hasElse
312
314
? ''
313
- : `if ( ~${ current_block_index } ) ` ;
315
+ : `if ( ~${ current_block_type_index } ) ` ;
314
316
315
- block . addVariable ( current_block_index ) ;
317
+ block . addVariable ( current_block_type_index ) ;
316
318
block . addVariable ( name ) ;
317
319
318
320
block . builders . init . addBlock ( deindent `
@@ -322,7 +324,7 @@ function compoundWithOutros(
322
324
323
325
var ${ if_blocks } = [];
324
326
325
- function ${ get_block } ( ${ params } ) {
327
+ function ${ select_block_type } ( ${ params } ) {
326
328
${ branches
327
329
. map ( ( { condition, block } , i ) => {
328
330
return `${ condition ? `if ( ${ condition } ) ` : '' } return ${ block
@@ -335,13 +337,13 @@ function compoundWithOutros(
335
337
336
338
if ( hasElse ) {
337
339
block . builders . init . addBlock ( deindent `
338
- ${ current_block_index } = ${ get_block } ( ${ params } );
339
- ${ name } = ${ if_blocks } [ ${ current_block_index } ] = ${ if_block_creators } [ ${ current_block_index } ]( ${ params } , #component );
340
+ ${ current_block_type_index } = ${ select_block_type } ( ${ params } );
341
+ ${ name } = ${ if_blocks } [ ${ current_block_type_index } ] = ${ if_block_creators } [ ${ current_block_type_index } ]( ${ params } , #component );
340
342
` ) ;
341
343
} else {
342
344
block . builders . init . addBlock ( deindent `
343
- if ( ~( ${ current_block_index } = ${ get_block } ( ${ params } ) ) ) {
344
- ${ name } = ${ if_blocks } [ ${ current_block_index } ] = ${ if_block_creators } [ ${ current_block_index } ]( ${ params } , #component );
345
+ if ( ~( ${ current_block_type_index } = ${ select_block_type } ( ${ params } ) ) ) {
346
+ ${ name } = ${ if_blocks } [ ${ current_block_type_index } ] = ${ if_block_creators } [ ${ current_block_type_index } ]( ${ params } , #component );
345
347
}
346
348
` ) ;
347
349
}
@@ -352,7 +354,7 @@ function compoundWithOutros(
352
354
const anchorNode = state . parentNode ? 'null' : 'anchor' ;
353
355
354
356
block . builders . mount . addLine (
355
- `${ if_current_block_index } ${ if_blocks } [ ${ current_block_index } ].${ mountOrIntro } ( ${ targetNode } , ${ anchorNode } );`
357
+ `${ if_current_block_type_index } ${ if_blocks } [ ${ current_block_type_index } ].${ mountOrIntro } ( ${ targetNode } , ${ anchorNode } );`
356
358
) ;
357
359
358
360
const parentNode = state . parentNode || `${ anchor } .parentNode` ;
@@ -366,9 +368,9 @@ function compoundWithOutros(
366
368
` ;
367
369
368
370
const createNewBlock = deindent `
369
- ${ name } = ${ if_blocks } [ ${ current_block_index } ];
371
+ ${ name } = ${ if_blocks } [ ${ current_block_type_index } ];
370
372
if ( !${ name } ) {
371
- ${ name } = ${ if_blocks } [ ${ current_block_index } ] = ${ if_block_creators } [ ${ current_block_index } ]( ${ params } , #component );
373
+ ${ name } = ${ if_blocks } [ ${ current_block_type_index } ] = ${ if_block_creators } [ ${ current_block_type_index } ]( ${ params } , #component );
372
374
${ name } .create();
373
375
}
374
376
${ name } .${ mountOrIntro } ( ${ parentNode } , ${ anchor } );
@@ -385,7 +387,7 @@ function compoundWithOutros(
385
387
${ destroyOldBlock }
386
388
}
387
389
388
- if ( ~${ current_block_index } ) {
390
+ if ( ~${ current_block_type_index } ) {
389
391
${ createNewBlock }
390
392
} else {
391
393
${ name } = null;
@@ -394,28 +396,28 @@ function compoundWithOutros(
394
396
395
397
if ( dynamic ) {
396
398
block . builders . update . addBlock ( deindent `
397
- var ${ previous_block_index } = ${ current_block_index } ;
398
- ${ current_block_index } = ${ get_block } ( ${ params } );
399
- if ( ${ current_block_index } === ${ previous_block_index } ) {
400
- ${ if_current_block_index } ${ if_blocks } [ ${ current_block_index } ].update( changed, ${ params } );
399
+ var ${ previous_block_index } = ${ current_block_type_index } ;
400
+ ${ current_block_type_index } = ${ select_block_type } ( ${ params } );
401
+ if ( ${ current_block_type_index } === ${ previous_block_index } ) {
402
+ ${ if_current_block_type_index } ${ if_blocks } [ ${ current_block_type_index } ].update( changed, ${ params } );
401
403
} else {
402
404
${ changeBlock }
403
405
}
404
406
` ) ;
405
407
} else {
406
408
block . builders . update . addBlock ( deindent `
407
- var ${ previous_block_index } = ${ current_block_index } ;
408
- ${ current_block_index } = ${ get_block } ( ${ params } );
409
- if ( ${ current_block_index } !== ${ previous_block_index } ) {
409
+ var ${ previous_block_index } = ${ current_block_type_index } ;
410
+ ${ current_block_type_index } = ${ select_block_type } ( ${ params } );
411
+ if ( ${ current_block_type_index } !== ${ previous_block_index } ) {
410
412
${ changeBlock }
411
413
}
412
414
` ) ;
413
415
}
414
416
415
417
block . builders . destroy . addLine ( deindent `
416
- ${ if_current_block_index } {
417
- ${ if_blocks } [ ${ current_block_index } ].unmount();
418
- ${ if_blocks } [ ${ current_block_index } ].destroy();
418
+ ${ if_current_block_type_index } {
419
+ ${ if_blocks } [ ${ current_block_type_index } ].unmount();
420
+ ${ if_blocks } [ ${ current_block_type_index } ].destroy();
419
421
}
420
422
` ) ;
421
423
}
0 commit comments