1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.UnaryExpression = UnaryExpression;
|
---|
7 | exports.DoExpression = DoExpression;
|
---|
8 | exports.ParenthesizedExpression = ParenthesizedExpression;
|
---|
9 | exports.UpdateExpression = UpdateExpression;
|
---|
10 | exports.ConditionalExpression = ConditionalExpression;
|
---|
11 | exports.NewExpression = NewExpression;
|
---|
12 | exports.SequenceExpression = SequenceExpression;
|
---|
13 | exports.ThisExpression = ThisExpression;
|
---|
14 | exports.Super = Super;
|
---|
15 | exports.Decorator = Decorator;
|
---|
16 | exports.OptionalMemberExpression = OptionalMemberExpression;
|
---|
17 | exports.OptionalCallExpression = OptionalCallExpression;
|
---|
18 | exports.CallExpression = CallExpression;
|
---|
19 | exports.Import = Import;
|
---|
20 | exports.EmptyStatement = EmptyStatement;
|
---|
21 | exports.ExpressionStatement = ExpressionStatement;
|
---|
22 | exports.AssignmentPattern = AssignmentPattern;
|
---|
23 | exports.LogicalExpression = exports.BinaryExpression = exports.AssignmentExpression = AssignmentExpression;
|
---|
24 | exports.BindExpression = BindExpression;
|
---|
25 | exports.MemberExpression = MemberExpression;
|
---|
26 | exports.MetaProperty = MetaProperty;
|
---|
27 | exports.PrivateName = PrivateName;
|
---|
28 | exports.V8IntrinsicIdentifier = V8IntrinsicIdentifier;
|
---|
29 | exports.ModuleExpression = ModuleExpression;
|
---|
30 | exports.AwaitExpression = exports.YieldExpression = void 0;
|
---|
31 |
|
---|
32 | var t = require("@babel/types");
|
---|
33 |
|
---|
34 | var n = require("../node");
|
---|
35 |
|
---|
36 | function 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 |
|
---|
47 | function 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 |
|
---|
58 | function ParenthesizedExpression(node) {
|
---|
59 | this.token("(");
|
---|
60 | this.print(node.expression, node);
|
---|
61 | this.token(")");
|
---|
62 | }
|
---|
63 |
|
---|
64 | function 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 |
|
---|
76 | function 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 |
|
---|
88 | function 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 |
|
---|
111 | function SequenceExpression(node) {
|
---|
112 | this.printList(node.expressions, node);
|
---|
113 | }
|
---|
114 |
|
---|
115 | function ThisExpression() {
|
---|
116 | this.word("this");
|
---|
117 | }
|
---|
118 |
|
---|
119 | function Super() {
|
---|
120 | this.word("super");
|
---|
121 | }
|
---|
122 |
|
---|
123 | function Decorator(node) {
|
---|
124 | this.token("@");
|
---|
125 | this.print(node.expression, node);
|
---|
126 | this.newline();
|
---|
127 | }
|
---|
128 |
|
---|
129 | function 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 |
|
---|
159 | function 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 |
|
---|
173 | function 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 |
|
---|
182 | function Import() {
|
---|
183 | this.word("import");
|
---|
184 | }
|
---|
185 |
|
---|
186 | function 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 |
|
---|
203 | const YieldExpression = buildYieldAwait("yield");
|
---|
204 | exports.YieldExpression = YieldExpression;
|
---|
205 | const AwaitExpression = buildYieldAwait("await");
|
---|
206 | exports.AwaitExpression = AwaitExpression;
|
---|
207 |
|
---|
208 | function EmptyStatement() {
|
---|
209 | this.semicolon(true);
|
---|
210 | }
|
---|
211 |
|
---|
212 | function ExpressionStatement(node) {
|
---|
213 | this.print(node.expression, node);
|
---|
214 | this.semicolon();
|
---|
215 | }
|
---|
216 |
|
---|
217 | function 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 |
|
---|
227 | function 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 |
|
---|
251 | function BindExpression(node) {
|
---|
252 | this.print(node.object, node);
|
---|
253 | this.token("::");
|
---|
254 | this.print(node.callee, node);
|
---|
255 | }
|
---|
256 |
|
---|
257 | function 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 |
|
---|
280 | function MetaProperty(node) {
|
---|
281 | this.print(node.meta, node);
|
---|
282 | this.token(".");
|
---|
283 | this.print(node.property, node);
|
---|
284 | }
|
---|
285 |
|
---|
286 | function PrivateName(node) {
|
---|
287 | this.token("#");
|
---|
288 | this.print(node.id, node);
|
---|
289 | }
|
---|
290 |
|
---|
291 | function V8IntrinsicIdentifier(node) {
|
---|
292 | this.token("%");
|
---|
293 | this.word(node.name);
|
---|
294 | }
|
---|
295 |
|
---|
296 | function 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 | } |
---|