feat: shadowed store

pull/5079/head
Tan Li Hau 5 years ago
parent 2e0566e1d2
commit 68e287f853

@ -836,7 +836,7 @@ export default class Component {
}); });
} }
warn_on_undefined_store_value_references(node, parent, scope) { warn_on_undefined_store_value_references(node, parent, scope: Scope) {
if ( if (
node.type === 'LabeledStatement' && node.type === 'LabeledStatement' &&
node.label.name === '$' && node.label.name === '$' &&
@ -852,9 +852,18 @@ export default class Component {
const object = get_object(node); const object = get_object(node);
const { name } = object; const { name } = object;
if (name[0] === '$' && !scope.has(name)) { if (name[0] === '$') {
if (!scope.has(name)) {
this.warn_if_undefined(name, object, null); this.warn_if_undefined(name, object, null);
} }
if (name[1] !== '$' && scope.has(name.slice(1)) && scope.find_owner(name.slice(1)) !== this.instance_scope) {
this.error(node, {
code: `contextual-store`,
message: `Stores must be declared at the top level of the component (this may change in a future version of Svelte)`
});
}
}
} }
} }

@ -0,0 +1,3 @@
export default {
error: `Stores must be declared at the top level of the component (this may change in a future version of Svelte)`
};

@ -0,0 +1,9 @@
<script>
import { writable } from 'svelte/store';
const store = writable();
function foo() {
let store = 1;
$store = 2;
}
</script>
Loading…
Cancel
Save