"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.XmlError = void 0; /** * An error that occurred while parsing XML. */ class XmlError extends Error { constructor(message, charIndex, xml) { let column = 1; let excerpt = ''; let line = 1; // Find the line and column where the error occurred. for (let i = 0; i < charIndex; ++i) { let char = xml[i]; if (char === '\n') { column = 1; excerpt = ''; line += 1; } else { column += 1; excerpt += char; } } let eol = xml.indexOf('\n', charIndex); excerpt += eol === -1 ? xml.slice(charIndex) : xml.slice(charIndex, eol); let excerptStart = 0; // Keep the excerpt below 50 chars, but always keep the error position in // view. if (excerpt.length > 50) { if (column < 40) { excerpt = excerpt.slice(0, 50); } else { excerptStart = column - 20; excerpt = excerpt.slice(excerptStart, column + 30); } } super(`${message} (line ${line}, column ${column})\n` + ` ${excerpt}\n` + ' '.repeat(column - excerptStart + 1) + '^\n'); this.column = column; this.excerpt = excerpt; this.line = line; this.name = 'XmlError'; this.pos = charIndex; } } exports.XmlError = XmlError; //# sourceMappingURL=XmlError.js.map