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