File tree 3 files changed +25
-3
lines changed
test/runtime/samples/store-shadow-scope
3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -836,7 +836,7 @@ export default class Component {
836
836
} ) ;
837
837
}
838
838
839
- warn_on_undefined_store_value_references ( node , parent , scope ) {
839
+ warn_on_undefined_store_value_references ( node , parent , scope : Scope ) {
840
840
if (
841
841
node . type === 'LabeledStatement' &&
842
842
node . label . name === '$' &&
@@ -852,8 +852,17 @@ export default class Component {
852
852
const object = get_object ( node ) ;
853
853
const { name } = object ;
854
854
855
- if ( name [ 0 ] === '$' && ! scope . has ( name ) ) {
856
- this . warn_if_undefined ( name , object , null ) ;
855
+ if ( name [ 0 ] === '$' ) {
856
+ if ( ! scope . has ( name ) ) {
857
+ this . warn_if_undefined ( name , object , null ) ;
858
+ }
859
+
860
+ if ( scope . find_owner ( name . slice ( 1 ) ) !== this . instance_scope ) {
861
+ this . error ( node , {
862
+ code : `contextual-store` ,
863
+ message : `Stores must be declared at the top level of the component (this may change in a future version of Svelte)`
864
+ } ) ;
865
+ }
857
866
}
858
867
}
859
868
}
Original file line number Diff line number Diff line change
1
+ export default {
2
+ error : `Stores must be declared at the top level of the component (this may change in a future version of Svelte)` ,
3
+ solo : true ,
4
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import { writable } from ' svelte/store' ;
3
+ const store = writable ();
4
+
5
+ function foo () {
6
+ let store = 1 ;
7
+ $store = 2 ;
8
+ }
9
+ </script >
You can’t perform that action at this time.
0 commit comments