nerdamer-ts
Version:
javascript light-weight symbolic math expression evaluator
40 lines • 1.6 kB
JavaScript
"use strict";
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _Context_instances, _Context_push, _Context_pop;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Context = void 0;
class Context {
constructor(initialData) {
_Context_instances.add(this);
this.stack = [];
this.currentData = initialData;
if (initialData) {
this.stack.push(initialData);
}
}
with(data, block) {
__classPrivateFieldGet(this, _Context_instances, "m", _Context_push).call(this, data);
block(data);
__classPrivateFieldGet(this, _Context_instances, "m", _Context_pop).call(this);
}
get() {
if (!this.currentData) {
throw new Error(`Context stack corrupted`);
}
return this.currentData;
}
}
exports.Context = Context;
_Context_instances = new WeakSet(), _Context_push = function _Context_push(data) {
this.stack.push(data);
this.currentData = data;
}, _Context_pop = function _Context_pop() {
if (this.stack.length > 0) {
this.currentData = this.stack.pop();
}
};
//# sourceMappingURL=Context.js.map