| 919 | * @param {Scope | null} parent |
| 920 | */ |
| 921 | export 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 | /** |