Home / Function/ UseDirective() — svelte Function Reference

UseDirective() — svelte Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  1d716a14_4437_0640_cce9_a92e17d6c8bb["UseDirective()"]
  64c70f73_5fcd_e4b8_935a_4ee4b4a90441["UseDirective.js"]
  1d716a14_4437_0640_cce9_a92e17d6c8bb -->|defined in| 64c70f73_5fcd_e4b8_935a_4ee4b4a90441
  adc3771e_5aef_eddf_fcf6_46eb2c97455a["parse_directive_name()"]
  1d716a14_4437_0640_cce9_a92e17d6c8bb -->|calls| adc3771e_5aef_eddf_fcf6_46eb2c97455a
  c8d80c9d_ab6c_13c0_c85e_a9b120f82f45["blockers()"]
  1d716a14_4437_0640_cce9_a92e17d6c8bb -->|calls| c8d80c9d_ab6c_13c0_c85e_a9b120f82f45
  style 1d716a14_4437_0640_cce9_a92e17d6c8bb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

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

export function UseDirective(node, context) {
	const params = [b.id('$$node')];

	if (node.expression) {
		params.push(b.id('$$action_arg'));
	}

	/** @type {Expression[]} */
	const args = [
		context.state.node,
		b.arrow(
			params,
			b.maybe_call(
				/** @type {Expression} */ (context.visit(parse_directive_name(node.name))),
				...params
			)
		)
	];

	if (node.expression) {
		args.push(b.thunk(/** @type {Expression} */ (context.visit(node.expression))));
	}

	// actions need to run after attribute updates in order with bindings/events
	let statement = b.stmt(b.call('$.action', ...args));

	if (node.metadata.expression.is_async()) {
		statement = b.stmt(
			b.call(
				'$.run_after_blockers',
				node.metadata.expression.blockers(),
				b.thunk(b.block([statement]))
			)
		);
	}

	context.state.init.push(statement);
	context.next();
}

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free