VariableDeclarator() — svelte Function Reference
Architecture documentation for the VariableDeclarator() function in VariableDeclarator.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 533f6c0a_5a99_4a6e_a54c_59fc0c845257["VariableDeclarator()"] 416fa746_6fc6_acf1_278b_bc8492cd9d83["VariableDeclarator.js"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|defined in| 416fa746_6fc6_acf1_278b_bc8492cd9d83 e45d09f8_7efb_bb2f_2b44_5d4db81a3bbe["ensure_no_module_import_conflict()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| e45d09f8_7efb_bb2f_2b44_5d4db81a3bbe bed91719_d047_2256_e199_ee875d5f49b9["get_rune()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| bed91719_d047_2256_e199_ee875d5f49b9 c254e734_2224_c309_f1f8_bb064e80b1af["extract_paths()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| c254e734_2224_c309_f1f8_bb064e80b1af 962a9e38_f393_8bb8_8642_fd23c4e768e6["validate_identifier_name()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| 962a9e38_f393_8bb8_8642_fd23c4e768e6 627dc2f8_4dbc_5bb1_8f54_cee503e17098["get()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| 627dc2f8_4dbc_5bb1_8f54_cee503e17098 5d96a738_e09b_3281_0901_433d3ea634b6["toString()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| 5d96a738_e09b_3281_0901_433d3ea634b6 106b5085_0bf8_d3d4_7000_b137b0fca0bb["props_invalid_identifier()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| 106b5085_0bf8_d3d4_7000_b137b0fca0bb a82fa95e_e0e4_d369_e0df_a6d12caf8c6a["custom_element_props_identifier()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| a82fa95e_e0e4_d369_e0df_a6d12caf8c6a 17a51b6e_dd74_015b_3476_a8f3087eb989["equal()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| 17a51b6e_dd74_015b_3476_a8f3087eb989 218dca00_61c6_f2d7_79a5_c0291e0fb4cd["props_invalid_pattern()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| 218dca00_61c6_f2d7_79a5_c0291e0fb4cd a3108763_2a7f_e4fb_4142_4698524040b1["props_illegal_name()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| a3108763_2a7f_e4fb_4142_4698524040b1 e56bf3cc_e3c2_36a9_6ad9_2935cafefde9["rune_invalid_usage()"] 533f6c0a_5a99_4a6e_a54c_59fc0c845257 -->|calls| e56bf3cc_e3c2_36a9_6ad9_2935cafefde9 style 533f6c0a_5a99_4a6e_a54c_59fc0c845257 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/2-analyze/visitors/VariableDeclarator.js lines 16–160
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());
}
(binding.metadata ??= {}).exclude_props = exclude_props;
}
}
}
if (rune === '$props') {
if (node.id.type !== 'ObjectPattern' && node.id.type !== 'Identifier') {
e.props_invalid_identifier(node);
}
if (
context.state.analysis.custom_element &&
context.state.options.customElementOptions?.props == null
) {
let warn_on;
if (
node.id.type === 'Identifier' ||
(warn_on = node.id.properties.find((p) => p.type === 'RestElement')) != null
) {
w.custom_element_props_identifier(warn_on ?? node.id);
}
}
context.state.analysis.needs_props = true;
if (node.id.type === 'Identifier') {
const binding = /** @type {Binding} */ (context.state.scope.get(node.id.name));
binding.initial = null; // else would be $props()
binding.kind = 'rest_prop';
} else {
equal(node.id.type, 'ObjectPattern');
for (const property of node.id.properties) {
if (property.type !== 'Property') continue;
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does VariableDeclarator() do?
VariableDeclarator() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/visitors/VariableDeclarator.js.
Where is VariableDeclarator() defined?
VariableDeclarator() is defined in packages/svelte/src/compiler/phases/2-analyze/visitors/VariableDeclarator.js at line 16.
What does VariableDeclarator() call?
VariableDeclarator() calls 12 function(s): custom_element_props_identifier, ensure_no_module_import_conflict, equal, extract_paths, get, get_rune, props_illegal_name, props_invalid_identifier, and 4 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free