aaa
Rich Harris 8 months ago
parent 69b95e6285
commit a4f17e139a

@ -266,7 +266,7 @@ export function analyze_module(ast, options) {
immutable: true,
tracing: analysis.tracing,
async_deriveds: new Set(),
suspenders: new Map()
context_preserving_awaits: new Set()
};
}
@ -461,7 +461,7 @@ export function analyze_component(root, source, options) {
snippet_renderers: new Map(),
snippets: new Set(),
async_deriveds: new Set(),
suspenders: new Map()
context_preserving_awaits: new Set()
};
if (!runes) {

@ -32,12 +32,12 @@ export function AwaitExpression(node, context) {
}
}
if (suspend) {
if (!context.state.analysis.runes) {
e.legacy_await_invalid(node);
}
if (suspend && !context.state.analysis.runes) {
e.legacy_await_invalid(node);
}
context.state.analysis.suspenders.set(node, preserve_context);
if (preserve_context) {
context.state.analysis.context_preserving_awaits.add(node);
}
context.next();

@ -8,7 +8,7 @@ import { get_rune } from '../../../scope.js';
* @param {Context} context
*/
export function AwaitExpression(node, context) {
const suspend = context.state.analysis.suspenders.get(node);
const suspend = context.state.analysis.context_preserving_awaits.has(node);
if (!suspend) {
return context.next();
@ -18,7 +18,8 @@ export function AwaitExpression(node, context) {
(n) =>
n.type === 'VariableDeclaration' &&
n.declarations.some(
(d) => d.init?.type === 'CallExpression' && get_rune(d.init, context.state.scope) === '$derived'
(d) =>
d.init?.type === 'CallExpression' && get_rune(d.init, context.state.scope) === '$derived'
)
);

@ -7,12 +7,7 @@ import * as b from '../../../../utils/builders.js';
* @param {Context} context
*/
export function AwaitExpression(node, context) {
// `has`, not `get`, because all top-level await expressions should
// block regardless of whether they need context preservation
// in the client output
const suspend = context.state.analysis.suspenders.has(node);
if (!suspend) {
if (context.state.scope.function_depth > 1) {
return context.next();
}

@ -43,8 +43,8 @@ export interface Analysis {
/** A set of deriveds that contain `await` expressions */
async_deriveds: Set<CallExpression>;
/** A map of `await` expressions that should block, and whether they should preserve context */
suspenders: Map<AwaitExpression, boolean>;
/** A map of `await` expressions that should preserve context */
context_preserving_awaits: Set<AwaitExpression>;
}
export interface ComponentAnalysis extends Analysis {

Loading…
Cancel
Save