Repository: sveltejs/prettier-plugin-svelte (ts)

Issue:
Can not write recommended #await shorthand
Hello there!

I want to write this, because I only care about the possibility of an error.

```svelte
  {#await goto('/somewhere') catch error}
    {@debug error}
  {/await}
```

But Prettier formats the snippet above returning this.

```svelte
  {#await goto('/somewhere')}{:catch error}
    {@debug error}
  {/await}
```

This needless separation also leaves a warning: `Empty blocksvelte(empty-block)`, because there is nothing between the `#await` block and the `:catch` one.

My prettier config is as such.

```javascript
/**
 * @type {import('prettier').Options}
 */
module.exports = {
  plugins: [require('prettier-plugin-tailwindcss')],
  pluginSearchDirs: ['.'],
  overrides: [{files: '*.svelte', options: {parser: 'svelte'}}],
  tailwindConfig: './tailwind.config.cjs',
  arrowParens: 'always',
  bracketSpacing: false,
  endOfLine: 'lf',
  plugins: [],
  pluginSearchDirs: ['../../'],
  printWidth: 80,
  semi: true,
  singleQuote: true,
  tabWidth: 2,
  trailingComma: 'es5',
  useTabs: false,
  svelteSortOrder: 'options-styles-scripts-markup',
  svelteStrictMode: true,
  svelteBracketNewLine: false,
  svelteAllowShorthand: false,
  svelteIndentScriptAndStyle: true,
};
```

Should I remove strict mode? In any case, shouldn't this be allowed?

Kind regards.

Pull request:
[fix] format `{#await .. catch ..}..{/await}` correctly
Fixes #323

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 947e434..036808b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # prettier-plugin-svelte changelog
 
+## 2.8.1 (Unreleased)
+
+* (fix) format `{#await .. catch ..}..{/await}` correctly ([#323](https://github.com/sveltejs/prettier-plugin-svelte/issues/323)) 
+
 ## 2.8.0
 
 * (feat) support `singleAttributePerLine` Prettier option ([#305](https://github.com/sveltejs/prettier-plugin-svelte/issues/305))
diff --git a/src/print/index.ts b/src/print/index.ts
index c783c0e..5728e1a 100644
--- a/src/print/index.ts
+++ b/src/print/index.ts
@@ -540,6 +540,17 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
                     ]),
                     path.call(print, 'then'),
                 );
+            } else if (!hasPendingBlock && hasCatchBlock) {
+                block.push(
+                    groupConcat([
+                        '{#await ',
+                        printSvelteBlockJS(path, print, 'expression'),
+                        ' catch',
+                        expandNode(node.error),
+                        '}',
+                    ]),
+                    path.call(print, 'catch'),
+                );
             } else {
                 block.push(
                     groupConcat(['{#await ', printSvelteBlockJS(path, print, 'expression'), '}']),
@@ -557,7 +568,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
                 }
             }
 
-            if (hasCatchBlock) {
+            if ((hasPendingBlock || hasThenBlock) && hasCatchBlock) {
                 block.push(
                     groupConcat(['{:catch', expandNode(node.error), '}']),
                     path.call(print, 'catch'),


Test patch:
diff --git a/test/printer/samples/await-catch-without-pending.html b/test/printer/samples/await-catch-without-pending.html
new file mode 100644
index 0000000..841f620
--- /dev/null
+++ b/test/printer/samples/await-catch-without-pending.html
@@ -0,0 +1,1 @@
+{#await thePromise catch theCatch}the value is {theCatch}{/await}