@@ -32,8 +32,8 @@ import {
32
32
resume_effect
33
33
} from '../../reactivity/effects.js' ;
34
34
import { source , mutable_source , set } from '../../reactivity/sources.js' ;
35
- import { is_array , is_frozen } from '../../../shared/utils.js' ;
36
- import { INERT , STATE_SYMBOL } from '../../constants.js' ;
35
+ import { array_from , is_array } from '../../../shared/utils.js' ;
36
+ import { INERT } from '../../constants.js' ;
37
37
import { queue_micro_task } from '../task.js' ;
38
38
import { current_effect } from '../../runtime.js' ;
39
39
@@ -139,7 +139,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
139
139
? collection
140
140
: collection == null
141
141
? [ ]
142
- : Array . from ( collection ) ;
142
+ : array_from ( collection ) ;
143
143
144
144
var length = array . length ;
145
145
@@ -242,14 +242,14 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
242
242
var first = state . first ;
243
243
var current = first ;
244
244
245
- /** @type {Set<EachItem> } */
246
- var seen = new Set ( ) ;
245
+ /** @type {undefined | Set<EachItem> } */
246
+ var seen ;
247
247
248
248
/** @type {EachItem | null } */
249
249
var prev = null ;
250
250
251
- /** @type {Set<EachItem> } */
252
- var to_animate = new Set ( ) ;
251
+ /** @type {undefined | Set<EachItem> } */
252
+ var to_animate ;
253
253
254
254
/** @type {EachItem[] } */
255
255
var matched = [ ] ;
@@ -277,7 +277,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
277
277
278
278
if ( item !== undefined ) {
279
279
item . a ?. measure ( ) ;
280
- to_animate . add ( item ) ;
280
+ ( to_animate ??= new Set ( ) ) . add ( item ) ;
281
281
}
282
282
}
283
283
}
@@ -319,12 +319,12 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
319
319
resume_effect ( item . e ) ;
320
320
if ( is_animated ) {
321
321
item . a ?. unfix ( ) ;
322
- to_animate . delete ( item ) ;
322
+ ( to_animate ??= new Set ( ) ) . delete ( item ) ;
323
323
}
324
324
}
325
325
326
326
if ( item !== current ) {
327
- if ( seen . has ( item ) ) {
327
+ if ( seen !== undefined && seen . has ( item ) ) {
328
328
if ( matched . length < stashed . length ) {
329
329
// more efficient to move later items to the front
330
330
var start = stashed [ 0 ] ;
@@ -372,7 +372,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
372
372
stashed = [ ] ;
373
373
374
374
while ( current !== null && current . k !== key ) {
375
- seen . add ( current ) ;
375
+ ( seen ??= new Set ( ) ) . add ( current ) ;
376
376
stashed . push ( current ) ;
377
377
current = current . next ;
378
378
}
@@ -389,32 +389,36 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
389
389
current = item . next ;
390
390
}
391
391
392
- const to_destroy = Array . from ( seen ) ;
392
+ if ( current !== null || seen !== undefined ) {
393
+ var to_destroy = seen === undefined ? [ ] : array_from ( seen ) ;
393
394
394
- while ( current !== null ) {
395
- to_destroy . push ( current ) ;
396
- current = current . next ;
397
- }
398
- var destroy_length = to_destroy . length ;
395
+ while ( current !== null ) {
396
+ to_destroy . push ( current ) ;
397
+ current = current . next ;
398
+ }
399
399
400
- if ( destroy_length > 0 ) {
401
- var controlled_anchor = ( flags & EACH_IS_CONTROLLED ) !== 0 && length === 0 ? anchor : null ;
400
+ var destroy_length = to_destroy . length ;
402
401
403
- if ( is_animated ) {
404
- for ( i = 0 ; i < destroy_length ; i += 1 ) {
405
- to_destroy [ i ] . a ?. measure ( ) ;
406
- }
402
+ if ( destroy_length > 0 ) {
403
+ var controlled_anchor = ( flags & EACH_IS_CONTROLLED ) !== 0 && length === 0 ? anchor : null ;
407
404
408
- for ( i = 0 ; i < destroy_length ; i += 1 ) {
409
- to_destroy [ i ] . a ?. fix ( ) ;
405
+ if ( is_animated ) {
406
+ for ( i = 0 ; i < destroy_length ; i += 1 ) {
407
+ to_destroy [ i ] . a ?. measure ( ) ;
408
+ }
409
+
410
+ for ( i = 0 ; i < destroy_length ; i += 1 ) {
411
+ to_destroy [ i ] . a ?. fix ( ) ;
412
+ }
410
413
}
411
- }
412
414
413
- pause_effects ( state , to_destroy , controlled_anchor , items ) ;
415
+ pause_effects ( state , to_destroy , controlled_anchor , items ) ;
416
+ }
414
417
}
415
418
416
419
if ( is_animated ) {
417
420
queue_micro_task ( ( ) => {
421
+ if ( to_animate === undefined ) return ;
418
422
for ( item of to_animate ) {
419
423
item . a ?. apply ( ) ;
420
424
}
0 commit comments