@@ -2493,6 +2493,12 @@ export const template_visitors = {
24932493 getters : { ...context . state . getters }
24942494 } ;
24952495
2496+ /** The state used when generating the key function, if necessary */
2497+ const key_state = {
2498+ ...context . state ,
2499+ getters : { ...context . state . getters }
2500+ } ;
2501+
24962502 /**
24972503 * @param {Pattern } expression_for_id
24982504 * @returns {Binding['mutation'] }
@@ -2552,6 +2558,8 @@ export const template_visitors = {
25522558 const index_with_loc = with_loc ( index , id ) ;
25532559 return b . call ( '$.unwrap' , index_with_loc ) ;
25542560 } ;
2561+
2562+ key_state . getters [ node . index ] = b . id ( node . index ) ;
25552563 }
25562564
25572565 /** @type {Statement[] } */
@@ -2565,6 +2573,8 @@ export const template_visitors = {
25652573 true
25662574 )
25672575 ) ;
2576+
2577+ key_state . getters [ node . context . name ] = node . context ;
25682578 } else {
25692579 const unwrapped = getter ( binding . node ) ;
25702580 const paths = extract_paths ( node . context ) ;
@@ -2592,23 +2602,22 @@ export const template_visitors = {
25922602 if ( context . state . options . dev ) {
25932603 declarations . push ( b . stmt ( getter ) ) ;
25942604 }
2605+
2606+ key_state . getters [ name ] = path . node ;
25952607 }
25962608 }
25972609
25982610 const block = /** @type {BlockStatement } */ ( context . visit ( node . body , child_state ) ) ;
25992611
2600- const key_function = node . key
2601- ? b . arrow (
2602- [ node . context . type === 'Identifier' ? node . context : b . id ( '$$item' ) , index ] ,
2603- declarations . length > 0
2604- ? b . block (
2605- declarations . concat (
2606- b . return ( /** @type {Expression } */ ( context . visit ( node . key , child_state ) ) )
2607- )
2608- )
2609- : /** @type {Expression } */ ( context . visit ( node . key , child_state ) )
2610- )
2611- : b . id ( '$.index' ) ;
2612+ /** @type {Expression } */
2613+ let key_function = b . id ( '$.index' ) ;
2614+
2615+ if ( node . key ) {
2616+ key_function = b . arrow (
2617+ [ node . context , index ] ,
2618+ /** @type {Expression } */ ( context . visit ( node . key , key_state ) )
2619+ ) ;
2620+ }
26122621
26132622 if ( node . index && each_node_meta . contains_group_binding ) {
26142623 // We needed to create a unique identifier for the index above, but we want to use the
0 commit comments