source: trip-planner-front/node_modules/@babel/generator/lib/generators/expressions.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: 6.9 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.UnaryExpression = UnaryExpression;
7exports.DoExpression = DoExpression;
8exports.ParenthesizedExpression = ParenthesizedExpression;
9exports.UpdateExpression = UpdateExpression;
10exports.ConditionalExpression = ConditionalExpression;
11exports.NewExpression = NewExpression;
12exports.SequenceExpression = SequenceExpression;
13exports.ThisExpression = ThisExpression;
14exports.Super = Super;
15exports.Decorator = Decorator;
16exports.OptionalMemberExpression = OptionalMemberExpression;
17exports.OptionalCallExpression = OptionalCallExpression;
18exports.CallExpression = CallExpression;
19exports.Import = Import;
20exports.EmptyStatement = EmptyStatement;
21exports.ExpressionStatement = ExpressionStatement;
22exports.AssignmentPattern = AssignmentPattern;
23exports.LogicalExpression = exports.BinaryExpression = exports.AssignmentExpression = AssignmentExpression;
24exports.BindExpression = BindExpression;
25exports.MemberExpression = MemberExpression;
26exports.MetaProperty = MetaProperty;
27exports.PrivateName = PrivateName;
28exports.V8IntrinsicIdentifier = V8IntrinsicIdentifier;
29exports.ModuleExpression = ModuleExpression;
30exports.AwaitExpression = exports.YieldExpression = void 0;
31
32var t = require("@babel/types");
33
34var n = require("../node");
35
36function UnaryExpression(node) {
37 if (node.operator === "void" || node.operator === "delete" || node.operator === "typeof" || node.operator === "throw") {
38 this.word(node.operator);
39 this.space();
40 } else {
41 this.token(node.operator);
42 }
43
44 this.print(node.argument, node);
45}
46
47function DoExpression(node) {
48 if (node.async) {
49 this.word("async");
50 this.space();
51 }
52
53 this.word("do");
54 this.space();
55 this.print(node.body, node);
56}
57
58function ParenthesizedExpression(node) {
59 this.token("(");
60 this.print(node.expression, node);
61 this.token(")");
62}
63
64function UpdateExpression(node) {
65 if (node.prefix) {
66 this.token(node.operator);
67 this.print(node.argument, node);
68 } else {
69 this.startTerminatorless(true);
70 this.print(node.argument, node);
71 this.endTerminatorless();
72 this.token(node.operator);
73 }
74}
75
76function ConditionalExpression(node) {
77 this.print(node.test, node);
78 this.space();
79 this.token("?");
80 this.space();
81 this.print(node.consequent, node);
82 this.space();
83 this.token(":");
84 this.space();
85 this.print(node.alternate, node);
86}
87
88function NewExpression(node, parent) {
89 this.word("new");
90 this.space();
91 this.print(node.callee, node);
92
93 if (this.format.minified && node.arguments.length === 0 && !node.optional && !t.isCallExpression(parent, {
94 callee: node
95 }) && !t.isMemberExpression(parent) && !t.isNewExpression(parent)) {
96 return;
97 }
98
99 this.print(node.typeArguments, node);
100 this.print(node.typeParameters, node);
101
102 if (node.optional) {
103 this.token("?.");
104 }
105
106 this.token("(");
107 this.printList(node.arguments, node);
108 this.token(")");
109}
110
111function SequenceExpression(node) {
112 this.printList(node.expressions, node);
113}
114
115function ThisExpression() {
116 this.word("this");
117}
118
119function Super() {
120 this.word("super");
121}
122
123function Decorator(node) {
124 this.token("@");
125 this.print(node.expression, node);
126 this.newline();
127}
128
129function OptionalMemberExpression(node) {
130 this.print(node.object, node);
131
132 if (!node.computed && t.isMemberExpression(node.property)) {
133 throw new TypeError("Got a MemberExpression for MemberExpression property");
134 }
135
136 let computed = node.computed;
137
138 if (t.isLiteral(node.property) && typeof node.property.value === "number") {
139 computed = true;
140 }
141
142 if (node.optional) {
143 this.token("?.");
144 }
145
146 if (computed) {
147 this.token("[");
148 this.print(node.property, node);
149 this.token("]");
150 } else {
151 if (!node.optional) {
152 this.token(".");
153 }
154
155 this.print(node.property, node);
156 }
157}
158
159function OptionalCallExpression(node) {
160 this.print(node.callee, node);
161 this.print(node.typeArguments, node);
162 this.print(node.typeParameters, node);
163
164 if (node.optional) {
165 this.token("?.");
166 }
167
168 this.token("(");
169 this.printList(node.arguments, node);
170 this.token(")");
171}
172
173function CallExpression(node) {
174 this.print(node.callee, node);
175 this.print(node.typeArguments, node);
176 this.print(node.typeParameters, node);
177 this.token("(");
178 this.printList(node.arguments, node);
179 this.token(")");
180}
181
182function Import() {
183 this.word("import");
184}
185
186function buildYieldAwait(keyword) {
187 return function (node) {
188 this.word(keyword);
189
190 if (node.delegate) {
191 this.token("*");
192 }
193
194 if (node.argument) {
195 this.space();
196 const terminatorState = this.startTerminatorless();
197 this.print(node.argument, node);
198 this.endTerminatorless(terminatorState);
199 }
200 };
201}
202
203const YieldExpression = buildYieldAwait("yield");
204exports.YieldExpression = YieldExpression;
205const AwaitExpression = buildYieldAwait("await");
206exports.AwaitExpression = AwaitExpression;
207
208function EmptyStatement() {
209 this.semicolon(true);
210}
211
212function ExpressionStatement(node) {
213 this.print(node.expression, node);
214 this.semicolon();
215}
216
217function AssignmentPattern(node) {
218 this.print(node.left, node);
219 if (node.left.optional) this.token("?");
220 this.print(node.left.typeAnnotation, node);
221 this.space();
222 this.token("=");
223 this.space();
224 this.print(node.right, node);
225}
226
227function AssignmentExpression(node, parent) {
228 const parens = this.inForStatementInitCounter && node.operator === "in" && !n.needsParens(node, parent);
229
230 if (parens) {
231 this.token("(");
232 }
233
234 this.print(node.left, node);
235 this.space();
236
237 if (node.operator === "in" || node.operator === "instanceof") {
238 this.word(node.operator);
239 } else {
240 this.token(node.operator);
241 }
242
243 this.space();
244 this.print(node.right, node);
245
246 if (parens) {
247 this.token(")");
248 }
249}
250
251function BindExpression(node) {
252 this.print(node.object, node);
253 this.token("::");
254 this.print(node.callee, node);
255}
256
257function MemberExpression(node) {
258 this.print(node.object, node);
259
260 if (!node.computed && t.isMemberExpression(node.property)) {
261 throw new TypeError("Got a MemberExpression for MemberExpression property");
262 }
263
264 let computed = node.computed;
265
266 if (t.isLiteral(node.property) && typeof node.property.value === "number") {
267 computed = true;
268 }
269
270 if (computed) {
271 this.token("[");
272 this.print(node.property, node);
273 this.token("]");
274 } else {
275 this.token(".");
276 this.print(node.property, node);
277 }
278}
279
280function MetaProperty(node) {
281 this.print(node.meta, node);
282 this.token(".");
283 this.print(node.property, node);
284}
285
286function PrivateName(node) {
287 this.token("#");
288 this.print(node.id, node);
289}
290
291function V8IntrinsicIdentifier(node) {
292 this.token("%");
293 this.word(node.name);
294}
295
296function ModuleExpression(node) {
297 this.word("module");
298 this.space();
299 this.token("{");
300
301 if (node.body.body.length === 0) {
302 this.token("}");
303 } else {
304 this.newline();
305 this.printSequence(node.body.body, node, {
306 indent: true
307 });
308 this.rightBrace();
309 }
310}
Note: See TracBrowser for help on using the repository browser.