Home / File/ utils.js — svelte Source File

utils.js — svelte Source File

Architecture documentation for utils.js, a javascript file in the svelte codebase. 11 imports, 8 dependents.

File javascript Compiler Transformer 11 imports 8 dependents 6 functions

Entity Profile

Dependency Diagram

graph LR
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3["utils.js"]
  ce051dbd_4cf1_f117_d66e_12cfa122de37["patterns.js"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> ce051dbd_4cf1_f117_d66e_12cfa122de37
  495501a4_a342_6a4d_ac11_e3e2fee8b218["errors.js"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> 495501a4_a342_6a4d_ac11_e3e2fee8b218
  a146f6ac_0088_8736_b6ce_318f9f115170["e"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> a146f6ac_0088_8736_b6ce_318f9f115170
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  c12e0147_3f27_cf17_5878_e54ffdc328d5["extract_identifiers"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> c12e0147_3f27_cf17_5878_e54ffdc328d5
  0033223e_723b_4eb4_cdb3_607c6df9a36c["check_graph_for_cycles.js"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> 0033223e_723b_4eb4_cdb3_607c6df9a36c
  d733cb1e_c294_8865_008a_cc79d441b336["check_graph_for_cycles"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> d733cb1e_c294_8865_008a_cc79d441b336
  ee93d8a6_6fde_b1c1_e15b_3a4da5326305["scope.js"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> ee93d8a6_6fde_b1c1_e15b_3a4da5326305
  2547d399_bd9b_8247_cde9_c6dc011a96ec["set_scope"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> 2547d399_bd9b_8247_cde9_c6dc011a96ec
  c49ac9f8_b355_57a2_8d10_b5fd945c6144["zimmerframe"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> c49ac9f8_b355_57a2_8d10_b5fd945c6144
  b932d26b_ff92_1d3f_5809_ff63edbef8d1["is-reference"]
  f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> b932d26b_ff92_1d3f_5809_ff63edbef8d1
  c195d127_ca65_6260_2e2d_70c2cc9b25f5["CallExpression.js"]
  c195d127_ca65_6260_2e2d_70c2cc9b25f5 --> f3fad5a9_6b91_ed4f_9331_7f9fc18491c3
  96f4a58f_3498_1ea2_7ff9_3d805414893b["Fragment.js"]
  96f4a58f_3498_1ea2_7ff9_3d805414893b --> f3fad5a9_6b91_ed4f_9331_7f9fc18491c3
  4610488f_3cf2_5f73_043e_da0aa9d026fe["RegularElement.js"]
  4610488f_3cf2_5f73_043e_da0aa9d026fe --> f3fad5a9_6b91_ed4f_9331_7f9fc18491c3
  style f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { TransformState } from './types.js' */
/** @import { AST, Binding, Namespace, ValidatedCompileOptions } from '#compiler' */
/** @import { Node, Expression, CallExpression, MemberExpression } from 'estree' */
import {
	regex_ends_with_whitespaces,
	regex_not_whitespace,
	regex_starts_with_whitespaces
} from '../patterns.js';
import * as e from '../../errors.js';
import { walk } from 'zimmerframe';
import { extract_identifiers } from '../../utils/ast.js';
import check_graph_for_cycles from '../2-analyze/utils/check_graph_for_cycles.js';
import is_reference from 'is-reference';
import { set_scope } from '../scope.js';

/**
 * Match Svelte 4 behaviour by sorting ConstTag nodes in topological order
 * @param {AST.SvelteNode[]} nodes
 * @param {TransformState} state
 */
function sort_const_tags(nodes, state) {
	/**
	 * @typedef {{
	 *   node: AST.ConstTag;
	 *   deps: Set<Binding>;
	 * }} Tag
	 */

	const other = [];

	/** @type {Map<Binding, Tag>} */
	const tags = new Map();

	for (const node of nodes) {
		if (node.type === 'ConstTag') {
			const declaration = node.declaration.declarations[0];

			const bindings = extract_identifiers(declaration.id).map((id) => {
				return /** @type {Binding} */ (state.scope.get(id.name));
			});

			/** @type {Set<Binding>} */
			const deps = new Set();

			walk(declaration.init, state, {
				// @ts-expect-error don't know, don't care
				_: set_scope,
				Identifier(node, context) {
					const parent = /** @type {Expression} */ (context.path.at(-1));

					if (is_reference(node, parent)) {
						const binding = context.state.scope.get(node.name);
						if (binding) deps.add(binding);
					}
				}
			});

			for (const binding of bindings) {
				tags.set(binding, { node, deps });
			}
// ... (392 more lines)

Domain

Subdomains

Frequently Asked Questions

What does utils.js do?
utils.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 utils.js?
utils.js defines 6 function(s): check_nodes_for_namespace, clean_nodes, determine_namespace_for_children, get_inspect_args, infer_namespace, sort_const_tags.
What does utils.js depend on?
utils.js imports 11 module(s): ast.js, check_graph_for_cycles, check_graph_for_cycles.js, e, errors.js, extract_identifiers, is-reference, patterns.js, and 3 more.
What files import utils.js?
utils.js is imported by 8 file(s): CallExpression.js, CallExpression.js, Fragment.js, Fragment.js, RegularElement.js, RegularElement.js, SvelteElement.js, SvelteElement.js.
Where is utils.js in the architecture?
utils.js is located at packages/svelte/src/compiler/phases/3-transform/utils.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform).

Analyze Your Own Codebase

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

Try Supermodel Free