scope.js 1.0 KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createSubScope = createSubScope;
  6. var _map = require("./map.js");
  7. /**
  8. * Create a new scope which can access the parent scope,
  9. * but does not affect it when written. This is suitable for variable definitions
  10. * within a block node, or function definition.
  11. *
  12. * If parent scope has a createSubScope method, it delegates to that. Otherwise,
  13. * creates an empty map, and copies the parent scope to it, adding in
  14. * the remaining `args`.
  15. *
  16. * @param {Map} parentScope
  17. * @param {...any} args
  18. * @returns {Map}
  19. */
  20. function createSubScope(parentScope) {
  21. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  22. args[_key - 1] = arguments[_key];
  23. }
  24. if (typeof parentScope.createSubScope === 'function') {
  25. return _map.assign.apply(void 0, [parentScope.createSubScope()].concat(args));
  26. }
  27. return _map.assign.apply(void 0, [(0, _map.createEmptyMap)(), parentScope].concat(args));
  28. }