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

Function base_element

packages/svelte/src/compiler/print/index.js:138–169  ·  view source on GitHub ↗

* @param {AST.BaseElement} node * @param {Context} context * @param {AST.JSComment[]} comments

(node, context, comments)

Source from the content-addressed store, hash-verified

136 * @param {AST.JSComment[]} comments
137 */
138function base_element(node, context, comments) {
139 const child_context = context.new();
140
141 child_context.write('<' + node.name);
142
143 // Handle special Svelte components/elements that need 'this' attribute
144 if (node.type === 'SvelteComponent') {
145 child_context.write(' this={');
146 child_context.visit(/** @type {AST.SvelteComponent} */ (node).expression);
147 child_context.write('}');
148 } else if (node.type === 'SvelteElement') {
149 child_context.write(' this={');
150 child_context.visit(/** @type {AST.SvelteElement} */ (node).tag);
151 child_context.write('}');
152 }
153
154 const multiline_attributes = attributes(node, node.attributes, child_context, comments);
155 const is_doctype_node = node.name.toLowerCase() === '!doctype';
156 const is_self_closing =
157 is_void(node.name) || (node.type === 'Component' && node.fragment.nodes.length === 0);
158
159 if (is_doctype_node) child_context.write(`>`);
160 else if (is_self_closing) {
161 child_context.write(`${multiline_attributes ? '' : ' '}/>`);
162 } else {
163 child_context.write('>');
164 block(child_context, node.fragment, true);
165 child_context.write(`</${node.name}>`);
166 }
167
168 context.append(child_context);
169}
170
171/** @type {Visitors<AST.SvelteNode>} */
172const css_visitors = {

Callers 11

ComponentFunction · 0.85
RegularElementFunction · 0.85
SlotElementFunction · 0.85
SvelteBodyFunction · 0.85
SvelteBoundaryFunction · 0.85
SvelteDocumentFunction · 0.85
SvelteFragmentFunction · 0.85
SvelteHeadFunction · 0.85
SvelteSelfFunction · 0.85
SvelteWindowFunction · 0.85
TitleElementFunction · 0.85

Calls 4

is_voidFunction · 0.90
attributesFunction · 0.70
blockFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected