Skip to content

Commit b6ebbd8

Browse files
authored
fix: ensure await-block type is preserved in the latest Svelte version (#2895)
1 parent 229b9d4 commit b6ebbd8

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

.changeset/shy-pants-punch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'svelte2tsx': patch
3+
'svelte-check': patch
4+
---
5+
6+
fix: ensure await-block type is preserved in the latest Svelte version

packages/svelte2tsx/src/htmlxtojsx_v2/nodes/AwaitPendingCatchBlock.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ export function handleAwait(str: MagicString, awaitBlock: BaseNode): void {
4141
transforms.push('await (', [awaitBlock.expression.start, expressionEnd], ');');
4242

4343
if (awaitBlock.value) {
44-
transforms.push(
45-
'{ const ',
46-
[awaitBlock.value.start, awaitBlock.value.end],
47-
' = $$_value; '
48-
);
44+
const end = awaitBlock.value.typeAnnotation?.end ?? awaitBlock.value.end;
45+
transforms.push('{ const ', [awaitBlock.value.start, end], ' = $$_value; ');
4946
}
5047
if (!awaitBlock.then.skip) {
5148
if (awaitBlock.pending.skip) {
@@ -62,12 +59,9 @@ export function handleAwait(str: MagicString, awaitBlock: BaseNode): void {
6259
}
6360
if (awaitBlock.error || !awaitBlock.catch.skip) {
6461
transforms.push('} catch($$_e) { ');
62+
const end = awaitBlock.error?.typeAnnotation?.end ?? awaitBlock.error?.end;
6563
if (awaitBlock.error) {
66-
transforms.push(
67-
'const ',
68-
[awaitBlock.error.start, awaitBlock.error.end],
69-
' = __sveltets_2_any();'
70-
);
64+
transforms.push('const ', [awaitBlock.error.start, end], ' = __sveltets_2_any();');
7165
}
7266
if (!awaitBlock.catch.skip && awaitBlock.catch.children?.length) {
7367
transforms.push([

0 commit comments

Comments
 (0)