Skip to content

Commit

Permalink
fix: migrate derivations without semicolons (#11704)
Browse files Browse the repository at this point in the history
Closes #11689
  • Loading branch information
paoloricciuti authored May 21, 2024
1 parent 02520ae commit b788b72
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-snakes-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: migrate derivations without semicolons
14 changes: 9 additions & 5 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,15 @@ const instance_script = {
/** @type {number} */ (node.body.expression.right.start),
'$derived('
);
state.str.update(
/** @type {number} */ (node.body.expression.right.end),
/** @type {number} */ (node.end),
');'
);
if (node.body.expression.right.end !== node.end) {
state.str.update(
/** @type {number} */ (node.body.expression.right.end),
/** @type {number} */ (node.end),
');'
);
} else {
state.str.appendRight(/** @type {number} */ (node.end), ');');
}
return;
} else {
for (const binding of reassigned_bindings) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let count = 0;
$: doubled = count * 2
$: ({ quadrupled } = { quadrupled: count * 4 })
</script>

{count} / {doubled} / {quadrupled}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let count = 0;
let doubled = $derived(count * 2);
let { quadrupled } = $derived({ quadrupled: count * 4 });
</script>

{count} / {doubled} / {quadrupled}

0 comments on commit b788b72

Please sign in to comment.