From 19aa51d443474fd89592a55c3d3aa0ccc5c240e2 Mon Sep 17 00:00:00 2001 From: Madan kumar Date: Thu, 20 Aug 2026 02:46:23 +0530 Subject: [PATCH] fix: print `{#await ... catch}` et al correctly (#18645) needs to check the error value, not the then value --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> --- .changeset/eighty-pugs-shave.md | 5 ++++ packages/svelte/src/compiler/print/index.js | 2 +- .../print/samples/await-block/input.svelte | 26 +++++++++++++++++++ .../print/samples/await-block/output.svelte | 26 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .changeset/eighty-pugs-shave.md diff --git a/.changeset/eighty-pugs-shave.md b/.changeset/eighty-pugs-shave.md new file mode 100644 index 0000000000..0f0eaf9a6c --- /dev/null +++ b/.changeset/eighty-pugs-shave.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: correctly print `{#await ... catch x}` et al diff --git a/packages/svelte/src/compiler/print/index.js b/packages/svelte/src/compiler/print/index.js index c6964fc0b7..a3e10085de 100644 --- a/packages/svelte/src/compiler/print/index.js +++ b/packages/svelte/src/compiler/print/index.js @@ -763,7 +763,7 @@ const svelte_visitors = (comments, state) => ({ } if (node.catch) { - context.write(node.value ? 'catch ' : 'catch'); + context.write(node.error ? 'catch ' : 'catch'); if (node.error) context.visit(node.error); context.write('}'); diff --git a/packages/svelte/tests/print/samples/await-block/input.svelte b/packages/svelte/tests/print/samples/await-block/input.svelte index 10f0b3fb9e..ba0ba8c882 100644 --- a/packages/svelte/tests/print/samples/await-block/input.svelte +++ b/packages/svelte/tests/print/samples/await-block/input.svelte @@ -8,3 +8,29 @@

Something went wrong: {error.message}

{/await} + +{#await promise catch error} +

The error is {error}

+{/await} + +{#await promise then value} +

The value is {value}

+{/await} + +{#await promise catch} +

Something went wrong

+{/await} + +{#await promise} +

waiting for the promise to resolve...

+{:then} +

the promise resolved

+{:catch error} +

The error is {error}

+{/await} + +{#await promise} +

waiting for the promise to resolve...

+{:catch} +

Something went wrong

+{/await} diff --git a/packages/svelte/tests/print/samples/await-block/output.svelte b/packages/svelte/tests/print/samples/await-block/output.svelte index 10f0b3fb9e..ba0ba8c882 100644 --- a/packages/svelte/tests/print/samples/await-block/output.svelte +++ b/packages/svelte/tests/print/samples/await-block/output.svelte @@ -8,3 +8,29 @@

Something went wrong: {error.message}

{/await} + +{#await promise catch error} +

The error is {error}

+{/await} + +{#await promise then value} +

The value is {value}

+{/await} + +{#await promise catch} +

Something went wrong

+{/await} + +{#await promise} +

waiting for the promise to resolve...

+{:then} +

the promise resolved

+{:catch error} +

The error is {error}

+{/await} + +{#await promise} +

waiting for the promise to resolve...

+{:catch} +

Something went wrong

+{/await}