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
  b419b46d_0943_3478_0109_3494c3daad24["ConstTag()"]
  a66fc5da_2bb3_93a3_20d8_c2990acb1c31["ConstTag.js"]
  b419b46d_0943_3478_0109_3494c3daad24 -->|defined in| a66fc5da_2bb3_93a3_20d8_c2990acb1c31
  7148e639_69d8_a03d_3f08_bd23f41e718a["validate_opening_tag()"]
  b419b46d_0943_3478_0109_3494c3daad24 -->|calls| 7148e639_69d8_a03d_3f08_bd23f41e718a
  d753eb7e_aed3_1328_b2a0_12637c458a7d["const_tag_invalid_placement()"]
  b419b46d_0943_3478_0109_3494c3daad24 -->|calls| d753eb7e_aed3_1328_b2a0_12637c458a7d
  style b419b46d_0943_3478_0109_3494c3daad24 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/2-analyze/visitors/ConstTag.js lines 10–45

export function ConstTag(node, context) {
	if (context.state.analysis.runes) {
		validate_opening_tag(node, context.state, '@');
	}

	const parent = context.path.at(-1);
	const grand_parent = context.path.at(-2);

	if (
		parent?.type !== 'Fragment' ||
		(grand_parent?.type !== 'IfBlock' &&
			grand_parent?.type !== 'SvelteFragment' &&
			grand_parent?.type !== 'Component' &&
			grand_parent?.type !== 'SvelteComponent' &&
			grand_parent?.type !== 'EachBlock' &&
			grand_parent?.type !== 'AwaitBlock' &&
			grand_parent?.type !== 'SnippetBlock' &&
			grand_parent?.type !== 'SvelteBoundary' &&
			grand_parent?.type !== 'KeyBlock' &&
			((grand_parent?.type !== 'RegularElement' && grand_parent?.type !== 'SvelteElement') ||
				!grand_parent.attributes.some((a) => a.type === 'Attribute' && a.name === 'slot')))
	) {
		e.const_tag_invalid_placement(node);
	}

	const declaration = node.declaration.declarations[0];

	context.visit(declaration.id);
	context.visit(declaration.init, {
		...context.state,
		expression: node.metadata.expression,
		// We're treating this like a $derived under the hood
		function_depth: context.state.function_depth + 1,
		derived_function_depth: context.state.function_depth + 1
	});
}

Domain

Subdomains

Frequently Asked Questions

What does ConstTag() do?
ConstTag() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/visitors/ConstTag.js.
Where is ConstTag() defined?
ConstTag() is defined in packages/svelte/src/compiler/phases/2-analyze/visitors/ConstTag.js at line 10.
What does ConstTag() call?
ConstTag() calls 2 function(s): const_tag_invalid_placement, validate_opening_tag.

Analyze Your Own Codebase

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

Try Supermodel Free