simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

scope.js (1036B)


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