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

Function fragment_from_tree

packages/svelte/src/internal/client/dom/template.js:171–211  ·  view source on GitHub ↗

* @param {TemplateStructure[]} structure * @param {typeof NAMESPACE_SVG | typeof NAMESPACE_MATHML | undefined} [ns]

(structure, ns)

Source from the content-addressed store, hash-verified

169 * @param {typeof NAMESPACE_SVG | typeof NAMESPACE_MATHML | undefined} [ns]
170 */
171function fragment_from_tree(structure, ns) {
172 var fragment = create_fragment();
173
174 for (var item of structure) {
175 if (typeof item === 'string') {
176 fragment.append(create_text(item));
177 continue;
178 }
179
180 // if `preserveComments === true`, comments are represented as `['// <data>']`
181 if (item === undefined || item[0][0] === '/') {
182 fragment.append(create_comment(item ? item[0].slice(3) : ''));
183 continue;
184 }
185
186 const [name, attributes, ...children] = item;
187
188 const namespace = name === 'svg' ? NAMESPACE_SVG : name === 'math' ? NAMESPACE_MATHML : ns;
189
190 var element = create_element(name, namespace, attributes?.is);
191
192 for (var key in attributes) {
193 set_attribute(element, key, attributes[key]);
194 }
195
196 if (children.length > 0) {
197 var target =
198 element.nodeName === TEMPLATE_TAG
199 ? /** @type {HTMLTemplateElement} */ (element).content
200 : element;
201
202 target.append(
203 fragment_from_tree(children, element.nodeName === 'foreignObject' ? undefined : namespace)
204 );
205 }
206
207 fragment.append(element);
208 }
209
210 return fragment;
211}
212
213/**
214 * @param {TemplateStructure[]} structure

Callers 1

from_treeFunction · 0.85

Calls 6

create_fragmentFunction · 0.90
create_textFunction · 0.90
create_commentFunction · 0.90
create_elementFunction · 0.90
set_attributeFunction · 0.90
appendMethod · 0.45

Tested by

no test coverage detected