Skip to content

Commit dfb30aa

Browse files
authored
fix: only warn about non-reactive state in runes mode (#11434)
Fixes #11269
1 parent 1f9ad03 commit dfb30aa

File tree

2 files changed

+48
-43
lines changed

2 files changed

+48
-43
lines changed

.changeset/serious-bobcats-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: only warn about non-reactive state in runes mode

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,49 @@ export function analyze_component(root, source, options) {
449449
merge(set_scope(scopes), validation_runes, runes_scope_tweaker, common_visitors)
450450
);
451451
}
452+
453+
// warn on any nonstate declarations that are a) reassigned and b) referenced in the template
454+
for (const scope of [module.scope, instance.scope]) {
455+
outer: for (const [name, binding] of scope.declarations) {
456+
if (binding.kind === 'normal' && binding.reassigned) {
457+
inner: for (const { path } of binding.references) {
458+
if (path[0].type !== 'Fragment') continue;
459+
for (let i = 1; i < path.length; i += 1) {
460+
const type = path[i].type;
461+
if (
462+
type === 'FunctionDeclaration' ||
463+
type === 'FunctionExpression' ||
464+
type === 'ArrowFunctionExpression'
465+
) {
466+
continue inner;
467+
}
468+
// bind:this doesn't need to be a state reference if it will never change
469+
if (
470+
type === 'BindDirective' &&
471+
/** @type {import('#compiler').BindDirective} */ (path[i]).name === 'this'
472+
) {
473+
for (let j = i - 1; j >= 0; j -= 1) {
474+
const type = path[j].type;
475+
if (
476+
type === 'IfBlock' ||
477+
type === 'EachBlock' ||
478+
type === 'AwaitBlock' ||
479+
type === 'KeyBlock'
480+
) {
481+
w.non_reactive_update(binding.node, name);
482+
continue outer;
483+
}
484+
}
485+
continue inner;
486+
}
487+
}
488+
489+
w.non_reactive_update(binding.node, name);
490+
continue outer;
491+
}
492+
}
493+
}
494+
}
452495
} else {
453496
instance.scope.declare(b.id('$$props'), 'rest_prop', 'synthetic');
454497
instance.scope.declare(b.id('$$restProps'), 'rest_prop', 'synthetic');
@@ -508,49 +551,6 @@ export function analyze_component(root, source, options) {
508551
e.slot_snippet_conflict(analysis.slot_names.values().next().value);
509552
}
510553

511-
// warn on any nonstate declarations that are a) reassigned and b) referenced in the template
512-
for (const scope of [module.scope, instance.scope]) {
513-
outer: for (const [name, binding] of scope.declarations) {
514-
if (binding.kind === 'normal' && binding.reassigned) {
515-
inner: for (const { path } of binding.references) {
516-
if (path[0].type !== 'Fragment') continue;
517-
for (let i = 1; i < path.length; i += 1) {
518-
const type = path[i].type;
519-
if (
520-
type === 'FunctionDeclaration' ||
521-
type === 'FunctionExpression' ||
522-
type === 'ArrowFunctionExpression'
523-
) {
524-
continue inner;
525-
}
526-
// bind:this doesn't need to be a state reference if it will never change
527-
if (
528-
type === 'BindDirective' &&
529-
/** @type {import('#compiler').BindDirective} */ (path[i]).name === 'this'
530-
) {
531-
for (let j = i - 1; j >= 0; j -= 1) {
532-
const type = path[j].type;
533-
if (
534-
type === 'IfBlock' ||
535-
type === 'EachBlock' ||
536-
type === 'AwaitBlock' ||
537-
type === 'KeyBlock'
538-
) {
539-
w.non_reactive_update(binding.node, name);
540-
continue outer;
541-
}
542-
}
543-
continue inner;
544-
}
545-
}
546-
547-
w.non_reactive_update(binding.node, name);
548-
continue outer;
549-
}
550-
}
551-
}
552-
}
553-
554554
if (analysis.css.ast) {
555555
analyze_css(analysis.css.ast, analysis);
556556

0 commit comments

Comments
 (0)