create_scopes() — svelte Function Reference
Architecture documentation for the create_scopes() function in scope.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f["create_scopes()"] ee93d8a6_6fde_b1c1_e15b_3a4da5326305["scope.js"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|defined in| ee93d8a6_6fde_b1c1_e15b_3a4da5326305 e6258220_a976_05ad_470f_313b670ef126["js()"] e6258220_a976_05ad_470f_313b670ef126 -->|calls| c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f 05334dc2_42b5_e2cb_fe55_aa3f6a2de9df["analyze_module()"] 05334dc2_42b5_e2cb_fe55_aa3f6a2de9df -->|calls| c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f 78a6ba9a_5003_f569_a638_76e4f1977809["analyze_component()"] 78a6ba9a_5003_f569_a638_76e4f1977809 -->|calls| c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f c12e0147_3f27_cf17_5878_e54ffdc328d5["extract_identifiers()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| c12e0147_3f27_cf17_5878_e54ffdc328d5 44642633_e3c9_8ae1_48af_53507481a2cb["declare()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| 44642633_e3c9_8ae1_48af_53507481a2cb 2f404503_a86a_3205_14f4_8e1279b02d1c["child()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| 2f404503_a86a_3205_14f4_8e1279b02d1c a2d986c5_5ad1_b6ea_d335_4846d9af9e9f["determine_slot()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| a2d986c5_5ad1_b6ea_d335_4846d9af9e9f e5ba0f80_c4ba_4a9e_c19c_5b02f60481ca["reference()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| e5ba0f80_c4ba_4a9e_c19c_5b02f60481ca 4d1d8bf4_9585_c879_52f8_3662d884f69c["extract_identifiers_from_destructuring()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| 4d1d8bf4_9585_c879_52f8_3662d884f69c 9148edcb_b5eb_bf41_8087_a1d28bac7f4d["unique()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| 9148edcb_b5eb_bf41_8087_a1d28bac7f4d 784480d0_767d_ac40_b03e_ae8ddcc82684["Set()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| 784480d0_767d_ac40_b03e_ae8ddcc82684 627dc2f8_4dbc_5bb1_8f54_cee503e17098["get()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| 627dc2f8_4dbc_5bb1_8f54_cee503e17098 d935f45f_6959_e32d_6e74_07f0885da3b7["unwrap_pattern()"] c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f -->|calls| d935f45f_6959_e32d_6e74_07f0885da3b7 style c531899f_2ddc_b054_bfe1_2cfdfd2b1c7f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/scope.js lines 873–1365
export function create_scopes(ast, root, allow_reactive_declarations, parent) {
/** @typedef {{ scope: Scope }} State */
/**
* A map of node->associated scope. A node appearing in this map does not necessarily mean that it created a scope
* @type {Map<AST.SvelteNode, Scope>}
*/
const scopes = new Map();
const scope = new Scope(root, parent, false);
scopes.set(ast, scope);
/** @type {State} */
const state = { scope };
/** @type {[Scope, { node: Identifier; path: AST.SvelteNode[] }][]} */
const references = [];
/** @type {[Scope, Pattern | MemberExpression, Expression][]} */
const updates = [];
/**
* An array of reactive declarations, i.e. the `a` in `$: a = b * 2`
* @type {Identifier[]}
*/
const possible_implicit_declarations = [];
/**
* @param {Scope} scope
* @param {Pattern[]} params
*/
function add_params(scope, params) {
for (const param of params) {
for (const node of extract_identifiers(param)) {
scope.declare(node, 'normal', param.type === 'RestElement' ? 'rest_param' : 'param');
}
}
}
/**
* @type {Visitor<Node, State, AST.SvelteNode>}
*/
const create_block_scope = (node, { state, next }) => {
const scope = state.scope.child(true);
scopes.set(node, scope);
next({ scope });
};
/**
* @type {Visitor<AST.ElementLike, State, AST.SvelteNode>}
*/
const SvelteFragment = (node, { state, next }) => {
const scope = state.scope.child();
scopes.set(node, scope);
next({ scope });
};
/**
* @type {Visitor<AST.Component | AST.SvelteComponent | AST.SvelteSelf, State, AST.SvelteNode>}
*/
const Component = (node, context) => {
node.metadata.scopes = {
default: context.state.scope.child()
};
if (node.type === 'SvelteComponent') {
context.visit(node.expression);
}
const default_state = determine_slot(node)
? context.state
: { scope: node.metadata.scopes.default };
for (const attribute of node.attributes) {
if (attribute.type === 'LetDirective') {
context.visit(attribute, default_state);
} else {
context.visit(attribute);
}
}
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does create_scopes() do?
create_scopes() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/scope.js.
Where is create_scopes() defined?
create_scopes() is defined in packages/svelte/src/compiler/phases/scope.js at line 873.
What does create_scopes() call?
create_scopes() calls 11 function(s): Set, child, declare, determine_slot, extract_identifiers, extract_identifiers_from_destructuring, get, object, and 3 more.
What calls create_scopes()?
create_scopes() is called by 3 function(s): analyze_component, analyze_module, js.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free