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