A stylesheet language written in TypeScript that compiles to CSS
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

env.ts 823B

1234567891011121314151617181920212223242526272829303132333435
  1. import { 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 = {}) {
  17. this.data = Object.assign({}, parent);
  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. }