MCPcopy
hub / github.com/sveltejs/svelte / child

Function child

packages/svelte/src/internal/client/dom/operations.js:110–133  ·  view source on GitHub ↗
(node, is_text)

Source from the content-addressed store, hash-verified

108 * @returns {TemplateNode | null}
109 */
110export function child(node, is_text) {
111 if (!hydrating) {
112 return get_first_child(node);
113 }
114
115 var child = get_first_child(hydrate_node);
116
117 // Child can be null if we have an element with a single child, like `<p>{text}</p>`, where `text` is empty
118 if (child === null) {
119 child = hydrate_node.appendChild(create_text());
120 } else if (is_text && child.nodeType !== TEXT_NODE) {
121 var text = create_text();
122 child?.before(text);
123 set_hydrate_node(text);
124 return text;
125 }
126
127 if (is_text) {
128 merge_text_nodes(/** @type {Text} */ (child));
129 }
130
131 set_hydrate_node(child);
132 return child;
133}
134
135/**
136 * Don't mark this as side-effect-free, hydration needs to walk all nodes

Callers

nothing calls this directly

Calls 4

set_hydrate_nodeFunction · 0.90
get_first_childFunction · 0.85
create_textFunction · 0.85
merge_text_nodesFunction · 0.85

Tested by

no test coverage detected