Skip to content

Commit 82e84a8

Browse files
committed
fix: migrate reactive statements with inner blocks
1 parent 0598f2b commit 82e84a8

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
@@ -570,7 +570,8 @@ const instance_script = {
570570

571571
const labeled_has_single_assignment =
572572
labeled_statement?.body.type === 'BlockStatement' &&
573-
labeled_statement.body.body.length === 1;
573+
labeled_statement.body.body.length === 1 &&
574+
labeled_statement.body.body[0].type === 'ExpressionStatement';
574575

575576
const is_expression_assignment =
576577
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)