From c9d85c2d522f790d5ddc34a0afeb7ecf80244be0 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 18 Oct 2024 18:15:11 +0100 Subject: [PATCH] fix: migrate reactive statements with inner blocks (#13675) --- .changeset/smooth-apes-shave.md | 5 +++++ packages/svelte/src/compiler/migrate/index.js | 3 ++- .../input.svelte | 17 +++++++++++++++++ .../output.svelte | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .changeset/smooth-apes-shave.md create mode 100644 packages/svelte/tests/migrate/samples/reactive-statements-inner-block/input.svelte create mode 100644 packages/svelte/tests/migrate/samples/reactive-statements-inner-block/output.svelte 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