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>
pull/13622/head
Paolo Ricciuti 2 months ago committed by GitHub
parent a17a28b30e
commit 48f0bfc73f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure inserted code is preserved during migration

@ -273,7 +273,7 @@ export function migrate(source, { filename } = {}) {
const { start, end } = get_node_range(source, node); const { start, end } = get_node_range(source, node);
str.appendLeft(end, '\n'); str.appendLeft(end, '\n');
str.move(start, end, /** @type {number} */ (parsed.instance?.content.end)); 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, '');
} }
} }

@ -0,0 +1,12 @@
<script>
export let data
$: ({ foo } = data)
import { blah } from './blah.js'
let bar
$: {
bar = []
let baz
}
</script>

@ -0,0 +1,15 @@
<script>
import { run } from 'svelte/legacy';
import { blah } from './blah.js'
/** @type {{data: any}} */
let { data } = $props();
let bar = $state()
let { foo } = $derived(data)
run(() => {
bar = []
let baz
});
</script>
Loading…
Cancel
Save