@tsukiroku/tiny
Version:
Tiny interpreter
34 lines (33 loc) • 835 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Enviroment {
store = new Map();
outer = null;
constructor(outer = null) {
this.outer = outer;
}
get(name) {
const value = this.store.get(name);
if (value)
return value;
if (this.outer)
return this.outer.get(name);
return null;
}
set(name, value) {
this.store.set(name, value);
}
delete(name) {
this.store.delete(name);
}
update(name, value) {
if (this.store.has(name))
this.store.set(name, value);
else if (this.outer)
this.outer.update(name, value);
}
has(name) {
return this.store.has(name) ?? (this.outer && this.outer.has(name));
}
}
exports.default = Enviroment;