Skip to content

Commit a4f17e1

Browse files
committed
tidy up
1 parent 69b95e6 commit a4f17e1

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export function analyze_module(ast, options) {
266266
immutable: true,
267267
tracing: analysis.tracing,
268268
async_deriveds: new Set(),
269-
suspenders: new Map()
269+
context_preserving_awaits: new Set()
270270
};
271271
}
272272

@@ -461,7 +461,7 @@ export function analyze_component(root, source, options) {
461461
snippet_renderers: new Map(),
462462
snippets: new Set(),
463463
async_deriveds: new Set(),
464-
suspenders: new Map()
464+
context_preserving_awaits: new Set()
465465
};
466466

467467
if (!runes) {

packages/svelte/src/compiler/phases/2-analyze/visitors/AwaitExpression.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export function AwaitExpression(node, context) {
3232
}
3333
}
3434

35-
if (suspend) {
36-
if (!context.state.analysis.runes) {
37-
e.legacy_await_invalid(node);
38-
}
35+
if (suspend && !context.state.analysis.runes) {
36+
e.legacy_await_invalid(node);
37+
}
3938

40-
context.state.analysis.suspenders.set(node, preserve_context);
39+
if (preserve_context) {
40+
context.state.analysis.context_preserving_awaits.add(node);
4141
}
4242

4343
context.next();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { get_rune } from '../../../scope.js';
88
* @param {Context} context
99
*/
1010
export function AwaitExpression(node, context) {
11-
const suspend = context.state.analysis.suspenders.get(node);
11+
const suspend = context.state.analysis.context_preserving_awaits.has(node);
1212

1313
if (!suspend) {
1414
return context.next();
@@ -18,7 +18,8 @@ export function AwaitExpression(node, context) {
1818
(n) =>
1919
n.type === 'VariableDeclaration' &&
2020
n.declarations.some(
21-
(d) => d.init?.type === 'CallExpression' && get_rune(d.init, context.state.scope) === '$derived'
21+
(d) =>
22+
d.init?.type === 'CallExpression' && get_rune(d.init, context.state.scope) === '$derived'
2223
)
2324
);
2425

packages/svelte/src/compiler/phases/3-transform/server/visitors/AwaitExpression.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ import * as b from '../../../../utils/builders.js';
77
* @param {Context} context
88
*/
99
export function AwaitExpression(node, context) {
10-
// `has`, not `get`, because all top-level await expressions should
11-
// block regardless of whether they need context preservation
12-
// in the client output
13-
const suspend = context.state.analysis.suspenders.has(node);
14-
15-
if (!suspend) {
10+
if (context.state.scope.function_depth > 1) {
1611
return context.next();
1712
}
1813

packages/svelte/src/compiler/phases/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export interface Analysis {
4343
/** A set of deriveds that contain `await` expressions */
4444
async_deriveds: Set<CallExpression>;
4545

46-
/** A map of `await` expressions that should block, and whether they should preserve context */
47-
suspenders: Map<AwaitExpression, boolean>;
46+
/** A map of `await` expressions that should preserve context */
47+
context_preserving_awaits: Set<AwaitExpression>;
4848
}
4949

5050
export interface ComponentAnalysis extends Analysis {

0 commit comments

Comments
 (0)