UNPKG

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