@@ -27,7 +27,7 @@ export function SnippetBlock(node, context) {
2727 const can_hoist =
2828 context . path . length === 1 &&
2929 context . path [ 0 ] . type === 'Fragment' &&
30- can_hoist_snippet ( node , local_scope , context . state . scopes ) ;
30+ can_hoist_snippet ( local_scope , context . state . scopes ) ;
3131 const undefined_exports = context . state . analysis . undefined_exports ;
3232 const name = node . expression . name ;
3333
@@ -78,15 +78,14 @@ export function SnippetBlock(node, context) {
7878}
7979
8080/**
81- * @param {AST.SnippetBlock } node
8281 * @param {Map<SvelteNode, Scope> } scopes
8382 * @param {Scope } scope
8483 */
85- function can_hoist_snippet ( node , scope , scopes , visited = new Set ( ) ) {
86- ref_loop: for ( const [ reference ] of scope . references ) {
84+ function can_hoist_snippet ( scope , scopes , visited = new Set ( ) ) {
85+ for ( const [ reference ] of scope . references ) {
8786 const binding = scope . get ( reference ) ;
8887
89- if ( ! binding || binding . node === node . expression || binding . scope . function_depth === 0 ) {
88+ if ( ! binding || binding . scope . function_depth === 0 ) {
9089 continue ;
9190 }
9291
@@ -95,21 +94,12 @@ function can_hoist_snippet(node, scope, scopes, visited = new Set()) {
9594 continue ;
9695 }
9796
98- // Recursively check if another snippet can be hoisted
99- if ( binding . kind === 'normal' ) {
100- for ( const ref of binding . references ) {
101- const parent = ref . path . at ( - 1 ) ;
102- if ( ref . node === binding . node && parent ?. type === 'SnippetBlock' ) {
103- const ref_scope = scopes . get ( parent ) ;
104- if ( visited . has ( ref ) ) {
105- break ;
106- }
107- visited . add ( ref ) ;
108- if ( ref_scope && can_hoist_snippet ( parent , ref_scope , scopes , visited ) ) {
109- continue ref_loop;
110- }
111- break ;
112- }
97+ if ( binding . initial ?. type === 'SnippetBlock' ) {
98+ if ( visited . has ( binding ) ) continue ;
99+ visited . add ( binding ) ;
100+
101+ if ( can_hoist_snippet ( binding . scope , scopes , visited ) ) {
102+ continue ;
113103 }
114104 }
115105
0 commit comments