UNPKG

refakts

Version:

TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.

52 lines 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocationParser = void 0; class LocationParser { static parseLocation(locationStr) { return this.tryParseCharacterPrecise(locationStr) || this.tryParseFullLine(locationStr) || this.tryParseToEndOfLine(locationStr) || this.tryParseFromLineStart(locationStr) || this.throwInvalidFormat(locationStr); } static tryParseCharacterPrecise(locationStr) { const match = locationStr.match(this.LOCATION_REGEX); return match ? this.createLocationRange(match[1], match[2], match[3], match[4], match[5]) : null; } static tryParseFullLine(locationStr) { const match = locationStr.match(this.FULL_LINE_REGEX); return match ? this.createLocationRange(match[1], match[2], '0', match[3], Number.MAX_SAFE_INTEGER.toString()) : null; } static tryParseToEndOfLine(locationStr) { const match = locationStr.match(this.TO_END_OF_LINE_REGEX); return match ? this.createLocationRange(match[1], match[2], match[3], match[2], Number.MAX_SAFE_INTEGER.toString()) : null; } static tryParseFromLineStart(locationStr) { const match = locationStr.match(this.FROM_LINE_START_REGEX); return match ? this.createLocationRange(match[1], match[2], '0', match[3], match[4]) : null; } static createLocationRange(file, startLine, startColumn, endLine, endColumn) { return { file, startLine: parseInt(startLine, 10), startColumn: parseInt(startColumn, 10), endLine: parseInt(endLine, 10), endColumn: parseInt(endColumn, 10) }; } static throwInvalidFormat(locationStr) { throw new Error(`Invalid location format: ${locationStr}`); } 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 = /^\[([^\]]+)\s+(\d+):(\d+)-(\d+):(\d+)\]$/; LocationParser.FULL_LINE_REGEX = /^\[([^\]]+)\s+(\d+):-(\d+):\]$/; LocationParser.TO_END_OF_LINE_REGEX = /^\[([^\]]+)\s+(\d+):(\d+)-\]$/; LocationParser.FROM_LINE_START_REGEX = /^\[([^\]]+)\s+(\d+)-(\d+):(\d+)\]$/; //# sourceMappingURL=location-parser.js.map