fix: don't hang `migrate` on a declaration that shares a line with its script tag (#18816)

`migrate()` never returned when a declaration shared a line with its
`<script>` tag:

```svelte
<script>export let answer</script>
```

The scan that removes a migrated `export let` line looked for a newline
in both directions with no bound. It now stops at the script's edges.
main
Nic Polumeyv 2 days ago committed by GitHub
parent 688a4e49b8
commit 8ef693e94e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: don't hang `migrate` on a declaration that shares a line with its script tag

@ -910,8 +910,10 @@ const instance_script = {
start = /** @type {number} */ (parent.start);
end = /** @type {number} */ (parent.end);
}
while (state.str.original[start] !== '\n') start--;
while (state.str.original[end] !== '\n') end++;
// remove the declaration's whole line, or what there is of it inside the script
const script = /** @type {{ start: number; end: number }} */ (state.analysis.instance.ast);
while (start > script.start && state.str.original[start] !== '\n') start--;
while (end < script.end && state.str.original[end] !== '\n') end++;
state.str.update(start, end, '');
}
},

@ -0,0 +1,2 @@
<script>export let answer</script>
<p>{answer}</p>

@ -0,0 +1,3 @@
<script>
let { answer } = $props();</script>
<p>{answer}</p>
Loading…
Cancel
Save