Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Range.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  8. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  9. var Range =
  10. /*#__PURE__*/
  11. function () {
  12. (0, _createClass2.default)(Range, null, [{
  13. key: "copy",
  14. value: function copy(orig) {
  15. return new Range(orig.start, orig.end);
  16. }
  17. }]);
  18. function Range(start, end) {
  19. (0, _classCallCheck2.default)(this, Range);
  20. this.start = start;
  21. this.end = end || start;
  22. }
  23. (0, _createClass2.default)(Range, [{
  24. key: "isEmpty",
  25. value: function isEmpty() {
  26. return typeof this.start !== 'number' || !this.end || this.end <= this.start;
  27. }
  28. /**
  29. * Set `origStart` and `origEnd` to point to the original source range for
  30. * this node, which may differ due to dropped CR characters.
  31. *
  32. * @param {number[]} cr - Positions of dropped CR characters
  33. * @param {number} offset - Starting index of `cr` from the last call
  34. * @returns {number} - The next offset, matching the one found for `origStart`
  35. */
  36. }, {
  37. key: "setOrigRange",
  38. value: function setOrigRange(cr, offset) {
  39. var start = this.start,
  40. end = this.end;
  41. if (cr.length === 0 || end <= cr[0]) {
  42. this.origStart = start;
  43. this.origEnd = end;
  44. return offset;
  45. }
  46. var i = offset;
  47. while (i < cr.length) {
  48. if (cr[i] > start) break;else ++i;
  49. }
  50. this.origStart = start + i;
  51. var nextOffset = i;
  52. while (i < cr.length) {
  53. // if end was at \n, it should now be at \r
  54. if (cr[i] >= end) break;else ++i;
  55. }
  56. this.origEnd = end + i;
  57. return nextOffset;
  58. }
  59. }]);
  60. return Range;
  61. }();
  62. exports.default = Range;