EachBlock.js — svelte Source File
Architecture documentation for EachBlock.js, a javascript file in the svelte codebase. 3 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 9e1a9d63_62c9_f709_d0c5_4420094b5f16["EachBlock.js"] 74eddc85_a390_2aab_af5a_ef32b77d5430["utils.js"] 9e1a9d63_62c9_f709_d0c5_4420094b5f16 --> 74eddc85_a390_2aab_af5a_ef32b77d5430 6487918e_a8f7_315c_caf5_9694fc4edde7["create_child_block"] 9e1a9d63_62c9_f709_d0c5_4420094b5f16 --> 6487918e_a8f7_315c_caf5_9694fc4edde7 95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"] 9e1a9d63_62c9_f709_d0c5_4420094b5f16 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc 86cf8685_38fa_3a1c_9b81_21c452968289["transform-server.js"] 86cf8685_38fa_3a1c_9b81_21c452968289 --> 9e1a9d63_62c9_f709_d0c5_4420094b5f16 style 9e1a9d63_62c9_f709_d0c5_4420094b5f16 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/** @import { BlockStatement, Expression, Statement } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types.js' */
import * as b from '#compiler/builders';
import { block_close, block_open, block_open_else, create_child_block } from './shared/utils.js';
/**
* @param {AST.EachBlock} node
* @param {ComponentContext} context
*/
export function EachBlock(node, context) {
const state = context.state;
const each_node_meta = node.metadata;
const collection = /** @type {Expression} */ (context.visit(node.expression));
const index =
each_node_meta.contains_group_binding || !node.index ? each_node_meta.index : b.id(node.index);
const array_id = state.scope.root.unique('each_array');
/** @type {Statement[]} */
let statements = [b.const(array_id, b.call('$.ensure_array_like', collection))];
/** @type {Statement[]} */
const each = [];
if (node.context) {
each.push(b.let(node.context, b.member(array_id, index, true)));
}
if (index.name !== node.index && node.index != null) {
each.push(b.let(node.index, index));
}
const new_body = /** @type {BlockStatement} */ (context.visit(node.body)).body;
if (node.body) each.push(...new_body);
const for_loop = b.for(
b.declaration('let', [
b.declarator(index, b.literal(0)),
b.declarator('$$length', b.member(array_id, 'length'))
]),
b.binary('<', index, b.id('$$length')),
b.update('++', index, false),
b.block(each)
);
if (node.fallback) {
const open = b.stmt(b.call(b.id('$$renderer.push'), block_open));
const fallback = /** @type {BlockStatement} */ (context.visit(node.fallback));
fallback.body.unshift(b.stmt(b.call(b.id('$$renderer.push'), block_open_else)));
statements.push(
b.if(
b.binary('!==', b.member(array_id, 'length'), b.literal(0)),
b.block([open, for_loop]),
fallback
)
);
} else {
state.template.push(block_open);
statements.push(for_loop);
}
state.template.push(
...create_child_block(
statements,
node.metadata.expression.blockers(),
node.metadata.expression.has_await
),
block_close
);
}
Domain
Subdomains
Functions
Dependencies
- builders
- create_child_block
- utils.js
Source
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 1 function(s): EachBlock.
What does EachBlock.js depend on?
EachBlock.js imports 3 module(s): builders, create_child_block, utils.js.
What files import EachBlock.js?
EachBlock.js is imported by 1 file(s): transform-server.js.
Where is EachBlock.js in the architecture?
EachBlock.js is located at packages/svelte/src/compiler/phases/3-transform/server/visitors/EachBlock.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/server/visitors).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free