UNPKG

2.76 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.BlockStatement = BlockStatement;
7exports.Directive = Directive;
8exports.DirectiveLiteral = DirectiveLiteral;
9exports.File = File;
10exports.InterpreterDirective = InterpreterDirective;
11exports.Placeholder = Placeholder;
12exports.Program = Program;
13function File(node) {
14 if (node.program) {
15 this.print(node.program.interpreter, node);
16 }
17 this.print(node.program, node);
18}
19function 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, node, {
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, node);
35}
36function BlockStatement(node) {
37 var _node$directives2;
38 this.tokenChar(123);
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, node, {
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, node, {
52 indent: true
53 });
54 this.rightBrace(node);
55}
56function Directive(node) {
57 this.print(node.value, node);
58 this.semicolon();
59}
60const unescapedSingleQuoteRE = /(?:^|[^\\])(?:\\\\)*'/;
61const unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/;
62function DirectiveLiteral(node) {
63 const raw = this.getPossibleRaw(node);
64 if (!this.format.minified && raw !== undefined) {
65 this.token(raw);
66 return;
67 }
68 const {
69 value
70 } = node;
71 if (!unescapedDoubleQuoteRE.test(value)) {
72 this.token(`"${value}"`);
73 } else if (!unescapedSingleQuoteRE.test(value)) {
74 this.token(`'${value}'`);
75 } else {
76 throw new Error("Malformed AST: it is not possible to print a directive containing" + " both unescaped single and double quotes.");
77 }
78}
79function InterpreterDirective(node) {
80 this.token(`#!${node.value}`);
81 this.newline(1, true);
82}
83function Placeholder(node) {
84 this.token("%%");
85 this.print(node.name);
86 this.token("%%");
87 if (node.expectedNode === "Statement") {
88 this.semicolon();
89 }
90}
91
92//# sourceMappingURL=base.js.map