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>
pull/18676/head
Madan kumar 5 days ago committed by GitHub
parent 8835003d41
commit 19aa51d443
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly print `{#await ... catch x}` et al

@ -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('}');

@ -8,3 +8,29 @@
<!-- promise was rejected -->
<p>Something went wrong: {error.message}</p>
{/await}
{#await promise catch error}
<p>The error is {error}</p>
{/await}
{#await promise then value}
<p>The value is {value}</p>
{/await}
{#await promise catch}
<p>Something went wrong</p>
{/await}
{#await promise}
<p>waiting for the promise to resolve...</p>
{:then}
<p>the promise resolved</p>
{:catch error}
<p>The error is {error}</p>
{/await}
{#await promise}
<p>waiting for the promise to resolve...</p>
{:catch}
<p>Something went wrong</p>
{/await}

@ -8,3 +8,29 @@
<!-- promise was rejected -->
<p>Something went wrong: {error.message}</p>
{/await}
{#await promise catch error}
<p>The error is {error}</p>
{/await}
{#await promise then value}
<p>The value is {value}</p>
{/await}
{#await promise catch}
<p>Something went wrong</p>
{/await}
{#await promise}
<p>waiting for the promise to resolve...</p>
{:then}
<p>the promise resolved</p>
{:catch error}
<p>The error is {error}</p>
{/await}
{#await promise}
<p>waiting for the promise to resolve...</p>
{:catch}
<p>Something went wrong</p>
{/await}

Loading…
Cancel
Save