|
2 | 2 | /** @import { Context } from '../types' */
|
3 | 3 | /** @import { Scope } from '../../scope' */
|
4 | 4 | import * as e from '../../../errors.js';
|
| 5 | +import { extract_identifiers } from '../../../utils/ast.js'; |
5 | 6 | import { mark_subtree_dynamic } from './shared/fragment.js';
|
6 | 7 | import { validate_block_not_empty, validate_opening_tag } from './shared/utils.js';
|
7 | 8 |
|
@@ -38,21 +39,32 @@ export function EachBlock(node, context) {
|
38 | 39 | if (node.key) context.visit(node.key);
|
39 | 40 | if (node.fallback) context.visit(node.fallback);
|
40 | 41 |
|
| 42 | + let mutated = false; |
| 43 | + |
41 | 44 | // collect transitive dependencies...
|
42 | 45 | for (const binding of node.metadata.expression.dependencies) {
|
43 | 46 | collect_transitive_dependencies(binding, node.metadata.transitive_deps);
|
44 | 47 | }
|
45 | 48 |
|
| 49 | + if (node.context) { |
| 50 | + for (const id of extract_identifiers(node.context)) { |
| 51 | + const binding = context.state.scope.get(id.name); |
| 52 | + if (binding?.mutated) mutated = true; |
| 53 | + } |
| 54 | + } |
| 55 | + |
46 | 56 | // ...and ensure they are marked as state, so they can be turned
|
47 | 57 | // into mutable sources and invalidated
|
48 |
| - for (const binding of node.metadata.transitive_deps) { |
49 |
| - if ( |
50 |
| - binding.kind === 'normal' && |
51 |
| - (binding.declaration_kind === 'const' || |
52 |
| - binding.declaration_kind === 'let' || |
53 |
| - binding.declaration_kind === 'var') |
54 |
| - ) { |
55 |
| - binding.kind = 'state'; |
| 58 | + if (mutated) { |
| 59 | + for (const binding of node.metadata.transitive_deps) { |
| 60 | + if ( |
| 61 | + binding.kind === 'normal' && |
| 62 | + (binding.declaration_kind === 'const' || |
| 63 | + binding.declaration_kind === 'let' || |
| 64 | + binding.declaration_kind === 'var') |
| 65 | + ) { |
| 66 | + binding.kind = 'state'; |
| 67 | + } |
56 | 68 | }
|
57 | 69 | }
|
58 | 70 |
|
|
0 commit comments