A stylesheet language written in TypeScript that compiles to CSS
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.

1234567891011121314151617181920212223242526272829303132333435
  1. import * as AST from './ast';
  2. import { Error } from './error';
  3. import Token from './token';
  4. export class EnvError implements Error {
  5. public line: number;
  6. public message: string;
  7. public module?: string;
  8. public constructor(line: number, message: string, module?: string) {
  9. this.line = line;
  10. this.message = message;
  11. this.module = module;
  12. }
  13. }
  14. export default class Env {
  15. public data: { [name: string]: AST.Node };
  16. public constructor(parent?: Env) {
  17. this.data = parent ? Object.assign({}, parent.data) : {};
  18. }
  19. public get(name: Token): AST.Node | EnvError {
  20. if (this.data[name.value]) return this.data[name.value];
  21. return new EnvError(
  22. name.line,
  23. `Reference to unbound variable ${name.value}`
  24. );
  25. }
  26. public set(name: string, value: AST.Node): void {
  27. this.data[name] = value;
  28. }
  29. }