Skip to content

Commit

Permalink
fix: handle type annotations on Svelte control flow blocks
Browse files Browse the repository at this point in the history
fixes #475
  • Loading branch information
dummdidumm committed Nov 22, 2024
1 parent ab6e713 commit d81ffcb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# prettier-plugin-svelte changelog

## 3.3.2

- (fix) Svelte 5: handle type annotations on Svelte control flow blocks

## 3.3.1

- (feat) Svelte 5: support upcoming `bind:value={get, set}`
Expand Down
7 changes: 6 additions & 1 deletion src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,12 @@ function printJS(path: FastPath, print: PrintFn, name: string) {
function expandNode(node: any, original: string): string {
let str = _expandNode(node);
if (node?.typeAnnotation) {
str += ': ' + original.slice(node.typeAnnotation.start, node.typeAnnotation.end);
str +=
': ' +
original.slice(
node.typeAnnotation.typeAnnotation.start,
node.typeAnnotation.typeAnnotation.end,
);
}
return str;
}
Expand Down
12 changes: 12 additions & 0 deletions test/printer/samples/typescript-template.html.skip
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@
>

<button onclick={(e: Event) => e.detail}>{bar as any}</button>

{#await promise}
<p>Waiting</p>
{:then num: number}
<p>{num}</p>
{:catch error: Error}
<p>Error: {error.message}</p>
{/await}

{#each [] as x: number}
{x}
{/each}

0 comments on commit d81ffcb

Please sign in to comment.