1 import {nextLineBreak} from "./whitespace.js"
3 // These are used when `options.locations` is on, for the
4 // `startLoc` and `endLoc` properties.
6 export class Position {
7 constructor(line, col) {
13 return new Position(this.line, this.column + n)
17 export class SourceLocation {
18 constructor(p, start, end) {
21 if (p.sourceFile !== null) this.source = p.sourceFile
25 // The `getLineInfo` function is mostly useful when the
26 // `locations` option is off (for performance reasons) and you
27 // want to find the line/column position for a given character
28 // offset. `input` should be the code string that the offset refers
31 export function getLineInfo(input, offset) {
32 for (let line = 1, cur = 0;;) {
33 let nextBreak = nextLineBreak(input, cur, offset)
34 if (nextBreak < 0) return new Position(line, offset - cur)