base.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.File = File;
  4. exports.Program = Program;
  5. exports.BlockStatement = BlockStatement;
  6. exports.Noop = Noop;
  7. exports.Directive = Directive;
  8. var _types = require("./types");
  9. Object.defineProperty(exports, "DirectiveLiteral", {
  10. enumerable: true,
  11. get: function get() {
  12. return _types.StringLiteral;
  13. }
  14. });
  15. function File(node) {
  16. this.print(node.program, node);
  17. }
  18. function Program(node) {
  19. this.printInnerComments(node, false);
  20. this.printSequence(node.directives, node);
  21. if (node.directives && node.directives.length) this.newline();
  22. this.printSequence(node.body, node);
  23. }
  24. function BlockStatement(node) {
  25. this.token("{");
  26. this.printInnerComments(node);
  27. var hasDirectives = node.directives && node.directives.length;
  28. if (node.body.length || hasDirectives) {
  29. this.newline();
  30. this.printSequence(node.directives, node, { indent: true });
  31. if (hasDirectives) this.newline();
  32. this.printSequence(node.body, node, { indent: true });
  33. this.removeTrailingNewline();
  34. this.source("end", node.loc);
  35. if (!this.endsWith("\n")) this.newline();
  36. this.rightBrace();
  37. } else {
  38. this.source("end", node.loc);
  39. this.token("}");
  40. }
  41. }
  42. function Noop() {}
  43. function Directive(node) {
  44. this.print(node.value, node);
  45. this.semicolon();
  46. }