diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 9dbfb3b41c..0a8fee5cf0 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -1034,7 +1034,10 @@ export default class Component { if (!assignee_nodes.has(identifier)) { const { name } = identifier; 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); } } diff --git a/test/js/samples/reactive-values-non-writable-dependencies/expected.js b/test/js/samples/reactive-values-non-writable-dependencies/expected.js index 42f57a0037..deded0d4e9 100644 --- a/test/js/samples/reactive-values-non-writable-dependencies/expected.js +++ b/test/js/samples/reactive-values-non-writable-dependencies/expected.js @@ -17,11 +17,11 @@ let a = 1; let b = 2; function instance($$self, $$props, $$invalidate) { - + let max; - $$self.$$.update = ($$dirty = { Math: 1, a: 1, b: 1 }) => { + $$self.$$.update = ($$dirty = { a: 1, b: 1 }) => { if ($$dirty.a || $$dirty.b) { max = Math.max(a, b); $$invalidate('max', max); } diff --git a/test/validator/samples/reactive-declaration-no-deps/errors.json b/test/validator/samples/reactive-declaration-no-deps/errors.json new file mode 100644 index 0000000000..0063d4005e --- /dev/null +++ b/test/validator/samples/reactive-declaration-no-deps/errors.json @@ -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 +}] diff --git a/test/validator/samples/reactive-declaration-no-deps/input.svelte b/test/validator/samples/reactive-declaration-no-deps/input.svelte new file mode 100644 index 0000000000..c334f92ab5 --- /dev/null +++ b/test/validator/samples/reactive-declaration-no-deps/input.svelte @@ -0,0 +1,3 @@ +