process_children() — svelte Function Reference
Architecture documentation for the process_children() function in fragment.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD b52df138_fa9e_4e12_86dd_c455789e68c1["process_children()"] 2d9685c3_3dc6_7a1f_823b_1e70d1834927["fragment.js"] b52df138_fa9e_4e12_86dd_c455789e68c1 -->|defined in| 2d9685c3_3dc6_7a1f_823b_1e70d1834927 0236de7e_7608_f21c_040b_e454b977a608["Fragment()"] 0236de7e_7608_f21c_040b_e454b977a608 -->|calls| b52df138_fa9e_4e12_86dd_c455789e68c1 1e3b81f2_cd53_e5a5_0140_a9af38facf99["RegularElement()"] 1e3b81f2_cd53_e5a5_0140_a9af38facf99 -->|calls| b52df138_fa9e_4e12_86dd_c455789e68c1 f3280f06_553d_66c3_8ca2_c3c36dcdda64["build_template_chunk()"] b52df138_fa9e_4e12_86dd_c455789e68c1 -->|calls| f3280f06_553d_66c3_8ca2_c3c36dcdda64 9ed24ec7_b6a7_48e2_39ec_d718faf36705["is_static_element()"] b52df138_fa9e_4e12_86dd_c455789e68c1 -->|calls| 9ed24ec7_b6a7_48e2_39ec_d718faf36705 3b2a4fcc_2df2_7057_21b4_4cac59b8df61["is_async()"] b52df138_fa9e_4e12_86dd_c455789e68c1 -->|calls| 3b2a4fcc_2df2_7057_21b4_4cac59b8df61 style b52df138_fa9e_4e12_86dd_c455789e68c1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js lines 19–136
export function process_children(nodes, initial, is_element, context) {
const within_bound_contenteditable = context.state.metadata.bound_contenteditable;
let prev = initial;
let skipped = 0;
/** @typedef {Array<AST.Text | AST.ExpressionTag>} Sequence */
/** @type {Sequence} */
let sequence = [];
/** @param {boolean} is_text */
function get_node(is_text) {
if (skipped === 0) {
return prev(is_text);
}
return b.call(
'$.sibling',
prev(false),
(is_text || skipped !== 1) && b.literal(skipped),
is_text && b.true
);
}
/**
* @param {boolean} is_text
* @param {string} name
* @param {SourceLocation | null} [loc]
*/
function flush_node(is_text, name, loc) {
const expression = get_node(is_text);
let id = expression;
if (id.type !== 'Identifier') {
id = b.id(context.state.scope.generate(name), loc);
context.state.init.push(b.var(id, expression));
}
prev = () => id;
skipped = 1; // the next node is `$.sibling(id)`
return id;
}
/**
* @param {Sequence} sequence
*/
function flush_sequence(sequence) {
if (sequence.every((node) => node.type === 'Text')) {
skipped += 1;
context.state.template.push_text(sequence);
return;
}
context.state.template.push_text([{ type: 'Text', data: ' ', raw: ' ', start: -1, end: -1 }]);
const { has_state, value } = build_template_chunk(sequence, context);
// if this is a standalone `{expression}`, make sure we handle the case where
// no text node was created because the expression was empty during SSR
const is_text = sequence.length === 1;
const id = flush_node(is_text, 'text');
const update = b.stmt(b.call('$.set_text', id, value));
if (has_state && !within_bound_contenteditable) {
context.state.update.push(update);
} else {
context.state.init.push(b.stmt(b.assignment('=', b.member(id, 'nodeValue'), value)));
}
}
for (const node of nodes) {
if (node.type === 'Text' || node.type === 'ExpressionTag') {
sequence.push(node);
} else {
if (sequence.length > 0) {
flush_sequence(sequence);
sequence = [];
}
let child_state = context.state;
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does process_children() do?
process_children() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js.
Where is process_children() defined?
process_children() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js at line 19.
What does process_children() call?
process_children() calls 3 function(s): build_template_chunk, is_async, is_static_element.
What calls process_children()?
process_children() is called by 2 function(s): Fragment, RegularElement.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free