@@ -2373,11 +2373,6 @@ export const template_visitors = {
23732373 context . state . init . push ( b . const ( each_node_meta . array_name , b . thunk ( collection ) ) ) ;
23742374 }
23752375
2376- // The runtime needs to know what kind of each block this is in order to optimize for the
2377- // key === item (we avoid extra allocations). In that case, the item doesn't need to be reactive.
2378- // We can guarantee this by knowing that in order for the item of the each block to change, they
2379- // would need to mutate the key/item directly in the array. Given that in runes mode we use ===
2380- // equality, we can apply a fast-path (as long as the index isn't reactive).
23812376 let flags = 0 ;
23822377
23832378 if (
@@ -2390,15 +2385,13 @@ export const template_visitors = {
23902385 flags |= EACH_INDEX_REACTIVE ;
23912386 }
23922387
2393- if (
2394- context . state . analysis . runes &&
2388+ // In runes mode, if key === item, we don't need to wrap the item in a source
2389+ const key_is_item =
23952390 node . key . type === 'Identifier' &&
23962391 node . context . type === 'Identifier' &&
2397- node . context . name === node . key . name &&
2398- ! node . index
2399- ) {
2400- // Fast-path for when the key === item
2401- } else {
2392+ node . context . name === node . key . name ;
2393+
2394+ if ( ! context . state . analysis . runes || ! key_is_item ) {
24022395 flags |= EACH_ITEM_REACTIVE ;
24032396 }
24042397 } else {
@@ -2448,10 +2441,12 @@ export const template_visitors = {
24482441 ) ;
24492442 return [ array , ...transitive_dependencies ] ;
24502443 } ) ;
2444+
24512445 if ( each_node_meta . array_name ) {
24522446 indirect_dependencies . push ( b . call ( each_node_meta . array_name ) ) ;
24532447 } else {
24542448 indirect_dependencies . push ( collection ) ;
2449+
24552450 const transitive_dependencies = serialize_transitive_dependencies (
24562451 each_node_meta . references ,
24572452 context
@@ -2470,6 +2465,7 @@ export const template_visitors = {
24702465 // into separate expressions, at which point this is called again with an identifier or member expression
24712466 return serialize_set_binding ( assignment , context , ( ) => assignment ) ;
24722467 }
2468+
24732469 const left = object ( assignment . left ) ;
24742470 const value = get_assignment_value ( assignment , context ) ;
24752471 const invalidate = b . call (
@@ -2510,10 +2506,12 @@ export const template_visitors = {
25102506 const item_with_loc = with_loc ( item , id ) ;
25112507 return b . call ( '$.unwrap' , item_with_loc ) ;
25122508 } ;
2509+
25132510 if ( node . index ) {
25142511 const index_binding = /** @type {import('#compiler').Binding } */ (
25152512 context . state . scope . get ( node . index )
25162513 ) ;
2514+
25172515 index_binding . expression = ( id ) => {
25182516 const index_with_loc = with_loc ( index , id ) ;
25192517 return b . call ( '$.unwrap' , index_with_loc ) ;
0 commit comments