Home / File/ LabeledStatement.js — svelte Source File

LabeledStatement.js — svelte Source File

Architecture documentation for LabeledStatement.js, a javascript file in the svelte codebase. 3 imports, 1 dependents.

File javascript Compiler Transformer 3 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  c1192f7f_6f47_cc18_0b15_11659cccaf8d["LabeledStatement.js"]
  c518b20b_2355_7b11_4ac2_2d9bb5dcfb43["utils.js"]
  c1192f7f_6f47_cc18_0b15_11659cccaf8d --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  27fded45_bc11_247b_d3fe_94831379f9ed["build_getter"]
  c1192f7f_6f47_cc18_0b15_11659cccaf8d --> 27fded45_bc11_247b_d3fe_94831379f9ed
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  c1192f7f_6f47_cc18_0b15_11659cccaf8d --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  7665e008_f37d_b860_a594_f2539a66af4e["transform-client.js"]
  7665e008_f37d_b860_a594_f2539a66af4e --> c1192f7f_6f47_cc18_0b15_11659cccaf8d
  style c1192f7f_6f47_cc18_0b15_11659cccaf8d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Expression, LabeledStatement, Statement } from 'estree' */
/** @import { ReactiveStatement } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '#compiler/builders';
import { build_getter } from '../utils.js';

/**
 * @param {LabeledStatement} node
 * @param {ComponentContext} context
 */
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

Functions

Dependencies

Frequently Asked Questions

What does LabeledStatement.js do?
LabeledStatement.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in LabeledStatement.js?
LabeledStatement.js defines 1 function(s): LabeledStatement.
What does LabeledStatement.js depend on?
LabeledStatement.js imports 3 module(s): build_getter, builders, utils.js.
What files import LabeledStatement.js?
LabeledStatement.js is imported by 1 file(s): transform-client.js.
Where is LabeledStatement.js in the architecture?
LabeledStatement.js is located at packages/svelte/src/compiler/phases/3-transform/client/visitors/LabeledStatement.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/client/visitors).

Analyze Your Own Codebase

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

Try Supermodel Free