Home / File/ Program.js — svelte Source File

Program.js — svelte Source File

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

File javascript Compiler Transformer 8 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  446a5632_54bb_cf7e_dbdc_33bec913df9e["Program.js"]
  c518b20b_2355_7b11_4ac2_2d9bb5dcfb43["utils.js"]
  446a5632_54bb_cf7e_dbdc_33bec913df9e --> c518b20b_2355_7b11_4ac2_2d9bb5dcfb43
  27fded45_bc11_247b_d3fe_94831379f9ed["build_getter"]
  446a5632_54bb_cf7e_dbdc_33bec913df9e --> 27fded45_bc11_247b_d3fe_94831379f9ed
  5f828ae1_5f83_74a8_876a_ea54ea47b588["is_prop_source"]
  446a5632_54bb_cf7e_dbdc_33bec913df9e --> 5f828ae1_5f83_74a8_876a_ea54ea47b588
  1a53d630_ca18_6783_bd92_8c72517a9306["declarations.js"]
  446a5632_54bb_cf7e_dbdc_33bec913df9e --> 1a53d630_ca18_6783_bd92_8c72517a9306
  fb41e547_07c8_cc9a_e227_3f08aad6d1f5["add_state_transformers"]
  446a5632_54bb_cf7e_dbdc_33bec913df9e --> fb41e547_07c8_cc9a_e227_3f08aad6d1f5
  4a72fe76_77b1_749a_ab61_f53e30c4916a["transform-async.js"]
  446a5632_54bb_cf7e_dbdc_33bec913df9e --> 4a72fe76_77b1_749a_ab61_f53e30c4916a
  6edb6f5e_a923_c9d9_63cc_ebec53916480["transform_body"]
  446a5632_54bb_cf7e_dbdc_33bec913df9e --> 6edb6f5e_a923_c9d9_63cc_ebec53916480
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  446a5632_54bb_cf7e_dbdc_33bec913df9e --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  7665e008_f37d_b860_a594_f2539a66af4e["transform-client.js"]
  7665e008_f37d_b860_a594_f2539a66af4e --> 446a5632_54bb_cf7e_dbdc_33bec913df9e
  style 446a5632_54bb_cf7e_dbdc_33bec913df9e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Expression, ImportDeclaration, MemberExpression, Node, Program } from 'estree' */
/** @import { ComponentContext } from '../types' */
import { build_getter, is_prop_source } from '../utils.js';
import * as b from '#compiler/builders';
import { add_state_transformers } from './shared/declarations.js';
import { transform_body } from '../../shared/transform-async.js';

/**
 * @param {Program} node
 * @param {ComponentContext} context
 */
export function Program(node, context) {
	if (!context.state.analysis.runes) {
		context.state.transform['$$props'] = {
			read: (node) => ({ ...node, name: '$$sanitized_props' })
		};

		for (const [name, binding] of context.state.scope.declarations) {
			if (binding.declaration_kind === 'import' && binding.mutated) {
				// the declaration itself is hoisted to the module scope, so we need
				// to resort to cruder measures to differentiate instance/module imports
				const { start, end } = context.state.analysis.instance.ast;
				const node = /** @type {ImportDeclaration} */ (binding.initial);
				const is_instance_import =
					/** @type {number} */ (node.start) > /** @type {number} */ (start) &&
					/** @type {number} */ (node.end) < /** @type {number} */ (end);

				if (is_instance_import) {
					const id = b.id('$$_import_' + name);

					context.state.transform[name] = {
						read: (_) => b.call(id),
						mutate: (_, mutation) => b.call(id, mutation)
					};

					context.state.legacy_reactive_imports.push(
						b.var(id, b.call('$.reactive_import', b.thunk(b.id(name))))
					);
				}
			}
		}
	}

	for (const [name, binding] of context.state.scope.declarations) {
		if (binding.kind === 'store_sub') {
			// read lazily, so that transforms added later are still applied
			/** @type {Expression} */
			let cached;

			const get_store = () => {
				return (cached ??= /** @type {Expression} */ (context.visit(b.id(name.slice(1)))));
			};

			context.state.transform[name] = {
				read: b.call,
				assign: (_, value) => b.call('$.store_set', get_store(), value),
				mutate: (node, mutation) => {
					// We need to untrack the store read, for consistency with Svelte 4
					const untracked = b.call('$.untrack', node);

// ... (94 more lines)

Domain

Subdomains

Functions

Frequently Asked Questions

What does Program.js do?
Program.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 Program.js?
Program.js defines 1 function(s): Program.
What does Program.js depend on?
Program.js imports 8 module(s): add_state_transformers, build_getter, builders, declarations.js, is_prop_source, transform-async.js, transform_body, utils.js.
What files import Program.js?
Program.js is imported by 1 file(s): transform-client.js.
Where is Program.js in the architecture?
Program.js is located at packages/svelte/src/compiler/phases/3-transform/client/visitors/Program.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/client/visitors).

Analyze Your Own Codebase

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

Try Supermodel Free