From 48f0bfc73f142a51c21e8bf2313fcde64a150d0b Mon Sep 17 00:00:00 2001 From: Paolo Ricciuti Date: Wed, 16 Oct 2024 11:44:08 +0200 Subject: [PATCH] fix: ensure inserted code is preserved during migration (#13617) * fix: moving deriveds during migration deletes part of the inserted code * fix: use update instead of remove * Update .changeset/cool-apes-confess.md Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> --- .changeset/cool-apes-confess.md | 5 +++++ packages/svelte/src/compiler/migrate/index.js | 2 +- .../input.svelte | 12 ++++++++++++ .../output.svelte | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .changeset/cool-apes-confess.md create mode 100644 packages/svelte/tests/migrate/samples/reactive-statements-reorder-not-deleting-additions/input.svelte create mode 100644 packages/svelte/tests/migrate/samples/reactive-statements-reorder-not-deleting-additions/output.svelte diff --git a/.changeset/cool-apes-confess.md b/.changeset/cool-apes-confess.md new file mode 100644 index 0000000000..6142d430ff --- /dev/null +++ b/.changeset/cool-apes-confess.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure inserted code is preserved during migration diff --git a/packages/svelte/src/compiler/migrate/index.js b/packages/svelte/src/compiler/migrate/index.js index 5c2c1fb484..42727ea212 100644 --- a/packages/svelte/src/compiler/migrate/index.js +++ b/packages/svelte/src/compiler/migrate/index.js @@ -273,7 +273,7 @@ export function migrate(source, { filename } = {}) { const { start, end } = get_node_range(source, node); str.appendLeft(end, '\n'); str.move(start, end, /** @type {number} */ (parsed.instance?.content.end)); - str.remove(start - (source[start - 2] === '\r' ? 2 : 1), start); + str.update(start - (source[start - 2] === '\r' ? 2 : 1), start, ''); } } diff --git a/packages/svelte/tests/migrate/samples/reactive-statements-reorder-not-deleting-additions/input.svelte b/packages/svelte/tests/migrate/samples/reactive-statements-reorder-not-deleting-additions/input.svelte new file mode 100644 index 0000000000..2b90ce8212 --- /dev/null +++ b/packages/svelte/tests/migrate/samples/reactive-statements-reorder-not-deleting-additions/input.svelte @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/packages/svelte/tests/migrate/samples/reactive-statements-reorder-not-deleting-additions/output.svelte b/packages/svelte/tests/migrate/samples/reactive-statements-reorder-not-deleting-additions/output.svelte new file mode 100644 index 0000000000..dffe4308fb --- /dev/null +++ b/packages/svelte/tests/migrate/samples/reactive-statements-reorder-not-deleting-additions/output.svelte @@ -0,0 +1,15 @@ + \ No newline at end of file