UNPKG

@sudoo/marked

Version:

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

48 lines (47 loc) 1.95 kB
"use strict"; /** * @author WMXPY * @namespace Debug_Snapshot * @description Location */ Object.defineProperty(exports, "__esModule", { value: true }); exports.MarkedDebugSnapshotLocation = void 0; const declare_1 = require("../../host/declare"); const position_1 = require("./position"); class MarkedDebugSnapshotLocation { static fromNode(node, trace) { const location = node.loc; const locationFinder = trace.ensureLocationFinder(); const startPosition = position_1.MarkedDebugSnapshotPosition.fromPosition(locationFinder.findSourceLocation(location.start, node)); const endPosition = position_1.MarkedDebugSnapshotPosition.fromPosition(locationFinder.findSourceLocation(location.end, node)); return new MarkedDebugSnapshotLocation(startPosition, endPosition); } constructor(startPosition, endPosition) { this._startPosition = startPosition; this._endPosition = endPosition; } get startPosition() { return this._startPosition; } get endPosition() { return this._endPosition; } sliceCodeClip(sourceCode) { const splitSourceCode = sourceCode.split(declare_1.New_Line_Character); const startLine = this._startPosition.line; const endLine = this._endPosition.line; const startColumn = this._startPosition.column; const endColumn = this._endPosition.column; if (startLine === endLine) { return splitSourceCode[startLine - 1].slice(startColumn, endColumn); } const result = []; result.push(splitSourceCode[startLine - 1].slice(startColumn)); for (let i = startLine; i < endLine - 1; i++) { result.push(splitSourceCode[i]); } result.push(splitSourceCode[endLine - 1].slice(0, endColumn)); return result.join(declare_1.New_Line_Character); } } exports.MarkedDebugSnapshotLocation = MarkedDebugSnapshotLocation;