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