diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js index 098e4535d9..abf70769c0 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js @@ -91,7 +91,9 @@ export function Identifier(node, context) { if (context.state.expression) { context.state.expression.dependencies.add(binding); context.state.expression.has_state ||= - !binding.is_function() && !context.state.scope.evaluate(node).is_known; + binding.kind !== 'static' && + !binding.is_function() && + !context.state.scope.evaluate(node).is_known; } if ( diff --git a/packages/svelte/src/compiler/phases/scope.js b/packages/svelte/src/compiler/phases/scope.js index 8fc4da8154..8b4967a82b 100644 --- a/packages/svelte/src/compiler/phases/scope.js +++ b/packages/svelte/src/compiler/phases/scope.js @@ -1153,7 +1153,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) { const is_keyed = node.key && (node.key.type !== 'Identifier' || !node.index || node.key.name !== node.index); - scope.declare(b.id(node.index), is_keyed ? 'template' : 'normal', 'const', node); + scope.declare(b.id(node.index), is_keyed ? 'template' : 'static', 'const', node); } if (node.key) visit(node.key, { scope }); diff --git a/packages/svelte/src/compiler/types/index.d.ts b/packages/svelte/src/compiler/types/index.d.ts index 0da036242b..fdd6024726 100644 --- a/packages/svelte/src/compiler/types/index.d.ts +++ b/packages/svelte/src/compiler/types/index.d.ts @@ -265,7 +265,8 @@ export type BindingKind = | 'snippet' // A snippet parameter | 'store_sub' // A $store value | 'legacy_reactive' // A `$:` declaration - | 'template'; // A binding declared in the template, e.g. in an `await` block or `const` tag + | 'template' // A binding declared in the template, e.g. in an `await` block or `const` tag + | 'static'; // A binding whose value is known to be static (i.e. each index) export type DeclarationKind = | 'var'