From 3e7589360a94eca01c547b7e9cb34006b53e7f88 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 24 Oct 2025 13:17:52 -0400 Subject: [PATCH] WIP --- .../src/compiler/phases/2-analyze/index.js | 23 +++++++++++++++- .../svelte/src/compiler/phases/types.d.ts | 27 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index b4c704c34d..5c653c7f2e 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -543,7 +543,9 @@ export function analyze_component(root, source, options) { snippet_renderers: new Map(), snippets: new Set(), async_deriveds: new Set(), - pickled_awaits: new Set() + pickled_awaits: new Set(), + awaited_declarations: new Map(), + awaited_statements: new Map() }; if (!runes) { @@ -687,6 +689,25 @@ export function analyze_component(root, source, options) { e.legacy_rest_props_invalid(rest_props_refs[0].node); } + if (instance.has_await) { + let awaiting = false; + let i = 0; + + for (const node of instance.ast.body) { + const has_await = has_await_expression(node); + awaiting ||= has_await; + + if (!awaiting) continue; + + const id = b.id(`$$${i++}`); + + analysis.awaited_statements.set(node, { + id, + has_await + }); + } + } + for (const { ast, scope, scopes } of [module, instance, template]) { /** @type {AnalysisState} */ const state = { diff --git a/packages/svelte/src/compiler/phases/types.d.ts b/packages/svelte/src/compiler/phases/types.d.ts index 4e287fd199..79fa4ab88e 100644 --- a/packages/svelte/src/compiler/phases/types.d.ts +++ b/packages/svelte/src/compiler/phases/types.d.ts @@ -5,7 +5,10 @@ import type { ClassBody, Identifier, LabeledStatement, - Program + ModuleDeclaration, + Pattern, + Program, + Statement } from 'estree'; import type { Scope, ScopeRoot } from './scope.js'; @@ -108,6 +111,28 @@ export interface ComponentAnalysis extends Analysis { * Every snippet that is declared locally */ snippets: Set; + /** + * A lookup of awaited declarations. If you have something this in `