Home / Function/ SvelteElement() — svelte Function Reference

SvelteElement() — svelte Function Reference

Architecture documentation for the SvelteElement() function in SvelteElement.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  2bb483c4_1076_90c3_46bb_acc4dec02b3b["SvelteElement()"]
  1e080b62_b957_2cdd_1807_50b2a8298518["SvelteElement.js"]
  2bb483c4_1076_90c3_46bb_acc4dec02b3b -->|defined in| 1e080b62_b957_2cdd_1807_50b2a8298518
  653284b2_68fd_eee3_0064_918a4c065d4a["is_text_attribute()"]
  2bb483c4_1076_90c3_46bb_acc4dec02b3b -->|calls| 653284b2_68fd_eee3_0064_918a4c065d4a
  573f9041_7062_5e5d_80e6_7292990c13c5["build_set_class()"]
  2bb483c4_1076_90c3_46bb_acc4dec02b3b -->|calls| 573f9041_7062_5e5d_80e6_7292990c13c5
  ef858948_a3b7_f31d_ad40_16743e642d00["build_attribute_effect()"]
  2bb483c4_1076_90c3_46bb_acc4dec02b3b -->|calls| ef858948_a3b7_f31d_ad40_16743e642d00
  0b544eaa_6377_1ef6_ac35_e0b4cbde3fbc["build_render_statement()"]
  2bb483c4_1076_90c3_46bb_acc4dec02b3b -->|calls| 0b544eaa_6377_1ef6_ac35_e0b4cbde3fbc
  a475d4d0_a1fa_71f2_13d3_ba42155a8763["determine_namespace_for_children()"]
  2bb483c4_1076_90c3_46bb_acc4dec02b3b -->|calls| a475d4d0_a1fa_71f2_13d3_ba42155a8763
  e31bc2c2_91c1_b9a9_f78a_2832bddce6c5["build_attribute_value()"]
  2bb483c4_1076_90c3_46bb_acc4dec02b3b -->|calls| e31bc2c2_91c1_b9a9_f78a_2832bddce6c5
  c8d80c9d_ab6c_13c0_c85e_a9b120f82f45["blockers()"]
  2bb483c4_1076_90c3_46bb_acc4dec02b3b -->|calls| c8d80c9d_ab6c_13c0_c85e_a9b120f82f45
  style 2bb483c4_1076_90c3_46bb_acc4dec02b3b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteElement.js lines 19–161

export function SvelteElement(node, context) {
	context.state.template.push_comment();

	/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
	const attributes = [];

	/** @type {AST.Attribute['value'] | undefined} */
	let dynamic_namespace = undefined;

	/** @type {AST.ClassDirective[]} */
	const class_directives = [];

	/** @type {AST.StyleDirective[]} */
	const style_directives = [];

	/** @type {ExpressionStatement[]} */
	const statements = [];

	// Create a temporary context which picks up the init/update statements.
	// They'll then be added to the function parameter of $.element
	const element_id = b.id(context.state.scope.generate('$$element'));

	/** @type {ComponentContext} */
	const inner_context = {
		...context,
		state: {
			...context.state,
			node: element_id,
			init: [],
			update: [],
			after_update: [],
			memoizer: new Memoizer()
		}
	};

	for (const attribute of node.attributes) {
		if (attribute.type === 'Attribute') {
			if (attribute.name === 'xmlns' && !is_text_attribute(attribute)) {
				dynamic_namespace = attribute.value;
			}
			attributes.push(attribute);
		} else if (attribute.type === 'SpreadAttribute') {
			attributes.push(attribute);
		} else if (attribute.type === 'ClassDirective') {
			class_directives.push(attribute);
		} else if (attribute.type === 'StyleDirective') {
			style_directives.push(attribute);
		} else if (attribute.type === 'LetDirective') {
			statements.push(/** @type {ExpressionStatement} */ (context.visit(attribute)));
		} else if (attribute.type === 'OnDirective') {
			const handler = /** @type {Expression} */ (context.visit(attribute, inner_context.state));
			inner_context.state.after_update.push(b.stmt(handler));
		} else {
			context.visit(attribute, inner_context.state);
		}
	}

	if (
		attributes.length === 1 &&
		attributes[0].type === 'Attribute' &&
		attributes[0].name.toLowerCase() === 'class' &&
		is_text_attribute(attributes[0])
	) {
		build_set_class(node, element_id, attributes[0], class_directives, inner_context, false);
	} else if (attributes.length) {
		// Always use spread because we don't know whether the element is a custom element or not,
		// therefore we need to do the "how to set an attribute" logic at runtime.
		build_attribute_effect(
			attributes,
			class_directives,
			style_directives,
			inner_context,
			node,
			element_id
		);
	}

	const has_await = node.metadata.expression.has_await;
	const has_blockers = node.metadata.expression.has_blockers();

	const expression = /** @type {Expression} */ (context.visit(node.tag));

Domain

Subdomains

Frequently Asked Questions

What does SvelteElement() do?
SvelteElement() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteElement.js.
Where is SvelteElement() defined?
SvelteElement() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteElement.js at line 19.
What does SvelteElement() call?
SvelteElement() calls 7 function(s): blockers, build_attribute_effect, build_attribute_value, build_render_statement, build_set_class, determine_namespace_for_children, is_text_attribute.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free