@@ -51,25 +51,29 @@ export function VariableDeclaration(node, context) {
5151 }
5252 }
5353 } ) ;
54- const to_remove = [ b . prop ( 'init' , b . id ( '$$events' ) , b . id ( '$$events' ) ) ] ;
55- // we don't want to spread away `$$slots` if `$$slots` is used in the component
56- // otherwise there will be a reference to `$$slots` in the component already
57- // the typecast is fine since `$props` can only be used in a component
58- if ( ! ( /** @type {ComponentAnalysis } */ ( context . state . analysis ) . uses_slots ) ) {
59- to_remove . unshift ( b . prop ( 'init' , b . id ( '$$slots' ) , b . id ( '$$slots' ) ) ) ;
60- }
54+
55+ // if `$$slots` is declared separately, deconflict
56+ const slots_name = /** @type {ComponentAnalysis } */ ( context . state . analysis ) . uses_slots
57+ ? b . id ( '$$slots_' )
58+ : b . id ( '$$slots' ) ;
59+
6160 if ( id . type === 'ObjectPattern' && has_rest ) {
6261 // If a rest pattern is used within an object pattern, we need to ensure we don't expose $$slots or $$events
6362 id . properties . splice (
6463 id . properties . length - 1 ,
6564 0 ,
6665 // @ts -ignore
67- ...to_remove
66+ b . prop ( 'init' , b . id ( '$$slots' ) , slots_name ) ,
67+ b . prop ( 'init' , b . id ( '$$events' ) , b . id ( '$$events' ) )
6868 ) ;
6969 } else if ( id . type === 'Identifier' ) {
7070 // If $props is referenced as an identifier, we need to ensure we don't expose $$slots or $$events as properties
7171 // on the identifier reference
72- id = b . object_pattern ( [ ...to_remove , b . rest ( b . id ( id . name ) ) ] ) ;
72+ id = b . object_pattern ( [
73+ b . prop ( 'init' , b . id ( '$$slots' ) , slots_name ) ,
74+ b . prop ( 'init' , b . id ( '$$events' ) , b . id ( '$$events' ) ) ,
75+ b . rest ( b . id ( id . name ) )
76+ ] ) ;
7377 }
7478 declarations . push (
7579 b . declarator ( /** @type {Pattern } */ ( context . visit ( id ) ) , b . id ( '$$props' ) )
0 commit comments