Home / Function/ ConstTag() — svelte Function Reference

ConstTag() — svelte Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  31ca148e_9353_47ad_f19c_73d06108cdb2["ConstTag()"]
  6343c694_bfb4_d6ba_184c_236382766928["ConstTag.js"]
  31ca148e_9353_47ad_f19c_73d06108cdb2 -->|defined in| 6343c694_bfb4_d6ba_184c_236382766928
  c12e0147_3f27_cf17_5878_e54ffdc328d5["extract_identifiers()"]
  31ca148e_9353_47ad_f19c_73d06108cdb2 -->|calls| c12e0147_3f27_cf17_5878_e54ffdc328d5
  style 31ca148e_9353_47ad_f19c_73d06108cdb2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

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

export function ConstTag(node, context) {
	const declaration = node.declaration.declarations[0];
	const id = /** @type {Pattern} */ (context.visit(declaration.id));
	const init = /** @type {Expression} */ (context.visit(declaration.init));
	const has_await = node.metadata.expression.has_await;
	const blockers = [...node.metadata.expression.dependencies]
		.map((dep) => dep.blocker)
		.filter((b) => b !== null && b.object !== context.state.async_consts?.id);

	if (has_await || context.state.async_consts || blockers.length > 0) {
		const run = (context.state.async_consts ??= {
			id: b.id(context.state.scope.generate('promises')),
			thunks: []
		});

		const identifiers = extract_identifiers(declaration.id);
		const bindings = context.state.scope.get_bindings(declaration);

		for (const identifier of identifiers) {
			context.state.init.push(b.let(identifier.name));
		}

		if (blockers.length === 1) {
			run.thunks.push(b.thunk(/** @type {Expression} */ (blockers[0])));
		} else if (blockers.length > 0) {
			run.thunks.push(b.thunk(b.call('Promise.all', b.array(blockers))));
		}

		const assignment = b.assignment('=', id, init);
		run.thunks.push(b.thunk(b.block([b.stmt(assignment)]), has_await));

		const blocker = b.member(run.id, b.literal(run.thunks.length - 1), true);
		for (const binding of bindings) {
			binding.blocker = blocker;
		}
	} else {
		context.state.init.push(b.const(id, init));
	}
}

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free