base.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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, node);
  15. }
  16. this.print(node.program, node);
  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, node, {
  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, node);
  34. }
  35. function BlockStatement(node) {
  36. var _node$directives2;
  37. this.tokenChar(123);
  38. const directivesLen = (_node$directives2 = node.directives) == null ? void 0 : _node$directives2.length;
  39. if (directivesLen) {
  40. var _node$directives$trai2;
  41. const newline = node.body.length ? 2 : 1;
  42. this.printSequence(node.directives, node, {
  43. indent: true,
  44. trailingCommentsLineOffset: newline
  45. });
  46. if (!((_node$directives$trai2 = node.directives[directivesLen - 1].trailingComments) != null && _node$directives$trai2.length)) {
  47. this.newline(newline);
  48. }
  49. }
  50. this.printSequence(node.body, node, {
  51. indent: true
  52. });
  53. this.rightBrace(node);
  54. }
  55. function Directive(node) {
  56. this.print(node.value, node);
  57. this.semicolon();
  58. }
  59. const unescapedSingleQuoteRE = /(?:^|[^\\])(?:\\\\)*'/;
  60. const unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/;
  61. function DirectiveLiteral(node) {
  62. const raw = this.getPossibleRaw(node);
  63. if (!this.format.minified && raw !== undefined) {
  64. this.token(raw);
  65. return;
  66. }
  67. const {
  68. value
  69. } = node;
  70. if (!unescapedDoubleQuoteRE.test(value)) {
  71. this.token(`"${value}"`);
  72. } else if (!unescapedSingleQuoteRE.test(value)) {
  73. this.token(`'${value}'`);
  74. } else {
  75. throw new Error("Malformed AST: it is not possible to print a directive containing" + " both unescaped single and double quotes.");
  76. }
  77. }
  78. function InterpreterDirective(node) {
  79. this.token(`#!${node.value}`);
  80. this.newline(1, true);
  81. }
  82. function Placeholder(node) {
  83. this.token("%%");
  84. this.print(node.name);
  85. this.token("%%");
  86. if (node.expectedNode === "Statement") {
  87. this.semicolon();
  88. }
  89. }
  90. //# sourceMappingURL=base.js.map