Skip to content

Commit 7cfd71b

Browse files
authored
[fix] format {#await .. catch ..}..{/await} correctly (#324)
Fixes #323
1 parent ebd7e9a commit 7cfd71b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# prettier-plugin-svelte changelog
22

3+
## 2.8.1 (Unreleased)
4+
5+
* (fix) format `{#await .. catch ..}..{/await}` correctly ([#323](https://github.com/sveltejs/prettier-plugin-svelte/issues/323))
6+
37
## 2.8.0
48

59
* (feat) support `singleAttributePerLine` Prettier option ([#305](https://github.com/sveltejs/prettier-plugin-svelte/issues/305))

src/print/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,17 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
540540
]),
541541
path.call(print, 'then'),
542542
);
543+
} else if (!hasPendingBlock && hasCatchBlock) {
544+
block.push(
545+
groupConcat([
546+
'{#await ',
547+
printSvelteBlockJS(path, print, 'expression'),
548+
' catch',
549+
expandNode(node.error),
550+
'}',
551+
]),
552+
path.call(print, 'catch'),
553+
);
543554
} else {
544555
block.push(
545556
groupConcat(['{#await ', printSvelteBlockJS(path, print, 'expression'), '}']),
@@ -557,7 +568,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
557568
}
558569
}
559570

560-
if (hasCatchBlock) {
571+
if ((hasPendingBlock || hasThenBlock) && hasCatchBlock) {
561572
block.push(
562573
groupConcat(['{:catch', expandNode(node.error), '}']),
563574
path.call(print, 'catch'),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{#await thePromise catch theCatch}the value is {theCatch}{/await}

0 commit comments

Comments
 (0)