1 | "use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var _flow = require('../plugins/flow');
|
32 | var _index = require('../plugins/jsx/index');
|
33 | var _types = require('../plugins/types');
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | var _typescript = require('../plugins/typescript');
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | var _index3 = require('../tokenizer/index');
|
56 | var _keywords = require('../tokenizer/keywords');
|
57 | var _state = require('../tokenizer/state');
|
58 | var _types3 = require('../tokenizer/types');
|
59 | var _base = require('./base');
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | var _lval = require('./lval');
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | var _statement = require('./statement');
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | var _util = require('./util');
|
82 |
|
83 | class StopState {
|
84 |
|
85 | constructor(stop) {
|
86 | this.stop = stop;
|
87 | }
|
88 | } exports.StopState = StopState;
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | function parseExpression(noIn = false) {
|
98 | parseMaybeAssign(noIn);
|
99 | if (_index3.match.call(void 0, _types3.TokenType.comma)) {
|
100 | while (_index3.eat.call(void 0, _types3.TokenType.comma)) {
|
101 | parseMaybeAssign(noIn);
|
102 | }
|
103 | }
|
104 | } exports.parseExpression = parseExpression;
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | function parseMaybeAssign(noIn = false, isWithinParens = false) {
|
114 | if (_base.isTypeScriptEnabled) {
|
115 | return _typescript.tsParseMaybeAssign.call(void 0, noIn, isWithinParens);
|
116 | } else if (_base.isFlowEnabled) {
|
117 | return _flow.flowParseMaybeAssign.call(void 0, noIn, isWithinParens);
|
118 | } else {
|
119 | return baseParseMaybeAssign(noIn, isWithinParens);
|
120 | }
|
121 | } exports.parseMaybeAssign = parseMaybeAssign;
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | function baseParseMaybeAssign(noIn, isWithinParens) {
|
127 | if (_index3.match.call(void 0, _types3.TokenType._yield)) {
|
128 | parseYield();
|
129 | return false;
|
130 | }
|
131 |
|
132 | if (_index3.match.call(void 0, _types3.TokenType.parenL) || _index3.match.call(void 0, _types3.TokenType.name) || _index3.match.call(void 0, _types3.TokenType._yield)) {
|
133 | _base.state.potentialArrowAt = _base.state.start;
|
134 | }
|
135 |
|
136 | const wasArrow = parseMaybeConditional(noIn);
|
137 | if (isWithinParens) {
|
138 | parseParenItem();
|
139 | }
|
140 | if (_base.state.type & _types3.TokenType.IS_ASSIGN) {
|
141 | _index3.next.call(void 0, );
|
142 | parseMaybeAssign(noIn);
|
143 | return false;
|
144 | }
|
145 | return wasArrow;
|
146 | } exports.baseParseMaybeAssign = baseParseMaybeAssign;
|
147 |
|
148 |
|
149 |
|
150 | function parseMaybeConditional(noIn) {
|
151 | const wasArrow = parseExprOps(noIn);
|
152 | if (wasArrow) {
|
153 | return true;
|
154 | }
|
155 | parseConditional(noIn);
|
156 | return false;
|
157 | }
|
158 |
|
159 | function parseConditional(noIn) {
|
160 | if (_base.isTypeScriptEnabled || _base.isFlowEnabled) {
|
161 | _types.typedParseConditional.call(void 0, noIn);
|
162 | } else {
|
163 | baseParseConditional(noIn);
|
164 | }
|
165 | }
|
166 |
|
167 | function baseParseConditional(noIn) {
|
168 | if (_index3.eat.call(void 0, _types3.TokenType.question)) {
|
169 | parseMaybeAssign();
|
170 | _util.expect.call(void 0, _types3.TokenType.colon);
|
171 | parseMaybeAssign(noIn);
|
172 | }
|
173 | } exports.baseParseConditional = baseParseConditional;
|
174 |
|
175 |
|
176 |
|
177 | function parseExprOps(noIn) {
|
178 | const wasArrow = parseMaybeUnary();
|
179 | if (wasArrow) {
|
180 | return true;
|
181 | }
|
182 | parseExprOp(-1, noIn);
|
183 | return false;
|
184 | }
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | function parseExprOp(minPrec, noIn) {
|
192 | if (
|
193 | _base.isTypeScriptEnabled &&
|
194 | (_types3.TokenType._in & _types3.TokenType.PRECEDENCE_MASK) > minPrec &&
|
195 | !_util.hasPrecedingLineBreak.call(void 0, ) &&
|
196 | _util.eatContextual.call(void 0, _keywords.ContextualKeyword._as)
|
197 | ) {
|
198 | _base.state.tokens[_base.state.tokens.length - 1].type = _types3.TokenType._as;
|
199 | const oldIsType = _index3.pushTypeContext.call(void 0, 1);
|
200 | _typescript.tsParseType.call(void 0, );
|
201 | _index3.popTypeContext.call(void 0, oldIsType);
|
202 | parseExprOp(minPrec, noIn);
|
203 | return;
|
204 | }
|
205 |
|
206 | const prec = _base.state.type & _types3.TokenType.PRECEDENCE_MASK;
|
207 | if (prec > 0 && (!noIn || !_index3.match.call(void 0, _types3.TokenType._in))) {
|
208 | if (prec > minPrec) {
|
209 | const op = _base.state.type;
|
210 | _index3.next.call(void 0, );
|
211 |
|
212 | parseMaybeUnary();
|
213 | parseExprOp(op & _types3.TokenType.IS_RIGHT_ASSOCIATIVE ? prec - 1 : prec, noIn);
|
214 | parseExprOp(minPrec, noIn);
|
215 | }
|
216 | }
|
217 | }
|
218 |
|
219 |
|
220 |
|
221 | function parseMaybeUnary() {
|
222 | if (_base.isTypeScriptEnabled && !_base.isJSXEnabled && _index3.eat.call(void 0, _types3.TokenType.lessThan)) {
|
223 | _typescript.tsParseTypeAssertion.call(void 0, );
|
224 | return false;
|
225 | }
|
226 |
|
227 | if (_base.state.type & _types3.TokenType.IS_PREFIX) {
|
228 | _index3.next.call(void 0, );
|
229 | parseMaybeUnary();
|
230 | return false;
|
231 | }
|
232 |
|
233 | const wasArrow = parseExprSubscripts();
|
234 | if (wasArrow) {
|
235 | return true;
|
236 | }
|
237 | while (_base.state.type & _types3.TokenType.IS_POSTFIX && !_util.canInsertSemicolon.call(void 0, )) {
|
238 |
|
239 |
|
240 | if (_base.state.type === _types3.TokenType.preIncDec) {
|
241 | _base.state.type = _types3.TokenType.postIncDec;
|
242 | }
|
243 | _index3.next.call(void 0, );
|
244 | }
|
245 | return false;
|
246 | } exports.parseMaybeUnary = parseMaybeUnary;
|
247 |
|
248 |
|
249 |
|
250 | function parseExprSubscripts() {
|
251 | const startPos = _base.state.start;
|
252 | const wasArrow = parseExprAtom();
|
253 | if (wasArrow) {
|
254 | return true;
|
255 | }
|
256 | parseSubscripts(startPos);
|
257 | return false;
|
258 | } exports.parseExprSubscripts = parseExprSubscripts;
|
259 |
|
260 | function parseSubscripts(startPos, noCalls = false) {
|
261 | if (_base.isFlowEnabled) {
|
262 | _flow.flowParseSubscripts.call(void 0, startPos, noCalls);
|
263 | } else {
|
264 | baseParseSubscripts(startPos, noCalls);
|
265 | }
|
266 | }
|
267 |
|
268 | function baseParseSubscripts(startPos, noCalls = false) {
|
269 | const stopState = new StopState(false);
|
270 | do {
|
271 | parseSubscript(startPos, noCalls, stopState);
|
272 | } while (!stopState.stop && !_base.state.error);
|
273 | } exports.baseParseSubscripts = baseParseSubscripts;
|
274 |
|
275 | function parseSubscript(startPos, noCalls, stopState) {
|
276 | if (_base.isTypeScriptEnabled) {
|
277 | _typescript.tsParseSubscript.call(void 0, startPos, noCalls, stopState);
|
278 | } else if (_base.isFlowEnabled) {
|
279 | _flow.flowParseSubscript.call(void 0, startPos, noCalls, stopState);
|
280 | } else {
|
281 | baseParseSubscript(startPos, noCalls, stopState);
|
282 | }
|
283 | }
|
284 |
|
285 |
|
286 | function baseParseSubscript(startPos, noCalls, stopState) {
|
287 | if (!noCalls && _index3.eat.call(void 0, _types3.TokenType.doubleColon)) {
|
288 | parseNoCallExpr();
|
289 | stopState.stop = true;
|
290 | parseSubscripts(startPos, noCalls);
|
291 | } else if (_index3.match.call(void 0, _types3.TokenType.questionDot)) {
|
292 | if (noCalls && _index3.lookaheadType.call(void 0, ) === _types3.TokenType.parenL) {
|
293 | stopState.stop = true;
|
294 | return;
|
295 | }
|
296 | _index3.next.call(void 0, );
|
297 |
|
298 | if (_index3.eat.call(void 0, _types3.TokenType.bracketL)) {
|
299 | parseExpression();
|
300 | _util.expect.call(void 0, _types3.TokenType.bracketR);
|
301 | } else if (_index3.eat.call(void 0, _types3.TokenType.parenL)) {
|
302 | parseCallExpressionArguments();
|
303 | } else {
|
304 | parseIdentifier();
|
305 | }
|
306 | } else if (_index3.eat.call(void 0, _types3.TokenType.dot)) {
|
307 | parseMaybePrivateName();
|
308 | } else if (_index3.eat.call(void 0, _types3.TokenType.bracketL)) {
|
309 | parseExpression();
|
310 | _util.expect.call(void 0, _types3.TokenType.bracketR);
|
311 | } else if (!noCalls && _index3.match.call(void 0, _types3.TokenType.parenL)) {
|
312 | if (atPossibleAsync()) {
|
313 |
|
314 |
|
315 | const snapshot = _base.state.snapshot();
|
316 | const startTokenIndex = _base.state.tokens.length;
|
317 | _index3.next.call(void 0, );
|
318 |
|
319 | const callContextId = _base.getNextContextId.call(void 0, );
|
320 |
|
321 | _base.state.tokens[_base.state.tokens.length - 1].contextId = callContextId;
|
322 | parseCallExpressionArguments();
|
323 | _base.state.tokens[_base.state.tokens.length - 1].contextId = callContextId;
|
324 |
|
325 | if (shouldParseAsyncArrow()) {
|
326 |
|
327 | _base.state.restoreFromSnapshot(snapshot);
|
328 | stopState.stop = true;
|
329 | _base.state.scopeDepth++;
|
330 |
|
331 | _statement.parseFunctionParams.call(void 0, );
|
332 | parseAsyncArrowFromCallExpression(startPos, startTokenIndex);
|
333 | }
|
334 | } else {
|
335 | _index3.next.call(void 0, );
|
336 | const callContextId = _base.getNextContextId.call(void 0, );
|
337 | _base.state.tokens[_base.state.tokens.length - 1].contextId = callContextId;
|
338 | parseCallExpressionArguments();
|
339 | _base.state.tokens[_base.state.tokens.length - 1].contextId = callContextId;
|
340 | }
|
341 | } else if (_index3.match.call(void 0, _types3.TokenType.backQuote)) {
|
342 |
|
343 | parseTemplate();
|
344 | } else {
|
345 | stopState.stop = true;
|
346 | }
|
347 | } exports.baseParseSubscript = baseParseSubscript;
|
348 |
|
349 | function atPossibleAsync() {
|
350 |
|
351 |
|
352 | return (
|
353 | _base.state.tokens[_base.state.tokens.length - 1].contextualKeyword === _keywords.ContextualKeyword._async &&
|
354 | !_util.canInsertSemicolon.call(void 0, )
|
355 | );
|
356 | } exports.atPossibleAsync = atPossibleAsync;
|
357 |
|
358 | function parseCallExpressionArguments() {
|
359 | let first = true;
|
360 | while (!_index3.eat.call(void 0, _types3.TokenType.parenR) && !_base.state.error) {
|
361 | if (first) {
|
362 | first = false;
|
363 | } else {
|
364 | _util.expect.call(void 0, _types3.TokenType.comma);
|
365 | if (_index3.eat.call(void 0, _types3.TokenType.parenR)) {
|
366 | break;
|
367 | }
|
368 | }
|
369 |
|
370 | parseExprListItem(false);
|
371 | }
|
372 | } exports.parseCallExpressionArguments = parseCallExpressionArguments;
|
373 |
|
374 | function shouldParseAsyncArrow() {
|
375 | return _index3.match.call(void 0, _types3.TokenType.colon) || _index3.match.call(void 0, _types3.TokenType.arrow);
|
376 | }
|
377 |
|
378 | function parseAsyncArrowFromCallExpression(functionStart, startTokenIndex) {
|
379 | if (_base.isTypeScriptEnabled) {
|
380 | _typescript.tsStartParseAsyncArrowFromCallExpression.call(void 0, );
|
381 | } else if (_base.isFlowEnabled) {
|
382 | _flow.flowStartParseAsyncArrowFromCallExpression.call(void 0, );
|
383 | }
|
384 | _util.expect.call(void 0, _types3.TokenType.arrow);
|
385 | parseArrowExpression(functionStart, startTokenIndex);
|
386 | }
|
387 |
|
388 |
|
389 |
|
390 | function parseNoCallExpr() {
|
391 | const startPos = _base.state.start;
|
392 | parseExprAtom();
|
393 | parseSubscripts(startPos, true);
|
394 | }
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 | function parseExprAtom() {
|
402 | if (_index3.match.call(void 0, _types3.TokenType.jsxText)) {
|
403 | parseLiteral();
|
404 | return false;
|
405 | } else if (_index3.match.call(void 0, _types3.TokenType.lessThan) && _base.isJSXEnabled) {
|
406 | _base.state.type = _types3.TokenType.jsxTagStart;
|
407 | _index.jsxParseElement.call(void 0, );
|
408 | _index3.next.call(void 0, );
|
409 | return false;
|
410 | }
|
411 |
|
412 | const canBeArrow = _base.state.potentialArrowAt === _base.state.start;
|
413 | switch (_base.state.type) {
|
414 | case _types3.TokenType.slash:
|
415 | case _types3.TokenType.assign:
|
416 | _index3.retokenizeSlashAsRegex.call(void 0, );
|
417 |
|
418 |
|
419 | case _types3.TokenType._super:
|
420 | case _types3.TokenType._this:
|
421 | case _types3.TokenType.regexp:
|
422 | case _types3.TokenType.num:
|
423 | case _types3.TokenType.bigint:
|
424 | case _types3.TokenType.string:
|
425 | case _types3.TokenType._null:
|
426 | case _types3.TokenType._true:
|
427 | case _types3.TokenType._false:
|
428 | _index3.next.call(void 0, );
|
429 | return false;
|
430 |
|
431 | case _types3.TokenType._import:
|
432 | if (_index3.lookaheadType.call(void 0, ) === _types3.TokenType.dot) {
|
433 | parseImportMetaProperty();
|
434 | return false;
|
435 | }
|
436 | _index3.next.call(void 0, );
|
437 | return false;
|
438 |
|
439 | case _types3.TokenType.name: {
|
440 | const startTokenIndex = _base.state.tokens.length;
|
441 | const functionStart = _base.state.start;
|
442 | const contextualKeyword = _base.state.contextualKeyword;
|
443 | parseIdentifier();
|
444 | if (contextualKeyword === _keywords.ContextualKeyword._await) {
|
445 | parseAwait();
|
446 | return false;
|
447 | } else if (
|
448 | contextualKeyword === _keywords.ContextualKeyword._async &&
|
449 | _index3.match.call(void 0, _types3.TokenType._function) &&
|
450 | !_util.canInsertSemicolon.call(void 0, )
|
451 | ) {
|
452 | _index3.next.call(void 0, );
|
453 | _statement.parseFunction.call(void 0, functionStart, false, false);
|
454 | return false;
|
455 | } else if (
|
456 | canBeArrow &&
|
457 | !_util.canInsertSemicolon.call(void 0, ) &&
|
458 | contextualKeyword === _keywords.ContextualKeyword._async &&
|
459 | _index3.match.call(void 0, _types3.TokenType.name)
|
460 | ) {
|
461 | _base.state.scopeDepth++;
|
462 | _lval.parseBindingIdentifier.call(void 0, false);
|
463 | _util.expect.call(void 0, _types3.TokenType.arrow);
|
464 |
|
465 | parseArrowExpression(functionStart, startTokenIndex);
|
466 | return true;
|
467 | }
|
468 |
|
469 | if (canBeArrow && !_util.canInsertSemicolon.call(void 0, ) && _index3.match.call(void 0, _types3.TokenType.arrow)) {
|
470 | _base.state.scopeDepth++;
|
471 | _lval.markPriorBindingIdentifier.call(void 0, false);
|
472 | _util.expect.call(void 0, _types3.TokenType.arrow);
|
473 | parseArrowExpression(functionStart, startTokenIndex);
|
474 | return true;
|
475 | }
|
476 |
|
477 | _base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index3.IdentifierRole.Access;
|
478 | return false;
|
479 | }
|
480 |
|
481 | case _types3.TokenType._do: {
|
482 | _index3.next.call(void 0, );
|
483 | _statement.parseBlock.call(void 0, false);
|
484 | return false;
|
485 | }
|
486 |
|
487 | case _types3.TokenType.parenL: {
|
488 | const wasArrow = parseParenAndDistinguishExpression(canBeArrow);
|
489 | return wasArrow;
|
490 | }
|
491 |
|
492 | case _types3.TokenType.bracketL:
|
493 | _index3.next.call(void 0, );
|
494 | parseExprList(_types3.TokenType.bracketR, true);
|
495 | return false;
|
496 |
|
497 | case _types3.TokenType.braceL:
|
498 | parseObj(false, false);
|
499 | return false;
|
500 |
|
501 | case _types3.TokenType._function:
|
502 | parseFunctionExpression();
|
503 | return false;
|
504 |
|
505 | case _types3.TokenType.at:
|
506 | _statement.parseDecorators.call(void 0, );
|
507 |
|
508 |
|
509 | case _types3.TokenType._class:
|
510 | _statement.parseClass.call(void 0, false);
|
511 | return false;
|
512 |
|
513 | case _types3.TokenType._new:
|
514 | parseNew();
|
515 | return false;
|
516 |
|
517 | case _types3.TokenType.backQuote:
|
518 | parseTemplate();
|
519 | return false;
|
520 |
|
521 | case _types3.TokenType.doubleColon: {
|
522 | _index3.next.call(void 0, );
|
523 | parseNoCallExpr();
|
524 | return false;
|
525 | }
|
526 |
|
527 | default:
|
528 | _util.unexpected.call(void 0, );
|
529 | return false;
|
530 | }
|
531 | } exports.parseExprAtom = parseExprAtom;
|
532 |
|
533 | function parseMaybePrivateName() {
|
534 | _index3.eat.call(void 0, _types3.TokenType.hash);
|
535 | parseIdentifier();
|
536 | }
|
537 |
|
538 | function parseFunctionExpression() {
|
539 | const functionStart = _base.state.start;
|
540 | parseIdentifier();
|
541 | if (_index3.eat.call(void 0, _types3.TokenType.dot)) {
|
542 |
|
543 | parseMetaProperty();
|
544 | }
|
545 | _statement.parseFunction.call(void 0, functionStart, false);
|
546 | }
|
547 |
|
548 | function parseMetaProperty() {
|
549 | parseIdentifier();
|
550 | }
|
551 |
|
552 | function parseImportMetaProperty() {
|
553 | parseIdentifier();
|
554 | _util.expect.call(void 0, _types3.TokenType.dot);
|
555 |
|
556 | parseMetaProperty();
|
557 | }
|
558 |
|
559 | function parseLiteral() {
|
560 | _index3.next.call(void 0, );
|
561 | } exports.parseLiteral = parseLiteral;
|
562 |
|
563 | function parseParenExpression() {
|
564 | _util.expect.call(void 0, _types3.TokenType.parenL);
|
565 | parseExpression();
|
566 | _util.expect.call(void 0, _types3.TokenType.parenR);
|
567 | } exports.parseParenExpression = parseParenExpression;
|
568 |
|
569 |
|
570 | function parseParenAndDistinguishExpression(canBeArrow) {
|
571 |
|
572 |
|
573 | const snapshot = _base.state.snapshot();
|
574 |
|
575 | const startTokenIndex = _base.state.tokens.length;
|
576 | _util.expect.call(void 0, _types3.TokenType.parenL);
|
577 |
|
578 | let first = true;
|
579 |
|
580 | while (!_index3.match.call(void 0, _types3.TokenType.parenR) && !_base.state.error) {
|
581 | if (first) {
|
582 | first = false;
|
583 | } else {
|
584 | _util.expect.call(void 0, _types3.TokenType.comma);
|
585 | if (_index3.match.call(void 0, _types3.TokenType.parenR)) {
|
586 | break;
|
587 | }
|
588 | }
|
589 |
|
590 | if (_index3.match.call(void 0, _types3.TokenType.ellipsis)) {
|
591 | _lval.parseRest.call(void 0, false );
|
592 | parseParenItem();
|
593 | break;
|
594 | } else {
|
595 | parseMaybeAssign(false, true);
|
596 | }
|
597 | }
|
598 |
|
599 | _util.expect.call(void 0, _types3.TokenType.parenR);
|
600 |
|
601 | if (canBeArrow && shouldParseArrow()) {
|
602 | const wasArrow = parseArrow();
|
603 | if (wasArrow) {
|
604 |
|
605 |
|
606 | _base.state.restoreFromSnapshot(snapshot);
|
607 | _base.state.scopeDepth++;
|
608 |
|
609 | const functionStart = _base.state.start;
|
610 |
|
611 | _statement.parseFunctionParams.call(void 0, );
|
612 | parseArrow();
|
613 | parseArrowExpression(functionStart, startTokenIndex);
|
614 | return true;
|
615 | }
|
616 | }
|
617 |
|
618 | return false;
|
619 | }
|
620 |
|
621 | function shouldParseArrow() {
|
622 | return _index3.match.call(void 0, _types3.TokenType.colon) || !_util.canInsertSemicolon.call(void 0, );
|
623 | }
|
624 |
|
625 |
|
626 | function parseArrow() {
|
627 | if (_base.isTypeScriptEnabled) {
|
628 | return _typescript.tsParseArrow.call(void 0, );
|
629 | } else if (_base.isFlowEnabled) {
|
630 | return _flow.flowParseArrow.call(void 0, );
|
631 | } else {
|
632 | return _index3.eat.call(void 0, _types3.TokenType.arrow);
|
633 | }
|
634 | } exports.parseArrow = parseArrow;
|
635 |
|
636 | function parseParenItem() {
|
637 | if (_base.isTypeScriptEnabled || _base.isFlowEnabled) {
|
638 | _types.typedParseParenItem.call(void 0, );
|
639 | }
|
640 | }
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 | function parseNew() {
|
648 | _util.expect.call(void 0, _types3.TokenType._new);
|
649 | if (_index3.eat.call(void 0, _types3.TokenType.dot)) {
|
650 |
|
651 | parseMetaProperty();
|
652 | return;
|
653 | }
|
654 | parseNoCallExpr();
|
655 | _index3.eat.call(void 0, _types3.TokenType.questionDot);
|
656 | parseNewArguments();
|
657 | }
|
658 |
|
659 | function parseNewArguments() {
|
660 | if (_base.isTypeScriptEnabled) {
|
661 | _typescript.tsStartParseNewArguments.call(void 0, );
|
662 | } else if (_base.isFlowEnabled) {
|
663 | _flow.flowStartParseNewArguments.call(void 0, );
|
664 | }
|
665 | if (_index3.eat.call(void 0, _types3.TokenType.parenL)) {
|
666 | parseExprList(_types3.TokenType.parenR);
|
667 | }
|
668 | }
|
669 |
|
670 | function parseTemplate() {
|
671 |
|
672 | _index3.nextTemplateToken.call(void 0, );
|
673 |
|
674 | _index3.nextTemplateToken.call(void 0, );
|
675 | while (!_index3.match.call(void 0, _types3.TokenType.backQuote) && !_base.state.error) {
|
676 | _util.expect.call(void 0, _types3.TokenType.dollarBraceL);
|
677 | parseExpression();
|
678 |
|
679 | _index3.nextTemplateToken.call(void 0, );
|
680 |
|
681 | _index3.nextTemplateToken.call(void 0, );
|
682 | }
|
683 | _index3.next.call(void 0, );
|
684 | } exports.parseTemplate = parseTemplate;
|
685 |
|
686 |
|
687 | function parseObj(isPattern, isBlockScope) {
|
688 |
|
689 | const contextId = _base.getNextContextId.call(void 0, );
|
690 | let first = true;
|
691 |
|
692 | _index3.next.call(void 0, );
|
693 | _base.state.tokens[_base.state.tokens.length - 1].contextId = contextId;
|
694 |
|
695 | while (!_index3.eat.call(void 0, _types3.TokenType.braceR) && !_base.state.error) {
|
696 | if (first) {
|
697 | first = false;
|
698 | } else {
|
699 | _util.expect.call(void 0, _types3.TokenType.comma);
|
700 | if (_index3.eat.call(void 0, _types3.TokenType.braceR)) {
|
701 | break;
|
702 | }
|
703 | }
|
704 |
|
705 | let isGenerator = false;
|
706 | if (_index3.match.call(void 0, _types3.TokenType.ellipsis)) {
|
707 | const previousIndex = _base.state.tokens.length;
|
708 | _lval.parseSpread.call(void 0, );
|
709 | if (isPattern) {
|
710 |
|
711 | if (_base.state.tokens.length === previousIndex + 2) {
|
712 | _lval.markPriorBindingIdentifier.call(void 0, isBlockScope);
|
713 | }
|
714 | if (_index3.eat.call(void 0, _types3.TokenType.braceR)) {
|
715 | break;
|
716 | }
|
717 | }
|
718 | continue;
|
719 | }
|
720 |
|
721 | if (!isPattern) {
|
722 | isGenerator = _index3.eat.call(void 0, _types3.TokenType.star);
|
723 | }
|
724 |
|
725 | if (!isPattern && _util.isContextual.call(void 0, _keywords.ContextualKeyword._async)) {
|
726 | if (isGenerator) _util.unexpected.call(void 0, );
|
727 |
|
728 | parseIdentifier();
|
729 | if (
|
730 | _index3.match.call(void 0, _types3.TokenType.colon) ||
|
731 | _index3.match.call(void 0, _types3.TokenType.parenL) ||
|
732 | _index3.match.call(void 0, _types3.TokenType.braceR) ||
|
733 | _index3.match.call(void 0, _types3.TokenType.eq) ||
|
734 | _index3.match.call(void 0, _types3.TokenType.comma)
|
735 | ) {
|
736 |
|
737 | } else {
|
738 | if (_index3.match.call(void 0, _types3.TokenType.star)) {
|
739 | _index3.next.call(void 0, );
|
740 | isGenerator = true;
|
741 | }
|
742 | parsePropertyName(contextId);
|
743 | }
|
744 | } else {
|
745 | parsePropertyName(contextId);
|
746 | }
|
747 |
|
748 | parseObjPropValue(isGenerator, isPattern, isBlockScope, contextId);
|
749 | }
|
750 |
|
751 | _base.state.tokens[_base.state.tokens.length - 1].contextId = contextId;
|
752 | } exports.parseObj = parseObj;
|
753 |
|
754 | function isGetterOrSetterMethod(isPattern) {
|
755 |
|
756 |
|
757 | return (
|
758 | !isPattern &&
|
759 | (_index3.match.call(void 0, _types3.TokenType.string) ||
|
760 | _index3.match.call(void 0, _types3.TokenType.num) ||
|
761 | _index3.match.call(void 0, _types3.TokenType.bracketL) ||
|
762 | _index3.match.call(void 0, _types3.TokenType.name) ||
|
763 | !!(_base.state.type & _types3.TokenType.IS_KEYWORD))
|
764 | );
|
765 | }
|
766 |
|
767 |
|
768 | function parseObjectMethod(
|
769 | isGenerator,
|
770 | isPattern,
|
771 | objectContextId,
|
772 | ) {
|
773 |
|
774 |
|
775 | const functionStart = _base.state.start;
|
776 | if (_index3.match.call(void 0, _types3.TokenType.parenL)) {
|
777 | if (isPattern) _util.unexpected.call(void 0, );
|
778 | parseMethod(functionStart, isGenerator, false);
|
779 | return true;
|
780 | }
|
781 |
|
782 | if (isGetterOrSetterMethod(isPattern)) {
|
783 | parsePropertyName(objectContextId);
|
784 | parseMethod(functionStart, false, false);
|
785 | return true;
|
786 | }
|
787 | return false;
|
788 | }
|
789 |
|
790 | function parseObjectProperty(isPattern, isBlockScope) {
|
791 | if (_index3.eat.call(void 0, _types3.TokenType.colon)) {
|
792 | if (isPattern) {
|
793 | _lval.parseMaybeDefault.call(void 0, isBlockScope);
|
794 | } else {
|
795 | parseMaybeAssign(false);
|
796 | }
|
797 | return;
|
798 | }
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 | if (isPattern) {
|
806 | _base.state.tokens[_base.state.tokens.length - 1].identifierRole = isBlockScope
|
807 | ? _index3.IdentifierRole.ObjectShorthandBlockScopedDeclaration
|
808 | : _index3.IdentifierRole.ObjectShorthandFunctionScopedDeclaration;
|
809 | } else {
|
810 | _base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index3.IdentifierRole.ObjectShorthand;
|
811 | }
|
812 |
|
813 |
|
814 |
|
815 | _lval.parseMaybeDefault.call(void 0, isBlockScope, true);
|
816 | }
|
817 |
|
818 | function parseObjPropValue(
|
819 | isGenerator,
|
820 | isPattern,
|
821 | isBlockScope,
|
822 | objectContextId,
|
823 | ) {
|
824 | if (_base.isTypeScriptEnabled) {
|
825 | _typescript.tsStartParseObjPropValue.call(void 0, );
|
826 | } else if (_base.isFlowEnabled) {
|
827 | _flow.flowStartParseObjPropValue.call(void 0, );
|
828 | }
|
829 | const wasMethod = parseObjectMethod(isGenerator, isPattern, objectContextId);
|
830 | if (!wasMethod) {
|
831 | parseObjectProperty(isPattern, isBlockScope);
|
832 | }
|
833 | }
|
834 |
|
835 | function parsePropertyName(objectContextId) {
|
836 | if (_base.isFlowEnabled) {
|
837 | _flow.flowParseVariance.call(void 0, );
|
838 | }
|
839 | if (_index3.eat.call(void 0, _types3.TokenType.bracketL)) {
|
840 | _base.state.tokens[_base.state.tokens.length - 1].contextId = objectContextId;
|
841 | parseMaybeAssign();
|
842 | _util.expect.call(void 0, _types3.TokenType.bracketR);
|
843 | _base.state.tokens[_base.state.tokens.length - 1].contextId = objectContextId;
|
844 | } else {
|
845 | if (_index3.match.call(void 0, _types3.TokenType.num) || _index3.match.call(void 0, _types3.TokenType.string)) {
|
846 | parseExprAtom();
|
847 | } else {
|
848 | parseMaybePrivateName();
|
849 | }
|
850 |
|
851 | _base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index3.IdentifierRole.ObjectKey;
|
852 | _base.state.tokens[_base.state.tokens.length - 1].contextId = objectContextId;
|
853 | }
|
854 | } exports.parsePropertyName = parsePropertyName;
|
855 |
|
856 |
|
857 | function parseMethod(
|
858 | functionStart,
|
859 | isGenerator,
|
860 | isConstructor,
|
861 | ) {
|
862 | const funcContextId = _base.getNextContextId.call(void 0, );
|
863 |
|
864 | _base.state.scopeDepth++;
|
865 | const startTokenIndex = _base.state.tokens.length;
|
866 | const allowModifiers = isConstructor;
|
867 | _statement.parseFunctionParams.call(void 0, allowModifiers, funcContextId);
|
868 | parseFunctionBodyAndFinish(
|
869 | functionStart,
|
870 | isGenerator,
|
871 | false ,
|
872 | funcContextId,
|
873 | );
|
874 | const endTokenIndex = _base.state.tokens.length;
|
875 | _base.state.scopes.push(new (0, _state.Scope)(startTokenIndex, endTokenIndex, true));
|
876 | _base.state.scopeDepth--;
|
877 | } exports.parseMethod = parseMethod;
|
878 |
|
879 |
|
880 |
|
881 |
|
882 | function parseArrowExpression(functionStart, startTokenIndex) {
|
883 | parseFunctionBody(functionStart, false , true);
|
884 | const endTokenIndex = _base.state.tokens.length;
|
885 | _base.state.scopes.push(new (0, _state.Scope)(startTokenIndex, endTokenIndex, true));
|
886 | _base.state.scopeDepth--;
|
887 | } exports.parseArrowExpression = parseArrowExpression;
|
888 |
|
889 | function parseFunctionBodyAndFinish(
|
890 | functionStart,
|
891 | isGenerator,
|
892 | allowExpressionBody = false,
|
893 | funcContextId = 0,
|
894 | ) {
|
895 | if (_base.isTypeScriptEnabled) {
|
896 | _typescript.tsParseFunctionBodyAndFinish.call(void 0, functionStart, isGenerator, allowExpressionBody, funcContextId);
|
897 | } else if (_base.isFlowEnabled) {
|
898 | _flow.flowParseFunctionBodyAndFinish.call(void 0, functionStart, isGenerator, allowExpressionBody, funcContextId);
|
899 | } else {
|
900 | parseFunctionBody(functionStart, isGenerator, allowExpressionBody, funcContextId);
|
901 | }
|
902 | } exports.parseFunctionBodyAndFinish = parseFunctionBodyAndFinish;
|
903 |
|
904 |
|
905 | function parseFunctionBody(
|
906 | functionStart,
|
907 | isGenerator,
|
908 | allowExpression,
|
909 | funcContextId = 0,
|
910 | ) {
|
911 | const isExpression = allowExpression && !_index3.match.call(void 0, _types3.TokenType.braceL);
|
912 |
|
913 | if (isExpression) {
|
914 | parseMaybeAssign();
|
915 | } else {
|
916 | _statement.parseBlock.call(void 0, true , true , funcContextId);
|
917 | }
|
918 | } exports.parseFunctionBody = parseFunctionBody;
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 |
|
926 | function parseExprList(close, allowEmpty = false) {
|
927 | let first = true;
|
928 | while (!_index3.eat.call(void 0, close) && !_base.state.error) {
|
929 | if (first) {
|
930 | first = false;
|
931 | } else {
|
932 | _util.expect.call(void 0, _types3.TokenType.comma);
|
933 | if (_index3.eat.call(void 0, close)) break;
|
934 | }
|
935 | parseExprListItem(allowEmpty);
|
936 | }
|
937 | }
|
938 |
|
939 | function parseExprListItem(allowEmpty) {
|
940 | if (allowEmpty && _index3.match.call(void 0, _types3.TokenType.comma)) {
|
941 |
|
942 | } else if (_index3.match.call(void 0, _types3.TokenType.ellipsis)) {
|
943 | _lval.parseSpread.call(void 0, );
|
944 | parseParenItem();
|
945 | } else {
|
946 | parseMaybeAssign(false, true);
|
947 | }
|
948 | }
|
949 |
|
950 |
|
951 | function parseIdentifier() {
|
952 | _index3.next.call(void 0, );
|
953 | _base.state.tokens[_base.state.tokens.length - 1].type = _types3.TokenType.name;
|
954 | } exports.parseIdentifier = parseIdentifier;
|
955 |
|
956 |
|
957 | function parseAwait() {
|
958 | parseMaybeUnary();
|
959 | }
|
960 |
|
961 |
|
962 | function parseYield() {
|
963 | _index3.next.call(void 0, );
|
964 | if (!_index3.match.call(void 0, _types3.TokenType.semi) && !_util.canInsertSemicolon.call(void 0, )) {
|
965 | _index3.eat.call(void 0, _types3.TokenType.star);
|
966 | parseMaybeAssign();
|
967 | }
|
968 | }
|