Home / File/ ConstTag.js — svelte Source File

ConstTag.js — svelte Source File

Architecture documentation for ConstTag.js, a javascript file in the svelte codebase. 3 imports, 1 dependents.

File javascript Compiler Transformer 3 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  6343c694_bfb4_d6ba_184c_236382766928["ConstTag.js"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  6343c694_bfb4_d6ba_184c_236382766928 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  c12e0147_3f27_cf17_5878_e54ffdc328d5["extract_identifiers"]
  6343c694_bfb4_d6ba_184c_236382766928 --> c12e0147_3f27_cf17_5878_e54ffdc328d5
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  6343c694_bfb4_d6ba_184c_236382766928 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  86cf8685_38fa_3a1c_9b81_21c452968289["transform-server.js"]
  86cf8685_38fa_3a1c_9b81_21c452968289 --> 6343c694_bfb4_d6ba_184c_236382766928
  style 6343c694_bfb4_d6ba_184c_236382766928 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Expression, Pattern } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types.js' */
import * as b from '#compiler/builders';
import { extract_identifiers } from '../../../../utils/ast.js';

/**
 * @param {AST.ConstTag} node
 * @param {ComponentContext} context
 */
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

Functions

Dependencies

Frequently Asked Questions

What does ConstTag.js do?
ConstTag.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in ConstTag.js?
ConstTag.js defines 1 function(s): ConstTag.
What does ConstTag.js depend on?
ConstTag.js imports 3 module(s): ast.js, builders, extract_identifiers.
What files import ConstTag.js?
ConstTag.js is imported by 1 file(s): transform-server.js.
Where is ConstTag.js in the architecture?
ConstTag.js is located at packages/svelte/src/compiler/phases/3-transform/server/visitors/ConstTag.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/server/visitors).

Analyze Your Own Codebase

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

Try Supermodel Free