File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed
src/compiler/phases/2-analyze
tests/validator/samples/static-state-reference Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " svelte " : patch
3+ ---
4+
5+ fix: don't warn on writes to ` $state `
Original file line number Diff line number Diff line change @@ -1242,6 +1242,7 @@ const common_visitors = {
12421242 if (
12431243 context . state . analysis . runes &&
12441244 node !== binding . node &&
1245+ context . state . function_depth === binding . scope . function_depth &&
12451246 // If we have $state that can be proxied or frozen and isn't re-assigned, then that means
12461247 // it's likely not using a primitive value and thus this warning isn't that helpful.
12471248 ( ( binding . kind === 'state' &&
@@ -1252,7 +1253,9 @@ const common_visitors = {
12521253 ! should_proxy_or_freeze ( binding . initial . arguments [ 0 ] , context . state . scope ) ) ) ) ||
12531254 binding . kind === 'frozen_state' ||
12541255 binding . kind === 'derived' ) &&
1255- context . state . function_depth === binding . scope . function_depth
1256+ // We're only concerned with reads here
1257+ ( parent . type !== 'AssignmentExpression' || parent . left !== node ) &&
1258+ parent . type !== 'UpdateExpression'
12561259 ) {
12571260 w . state_referenced_locally ( node ) ;
12581261 }
Original file line number Diff line number Diff line change 66 console .log (obj);
77 console .log (count);
88 console .log (doubled);
9+ // these are ok because they're writes
10+ count++ ;
11+ count = 1 ;
12+ obj .a ++ ;
13+ obj .a = 1 ;
914 </script >
1015
1116<button onclick ={() => count += 1 }>
You can’t perform that action at this time.
0 commit comments