VariableDeclaration() — svelte Function Reference
Architecture documentation for the VariableDeclaration() function in VariableDeclaration.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD dbadea0c_9bb0_dd96_41bd_09a33169352f["VariableDeclaration()"] 12047c60_7eb9_7476_83e2_7d8004a6f868["VariableDeclaration.js"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|defined in| 12047c60_7eb9_7476_83e2_7d8004a6f868 bed91719_d047_2256_e199_ee875d5f49b9["get_rune()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| bed91719_d047_2256_e199_ee875d5f49b9 17a51b6e_dd74_015b_3476_a8f3087eb989["equal()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| 17a51b6e_dd74_015b_3476_a8f3087eb989 627dc2f8_4dbc_5bb1_8f54_cee503e17098["get()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| 627dc2f8_4dbc_5bb1_8f54_cee503e17098 88db3726_5740_3eb8_99fb_4b297fb19b24["should_proxy()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| 88db3726_5740_3eb8_99fb_4b297fb19b24 5f828ae1_5f83_74a8_876a_ea54ea47b588["is_prop_source()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| 5f828ae1_5f83_74a8_876a_ea54ea47b588 5f0f3809_9fa1_84c1_24be_92d8863f2fb1["get_prop_source()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| 5f0f3809_9fa1_84c1_24be_92d8863f2fb1 03ec0ace_6e52_c362_5e4b_06e8333b938f["is_state_source()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| 03ec0ace_6e52_c362_5e4b_06e8333b938f 8980dd2b_1c7a_2c03_2400_e31c60358534["generate()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| 8980dd2b_1c7a_2c03_2400_e31c60358534 c254e734_2224_c309_f1f8_bb064e80b1af["extract_paths()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| c254e734_2224_c309_f1f8_bb064e80b1af 7a7783f8_ffa6_0cc3_61b0_031882649535["is_ignored()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| 7a7783f8_ffa6_0cc3_61b0_031882649535 bde97aff_493a_f552_a038_3e029fefca90["locate_node()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| bde97aff_493a_f552_a038_3e029fefca90 a5d434ec_3ca3_7fe0_cea3_58f60f017b7b["save()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| a5d434ec_3ca3_7fe0_cea3_58f60f017b7b 620ed390_0877_e37c_0313_1a3448ba6a56["get_bindings()"] dbadea0c_9bb0_dd96_41bd_09a33169352f -->|calls| 620ed390_0877_e37c_0313_1a3448ba6a56 style dbadea0c_9bb0_dd96_41bd_09a33169352f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js lines 16–380
export function VariableDeclaration(node, context) {
/** @type {VariableDeclarator[]} */
const declarations = [];
if (context.state.analysis.runes) {
for (const declarator of node.declarations) {
const init = /** @type {Expression} */ (declarator.init);
const rune = get_rune(init, context.state.scope);
if (
!rune ||
rune === '$effect.tracking' ||
rune === '$effect.root' ||
rune === '$inspect' ||
rune === '$inspect.trace' ||
rune === '$state.snapshot' ||
rune === '$host'
) {
declarations.push(/** @type {VariableDeclarator} */ (context.visit(declarator)));
continue;
}
if (rune === '$props.id') {
// skip
continue;
}
if (rune === '$props') {
/** @type {string[]} */
const seen = ['$$slots', '$$events', '$$legacy'];
if (context.state.analysis.custom_element) {
seen.push('$$host');
}
if (declarator.id.type === 'Identifier') {
/** @type {Expression[]} */
const args = [b.id('$$props'), b.array(seen.map((name) => b.literal(name)))];
if (dev) {
// include rest name, so we can provide informative error messages
args.push(b.literal(declarator.id.name));
}
declarations.push(b.declarator(declarator.id, b.call('$.rest_props', ...args)));
} else {
assert.equal(declarator.id.type, 'ObjectPattern');
for (const property of declarator.id.properties) {
if (property.type === 'Property') {
const key = /** @type {Identifier | Literal} */ (property.key);
const name = key.type === 'Identifier' ? key.name : /** @type {string} */ (key.value);
seen.push(name);
let id =
property.value.type === 'AssignmentPattern' ? property.value.left : property.value;
assert.equal(id.type, 'Identifier');
const binding = /** @type {Binding} */ (context.state.scope.get(id.name));
let initial =
binding.initial && /** @type {Expression} */ (context.visit(binding.initial));
// We're adding proxy here on demand and not within the prop runtime function so that
// people not using proxied state anywhere in their code don't have to pay the additional bundle size cost
if (
initial &&
binding.kind === 'bindable_prop' &&
should_proxy(initial, context.state.scope)
) {
initial = b.call('$.proxy', initial);
if (dev) {
initial = b.call('$.tag_proxy', initial, b.literal(id.name));
}
}
if (is_prop_source(binding, context.state)) {
declarations.push(
b.declarator(id, get_prop_source(binding, context.state, name, initial))
);
}
} else {
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does VariableDeclaration() do?
VariableDeclaration() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js.
Where is VariableDeclaration() defined?
VariableDeclaration() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js at line 16.
What does VariableDeclaration() call?
VariableDeclaration() calls 14 function(s): create_state_declarators, equal, extract_paths, generate, get, get_bindings, get_prop_source, get_rune, and 6 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free