Home / Function/ LabeledStatement() — svelte Function Reference

LabeledStatement() — svelte Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  e53f58f8_c7f0_df51_d353_c71c4d511fda["LabeledStatement()"]
  c1192f7f_6f47_cc18_0b15_11659cccaf8d["LabeledStatement.js"]
  e53f58f8_c7f0_df51_d353_c71c4d511fda -->|defined in| c1192f7f_6f47_cc18_0b15_11659cccaf8d
  27fded45_bc11_247b_d3fe_94831379f9ed["build_getter()"]
  e53f58f8_c7f0_df51_d353_c71c4d511fda -->|calls| 27fded45_bc11_247b_d3fe_94831379f9ed
  style e53f58f8_c7f0_df51_d353_c71c4d511fda fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/3-transform/client/visitors/LabeledStatement.js lines 11–64

export function LabeledStatement(node, context) {
	if (context.state.analysis.runes || context.path.length > 1 || node.label.name !== '$') {
		context.next();
		return;
	}

	// To recreate Svelte 4 behaviour, we track the dependencies
	// the compiler can 'see', but we untrack the effect itself
	const reactive_statement = /** @type {ReactiveStatement} */ (
		context.state.analysis.reactive_statements.get(node)
	);

	if (!reactive_statement) return; // not the instance context

	let serialized_body = /** @type {Statement} */ (context.visit(node.body));

	if (serialized_body.type !== 'BlockStatement') {
		serialized_body = b.block([serialized_body]);
	}

	const body = serialized_body.body;

	/** @type {Expression[]} */
	const sequence = [];

	for (const binding of reactive_statement.dependencies) {
		if (binding.kind === 'normal' && binding.declaration_kind !== 'import') continue;

		const name = binding.node.name;
		let serialized = build_getter(b.id(name), context.state);

		// If the binding is a prop, we need to deep read it because it could be fine-grained $state
		// from a runes-component, where mutations don't trigger an update on the prop as a whole.
		if (name === '$$props' || name === '$$restProps' || binding.kind === 'bindable_prop') {
			serialized = b.call('$.deep_read_state', serialized);
		}

		sequence.push(serialized);
	}

	// these statements will be topologically ordered later
	context.state.legacy_reactive_statements.set(
		node,
		b.stmt(
			b.call(
				'$.legacy_pre_effect',
				sequence.length > 0 ? b.thunk(b.sequence(sequence)) : b.thunk(b.block([])),
				b.thunk(b.block(body))
			)
		)
	);

	return b.empty;
}

Domain

Subdomains

Frequently Asked Questions

What does LabeledStatement() do?
LabeledStatement() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/LabeledStatement.js.
Where is LabeledStatement() defined?
LabeledStatement() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/LabeledStatement.js at line 11.
What does LabeledStatement() call?
LabeledStatement() calls 1 function(s): build_getter.

Analyze Your Own Codebase

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

Try Supermodel Free