Home / File/ AwaitExpression.js — svelte Source File

AwaitExpression.js — svelte Source File

Architecture documentation for AwaitExpression.js, a javascript file in the svelte codebase. 2 imports, 1 dependents.

File javascript Compiler Transformer 2 imports 1 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  c9c24023_1004_2023_0ff3_88c290127328["AwaitExpression.js"]
  495501a4_a342_6a4d_ac11_e3e2fee8b218["errors.js"]
  c9c24023_1004_2023_0ff3_88c290127328 --> 495501a4_a342_6a4d_ac11_e3e2fee8b218
  a146f6ac_0088_8736_b6ce_318f9f115170["e"]
  c9c24023_1004_2023_0ff3_88c290127328 --> a146f6ac_0088_8736_b6ce_318f9f115170
  4aa8a188_84d4_0274_ed83_cac0ab1d3572["index.js"]
  4aa8a188_84d4_0274_ed83_cac0ab1d3572 --> c9c24023_1004_2023_0ff3_88c290127328
  style c9c24023_1004_2023_0ff3_88c290127328 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { AwaitExpression, Expression, SpreadElement, Property } from 'estree' */
/** @import { Context } from '../types' */
/** @import { AST } from '#compiler' */
import * as e from '../../../errors.js';

/**
 * @param {AwaitExpression} node
 * @param {Context} context
 */
export function AwaitExpression(node, context) {
	const tla = context.state.ast_type === 'instance' && context.state.function_depth === 1;

	// preserve context for awaits that precede other expressions in template or `$derived(...)`
	if (
		is_reactive_expression(
			context.path,
			context.state.derived_function_depth === context.state.function_depth
		) &&
		!is_last_evaluated_expression(context.path, node)
	) {
		context.state.analysis.pickled_awaits.add(node);
	}

	let suspend = tla;

	if (context.state.expression) {
		context.state.expression.has_await = true;

		suspend = true;
	}

	// disallow top-level `await` or `await` in template expressions
	// unless a) in runes mode and b) opted into `experimental.async`
	if (suspend) {
		if (!context.state.options.experimental.async) {
			e.experimental_async(node);
		}

		if (!context.state.analysis.runes) {
			e.legacy_await_invalid(node);
		}
	}

	context.next();
}

/**
 * @param {AST.SvelteNode[]} path
 * @param {boolean} in_derived
 */
export function is_reactive_expression(path, in_derived) {
	if (in_derived) return true;

	let i = path.length;

	while (i--) {
		const parent = path[i];

		if (
			parent.type === 'ArrowFunctionExpression' ||
// ... (91 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does AwaitExpression.js do?
AwaitExpression.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in AwaitExpression.js?
AwaitExpression.js defines 3 function(s): AwaitExpression, is_last_evaluated_expression, is_reactive_expression.
What does AwaitExpression.js depend on?
AwaitExpression.js imports 2 module(s): e, errors.js.
What files import AwaitExpression.js?
AwaitExpression.js is imported by 1 file(s): index.js.
Where is AwaitExpression.js in the architecture?
AwaitExpression.js is located at packages/svelte/src/compiler/phases/2-analyze/visitors/AwaitExpression.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/2-analyze/visitors).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free