MCPcopy
hub / github.com/sveltejs/svelte / create_scopes

Function create_scopes

packages/svelte/src/compiler/phases/scope.js:921–1416  ·  view source on GitHub ↗
(ast, root, allow_reactive_declarations, parent)

Source from the content-addressed store, hash-verified

919 * @param {Scope | null} parent
920 */
921export function create_scopes(ast, root, allow_reactive_declarations, parent) {
922 /** @typedef {{ scope: Scope }} State */
923
924 /**
925 * A map of node->associated scope. A node appearing in this map does not necessarily mean that it created a scope
926 * @type {Map<AST.SvelteNode, Scope>}
927 */
928 const scopes = new Map();
929 const scope = new Scope(root, parent, false);
930 scopes.set(ast, scope);
931
932 /** @type {State} */
933 const state = { scope };
934
935 /** @type {[Scope, { node: Identifier; path: AST.SvelteNode[] }][]} */
936 const references = [];
937
938 /** @type {[Scope, Pattern | MemberExpression, Expression][]} */
939 const updates = [];
940
941 /**
942 * An array of reactive declarations, i.e. the `a` in `$: a = b * 2`
943 * @type {Identifier[]}
944 */
945 const possible_implicit_declarations = [];
946
947 /**
948 * @param {Scope} scope
949 * @param {Pattern[]} params
950 */
951 function add_params(scope, params) {
952 for (const param of params) {
953 for (const node of extract_identifiers(param)) {
954 scope.declare(node, 'normal', param.type === 'RestElement' ? 'rest_param' : 'param');
955 }
956 }
957 }
958
959 /**
960 * @type {Visitor<Node, State, AST.SvelteNode>}
961 */
962 const create_block_scope = (node, { state, next }) => {
963 const scope = state.scope.child(true);
964 scopes.set(node, scope);
965
966 next({ scope });
967 };
968
969 /**
970 * @type {Visitor<AST.ElementLike, State, AST.SvelteNode>}
971 */
972 const SvelteFragment = (node, { state, next }) => {
973 const scope = state.scope.child();
974 scopes.set(node, scope);
975 next({ scope });
976 };
977
978 /**

Callers 3

jsFunction · 0.90
analyze_moduleFunction · 0.90
analyze_componentFunction · 0.90

Calls 10

referenceMethod · 0.95
getMethod · 0.95
declareMethod · 0.95
unwrap_patternFunction · 0.90
objectFunction · 0.90
walkFunction · 0.85
pushMethod · 0.80
ComponentFunction · 0.70
setMethod · 0.65
childMethod · 0.45

Tested by

no test coverage detected