Home / File/ AwaitBlock.js — svelte Source File

AwaitBlock.js — svelte Source File

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

File javascript Compiler Transformer 11 imports 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  844ad472_83ed_856d_0120_d6773152f6bb["AwaitBlock.js"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  844ad472_83ed_856d_0120_d6773152f6bb --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  c12e0147_3f27_cf17_5878_e54ffdc328d5["extract_identifiers"]
  844ad472_83ed_856d_0120_d6773152f6bb --> c12e0147_3f27_cf17_5878_e54ffdc328d5
  bdb5b0f7_5673_570b_155a_0bd0f9f8169a["is_expression_async"]
  844ad472_83ed_856d_0120_d6773152f6bb --> bdb5b0f7_5673_570b_155a_0bd0f9f8169a
  c518b20b_2355_7b11_4ac2_2d9bb5dcfb43["utils.js"]
  844ad472_83ed_856d_0120_d6773152f6bb --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  c6147fac_8ab6_4ed2_9c90_08e83553fb43["create_derived"]
  844ad472_83ed_856d_0120_d6773152f6bb --> c6147fac_8ab6_4ed2_9c90_08e83553fb43
  1a53d630_ca18_6783_bd92_8c72517a9306["declarations.js"]
  844ad472_83ed_856d_0120_d6773152f6bb --> 1a53d630_ca18_6783_bd92_8c72517a9306
  b1380aab_0ea6_e12d_3df0_c3526fef2b75["get_value"]
  844ad472_83ed_856d_0120_d6773152f6bb --> b1380aab_0ea6_e12d_3df0_c3526fef2b75
  d04d7971_88df_542d_dd4f_26170ce6f581["utils.js"]
  844ad472_83ed_856d_0120_d6773152f6bb --> d04d7971_88df_542d_dd4f_26170ce6f581
  66243dec_e2be_a66d_3992_3ea42cf964b5["build_expression"]
  844ad472_83ed_856d_0120_d6773152f6bb --> 66243dec_e2be_a66d_3992_3ea42cf964b5
  575bfb79_8777_5076_eda3_be015882482a["add_svelte_meta"]
  844ad472_83ed_856d_0120_d6773152f6bb --> 575bfb79_8777_5076_eda3_be015882482a
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  844ad472_83ed_856d_0120_d6773152f6bb --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  7665e008_f37d_b860_a594_f2539a66af4e["transform-client.js"]
  7665e008_f37d_b860_a594_f2539a66af4e --> 844ad472_83ed_856d_0120_d6773152f6bb
  style 844ad472_83ed_856d_0120_d6773152f6bb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { BlockStatement, Pattern, Statement } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentClientTransformState, ComponentContext } from '../types' */
import { extract_identifiers, is_expression_async } from '../../../../utils/ast.js';
import * as b from '#compiler/builders';
import { create_derived } from '../utils.js';
import { get_value } from './shared/declarations.js';
import { build_expression, add_svelte_meta } from './shared/utils.js';

/**
 * @param {AST.AwaitBlock} node
 * @param {ComponentContext} context
 */
export function AwaitBlock(node, context) {
	context.state.template.push_comment();

	// Visit {#await <expression>} first to ensure that scopes are in the correct order
	const expression = b.thunk(
		build_expression(context, node.expression, node.metadata.expression),
		node.metadata.expression.has_await
	);

	let then_block;
	let catch_block;

	if (node.then) {
		const then_context = {
			...context,
			state: { ...context.state, transform: { ...context.state.transform } }
		};
		const argument = node.value && create_derived_block_argument(node.value, then_context);

		/** @type {Pattern[]} */
		const args = [b.id('$$anchor')];
		if (argument) args.push(argument.id);

		const declarations = argument?.declarations ?? [];
		const block = /** @type {BlockStatement} */ (then_context.visit(node.then, then_context.state));

		then_block = b.arrow(args, b.block([...declarations, ...block.body]));
	}

	if (node.catch) {
		const catch_context = { ...context, state: { ...context.state } };
		const argument = node.error && create_derived_block_argument(node.error, catch_context);

		/** @type {Pattern[]} */
		const args = [b.id('$$anchor')];
		if (argument) args.push(argument.id);

		const declarations = argument?.declarations ?? [];
		const block = /** @type {BlockStatement} */ (
			catch_context.visit(node.catch, catch_context.state)
		);

		catch_block = b.arrow(args, b.block([...declarations, ...block.body]));
	}

	const stmt = add_svelte_meta(
		b.call(
// ... (65 more lines)

Domain

Subdomains

Frequently Asked Questions

What does AwaitBlock.js do?
AwaitBlock.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 AwaitBlock.js?
AwaitBlock.js defines 2 function(s): AwaitBlock, create_derived_block_argument.
What does AwaitBlock.js depend on?
AwaitBlock.js imports 11 module(s): add_svelte_meta, ast.js, build_expression, builders, create_derived, declarations.js, extract_identifiers, get_value, and 3 more.
What files import AwaitBlock.js?
AwaitBlock.js is imported by 1 file(s): transform-client.js.
Where is AwaitBlock.js in the architecture?
AwaitBlock.js is located at packages/svelte/src/compiler/phases/3-transform/client/visitors/AwaitBlock.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/client/visitors).

Analyze Your Own Codebase

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

Try Supermodel Free