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