@@ -169,20 +169,18 @@ export class Scope {
169
169
/**
170
170
* @param {import('estree').Identifier } node
171
171
* @param {import('#compiler').SvelteNode[] } path
172
- * @param {boolean } is_template
173
172
*/
174
- reference ( node , path , is_template ) {
173
+ reference ( node , path ) {
175
174
let references = this . references . get ( node . name ) ;
176
175
if ( ! references ) this . references . set ( node . name , ( references = [ ] ) ) ;
177
176
178
177
references . push ( { node, path } ) ;
179
178
180
179
const binding = this . declarations . get ( node . name ) ;
181
180
if ( binding ) {
182
- if ( is_template ) binding . referenced_in_template = true ;
183
181
binding . references . push ( { node, path } ) ;
184
182
} else if ( this . #parent) {
185
- this . #parent. reference ( node , path , is_template ) ;
183
+ this . #parent. reference ( node , path ) ;
186
184
} else {
187
185
// no binding was found, and this is the top level scope,
188
186
// which means this is a global
@@ -217,11 +215,10 @@ export class ScopeRoot {
217
215
* @param {import('#compiler').SvelteNode } ast
218
216
* @param {ScopeRoot } root
219
217
* @param {boolean } allow_reactive_declarations
220
- * @param {boolean } is_template
221
218
* @param {Scope | null } parent
222
219
*/
223
- export function create_scopes ( ast , root , allow_reactive_declarations , is_template , parent ) {
224
- /** @typedef {{ scope: Scope, is_template: boolean } } State */
220
+ export function create_scopes ( ast , root , allow_reactive_declarations , parent ) {
221
+ /** @typedef {{ scope: Scope } } State */
225
222
226
223
/**
227
224
* A map of node->associated scope. A node appearing in this map does not necessarily mean that it created a scope
@@ -232,9 +229,9 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
232
229
scopes . set ( ast , scope ) ;
233
230
234
231
/** @type {State } */
235
- const state = { scope, is_template } ;
232
+ const state = { scope } ;
236
233
237
- /** @type {[Scope, { node: import('estree').Identifier; path: import('#compiler').SvelteNode[]; is_template: boolean }][] } */
234
+ /** @type {[Scope, { node: import('estree').Identifier; path: import('#compiler').SvelteNode[] }][] } */
238
235
const references = [ ] ;
239
236
240
237
/** @type {[Scope, import('estree').Pattern | import('estree').MemberExpression][] } */
@@ -265,7 +262,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
265
262
const scope = state . scope . child ( true ) ;
266
263
scopes . set ( node , scope ) ;
267
264
268
- next ( { ... state , scope } ) ;
265
+ next ( { scope } ) ;
269
266
} ;
270
267
271
268
/**
@@ -274,7 +271,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
274
271
const SvelteFragment = ( node , { state, next } ) => {
275
272
const scope = analyze_let_directives ( node , state . scope ) ;
276
273
scopes . set ( node , scope ) ;
277
- next ( { ... state , scope } ) ;
274
+ next ( { scope } ) ;
278
275
} ;
279
276
280
277
/**
@@ -320,10 +317,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
320
317
Identifier ( node , { path, state } ) {
321
318
const parent = path . at ( - 1 ) ;
322
319
if ( parent && is_reference ( node , /** @type {import('estree').Node } */ ( parent ) ) ) {
323
- references . push ( [
324
- state . scope ,
325
- { node, path : path . slice ( ) , is_template : state . is_template }
326
- ] ) ;
320
+ references . push ( [ state . scope , { node, path : path . slice ( ) } ] ) ;
327
321
}
328
322
} ,
329
323
@@ -346,15 +340,15 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
346
340
}
347
341
}
348
342
349
- next ( { ... state , scope } ) ;
343
+ next ( { scope } ) ;
350
344
} ,
351
345
352
346
SvelteFragment,
353
347
SvelteElement : SvelteFragment ,
354
348
RegularElement : SvelteFragment ,
355
349
356
350
Component ( node , { state, visit, path } ) {
357
- state . scope . reference ( b . id ( node . name ) , path , false ) ;
351
+ state . scope . reference ( b . id ( node . name ) , path ) ;
358
352
359
353
// let:x from the default slot is a weird one:
360
354
// Its scope only applies to children that are not slots themselves.
@@ -378,7 +372,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
378
372
} else if ( child . type === 'SnippetBlock' ) {
379
373
visit ( child ) ;
380
374
} else {
381
- visit ( child , { ... state , scope } ) ;
375
+ visit ( child , { scope } ) ;
382
376
}
383
377
}
384
378
} ,
@@ -412,7 +406,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
412
406
if ( node . id ) scope . declare ( node . id , 'normal' , 'function' ) ;
413
407
414
408
add_params ( scope , node . params ) ;
415
- next ( { scope, is_template : false } ) ;
409
+ next ( { scope } ) ;
416
410
} ,
417
411
418
412
FunctionDeclaration ( node , { state, next } ) {
@@ -422,15 +416,15 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
422
416
scopes . set ( node , scope ) ;
423
417
424
418
add_params ( scope , node . params ) ;
425
- next ( { scope, is_template : false } ) ;
419
+ next ( { scope } ) ;
426
420
} ,
427
421
428
422
ArrowFunctionExpression ( node , { state, next } ) {
429
423
const scope = state . scope . child ( ) ;
430
424
scopes . set ( node , scope ) ;
431
425
432
426
add_params ( scope , node . params ) ;
433
- next ( { scope, is_template : false } ) ;
427
+ next ( { scope } ) ;
434
428
} ,
435
429
436
430
ForStatement : create_block_scope ,
@@ -475,7 +469,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
475
469
state . scope . declare ( id , 'normal' , 'let' ) ;
476
470
}
477
471
478
- next ( { ... state , scope } ) ;
472
+ next ( { scope } ) ;
479
473
} else {
480
474
next ( ) ;
481
475
}
@@ -513,13 +507,13 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
513
507
( node . key . type !== 'Identifier' || ! node . index || node . key . name !== node . index ) ;
514
508
scope . declare ( b . id ( node . index ) , is_keyed ? 'derived' : 'normal' , 'const' ) ;
515
509
}
516
- if ( node . key ) visit ( node . key , { ... state , scope } ) ;
510
+ if ( node . key ) visit ( node . key , { scope } ) ;
517
511
518
512
// children
519
513
for ( const child of node . body . nodes ) {
520
- visit ( child , { ... state , scope } ) ;
514
+ visit ( child , { scope } ) ;
521
515
}
522
- if ( node . fallback ) visit ( node . fallback , { ... state , scope } ) ;
516
+ if ( node . fallback ) visit ( node . fallback , { scope } ) ;
523
517
524
518
// Check if inner scope shadows something from outer scope.
525
519
// This is necessary because we need access to the array expression of the each block
@@ -586,13 +580,13 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
586
580
}
587
581
}
588
582
589
- context . next ( { ... state , scope : child_scope } ) ;
583
+ context . next ( { scope : child_scope } ) ;
590
584
} ,
591
585
592
586
Fragment : ( node , context ) => {
593
587
const scope = context . state . scope . child ( node . transparent ) ;
594
588
scopes . set ( node , scope ) ;
595
- context . next ( { ... state , scope } ) ;
589
+ context . next ( { scope } ) ;
596
590
} ,
597
591
598
592
BindDirective ( node , context ) {
@@ -629,8 +623,8 @@ export function create_scopes(ast, root, allow_reactive_declarations, is_templat
629
623
630
624
// we do this after the fact, so that we don't need to worry
631
625
// about encountering references before their declarations
632
- for ( const [ scope , { node, path, is_template } ] of references ) {
633
- scope . reference ( node , path , is_template ) ;
626
+ for ( const [ scope , { node, path } ] of references ) {
627
+ scope . reference ( node , path ) ;
634
628
}
635
629
636
630
for ( const [ scope , node ] of updates ) {
0 commit comments