Skip to content

Commit c9d85c2

Browse files
authored
fix: migrate reactive statements with inner blocks (#13675)
1 parent f398929 commit c9d85c2

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

.changeset/smooth-apes-shave.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: migrate reactive statements with inner blocks

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ const instance_script = {
575575

576576
const labeled_has_single_assignment =
577577
labeled_statement?.body.type === 'BlockStatement' &&
578-
labeled_statement.body.body.length === 1;
578+
labeled_statement.body.body.length === 1 &&
579+
labeled_statement.body.body[0].type === 'ExpressionStatement';
579580

580581
const is_expression_assignment =
581582
labeled_statement?.body.type === 'ExpressionStatement' &&
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script lang="ts">
2+
let menuElement: HTMLUListElement | undefined = undefined;
3+
let left: number;
4+
let top: number;
5+
6+
$: {
7+
if (menuElement) {
8+
const rect = menuElement.getBoundingClientRect();
9+
const menuHeight = 0;
10+
11+
left = window.innerWidth - rect.width
12+
top = window.innerHeight - menuHeight;
13+
}
14+
}
15+
</script>
16+
17+
<ul bind:this={menuElement}></ul>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script lang="ts">
2+
import { run } from 'svelte/legacy';
3+
4+
let menuElement: HTMLUListElement | undefined = $state(undefined);
5+
let left: number = $state();
6+
let top: number = $state();
7+
8+
run(() => {
9+
if (menuElement) {
10+
const rect = menuElement.getBoundingClientRect();
11+
const menuHeight = 0;
12+
13+
left = window.innerWidth - rect.width
14+
top = window.innerHeight - menuHeight;
15+
}
16+
});
17+
</script>
18+
19+
<ul bind:this={menuElement}></ul>

0 commit comments

Comments
 (0)