pull/17038/head
Rich Harris 1 week ago
parent 3e7589360a
commit d18d1b9fae

@ -693,12 +693,38 @@ export function analyze_component(root, source, options) {
let awaiting = false;
let i = 0;
for (const node of instance.ast.body) {
for (let node of instance.ast.body) {
if (node.type === 'ExportNamedDeclaration' && node.declaration) {
node = node.declaration;
}
if (node.type === 'VariableDeclaration') {
for (const declarator of node.declarations) {
const has_await = has_await_expression(declarator);
awaiting ||= has_await;
if (!awaiting) continue;
const id = b.id(`$$${i++}`);
for (const identifier of extract_identifiers(declarator.id)) {
analysis.awaited_declarations.set(identifier.name, {
id,
has_await,
pattern: declarator.id,
updated_by: new Set()
});
}
}
} else {
const has_await = has_await_expression(node);
awaiting ||= has_await;
if (!awaiting) continue;
if (node.type === 'ClassDeclaration' || node.type === 'FunctionDeclaration') {
throw new Error('TODO handle class/function declaration');
} else {
const id = b.id(`$$${i++}`);
analysis.awaited_statements.set(node, {
@ -707,6 +733,8 @@ export function analyze_component(root, source, options) {
});
}
}
}
}
for (const { ast, scope, scopes } of [module, instance, template]) {
/** @type {AnalysisState} */

@ -126,7 +126,7 @@ export interface ComponentAnalysis extends Analysis {
*/
awaited_declarations: Map<
string,
{ id: Identifier; pattern: Pattern; updated_by: Set<Identifier> }
{ id: Identifier; has_await: boolean; pattern: Pattern; updated_by: Set<Identifier> }
>;
/**
* Information about top-level instance statements that need to be transformed

Loading…
Cancel
Save