Skip to content

Commit c36784c

Browse files
committed
fix + test
1 parent 38738a8 commit c36784c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/svelte/src/compiler/migrate/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,11 @@ const instance_script = {
739739
);
740740
const bindings = ids.map((id) => state.scope.get(id.name));
741741
const reassigned_bindings = bindings.filter((b) => b?.reassigned);
742-
if (reassigned_bindings.length === 0 && !bindings.some((b) => b?.kind === 'store_sub') && node.body.expression.left.type === "Identifier") {
742+
if (
743+
reassigned_bindings.length === 0 &&
744+
!bindings.some((b) => b?.kind === 'store_sub') &&
745+
node.body.expression.left.type !== 'MemberExpression'
746+
) {
743747
let { start, end } = /** @type {{ start: number, end: number }} */ (
744748
node.body.expression.right
745749
);

packages/svelte/tests/migrate/samples/effects/output.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import { run } from 'svelte/legacy';
33
4-
let count = 0;
4+
let count = $state(0);
55
run(() => {
66
console.log(count);
77
});
@@ -18,6 +18,9 @@
1818
run(() => {
1919
$count = 1;
2020
});
21+
run(() => {
22+
$count.x = count;
23+
});
2124
</script>
2225

23-
<button onclick={() => count++}>increment</button>
26+
<button onclick={() => count++}>increment</button>

0 commit comments

Comments
 (0)