Home / File/ utils.js — svelte Source File

utils.js — svelte Source File

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

File javascript Compiler Transformer 12 imports 21 dependents 9 functions

Entity Profile

Dependency Diagram

graph LR
  bf0d8f1b_17da_970d_bf44_fbcf099d5371["utils.js"]
  495501a4_a342_6a4d_ac11_e3e2fee8b218["errors.js"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> 495501a4_a342_6a4d_ac11_e3e2fee8b218
  a146f6ac_0088_8736_b6ce_318f9f115170["e"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> a146f6ac_0088_8736_b6ce_318f9f115170
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  c12e0147_3f27_cf17_5878_e54ffdc328d5["extract_identifiers"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> c12e0147_3f27_cf17_5878_e54ffdc328d5
  68a38b3b_6f0f_ed43_404f_3d00302677a2["get_parent"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> 68a38b3b_6f0f_ed43_404f_3d00302677a2
  56a689f9_11c0_cc76_bd60_41bb6dc96475["warnings.js"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> 56a689f9_11c0_cc76_bd60_41bb6dc96475
  3246e0bc_b9fc_f638_5e35_41e8c39a2408["w"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> 3246e0bc_b9fc_f638_5e35_41e8c39a2408
  ee93d8a6_6fde_b1c1_e15b_3a4da5326305["scope.js"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> ee93d8a6_6fde_b1c1_e15b_3a4da5326305
  bed91719_d047_2256_e199_ee875d5f49b9["get_rune"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> bed91719_d047_2256_e199_ee875d5f49b9
  bbca3d2a_42c8_b215_d3b5_5077ccaf0797["nodes.js"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> bbca3d2a_42c8_b215_d3b5_5077ccaf0797
  d69a156c_617a_9397_4c8b_e94508c59e30["get_name"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> d69a156c_617a_9397_4c8b_e94508c59e30
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  bf0d8f1b_17da_970d_bf44_fbcf099d5371 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  17a1befc_da6e_74db_4a59_7e1534b65053["AssignmentExpression.js"]
  17a1befc_da6e_74db_4a59_7e1534b65053 --> bf0d8f1b_17da_970d_bf44_fbcf099d5371
  93e88a6f_3f11_4770_b83f_853f9bf1fc2b["AwaitBlock.js"]
  93e88a6f_3f11_4770_b83f_853f9bf1fc2b --> bf0d8f1b_17da_970d_bf44_fbcf099d5371
  style bf0d8f1b_17da_970d_bf44_fbcf099d5371 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { AssignmentExpression, Expression, Literal, Node, Pattern, Super, UpdateExpression, VariableDeclarator } from 'estree' */
/** @import { AST, Binding } from '#compiler' */
/** @import { AnalysisState, Context } from '../../types' */
/** @import { Scope } from '../../../scope' */
/** @import { NodeLike } from '../../../../errors.js' */
import * as e from '../../../../errors.js';
import { extract_identifiers, get_parent } from '../../../../utils/ast.js';
import * as w from '../../../../warnings.js';
import * as b from '#compiler/builders';
import { get_rune } from '../../../scope.js';
import { get_name } from '../../../nodes.js';

/**
 * @param {AssignmentExpression | UpdateExpression | AST.BindDirective} node
 * @param {Pattern | Expression} argument
 * @param {Context} context
 */
export function validate_assignment(node, argument, context) {
	validate_no_const_assignment(node, argument, context.state.scope, node.type === 'BindDirective');

	if (argument.type === 'Identifier') {
		const binding = context.state.scope.get(argument.name);

		if (context.state.analysis.runes) {
			if (
				context.state.analysis.props_id != null &&
				binding?.node === context.state.analysis.props_id
			) {
				e.constant_assignment(node, '$props.id()');
			}

			if (binding?.kind === 'each') {
				e.each_item_invalid_assignment(node);
			}
		}

		if (binding?.kind === 'snippet') {
			e.snippet_parameter_assignment(node);
		}
	}

	if (argument.type === 'MemberExpression' && argument.object.type === 'ThisExpression') {
		const name =
			argument.computed && argument.property.type !== 'Literal'
				? null
				: get_name(argument.property);

		const field = name !== null && context.state.state_fields?.get(name);

		// check we're not assigning to a state field before its declaration in the constructor
		if (field && field.node.type === 'AssignmentExpression' && node !== field.node) {
			let i = context.path.length;
			while (i--) {
				const parent = context.path[i];

				if (
					parent.type === 'FunctionDeclaration' ||
					parent.type === 'FunctionExpression' ||
					parent.type === 'ArrowFunctionExpression'
				) {
// ... (242 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 9 function(s): ensure_no_module_import_conflict, is_pure, is_safe_identifier, validate_assignment, validate_block_not_empty, validate_export, validate_identifier_name, validate_no_const_assignment, validate_opening_tag.
What does utils.js depend on?
utils.js imports 12 module(s): ast.js, builders, e, errors.js, extract_identifiers, get_name, get_parent, get_rune, and 4 more.
What files import utils.js?
utils.js is imported by 21 file(s): AssignmentExpression.js, AwaitBlock.js, BindDirective.js, CallExpression.js, ClassDeclaration.js, ConstTag.js, DebugTag.js, EachBlock.js, and 13 more.
Where is utils.js in the architecture?
utils.js is located at packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/2-analyze/visitors/shared).

Analyze Your Own Codebase

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

Try Supermodel Free