Home / Class/ Binding Class — svelte Architecture

Binding Class — svelte Architecture

Architecture documentation for the Binding class in scope.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  081337ba_de52_5c6a_048c_b2c15432ee87["Binding"]
  ee93d8a6_6fde_b1c1_e15b_3a4da5326305["scope.js"]
  081337ba_de52_5c6a_048c_b2c15432ee87 -->|defined in| ee93d8a6_6fde_b1c1_e15b_3a4da5326305
  4590c702_cbcc_17a6_4fb5_30e5c8cd2d60["constructor()"]
  081337ba_de52_5c6a_048c_b2c15432ee87 -->|method| 4590c702_cbcc_17a6_4fb5_30e5c8cd2d60
  673fefa3_12a6_78c1_9ed6_627d10ab8311["updated()"]
  081337ba_de52_5c6a_048c_b2c15432ee87 -->|method| 673fefa3_12a6_78c1_9ed6_627d10ab8311
  f10026d2_055e_88d6_ace4_e4f662b54259["is_function()"]
  081337ba_de52_5c6a_048c_b2c15432ee87 -->|method| f10026d2_055e_88d6_ace4_e4f662b54259

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/scope.js lines 88–190

export class Binding {
	/** @type {Scope} */
	scope;

	/** @type {Identifier} */
	node;

	/** @type {BindingKind} */
	kind;

	/** @type {DeclarationKind} */
	declaration_kind;

	/**
	 * What the value was initialized with.
	 * For destructured props such as `let { foo = 'bar' } = $props()` this is `'bar'` and not `$props()`
	 * @type {null | Expression | FunctionDeclaration | ClassDeclaration | ImportDeclaration | AST.EachBlock | AST.SnippetBlock}
	 */
	initial = null;

	/** @type {Array<{ node: Identifier; path: AST.SvelteNode[] }>} */
	references = [];

	/**
	 * (Re)assignments of this binding. Includes declarations such as `function x() {}`.
	 * @type {Array<{ value: Expression; scope: Scope }>}
	 */
	assignments = [];

	/**
	 * For `legacy_reactive`: its reactive dependencies
	 * @type {Binding[]}
	 */
	legacy_dependencies = [];

	/**
	 * Legacy props: the `class` in `{ export klass as class}`. $props(): The `class` in { class: klass } = $props()
	 * @type {string | null}
	 */
	prop_alias = null;

	/**
	 * Additional metadata, varies per binding type
	 * @type {null | { inside_rest?: boolean; is_template_declaration?: boolean; exclude_props?: string[] }}
	 */
	metadata = null;

	mutated = false;
	reassigned = false;

	/**
	 * Instance-level declarations may follow (or contain) a top-level `await`. In these cases,
	 * any reads that occur in the template must wait for the corresponding promise to resolve
	 * otherwise the initial value will not have been assigned.
	 * It is a member expression of the form `$$blockers[n]`.
	 * TODO the blocker is set during transform which feels a bit grubby
	 * @type {MemberExpression | null}
	 */
	blocker = null;

	/**
	 *
	 * @param {Scope} scope
	 * @param {Identifier} node
	 * @param {BindingKind} kind
	 * @param {DeclarationKind} declaration_kind
	 * @param {Binding['initial']} initial
	 */
	constructor(scope, node, kind, declaration_kind, initial) {
		this.scope = scope;
		this.node = node;
		this.initial = initial;
		this.kind = kind;
		this.declaration_kind = declaration_kind;

		if (initial) {
			this.assignments.push({ value: /** @type {Expression} */ (initial), scope });
		}
	}

	get updated() {

Domain

Frequently Asked Questions

What is the Binding class?
Binding is a class in the svelte codebase, defined in packages/svelte/src/compiler/phases/scope.js.
Where is Binding defined?
Binding is defined in packages/svelte/src/compiler/phases/scope.js at line 88.

Analyze Your Own Codebase

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

Try Supermodel Free