@@ -149,14 +149,23 @@ export function EachBlock(node, context) {
149
149
each_node_meta . contains_group_binding || ! node . index ? each_node_meta . index : b . id ( node . index ) ;
150
150
const item = each_node_meta . item ;
151
151
152
+ let uses_index = each_node_meta . contains_group_binding ;
153
+ let key_uses_index = false ;
154
+
152
155
if ( node . index ) {
153
- if ( ( flags & EACH_INDEX_REACTIVE ) !== 0 ) {
154
- child_state . transform [ node . index ] = { read : get_value } ;
155
- } else {
156
- delete child_state . transform [ node . index ] ;
157
- }
156
+ child_state . transform [ node . index ] = {
157
+ read : ( node ) => {
158
+ uses_index = true ;
159
+ return ( flags & EACH_INDEX_REACTIVE ) !== 0 ? get_value ( node ) : node ;
160
+ }
161
+ } ;
158
162
159
- delete key_state . transform [ node . index ] ;
163
+ key_state . transform [ node . index ] = {
164
+ read : ( node ) => {
165
+ key_uses_index = true ;
166
+ return node ;
167
+ }
168
+ } ;
160
169
}
161
170
162
171
/** @type {Statement[] } */
@@ -180,6 +189,8 @@ export function EachBlock(node, context) {
180
189
child_state . transform [ node . context . name ] = {
181
190
read : ( flags & EACH_ITEM_REACTIVE ) !== 0 ? get_value : ( node ) => node ,
182
191
assign : ( _ , value ) => {
192
+ uses_index = true ;
193
+
183
194
const left = b . member (
184
195
each_node_meta . array_name ? b . call ( each_node_meta . array_name ) : collection ,
185
196
index ,
@@ -238,7 +249,7 @@ export function EachBlock(node, context) {
238
249
context . visit ( /** @type {Expression } */ ( node . key ) , key_state )
239
250
) ;
240
251
241
- key_function = b . arrow ( [ node . context , index ] , expression ) ;
252
+ key_function = b . arrow ( key_uses_index ? [ node . context , index ] : [ node . context ] , expression ) ;
242
253
}
243
254
244
255
if ( node . index && each_node_meta . contains_group_binding ) {
@@ -259,7 +270,10 @@ export function EachBlock(node, context) {
259
270
b . literal ( flags ) ,
260
271
each_node_meta . array_name ? each_node_meta . array_name : b . thunk ( collection ) ,
261
272
key_function ,
262
- b . arrow ( [ b . id ( '$$anchor' ) , item , index ] , b . block ( declarations . concat ( block . body ) ) )
273
+ b . arrow (
274
+ uses_index ? [ b . id ( '$$anchor' ) , item , index ] : [ b . id ( '$$anchor' ) , item ] ,
275
+ b . block ( declarations . concat ( block . body ) )
276
+ )
263
277
] ;
264
278
265
279
if ( node . fallback ) {
0 commit comments