UNPKG

@sudoo/marked

Version:

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

81 lines (80 loc) 2.64 kB
"use strict"; /** * @author WMXPY * @namespace Variable_Trace * @description Trace */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Trace = void 0; const error_code_1 = require("../../declare/error-code"); const error_1 = require("../../util/error/error"); class Trace { static init(scriptLocation, locationFinder, breakPointController) { return new Trace(scriptLocation, null, undefined, locationFinder, breakPointController); } constructor(scriptLocation, node, parent, locationFinder, breakPointController) { this._scriptLocation = scriptLocation; this._parent = parent !== null && parent !== void 0 ? parent : null; this._node = node; this._locationFinder = locationFinder !== null && locationFinder !== void 0 ? locationFinder : null; this._breakPointController = breakPointController !== null && breakPointController !== void 0 ? breakPointController : null; this._label = null; } get scriptLocation() { return this._scriptLocation; } hasBreakPointController() { if (this._breakPointController !== null) { return true; } if (this._parent) { return this._parent.hasBreakPointController(); } return false; } ensureBreakPointController() { if (this._breakPointController !== null) { return this._breakPointController; } if (this._parent) { return this._parent.ensureBreakPointController(); } throw (0, error_1.error)(error_code_1.ERROR_CODE.INTERNAL_ERROR, "No Break Point Controller"); } ensureLocationFinder() { if (this._locationFinder !== null) { return this._locationFinder; } if (this._parent) { return this._parent.ensureLocationFinder(); } throw (0, error_1.error)(error_code_1.ERROR_CODE.INTERNAL_ERROR, "No Location Finder"); } getNode() { return this._node; } getParent() { return this._parent; } hasLabel() { return typeof this._label === "string"; } getLabel() { return this._label; } ensureLabel() { if (typeof this._label === "string") { return this._label; } throw (0, error_1.error)(error_code_1.ERROR_CODE.INTERNAL_ERROR, "No Label"); } stack(node) { return new Trace(this._scriptLocation, node, this); } stackWithLabel(node, label) { const trace = this.stack(node); trace._label = label; return trace; } } exports.Trace = Trace;