Fragment() — svelte Function Reference
Architecture documentation for the Fragment() function in Fragment.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 0236de7e_7608_f21c_040b_e454b977a608["Fragment()"] 96f4a58f_3498_1ea2_7ff9_3d805414893b["Fragment.js"] 0236de7e_7608_f21c_040b_e454b977a608 -->|defined in| 96f4a58f_3498_1ea2_7ff9_3d805414893b 19ba44b1_ed7b_aeee_985f_f1c151bf7e44["infer_namespace()"] 0236de7e_7608_f21c_040b_e454b977a608 -->|calls| 19ba44b1_ed7b_aeee_985f_f1c151bf7e44 48b02cf8_c90b_7278_8655_c24e3431a4b3["clean_nodes()"] 0236de7e_7608_f21c_040b_e454b977a608 -->|calls| 48b02cf8_c90b_7278_8655_c24e3431a4b3 bc77ac7b_055c_071d_a2e8_bdfe53d963db["transform_template()"] 0236de7e_7608_f21c_040b_e454b977a608 -->|calls| bc77ac7b_055c_071d_a2e8_bdfe53d963db b52df138_fa9e_4e12_86dd_c455789e68c1["process_children()"] 0236de7e_7608_f21c_040b_e454b977a608 -->|calls| b52df138_fa9e_4e12_86dd_c455789e68c1 0b544eaa_6377_1ef6_ac35_e0b4cbde3fbc["build_render_statement()"] 0236de7e_7608_f21c_040b_e454b977a608 -->|calls| 0b544eaa_6377_1ef6_ac35_e0b4cbde3fbc style 0236de7e_7608_f21c_040b_e454b977a608 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.js lines 16–186
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} */
let close = undefined;
/** @type {ComponentClientTransformState} */
const state = {
...context.state,
init: [],
snippets: [],
consts: [],
let_directives: [],
update: [],
after_update: [],
memoizer: new Memoizer(),
template: new Template(),
transform: { ...context.state.transform },
metadata: {
namespace,
bound_contenteditable: context.state.metadata.bound_contenteditable
},
async_consts: undefined
};
for (const node of hoisted) {
context.visit(node, state);
}
if (is_single_element) {
const element = /** @type {AST.RegularElement} */ (trimmed[0]);
const id = b.id(context.state.scope.generate(element.name), element.name_loc);
context.visit(element, {
...state,
node: id
});
let flags = state.template.needs_import_node ? TEMPLATE_USE_IMPORT_NODE : undefined;
Domain
Subdomains
Source
Frequently Asked Questions
What does Fragment() do?
Fragment() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.js.
Where is Fragment() defined?
Fragment() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.js at line 16.
What does Fragment() call?
Fragment() calls 5 function(s): build_render_statement, clean_nodes, infer_namespace, process_children, transform_template.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free