UNPKG

334 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function _AwaitValue(value) {
6 this.wrapped = value;
7}
8
9function _AsyncGenerator(gen) {
10 var front, back;
11
12 function send(key, arg) {
13 return new Promise(function (resolve, reject) {
14 var request = {
15 key: key,
16 arg: arg,
17 resolve: resolve,
18 reject: reject,
19 next: null
20 };
21
22 if (back) {
23 back = back.next = request;
24 } else {
25 front = back = request;
26 resume(key, arg);
27 }
28 });
29 }
30
31 function resume(key, arg) {
32 try {
33 var result = gen[key](arg);
34 var value = result.value;
35 var wrappedAwait = value instanceof _AwaitValue;
36 Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) {
37 if (wrappedAwait) {
38 resume("next", arg);
39 return;
40 }
41
42 settle(result.done ? "return" : "normal", arg);
43 }, function (err) {
44 resume("throw", err);
45 });
46 } catch (err) {
47 settle("throw", err);
48 }
49 }
50
51 function settle(type, value) {
52 switch (type) {
53 case "return":
54 front.resolve({
55 value: value,
56 done: true
57 });
58 break;
59
60 case "throw":
61 front.reject(value);
62 break;
63
64 default:
65 front.resolve({
66 value: value,
67 done: false
68 });
69 break;
70 }
71
72 front = front.next;
73
74 if (front) {
75 resume(front.key, front.arg);
76 } else {
77 back = null;
78 }
79 }
80
81 this._invoke = send;
82
83 if (typeof gen.return !== "function") {
84 this.return = undefined;
85 }
86}
87
88if (typeof Symbol === "function" && Symbol.asyncIterator) {
89 _AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
90 return this;
91 };
92}
93
94_AsyncGenerator.prototype.next = function (arg) {
95 return this._invoke("next", arg);
96};
97
98_AsyncGenerator.prototype.throw = function (arg) {
99 return this._invoke("throw", arg);
100};
101
102_AsyncGenerator.prototype.return = function (arg) {
103 return this._invoke("return", arg);
104};
105
106function _inheritsLoose(subClass, superClass) {
107 subClass.prototype = Object.create(superClass.prototype);
108 subClass.prototype.constructor = subClass;
109 subClass.__proto__ = superClass;
110}
111
112var beforeExpr = true;
113var startsExpr = true;
114var isLoop = true;
115var isAssign = true;
116var prefix = true;
117var postfix = true;
118var TokenType = function TokenType(label, conf) {
119 if (conf === void 0) {
120 conf = {};
121 }
122
123 this.label = label;
124 this.keyword = conf.keyword;
125 this.beforeExpr = !!conf.beforeExpr;
126 this.startsExpr = !!conf.startsExpr;
127 this.rightAssociative = !!conf.rightAssociative;
128 this.isLoop = !!conf.isLoop;
129 this.isAssign = !!conf.isAssign;
130 this.prefix = !!conf.prefix;
131 this.postfix = !!conf.postfix;
132 this.binop = conf.binop === 0 ? 0 : conf.binop || null;
133 this.updateContext = null;
134};
135
136var KeywordTokenType = function (_TokenType) {
137 _inheritsLoose(KeywordTokenType, _TokenType);
138
139 function KeywordTokenType(name, options) {
140 if (options === void 0) {
141 options = {};
142 }
143
144 options.keyword = name;
145 return _TokenType.call(this, name, options) || this;
146 }
147
148 return KeywordTokenType;
149}(TokenType);
150
151var BinopTokenType = function (_TokenType2) {
152 _inheritsLoose(BinopTokenType, _TokenType2);
153
154 function BinopTokenType(name, prec) {
155 return _TokenType2.call(this, name, {
156 beforeExpr: beforeExpr,
157 binop: prec
158 }) || this;
159 }
160
161 return BinopTokenType;
162}(TokenType);
163var types = {
164 num: new TokenType("num", {
165 startsExpr: startsExpr
166 }),
167 bigint: new TokenType("bigint", {
168 startsExpr: startsExpr
169 }),
170 regexp: new TokenType("regexp", {
171 startsExpr: startsExpr
172 }),
173 string: new TokenType("string", {
174 startsExpr: startsExpr
175 }),
176 name: new TokenType("name", {
177 startsExpr: startsExpr
178 }),
179 eof: new TokenType("eof"),
180 bracketL: new TokenType("[", {
181 beforeExpr: beforeExpr,
182 startsExpr: startsExpr
183 }),
184 bracketR: new TokenType("]"),
185 braceL: new TokenType("{", {
186 beforeExpr: beforeExpr,
187 startsExpr: startsExpr
188 }),
189 braceBarL: new TokenType("{|", {
190 beforeExpr: beforeExpr,
191 startsExpr: startsExpr
192 }),
193 braceR: new TokenType("}"),
194 braceBarR: new TokenType("|}"),
195 parenL: new TokenType("(", {
196 beforeExpr: beforeExpr,
197 startsExpr: startsExpr
198 }),
199 parenR: new TokenType(")"),
200 comma: new TokenType(",", {
201 beforeExpr: beforeExpr
202 }),
203 semi: new TokenType(";", {
204 beforeExpr: beforeExpr
205 }),
206 colon: new TokenType(":", {
207 beforeExpr: beforeExpr
208 }),
209 doubleColon: new TokenType("::", {
210 beforeExpr: beforeExpr
211 }),
212 dot: new TokenType("."),
213 question: new TokenType("?", {
214 beforeExpr: beforeExpr
215 }),
216 questionDot: new TokenType("?."),
217 arrow: new TokenType("=>", {
218 beforeExpr: beforeExpr
219 }),
220 template: new TokenType("template"),
221 ellipsis: new TokenType("...", {
222 beforeExpr: beforeExpr
223 }),
224 backQuote: new TokenType("`", {
225 startsExpr: startsExpr
226 }),
227 dollarBraceL: new TokenType("${", {
228 beforeExpr: beforeExpr,
229 startsExpr: startsExpr
230 }),
231 at: new TokenType("@"),
232 hash: new TokenType("#"),
233 interpreterDirective: new TokenType("#!..."),
234 eq: new TokenType("=", {
235 beforeExpr: beforeExpr,
236 isAssign: isAssign
237 }),
238 assign: new TokenType("_=", {
239 beforeExpr: beforeExpr,
240 isAssign: isAssign
241 }),
242 incDec: new TokenType("++/--", {
243 prefix: prefix,
244 postfix: postfix,
245 startsExpr: startsExpr
246 }),
247 bang: new TokenType("!", {
248 beforeExpr: beforeExpr,
249 prefix: prefix,
250 startsExpr: startsExpr
251 }),
252 tilde: new TokenType("~", {
253 beforeExpr: beforeExpr,
254 prefix: prefix,
255 startsExpr: startsExpr
256 }),
257 pipeline: new BinopTokenType("|>", 0),
258 nullishCoalescing: new BinopTokenType("??", 1),
259 logicalOR: new BinopTokenType("||", 1),
260 logicalAND: new BinopTokenType("&&", 2),
261 bitwiseOR: new BinopTokenType("|", 3),
262 bitwiseXOR: new BinopTokenType("^", 4),
263 bitwiseAND: new BinopTokenType("&", 5),
264 equality: new BinopTokenType("==/!=", 6),
265 relational: new BinopTokenType("</>", 7),
266 bitShift: new BinopTokenType("<</>>", 8),
267 plusMin: new TokenType("+/-", {
268 beforeExpr: beforeExpr,
269 binop: 9,
270 prefix: prefix,
271 startsExpr: startsExpr
272 }),
273 modulo: new BinopTokenType("%", 10),
274 star: new BinopTokenType("*", 10),
275 slash: new BinopTokenType("/", 10),
276 exponent: new TokenType("**", {
277 beforeExpr: beforeExpr,
278 binop: 11,
279 rightAssociative: true
280 })
281};
282var keywords = {
283 break: new KeywordTokenType("break"),
284 case: new KeywordTokenType("case", {
285 beforeExpr: beforeExpr
286 }),
287 catch: new KeywordTokenType("catch"),
288 continue: new KeywordTokenType("continue"),
289 debugger: new KeywordTokenType("debugger"),
290 default: new KeywordTokenType("default", {
291 beforeExpr: beforeExpr
292 }),
293 do: new KeywordTokenType("do", {
294 isLoop: isLoop,
295 beforeExpr: beforeExpr
296 }),
297 else: new KeywordTokenType("else", {
298 beforeExpr: beforeExpr
299 }),
300 finally: new KeywordTokenType("finally"),
301 for: new KeywordTokenType("for", {
302 isLoop: isLoop
303 }),
304 function: new KeywordTokenType("function", {
305 startsExpr: startsExpr
306 }),
307 if: new KeywordTokenType("if"),
308 return: new KeywordTokenType("return", {
309 beforeExpr: beforeExpr
310 }),
311 switch: new KeywordTokenType("switch"),
312 throw: new KeywordTokenType("throw", {
313 beforeExpr: beforeExpr,
314 prefix: prefix,
315 startsExpr: startsExpr
316 }),
317 try: new KeywordTokenType("try"),
318 var: new KeywordTokenType("var"),
319 let: new KeywordTokenType("let"),
320 const: new KeywordTokenType("const"),
321 while: new KeywordTokenType("while", {
322 isLoop: isLoop
323 }),
324 with: new KeywordTokenType("with"),
325 new: new KeywordTokenType("new", {
326 beforeExpr: beforeExpr,
327 startsExpr: startsExpr
328 }),
329 this: new KeywordTokenType("this", {
330 startsExpr: startsExpr
331 }),
332 super: new KeywordTokenType("super", {
333 startsExpr: startsExpr
334 }),
335 class: new KeywordTokenType("class"),
336 extends: new KeywordTokenType("extends", {
337 beforeExpr: beforeExpr
338 }),
339 export: new KeywordTokenType("export"),
340 import: new KeywordTokenType("import", {
341 startsExpr: startsExpr
342 }),
343 yield: new KeywordTokenType("yield", {
344 beforeExpr: beforeExpr,
345 startsExpr: startsExpr
346 }),
347 null: new KeywordTokenType("null", {
348 startsExpr: startsExpr
349 }),
350 true: new KeywordTokenType("true", {
351 startsExpr: startsExpr
352 }),
353 false: new KeywordTokenType("false", {
354 startsExpr: startsExpr
355 }),
356 in: new KeywordTokenType("in", {
357 beforeExpr: beforeExpr,
358 binop: 7
359 }),
360 instanceof: new KeywordTokenType("instanceof", {
361 beforeExpr: beforeExpr,
362 binop: 7
363 }),
364 typeof: new KeywordTokenType("typeof", {
365 beforeExpr: beforeExpr,
366 prefix: prefix,
367 startsExpr: startsExpr
368 }),
369 void: new KeywordTokenType("void", {
370 beforeExpr: beforeExpr,
371 prefix: prefix,
372 startsExpr: startsExpr
373 }),
374 delete: new KeywordTokenType("delete", {
375 beforeExpr: beforeExpr,
376 prefix: prefix,
377 startsExpr: startsExpr
378 })
379};
380Object.keys(keywords).forEach(function (name) {
381 types["_" + name] = keywords[name];
382});
383
384function isSimpleProperty(node) {
385 return node != null && node.type === "Property" && node.kind === "init" && node.method === false;
386}
387
388var estree = (function (superClass) {
389 return function (_superClass) {
390 _inheritsLoose(_class, _superClass);
391
392 function _class() {
393 return _superClass.apply(this, arguments) || this;
394 }
395
396 var _proto = _class.prototype;
397
398 _proto.estreeParseRegExpLiteral = function estreeParseRegExpLiteral(_ref) {
399 var pattern = _ref.pattern,
400 flags = _ref.flags;
401 var regex = null;
402
403 try {
404 regex = new RegExp(pattern, flags);
405 } catch (e) {}
406
407 var node = this.estreeParseLiteral(regex);
408 node.regex = {
409 pattern: pattern,
410 flags: flags
411 };
412 return node;
413 };
414
415 _proto.estreeParseLiteral = function estreeParseLiteral(value) {
416 return this.parseLiteral(value, "Literal");
417 };
418
419 _proto.directiveToStmt = function directiveToStmt(directive) {
420 var directiveLiteral = directive.value;
421 var stmt = this.startNodeAt(directive.start, directive.loc.start);
422 var expression = this.startNodeAt(directiveLiteral.start, directiveLiteral.loc.start);
423 expression.value = directiveLiteral.value;
424 expression.raw = directiveLiteral.extra.raw;
425 stmt.expression = this.finishNodeAt(expression, "Literal", directiveLiteral.end, directiveLiteral.loc.end);
426 stmt.directive = directiveLiteral.extra.raw.slice(1, -1);
427 return this.finishNodeAt(stmt, "ExpressionStatement", directive.end, directive.loc.end);
428 };
429
430 _proto.initFunction = function initFunction(node, isAsync) {
431 _superClass.prototype.initFunction.call(this, node, isAsync);
432
433 node.expression = false;
434 };
435
436 _proto.checkDeclaration = function checkDeclaration(node) {
437 if (isSimpleProperty(node)) {
438 this.checkDeclaration(node.value);
439 } else {
440 _superClass.prototype.checkDeclaration.call(this, node);
441 }
442 };
443
444 _proto.checkGetterSetterParams = function checkGetterSetterParams(method) {
445 var prop = method;
446 var paramCount = prop.kind === "get" ? 0 : 1;
447 var start = prop.start;
448
449 if (prop.value.params.length !== paramCount) {
450 if (prop.kind === "get") {
451 this.raise(start, "getter must not have any formal parameters");
452 } else {
453 this.raise(start, "setter must have exactly one formal parameter");
454 }
455 }
456
457 if (prop.kind === "set" && prop.value.params[0].type === "RestElement") {
458 this.raise(start, "setter function argument must not be a rest parameter");
459 }
460 };
461
462 _proto.checkLVal = function checkLVal(expr, isBinding, checkClashes, contextDescription) {
463 var _this = this;
464
465 switch (expr.type) {
466 case "ObjectPattern":
467 expr.properties.forEach(function (prop) {
468 _this.checkLVal(prop.type === "Property" ? prop.value : prop, isBinding, checkClashes, "object destructuring pattern");
469 });
470 break;
471
472 default:
473 _superClass.prototype.checkLVal.call(this, expr, isBinding, checkClashes, contextDescription);
474
475 }
476 };
477
478 _proto.checkPropClash = function checkPropClash(prop, propHash) {
479 if (prop.computed || !isSimpleProperty(prop)) return;
480 var key = prop.key;
481 var name = key.type === "Identifier" ? key.name : String(key.value);
482
483 if (name === "__proto__") {
484 if (propHash.proto) {
485 this.raise(key.start, "Redefinition of __proto__ property");
486 }
487
488 propHash.proto = true;
489 }
490 };
491
492 _proto.isStrictBody = function isStrictBody(node) {
493 var isBlockStatement = node.body.type === "BlockStatement";
494
495 if (isBlockStatement && node.body.body.length > 0) {
496 for (var _i2 = 0, _node$body$body2 = node.body.body; _i2 < _node$body$body2.length; _i2++) {
497 var directive = _node$body$body2[_i2];
498
499 if (directive.type === "ExpressionStatement" && directive.expression.type === "Literal") {
500 if (directive.expression.value === "use strict") return true;
501 } else {
502 break;
503 }
504 }
505 }
506
507 return false;
508 };
509
510 _proto.isValidDirective = function isValidDirective(stmt) {
511 return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && (!stmt.expression.extra || !stmt.expression.extra.parenthesized);
512 };
513
514 _proto.stmtToDirective = function stmtToDirective(stmt) {
515 var directive = _superClass.prototype.stmtToDirective.call(this, stmt);
516
517 var value = stmt.expression.value;
518 directive.value.value = value;
519 return directive;
520 };
521
522 _proto.parseBlockBody = function parseBlockBody(node, allowDirectives, topLevel, end) {
523 var _this2 = this;
524
525 _superClass.prototype.parseBlockBody.call(this, node, allowDirectives, topLevel, end);
526
527 var directiveStatements = node.directives.map(function (d) {
528 return _this2.directiveToStmt(d);
529 });
530 node.body = directiveStatements.concat(node.body);
531 delete node.directives;
532 };
533
534 _proto.pushClassMethod = function pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) {
535 this.parseMethod(method, isGenerator, isAsync, isConstructor, "MethodDefinition");
536
537 if (method.typeParameters) {
538 method.value.typeParameters = method.typeParameters;
539 delete method.typeParameters;
540 }
541
542 classBody.body.push(method);
543 };
544
545 _proto.parseExprAtom = function parseExprAtom(refShorthandDefaultPos) {
546 switch (this.state.type) {
547 case types.regexp:
548 return this.estreeParseRegExpLiteral(this.state.value);
549
550 case types.num:
551 case types.string:
552 return this.estreeParseLiteral(this.state.value);
553
554 case types._null:
555 return this.estreeParseLiteral(null);
556
557 case types._true:
558 return this.estreeParseLiteral(true);
559
560 case types._false:
561 return this.estreeParseLiteral(false);
562
563 default:
564 return _superClass.prototype.parseExprAtom.call(this, refShorthandDefaultPos);
565 }
566 };
567
568 _proto.parseLiteral = function parseLiteral(value, type, startPos, startLoc) {
569 var node = _superClass.prototype.parseLiteral.call(this, value, type, startPos, startLoc);
570
571 node.raw = node.extra.raw;
572 delete node.extra;
573 return node;
574 };
575
576 _proto.parseFunctionBody = function parseFunctionBody(node, allowExpression) {
577 _superClass.prototype.parseFunctionBody.call(this, node, allowExpression);
578
579 node.expression = node.body.type !== "BlockStatement";
580 };
581
582 _proto.parseMethod = function parseMethod(node, isGenerator, isAsync, isConstructor, type) {
583 var funcNode = this.startNode();
584 funcNode.kind = node.kind;
585 funcNode = _superClass.prototype.parseMethod.call(this, funcNode, isGenerator, isAsync, isConstructor, "FunctionExpression");
586 delete funcNode.kind;
587 node.value = funcNode;
588 return this.finishNode(node, type);
589 };
590
591 _proto.parseObjectMethod = function parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) {
592 var node = _superClass.prototype.parseObjectMethod.call(this, prop, isGenerator, isAsync, isPattern, containsEsc);
593
594 if (node) {
595 node.type = "Property";
596 if (node.kind === "method") node.kind = "init";
597 node.shorthand = false;
598 }
599
600 return node;
601 };
602
603 _proto.parseObjectProperty = function parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos) {
604 var node = _superClass.prototype.parseObjectProperty.call(this, prop, startPos, startLoc, isPattern, refShorthandDefaultPos);
605
606 if (node) {
607 node.kind = "init";
608 node.type = "Property";
609 }
610
611 return node;
612 };
613
614 _proto.toAssignable = function toAssignable(node, isBinding, contextDescription) {
615 if (isSimpleProperty(node)) {
616 this.toAssignable(node.value, isBinding, contextDescription);
617 return node;
618 }
619
620 return _superClass.prototype.toAssignable.call(this, node, isBinding, contextDescription);
621 };
622
623 _proto.toAssignableObjectExpressionProp = function toAssignableObjectExpressionProp(prop, isBinding, isLast) {
624 if (prop.kind === "get" || prop.kind === "set") {
625 this.raise(prop.key.start, "Object pattern can't contain getter or setter");
626 } else if (prop.method) {
627 this.raise(prop.key.start, "Object pattern can't contain methods");
628 } else {
629 _superClass.prototype.toAssignableObjectExpressionProp.call(this, prop, isBinding, isLast);
630 }
631 };
632
633 return _class;
634 }(superClass);
635});
636
637function makePredicate(words) {
638 var wordsArr = words.split(" ");
639 return function (str) {
640 return wordsArr.indexOf(str) >= 0;
641 };
642}
643
644var reservedWords = {
645 "6": makePredicate("enum await"),
646 strict: makePredicate("implements interface let package private protected public static yield"),
647 strictBind: makePredicate("eval arguments")
648};
649var isKeyword = makePredicate("break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this let const class extends export import yield super");
650var nonASCIIidentifierStartChars = "\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7B9\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC";
651var nonASCIIidentifierChars = "\u200C\u200D\xB7\u0300-\u036F\u0387\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\u096F\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09E6-\u09EF\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A66-\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AE6-\u0AEF\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B66-\u0B6F\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0BE6-\u0BEF\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0CE6-\u0CEF\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D66-\u0D6F\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0E50-\u0E59\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0ED0-\u0ED9\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1040-\u1049\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F-\u109D\u135D-\u135F\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u18A9\u1920-\u192B\u1930-\u193B\u1946-\u194F\u19D0-\u19DA\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AB0-\u1ABD\u1B00-\u1B04\u1B34-\u1B44\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BB0-\u1BB9\u1BE6-\u1BF3\u1C24-\u1C37\u1C40-\u1C49\u1C50-\u1C59\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u203F\u2040\u2054\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA620-\uA629\uA66F\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F1\uA8FF-\uA909\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9D0-\uA9D9\uA9E5\uA9F0-\uA9F9\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA50-\uAA59\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uABF0-\uABF9\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFF10-\uFF19\uFF3F";
652var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
653var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
654nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
655var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 477, 28, 11, 0, 9, 21, 190, 52, 76, 44, 33, 24, 27, 35, 30, 0, 12, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 54, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 86, 26, 230, 43, 117, 63, 32, 0, 257, 0, 11, 39, 8, 0, 22, 0, 12, 39, 3, 3, 20, 0, 35, 56, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 270, 921, 103, 110, 18, 195, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 68, 12, 0, 67, 12, 65, 1, 31, 6129, 15, 754, 9486, 286, 82, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 4149, 196, 60, 67, 1213, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42710, 42, 4148, 12, 221, 3, 5761, 15, 7472, 3104, 541];
656var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 525, 10, 176, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 4, 9, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 280, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 135, 4, 60, 6, 26, 9, 1016, 45, 17, 3, 19723, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 2214, 6, 110, 6, 6, 9, 792487, 239];
657
658function isInAstralSet(code, set) {
659 var pos = 0x10000;
660
661 for (var i = 0; i < set.length; i += 2) {
662 pos += set[i];
663 if (pos > code) return false;
664 pos += set[i + 1];
665 if (pos >= code) return true;
666 }
667
668 return false;
669}
670
671function isIdentifierStart(code) {
672 if (code < 65) return code === 36;
673 if (code <= 90) return true;
674 if (code < 97) return code === 95;
675 if (code <= 122) return true;
676
677 if (code <= 0xffff) {
678 return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
679 }
680
681 return isInAstralSet(code, astralIdentifierStartCodes);
682}
683function isIteratorStart(current, next) {
684 return current === 64 && next === 64;
685}
686function isIdentifierChar(code) {
687 if (code < 48) return code === 36;
688 if (code < 58) return true;
689 if (code < 65) return false;
690 if (code <= 90) return true;
691 if (code < 97) return code === 95;
692 if (code <= 122) return true;
693
694 if (code <= 0xffff) {
695 return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
696 }
697
698 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
699}
700
701var primitiveTypes = ["any", "bool", "boolean", "empty", "false", "mixed", "null", "number", "static", "string", "true", "typeof", "void"];
702
703function isEsModuleType(bodyElement) {
704 return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
705}
706
707function hasTypeImportKind(node) {
708 return node.importKind === "type" || node.importKind === "typeof";
709}
710
711function isMaybeDefaultImport(state) {
712 return (state.type === types.name || !!state.type.keyword) && state.value !== "from";
713}
714
715var exportSuggestions = {
716 const: "declare export var",
717 let: "declare export var",
718 type: "export type",
719 interface: "export interface"
720};
721
722function partition(list, test) {
723 var list1 = [];
724 var list2 = [];
725
726 for (var i = 0; i < list.length; i++) {
727 (test(list[i], i, list) ? list1 : list2).push(list[i]);
728 }
729
730 return [list1, list2];
731}
732
733var FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
734var flow = (function (superClass) {
735 return function (_superClass) {
736 _inheritsLoose(_class, _superClass);
737
738 function _class(options, input) {
739 var _this;
740
741 _this = _superClass.call(this, options, input) || this;
742 _this.flowPragma = undefined;
743 return _this;
744 }
745
746 var _proto = _class.prototype;
747
748 _proto.shouldParseTypes = function shouldParseTypes() {
749 return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
750 };
751
752 _proto.addComment = function addComment(comment) {
753 if (this.flowPragma === undefined) {
754 var matches = FLOW_PRAGMA_REGEX.exec(comment.value);
755
756 if (!matches) {
757 this.flowPragma = null;
758 } else if (matches[1] === "flow") {
759 this.flowPragma = "flow";
760 } else if (matches[1] === "noflow") {
761 this.flowPragma = "noflow";
762 } else {
763 throw new Error("Unexpected flow pragma");
764 }
765 }
766
767 return _superClass.prototype.addComment.call(this, comment);
768 };
769
770 _proto.flowParseTypeInitialiser = function flowParseTypeInitialiser(tok) {
771 var oldInType = this.state.inType;
772 this.state.inType = true;
773 this.expect(tok || types.colon);
774 var type = this.flowParseType();
775 this.state.inType = oldInType;
776 return type;
777 };
778
779 _proto.flowParsePredicate = function flowParsePredicate() {
780 var node = this.startNode();
781 var moduloLoc = this.state.startLoc;
782 var moduloPos = this.state.start;
783 this.expect(types.modulo);
784 var checksLoc = this.state.startLoc;
785 this.expectContextual("checks");
786
787 if (moduloLoc.line !== checksLoc.line || moduloLoc.column !== checksLoc.column - 1) {
788 this.raise(moduloPos, "Spaces between ´%´ and ´checks´ are not allowed here.");
789 }
790
791 if (this.eat(types.parenL)) {
792 node.value = this.parseExpression();
793 this.expect(types.parenR);
794 return this.finishNode(node, "DeclaredPredicate");
795 } else {
796 return this.finishNode(node, "InferredPredicate");
797 }
798 };
799
800 _proto.flowParseTypeAndPredicateInitialiser = function flowParseTypeAndPredicateInitialiser() {
801 var oldInType = this.state.inType;
802 this.state.inType = true;
803 this.expect(types.colon);
804 var type = null;
805 var predicate = null;
806
807 if (this.match(types.modulo)) {
808 this.state.inType = oldInType;
809 predicate = this.flowParsePredicate();
810 } else {
811 type = this.flowParseType();
812 this.state.inType = oldInType;
813
814 if (this.match(types.modulo)) {
815 predicate = this.flowParsePredicate();
816 }
817 }
818
819 return [type, predicate];
820 };
821
822 _proto.flowParseDeclareClass = function flowParseDeclareClass(node) {
823 this.next();
824 this.flowParseInterfaceish(node, true);
825 return this.finishNode(node, "DeclareClass");
826 };
827
828 _proto.flowParseDeclareFunction = function flowParseDeclareFunction(node) {
829 this.next();
830 var id = node.id = this.parseIdentifier();
831 var typeNode = this.startNode();
832 var typeContainer = this.startNode();
833
834 if (this.isRelational("<")) {
835 typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
836 } else {
837 typeNode.typeParameters = null;
838 }
839
840 this.expect(types.parenL);
841 var tmp = this.flowParseFunctionTypeParams();
842 typeNode.params = tmp.params;
843 typeNode.rest = tmp.rest;
844 this.expect(types.parenR);
845
846 var _this$flowParseTypeAn = this.flowParseTypeAndPredicateInitialiser();
847
848 typeNode.returnType = _this$flowParseTypeAn[0];
849 node.predicate = _this$flowParseTypeAn[1];
850 typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
851 id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
852 this.finishNode(id, id.type);
853 this.semicolon();
854 return this.finishNode(node, "DeclareFunction");
855 };
856
857 _proto.flowParseDeclare = function flowParseDeclare(node, insideModule) {
858 if (this.match(types._class)) {
859 return this.flowParseDeclareClass(node);
860 } else if (this.match(types._function)) {
861 return this.flowParseDeclareFunction(node);
862 } else if (this.match(types._var)) {
863 return this.flowParseDeclareVariable(node);
864 } else if (this.isContextual("module")) {
865 if (this.lookahead().type === types.dot) {
866 return this.flowParseDeclareModuleExports(node);
867 } else {
868 if (insideModule) {
869 this.unexpected(null, "`declare module` cannot be used inside another `declare module`");
870 }
871
872 return this.flowParseDeclareModule(node);
873 }
874 } else if (this.isContextual("type")) {
875 return this.flowParseDeclareTypeAlias(node);
876 } else if (this.isContextual("opaque")) {
877 return this.flowParseDeclareOpaqueType(node);
878 } else if (this.isContextual("interface")) {
879 return this.flowParseDeclareInterface(node);
880 } else if (this.match(types._export)) {
881 return this.flowParseDeclareExportDeclaration(node, insideModule);
882 } else {
883 throw this.unexpected();
884 }
885 };
886
887 _proto.flowParseDeclareVariable = function flowParseDeclareVariable(node) {
888 this.next();
889 node.id = this.flowParseTypeAnnotatableIdentifier(true);
890 this.semicolon();
891 return this.finishNode(node, "DeclareVariable");
892 };
893
894 _proto.flowParseDeclareModule = function flowParseDeclareModule(node) {
895 var _this2 = this;
896
897 this.next();
898
899 if (this.match(types.string)) {
900 node.id = this.parseExprAtom();
901 } else {
902 node.id = this.parseIdentifier();
903 }
904
905 var bodyNode = node.body = this.startNode();
906 var body = bodyNode.body = [];
907 this.expect(types.braceL);
908
909 while (!this.match(types.braceR)) {
910 var _bodyNode = this.startNode();
911
912 if (this.match(types._import)) {
913 var lookahead = this.lookahead();
914
915 if (lookahead.value !== "type" && lookahead.value !== "typeof") {
916 this.unexpected(null, "Imports within a `declare module` body must always be `import type` or `import typeof`");
917 }
918
919 this.next();
920 this.parseImport(_bodyNode);
921 } else {
922 this.expectContextual("declare", "Only declares and type imports are allowed inside declare module");
923 _bodyNode = this.flowParseDeclare(_bodyNode, true);
924 }
925
926 body.push(_bodyNode);
927 }
928
929 this.expect(types.braceR);
930 this.finishNode(bodyNode, "BlockStatement");
931 var kind = null;
932 var hasModuleExport = false;
933 var errorMessage = "Found both `declare module.exports` and `declare export` in the same module. " + "Modules can only have 1 since they are either an ES module or they are a CommonJS module";
934 body.forEach(function (bodyElement) {
935 if (isEsModuleType(bodyElement)) {
936 if (kind === "CommonJS") {
937 _this2.unexpected(bodyElement.start, errorMessage);
938 }
939
940 kind = "ES";
941 } else if (bodyElement.type === "DeclareModuleExports") {
942 if (hasModuleExport) {
943 _this2.unexpected(bodyElement.start, "Duplicate `declare module.exports` statement");
944 }
945
946 if (kind === "ES") _this2.unexpected(bodyElement.start, errorMessage);
947 kind = "CommonJS";
948 hasModuleExport = true;
949 }
950 });
951 node.kind = kind || "CommonJS";
952 return this.finishNode(node, "DeclareModule");
953 };
954
955 _proto.flowParseDeclareExportDeclaration = function flowParseDeclareExportDeclaration(node, insideModule) {
956 this.expect(types._export);
957
958 if (this.eat(types._default)) {
959 if (this.match(types._function) || this.match(types._class)) {
960 node.declaration = this.flowParseDeclare(this.startNode());
961 } else {
962 node.declaration = this.flowParseType();
963 this.semicolon();
964 }
965
966 node.default = true;
967 return this.finishNode(node, "DeclareExportDeclaration");
968 } else {
969 if (this.match(types._const) || this.match(types._let) || (this.isContextual("type") || this.isContextual("interface")) && !insideModule) {
970 var label = this.state.value;
971 var suggestion = exportSuggestions[label];
972 this.unexpected(this.state.start, "`declare export " + label + "` is not supported. Use `" + suggestion + "` instead");
973 }
974
975 if (this.match(types._var) || this.match(types._function) || this.match(types._class) || this.isContextual("opaque")) {
976 node.declaration = this.flowParseDeclare(this.startNode());
977 node.default = false;
978 return this.finishNode(node, "DeclareExportDeclaration");
979 } else if (this.match(types.star) || this.match(types.braceL) || this.isContextual("interface") || this.isContextual("type") || this.isContextual("opaque")) {
980 node = this.parseExport(node);
981
982 if (node.type === "ExportNamedDeclaration") {
983 node.type = "ExportDeclaration";
984 node.default = false;
985 delete node.exportKind;
986 }
987
988 node.type = "Declare" + node.type;
989 return node;
990 }
991 }
992
993 throw this.unexpected();
994 };
995
996 _proto.flowParseDeclareModuleExports = function flowParseDeclareModuleExports(node) {
997 this.expectContextual("module");
998 this.expect(types.dot);
999 this.expectContextual("exports");
1000 node.typeAnnotation = this.flowParseTypeAnnotation();
1001 this.semicolon();
1002 return this.finishNode(node, "DeclareModuleExports");
1003 };
1004
1005 _proto.flowParseDeclareTypeAlias = function flowParseDeclareTypeAlias(node) {
1006 this.next();
1007 this.flowParseTypeAlias(node);
1008 return this.finishNode(node, "DeclareTypeAlias");
1009 };
1010
1011 _proto.flowParseDeclareOpaqueType = function flowParseDeclareOpaqueType(node) {
1012 this.next();
1013 this.flowParseOpaqueType(node, true);
1014 return this.finishNode(node, "DeclareOpaqueType");
1015 };
1016
1017 _proto.flowParseDeclareInterface = function flowParseDeclareInterface(node) {
1018 this.next();
1019 this.flowParseInterfaceish(node);
1020 return this.finishNode(node, "DeclareInterface");
1021 };
1022
1023 _proto.flowParseInterfaceish = function flowParseInterfaceish(node, isClass) {
1024 if (isClass === void 0) {
1025 isClass = false;
1026 }
1027
1028 node.id = this.flowParseRestrictedIdentifier(!isClass);
1029
1030 if (this.isRelational("<")) {
1031 node.typeParameters = this.flowParseTypeParameterDeclaration();
1032 } else {
1033 node.typeParameters = null;
1034 }
1035
1036 node.extends = [];
1037 node.implements = [];
1038 node.mixins = [];
1039
1040 if (this.eat(types._extends)) {
1041 do {
1042 node.extends.push(this.flowParseInterfaceExtends());
1043 } while (!isClass && this.eat(types.comma));
1044 }
1045
1046 if (this.isContextual("mixins")) {
1047 this.next();
1048
1049 do {
1050 node.mixins.push(this.flowParseInterfaceExtends());
1051 } while (this.eat(types.comma));
1052 }
1053
1054 if (this.isContextual("implements")) {
1055 this.next();
1056
1057 do {
1058 node.implements.push(this.flowParseInterfaceExtends());
1059 } while (this.eat(types.comma));
1060 }
1061
1062 node.body = this.flowParseObjectType(isClass, false, false, isClass);
1063 };
1064
1065 _proto.flowParseInterfaceExtends = function flowParseInterfaceExtends() {
1066 var node = this.startNode();
1067 node.id = this.flowParseQualifiedTypeIdentifier();
1068
1069 if (this.isRelational("<")) {
1070 node.typeParameters = this.flowParseTypeParameterInstantiation();
1071 } else {
1072 node.typeParameters = null;
1073 }
1074
1075 return this.finishNode(node, "InterfaceExtends");
1076 };
1077
1078 _proto.flowParseInterface = function flowParseInterface(node) {
1079 this.flowParseInterfaceish(node);
1080 return this.finishNode(node, "InterfaceDeclaration");
1081 };
1082
1083 _proto.checkReservedType = function checkReservedType(word, startLoc) {
1084 if (primitiveTypes.indexOf(word) > -1) {
1085 this.raise(startLoc, "Cannot overwrite primitive type " + word);
1086 }
1087 };
1088
1089 _proto.flowParseRestrictedIdentifier = function flowParseRestrictedIdentifier(liberal) {
1090 this.checkReservedType(this.state.value, this.state.start);
1091 return this.parseIdentifier(liberal);
1092 };
1093
1094 _proto.flowParseTypeAlias = function flowParseTypeAlias(node) {
1095 node.id = this.flowParseRestrictedIdentifier();
1096
1097 if (this.isRelational("<")) {
1098 node.typeParameters = this.flowParseTypeParameterDeclaration();
1099 } else {
1100 node.typeParameters = null;
1101 }
1102
1103 node.right = this.flowParseTypeInitialiser(types.eq);
1104 this.semicolon();
1105 return this.finishNode(node, "TypeAlias");
1106 };
1107
1108 _proto.flowParseOpaqueType = function flowParseOpaqueType(node, declare) {
1109 this.expectContextual("type");
1110 node.id = this.flowParseRestrictedIdentifier(true);
1111
1112 if (this.isRelational("<")) {
1113 node.typeParameters = this.flowParseTypeParameterDeclaration();
1114 } else {
1115 node.typeParameters = null;
1116 }
1117
1118 node.supertype = null;
1119
1120 if (this.match(types.colon)) {
1121 node.supertype = this.flowParseTypeInitialiser(types.colon);
1122 }
1123
1124 node.impltype = null;
1125
1126 if (!declare) {
1127 node.impltype = this.flowParseTypeInitialiser(types.eq);
1128 }
1129
1130 this.semicolon();
1131 return this.finishNode(node, "OpaqueType");
1132 };
1133
1134 _proto.flowParseTypeParameter = function flowParseTypeParameter(allowDefault, requireDefault) {
1135 if (allowDefault === void 0) {
1136 allowDefault = true;
1137 }
1138
1139 if (requireDefault === void 0) {
1140 requireDefault = false;
1141 }
1142
1143 if (!allowDefault && requireDefault) {
1144 throw new Error("Cannot disallow a default value (`allowDefault`) while also requiring it (`requireDefault`).");
1145 }
1146
1147 var nodeStart = this.state.start;
1148 var node = this.startNode();
1149 var variance = this.flowParseVariance();
1150 var ident = this.flowParseTypeAnnotatableIdentifier();
1151 node.name = ident.name;
1152 node.variance = variance;
1153 node.bound = ident.typeAnnotation;
1154
1155 if (this.match(types.eq)) {
1156 if (allowDefault) {
1157 this.eat(types.eq);
1158 node.default = this.flowParseType();
1159 } else {
1160 this.unexpected();
1161 }
1162 } else {
1163 if (requireDefault) {
1164 this.unexpected(nodeStart, "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.");
1165 }
1166 }
1167
1168 return this.finishNode(node, "TypeParameter");
1169 };
1170
1171 _proto.flowParseTypeParameterDeclaration = function flowParseTypeParameterDeclaration(allowDefault) {
1172 if (allowDefault === void 0) {
1173 allowDefault = true;
1174 }
1175
1176 var oldInType = this.state.inType;
1177 var node = this.startNode();
1178 node.params = [];
1179 this.state.inType = true;
1180
1181 if (this.isRelational("<") || this.match(types.jsxTagStart)) {
1182 this.next();
1183 } else {
1184 this.unexpected();
1185 }
1186
1187 var defaultRequired = false;
1188
1189 do {
1190 var typeParameter = this.flowParseTypeParameter(allowDefault, defaultRequired);
1191 node.params.push(typeParameter);
1192
1193 if (typeParameter.default) {
1194 defaultRequired = true;
1195 }
1196
1197 if (!this.isRelational(">")) {
1198 this.expect(types.comma);
1199 }
1200 } while (!this.isRelational(">"));
1201
1202 this.expectRelational(">");
1203 this.state.inType = oldInType;
1204 return this.finishNode(node, "TypeParameterDeclaration");
1205 };
1206
1207 _proto.flowParseTypeParameterInstantiation = function flowParseTypeParameterInstantiation() {
1208 var node = this.startNode();
1209 var oldInType = this.state.inType;
1210 node.params = [];
1211 this.state.inType = true;
1212 this.expectRelational("<");
1213
1214 while (!this.isRelational(">")) {
1215 node.params.push(this.flowParseType());
1216
1217 if (!this.isRelational(">")) {
1218 this.expect(types.comma);
1219 }
1220 }
1221
1222 this.expectRelational(">");
1223 this.state.inType = oldInType;
1224 return this.finishNode(node, "TypeParameterInstantiation");
1225 };
1226
1227 _proto.flowParseInterfaceType = function flowParseInterfaceType() {
1228 var node = this.startNode();
1229 this.expectContextual("interface");
1230 node.extends = [];
1231
1232 if (this.eat(types._extends)) {
1233 do {
1234 node.extends.push(this.flowParseInterfaceExtends());
1235 } while (this.eat(types.comma));
1236 }
1237
1238 node.body = this.flowParseObjectType(false, false, false, false);
1239 return this.finishNode(node, "InterfaceTypeAnnotation");
1240 };
1241
1242 _proto.flowParseObjectPropertyKey = function flowParseObjectPropertyKey() {
1243 return this.match(types.num) || this.match(types.string) ? this.parseExprAtom() : this.parseIdentifier(true);
1244 };
1245
1246 _proto.flowParseObjectTypeIndexer = function flowParseObjectTypeIndexer(node, isStatic, variance) {
1247 node.static = isStatic;
1248
1249 if (this.lookahead().type === types.colon) {
1250 node.id = this.flowParseObjectPropertyKey();
1251 node.key = this.flowParseTypeInitialiser();
1252 } else {
1253 node.id = null;
1254 node.key = this.flowParseType();
1255 }
1256
1257 this.expect(types.bracketR);
1258 node.value = this.flowParseTypeInitialiser();
1259 node.variance = variance;
1260 return this.finishNode(node, "ObjectTypeIndexer");
1261 };
1262
1263 _proto.flowParseObjectTypeInternalSlot = function flowParseObjectTypeInternalSlot(node, isStatic) {
1264 node.static = isStatic;
1265 node.id = this.flowParseObjectPropertyKey();
1266 this.expect(types.bracketR);
1267 this.expect(types.bracketR);
1268
1269 if (this.isRelational("<") || this.match(types.parenL)) {
1270 node.method = true;
1271 node.optional = false;
1272 node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.start, node.loc.start));
1273 } else {
1274 node.method = false;
1275
1276 if (this.eat(types.question)) {
1277 node.optional = true;
1278 }
1279
1280 node.value = this.flowParseTypeInitialiser();
1281 }
1282
1283 return this.finishNode(node, "ObjectTypeInternalSlot");
1284 };
1285
1286 _proto.flowParseObjectTypeMethodish = function flowParseObjectTypeMethodish(node) {
1287 node.params = [];
1288 node.rest = null;
1289 node.typeParameters = null;
1290
1291 if (this.isRelational("<")) {
1292 node.typeParameters = this.flowParseTypeParameterDeclaration(false);
1293 }
1294
1295 this.expect(types.parenL);
1296
1297 while (!this.match(types.parenR) && !this.match(types.ellipsis)) {
1298 node.params.push(this.flowParseFunctionTypeParam());
1299
1300 if (!this.match(types.parenR)) {
1301 this.expect(types.comma);
1302 }
1303 }
1304
1305 if (this.eat(types.ellipsis)) {
1306 node.rest = this.flowParseFunctionTypeParam();
1307 }
1308
1309 this.expect(types.parenR);
1310 node.returnType = this.flowParseTypeInitialiser();
1311 return this.finishNode(node, "FunctionTypeAnnotation");
1312 };
1313
1314 _proto.flowParseObjectTypeCallProperty = function flowParseObjectTypeCallProperty(node, isStatic) {
1315 var valueNode = this.startNode();
1316 node.static = isStatic;
1317 node.value = this.flowParseObjectTypeMethodish(valueNode);
1318 return this.finishNode(node, "ObjectTypeCallProperty");
1319 };
1320
1321 _proto.flowParseObjectType = function flowParseObjectType(allowStatic, allowExact, allowSpread, allowProto) {
1322 var oldInType = this.state.inType;
1323 this.state.inType = true;
1324 var nodeStart = this.startNode();
1325 nodeStart.callProperties = [];
1326 nodeStart.properties = [];
1327 nodeStart.indexers = [];
1328 nodeStart.internalSlots = [];
1329 var endDelim;
1330 var exact;
1331
1332 if (allowExact && this.match(types.braceBarL)) {
1333 this.expect(types.braceBarL);
1334 endDelim = types.braceBarR;
1335 exact = true;
1336 } else {
1337 this.expect(types.braceL);
1338 endDelim = types.braceR;
1339 exact = false;
1340 }
1341
1342 nodeStart.exact = exact;
1343
1344 while (!this.match(endDelim)) {
1345 var isStatic = false;
1346 var protoStart = null;
1347 var node = this.startNode();
1348
1349 if (allowProto && this.isContextual("proto")) {
1350 var lookahead = this.lookahead();
1351
1352 if (lookahead.type !== types.colon && lookahead.type !== types.question) {
1353 this.next();
1354 protoStart = this.state.start;
1355 allowStatic = false;
1356 }
1357 }
1358
1359 if (allowStatic && this.isContextual("static")) {
1360 var _lookahead = this.lookahead();
1361
1362 if (_lookahead.type !== types.colon && _lookahead.type !== types.question) {
1363 this.next();
1364 isStatic = true;
1365 }
1366 }
1367
1368 var variance = this.flowParseVariance();
1369
1370 if (this.eat(types.bracketL)) {
1371 if (protoStart != null) {
1372 this.unexpected(protoStart);
1373 }
1374
1375 if (this.eat(types.bracketL)) {
1376 if (variance) {
1377 this.unexpected(variance.start);
1378 }
1379
1380 nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
1381 } else {
1382 nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
1383 }
1384 } else if (this.match(types.parenL) || this.isRelational("<")) {
1385 if (protoStart != null) {
1386 this.unexpected(protoStart);
1387 }
1388
1389 if (variance) {
1390 this.unexpected(variance.start);
1391 }
1392
1393 nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
1394 } else {
1395 var kind = "init";
1396
1397 if (this.isContextual("get") || this.isContextual("set")) {
1398 var _lookahead2 = this.lookahead();
1399
1400 if (_lookahead2.type === types.name || _lookahead2.type === types.string || _lookahead2.type === types.num) {
1401 kind = this.state.value;
1402 this.next();
1403 }
1404 }
1405
1406 nodeStart.properties.push(this.flowParseObjectTypeProperty(node, isStatic, protoStart, variance, kind, allowSpread));
1407 }
1408
1409 this.flowObjectTypeSemicolon();
1410 }
1411
1412 this.expect(endDelim);
1413 var out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
1414 this.state.inType = oldInType;
1415 return out;
1416 };
1417
1418 _proto.flowParseObjectTypeProperty = function flowParseObjectTypeProperty(node, isStatic, protoStart, variance, kind, allowSpread) {
1419 if (this.match(types.ellipsis)) {
1420 if (!allowSpread) {
1421 this.unexpected(null, "Spread operator cannot appear in class or interface definitions");
1422 }
1423
1424 if (protoStart != null) {
1425 this.unexpected(protoStart);
1426 }
1427
1428 if (variance) {
1429 this.unexpected(variance.start, "Spread properties cannot have variance");
1430 }
1431
1432 this.expect(types.ellipsis);
1433 node.argument = this.flowParseType();
1434 return this.finishNode(node, "ObjectTypeSpreadProperty");
1435 } else {
1436 node.key = this.flowParseObjectPropertyKey();
1437 node.static = isStatic;
1438 node.proto = protoStart != null;
1439 node.kind = kind;
1440 var optional = false;
1441
1442 if (this.isRelational("<") || this.match(types.parenL)) {
1443 node.method = true;
1444
1445 if (protoStart != null) {
1446 this.unexpected(protoStart);
1447 }
1448
1449 if (variance) {
1450 this.unexpected(variance.start);
1451 }
1452
1453 node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.start, node.loc.start));
1454
1455 if (kind === "get" || kind === "set") {
1456 this.flowCheckGetterSetterParams(node);
1457 }
1458 } else {
1459 if (kind !== "init") this.unexpected();
1460 node.method = false;
1461
1462 if (this.eat(types.question)) {
1463 optional = true;
1464 }
1465
1466 node.value = this.flowParseTypeInitialiser();
1467 node.variance = variance;
1468 }
1469
1470 node.optional = optional;
1471 return this.finishNode(node, "ObjectTypeProperty");
1472 }
1473 };
1474
1475 _proto.flowCheckGetterSetterParams = function flowCheckGetterSetterParams(property) {
1476 var paramCount = property.kind === "get" ? 0 : 1;
1477 var start = property.start;
1478 var length = property.value.params.length + (property.value.rest ? 1 : 0);
1479
1480 if (length !== paramCount) {
1481 if (property.kind === "get") {
1482 this.raise(start, "getter must not have any formal parameters");
1483 } else {
1484 this.raise(start, "setter must have exactly one formal parameter");
1485 }
1486 }
1487
1488 if (property.kind === "set" && property.value.rest) {
1489 this.raise(start, "setter function argument must not be a rest parameter");
1490 }
1491 };
1492
1493 _proto.flowObjectTypeSemicolon = function flowObjectTypeSemicolon() {
1494 if (!this.eat(types.semi) && !this.eat(types.comma) && !this.match(types.braceR) && !this.match(types.braceBarR)) {
1495 this.unexpected();
1496 }
1497 };
1498
1499 _proto.flowParseQualifiedTypeIdentifier = function flowParseQualifiedTypeIdentifier(startPos, startLoc, id) {
1500 startPos = startPos || this.state.start;
1501 startLoc = startLoc || this.state.startLoc;
1502 var node = id || this.parseIdentifier();
1503
1504 while (this.eat(types.dot)) {
1505 var node2 = this.startNodeAt(startPos, startLoc);
1506 node2.qualification = node;
1507 node2.id = this.parseIdentifier();
1508 node = this.finishNode(node2, "QualifiedTypeIdentifier");
1509 }
1510
1511 return node;
1512 };
1513
1514 _proto.flowParseGenericType = function flowParseGenericType(startPos, startLoc, id) {
1515 var node = this.startNodeAt(startPos, startLoc);
1516 node.typeParameters = null;
1517 node.id = this.flowParseQualifiedTypeIdentifier(startPos, startLoc, id);
1518
1519 if (this.isRelational("<")) {
1520 node.typeParameters = this.flowParseTypeParameterInstantiation();
1521 }
1522
1523 return this.finishNode(node, "GenericTypeAnnotation");
1524 };
1525
1526 _proto.flowParseTypeofType = function flowParseTypeofType() {
1527 var node = this.startNode();
1528 this.expect(types._typeof);
1529 node.argument = this.flowParsePrimaryType();
1530 return this.finishNode(node, "TypeofTypeAnnotation");
1531 };
1532
1533 _proto.flowParseTupleType = function flowParseTupleType() {
1534 var node = this.startNode();
1535 node.types = [];
1536 this.expect(types.bracketL);
1537
1538 while (this.state.pos < this.input.length && !this.match(types.bracketR)) {
1539 node.types.push(this.flowParseType());
1540 if (this.match(types.bracketR)) break;
1541 this.expect(types.comma);
1542 }
1543
1544 this.expect(types.bracketR);
1545 return this.finishNode(node, "TupleTypeAnnotation");
1546 };
1547
1548 _proto.flowParseFunctionTypeParam = function flowParseFunctionTypeParam() {
1549 var name = null;
1550 var optional = false;
1551 var typeAnnotation = null;
1552 var node = this.startNode();
1553 var lh = this.lookahead();
1554
1555 if (lh.type === types.colon || lh.type === types.question) {
1556 name = this.parseIdentifier();
1557
1558 if (this.eat(types.question)) {
1559 optional = true;
1560 }
1561
1562 typeAnnotation = this.flowParseTypeInitialiser();
1563 } else {
1564 typeAnnotation = this.flowParseType();
1565 }
1566
1567 node.name = name;
1568 node.optional = optional;
1569 node.typeAnnotation = typeAnnotation;
1570 return this.finishNode(node, "FunctionTypeParam");
1571 };
1572
1573 _proto.reinterpretTypeAsFunctionTypeParam = function reinterpretTypeAsFunctionTypeParam(type) {
1574 var node = this.startNodeAt(type.start, type.loc.start);
1575 node.name = null;
1576 node.optional = false;
1577 node.typeAnnotation = type;
1578 return this.finishNode(node, "FunctionTypeParam");
1579 };
1580
1581 _proto.flowParseFunctionTypeParams = function flowParseFunctionTypeParams(params) {
1582 if (params === void 0) {
1583 params = [];
1584 }
1585
1586 var rest = null;
1587
1588 while (!this.match(types.parenR) && !this.match(types.ellipsis)) {
1589 params.push(this.flowParseFunctionTypeParam());
1590
1591 if (!this.match(types.parenR)) {
1592 this.expect(types.comma);
1593 }
1594 }
1595
1596 if (this.eat(types.ellipsis)) {
1597 rest = this.flowParseFunctionTypeParam();
1598 }
1599
1600 return {
1601 params: params,
1602 rest: rest
1603 };
1604 };
1605
1606 _proto.flowIdentToTypeAnnotation = function flowIdentToTypeAnnotation(startPos, startLoc, node, id) {
1607 switch (id.name) {
1608 case "any":
1609 return this.finishNode(node, "AnyTypeAnnotation");
1610
1611 case "void":
1612 return this.finishNode(node, "VoidTypeAnnotation");
1613
1614 case "bool":
1615 case "boolean":
1616 return this.finishNode(node, "BooleanTypeAnnotation");
1617
1618 case "mixed":
1619 return this.finishNode(node, "MixedTypeAnnotation");
1620
1621 case "empty":
1622 return this.finishNode(node, "EmptyTypeAnnotation");
1623
1624 case "number":
1625 return this.finishNode(node, "NumberTypeAnnotation");
1626
1627 case "string":
1628 return this.finishNode(node, "StringTypeAnnotation");
1629
1630 default:
1631 return this.flowParseGenericType(startPos, startLoc, id);
1632 }
1633 };
1634
1635 _proto.flowParsePrimaryType = function flowParsePrimaryType() {
1636 var startPos = this.state.start;
1637 var startLoc = this.state.startLoc;
1638 var node = this.startNode();
1639 var tmp;
1640 var type;
1641 var isGroupedType = false;
1642 var oldNoAnonFunctionType = this.state.noAnonFunctionType;
1643
1644 switch (this.state.type) {
1645 case types.name:
1646 if (this.isContextual("interface")) {
1647 return this.flowParseInterfaceType();
1648 }
1649
1650 return this.flowIdentToTypeAnnotation(startPos, startLoc, node, this.parseIdentifier());
1651
1652 case types.braceL:
1653 return this.flowParseObjectType(false, false, true, false);
1654
1655 case types.braceBarL:
1656 return this.flowParseObjectType(false, true, true, false);
1657
1658 case types.bracketL:
1659 return this.flowParseTupleType();
1660
1661 case types.relational:
1662 if (this.state.value === "<") {
1663 node.typeParameters = this.flowParseTypeParameterDeclaration(false);
1664 this.expect(types.parenL);
1665 tmp = this.flowParseFunctionTypeParams();
1666 node.params = tmp.params;
1667 node.rest = tmp.rest;
1668 this.expect(types.parenR);
1669 this.expect(types.arrow);
1670 node.returnType = this.flowParseType();
1671 return this.finishNode(node, "FunctionTypeAnnotation");
1672 }
1673
1674 break;
1675
1676 case types.parenL:
1677 this.next();
1678
1679 if (!this.match(types.parenR) && !this.match(types.ellipsis)) {
1680 if (this.match(types.name)) {
1681 var token = this.lookahead().type;
1682 isGroupedType = token !== types.question && token !== types.colon;
1683 } else {
1684 isGroupedType = true;
1685 }
1686 }
1687
1688 if (isGroupedType) {
1689 this.state.noAnonFunctionType = false;
1690 type = this.flowParseType();
1691 this.state.noAnonFunctionType = oldNoAnonFunctionType;
1692
1693 if (this.state.noAnonFunctionType || !(this.match(types.comma) || this.match(types.parenR) && this.lookahead().type === types.arrow)) {
1694 this.expect(types.parenR);
1695 return type;
1696 } else {
1697 this.eat(types.comma);
1698 }
1699 }
1700
1701 if (type) {
1702 tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
1703 } else {
1704 tmp = this.flowParseFunctionTypeParams();
1705 }
1706
1707 node.params = tmp.params;
1708 node.rest = tmp.rest;
1709 this.expect(types.parenR);
1710 this.expect(types.arrow);
1711 node.returnType = this.flowParseType();
1712 node.typeParameters = null;
1713 return this.finishNode(node, "FunctionTypeAnnotation");
1714
1715 case types.string:
1716 return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
1717
1718 case types._true:
1719 case types._false:
1720 node.value = this.match(types._true);
1721 this.next();
1722 return this.finishNode(node, "BooleanLiteralTypeAnnotation");
1723
1724 case types.plusMin:
1725 if (this.state.value === "-") {
1726 this.next();
1727
1728 if (!this.match(types.num)) {
1729 this.unexpected(null, "Unexpected token, expected \"number\"");
1730 }
1731
1732 return this.parseLiteral(-this.state.value, "NumberLiteralTypeAnnotation", node.start, node.loc.start);
1733 }
1734
1735 this.unexpected();
1736
1737 case types.num:
1738 return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
1739
1740 case types._null:
1741 this.next();
1742 return this.finishNode(node, "NullLiteralTypeAnnotation");
1743
1744 case types._this:
1745 this.next();
1746 return this.finishNode(node, "ThisTypeAnnotation");
1747
1748 case types.star:
1749 this.next();
1750 return this.finishNode(node, "ExistsTypeAnnotation");
1751
1752 default:
1753 if (this.state.type.keyword === "typeof") {
1754 return this.flowParseTypeofType();
1755 }
1756
1757 }
1758
1759 throw this.unexpected();
1760 };
1761
1762 _proto.flowParsePostfixType = function flowParsePostfixType() {
1763 var startPos = this.state.start,
1764 startLoc = this.state.startLoc;
1765 var type = this.flowParsePrimaryType();
1766
1767 while (!this.canInsertSemicolon() && this.match(types.bracketL)) {
1768 var node = this.startNodeAt(startPos, startLoc);
1769 node.elementType = type;
1770 this.expect(types.bracketL);
1771 this.expect(types.bracketR);
1772 type = this.finishNode(node, "ArrayTypeAnnotation");
1773 }
1774
1775 return type;
1776 };
1777
1778 _proto.flowParsePrefixType = function flowParsePrefixType() {
1779 var node = this.startNode();
1780
1781 if (this.eat(types.question)) {
1782 node.typeAnnotation = this.flowParsePrefixType();
1783 return this.finishNode(node, "NullableTypeAnnotation");
1784 } else {
1785 return this.flowParsePostfixType();
1786 }
1787 };
1788
1789 _proto.flowParseAnonFunctionWithoutParens = function flowParseAnonFunctionWithoutParens() {
1790 var param = this.flowParsePrefixType();
1791
1792 if (!this.state.noAnonFunctionType && this.eat(types.arrow)) {
1793 var node = this.startNodeAt(param.start, param.loc.start);
1794 node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
1795 node.rest = null;
1796 node.returnType = this.flowParseType();
1797 node.typeParameters = null;
1798 return this.finishNode(node, "FunctionTypeAnnotation");
1799 }
1800
1801 return param;
1802 };
1803
1804 _proto.flowParseIntersectionType = function flowParseIntersectionType() {
1805 var node = this.startNode();
1806 this.eat(types.bitwiseAND);
1807 var type = this.flowParseAnonFunctionWithoutParens();
1808 node.types = [type];
1809
1810 while (this.eat(types.bitwiseAND)) {
1811 node.types.push(this.flowParseAnonFunctionWithoutParens());
1812 }
1813
1814 return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
1815 };
1816
1817 _proto.flowParseUnionType = function flowParseUnionType() {
1818 var node = this.startNode();
1819 this.eat(types.bitwiseOR);
1820 var type = this.flowParseIntersectionType();
1821 node.types = [type];
1822
1823 while (this.eat(types.bitwiseOR)) {
1824 node.types.push(this.flowParseIntersectionType());
1825 }
1826
1827 return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
1828 };
1829
1830 _proto.flowParseType = function flowParseType() {
1831 var oldInType = this.state.inType;
1832 this.state.inType = true;
1833 var type = this.flowParseUnionType();
1834 this.state.inType = oldInType;
1835 this.state.exprAllowed = this.state.exprAllowed || this.state.noAnonFunctionType;
1836 return type;
1837 };
1838
1839 _proto.flowParseTypeAnnotation = function flowParseTypeAnnotation() {
1840 var node = this.startNode();
1841 node.typeAnnotation = this.flowParseTypeInitialiser();
1842 return this.finishNode(node, "TypeAnnotation");
1843 };
1844
1845 _proto.flowParseTypeAnnotatableIdentifier = function flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
1846 var ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
1847
1848 if (this.match(types.colon)) {
1849 ident.typeAnnotation = this.flowParseTypeAnnotation();
1850 this.finishNode(ident, ident.type);
1851 }
1852
1853 return ident;
1854 };
1855
1856 _proto.typeCastToParameter = function typeCastToParameter(node) {
1857 node.expression.typeAnnotation = node.typeAnnotation;
1858 return this.finishNodeAt(node.expression, node.expression.type, node.typeAnnotation.end, node.typeAnnotation.loc.end);
1859 };
1860
1861 _proto.flowParseVariance = function flowParseVariance() {
1862 var variance = null;
1863
1864 if (this.match(types.plusMin)) {
1865 variance = this.startNode();
1866
1867 if (this.state.value === "+") {
1868 variance.kind = "plus";
1869 } else {
1870 variance.kind = "minus";
1871 }
1872
1873 this.next();
1874 this.finishNode(variance, "Variance");
1875 }
1876
1877 return variance;
1878 };
1879
1880 _proto.parseFunctionBody = function parseFunctionBody(node, allowExpressionBody) {
1881 var _this3 = this;
1882
1883 if (allowExpressionBody) {
1884 return this.forwardNoArrowParamsConversionAt(node, function () {
1885 return _superClass.prototype.parseFunctionBody.call(_this3, node, true);
1886 });
1887 }
1888
1889 return _superClass.prototype.parseFunctionBody.call(this, node, false);
1890 };
1891
1892 _proto.parseFunctionBodyAndFinish = function parseFunctionBodyAndFinish(node, type, allowExpressionBody) {
1893 if (!allowExpressionBody && this.match(types.colon)) {
1894 var typeNode = this.startNode();
1895
1896 var _this$flowParseTypeAn2 = this.flowParseTypeAndPredicateInitialiser();
1897
1898 typeNode.typeAnnotation = _this$flowParseTypeAn2[0];
1899 node.predicate = _this$flowParseTypeAn2[1];
1900 node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
1901 }
1902
1903 _superClass.prototype.parseFunctionBodyAndFinish.call(this, node, type, allowExpressionBody);
1904 };
1905
1906 _proto.parseStatement = function parseStatement(declaration, topLevel) {
1907 if (this.state.strict && this.match(types.name) && this.state.value === "interface") {
1908 var node = this.startNode();
1909 this.next();
1910 return this.flowParseInterface(node);
1911 } else {
1912 var stmt = _superClass.prototype.parseStatement.call(this, declaration, topLevel);
1913
1914 if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
1915 this.flowPragma = null;
1916 }
1917
1918 return stmt;
1919 }
1920 };
1921
1922 _proto.parseExpressionStatement = function parseExpressionStatement(node, expr) {
1923 if (expr.type === "Identifier") {
1924 if (expr.name === "declare") {
1925 if (this.match(types._class) || this.match(types.name) || this.match(types._function) || this.match(types._var) || this.match(types._export)) {
1926 return this.flowParseDeclare(node);
1927 }
1928 } else if (this.match(types.name)) {
1929 if (expr.name === "interface") {
1930 return this.flowParseInterface(node);
1931 } else if (expr.name === "type") {
1932 return this.flowParseTypeAlias(node);
1933 } else if (expr.name === "opaque") {
1934 return this.flowParseOpaqueType(node, false);
1935 }
1936 }
1937 }
1938
1939 return _superClass.prototype.parseExpressionStatement.call(this, node, expr);
1940 };
1941
1942 _proto.shouldParseExportDeclaration = function shouldParseExportDeclaration() {
1943 return this.isContextual("type") || this.isContextual("interface") || this.isContextual("opaque") || _superClass.prototype.shouldParseExportDeclaration.call(this);
1944 };
1945
1946 _proto.isExportDefaultSpecifier = function isExportDefaultSpecifier() {
1947 if (this.match(types.name) && (this.state.value === "type" || this.state.value === "interface" || this.state.value == "opaque")) {
1948 return false;
1949 }
1950
1951 return _superClass.prototype.isExportDefaultSpecifier.call(this);
1952 };
1953
1954 _proto.parseConditional = function parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) {
1955 var _this4 = this;
1956
1957 if (!this.match(types.question)) return expr;
1958
1959 if (refNeedsArrowPos) {
1960 var _state = this.state.clone();
1961
1962 try {
1963 return _superClass.prototype.parseConditional.call(this, expr, noIn, startPos, startLoc);
1964 } catch (err) {
1965 if (err instanceof SyntaxError) {
1966 this.state = _state;
1967 refNeedsArrowPos.start = err.pos || this.state.start;
1968 return expr;
1969 } else {
1970 throw err;
1971 }
1972 }
1973 }
1974
1975 this.expect(types.question);
1976 var state = this.state.clone();
1977 var originalNoArrowAt = this.state.noArrowAt;
1978 var node = this.startNodeAt(startPos, startLoc);
1979
1980 var _this$tryParseConditi = this.tryParseConditionalConsequent(),
1981 consequent = _this$tryParseConditi.consequent,
1982 failed = _this$tryParseConditi.failed;
1983
1984 var _this$getArrowLikeExp = this.getArrowLikeExpressions(consequent),
1985 valid = _this$getArrowLikeExp[0],
1986 invalid = _this$getArrowLikeExp[1];
1987
1988 if (failed || invalid.length > 0) {
1989 var noArrowAt = originalNoArrowAt.concat();
1990
1991 if (invalid.length > 0) {
1992 this.state = state;
1993 this.state.noArrowAt = noArrowAt;
1994
1995 for (var i = 0; i < invalid.length; i++) {
1996 noArrowAt.push(invalid[i].start);
1997 }
1998
1999 var _this$tryParseConditi2 = this.tryParseConditionalConsequent();
2000
2001 consequent = _this$tryParseConditi2.consequent;
2002 failed = _this$tryParseConditi2.failed;
2003
2004 var _this$getArrowLikeExp2 = this.getArrowLikeExpressions(consequent);
2005
2006 valid = _this$getArrowLikeExp2[0];
2007 invalid = _this$getArrowLikeExp2[1];
2008 }
2009
2010 if (failed && valid.length > 1) {
2011 this.raise(state.start, "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.");
2012 }
2013
2014 if (failed && valid.length === 1) {
2015 this.state = state;
2016 this.state.noArrowAt = noArrowAt.concat(valid[0].start);
2017
2018 var _this$tryParseConditi3 = this.tryParseConditionalConsequent();
2019
2020 consequent = _this$tryParseConditi3.consequent;
2021 failed = _this$tryParseConditi3.failed;
2022 }
2023
2024 this.getArrowLikeExpressions(consequent, true);
2025 }
2026
2027 this.state.noArrowAt = originalNoArrowAt;
2028 this.expect(types.colon);
2029 node.test = expr;
2030 node.consequent = consequent;
2031 node.alternate = this.forwardNoArrowParamsConversionAt(node, function () {
2032 return _this4.parseMaybeAssign(noIn, undefined, undefined, undefined);
2033 });
2034 return this.finishNode(node, "ConditionalExpression");
2035 };
2036
2037 _proto.tryParseConditionalConsequent = function tryParseConditionalConsequent() {
2038 this.state.noArrowParamsConversionAt.push(this.state.start);
2039 var consequent = this.parseMaybeAssign();
2040 var failed = !this.match(types.colon);
2041 this.state.noArrowParamsConversionAt.pop();
2042 return {
2043 consequent: consequent,
2044 failed: failed
2045 };
2046 };
2047
2048 _proto.getArrowLikeExpressions = function getArrowLikeExpressions(node, disallowInvalid) {
2049 var _this5 = this;
2050
2051 var stack = [node];
2052 var arrows = [];
2053
2054 while (stack.length !== 0) {
2055 var _node = stack.pop();
2056
2057 if (_node.type === "ArrowFunctionExpression") {
2058 if (_node.typeParameters || !_node.returnType) {
2059 this.toAssignableList(_node.params, true, "arrow function parameters");
2060
2061 _superClass.prototype.checkFunctionNameAndParams.call(this, _node, true);
2062 } else {
2063 arrows.push(_node);
2064 }
2065
2066 stack.push(_node.body);
2067 } else if (_node.type === "ConditionalExpression") {
2068 stack.push(_node.consequent);
2069 stack.push(_node.alternate);
2070 }
2071 }
2072
2073 if (disallowInvalid) {
2074 for (var i = 0; i < arrows.length; i++) {
2075 this.toAssignableList(node.params, true, "arrow function parameters");
2076 }
2077
2078 return [arrows, []];
2079 }
2080
2081 return partition(arrows, function (node) {
2082 try {
2083 _this5.toAssignableList(node.params, true, "arrow function parameters");
2084
2085 return true;
2086 } catch (err) {
2087 return false;
2088 }
2089 });
2090 };
2091
2092 _proto.forwardNoArrowParamsConversionAt = function forwardNoArrowParamsConversionAt(node, parse) {
2093 var result;
2094
2095 if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
2096 this.state.noArrowParamsConversionAt.push(this.state.start);
2097 result = parse();
2098 this.state.noArrowParamsConversionAt.pop();
2099 } else {
2100 result = parse();
2101 }
2102
2103 return result;
2104 };
2105
2106 _proto.parseParenItem = function parseParenItem(node, startPos, startLoc) {
2107 node = _superClass.prototype.parseParenItem.call(this, node, startPos, startLoc);
2108
2109 if (this.eat(types.question)) {
2110 node.optional = true;
2111 }
2112
2113 if (this.match(types.colon)) {
2114 var typeCastNode = this.startNodeAt(startPos, startLoc);
2115 typeCastNode.expression = node;
2116 typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
2117 return this.finishNode(typeCastNode, "TypeCastExpression");
2118 }
2119
2120 return node;
2121 };
2122
2123 _proto.assertModuleNodeAllowed = function assertModuleNodeAllowed(node) {
2124 if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
2125 return;
2126 }
2127
2128 _superClass.prototype.assertModuleNodeAllowed.call(this, node);
2129 };
2130
2131 _proto.parseExport = function parseExport(node) {
2132 node = _superClass.prototype.parseExport.call(this, node);
2133
2134 if (node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") {
2135 node.exportKind = node.exportKind || "value";
2136 }
2137
2138 return node;
2139 };
2140
2141 _proto.parseExportDeclaration = function parseExportDeclaration(node) {
2142 if (this.isContextual("type")) {
2143 node.exportKind = "type";
2144 var declarationNode = this.startNode();
2145 this.next();
2146
2147 if (this.match(types.braceL)) {
2148 node.specifiers = this.parseExportSpecifiers();
2149 this.parseExportFrom(node);
2150 return null;
2151 } else {
2152 return this.flowParseTypeAlias(declarationNode);
2153 }
2154 } else if (this.isContextual("opaque")) {
2155 node.exportKind = "type";
2156
2157 var _declarationNode = this.startNode();
2158
2159 this.next();
2160 return this.flowParseOpaqueType(_declarationNode, false);
2161 } else if (this.isContextual("interface")) {
2162 node.exportKind = "type";
2163
2164 var _declarationNode2 = this.startNode();
2165
2166 this.next();
2167 return this.flowParseInterface(_declarationNode2);
2168 } else {
2169 return _superClass.prototype.parseExportDeclaration.call(this, node);
2170 }
2171 };
2172
2173 _proto.shouldParseExportStar = function shouldParseExportStar() {
2174 return _superClass.prototype.shouldParseExportStar.call(this) || this.isContextual("type") && this.lookahead().type === types.star;
2175 };
2176
2177 _proto.parseExportStar = function parseExportStar(node) {
2178 if (this.eatContextual("type")) {
2179 node.exportKind = "type";
2180 }
2181
2182 return _superClass.prototype.parseExportStar.call(this, node);
2183 };
2184
2185 _proto.parseExportNamespace = function parseExportNamespace(node) {
2186 if (node.exportKind === "type") {
2187 this.unexpected();
2188 }
2189
2190 return _superClass.prototype.parseExportNamespace.call(this, node);
2191 };
2192
2193 _proto.parseClassId = function parseClassId(node, isStatement, optionalId) {
2194 _superClass.prototype.parseClassId.call(this, node, isStatement, optionalId);
2195
2196 if (this.isRelational("<")) {
2197 node.typeParameters = this.flowParseTypeParameterDeclaration();
2198 }
2199 };
2200
2201 _proto.isKeyword = function isKeyword$$1(name) {
2202 if (this.state.inType && name === "void") {
2203 return false;
2204 } else {
2205 return _superClass.prototype.isKeyword.call(this, name);
2206 }
2207 };
2208
2209 _proto.readToken = function readToken(code) {
2210 var next = this.input.charCodeAt(this.state.pos + 1);
2211
2212 if (this.state.inType && (code === 62 || code === 60)) {
2213 return this.finishOp(types.relational, 1);
2214 } else if (isIteratorStart(code, next)) {
2215 this.state.isIterator = true;
2216 return _superClass.prototype.readWord.call(this);
2217 } else {
2218 return _superClass.prototype.readToken.call(this, code);
2219 }
2220 };
2221
2222 _proto.toAssignable = function toAssignable(node, isBinding, contextDescription) {
2223 if (node.type === "TypeCastExpression") {
2224 return _superClass.prototype.toAssignable.call(this, this.typeCastToParameter(node), isBinding, contextDescription);
2225 } else {
2226 return _superClass.prototype.toAssignable.call(this, node, isBinding, contextDescription);
2227 }
2228 };
2229
2230 _proto.toAssignableList = function toAssignableList(exprList, isBinding, contextDescription) {
2231 for (var i = 0; i < exprList.length; i++) {
2232 var expr = exprList[i];
2233
2234 if (expr && expr.type === "TypeCastExpression") {
2235 exprList[i] = this.typeCastToParameter(expr);
2236 }
2237 }
2238
2239 return _superClass.prototype.toAssignableList.call(this, exprList, isBinding, contextDescription);
2240 };
2241
2242 _proto.toReferencedList = function toReferencedList(exprList) {
2243 for (var i = 0; i < exprList.length; i++) {
2244 var expr = exprList[i];
2245
2246 if (expr && expr._exprListItem && expr.type === "TypeCastExpression") {
2247 this.raise(expr.start, "Unexpected type cast");
2248 }
2249 }
2250
2251 return exprList;
2252 };
2253
2254 _proto.parseExprListItem = function parseExprListItem(allowEmpty, refShorthandDefaultPos, refNeedsArrowPos) {
2255 var container = this.startNode();
2256
2257 var node = _superClass.prototype.parseExprListItem.call(this, allowEmpty, refShorthandDefaultPos, refNeedsArrowPos);
2258
2259 if (this.match(types.colon)) {
2260 container._exprListItem = true;
2261 container.expression = node;
2262 container.typeAnnotation = this.flowParseTypeAnnotation();
2263 return this.finishNode(container, "TypeCastExpression");
2264 } else {
2265 return node;
2266 }
2267 };
2268
2269 _proto.checkLVal = function checkLVal(expr, isBinding, checkClashes, contextDescription) {
2270 if (expr.type !== "TypeCastExpression") {
2271 return _superClass.prototype.checkLVal.call(this, expr, isBinding, checkClashes, contextDescription);
2272 }
2273 };
2274
2275 _proto.parseClassProperty = function parseClassProperty(node) {
2276 if (this.match(types.colon)) {
2277 node.typeAnnotation = this.flowParseTypeAnnotation();
2278 }
2279
2280 return _superClass.prototype.parseClassProperty.call(this, node);
2281 };
2282
2283 _proto.parseClassPrivateProperty = function parseClassPrivateProperty(node) {
2284 if (this.match(types.colon)) {
2285 node.typeAnnotation = this.flowParseTypeAnnotation();
2286 }
2287
2288 return _superClass.prototype.parseClassPrivateProperty.call(this, node);
2289 };
2290
2291 _proto.isClassMethod = function isClassMethod() {
2292 return this.isRelational("<") || _superClass.prototype.isClassMethod.call(this);
2293 };
2294
2295 _proto.isClassProperty = function isClassProperty() {
2296 return this.match(types.colon) || _superClass.prototype.isClassProperty.call(this);
2297 };
2298
2299 _proto.isNonstaticConstructor = function isNonstaticConstructor(method) {
2300 return !this.match(types.colon) && _superClass.prototype.isNonstaticConstructor.call(this, method);
2301 };
2302
2303 _proto.pushClassMethod = function pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) {
2304 if (method.variance) {
2305 this.unexpected(method.variance.start);
2306 }
2307
2308 delete method.variance;
2309
2310 if (this.isRelational("<")) {
2311 method.typeParameters = this.flowParseTypeParameterDeclaration(false);
2312 }
2313
2314 _superClass.prototype.pushClassMethod.call(this, classBody, method, isGenerator, isAsync, isConstructor);
2315 };
2316
2317 _proto.pushClassPrivateMethod = function pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
2318 if (method.variance) {
2319 this.unexpected(method.variance.start);
2320 }
2321
2322 delete method.variance;
2323
2324 if (this.isRelational("<")) {
2325 method.typeParameters = this.flowParseTypeParameterDeclaration();
2326 }
2327
2328 _superClass.prototype.pushClassPrivateMethod.call(this, classBody, method, isGenerator, isAsync);
2329 };
2330
2331 _proto.parseClassSuper = function parseClassSuper(node) {
2332 _superClass.prototype.parseClassSuper.call(this, node);
2333
2334 if (node.superClass && this.isRelational("<")) {
2335 node.superTypeParameters = this.flowParseTypeParameterInstantiation();
2336 }
2337
2338 if (this.isContextual("implements")) {
2339 this.next();
2340 var implemented = node.implements = [];
2341
2342 do {
2343 var _node2 = this.startNode();
2344
2345 _node2.id = this.flowParseRestrictedIdentifier(true);
2346
2347 if (this.isRelational("<")) {
2348 _node2.typeParameters = this.flowParseTypeParameterInstantiation();
2349 } else {
2350 _node2.typeParameters = null;
2351 }
2352
2353 implemented.push(this.finishNode(_node2, "ClassImplements"));
2354 } while (this.eat(types.comma));
2355 }
2356 };
2357
2358 _proto.parsePropertyName = function parsePropertyName(node) {
2359 var variance = this.flowParseVariance();
2360
2361 var key = _superClass.prototype.parsePropertyName.call(this, node);
2362
2363 node.variance = variance;
2364 return key;
2365 };
2366
2367 _proto.parseObjPropValue = function parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc) {
2368 if (prop.variance) {
2369 this.unexpected(prop.variance.start);
2370 }
2371
2372 delete prop.variance;
2373 var typeParameters;
2374
2375 if (this.isRelational("<")) {
2376 typeParameters = this.flowParseTypeParameterDeclaration(false);
2377 if (!this.match(types.parenL)) this.unexpected();
2378 }
2379
2380 _superClass.prototype.parseObjPropValue.call(this, prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc);
2381
2382 if (typeParameters) {
2383 (prop.value || prop).typeParameters = typeParameters;
2384 }
2385 };
2386
2387 _proto.parseAssignableListItemTypes = function parseAssignableListItemTypes(param) {
2388 if (this.eat(types.question)) {
2389 if (param.type !== "Identifier") {
2390 throw this.raise(param.start, "A binding pattern parameter cannot be optional in an implementation signature.");
2391 }
2392
2393 param.optional = true;
2394 }
2395
2396 if (this.match(types.colon)) {
2397 param.typeAnnotation = this.flowParseTypeAnnotation();
2398 }
2399
2400 this.finishNode(param, param.type);
2401 return param;
2402 };
2403
2404 _proto.parseMaybeDefault = function parseMaybeDefault(startPos, startLoc, left) {
2405 var node = _superClass.prototype.parseMaybeDefault.call(this, startPos, startLoc, left);
2406
2407 if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
2408 this.raise(node.typeAnnotation.start, "Type annotations must come before default assignments, " + "e.g. instead of `age = 25: number` use `age: number = 25`");
2409 }
2410
2411 return node;
2412 };
2413
2414 _proto.shouldParseDefaultImport = function shouldParseDefaultImport(node) {
2415 if (!hasTypeImportKind(node)) {
2416 return _superClass.prototype.shouldParseDefaultImport.call(this, node);
2417 }
2418
2419 return isMaybeDefaultImport(this.state);
2420 };
2421
2422 _proto.parseImportSpecifierLocal = function parseImportSpecifierLocal(node, specifier, type, contextDescription) {
2423 specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true) : this.parseIdentifier();
2424 this.checkLVal(specifier.local, true, undefined, contextDescription);
2425 node.specifiers.push(this.finishNode(specifier, type));
2426 };
2427
2428 _proto.parseImportSpecifiers = function parseImportSpecifiers(node) {
2429 node.importKind = "value";
2430 var kind = null;
2431
2432 if (this.match(types._typeof)) {
2433 kind = "typeof";
2434 } else if (this.isContextual("type")) {
2435 kind = "type";
2436 }
2437
2438 if (kind) {
2439 var lh = this.lookahead();
2440
2441 if (kind === "type" && lh.type === types.star) {
2442 this.unexpected(lh.start);
2443 }
2444
2445 if (isMaybeDefaultImport(lh) || lh.type === types.braceL || lh.type === types.star) {
2446 this.next();
2447 node.importKind = kind;
2448 }
2449 }
2450
2451 _superClass.prototype.parseImportSpecifiers.call(this, node);
2452 };
2453
2454 _proto.parseImportSpecifier = function parseImportSpecifier(node) {
2455 var specifier = this.startNode();
2456 var firstIdentLoc = this.state.start;
2457 var firstIdent = this.parseIdentifier(true);
2458 var specifierTypeKind = null;
2459
2460 if (firstIdent.name === "type") {
2461 specifierTypeKind = "type";
2462 } else if (firstIdent.name === "typeof") {
2463 specifierTypeKind = "typeof";
2464 }
2465
2466 var isBinding = false;
2467
2468 if (this.isContextual("as") && !this.isLookaheadContextual("as")) {
2469 var as_ident = this.parseIdentifier(true);
2470
2471 if (specifierTypeKind !== null && !this.match(types.name) && !this.state.type.keyword) {
2472 specifier.imported = as_ident;
2473 specifier.importKind = specifierTypeKind;
2474 specifier.local = as_ident.__clone();
2475 } else {
2476 specifier.imported = firstIdent;
2477 specifier.importKind = null;
2478 specifier.local = this.parseIdentifier();
2479 }
2480 } else if (specifierTypeKind !== null && (this.match(types.name) || this.state.type.keyword)) {
2481 specifier.imported = this.parseIdentifier(true);
2482 specifier.importKind = specifierTypeKind;
2483
2484 if (this.eatContextual("as")) {
2485 specifier.local = this.parseIdentifier();
2486 } else {
2487 isBinding = true;
2488 specifier.local = specifier.imported.__clone();
2489 }
2490 } else {
2491 isBinding = true;
2492 specifier.imported = firstIdent;
2493 specifier.importKind = null;
2494 specifier.local = specifier.imported.__clone();
2495 }
2496
2497 var nodeIsTypeImport = hasTypeImportKind(node);
2498 var specifierIsTypeImport = hasTypeImportKind(specifier);
2499
2500 if (nodeIsTypeImport && specifierIsTypeImport) {
2501 this.raise(firstIdentLoc, "The `type` and `typeof` keywords on named imports can only be used on regular " + "`import` statements. It cannot be used with `import type` or `import typeof` statements");
2502 }
2503
2504 if (nodeIsTypeImport || specifierIsTypeImport) {
2505 this.checkReservedType(specifier.local.name, specifier.local.start);
2506 }
2507
2508 if (isBinding && !nodeIsTypeImport && !specifierIsTypeImport) {
2509 this.checkReservedWord(specifier.local.name, specifier.start, true, true);
2510 }
2511
2512 this.checkLVal(specifier.local, true, undefined, "import specifier");
2513 node.specifiers.push(this.finishNode(specifier, "ImportSpecifier"));
2514 };
2515
2516 _proto.parseFunctionParams = function parseFunctionParams(node) {
2517 var kind = node.kind;
2518
2519 if (kind !== "get" && kind !== "set" && this.isRelational("<")) {
2520 node.typeParameters = this.flowParseTypeParameterDeclaration(false);
2521 }
2522
2523 _superClass.prototype.parseFunctionParams.call(this, node);
2524 };
2525
2526 _proto.parseVarHead = function parseVarHead(decl) {
2527 _superClass.prototype.parseVarHead.call(this, decl);
2528
2529 if (this.match(types.colon)) {
2530 decl.id.typeAnnotation = this.flowParseTypeAnnotation();
2531 this.finishNode(decl.id, decl.id.type);
2532 }
2533 };
2534
2535 _proto.parseAsyncArrowFromCallExpression = function parseAsyncArrowFromCallExpression(node, call) {
2536 if (this.match(types.colon)) {
2537 var oldNoAnonFunctionType = this.state.noAnonFunctionType;
2538 this.state.noAnonFunctionType = true;
2539 node.returnType = this.flowParseTypeAnnotation();
2540 this.state.noAnonFunctionType = oldNoAnonFunctionType;
2541 }
2542
2543 return _superClass.prototype.parseAsyncArrowFromCallExpression.call(this, node, call);
2544 };
2545
2546 _proto.shouldParseAsyncArrow = function shouldParseAsyncArrow() {
2547 return this.match(types.colon) || _superClass.prototype.shouldParseAsyncArrow.call(this);
2548 };
2549
2550 _proto.parseMaybeAssign = function parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos) {
2551 var _this6 = this;
2552
2553 var jsxError = null;
2554
2555 if (types.jsxTagStart && this.match(types.jsxTagStart)) {
2556 var state = this.state.clone();
2557
2558 try {
2559 return _superClass.prototype.parseMaybeAssign.call(this, noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos);
2560 } catch (err) {
2561 if (err instanceof SyntaxError) {
2562 this.state = state;
2563 this.state.context.length -= 2;
2564 jsxError = err;
2565 } else {
2566 throw err;
2567 }
2568 }
2569 }
2570
2571 if (jsxError != null || this.isRelational("<")) {
2572 var arrowExpression;
2573 var typeParameters;
2574
2575 try {
2576 typeParameters = this.flowParseTypeParameterDeclaration();
2577 arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, function () {
2578 return _superClass.prototype.parseMaybeAssign.call(_this6, noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos);
2579 });
2580 arrowExpression.typeParameters = typeParameters;
2581 this.resetStartLocationFromNode(arrowExpression, typeParameters);
2582 } catch (err) {
2583 throw jsxError || err;
2584 }
2585
2586 if (arrowExpression.type === "ArrowFunctionExpression") {
2587 return arrowExpression;
2588 } else if (jsxError != null) {
2589 throw jsxError;
2590 } else {
2591 this.raise(typeParameters.start, "Expected an arrow function after this type parameter declaration");
2592 }
2593 }
2594
2595 return _superClass.prototype.parseMaybeAssign.call(this, noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos);
2596 };
2597
2598 _proto.parseArrow = function parseArrow(node) {
2599 if (this.match(types.colon)) {
2600 var state = this.state.clone();
2601
2602 try {
2603 var oldNoAnonFunctionType = this.state.noAnonFunctionType;
2604 this.state.noAnonFunctionType = true;
2605 var typeNode = this.startNode();
2606
2607 var _this$flowParseTypeAn3 = this.flowParseTypeAndPredicateInitialiser();
2608
2609 typeNode.typeAnnotation = _this$flowParseTypeAn3[0];
2610 node.predicate = _this$flowParseTypeAn3[1];
2611 this.state.noAnonFunctionType = oldNoAnonFunctionType;
2612 if (this.canInsertSemicolon()) this.unexpected();
2613 if (!this.match(types.arrow)) this.unexpected();
2614 node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
2615 } catch (err) {
2616 if (err instanceof SyntaxError) {
2617 this.state = state;
2618 } else {
2619 throw err;
2620 }
2621 }
2622 }
2623
2624 return _superClass.prototype.parseArrow.call(this, node);
2625 };
2626
2627 _proto.shouldParseArrow = function shouldParseArrow() {
2628 return this.match(types.colon) || _superClass.prototype.shouldParseArrow.call(this);
2629 };
2630
2631 _proto.setArrowFunctionParameters = function setArrowFunctionParameters(node, params) {
2632 if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
2633 node.params = params;
2634 } else {
2635 _superClass.prototype.setArrowFunctionParameters.call(this, node, params);
2636 }
2637 };
2638
2639 _proto.checkFunctionNameAndParams = function checkFunctionNameAndParams(node, isArrowFunction) {
2640 if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
2641 return;
2642 }
2643
2644 return _superClass.prototype.checkFunctionNameAndParams.call(this, node, isArrowFunction);
2645 };
2646
2647 _proto.parseParenAndDistinguishExpression = function parseParenAndDistinguishExpression(canBeArrow) {
2648 return _superClass.prototype.parseParenAndDistinguishExpression.call(this, canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
2649 };
2650
2651 _proto.parseSubscripts = function parseSubscripts(base, startPos, startLoc, noCalls) {
2652 if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startPos) !== -1) {
2653 this.next();
2654 var node = this.startNodeAt(startPos, startLoc);
2655 node.callee = base;
2656 node.arguments = this.parseCallExpressionArguments(types.parenR, false);
2657 base = this.finishNode(node, "CallExpression");
2658 } else if (base.type === "Identifier" && base.name === "async" && this.isRelational("<")) {
2659 var state = this.state.clone();
2660 var error;
2661
2662 try {
2663 var _node3 = this.parseAsyncArrowWithTypeParameters(startPos, startLoc);
2664
2665 if (_node3) return _node3;
2666 } catch (e) {
2667 error = e;
2668 }
2669
2670 this.state = state;
2671
2672 try {
2673 return _superClass.prototype.parseSubscripts.call(this, base, startPos, startLoc, noCalls);
2674 } catch (e) {
2675 throw error || e;
2676 }
2677 }
2678
2679 return _superClass.prototype.parseSubscripts.call(this, base, startPos, startLoc, noCalls);
2680 };
2681
2682 _proto.parseSubscript = function parseSubscript(base, startPos, startLoc, noCalls, subscriptState) {
2683 if (this.match(types.questionDot) && this.isLookaheadRelational("<")) {
2684 this.expectPlugin("optionalChaining");
2685 subscriptState.optionalChainMember = true;
2686
2687 if (noCalls) {
2688 subscriptState.stop = true;
2689 return base;
2690 }
2691
2692 this.next();
2693 var node = this.startNodeAt(startPos, startLoc);
2694 node.callee = base;
2695 node.typeArguments = this.flowParseTypeParameterInstantiation();
2696 this.expect(types.parenL);
2697 node.arguments = this.parseCallExpressionArguments(types.parenR, false);
2698 node.optional = true;
2699 return this.finishNode(node, "OptionalCallExpression");
2700 } else if (!noCalls && this.shouldParseTypes() && this.isRelational("<")) {
2701 var _node4 = this.startNodeAt(startPos, startLoc);
2702
2703 _node4.callee = base;
2704 var state = this.state.clone();
2705
2706 try {
2707 _node4.typeArguments = this.flowParseTypeParameterInstantiation();
2708 this.expect(types.parenL);
2709 _node4.arguments = this.parseCallExpressionArguments(types.parenR, false);
2710
2711 if (subscriptState.optionalChainMember) {
2712 _node4.optional = false;
2713 return this.finishNode(_node4, "OptionalCallExpression");
2714 }
2715
2716 return this.finishNode(_node4, "CallExpression");
2717 } catch (e) {
2718 if (e instanceof SyntaxError) {
2719 this.state = state;
2720 } else {
2721 throw e;
2722 }
2723 }
2724 }
2725
2726 return _superClass.prototype.parseSubscript.call(this, base, startPos, startLoc, noCalls, subscriptState);
2727 };
2728
2729 _proto.parseNewArguments = function parseNewArguments(node) {
2730 var targs = null;
2731
2732 if (this.shouldParseTypes() && this.isRelational("<")) {
2733 var state = this.state.clone();
2734
2735 try {
2736 targs = this.flowParseTypeParameterInstantiation();
2737 } catch (e) {
2738 if (e instanceof SyntaxError) {
2739 this.state = state;
2740 } else {
2741 throw e;
2742 }
2743 }
2744 }
2745
2746 node.typeArguments = targs;
2747
2748 _superClass.prototype.parseNewArguments.call(this, node);
2749 };
2750
2751 _proto.parseAsyncArrowWithTypeParameters = function parseAsyncArrowWithTypeParameters(startPos, startLoc) {
2752 var node = this.startNodeAt(startPos, startLoc);
2753 this.parseFunctionParams(node);
2754 if (!this.parseArrow(node)) return;
2755 return this.parseArrowExpression(node, undefined, true);
2756 };
2757
2758 _proto.readToken_mult_modulo = function readToken_mult_modulo(code) {
2759 var next = this.input.charCodeAt(this.state.pos + 1);
2760
2761 if (code === 42 && next === 47 && this.state.hasFlowComment) {
2762 this.state.hasFlowComment = false;
2763 this.state.pos += 2;
2764 this.nextToken();
2765 return;
2766 }
2767
2768 _superClass.prototype.readToken_mult_modulo.call(this, code);
2769 };
2770
2771 _proto.skipBlockComment = function skipBlockComment() {
2772 if (this.hasPlugin("flow") && this.hasPlugin("flowComments") && this.skipFlowComment()) {
2773 this.hasFlowCommentCompletion();
2774 this.state.pos += this.skipFlowComment();
2775 this.state.hasFlowComment = true;
2776 return;
2777 }
2778
2779 var end;
2780
2781 if (this.hasPlugin("flow") && this.state.hasFlowComment) {
2782 end = this.input.indexOf("*-/", this.state.pos += 2);
2783 if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment");
2784 this.state.pos = end + 3;
2785 return;
2786 }
2787
2788 _superClass.prototype.skipBlockComment.call(this);
2789 };
2790
2791 _proto.skipFlowComment = function skipFlowComment() {
2792 var ch2 = this.input.charCodeAt(this.state.pos + 2);
2793 var ch3 = this.input.charCodeAt(this.state.pos + 3);
2794
2795 if (ch2 === 58 && ch3 === 58) {
2796 return 4;
2797 }
2798
2799 if (this.input.slice(this.state.pos + 2, 14) === "flow-include") {
2800 return 14;
2801 }
2802
2803 if (ch2 === 58 && ch3 !== 58) {
2804 return 2;
2805 }
2806
2807 return false;
2808 };
2809
2810 _proto.hasFlowCommentCompletion = function hasFlowCommentCompletion() {
2811 var end = this.input.indexOf("*/", this.state.pos);
2812
2813 if (end === -1) {
2814 this.raise(this.state.pos, "Unterminated comment");
2815 }
2816 };
2817
2818 return _class;
2819 }(superClass);
2820});
2821
2822var entities = {
2823 quot: "\"",
2824 amp: "&",
2825 apos: "'",
2826 lt: "<",
2827 gt: ">",
2828 nbsp: "\xA0",
2829 iexcl: "\xA1",
2830 cent: "\xA2",
2831 pound: "\xA3",
2832 curren: "\xA4",
2833 yen: "\xA5",
2834 brvbar: "\xA6",
2835 sect: "\xA7",
2836 uml: "\xA8",
2837 copy: "\xA9",
2838 ordf: "\xAA",
2839 laquo: "\xAB",
2840 not: "\xAC",
2841 shy: "\xAD",
2842 reg: "\xAE",
2843 macr: "\xAF",
2844 deg: "\xB0",
2845 plusmn: "\xB1",
2846 sup2: "\xB2",
2847 sup3: "\xB3",
2848 acute: "\xB4",
2849 micro: "\xB5",
2850 para: "\xB6",
2851 middot: "\xB7",
2852 cedil: "\xB8",
2853 sup1: "\xB9",
2854 ordm: "\xBA",
2855 raquo: "\xBB",
2856 frac14: "\xBC",
2857 frac12: "\xBD",
2858 frac34: "\xBE",
2859 iquest: "\xBF",
2860 Agrave: "\xC0",
2861 Aacute: "\xC1",
2862 Acirc: "\xC2",
2863 Atilde: "\xC3",
2864 Auml: "\xC4",
2865 Aring: "\xC5",
2866 AElig: "\xC6",
2867 Ccedil: "\xC7",
2868 Egrave: "\xC8",
2869 Eacute: "\xC9",
2870 Ecirc: "\xCA",
2871 Euml: "\xCB",
2872 Igrave: "\xCC",
2873 Iacute: "\xCD",
2874 Icirc: "\xCE",
2875 Iuml: "\xCF",
2876 ETH: "\xD0",
2877 Ntilde: "\xD1",
2878 Ograve: "\xD2",
2879 Oacute: "\xD3",
2880 Ocirc: "\xD4",
2881 Otilde: "\xD5",
2882 Ouml: "\xD6",
2883 times: "\xD7",
2884 Oslash: "\xD8",
2885 Ugrave: "\xD9",
2886 Uacute: "\xDA",
2887 Ucirc: "\xDB",
2888 Uuml: "\xDC",
2889 Yacute: "\xDD",
2890 THORN: "\xDE",
2891 szlig: "\xDF",
2892 agrave: "\xE0",
2893 aacute: "\xE1",
2894 acirc: "\xE2",
2895 atilde: "\xE3",
2896 auml: "\xE4",
2897 aring: "\xE5",
2898 aelig: "\xE6",
2899 ccedil: "\xE7",
2900 egrave: "\xE8",
2901 eacute: "\xE9",
2902 ecirc: "\xEA",
2903 euml: "\xEB",
2904 igrave: "\xEC",
2905 iacute: "\xED",
2906 icirc: "\xEE",
2907 iuml: "\xEF",
2908 eth: "\xF0",
2909 ntilde: "\xF1",
2910 ograve: "\xF2",
2911 oacute: "\xF3",
2912 ocirc: "\xF4",
2913 otilde: "\xF5",
2914 ouml: "\xF6",
2915 divide: "\xF7",
2916 oslash: "\xF8",
2917 ugrave: "\xF9",
2918 uacute: "\xFA",
2919 ucirc: "\xFB",
2920 uuml: "\xFC",
2921 yacute: "\xFD",
2922 thorn: "\xFE",
2923 yuml: "\xFF",
2924 OElig: "\u0152",
2925 oelig: "\u0153",
2926 Scaron: "\u0160",
2927 scaron: "\u0161",
2928 Yuml: "\u0178",
2929 fnof: "\u0192",
2930 circ: "\u02C6",
2931 tilde: "\u02DC",
2932 Alpha: "\u0391",
2933 Beta: "\u0392",
2934 Gamma: "\u0393",
2935 Delta: "\u0394",
2936 Epsilon: "\u0395",
2937 Zeta: "\u0396",
2938 Eta: "\u0397",
2939 Theta: "\u0398",
2940 Iota: "\u0399",
2941 Kappa: "\u039A",
2942 Lambda: "\u039B",
2943 Mu: "\u039C",
2944 Nu: "\u039D",
2945 Xi: "\u039E",
2946 Omicron: "\u039F",
2947 Pi: "\u03A0",
2948 Rho: "\u03A1",
2949 Sigma: "\u03A3",
2950 Tau: "\u03A4",
2951 Upsilon: "\u03A5",
2952 Phi: "\u03A6",
2953 Chi: "\u03A7",
2954 Psi: "\u03A8",
2955 Omega: "\u03A9",
2956 alpha: "\u03B1",
2957 beta: "\u03B2",
2958 gamma: "\u03B3",
2959 delta: "\u03B4",
2960 epsilon: "\u03B5",
2961 zeta: "\u03B6",
2962 eta: "\u03B7",
2963 theta: "\u03B8",
2964 iota: "\u03B9",
2965 kappa: "\u03BA",
2966 lambda: "\u03BB",
2967 mu: "\u03BC",
2968 nu: "\u03BD",
2969 xi: "\u03BE",
2970 omicron: "\u03BF",
2971 pi: "\u03C0",
2972 rho: "\u03C1",
2973 sigmaf: "\u03C2",
2974 sigma: "\u03C3",
2975 tau: "\u03C4",
2976 upsilon: "\u03C5",
2977 phi: "\u03C6",
2978 chi: "\u03C7",
2979 psi: "\u03C8",
2980 omega: "\u03C9",
2981 thetasym: "\u03D1",
2982 upsih: "\u03D2",
2983 piv: "\u03D6",
2984 ensp: "\u2002",
2985 emsp: "\u2003",
2986 thinsp: "\u2009",
2987 zwnj: "\u200C",
2988 zwj: "\u200D",
2989 lrm: "\u200E",
2990 rlm: "\u200F",
2991 ndash: "\u2013",
2992 mdash: "\u2014",
2993 lsquo: "\u2018",
2994 rsquo: "\u2019",
2995 sbquo: "\u201A",
2996 ldquo: "\u201C",
2997 rdquo: "\u201D",
2998 bdquo: "\u201E",
2999 dagger: "\u2020",
3000 Dagger: "\u2021",
3001 bull: "\u2022",
3002 hellip: "\u2026",
3003 permil: "\u2030",
3004 prime: "\u2032",
3005 Prime: "\u2033",
3006 lsaquo: "\u2039",
3007 rsaquo: "\u203A",
3008 oline: "\u203E",
3009 frasl: "\u2044",
3010 euro: "\u20AC",
3011 image: "\u2111",
3012 weierp: "\u2118",
3013 real: "\u211C",
3014 trade: "\u2122",
3015 alefsym: "\u2135",
3016 larr: "\u2190",
3017 uarr: "\u2191",
3018 rarr: "\u2192",
3019 darr: "\u2193",
3020 harr: "\u2194",
3021 crarr: "\u21B5",
3022 lArr: "\u21D0",
3023 uArr: "\u21D1",
3024 rArr: "\u21D2",
3025 dArr: "\u21D3",
3026 hArr: "\u21D4",
3027 forall: "\u2200",
3028 part: "\u2202",
3029 exist: "\u2203",
3030 empty: "\u2205",
3031 nabla: "\u2207",
3032 isin: "\u2208",
3033 notin: "\u2209",
3034 ni: "\u220B",
3035 prod: "\u220F",
3036 sum: "\u2211",
3037 minus: "\u2212",
3038 lowast: "\u2217",
3039 radic: "\u221A",
3040 prop: "\u221D",
3041 infin: "\u221E",
3042 ang: "\u2220",
3043 and: "\u2227",
3044 or: "\u2228",
3045 cap: "\u2229",
3046 cup: "\u222A",
3047 int: "\u222B",
3048 there4: "\u2234",
3049 sim: "\u223C",
3050 cong: "\u2245",
3051 asymp: "\u2248",
3052 ne: "\u2260",
3053 equiv: "\u2261",
3054 le: "\u2264",
3055 ge: "\u2265",
3056 sub: "\u2282",
3057 sup: "\u2283",
3058 nsub: "\u2284",
3059 sube: "\u2286",
3060 supe: "\u2287",
3061 oplus: "\u2295",
3062 otimes: "\u2297",
3063 perp: "\u22A5",
3064 sdot: "\u22C5",
3065 lceil: "\u2308",
3066 rceil: "\u2309",
3067 lfloor: "\u230A",
3068 rfloor: "\u230B",
3069 lang: "\u2329",
3070 rang: "\u232A",
3071 loz: "\u25CA",
3072 spades: "\u2660",
3073 clubs: "\u2663",
3074 hearts: "\u2665",
3075 diams: "\u2666"
3076};
3077
3078var lineBreak = /\r\n?|\n|\u2028|\u2029/;
3079var lineBreakG = new RegExp(lineBreak.source, "g");
3080function isNewLine(code) {
3081 return code === 10 || code === 13 || code === 0x2028 || code === 0x2029;
3082}
3083var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
3084
3085var TokContext = function TokContext(token, isExpr, preserveSpace, override) {
3086 this.token = token;
3087 this.isExpr = !!isExpr;
3088 this.preserveSpace = !!preserveSpace;
3089 this.override = override;
3090};
3091var types$1 = {
3092 braceStatement: new TokContext("{", false),
3093 braceExpression: new TokContext("{", true),
3094 templateQuasi: new TokContext("${", true),
3095 parenStatement: new TokContext("(", false),
3096 parenExpression: new TokContext("(", true),
3097 template: new TokContext("`", true, true, function (p) {
3098 return p.readTmplToken();
3099 }),
3100 functionExpression: new TokContext("function", true)
3101};
3102
3103types.parenR.updateContext = types.braceR.updateContext = function () {
3104 if (this.state.context.length === 1) {
3105 this.state.exprAllowed = true;
3106 return;
3107 }
3108
3109 var out = this.state.context.pop();
3110
3111 if (out === types$1.braceStatement && this.curContext() === types$1.functionExpression) {
3112 this.state.context.pop();
3113 this.state.exprAllowed = false;
3114 } else if (out === types$1.templateQuasi) {
3115 this.state.exprAllowed = true;
3116 } else {
3117 this.state.exprAllowed = !out.isExpr;
3118 }
3119};
3120
3121types.name.updateContext = function (prevType) {
3122 if (this.state.value === "of" && this.curContext() === types$1.parenStatement) {
3123 this.state.exprAllowed = !prevType.beforeExpr;
3124 return;
3125 }
3126
3127 this.state.exprAllowed = false;
3128
3129 if (prevType === types._let || prevType === types._const || prevType === types._var) {
3130 if (lineBreak.test(this.input.slice(this.state.end))) {
3131 this.state.exprAllowed = true;
3132 }
3133 }
3134
3135 if (this.state.isIterator) {
3136 this.state.isIterator = false;
3137 }
3138};
3139
3140types.braceL.updateContext = function (prevType) {
3141 this.state.context.push(this.braceIsBlock(prevType) ? types$1.braceStatement : types$1.braceExpression);
3142 this.state.exprAllowed = true;
3143};
3144
3145types.dollarBraceL.updateContext = function () {
3146 this.state.context.push(types$1.templateQuasi);
3147 this.state.exprAllowed = true;
3148};
3149
3150types.parenL.updateContext = function (prevType) {
3151 var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
3152 this.state.context.push(statementParens ? types$1.parenStatement : types$1.parenExpression);
3153 this.state.exprAllowed = true;
3154};
3155
3156types.incDec.updateContext = function () {};
3157
3158types._function.updateContext = function (prevType) {
3159 if (this.state.exprAllowed && !this.braceIsBlock(prevType)) {
3160 this.state.context.push(types$1.functionExpression);
3161 }
3162
3163 this.state.exprAllowed = false;
3164};
3165
3166types.backQuote.updateContext = function () {
3167 if (this.curContext() === types$1.template) {
3168 this.state.context.pop();
3169 } else {
3170 this.state.context.push(types$1.template);
3171 }
3172
3173 this.state.exprAllowed = false;
3174};
3175
3176var HEX_NUMBER = /^[\da-fA-F]+$/;
3177var DECIMAL_NUMBER = /^\d+$/;
3178types$1.j_oTag = new TokContext("<tag", false);
3179types$1.j_cTag = new TokContext("</tag", false);
3180types$1.j_expr = new TokContext("<tag>...</tag>", true, true);
3181types.jsxName = new TokenType("jsxName");
3182types.jsxText = new TokenType("jsxText", {
3183 beforeExpr: true
3184});
3185types.jsxTagStart = new TokenType("jsxTagStart", {
3186 startsExpr: true
3187});
3188types.jsxTagEnd = new TokenType("jsxTagEnd");
3189
3190types.jsxTagStart.updateContext = function () {
3191 this.state.context.push(types$1.j_expr);
3192 this.state.context.push(types$1.j_oTag);
3193 this.state.exprAllowed = false;
3194};
3195
3196types.jsxTagEnd.updateContext = function (prevType) {
3197 var out = this.state.context.pop();
3198
3199 if (out === types$1.j_oTag && prevType === types.slash || out === types$1.j_cTag) {
3200 this.state.context.pop();
3201 this.state.exprAllowed = this.curContext() === types$1.j_expr;
3202 } else {
3203 this.state.exprAllowed = true;
3204 }
3205};
3206
3207function isFragment(object) {
3208 return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
3209}
3210
3211function getQualifiedJSXName(object) {
3212 if (object.type === "JSXIdentifier") {
3213 return object.name;
3214 }
3215
3216 if (object.type === "JSXNamespacedName") {
3217 return object.namespace.name + ":" + object.name.name;
3218 }
3219
3220 if (object.type === "JSXMemberExpression") {
3221 return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
3222 }
3223
3224 throw new Error("Node had unexpected type: " + object.type);
3225}
3226
3227var jsx = (function (superClass) {
3228 return function (_superClass) {
3229 _inheritsLoose(_class, _superClass);
3230
3231 function _class() {
3232 return _superClass.apply(this, arguments) || this;
3233 }
3234
3235 var _proto = _class.prototype;
3236
3237 _proto.jsxReadToken = function jsxReadToken() {
3238 var out = "";
3239 var chunkStart = this.state.pos;
3240
3241 for (;;) {
3242 if (this.state.pos >= this.input.length) {
3243 this.raise(this.state.start, "Unterminated JSX contents");
3244 }
3245
3246 var ch = this.input.charCodeAt(this.state.pos);
3247
3248 switch (ch) {
3249 case 60:
3250 case 123:
3251 if (this.state.pos === this.state.start) {
3252 if (ch === 60 && this.state.exprAllowed) {
3253 ++this.state.pos;
3254 return this.finishToken(types.jsxTagStart);
3255 }
3256
3257 return this.getTokenFromCode(ch);
3258 }
3259
3260 out += this.input.slice(chunkStart, this.state.pos);
3261 return this.finishToken(types.jsxText, out);
3262
3263 case 38:
3264 out += this.input.slice(chunkStart, this.state.pos);
3265 out += this.jsxReadEntity();
3266 chunkStart = this.state.pos;
3267 break;
3268
3269 default:
3270 if (isNewLine(ch)) {
3271 out += this.input.slice(chunkStart, this.state.pos);
3272 out += this.jsxReadNewLine(true);
3273 chunkStart = this.state.pos;
3274 } else {
3275 ++this.state.pos;
3276 }
3277
3278 }
3279 }
3280 };
3281
3282 _proto.jsxReadNewLine = function jsxReadNewLine(normalizeCRLF) {
3283 var ch = this.input.charCodeAt(this.state.pos);
3284 var out;
3285 ++this.state.pos;
3286
3287 if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
3288 ++this.state.pos;
3289 out = normalizeCRLF ? "\n" : "\r\n";
3290 } else {
3291 out = String.fromCharCode(ch);
3292 }
3293
3294 ++this.state.curLine;
3295 this.state.lineStart = this.state.pos;
3296 return out;
3297 };
3298
3299 _proto.jsxReadString = function jsxReadString(quote) {
3300 var out = "";
3301 var chunkStart = ++this.state.pos;
3302
3303 for (;;) {
3304 if (this.state.pos >= this.input.length) {
3305 this.raise(this.state.start, "Unterminated string constant");
3306 }
3307
3308 var ch = this.input.charCodeAt(this.state.pos);
3309 if (ch === quote) break;
3310
3311 if (ch === 38) {
3312 out += this.input.slice(chunkStart, this.state.pos);
3313 out += this.jsxReadEntity();
3314 chunkStart = this.state.pos;
3315 } else if (isNewLine(ch)) {
3316 out += this.input.slice(chunkStart, this.state.pos);
3317 out += this.jsxReadNewLine(false);
3318 chunkStart = this.state.pos;
3319 } else {
3320 ++this.state.pos;
3321 }
3322 }
3323
3324 out += this.input.slice(chunkStart, this.state.pos++);
3325 return this.finishToken(types.string, out);
3326 };
3327
3328 _proto.jsxReadEntity = function jsxReadEntity() {
3329 var str = "";
3330 var count = 0;
3331 var entity;
3332 var ch = this.input[this.state.pos];
3333 var startPos = ++this.state.pos;
3334
3335 while (this.state.pos < this.input.length && count++ < 10) {
3336 ch = this.input[this.state.pos++];
3337
3338 if (ch === ";") {
3339 if (str[0] === "#") {
3340 if (str[1] === "x") {
3341 str = str.substr(2);
3342
3343 if (HEX_NUMBER.test(str)) {
3344 entity = String.fromCodePoint(parseInt(str, 16));
3345 }
3346 } else {
3347 str = str.substr(1);
3348
3349 if (DECIMAL_NUMBER.test(str)) {
3350 entity = String.fromCodePoint(parseInt(str, 10));
3351 }
3352 }
3353 } else {
3354 entity = entities[str];
3355 }
3356
3357 break;
3358 }
3359
3360 str += ch;
3361 }
3362
3363 if (!entity) {
3364 this.state.pos = startPos;
3365 return "&";
3366 }
3367
3368 return entity;
3369 };
3370
3371 _proto.jsxReadWord = function jsxReadWord() {
3372 var ch;
3373 var start = this.state.pos;
3374
3375 do {
3376 ch = this.input.charCodeAt(++this.state.pos);
3377 } while (isIdentifierChar(ch) || ch === 45);
3378
3379 return this.finishToken(types.jsxName, this.input.slice(start, this.state.pos));
3380 };
3381
3382 _proto.jsxParseIdentifier = function jsxParseIdentifier() {
3383 var node = this.startNode();
3384
3385 if (this.match(types.jsxName)) {
3386 node.name = this.state.value;
3387 } else if (this.state.type.keyword) {
3388 node.name = this.state.type.keyword;
3389 } else {
3390 this.unexpected();
3391 }
3392
3393 this.next();
3394 return this.finishNode(node, "JSXIdentifier");
3395 };
3396
3397 _proto.jsxParseNamespacedName = function jsxParseNamespacedName() {
3398 var startPos = this.state.start;
3399 var startLoc = this.state.startLoc;
3400 var name = this.jsxParseIdentifier();
3401 if (!this.eat(types.colon)) return name;
3402 var node = this.startNodeAt(startPos, startLoc);
3403 node.namespace = name;
3404 node.name = this.jsxParseIdentifier();
3405 return this.finishNode(node, "JSXNamespacedName");
3406 };
3407
3408 _proto.jsxParseElementName = function jsxParseElementName() {
3409 var startPos = this.state.start;
3410 var startLoc = this.state.startLoc;
3411 var node = this.jsxParseNamespacedName();
3412
3413 while (this.eat(types.dot)) {
3414 var newNode = this.startNodeAt(startPos, startLoc);
3415 newNode.object = node;
3416 newNode.property = this.jsxParseIdentifier();
3417 node = this.finishNode(newNode, "JSXMemberExpression");
3418 }
3419
3420 return node;
3421 };
3422
3423 _proto.jsxParseAttributeValue = function jsxParseAttributeValue() {
3424 var node;
3425
3426 switch (this.state.type) {
3427 case types.braceL:
3428 node = this.jsxParseExpressionContainer();
3429
3430 if (node.expression.type === "JSXEmptyExpression") {
3431 throw this.raise(node.start, "JSX attributes must only be assigned a non-empty expression");
3432 } else {
3433 return node;
3434 }
3435
3436 case types.jsxTagStart:
3437 case types.string:
3438 return this.parseExprAtom();
3439
3440 default:
3441 throw this.raise(this.state.start, "JSX value should be either an expression or a quoted JSX text");
3442 }
3443 };
3444
3445 _proto.jsxParseEmptyExpression = function jsxParseEmptyExpression() {
3446 var node = this.startNodeAt(this.state.lastTokEnd, this.state.lastTokEndLoc);
3447 return this.finishNodeAt(node, "JSXEmptyExpression", this.state.start, this.state.startLoc);
3448 };
3449
3450 _proto.jsxParseSpreadChild = function jsxParseSpreadChild() {
3451 var node = this.startNode();
3452 this.expect(types.braceL);
3453 this.expect(types.ellipsis);
3454 node.expression = this.parseExpression();
3455 this.expect(types.braceR);
3456 return this.finishNode(node, "JSXSpreadChild");
3457 };
3458
3459 _proto.jsxParseExpressionContainer = function jsxParseExpressionContainer() {
3460 var node = this.startNode();
3461 this.next();
3462
3463 if (this.match(types.braceR)) {
3464 node.expression = this.jsxParseEmptyExpression();
3465 } else {
3466 node.expression = this.parseExpression();
3467 }
3468
3469 this.expect(types.braceR);
3470 return this.finishNode(node, "JSXExpressionContainer");
3471 };
3472
3473 _proto.jsxParseAttribute = function jsxParseAttribute() {
3474 var node = this.startNode();
3475
3476 if (this.eat(types.braceL)) {
3477 this.expect(types.ellipsis);
3478 node.argument = this.parseMaybeAssign();
3479 this.expect(types.braceR);
3480 return this.finishNode(node, "JSXSpreadAttribute");
3481 }
3482
3483 node.name = this.jsxParseNamespacedName();
3484 node.value = this.eat(types.eq) ? this.jsxParseAttributeValue() : null;
3485 return this.finishNode(node, "JSXAttribute");
3486 };
3487
3488 _proto.jsxParseOpeningElementAt = function jsxParseOpeningElementAt(startPos, startLoc) {
3489 var node = this.startNodeAt(startPos, startLoc);
3490
3491 if (this.match(types.jsxTagEnd)) {
3492 this.expect(types.jsxTagEnd);
3493 return this.finishNode(node, "JSXOpeningFragment");
3494 }
3495
3496 node.name = this.jsxParseElementName();
3497 return this.jsxParseOpeningElementAfterName(node);
3498 };
3499
3500 _proto.jsxParseOpeningElementAfterName = function jsxParseOpeningElementAfterName(node) {
3501 var attributes = [];
3502
3503 while (!this.match(types.slash) && !this.match(types.jsxTagEnd)) {
3504 attributes.push(this.jsxParseAttribute());
3505 }
3506
3507 node.attributes = attributes;
3508 node.selfClosing = this.eat(types.slash);
3509 this.expect(types.jsxTagEnd);
3510 return this.finishNode(node, "JSXOpeningElement");
3511 };
3512
3513 _proto.jsxParseClosingElementAt = function jsxParseClosingElementAt(startPos, startLoc) {
3514 var node = this.startNodeAt(startPos, startLoc);
3515
3516 if (this.match(types.jsxTagEnd)) {
3517 this.expect(types.jsxTagEnd);
3518 return this.finishNode(node, "JSXClosingFragment");
3519 }
3520
3521 node.name = this.jsxParseElementName();
3522 this.expect(types.jsxTagEnd);
3523 return this.finishNode(node, "JSXClosingElement");
3524 };
3525
3526 _proto.jsxParseElementAt = function jsxParseElementAt(startPos, startLoc) {
3527 var node = this.startNodeAt(startPos, startLoc);
3528 var children = [];
3529 var openingElement = this.jsxParseOpeningElementAt(startPos, startLoc);
3530 var closingElement = null;
3531
3532 if (!openingElement.selfClosing) {
3533 contents: for (;;) {
3534 switch (this.state.type) {
3535 case types.jsxTagStart:
3536 startPos = this.state.start;
3537 startLoc = this.state.startLoc;
3538 this.next();
3539
3540 if (this.eat(types.slash)) {
3541 closingElement = this.jsxParseClosingElementAt(startPos, startLoc);
3542 break contents;
3543 }
3544
3545 children.push(this.jsxParseElementAt(startPos, startLoc));
3546 break;
3547
3548 case types.jsxText:
3549 children.push(this.parseExprAtom());
3550 break;
3551
3552 case types.braceL:
3553 if (this.lookahead().type === types.ellipsis) {
3554 children.push(this.jsxParseSpreadChild());
3555 } else {
3556 children.push(this.jsxParseExpressionContainer());
3557 }
3558
3559 break;
3560
3561 default:
3562 throw this.unexpected();
3563 }
3564 }
3565
3566 if (isFragment(openingElement) && !isFragment(closingElement)) {
3567 this.raise(closingElement.start, "Expected corresponding JSX closing tag for <>");
3568 } else if (!isFragment(openingElement) && isFragment(closingElement)) {
3569 this.raise(closingElement.start, "Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">");
3570 } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
3571 if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
3572 this.raise(closingElement.start, "Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">");
3573 }
3574 }
3575 }
3576
3577 if (isFragment(openingElement)) {
3578 node.openingFragment = openingElement;
3579 node.closingFragment = closingElement;
3580 } else {
3581 node.openingElement = openingElement;
3582 node.closingElement = closingElement;
3583 }
3584
3585 node.children = children;
3586
3587 if (this.match(types.relational) && this.state.value === "<") {
3588 this.raise(this.state.start, "Adjacent JSX elements must be wrapped in an enclosing tag. " + "Did you want a JSX fragment <>...</>?");
3589 }
3590
3591 return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
3592 };
3593
3594 _proto.jsxParseElement = function jsxParseElement() {
3595 var startPos = this.state.start;
3596 var startLoc = this.state.startLoc;
3597 this.next();
3598 return this.jsxParseElementAt(startPos, startLoc);
3599 };
3600
3601 _proto.parseExprAtom = function parseExprAtom(refShortHandDefaultPos) {
3602 if (this.match(types.jsxText)) {
3603 return this.parseLiteral(this.state.value, "JSXText");
3604 } else if (this.match(types.jsxTagStart)) {
3605 return this.jsxParseElement();
3606 } else {
3607 return _superClass.prototype.parseExprAtom.call(this, refShortHandDefaultPos);
3608 }
3609 };
3610
3611 _proto.readToken = function readToken(code) {
3612 if (this.state.inPropertyName) return _superClass.prototype.readToken.call(this, code);
3613 var context = this.curContext();
3614
3615 if (context === types$1.j_expr) {
3616 return this.jsxReadToken();
3617 }
3618
3619 if (context === types$1.j_oTag || context === types$1.j_cTag) {
3620 if (isIdentifierStart(code)) {
3621 return this.jsxReadWord();
3622 }
3623
3624 if (code === 62) {
3625 ++this.state.pos;
3626 return this.finishToken(types.jsxTagEnd);
3627 }
3628
3629 if ((code === 34 || code === 39) && context === types$1.j_oTag) {
3630 return this.jsxReadString(code);
3631 }
3632 }
3633
3634 if (code === 60 && this.state.exprAllowed) {
3635 ++this.state.pos;
3636 return this.finishToken(types.jsxTagStart);
3637 }
3638
3639 return _superClass.prototype.readToken.call(this, code);
3640 };
3641
3642 _proto.updateContext = function updateContext(prevType) {
3643 if (this.match(types.braceL)) {
3644 var curContext = this.curContext();
3645
3646 if (curContext === types$1.j_oTag) {
3647 this.state.context.push(types$1.braceExpression);
3648 } else if (curContext === types$1.j_expr) {
3649 this.state.context.push(types$1.templateQuasi);
3650 } else {
3651 _superClass.prototype.updateContext.call(this, prevType);
3652 }
3653
3654 this.state.exprAllowed = true;
3655 } else if (this.match(types.slash) && prevType === types.jsxTagStart) {
3656 this.state.context.length -= 2;
3657 this.state.context.push(types$1.j_cTag);
3658 this.state.exprAllowed = false;
3659 } else {
3660 return _superClass.prototype.updateContext.call(this, prevType);
3661 }
3662 };
3663
3664 return _class;
3665 }(superClass);
3666});
3667
3668var defaultOptions = {
3669 sourceType: "script",
3670 sourceFilename: undefined,
3671 startLine: 1,
3672 allowAwaitOutsideFunction: false,
3673 allowReturnOutsideFunction: false,
3674 allowImportExportEverywhere: false,
3675 allowSuperOutsideMethod: false,
3676 plugins: [],
3677 strictMode: null,
3678 ranges: false,
3679 tokens: false
3680};
3681function getOptions(opts) {
3682 var options = {};
3683
3684 for (var key in defaultOptions) {
3685 options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key];
3686 }
3687
3688 return options;
3689}
3690
3691var Position = function Position(line, col) {
3692 this.line = line;
3693 this.column = col;
3694};
3695var SourceLocation = function SourceLocation(start, end) {
3696 this.start = start;
3697 this.end = end;
3698};
3699function getLineInfo(input, offset) {
3700 for (var line = 1, cur = 0;;) {
3701 lineBreakG.lastIndex = cur;
3702 var match = lineBreakG.exec(input);
3703
3704 if (match && match.index < offset) {
3705 ++line;
3706 cur = match.index + match[0].length;
3707 } else {
3708 return new Position(line, offset - cur);
3709 }
3710 }
3711
3712 throw new Error("Unreachable");
3713}
3714
3715var BaseParser = function () {
3716 function BaseParser() {
3717 this.sawUnambiguousESM = false;
3718 }
3719
3720 var _proto = BaseParser.prototype;
3721
3722 _proto.isReservedWord = function isReservedWord(word) {
3723 if (word === "await") {
3724 return this.inModule;
3725 } else {
3726 return reservedWords[6](word);
3727 }
3728 };
3729
3730 _proto.hasPlugin = function hasPlugin(name) {
3731 return Object.hasOwnProperty.call(this.plugins, name);
3732 };
3733
3734 _proto.getPluginOption = function getPluginOption(plugin, name) {
3735 if (this.hasPlugin(plugin)) return this.plugins[plugin][name];
3736 };
3737
3738 return BaseParser;
3739}();
3740
3741function last(stack) {
3742 return stack[stack.length - 1];
3743}
3744
3745var CommentsParser = function (_BaseParser) {
3746 _inheritsLoose(CommentsParser, _BaseParser);
3747
3748 function CommentsParser() {
3749 return _BaseParser.apply(this, arguments) || this;
3750 }
3751
3752 var _proto = CommentsParser.prototype;
3753
3754 _proto.addComment = function addComment(comment) {
3755 if (this.filename) comment.loc.filename = this.filename;
3756 this.state.trailingComments.push(comment);
3757 this.state.leadingComments.push(comment);
3758 };
3759
3760 _proto.processComment = function processComment(node) {
3761 if (node.type === "Program" && node.body.length > 0) return;
3762 var stack = this.state.commentStack;
3763 var firstChild, lastChild, trailingComments, i, j;
3764
3765 if (this.state.trailingComments.length > 0) {
3766 if (this.state.trailingComments[0].start >= node.end) {
3767 trailingComments = this.state.trailingComments;
3768 this.state.trailingComments = [];
3769 } else {
3770 this.state.trailingComments.length = 0;
3771 }
3772 } else if (stack.length > 0) {
3773 var lastInStack = last(stack);
3774
3775 if (lastInStack.trailingComments && lastInStack.trailingComments[0].start >= node.end) {
3776 trailingComments = lastInStack.trailingComments;
3777 delete lastInStack.trailingComments;
3778 }
3779 }
3780
3781 if (stack.length > 0 && last(stack).start >= node.start) {
3782 firstChild = stack.pop();
3783 }
3784
3785 while (stack.length > 0 && last(stack).start >= node.start) {
3786 lastChild = stack.pop();
3787 }
3788
3789 if (!lastChild && firstChild) lastChild = firstChild;
3790
3791 if (firstChild && this.state.leadingComments.length > 0) {
3792 var lastComment = last(this.state.leadingComments);
3793
3794 if (firstChild.type === "ObjectProperty") {
3795 if (lastComment.start >= node.start) {
3796 if (this.state.commentPreviousNode) {
3797 for (j = 0; j < this.state.leadingComments.length; j++) {
3798 if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) {
3799 this.state.leadingComments.splice(j, 1);
3800 j--;
3801 }
3802 }
3803
3804 if (this.state.leadingComments.length > 0) {
3805 firstChild.trailingComments = this.state.leadingComments;
3806 this.state.leadingComments = [];
3807 }
3808 }
3809 }
3810 } else if (node.type === "CallExpression" && node.arguments && node.arguments.length) {
3811 var lastArg = last(node.arguments);
3812
3813 if (lastArg && lastComment.start >= lastArg.start && lastComment.end <= node.end) {
3814 if (this.state.commentPreviousNode) {
3815 if (this.state.leadingComments.length > 0) {
3816 lastArg.trailingComments = this.state.leadingComments;
3817 this.state.leadingComments = [];
3818 }
3819 }
3820 }
3821 }
3822 }
3823
3824 if (lastChild) {
3825 if (lastChild.leadingComments) {
3826 if (lastChild !== node && lastChild.leadingComments.length > 0 && last(lastChild.leadingComments).end <= node.start) {
3827 node.leadingComments = lastChild.leadingComments;
3828 delete lastChild.leadingComments;
3829 } else {
3830 for (i = lastChild.leadingComments.length - 2; i >= 0; --i) {
3831 if (lastChild.leadingComments[i].end <= node.start) {
3832 node.leadingComments = lastChild.leadingComments.splice(0, i + 1);
3833 break;
3834 }
3835 }
3836 }
3837 }
3838 } else if (this.state.leadingComments.length > 0) {
3839 if (last(this.state.leadingComments).end <= node.start) {
3840 if (this.state.commentPreviousNode) {
3841 for (j = 0; j < this.state.leadingComments.length; j++) {
3842 if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) {
3843 this.state.leadingComments.splice(j, 1);
3844 j--;
3845 }
3846 }
3847 }
3848
3849 if (this.state.leadingComments.length > 0) {
3850 node.leadingComments = this.state.leadingComments;
3851 this.state.leadingComments = [];
3852 }
3853 } else {
3854 for (i = 0; i < this.state.leadingComments.length; i++) {
3855 if (this.state.leadingComments[i].end > node.start) {
3856 break;
3857 }
3858 }
3859
3860 var leadingComments = this.state.leadingComments.slice(0, i);
3861
3862 if (leadingComments.length) {
3863 node.leadingComments = leadingComments;
3864 }
3865
3866 trailingComments = this.state.leadingComments.slice(i);
3867
3868 if (trailingComments.length === 0) {
3869 trailingComments = null;
3870 }
3871 }
3872 }
3873
3874 this.state.commentPreviousNode = node;
3875
3876 if (trailingComments) {
3877 if (trailingComments.length && trailingComments[0].start >= node.start && last(trailingComments).end <= node.end) {
3878 node.innerComments = trailingComments;
3879 } else {
3880 node.trailingComments = trailingComments;
3881 }
3882 }
3883
3884 stack.push(node);
3885 };
3886
3887 return CommentsParser;
3888}(BaseParser);
3889
3890var LocationParser = function (_CommentsParser) {
3891 _inheritsLoose(LocationParser, _CommentsParser);
3892
3893 function LocationParser() {
3894 return _CommentsParser.apply(this, arguments) || this;
3895 }
3896
3897 var _proto = LocationParser.prototype;
3898
3899 _proto.raise = function raise(pos, message, _temp) {
3900 var _ref = _temp === void 0 ? {} : _temp,
3901 missingPluginNames = _ref.missingPluginNames,
3902 code = _ref.code;
3903
3904 var loc = getLineInfo(this.input, pos);
3905 message += " (" + loc.line + ":" + loc.column + ")";
3906 var err = new SyntaxError(message);
3907 err.pos = pos;
3908 err.loc = loc;
3909
3910 if (missingPluginNames) {
3911 err.missingPlugin = missingPluginNames;
3912 }
3913
3914 if (code !== undefined) {
3915 err.code = code;
3916 }
3917
3918 throw err;
3919 };
3920
3921 return LocationParser;
3922}(CommentsParser);
3923
3924var State = function () {
3925 function State() {}
3926
3927 var _proto = State.prototype;
3928
3929 _proto.init = function init(options, input) {
3930 this.strict = options.strictMode === false ? false : options.sourceType === "module";
3931 this.input = input;
3932 this.potentialArrowAt = -1;
3933 this.noArrowAt = [];
3934 this.noArrowParamsConversionAt = [];
3935 this.inMethod = false;
3936 this.inFunction = false;
3937 this.inParameters = false;
3938 this.maybeInArrowParameters = false;
3939 this.inGenerator = false;
3940 this.inAsync = false;
3941 this.inPropertyName = false;
3942 this.inType = false;
3943 this.inClassProperty = false;
3944 this.noAnonFunctionType = false;
3945 this.hasFlowComment = false;
3946 this.isIterator = false;
3947 this.classLevel = 0;
3948 this.labels = [];
3949 this.decoratorStack = [[]];
3950 this.yieldInPossibleArrowParameters = null;
3951 this.tokens = [];
3952 this.comments = [];
3953 this.trailingComments = [];
3954 this.leadingComments = [];
3955 this.commentStack = [];
3956 this.commentPreviousNode = null;
3957 this.pos = this.lineStart = 0;
3958 this.curLine = options.startLine;
3959 this.type = types.eof;
3960 this.value = null;
3961 this.start = this.end = this.pos;
3962 this.startLoc = this.endLoc = this.curPosition();
3963 this.lastTokEndLoc = this.lastTokStartLoc = null;
3964 this.lastTokStart = this.lastTokEnd = this.pos;
3965 this.context = [types$1.braceStatement];
3966 this.exprAllowed = true;
3967 this.containsEsc = this.containsOctal = false;
3968 this.octalPosition = null;
3969 this.invalidTemplateEscapePosition = null;
3970 this.exportedIdentifiers = [];
3971 };
3972
3973 _proto.curPosition = function curPosition() {
3974 return new Position(this.curLine, this.pos - this.lineStart);
3975 };
3976
3977 _proto.clone = function clone(skipArrays) {
3978 var _this = this;
3979
3980 var state = new State();
3981 Object.keys(this).forEach(function (key) {
3982 var val = _this[key];
3983
3984 if ((!skipArrays || key === "context") && Array.isArray(val)) {
3985 val = val.slice();
3986 }
3987
3988 state[key] = val;
3989 });
3990 return state;
3991 };
3992
3993 return State;
3994}();
3995
3996var _isDigit = function isDigit(code) {
3997 return code >= 48 && code <= 57;
3998};
3999
4000var VALID_REGEX_FLAGS = "gmsiyu";
4001var forbiddenNumericSeparatorSiblings = {
4002 decBinOct: [46, 66, 69, 79, 95, 98, 101, 111],
4003 hex: [46, 88, 95, 120]
4004};
4005var allowedNumericSeparatorSiblings = {};
4006allowedNumericSeparatorSiblings.bin = [48, 49];
4007allowedNumericSeparatorSiblings.oct = allowedNumericSeparatorSiblings.bin.concat([50, 51, 52, 53, 54, 55]);
4008allowedNumericSeparatorSiblings.dec = allowedNumericSeparatorSiblings.oct.concat([56, 57]);
4009allowedNumericSeparatorSiblings.hex = allowedNumericSeparatorSiblings.dec.concat([65, 66, 67, 68, 69, 70, 97, 98, 99, 100, 101, 102]);
4010var Token = function Token(state) {
4011 this.type = state.type;
4012 this.value = state.value;
4013 this.start = state.start;
4014 this.end = state.end;
4015 this.loc = new SourceLocation(state.startLoc, state.endLoc);
4016};
4017
4018function codePointToString(code) {
4019 if (code <= 0xffff) {
4020 return String.fromCharCode(code);
4021 } else {
4022 return String.fromCharCode((code - 0x10000 >> 10) + 0xd800, (code - 0x10000 & 1023) + 0xdc00);
4023 }
4024}
4025
4026var Tokenizer = function (_LocationParser) {
4027 _inheritsLoose(Tokenizer, _LocationParser);
4028
4029 function Tokenizer(options, input) {
4030 var _this;
4031
4032 _this = _LocationParser.call(this) || this;
4033 _this.state = new State();
4034
4035 _this.state.init(options, input);
4036
4037 _this.isLookahead = false;
4038 return _this;
4039 }
4040
4041 var _proto = Tokenizer.prototype;
4042
4043 _proto.next = function next() {
4044 if (this.options.tokens && !this.isLookahead) {
4045 this.state.tokens.push(new Token(this.state));
4046 }
4047
4048 this.state.lastTokEnd = this.state.end;
4049 this.state.lastTokStart = this.state.start;
4050 this.state.lastTokEndLoc = this.state.endLoc;
4051 this.state.lastTokStartLoc = this.state.startLoc;
4052 this.nextToken();
4053 };
4054
4055 _proto.eat = function eat(type) {
4056 if (this.match(type)) {
4057 this.next();
4058 return true;
4059 } else {
4060 return false;
4061 }
4062 };
4063
4064 _proto.match = function match(type) {
4065 return this.state.type === type;
4066 };
4067
4068 _proto.isKeyword = function isKeyword$$1(word) {
4069 return isKeyword(word);
4070 };
4071
4072 _proto.lookahead = function lookahead() {
4073 var old = this.state;
4074 this.state = old.clone(true);
4075 this.isLookahead = true;
4076 this.next();
4077 this.isLookahead = false;
4078 var curr = this.state;
4079 this.state = old;
4080 return curr;
4081 };
4082
4083 _proto.setStrict = function setStrict(strict) {
4084 this.state.strict = strict;
4085 if (!this.match(types.num) && !this.match(types.string)) return;
4086 this.state.pos = this.state.start;
4087
4088 while (this.state.pos < this.state.lineStart) {
4089 this.state.lineStart = this.input.lastIndexOf("\n", this.state.lineStart - 2) + 1;
4090 --this.state.curLine;
4091 }
4092
4093 this.nextToken();
4094 };
4095
4096 _proto.curContext = function curContext() {
4097 return this.state.context[this.state.context.length - 1];
4098 };
4099
4100 _proto.nextToken = function nextToken() {
4101 var curContext = this.curContext();
4102 if (!curContext || !curContext.preserveSpace) this.skipSpace();
4103 this.state.containsOctal = false;
4104 this.state.octalPosition = null;
4105 this.state.start = this.state.pos;
4106 this.state.startLoc = this.state.curPosition();
4107
4108 if (this.state.pos >= this.input.length) {
4109 this.finishToken(types.eof);
4110 return;
4111 }
4112
4113 if (curContext.override) {
4114 curContext.override(this);
4115 } else {
4116 this.readToken(this.fullCharCodeAtPos());
4117 }
4118 };
4119
4120 _proto.readToken = function readToken(code) {
4121 if (isIdentifierStart(code) || code === 92) {
4122 this.readWord();
4123 } else {
4124 this.getTokenFromCode(code);
4125 }
4126 };
4127
4128 _proto.fullCharCodeAtPos = function fullCharCodeAtPos() {
4129 var code = this.input.charCodeAt(this.state.pos);
4130 if (code <= 0xd7ff || code >= 0xe000) return code;
4131 var next = this.input.charCodeAt(this.state.pos + 1);
4132 return (code << 10) + next - 0x35fdc00;
4133 };
4134
4135 _proto.pushComment = function pushComment(block, text, start, end, startLoc, endLoc) {
4136 var comment = {
4137 type: block ? "CommentBlock" : "CommentLine",
4138 value: text,
4139 start: start,
4140 end: end,
4141 loc: new SourceLocation(startLoc, endLoc)
4142 };
4143
4144 if (!this.isLookahead) {
4145 if (this.options.tokens) this.state.tokens.push(comment);
4146 this.state.comments.push(comment);
4147 this.addComment(comment);
4148 }
4149 };
4150
4151 _proto.skipBlockComment = function skipBlockComment() {
4152 var startLoc = this.state.curPosition();
4153 var start = this.state.pos;
4154 var end = this.input.indexOf("*/", this.state.pos += 2);
4155 if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment");
4156 this.state.pos = end + 2;
4157 lineBreakG.lastIndex = start;
4158 var match;
4159
4160 while ((match = lineBreakG.exec(this.input)) && match.index < this.state.pos) {
4161 ++this.state.curLine;
4162 this.state.lineStart = match.index + match[0].length;
4163 }
4164
4165 this.pushComment(true, this.input.slice(start + 2, end), start, this.state.pos, startLoc, this.state.curPosition());
4166 };
4167
4168 _proto.skipLineComment = function skipLineComment(startSkip) {
4169 var start = this.state.pos;
4170 var startLoc = this.state.curPosition();
4171 var ch = this.input.charCodeAt(this.state.pos += startSkip);
4172
4173 if (this.state.pos < this.input.length) {
4174 while (ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233 && ++this.state.pos < this.input.length) {
4175 ch = this.input.charCodeAt(this.state.pos);
4176 }
4177 }
4178
4179 this.pushComment(false, this.input.slice(start + startSkip, this.state.pos), start, this.state.pos, startLoc, this.state.curPosition());
4180 };
4181
4182 _proto.skipSpace = function skipSpace() {
4183 loop: while (this.state.pos < this.input.length) {
4184 var ch = this.input.charCodeAt(this.state.pos);
4185
4186 switch (ch) {
4187 case 32:
4188 case 160:
4189 ++this.state.pos;
4190 break;
4191
4192 case 13:
4193 if (this.input.charCodeAt(this.state.pos + 1) === 10) {
4194 ++this.state.pos;
4195 }
4196
4197 case 10:
4198 case 8232:
4199 case 8233:
4200 ++this.state.pos;
4201 ++this.state.curLine;
4202 this.state.lineStart = this.state.pos;
4203 break;
4204
4205 case 47:
4206 switch (this.input.charCodeAt(this.state.pos + 1)) {
4207 case 42:
4208 this.skipBlockComment();
4209 break;
4210
4211 case 47:
4212 this.skipLineComment(2);
4213 break;
4214
4215 default:
4216 break loop;
4217 }
4218
4219 break;
4220
4221 default:
4222 if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
4223 ++this.state.pos;
4224 } else {
4225 break loop;
4226 }
4227
4228 }
4229 }
4230 };
4231
4232 _proto.finishToken = function finishToken(type, val) {
4233 this.state.end = this.state.pos;
4234 this.state.endLoc = this.state.curPosition();
4235 var prevType = this.state.type;
4236 this.state.type = type;
4237 this.state.value = val;
4238 this.updateContext(prevType);
4239 };
4240
4241 _proto.readToken_dot = function readToken_dot() {
4242 var next = this.input.charCodeAt(this.state.pos + 1);
4243
4244 if (next >= 48 && next <= 57) {
4245 this.readNumber(true);
4246 return;
4247 }
4248
4249 var next2 = this.input.charCodeAt(this.state.pos + 2);
4250
4251 if (next === 46 && next2 === 46) {
4252 this.state.pos += 3;
4253 this.finishToken(types.ellipsis);
4254 } else {
4255 ++this.state.pos;
4256 this.finishToken(types.dot);
4257 }
4258 };
4259
4260 _proto.readToken_slash = function readToken_slash() {
4261 if (this.state.exprAllowed && !this.state.inType) {
4262 ++this.state.pos;
4263 this.readRegexp();
4264 return;
4265 }
4266
4267 var next = this.input.charCodeAt(this.state.pos + 1);
4268
4269 if (next === 61) {
4270 this.finishOp(types.assign, 2);
4271 } else {
4272 this.finishOp(types.slash, 1);
4273 }
4274 };
4275
4276 _proto.readToken_interpreter = function readToken_interpreter() {
4277 if (this.state.pos !== 0 || this.state.input.length < 2) return false;
4278 var start = this.state.pos;
4279 this.state.pos += 1;
4280 var ch = this.input.charCodeAt(this.state.pos);
4281 if (ch !== 33) return false;
4282
4283 while (ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233 && ++this.state.pos < this.input.length) {
4284 ch = this.input.charCodeAt(this.state.pos);
4285 }
4286
4287 var value = this.input.slice(start + 2, this.state.pos);
4288 this.finishToken(types.interpreterDirective, value);
4289 return true;
4290 };
4291
4292 _proto.readToken_mult_modulo = function readToken_mult_modulo(code) {
4293 var type = code === 42 ? types.star : types.modulo;
4294 var width = 1;
4295 var next = this.input.charCodeAt(this.state.pos + 1);
4296 var exprAllowed = this.state.exprAllowed;
4297
4298 if (code === 42 && next === 42) {
4299 width++;
4300 next = this.input.charCodeAt(this.state.pos + 2);
4301 type = types.exponent;
4302 }
4303
4304 if (next === 61 && !exprAllowed) {
4305 width++;
4306 type = types.assign;
4307 }
4308
4309 this.finishOp(type, width);
4310 };
4311
4312 _proto.readToken_pipe_amp = function readToken_pipe_amp(code) {
4313 var next = this.input.charCodeAt(this.state.pos + 1);
4314
4315 if (next === code) {
4316 if (this.input.charCodeAt(this.state.pos + 2) === 61) {
4317 this.finishOp(types.assign, 3);
4318 } else {
4319 this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2);
4320 }
4321
4322 return;
4323 }
4324
4325 if (code === 124) {
4326 if (next === 62) {
4327 this.finishOp(types.pipeline, 2);
4328 return;
4329 } else if (next === 125 && this.hasPlugin("flow")) {
4330 this.finishOp(types.braceBarR, 2);
4331 return;
4332 }
4333 }
4334
4335 if (next === 61) {
4336 this.finishOp(types.assign, 2);
4337 return;
4338 }
4339
4340 this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1);
4341 };
4342
4343 _proto.readToken_caret = function readToken_caret() {
4344 var next = this.input.charCodeAt(this.state.pos + 1);
4345
4346 if (next === 61) {
4347 this.finishOp(types.assign, 2);
4348 } else {
4349 this.finishOp(types.bitwiseXOR, 1);
4350 }
4351 };
4352
4353 _proto.readToken_plus_min = function readToken_plus_min(code) {
4354 var next = this.input.charCodeAt(this.state.pos + 1);
4355
4356 if (next === code) {
4357 if (next === 45 && !this.inModule && this.input.charCodeAt(this.state.pos + 2) === 62 && lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.pos))) {
4358 this.skipLineComment(3);
4359 this.skipSpace();
4360 this.nextToken();
4361 return;
4362 }
4363
4364 this.finishOp(types.incDec, 2);
4365 return;
4366 }
4367
4368 if (next === 61) {
4369 this.finishOp(types.assign, 2);
4370 } else {
4371 this.finishOp(types.plusMin, 1);
4372 }
4373 };
4374
4375 _proto.readToken_lt_gt = function readToken_lt_gt(code) {
4376 var next = this.input.charCodeAt(this.state.pos + 1);
4377 var size = 1;
4378
4379 if (next === code) {
4380 size = code === 62 && this.input.charCodeAt(this.state.pos + 2) === 62 ? 3 : 2;
4381
4382 if (this.input.charCodeAt(this.state.pos + size) === 61) {
4383 this.finishOp(types.assign, size + 1);
4384 return;
4385 }
4386
4387 this.finishOp(types.bitShift, size);
4388 return;
4389 }
4390
4391 if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.state.pos + 2) === 45 && this.input.charCodeAt(this.state.pos + 3) === 45) {
4392 this.skipLineComment(4);
4393 this.skipSpace();
4394 this.nextToken();
4395 return;
4396 }
4397
4398 if (next === 61) {
4399 size = 2;
4400 }
4401
4402 this.finishOp(types.relational, size);
4403 };
4404
4405 _proto.readToken_eq_excl = function readToken_eq_excl(code) {
4406 var next = this.input.charCodeAt(this.state.pos + 1);
4407
4408 if (next === 61) {
4409 this.finishOp(types.equality, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
4410 return;
4411 }
4412
4413 if (code === 61 && next === 62) {
4414 this.state.pos += 2;
4415 this.finishToken(types.arrow);
4416 return;
4417 }
4418
4419 this.finishOp(code === 61 ? types.eq : types.bang, 1);
4420 };
4421
4422 _proto.readToken_question = function readToken_question() {
4423 var next = this.input.charCodeAt(this.state.pos + 1);
4424 var next2 = this.input.charCodeAt(this.state.pos + 2);
4425
4426 if (next === 63 && !this.state.inType) {
4427 if (next2 === 61) {
4428 this.finishOp(types.assign, 3);
4429 } else {
4430 this.finishOp(types.nullishCoalescing, 2);
4431 }
4432 } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
4433 this.state.pos += 2;
4434 this.finishToken(types.questionDot);
4435 } else {
4436 ++this.state.pos;
4437 this.finishToken(types.question);
4438 }
4439 };
4440
4441 _proto.getTokenFromCode = function getTokenFromCode(code) {
4442 switch (code) {
4443 case 35:
4444 if (this.state.pos === 0 && this.readToken_interpreter()) {
4445 return;
4446 }
4447
4448 if ((this.hasPlugin("classPrivateProperties") || this.hasPlugin("classPrivateMethods")) && this.state.classLevel > 0) {
4449 ++this.state.pos;
4450 this.finishToken(types.hash);
4451 return;
4452 } else {
4453 this.raise(this.state.pos, "Unexpected character '" + codePointToString(code) + "'");
4454 }
4455
4456 case 46:
4457 this.readToken_dot();
4458 return;
4459
4460 case 40:
4461 ++this.state.pos;
4462 this.finishToken(types.parenL);
4463 return;
4464
4465 case 41:
4466 ++this.state.pos;
4467 this.finishToken(types.parenR);
4468 return;
4469
4470 case 59:
4471 ++this.state.pos;
4472 this.finishToken(types.semi);
4473 return;
4474
4475 case 44:
4476 ++this.state.pos;
4477 this.finishToken(types.comma);
4478 return;
4479
4480 case 91:
4481 ++this.state.pos;
4482 this.finishToken(types.bracketL);
4483 return;
4484
4485 case 93:
4486 ++this.state.pos;
4487 this.finishToken(types.bracketR);
4488 return;
4489
4490 case 123:
4491 if (this.hasPlugin("flow") && this.input.charCodeAt(this.state.pos + 1) === 124) {
4492 this.finishOp(types.braceBarL, 2);
4493 } else {
4494 ++this.state.pos;
4495 this.finishToken(types.braceL);
4496 }
4497
4498 return;
4499
4500 case 125:
4501 ++this.state.pos;
4502 this.finishToken(types.braceR);
4503 return;
4504
4505 case 58:
4506 if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
4507 this.finishOp(types.doubleColon, 2);
4508 } else {
4509 ++this.state.pos;
4510 this.finishToken(types.colon);
4511 }
4512
4513 return;
4514
4515 case 63:
4516 this.readToken_question();
4517 return;
4518
4519 case 64:
4520 ++this.state.pos;
4521 this.finishToken(types.at);
4522 return;
4523
4524 case 96:
4525 ++this.state.pos;
4526 this.finishToken(types.backQuote);
4527 return;
4528
4529 case 48:
4530 {
4531 var next = this.input.charCodeAt(this.state.pos + 1);
4532
4533 if (next === 120 || next === 88) {
4534 this.readRadixNumber(16);
4535 return;
4536 }
4537
4538 if (next === 111 || next === 79) {
4539 this.readRadixNumber(8);
4540 return;
4541 }
4542
4543 if (next === 98 || next === 66) {
4544 this.readRadixNumber(2);
4545 return;
4546 }
4547 }
4548
4549 case 49:
4550 case 50:
4551 case 51:
4552 case 52:
4553 case 53:
4554 case 54:
4555 case 55:
4556 case 56:
4557 case 57:
4558 this.readNumber(false);
4559 return;
4560
4561 case 34:
4562 case 39:
4563 this.readString(code);
4564 return;
4565
4566 case 47:
4567 this.readToken_slash();
4568 return;
4569
4570 case 37:
4571 case 42:
4572 this.readToken_mult_modulo(code);
4573 return;
4574
4575 case 124:
4576 case 38:
4577 this.readToken_pipe_amp(code);
4578 return;
4579
4580 case 94:
4581 this.readToken_caret();
4582 return;
4583
4584 case 43:
4585 case 45:
4586 this.readToken_plus_min(code);
4587 return;
4588
4589 case 60:
4590 case 62:
4591 this.readToken_lt_gt(code);
4592 return;
4593
4594 case 61:
4595 case 33:
4596 this.readToken_eq_excl(code);
4597 return;
4598
4599 case 126:
4600 this.finishOp(types.tilde, 1);
4601 return;
4602 }
4603
4604 this.raise(this.state.pos, "Unexpected character '" + codePointToString(code) + "'");
4605 };
4606
4607 _proto.finishOp = function finishOp(type, size) {
4608 var str = this.input.slice(this.state.pos, this.state.pos + size);
4609 this.state.pos += size;
4610 this.finishToken(type, str);
4611 };
4612
4613 _proto.readRegexp = function readRegexp() {
4614 var start = this.state.pos;
4615 var escaped, inClass;
4616
4617 for (;;) {
4618 if (this.state.pos >= this.input.length) {
4619 this.raise(start, "Unterminated regular expression");
4620 }
4621
4622 var ch = this.input.charAt(this.state.pos);
4623
4624 if (lineBreak.test(ch)) {
4625 this.raise(start, "Unterminated regular expression");
4626 }
4627
4628 if (escaped) {
4629 escaped = false;
4630 } else {
4631 if (ch === "[") {
4632 inClass = true;
4633 } else if (ch === "]" && inClass) {
4634 inClass = false;
4635 } else if (ch === "/" && !inClass) {
4636 break;
4637 }
4638
4639 escaped = ch === "\\";
4640 }
4641
4642 ++this.state.pos;
4643 }
4644
4645 var content = this.input.slice(start, this.state.pos);
4646 ++this.state.pos;
4647 var mods = "";
4648
4649 while (this.state.pos < this.input.length) {
4650 var char = this.input[this.state.pos];
4651 var charCode = this.fullCharCodeAtPos();
4652
4653 if (VALID_REGEX_FLAGS.indexOf(char) > -1) {
4654 if (mods.indexOf(char) > -1) {
4655 this.raise(this.state.pos + 1, "Duplicate regular expression flag");
4656 }
4657
4658 ++this.state.pos;
4659 mods += char;
4660 } else if (isIdentifierChar(charCode) || charCode === 92) {
4661 this.raise(this.state.pos + 1, "Invalid regular expression flag");
4662 } else {
4663 break;
4664 }
4665 }
4666
4667 this.finishToken(types.regexp, {
4668 pattern: content,
4669 flags: mods
4670 });
4671 };
4672
4673 _proto.readInt = function readInt(radix, len) {
4674 var start = this.state.pos;
4675 var forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
4676 var allowedSiblings = radix === 16 ? allowedNumericSeparatorSiblings.hex : radix === 10 ? allowedNumericSeparatorSiblings.dec : radix === 8 ? allowedNumericSeparatorSiblings.oct : allowedNumericSeparatorSiblings.bin;
4677 var total = 0;
4678
4679 for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
4680 var code = this.input.charCodeAt(this.state.pos);
4681 var val = void 0;
4682
4683 if (this.hasPlugin("numericSeparator")) {
4684 var prev = this.input.charCodeAt(this.state.pos - 1);
4685 var next = this.input.charCodeAt(this.state.pos + 1);
4686
4687 if (code === 95) {
4688 if (allowedSiblings.indexOf(next) === -1) {
4689 this.raise(this.state.pos, "Invalid or unexpected token");
4690 }
4691
4692 if (forbiddenSiblings.indexOf(prev) > -1 || forbiddenSiblings.indexOf(next) > -1 || Number.isNaN(next)) {
4693 this.raise(this.state.pos, "Invalid or unexpected token");
4694 }
4695
4696 ++this.state.pos;
4697 continue;
4698 }
4699 }
4700
4701 if (code >= 97) {
4702 val = code - 97 + 10;
4703 } else if (code >= 65) {
4704 val = code - 65 + 10;
4705 } else if (_isDigit(code)) {
4706 val = code - 48;
4707 } else {
4708 val = Infinity;
4709 }
4710
4711 if (val >= radix) break;
4712 ++this.state.pos;
4713 total = total * radix + val;
4714 }
4715
4716 if (this.state.pos === start || len != null && this.state.pos - start !== len) {
4717 return null;
4718 }
4719
4720 return total;
4721 };
4722
4723 _proto.readRadixNumber = function readRadixNumber(radix) {
4724 var start = this.state.pos;
4725 var isBigInt = false;
4726 this.state.pos += 2;
4727 var val = this.readInt(radix);
4728
4729 if (val == null) {
4730 this.raise(this.state.start + 2, "Expected number in radix " + radix);
4731 }
4732
4733 if (this.hasPlugin("bigInt")) {
4734 if (this.input.charCodeAt(this.state.pos) === 110) {
4735 ++this.state.pos;
4736 isBigInt = true;
4737 }
4738 }
4739
4740 if (isIdentifierStart(this.fullCharCodeAtPos())) {
4741 this.raise(this.state.pos, "Identifier directly after number");
4742 }
4743
4744 if (isBigInt) {
4745 var str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
4746 this.finishToken(types.bigint, str);
4747 return;
4748 }
4749
4750 this.finishToken(types.num, val);
4751 };
4752
4753 _proto.readNumber = function readNumber(startsWithDot) {
4754 var start = this.state.pos;
4755 var octal = this.input.charCodeAt(start) === 48;
4756 var isFloat = false;
4757 var isBigInt = false;
4758
4759 if (!startsWithDot && this.readInt(10) === null) {
4760 this.raise(start, "Invalid number");
4761 }
4762
4763 if (octal && this.state.pos == start + 1) octal = false;
4764 var next = this.input.charCodeAt(this.state.pos);
4765
4766 if (next === 46 && !octal) {
4767 ++this.state.pos;
4768 this.readInt(10);
4769 isFloat = true;
4770 next = this.input.charCodeAt(this.state.pos);
4771 }
4772
4773 if ((next === 69 || next === 101) && !octal) {
4774 next = this.input.charCodeAt(++this.state.pos);
4775
4776 if (next === 43 || next === 45) {
4777 ++this.state.pos;
4778 }
4779
4780 if (this.readInt(10) === null) this.raise(start, "Invalid number");
4781 isFloat = true;
4782 next = this.input.charCodeAt(this.state.pos);
4783 }
4784
4785 if (this.hasPlugin("bigInt")) {
4786 if (next === 110) {
4787 if (isFloat || octal) this.raise(start, "Invalid BigIntLiteral");
4788 ++this.state.pos;
4789 isBigInt = true;
4790 }
4791 }
4792
4793 if (isIdentifierStart(this.fullCharCodeAtPos())) {
4794 this.raise(this.state.pos, "Identifier directly after number");
4795 }
4796
4797 var str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
4798
4799 if (isBigInt) {
4800 this.finishToken(types.bigint, str);
4801 return;
4802 }
4803
4804 var val;
4805
4806 if (isFloat) {
4807 val = parseFloat(str);
4808 } else if (!octal || str.length === 1) {
4809 val = parseInt(str, 10);
4810 } else if (this.state.strict) {
4811 this.raise(start, "Invalid number");
4812 } else if (/[89]/.test(str)) {
4813 val = parseInt(str, 10);
4814 } else {
4815 val = parseInt(str, 8);
4816 }
4817
4818 this.finishToken(types.num, val);
4819 };
4820
4821 _proto.readCodePoint = function readCodePoint(throwOnInvalid) {
4822 var ch = this.input.charCodeAt(this.state.pos);
4823 var code;
4824
4825 if (ch === 123) {
4826 var codePos = ++this.state.pos;
4827 code = this.readHexChar(this.input.indexOf("}", this.state.pos) - this.state.pos, throwOnInvalid);
4828 ++this.state.pos;
4829
4830 if (code === null) {
4831 --this.state.invalidTemplateEscapePosition;
4832 } else if (code > 0x10ffff) {
4833 if (throwOnInvalid) {
4834 this.raise(codePos, "Code point out of bounds");
4835 } else {
4836 this.state.invalidTemplateEscapePosition = codePos - 2;
4837 return null;
4838 }
4839 }
4840 } else {
4841 code = this.readHexChar(4, throwOnInvalid);
4842 }
4843
4844 return code;
4845 };
4846
4847 _proto.readString = function readString(quote) {
4848 var out = "",
4849 chunkStart = ++this.state.pos;
4850 var hasJsonStrings = this.hasPlugin("jsonStrings");
4851
4852 for (;;) {
4853 if (this.state.pos >= this.input.length) {
4854 this.raise(this.state.start, "Unterminated string constant");
4855 }
4856
4857 var ch = this.input.charCodeAt(this.state.pos);
4858 if (ch === quote) break;
4859
4860 if (ch === 92) {
4861 out += this.input.slice(chunkStart, this.state.pos);
4862 out += this.readEscapedChar(false);
4863 chunkStart = this.state.pos;
4864 } else if (hasJsonStrings && (ch === 8232 || ch === 8233)) {
4865 ++this.state.pos;
4866 } else if (isNewLine(ch)) {
4867 this.raise(this.state.start, "Unterminated string constant");
4868 } else {
4869 ++this.state.pos;
4870 }
4871 }
4872
4873 out += this.input.slice(chunkStart, this.state.pos++);
4874 this.finishToken(types.string, out);
4875 };
4876
4877 _proto.readTmplToken = function readTmplToken() {
4878 var out = "",
4879 chunkStart = this.state.pos,
4880 containsInvalid = false;
4881
4882 for (;;) {
4883 if (this.state.pos >= this.input.length) {
4884 this.raise(this.state.start, "Unterminated template");
4885 }
4886
4887 var ch = this.input.charCodeAt(this.state.pos);
4888
4889 if (ch === 96 || ch === 36 && this.input.charCodeAt(this.state.pos + 1) === 123) {
4890 if (this.state.pos === this.state.start && this.match(types.template)) {
4891 if (ch === 36) {
4892 this.state.pos += 2;
4893 this.finishToken(types.dollarBraceL);
4894 return;
4895 } else {
4896 ++this.state.pos;
4897 this.finishToken(types.backQuote);
4898 return;
4899 }
4900 }
4901
4902 out += this.input.slice(chunkStart, this.state.pos);
4903 this.finishToken(types.template, containsInvalid ? null : out);
4904 return;
4905 }
4906
4907 if (ch === 92) {
4908 out += this.input.slice(chunkStart, this.state.pos);
4909 var escaped = this.readEscapedChar(true);
4910
4911 if (escaped === null) {
4912 containsInvalid = true;
4913 } else {
4914 out += escaped;
4915 }
4916
4917 chunkStart = this.state.pos;
4918 } else if (isNewLine(ch)) {
4919 out += this.input.slice(chunkStart, this.state.pos);
4920 ++this.state.pos;
4921
4922 switch (ch) {
4923 case 13:
4924 if (this.input.charCodeAt(this.state.pos) === 10) {
4925 ++this.state.pos;
4926 }
4927
4928 case 10:
4929 out += "\n";
4930 break;
4931
4932 default:
4933 out += String.fromCharCode(ch);
4934 break;
4935 }
4936
4937 ++this.state.curLine;
4938 this.state.lineStart = this.state.pos;
4939 chunkStart = this.state.pos;
4940 } else {
4941 ++this.state.pos;
4942 }
4943 }
4944 };
4945
4946 _proto.readEscapedChar = function readEscapedChar(inTemplate) {
4947 var throwOnInvalid = !inTemplate;
4948 var ch = this.input.charCodeAt(++this.state.pos);
4949 ++this.state.pos;
4950
4951 switch (ch) {
4952 case 110:
4953 return "\n";
4954
4955 case 114:
4956 return "\r";
4957
4958 case 120:
4959 {
4960 var code = this.readHexChar(2, throwOnInvalid);
4961 return code === null ? null : String.fromCharCode(code);
4962 }
4963
4964 case 117:
4965 {
4966 var _code = this.readCodePoint(throwOnInvalid);
4967
4968 return _code === null ? null : codePointToString(_code);
4969 }
4970
4971 case 116:
4972 return "\t";
4973
4974 case 98:
4975 return "\b";
4976
4977 case 118:
4978 return "\x0B";
4979
4980 case 102:
4981 return "\f";
4982
4983 case 13:
4984 if (this.input.charCodeAt(this.state.pos) === 10) {
4985 ++this.state.pos;
4986 }
4987
4988 case 10:
4989 this.state.lineStart = this.state.pos;
4990 ++this.state.curLine;
4991 return "";
4992
4993 default:
4994 if (ch >= 48 && ch <= 55) {
4995 var codePos = this.state.pos - 1;
4996 var octalStr = this.input.substr(this.state.pos - 1, 3).match(/^[0-7]+/)[0];
4997 var octal = parseInt(octalStr, 8);
4998
4999 if (octal > 255) {
5000 octalStr = octalStr.slice(0, -1);
5001 octal = parseInt(octalStr, 8);
5002 }
5003
5004 if (octal > 0) {
5005 if (inTemplate) {
5006 this.state.invalidTemplateEscapePosition = codePos;
5007 return null;
5008 } else if (this.state.strict) {
5009 this.raise(codePos, "Octal literal in strict mode");
5010 } else if (!this.state.containsOctal) {
5011 this.state.containsOctal = true;
5012 this.state.octalPosition = codePos;
5013 }
5014 }
5015
5016 this.state.pos += octalStr.length - 1;
5017 return String.fromCharCode(octal);
5018 }
5019
5020 return String.fromCharCode(ch);
5021 }
5022 };
5023
5024 _proto.readHexChar = function readHexChar(len, throwOnInvalid) {
5025 var codePos = this.state.pos;
5026 var n = this.readInt(16, len);
5027
5028 if (n === null) {
5029 if (throwOnInvalid) {
5030 this.raise(codePos, "Bad character escape sequence");
5031 } else {
5032 this.state.pos = codePos - 1;
5033 this.state.invalidTemplateEscapePosition = codePos - 1;
5034 }
5035 }
5036
5037 return n;
5038 };
5039
5040 _proto.readWord1 = function readWord1() {
5041 this.state.containsEsc = false;
5042 var word = "",
5043 first = true,
5044 chunkStart = this.state.pos;
5045
5046 while (this.state.pos < this.input.length) {
5047 var ch = this.fullCharCodeAtPos();
5048
5049 if (isIdentifierChar(ch)) {
5050 this.state.pos += ch <= 0xffff ? 1 : 2;
5051 } else if (this.state.isIterator && ch === 64) {
5052 this.state.pos += 1;
5053 } else if (ch === 92) {
5054 this.state.containsEsc = true;
5055 word += this.input.slice(chunkStart, this.state.pos);
5056 var escStart = this.state.pos;
5057
5058 if (this.input.charCodeAt(++this.state.pos) !== 117) {
5059 this.raise(this.state.pos, "Expecting Unicode escape sequence \\uXXXX");
5060 }
5061
5062 ++this.state.pos;
5063 var esc = this.readCodePoint(true);
5064
5065 if (!(first ? isIdentifierStart : isIdentifierChar)(esc, true)) {
5066 this.raise(escStart, "Invalid Unicode escape");
5067 }
5068
5069 word += codePointToString(esc);
5070 chunkStart = this.state.pos;
5071 } else {
5072 break;
5073 }
5074
5075 first = false;
5076 }
5077
5078 return word + this.input.slice(chunkStart, this.state.pos);
5079 };
5080
5081 _proto.isIterator = function isIterator(word) {
5082 return word === "@@iterator" || word === "@@asyncIterator";
5083 };
5084
5085 _proto.readWord = function readWord() {
5086 var word = this.readWord1();
5087 var type = types.name;
5088
5089 if (this.isKeyword(word)) {
5090 if (this.state.containsEsc) {
5091 this.raise(this.state.pos, "Escape sequence in keyword " + word);
5092 }
5093
5094 type = keywords[word];
5095 }
5096
5097 if (this.state.isIterator && (!this.isIterator(word) || !this.state.inType)) {
5098 this.raise(this.state.pos, "Invalid identifier " + word);
5099 }
5100
5101 this.finishToken(type, word);
5102 };
5103
5104 _proto.braceIsBlock = function braceIsBlock(prevType) {
5105 if (prevType === types.colon) {
5106 var parent = this.curContext();
5107
5108 if (parent === types$1.braceStatement || parent === types$1.braceExpression) {
5109 return !parent.isExpr;
5110 }
5111 }
5112
5113 if (prevType === types._return) {
5114 return lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start));
5115 }
5116
5117 if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR) {
5118 return true;
5119 }
5120
5121 if (prevType === types.braceL) {
5122 return this.curContext() === types$1.braceStatement;
5123 }
5124
5125 if (prevType === types.relational) {
5126 return true;
5127 }
5128
5129 return !this.state.exprAllowed;
5130 };
5131
5132 _proto.updateContext = function updateContext(prevType) {
5133 var type = this.state.type;
5134 var update;
5135
5136 if (type.keyword && (prevType === types.dot || prevType === types.questionDot)) {
5137 this.state.exprAllowed = false;
5138 } else if (update = type.updateContext) {
5139 update.call(this, prevType);
5140 } else {
5141 this.state.exprAllowed = type.beforeExpr;
5142 }
5143 };
5144
5145 return Tokenizer;
5146}(LocationParser);
5147
5148var UtilParser = function (_Tokenizer) {
5149 _inheritsLoose(UtilParser, _Tokenizer);
5150
5151 function UtilParser() {
5152 return _Tokenizer.apply(this, arguments) || this;
5153 }
5154
5155 var _proto = UtilParser.prototype;
5156
5157 _proto.addExtra = function addExtra(node, key, val) {
5158 if (!node) return;
5159 var extra = node.extra = node.extra || {};
5160 extra[key] = val;
5161 };
5162
5163 _proto.isRelational = function isRelational(op) {
5164 return this.match(types.relational) && this.state.value === op;
5165 };
5166
5167 _proto.isLookaheadRelational = function isLookaheadRelational(op) {
5168 var l = this.lookahead();
5169 return l.type == types.relational && l.value == op;
5170 };
5171
5172 _proto.expectRelational = function expectRelational(op) {
5173 if (this.isRelational(op)) {
5174 this.next();
5175 } else {
5176 this.unexpected(null, types.relational);
5177 }
5178 };
5179
5180 _proto.eatRelational = function eatRelational(op) {
5181 if (this.isRelational(op)) {
5182 this.next();
5183 return true;
5184 }
5185
5186 return false;
5187 };
5188
5189 _proto.isContextual = function isContextual(name) {
5190 return this.match(types.name) && this.state.value === name && !this.state.containsEsc;
5191 };
5192
5193 _proto.isLookaheadContextual = function isLookaheadContextual(name) {
5194 var l = this.lookahead();
5195 return l.type === types.name && l.value === name;
5196 };
5197
5198 _proto.eatContextual = function eatContextual(name) {
5199 return this.isContextual(name) && this.eat(types.name);
5200 };
5201
5202 _proto.expectContextual = function expectContextual(name, message) {
5203 if (!this.eatContextual(name)) this.unexpected(null, message);
5204 };
5205
5206 _proto.canInsertSemicolon = function canInsertSemicolon() {
5207 return this.match(types.eof) || this.match(types.braceR) || this.hasPrecedingLineBreak();
5208 };
5209
5210 _proto.hasPrecedingLineBreak = function hasPrecedingLineBreak() {
5211 return lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start));
5212 };
5213
5214 _proto.isLineTerminator = function isLineTerminator() {
5215 return this.eat(types.semi) || this.canInsertSemicolon();
5216 };
5217
5218 _proto.semicolon = function semicolon() {
5219 if (!this.isLineTerminator()) this.unexpected(null, types.semi);
5220 };
5221
5222 _proto.expect = function expect(type, pos) {
5223 this.eat(type) || this.unexpected(pos, type);
5224 };
5225
5226 _proto.unexpected = function unexpected(pos, messageOrType) {
5227 if (messageOrType === void 0) {
5228 messageOrType = "Unexpected token";
5229 }
5230
5231 if (typeof messageOrType !== "string") {
5232 messageOrType = "Unexpected token, expected \"" + messageOrType.label + "\"";
5233 }
5234
5235 throw this.raise(pos != null ? pos : this.state.start, messageOrType);
5236 };
5237
5238 _proto.expectPlugin = function expectPlugin(name, pos) {
5239 if (!this.hasPlugin(name)) {
5240 throw this.raise(pos != null ? pos : this.state.start, "This experimental syntax requires enabling the parser plugin: '" + name + "'", {
5241 missingPluginNames: [name]
5242 });
5243 }
5244
5245 return true;
5246 };
5247
5248 _proto.expectOnePlugin = function expectOnePlugin(names, pos) {
5249 var _this = this;
5250
5251 if (!names.some(function (n) {
5252 return _this.hasPlugin(n);
5253 })) {
5254 throw this.raise(pos != null ? pos : this.state.start, "This experimental syntax requires enabling one of the following parser plugin(s): '" + names.join(", ") + "'", {
5255 missingPluginNames: names
5256 });
5257 }
5258 };
5259
5260 return UtilParser;
5261}(Tokenizer);
5262
5263var commentKeys = ["leadingComments", "trailingComments", "innerComments"];
5264
5265var Node = function () {
5266 function Node(parser, pos, loc) {
5267 this.type = "";
5268 this.start = pos;
5269 this.end = 0;
5270 this.loc = new SourceLocation(loc);
5271 if (parser && parser.options.ranges) this.range = [pos, 0];
5272 if (parser && parser.filename) this.loc.filename = parser.filename;
5273 }
5274
5275 var _proto = Node.prototype;
5276
5277 _proto.__clone = function __clone() {
5278 var _this = this;
5279
5280 var node2 = new Node();
5281 Object.keys(this).forEach(function (key) {
5282 if (commentKeys.indexOf(key) < 0) {
5283 node2[key] = _this[key];
5284 }
5285 });
5286 return node2;
5287 };
5288
5289 return Node;
5290}();
5291
5292var NodeUtils = function (_UtilParser) {
5293 _inheritsLoose(NodeUtils, _UtilParser);
5294
5295 function NodeUtils() {
5296 return _UtilParser.apply(this, arguments) || this;
5297 }
5298
5299 var _proto2 = NodeUtils.prototype;
5300
5301 _proto2.startNode = function startNode() {
5302 return new Node(this, this.state.start, this.state.startLoc);
5303 };
5304
5305 _proto2.startNodeAt = function startNodeAt(pos, loc) {
5306 return new Node(this, pos, loc);
5307 };
5308
5309 _proto2.startNodeAtNode = function startNodeAtNode(type) {
5310 return this.startNodeAt(type.start, type.loc.start);
5311 };
5312
5313 _proto2.finishNode = function finishNode(node, type) {
5314 return this.finishNodeAt(node, type, this.state.lastTokEnd, this.state.lastTokEndLoc);
5315 };
5316
5317 _proto2.finishNodeAt = function finishNodeAt(node, type, pos, loc) {
5318 node.type = type;
5319 node.end = pos;
5320 node.loc.end = loc;
5321 if (this.options.ranges) node.range[1] = pos;
5322 this.processComment(node);
5323 return node;
5324 };
5325
5326 _proto2.resetStartLocationFromNode = function resetStartLocationFromNode(node, locationNode) {
5327 node.start = locationNode.start;
5328 node.loc.start = locationNode.loc.start;
5329 if (this.options.ranges) node.range[0] = locationNode.range[0];
5330 };
5331
5332 return NodeUtils;
5333}(UtilParser);
5334
5335var LValParser = function (_NodeUtils) {
5336 _inheritsLoose(LValParser, _NodeUtils);
5337
5338 function LValParser() {
5339 return _NodeUtils.apply(this, arguments) || this;
5340 }
5341
5342 var _proto = LValParser.prototype;
5343
5344 _proto.toAssignable = function toAssignable(node, isBinding, contextDescription) {
5345 if (node) {
5346 switch (node.type) {
5347 case "Identifier":
5348 case "ObjectPattern":
5349 case "ArrayPattern":
5350 case "AssignmentPattern":
5351 break;
5352
5353 case "ObjectExpression":
5354 node.type = "ObjectPattern";
5355
5356 for (var index = 0; index < node.properties.length; index++) {
5357 var prop = node.properties[index];
5358 var isLast = index === node.properties.length - 1;
5359 this.toAssignableObjectExpressionProp(prop, isBinding, isLast);
5360 }
5361
5362 break;
5363
5364 case "ObjectProperty":
5365 this.toAssignable(node.value, isBinding, contextDescription);
5366 break;
5367
5368 case "SpreadElement":
5369 {
5370 this.checkToRestConversion(node);
5371 node.type = "RestElement";
5372 var arg = node.argument;
5373 this.toAssignable(arg, isBinding, contextDescription);
5374 break;
5375 }
5376
5377 case "ArrayExpression":
5378 node.type = "ArrayPattern";
5379 this.toAssignableList(node.elements, isBinding, contextDescription);
5380 break;
5381
5382 case "AssignmentExpression":
5383 if (node.operator === "=") {
5384 node.type = "AssignmentPattern";
5385 delete node.operator;
5386 } else {
5387 this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
5388 }
5389
5390 break;
5391
5392 case "MemberExpression":
5393 if (!isBinding) break;
5394
5395 default:
5396 {
5397 var message = "Invalid left-hand side" + (contextDescription ? " in " + contextDescription : "expression");
5398 this.raise(node.start, message);
5399 }
5400 }
5401 }
5402
5403 return node;
5404 };
5405
5406 _proto.toAssignableObjectExpressionProp = function toAssignableObjectExpressionProp(prop, isBinding, isLast) {
5407 if (prop.type === "ObjectMethod") {
5408 var error = prop.kind === "get" || prop.kind === "set" ? "Object pattern can't contain getter or setter" : "Object pattern can't contain methods";
5409 this.raise(prop.key.start, error);
5410 } else if (prop.type === "SpreadElement" && !isLast) {
5411 this.raise(prop.start, "The rest element has to be the last element when destructuring");
5412 } else {
5413 this.toAssignable(prop, isBinding, "object destructuring pattern");
5414 }
5415 };
5416
5417 _proto.toAssignableList = function toAssignableList(exprList, isBinding, contextDescription) {
5418 var end = exprList.length;
5419
5420 if (end) {
5421 var last = exprList[end - 1];
5422
5423 if (last && last.type === "RestElement") {
5424 --end;
5425 } else if (last && last.type === "SpreadElement") {
5426 last.type = "RestElement";
5427 var arg = last.argument;
5428 this.toAssignable(arg, isBinding, contextDescription);
5429
5430 if (["Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern"].indexOf(arg.type) === -1) {
5431 this.unexpected(arg.start);
5432 }
5433
5434 --end;
5435 }
5436 }
5437
5438 for (var i = 0; i < end; i++) {
5439 var elt = exprList[i];
5440
5441 if (elt && elt.type === "SpreadElement") {
5442 this.raise(elt.start, "The rest element has to be the last element when destructuring");
5443 }
5444
5445 if (elt) this.toAssignable(elt, isBinding, contextDescription);
5446 }
5447
5448 return exprList;
5449 };
5450
5451 _proto.toReferencedList = function toReferencedList(exprList) {
5452 return exprList;
5453 };
5454
5455 _proto.parseSpread = function parseSpread(refShorthandDefaultPos, refNeedsArrowPos) {
5456 var node = this.startNode();
5457 this.next();
5458 node.argument = this.parseMaybeAssign(false, refShorthandDefaultPos, undefined, refNeedsArrowPos);
5459 return this.finishNode(node, "SpreadElement");
5460 };
5461
5462 _proto.parseRest = function parseRest() {
5463 var node = this.startNode();
5464 this.next();
5465 node.argument = this.parseBindingAtom();
5466 return this.finishNode(node, "RestElement");
5467 };
5468
5469 _proto.shouldAllowYieldIdentifier = function shouldAllowYieldIdentifier() {
5470 return this.match(types._yield) && !this.state.strict && !this.state.inGenerator;
5471 };
5472
5473 _proto.parseBindingIdentifier = function parseBindingIdentifier() {
5474 return this.parseIdentifier(this.shouldAllowYieldIdentifier());
5475 };
5476
5477 _proto.parseBindingAtom = function parseBindingAtom() {
5478 switch (this.state.type) {
5479 case types._yield:
5480 case types.name:
5481 return this.parseBindingIdentifier();
5482
5483 case types.bracketL:
5484 {
5485 var node = this.startNode();
5486 this.next();
5487 node.elements = this.parseBindingList(types.bracketR, true);
5488 return this.finishNode(node, "ArrayPattern");
5489 }
5490
5491 case types.braceL:
5492 return this.parseObj(true);
5493
5494 default:
5495 throw this.unexpected();
5496 }
5497 };
5498
5499 _proto.parseBindingList = function parseBindingList(close, allowEmpty, allowModifiers) {
5500 var elts = [];
5501 var first = true;
5502
5503 while (!this.eat(close)) {
5504 if (first) {
5505 first = false;
5506 } else {
5507 this.expect(types.comma);
5508 }
5509
5510 if (allowEmpty && this.match(types.comma)) {
5511 elts.push(null);
5512 } else if (this.eat(close)) {
5513 break;
5514 } else if (this.match(types.ellipsis)) {
5515 elts.push(this.parseAssignableListItemTypes(this.parseRest()));
5516 this.expect(close);
5517 break;
5518 } else {
5519 var decorators = [];
5520
5521 if (this.match(types.at) && this.hasPlugin("decorators")) {
5522 this.raise(this.state.start, "Stage 2 decorators cannot be used to decorate parameters");
5523 }
5524
5525 while (this.match(types.at)) {
5526 decorators.push(this.parseDecorator());
5527 }
5528
5529 elts.push(this.parseAssignableListItem(allowModifiers, decorators));
5530 }
5531 }
5532
5533 return elts;
5534 };
5535
5536 _proto.parseAssignableListItem = function parseAssignableListItem(allowModifiers, decorators) {
5537 var left = this.parseMaybeDefault();
5538 this.parseAssignableListItemTypes(left);
5539 var elt = this.parseMaybeDefault(left.start, left.loc.start, left);
5540
5541 if (decorators.length) {
5542 left.decorators = decorators;
5543 }
5544
5545 return elt;
5546 };
5547
5548 _proto.parseAssignableListItemTypes = function parseAssignableListItemTypes(param) {
5549 return param;
5550 };
5551
5552 _proto.parseMaybeDefault = function parseMaybeDefault(startPos, startLoc, left) {
5553 startLoc = startLoc || this.state.startLoc;
5554 startPos = startPos || this.state.start;
5555 left = left || this.parseBindingAtom();
5556 if (!this.eat(types.eq)) return left;
5557 var node = this.startNodeAt(startPos, startLoc);
5558 node.left = left;
5559 node.right = this.parseMaybeAssign();
5560 return this.finishNode(node, "AssignmentPattern");
5561 };
5562
5563 _proto.checkLVal = function checkLVal(expr, isBinding, checkClashes, contextDescription) {
5564 switch (expr.type) {
5565 case "Identifier":
5566 this.checkReservedWord(expr.name, expr.start, false, true);
5567
5568 if (checkClashes) {
5569 var _key = "_" + expr.name;
5570
5571 if (checkClashes[_key]) {
5572 this.raise(expr.start, "Argument name clash in strict mode");
5573 } else {
5574 checkClashes[_key] = true;
5575 }
5576 }
5577
5578 break;
5579
5580 case "MemberExpression":
5581 if (isBinding) this.raise(expr.start, "Binding member expression");
5582 break;
5583
5584 case "ObjectPattern":
5585 for (var _i2 = 0, _expr$properties2 = expr.properties; _i2 < _expr$properties2.length; _i2++) {
5586 var prop = _expr$properties2[_i2];
5587 if (prop.type === "ObjectProperty") prop = prop.value;
5588 this.checkLVal(prop, isBinding, checkClashes, "object destructuring pattern");
5589 }
5590
5591 break;
5592
5593 case "ArrayPattern":
5594 for (var _i4 = 0, _expr$elements2 = expr.elements; _i4 < _expr$elements2.length; _i4++) {
5595 var elem = _expr$elements2[_i4];
5596
5597 if (elem) {
5598 this.checkLVal(elem, isBinding, checkClashes, "array destructuring pattern");
5599 }
5600 }
5601
5602 break;
5603
5604 case "AssignmentPattern":
5605 this.checkLVal(expr.left, isBinding, checkClashes, "assignment pattern");
5606 break;
5607
5608 case "RestElement":
5609 this.checkLVal(expr.argument, isBinding, checkClashes, "rest element");
5610 break;
5611
5612 default:
5613 {
5614 var message = (isBinding ? "Binding invalid" : "Invalid") + " left-hand side" + (contextDescription ? " in " + contextDescription : "expression");
5615 this.raise(expr.start, message);
5616 }
5617 }
5618 };
5619
5620 _proto.checkToRestConversion = function checkToRestConversion(node) {
5621 var validArgumentTypes = ["Identifier", "MemberExpression"];
5622
5623 if (validArgumentTypes.indexOf(node.argument.type) !== -1) {
5624 return;
5625 }
5626
5627 this.raise(node.argument.start, "Invalid rest operator's argument");
5628 };
5629
5630 return LValParser;
5631}(NodeUtils);
5632
5633var ExpressionParser = function (_LValParser) {
5634 _inheritsLoose(ExpressionParser, _LValParser);
5635
5636 function ExpressionParser() {
5637 return _LValParser.apply(this, arguments) || this;
5638 }
5639
5640 var _proto = ExpressionParser.prototype;
5641
5642 _proto.checkPropClash = function checkPropClash(prop, propHash) {
5643 if (prop.computed || prop.kind) return;
5644 var key = prop.key;
5645 var name = key.type === "Identifier" ? key.name : String(key.value);
5646
5647 if (name === "__proto__") {
5648 if (propHash.proto) {
5649 this.raise(key.start, "Redefinition of __proto__ property");
5650 }
5651
5652 propHash.proto = true;
5653 }
5654 };
5655
5656 _proto.getExpression = function getExpression() {
5657 this.nextToken();
5658 var expr = this.parseExpression();
5659
5660 if (!this.match(types.eof)) {
5661 this.unexpected();
5662 }
5663
5664 expr.comments = this.state.comments;
5665 return expr;
5666 };
5667
5668 _proto.parseExpression = function parseExpression(noIn, refShorthandDefaultPos) {
5669 var startPos = this.state.start;
5670 var startLoc = this.state.startLoc;
5671 var expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos);
5672
5673 if (this.match(types.comma)) {
5674 var _node = this.startNodeAt(startPos, startLoc);
5675
5676 _node.expressions = [expr];
5677
5678 while (this.eat(types.comma)) {
5679 _node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos));
5680 }
5681
5682 this.toReferencedList(_node.expressions);
5683 return this.finishNode(_node, "SequenceExpression");
5684 }
5685
5686 return expr;
5687 };
5688
5689 _proto.parseMaybeAssign = function parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos) {
5690 var startPos = this.state.start;
5691 var startLoc = this.state.startLoc;
5692
5693 if (this.match(types._yield) && this.state.inGenerator) {
5694 var _left = this.parseYield();
5695
5696 if (afterLeftParse) {
5697 _left = afterLeftParse.call(this, _left, startPos, startLoc);
5698 }
5699
5700 return _left;
5701 }
5702
5703 var failOnShorthandAssign;
5704
5705 if (refShorthandDefaultPos) {
5706 failOnShorthandAssign = false;
5707 } else {
5708 refShorthandDefaultPos = {
5709 start: 0
5710 };
5711 failOnShorthandAssign = true;
5712 }
5713
5714 if (this.match(types.parenL) || this.match(types.name) || this.match(types._yield)) {
5715 this.state.potentialArrowAt = this.state.start;
5716 }
5717
5718 var left = this.parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos);
5719
5720 if (afterLeftParse) {
5721 left = afterLeftParse.call(this, left, startPos, startLoc);
5722 }
5723
5724 if (this.state.type.isAssign) {
5725 var _node2 = this.startNodeAt(startPos, startLoc);
5726
5727 var operator = this.state.value;
5728 _node2.operator = operator;
5729
5730 if (operator === "??=") {
5731 this.expectPlugin("nullishCoalescingOperator");
5732 this.expectPlugin("logicalAssignment");
5733 }
5734
5735 if (operator === "||=" || operator === "&&=") {
5736 this.expectPlugin("logicalAssignment");
5737 }
5738
5739 _node2.left = this.match(types.eq) ? this.toAssignable(left, undefined, "assignment expression") : left;
5740 refShorthandDefaultPos.start = 0;
5741 this.checkLVal(left, undefined, undefined, "assignment expression");
5742
5743 if (left.extra && left.extra.parenthesized) {
5744 var errorMsg;
5745
5746 if (left.type === "ObjectPattern") {
5747 errorMsg = "`({a}) = 0` use `({a} = 0)`";
5748 } else if (left.type === "ArrayPattern") {
5749 errorMsg = "`([a]) = 0` use `([a] = 0)`";
5750 }
5751
5752 if (errorMsg) {
5753 this.raise(left.start, "You're trying to assign to a parenthesized expression, eg. instead of " + errorMsg);
5754 }
5755 }
5756
5757 this.next();
5758 _node2.right = this.parseMaybeAssign(noIn);
5759 return this.finishNode(_node2, "AssignmentExpression");
5760 } else if (failOnShorthandAssign && refShorthandDefaultPos.start) {
5761 this.unexpected(refShorthandDefaultPos.start);
5762 }
5763
5764 return left;
5765 };
5766
5767 _proto.parseMaybeConditional = function parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos) {
5768 var startPos = this.state.start;
5769 var startLoc = this.state.startLoc;
5770 var potentialArrowAt = this.state.potentialArrowAt;
5771 var expr = this.parseExprOps(noIn, refShorthandDefaultPos);
5772
5773 if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) {
5774 return expr;
5775 }
5776
5777 if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
5778 return this.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos);
5779 };
5780
5781 _proto.parseConditional = function parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) {
5782 if (this.eat(types.question)) {
5783 var _node3 = this.startNodeAt(startPos, startLoc);
5784
5785 _node3.test = expr;
5786 _node3.consequent = this.parseMaybeAssign();
5787 this.expect(types.colon);
5788 _node3.alternate = this.parseMaybeAssign(noIn);
5789 return this.finishNode(_node3, "ConditionalExpression");
5790 }
5791
5792 return expr;
5793 };
5794
5795 _proto.parseExprOps = function parseExprOps(noIn, refShorthandDefaultPos) {
5796 var startPos = this.state.start;
5797 var startLoc = this.state.startLoc;
5798 var potentialArrowAt = this.state.potentialArrowAt;
5799 var expr = this.parseMaybeUnary(refShorthandDefaultPos);
5800
5801 if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) {
5802 return expr;
5803 }
5804
5805 if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
5806 return expr;
5807 }
5808
5809 return this.parseExprOp(expr, startPos, startLoc, -1, noIn);
5810 };
5811
5812 _proto.parseExprOp = function parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn) {
5813 var prec = this.state.type.binop;
5814
5815 if (prec != null && (!noIn || !this.match(types._in))) {
5816 if (prec > minPrec) {
5817 var _node4 = this.startNodeAt(leftStartPos, leftStartLoc);
5818
5819 var operator = this.state.value;
5820 _node4.left = left;
5821 _node4.operator = operator;
5822
5823 if (operator === "**" && left.type === "UnaryExpression" && !(left.extra && left.extra.parenthesized)) {
5824 this.raise(left.argument.start, "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.");
5825 }
5826
5827 var op = this.state.type;
5828
5829 if (op === types.nullishCoalescing) {
5830 this.expectPlugin("nullishCoalescingOperator");
5831 } else if (op === types.pipeline) {
5832 this.expectPlugin("pipelineOperator");
5833 }
5834
5835 this.next();
5836 var startPos = this.state.start;
5837 var startLoc = this.state.startLoc;
5838
5839 if (op === types.pipeline) {
5840 if (this.match(types.name) && this.state.value === "await" && this.state.inAsync) {
5841 throw this.raise(this.state.start, "Unexpected \"await\" after pipeline body; await must have parentheses in minimal proposal");
5842 }
5843 }
5844
5845 _node4.right = this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, op.rightAssociative ? prec - 1 : prec, noIn);
5846 this.finishNode(_node4, op === types.logicalOR || op === types.logicalAND || op === types.nullishCoalescing ? "LogicalExpression" : "BinaryExpression");
5847 return this.parseExprOp(_node4, leftStartPos, leftStartLoc, minPrec, noIn);
5848 }
5849 }
5850
5851 return left;
5852 };
5853
5854 _proto.parseMaybeUnary = function parseMaybeUnary(refShorthandDefaultPos) {
5855 if (this.state.type.prefix) {
5856 var _node5 = this.startNode();
5857
5858 var update = this.match(types.incDec);
5859 _node5.operator = this.state.value;
5860 _node5.prefix = true;
5861
5862 if (_node5.operator === "throw") {
5863 this.expectPlugin("throwExpressions");
5864 }
5865
5866 this.next();
5867 _node5.argument = this.parseMaybeUnary();
5868
5869 if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
5870 this.unexpected(refShorthandDefaultPos.start);
5871 }
5872
5873 if (update) {
5874 this.checkLVal(_node5.argument, undefined, undefined, "prefix operation");
5875 } else if (this.state.strict && _node5.operator === "delete") {
5876 var arg = _node5.argument;
5877
5878 if (arg.type === "Identifier") {
5879 this.raise(_node5.start, "Deleting local variable in strict mode");
5880 } else if (arg.type === "MemberExpression" && arg.property.type === "PrivateName") {
5881 this.raise(_node5.start, "Deleting a private field is not allowed");
5882 }
5883 }
5884
5885 return this.finishNode(_node5, update ? "UpdateExpression" : "UnaryExpression");
5886 }
5887
5888 var startPos = this.state.start;
5889 var startLoc = this.state.startLoc;
5890 var expr = this.parseExprSubscripts(refShorthandDefaultPos);
5891 if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
5892
5893 while (this.state.type.postfix && !this.canInsertSemicolon()) {
5894 var _node6 = this.startNodeAt(startPos, startLoc);
5895
5896 _node6.operator = this.state.value;
5897 _node6.prefix = false;
5898 _node6.argument = expr;
5899 this.checkLVal(expr, undefined, undefined, "postfix operation");
5900 this.next();
5901 expr = this.finishNode(_node6, "UpdateExpression");
5902 }
5903
5904 return expr;
5905 };
5906
5907 _proto.parseExprSubscripts = function parseExprSubscripts(refShorthandDefaultPos) {
5908 var startPos = this.state.start;
5909 var startLoc = this.state.startLoc;
5910 var potentialArrowAt = this.state.potentialArrowAt;
5911 var expr = this.parseExprAtom(refShorthandDefaultPos);
5912
5913 if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) {
5914 return expr;
5915 }
5916
5917 if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
5918 return expr;
5919 }
5920
5921 return this.parseSubscripts(expr, startPos, startLoc);
5922 };
5923
5924 _proto.parseSubscripts = function parseSubscripts(base, startPos, startLoc, noCalls) {
5925 var state = {
5926 optionalChainMember: false,
5927 stop: false
5928 };
5929
5930 do {
5931 base = this.parseSubscript(base, startPos, startLoc, noCalls, state);
5932 } while (!state.stop);
5933
5934 return base;
5935 };
5936
5937 _proto.parseSubscript = function parseSubscript(base, startPos, startLoc, noCalls, state) {
5938 if (!noCalls && this.eat(types.doubleColon)) {
5939 var _node7 = this.startNodeAt(startPos, startLoc);
5940
5941 _node7.object = base;
5942 _node7.callee = this.parseNoCallExpr();
5943 state.stop = true;
5944 return this.parseSubscripts(this.finishNode(_node7, "BindExpression"), startPos, startLoc, noCalls);
5945 } else if (this.match(types.questionDot)) {
5946 this.expectPlugin("optionalChaining");
5947 state.optionalChainMember = true;
5948
5949 if (noCalls && this.lookahead().type == types.parenL) {
5950 state.stop = true;
5951 return base;
5952 }
5953
5954 this.next();
5955
5956 var _node8 = this.startNodeAt(startPos, startLoc);
5957
5958 if (this.eat(types.bracketL)) {
5959 _node8.object = base;
5960 _node8.property = this.parseExpression();
5961 _node8.computed = true;
5962 _node8.optional = true;
5963 this.expect(types.bracketR);
5964 return this.finishNode(_node8, "OptionalMemberExpression");
5965 } else if (this.eat(types.parenL)) {
5966 var possibleAsync = this.atPossibleAsync(base);
5967 _node8.callee = base;
5968 _node8.arguments = this.parseCallExpressionArguments(types.parenR, possibleAsync);
5969 _node8.optional = true;
5970 return this.finishNode(_node8, "OptionalCallExpression");
5971 } else {
5972 _node8.object = base;
5973 _node8.property = this.parseIdentifier(true);
5974 _node8.computed = false;
5975 _node8.optional = true;
5976 return this.finishNode(_node8, "OptionalMemberExpression");
5977 }
5978 } else if (this.eat(types.dot)) {
5979 var _node9 = this.startNodeAt(startPos, startLoc);
5980
5981 _node9.object = base;
5982 _node9.property = this.parseMaybePrivateName();
5983 _node9.computed = false;
5984
5985 if (state.optionalChainMember) {
5986 _node9.optional = false;
5987 return this.finishNode(_node9, "OptionalMemberExpression");
5988 }
5989
5990 return this.finishNode(_node9, "MemberExpression");
5991 } else if (this.eat(types.bracketL)) {
5992 var _node10 = this.startNodeAt(startPos, startLoc);
5993
5994 _node10.object = base;
5995 _node10.property = this.parseExpression();
5996 _node10.computed = true;
5997 this.expect(types.bracketR);
5998
5999 if (state.optionalChainMember) {
6000 _node10.optional = false;
6001 return this.finishNode(_node10, "OptionalMemberExpression");
6002 }
6003
6004 return this.finishNode(_node10, "MemberExpression");
6005 } else if (!noCalls && this.match(types.parenL)) {
6006 var _possibleAsync = this.atPossibleAsync(base);
6007
6008 this.next();
6009
6010 var _node11 = this.startNodeAt(startPos, startLoc);
6011
6012 _node11.callee = base;
6013 var refTrailingCommaPos = {
6014 start: -1
6015 };
6016 _node11.arguments = this.parseCallExpressionArguments(types.parenR, _possibleAsync, refTrailingCommaPos);
6017
6018 if (!state.optionalChainMember) {
6019 this.finishCallExpression(_node11);
6020 } else {
6021 this.finishOptionalCallExpression(_node11);
6022 }
6023
6024 if (_possibleAsync && this.shouldParseAsyncArrow()) {
6025 state.stop = true;
6026
6027 if (refTrailingCommaPos.start > -1) {
6028 this.raise(refTrailingCommaPos.start, "A trailing comma is not permitted after the rest element");
6029 }
6030
6031 return this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), _node11);
6032 } else {
6033 this.toReferencedList(_node11.arguments);
6034 }
6035
6036 return _node11;
6037 } else if (this.match(types.backQuote)) {
6038 return this.parseTaggedTemplateExpression(startPos, startLoc, base, state);
6039 } else {
6040 state.stop = true;
6041 return base;
6042 }
6043 };
6044
6045 _proto.parseTaggedTemplateExpression = function parseTaggedTemplateExpression(startPos, startLoc, base, state, typeArguments) {
6046 var node = this.startNodeAt(startPos, startLoc);
6047 node.tag = base;
6048 node.quasi = this.parseTemplate(true);
6049 if (typeArguments) node.typeParameters = typeArguments;
6050
6051 if (state.optionalChainMember) {
6052 this.raise(startPos, "Tagged Template Literals are not allowed in optionalChain");
6053 }
6054
6055 return this.finishNode(node, "TaggedTemplateExpression");
6056 };
6057
6058 _proto.atPossibleAsync = function atPossibleAsync(base) {
6059 return !this.state.containsEsc && this.state.potentialArrowAt === base.start && base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon();
6060 };
6061
6062 _proto.finishCallExpression = function finishCallExpression(node) {
6063 if (node.callee.type === "Import") {
6064 if (node.arguments.length !== 1) {
6065 this.raise(node.start, "import() requires exactly one argument");
6066 }
6067
6068 var importArg = node.arguments[0];
6069
6070 if (importArg && importArg.type === "SpreadElement") {
6071 this.raise(importArg.start, "... is not allowed in import()");
6072 }
6073 }
6074
6075 return this.finishNode(node, "CallExpression");
6076 };
6077
6078 _proto.finishOptionalCallExpression = function finishOptionalCallExpression(node) {
6079 if (node.callee.type === "Import") {
6080 if (node.arguments.length !== 1) {
6081 this.raise(node.start, "import() requires exactly one argument");
6082 }
6083
6084 var importArg = node.arguments[0];
6085
6086 if (importArg && importArg.type === "SpreadElement") {
6087 this.raise(importArg.start, "... is not allowed in import()");
6088 }
6089 }
6090
6091 return this.finishNode(node, "OptionalCallExpression");
6092 };
6093
6094 _proto.parseCallExpressionArguments = function parseCallExpressionArguments(close, possibleAsyncArrow, refTrailingCommaPos) {
6095 var elts = [];
6096 var innerParenStart;
6097 var first = true;
6098
6099 while (!this.eat(close)) {
6100 if (first) {
6101 first = false;
6102 } else {
6103 this.expect(types.comma);
6104 if (this.eat(close)) break;
6105 }
6106
6107 if (this.match(types.parenL) && !innerParenStart) {
6108 innerParenStart = this.state.start;
6109 }
6110
6111 elts.push(this.parseExprListItem(false, possibleAsyncArrow ? {
6112 start: 0
6113 } : undefined, possibleAsyncArrow ? {
6114 start: 0
6115 } : undefined, possibleAsyncArrow ? refTrailingCommaPos : undefined));
6116 }
6117
6118 if (possibleAsyncArrow && innerParenStart && this.shouldParseAsyncArrow()) {
6119 this.unexpected();
6120 }
6121
6122 return elts;
6123 };
6124
6125 _proto.shouldParseAsyncArrow = function shouldParseAsyncArrow() {
6126 return this.match(types.arrow);
6127 };
6128
6129 _proto.parseAsyncArrowFromCallExpression = function parseAsyncArrowFromCallExpression(node, call) {
6130 var oldYield = this.state.yieldInPossibleArrowParameters;
6131 this.state.yieldInPossibleArrowParameters = null;
6132 this.expect(types.arrow);
6133 this.parseArrowExpression(node, call.arguments, true);
6134 this.state.yieldInPossibleArrowParameters = oldYield;
6135 return node;
6136 };
6137
6138 _proto.parseNoCallExpr = function parseNoCallExpr() {
6139 var startPos = this.state.start;
6140 var startLoc = this.state.startLoc;
6141 return this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
6142 };
6143
6144 _proto.parseExprAtom = function parseExprAtom(refShorthandDefaultPos) {
6145 var canBeArrow = this.state.potentialArrowAt === this.state.start;
6146 var node;
6147
6148 switch (this.state.type) {
6149 case types._super:
6150 if (!this.state.inMethod && !this.state.inClassProperty && !this.options.allowSuperOutsideMethod) {
6151 this.raise(this.state.start, "super is only allowed in object methods and classes");
6152 }
6153
6154 node = this.startNode();
6155 this.next();
6156
6157 if (!this.match(types.parenL) && !this.match(types.bracketL) && !this.match(types.dot)) {
6158 this.unexpected();
6159 }
6160
6161 if (this.match(types.parenL) && this.state.inMethod !== "constructor" && !this.options.allowSuperOutsideMethod) {
6162 this.raise(node.start, "super() is only valid inside a class constructor. " + "Make sure the method name is spelled exactly as 'constructor'.");
6163 }
6164
6165 return this.finishNode(node, "Super");
6166
6167 case types._import:
6168 if (this.lookahead().type === types.dot) {
6169 return this.parseImportMetaProperty();
6170 }
6171
6172 this.expectPlugin("dynamicImport");
6173 node = this.startNode();
6174 this.next();
6175
6176 if (!this.match(types.parenL)) {
6177 this.unexpected(null, types.parenL);
6178 }
6179
6180 return this.finishNode(node, "Import");
6181
6182 case types._this:
6183 node = this.startNode();
6184 this.next();
6185 return this.finishNode(node, "ThisExpression");
6186
6187 case types._yield:
6188 if (this.state.inGenerator) this.unexpected();
6189
6190 case types.name:
6191 {
6192 node = this.startNode();
6193 var allowAwait = this.state.value === "await" && (this.state.inAsync || !this.state.inFunction && this.options.allowAwaitOutsideFunction);
6194 var containsEsc = this.state.containsEsc;
6195 var allowYield = this.shouldAllowYieldIdentifier();
6196 var id = this.parseIdentifier(allowAwait || allowYield);
6197
6198 if (id.name === "await") {
6199 if (this.state.inAsync || this.inModule || !this.state.inFunction && this.options.allowAwaitOutsideFunction) {
6200 return this.parseAwait(node);
6201 }
6202 } else if (!containsEsc && id.name === "async" && this.match(types._function) && !this.canInsertSemicolon()) {
6203 this.next();
6204 return this.parseFunction(node, false, false, true);
6205 } else if (canBeArrow && id.name === "async" && this.match(types.name)) {
6206 var oldYield = this.state.yieldInPossibleArrowParameters;
6207 this.state.yieldInPossibleArrowParameters = null;
6208 var params = [this.parseIdentifier()];
6209 this.expect(types.arrow);
6210 this.parseArrowExpression(node, params, true);
6211 this.state.yieldInPossibleArrowParameters = oldYield;
6212 return node;
6213 }
6214
6215 if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
6216 var _oldYield = this.state.yieldInPossibleArrowParameters;
6217 this.state.yieldInPossibleArrowParameters = null;
6218 this.parseArrowExpression(node, [id]);
6219 this.state.yieldInPossibleArrowParameters = _oldYield;
6220 return node;
6221 }
6222
6223 return id;
6224 }
6225
6226 case types._do:
6227 {
6228 this.expectPlugin("doExpressions");
6229
6230 var _node12 = this.startNode();
6231
6232 this.next();
6233 var oldInFunction = this.state.inFunction;
6234 var oldLabels = this.state.labels;
6235 this.state.labels = [];
6236 this.state.inFunction = false;
6237 _node12.body = this.parseBlock(false);
6238 this.state.inFunction = oldInFunction;
6239 this.state.labels = oldLabels;
6240 return this.finishNode(_node12, "DoExpression");
6241 }
6242
6243 case types.regexp:
6244 {
6245 var value = this.state.value;
6246 node = this.parseLiteral(value.value, "RegExpLiteral");
6247 node.pattern = value.pattern;
6248 node.flags = value.flags;
6249 return node;
6250 }
6251
6252 case types.num:
6253 return this.parseLiteral(this.state.value, "NumericLiteral");
6254
6255 case types.bigint:
6256 return this.parseLiteral(this.state.value, "BigIntLiteral");
6257
6258 case types.string:
6259 return this.parseLiteral(this.state.value, "StringLiteral");
6260
6261 case types._null:
6262 node = this.startNode();
6263 this.next();
6264 return this.finishNode(node, "NullLiteral");
6265
6266 case types._true:
6267 case types._false:
6268 return this.parseBooleanLiteral();
6269
6270 case types.parenL:
6271 return this.parseParenAndDistinguishExpression(canBeArrow);
6272
6273 case types.bracketL:
6274 node = this.startNode();
6275 this.next();
6276 node.elements = this.parseExprList(types.bracketR, true, refShorthandDefaultPos);
6277 this.toReferencedList(node.elements);
6278 return this.finishNode(node, "ArrayExpression");
6279
6280 case types.braceL:
6281 return this.parseObj(false, refShorthandDefaultPos);
6282
6283 case types._function:
6284 return this.parseFunctionExpression();
6285
6286 case types.at:
6287 this.parseDecorators();
6288
6289 case types._class:
6290 node = this.startNode();
6291 this.takeDecorators(node);
6292 return this.parseClass(node, false);
6293
6294 case types._new:
6295 return this.parseNew();
6296
6297 case types.backQuote:
6298 return this.parseTemplate(false);
6299
6300 case types.doubleColon:
6301 {
6302 node = this.startNode();
6303 this.next();
6304 node.object = null;
6305 var callee = node.callee = this.parseNoCallExpr();
6306
6307 if (callee.type === "MemberExpression") {
6308 return this.finishNode(node, "BindExpression");
6309 } else {
6310 throw this.raise(callee.start, "Binding should be performed on object property.");
6311 }
6312 }
6313
6314 default:
6315 throw this.unexpected();
6316 }
6317 };
6318
6319 _proto.parseBooleanLiteral = function parseBooleanLiteral() {
6320 var node = this.startNode();
6321 node.value = this.match(types._true);
6322 this.next();
6323 return this.finishNode(node, "BooleanLiteral");
6324 };
6325
6326 _proto.parseMaybePrivateName = function parseMaybePrivateName() {
6327 var isPrivate = this.match(types.hash);
6328
6329 if (isPrivate) {
6330 this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]);
6331
6332 var _node13 = this.startNode();
6333
6334 this.next();
6335 _node13.id = this.parseIdentifier(true);
6336 return this.finishNode(_node13, "PrivateName");
6337 } else {
6338 return this.parseIdentifier(true);
6339 }
6340 };
6341
6342 _proto.parseFunctionExpression = function parseFunctionExpression() {
6343 var node = this.startNode();
6344 var meta = this.parseIdentifier(true);
6345
6346 if (this.state.inGenerator && this.eat(types.dot)) {
6347 return this.parseMetaProperty(node, meta, "sent");
6348 }
6349
6350 return this.parseFunction(node, false);
6351 };
6352
6353 _proto.parseMetaProperty = function parseMetaProperty(node, meta, propertyName) {
6354 node.meta = meta;
6355
6356 if (meta.name === "function" && propertyName === "sent") {
6357 if (this.isContextual(propertyName)) {
6358 this.expectPlugin("functionSent");
6359 } else if (!this.hasPlugin("functionSent")) {
6360 this.unexpected();
6361 }
6362 }
6363
6364 var containsEsc = this.state.containsEsc;
6365 node.property = this.parseIdentifier(true);
6366
6367 if (node.property.name !== propertyName || containsEsc) {
6368 this.raise(node.property.start, "The only valid meta property for " + meta.name + " is " + meta.name + "." + propertyName);
6369 }
6370
6371 return this.finishNode(node, "MetaProperty");
6372 };
6373
6374 _proto.parseImportMetaProperty = function parseImportMetaProperty() {
6375 var node = this.startNode();
6376 var id = this.parseIdentifier(true);
6377 this.expect(types.dot);
6378
6379 if (id.name === "import") {
6380 if (this.isContextual("meta")) {
6381 this.expectPlugin("importMeta");
6382 } else if (!this.hasPlugin("importMeta")) {
6383 this.raise(id.start, "Dynamic imports require a parameter: import('a.js')");
6384 }
6385 }
6386
6387 if (!this.inModule) {
6388 this.raise(id.start, "import.meta may appear only with 'sourceType: \"module\"'", {
6389 code: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"
6390 });
6391 }
6392
6393 this.sawUnambiguousESM = true;
6394 return this.parseMetaProperty(node, id, "meta");
6395 };
6396
6397 _proto.parseLiteral = function parseLiteral(value, type, startPos, startLoc) {
6398 startPos = startPos || this.state.start;
6399 startLoc = startLoc || this.state.startLoc;
6400 var node = this.startNodeAt(startPos, startLoc);
6401 this.addExtra(node, "rawValue", value);
6402 this.addExtra(node, "raw", this.input.slice(startPos, this.state.end));
6403 node.value = value;
6404 this.next();
6405 return this.finishNode(node, type);
6406 };
6407
6408 _proto.parseParenExpression = function parseParenExpression() {
6409 this.expect(types.parenL);
6410 var val = this.parseExpression();
6411 this.expect(types.parenR);
6412 return val;
6413 };
6414
6415 _proto.parseParenAndDistinguishExpression = function parseParenAndDistinguishExpression(canBeArrow) {
6416 var startPos = this.state.start;
6417 var startLoc = this.state.startLoc;
6418 var val;
6419 this.expect(types.parenL);
6420 var oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
6421 var oldYield = this.state.yieldInPossibleArrowParameters;
6422 this.state.maybeInArrowParameters = true;
6423 this.state.yieldInPossibleArrowParameters = null;
6424 var innerStartPos = this.state.start;
6425 var innerStartLoc = this.state.startLoc;
6426 var exprList = [];
6427 var refShorthandDefaultPos = {
6428 start: 0
6429 };
6430 var refNeedsArrowPos = {
6431 start: 0
6432 };
6433 var first = true;
6434 var spreadStart;
6435 var optionalCommaStart;
6436
6437 while (!this.match(types.parenR)) {
6438 if (first) {
6439 first = false;
6440 } else {
6441 this.expect(types.comma, refNeedsArrowPos.start || null);
6442
6443 if (this.match(types.parenR)) {
6444 optionalCommaStart = this.state.start;
6445 break;
6446 }
6447 }
6448
6449 if (this.match(types.ellipsis)) {
6450 var spreadNodeStartPos = this.state.start;
6451 var spreadNodeStartLoc = this.state.startLoc;
6452 spreadStart = this.state.start;
6453 exprList.push(this.parseParenItem(this.parseRest(), spreadNodeStartPos, spreadNodeStartLoc));
6454
6455 if (this.match(types.comma) && this.lookahead().type === types.parenR) {
6456 this.raise(this.state.start, "A trailing comma is not permitted after the rest element");
6457 }
6458
6459 break;
6460 } else {
6461 exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos));
6462 }
6463 }
6464
6465 var innerEndPos = this.state.start;
6466 var innerEndLoc = this.state.startLoc;
6467 this.expect(types.parenR);
6468 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
6469 var arrowNode = this.startNodeAt(startPos, startLoc);
6470
6471 if (canBeArrow && this.shouldParseArrow() && (arrowNode = this.parseArrow(arrowNode))) {
6472 for (var _i2 = 0; _i2 < exprList.length; _i2++) {
6473 var param = exprList[_i2];
6474
6475 if (param.extra && param.extra.parenthesized) {
6476 this.unexpected(param.extra.parenStart);
6477 }
6478 }
6479
6480 this.parseArrowExpression(arrowNode, exprList);
6481 this.state.yieldInPossibleArrowParameters = oldYield;
6482 return arrowNode;
6483 }
6484
6485 this.state.yieldInPossibleArrowParameters = oldYield;
6486
6487 if (!exprList.length) {
6488 this.unexpected(this.state.lastTokStart);
6489 }
6490
6491 if (optionalCommaStart) this.unexpected(optionalCommaStart);
6492 if (spreadStart) this.unexpected(spreadStart);
6493
6494 if (refShorthandDefaultPos.start) {
6495 this.unexpected(refShorthandDefaultPos.start);
6496 }
6497
6498 if (refNeedsArrowPos.start) this.unexpected(refNeedsArrowPos.start);
6499
6500 if (exprList.length > 1) {
6501 val = this.startNodeAt(innerStartPos, innerStartLoc);
6502 val.expressions = exprList;
6503 this.toReferencedList(val.expressions);
6504 this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
6505 } else {
6506 val = exprList[0];
6507 }
6508
6509 this.addExtra(val, "parenthesized", true);
6510 this.addExtra(val, "parenStart", startPos);
6511 return val;
6512 };
6513
6514 _proto.shouldParseArrow = function shouldParseArrow() {
6515 return !this.canInsertSemicolon();
6516 };
6517
6518 _proto.parseArrow = function parseArrow(node) {
6519 if (this.eat(types.arrow)) {
6520 return node;
6521 }
6522 };
6523
6524 _proto.parseParenItem = function parseParenItem(node, startPos, startLoc) {
6525 return node;
6526 };
6527
6528 _proto.parseNew = function parseNew() {
6529 var node = this.startNode();
6530 var meta = this.parseIdentifier(true);
6531
6532 if (this.eat(types.dot)) {
6533 var metaProp = this.parseMetaProperty(node, meta, "target");
6534
6535 if (!this.state.inFunction && !this.state.inClassProperty) {
6536 var error = "new.target can only be used in functions";
6537
6538 if (this.hasPlugin("classProperties")) {
6539 error += " or class properties";
6540 }
6541
6542 this.raise(metaProp.start, error);
6543 }
6544
6545 return metaProp;
6546 }
6547
6548 node.callee = this.parseNoCallExpr();
6549
6550 if (node.callee.type === "OptionalMemberExpression" || node.callee.type === "OptionalCallExpression") {
6551 this.raise(this.state.lastTokEnd, "constructors in/after an Optional Chain are not allowed");
6552 }
6553
6554 if (this.eat(types.questionDot)) {
6555 this.raise(this.state.start, "constructors in/after an Optional Chain are not allowed");
6556 }
6557
6558 this.parseNewArguments(node);
6559 return this.finishNode(node, "NewExpression");
6560 };
6561
6562 _proto.parseNewArguments = function parseNewArguments(node) {
6563 if (this.eat(types.parenL)) {
6564 var args = this.parseExprList(types.parenR);
6565 this.toReferencedList(args);
6566 node.arguments = args;
6567 } else {
6568 node.arguments = [];
6569 }
6570 };
6571
6572 _proto.parseTemplateElement = function parseTemplateElement(isTagged) {
6573 var elem = this.startNode();
6574
6575 if (this.state.value === null) {
6576 if (!isTagged) {
6577 this.raise(this.state.invalidTemplateEscapePosition || 0, "Invalid escape sequence in template");
6578 } else {
6579 this.state.invalidTemplateEscapePosition = null;
6580 }
6581 }
6582
6583 elem.value = {
6584 raw: this.input.slice(this.state.start, this.state.end).replace(/\r\n?/g, "\n"),
6585 cooked: this.state.value
6586 };
6587 this.next();
6588 elem.tail = this.match(types.backQuote);
6589 return this.finishNode(elem, "TemplateElement");
6590 };
6591
6592 _proto.parseTemplate = function parseTemplate(isTagged) {
6593 var node = this.startNode();
6594 this.next();
6595 node.expressions = [];
6596 var curElt = this.parseTemplateElement(isTagged);
6597 node.quasis = [curElt];
6598
6599 while (!curElt.tail) {
6600 this.expect(types.dollarBraceL);
6601 node.expressions.push(this.parseExpression());
6602 this.expect(types.braceR);
6603 node.quasis.push(curElt = this.parseTemplateElement(isTagged));
6604 }
6605
6606 this.next();
6607 return this.finishNode(node, "TemplateLiteral");
6608 };
6609
6610 _proto.parseObj = function parseObj(isPattern, refShorthandDefaultPos) {
6611 var decorators = [];
6612 var propHash = Object.create(null);
6613 var first = true;
6614 var node = this.startNode();
6615 node.properties = [];
6616 this.next();
6617 var firstRestLocation = null;
6618
6619 while (!this.eat(types.braceR)) {
6620 if (first) {
6621 first = false;
6622 } else {
6623 this.expect(types.comma);
6624 if (this.eat(types.braceR)) break;
6625 }
6626
6627 if (this.match(types.at)) {
6628 if (this.hasPlugin("decorators")) {
6629 this.raise(this.state.start, "Stage 2 decorators disallow object literal property decorators");
6630 } else {
6631 while (this.match(types.at)) {
6632 decorators.push(this.parseDecorator());
6633 }
6634 }
6635 }
6636
6637 var prop = this.startNode(),
6638 isGenerator = false,
6639 _isAsync = false,
6640 startPos = void 0,
6641 startLoc = void 0;
6642
6643 if (decorators.length) {
6644 prop.decorators = decorators;
6645 decorators = [];
6646 }
6647
6648 if (this.match(types.ellipsis)) {
6649 this.expectPlugin("objectRestSpread");
6650 prop = this.parseSpread(isPattern ? {
6651 start: 0
6652 } : undefined);
6653
6654 if (isPattern) {
6655 this.toAssignable(prop, true, "object pattern");
6656 }
6657
6658 node.properties.push(prop);
6659
6660 if (isPattern) {
6661 var position = this.state.start;
6662
6663 if (firstRestLocation !== null) {
6664 this.unexpected(firstRestLocation, "Cannot have multiple rest elements when destructuring");
6665 } else if (this.eat(types.braceR)) {
6666 break;
6667 } else if (this.match(types.comma) && this.lookahead().type === types.braceR) {
6668 this.unexpected(position, "A trailing comma is not permitted after the rest element");
6669 } else {
6670 firstRestLocation = position;
6671 continue;
6672 }
6673 } else {
6674 continue;
6675 }
6676 }
6677
6678 prop.method = false;
6679
6680 if (isPattern || refShorthandDefaultPos) {
6681 startPos = this.state.start;
6682 startLoc = this.state.startLoc;
6683 }
6684
6685 if (!isPattern) {
6686 isGenerator = this.eat(types.star);
6687 }
6688
6689 var containsEsc = this.state.containsEsc;
6690
6691 if (!isPattern && this.isContextual("async")) {
6692 if (isGenerator) this.unexpected();
6693 var asyncId = this.parseIdentifier();
6694
6695 if (this.match(types.colon) || this.match(types.parenL) || this.match(types.braceR) || this.match(types.eq) || this.match(types.comma)) {
6696 prop.key = asyncId;
6697 prop.computed = false;
6698 } else {
6699 _isAsync = true;
6700
6701 if (this.match(types.star)) {
6702 this.expectPlugin("asyncGenerators");
6703 this.next();
6704 isGenerator = true;
6705 }
6706
6707 this.parsePropertyName(prop);
6708 }
6709 } else {
6710 this.parsePropertyName(prop);
6711 }
6712
6713 this.parseObjPropValue(prop, startPos, startLoc, isGenerator, _isAsync, isPattern, refShorthandDefaultPos, containsEsc);
6714 this.checkPropClash(prop, propHash);
6715
6716 if (prop.shorthand) {
6717 this.addExtra(prop, "shorthand", true);
6718 }
6719
6720 node.properties.push(prop);
6721 }
6722
6723 if (firstRestLocation !== null) {
6724 this.unexpected(firstRestLocation, "The rest element has to be the last element when destructuring");
6725 }
6726
6727 if (decorators.length) {
6728 this.raise(this.state.start, "You have trailing decorators with no property");
6729 }
6730
6731 return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression");
6732 };
6733
6734 _proto.isGetterOrSetterMethod = function isGetterOrSetterMethod(prop, isPattern) {
6735 return !isPattern && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (this.match(types.string) || this.match(types.num) || this.match(types.bracketL) || this.match(types.name) || !!this.state.type.keyword);
6736 };
6737
6738 _proto.checkGetterSetterParams = function checkGetterSetterParams(method) {
6739 var paramCount = method.kind === "get" ? 0 : 1;
6740 var start = method.start;
6741
6742 if (method.params.length !== paramCount) {
6743 if (method.kind === "get") {
6744 this.raise(start, "getter must not have any formal parameters");
6745 } else {
6746 this.raise(start, "setter must have exactly one formal parameter");
6747 }
6748 }
6749
6750 if (method.kind === "set" && method.params[0].type === "RestElement") {
6751 this.raise(start, "setter function argument must not be a rest parameter");
6752 }
6753 };
6754
6755 _proto.parseObjectMethod = function parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) {
6756 if (isAsync || isGenerator || this.match(types.parenL)) {
6757 if (isPattern) this.unexpected();
6758 prop.kind = "method";
6759 prop.method = true;
6760 return this.parseMethod(prop, isGenerator, isAsync, false, "ObjectMethod");
6761 }
6762
6763 if (!containsEsc && this.isGetterOrSetterMethod(prop, isPattern)) {
6764 if (isGenerator || isAsync) this.unexpected();
6765 prop.kind = prop.key.name;
6766 this.parsePropertyName(prop);
6767 this.parseMethod(prop, false, false, false, "ObjectMethod");
6768 this.checkGetterSetterParams(prop);
6769 return prop;
6770 }
6771 };
6772
6773 _proto.parseObjectProperty = function parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos) {
6774 prop.shorthand = false;
6775
6776 if (this.eat(types.colon)) {
6777 prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos);
6778 return this.finishNode(prop, "ObjectProperty");
6779 }
6780
6781 if (!prop.computed && prop.key.type === "Identifier") {
6782 this.checkReservedWord(prop.key.name, prop.key.start, true, true);
6783
6784 if (isPattern) {
6785 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone());
6786 } else if (this.match(types.eq) && refShorthandDefaultPos) {
6787 if (!refShorthandDefaultPos.start) {
6788 refShorthandDefaultPos.start = this.state.start;
6789 }
6790
6791 prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone());
6792 } else {
6793 prop.value = prop.key.__clone();
6794 }
6795
6796 prop.shorthand = true;
6797 return this.finishNode(prop, "ObjectProperty");
6798 }
6799 };
6800
6801 _proto.parseObjPropValue = function parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc) {
6802 var node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) || this.parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos);
6803 if (!node) this.unexpected();
6804 return node;
6805 };
6806
6807 _proto.parsePropertyName = function parsePropertyName(prop) {
6808 if (this.eat(types.bracketL)) {
6809 prop.computed = true;
6810 prop.key = this.parseMaybeAssign();
6811 this.expect(types.bracketR);
6812 } else {
6813 var oldInPropertyName = this.state.inPropertyName;
6814 this.state.inPropertyName = true;
6815 prop.key = this.match(types.num) || this.match(types.string) ? this.parseExprAtom() : this.parseMaybePrivateName();
6816
6817 if (prop.key.type !== "PrivateName") {
6818 prop.computed = false;
6819 }
6820
6821 this.state.inPropertyName = oldInPropertyName;
6822 }
6823
6824 return prop.key;
6825 };
6826
6827 _proto.initFunction = function initFunction(node, isAsync) {
6828 node.id = null;
6829 node.generator = false;
6830 node.async = !!isAsync;
6831 };
6832
6833 _proto.parseMethod = function parseMethod(node, isGenerator, isAsync, isConstructor, type) {
6834 var oldInFunc = this.state.inFunction;
6835 var oldInMethod = this.state.inMethod;
6836 var oldInGenerator = this.state.inGenerator;
6837 this.state.inFunction = true;
6838 this.state.inMethod = node.kind || true;
6839 this.state.inGenerator = isGenerator;
6840 this.initFunction(node, isAsync);
6841 node.generator = !!isGenerator;
6842 var allowModifiers = isConstructor;
6843 this.parseFunctionParams(node, allowModifiers);
6844 this.parseFunctionBodyAndFinish(node, type);
6845 this.state.inFunction = oldInFunc;
6846 this.state.inMethod = oldInMethod;
6847 this.state.inGenerator = oldInGenerator;
6848 return node;
6849 };
6850
6851 _proto.parseArrowExpression = function parseArrowExpression(node, params, isAsync) {
6852 if (this.state.yieldInPossibleArrowParameters) {
6853 this.raise(this.state.yieldInPossibleArrowParameters.start, "yield is not allowed in the parameters of an arrow function" + " inside a generator");
6854 }
6855
6856 var oldInFunc = this.state.inFunction;
6857 this.state.inFunction = true;
6858 this.initFunction(node, isAsync);
6859 if (params) this.setArrowFunctionParameters(node, params);
6860 var oldInGenerator = this.state.inGenerator;
6861 var oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
6862 this.state.inGenerator = false;
6863 this.state.maybeInArrowParameters = false;
6864 this.parseFunctionBody(node, true);
6865 this.state.inGenerator = oldInGenerator;
6866 this.state.inFunction = oldInFunc;
6867 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
6868 return this.finishNode(node, "ArrowFunctionExpression");
6869 };
6870
6871 _proto.setArrowFunctionParameters = function setArrowFunctionParameters(node, params) {
6872 node.params = this.toAssignableList(params, true, "arrow function parameters");
6873 };
6874
6875 _proto.isStrictBody = function isStrictBody(node) {
6876 var isBlockStatement = node.body.type === "BlockStatement";
6877
6878 if (isBlockStatement && node.body.directives.length) {
6879 for (var _i4 = 0, _node$body$directives2 = node.body.directives; _i4 < _node$body$directives2.length; _i4++) {
6880 var directive = _node$body$directives2[_i4];
6881
6882 if (directive.value.value === "use strict") {
6883 return true;
6884 }
6885 }
6886 }
6887
6888 return false;
6889 };
6890
6891 _proto.parseFunctionBodyAndFinish = function parseFunctionBodyAndFinish(node, type, allowExpressionBody) {
6892 this.parseFunctionBody(node, allowExpressionBody);
6893 this.finishNode(node, type);
6894 };
6895
6896 _proto.parseFunctionBody = function parseFunctionBody(node, allowExpression) {
6897 var isExpression = allowExpression && !this.match(types.braceL);
6898 var oldInParameters = this.state.inParameters;
6899 var oldInAsync = this.state.inAsync;
6900 this.state.inParameters = false;
6901 this.state.inAsync = node.async;
6902
6903 if (isExpression) {
6904 node.body = this.parseMaybeAssign();
6905 } else {
6906 var oldInGen = this.state.inGenerator;
6907 var oldInFunc = this.state.inFunction;
6908 var oldLabels = this.state.labels;
6909 this.state.inGenerator = node.generator;
6910 this.state.inFunction = true;
6911 this.state.labels = [];
6912 node.body = this.parseBlock(true);
6913 this.state.inFunction = oldInFunc;
6914 this.state.inGenerator = oldInGen;
6915 this.state.labels = oldLabels;
6916 }
6917
6918 this.state.inAsync = oldInAsync;
6919 this.checkFunctionNameAndParams(node, allowExpression);
6920 this.state.inParameters = oldInParameters;
6921 };
6922
6923 _proto.checkFunctionNameAndParams = function checkFunctionNameAndParams(node, isArrowFunction) {
6924 var isStrict = this.isStrictBody(node);
6925 var checkLVal = this.state.strict || isStrict || isArrowFunction;
6926 var oldStrict = this.state.strict;
6927 if (isStrict) this.state.strict = isStrict;
6928
6929 if (checkLVal) {
6930 var nameHash = Object.create(null);
6931
6932 if (node.id) {
6933 this.checkLVal(node.id, true, undefined, "function name");
6934 }
6935
6936 for (var _i6 = 0, _node$params2 = node.params; _i6 < _node$params2.length; _i6++) {
6937 var param = _node$params2[_i6];
6938
6939 if (isStrict && param.type !== "Identifier") {
6940 this.raise(param.start, "Non-simple parameter in strict mode");
6941 }
6942
6943 this.checkLVal(param, true, nameHash, "function parameter list");
6944 }
6945 }
6946
6947 this.state.strict = oldStrict;
6948 };
6949
6950 _proto.parseExprList = function parseExprList(close, allowEmpty, refShorthandDefaultPos) {
6951 var elts = [];
6952 var first = true;
6953
6954 while (!this.eat(close)) {
6955 if (first) {
6956 first = false;
6957 } else {
6958 this.expect(types.comma);
6959 if (this.eat(close)) break;
6960 }
6961
6962 elts.push(this.parseExprListItem(allowEmpty, refShorthandDefaultPos));
6963 }
6964
6965 return elts;
6966 };
6967
6968 _proto.parseExprListItem = function parseExprListItem(allowEmpty, refShorthandDefaultPos, refNeedsArrowPos, refTrailingCommaPos) {
6969 var elt;
6970
6971 if (allowEmpty && this.match(types.comma)) {
6972 elt = null;
6973 } else if (this.match(types.ellipsis)) {
6974 var spreadNodeStartPos = this.state.start;
6975 var spreadNodeStartLoc = this.state.startLoc;
6976 elt = this.parseParenItem(this.parseSpread(refShorthandDefaultPos, refNeedsArrowPos), spreadNodeStartPos, spreadNodeStartLoc);
6977
6978 if (refTrailingCommaPos && this.match(types.comma)) {
6979 refTrailingCommaPos.start = this.state.start;
6980 }
6981 } else {
6982 elt = this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos);
6983 }
6984
6985 return elt;
6986 };
6987
6988 _proto.parseIdentifier = function parseIdentifier(liberal) {
6989 var node = this.startNode();
6990 var name = this.parseIdentifierName(node.start, liberal);
6991 node.name = name;
6992 node.loc.identifierName = name;
6993 return this.finishNode(node, "Identifier");
6994 };
6995
6996 _proto.parseIdentifierName = function parseIdentifierName(pos, liberal) {
6997 if (!liberal) {
6998 this.checkReservedWord(this.state.value, this.state.start, !!this.state.type.keyword, false);
6999 }
7000
7001 var name;
7002
7003 if (this.match(types.name)) {
7004 name = this.state.value;
7005 } else if (this.state.type.keyword) {
7006 name = this.state.type.keyword;
7007 } else {
7008 throw this.unexpected();
7009 }
7010
7011 if (!liberal && name === "await" && this.state.inAsync) {
7012 this.raise(pos, "invalid use of await inside of an async function");
7013 }
7014
7015 this.next();
7016 return name;
7017 };
7018
7019 _proto.checkReservedWord = function checkReservedWord(word, startLoc, checkKeywords, isBinding) {
7020 if (this.state.strict && (reservedWords.strict(word) || isBinding && reservedWords.strictBind(word))) {
7021 this.raise(startLoc, word + " is a reserved word in strict mode");
7022 }
7023
7024 if (this.state.inGenerator && word === "yield") {
7025 this.raise(startLoc, "yield is a reserved word inside generator functions");
7026 }
7027
7028 if (this.state.inClassProperty && word === "arguments") {
7029 this.raise(startLoc, "'arguments' is not allowed in class field initializer");
7030 }
7031
7032 if (this.isReservedWord(word) || checkKeywords && this.isKeyword(word)) {
7033 this.raise(startLoc, word + " is a reserved word");
7034 }
7035 };
7036
7037 _proto.parseAwait = function parseAwait(node) {
7038 if (!this.state.inAsync && (this.state.inFunction || !this.options.allowAwaitOutsideFunction)) {
7039 this.unexpected();
7040 }
7041
7042 if (this.match(types.star)) {
7043 this.raise(node.start, "await* has been removed from the async functions proposal. Use Promise.all() instead.");
7044 }
7045
7046 node.argument = this.parseMaybeUnary();
7047 return this.finishNode(node, "AwaitExpression");
7048 };
7049
7050 _proto.parseYield = function parseYield() {
7051 var node = this.startNode();
7052
7053 if (this.state.inParameters) {
7054 this.raise(node.start, "yield is not allowed in generator parameters");
7055 }
7056
7057 if (this.state.maybeInArrowParameters && !this.state.yieldInPossibleArrowParameters) {
7058 this.state.yieldInPossibleArrowParameters = node;
7059 }
7060
7061 this.next();
7062
7063 if (this.match(types.semi) || this.canInsertSemicolon() || !this.match(types.star) && !this.state.type.startsExpr) {
7064 node.delegate = false;
7065 node.argument = null;
7066 } else {
7067 node.delegate = this.eat(types.star);
7068 node.argument = this.parseMaybeAssign();
7069 }
7070
7071 return this.finishNode(node, "YieldExpression");
7072 };
7073
7074 return ExpressionParser;
7075}(LValParser);
7076
7077var empty = [];
7078var loopLabel = {
7079 kind: "loop"
7080};
7081var switchLabel = {
7082 kind: "switch"
7083};
7084
7085var StatementParser = function (_ExpressionParser) {
7086 _inheritsLoose(StatementParser, _ExpressionParser);
7087
7088 function StatementParser() {
7089 return _ExpressionParser.apply(this, arguments) || this;
7090 }
7091
7092 var _proto = StatementParser.prototype;
7093
7094 _proto.parseTopLevel = function parseTopLevel(file, program) {
7095 program.sourceType = this.options.sourceType;
7096 program.interpreter = this.parseInterpreterDirective();
7097 this.parseBlockBody(program, true, true, types.eof);
7098 file.program = this.finishNode(program, "Program");
7099 file.comments = this.state.comments;
7100 if (this.options.tokens) file.tokens = this.state.tokens;
7101 return this.finishNode(file, "File");
7102 };
7103
7104 _proto.stmtToDirective = function stmtToDirective(stmt) {
7105 var expr = stmt.expression;
7106 var directiveLiteral = this.startNodeAt(expr.start, expr.loc.start);
7107 var directive = this.startNodeAt(stmt.start, stmt.loc.start);
7108 var raw = this.input.slice(expr.start, expr.end);
7109 var val = directiveLiteral.value = raw.slice(1, -1);
7110 this.addExtra(directiveLiteral, "raw", raw);
7111 this.addExtra(directiveLiteral, "rawValue", val);
7112 directive.value = this.finishNodeAt(directiveLiteral, "DirectiveLiteral", expr.end, expr.loc.end);
7113 return this.finishNodeAt(directive, "Directive", stmt.end, stmt.loc.end);
7114 };
7115
7116 _proto.parseInterpreterDirective = function parseInterpreterDirective() {
7117 if (!this.match(types.interpreterDirective)) {
7118 return null;
7119 }
7120
7121 var node = this.startNode();
7122 node.value = this.state.value;
7123 this.next();
7124 return this.finishNode(node, "InterpreterDirective");
7125 };
7126
7127 _proto.parseStatement = function parseStatement(declaration, topLevel) {
7128 if (this.match(types.at)) {
7129 this.parseDecorators(true);
7130 }
7131
7132 return this.parseStatementContent(declaration, topLevel);
7133 };
7134
7135 _proto.parseStatementContent = function parseStatementContent(declaration, topLevel) {
7136 var starttype = this.state.type;
7137 var node = this.startNode();
7138
7139 switch (starttype) {
7140 case types._break:
7141 case types._continue:
7142 return this.parseBreakContinueStatement(node, starttype.keyword);
7143
7144 case types._debugger:
7145 return this.parseDebuggerStatement(node);
7146
7147 case types._do:
7148 return this.parseDoStatement(node);
7149
7150 case types._for:
7151 return this.parseForStatement(node);
7152
7153 case types._function:
7154 if (this.lookahead().type === types.dot) break;
7155 if (!declaration) this.unexpected();
7156 return this.parseFunctionStatement(node);
7157
7158 case types._class:
7159 if (!declaration) this.unexpected();
7160 return this.parseClass(node, true);
7161
7162 case types._if:
7163 return this.parseIfStatement(node);
7164
7165 case types._return:
7166 return this.parseReturnStatement(node);
7167
7168 case types._switch:
7169 return this.parseSwitchStatement(node);
7170
7171 case types._throw:
7172 return this.parseThrowStatement(node);
7173
7174 case types._try:
7175 return this.parseTryStatement(node);
7176
7177 case types._let:
7178 case types._const:
7179 if (!declaration) this.unexpected();
7180
7181 case types._var:
7182 return this.parseVarStatement(node, starttype);
7183
7184 case types._while:
7185 return this.parseWhileStatement(node);
7186
7187 case types._with:
7188 return this.parseWithStatement(node);
7189
7190 case types.braceL:
7191 return this.parseBlock();
7192
7193 case types.semi:
7194 return this.parseEmptyStatement(node);
7195
7196 case types._export:
7197 case types._import:
7198 {
7199 var nextToken = this.lookahead();
7200
7201 if (nextToken.type === types.parenL || nextToken.type === types.dot) {
7202 break;
7203 }
7204
7205 if (!this.options.allowImportExportEverywhere && !topLevel) {
7206 this.raise(this.state.start, "'import' and 'export' may only appear at the top level");
7207 }
7208
7209 this.next();
7210 var result;
7211
7212 if (starttype == types._import) {
7213 result = this.parseImport(node);
7214
7215 if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
7216 this.sawUnambiguousESM = true;
7217 }
7218 } else {
7219 result = this.parseExport(node);
7220
7221 if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
7222 this.sawUnambiguousESM = true;
7223 }
7224 }
7225
7226 this.assertModuleNodeAllowed(node);
7227 return result;
7228 }
7229
7230 case types.name:
7231 if (this.isContextual("async")) {
7232 var state = this.state.clone();
7233 this.next();
7234
7235 if (this.match(types._function) && !this.canInsertSemicolon()) {
7236 this.expect(types._function);
7237 return this.parseFunction(node, true, false, true);
7238 } else {
7239 this.state = state;
7240 }
7241 }
7242
7243 }
7244
7245 var maybeName = this.state.value;
7246 var expr = this.parseExpression();
7247
7248 if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon)) {
7249 return this.parseLabeledStatement(node, maybeName, expr);
7250 } else {
7251 return this.parseExpressionStatement(node, expr);
7252 }
7253 };
7254
7255 _proto.assertModuleNodeAllowed = function assertModuleNodeAllowed(node) {
7256 if (!this.options.allowImportExportEverywhere && !this.inModule) {
7257 this.raise(node.start, "'import' and 'export' may appear only with 'sourceType: \"module\"'", {
7258 code: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"
7259 });
7260 }
7261 };
7262
7263 _proto.takeDecorators = function takeDecorators(node) {
7264 var decorators = this.state.decoratorStack[this.state.decoratorStack.length - 1];
7265
7266 if (decorators.length) {
7267 node.decorators = decorators;
7268 this.resetStartLocationFromNode(node, decorators[0]);
7269 this.state.decoratorStack[this.state.decoratorStack.length - 1] = [];
7270 }
7271 };
7272
7273 _proto.canHaveLeadingDecorator = function canHaveLeadingDecorator() {
7274 return this.match(types._class);
7275 };
7276
7277 _proto.parseDecorators = function parseDecorators(allowExport) {
7278 var currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1];
7279
7280 while (this.match(types.at)) {
7281 var decorator = this.parseDecorator();
7282 currentContextDecorators.push(decorator);
7283 }
7284
7285 if (this.match(types._export)) {
7286 if (!allowExport) {
7287 this.unexpected();
7288 }
7289
7290 if (this.hasPlugin("decorators") && !this.getPluginOption("decorators", "decoratorsBeforeExport")) {
7291 this.raise(this.state.start, "Using the export keyword between a decorator and a class is not allowed. " + "Please use `export @dec class` instead.");
7292 }
7293 } else if (!this.canHaveLeadingDecorator()) {
7294 this.raise(this.state.start, "Leading decorators must be attached to a class declaration");
7295 }
7296 };
7297
7298 _proto.parseDecorator = function parseDecorator() {
7299 this.expectOnePlugin(["decorators-legacy", "decorators"]);
7300 var node = this.startNode();
7301 this.next();
7302
7303 if (this.hasPlugin("decorators")) {
7304 this.state.decoratorStack.push([]);
7305 var startPos = this.state.start;
7306 var startLoc = this.state.startLoc;
7307 var expr;
7308
7309 if (this.eat(types.parenL)) {
7310 expr = this.parseExpression();
7311 this.expect(types.parenR);
7312 } else {
7313 expr = this.parseIdentifier(false);
7314
7315 while (this.eat(types.dot)) {
7316 var _node = this.startNodeAt(startPos, startLoc);
7317
7318 _node.object = expr;
7319 _node.property = this.parseIdentifier(true);
7320 _node.computed = false;
7321 expr = this.finishNode(_node, "MemberExpression");
7322 }
7323 }
7324
7325 if (this.eat(types.parenL)) {
7326 var _node2 = this.startNodeAt(startPos, startLoc);
7327
7328 _node2.callee = expr;
7329 _node2.arguments = this.parseCallExpressionArguments(types.parenR, false);
7330 this.toReferencedList(_node2.arguments);
7331 expr = this.finishNode(_node2, "CallExpression");
7332 }
7333
7334 node.expression = expr;
7335 this.state.decoratorStack.pop();
7336 } else {
7337 node.expression = this.parseMaybeAssign();
7338 }
7339
7340 return this.finishNode(node, "Decorator");
7341 };
7342
7343 _proto.parseBreakContinueStatement = function parseBreakContinueStatement(node, keyword) {
7344 var isBreak = keyword === "break";
7345 this.next();
7346
7347 if (this.isLineTerminator()) {
7348 node.label = null;
7349 } else if (!this.match(types.name)) {
7350 this.unexpected();
7351 } else {
7352 node.label = this.parseIdentifier();
7353 this.semicolon();
7354 }
7355
7356 var i;
7357
7358 for (i = 0; i < this.state.labels.length; ++i) {
7359 var lab = this.state.labels[i];
7360
7361 if (node.label == null || lab.name === node.label.name) {
7362 if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
7363 if (node.label && isBreak) break;
7364 }
7365 }
7366
7367 if (i === this.state.labels.length) {
7368 this.raise(node.start, "Unsyntactic " + keyword);
7369 }
7370
7371 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
7372 };
7373
7374 _proto.parseDebuggerStatement = function parseDebuggerStatement(node) {
7375 this.next();
7376 this.semicolon();
7377 return this.finishNode(node, "DebuggerStatement");
7378 };
7379
7380 _proto.parseDoStatement = function parseDoStatement(node) {
7381 this.next();
7382 this.state.labels.push(loopLabel);
7383 node.body = this.parseStatement(false);
7384 this.state.labels.pop();
7385 this.expect(types._while);
7386 node.test = this.parseParenExpression();
7387 this.eat(types.semi);
7388 return this.finishNode(node, "DoWhileStatement");
7389 };
7390
7391 _proto.parseForStatement = function parseForStatement(node) {
7392 this.next();
7393 this.state.labels.push(loopLabel);
7394 var forAwait = false;
7395
7396 if (this.state.inAsync && this.isContextual("await")) {
7397 this.expectPlugin("asyncGenerators");
7398 forAwait = true;
7399 this.next();
7400 }
7401
7402 this.expect(types.parenL);
7403
7404 if (this.match(types.semi)) {
7405 if (forAwait) {
7406 this.unexpected();
7407 }
7408
7409 return this.parseFor(node, null);
7410 }
7411
7412 if (this.match(types._var) || this.match(types._let) || this.match(types._const)) {
7413 var _init = this.startNode();
7414
7415 var varKind = this.state.type;
7416 this.next();
7417 this.parseVar(_init, true, varKind);
7418 this.finishNode(_init, "VariableDeclaration");
7419
7420 if (this.match(types._in) || this.isContextual("of")) {
7421 if (_init.declarations.length === 1) {
7422 var declaration = _init.declarations[0];
7423 var isForInInitializer = varKind === types._var && declaration.init && declaration.id.type != "ObjectPattern" && declaration.id.type != "ArrayPattern" && !this.isContextual("of");
7424
7425 if (this.state.strict && isForInInitializer) {
7426 this.raise(this.state.start, "for-in initializer in strict mode");
7427 } else if (isForInInitializer || !declaration.init) {
7428 return this.parseForIn(node, _init, forAwait);
7429 }
7430 }
7431 }
7432
7433 if (forAwait) {
7434 this.unexpected();
7435 }
7436
7437 return this.parseFor(node, _init);
7438 }
7439
7440 var refShorthandDefaultPos = {
7441 start: 0
7442 };
7443 var init = this.parseExpression(true, refShorthandDefaultPos);
7444
7445 if (this.match(types._in) || this.isContextual("of")) {
7446 var description = this.isContextual("of") ? "for-of statement" : "for-in statement";
7447 this.toAssignable(init, undefined, description);
7448 this.checkLVal(init, undefined, undefined, description);
7449 return this.parseForIn(node, init, forAwait);
7450 } else if (refShorthandDefaultPos.start) {
7451 this.unexpected(refShorthandDefaultPos.start);
7452 }
7453
7454 if (forAwait) {
7455 this.unexpected();
7456 }
7457
7458 return this.parseFor(node, init);
7459 };
7460
7461 _proto.parseFunctionStatement = function parseFunctionStatement(node) {
7462 this.next();
7463 return this.parseFunction(node, true);
7464 };
7465
7466 _proto.parseIfStatement = function parseIfStatement(node) {
7467 this.next();
7468 node.test = this.parseParenExpression();
7469 node.consequent = this.parseStatement(false);
7470 node.alternate = this.eat(types._else) ? this.parseStatement(false) : null;
7471 return this.finishNode(node, "IfStatement");
7472 };
7473
7474 _proto.parseReturnStatement = function parseReturnStatement(node) {
7475 if (!this.state.inFunction && !this.options.allowReturnOutsideFunction) {
7476 this.raise(this.state.start, "'return' outside of function");
7477 }
7478
7479 this.next();
7480
7481 if (this.isLineTerminator()) {
7482 node.argument = null;
7483 } else {
7484 node.argument = this.parseExpression();
7485 this.semicolon();
7486 }
7487
7488 return this.finishNode(node, "ReturnStatement");
7489 };
7490
7491 _proto.parseSwitchStatement = function parseSwitchStatement(node) {
7492 this.next();
7493 node.discriminant = this.parseParenExpression();
7494 var cases = node.cases = [];
7495 this.expect(types.braceL);
7496 this.state.labels.push(switchLabel);
7497 var cur;
7498
7499 for (var sawDefault; !this.match(types.braceR);) {
7500 if (this.match(types._case) || this.match(types._default)) {
7501 var isCase = this.match(types._case);
7502 if (cur) this.finishNode(cur, "SwitchCase");
7503 cases.push(cur = this.startNode());
7504 cur.consequent = [];
7505 this.next();
7506
7507 if (isCase) {
7508 cur.test = this.parseExpression();
7509 } else {
7510 if (sawDefault) {
7511 this.raise(this.state.lastTokStart, "Multiple default clauses");
7512 }
7513
7514 sawDefault = true;
7515 cur.test = null;
7516 }
7517
7518 this.expect(types.colon);
7519 } else {
7520 if (cur) {
7521 cur.consequent.push(this.parseStatement(true));
7522 } else {
7523 this.unexpected();
7524 }
7525 }
7526 }
7527
7528 if (cur) this.finishNode(cur, "SwitchCase");
7529 this.next();
7530 this.state.labels.pop();
7531 return this.finishNode(node, "SwitchStatement");
7532 };
7533
7534 _proto.parseThrowStatement = function parseThrowStatement(node) {
7535 this.next();
7536
7537 if (lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))) {
7538 this.raise(this.state.lastTokEnd, "Illegal newline after throw");
7539 }
7540
7541 node.argument = this.parseExpression();
7542 this.semicolon();
7543 return this.finishNode(node, "ThrowStatement");
7544 };
7545
7546 _proto.parseTryStatement = function parseTryStatement(node) {
7547 this.next();
7548 node.block = this.parseBlock();
7549 node.handler = null;
7550
7551 if (this.match(types._catch)) {
7552 var clause = this.startNode();
7553 this.next();
7554
7555 if (this.match(types.parenL)) {
7556 this.expect(types.parenL);
7557 clause.param = this.parseBindingAtom();
7558 var clashes = Object.create(null);
7559 this.checkLVal(clause.param, true, clashes, "catch clause");
7560 this.expect(types.parenR);
7561 } else {
7562 this.expectPlugin("optionalCatchBinding");
7563 clause.param = null;
7564 }
7565
7566 clause.body = this.parseBlock();
7567 node.handler = this.finishNode(clause, "CatchClause");
7568 }
7569
7570 node.guardedHandlers = empty;
7571 node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
7572
7573 if (!node.handler && !node.finalizer) {
7574 this.raise(node.start, "Missing catch or finally clause");
7575 }
7576
7577 return this.finishNode(node, "TryStatement");
7578 };
7579
7580 _proto.parseVarStatement = function parseVarStatement(node, kind) {
7581 this.next();
7582 this.parseVar(node, false, kind);
7583 this.semicolon();
7584 return this.finishNode(node, "VariableDeclaration");
7585 };
7586
7587 _proto.parseWhileStatement = function parseWhileStatement(node) {
7588 this.next();
7589 node.test = this.parseParenExpression();
7590 this.state.labels.push(loopLabel);
7591 node.body = this.parseStatement(false);
7592 this.state.labels.pop();
7593 return this.finishNode(node, "WhileStatement");
7594 };
7595
7596 _proto.parseWithStatement = function parseWithStatement(node) {
7597 if (this.state.strict) {
7598 this.raise(this.state.start, "'with' in strict mode");
7599 }
7600
7601 this.next();
7602 node.object = this.parseParenExpression();
7603 node.body = this.parseStatement(false);
7604 return this.finishNode(node, "WithStatement");
7605 };
7606
7607 _proto.parseEmptyStatement = function parseEmptyStatement(node) {
7608 this.next();
7609 return this.finishNode(node, "EmptyStatement");
7610 };
7611
7612 _proto.parseLabeledStatement = function parseLabeledStatement(node, maybeName, expr) {
7613 for (var _i2 = 0, _this$state$labels2 = this.state.labels; _i2 < _this$state$labels2.length; _i2++) {
7614 var label = _this$state$labels2[_i2];
7615
7616 if (label.name === maybeName) {
7617 this.raise(expr.start, "Label '" + maybeName + "' is already declared");
7618 }
7619 }
7620
7621 var kind = this.state.type.isLoop ? "loop" : this.match(types._switch) ? "switch" : null;
7622
7623 for (var i = this.state.labels.length - 1; i >= 0; i--) {
7624 var _label = this.state.labels[i];
7625
7626 if (_label.statementStart === node.start) {
7627 _label.statementStart = this.state.start;
7628 _label.kind = kind;
7629 } else {
7630 break;
7631 }
7632 }
7633
7634 this.state.labels.push({
7635 name: maybeName,
7636 kind: kind,
7637 statementStart: this.state.start
7638 });
7639 node.body = this.parseStatement(true);
7640
7641 if (node.body.type == "ClassDeclaration" || node.body.type == "VariableDeclaration" && node.body.kind !== "var" || node.body.type == "FunctionDeclaration" && (this.state.strict || node.body.generator || node.body.async)) {
7642 this.raise(node.body.start, "Invalid labeled declaration");
7643 }
7644
7645 this.state.labels.pop();
7646 node.label = expr;
7647 return this.finishNode(node, "LabeledStatement");
7648 };
7649
7650 _proto.parseExpressionStatement = function parseExpressionStatement(node, expr) {
7651 node.expression = expr;
7652 this.semicolon();
7653 return this.finishNode(node, "ExpressionStatement");
7654 };
7655
7656 _proto.parseBlock = function parseBlock(allowDirectives) {
7657 var node = this.startNode();
7658 this.expect(types.braceL);
7659 this.parseBlockBody(node, allowDirectives, false, types.braceR);
7660 return this.finishNode(node, "BlockStatement");
7661 };
7662
7663 _proto.isValidDirective = function isValidDirective(stmt) {
7664 return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
7665 };
7666
7667 _proto.parseBlockBody = function parseBlockBody(node, allowDirectives, topLevel, end) {
7668 var body = node.body = [];
7669 var directives = node.directives = [];
7670 this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end);
7671 };
7672
7673 _proto.parseBlockOrModuleBlockBody = function parseBlockOrModuleBlockBody(body, directives, topLevel, end) {
7674 var parsedNonDirective = false;
7675 var oldStrict;
7676 var octalPosition;
7677
7678 while (!this.eat(end)) {
7679 if (!parsedNonDirective && this.state.containsOctal && !octalPosition) {
7680 octalPosition = this.state.octalPosition;
7681 }
7682
7683 var stmt = this.parseStatement(true, topLevel);
7684
7685 if (directives && !parsedNonDirective && this.isValidDirective(stmt)) {
7686 var directive = this.stmtToDirective(stmt);
7687 directives.push(directive);
7688
7689 if (oldStrict === undefined && directive.value.value === "use strict") {
7690 oldStrict = this.state.strict;
7691 this.setStrict(true);
7692
7693 if (octalPosition) {
7694 this.raise(octalPosition, "Octal literal in strict mode");
7695 }
7696 }
7697
7698 continue;
7699 }
7700
7701 parsedNonDirective = true;
7702 body.push(stmt);
7703 }
7704
7705 if (oldStrict === false) {
7706 this.setStrict(false);
7707 }
7708 };
7709
7710 _proto.parseFor = function parseFor(node, init) {
7711 node.init = init;
7712 this.expect(types.semi);
7713 node.test = this.match(types.semi) ? null : this.parseExpression();
7714 this.expect(types.semi);
7715 node.update = this.match(types.parenR) ? null : this.parseExpression();
7716 this.expect(types.parenR);
7717 node.body = this.parseStatement(false);
7718 this.state.labels.pop();
7719 return this.finishNode(node, "ForStatement");
7720 };
7721
7722 _proto.parseForIn = function parseForIn(node, init, forAwait) {
7723 var type = this.match(types._in) ? "ForInStatement" : "ForOfStatement";
7724
7725 if (forAwait) {
7726 this.eatContextual("of");
7727 } else {
7728 this.next();
7729 }
7730
7731 if (type === "ForOfStatement") {
7732 node.await = !!forAwait;
7733 }
7734
7735 node.left = init;
7736 node.right = this.parseExpression();
7737 this.expect(types.parenR);
7738 node.body = this.parseStatement(false);
7739 this.state.labels.pop();
7740 return this.finishNode(node, type);
7741 };
7742
7743 _proto.parseVar = function parseVar(node, isFor, kind) {
7744 var declarations = node.declarations = [];
7745 node.kind = kind.keyword;
7746
7747 for (;;) {
7748 var decl = this.startNode();
7749 this.parseVarHead(decl);
7750
7751 if (this.eat(types.eq)) {
7752 decl.init = this.parseMaybeAssign(isFor);
7753 } else {
7754 if (kind === types._const && !(this.match(types._in) || this.isContextual("of"))) {
7755 if (!this.hasPlugin("typescript")) {
7756 this.unexpected();
7757 }
7758 } else if (decl.id.type !== "Identifier" && !(isFor && (this.match(types._in) || this.isContextual("of")))) {
7759 this.raise(this.state.lastTokEnd, "Complex binding patterns require an initialization value");
7760 }
7761
7762 decl.init = null;
7763 }
7764
7765 declarations.push(this.finishNode(decl, "VariableDeclarator"));
7766 if (!this.eat(types.comma)) break;
7767 }
7768
7769 return node;
7770 };
7771
7772 _proto.parseVarHead = function parseVarHead(decl) {
7773 decl.id = this.parseBindingAtom();
7774 this.checkLVal(decl.id, true, undefined, "variable declaration");
7775 };
7776
7777 _proto.parseFunction = function parseFunction(node, isStatement, allowExpressionBody, isAsync, optionalId) {
7778 var oldInFunc = this.state.inFunction;
7779 var oldInMethod = this.state.inMethod;
7780 var oldInGenerator = this.state.inGenerator;
7781 var oldInClassProperty = this.state.inClassProperty;
7782 this.state.inFunction = true;
7783 this.state.inMethod = false;
7784 this.state.inClassProperty = false;
7785 this.initFunction(node, isAsync);
7786
7787 if (this.match(types.star)) {
7788 if (node.async) {
7789 this.expectPlugin("asyncGenerators");
7790 }
7791
7792 node.generator = true;
7793 this.next();
7794 }
7795
7796 if (isStatement && !optionalId && !this.match(types.name) && !this.match(types._yield)) {
7797 this.unexpected();
7798 }
7799
7800 if (!isStatement) this.state.inGenerator = node.generator;
7801
7802 if (this.match(types.name) || this.match(types._yield)) {
7803 node.id = this.parseBindingIdentifier();
7804 }
7805
7806 if (isStatement) this.state.inGenerator = node.generator;
7807 this.parseFunctionParams(node);
7808 this.parseFunctionBodyAndFinish(node, isStatement ? "FunctionDeclaration" : "FunctionExpression", allowExpressionBody);
7809 this.state.inFunction = oldInFunc;
7810 this.state.inMethod = oldInMethod;
7811 this.state.inGenerator = oldInGenerator;
7812 this.state.inClassProperty = oldInClassProperty;
7813 return node;
7814 };
7815
7816 _proto.parseFunctionParams = function parseFunctionParams(node, allowModifiers) {
7817 var oldInParameters = this.state.inParameters;
7818 this.state.inParameters = true;
7819 this.expect(types.parenL);
7820 node.params = this.parseBindingList(types.parenR, false, allowModifiers);
7821 this.state.inParameters = oldInParameters;
7822 };
7823
7824 _proto.parseClass = function parseClass(node, isStatement, optionalId) {
7825 this.next();
7826 this.takeDecorators(node);
7827 this.parseClassId(node, isStatement, optionalId);
7828 this.parseClassSuper(node);
7829 this.parseClassBody(node);
7830 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
7831 };
7832
7833 _proto.isClassProperty = function isClassProperty() {
7834 return this.match(types.eq) || this.match(types.semi) || this.match(types.braceR);
7835 };
7836
7837 _proto.isClassMethod = function isClassMethod() {
7838 return this.match(types.parenL);
7839 };
7840
7841 _proto.isNonstaticConstructor = function isNonstaticConstructor(method) {
7842 return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
7843 };
7844
7845 _proto.parseClassBody = function parseClassBody(node) {
7846 var oldStrict = this.state.strict;
7847 this.state.strict = true;
7848 this.state.classLevel++;
7849 var state = {
7850 hadConstructor: false
7851 };
7852 var decorators = [];
7853 var classBody = this.startNode();
7854 classBody.body = [];
7855 this.expect(types.braceL);
7856
7857 while (!this.eat(types.braceR)) {
7858 if (this.eat(types.semi)) {
7859 if (decorators.length > 0) {
7860 this.raise(this.state.lastTokEnd, "Decorators must not be followed by a semicolon");
7861 }
7862
7863 continue;
7864 }
7865
7866 if (this.match(types.at)) {
7867 decorators.push(this.parseDecorator());
7868 continue;
7869 }
7870
7871 var member = this.startNode();
7872
7873 if (decorators.length) {
7874 member.decorators = decorators;
7875 this.resetStartLocationFromNode(member, decorators[0]);
7876 decorators = [];
7877 }
7878
7879 this.parseClassMember(classBody, member, state);
7880
7881 if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
7882 this.raise(member.start, "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?");
7883 }
7884 }
7885
7886 if (decorators.length) {
7887 this.raise(this.state.start, "You have trailing decorators with no method");
7888 }
7889
7890 node.body = this.finishNode(classBody, "ClassBody");
7891 this.state.classLevel--;
7892 this.state.strict = oldStrict;
7893 };
7894
7895 _proto.parseClassMember = function parseClassMember(classBody, member, state) {
7896 var isStatic = false;
7897 var containsEsc = this.state.containsEsc;
7898
7899 if (this.match(types.name) && this.state.value === "static") {
7900 var key = this.parseIdentifier(true);
7901
7902 if (this.isClassMethod()) {
7903 var method = member;
7904 method.kind = "method";
7905 method.computed = false;
7906 method.key = key;
7907 method.static = false;
7908 this.pushClassMethod(classBody, method, false, false, false);
7909 return;
7910 } else if (this.isClassProperty()) {
7911 var prop = member;
7912 prop.computed = false;
7913 prop.key = key;
7914 prop.static = false;
7915 classBody.body.push(this.parseClassProperty(prop));
7916 return;
7917 } else if (containsEsc) {
7918 throw this.unexpected();
7919 }
7920
7921 isStatic = true;
7922 }
7923
7924 this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
7925 };
7926
7927 _proto.parseClassMemberWithIsStatic = function parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
7928 var publicMethod = member;
7929 var privateMethod = member;
7930 var publicProp = member;
7931 var privateProp = member;
7932 var method = publicMethod;
7933 var publicMember = publicMethod;
7934 member.static = isStatic;
7935
7936 if (this.eat(types.star)) {
7937 method.kind = "method";
7938 this.parseClassPropertyName(method);
7939
7940 if (method.key.type === "PrivateName") {
7941 this.pushClassPrivateMethod(classBody, privateMethod, true, false);
7942 return;
7943 }
7944
7945 if (this.isNonstaticConstructor(publicMethod)) {
7946 this.raise(publicMethod.key.start, "Constructor can't be a generator");
7947 }
7948
7949 this.pushClassMethod(classBody, publicMethod, true, false, false);
7950 return;
7951 }
7952
7953 var key = this.parseClassPropertyName(member);
7954 var isPrivate = key.type === "PrivateName";
7955 var isSimple = key.type === "Identifier";
7956 this.parsePostMemberNameModifiers(publicMember);
7957
7958 if (this.isClassMethod()) {
7959 method.kind = "method";
7960
7961 if (isPrivate) {
7962 this.pushClassPrivateMethod(classBody, privateMethod, false, false);
7963 return;
7964 }
7965
7966 var isConstructor = this.isNonstaticConstructor(publicMethod);
7967
7968 if (isConstructor) {
7969 publicMethod.kind = "constructor";
7970
7971 if (publicMethod.decorators) {
7972 this.raise(publicMethod.start, "You can't attach decorators to a class constructor");
7973 }
7974
7975 if (state.hadConstructor && !this.hasPlugin("typescript")) {
7976 this.raise(key.start, "Duplicate constructor in the same class");
7977 }
7978
7979 state.hadConstructor = true;
7980 }
7981
7982 this.pushClassMethod(classBody, publicMethod, false, false, isConstructor);
7983 } else if (this.isClassProperty()) {
7984 if (isPrivate) {
7985 this.pushClassPrivateProperty(classBody, privateProp);
7986 } else {
7987 this.pushClassProperty(classBody, publicProp);
7988 }
7989 } else if (isSimple && key.name === "async" && !this.isLineTerminator()) {
7990 var isGenerator = this.match(types.star);
7991
7992 if (isGenerator) {
7993 this.expectPlugin("asyncGenerators");
7994 this.next();
7995 }
7996
7997 method.kind = "method";
7998 this.parseClassPropertyName(method);
7999
8000 if (method.key.type === "PrivateName") {
8001 this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
8002 } else {
8003 if (this.isNonstaticConstructor(publicMethod)) {
8004 this.raise(publicMethod.key.start, "Constructor can't be an async function");
8005 }
8006
8007 this.pushClassMethod(classBody, publicMethod, isGenerator, true, false);
8008 }
8009 } else if (isSimple && (key.name === "get" || key.name === "set") && !(this.isLineTerminator() && this.match(types.star))) {
8010 method.kind = key.name;
8011 this.parseClassPropertyName(publicMethod);
8012
8013 if (method.key.type === "PrivateName") {
8014 this.pushClassPrivateMethod(classBody, privateMethod, false, false);
8015 } else {
8016 if (this.isNonstaticConstructor(publicMethod)) {
8017 this.raise(publicMethod.key.start, "Constructor can't have get/set modifier");
8018 }
8019
8020 this.pushClassMethod(classBody, publicMethod, false, false, false);
8021 }
8022
8023 this.checkGetterSetterParams(publicMethod);
8024 } else if (this.isLineTerminator()) {
8025 if (isPrivate) {
8026 this.pushClassPrivateProperty(classBody, privateProp);
8027 } else {
8028 this.pushClassProperty(classBody, publicProp);
8029 }
8030 } else {
8031 this.unexpected();
8032 }
8033 };
8034
8035 _proto.parseClassPropertyName = function parseClassPropertyName(member) {
8036 var key = this.parsePropertyName(member);
8037
8038 if (!member.computed && member.static && (key.name === "prototype" || key.value === "prototype")) {
8039 this.raise(key.start, "Classes may not have static property named prototype");
8040 }
8041
8042 if (key.type === "PrivateName" && key.id.name === "constructor") {
8043 this.raise(key.start, "Classes may not have a private field named '#constructor'");
8044 }
8045
8046 return key;
8047 };
8048
8049 _proto.pushClassProperty = function pushClassProperty(classBody, prop) {
8050 if (this.isNonstaticConstructor(prop)) {
8051 this.raise(prop.key.start, "Classes may not have a non-static field named 'constructor'");
8052 }
8053
8054 classBody.body.push(this.parseClassProperty(prop));
8055 };
8056
8057 _proto.pushClassPrivateProperty = function pushClassPrivateProperty(classBody, prop) {
8058 this.expectPlugin("classPrivateProperties", prop.key.start);
8059 classBody.body.push(this.parseClassPrivateProperty(prop));
8060 };
8061
8062 _proto.pushClassMethod = function pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) {
8063 classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, "ClassMethod"));
8064 };
8065
8066 _proto.pushClassPrivateMethod = function pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
8067 this.expectPlugin("classPrivateMethods", method.key.start);
8068 classBody.body.push(this.parseMethod(method, isGenerator, isAsync, false, "ClassPrivateMethod"));
8069 };
8070
8071 _proto.parsePostMemberNameModifiers = function parsePostMemberNameModifiers(methodOrProp) {};
8072
8073 _proto.parseAccessModifier = function parseAccessModifier() {
8074 return undefined;
8075 };
8076
8077 _proto.parseClassPrivateProperty = function parseClassPrivateProperty(node) {
8078 var oldInMethod = this.state.inMethod;
8079 this.state.inMethod = false;
8080 this.state.inClassProperty = true;
8081 node.value = this.eat(types.eq) ? this.parseMaybeAssign() : null;
8082 this.semicolon();
8083 this.state.inClassProperty = false;
8084 this.state.inMethod = oldInMethod;
8085 return this.finishNode(node, "ClassPrivateProperty");
8086 };
8087
8088 _proto.parseClassProperty = function parseClassProperty(node) {
8089 if (!node.typeAnnotation) {
8090 this.expectPlugin("classProperties");
8091 }
8092
8093 var oldInMethod = this.state.inMethod;
8094 this.state.inMethod = false;
8095 this.state.inClassProperty = true;
8096
8097 if (this.match(types.eq)) {
8098 this.expectPlugin("classProperties");
8099 this.next();
8100 node.value = this.parseMaybeAssign();
8101 } else {
8102 node.value = null;
8103 }
8104
8105 this.semicolon();
8106 this.state.inClassProperty = false;
8107 this.state.inMethod = oldInMethod;
8108 return this.finishNode(node, "ClassProperty");
8109 };
8110
8111 _proto.parseClassId = function parseClassId(node, isStatement, optionalId) {
8112 if (this.match(types.name)) {
8113 node.id = this.parseIdentifier();
8114 } else {
8115 if (optionalId || !isStatement) {
8116 node.id = null;
8117 } else {
8118 this.unexpected(null, "A class name is required");
8119 }
8120 }
8121 };
8122
8123 _proto.parseClassSuper = function parseClassSuper(node) {
8124 node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
8125 };
8126
8127 _proto.parseExport = function parseExport(node) {
8128 if (this.shouldParseExportStar()) {
8129 this.parseExportStar(node);
8130 if (node.type === "ExportAllDeclaration") return node;
8131 } else if (this.isExportDefaultSpecifier()) {
8132 this.expectPlugin("exportDefaultFrom");
8133 var specifier = this.startNode();
8134 specifier.exported = this.parseIdentifier(true);
8135 var specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
8136 node.specifiers = specifiers;
8137
8138 if (this.match(types.comma) && this.lookahead().type === types.star) {
8139 this.expect(types.comma);
8140
8141 var _specifier = this.startNode();
8142
8143 this.expect(types.star);
8144 this.expectContextual("as");
8145 _specifier.exported = this.parseIdentifier();
8146 specifiers.push(this.finishNode(_specifier, "ExportNamespaceSpecifier"));
8147 } else {
8148 this.parseExportSpecifiersMaybe(node);
8149 }
8150
8151 this.parseExportFrom(node, true);
8152 } else if (this.eat(types._default)) {
8153 node.declaration = this.parseExportDefaultExpression();
8154 this.checkExport(node, true, true);
8155 return this.finishNode(node, "ExportDefaultDeclaration");
8156 } else if (this.shouldParseExportDeclaration()) {
8157 if (this.isContextual("async")) {
8158 var next = this.lookahead();
8159
8160 if (next.type !== types._function) {
8161 this.unexpected(next.start, "Unexpected token, expected \"function\"");
8162 }
8163 }
8164
8165 node.specifiers = [];
8166 node.source = null;
8167 node.declaration = this.parseExportDeclaration(node);
8168 } else {
8169 node.declaration = null;
8170 node.specifiers = this.parseExportSpecifiers();
8171 this.parseExportFrom(node);
8172 }
8173
8174 this.checkExport(node, true);
8175 return this.finishNode(node, "ExportNamedDeclaration");
8176 };
8177
8178 _proto.parseExportDefaultExpression = function parseExportDefaultExpression() {
8179 var expr = this.startNode();
8180
8181 if (this.eat(types._function)) {
8182 return this.parseFunction(expr, true, false, false, true);
8183 } else if (this.isContextual("async") && this.lookahead().type === types._function) {
8184 this.eatContextual("async");
8185 this.eat(types._function);
8186 return this.parseFunction(expr, true, false, true, true);
8187 } else if (this.match(types._class)) {
8188 return this.parseClass(expr, true, true);
8189 } else if (this.match(types.at)) {
8190 if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport")) {
8191 this.unexpected(this.state.start, "Decorators must be placed *before* the 'export' keyword." + " You can set the 'decoratorsBeforeExport' option to false to use" + " the 'export @decorator class {}' syntax");
8192 }
8193
8194 this.parseDecorators(false);
8195 return this.parseClass(expr, true, true);
8196 } else if (this.match(types._let) || this.match(types._const) || this.match(types._var)) {
8197 return this.raise(this.state.start, "Only expressions, functions or classes are allowed as the `default` export.");
8198 } else {
8199 var res = this.parseMaybeAssign();
8200 this.semicolon();
8201 return res;
8202 }
8203 };
8204
8205 _proto.parseExportDeclaration = function parseExportDeclaration(node) {
8206 return this.parseStatement(true);
8207 };
8208
8209 _proto.isExportDefaultSpecifier = function isExportDefaultSpecifier() {
8210 if (this.match(types.name)) {
8211 return this.state.value !== "async";
8212 }
8213
8214 if (!this.match(types._default)) {
8215 return false;
8216 }
8217
8218 var lookahead = this.lookahead();
8219 return lookahead.type === types.comma || lookahead.type === types.name && lookahead.value === "from";
8220 };
8221
8222 _proto.parseExportSpecifiersMaybe = function parseExportSpecifiersMaybe(node) {
8223 if (this.eat(types.comma)) {
8224 node.specifiers = node.specifiers.concat(this.parseExportSpecifiers());
8225 }
8226 };
8227
8228 _proto.parseExportFrom = function parseExportFrom(node, expect) {
8229 if (this.eatContextual("from")) {
8230 node.source = this.match(types.string) ? this.parseExprAtom() : this.unexpected();
8231 this.checkExport(node);
8232 } else {
8233 if (expect) {
8234 this.unexpected();
8235 } else {
8236 node.source = null;
8237 }
8238 }
8239
8240 this.semicolon();
8241 };
8242
8243 _proto.shouldParseExportStar = function shouldParseExportStar() {
8244 return this.match(types.star);
8245 };
8246
8247 _proto.parseExportStar = function parseExportStar(node) {
8248 this.expect(types.star);
8249
8250 if (this.isContextual("as")) {
8251 this.parseExportNamespace(node);
8252 } else {
8253 this.parseExportFrom(node, true);
8254 this.finishNode(node, "ExportAllDeclaration");
8255 }
8256 };
8257
8258 _proto.parseExportNamespace = function parseExportNamespace(node) {
8259 this.expectPlugin("exportNamespaceFrom");
8260 var specifier = this.startNodeAt(this.state.lastTokStart, this.state.lastTokStartLoc);
8261 this.next();
8262 specifier.exported = this.parseIdentifier(true);
8263 node.specifiers = [this.finishNode(specifier, "ExportNamespaceSpecifier")];
8264 this.parseExportSpecifiersMaybe(node);
8265 this.parseExportFrom(node, true);
8266 };
8267
8268 _proto.shouldParseExportDeclaration = function shouldParseExportDeclaration() {
8269 if (this.match(types.at)) {
8270 this.expectOnePlugin(["decorators", "decorators-legacy"]);
8271
8272 if (this.hasPlugin("decorators")) {
8273 if (this.getPluginOption("decorators", "decoratorsBeforeExport")) {
8274 this.unexpected(this.state.start, "Decorators must be placed *before* the 'export' keyword." + " You can set the 'decoratorsBeforeExport' option to false to use" + " the 'export @decorator class {}' syntax");
8275 } else {
8276 return true;
8277 }
8278 }
8279 }
8280
8281 return this.state.type.keyword === "var" || this.state.type.keyword === "const" || this.state.type.keyword === "let" || this.state.type.keyword === "function" || this.state.type.keyword === "class" || this.isContextual("async");
8282 };
8283
8284 _proto.checkExport = function checkExport(node, checkNames, isDefault) {
8285 if (checkNames) {
8286 if (isDefault) {
8287 this.checkDuplicateExports(node, "default");
8288 } else if (node.specifiers && node.specifiers.length) {
8289 for (var _i4 = 0, _node$specifiers2 = node.specifiers; _i4 < _node$specifiers2.length; _i4++) {
8290 var specifier = _node$specifiers2[_i4];
8291 this.checkDuplicateExports(specifier, specifier.exported.name);
8292 }
8293 } else if (node.declaration) {
8294 if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
8295 var id = node.declaration.id;
8296 if (!id) throw new Error("Assertion failure");
8297 this.checkDuplicateExports(node, id.name);
8298 } else if (node.declaration.type === "VariableDeclaration") {
8299 for (var _i6 = 0, _node$declaration$dec2 = node.declaration.declarations; _i6 < _node$declaration$dec2.length; _i6++) {
8300 var declaration = _node$declaration$dec2[_i6];
8301 this.checkDeclaration(declaration.id);
8302 }
8303 }
8304 }
8305 }
8306
8307 var currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1];
8308
8309 if (currentContextDecorators.length) {
8310 var isClass = node.declaration && (node.declaration.type === "ClassDeclaration" || node.declaration.type === "ClassExpression");
8311
8312 if (!node.declaration || !isClass) {
8313 throw this.raise(node.start, "You can only use decorators on an export when exporting a class");
8314 }
8315
8316 this.takeDecorators(node.declaration);
8317 }
8318 };
8319
8320 _proto.checkDeclaration = function checkDeclaration(node) {
8321 if (node.type === "ObjectPattern") {
8322 for (var _i8 = 0, _node$properties2 = node.properties; _i8 < _node$properties2.length; _i8++) {
8323 var prop = _node$properties2[_i8];
8324 this.checkDeclaration(prop);
8325 }
8326 } else if (node.type === "ArrayPattern") {
8327 for (var _i10 = 0, _node$elements2 = node.elements; _i10 < _node$elements2.length; _i10++) {
8328 var elem = _node$elements2[_i10];
8329
8330 if (elem) {
8331 this.checkDeclaration(elem);
8332 }
8333 }
8334 } else if (node.type === "ObjectProperty") {
8335 this.checkDeclaration(node.value);
8336 } else if (node.type === "RestElement") {
8337 this.checkDeclaration(node.argument);
8338 } else if (node.type === "Identifier") {
8339 this.checkDuplicateExports(node, node.name);
8340 }
8341 };
8342
8343 _proto.checkDuplicateExports = function checkDuplicateExports(node, name) {
8344 if (this.state.exportedIdentifiers.indexOf(name) > -1) {
8345 this.raiseDuplicateExportError(node, name);
8346 }
8347
8348 this.state.exportedIdentifiers.push(name);
8349 };
8350
8351 _proto.raiseDuplicateExportError = function raiseDuplicateExportError(node, name) {
8352 throw this.raise(node.start, name === "default" ? "Only one default export allowed per module." : "`" + name + "` has already been exported. Exported identifiers must be unique.");
8353 };
8354
8355 _proto.parseExportSpecifiers = function parseExportSpecifiers() {
8356 var nodes = [];
8357 var first = true;
8358 var needsFrom;
8359 this.expect(types.braceL);
8360
8361 while (!this.eat(types.braceR)) {
8362 if (first) {
8363 first = false;
8364 } else {
8365 this.expect(types.comma);
8366 if (this.eat(types.braceR)) break;
8367 }
8368
8369 var isDefault = this.match(types._default);
8370 if (isDefault && !needsFrom) needsFrom = true;
8371 var node = this.startNode();
8372 node.local = this.parseIdentifier(isDefault);
8373 node.exported = this.eatContextual("as") ? this.parseIdentifier(true) : node.local.__clone();
8374 nodes.push(this.finishNode(node, "ExportSpecifier"));
8375 }
8376
8377 if (needsFrom && !this.isContextual("from")) {
8378 this.unexpected();
8379 }
8380
8381 return nodes;
8382 };
8383
8384 _proto.parseImport = function parseImport(node) {
8385 if (this.match(types.string)) {
8386 node.specifiers = [];
8387 node.source = this.parseExprAtom();
8388 } else {
8389 node.specifiers = [];
8390 this.parseImportSpecifiers(node);
8391 this.expectContextual("from");
8392 node.source = this.match(types.string) ? this.parseExprAtom() : this.unexpected();
8393 }
8394
8395 this.semicolon();
8396 return this.finishNode(node, "ImportDeclaration");
8397 };
8398
8399 _proto.shouldParseDefaultImport = function shouldParseDefaultImport(node) {
8400 return this.match(types.name);
8401 };
8402
8403 _proto.parseImportSpecifierLocal = function parseImportSpecifierLocal(node, specifier, type, contextDescription) {
8404 specifier.local = this.parseIdentifier();
8405 this.checkLVal(specifier.local, true, undefined, contextDescription);
8406 node.specifiers.push(this.finishNode(specifier, type));
8407 };
8408
8409 _proto.parseImportSpecifiers = function parseImportSpecifiers(node) {
8410 var first = true;
8411
8412 if (this.shouldParseDefaultImport(node)) {
8413 this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier", "default import specifier");
8414 if (!this.eat(types.comma)) return;
8415 }
8416
8417 if (this.match(types.star)) {
8418 var specifier = this.startNode();
8419 this.next();
8420 this.expectContextual("as");
8421 this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier", "import namespace specifier");
8422 return;
8423 }
8424
8425 this.expect(types.braceL);
8426
8427 while (!this.eat(types.braceR)) {
8428 if (first) {
8429 first = false;
8430 } else {
8431 if (this.eat(types.colon)) {
8432 this.unexpected(null, "ES2015 named imports do not destructure. " + "Use another statement for destructuring after the import.");
8433 }
8434
8435 this.expect(types.comma);
8436 if (this.eat(types.braceR)) break;
8437 }
8438
8439 this.parseImportSpecifier(node);
8440 }
8441 };
8442
8443 _proto.parseImportSpecifier = function parseImportSpecifier(node) {
8444 var specifier = this.startNode();
8445 specifier.imported = this.parseIdentifier(true);
8446
8447 if (this.eatContextual("as")) {
8448 specifier.local = this.parseIdentifier();
8449 } else {
8450 this.checkReservedWord(specifier.imported.name, specifier.start, true, true);
8451 specifier.local = specifier.imported.__clone();
8452 }
8453
8454 this.checkLVal(specifier.local, true, undefined, "import specifier");
8455 node.specifiers.push(this.finishNode(specifier, "ImportSpecifier"));
8456 };
8457
8458 return StatementParser;
8459}(ExpressionParser);
8460
8461var Parser = function (_StatementParser) {
8462 _inheritsLoose(Parser, _StatementParser);
8463
8464 function Parser(options, input) {
8465 var _this;
8466
8467 options = getOptions(options);
8468 _this = _StatementParser.call(this, options, input) || this;
8469 _this.options = options;
8470 _this.inModule = _this.options.sourceType === "module";
8471 _this.input = input;
8472 _this.plugins = pluginsMap(_this.options.plugins);
8473 _this.filename = options.sourceFilename;
8474 return _this;
8475 }
8476
8477 var _proto = Parser.prototype;
8478
8479 _proto.parse = function parse() {
8480 var file = this.startNode();
8481 var program = this.startNode();
8482 this.nextToken();
8483 return this.parseTopLevel(file, program);
8484 };
8485
8486 return Parser;
8487}(StatementParser);
8488
8489function pluginsMap(plugins) {
8490 var pluginMap = Object.create(null);
8491
8492 for (var _i2 = 0; _i2 < plugins.length; _i2++) {
8493 var plugin = plugins[_i2];
8494
8495 var _ref = Array.isArray(plugin) ? plugin : [plugin, {}],
8496 name = _ref[0],
8497 _ref$ = _ref[1],
8498 options = _ref$ === void 0 ? {} : _ref$;
8499
8500 if (!pluginMap[name]) pluginMap[name] = options || {};
8501 }
8502
8503 return pluginMap;
8504}
8505
8506function nonNull(x) {
8507 if (x == null) {
8508 throw new Error("Unexpected " + x + " value.");
8509 }
8510
8511 return x;
8512}
8513
8514function assert(x) {
8515 if (!x) {
8516 throw new Error("Assert fail");
8517 }
8518}
8519
8520function keywordTypeFromName(value) {
8521 switch (value) {
8522 case "any":
8523 return "TSAnyKeyword";
8524
8525 case "boolean":
8526 return "TSBooleanKeyword";
8527
8528 case "never":
8529 return "TSNeverKeyword";
8530
8531 case "number":
8532 return "TSNumberKeyword";
8533
8534 case "object":
8535 return "TSObjectKeyword";
8536
8537 case "string":
8538 return "TSStringKeyword";
8539
8540 case "symbol":
8541 return "TSSymbolKeyword";
8542
8543 case "undefined":
8544 return "TSUndefinedKeyword";
8545
8546 default:
8547 return undefined;
8548 }
8549}
8550
8551var typescript = (function (superClass) {
8552 return function (_superClass) {
8553 _inheritsLoose(_class, _superClass);
8554
8555 function _class() {
8556 return _superClass.apply(this, arguments) || this;
8557 }
8558
8559 var _proto = _class.prototype;
8560
8561 _proto.tsIsIdentifier = function tsIsIdentifier() {
8562 return this.match(types.name);
8563 };
8564
8565 _proto.tsNextTokenCanFollowModifier = function tsNextTokenCanFollowModifier() {
8566 this.next();
8567 return !this.hasPrecedingLineBreak() && !this.match(types.parenL) && !this.match(types.parenR) && !this.match(types.colon) && !this.match(types.eq) && !this.match(types.question);
8568 };
8569
8570 _proto.tsParseModifier = function tsParseModifier(allowedModifiers) {
8571 if (!this.match(types.name)) {
8572 return undefined;
8573 }
8574
8575 var modifier = this.state.value;
8576
8577 if (allowedModifiers.indexOf(modifier) !== -1 && this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
8578 return modifier;
8579 }
8580
8581 return undefined;
8582 };
8583
8584 _proto.tsIsListTerminator = function tsIsListTerminator(kind) {
8585 switch (kind) {
8586 case "EnumMembers":
8587 case "TypeMembers":
8588 return this.match(types.braceR);
8589
8590 case "HeritageClauseElement":
8591 return this.match(types.braceL);
8592
8593 case "TupleElementTypes":
8594 return this.match(types.bracketR);
8595
8596 case "TypeParametersOrArguments":
8597 return this.isRelational(">");
8598 }
8599
8600 throw new Error("Unreachable");
8601 };
8602
8603 _proto.tsParseList = function tsParseList(kind, parseElement) {
8604 var result = [];
8605
8606 while (!this.tsIsListTerminator(kind)) {
8607 result.push(parseElement());
8608 }
8609
8610 return result;
8611 };
8612
8613 _proto.tsParseDelimitedList = function tsParseDelimitedList(kind, parseElement) {
8614 return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true));
8615 };
8616
8617 _proto.tsTryParseDelimitedList = function tsTryParseDelimitedList(kind, parseElement) {
8618 return this.tsParseDelimitedListWorker(kind, parseElement, false);
8619 };
8620
8621 _proto.tsParseDelimitedListWorker = function tsParseDelimitedListWorker(kind, parseElement, expectSuccess) {
8622 var result = [];
8623
8624 while (true) {
8625 if (this.tsIsListTerminator(kind)) {
8626 break;
8627 }
8628
8629 var element = parseElement();
8630
8631 if (element == null) {
8632 return undefined;
8633 }
8634
8635 result.push(element);
8636
8637 if (this.eat(types.comma)) {
8638 continue;
8639 }
8640
8641 if (this.tsIsListTerminator(kind)) {
8642 break;
8643 }
8644
8645 if (expectSuccess) {
8646 this.expect(types.comma);
8647 }
8648
8649 return undefined;
8650 }
8651
8652 return result;
8653 };
8654
8655 _proto.tsParseBracketedList = function tsParseBracketedList(kind, parseElement, bracket, skipFirstToken) {
8656 if (!skipFirstToken) {
8657 if (bracket) {
8658 this.expect(types.bracketL);
8659 } else {
8660 this.expectRelational("<");
8661 }
8662 }
8663
8664 var result = this.tsParseDelimitedList(kind, parseElement);
8665
8666 if (bracket) {
8667 this.expect(types.bracketR);
8668 } else {
8669 this.expectRelational(">");
8670 }
8671
8672 return result;
8673 };
8674
8675 _proto.tsParseEntityName = function tsParseEntityName(allowReservedWords) {
8676 var entity = this.parseIdentifier();
8677
8678 while (this.eat(types.dot)) {
8679 var node = this.startNodeAtNode(entity);
8680 node.left = entity;
8681 node.right = this.parseIdentifier(allowReservedWords);
8682 entity = this.finishNode(node, "TSQualifiedName");
8683 }
8684
8685 return entity;
8686 };
8687
8688 _proto.tsParseTypeReference = function tsParseTypeReference() {
8689 var node = this.startNode();
8690 node.typeName = this.tsParseEntityName(false);
8691
8692 if (!this.hasPrecedingLineBreak() && this.isRelational("<")) {
8693 node.typeParameters = this.tsParseTypeArguments();
8694 }
8695
8696 return this.finishNode(node, "TSTypeReference");
8697 };
8698
8699 _proto.tsParseThisTypePredicate = function tsParseThisTypePredicate(lhs) {
8700 this.next();
8701 var node = this.startNode();
8702 node.parameterName = lhs;
8703 node.typeAnnotation = this.tsParseTypeAnnotation(false);
8704 return this.finishNode(node, "TSTypePredicate");
8705 };
8706
8707 _proto.tsParseThisTypeNode = function tsParseThisTypeNode() {
8708 var node = this.startNode();
8709 this.next();
8710 return this.finishNode(node, "TSThisType");
8711 };
8712
8713 _proto.tsParseTypeQuery = function tsParseTypeQuery() {
8714 var node = this.startNode();
8715 this.expect(types._typeof);
8716 node.exprName = this.tsParseEntityName(true);
8717 return this.finishNode(node, "TSTypeQuery");
8718 };
8719
8720 _proto.tsParseTypeParameter = function tsParseTypeParameter() {
8721 var node = this.startNode();
8722 node.name = this.parseIdentifierName(node.start);
8723 node.constraint = this.tsEatThenParseType(types._extends);
8724 node.default = this.tsEatThenParseType(types.eq);
8725 return this.finishNode(node, "TSTypeParameter");
8726 };
8727
8728 _proto.tsTryParseTypeParameters = function tsTryParseTypeParameters() {
8729 if (this.isRelational("<")) {
8730 return this.tsParseTypeParameters();
8731 }
8732 };
8733
8734 _proto.tsParseTypeParameters = function tsParseTypeParameters() {
8735 var node = this.startNode();
8736
8737 if (this.isRelational("<") || this.match(types.jsxTagStart)) {
8738 this.next();
8739 } else {
8740 this.unexpected();
8741 }
8742
8743 node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this), false, true);
8744 return this.finishNode(node, "TSTypeParameterDeclaration");
8745 };
8746
8747 _proto.tsFillSignature = function tsFillSignature(returnToken, signature) {
8748 var returnTokenRequired = returnToken === types.arrow;
8749 signature.typeParameters = this.tsTryParseTypeParameters();
8750 this.expect(types.parenL);
8751 signature.parameters = this.tsParseBindingListForSignature();
8752
8753 if (returnTokenRequired) {
8754 signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
8755 } else if (this.match(returnToken)) {
8756 signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
8757 }
8758 };
8759
8760 _proto.tsParseBindingListForSignature = function tsParseBindingListForSignature() {
8761 var _this = this;
8762
8763 return this.parseBindingList(types.parenR).map(function (pattern) {
8764 if (pattern.type !== "Identifier" && pattern.type !== "RestElement") {
8765 throw _this.unexpected(pattern.start, "Name in a signature must be an Identifier.");
8766 }
8767
8768 return pattern;
8769 });
8770 };
8771
8772 _proto.tsParseTypeMemberSemicolon = function tsParseTypeMemberSemicolon() {
8773 if (!this.eat(types.comma)) {
8774 this.semicolon();
8775 }
8776 };
8777
8778 _proto.tsParseSignatureMember = function tsParseSignatureMember(kind) {
8779 var node = this.startNode();
8780
8781 if (kind === "TSConstructSignatureDeclaration") {
8782 this.expect(types._new);
8783 }
8784
8785 this.tsFillSignature(types.colon, node);
8786 this.tsParseTypeMemberSemicolon();
8787 return this.finishNode(node, kind);
8788 };
8789
8790 _proto.tsIsUnambiguouslyIndexSignature = function tsIsUnambiguouslyIndexSignature() {
8791 this.next();
8792 return this.eat(types.name) && this.match(types.colon);
8793 };
8794
8795 _proto.tsTryParseIndexSignature = function tsTryParseIndexSignature(node) {
8796 if (!(this.match(types.bracketL) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
8797 return undefined;
8798 }
8799
8800 this.expect(types.bracketL);
8801 var id = this.parseIdentifier();
8802 this.expect(types.colon);
8803 id.typeAnnotation = this.tsParseTypeAnnotation(false);
8804 this.expect(types.bracketR);
8805 node.parameters = [id];
8806 var type = this.tsTryParseTypeAnnotation();
8807 if (type) node.typeAnnotation = type;
8808 this.tsParseTypeMemberSemicolon();
8809 return this.finishNode(node, "TSIndexSignature");
8810 };
8811
8812 _proto.tsParsePropertyOrMethodSignature = function tsParsePropertyOrMethodSignature(node, readonly) {
8813 this.parsePropertyName(node);
8814 if (this.eat(types.question)) node.optional = true;
8815 var nodeAny = node;
8816
8817 if (!readonly && (this.match(types.parenL) || this.isRelational("<"))) {
8818 var method = nodeAny;
8819 this.tsFillSignature(types.colon, method);
8820 this.tsParseTypeMemberSemicolon();
8821 return this.finishNode(method, "TSMethodSignature");
8822 } else {
8823 var property = nodeAny;
8824 if (readonly) property.readonly = true;
8825 var type = this.tsTryParseTypeAnnotation();
8826 if (type) property.typeAnnotation = type;
8827 this.tsParseTypeMemberSemicolon();
8828 return this.finishNode(property, "TSPropertySignature");
8829 }
8830 };
8831
8832 _proto.tsParseTypeMember = function tsParseTypeMember() {
8833 if (this.match(types.parenL) || this.isRelational("<")) {
8834 return this.tsParseSignatureMember("TSCallSignatureDeclaration");
8835 }
8836
8837 if (this.match(types._new) && this.tsLookAhead(this.tsIsStartOfConstructSignature.bind(this))) {
8838 return this.tsParseSignatureMember("TSConstructSignatureDeclaration");
8839 }
8840
8841 var node = this.startNode();
8842 var readonly = !!this.tsParseModifier(["readonly"]);
8843 var idx = this.tsTryParseIndexSignature(node);
8844
8845 if (idx) {
8846 if (readonly) node.readonly = true;
8847 return idx;
8848 }
8849
8850 return this.tsParsePropertyOrMethodSignature(node, readonly);
8851 };
8852
8853 _proto.tsIsStartOfConstructSignature = function tsIsStartOfConstructSignature() {
8854 this.next();
8855 return this.match(types.parenL) || this.isRelational("<");
8856 };
8857
8858 _proto.tsParseTypeLiteral = function tsParseTypeLiteral() {
8859 var node = this.startNode();
8860 node.members = this.tsParseObjectTypeMembers();
8861 return this.finishNode(node, "TSTypeLiteral");
8862 };
8863
8864 _proto.tsParseObjectTypeMembers = function tsParseObjectTypeMembers() {
8865 this.expect(types.braceL);
8866 var members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
8867 this.expect(types.braceR);
8868 return members;
8869 };
8870
8871 _proto.tsIsStartOfMappedType = function tsIsStartOfMappedType() {
8872 this.next();
8873
8874 if (this.eat(types.plusMin)) {
8875 return this.isContextual("readonly");
8876 }
8877
8878 if (this.isContextual("readonly")) {
8879 this.next();
8880 }
8881
8882 if (!this.match(types.bracketL)) {
8883 return false;
8884 }
8885
8886 this.next();
8887
8888 if (!this.tsIsIdentifier()) {
8889 return false;
8890 }
8891
8892 this.next();
8893 return this.match(types._in);
8894 };
8895
8896 _proto.tsParseMappedTypeParameter = function tsParseMappedTypeParameter() {
8897 var node = this.startNode();
8898 node.name = this.parseIdentifierName(node.start);
8899 node.constraint = this.tsExpectThenParseType(types._in);
8900 return this.finishNode(node, "TSTypeParameter");
8901 };
8902
8903 _proto.tsParseMappedType = function tsParseMappedType() {
8904 var node = this.startNode();
8905 this.expect(types.braceL);
8906
8907 if (this.match(types.plusMin)) {
8908 node.readonly = this.state.value;
8909 this.next();
8910 this.expectContextual("readonly");
8911 } else if (this.eatContextual("readonly")) {
8912 node.readonly = true;
8913 }
8914
8915 this.expect(types.bracketL);
8916 node.typeParameter = this.tsParseMappedTypeParameter();
8917 this.expect(types.bracketR);
8918
8919 if (this.match(types.plusMin)) {
8920 node.optional = this.state.value;
8921 this.next();
8922 this.expect(types.question);
8923 } else if (this.eat(types.question)) {
8924 node.optional = true;
8925 }
8926
8927 node.typeAnnotation = this.tsTryParseType();
8928 this.semicolon();
8929 this.expect(types.braceR);
8930 return this.finishNode(node, "TSMappedType");
8931 };
8932
8933 _proto.tsParseTupleType = function tsParseTupleType() {
8934 var node = this.startNode();
8935 node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseType.bind(this), true, false);
8936 return this.finishNode(node, "TSTupleType");
8937 };
8938
8939 _proto.tsParseParenthesizedType = function tsParseParenthesizedType() {
8940 var node = this.startNode();
8941 this.expect(types.parenL);
8942 node.typeAnnotation = this.tsParseType();
8943 this.expect(types.parenR);
8944 return this.finishNode(node, "TSParenthesizedType");
8945 };
8946
8947 _proto.tsParseFunctionOrConstructorType = function tsParseFunctionOrConstructorType(type) {
8948 var node = this.startNode();
8949
8950 if (type === "TSConstructorType") {
8951 this.expect(types._new);
8952 }
8953
8954 this.tsFillSignature(types.arrow, node);
8955 return this.finishNode(node, type);
8956 };
8957
8958 _proto.tsParseLiteralTypeNode = function tsParseLiteralTypeNode() {
8959 var _this2 = this;
8960
8961 var node = this.startNode();
8962
8963 node.literal = function () {
8964 switch (_this2.state.type) {
8965 case types.num:
8966 return _this2.parseLiteral(_this2.state.value, "NumericLiteral");
8967
8968 case types.string:
8969 return _this2.parseLiteral(_this2.state.value, "StringLiteral");
8970
8971 case types._true:
8972 case types._false:
8973 return _this2.parseBooleanLiteral();
8974
8975 default:
8976 throw _this2.unexpected();
8977 }
8978 }();
8979
8980 return this.finishNode(node, "TSLiteralType");
8981 };
8982
8983 _proto.tsParseNonArrayType = function tsParseNonArrayType() {
8984 switch (this.state.type) {
8985 case types.name:
8986 case types._void:
8987 case types._null:
8988 {
8989 var type = this.match(types._void) ? "TSVoidKeyword" : this.match(types._null) ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
8990
8991 if (type !== undefined && this.lookahead().type !== types.dot) {
8992 var node = this.startNode();
8993 this.next();
8994 return this.finishNode(node, type);
8995 }
8996
8997 return this.tsParseTypeReference();
8998 }
8999
9000 case types.string:
9001 case types.num:
9002 case types._true:
9003 case types._false:
9004 return this.tsParseLiteralTypeNode();
9005
9006 case types.plusMin:
9007 if (this.state.value === "-") {
9008 var _node = this.startNode();
9009
9010 this.next();
9011
9012 if (!this.match(types.num)) {
9013 throw this.unexpected();
9014 }
9015
9016 _node.literal = this.parseLiteral(-this.state.value, "NumericLiteral", _node.start, _node.loc.start);
9017 return this.finishNode(_node, "TSLiteralType");
9018 }
9019
9020 break;
9021
9022 case types._this:
9023 {
9024 var thisKeyword = this.tsParseThisTypeNode();
9025
9026 if (this.isContextual("is") && !this.hasPrecedingLineBreak()) {
9027 return this.tsParseThisTypePredicate(thisKeyword);
9028 } else {
9029 return thisKeyword;
9030 }
9031 }
9032
9033 case types._typeof:
9034 return this.tsParseTypeQuery();
9035
9036 case types.braceL:
9037 return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
9038
9039 case types.bracketL:
9040 return this.tsParseTupleType();
9041
9042 case types.parenL:
9043 return this.tsParseParenthesizedType();
9044 }
9045
9046 throw this.unexpected();
9047 };
9048
9049 _proto.tsParseArrayTypeOrHigher = function tsParseArrayTypeOrHigher() {
9050 var type = this.tsParseNonArrayType();
9051
9052 while (!this.hasPrecedingLineBreak() && this.eat(types.bracketL)) {
9053 if (this.match(types.bracketR)) {
9054 var node = this.startNodeAtNode(type);
9055 node.elementType = type;
9056 this.expect(types.bracketR);
9057 type = this.finishNode(node, "TSArrayType");
9058 } else {
9059 var _node2 = this.startNodeAtNode(type);
9060
9061 _node2.objectType = type;
9062 _node2.indexType = this.tsParseType();
9063 this.expect(types.bracketR);
9064 type = this.finishNode(_node2, "TSIndexedAccessType");
9065 }
9066 }
9067
9068 return type;
9069 };
9070
9071 _proto.tsParseTypeOperator = function tsParseTypeOperator(operator) {
9072 var node = this.startNode();
9073 this.expectContextual(operator);
9074 node.operator = operator;
9075 node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
9076 return this.finishNode(node, "TSTypeOperator");
9077 };
9078
9079 _proto.tsParseInferType = function tsParseInferType() {
9080 var node = this.startNode();
9081 this.expectContextual("infer");
9082 var typeParameter = this.startNode();
9083 typeParameter.name = this.parseIdentifierName(typeParameter.start);
9084 node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
9085 return this.finishNode(node, "TSInferType");
9086 };
9087
9088 _proto.tsParseTypeOperatorOrHigher = function tsParseTypeOperatorOrHigher() {
9089 var _this3 = this;
9090
9091 var operator = ["keyof", "unique"].find(function (kw) {
9092 return _this3.isContextual(kw);
9093 });
9094 return operator ? this.tsParseTypeOperator(operator) : this.isContextual("infer") ? this.tsParseInferType() : this.tsParseArrayTypeOrHigher();
9095 };
9096
9097 _proto.tsParseUnionOrIntersectionType = function tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
9098 this.eat(operator);
9099 var type = parseConstituentType();
9100
9101 if (this.match(operator)) {
9102 var types$$1 = [type];
9103
9104 while (this.eat(operator)) {
9105 types$$1.push(parseConstituentType());
9106 }
9107
9108 var node = this.startNodeAtNode(type);
9109 node.types = types$$1;
9110 type = this.finishNode(node, kind);
9111 }
9112
9113 return type;
9114 };
9115
9116 _proto.tsParseIntersectionTypeOrHigher = function tsParseIntersectionTypeOrHigher() {
9117 return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), types.bitwiseAND);
9118 };
9119
9120 _proto.tsParseUnionTypeOrHigher = function tsParseUnionTypeOrHigher() {
9121 return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), types.bitwiseOR);
9122 };
9123
9124 _proto.tsIsStartOfFunctionType = function tsIsStartOfFunctionType() {
9125 if (this.isRelational("<")) {
9126 return true;
9127 }
9128
9129 return this.match(types.parenL) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
9130 };
9131
9132 _proto.tsSkipParameterStart = function tsSkipParameterStart() {
9133 if (this.match(types.name) || this.match(types._this)) {
9134 this.next();
9135 return true;
9136 }
9137
9138 return false;
9139 };
9140
9141 _proto.tsIsUnambiguouslyStartOfFunctionType = function tsIsUnambiguouslyStartOfFunctionType() {
9142 this.next();
9143
9144 if (this.match(types.parenR) || this.match(types.ellipsis)) {
9145 return true;
9146 }
9147
9148 if (this.tsSkipParameterStart()) {
9149 if (this.match(types.colon) || this.match(types.comma) || this.match(types.question) || this.match(types.eq)) {
9150 return true;
9151 }
9152
9153 if (this.match(types.parenR)) {
9154 this.next();
9155
9156 if (this.match(types.arrow)) {
9157 return true;
9158 }
9159 }
9160 }
9161
9162 return false;
9163 };
9164
9165 _proto.tsParseTypeOrTypePredicateAnnotation = function tsParseTypeOrTypePredicateAnnotation(returnToken) {
9166 var _this4 = this;
9167
9168 return this.tsInType(function () {
9169 var t = _this4.startNode();
9170
9171 _this4.expect(returnToken);
9172
9173 var typePredicateVariable = _this4.tsIsIdentifier() && _this4.tsTryParse(_this4.tsParseTypePredicatePrefix.bind(_this4));
9174
9175 if (!typePredicateVariable) {
9176 return _this4.tsParseTypeAnnotation(false, t);
9177 }
9178
9179 var type = _this4.tsParseTypeAnnotation(false);
9180
9181 var node = _this4.startNodeAtNode(typePredicateVariable);
9182
9183 node.parameterName = typePredicateVariable;
9184 node.typeAnnotation = type;
9185 t.typeAnnotation = _this4.finishNode(node, "TSTypePredicate");
9186 return _this4.finishNode(t, "TSTypeAnnotation");
9187 });
9188 };
9189
9190 _proto.tsTryParseTypeOrTypePredicateAnnotation = function tsTryParseTypeOrTypePredicateAnnotation() {
9191 return this.match(types.colon) ? this.tsParseTypeOrTypePredicateAnnotation(types.colon) : undefined;
9192 };
9193
9194 _proto.tsTryParseTypeAnnotation = function tsTryParseTypeAnnotation() {
9195 return this.match(types.colon) ? this.tsParseTypeAnnotation() : undefined;
9196 };
9197
9198 _proto.tsTryParseType = function tsTryParseType() {
9199 return this.tsEatThenParseType(types.colon);
9200 };
9201
9202 _proto.tsParseTypePredicatePrefix = function tsParseTypePredicatePrefix() {
9203 var id = this.parseIdentifier();
9204
9205 if (this.isContextual("is") && !this.hasPrecedingLineBreak()) {
9206 this.next();
9207 return id;
9208 }
9209 };
9210
9211 _proto.tsParseTypeAnnotation = function tsParseTypeAnnotation(eatColon, t) {
9212 var _this5 = this;
9213
9214 if (eatColon === void 0) {
9215 eatColon = true;
9216 }
9217
9218 if (t === void 0) {
9219 t = this.startNode();
9220 }
9221
9222 this.tsInType(function () {
9223 if (eatColon) _this5.expect(types.colon);
9224 t.typeAnnotation = _this5.tsParseType();
9225 });
9226 return this.finishNode(t, "TSTypeAnnotation");
9227 };
9228
9229 _proto.tsParseType = function tsParseType() {
9230 assert(this.state.inType);
9231 var type = this.tsParseNonConditionalType();
9232
9233 if (this.hasPrecedingLineBreak() || !this.eat(types._extends)) {
9234 return type;
9235 }
9236
9237 var node = this.startNodeAtNode(type);
9238 node.checkType = type;
9239 node.extendsType = this.tsParseNonConditionalType();
9240 this.expect(types.question);
9241 node.trueType = this.tsParseType();
9242 this.expect(types.colon);
9243 node.falseType = this.tsParseType();
9244 return this.finishNode(node, "TSConditionalType");
9245 };
9246
9247 _proto.tsParseNonConditionalType = function tsParseNonConditionalType() {
9248 if (this.tsIsStartOfFunctionType()) {
9249 return this.tsParseFunctionOrConstructorType("TSFunctionType");
9250 }
9251
9252 if (this.match(types._new)) {
9253 return this.tsParseFunctionOrConstructorType("TSConstructorType");
9254 }
9255
9256 return this.tsParseUnionTypeOrHigher();
9257 };
9258
9259 _proto.tsParseTypeAssertion = function tsParseTypeAssertion() {
9260 var _this6 = this;
9261
9262 var node = this.startNode();
9263 node.typeAnnotation = this.tsInType(function () {
9264 return _this6.tsParseType();
9265 });
9266 this.expectRelational(">");
9267 node.expression = this.parseMaybeUnary();
9268 return this.finishNode(node, "TSTypeAssertion");
9269 };
9270
9271 _proto.tsParseHeritageClause = function tsParseHeritageClause() {
9272 return this.tsParseDelimitedList("HeritageClauseElement", this.tsParseExpressionWithTypeArguments.bind(this));
9273 };
9274
9275 _proto.tsParseExpressionWithTypeArguments = function tsParseExpressionWithTypeArguments() {
9276 var node = this.startNode();
9277 node.expression = this.tsParseEntityName(false);
9278
9279 if (this.isRelational("<")) {
9280 node.typeParameters = this.tsParseTypeArguments();
9281 }
9282
9283 return this.finishNode(node, "TSExpressionWithTypeArguments");
9284 };
9285
9286 _proto.tsParseInterfaceDeclaration = function tsParseInterfaceDeclaration(node) {
9287 node.id = this.parseIdentifier();
9288 node.typeParameters = this.tsTryParseTypeParameters();
9289
9290 if (this.eat(types._extends)) {
9291 node.extends = this.tsParseHeritageClause();
9292 }
9293
9294 var body = this.startNode();
9295 body.body = this.tsParseObjectTypeMembers();
9296 node.body = this.finishNode(body, "TSInterfaceBody");
9297 return this.finishNode(node, "TSInterfaceDeclaration");
9298 };
9299
9300 _proto.tsParseTypeAliasDeclaration = function tsParseTypeAliasDeclaration(node) {
9301 node.id = this.parseIdentifier();
9302 node.typeParameters = this.tsTryParseTypeParameters();
9303 node.typeAnnotation = this.tsExpectThenParseType(types.eq);
9304 this.semicolon();
9305 return this.finishNode(node, "TSTypeAliasDeclaration");
9306 };
9307
9308 _proto.tsInNoContext = function tsInNoContext(cb) {
9309 var oldContext = this.state.context;
9310 this.state.context = [oldContext[0]];
9311
9312 try {
9313 return cb();
9314 } finally {
9315 this.state.context = oldContext;
9316 }
9317 };
9318
9319 _proto.tsInType = function tsInType(cb) {
9320 var oldInType = this.state.inType;
9321 this.state.inType = true;
9322
9323 try {
9324 return cb();
9325 } finally {
9326 this.state.inType = oldInType;
9327 }
9328 };
9329
9330 _proto.tsEatThenParseType = function tsEatThenParseType(token) {
9331 return !this.match(token) ? undefined : this.tsNextThenParseType();
9332 };
9333
9334 _proto.tsExpectThenParseType = function tsExpectThenParseType(token) {
9335 var _this7 = this;
9336
9337 return this.tsDoThenParseType(function () {
9338 return _this7.expect(token);
9339 });
9340 };
9341
9342 _proto.tsNextThenParseType = function tsNextThenParseType() {
9343 var _this8 = this;
9344
9345 return this.tsDoThenParseType(function () {
9346 return _this8.next();
9347 });
9348 };
9349
9350 _proto.tsDoThenParseType = function tsDoThenParseType(cb) {
9351 var _this9 = this;
9352
9353 return this.tsInType(function () {
9354 cb();
9355 return _this9.tsParseType();
9356 });
9357 };
9358
9359 _proto.tsParseEnumMember = function tsParseEnumMember() {
9360 var node = this.startNode();
9361 node.id = this.match(types.string) ? this.parseLiteral(this.state.value, "StringLiteral") : this.parseIdentifier(true);
9362
9363 if (this.eat(types.eq)) {
9364 node.initializer = this.parseMaybeAssign();
9365 }
9366
9367 return this.finishNode(node, "TSEnumMember");
9368 };
9369
9370 _proto.tsParseEnumDeclaration = function tsParseEnumDeclaration(node, isConst) {
9371 if (isConst) node.const = true;
9372 node.id = this.parseIdentifier();
9373 this.expect(types.braceL);
9374 node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
9375 this.expect(types.braceR);
9376 return this.finishNode(node, "TSEnumDeclaration");
9377 };
9378
9379 _proto.tsParseModuleBlock = function tsParseModuleBlock() {
9380 var node = this.startNode();
9381 this.expect(types.braceL);
9382 this.parseBlockOrModuleBlockBody(node.body = [], undefined, true, types.braceR);
9383 return this.finishNode(node, "TSModuleBlock");
9384 };
9385
9386 _proto.tsParseModuleOrNamespaceDeclaration = function tsParseModuleOrNamespaceDeclaration(node) {
9387 node.id = this.parseIdentifier();
9388
9389 if (this.eat(types.dot)) {
9390 var inner = this.startNode();
9391 this.tsParseModuleOrNamespaceDeclaration(inner);
9392 node.body = inner;
9393 } else {
9394 node.body = this.tsParseModuleBlock();
9395 }
9396
9397 return this.finishNode(node, "TSModuleDeclaration");
9398 };
9399
9400 _proto.tsParseAmbientExternalModuleDeclaration = function tsParseAmbientExternalModuleDeclaration(node) {
9401 if (this.isContextual("global")) {
9402 node.global = true;
9403 node.id = this.parseIdentifier();
9404 } else if (this.match(types.string)) {
9405 node.id = this.parseExprAtom();
9406 } else {
9407 this.unexpected();
9408 }
9409
9410 if (this.match(types.braceL)) {
9411 node.body = this.tsParseModuleBlock();
9412 } else {
9413 this.semicolon();
9414 }
9415
9416 return this.finishNode(node, "TSModuleDeclaration");
9417 };
9418
9419 _proto.tsParseImportEqualsDeclaration = function tsParseImportEqualsDeclaration(node, isExport) {
9420 node.isExport = isExport || false;
9421 node.id = this.parseIdentifier();
9422 this.expect(types.eq);
9423 node.moduleReference = this.tsParseModuleReference();
9424 this.semicolon();
9425 return this.finishNode(node, "TSImportEqualsDeclaration");
9426 };
9427
9428 _proto.tsIsExternalModuleReference = function tsIsExternalModuleReference() {
9429 return this.isContextual("require") && this.lookahead().type === types.parenL;
9430 };
9431
9432 _proto.tsParseModuleReference = function tsParseModuleReference() {
9433 return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
9434 };
9435
9436 _proto.tsParseExternalModuleReference = function tsParseExternalModuleReference() {
9437 var node = this.startNode();
9438 this.expectContextual("require");
9439 this.expect(types.parenL);
9440
9441 if (!this.match(types.string)) {
9442 throw this.unexpected();
9443 }
9444
9445 node.expression = this.parseLiteral(this.state.value, "StringLiteral");
9446 this.expect(types.parenR);
9447 return this.finishNode(node, "TSExternalModuleReference");
9448 };
9449
9450 _proto.tsLookAhead = function tsLookAhead(f) {
9451 var state = this.state.clone();
9452 var res = f();
9453 this.state = state;
9454 return res;
9455 };
9456
9457 _proto.tsTryParseAndCatch = function tsTryParseAndCatch(f) {
9458 var state = this.state.clone();
9459
9460 try {
9461 return f();
9462 } catch (e) {
9463 if (e instanceof SyntaxError) {
9464 this.state = state;
9465 return undefined;
9466 }
9467
9468 throw e;
9469 }
9470 };
9471
9472 _proto.tsTryParse = function tsTryParse(f) {
9473 var state = this.state.clone();
9474 var result = f();
9475
9476 if (result !== undefined && result !== false) {
9477 return result;
9478 } else {
9479 this.state = state;
9480 return undefined;
9481 }
9482 };
9483
9484 _proto.nodeWithSamePosition = function nodeWithSamePosition(original, type) {
9485 var node = this.startNodeAtNode(original);
9486 node.type = type;
9487 node.end = original.end;
9488 node.loc.end = original.loc.end;
9489
9490 if (original.leadingComments) {
9491 node.leadingComments = original.leadingComments;
9492 }
9493
9494 if (original.trailingComments) {
9495 node.trailingComments = original.trailingComments;
9496 }
9497
9498 if (original.innerComments) node.innerComments = original.innerComments;
9499 return node;
9500 };
9501
9502 _proto.tsTryParseDeclare = function tsTryParseDeclare(nany) {
9503 switch (this.state.type) {
9504 case types._function:
9505 this.next();
9506 return this.parseFunction(nany, true);
9507
9508 case types._class:
9509 return this.parseClass(nany, true, false);
9510
9511 case types._const:
9512 if (this.match(types._const) && this.isLookaheadContextual("enum")) {
9513 this.expect(types._const);
9514 this.expectContextual("enum");
9515 return this.tsParseEnumDeclaration(nany, true);
9516 }
9517
9518 case types._var:
9519 case types._let:
9520 return this.parseVarStatement(nany, this.state.type);
9521
9522 case types.name:
9523 {
9524 var value = this.state.value;
9525
9526 if (value === "global") {
9527 return this.tsParseAmbientExternalModuleDeclaration(nany);
9528 } else {
9529 return this.tsParseDeclaration(nany, value, true);
9530 }
9531 }
9532 }
9533 };
9534
9535 _proto.tsTryParseExportDeclaration = function tsTryParseExportDeclaration() {
9536 return this.tsParseDeclaration(this.startNode(), this.state.value, true);
9537 };
9538
9539 _proto.tsParseExpressionStatement = function tsParseExpressionStatement(node, expr) {
9540 switch (expr.name) {
9541 case "declare":
9542 {
9543 var declaration = this.tsTryParseDeclare(node);
9544
9545 if (declaration) {
9546 declaration.declare = true;
9547 return declaration;
9548 }
9549
9550 break;
9551 }
9552
9553 case "global":
9554 if (this.match(types.braceL)) {
9555 var mod = node;
9556 mod.global = true;
9557 mod.id = expr;
9558 mod.body = this.tsParseModuleBlock();
9559 return this.finishNode(mod, "TSModuleDeclaration");
9560 }
9561
9562 break;
9563
9564 default:
9565 return this.tsParseDeclaration(node, expr.name, false);
9566 }
9567 };
9568
9569 _proto.tsParseDeclaration = function tsParseDeclaration(node, value, next) {
9570 switch (value) {
9571 case "abstract":
9572 if (next || this.match(types._class)) {
9573 var cls = node;
9574 cls.abstract = true;
9575 if (next) this.next();
9576 return this.parseClass(cls, true, false);
9577 }
9578
9579 break;
9580
9581 case "enum":
9582 if (next || this.match(types.name)) {
9583 if (next) this.next();
9584 return this.tsParseEnumDeclaration(node, false);
9585 }
9586
9587 break;
9588
9589 case "interface":
9590 if (next || this.match(types.name)) {
9591 if (next) this.next();
9592 return this.tsParseInterfaceDeclaration(node);
9593 }
9594
9595 break;
9596
9597 case "module":
9598 if (next) this.next();
9599
9600 if (this.match(types.string)) {
9601 return this.tsParseAmbientExternalModuleDeclaration(node);
9602 } else if (next || this.match(types.name)) {
9603 return this.tsParseModuleOrNamespaceDeclaration(node);
9604 }
9605
9606 break;
9607
9608 case "namespace":
9609 if (next || this.match(types.name)) {
9610 if (next) this.next();
9611 return this.tsParseModuleOrNamespaceDeclaration(node);
9612 }
9613
9614 break;
9615
9616 case "type":
9617 if (next || this.match(types.name)) {
9618 if (next) this.next();
9619 return this.tsParseTypeAliasDeclaration(node);
9620 }
9621
9622 break;
9623 }
9624 };
9625
9626 _proto.tsTryParseGenericAsyncArrowFunction = function tsTryParseGenericAsyncArrowFunction(startPos, startLoc) {
9627 var _this10 = this;
9628
9629 var res = this.tsTryParseAndCatch(function () {
9630 var node = _this10.startNodeAt(startPos, startLoc);
9631
9632 node.typeParameters = _this10.tsParseTypeParameters();
9633
9634 _superClass.prototype.parseFunctionParams.call(_this10, node);
9635
9636 node.returnType = _this10.tsTryParseTypeOrTypePredicateAnnotation();
9637
9638 _this10.expect(types.arrow);
9639
9640 return node;
9641 });
9642
9643 if (!res) {
9644 return undefined;
9645 }
9646
9647 res.id = null;
9648 res.generator = false;
9649 res.expression = true;
9650 res.async = true;
9651 this.parseFunctionBody(res, true);
9652 return this.finishNode(res, "ArrowFunctionExpression");
9653 };
9654
9655 _proto.tsParseTypeArguments = function tsParseTypeArguments() {
9656 var _this11 = this;
9657
9658 var node = this.startNode();
9659 node.params = this.tsInType(function () {
9660 return _this11.tsInNoContext(function () {
9661 _this11.expectRelational("<");
9662
9663 return _this11.tsParseDelimitedList("TypeParametersOrArguments", _this11.tsParseType.bind(_this11));
9664 });
9665 });
9666 this.state.exprAllowed = false;
9667 this.expectRelational(">");
9668 return this.finishNode(node, "TSTypeParameterInstantiation");
9669 };
9670
9671 _proto.tsIsDeclarationStart = function tsIsDeclarationStart() {
9672 if (this.match(types.name)) {
9673 switch (this.state.value) {
9674 case "abstract":
9675 case "declare":
9676 case "enum":
9677 case "interface":
9678 case "module":
9679 case "namespace":
9680 case "type":
9681 return true;
9682 }
9683 }
9684
9685 return false;
9686 };
9687
9688 _proto.isExportDefaultSpecifier = function isExportDefaultSpecifier() {
9689 if (this.tsIsDeclarationStart()) return false;
9690 return _superClass.prototype.isExportDefaultSpecifier.call(this);
9691 };
9692
9693 _proto.parseAssignableListItem = function parseAssignableListItem(allowModifiers, decorators) {
9694 var accessibility;
9695 var readonly = false;
9696
9697 if (allowModifiers) {
9698 accessibility = this.parseAccessModifier();
9699 readonly = !!this.tsParseModifier(["readonly"]);
9700 }
9701
9702 var left = this.parseMaybeDefault();
9703 this.parseAssignableListItemTypes(left);
9704 var elt = this.parseMaybeDefault(left.start, left.loc.start, left);
9705
9706 if (accessibility || readonly) {
9707 var pp = this.startNodeAtNode(elt);
9708
9709 if (decorators.length) {
9710 pp.decorators = decorators;
9711 }
9712
9713 if (accessibility) pp.accessibility = accessibility;
9714 if (readonly) pp.readonly = readonly;
9715
9716 if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
9717 throw this.raise(pp.start, "A parameter property may not be declared using a binding pattern.");
9718 }
9719
9720 pp.parameter = elt;
9721 return this.finishNode(pp, "TSParameterProperty");
9722 } else {
9723 if (decorators.length) {
9724 left.decorators = decorators;
9725 }
9726
9727 return elt;
9728 }
9729 };
9730
9731 _proto.parseFunctionBodyAndFinish = function parseFunctionBodyAndFinish(node, type, allowExpressionBody) {
9732 if (!allowExpressionBody && this.match(types.colon)) {
9733 node.returnType = this.tsParseTypeOrTypePredicateAnnotation(types.colon);
9734 }
9735
9736 var bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" ? "TSDeclareMethod" : undefined;
9737
9738 if (bodilessType && !this.match(types.braceL) && this.isLineTerminator()) {
9739 this.finishNode(node, bodilessType);
9740 return;
9741 }
9742
9743 _superClass.prototype.parseFunctionBodyAndFinish.call(this, node, type, allowExpressionBody);
9744 };
9745
9746 _proto.parseSubscript = function parseSubscript(base, startPos, startLoc, noCalls, state) {
9747 var _this12 = this;
9748
9749 if (!this.hasPrecedingLineBreak() && this.match(types.bang)) {
9750 this.state.exprAllowed = false;
9751 this.next();
9752 var nonNullExpression = this.startNodeAt(startPos, startLoc);
9753 nonNullExpression.expression = base;
9754 return this.finishNode(nonNullExpression, "TSNonNullExpression");
9755 }
9756
9757 var result = this.tsTryParseAndCatch(function () {
9758 if (_this12.isRelational("<")) {
9759 if (!noCalls && _this12.atPossibleAsync(base)) {
9760 var asyncArrowFn = _this12.tsTryParseGenericAsyncArrowFunction(startPos, startLoc);
9761
9762 if (asyncArrowFn) {
9763 return asyncArrowFn;
9764 }
9765 }
9766
9767 var node = _this12.startNodeAt(startPos, startLoc);
9768
9769 node.callee = base;
9770
9771 var typeArguments = _this12.tsParseTypeArguments();
9772
9773 if (typeArguments) {
9774 if (!noCalls && _this12.eat(types.parenL)) {
9775 node.arguments = _this12.parseCallExpressionArguments(types.parenR, false);
9776 node.typeParameters = typeArguments;
9777 return _this12.finishCallExpression(node);
9778 } else if (_this12.match(types.backQuote)) {
9779 return _this12.parseTaggedTemplateExpression(startPos, startLoc, base, state, typeArguments);
9780 }
9781 }
9782 }
9783
9784 _this12.unexpected();
9785 });
9786 if (result) return result;
9787 return _superClass.prototype.parseSubscript.call(this, base, startPos, startLoc, noCalls, state);
9788 };
9789
9790 _proto.parseNewArguments = function parseNewArguments(node) {
9791 var _this13 = this;
9792
9793 if (this.isRelational("<")) {
9794 var typeParameters = this.tsTryParseAndCatch(function () {
9795 var args = _this13.tsParseTypeArguments();
9796
9797 if (!_this13.match(types.parenL)) _this13.unexpected();
9798 return args;
9799 });
9800
9801 if (typeParameters) {
9802 node.typeParameters = typeParameters;
9803 }
9804 }
9805
9806 _superClass.prototype.parseNewArguments.call(this, node);
9807 };
9808
9809 _proto.parseExprOp = function parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn) {
9810 if (nonNull(types._in.binop) > minPrec && !this.hasPrecedingLineBreak() && this.isContextual("as")) {
9811 var node = this.startNodeAt(leftStartPos, leftStartLoc);
9812 node.expression = left;
9813 node.typeAnnotation = this.tsNextThenParseType();
9814 this.finishNode(node, "TSAsExpression");
9815 return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn);
9816 }
9817
9818 return _superClass.prototype.parseExprOp.call(this, left, leftStartPos, leftStartLoc, minPrec, noIn);
9819 };
9820
9821 _proto.checkReservedWord = function checkReservedWord(word, startLoc, checkKeywords, isBinding) {};
9822
9823 _proto.checkDuplicateExports = function checkDuplicateExports() {};
9824
9825 _proto.parseImport = function parseImport(node) {
9826 if (this.match(types.name) && this.lookahead().type === types.eq) {
9827 return this.tsParseImportEqualsDeclaration(node);
9828 }
9829
9830 return _superClass.prototype.parseImport.call(this, node);
9831 };
9832
9833 _proto.parseExport = function parseExport(node) {
9834 if (this.match(types._import)) {
9835 this.expect(types._import);
9836 return this.tsParseImportEqualsDeclaration(node, true);
9837 } else if (this.eat(types.eq)) {
9838 var assign = node;
9839 assign.expression = this.parseExpression();
9840 this.semicolon();
9841 return this.finishNode(assign, "TSExportAssignment");
9842 } else if (this.eatContextual("as")) {
9843 var decl = node;
9844 this.expectContextual("namespace");
9845 decl.id = this.parseIdentifier();
9846 this.semicolon();
9847 return this.finishNode(decl, "TSNamespaceExportDeclaration");
9848 } else {
9849 return _superClass.prototype.parseExport.call(this, node);
9850 }
9851 };
9852
9853 _proto.isAbstractClass = function isAbstractClass() {
9854 return this.isContextual("abstract") && this.lookahead().type === types._class;
9855 };
9856
9857 _proto.parseExportDefaultExpression = function parseExportDefaultExpression() {
9858 if (this.isAbstractClass()) {
9859 var cls = this.startNode();
9860 this.next();
9861 this.parseClass(cls, true, true);
9862 cls.abstract = true;
9863 return cls;
9864 }
9865
9866 if (this.state.value === "interface") {
9867 return this.tsParseDeclaration(this.startNode(), this.state.value, true);
9868 }
9869
9870 return _superClass.prototype.parseExportDefaultExpression.call(this);
9871 };
9872
9873 _proto.parseStatementContent = function parseStatementContent(declaration, topLevel) {
9874 if (this.state.type === types._const) {
9875 var ahead = this.lookahead();
9876
9877 if (ahead.type === types.name && ahead.value === "enum") {
9878 var node = this.startNode();
9879 this.expect(types._const);
9880 this.expectContextual("enum");
9881 return this.tsParseEnumDeclaration(node, true);
9882 }
9883 }
9884
9885 return _superClass.prototype.parseStatementContent.call(this, declaration, topLevel);
9886 };
9887
9888 _proto.parseAccessModifier = function parseAccessModifier() {
9889 return this.tsParseModifier(["public", "protected", "private"]);
9890 };
9891
9892 _proto.parseClassMember = function parseClassMember(classBody, member, state) {
9893 var accessibility = this.parseAccessModifier();
9894 if (accessibility) member.accessibility = accessibility;
9895
9896 _superClass.prototype.parseClassMember.call(this, classBody, member, state);
9897 };
9898
9899 _proto.parseClassMemberWithIsStatic = function parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
9900 var methodOrProp = member;
9901 var prop = member;
9902 var propOrIdx = member;
9903 var abstract = false,
9904 readonly = false;
9905 var mod = this.tsParseModifier(["abstract", "readonly"]);
9906
9907 switch (mod) {
9908 case "readonly":
9909 readonly = true;
9910 abstract = !!this.tsParseModifier(["abstract"]);
9911 break;
9912
9913 case "abstract":
9914 abstract = true;
9915 readonly = !!this.tsParseModifier(["readonly"]);
9916 break;
9917 }
9918
9919 if (abstract) methodOrProp.abstract = true;
9920 if (readonly) propOrIdx.readonly = true;
9921
9922 if (!abstract && !isStatic && !methodOrProp.accessibility) {
9923 var idx = this.tsTryParseIndexSignature(member);
9924
9925 if (idx) {
9926 classBody.body.push(idx);
9927 return;
9928 }
9929 }
9930
9931 if (readonly) {
9932 methodOrProp.static = isStatic;
9933 this.parseClassPropertyName(prop);
9934 this.parsePostMemberNameModifiers(methodOrProp);
9935 this.pushClassProperty(classBody, prop);
9936 return;
9937 }
9938
9939 _superClass.prototype.parseClassMemberWithIsStatic.call(this, classBody, member, state, isStatic);
9940 };
9941
9942 _proto.parsePostMemberNameModifiers = function parsePostMemberNameModifiers(methodOrProp) {
9943 var optional = this.eat(types.question);
9944 if (optional) methodOrProp.optional = true;
9945 };
9946
9947 _proto.parseExpressionStatement = function parseExpressionStatement(node, expr) {
9948 var decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr) : undefined;
9949 return decl || _superClass.prototype.parseExpressionStatement.call(this, node, expr);
9950 };
9951
9952 _proto.shouldParseExportDeclaration = function shouldParseExportDeclaration() {
9953 if (this.tsIsDeclarationStart()) return true;
9954 return _superClass.prototype.shouldParseExportDeclaration.call(this);
9955 };
9956
9957 _proto.parseConditional = function parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) {
9958 if (!refNeedsArrowPos || !this.match(types.question)) {
9959 return _superClass.prototype.parseConditional.call(this, expr, noIn, startPos, startLoc, refNeedsArrowPos);
9960 }
9961
9962 var state = this.state.clone();
9963
9964 try {
9965 return _superClass.prototype.parseConditional.call(this, expr, noIn, startPos, startLoc);
9966 } catch (err) {
9967 if (!(err instanceof SyntaxError)) {
9968 throw err;
9969 }
9970
9971 this.state = state;
9972 refNeedsArrowPos.start = err.pos || this.state.start;
9973 return expr;
9974 }
9975 };
9976
9977 _proto.parseParenItem = function parseParenItem(node, startPos, startLoc) {
9978 node = _superClass.prototype.parseParenItem.call(this, node, startPos, startLoc);
9979
9980 if (this.eat(types.question)) {
9981 node.optional = true;
9982 }
9983
9984 if (this.match(types.colon)) {
9985 var typeCastNode = this.startNodeAt(startPos, startLoc);
9986 typeCastNode.expression = node;
9987 typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
9988 return this.finishNode(typeCastNode, "TSTypeCastExpression");
9989 }
9990
9991 return node;
9992 };
9993
9994 _proto.parseExportDeclaration = function parseExportDeclaration(node) {
9995 var isDeclare = this.eatContextual("declare");
9996 var declaration;
9997
9998 if (this.match(types.name)) {
9999 declaration = this.tsTryParseExportDeclaration();
10000 }
10001
10002 if (!declaration) {
10003 declaration = _superClass.prototype.parseExportDeclaration.call(this, node);
10004 }
10005
10006 if (declaration && isDeclare) {
10007 declaration.declare = true;
10008 }
10009
10010 return declaration;
10011 };
10012
10013 _proto.parseClassId = function parseClassId(node, isStatement, optionalId) {
10014 if ((!isStatement || optionalId) && this.isContextual("implements")) {
10015 return;
10016 }
10017
10018 _superClass.prototype.parseClassId.apply(this, arguments);
10019
10020 var typeParameters = this.tsTryParseTypeParameters();
10021 if (typeParameters) node.typeParameters = typeParameters;
10022 };
10023
10024 _proto.parseClassProperty = function parseClassProperty(node) {
10025 if (!node.optional && this.eat(types.bang)) {
10026 node.definite = true;
10027 }
10028
10029 var type = this.tsTryParseTypeAnnotation();
10030 if (type) node.typeAnnotation = type;
10031 return _superClass.prototype.parseClassProperty.call(this, node);
10032 };
10033
10034 _proto.pushClassMethod = function pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) {
10035 var typeParameters = this.tsTryParseTypeParameters();
10036 if (typeParameters) method.typeParameters = typeParameters;
10037
10038 _superClass.prototype.pushClassMethod.call(this, classBody, method, isGenerator, isAsync, isConstructor);
10039 };
10040
10041 _proto.pushClassPrivateMethod = function pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
10042 var typeParameters = this.tsTryParseTypeParameters();
10043 if (typeParameters) method.typeParameters = typeParameters;
10044
10045 _superClass.prototype.pushClassPrivateMethod.call(this, classBody, method, isGenerator, isAsync);
10046 };
10047
10048 _proto.parseClassSuper = function parseClassSuper(node) {
10049 _superClass.prototype.parseClassSuper.call(this, node);
10050
10051 if (node.superClass && this.isRelational("<")) {
10052 node.superTypeParameters = this.tsParseTypeArguments();
10053 }
10054
10055 if (this.eatContextual("implements")) {
10056 node.implements = this.tsParseHeritageClause();
10057 }
10058 };
10059
10060 _proto.parseObjPropValue = function parseObjPropValue(prop) {
10061 var _superClass$prototype;
10062
10063 if (this.isRelational("<")) {
10064 throw new Error("TODO");
10065 }
10066
10067 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
10068 args[_key - 1] = arguments[_key];
10069 }
10070
10071 (_superClass$prototype = _superClass.prototype.parseObjPropValue).call.apply(_superClass$prototype, [this, prop].concat(args));
10072 };
10073
10074 _proto.parseFunctionParams = function parseFunctionParams(node, allowModifiers) {
10075 var typeParameters = this.tsTryParseTypeParameters();
10076 if (typeParameters) node.typeParameters = typeParameters;
10077
10078 _superClass.prototype.parseFunctionParams.call(this, node, allowModifiers);
10079 };
10080
10081 _proto.parseVarHead = function parseVarHead(decl) {
10082 _superClass.prototype.parseVarHead.call(this, decl);
10083
10084 if (decl.id.type === "Identifier" && this.eat(types.bang)) {
10085 decl.definite = true;
10086 }
10087
10088 var type = this.tsTryParseTypeAnnotation();
10089
10090 if (type) {
10091 decl.id.typeAnnotation = type;
10092 this.finishNode(decl.id, decl.id.type);
10093 }
10094 };
10095
10096 _proto.parseAsyncArrowFromCallExpression = function parseAsyncArrowFromCallExpression(node, call) {
10097 if (this.match(types.colon)) {
10098 node.returnType = this.tsParseTypeAnnotation();
10099 }
10100
10101 return _superClass.prototype.parseAsyncArrowFromCallExpression.call(this, node, call);
10102 };
10103
10104 _proto.parseMaybeAssign = function parseMaybeAssign() {
10105 var jsxError;
10106
10107 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
10108 args[_key2] = arguments[_key2];
10109 }
10110
10111 if (this.match(types.jsxTagStart)) {
10112 var context = this.curContext();
10113 assert(context === types$1.j_oTag);
10114 assert(this.state.context[this.state.context.length - 2] === types$1.j_expr);
10115
10116 var _state = this.state.clone();
10117
10118 try {
10119 var _superClass$prototype2;
10120
10121 return (_superClass$prototype2 = _superClass.prototype.parseMaybeAssign).call.apply(_superClass$prototype2, [this].concat(args));
10122 } catch (err) {
10123 if (!(err instanceof SyntaxError)) {
10124 throw err;
10125 }
10126
10127 this.state = _state;
10128 assert(this.curContext() === types$1.j_oTag);
10129 this.state.context.pop();
10130 assert(this.curContext() === types$1.j_expr);
10131 this.state.context.pop();
10132 jsxError = err;
10133 }
10134 }
10135
10136 if (jsxError === undefined && !this.isRelational("<")) {
10137 var _superClass$prototype3;
10138
10139 return (_superClass$prototype3 = _superClass.prototype.parseMaybeAssign).call.apply(_superClass$prototype3, [this].concat(args));
10140 }
10141
10142 var arrowExpression;
10143 var typeParameters;
10144 var state = this.state.clone();
10145
10146 try {
10147 var _superClass$prototype4;
10148
10149 typeParameters = this.tsParseTypeParameters();
10150 arrowExpression = (_superClass$prototype4 = _superClass.prototype.parseMaybeAssign).call.apply(_superClass$prototype4, [this].concat(args));
10151
10152 if (arrowExpression.type !== "ArrowFunctionExpression") {
10153 this.unexpected();
10154 }
10155 } catch (err) {
10156 var _superClass$prototype5;
10157
10158 if (!(err instanceof SyntaxError)) {
10159 throw err;
10160 }
10161
10162 if (jsxError) {
10163 throw jsxError;
10164 }
10165
10166 assert(!this.hasPlugin("jsx"));
10167 this.state = state;
10168 return (_superClass$prototype5 = _superClass.prototype.parseMaybeAssign).call.apply(_superClass$prototype5, [this].concat(args));
10169 }
10170
10171 if (typeParameters && typeParameters.params.length !== 0) {
10172 this.resetStartLocationFromNode(arrowExpression, typeParameters.params[0]);
10173 }
10174
10175 arrowExpression.typeParameters = typeParameters;
10176 return arrowExpression;
10177 };
10178
10179 _proto.parseMaybeUnary = function parseMaybeUnary(refShorthandDefaultPos) {
10180 if (!this.hasPlugin("jsx") && this.eatRelational("<")) {
10181 return this.tsParseTypeAssertion();
10182 } else {
10183 return _superClass.prototype.parseMaybeUnary.call(this, refShorthandDefaultPos);
10184 }
10185 };
10186
10187 _proto.parseArrow = function parseArrow(node) {
10188 if (this.match(types.colon)) {
10189 var state = this.state.clone();
10190
10191 try {
10192 var returnType = this.tsParseTypeOrTypePredicateAnnotation(types.colon);
10193 if (this.canInsertSemicolon()) this.unexpected();
10194 if (!this.match(types.arrow)) this.unexpected();
10195 node.returnType = returnType;
10196 } catch (err) {
10197 if (err instanceof SyntaxError) {
10198 this.state = state;
10199 } else {
10200 throw err;
10201 }
10202 }
10203 }
10204
10205 return _superClass.prototype.parseArrow.call(this, node);
10206 };
10207
10208 _proto.parseAssignableListItemTypes = function parseAssignableListItemTypes(param) {
10209 if (this.eat(types.question)) {
10210 if (param.type !== "Identifier") {
10211 throw this.raise(param.start, "A binding pattern parameter cannot be optional in an implementation signature.");
10212 }
10213
10214 param.optional = true;
10215 }
10216
10217 var type = this.tsTryParseTypeAnnotation();
10218 if (type) param.typeAnnotation = type;
10219 return this.finishNode(param, param.type);
10220 };
10221
10222 _proto.toAssignable = function toAssignable(node, isBinding, contextDescription) {
10223 switch (node.type) {
10224 case "TSTypeCastExpression":
10225 return _superClass.prototype.toAssignable.call(this, this.typeCastToParameter(node), isBinding, contextDescription);
10226
10227 case "TSParameterProperty":
10228 return _superClass.prototype.toAssignable.call(this, node, isBinding, contextDescription);
10229
10230 case "TSAsExpression":
10231 case "TSNonNullExpression":
10232 case "TSTypeAssertion":
10233 node.expression = this.toAssignable(node.expression, isBinding, contextDescription);
10234 return node;
10235
10236 default:
10237 return _superClass.prototype.toAssignable.call(this, node, isBinding, contextDescription);
10238 }
10239 };
10240
10241 _proto.checkLVal = function checkLVal(expr, isBinding, checkClashes, contextDescription) {
10242 switch (expr.type) {
10243 case "TSTypeCastExpression":
10244 return;
10245
10246 case "TSParameterProperty":
10247 this.checkLVal(expr.parameter, isBinding, checkClashes, "parameter property");
10248 return;
10249
10250 case "TSAsExpression":
10251 case "TSNonNullExpression":
10252 case "TSTypeAssertion":
10253 this.checkLVal(expr.expression, isBinding, checkClashes, contextDescription);
10254 return;
10255
10256 default:
10257 _superClass.prototype.checkLVal.call(this, expr, isBinding, checkClashes, contextDescription);
10258
10259 return;
10260 }
10261 };
10262
10263 _proto.parseBindingAtom = function parseBindingAtom() {
10264 switch (this.state.type) {
10265 case types._this:
10266 return this.parseIdentifier(true);
10267
10268 default:
10269 return _superClass.prototype.parseBindingAtom.call(this);
10270 }
10271 };
10272
10273 _proto.isClassMethod = function isClassMethod() {
10274 return this.isRelational("<") || _superClass.prototype.isClassMethod.call(this);
10275 };
10276
10277 _proto.isClassProperty = function isClassProperty() {
10278 return this.match(types.bang) || this.match(types.colon) || _superClass.prototype.isClassProperty.call(this);
10279 };
10280
10281 _proto.parseMaybeDefault = function parseMaybeDefault() {
10282 var _superClass$prototype6;
10283
10284 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
10285 args[_key3] = arguments[_key3];
10286 }
10287
10288 var node = (_superClass$prototype6 = _superClass.prototype.parseMaybeDefault).call.apply(_superClass$prototype6, [this].concat(args));
10289
10290 if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
10291 this.raise(node.typeAnnotation.start, "Type annotations must come before default assignments, " + "e.g. instead of `age = 25: number` use `age: number = 25`");
10292 }
10293
10294 return node;
10295 };
10296
10297 _proto.readToken = function readToken(code) {
10298 if (this.state.inType && (code === 62 || code === 60)) {
10299 return this.finishOp(types.relational, 1);
10300 } else {
10301 return _superClass.prototype.readToken.call(this, code);
10302 }
10303 };
10304
10305 _proto.toAssignableList = function toAssignableList(exprList, isBinding, contextDescription) {
10306 for (var i = 0; i < exprList.length; i++) {
10307 var expr = exprList[i];
10308
10309 if (expr && expr.type === "TSTypeCastExpression") {
10310 exprList[i] = this.typeCastToParameter(expr);
10311 }
10312 }
10313
10314 return _superClass.prototype.toAssignableList.call(this, exprList, isBinding, contextDescription);
10315 };
10316
10317 _proto.typeCastToParameter = function typeCastToParameter(node) {
10318 node.expression.typeAnnotation = node.typeAnnotation;
10319 return this.finishNodeAt(node.expression, node.expression.type, node.typeAnnotation.end, node.typeAnnotation.loc.end);
10320 };
10321
10322 _proto.toReferencedList = function toReferencedList(exprList) {
10323 for (var i = 0; i < exprList.length; i++) {
10324 var expr = exprList[i];
10325
10326 if (expr && expr._exprListItem && expr.type === "TsTypeCastExpression") {
10327 this.raise(expr.start, "Did not expect a type annotation here.");
10328 }
10329 }
10330
10331 return exprList;
10332 };
10333
10334 _proto.shouldParseArrow = function shouldParseArrow() {
10335 return this.match(types.colon) || _superClass.prototype.shouldParseArrow.call(this);
10336 };
10337
10338 _proto.shouldParseAsyncArrow = function shouldParseAsyncArrow() {
10339 return this.match(types.colon) || _superClass.prototype.shouldParseAsyncArrow.call(this);
10340 };
10341
10342 _proto.canHaveLeadingDecorator = function canHaveLeadingDecorator() {
10343 return _superClass.prototype.canHaveLeadingDecorator.call(this) || this.isAbstractClass();
10344 };
10345
10346 _proto.jsxParseOpeningElementAfterName = function jsxParseOpeningElementAfterName(node) {
10347 var _this14 = this;
10348
10349 var typeArguments = this.tsTryParseAndCatch(function () {
10350 return _this14.tsParseTypeArguments();
10351 });
10352 if (typeArguments) node.typeParameters = typeArguments;
10353 return _superClass.prototype.jsxParseOpeningElementAfterName.call(this, node);
10354 };
10355
10356 return _class;
10357 }(superClass);
10358});
10359
10360function hasPlugin(plugins, name) {
10361 return plugins.some(function (plugin) {
10362 if (Array.isArray(plugin)) {
10363 return plugin[0] === name;
10364 } else {
10365 return plugin === name;
10366 }
10367 });
10368}
10369function getPluginOption(plugins, name, option) {
10370 var plugin = plugins.find(function (plugin) {
10371 if (Array.isArray(plugin)) {
10372 return plugin[0] === name;
10373 } else {
10374 return plugin === name;
10375 }
10376 });
10377
10378 if (plugin && Array.isArray(plugin)) {
10379 return plugin[1][option];
10380 }
10381
10382 return null;
10383}
10384var PIPELINE_PROPOSALS = ["minimal"];
10385function validatePlugins(plugins) {
10386 if (hasPlugin(plugins, "decorators") && hasPlugin(plugins, "decorators-legacy")) {
10387 throw new Error("Cannot use the decorators and decorators-legacy plugin together");
10388 }
10389
10390 if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
10391 throw new Error("Cannot combine flow and typescript plugins.");
10392 }
10393
10394 if (hasPlugin(plugins, "pipelineOperator") && !PIPELINE_PROPOSALS.includes(getPluginOption(plugins, "pipelineOperator", "proposal"))) {
10395 throw new Error("'pipelineOperator' requires 'proposal' option whose value should be one of: " + PIPELINE_PROPOSALS.join(", "));
10396 }
10397}
10398var mixinPluginNames = ["estree", "jsx", "flow", "typescript"];
10399var mixinPlugins = {
10400 estree: estree,
10401 jsx: jsx,
10402 flow: flow,
10403 typescript: typescript
10404};
10405
10406function parse(input, options) {
10407 if (options && options.sourceType === "unambiguous") {
10408 options = Object.assign({}, options);
10409
10410 try {
10411 options.sourceType = "module";
10412 var parser = getParser(options, input);
10413 var ast = parser.parse();
10414 if (!parser.sawUnambiguousESM) ast.program.sourceType = "script";
10415 return ast;
10416 } catch (moduleError) {
10417 try {
10418 options.sourceType = "script";
10419 return getParser(options, input).parse();
10420 } catch (scriptError) {}
10421
10422 throw moduleError;
10423 }
10424 } else {
10425 return getParser(options, input).parse();
10426 }
10427}
10428function parseExpression(input, options) {
10429 var parser = getParser(options, input);
10430
10431 if (parser.options.strictMode) {
10432 parser.state.strict = true;
10433 }
10434
10435 return parser.getExpression();
10436}
10437function getParser(options, input) {
10438 var cls = Parser;
10439
10440 if (options && options.plugins) {
10441 validatePlugins(options.plugins);
10442 cls = getParserClass(options.plugins);
10443 }
10444
10445 return new cls(options, input);
10446}
10447
10448var parserClassCache = {};
10449
10450function getParserClass(pluginsFromOptions) {
10451 var pluginList = mixinPluginNames.filter(function (name) {
10452 return hasPlugin(pluginsFromOptions, name);
10453 });
10454 var key = pluginList.join("/");
10455 var cls = parserClassCache[key];
10456
10457 if (!cls) {
10458 cls = Parser;
10459
10460 for (var _i2 = 0; _i2 < pluginList.length; _i2++) {
10461 var plugin = pluginList[_i2];
10462 cls = mixinPlugins[plugin](cls);
10463 }
10464
10465 parserClassCache[key] = cls;
10466 }
10467
10468 return cls;
10469}
10470
10471exports.parse = parse;
10472exports.parseExpression = parseExpression;
10473exports.tokTypes = types;
10474
\No newline at end of file