You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
524 B
30 lines
524 B
3 years ago
|
export class Env {
|
||
|
constructor(outer, data = {}) {
|
||
|
this.outer = outer;
|
||
|
this.data = data;
|
||
|
}
|
||
|
|
||
|
static set(env, key, val) {
|
||
|
if (env.data[key] ||
|
||
|
env.outer === null) {
|
||
|
return env.data[key] = val;
|
||
|
}
|
||
|
|
||
|
return Env.set(env.outer, key, val);
|
||
|
}
|
||
|
|
||
|
static find(env, key) {
|
||
|
return env.data[key] ||
|
||
|
(env.outer && Env.find(env.outer, key));
|
||
|
}
|
||
|
|
||
|
static get(env, key) {
|
||
|
const o = Env.find(env, key);
|
||
|
if (o === null) {
|
||
|
throw new Error(`Not found: ${key}`);
|
||
|
}
|
||
|
|
||
|
return o;
|
||
|
}
|
||
|
}
|