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}