posthtml-parser
Version:
Parse HTML/XML to PostHTMLTree
37 lines • 1.04 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocationTracker = void 0;
class LocationTracker {
source;
lastPosition;
lastIndex;
constructor(source) {
this.source = source;
this.lastPosition = {
line: 1,
column: 1,
};
this.lastIndex = 0;
}
getPosition(index) {
if (index < this.lastIndex) {
throw new Error("Source indices must be monotonic");
}
while (this.lastIndex < index) {
if (this.source.charCodeAt(this.lastIndex) === /* \n */ 10) {
this.lastPosition.line++;
this.lastPosition.column = 1;
}
else {
this.lastPosition.column++;
}
this.lastIndex++;
}
return {
line: this.lastPosition.line,
column: this.lastPosition.column,
};
}
}
exports.LocationTracker = LocationTracker;
//# sourceMappingURL=location-tracker.js.map