base.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.BlockStatement = BlockStatement;
  6. exports.Directive = Directive;
  7. exports.DirectiveLiteral = DirectiveLiteral;
  8. exports.File = File;
  9. exports.InterpreterDirective = InterpreterDirective;
  10. exports.Placeholder = Placeholder;
  11. exports.Program = Program;
  12. function File(node) {
  13. if (node.program) {
  14. this.print(node.program.interpreter);
  15. }
  16. this.print(node.program);
  17. }
  18. function Program(node) {
  19. var _node$directives;
  20. this.noIndentInnerCommentsHere();
  21. this.printInnerComments();
  22. const directivesLen = (_node$directives = node.directives) == null ? void 0 : _node$directives.length;
  23. if (directivesLen) {
  24. var _node$directives$trai;
  25. const newline = node.body.length ? 2 : 1;
  26. this.printSequence(node.directives, {
  27. trailingCommentsLineOffset: newline
  28. });
  29. if (!((_node$directives$trai = node.directives[directivesLen - 1].trailingComments) != null && _node$directives$trai.length)) {
  30. this.newline(newline);
  31. }
  32. }
  33. this.printSequence(node.body);
  34. }
  35. function BlockStatement(node) {
  36. var _node$directives2;
  37. this.tokenChar(123);
  38. const exit = this.enterDelimited();
  39. const directivesLen = (_node$directives2 = node.directives) == null ? void 0 : _node$directives2.length;
  40. if (directivesLen) {
  41. var _node$directives$trai2;
  42. const newline = node.body.length ? 2 : 1;
  43. this.printSequence(node.directives, {
  44. indent: true,
  45. trailingCommentsLineOffset: newline
  46. });
  47. if (!((_node$directives$trai2 = node.directives[directivesLen - 1].trailingComments) != null && _node$directives$trai2.length)) {
  48. this.newline(newline);
  49. }
  50. }
  51. this.printSequence(node.body, {
  52. indent: true
  53. });
  54. exit();
  55. this.rightBrace(node);
  56. }
  57. function Directive(node) {
  58. this.print(node.value);
  59. this.semicolon();
  60. }
  61. const unescapedSingleQuoteRE = /(?:^|[^\\])(?:\\\\)*'/;
  62. const unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/;
  63. function DirectiveLiteral(node) {
  64. const raw = this.getPossibleRaw(node);
  65. if (!this.format.minified && raw !== undefined) {
  66. this.token(raw);
  67. return;
  68. }
  69. const {
  70. value
  71. } = node;
  72. if (!unescapedDoubleQuoteRE.test(value)) {
  73. this.token(`"${value}"`);
  74. } else if (!unescapedSingleQuoteRE.test(value)) {
  75. this.token(`'${value}'`);
  76. } else {
  77. throw new Error("Malformed AST: it is not possible to print a directive containing" + " both unescaped single and double quotes.");
  78. }
  79. }
  80. function InterpreterDirective(node) {
  81. this.token(`#!${node.value}`);
  82. this.newline(1, true);
  83. }
  84. function Placeholder(node) {
  85. this.token("%%");
  86. this.print(node.name);
  87. this.token("%%");
  88. if (node.expectedNode === "Statement") {
  89. this.semicolon();
  90. }
  91. }
  92. //# sourceMappingURL=base.js.map