@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
64 lines (63 loc) • 2.04 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Debug_Snapshot
* @description Scope
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarkedDebugSnapshotScope = void 0;
const snapshot_scope_variable_1 = require("../../parse/snapshot-scope-variable");
class MarkedDebugSnapshotScope {
static fromScope(scope) {
const map = new Map();
const constantMapKeys = scope.constantMap.keys();
for (const key of constantMapKeys) {
const variable = scope.constantMap.get(key);
const value = (0, snapshot_scope_variable_1.parseSnapshotScopeVariable)(variable);
map.set(key, value);
}
const scopeMapKeys = scope.scopeMap.keys();
for (const key of scopeMapKeys) {
const variable = scope.scopeMap.get(key);
const value = (0, snapshot_scope_variable_1.parseSnapshotScopeVariable)(variable);
map.set(key, value);
}
if (scope.hasParent()) {
const parentScope = MarkedDebugSnapshotScope.fromScope(scope.ensureParent());
return new MarkedDebugSnapshotScope(parentScope, map);
}
return new MarkedDebugSnapshotScope(null, map);
}
constructor(parent, map) {
this._map = new Map();
this._parent = parent;
this._map = map;
}
get map() {
return this._map;
}
getDetailedObject() {
const object = {};
const keys = this._map.keys();
for (const key of keys) {
object[key] = this._map.get(key);
}
return object;
}
getKeyValueObject() {
const object = {};
const keys = this._map.keys();
for (const key of keys) {
const variable = this._map.get(key);
object[key] = variable.value;
}
return object;
}
hasParent() {
return this._parent !== null;
}
getParent() {
return this._parent;
}
}
exports.MarkedDebugSnapshotScope = MarkedDebugSnapshotScope;