Skip to content

Commit d81ffcb

Browse files
committed
fix: handle type annotations on Svelte control flow blocks
fixes #475
1 parent ab6e713 commit d81ffcb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-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+
## 3.3.2
4+
5+
- (fix) Svelte 5: handle type annotations on Svelte control flow blocks
6+
37
## 3.3.1
48

59
- (feat) Svelte 5: support upcoming `bind:value={get, set}`

src/print/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,12 @@ function printJS(path: FastPath, print: PrintFn, name: string) {
11771177
function expandNode(node: any, original: string): string {
11781178
let str = _expandNode(node);
11791179
if (node?.typeAnnotation) {
1180-
str += ': ' + original.slice(node.typeAnnotation.start, node.typeAnnotation.end);
1180+
str +=
1181+
': ' +
1182+
original.slice(
1183+
node.typeAnnotation.typeAnnotation.start,
1184+
node.typeAnnotation.typeAnnotation.end,
1185+
);
11811186
}
11821187
return str;
11831188
}

test/printer/samples/typescript-template.html.skip

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@
77
>
88

99
<button onclick={(e: Event) => e.detail}>{bar as any}</button>
10+
11+
{#await promise}
12+
<p>Waiting</p>
13+
{:then num: number}
14+
<p>{num}</p>
15+
{:catch error: Error}
16+
<p>Error: {error.message}</p>
17+
{/await}
18+
19+
{#each [] as x: number}
20+
{x}
21+
{/each}

0 commit comments

Comments
 (0)