mirror of https://github.com/sveltejs/svelte
parent
2af7ba2156
commit
396305a16d
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: warn when a variable is created an read within the same reaction
|
@ -0,0 +1,13 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
async test({ assert, warnings }) {
|
||||||
|
console.log(warnings);
|
||||||
|
assert.deepEqual(warnings, [
|
||||||
|
'The variable `count` is created and read within `derived_count`. `derived_count` will not depend on it.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,18 @@
|
|||||||
|
<script>
|
||||||
|
function test(){
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
return {
|
||||||
|
get count(){
|
||||||
|
return count;
|
||||||
|
},
|
||||||
|
set count(c){
|
||||||
|
count = c
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let derived_count = $derived(test().count);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{derived_count}
|
@ -0,0 +1,13 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
async test({ assert, warnings }) {
|
||||||
|
console.log(warnings);
|
||||||
|
assert.deepEqual(warnings, [
|
||||||
|
'The variable `x` is created and read within `$effect`. `$effect` will not depend on it.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,6 @@
|
|||||||
|
<script>
|
||||||
|
$effect(()=>{
|
||||||
|
let x = $state(0);
|
||||||
|
x++;
|
||||||
|
})
|
||||||
|
</script>
|
Loading…
Reference in new issue