IfBlock.js — svelte Source File
Architecture documentation for IfBlock.js, a javascript file in the svelte codebase. 5 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 349b9b06_99f6_79ed_a469_c74ec514305c["IfBlock.js"] c4b4ac8d_9914_5ede_1aea_723bf80d2e9b["fragment.js"] 349b9b06_99f6_79ed_a469_c74ec514305c --> c4b4ac8d_9914_5ede_1aea_723bf80d2e9b 313d2a82_30ea_3161_3aad_0cc2094979aa["mark_subtree_dynamic"] 349b9b06_99f6_79ed_a469_c74ec514305c --> 313d2a82_30ea_3161_3aad_0cc2094979aa bf0d8f1b_17da_970d_bf44_fbcf099d5371["utils.js"] 349b9b06_99f6_79ed_a469_c74ec514305c --> bf0d8f1b_17da_970d_bf44_fbcf099d5371 ea08cb05_2664_4e93_7551_6103e0cb3a87["validate_block_not_empty"] 349b9b06_99f6_79ed_a469_c74ec514305c --> ea08cb05_2664_4e93_7551_6103e0cb3a87 7148e639_69d8_a03d_3f08_bd23f41e718a["validate_opening_tag"] 349b9b06_99f6_79ed_a469_c74ec514305c --> 7148e639_69d8_a03d_3f08_bd23f41e718a 4aa8a188_84d4_0274_ed83_cac0ab1d3572["index.js"] 4aa8a188_84d4_0274_ed83_cac0ab1d3572 --> 349b9b06_99f6_79ed_a469_c74ec514305c style 349b9b06_99f6_79ed_a469_c74ec514305c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { mark_subtree_dynamic } from './shared/fragment.js';
import { validate_block_not_empty, validate_opening_tag } from './shared/utils.js';
/**
* @param {AST.IfBlock} node
* @param {Context} context
*/
export function IfBlock(node, context) {
validate_block_not_empty(node.consequent, context);
validate_block_not_empty(node.alternate, context);
if (context.state.analysis.runes) {
validate_opening_tag(node, context.state, node.elseif ? ':' : '#');
}
mark_subtree_dynamic(context.path);
context.visit(node.test, {
...context.state,
expression: node.metadata.expression
});
context.visit(node.consequent);
if (node.alternate) context.visit(node.alternate);
// Check if we can flatten branches
const alt = node.alternate;
if (alt && alt.nodes.length === 1 && alt.nodes[0].type === 'IfBlock' && alt.nodes[0].elseif) {
const elseif = alt.nodes[0];
// Don't flatten if this else-if has an await expression or new blockers
// TODO would be nice to check the await expression itself to see if it's awaiting the same thing as a previous if expression
if (
!elseif.metadata.expression.has_await &&
!elseif.metadata.expression.has_more_blockers_than(node.metadata.expression)
) {
// Roll the existing flattened branches (if any) into this one, then delete those of the else-if block
// to avoid processing them multiple times as we walk down the chain during code transformation.
node.metadata.flattened = [elseif, ...(elseif.metadata.flattened ?? [])];
elseif.metadata.flattened = undefined;
}
}
}
Domain
Subdomains
Functions
Source
Frequently Asked Questions
What does IfBlock.js do?
IfBlock.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 IfBlock.js?
IfBlock.js defines 1 function(s): IfBlock.
What does IfBlock.js depend on?
IfBlock.js imports 5 module(s): fragment.js, mark_subtree_dynamic, utils.js, validate_block_not_empty, validate_opening_tag.
What files import IfBlock.js?
IfBlock.js is imported by 1 file(s): index.js.
Where is IfBlock.js in the architecture?
IfBlock.js is located at packages/svelte/src/compiler/phases/2-analyze/visitors/IfBlock.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