File tree 3 files changed +20
-5
lines changed
src/compiler/compile/nodes/shared
test/runtime/samples/store-template-expression-scope
3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -78,11 +78,14 @@ export default class Expression {
78
78
79
79
if ( scope . has ( name ) ) return ;
80
80
81
- if ( name [ 0 ] === '$' && template_scope . names . has ( name . slice ( 1 ) ) ) {
82
- component . error ( node , {
83
- code : `contextual-store` ,
84
- message : `Stores must be declared at the top level of the component (this may change in a future version of Svelte)`
85
- } ) ;
81
+ if ( name [ 0 ] === '$' ) {
82
+ const store_name = name . slice ( 1 ) ;
83
+ if ( template_scope . names . has ( store_name ) || scope . has ( store_name ) ) {
84
+ component . error ( node , {
85
+ code : `contextual-store` ,
86
+ message : `Stores must be declared at the top level of the component (this may change in a future version of Svelte)`
87
+ } ) ;
88
+ }
86
89
}
87
90
88
91
if ( template_scope . is_let ( name ) ) {
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
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import { writable } from ' svelte/store' ;
3
+ const store = writable ();
4
+ </script >
5
+
6
+ <button
7
+ on:click ={(store ) => {
8
+ $store = Math .random ();
9
+ }} />
You can’t perform that action at this time.
0 commit comments