Home / File/ utils.js — svelte Source File

utils.js — svelte Source File

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

File javascript Compiler Transformer 5 imports 14 dependents 6 functions

Entity Profile

Dependency Diagram

graph LR
  c518b20b_2355_7b11_4ac2_2d9bb5dcfb43["utils.js"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  c518b20b_2355_7b11_4ac2_2d9bb5dcfb43 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  0eb6598b_73c2_c88f_86a0_12cef2210ad8["is_simple_expression"]
  c518b20b_2355_7b11_4ac2_2d9bb5dcfb43 --> 0eb6598b_73c2_c88f_86a0_12cef2210ad8
  a5d434ec_3ca3_7fe0_cea3_58f60f017b7b["save"]
  c518b20b_2355_7b11_4ac2_2d9bb5dcfb43 --> a5d434ec_3ca3_7fe0_cea3_58f60f017b7b
  73865c3c_2786_c9ac_d34f_b51d28b3a29e["constants.js"]
  c518b20b_2355_7b11_4ac2_2d9bb5dcfb43 --> 73865c3c_2786_c9ac_d34f_b51d28b3a29e
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  c518b20b_2355_7b11_4ac2_2d9bb5dcfb43 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  dbcd64ee_7333_aa92_9b8e_ed189c6c4449["Identifier.js"]
  dbcd64ee_7333_aa92_9b8e_ed189c6c4449 --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  7665e008_f37d_b860_a594_f2539a66af4e["transform-client.js"]
  7665e008_f37d_b860_a594_f2539a66af4e --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  96ee438d_6c6f_9aff_59f4_d00e63e9d98c["AssignmentExpression.js"]
  96ee438d_6c6f_9aff_59f4_d00e63e9d98c --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  844ad472_83ed_856d_0120_d6773152f6bb["AwaitBlock.js"]
  844ad472_83ed_856d_0120_d6773152f6bb --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  c195d127_ca65_6260_2e2d_70c2cc9b25f5["CallExpression.js"]
  c195d127_ca65_6260_2e2d_70c2cc9b25f5 --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  c2ea7651_b458_9fe9_2c66_78f1a5171027["ConstTag.js"]
  c2ea7651_b458_9fe9_2c66_78f1a5171027 --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  ca0f0f27_a1ac_e3ec_cf1e_8b4bde24834b["Identifier.js"]
  ca0f0f27_a1ac_e3ec_cf1e_8b4bde24834b --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  c1192f7f_6f47_cc18_0b15_11659cccaf8d["LabeledStatement.js"]
  c1192f7f_6f47_cc18_0b15_11659cccaf8d --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  6db00b99_6c00_8c37_49e7_072e5c55ca92["LetDirective.js"]
  6db00b99_6c00_8c37_49e7_072e5c55ca92 --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  style c518b20b_2355_7b11_4ac2_2d9bb5dcfb43 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { BlockStatement, Expression, Identifier } from 'estree' */
/** @import { Binding } from '#compiler' */
/** @import { ClientTransformState, ComponentClientTransformState } from './types.js' */
/** @import { Analysis } from '../../types.js' */
/** @import { Scope } from '../../scope.js' */
import * as b from '#compiler/builders';
import { is_simple_expression, save } from '../../../utils/ast.js';
import {
	PROPS_IS_LAZY_INITIAL,
	PROPS_IS_IMMUTABLE,
	PROPS_IS_RUNES,
	PROPS_IS_UPDATED,
	PROPS_IS_BINDABLE
} from '../../../../constants.js';

/**
 * @param {Binding} binding
 * @param {Analysis} analysis
 * @returns {boolean}
 */
export function is_state_source(binding, analysis) {
	return (
		(binding.kind === 'state' || binding.kind === 'raw_state') &&
		(!analysis.immutable || binding.reassigned || analysis.accessors)
	);
}

/**
 * @param {Identifier} node
 * @param {ClientTransformState} state
 * @returns {Expression}
 */
export function build_getter(node, state) {
	if (Object.hasOwn(state.transform, node.name)) {
		const binding = state.scope.get(node.name);

		// don't transform the declaration itself
		if (node !== binding?.node) {
			return state.transform[node.name].read(node);
		}
	}

	return node;
}

/**
 * @param {Binding} binding
 * @param {ComponentClientTransformState} state
 * @param {string} name
 * @param {Expression | null} [initial]
 * @returns
 */
export function get_prop_source(binding, state, name, initial) {
	/** @type {Expression[]} */
	const args = [b.id('$$props'), b.literal(name)];

	let flags = 0;

	if (binding.kind === 'bindable_prop') {
		flags |= PROPS_IS_BINDABLE;
// ... (122 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): build_getter, create_derived, get_prop_source, is_prop_source, is_state_source, should_proxy.
What does utils.js depend on?
utils.js imports 5 module(s): ast.js, builders, constants.js, is_simple_expression, save.
What files import utils.js?
utils.js is imported by 14 file(s): AssignmentExpression.js, AwaitBlock.js, CallExpression.js, ConstTag.js, Identifier.js, Identifier.js, LabeledStatement.js, LetDirective.js, and 6 more.
Where is utils.js in the architecture?
utils.js is located at packages/svelte/src/compiler/phases/3-transform/client/utils.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/client).

Analyze Your Own Codebase

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

Try Supermodel Free