Merge pull request #2228 from sveltejs/gh-2173

Only include writable vars in reactive declaration dependencies
pull/2231/head
Rich Harris 7 years ago committed by GitHub
commit 1fe76d45a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1034,7 +1034,10 @@ export default class Component {
if (!assignee_nodes.has(identifier)) { if (!assignee_nodes.has(identifier)) {
const { name } = identifier; const { name } = identifier;
const owner = scope.findOwner(name); const owner = scope.findOwner(name);
if ((!owner || owner === component.instance_scope) && (name[0] === '$' || component.var_lookup.has(name))) { if (
(!owner || owner === component.instance_scope) &&
(name[0] === '$' || component.var_lookup.has(name) && component.var_lookup.get(name).writable)
) {
dependencies.add(name); dependencies.add(name);
} }
} }

@ -17,11 +17,11 @@ let a = 1;
let b = 2; let b = 2;
function instance($$self, $$props, $$invalidate) { function instance($$self, $$props, $$invalidate) {
let max; let max;
$$self.$$.update = ($$dirty = { Math: 1, a: 1, b: 1 }) => { $$self.$$.update = ($$dirty = { a: 1, b: 1 }) => {
if ($$dirty.a || $$dirty.b) { if ($$dirty.a || $$dirty.b) {
max = Math.max(a, b); $$invalidate('max', max); max = Math.max(a, b); $$invalidate('max', max);
} }

@ -0,0 +1,7 @@
[{
"message": "Invalid reactive declaration — must depend on local state",
"code": "invalid-reactive-declaration",
"start": { "line": 2, "column": 1, "character": 10 },
"end": { "line": 2, "column": 23, "character": 32 },
"pos": 10
}]

@ -0,0 +1,3 @@
<script>
$: console.log('foo');
</script>
Loading…
Cancel
Save