base.js 2.7 KB

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