location.js 971 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getLineInfo = getLineInfo;
  6. exports.SourceLocation = exports.Position = void 0;
  7. var _whitespace = require("./whitespace");
  8. class Position {
  9. constructor(line, col) {
  10. this.line = void 0;
  11. this.column = void 0;
  12. this.line = line;
  13. this.column = col;
  14. }
  15. }
  16. exports.Position = Position;
  17. class SourceLocation {
  18. constructor(start, end) {
  19. this.start = void 0;
  20. this.end = void 0;
  21. this.filename = void 0;
  22. this.identifierName = void 0;
  23. this.start = start;
  24. this.end = end;
  25. }
  26. }
  27. exports.SourceLocation = SourceLocation;
  28. function getLineInfo(input, offset) {
  29. let line = 1;
  30. let lineStart = 0;
  31. let match;
  32. _whitespace.lineBreakG.lastIndex = 0;
  33. while ((match = _whitespace.lineBreakG.exec(input)) && match.index < offset) {
  34. line++;
  35. lineStart = _whitespace.lineBreakG.lastIndex;
  36. }
  37. return new Position(line, offset - lineStart);
  38. }