@@ -455,18 +455,28 @@ export const function_visitor = (node, context) => {
455
455
function get_hoistable_params ( node , context ) {
456
456
const scope = context . state . scope ;
457
457
458
- /** @type {import('estree').Pattern [] } */
458
+ /** @type {import('estree').Identifier [] } */
459
459
const params = [ ] ;
460
460
let added_props = false ;
461
461
462
+ /**
463
+ * we only want to push if it's not already present to avoid name clashing
464
+ * @param {import('estree').Identifier } id
465
+ */
466
+ function safe_push ( id ) {
467
+ if ( ! params . find ( ( param ) => param . name === id . name ) ) {
468
+ params . push ( id ) ;
469
+ }
470
+ }
471
+
462
472
for ( const [ reference ] of scope . references ) {
463
473
const binding = scope . get ( reference ) ;
464
474
465
475
if ( binding !== null && ! scope . declarations . has ( reference ) && binding . initial !== node ) {
466
476
if ( binding . kind === 'store_sub' ) {
467
477
// We need both the subscription for getting the value and the store for updating
468
- params . push ( b . id ( binding . node . name . slice ( 1 ) ) ) ;
469
- params . push ( b . id ( binding . node . name ) ) ;
478
+ safe_push ( b . id ( binding . node . name . slice ( 1 ) ) ) ;
479
+ safe_push ( b . id ( binding . node . name ) ) ;
470
480
} else if (
471
481
// If it's a destructured derived binding, then we can extract the derived signal reference and use that.
472
482
binding . expression !== null &&
@@ -477,7 +487,7 @@ function get_hoistable_params(node, context) {
477
487
binding . expression . object . callee . name === '$.get' &&
478
488
binding . expression . object . arguments [ 0 ] . type === 'Identifier'
479
489
) {
480
- params . push ( b . id ( binding . expression . object . arguments [ 0 ] . name ) ) ;
490
+ safe_push ( b . id ( binding . expression . object . arguments [ 0 ] . name ) ) ;
481
491
} else if (
482
492
// If we are referencing a simple $$props value, then we need to reference the object property instead
483
493
( binding . kind === 'prop' || binding . kind === 'bindable_prop' ) &&
@@ -488,11 +498,11 @@ function get_hoistable_params(node, context) {
488
498
// Handle $$props.something use-cases
489
499
if ( ! added_props ) {
490
500
added_props = true ;
491
- params . push ( b . id ( '$$props' ) ) ;
501
+ safe_push ( b . id ( '$$props' ) ) ;
492
502
}
493
503
} else {
494
504
// create a copy to remove start/end tags which would mess up source maps
495
- params . push ( b . id ( binding . node . name ) ) ;
505
+ safe_push ( b . id ( binding . node . name ) ) ;
496
506
}
497
507
}
498
508
}
0 commit comments