Created
February 9, 2024 08:26
-
-
Save broquaint/47b41f119dcc0def381db04d7a651a18 to your computer and use it in GitHub Desktop.
The deno TypeScript compiler output for env.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Plucked from the output of: deno bundle impls/ts/step3_env.ts | |
class Env { | |
outer; | |
data; | |
constructor(outer){ | |
this.outer = outer ?? null; | |
this.data = {}; | |
} | |
set(k, v) { | |
this.data[k.value] = v; | |
return v; | |
} | |
find(k) { | |
if (k.value in this.data) return this; | |
else if (this.outer) return this.outer.find(k); | |
else return null; | |
} | |
get(k) { | |
const env = this.find(k); | |
if (env !== null) return env.data[k.value]; | |
else throw `The symbol '${k.value}' not found in the environment`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment