Home / File/ Fragment.js — svelte Source File

Fragment.js — svelte Source File

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

File javascript Compiler Transformer 14 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  96f4a58f_3498_1ea2_7ff9_3d805414893b["Fragment.js"]
  73865c3c_2786_c9ac_d34f_b51d28b3a29e["constants.js"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> 73865c3c_2786_c9ac_d34f_b51d28b3a29e
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3["utils.js"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> f3fad5a9_6b91_ed4f_9331_7f9fc18491c3
  48b02cf8_c90b_7278_8655_c24e3431a4b3["clean_nodes"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> 48b02cf8_c90b_7278_8655_c24e3431a4b3
  19ba44b1_ed7b_aeee_985f_f1c151bf7e44["infer_namespace"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> 19ba44b1_ed7b_aeee_985f_f1c151bf7e44
  b14524b3_fb6c_95cc_463c_fff3e50c6bc6["index.js"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> b14524b3_fb6c_95cc_463c_fff3e50c6bc6
  bc77ac7b_055c_071d_a2e8_bdfe53d963db["transform_template"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> bc77ac7b_055c_071d_a2e8_bdfe53d963db
  c3ec4c82_ce35_6219_c232_12ebeea91443["template.js"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> c3ec4c82_ce35_6219_c232_12ebeea91443
  e1ee663e_9a6d_c084_3617_f6741c138bb7["Template"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> e1ee663e_9a6d_c084_3617_f6741c138bb7
  2d9685c3_3dc6_7a1f_823b_1e70d1834927["fragment.js"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> 2d9685c3_3dc6_7a1f_823b_1e70d1834927
  b52df138_fa9e_4e12_86dd_c455789e68c1["process_children"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> b52df138_fa9e_4e12_86dd_c455789e68c1
  d04d7971_88df_542d_dd4f_26170ce6f581["utils.js"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> d04d7971_88df_542d_dd4f_26170ce6f581
  0b544eaa_6377_1ef6_ac35_e0b4cbde3fbc["build_render_statement"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> 0b544eaa_6377_1ef6_ac35_e0b4cbde3fbc
  be60a9d7_77eb_5ad3_ab7e_2f9bd93a3db1["Memoizer"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> be60a9d7_77eb_5ad3_ab7e_2f9bd93a3db1
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  style 96f4a58f_3498_1ea2_7ff9_3d805414893b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Expression, Statement } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentClientTransformState, ComponentContext } from '../types' */
import * as b from '#compiler/builders';
import { TEMPLATE_FRAGMENT, TEMPLATE_USE_IMPORT_NODE } from '../../../../../constants.js';
import { clean_nodes, infer_namespace } from '../../utils.js';
import { transform_template } from '../transform-template/index.js';
import { Template } from '../transform-template/template.js';
import { process_children } from './shared/fragment.js';
import { build_render_statement, Memoizer } from './shared/utils.js';

/**
 * @param {AST.Fragment} node
 * @param {ComponentContext} context
 */
export function Fragment(node, context) {
	// Creates a new block which looks roughly like this:
	// ```js
	// // hoisted:
	// const block_name = $.from_html(`...`);
	//
	// // for the main block:
	// const id = block_name();
	// // init stuff and possibly render effect
	// $.append($$anchor, id);
	// ```
	// Adds the hoisted parts to `context.state.hoisted` and returns the statements of the main block.

	const parent = context.path.at(-1) ?? node;

	const namespace = infer_namespace(context.state.metadata.namespace, parent, node.nodes);

	const { hoisted, trimmed, is_standalone, is_text_first } = clean_nodes(
		parent,
		node.nodes,
		context.path,
		namespace,
		context.state,
		context.state.preserve_whitespace,
		context.state.options.preserveComments
	);

	if (hoisted.length === 0 && trimmed.length === 0) {
		return b.block([]);
	}

	const is_single_element = trimmed.length === 1 && trimmed[0].type === 'RegularElement';
	const is_single_child_not_needing_template =
		trimmed.length === 1 &&
		(trimmed[0].type === 'SvelteFragment' ||
			trimmed[0].type === 'TitleElement' ||
			(trimmed[0].type === 'IfBlock' &&
				trimmed[0].elseif &&
				/** @type {AST.IfBlock} */ (parent).metadata.flattened?.includes(trimmed[0])));
	const template_name = context.state.scope.root.unique('root'); // TODO infer name from parent

	/** @type {Statement[]} */
	const body = [];

	/** @type {Statement | undefined} */
// ... (127 more lines)

Domain

Subdomains

Functions

Frequently Asked Questions

What does Fragment.js do?
Fragment.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 Fragment.js?
Fragment.js defines 1 function(s): Fragment.
What does Fragment.js depend on?
Fragment.js imports 14 module(s): Memoizer, Template, build_render_statement, builders, clean_nodes, constants.js, fragment.js, index.js, and 6 more.
What files import Fragment.js?
Fragment.js is imported by 1 file(s): transform-client.js.
Where is Fragment.js in the architecture?
Fragment.js is located at packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.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