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