Home / Class/ ExpressionMetadata Class — svelte Architecture

ExpressionMetadata Class — svelte Architecture

Architecture documentation for the ExpressionMetadata class in nodes.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  6e00a8f3_2371_ecf1_5a93_296f787aca83["ExpressionMetadata"]
  bbca3d2a_42c8_b215_d3b5_5077ccaf0797["nodes.js"]
  6e00a8f3_2371_ecf1_5a93_296f787aca83 -->|defined in| bbca3d2a_42c8_b215_d3b5_5077ccaf0797
  784480d0_767d_ac40_b03e_ae8ddcc82684["Set()"]
  6e00a8f3_2371_ecf1_5a93_296f787aca83 -->|method| 784480d0_767d_ac40_b03e_ae8ddcc82684
  c116ef6a_6001_a2a2_8f2b_e5eb756c65ac["blockers()"]
  6e00a8f3_2371_ecf1_5a93_296f787aca83 -->|method| c116ef6a_6001_a2a2_8f2b_e5eb756c65ac
  13e926d4_7098_edcb_143e_3e3e944df9b6["has_blockers()"]
  6e00a8f3_2371_ecf1_5a93_296f787aca83 -->|method| 13e926d4_7098_edcb_143e_3e3e944df9b6
  4c31ebdd_a0b5_39e1_46c7_943aeeefb373["has_more_blockers_than()"]
  6e00a8f3_2371_ecf1_5a93_296f787aca83 -->|method| 4c31ebdd_a0b5_39e1_46c7_943aeeefb373
  3b2a4fcc_2df2_7057_21b4_4cac59b8df61["is_async()"]
  6e00a8f3_2371_ecf1_5a93_296f787aca83 -->|method| 3b2a4fcc_2df2_7057_21b4_4cac59b8df61
  23cf92f5_03a7_f07d_fe6f_d5ac1659d37e["merge()"]
  6e00a8f3_2371_ecf1_5a93_296f787aca83 -->|method| 23cf92f5_03a7_f07d_fe6f_d5ac1659d37e

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/nodes.js lines 70–152

export class ExpressionMetadata {
	/** True if the expression references state directly, or _might_ (via member/call expressions) */
	has_state = false;

	/** True if the expression involves a call expression (often, it will need to be wrapped in a derived) */
	has_call = false;

	/** True if the expression contains `await` */
	has_await = false;

	/** True if the expression includes a member expression */
	has_member_expression = false;

	/** True if the expression includes an assignment or an update */
	has_assignment = false;

	/**
	 * All the bindings that are referenced eagerly (not inside functions) in this expression
	 * @type {Set<Binding>}
	 */
	dependencies = new Set();

	/**
	 * True if the expression references state directly, or _might_ (via member/call expressions)
	 * @type {Set<Binding>}
	 */
	references = new Set();

	/** @type {null | Set<Expression>} */
	#blockers = null;

	#get_blockers() {
		if (!this.#blockers) {
			this.#blockers = new Set();

			for (const d of this.dependencies) {
				if (d.blocker) this.#blockers.add(d.blocker);
			}
		}

		return this.#blockers;
	}

	blockers() {
		return b.array([...this.#get_blockers()]);
	}

	has_blockers() {
		return this.#get_blockers().size > 0;
	}

	/**
	 * @param {ExpressionMetadata} other
	 */
	has_more_blockers_than(other) {
		for (const blocker of this.#get_blockers()) {
			if (!other.#get_blockers().has(blocker)) {
				return true;
			}
		}

		return false;
	}

	is_async() {
		return this.has_await || this.#get_blockers().size > 0;
	}

	/**
	 * @param {ExpressionMetadata} source
	 */
	merge(source) {
		this.has_state ||= source.has_state;
		this.has_call ||= source.has_call;
		this.has_await ||= source.has_await;
		this.has_member_expression ||= source.has_member_expression;
		this.has_assignment ||= source.has_assignment;
		this.#blockers = null; // so that blockers are recalculated

		for (const r of source.references) this.references.add(r);
		for (const b of source.dependencies) this.dependencies.add(b);

Domain

Frequently Asked Questions

What is the ExpressionMetadata class?
ExpressionMetadata is a class in the svelte codebase, defined in packages/svelte/src/compiler/phases/nodes.js.
Where is ExpressionMetadata defined?
ExpressionMetadata is defined in packages/svelte/src/compiler/phases/nodes.js at line 70.

Analyze Your Own Codebase

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

Try Supermodel Free