Skip to content

Commit b155600

Browse files
committed
fix?
1 parent 741ba06 commit b155600

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { BlockStatement, Statement, Expression, VariableDeclaration } from 'estree' */
1+
/** @import { BlockStatement, Statement, Expression, VariableDeclaration, ArrowFunctionExpression, FunctionDeclaration } from 'estree' */
22
/** @import { AST } from '#compiler' */
33
/** @import { ComponentContext } from '../types' */
44
import { dev } from '../../../../state.js';
@@ -60,14 +60,26 @@ export function SvelteBoundary(node, context) {
6060

6161
const snippet = /** @type {VariableDeclaration} */ (statements[0]);
6262

63+
/** @type {FunctionDeclaration | (ArrowFunctionExpression & { body: BlockStatement})} */
6364
const snippet_fn = dev
6465
? // @ts-expect-error we know this shape is correct
6566
snippet.declarations[0].init.arguments[1]
6667
: snippet.declarations[0].init;
6768

68-
snippet_fn.body.body.unshift(
69-
...const_tags.filter((node) => node.type === 'VariableDeclaration')
70-
);
69+
if (node.fragment.metadata.has_await) {
70+
// we have to make sure the `$.suspend` goes before everything else
71+
snippet_fn.body.body.splice(
72+
dev ? 2 : 1,
73+
0,
74+
...const_tags.filter((node) => node.type === 'VariableDeclaration')
75+
);
76+
} else {
77+
snippet_fn.body.body.splice(
78+
dev ? 1 : 0,
79+
0,
80+
...const_tags.filter((node) => node.type === 'VariableDeclaration')
81+
);
82+
}
7183

7284
hoisted.push(snippet);
7385

0 commit comments

Comments
 (0)