mirror of https://github.com/sveltejs/svelte
chore: add error for derived self referencing (#12746)
* chore: add warning for derived self referencin * update build * address feedback * address feedback * build * messages shouldn't end with a period * simplify test * regenerate * newlines are free * no need to export this, we can move it closer to where it's used * fix double negative --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/12752/head
parent
bd9a2d2077
commit
d06174e461
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore: add error for derived self referencing
|
@ -0,0 +1,21 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `<button>increment</button>\n0`,
|
||||||
|
|
||||||
|
mode: ['client'],
|
||||||
|
|
||||||
|
test({ assert, target }) {
|
||||||
|
const btn = target.querySelector('button');
|
||||||
|
|
||||||
|
btn?.click();
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
flushSync,
|
||||||
|
'derived_references_self\nA derived value cannot reference itself recursively'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>increment</button>\n0`);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(0);
|
||||||
|
let even = $derived.by(() => {
|
||||||
|
return count > 0 ? even : 0;
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count++}>increment</button>
|
||||||
|
|
||||||
|
{even}
|
Loading…
Reference in new issue