VariableDeclarator.js — svelte Source File
Architecture documentation for VariableDeclarator.js, a javascript file in the svelte codebase. 14 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 416fa746_6fc6_acf1_278b_bc8492cd9d83["VariableDeclarator.js"] ee93d8a6_6fde_b1c1_e15b_3a4da5326305["scope.js"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> ee93d8a6_6fde_b1c1_e15b_3a4da5326305 bed91719_d047_2256_e199_ee875d5f49b9["get_rune"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> bed91719_d047_2256_e199_ee875d5f49b9 bf0d8f1b_17da_970d_bf44_fbcf099d5371["utils.js"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> bf0d8f1b_17da_970d_bf44_fbcf099d5371 e45d09f8_7efb_bb2f_2b44_5d4db81a3bbe["ensure_no_module_import_conflict"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> e45d09f8_7efb_bb2f_2b44_5d4db81a3bbe 962a9e38_f393_8bb8_8642_fd23c4e768e6["validate_identifier_name"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> 962a9e38_f393_8bb8_8642_fd23c4e768e6 495501a4_a342_6a4d_ac11_e3e2fee8b218["errors.js"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> 495501a4_a342_6a4d_ac11_e3e2fee8b218 a146f6ac_0088_8736_b6ce_318f9f115170["e"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> a146f6ac_0088_8736_b6ce_318f9f115170 56a689f9_11c0_cc76_bd60_41bb6dc96475["warnings.js"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> 56a689f9_11c0_cc76_bd60_41bb6dc96475 3246e0bc_b9fc_f638_5e35_41e8c39a2408["w"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> 3246e0bc_b9fc_f638_5e35_41e8c39a2408 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c c254e734_2224_c309_f1f8_bb064e80b1af["extract_paths"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> c254e734_2224_c309_f1f8_bb064e80b1af d1e506f3_176e_9858_77c8_809e5b1d3b25["assert.js"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> d1e506f3_176e_9858_77c8_809e5b1d3b25 17a51b6e_dd74_015b_3476_a8f3087eb989["equal"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> 17a51b6e_dd74_015b_3476_a8f3087eb989 95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"] 416fa746_6fc6_acf1_278b_bc8492cd9d83 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc style 416fa746_6fc6_acf1_278b_bc8492cd9d83 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/** @import { Expression, Identifier, Literal, VariableDeclarator } from 'estree' */
/** @import { Binding } from '#compiler' */
/** @import { Context } from '../types' */
import { get_rune } from '../../scope.js';
import { ensure_no_module_import_conflict, validate_identifier_name } from './shared/utils.js';
import * as e from '../../../errors.js';
import * as w from '../../../warnings.js';
import { extract_paths } from '../../../utils/ast.js';
import { equal } from '../../../utils/assert.js';
import * as b from '#compiler/builders';
/**
* @param {VariableDeclarator} node
* @param {Context} context
*/
export function VariableDeclarator(node, context) {
ensure_no_module_import_conflict(node, context.state);
if (context.state.analysis.runes) {
const init = node.init;
const rune = get_rune(init, context.state.scope);
const { paths } = extract_paths(node.id, b.id('dummy'));
for (const path of paths) {
validate_identifier_name(context.state.scope.get(/** @type {Identifier} */ (path.node).name));
}
// TODO feels like this should happen during scope creation?
if (
rune === '$state' ||
rune === '$state.raw' ||
rune === '$derived' ||
rune === '$derived.by' ||
rune === '$props'
) {
for (const path of paths) {
// @ts-ignore this fails in CI for some insane reason
const binding = /** @type {Binding} */ (context.state.scope.get(path.node.name));
binding.kind =
rune === '$state'
? 'state'
: rune === '$state.raw'
? 'raw_state'
: rune === '$derived' || rune === '$derived.by'
? 'derived'
: path.is_rest
? 'rest_prop'
: 'prop';
if (rune === '$props' && binding.kind === 'rest_prop' && node.id.type === 'ObjectPattern') {
const { properties } = node.id;
/** @type {string[]} */
const exclude_props = [];
for (const property of properties) {
if (property.type === 'RestElement') {
continue;
}
const key = /** @type {Identifier | Literal & { value: string | number }} */ (
property.key
);
exclude_props.push(key.type === 'Identifier' ? key.name : key.value.toString());
// ... (101 more lines)
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does VariableDeclarator.js do?
VariableDeclarator.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 VariableDeclarator.js?
VariableDeclarator.js defines 1 function(s): VariableDeclarator.
What does VariableDeclarator.js depend on?
VariableDeclarator.js imports 14 module(s): assert.js, ast.js, builders, e, ensure_no_module_import_conflict, equal, errors.js, extract_paths, and 6 more.
What files import VariableDeclarator.js?
VariableDeclarator.js is imported by 1 file(s): index.js.
Where is VariableDeclarator.js in the architecture?
VariableDeclarator.js is located at packages/svelte/src/compiler/phases/2-analyze/visitors/VariableDeclarator.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/2-analyze/visitors).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free