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.

12345678910111213141516171819202122232425262728293031323334353637
  1. import * as AST from './ast';
  2. import Env, { EnvError } from './env';
  3. export interface CompilerOpts {
  4. prettyPrint?: boolean;
  5. env?: Env;
  6. }
  7. export default class Compiler {
  8. private tree: AST.Node[];
  9. private prettyPrint: boolean;
  10. private env: Env;
  11. public constructor(
  12. parserResult: { tree: AST.Node[]; module?: string },
  13. opts: CompilerOpts
  14. ) {
  15. this.tree = parserResult.tree;
  16. this.prettyPrint = opts.prettyPrint || false;
  17. this.env = opts.env || new Env();
  18. }
  19. public compile(): string | EnvError {
  20. const result = this.tree.map((node) =>
  21. node.compile(this.env, {
  22. depth: 0,
  23. prettyPrint: this.prettyPrint,
  24. })
  25. );
  26. const resultError = result.find((el) => el instanceof EnvError);
  27. if (resultError !== undefined) return resultError;
  28. const output = result.join(this.prettyPrint ? '\n' : '');
  29. return this.prettyPrint ? output.trim() : output;
  30. }
  31. }