Sha256: b8b76dcb51bf5de4d4e75891424738c3175ccc84ae98b601b5926f91b62771f1

Contents?: true

Size: 1.29 KB

Versions: 24

Compression:

Stored size: 1.29 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

class Range {
  static copy(orig) {
    return new Range(orig.start, orig.end);
  }

  constructor(start, end) {
    this.start = start;
    this.end = end || start;
  }

  isEmpty() {
    return typeof this.start !== 'number' || !this.end || this.end <= this.start;
  }
  /**
   * Set `origStart` and `origEnd` to point to the original source range for
   * this node, which may differ due to dropped CR characters.
   *
   * @param {number[]} cr - Positions of dropped CR characters
   * @param {number} offset - Starting index of `cr` from the last call
   * @returns {number} - The next offset, matching the one found for `origStart`
   */


  setOrigRange(cr, offset) {
    const {
      start,
      end
    } = this;

    if (cr.length === 0 || end <= cr[0]) {
      this.origStart = start;
      this.origEnd = end;
      return offset;
    }

    let i = offset;

    while (i < cr.length) {
      if (cr[i] > start) break;else ++i;
    }

    this.origStart = start + i;
    const nextOffset = i;

    while (i < cr.length) {
      // if end was at \n, it should now be at \r
      if (cr[i] >= end) break;else ++i;
    }

    this.origEnd = end + i;
    return nextOffset;
  }

}

exports.default = Range;

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
trusty-cms-5.0.7 node_modules/yaml/dist/cst/Range.js
trusty-cms-5.0.6 node_modules/yaml/dist/cst/Range.js
trusty-cms-5.0.5 node_modules/yaml/dist/cst/Range.js
trusty-cms-5.0.4 node_modules/yaml/dist/cst/Range.js
trusty-cms-5.0.3 node_modules/yaml/dist/cst/Range.js
trusty-cms-5.0.2 node_modules/yaml/dist/cst/Range.js
trusty-cms-5.0.1 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.3.5 node_modules/yaml/dist/cst/Range.js
trusty-cms-5.0.0 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.3.4 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.3.3 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.3.2 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.3.1 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.3 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.2.3 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.2.2 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.2.1 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.2 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.1.9 node_modules/yaml/dist/cst/Range.js
trusty-cms-4.1.8 node_modules/yaml/dist/cst/Range.js