From f398929fdd99f1d500fd994c9b2f80820a88d048 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 18 Oct 2024 18:04:53 +0100 Subject: [PATCH] fix: correct migration of uninitialised state (#13673) * fix: correct migration of uninitialised state * better fix --- .changeset/neat-rabbits-divide.md | 5 +++++ packages/svelte/src/compiler/migrate/index.js | 7 ++++++- .../migrate/samples/state-no-initial/input.svelte | 13 +++++++++++++ .../migrate/samples/state-no-initial/output.svelte | 13 +++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .changeset/neat-rabbits-divide.md create mode 100644 packages/svelte/tests/migrate/samples/state-no-initial/input.svelte create mode 100644 packages/svelte/tests/migrate/samples/state-no-initial/output.svelte diff --git a/.changeset/neat-rabbits-divide.md b/.changeset/neat-rabbits-divide.md new file mode 100644 index 0000000000..ffe57a6f18 --- /dev/null +++ b/.changeset/neat-rabbits-divide.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: correct migration of uninitialised state diff --git a/packages/svelte/src/compiler/migrate/index.js b/packages/svelte/src/compiler/migrate/index.js index 69c840aedb..3d70d54d9f 100644 --- a/packages/svelte/src/compiler/migrate/index.js +++ b/packages/svelte/src/compiler/migrate/index.js @@ -564,7 +564,12 @@ const instance_script = { labeled_statement = /** @type {LabeledStatement} */ (labeled); } - return !update && (declaration || (labeled && assignment) || (!labeled && !assignment)); + return ( + !update && + ((declaration && binding.initial) || + (labeled && assignment) || + (!labeled && !assignment)) + ); }) ); diff --git a/packages/svelte/tests/migrate/samples/state-no-initial/input.svelte b/packages/svelte/tests/migrate/samples/state-no-initial/input.svelte new file mode 100644 index 0000000000..c2c4183465 --- /dev/null +++ b/packages/svelte/tests/migrate/samples/state-no-initial/input.svelte @@ -0,0 +1,13 @@ + + +
diff --git a/packages/svelte/tests/migrate/samples/state-no-initial/output.svelte b/packages/svelte/tests/migrate/samples/state-no-initial/output.svelte new file mode 100644 index 0000000000..2f6a9933ee --- /dev/null +++ b/packages/svelte/tests/migrate/samples/state-no-initial/output.svelte @@ -0,0 +1,13 @@ + + +
\ No newline at end of file