UNPKG

@sudoo/marked

Version:

JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous

39 lines (38 loc) 1.53 kB
"use strict"; /** * @author WMXPY * @namespace SourceMap_LocationFinder * @description Segment */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SegmentSourceMapLocationFinder = void 0; const decode_1 = require("../decode"); const error_1 = require("../../util/error/error"); const error_code_1 = require("../../declare/error-code"); const base_1 = require("./base"); class SegmentSourceMapLocationFinder extends base_1.BaseSourceMapLocationFinder { static fromSourceMap(sourceMap) { const decoded = (0, decode_1.decodeSourceMap)(sourceMap.mappings); return new SegmentSourceMapLocationFinder(decoded); } constructor(decoded) { super(); this._decoded = decoded; } findSourceLocation(position, node) { const line = this._decoded[position.line - 1]; if (typeof line === "undefined") { throw (0, error_1.error)(error_code_1.ERROR_CODE.CANNOT_FIND_ORIGINAL_POSITION_FROM_LINE, `${position.line}:${position.column}`, node); } for (const segment of line) { if (segment.targetColumn === position.column) { return { line: segment.sourceLine + 1, column: segment.sourceColumn, }; } } throw (0, error_1.error)(error_code_1.ERROR_CODE.CANNOT_FIND_ORIGINAL_POSITION_FROM_COLUMN, `${position.line}:${position.column}`, node); } } exports.SegmentSourceMapLocationFinder = SegmentSourceMapLocationFinder;