Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/keep-empty-await-catch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'prettier-plugin-svelte': patch
---

fix: keep empty `{:catch}` in `{#await}` blocks (removing it turns a handled rejection into an unhandled one)
4 changes: 2 additions & 2 deletions src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,10 @@ export function print(path: AstPath, options: ParserOptions, print: PrintFn): Do
case 'AwaitBlock': {
const pending_children = node.pending?.nodes ?? [];
const then_children = node.then?.nodes ?? [];
const catch_children = node.catch?.nodes ?? [];
const hasPendingBlock = pending_children.some((n) => !isEmptyTextNode(n));
const hasThenBlock = then_children.some((n) => !isEmptyTextNode(n));
const hasCatchBlock = catch_children.some((n) => !isEmptyTextNode(n));
// Keep an empty `{:catch}`: without one, Svelte rethrows the rejection
const hasCatchBlock = !!node.catch;

let block = [];

Expand Down
5 changes: 5 additions & 0 deletions test/printer/samples/await-block-empty-catch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{#await thePromise then theValue}
<p>the value is {theValue}</p>
{:catch}{/await}

{#await thePromise catch}{/await}