@@ -276,6 +276,8 @@ export function analyze_component(root, source, options) {
276
276
/** @type {Template } */
277
277
const template = { ast : root . fragment , scope, scopes } ;
278
278
279
+ let synthetic_stores_legacy_check = [ ] ;
280
+
279
281
// create synthetic bindings for store subscriptions
280
282
for ( const [ name , references ] of module . scope . references ) {
281
283
if ( name [ 0 ] !== '$' || RESERVED . includes ( name ) ) continue ;
@@ -351,16 +353,21 @@ export function analyze_component(root, source, options) {
351
353
}
352
354
}
353
355
354
- // if we are creating a synthetic binding for a let declaration we should also declare
355
- // the declaration as state in case it's reassigned
356
- if (
357
- declaration !== null &&
358
- declaration . kind === 'normal' &&
359
- declaration . declaration_kind === 'let' &&
360
- declaration . reassigned
361
- ) {
362
- declaration . kind = 'state' ;
363
- }
356
+ // we push to the array because at this moment in time we can't be sure if we are in legacy
357
+ // mode yet because we are still changing the module scope
358
+ synthetic_stores_legacy_check . push ( ( ) => {
359
+ // if we are creating a synthetic binding for a let declaration we should also declare
360
+ // the declaration as state in case it's reassigned and we are not in runes mode (the function will
361
+ // not be called if we are not in runes mode, that's why there's no !runes check here)
362
+ if (
363
+ declaration !== null &&
364
+ declaration . kind === 'normal' &&
365
+ declaration . declaration_kind === 'let' &&
366
+ declaration . reassigned
367
+ ) {
368
+ declaration . kind = 'state' ;
369
+ }
370
+ } ) ;
364
371
365
372
const binding = instance . scope . declare ( b . id ( name ) , 'store_sub' , 'synthetic' ) ;
366
373
binding . references = references ;
@@ -373,6 +380,12 @@ export function analyze_component(root, source, options) {
373
380
374
381
const runes = options . runes ?? Array . from ( module . scope . references . keys ( ) ) . some ( is_rune ) ;
375
382
383
+ if ( ! runes ) {
384
+ for ( let check of synthetic_stores_legacy_check ) {
385
+ check ( ) ;
386
+ }
387
+ }
388
+
376
389
if ( runes && root . module ) {
377
390
const context = root . module . attributes . find ( ( attribute ) => attribute . name === 'context' ) ;
378
391
if ( context ) {
0 commit comments