Home / File/ VariableDeclaration.js — svelte Source File

VariableDeclaration.js — svelte Source File

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

File javascript Compiler Transformer 7 imports 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  43cccc92_b6ec_71e7_dbb2_9db18fe66f68["VariableDeclaration.js"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  43cccc92_b6ec_71e7_dbb2_9db18fe66f68 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  84572b9b_9a21_09af_15ac_85b59b114603["build_fallback"]
  43cccc92_b6ec_71e7_dbb2_9db18fe66f68 --> 84572b9b_9a21_09af_15ac_85b59b114603
  c254e734_2224_c309_f1f8_bb064e80b1af["extract_paths"]
  43cccc92_b6ec_71e7_dbb2_9db18fe66f68 --> c254e734_2224_c309_f1f8_bb064e80b1af
  ee93d8a6_6fde_b1c1_e15b_3a4da5326305["scope.js"]
  43cccc92_b6ec_71e7_dbb2_9db18fe66f68 --> ee93d8a6_6fde_b1c1_e15b_3a4da5326305
  bed91719_d047_2256_e199_ee875d5f49b9["get_rune"]
  43cccc92_b6ec_71e7_dbb2_9db18fe66f68 --> bed91719_d047_2256_e199_ee875d5f49b9
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  43cccc92_b6ec_71e7_dbb2_9db18fe66f68 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  c49ac9f8_b355_57a2_8d10_b5fd945c6144["zimmerframe"]
  43cccc92_b6ec_71e7_dbb2_9db18fe66f68 --> c49ac9f8_b355_57a2_8d10_b5fd945c6144
  86cf8685_38fa_3a1c_9b81_21c452968289["transform-server.js"]
  86cf8685_38fa_3a1c_9b81_21c452968289 --> 43cccc92_b6ec_71e7_dbb2_9db18fe66f68
  style 43cccc92_b6ec_71e7_dbb2_9db18fe66f68 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { VariableDeclaration, VariableDeclarator, Expression, CallExpression, Pattern, Identifier } from 'estree' */
/** @import { Binding } from '#compiler' */
/** @import { Context } from '../types.js' */
/** @import { ComponentAnalysis } from '../../../types.js' */
/** @import { Scope } from '../../../scope.js' */
import { build_fallback, extract_paths } from '../../../../utils/ast.js';
import * as b from '#compiler/builders';
import { get_rune } from '../../../scope.js';
import { walk } from 'zimmerframe';

/**
 * @param {VariableDeclaration} node
 * @param {Context} context
 */
export function VariableDeclaration(node, context) {
	/** @type {VariableDeclarator[]} */
	const declarations = [];

	if (context.state.analysis.runes) {
		for (const declarator of node.declarations) {
			const init = declarator.init;
			const rune = get_rune(init, context.state.scope);
			if (!rune || rune === '$effect.tracking' || rune === '$inspect' || rune === '$effect.root') {
				declarations.push(/** @type {VariableDeclarator} */ (context.visit(declarator)));
				continue;
			}

			if (rune === '$props.id') {
				// skip
				continue;
			}

			if (rune === '$props') {
				let has_rest = false;
				// remove $bindable() from props declaration
				let id = walk(declarator.id, null, {
					RestElement(node, context) {
						if (context.path.at(-1) === declarator.id) {
							has_rest = true;
						}
					},
					AssignmentPattern(node) {
						if (
							node.right.type === 'CallExpression' &&
							get_rune(node.right, context.state.scope) === '$bindable'
						) {
							const right = node.right.arguments.length
								? /** @type {Expression} */ (context.visit(node.right.arguments[0]))
								: b.void0;
							return b.assignment_pattern(node.left, right);
						}
					}
				});

				// if `$$slots` is declared separately, deconflict
				const slots_name = /** @type {ComponentAnalysis} */ (context.state.analysis).uses_slots
					? b.id('$$slots_')
					: b.id('$$slots');

				if (id.type === 'ObjectPattern' && has_rest) {
// ... (153 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does VariableDeclaration.js do?
VariableDeclaration.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 VariableDeclaration.js?
VariableDeclaration.js defines 2 function(s): VariableDeclaration, create_state_declarators.
What does VariableDeclaration.js depend on?
VariableDeclaration.js imports 7 module(s): ast.js, build_fallback, builders, extract_paths, get_rune, scope.js, zimmerframe.
What files import VariableDeclaration.js?
VariableDeclaration.js is imported by 1 file(s): transform-server.js.
Where is VariableDeclaration.js in the architecture?
VariableDeclaration.js is located at packages/svelte/src/compiler/phases/3-transform/server/visitors/VariableDeclaration.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