HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-172-31-4-197 6.8.0-1036-aws #38~22.04.1-Ubuntu SMP Fri Aug 22 15:44:33 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/api-management/node_modules/alce/lib/ast/collection.js
var util = require('../util'),
      extractRange = util.extractRange;

module.exports = Collection;

function Collection(node, src, options) {
  this.options = options;
  this.values = {};
  this.children = [];

  if (!node) {
    return;
  }

  this.range = node.range;
  this.innerRange = [node.range[0] + 1, node.range[1] - 1];
  this.source = extractRange(src, node.range);
}
Collection.prototype = {
  preamble: '',
  innerPrologue: '',
  prologue: '',

  get: function(id) {
    /*jshint eqnull:true */
    if (id != null) {
      var node = this._getChild(id);
      return node && node.get();
    } else {
      return this;
    }
  },

  remove: function(id) {
    if (this.values[id]) {
      for (var i = 0; i < this.children.length; i++) {
        if (this.children[i].key && this.children[i].key.value===id) {
          this.children.splice(i,1);
          break;
        }
      }
      delete this.values[id];
    }
  },

  toString: function() {
    return this.preamble + this.open + this.children.join('') + this.innerPrologue + this.close + this.prologue;
  },

  _calcIndent: function(parent) {
    this.options.seedIndent && this.options.seedIndent(parent, this);

    for (var i = 0; i < this.children.length; i++) {
      this.children[i]._calcIndent(this);
    }
  },

  _leave: function(src) {
    var last = this.children[this.children.length - 1];

    if (last) {
      this.innerPrologue = extractRange(src, [last.range[1], this.innerRange[1]]);
    } else {
      this.innerPrologue = extractRange(src, this.innerRange);
    }
  },

  _insert: function(value, src) {
    if (value.key) {
      this.values[value.key.value] = value;
    }

    var priorSibling = this.children[this.children.length - 1];

    this.children.push(value);

    var priorRange;
    if (priorSibling) {
      priorRange = [priorSibling.range[1], value.range[0]];
    } else {
      priorRange = [this.innerRange[0], value.range[0]];
    }

    value.preamble = extractRange(src, priorRange);
  }
};