mirror of https://github.com/sveltejs/svelte
feat: warn on referenced mutated nonstate (#9669)
Walk the path and warn if this is a mutated normal variable that's referenced inside a function scopepull/9650/head
parent
9c44fd7854
commit
6e863e617c
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: warn on references to mutated non-state in template
|
@ -0,0 +1,3 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({});
|
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
let a = $state(1);
|
||||||
|
let b = 2;
|
||||||
|
let c = 3;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => a += 1}>a += 1</button>
|
||||||
|
<button onclick={() => b += 1}>b += 1</button>
|
||||||
|
<button onclick={() => c += 1}>c += 1</button>
|
||||||
|
<p>{a} + {b} + {c} = {a + b + c}</p>
|
@ -0,0 +1,26 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"code": "non-state-reference",
|
||||||
|
"message": "b is updated, but is not declared with $state(...). Changing its value will not correctly trigger updates.",
|
||||||
|
"start": {
|
||||||
|
"column": 5,
|
||||||
|
"line": 3
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"column": 6,
|
||||||
|
"line": 3
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": "non-state-reference",
|
||||||
|
"message": "c is updated, but is not declared with $state(...). Changing its value will not correctly trigger updates.",
|
||||||
|
"start": {
|
||||||
|
"column": 5,
|
||||||
|
"line": 4
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"column": 6,
|
||||||
|
"line": 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in new issue