instance_script.VariableDeclaration() — svelte Function Reference
Architecture documentation for the instance_script.VariableDeclaration() function in index.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 8f93b8d1_a873_5c72_eae3_de296245116a["instance_script.VariableDeclaration()"] cab41022_1b55_3b7a_06c6_b90763bbea47["index.js"] 8f93b8d1_a873_5c72_eae3_de296245116a -->|defined in| cab41022_1b55_3b7a_06c6_b90763bbea47 bed91719_d047_2256_e199_ee875d5f49b9["get_rune()"] 8f93b8d1_a873_5c72_eae3_de296245116a -->|calls| bed91719_d047_2256_e199_ee875d5f49b9 620ed390_0877_e37c_0313_1a3448ba6a56["get_bindings()"] 8f93b8d1_a873_5c72_eae3_de296245116a -->|calls| 620ed390_0877_e37c_0313_1a3448ba6a56 8980dd2b_1c7a_2c03_2400_e31c60358534["generate()"] 8f93b8d1_a873_5c72_eae3_de296245116a -->|calls| 8980dd2b_1c7a_2c03_2400_e31c60358534 c254e734_2224_c309_f1f8_bb064e80b1af["extract_paths()"] 8f93b8d1_a873_5c72_eae3_de296245116a -->|calls| c254e734_2224_c309_f1f8_bb064e80b1af 627dc2f8_4dbc_5bb1_8f54_cee503e17098["get()"] 8f93b8d1_a873_5c72_eae3_de296245116a -->|calls| 627dc2f8_4dbc_5bb1_8f54_cee503e17098 01f56d6c_9f35_6b0e_ad0a_fdb401fca3b4["extract_type_and_comment()"] 8f93b8d1_a873_5c72_eae3_de296245116a -->|calls| 01f56d6c_9f35_6b0e_ad0a_fdb401fca3b4 f37fcfdb_9d8e_8c81_7fc8_e49a289d52bc["extract_all_identifiers_from_expression()"] 8f93b8d1_a873_5c72_eae3_de296245116a -->|calls| f37fcfdb_9d8e_8c81_7fc8_e49a289d52bc style 8f93b8d1_a873_5c72_eae3_de296245116a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/migrate/index.js lines 565–915
VariableDeclaration(node, { state, path, visit, next }) {
if (state.scope !== state.analysis.instance.scope) {
return;
}
let nr_of_props = 0;
for (let i = 0; i < node.declarations.length; i++) {
const declarator = node.declarations[i];
if (state.analysis.runes) {
if (get_rune(declarator.init, state.scope) === '$props') {
state.props_insertion_point = /** @type {number} */ (declarator.id.start) + 1;
state.has_props_rune = true;
}
continue;
}
let bindings;
try {
bindings = state.scope.get_bindings(declarator);
} catch (e) {
// no bindings, so we can skip this
next();
continue;
}
const has_state = bindings.some((binding) => binding.kind === 'state');
const has_props = bindings.some((binding) => binding.kind === 'bindable_prop');
if (!has_state && !has_props) {
next();
continue;
}
if (has_props) {
nr_of_props++;
if (declarator.id.type !== 'Identifier') {
// TODO invest time in this?
throw new MigrationError(
'Encountered an export declaration pattern that is not supported for automigration.'
);
// Turn export let into props. It's really really weird because export let { x: foo, z: [bar]} = ..
// means that foo and bar are the props (i.e. the leaves are the prop names), not x and z.
// const tmp = b.id(state.scope.generate('tmp'));
// const paths = extract_paths(declarator.id, tmp);
// state.props_pre.push(
// b.declaration('const', tmp, visit(declarator.init!) as Expression)
// );
// for (const path of paths) {
// const name = (path.node as Identifier).name;
// const binding = state.scope.get(name)!;
// const value = path.expression;
// if (binding.kind === 'bindable_prop' || binding.kind === 'rest_prop') {
// state.props.push({
// local: name,
// exported: binding.prop_alias ? binding.prop_alias : name,
// init: value
// });
// state.props_insertion_point = /** @type {number} */(declarator.end);
// } else {
// declarations.push(b.declarator(path.node, value));
// }
// }
}
const name = declarator.id.name;
const binding = /** @type {Binding} */ (state.scope.get(name));
if (state.analysis.uses_props && (declarator.init || binding.updated)) {
throw new MigrationError(
'$$props is used together with named props in a way that cannot be automatically migrated.'
);
}
const prop = state.props.find((prop) => prop.exported === (binding.prop_alias || name));
if (prop) {
next();
// $$Props type was used
prop.init = declarator.init
? state.str
.snip(
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does instance_script.VariableDeclaration() do?
instance_script.VariableDeclaration() is a function in the svelte codebase, defined in packages/svelte/src/compiler/migrate/index.js.
Where is instance_script.VariableDeclaration() defined?
instance_script.VariableDeclaration() is defined in packages/svelte/src/compiler/migrate/index.js at line 565.
What does instance_script.VariableDeclaration() call?
instance_script.VariableDeclaration() calls 7 function(s): extract_all_identifiers_from_expression, extract_paths, extract_type_and_comment, generate, get, get_bindings, get_rune.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free