UNPKG

880 BJavaScriptView Raw
1import { createEmptyMap, assign } from './map.js';
2/**
3 * Create a new scope which can access the parent scope,
4 * but does not affect it when written. This is suitable for variable definitions
5 * within a block node, or function definition.
6 *
7 * If parent scope has a createSubScope method, it delegates to that. Otherwise,
8 * creates an empty map, and copies the parent scope to it, adding in
9 * the remaining `args`.
10 *
11 * @param {Map} parentScope
12 * @param {...any} args
13 * @returns {Map}
14 */
15
16export function createSubScope(parentScope) {
17 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
18 args[_key - 1] = arguments[_key];
19 }
20
21 if (typeof parentScope.createSubScope === 'function') {
22 return assign(parentScope.createSubScope(), ...args);
23 }
24
25 return assign(createEmptyMap(), parentScope, ...args);
26}
\No newline at end of file