123456789101112131415161718192021222324 |
- import * as AST from '../ast';
- import Env, { EnvError } from '../env';
-
- export class Let {
- public bindings: AST.Binding[];
- public children: AST.Node[];
-
- public constructor(bindings: AST.Binding[], children: AST.Node[]) {
- this.bindings = bindings;
- this.children = children;
- }
-
- public compile(env: Env, opts: AST.Opts): string | EnvError {
- this.bindings.forEach((binding) => {
- env.set(binding.identifier.name.value, binding.value);
- });
-
- const children = this.children.map((child) => child.compile(env, opts));
- const childrenError = children.find((node) => node instanceof EnvError);
- if (childrenError instanceof EnvError) return childrenError;
-
- return children.join(opts.prettyPrint ? '\n' : '');
- }
- }
|