From 2ba45da40b0bb0edfc709f84810e5e5a5adc6ab0 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Mon, 20 May 2024 22:22:36 +0200 Subject: [PATCH] fix: migrate derivations without semicolons --- .changeset/kind-snakes-drive.md | 5 +++++ packages/svelte/src/compiler/migrate/index.js | 14 +++++++++----- .../samples/derivations-no-colon/input.svelte | 7 +++++++ .../samples/derivations-no-colon/output.svelte | 7 +++++++ 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 .changeset/kind-snakes-drive.md create mode 100644 packages/svelte/tests/migrate/samples/derivations-no-colon/input.svelte create mode 100644 packages/svelte/tests/migrate/samples/derivations-no-colon/output.svelte diff --git a/.changeset/kind-snakes-drive.md b/.changeset/kind-snakes-drive.md new file mode 100644 index 000000000000..4ca726ad9a67 --- /dev/null +++ b/.changeset/kind-snakes-drive.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: migrate derivations without semicolons diff --git a/packages/svelte/src/compiler/migrate/index.js b/packages/svelte/src/compiler/migrate/index.js index 0a64088c5a9e..0ca0fba137b3 100644 --- a/packages/svelte/src/compiler/migrate/index.js +++ b/packages/svelte/src/compiler/migrate/index.js @@ -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) { diff --git a/packages/svelte/tests/migrate/samples/derivations-no-colon/input.svelte b/packages/svelte/tests/migrate/samples/derivations-no-colon/input.svelte new file mode 100644 index 000000000000..7df9187a0283 --- /dev/null +++ b/packages/svelte/tests/migrate/samples/derivations-no-colon/input.svelte @@ -0,0 +1,7 @@ + + +{count} / {doubled} / {quadrupled} diff --git a/packages/svelte/tests/migrate/samples/derivations-no-colon/output.svelte b/packages/svelte/tests/migrate/samples/derivations-no-colon/output.svelte new file mode 100644 index 000000000000..f6af6dd45069 --- /dev/null +++ b/packages/svelte/tests/migrate/samples/derivations-no-colon/output.svelte @@ -0,0 +1,7 @@ + + +{count} / {doubled} / {quadrupled} \ No newline at end of file