Home / File/ EachBlock.js — svelte Source File

EachBlock.js — svelte Source File

Architecture documentation for EachBlock.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
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23["EachBlock.js"]
  73865c3c_2786_c9ac_d34f_b51d28b3a29e["constants.js"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> 73865c3c_2786_c9ac_d34f_b51d28b3a29e
  62f818c8_e890_17ed_5ec1_92f953d4a7a6["state.js"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> 62f818c8_e890_17ed_5ec1_92f953d4a7a6
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  c254e734_2224_c309_f1f8_bb064e80b1af["extract_paths"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> c254e734_2224_c309_f1f8_bb064e80b1af
  804afe56_25d1_9f41_dafe_adc75e952134["object"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> 804afe56_25d1_9f41_dafe_adc75e952134
  1a53d630_ca18_6783_bd92_8c72517a9306["declarations.js"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> 1a53d630_ca18_6783_bd92_8c72517a9306
  b1380aab_0ea6_e12d_3df0_c3526fef2b75["get_value"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> b1380aab_0ea6_e12d_3df0_c3526fef2b75
  d04d7971_88df_542d_dd4f_26170ce6f581["utils.js"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> d04d7971_88df_542d_dd4f_26170ce6f581
  66243dec_e2be_a66d_3992_3ea42cf964b5["build_expression"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> 66243dec_e2be_a66d_3992_3ea42cf964b5
  575bfb79_8777_5076_eda3_be015882482a["add_svelte_meta"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> 575bfb79_8777_5076_eda3_be015882482a
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  7665e008_f37d_b860_a594_f2539a66af4e["transform-client.js"]
  7665e008_f37d_b860_a594_f2539a66af4e --> f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23
  style f0f2f8c6_dafa_048c_81e7_9a2e89e2dd23 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { BlockStatement, Expression, Identifier, Pattern, Statement } from 'estree' */
/** @import { AST, Binding } from '#compiler' */
/** @import { ComponentContext } from '../types' */
/** @import { Scope } from '../../../scope' */
import {
	EACH_INDEX_REACTIVE,
	EACH_IS_ANIMATED,
	EACH_IS_CONTROLLED,
	EACH_ITEM_IMMUTABLE,
	EACH_ITEM_REACTIVE
} from '../../../../../constants.js';
import { dev } from '../../../../state.js';
import { extract_paths, object } from '../../../../utils/ast.js';
import * as b from '#compiler/builders';
import { get_value } from './shared/declarations.js';
import { build_expression, add_svelte_meta } from './shared/utils.js';

/**
 * @param {AST.EachBlock} node
 * @param {ComponentContext} context
 */
export function EachBlock(node, context) {
	const each_node_meta = node.metadata;

	// expression should be evaluated in the parent scope, not the scope
	// created by the each block itself
	const parent_scope_state = {
		...context.state,
		scope: /** @type {Scope} */ (context.state.scope.parent)
	};

	const collection = build_expression(
		{
			...context,
			state: parent_scope_state
		},
		node.expression,
		node.metadata.expression
	);

	if (!each_node_meta.is_controlled) {
		context.state.template.push_comment();
	}

	let flags = 0;

	if (node.metadata.keyed && node.index) {
		flags |= EACH_INDEX_REACTIVE;
	}

	const key_is_item =
		node.key?.type === 'Identifier' &&
		node.context?.type === 'Identifier' &&
		node.context?.name === node.key.name;

	// if the each block expression references a store subscription, we need
	// to use mutable stores internally
	let uses_store;

	for (const binding of node.metadata.expression.dependencies) {
// ... (303 more lines)

Domain

Subdomains

Frequently Asked Questions

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