Home / Function/ build_component() — svelte Function Reference

build_component() — svelte Function Reference

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

Function javascript Compiler Transformer calls 16 called by 3

Entity Profile

Dependency Diagram

graph TD
  2b6a1e4d_7060_eb43_d939_71517fa01ad9["build_component()"]
  be3a40b1_7e88_8a0c_e231_56c97bd7899f["component.js"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|defined in| be3a40b1_7e88_8a0c_e231_56c97bd7899f
  dd816393_ef95_1548_06fb_ab3a0914095c["Component()"]
  dd816393_ef95_1548_06fb_ab3a0914095c -->|calls| 2b6a1e4d_7060_eb43_d939_71517fa01ad9
  5349c3f9_f895_215f_b288_7cb5b05399d5["SvelteComponent()"]
  5349c3f9_f895_215f_b288_7cb5b05399d5 -->|calls| 2b6a1e4d_7060_eb43_d939_71517fa01ad9
  eaa8755e_f818_3556_13e3_2b83facd877a["SvelteSelf()"]
  eaa8755e_f818_3556_13e3_2b83facd877a -->|calls| 2b6a1e4d_7060_eb43_d939_71517fa01ad9
  a2d986c5_5ad1_b6ea_d335_4846d9af9e9f["determine_slot()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| a2d986c5_5ad1_b6ea_d335_4846d9af9e9f
  cd53dd1a_8bd9_06e2_6bfe_ed90344d0b28["build_event_handler()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| cd53dd1a_8bd9_06e2_6bfe_ed90344d0b28
  5ff7d39f_78e8_c057_8c8e_279f6e72149e["add()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| 5ff7d39f_78e8_c057_8c8e_279f6e72149e
  e31bc2c2_91c1_b9a9_f78a_2832bddce6c5["build_attribute_value()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| e31bc2c2_91c1_b9a9_f78a_2832bddce6c5
  f6625393_617b_8f3b_aaa5_b87527fde52f["get_attribute_chunks()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| f6625393_617b_8f3b_aaa5_b87527fde52f
  2cbdb96a_8cdf_2a80_c6c4_74090309d76b["check_blockers()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| 2cbdb96a_8cdf_2a80_c6c4_74090309d76b
  7a7783f8_ffa6_0cc3_61b0_031882649535["is_ignored()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| 7a7783f8_ffa6_0cc3_61b0_031882649535
  804afe56_25d1_9f41_dafe_adc75e952134["object()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| 804afe56_25d1_9f41_dafe_adc75e952134
  6922c44b_14fe_b017_d157_304290a82a06["validate_binding()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| 6922c44b_14fe_b017_d157_304290a82a06
  8027aa4e_4fda_68d8_71fa_0a45b97acb64["build_bind_this()"]
  2b6a1e4d_7060_eb43_d939_71517fa01ad9 -->|calls| 8027aa4e_4fda_68d8_71fa_0a45b97acb64
  style 2b6a1e4d_7060_eb43_d939_71517fa01ad9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js lines 19–536

export function build_component(node, component_name, loc, context) {
	/** @type {Expression} */
	const anchor = context.state.node;

	/** @type {Array<Property[] | Expression>} */
	const props_and_spreads = [];

	/** @type {Array<() => void>} */
	const delayed_props = [];

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

	/** @type {Record<string, typeof context.state>} */
	const states = {
		default: {
			...context.state,
			scope: node.metadata.scopes.default,
			transform: { ...context.state.transform }
		}
	};

	/** @type {Record<string, AST.TemplateNode[]>} */
	const children = {};

	/** @type {Record<string, Expression[]>} */
	const events = {};

	const memoizer = new Memoizer();

	/** @type {Property[]} */
	const custom_css_props = [];

	/** @type {Identifier | MemberExpression | SequenceExpression | null} */
	let bind_this = null;

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

	const is_component_dynamic =
		node.type === 'SvelteComponent' || (node.type === 'Component' && node.metadata.dynamic);

	// The variable name used for the component inside $.component()
	const intermediate_name =
		node.type === 'Component' && node.metadata.dynamic
			? context.state.scope.generate(node.name)
			: '$$component';

	/**
	 * If this component has a slot property, it is a named slot within another component. In this case
	 * the slot scope applies to the component itself, too, and not just its children.
	 */
	let slot_scope_applies_to_itself = !!determine_slot(node);

	/**
	 * Components may have a children prop and also have child nodes. In this case, we assume
	 * that the child component isn't using render tags yet and pass the slot as $$slots.default.
	 * We're not doing it for spread attributes, as this would result in too many false positives.
	 */
	let has_children_prop = false;

	/**
	 * @param {Property} prop
	 * @param {boolean} [delay]
	 */
	function push_prop(prop, delay = false) {
		const do_push = () => {
			const current = props_and_spreads.at(-1);
			const current_is_props = Array.isArray(current);
			const props = current_is_props ? current : [];
			props.push(prop);
			if (!current_is_props) {
				props_and_spreads.push(props);
			}
		};

		if (delay) {
			delayed_props.push(do_push);
		} else {
			do_push();
		}

Domain

Subdomains

Frequently Asked Questions

What does build_component() do?
build_component() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js.
Where is build_component() defined?
build_component() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js at line 19.
What does build_component() call?
build_component() calls 16 function(s): add, add_svelte_meta, apply, async_ids, async_values, blockers, build_attribute_value, build_bind_this, and 8 more.
What calls build_component()?
build_component() is called by 3 function(s): Component, SvelteComponent, SvelteSelf.

Analyze Your Own Codebase

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

Try Supermodel Free