mirror of https://github.com/sveltejs/svelte
fix: keep a reactive assignment with no dependencies when `migrate` cannot turn it into a declaration (#18817)
`migrate()` dropped a reactive assignment that has no dependencies and
put nothing in its place:
```svelte
$: count = 7; → (gone, `{count}` now undeclared)
$: obj.x = 1; → (gone)
```
A binding the statement declares now always gets its `let`, and the
statement is only removed once every target has one; otherwise it
becomes `run()`:
```svelte
let count = $state(7);
run(() => { obj.x = 1; });
```
main
parent
8ef693e94e
commit
5b44f26bc2
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: keep a reactive assignment with no dependencies when `migrate` cannot turn it into a declaration
|
||||
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
$: count = 7;
|
||||
$: other = 8;
|
||||
let obj = {};
|
||||
$: obj.x = 1;
|
||||
</script>
|
||||
|
||||
<p>{count} {other} {obj.x}</p>
|
||||
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
import { run } from 'svelte/legacy';
|
||||
|
||||
let count = $state(7);
|
||||
|
||||
let other = $state(8);
|
||||
|
||||
let obj = $state({});
|
||||
run(() => {
|
||||
obj.x = 1;
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>{count} {other} {obj.x}</p>
|
||||
Loading…
Reference in new issue