source: trip-planner-front/node_modules/@babel/generator/lib/generators/base.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.File = File;
7exports.Program = Program;
8exports.BlockStatement = BlockStatement;
9exports.Directive = Directive;
10exports.DirectiveLiteral = DirectiveLiteral;
11exports.InterpreterDirective = InterpreterDirective;
12exports.Placeholder = Placeholder;
13
14var t = require("@babel/types");
15
16function File(node) {
17 if (node.program) {
18 this.print(node.program.interpreter, node);
19 }
20
21 this.print(node.program, node);
22}
23
24function Program(node) {
25 this.printInnerComments(node, false);
26 this.printSequence(node.directives, node);
27 if (node.directives && node.directives.length) this.newline();
28 this.printSequence(node.body, node);
29}
30
31function BlockStatement(node) {
32 var _node$directives;
33
34 this.token("{");
35 this.printInnerComments(node);
36 const hasDirectives = (_node$directives = node.directives) == null ? void 0 : _node$directives.length;
37
38 if (node.body.length || hasDirectives) {
39 this.newline();
40 this.printSequence(node.directives, node, {
41 indent: true
42 });
43 if (hasDirectives) this.newline();
44 this.printSequence(node.body, node, {
45 indent: true
46 });
47 this.removeTrailingNewline();
48 this.source("end", node.loc);
49 if (!this.endsWith("\n")) this.newline();
50 this.rightBrace();
51 } else {
52 this.source("end", node.loc);
53 this.token("}");
54 }
55}
56
57function Directive(node) {
58 this.print(node.value, node);
59 this.semicolon();
60}
61
62const unescapedSingleQuoteRE = /(?:^|[^\\])(?:\\\\)*'/;
63const unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/;
64
65function DirectiveLiteral(node) {
66 const raw = this.getPossibleRaw(node);
67
68 if (raw != null) {
69 this.token(raw);
70 return;
71 }
72
73 const {
74 value
75 } = node;
76
77 if (!unescapedDoubleQuoteRE.test(value)) {
78 this.token(`"${value}"`);
79 } else if (!unescapedSingleQuoteRE.test(value)) {
80 this.token(`'${value}'`);
81 } else {
82 throw new Error("Malformed AST: it is not possible to print a directive containing" + " both unescaped single and double quotes.");
83 }
84}
85
86function InterpreterDirective(node) {
87 this.token(`#!${node.value}\n`);
88}
89
90function Placeholder(node) {
91 this.token("%%");
92 this.print(node.name);
93 this.token("%%");
94
95 if (node.expectedNode === "Statement") {
96 this.semicolon();
97 }
98}
Note: See TracBrowser for help on using the repository browser.