source: trip-planner-front/node_modules/@babel/generator/lib/generators/types.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 5.6 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.Identifier = Identifier;
7exports.ArgumentPlaceholder = ArgumentPlaceholder;
8exports.SpreadElement = exports.RestElement = RestElement;
9exports.ObjectPattern = exports.ObjectExpression = ObjectExpression;
10exports.ObjectMethod = ObjectMethod;
11exports.ObjectProperty = ObjectProperty;
12exports.ArrayPattern = exports.ArrayExpression = ArrayExpression;
13exports.RecordExpression = RecordExpression;
14exports.TupleExpression = TupleExpression;
15exports.RegExpLiteral = RegExpLiteral;
16exports.BooleanLiteral = BooleanLiteral;
17exports.NullLiteral = NullLiteral;
18exports.NumericLiteral = NumericLiteral;
19exports.StringLiteral = StringLiteral;
20exports.BigIntLiteral = BigIntLiteral;
21exports.DecimalLiteral = DecimalLiteral;
22exports.PipelineTopicExpression = PipelineTopicExpression;
23exports.PipelineBareFunction = PipelineBareFunction;
24exports.PipelinePrimaryTopicReference = PipelinePrimaryTopicReference;
25
26var t = require("@babel/types");
27
28var _jsesc = require("jsesc");
29
30function Identifier(node) {
31 this.exactSource(node.loc, () => {
32 this.word(node.name);
33 });
34}
35
36function ArgumentPlaceholder() {
37 this.token("?");
38}
39
40function RestElement(node) {
41 this.token("...");
42 this.print(node.argument, node);
43}
44
45function ObjectExpression(node) {
46 const props = node.properties;
47 this.token("{");
48 this.printInnerComments(node);
49
50 if (props.length) {
51 this.space();
52 this.printList(props, node, {
53 indent: true,
54 statement: true
55 });
56 this.space();
57 }
58
59 this.token("}");
60}
61
62function ObjectMethod(node) {
63 this.printJoin(node.decorators, node);
64
65 this._methodHead(node);
66
67 this.space();
68 this.print(node.body, node);
69}
70
71function ObjectProperty(node) {
72 this.printJoin(node.decorators, node);
73
74 if (node.computed) {
75 this.token("[");
76 this.print(node.key, node);
77 this.token("]");
78 } else {
79 if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) {
80 this.print(node.value, node);
81 return;
82 }
83
84 this.print(node.key, node);
85
86 if (node.shorthand && t.isIdentifier(node.key) && t.isIdentifier(node.value) && node.key.name === node.value.name) {
87 return;
88 }
89 }
90
91 this.token(":");
92 this.space();
93 this.print(node.value, node);
94}
95
96function ArrayExpression(node) {
97 const elems = node.elements;
98 const len = elems.length;
99 this.token("[");
100 this.printInnerComments(node);
101
102 for (let i = 0; i < elems.length; i++) {
103 const elem = elems[i];
104
105 if (elem) {
106 if (i > 0) this.space();
107 this.print(elem, node);
108 if (i < len - 1) this.token(",");
109 } else {
110 this.token(",");
111 }
112 }
113
114 this.token("]");
115}
116
117function RecordExpression(node) {
118 const props = node.properties;
119 let startToken;
120 let endToken;
121
122 if (this.format.recordAndTupleSyntaxType === "bar") {
123 startToken = "{|";
124 endToken = "|}";
125 } else if (this.format.recordAndTupleSyntaxType === "hash") {
126 startToken = "#{";
127 endToken = "}";
128 } else {
129 throw new Error(`The "recordAndTupleSyntaxType" generator option must be "bar" or "hash" (${JSON.stringify(this.format.recordAndTupleSyntaxType)} received).`);
130 }
131
132 this.token(startToken);
133 this.printInnerComments(node);
134
135 if (props.length) {
136 this.space();
137 this.printList(props, node, {
138 indent: true,
139 statement: true
140 });
141 this.space();
142 }
143
144 this.token(endToken);
145}
146
147function TupleExpression(node) {
148 const elems = node.elements;
149 const len = elems.length;
150 let startToken;
151 let endToken;
152
153 if (this.format.recordAndTupleSyntaxType === "bar") {
154 startToken = "[|";
155 endToken = "|]";
156 } else if (this.format.recordAndTupleSyntaxType === "hash") {
157 startToken = "#[";
158 endToken = "]";
159 } else {
160 throw new Error(`${this.format.recordAndTupleSyntaxType} is not a valid recordAndTuple syntax type`);
161 }
162
163 this.token(startToken);
164 this.printInnerComments(node);
165
166 for (let i = 0; i < elems.length; i++) {
167 const elem = elems[i];
168
169 if (elem) {
170 if (i > 0) this.space();
171 this.print(elem, node);
172 if (i < len - 1) this.token(",");
173 }
174 }
175
176 this.token(endToken);
177}
178
179function RegExpLiteral(node) {
180 this.word(`/${node.pattern}/${node.flags}`);
181}
182
183function BooleanLiteral(node) {
184 this.word(node.value ? "true" : "false");
185}
186
187function NullLiteral() {
188 this.word("null");
189}
190
191function NumericLiteral(node) {
192 const raw = this.getPossibleRaw(node);
193 const opts = this.format.jsescOption;
194 const value = node.value + "";
195
196 if (opts.numbers) {
197 this.number(_jsesc(node.value, opts));
198 } else if (raw == null) {
199 this.number(value);
200 } else if (this.format.minified) {
201 this.number(raw.length < value.length ? raw : value);
202 } else {
203 this.number(raw);
204 }
205}
206
207function StringLiteral(node) {
208 const raw = this.getPossibleRaw(node);
209
210 if (!this.format.minified && raw != null) {
211 this.token(raw);
212 return;
213 }
214
215 const val = _jsesc(node.value, Object.assign(this.format.jsescOption, this.format.jsonCompatibleStrings && {
216 json: true
217 }));
218
219 return this.token(val);
220}
221
222function BigIntLiteral(node) {
223 const raw = this.getPossibleRaw(node);
224
225 if (!this.format.minified && raw != null) {
226 this.word(raw);
227 return;
228 }
229
230 this.word(node.value + "n");
231}
232
233function DecimalLiteral(node) {
234 const raw = this.getPossibleRaw(node);
235
236 if (!this.format.minified && raw != null) {
237 this.word(raw);
238 return;
239 }
240
241 this.word(node.value + "m");
242}
243
244function PipelineTopicExpression(node) {
245 this.print(node.expression, node);
246}
247
248function PipelineBareFunction(node) {
249 this.print(node.callee, node);
250}
251
252function PipelinePrimaryTopicReference() {
253 this.token("#");
254}
Note: See TracBrowser for help on using the repository browser.