@@ -456,39 +456,30 @@ function get_hoistable_params(node, context) {
456456
457457 /** @type {import('estree').Identifier[] } */
458458 const params = [ ] ;
459- let added_props = false ;
460459
461460 /**
462- * we only want to push if it's not already present to avoid name clashing
461+ * We only want to push if it's not already present to avoid name clashing
463462 * @param {import('estree').Identifier } id
464463 */
465- function safe_push ( id ) {
464+ function push_unique ( id ) {
466465 if ( ! params . find ( ( param ) => param . name === id . name ) ) {
467466 params . push ( id ) ;
468467 }
469468 }
470469
471470 for ( const [ reference ] of scope . references ) {
472- const binding = scope . get ( reference ) ;
471+ let binding = scope . get ( reference ) ;
473472
474473 if ( binding !== null && ! scope . declarations . has ( reference ) && binding . initial !== node ) {
475474 if ( binding . kind === 'store_sub' ) {
476- const is_from_prop =
477- binding . declaration_kind === 'synthetic' &&
478- [ ...binding . scope . declarations . values ( ) ] . find (
479- ( declaration ) => declaration . kind === 'prop' || declaration . kind === 'bindable_prop'
480- ) ;
481- if ( is_from_prop && ! added_props ) {
482- // if the store come from props we want $$props to be pushed rather than the name
483- // of the store since that variable doesn't exist
484- added_props = true ;
485- safe_push ( b . id ( '$$props' ) ) ;
486- } else {
487- // We need both the subscription for getting the value and the store for updating
488- safe_push ( b . id ( binding . node . name . slice ( 1 ) ) ) ;
489- }
490- safe_push ( b . id ( binding . node . name ) ) ;
491- } else if (
475+ // We need both the subscription for getting the value and the store for updating
476+ push_unique ( b . id ( binding . node . name ) ) ;
477+ binding = /** @type {import('#compiler').Binding } */ (
478+ scope . get ( binding . node . name . slice ( 1 ) )
479+ ) ;
480+ }
481+
482+ if (
492483 // If it's a destructured derived binding, then we can extract the derived signal reference and use that.
493484 binding . expression !== null &&
494485 typeof binding . expression !== 'function' &&
@@ -498,22 +489,18 @@ function get_hoistable_params(node, context) {
498489 binding . expression . object . callee . name === '$.get' &&
499490 binding . expression . object . arguments [ 0 ] . type === 'Identifier'
500491 ) {
501- safe_push ( b . id ( binding . expression . object . arguments [ 0 ] . name ) ) ;
492+ push_unique ( b . id ( binding . expression . object . arguments [ 0 ] . name ) ) ;
502493 } else if (
503494 // If we are referencing a simple $$props value, then we need to reference the object property instead
504495 ( binding . kind === 'prop' || binding . kind === 'bindable_prop' ) &&
505496 ! binding . reassigned &&
506497 binding . initial === null &&
507498 ! context . state . analysis . accessors
508499 ) {
509- // Handle $$props.something use-cases
510- if ( ! added_props ) {
511- added_props = true ;
512- safe_push ( b . id ( '$$props' ) ) ;
513- }
500+ push_unique ( b . id ( '$$props' ) ) ;
514501 } else {
515502 // create a copy to remove start/end tags which would mess up source maps
516- safe_push ( b . id ( binding . node . name ) ) ;
503+ push_unique ( b . id ( binding . node . name ) ) ;
517504 }
518505 }
519506 }
0 commit comments