diff --git a/.changeset/smooth-apes-shave.md b/.changeset/smooth-apes-shave.md new file mode 100644 index 0000000000..18d141f4ef --- /dev/null +++ b/.changeset/smooth-apes-shave.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: migrate reactive statements with inner blocks diff --git a/packages/svelte/src/compiler/migrate/index.js b/packages/svelte/src/compiler/migrate/index.js index 3d70d54d9f..57091ba1a1 100644 --- a/packages/svelte/src/compiler/migrate/index.js +++ b/packages/svelte/src/compiler/migrate/index.js @@ -575,7 +575,8 @@ const instance_script = { const labeled_has_single_assignment = labeled_statement?.body.type === 'BlockStatement' && - labeled_statement.body.body.length === 1; + labeled_statement.body.body.length === 1 && + labeled_statement.body.body[0].type === 'ExpressionStatement'; const is_expression_assignment = labeled_statement?.body.type === 'ExpressionStatement' && diff --git a/packages/svelte/tests/migrate/samples/reactive-statements-inner-block/input.svelte b/packages/svelte/tests/migrate/samples/reactive-statements-inner-block/input.svelte new file mode 100644 index 0000000000..fe9821b58d --- /dev/null +++ b/packages/svelte/tests/migrate/samples/reactive-statements-inner-block/input.svelte @@ -0,0 +1,17 @@ + + + diff --git a/packages/svelte/tests/migrate/samples/reactive-statements-inner-block/output.svelte b/packages/svelte/tests/migrate/samples/reactive-statements-inner-block/output.svelte new file mode 100644 index 0000000000..4ff77477e4 --- /dev/null +++ b/packages/svelte/tests/migrate/samples/reactive-statements-inner-block/output.svelte @@ -0,0 +1,19 @@ + + + \ No newline at end of file