mirror of https://github.com/sveltejs/svelte
parent
378bb25097
commit
b76b937e00
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: correctly transform references to earlier declarators in a declaration tag (e.g. `{let a = $state(0), b = $derived(a * 2)}`)
|
||||
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: avoid spurious `state_referenced_locally` warnings for `$derived` declarations in declaration tags
|
||||
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: tolerate whitespace before `let`/`const` in declaration tags
|
||||
@ -0,0 +1,17 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>increment</button><p>count: 0</p><p>doubled: 0</p><p>quadrupled: 0</p>`,
|
||||
async test({ assert, target }) {
|
||||
const [button] = target.querySelectorAll('button');
|
||||
|
||||
button.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>increment</button><p>count: 1</p><p>doubled: 2</p><p>quadrupled: 4</p>`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,10 @@
|
||||
<!-- a later declarator can reference an earlier one within the same tag... -->
|
||||
{let count = $state(0), doubled = $derived(count * 2)}
|
||||
|
||||
<!-- ...and leading whitespace is tolerated -->
|
||||
{ let quadrupled = $derived(doubled * 2) }
|
||||
|
||||
<button onclick={() => (count += 1)}>increment</button>
|
||||
<p>count: {count}</p>
|
||||
<p>doubled: {doubled}</p>
|
||||
<p>quadrupled: {quadrupled}</p>
|
||||
@ -0,0 +1,9 @@
|
||||
<!-- `$derived` reads happen inside a closure, so these should _not_ warn -->
|
||||
{let a = $state(0), b = $derived(a * 2)}
|
||||
{let c = $state(0)}
|
||||
{let d = $derived(c * 2)}
|
||||
|
||||
<!-- this is a non-closure read of state, so it _should_ warn -->
|
||||
{let e = $state(0), f = e}
|
||||
|
||||
{a}{b}{c}{d}{e}{f}
|
||||
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"code": "state_referenced_locally",
|
||||
"message": "This reference only captures the initial value of `e`. Did you mean to reference it inside a closure instead?",
|
||||
"start": {
|
||||
"line": 7,
|
||||
"column": 24
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 25
|
||||
}
|
||||
}
|
||||
]
|
||||
Loading…
Reference in new issue