From 710c3a6594117509903e974e347d02eee3cb4549 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Sat, 19 Oct 2024 23:17:03 +0200 Subject: [PATCH] fix: don't blank css on migration error --- .changeset/healthy-bees-wave.md | 5 +++++ packages/svelte/src/compiler/migrate/index.js | 3 ++- .../samples/not-blank-css-if-error/input.svelte | 11 +++++++++++ .../samples/not-blank-css-if-error/output.svelte | 12 ++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .changeset/healthy-bees-wave.md create mode 100644 packages/svelte/tests/migrate/samples/not-blank-css-if-error/input.svelte create mode 100644 packages/svelte/tests/migrate/samples/not-blank-css-if-error/output.svelte diff --git a/.changeset/healthy-bees-wave.md b/.changeset/healthy-bees-wave.md new file mode 100644 index 0000000000..6a31a94e3a --- /dev/null +++ b/.changeset/healthy-bees-wave.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: don't blank css on migration error diff --git a/packages/svelte/src/compiler/migrate/index.js b/packages/svelte/src/compiler/migrate/index.js index b0867766e3..f2b6977ea1 100644 --- a/packages/svelte/src/compiler/migrate/index.js +++ b/packages/svelte/src/compiler/migrate/index.js @@ -34,6 +34,7 @@ let has_migration_task = false; * @returns {{ code: string; }} */ export function migrate(source, { filename } = {}) { + let og_source = source; try { has_migration_task = false; // Blank CSS, could contain SCSS or similar that needs a preprocessor. @@ -303,7 +304,7 @@ export function migrate(source, { filename } = {}) { console.error('Error while migrating Svelte code', e); has_migration_task = true; return { - code: `\n${source}` + code: `\n${og_source}` }; } finally { if (has_migration_task) { diff --git a/packages/svelte/tests/migrate/samples/not-blank-css-if-error/input.svelte b/packages/svelte/tests/migrate/samples/not-blank-css-if-error/input.svelte new file mode 100644 index 0000000000..c31b74df34 --- /dev/null +++ b/packages/svelte/tests/migrate/samples/not-blank-css-if-error/input.svelte @@ -0,0 +1,11 @@ + + +{$$props} + + \ No newline at end of file diff --git a/packages/svelte/tests/migrate/samples/not-blank-css-if-error/output.svelte b/packages/svelte/tests/migrate/samples/not-blank-css-if-error/output.svelte new file mode 100644 index 0000000000..a62a6d4d90 --- /dev/null +++ b/packages/svelte/tests/migrate/samples/not-blank-css-if-error/output.svelte @@ -0,0 +1,12 @@ + + + +{$$props} + + \ No newline at end of file