@@ -2178,21 +2178,15 @@ export const template_visitors = {
2178
2178
state . options . preserveComments
2179
2179
) ;
2180
2180
2181
- /**
2182
- * @type {import("estree").Statement[] }
2183
- */
2184
- const init = [ ] ;
2185
- /**
2186
- * @type {never[] }
2187
- */
2188
- const update = [ ] ;
2189
- /**
2190
- * @type {never[] }
2191
- */
2192
- const after_update = [ ] ;
2181
+ /** Whether or not we need to wrap the children in `{...}` to avoid declaration conflicts */
2182
+ const has_declaration = node . fragment . nodes . some ( ( node ) => node . type === 'SnippetBlock' ) ;
2183
+
2184
+ const child_state = has_declaration
2185
+ ? { ...state , init : [ ] , update : [ ] , after_update : [ ] }
2186
+ : state ;
2193
2187
2194
2188
for ( const node of hoisted ) {
2195
- context . visit ( node , { ... state , init , update , after_update } ) ;
2189
+ context . visit ( node , child_state ) ;
2196
2190
}
2197
2191
2198
2192
process_children (
@@ -2205,16 +2199,17 @@ export const template_visitors = {
2205
2199
: context . state . node
2206
2200
) ,
2207
2201
true ,
2208
- { ...context , state : { ... state , init , update , after_update } }
2202
+ { ...context , state : child_state }
2209
2203
) ;
2210
2204
2211
- if ( init . length !== 0 || update . length !== 0 || after_update . length !== 0 ) {
2212
- const block = b . block ( [ ...init ] ) ;
2213
- if ( update . length > 0 ) {
2214
- block . body . push ( serialize_render_stmt ( update ) ) ;
2215
- }
2216
- block . body . push ( ...after_update ) ;
2217
- context . state . init . push ( block ) ;
2205
+ if ( has_declaration ) {
2206
+ context . state . init . push (
2207
+ b . block ( [
2208
+ ...child_state . init ,
2209
+ child_state . update . length > 0 ? serialize_render_stmt ( child_state . update ) : b . empty ,
2210
+ ...child_state . after_update
2211
+ ] )
2212
+ ) ;
2218
2213
}
2219
2214
2220
2215
if ( has_direction_attribute ) {
0 commit comments