Skip to content

Commit 48f0bfc

Browse files
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 <[email protected]> --------- Co-authored-by: Simon H <[email protected]>
1 parent a17a28b commit 48f0bfc

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.changeset/cool-apes-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure inserted code is preserved during migration

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export function migrate(source, { filename } = {}) {
273273
const { start, end } = get_node_range(source, node);
274274
str.appendLeft(end, '\n');
275275
str.move(start, end, /** @type {number} */ (parsed.instance?.content.end));
276-
str.remove(start - (source[start - 2] === '\r' ? 2 : 1), start);
276+
str.update(start - (source[start - 2] === '\r' ? 2 : 1), start, '');
277277
}
278278
}
279279

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
export let data
3+
$: ({ foo } = data)
4+
5+
import { blah } from './blah.js'
6+
7+
let bar
8+
$: {
9+
bar = []
10+
let baz
11+
}
12+
</script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
import { run } from 'svelte/legacy';
3+
4+
5+
import { blah } from './blah.js'
6+
/** @type {{data: any}} */
7+
let { data } = $props();
8+
9+
let bar = $state()
10+
let { foo } = $derived(data)
11+
run(() => {
12+
bar = []
13+
let baz
14+
});
15+
</script>

0 commit comments

Comments
 (0)