refakts
Version:
TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.
40 lines • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocationParser = void 0;
class LocationParser {
static parseLocation(locationStr) {
const match = this.matchLocationString(locationStr);
return this.buildLocationRange(match.groups);
}
static matchLocationString(locationStr) {
const match = locationStr.match(this.LOCATION_REGEX);
if (!match?.groups) {
throw new Error(`Invalid location format: ${locationStr}`);
}
return match;
}
static buildLocationRange(groups) {
return {
file: groups.file,
startLine: parseInt(groups.startLine, 10),
startColumn: this.parseColumnOrDefault(groups.startColumn, 0),
endLine: this.parseLineOrDefault(groups.endLine, parseInt(groups.startLine, 10)),
endColumn: this.parseColumnOrDefault(groups.endColumn, Number.MAX_SAFE_INTEGER)
};
}
static parseColumnOrDefault(value, defaultValue) {
return !value || value === '' ? defaultValue : parseInt(value, 10);
}
static parseLineOrDefault(value, defaultValue) {
return !value || value === '' ? defaultValue : parseInt(value, 10);
}
static isLocationFormat(input) {
return input.startsWith('[') && input.endsWith(']');
}
static formatLocation(location) {
return `[${location.file} ${location.startLine}:${location.startColumn}-${location.endLine}:${location.endColumn}]`;
}
}
exports.LocationParser = LocationParser;
LocationParser.LOCATION_REGEX = /^\[(?<file>[^\]]+)\s+(?<startLine>\d+)(?::(?<startColumn>\d*))?-(?<endLine>\d*):?(?<endColumn>\d*)\]$/;
//# sourceMappingURL=location-parser.js.map