base.js 1.3 KB

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