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

Function element

packages/svelte/src/internal/client/dom/blocks/svelte-element.js:31–154  ·  view source on GitHub ↗
(node, get_tag, is_svg, render_fn, get_namespace, location)

Source from the content-addressed store, hash-verified

29 * @returns {void}
30 */
31export function element(node, get_tag, is_svg, render_fn, get_namespace, location) {
32 let was_hydrating = hydrating;
33
34 if (hydrating) {
35 hydrate_next();
36 }
37
38 var filename = DEV && location && component_context?.function[FILENAME];
39
40 /** @type {null | Element} */
41 var element = null;
42
43 if (hydrating && hydrate_node.nodeType === ELEMENT_NODE) {
44 element = /** @type {Element} */ (hydrate_node);
45 hydrate_next();
46 }
47
48 var anchor = /** @type {TemplateNode} */ (hydrating ? hydrate_node : node);
49
50 /**
51 * We track this so we can set it when changing the element, allowing any
52 * `animate:` directive to bind itself to the correct block
53 */
54 var parent_effect = /** @type {Effect} */ (active_effect);
55
56 var branches = new BranchManager(anchor, false);
57
58 block(() => {
59 const next_tag = get_tag() || null;
60 var ns = get_namespace
61 ? get_namespace()
62 : is_svg || next_tag === 'svg'
63 ? NAMESPACE_SVG
64 : undefined;
65
66 if (next_tag === null) {
67 branches.ensure(null, null);
68 set_should_intro(true);
69 return;
70 }
71
72 branches.ensure(next_tag, (anchor) => {
73 if (next_tag) {
74 element = hydrating ? /** @type {Element} */ (element) : create_element(next_tag, ns);
75
76 if (DEV && location) {
77 // @ts-expect-error
78 element.__svelte_meta = {
79 parent: dev_stack,
80 loc: {
81 file: filename,
82 line: location[0],
83 column: location[1]
84 }
85 };
86 }
87
88 assign_nodes(element, element);

Callers

nothing calls this directly

Calls 14

ensureMethod · 0.95
hydrate_nextFunction · 0.90
blockFunction · 0.90
set_should_introFunction · 0.90
create_elementFunction · 0.90
assign_nodesFunction · 0.90
is_raw_text_elementFunction · 0.90
get_first_childFunction · 0.90
create_textFunction · 0.90
set_hydratingFunction · 0.90
set_hydrate_nodeFunction · 0.90

Tested by

no test coverage detected