1 (function webpackUniversalModuleDefinition(root, factory) {
2 /* istanbul ignore next */
3 if(typeof exports === 'object' && typeof module === 'object')
4 module.exports = factory();
5 else if(typeof define === 'function' && define.amd)
7 /* istanbul ignore next */
8 else if(typeof exports === 'object')
9 exports["esprima"] = factory();
11 root["esprima"] = factory();
13 return /******/ (function(modules) { // webpackBootstrap
14 /******/ // The module cache
15 /******/ var installedModules = {};
17 /******/ // The require function
18 /******/ function __webpack_require__(moduleId) {
20 /******/ // Check if module is in cache
21 /* istanbul ignore if */
22 /******/ if(installedModules[moduleId])
23 /******/ return installedModules[moduleId].exports;
25 /******/ // Create a new module (and put it into the cache)
26 /******/ var module = installedModules[moduleId] = {
28 /******/ id: moduleId,
29 /******/ loaded: false
32 /******/ // Execute the module function
33 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
35 /******/ // Flag the module as loaded
36 /******/ module.loaded = true;
38 /******/ // Return the exports of the module
39 /******/ return module.exports;
43 /******/ // expose the modules object (__webpack_modules__)
44 /******/ __webpack_require__.m = modules;
46 /******/ // expose the module cache
47 /******/ __webpack_require__.c = installedModules;
49 /******/ // __webpack_public_path__
50 /******/ __webpack_require__.p = "";
52 /******/ // Load entry module and return exports
53 /******/ return __webpack_require__(0);
55 /************************************************************************/
58 /***/ function(module, exports, __webpack_require__) {
62 Copyright JS Foundation and other contributors, https://js.foundation/
64 Redistribution and use in source and binary forms, with or without
65 modification, are permitted provided that the following conditions are met:
67 * Redistributions of source code must retain the above copyright
68 notice, this list of conditions and the following disclaimer.
69 * Redistributions in binary form must reproduce the above copyright
70 notice, this list of conditions and the following disclaimer in the
71 documentation and/or other materials provided with the distribution.
73 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84 Object.defineProperty(exports, "__esModule", { value: true });
85 var comment_handler_1 = __webpack_require__(1);
86 var jsx_parser_1 = __webpack_require__(3);
87 var parser_1 = __webpack_require__(8);
88 var tokenizer_1 = __webpack_require__(15);
89 function parse(code, options, delegate) {
90 var commentHandler = null;
91 var proxyDelegate = function (node, metadata) {
93 delegate(node, metadata);
96 commentHandler.visit(node, metadata);
99 var parserDelegate = (typeof delegate === 'function') ? proxyDelegate : null;
100 var collectComment = false;
102 collectComment = (typeof options.comment === 'boolean' && options.comment);
103 var attachComment = (typeof options.attachComment === 'boolean' && options.attachComment);
104 if (collectComment || attachComment) {
105 commentHandler = new comment_handler_1.CommentHandler();
106 commentHandler.attach = attachComment;
107 options.comment = true;
108 parserDelegate = proxyDelegate;
111 var isModule = false;
112 if (options && typeof options.sourceType === 'string') {
113 isModule = (options.sourceType === 'module');
116 if (options && typeof options.jsx === 'boolean' && options.jsx) {
117 parser = new jsx_parser_1.JSXParser(code, options, parserDelegate);
120 parser = new parser_1.Parser(code, options, parserDelegate);
122 var program = isModule ? parser.parseModule() : parser.parseScript();
124 if (collectComment && commentHandler) {
125 ast.comments = commentHandler.comments;
127 if (parser.config.tokens) {
128 ast.tokens = parser.tokens;
130 if (parser.config.tolerant) {
131 ast.errors = parser.errorHandler.errors;
135 exports.parse = parse;
136 function parseModule(code, options, delegate) {
137 var parsingOptions = options || {};
138 parsingOptions.sourceType = 'module';
139 return parse(code, parsingOptions, delegate);
141 exports.parseModule = parseModule;
142 function parseScript(code, options, delegate) {
143 var parsingOptions = options || {};
144 parsingOptions.sourceType = 'script';
145 return parse(code, parsingOptions, delegate);
147 exports.parseScript = parseScript;
148 function tokenize(code, options, delegate) {
149 var tokenizer = new tokenizer_1.Tokenizer(code, options);
154 var token = tokenizer.getNextToken();
159 token = delegate(token);
165 tokenizer.errorHandler.tolerate(e);
167 if (tokenizer.errorHandler.tolerant) {
168 tokens.errors = tokenizer.errors();
172 exports.tokenize = tokenize;
173 var syntax_1 = __webpack_require__(2);
174 exports.Syntax = syntax_1.Syntax;
175 // Sync with *.json manifests.
176 exports.version = '4.0.1';
181 /***/ function(module, exports, __webpack_require__) {
184 Object.defineProperty(exports, "__esModule", { value: true });
185 var syntax_1 = __webpack_require__(2);
186 var CommentHandler = (function () {
187 function CommentHandler() {
194 CommentHandler.prototype.insertInnerComments = function (node, metadata) {
195 // innnerComments for properties empty block
196 // `function a() {/** comments **\/}`
197 if (node.type === syntax_1.Syntax.BlockStatement && node.body.length === 0) {
198 var innerComments = [];
199 for (var i = this.leading.length - 1; i >= 0; --i) {
200 var entry = this.leading[i];
201 if (metadata.end.offset >= entry.start) {
202 innerComments.unshift(entry.comment);
203 this.leading.splice(i, 1);
204 this.trailing.splice(i, 1);
207 if (innerComments.length) {
208 node.innerComments = innerComments;
212 CommentHandler.prototype.findTrailingComments = function (metadata) {
213 var trailingComments = [];
214 if (this.trailing.length > 0) {
215 for (var i = this.trailing.length - 1; i >= 0; --i) {
216 var entry_1 = this.trailing[i];
217 if (entry_1.start >= metadata.end.offset) {
218 trailingComments.unshift(entry_1.comment);
221 this.trailing.length = 0;
222 return trailingComments;
224 var entry = this.stack[this.stack.length - 1];
225 if (entry && entry.node.trailingComments) {
226 var firstComment = entry.node.trailingComments[0];
227 if (firstComment && firstComment.range[0] >= metadata.end.offset) {
228 trailingComments = entry.node.trailingComments;
229 delete entry.node.trailingComments;
232 return trailingComments;
234 CommentHandler.prototype.findLeadingComments = function (metadata) {
235 var leadingComments = [];
237 while (this.stack.length > 0) {
238 var entry = this.stack[this.stack.length - 1];
239 if (entry && entry.start >= metadata.start.offset) {
248 var count = target.leadingComments ? target.leadingComments.length : 0;
249 for (var i = count - 1; i >= 0; --i) {
250 var comment = target.leadingComments[i];
251 if (comment.range[1] <= metadata.start.offset) {
252 leadingComments.unshift(comment);
253 target.leadingComments.splice(i, 1);
256 if (target.leadingComments && target.leadingComments.length === 0) {
257 delete target.leadingComments;
259 return leadingComments;
261 for (var i = this.leading.length - 1; i >= 0; --i) {
262 var entry = this.leading[i];
263 if (entry.start <= metadata.start.offset) {
264 leadingComments.unshift(entry.comment);
265 this.leading.splice(i, 1);
268 return leadingComments;
270 CommentHandler.prototype.visitNode = function (node, metadata) {
271 if (node.type === syntax_1.Syntax.Program && node.body.length > 0) {
274 this.insertInnerComments(node, metadata);
275 var trailingComments = this.findTrailingComments(metadata);
276 var leadingComments = this.findLeadingComments(metadata);
277 if (leadingComments.length > 0) {
278 node.leadingComments = leadingComments;
280 if (trailingComments.length > 0) {
281 node.trailingComments = trailingComments;
285 start: metadata.start.offset
288 CommentHandler.prototype.visitComment = function (node, metadata) {
289 var type = (node.type[0] === 'L') ? 'Line' : 'Block';
295 comment.range = node.range;
298 comment.loc = node.loc;
300 this.comments.push(comment);
306 range: [metadata.start.offset, metadata.end.offset]
308 start: metadata.start.offset
311 entry.comment.loc = node.loc;
314 this.leading.push(entry);
315 this.trailing.push(entry);
318 CommentHandler.prototype.visit = function (node, metadata) {
319 if (node.type === 'LineComment') {
320 this.visitComment(node, metadata);
322 else if (node.type === 'BlockComment') {
323 this.visitComment(node, metadata);
325 else if (this.attach) {
326 this.visitNode(node, metadata);
329 return CommentHandler;
331 exports.CommentHandler = CommentHandler;
336 /***/ function(module, exports) {
339 Object.defineProperty(exports, "__esModule", { value: true });
341 AssignmentExpression: 'AssignmentExpression',
342 AssignmentPattern: 'AssignmentPattern',
343 ArrayExpression: 'ArrayExpression',
344 ArrayPattern: 'ArrayPattern',
345 ArrowFunctionExpression: 'ArrowFunctionExpression',
346 AwaitExpression: 'AwaitExpression',
347 BlockStatement: 'BlockStatement',
348 BinaryExpression: 'BinaryExpression',
349 BreakStatement: 'BreakStatement',
350 CallExpression: 'CallExpression',
351 CatchClause: 'CatchClause',
352 ClassBody: 'ClassBody',
353 ClassDeclaration: 'ClassDeclaration',
354 ClassExpression: 'ClassExpression',
355 ConditionalExpression: 'ConditionalExpression',
356 ContinueStatement: 'ContinueStatement',
357 DoWhileStatement: 'DoWhileStatement',
358 DebuggerStatement: 'DebuggerStatement',
359 EmptyStatement: 'EmptyStatement',
360 ExportAllDeclaration: 'ExportAllDeclaration',
361 ExportDefaultDeclaration: 'ExportDefaultDeclaration',
362 ExportNamedDeclaration: 'ExportNamedDeclaration',
363 ExportSpecifier: 'ExportSpecifier',
364 ExpressionStatement: 'ExpressionStatement',
365 ForStatement: 'ForStatement',
366 ForOfStatement: 'ForOfStatement',
367 ForInStatement: 'ForInStatement',
368 FunctionDeclaration: 'FunctionDeclaration',
369 FunctionExpression: 'FunctionExpression',
370 Identifier: 'Identifier',
371 IfStatement: 'IfStatement',
372 ImportDeclaration: 'ImportDeclaration',
373 ImportDefaultSpecifier: 'ImportDefaultSpecifier',
374 ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
375 ImportSpecifier: 'ImportSpecifier',
377 LabeledStatement: 'LabeledStatement',
378 LogicalExpression: 'LogicalExpression',
379 MemberExpression: 'MemberExpression',
380 MetaProperty: 'MetaProperty',
381 MethodDefinition: 'MethodDefinition',
382 NewExpression: 'NewExpression',
383 ObjectExpression: 'ObjectExpression',
384 ObjectPattern: 'ObjectPattern',
386 Property: 'Property',
387 RestElement: 'RestElement',
388 ReturnStatement: 'ReturnStatement',
389 SequenceExpression: 'SequenceExpression',
390 SpreadElement: 'SpreadElement',
392 SwitchCase: 'SwitchCase',
393 SwitchStatement: 'SwitchStatement',
394 TaggedTemplateExpression: 'TaggedTemplateExpression',
395 TemplateElement: 'TemplateElement',
396 TemplateLiteral: 'TemplateLiteral',
397 ThisExpression: 'ThisExpression',
398 ThrowStatement: 'ThrowStatement',
399 TryStatement: 'TryStatement',
400 UnaryExpression: 'UnaryExpression',
401 UpdateExpression: 'UpdateExpression',
402 VariableDeclaration: 'VariableDeclaration',
403 VariableDeclarator: 'VariableDeclarator',
404 WhileStatement: 'WhileStatement',
405 WithStatement: 'WithStatement',
406 YieldExpression: 'YieldExpression'
412 /***/ function(module, exports, __webpack_require__) {
415 /* istanbul ignore next */
416 var __extends = (this && this.__extends) || (function () {
417 var extendStatics = Object.setPrototypeOf ||
418 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
419 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
420 return function (d, b) {
422 function __() { this.constructor = d; }
423 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
426 Object.defineProperty(exports, "__esModule", { value: true });
427 var character_1 = __webpack_require__(4);
428 var JSXNode = __webpack_require__(5);
429 var jsx_syntax_1 = __webpack_require__(6);
430 var Node = __webpack_require__(7);
431 var parser_1 = __webpack_require__(8);
432 var token_1 = __webpack_require__(13);
433 var xhtml_entities_1 = __webpack_require__(14);
434 token_1.TokenName[100 /* Identifier */] = 'JSXIdentifier';
435 token_1.TokenName[101 /* Text */] = 'JSXText';
436 // Fully qualified element name, e.g. <svg:path> returns "svg:path"
437 function getQualifiedElementName(elementName) {
439 switch (elementName.type) {
440 case jsx_syntax_1.JSXSyntax.JSXIdentifier:
441 var id = elementName;
442 qualifiedName = id.name;
444 case jsx_syntax_1.JSXSyntax.JSXNamespacedName:
445 var ns = elementName;
446 qualifiedName = getQualifiedElementName(ns.namespace) + ':' +
447 getQualifiedElementName(ns.name);
449 case jsx_syntax_1.JSXSyntax.JSXMemberExpression:
450 var expr = elementName;
451 qualifiedName = getQualifiedElementName(expr.object) + '.' +
452 getQualifiedElementName(expr.property);
454 /* istanbul ignore next */
458 return qualifiedName;
460 var JSXParser = (function (_super) {
461 __extends(JSXParser, _super);
462 function JSXParser(code, options, delegate) {
463 return _super.call(this, code, options, delegate) || this;
465 JSXParser.prototype.parsePrimaryExpression = function () {
466 return this.match('<') ? this.parseJSXRoot() : _super.prototype.parsePrimaryExpression.call(this);
468 JSXParser.prototype.startJSX = function () {
469 // Unwind the scanner before the lookahead token.
470 this.scanner.index = this.startMarker.index;
471 this.scanner.lineNumber = this.startMarker.line;
472 this.scanner.lineStart = this.startMarker.index - this.startMarker.column;
474 JSXParser.prototype.finishJSX = function () {
475 // Prime the next lookahead.
478 JSXParser.prototype.reenterJSX = function () {
481 // Pop the closing '}' added from the lookahead.
482 if (this.config.tokens) {
486 JSXParser.prototype.createJSXNode = function () {
487 this.collectComments();
489 index: this.scanner.index,
490 line: this.scanner.lineNumber,
491 column: this.scanner.index - this.scanner.lineStart
494 JSXParser.prototype.createJSXChildNode = function () {
496 index: this.scanner.index,
497 line: this.scanner.lineNumber,
498 column: this.scanner.index - this.scanner.lineStart
501 JSXParser.prototype.scanXHTMLEntity = function (quote) {
504 var terminated = false;
507 while (!this.scanner.eof() && valid && !terminated) {
508 var ch = this.scanner.source[this.scanner.index];
512 terminated = (ch === ';');
514 ++this.scanner.index;
516 switch (result.length) {
519 numeric = (ch === '#');
525 valid = hex || character_1.Character.isDecimalDigit(ch.charCodeAt(0));
526 numeric = numeric && !hex;
530 valid = valid && !(numeric && !character_1.Character.isDecimalDigit(ch.charCodeAt(0)));
531 valid = valid && !(hex && !character_1.Character.isHexDigit(ch.charCodeAt(0)));
536 if (valid && terminated && result.length > 2) {
537 // e.g. 'A' becomes just '#x41'
538 var str = result.substr(1, result.length - 2);
539 if (numeric && str.length > 1) {
540 result = String.fromCharCode(parseInt(str.substr(1), 10));
542 else if (hex && str.length > 2) {
543 result = String.fromCharCode(parseInt('0' + str.substr(1), 16));
545 else if (!numeric && !hex && xhtml_entities_1.XHTMLEntities[str]) {
546 result = xhtml_entities_1.XHTMLEntities[str];
551 // Scan the next JSX token. This replaces Scanner#lex when in JSX mode.
552 JSXParser.prototype.lexJSX = function () {
553 var cp = this.scanner.source.charCodeAt(this.scanner.index);
555 if (cp === 60 || cp === 62 || cp === 47 || cp === 58 || cp === 61 || cp === 123 || cp === 125) {
556 var value = this.scanner.source[this.scanner.index++];
558 type: 7 /* Punctuator */,
560 lineNumber: this.scanner.lineNumber,
561 lineStart: this.scanner.lineStart,
562 start: this.scanner.index - 1,
563 end: this.scanner.index
567 if (cp === 34 || cp === 39) {
568 var start = this.scanner.index;
569 var quote = this.scanner.source[this.scanner.index++];
571 while (!this.scanner.eof()) {
572 var ch = this.scanner.source[this.scanner.index++];
576 else if (ch === '&') {
577 str += this.scanXHTMLEntity(quote);
584 type: 8 /* StringLiteral */,
586 lineNumber: this.scanner.lineNumber,
587 lineStart: this.scanner.lineStart,
589 end: this.scanner.index
594 var n1 = this.scanner.source.charCodeAt(this.scanner.index + 1);
595 var n2 = this.scanner.source.charCodeAt(this.scanner.index + 2);
596 var value = (n1 === 46 && n2 === 46) ? '...' : '.';
597 var start = this.scanner.index;
598 this.scanner.index += value.length;
600 type: 7 /* Punctuator */,
602 lineNumber: this.scanner.lineNumber,
603 lineStart: this.scanner.lineStart,
605 end: this.scanner.index
610 // Only placeholder, since it will be rescanned as a real assignment expression.
612 type: 10 /* Template */,
614 lineNumber: this.scanner.lineNumber,
615 lineStart: this.scanner.lineStart,
616 start: this.scanner.index,
617 end: this.scanner.index
620 // Identifer can not contain backslash (char code 92).
621 if (character_1.Character.isIdentifierStart(cp) && (cp !== 92)) {
622 var start = this.scanner.index;
623 ++this.scanner.index;
624 while (!this.scanner.eof()) {
625 var ch = this.scanner.source.charCodeAt(this.scanner.index);
626 if (character_1.Character.isIdentifierPart(ch) && (ch !== 92)) {
627 ++this.scanner.index;
629 else if (ch === 45) {
630 // Hyphen (char code 45) can be part of an identifier.
631 ++this.scanner.index;
637 var id = this.scanner.source.slice(start, this.scanner.index);
639 type: 100 /* Identifier */,
641 lineNumber: this.scanner.lineNumber,
642 lineStart: this.scanner.lineStart,
644 end: this.scanner.index
647 return this.scanner.lex();
649 JSXParser.prototype.nextJSXToken = function () {
650 this.collectComments();
651 this.startMarker.index = this.scanner.index;
652 this.startMarker.line = this.scanner.lineNumber;
653 this.startMarker.column = this.scanner.index - this.scanner.lineStart;
654 var token = this.lexJSX();
655 this.lastMarker.index = this.scanner.index;
656 this.lastMarker.line = this.scanner.lineNumber;
657 this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
658 if (this.config.tokens) {
659 this.tokens.push(this.convertToken(token));
663 JSXParser.prototype.nextJSXText = function () {
664 this.startMarker.index = this.scanner.index;
665 this.startMarker.line = this.scanner.lineNumber;
666 this.startMarker.column = this.scanner.index - this.scanner.lineStart;
667 var start = this.scanner.index;
669 while (!this.scanner.eof()) {
670 var ch = this.scanner.source[this.scanner.index];
671 if (ch === '{' || ch === '<') {
674 ++this.scanner.index;
676 if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
677 ++this.scanner.lineNumber;
678 if (ch === '\r' && this.scanner.source[this.scanner.index] === '\n') {
679 ++this.scanner.index;
681 this.scanner.lineStart = this.scanner.index;
684 this.lastMarker.index = this.scanner.index;
685 this.lastMarker.line = this.scanner.lineNumber;
686 this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
688 type: 101 /* Text */,
690 lineNumber: this.scanner.lineNumber,
691 lineStart: this.scanner.lineStart,
693 end: this.scanner.index
695 if ((text.length > 0) && this.config.tokens) {
696 this.tokens.push(this.convertToken(token));
700 JSXParser.prototype.peekJSXToken = function () {
701 var state = this.scanner.saveState();
702 this.scanner.scanComments();
703 var next = this.lexJSX();
704 this.scanner.restoreState(state);
707 // Expect the next JSX token to match the specified punctuator.
708 // If not, an exception will be thrown.
709 JSXParser.prototype.expectJSX = function (value) {
710 var token = this.nextJSXToken();
711 if (token.type !== 7 /* Punctuator */ || token.value !== value) {
712 this.throwUnexpectedToken(token);
715 // Return true if the next JSX token matches the specified punctuator.
716 JSXParser.prototype.matchJSX = function (value) {
717 var next = this.peekJSXToken();
718 return next.type === 7 /* Punctuator */ && next.value === value;
720 JSXParser.prototype.parseJSXIdentifier = function () {
721 var node = this.createJSXNode();
722 var token = this.nextJSXToken();
723 if (token.type !== 100 /* Identifier */) {
724 this.throwUnexpectedToken(token);
726 return this.finalize(node, new JSXNode.JSXIdentifier(token.value));
728 JSXParser.prototype.parseJSXElementName = function () {
729 var node = this.createJSXNode();
730 var elementName = this.parseJSXIdentifier();
731 if (this.matchJSX(':')) {
732 var namespace = elementName;
734 var name_1 = this.parseJSXIdentifier();
735 elementName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_1));
737 else if (this.matchJSX('.')) {
738 while (this.matchJSX('.')) {
739 var object = elementName;
741 var property = this.parseJSXIdentifier();
742 elementName = this.finalize(node, new JSXNode.JSXMemberExpression(object, property));
747 JSXParser.prototype.parseJSXAttributeName = function () {
748 var node = this.createJSXNode();
750 var identifier = this.parseJSXIdentifier();
751 if (this.matchJSX(':')) {
752 var namespace = identifier;
754 var name_2 = this.parseJSXIdentifier();
755 attributeName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_2));
758 attributeName = identifier;
760 return attributeName;
762 JSXParser.prototype.parseJSXStringLiteralAttribute = function () {
763 var node = this.createJSXNode();
764 var token = this.nextJSXToken();
765 if (token.type !== 8 /* StringLiteral */) {
766 this.throwUnexpectedToken(token);
768 var raw = this.getTokenRaw(token);
769 return this.finalize(node, new Node.Literal(token.value, raw));
771 JSXParser.prototype.parseJSXExpressionAttribute = function () {
772 var node = this.createJSXNode();
775 if (this.match('}')) {
776 this.tolerateError('JSX attributes must only be assigned a non-empty expression');
778 var expression = this.parseAssignmentExpression();
780 return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
782 JSXParser.prototype.parseJSXAttributeValue = function () {
783 return this.matchJSX('{') ? this.parseJSXExpressionAttribute() :
784 this.matchJSX('<') ? this.parseJSXElement() : this.parseJSXStringLiteralAttribute();
786 JSXParser.prototype.parseJSXNameValueAttribute = function () {
787 var node = this.createJSXNode();
788 var name = this.parseJSXAttributeName();
790 if (this.matchJSX('=')) {
792 value = this.parseJSXAttributeValue();
794 return this.finalize(node, new JSXNode.JSXAttribute(name, value));
796 JSXParser.prototype.parseJSXSpreadAttribute = function () {
797 var node = this.createJSXNode();
799 this.expectJSX('...');
801 var argument = this.parseAssignmentExpression();
803 return this.finalize(node, new JSXNode.JSXSpreadAttribute(argument));
805 JSXParser.prototype.parseJSXAttributes = function () {
807 while (!this.matchJSX('/') && !this.matchJSX('>')) {
808 var attribute = this.matchJSX('{') ? this.parseJSXSpreadAttribute() :
809 this.parseJSXNameValueAttribute();
810 attributes.push(attribute);
814 JSXParser.prototype.parseJSXOpeningElement = function () {
815 var node = this.createJSXNode();
817 var name = this.parseJSXElementName();
818 var attributes = this.parseJSXAttributes();
819 var selfClosing = this.matchJSX('/');
824 return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
826 JSXParser.prototype.parseJSXBoundaryElement = function () {
827 var node = this.createJSXNode();
829 if (this.matchJSX('/')) {
831 var name_3 = this.parseJSXElementName();
833 return this.finalize(node, new JSXNode.JSXClosingElement(name_3));
835 var name = this.parseJSXElementName();
836 var attributes = this.parseJSXAttributes();
837 var selfClosing = this.matchJSX('/');
842 return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
844 JSXParser.prototype.parseJSXEmptyExpression = function () {
845 var node = this.createJSXChildNode();
846 this.collectComments();
847 this.lastMarker.index = this.scanner.index;
848 this.lastMarker.line = this.scanner.lineNumber;
849 this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
850 return this.finalize(node, new JSXNode.JSXEmptyExpression());
852 JSXParser.prototype.parseJSXExpressionContainer = function () {
853 var node = this.createJSXNode();
856 if (this.matchJSX('}')) {
857 expression = this.parseJSXEmptyExpression();
862 expression = this.parseAssignmentExpression();
865 return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
867 JSXParser.prototype.parseJSXChildren = function () {
869 while (!this.scanner.eof()) {
870 var node = this.createJSXChildNode();
871 var token = this.nextJSXText();
872 if (token.start < token.end) {
873 var raw = this.getTokenRaw(token);
874 var child = this.finalize(node, new JSXNode.JSXText(token.value, raw));
875 children.push(child);
877 if (this.scanner.source[this.scanner.index] === '{') {
878 var container = this.parseJSXExpressionContainer();
879 children.push(container);
887 JSXParser.prototype.parseComplexJSXElement = function (el) {
889 while (!this.scanner.eof()) {
890 el.children = el.children.concat(this.parseJSXChildren());
891 var node = this.createJSXChildNode();
892 var element = this.parseJSXBoundaryElement();
893 if (element.type === jsx_syntax_1.JSXSyntax.JSXOpeningElement) {
894 var opening = element;
895 if (opening.selfClosing) {
896 var child = this.finalize(node, new JSXNode.JSXElement(opening, [], null));
897 el.children.push(child);
901 el = { node: node, opening: opening, closing: null, children: [] };
904 if (element.type === jsx_syntax_1.JSXSyntax.JSXClosingElement) {
905 el.closing = element;
906 var open_1 = getQualifiedElementName(el.opening.name);
907 var close_1 = getQualifiedElementName(el.closing.name);
908 if (open_1 !== close_1) {
909 this.tolerateError('Expected corresponding JSX closing tag for %0', open_1);
911 if (stack.length > 0) {
912 var child = this.finalize(el.node, new JSXNode.JSXElement(el.opening, el.children, el.closing));
913 el = stack[stack.length - 1];
914 el.children.push(child);
924 JSXParser.prototype.parseJSXElement = function () {
925 var node = this.createJSXNode();
926 var opening = this.parseJSXOpeningElement();
929 if (!opening.selfClosing) {
930 var el = this.parseComplexJSXElement({ node: node, opening: opening, closing: closing, children: children });
931 children = el.children;
932 closing = el.closing;
934 return this.finalize(node, new JSXNode.JSXElement(opening, children, closing));
936 JSXParser.prototype.parseJSXRoot = function () {
937 // Pop the opening '<' added from the lookahead.
938 if (this.config.tokens) {
942 var element = this.parseJSXElement();
946 JSXParser.prototype.isStartOfExpression = function () {
947 return _super.prototype.isStartOfExpression.call(this) || this.match('<');
951 exports.JSXParser = JSXParser;
956 /***/ function(module, exports) {
959 Object.defineProperty(exports, "__esModule", { value: true });
960 // See also tools/generate-unicode-regex.js.
962 // Unicode v8.0.0 NonAsciiIdentifierStart:
963 NonAsciiIdentifierStart: /[\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\u0561-\u0587\u05D0-\u05EA\u05F0-\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\u08A0-\u08B4\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\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\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\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-\u1877\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\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-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\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]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,
964 // Unicode v8.0.0 NonAsciiIdentifierPart:
965 NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\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\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\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\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\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-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
967 exports.Character = {
968 /* tslint:disable:no-bitwise */
969 fromCodePoint: function (cp) {
970 return (cp < 0x10000) ? String.fromCharCode(cp) :
971 String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) +
972 String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023));
974 // https://tc39.github.io/ecma262/#sec-white-space
975 isWhiteSpace: function (cp) {
976 return (cp === 0x20) || (cp === 0x09) || (cp === 0x0B) || (cp === 0x0C) || (cp === 0xA0) ||
977 (cp >= 0x1680 && [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(cp) >= 0);
979 // https://tc39.github.io/ecma262/#sec-line-terminators
980 isLineTerminator: function (cp) {
981 return (cp === 0x0A) || (cp === 0x0D) || (cp === 0x2028) || (cp === 0x2029);
983 // https://tc39.github.io/ecma262/#sec-names-and-keywords
984 isIdentifierStart: function (cp) {
985 return (cp === 0x24) || (cp === 0x5F) ||
986 (cp >= 0x41 && cp <= 0x5A) ||
987 (cp >= 0x61 && cp <= 0x7A) ||
989 ((cp >= 0x80) && Regex.NonAsciiIdentifierStart.test(exports.Character.fromCodePoint(cp)));
991 isIdentifierPart: function (cp) {
992 return (cp === 0x24) || (cp === 0x5F) ||
993 (cp >= 0x41 && cp <= 0x5A) ||
994 (cp >= 0x61 && cp <= 0x7A) ||
995 (cp >= 0x30 && cp <= 0x39) ||
997 ((cp >= 0x80) && Regex.NonAsciiIdentifierPart.test(exports.Character.fromCodePoint(cp)));
999 // https://tc39.github.io/ecma262/#sec-literals-numeric-literals
1000 isDecimalDigit: function (cp) {
1001 return (cp >= 0x30 && cp <= 0x39); // 0..9
1003 isHexDigit: function (cp) {
1004 return (cp >= 0x30 && cp <= 0x39) ||
1005 (cp >= 0x41 && cp <= 0x46) ||
1006 (cp >= 0x61 && cp <= 0x66); // a..f
1008 isOctalDigit: function (cp) {
1009 return (cp >= 0x30 && cp <= 0x37); // 0..7
1016 /***/ function(module, exports, __webpack_require__) {
1019 Object.defineProperty(exports, "__esModule", { value: true });
1020 var jsx_syntax_1 = __webpack_require__(6);
1021 /* tslint:disable:max-classes-per-file */
1022 var JSXClosingElement = (function () {
1023 function JSXClosingElement(name) {
1024 this.type = jsx_syntax_1.JSXSyntax.JSXClosingElement;
1027 return JSXClosingElement;
1029 exports.JSXClosingElement = JSXClosingElement;
1030 var JSXElement = (function () {
1031 function JSXElement(openingElement, children, closingElement) {
1032 this.type = jsx_syntax_1.JSXSyntax.JSXElement;
1033 this.openingElement = openingElement;
1034 this.children = children;
1035 this.closingElement = closingElement;
1039 exports.JSXElement = JSXElement;
1040 var JSXEmptyExpression = (function () {
1041 function JSXEmptyExpression() {
1042 this.type = jsx_syntax_1.JSXSyntax.JSXEmptyExpression;
1044 return JSXEmptyExpression;
1046 exports.JSXEmptyExpression = JSXEmptyExpression;
1047 var JSXExpressionContainer = (function () {
1048 function JSXExpressionContainer(expression) {
1049 this.type = jsx_syntax_1.JSXSyntax.JSXExpressionContainer;
1050 this.expression = expression;
1052 return JSXExpressionContainer;
1054 exports.JSXExpressionContainer = JSXExpressionContainer;
1055 var JSXIdentifier = (function () {
1056 function JSXIdentifier(name) {
1057 this.type = jsx_syntax_1.JSXSyntax.JSXIdentifier;
1060 return JSXIdentifier;
1062 exports.JSXIdentifier = JSXIdentifier;
1063 var JSXMemberExpression = (function () {
1064 function JSXMemberExpression(object, property) {
1065 this.type = jsx_syntax_1.JSXSyntax.JSXMemberExpression;
1066 this.object = object;
1067 this.property = property;
1069 return JSXMemberExpression;
1071 exports.JSXMemberExpression = JSXMemberExpression;
1072 var JSXAttribute = (function () {
1073 function JSXAttribute(name, value) {
1074 this.type = jsx_syntax_1.JSXSyntax.JSXAttribute;
1078 return JSXAttribute;
1080 exports.JSXAttribute = JSXAttribute;
1081 var JSXNamespacedName = (function () {
1082 function JSXNamespacedName(namespace, name) {
1083 this.type = jsx_syntax_1.JSXSyntax.JSXNamespacedName;
1084 this.namespace = namespace;
1087 return JSXNamespacedName;
1089 exports.JSXNamespacedName = JSXNamespacedName;
1090 var JSXOpeningElement = (function () {
1091 function JSXOpeningElement(name, selfClosing, attributes) {
1092 this.type = jsx_syntax_1.JSXSyntax.JSXOpeningElement;
1094 this.selfClosing = selfClosing;
1095 this.attributes = attributes;
1097 return JSXOpeningElement;
1099 exports.JSXOpeningElement = JSXOpeningElement;
1100 var JSXSpreadAttribute = (function () {
1101 function JSXSpreadAttribute(argument) {
1102 this.type = jsx_syntax_1.JSXSyntax.JSXSpreadAttribute;
1103 this.argument = argument;
1105 return JSXSpreadAttribute;
1107 exports.JSXSpreadAttribute = JSXSpreadAttribute;
1108 var JSXText = (function () {
1109 function JSXText(value, raw) {
1110 this.type = jsx_syntax_1.JSXSyntax.JSXText;
1116 exports.JSXText = JSXText;
1121 /***/ function(module, exports) {
1124 Object.defineProperty(exports, "__esModule", { value: true });
1125 exports.JSXSyntax = {
1126 JSXAttribute: 'JSXAttribute',
1127 JSXClosingElement: 'JSXClosingElement',
1128 JSXElement: 'JSXElement',
1129 JSXEmptyExpression: 'JSXEmptyExpression',
1130 JSXExpressionContainer: 'JSXExpressionContainer',
1131 JSXIdentifier: 'JSXIdentifier',
1132 JSXMemberExpression: 'JSXMemberExpression',
1133 JSXNamespacedName: 'JSXNamespacedName',
1134 JSXOpeningElement: 'JSXOpeningElement',
1135 JSXSpreadAttribute: 'JSXSpreadAttribute',
1142 /***/ function(module, exports, __webpack_require__) {
1145 Object.defineProperty(exports, "__esModule", { value: true });
1146 var syntax_1 = __webpack_require__(2);
1147 /* tslint:disable:max-classes-per-file */
1148 var ArrayExpression = (function () {
1149 function ArrayExpression(elements) {
1150 this.type = syntax_1.Syntax.ArrayExpression;
1151 this.elements = elements;
1153 return ArrayExpression;
1155 exports.ArrayExpression = ArrayExpression;
1156 var ArrayPattern = (function () {
1157 function ArrayPattern(elements) {
1158 this.type = syntax_1.Syntax.ArrayPattern;
1159 this.elements = elements;
1161 return ArrayPattern;
1163 exports.ArrayPattern = ArrayPattern;
1164 var ArrowFunctionExpression = (function () {
1165 function ArrowFunctionExpression(params, body, expression) {
1166 this.type = syntax_1.Syntax.ArrowFunctionExpression;
1168 this.params = params;
1170 this.generator = false;
1171 this.expression = expression;
1174 return ArrowFunctionExpression;
1176 exports.ArrowFunctionExpression = ArrowFunctionExpression;
1177 var AssignmentExpression = (function () {
1178 function AssignmentExpression(operator, left, right) {
1179 this.type = syntax_1.Syntax.AssignmentExpression;
1180 this.operator = operator;
1184 return AssignmentExpression;
1186 exports.AssignmentExpression = AssignmentExpression;
1187 var AssignmentPattern = (function () {
1188 function AssignmentPattern(left, right) {
1189 this.type = syntax_1.Syntax.AssignmentPattern;
1193 return AssignmentPattern;
1195 exports.AssignmentPattern = AssignmentPattern;
1196 var AsyncArrowFunctionExpression = (function () {
1197 function AsyncArrowFunctionExpression(params, body, expression) {
1198 this.type = syntax_1.Syntax.ArrowFunctionExpression;
1200 this.params = params;
1202 this.generator = false;
1203 this.expression = expression;
1206 return AsyncArrowFunctionExpression;
1208 exports.AsyncArrowFunctionExpression = AsyncArrowFunctionExpression;
1209 var AsyncFunctionDeclaration = (function () {
1210 function AsyncFunctionDeclaration(id, params, body) {
1211 this.type = syntax_1.Syntax.FunctionDeclaration;
1213 this.params = params;
1215 this.generator = false;
1216 this.expression = false;
1219 return AsyncFunctionDeclaration;
1221 exports.AsyncFunctionDeclaration = AsyncFunctionDeclaration;
1222 var AsyncFunctionExpression = (function () {
1223 function AsyncFunctionExpression(id, params, body) {
1224 this.type = syntax_1.Syntax.FunctionExpression;
1226 this.params = params;
1228 this.generator = false;
1229 this.expression = false;
1232 return AsyncFunctionExpression;
1234 exports.AsyncFunctionExpression = AsyncFunctionExpression;
1235 var AwaitExpression = (function () {
1236 function AwaitExpression(argument) {
1237 this.type = syntax_1.Syntax.AwaitExpression;
1238 this.argument = argument;
1240 return AwaitExpression;
1242 exports.AwaitExpression = AwaitExpression;
1243 var BinaryExpression = (function () {
1244 function BinaryExpression(operator, left, right) {
1245 var logical = (operator === '||' || operator === '&&');
1246 this.type = logical ? syntax_1.Syntax.LogicalExpression : syntax_1.Syntax.BinaryExpression;
1247 this.operator = operator;
1251 return BinaryExpression;
1253 exports.BinaryExpression = BinaryExpression;
1254 var BlockStatement = (function () {
1255 function BlockStatement(body) {
1256 this.type = syntax_1.Syntax.BlockStatement;
1259 return BlockStatement;
1261 exports.BlockStatement = BlockStatement;
1262 var BreakStatement = (function () {
1263 function BreakStatement(label) {
1264 this.type = syntax_1.Syntax.BreakStatement;
1267 return BreakStatement;
1269 exports.BreakStatement = BreakStatement;
1270 var CallExpression = (function () {
1271 function CallExpression(callee, args) {
1272 this.type = syntax_1.Syntax.CallExpression;
1273 this.callee = callee;
1274 this.arguments = args;
1276 return CallExpression;
1278 exports.CallExpression = CallExpression;
1279 var CatchClause = (function () {
1280 function CatchClause(param, body) {
1281 this.type = syntax_1.Syntax.CatchClause;
1287 exports.CatchClause = CatchClause;
1288 var ClassBody = (function () {
1289 function ClassBody(body) {
1290 this.type = syntax_1.Syntax.ClassBody;
1295 exports.ClassBody = ClassBody;
1296 var ClassDeclaration = (function () {
1297 function ClassDeclaration(id, superClass, body) {
1298 this.type = syntax_1.Syntax.ClassDeclaration;
1300 this.superClass = superClass;
1303 return ClassDeclaration;
1305 exports.ClassDeclaration = ClassDeclaration;
1306 var ClassExpression = (function () {
1307 function ClassExpression(id, superClass, body) {
1308 this.type = syntax_1.Syntax.ClassExpression;
1310 this.superClass = superClass;
1313 return ClassExpression;
1315 exports.ClassExpression = ClassExpression;
1316 var ComputedMemberExpression = (function () {
1317 function ComputedMemberExpression(object, property) {
1318 this.type = syntax_1.Syntax.MemberExpression;
1319 this.computed = true;
1320 this.object = object;
1321 this.property = property;
1323 return ComputedMemberExpression;
1325 exports.ComputedMemberExpression = ComputedMemberExpression;
1326 var ConditionalExpression = (function () {
1327 function ConditionalExpression(test, consequent, alternate) {
1328 this.type = syntax_1.Syntax.ConditionalExpression;
1330 this.consequent = consequent;
1331 this.alternate = alternate;
1333 return ConditionalExpression;
1335 exports.ConditionalExpression = ConditionalExpression;
1336 var ContinueStatement = (function () {
1337 function ContinueStatement(label) {
1338 this.type = syntax_1.Syntax.ContinueStatement;
1341 return ContinueStatement;
1343 exports.ContinueStatement = ContinueStatement;
1344 var DebuggerStatement = (function () {
1345 function DebuggerStatement() {
1346 this.type = syntax_1.Syntax.DebuggerStatement;
1348 return DebuggerStatement;
1350 exports.DebuggerStatement = DebuggerStatement;
1351 var Directive = (function () {
1352 function Directive(expression, directive) {
1353 this.type = syntax_1.Syntax.ExpressionStatement;
1354 this.expression = expression;
1355 this.directive = directive;
1359 exports.Directive = Directive;
1360 var DoWhileStatement = (function () {
1361 function DoWhileStatement(body, test) {
1362 this.type = syntax_1.Syntax.DoWhileStatement;
1366 return DoWhileStatement;
1368 exports.DoWhileStatement = DoWhileStatement;
1369 var EmptyStatement = (function () {
1370 function EmptyStatement() {
1371 this.type = syntax_1.Syntax.EmptyStatement;
1373 return EmptyStatement;
1375 exports.EmptyStatement = EmptyStatement;
1376 var ExportAllDeclaration = (function () {
1377 function ExportAllDeclaration(source) {
1378 this.type = syntax_1.Syntax.ExportAllDeclaration;
1379 this.source = source;
1381 return ExportAllDeclaration;
1383 exports.ExportAllDeclaration = ExportAllDeclaration;
1384 var ExportDefaultDeclaration = (function () {
1385 function ExportDefaultDeclaration(declaration) {
1386 this.type = syntax_1.Syntax.ExportDefaultDeclaration;
1387 this.declaration = declaration;
1389 return ExportDefaultDeclaration;
1391 exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
1392 var ExportNamedDeclaration = (function () {
1393 function ExportNamedDeclaration(declaration, specifiers, source) {
1394 this.type = syntax_1.Syntax.ExportNamedDeclaration;
1395 this.declaration = declaration;
1396 this.specifiers = specifiers;
1397 this.source = source;
1399 return ExportNamedDeclaration;
1401 exports.ExportNamedDeclaration = ExportNamedDeclaration;
1402 var ExportSpecifier = (function () {
1403 function ExportSpecifier(local, exported) {
1404 this.type = syntax_1.Syntax.ExportSpecifier;
1405 this.exported = exported;
1408 return ExportSpecifier;
1410 exports.ExportSpecifier = ExportSpecifier;
1411 var ExpressionStatement = (function () {
1412 function ExpressionStatement(expression) {
1413 this.type = syntax_1.Syntax.ExpressionStatement;
1414 this.expression = expression;
1416 return ExpressionStatement;
1418 exports.ExpressionStatement = ExpressionStatement;
1419 var ForInStatement = (function () {
1420 function ForInStatement(left, right, body) {
1421 this.type = syntax_1.Syntax.ForInStatement;
1427 return ForInStatement;
1429 exports.ForInStatement = ForInStatement;
1430 var ForOfStatement = (function () {
1431 function ForOfStatement(left, right, body) {
1432 this.type = syntax_1.Syntax.ForOfStatement;
1437 return ForOfStatement;
1439 exports.ForOfStatement = ForOfStatement;
1440 var ForStatement = (function () {
1441 function ForStatement(init, test, update, body) {
1442 this.type = syntax_1.Syntax.ForStatement;
1445 this.update = update;
1448 return ForStatement;
1450 exports.ForStatement = ForStatement;
1451 var FunctionDeclaration = (function () {
1452 function FunctionDeclaration(id, params, body, generator) {
1453 this.type = syntax_1.Syntax.FunctionDeclaration;
1455 this.params = params;
1457 this.generator = generator;
1458 this.expression = false;
1461 return FunctionDeclaration;
1463 exports.FunctionDeclaration = FunctionDeclaration;
1464 var FunctionExpression = (function () {
1465 function FunctionExpression(id, params, body, generator) {
1466 this.type = syntax_1.Syntax.FunctionExpression;
1468 this.params = params;
1470 this.generator = generator;
1471 this.expression = false;
1474 return FunctionExpression;
1476 exports.FunctionExpression = FunctionExpression;
1477 var Identifier = (function () {
1478 function Identifier(name) {
1479 this.type = syntax_1.Syntax.Identifier;
1484 exports.Identifier = Identifier;
1485 var IfStatement = (function () {
1486 function IfStatement(test, consequent, alternate) {
1487 this.type = syntax_1.Syntax.IfStatement;
1489 this.consequent = consequent;
1490 this.alternate = alternate;
1494 exports.IfStatement = IfStatement;
1495 var ImportDeclaration = (function () {
1496 function ImportDeclaration(specifiers, source) {
1497 this.type = syntax_1.Syntax.ImportDeclaration;
1498 this.specifiers = specifiers;
1499 this.source = source;
1501 return ImportDeclaration;
1503 exports.ImportDeclaration = ImportDeclaration;
1504 var ImportDefaultSpecifier = (function () {
1505 function ImportDefaultSpecifier(local) {
1506 this.type = syntax_1.Syntax.ImportDefaultSpecifier;
1509 return ImportDefaultSpecifier;
1511 exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
1512 var ImportNamespaceSpecifier = (function () {
1513 function ImportNamespaceSpecifier(local) {
1514 this.type = syntax_1.Syntax.ImportNamespaceSpecifier;
1517 return ImportNamespaceSpecifier;
1519 exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
1520 var ImportSpecifier = (function () {
1521 function ImportSpecifier(local, imported) {
1522 this.type = syntax_1.Syntax.ImportSpecifier;
1524 this.imported = imported;
1526 return ImportSpecifier;
1528 exports.ImportSpecifier = ImportSpecifier;
1529 var LabeledStatement = (function () {
1530 function LabeledStatement(label, body) {
1531 this.type = syntax_1.Syntax.LabeledStatement;
1535 return LabeledStatement;
1537 exports.LabeledStatement = LabeledStatement;
1538 var Literal = (function () {
1539 function Literal(value, raw) {
1540 this.type = syntax_1.Syntax.Literal;
1546 exports.Literal = Literal;
1547 var MetaProperty = (function () {
1548 function MetaProperty(meta, property) {
1549 this.type = syntax_1.Syntax.MetaProperty;
1551 this.property = property;
1553 return MetaProperty;
1555 exports.MetaProperty = MetaProperty;
1556 var MethodDefinition = (function () {
1557 function MethodDefinition(key, computed, value, kind, isStatic) {
1558 this.type = syntax_1.Syntax.MethodDefinition;
1560 this.computed = computed;
1563 this.static = isStatic;
1565 return MethodDefinition;
1567 exports.MethodDefinition = MethodDefinition;
1568 var Module = (function () {
1569 function Module(body) {
1570 this.type = syntax_1.Syntax.Program;
1572 this.sourceType = 'module';
1576 exports.Module = Module;
1577 var NewExpression = (function () {
1578 function NewExpression(callee, args) {
1579 this.type = syntax_1.Syntax.NewExpression;
1580 this.callee = callee;
1581 this.arguments = args;
1583 return NewExpression;
1585 exports.NewExpression = NewExpression;
1586 var ObjectExpression = (function () {
1587 function ObjectExpression(properties) {
1588 this.type = syntax_1.Syntax.ObjectExpression;
1589 this.properties = properties;
1591 return ObjectExpression;
1593 exports.ObjectExpression = ObjectExpression;
1594 var ObjectPattern = (function () {
1595 function ObjectPattern(properties) {
1596 this.type = syntax_1.Syntax.ObjectPattern;
1597 this.properties = properties;
1599 return ObjectPattern;
1601 exports.ObjectPattern = ObjectPattern;
1602 var Property = (function () {
1603 function Property(kind, key, computed, value, method, shorthand) {
1604 this.type = syntax_1.Syntax.Property;
1606 this.computed = computed;
1609 this.method = method;
1610 this.shorthand = shorthand;
1614 exports.Property = Property;
1615 var RegexLiteral = (function () {
1616 function RegexLiteral(value, raw, pattern, flags) {
1617 this.type = syntax_1.Syntax.Literal;
1620 this.regex = { pattern: pattern, flags: flags };
1622 return RegexLiteral;
1624 exports.RegexLiteral = RegexLiteral;
1625 var RestElement = (function () {
1626 function RestElement(argument) {
1627 this.type = syntax_1.Syntax.RestElement;
1628 this.argument = argument;
1632 exports.RestElement = RestElement;
1633 var ReturnStatement = (function () {
1634 function ReturnStatement(argument) {
1635 this.type = syntax_1.Syntax.ReturnStatement;
1636 this.argument = argument;
1638 return ReturnStatement;
1640 exports.ReturnStatement = ReturnStatement;
1641 var Script = (function () {
1642 function Script(body) {
1643 this.type = syntax_1.Syntax.Program;
1645 this.sourceType = 'script';
1649 exports.Script = Script;
1650 var SequenceExpression = (function () {
1651 function SequenceExpression(expressions) {
1652 this.type = syntax_1.Syntax.SequenceExpression;
1653 this.expressions = expressions;
1655 return SequenceExpression;
1657 exports.SequenceExpression = SequenceExpression;
1658 var SpreadElement = (function () {
1659 function SpreadElement(argument) {
1660 this.type = syntax_1.Syntax.SpreadElement;
1661 this.argument = argument;
1663 return SpreadElement;
1665 exports.SpreadElement = SpreadElement;
1666 var StaticMemberExpression = (function () {
1667 function StaticMemberExpression(object, property) {
1668 this.type = syntax_1.Syntax.MemberExpression;
1669 this.computed = false;
1670 this.object = object;
1671 this.property = property;
1673 return StaticMemberExpression;
1675 exports.StaticMemberExpression = StaticMemberExpression;
1676 var Super = (function () {
1678 this.type = syntax_1.Syntax.Super;
1682 exports.Super = Super;
1683 var SwitchCase = (function () {
1684 function SwitchCase(test, consequent) {
1685 this.type = syntax_1.Syntax.SwitchCase;
1687 this.consequent = consequent;
1691 exports.SwitchCase = SwitchCase;
1692 var SwitchStatement = (function () {
1693 function SwitchStatement(discriminant, cases) {
1694 this.type = syntax_1.Syntax.SwitchStatement;
1695 this.discriminant = discriminant;
1698 return SwitchStatement;
1700 exports.SwitchStatement = SwitchStatement;
1701 var TaggedTemplateExpression = (function () {
1702 function TaggedTemplateExpression(tag, quasi) {
1703 this.type = syntax_1.Syntax.TaggedTemplateExpression;
1707 return TaggedTemplateExpression;
1709 exports.TaggedTemplateExpression = TaggedTemplateExpression;
1710 var TemplateElement = (function () {
1711 function TemplateElement(value, tail) {
1712 this.type = syntax_1.Syntax.TemplateElement;
1716 return TemplateElement;
1718 exports.TemplateElement = TemplateElement;
1719 var TemplateLiteral = (function () {
1720 function TemplateLiteral(quasis, expressions) {
1721 this.type = syntax_1.Syntax.TemplateLiteral;
1722 this.quasis = quasis;
1723 this.expressions = expressions;
1725 return TemplateLiteral;
1727 exports.TemplateLiteral = TemplateLiteral;
1728 var ThisExpression = (function () {
1729 function ThisExpression() {
1730 this.type = syntax_1.Syntax.ThisExpression;
1732 return ThisExpression;
1734 exports.ThisExpression = ThisExpression;
1735 var ThrowStatement = (function () {
1736 function ThrowStatement(argument) {
1737 this.type = syntax_1.Syntax.ThrowStatement;
1738 this.argument = argument;
1740 return ThrowStatement;
1742 exports.ThrowStatement = ThrowStatement;
1743 var TryStatement = (function () {
1744 function TryStatement(block, handler, finalizer) {
1745 this.type = syntax_1.Syntax.TryStatement;
1747 this.handler = handler;
1748 this.finalizer = finalizer;
1750 return TryStatement;
1752 exports.TryStatement = TryStatement;
1753 var UnaryExpression = (function () {
1754 function UnaryExpression(operator, argument) {
1755 this.type = syntax_1.Syntax.UnaryExpression;
1756 this.operator = operator;
1757 this.argument = argument;
1760 return UnaryExpression;
1762 exports.UnaryExpression = UnaryExpression;
1763 var UpdateExpression = (function () {
1764 function UpdateExpression(operator, argument, prefix) {
1765 this.type = syntax_1.Syntax.UpdateExpression;
1766 this.operator = operator;
1767 this.argument = argument;
1768 this.prefix = prefix;
1770 return UpdateExpression;
1772 exports.UpdateExpression = UpdateExpression;
1773 var VariableDeclaration = (function () {
1774 function VariableDeclaration(declarations, kind) {
1775 this.type = syntax_1.Syntax.VariableDeclaration;
1776 this.declarations = declarations;
1779 return VariableDeclaration;
1781 exports.VariableDeclaration = VariableDeclaration;
1782 var VariableDeclarator = (function () {
1783 function VariableDeclarator(id, init) {
1784 this.type = syntax_1.Syntax.VariableDeclarator;
1788 return VariableDeclarator;
1790 exports.VariableDeclarator = VariableDeclarator;
1791 var WhileStatement = (function () {
1792 function WhileStatement(test, body) {
1793 this.type = syntax_1.Syntax.WhileStatement;
1797 return WhileStatement;
1799 exports.WhileStatement = WhileStatement;
1800 var WithStatement = (function () {
1801 function WithStatement(object, body) {
1802 this.type = syntax_1.Syntax.WithStatement;
1803 this.object = object;
1806 return WithStatement;
1808 exports.WithStatement = WithStatement;
1809 var YieldExpression = (function () {
1810 function YieldExpression(argument, delegate) {
1811 this.type = syntax_1.Syntax.YieldExpression;
1812 this.argument = argument;
1813 this.delegate = delegate;
1815 return YieldExpression;
1817 exports.YieldExpression = YieldExpression;
1822 /***/ function(module, exports, __webpack_require__) {
1825 Object.defineProperty(exports, "__esModule", { value: true });
1826 var assert_1 = __webpack_require__(9);
1827 var error_handler_1 = __webpack_require__(10);
1828 var messages_1 = __webpack_require__(11);
1829 var Node = __webpack_require__(7);
1830 var scanner_1 = __webpack_require__(12);
1831 var syntax_1 = __webpack_require__(2);
1832 var token_1 = __webpack_require__(13);
1833 var ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder';
1834 var Parser = (function () {
1835 function Parser(code, options, delegate) {
1836 if (options === void 0) { options = {}; }
1838 range: (typeof options.range === 'boolean') && options.range,
1839 loc: (typeof options.loc === 'boolean') && options.loc,
1841 tokens: (typeof options.tokens === 'boolean') && options.tokens,
1842 comment: (typeof options.comment === 'boolean') && options.comment,
1843 tolerant: (typeof options.tolerant === 'boolean') && options.tolerant
1845 if (this.config.loc && options.source && options.source !== null) {
1846 this.config.source = String(options.source);
1848 this.delegate = delegate;
1849 this.errorHandler = new error_handler_1.ErrorHandler();
1850 this.errorHandler.tolerant = this.config.tolerant;
1851 this.scanner = new scanner_1.Scanner(code, this.errorHandler);
1852 this.scanner.trackComment = this.config.comment;
1853 this.operatorPrecedence = {
1884 lineNumber: this.scanner.lineNumber,
1889 this.hasLineTerminator = false;
1894 allowStrictDirective: true,
1896 firstCoverInitializedNameError: null,
1897 isAssignmentTarget: false,
1898 isBindingElement: false,
1899 inFunctionBody: false,
1906 this.startMarker = {
1908 line: this.scanner.lineNumber,
1913 line: this.scanner.lineNumber,
1918 index: this.scanner.index,
1919 line: this.scanner.lineNumber,
1920 column: this.scanner.index - this.scanner.lineStart
1923 Parser.prototype.throwError = function (messageFormat) {
1925 for (var _i = 1; _i < arguments.length; _i++) {
1926 values[_i - 1] = arguments[_i];
1928 var args = Array.prototype.slice.call(arguments, 1);
1929 var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
1930 assert_1.assert(idx < args.length, 'Message reference must be in range');
1933 var index = this.lastMarker.index;
1934 var line = this.lastMarker.line;
1935 var column = this.lastMarker.column + 1;
1936 throw this.errorHandler.createError(index, line, column, msg);
1938 Parser.prototype.tolerateError = function (messageFormat) {
1940 for (var _i = 1; _i < arguments.length; _i++) {
1941 values[_i - 1] = arguments[_i];
1943 var args = Array.prototype.slice.call(arguments, 1);
1944 var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
1945 assert_1.assert(idx < args.length, 'Message reference must be in range');
1948 var index = this.lastMarker.index;
1949 var line = this.scanner.lineNumber;
1950 var column = this.lastMarker.column + 1;
1951 this.errorHandler.tolerateError(index, line, column, msg);
1953 // Throw an exception because of the token.
1954 Parser.prototype.unexpectedTokenError = function (token, message) {
1955 var msg = message || messages_1.Messages.UnexpectedToken;
1959 msg = (token.type === 2 /* EOF */) ? messages_1.Messages.UnexpectedEOS :
1960 (token.type === 3 /* Identifier */) ? messages_1.Messages.UnexpectedIdentifier :
1961 (token.type === 6 /* NumericLiteral */) ? messages_1.Messages.UnexpectedNumber :
1962 (token.type === 8 /* StringLiteral */) ? messages_1.Messages.UnexpectedString :
1963 (token.type === 10 /* Template */) ? messages_1.Messages.UnexpectedTemplate :
1964 messages_1.Messages.UnexpectedToken;
1965 if (token.type === 4 /* Keyword */) {
1966 if (this.scanner.isFutureReservedWord(token.value)) {
1967 msg = messages_1.Messages.UnexpectedReserved;
1969 else if (this.context.strict && this.scanner.isStrictModeReservedWord(token.value)) {
1970 msg = messages_1.Messages.StrictReservedWord;
1974 value = token.value;
1979 msg = msg.replace('%0', value);
1980 if (token && typeof token.lineNumber === 'number') {
1981 var index = token.start;
1982 var line = token.lineNumber;
1983 var lastMarkerLineStart = this.lastMarker.index - this.lastMarker.column;
1984 var column = token.start - lastMarkerLineStart + 1;
1985 return this.errorHandler.createError(index, line, column, msg);
1988 var index = this.lastMarker.index;
1989 var line = this.lastMarker.line;
1990 var column = this.lastMarker.column + 1;
1991 return this.errorHandler.createError(index, line, column, msg);
1994 Parser.prototype.throwUnexpectedToken = function (token, message) {
1995 throw this.unexpectedTokenError(token, message);
1997 Parser.prototype.tolerateUnexpectedToken = function (token, message) {
1998 this.errorHandler.tolerate(this.unexpectedTokenError(token, message));
2000 Parser.prototype.collectComments = function () {
2001 if (!this.config.comment) {
2002 this.scanner.scanComments();
2005 var comments = this.scanner.scanComments();
2006 if (comments.length > 0 && this.delegate) {
2007 for (var i = 0; i < comments.length; ++i) {
2008 var e = comments[i];
2011 type: e.multiLine ? 'BlockComment' : 'LineComment',
2012 value: this.scanner.source.slice(e.slice[0], e.slice[1])
2014 if (this.config.range) {
2015 node.range = e.range;
2017 if (this.config.loc) {
2022 line: e.loc.start.line,
2023 column: e.loc.start.column,
2027 line: e.loc.end.line,
2028 column: e.loc.end.column,
2032 this.delegate(node, metadata);
2037 // From internal representation to an external structure
2038 Parser.prototype.getTokenRaw = function (token) {
2039 return this.scanner.source.slice(token.start, token.end);
2041 Parser.prototype.convertToken = function (token) {
2043 type: token_1.TokenName[token.type],
2044 value: this.getTokenRaw(token)
2046 if (this.config.range) {
2047 t.range = [token.start, token.end];
2049 if (this.config.loc) {
2052 line: this.startMarker.line,
2053 column: this.startMarker.column
2056 line: this.scanner.lineNumber,
2057 column: this.scanner.index - this.scanner.lineStart
2061 if (token.type === 9 /* RegularExpression */) {
2062 var pattern = token.pattern;
2063 var flags = token.flags;
2064 t.regex = { pattern: pattern, flags: flags };
2068 Parser.prototype.nextToken = function () {
2069 var token = this.lookahead;
2070 this.lastMarker.index = this.scanner.index;
2071 this.lastMarker.line = this.scanner.lineNumber;
2072 this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
2073 this.collectComments();
2074 if (this.scanner.index !== this.startMarker.index) {
2075 this.startMarker.index = this.scanner.index;
2076 this.startMarker.line = this.scanner.lineNumber;
2077 this.startMarker.column = this.scanner.index - this.scanner.lineStart;
2079 var next = this.scanner.lex();
2080 this.hasLineTerminator = (token.lineNumber !== next.lineNumber);
2081 if (next && this.context.strict && next.type === 3 /* Identifier */) {
2082 if (this.scanner.isStrictModeReservedWord(next.value)) {
2083 next.type = 4 /* Keyword */;
2086 this.lookahead = next;
2087 if (this.config.tokens && next.type !== 2 /* EOF */) {
2088 this.tokens.push(this.convertToken(next));
2092 Parser.prototype.nextRegexToken = function () {
2093 this.collectComments();
2094 var token = this.scanner.scanRegExp();
2095 if (this.config.tokens) {
2096 // Pop the previous token, '/' or '/='
2097 // This is added from the lookahead token.
2099 this.tokens.push(this.convertToken(token));
2101 // Prime the next lookahead.
2102 this.lookahead = token;
2106 Parser.prototype.createNode = function () {
2108 index: this.startMarker.index,
2109 line: this.startMarker.line,
2110 column: this.startMarker.column
2113 Parser.prototype.startNode = function (token, lastLineStart) {
2114 if (lastLineStart === void 0) { lastLineStart = 0; }
2115 var column = token.start - token.lineStart;
2116 var line = token.lineNumber;
2118 column += lastLineStart;
2127 Parser.prototype.finalize = function (marker, node) {
2128 if (this.config.range) {
2129 node.range = [marker.index, this.lastMarker.index];
2131 if (this.config.loc) {
2135 column: marker.column,
2138 line: this.lastMarker.line,
2139 column: this.lastMarker.column
2142 if (this.config.source) {
2143 node.loc.source = this.config.source;
2146 if (this.delegate) {
2150 column: marker.column,
2151 offset: marker.index
2154 line: this.lastMarker.line,
2155 column: this.lastMarker.column,
2156 offset: this.lastMarker.index
2159 this.delegate(node, metadata);
2163 // Expect the next token to match the specified punctuator.
2164 // If not, an exception will be thrown.
2165 Parser.prototype.expect = function (value) {
2166 var token = this.nextToken();
2167 if (token.type !== 7 /* Punctuator */ || token.value !== value) {
2168 this.throwUnexpectedToken(token);
2171 // Quietly expect a comma when in tolerant mode, otherwise delegates to expect().
2172 Parser.prototype.expectCommaSeparator = function () {
2173 if (this.config.tolerant) {
2174 var token = this.lookahead;
2175 if (token.type === 7 /* Punctuator */ && token.value === ',') {
2178 else if (token.type === 7 /* Punctuator */ && token.value === ';') {
2180 this.tolerateUnexpectedToken(token);
2183 this.tolerateUnexpectedToken(token, messages_1.Messages.UnexpectedToken);
2190 // Expect the next token to match the specified keyword.
2191 // If not, an exception will be thrown.
2192 Parser.prototype.expectKeyword = function (keyword) {
2193 var token = this.nextToken();
2194 if (token.type !== 4 /* Keyword */ || token.value !== keyword) {
2195 this.throwUnexpectedToken(token);
2198 // Return true if the next token matches the specified punctuator.
2199 Parser.prototype.match = function (value) {
2200 return this.lookahead.type === 7 /* Punctuator */ && this.lookahead.value === value;
2202 // Return true if the next token matches the specified keyword
2203 Parser.prototype.matchKeyword = function (keyword) {
2204 return this.lookahead.type === 4 /* Keyword */ && this.lookahead.value === keyword;
2206 // Return true if the next token matches the specified contextual keyword
2207 // (where an identifier is sometimes a keyword depending on the context)
2208 Parser.prototype.matchContextualKeyword = function (keyword) {
2209 return this.lookahead.type === 3 /* Identifier */ && this.lookahead.value === keyword;
2211 // Return true if the next token is an assignment operator
2212 Parser.prototype.matchAssign = function () {
2213 if (this.lookahead.type !== 7 /* Punctuator */) {
2216 var op = this.lookahead.value;
2217 return op === '=' ||
2231 // Cover grammar support.
2233 // When an assignment expression position starts with an left parenthesis, the determination of the type
2234 // of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
2235 // or the first comma. This situation also defers the determination of all the expressions nested in the pair.
2237 // There are three productions that can be parsed in a parentheses pair that needs to be determined
2238 // after the outermost pair is closed. They are:
2240 // 1. AssignmentExpression
2241 // 2. BindingElements
2242 // 3. AssignmentTargets
2244 // In order to avoid exponential backtracking, we use two flags to denote if the production can be
2245 // binding element or assignment target.
2247 // The three productions have the relationship:
2249 // BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
2251 // with a single exception that CoverInitializedName when used directly in an Expression, generates
2252 // an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
2253 // first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
2255 // isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
2256 // effect the current flags. This means the production the parser parses is only used as an expression. Therefore
2257 // the CoverInitializedName check is conducted.
2259 // inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
2260 // the flags outside of the parser. This means the production the parser parses is used as a part of a potential
2261 // pattern. The CoverInitializedName check is deferred.
2262 Parser.prototype.isolateCoverGrammar = function (parseFunction) {
2263 var previousIsBindingElement = this.context.isBindingElement;
2264 var previousIsAssignmentTarget = this.context.isAssignmentTarget;
2265 var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
2266 this.context.isBindingElement = true;
2267 this.context.isAssignmentTarget = true;
2268 this.context.firstCoverInitializedNameError = null;
2269 var result = parseFunction.call(this);
2270 if (this.context.firstCoverInitializedNameError !== null) {
2271 this.throwUnexpectedToken(this.context.firstCoverInitializedNameError);
2273 this.context.isBindingElement = previousIsBindingElement;
2274 this.context.isAssignmentTarget = previousIsAssignmentTarget;
2275 this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError;
2278 Parser.prototype.inheritCoverGrammar = function (parseFunction) {
2279 var previousIsBindingElement = this.context.isBindingElement;
2280 var previousIsAssignmentTarget = this.context.isAssignmentTarget;
2281 var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
2282 this.context.isBindingElement = true;
2283 this.context.isAssignmentTarget = true;
2284 this.context.firstCoverInitializedNameError = null;
2285 var result = parseFunction.call(this);
2286 this.context.isBindingElement = this.context.isBindingElement && previousIsBindingElement;
2287 this.context.isAssignmentTarget = this.context.isAssignmentTarget && previousIsAssignmentTarget;
2288 this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError || this.context.firstCoverInitializedNameError;
2291 Parser.prototype.consumeSemicolon = function () {
2292 if (this.match(';')) {
2295 else if (!this.hasLineTerminator) {
2296 if (this.lookahead.type !== 2 /* EOF */ && !this.match('}')) {
2297 this.throwUnexpectedToken(this.lookahead);
2299 this.lastMarker.index = this.startMarker.index;
2300 this.lastMarker.line = this.startMarker.line;
2301 this.lastMarker.column = this.startMarker.column;
2304 // https://tc39.github.io/ecma262/#sec-primary-expression
2305 Parser.prototype.parsePrimaryExpression = function () {
2306 var node = this.createNode();
2309 switch (this.lookahead.type) {
2310 case 3 /* Identifier */:
2311 if ((this.context.isModule || this.context.await) && this.lookahead.value === 'await') {
2312 this.tolerateUnexpectedToken(this.lookahead);
2314 expr = this.matchAsyncFunction() ? this.parseFunctionExpression() : this.finalize(node, new Node.Identifier(this.nextToken().value));
2316 case 6 /* NumericLiteral */:
2317 case 8 /* StringLiteral */:
2318 if (this.context.strict && this.lookahead.octal) {
2319 this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.StrictOctalLiteral);
2321 this.context.isAssignmentTarget = false;
2322 this.context.isBindingElement = false;
2323 token = this.nextToken();
2324 raw = this.getTokenRaw(token);
2325 expr = this.finalize(node, new Node.Literal(token.value, raw));
2327 case 1 /* BooleanLiteral */:
2328 this.context.isAssignmentTarget = false;
2329 this.context.isBindingElement = false;
2330 token = this.nextToken();
2331 raw = this.getTokenRaw(token);
2332 expr = this.finalize(node, new Node.Literal(token.value === 'true', raw));
2334 case 5 /* NullLiteral */:
2335 this.context.isAssignmentTarget = false;
2336 this.context.isBindingElement = false;
2337 token = this.nextToken();
2338 raw = this.getTokenRaw(token);
2339 expr = this.finalize(node, new Node.Literal(null, raw));
2341 case 10 /* Template */:
2342 expr = this.parseTemplateLiteral();
2344 case 7 /* Punctuator */:
2345 switch (this.lookahead.value) {
2347 this.context.isBindingElement = false;
2348 expr = this.inheritCoverGrammar(this.parseGroupExpression);
2351 expr = this.inheritCoverGrammar(this.parseArrayInitializer);
2354 expr = this.inheritCoverGrammar(this.parseObjectInitializer);
2358 this.context.isAssignmentTarget = false;
2359 this.context.isBindingElement = false;
2360 this.scanner.index = this.startMarker.index;
2361 token = this.nextRegexToken();
2362 raw = this.getTokenRaw(token);
2363 expr = this.finalize(node, new Node.RegexLiteral(token.regex, raw, token.pattern, token.flags));
2366 expr = this.throwUnexpectedToken(this.nextToken());
2369 case 4 /* Keyword */:
2370 if (!this.context.strict && this.context.allowYield && this.matchKeyword('yield')) {
2371 expr = this.parseIdentifierName();
2373 else if (!this.context.strict && this.matchKeyword('let')) {
2374 expr = this.finalize(node, new Node.Identifier(this.nextToken().value));
2377 this.context.isAssignmentTarget = false;
2378 this.context.isBindingElement = false;
2379 if (this.matchKeyword('function')) {
2380 expr = this.parseFunctionExpression();
2382 else if (this.matchKeyword('this')) {
2384 expr = this.finalize(node, new Node.ThisExpression());
2386 else if (this.matchKeyword('class')) {
2387 expr = this.parseClassExpression();
2390 expr = this.throwUnexpectedToken(this.nextToken());
2395 expr = this.throwUnexpectedToken(this.nextToken());
2399 // https://tc39.github.io/ecma262/#sec-array-initializer
2400 Parser.prototype.parseSpreadElement = function () {
2401 var node = this.createNode();
2403 var arg = this.inheritCoverGrammar(this.parseAssignmentExpression);
2404 return this.finalize(node, new Node.SpreadElement(arg));
2406 Parser.prototype.parseArrayInitializer = function () {
2407 var node = this.createNode();
2410 while (!this.match(']')) {
2411 if (this.match(',')) {
2413 elements.push(null);
2415 else if (this.match('...')) {
2416 var element = this.parseSpreadElement();
2417 if (!this.match(']')) {
2418 this.context.isAssignmentTarget = false;
2419 this.context.isBindingElement = false;
2422 elements.push(element);
2425 elements.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
2426 if (!this.match(']')) {
2432 return this.finalize(node, new Node.ArrayExpression(elements));
2434 // https://tc39.github.io/ecma262/#sec-object-initializer
2435 Parser.prototype.parsePropertyMethod = function (params) {
2436 this.context.isAssignmentTarget = false;
2437 this.context.isBindingElement = false;
2438 var previousStrict = this.context.strict;
2439 var previousAllowStrictDirective = this.context.allowStrictDirective;
2440 this.context.allowStrictDirective = params.simple;
2441 var body = this.isolateCoverGrammar(this.parseFunctionSourceElements);
2442 if (this.context.strict && params.firstRestricted) {
2443 this.tolerateUnexpectedToken(params.firstRestricted, params.message);
2445 if (this.context.strict && params.stricted) {
2446 this.tolerateUnexpectedToken(params.stricted, params.message);
2448 this.context.strict = previousStrict;
2449 this.context.allowStrictDirective = previousAllowStrictDirective;
2452 Parser.prototype.parsePropertyMethodFunction = function () {
2453 var isGenerator = false;
2454 var node = this.createNode();
2455 var previousAllowYield = this.context.allowYield;
2456 this.context.allowYield = true;
2457 var params = this.parseFormalParameters();
2458 var method = this.parsePropertyMethod(params);
2459 this.context.allowYield = previousAllowYield;
2460 return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
2462 Parser.prototype.parsePropertyMethodAsyncFunction = function () {
2463 var node = this.createNode();
2464 var previousAllowYield = this.context.allowYield;
2465 var previousAwait = this.context.await;
2466 this.context.allowYield = false;
2467 this.context.await = true;
2468 var params = this.parseFormalParameters();
2469 var method = this.parsePropertyMethod(params);
2470 this.context.allowYield = previousAllowYield;
2471 this.context.await = previousAwait;
2472 return this.finalize(node, new Node.AsyncFunctionExpression(null, params.params, method));
2474 Parser.prototype.parseObjectPropertyKey = function () {
2475 var node = this.createNode();
2476 var token = this.nextToken();
2478 switch (token.type) {
2479 case 8 /* StringLiteral */:
2480 case 6 /* NumericLiteral */:
2481 if (this.context.strict && token.octal) {
2482 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictOctalLiteral);
2484 var raw = this.getTokenRaw(token);
2485 key = this.finalize(node, new Node.Literal(token.value, raw));
2487 case 3 /* Identifier */:
2488 case 1 /* BooleanLiteral */:
2489 case 5 /* NullLiteral */:
2490 case 4 /* Keyword */:
2491 key = this.finalize(node, new Node.Identifier(token.value));
2493 case 7 /* Punctuator */:
2494 if (token.value === '[') {
2495 key = this.isolateCoverGrammar(this.parseAssignmentExpression);
2499 key = this.throwUnexpectedToken(token);
2503 key = this.throwUnexpectedToken(token);
2507 Parser.prototype.isPropertyKey = function (key, value) {
2508 return (key.type === syntax_1.Syntax.Identifier && key.name === value) ||
2509 (key.type === syntax_1.Syntax.Literal && key.value === value);
2511 Parser.prototype.parseObjectProperty = function (hasProto) {
2512 var node = this.createNode();
2513 var token = this.lookahead;
2517 var computed = false;
2519 var shorthand = false;
2520 var isAsync = false;
2521 if (token.type === 3 /* Identifier */) {
2522 var id = token.value;
2524 computed = this.match('[');
2525 isAsync = !this.hasLineTerminator && (id === 'async') &&
2526 !this.match(':') && !this.match('(') && !this.match('*') && !this.match(',');
2527 key = isAsync ? this.parseObjectPropertyKey() : this.finalize(node, new Node.Identifier(id));
2529 else if (this.match('*')) {
2533 computed = this.match('[');
2534 key = this.parseObjectPropertyKey();
2536 var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
2537 if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'get' && lookaheadPropertyKey) {
2539 computed = this.match('[');
2540 key = this.parseObjectPropertyKey();
2541 this.context.allowYield = false;
2542 value = this.parseGetterMethod();
2544 else if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'set' && lookaheadPropertyKey) {
2546 computed = this.match('[');
2547 key = this.parseObjectPropertyKey();
2548 value = this.parseSetterMethod();
2550 else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
2552 computed = this.match('[');
2553 key = this.parseObjectPropertyKey();
2554 value = this.parseGeneratorMethod();
2559 this.throwUnexpectedToken(this.lookahead);
2562 if (this.match(':') && !isAsync) {
2563 if (!computed && this.isPropertyKey(key, '__proto__')) {
2564 if (hasProto.value) {
2565 this.tolerateError(messages_1.Messages.DuplicateProtoProperty);
2567 hasProto.value = true;
2570 value = this.inheritCoverGrammar(this.parseAssignmentExpression);
2572 else if (this.match('(')) {
2573 value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
2576 else if (token.type === 3 /* Identifier */) {
2577 var id = this.finalize(node, new Node.Identifier(token.value));
2578 if (this.match('=')) {
2579 this.context.firstCoverInitializedNameError = this.lookahead;
2582 var init = this.isolateCoverGrammar(this.parseAssignmentExpression);
2583 value = this.finalize(node, new Node.AssignmentPattern(id, init));
2591 this.throwUnexpectedToken(this.nextToken());
2594 return this.finalize(node, new Node.Property(kind, key, computed, value, method, shorthand));
2596 Parser.prototype.parseObjectInitializer = function () {
2597 var node = this.createNode();
2599 var properties = [];
2600 var hasProto = { value: false };
2601 while (!this.match('}')) {
2602 properties.push(this.parseObjectProperty(hasProto));
2603 if (!this.match('}')) {
2604 this.expectCommaSeparator();
2608 return this.finalize(node, new Node.ObjectExpression(properties));
2610 // https://tc39.github.io/ecma262/#sec-template-literals
2611 Parser.prototype.parseTemplateHead = function () {
2612 assert_1.assert(this.lookahead.head, 'Template literal must start with a template head');
2613 var node = this.createNode();
2614 var token = this.nextToken();
2615 var raw = token.value;
2616 var cooked = token.cooked;
2617 return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
2619 Parser.prototype.parseTemplateElement = function () {
2620 if (this.lookahead.type !== 10 /* Template */) {
2621 this.throwUnexpectedToken();
2623 var node = this.createNode();
2624 var token = this.nextToken();
2625 var raw = token.value;
2626 var cooked = token.cooked;
2627 return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
2629 Parser.prototype.parseTemplateLiteral = function () {
2630 var node = this.createNode();
2631 var expressions = [];
2633 var quasi = this.parseTemplateHead();
2635 while (!quasi.tail) {
2636 expressions.push(this.parseExpression());
2637 quasi = this.parseTemplateElement();
2640 return this.finalize(node, new Node.TemplateLiteral(quasis, expressions));
2642 // https://tc39.github.io/ecma262/#sec-grouping-operator
2643 Parser.prototype.reinterpretExpressionAsPattern = function (expr) {
2644 switch (expr.type) {
2645 case syntax_1.Syntax.Identifier:
2646 case syntax_1.Syntax.MemberExpression:
2647 case syntax_1.Syntax.RestElement:
2648 case syntax_1.Syntax.AssignmentPattern:
2650 case syntax_1.Syntax.SpreadElement:
2651 expr.type = syntax_1.Syntax.RestElement;
2652 this.reinterpretExpressionAsPattern(expr.argument);
2654 case syntax_1.Syntax.ArrayExpression:
2655 expr.type = syntax_1.Syntax.ArrayPattern;
2656 for (var i = 0; i < expr.elements.length; i++) {
2657 if (expr.elements[i] !== null) {
2658 this.reinterpretExpressionAsPattern(expr.elements[i]);
2662 case syntax_1.Syntax.ObjectExpression:
2663 expr.type = syntax_1.Syntax.ObjectPattern;
2664 for (var i = 0; i < expr.properties.length; i++) {
2665 this.reinterpretExpressionAsPattern(expr.properties[i].value);
2668 case syntax_1.Syntax.AssignmentExpression:
2669 expr.type = syntax_1.Syntax.AssignmentPattern;
2670 delete expr.operator;
2671 this.reinterpretExpressionAsPattern(expr.left);
2674 // Allow other node type for tolerant parsing.
2678 Parser.prototype.parseGroupExpression = function () {
2681 if (this.match(')')) {
2683 if (!this.match('=>')) {
2687 type: ArrowParameterPlaceHolder,
2693 var startToken = this.lookahead;
2695 if (this.match('...')) {
2696 expr = this.parseRestElement(params);
2698 if (!this.match('=>')) {
2702 type: ArrowParameterPlaceHolder,
2709 this.context.isBindingElement = true;
2710 expr = this.inheritCoverGrammar(this.parseAssignmentExpression);
2711 if (this.match(',')) {
2712 var expressions = [];
2713 this.context.isAssignmentTarget = false;
2714 expressions.push(expr);
2715 while (this.lookahead.type !== 2 /* EOF */) {
2716 if (!this.match(',')) {
2720 if (this.match(')')) {
2722 for (var i = 0; i < expressions.length; i++) {
2723 this.reinterpretExpressionAsPattern(expressions[i]);
2727 type: ArrowParameterPlaceHolder,
2728 params: expressions,
2732 else if (this.match('...')) {
2733 if (!this.context.isBindingElement) {
2734 this.throwUnexpectedToken(this.lookahead);
2736 expressions.push(this.parseRestElement(params));
2738 if (!this.match('=>')) {
2741 this.context.isBindingElement = false;
2742 for (var i = 0; i < expressions.length; i++) {
2743 this.reinterpretExpressionAsPattern(expressions[i]);
2747 type: ArrowParameterPlaceHolder,
2748 params: expressions,
2753 expressions.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
2760 expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
2765 if (this.match('=>')) {
2766 if (expr.type === syntax_1.Syntax.Identifier && expr.name === 'yield') {
2769 type: ArrowParameterPlaceHolder,
2775 if (!this.context.isBindingElement) {
2776 this.throwUnexpectedToken(this.lookahead);
2778 if (expr.type === syntax_1.Syntax.SequenceExpression) {
2779 for (var i = 0; i < expr.expressions.length; i++) {
2780 this.reinterpretExpressionAsPattern(expr.expressions[i]);
2784 this.reinterpretExpressionAsPattern(expr);
2786 var parameters = (expr.type === syntax_1.Syntax.SequenceExpression ? expr.expressions : [expr]);
2788 type: ArrowParameterPlaceHolder,
2794 this.context.isBindingElement = false;
2800 // https://tc39.github.io/ecma262/#sec-left-hand-side-expressions
2801 Parser.prototype.parseArguments = function () {
2804 if (!this.match(')')) {
2806 var expr = this.match('...') ? this.parseSpreadElement() :
2807 this.isolateCoverGrammar(this.parseAssignmentExpression);
2809 if (this.match(')')) {
2812 this.expectCommaSeparator();
2813 if (this.match(')')) {
2821 Parser.prototype.isIdentifierName = function (token) {
2822 return token.type === 3 /* Identifier */ ||
2823 token.type === 4 /* Keyword */ ||
2824 token.type === 1 /* BooleanLiteral */ ||
2825 token.type === 5 /* NullLiteral */;
2827 Parser.prototype.parseIdentifierName = function () {
2828 var node = this.createNode();
2829 var token = this.nextToken();
2830 if (!this.isIdentifierName(token)) {
2831 this.throwUnexpectedToken(token);
2833 return this.finalize(node, new Node.Identifier(token.value));
2835 Parser.prototype.parseNewExpression = function () {
2836 var node = this.createNode();
2837 var id = this.parseIdentifierName();
2838 assert_1.assert(id.name === 'new', 'New expression must start with `new`');
2840 if (this.match('.')) {
2842 if (this.lookahead.type === 3 /* Identifier */ && this.context.inFunctionBody && this.lookahead.value === 'target') {
2843 var property = this.parseIdentifierName();
2844 expr = new Node.MetaProperty(id, property);
2847 this.throwUnexpectedToken(this.lookahead);
2851 var callee = this.isolateCoverGrammar(this.parseLeftHandSideExpression);
2852 var args = this.match('(') ? this.parseArguments() : [];
2853 expr = new Node.NewExpression(callee, args);
2854 this.context.isAssignmentTarget = false;
2855 this.context.isBindingElement = false;
2857 return this.finalize(node, expr);
2859 Parser.prototype.parseAsyncArgument = function () {
2860 var arg = this.parseAssignmentExpression();
2861 this.context.firstCoverInitializedNameError = null;
2864 Parser.prototype.parseAsyncArguments = function () {
2867 if (!this.match(')')) {
2869 var expr = this.match('...') ? this.parseSpreadElement() :
2870 this.isolateCoverGrammar(this.parseAsyncArgument);
2872 if (this.match(')')) {
2875 this.expectCommaSeparator();
2876 if (this.match(')')) {
2884 Parser.prototype.parseLeftHandSideExpressionAllowCall = function () {
2885 var startToken = this.lookahead;
2886 var maybeAsync = this.matchContextualKeyword('async');
2887 var previousAllowIn = this.context.allowIn;
2888 this.context.allowIn = true;
2890 if (this.matchKeyword('super') && this.context.inFunctionBody) {
2891 expr = this.createNode();
2893 expr = this.finalize(expr, new Node.Super());
2894 if (!this.match('(') && !this.match('.') && !this.match('[')) {
2895 this.throwUnexpectedToken(this.lookahead);
2899 expr = this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
2902 if (this.match('.')) {
2903 this.context.isBindingElement = false;
2904 this.context.isAssignmentTarget = true;
2906 var property = this.parseIdentifierName();
2907 expr = this.finalize(this.startNode(startToken), new Node.StaticMemberExpression(expr, property));
2909 else if (this.match('(')) {
2910 var asyncArrow = maybeAsync && (startToken.lineNumber === this.lookahead.lineNumber);
2911 this.context.isBindingElement = false;
2912 this.context.isAssignmentTarget = false;
2913 var args = asyncArrow ? this.parseAsyncArguments() : this.parseArguments();
2914 expr = this.finalize(this.startNode(startToken), new Node.CallExpression(expr, args));
2915 if (asyncArrow && this.match('=>')) {
2916 for (var i = 0; i < args.length; ++i) {
2917 this.reinterpretExpressionAsPattern(args[i]);
2920 type: ArrowParameterPlaceHolder,
2926 else if (this.match('[')) {
2927 this.context.isBindingElement = false;
2928 this.context.isAssignmentTarget = true;
2930 var property = this.isolateCoverGrammar(this.parseExpression);
2932 expr = this.finalize(this.startNode(startToken), new Node.ComputedMemberExpression(expr, property));
2934 else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
2935 var quasi = this.parseTemplateLiteral();
2936 expr = this.finalize(this.startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi));
2942 this.context.allowIn = previousAllowIn;
2945 Parser.prototype.parseSuper = function () {
2946 var node = this.createNode();
2947 this.expectKeyword('super');
2948 if (!this.match('[') && !this.match('.')) {
2949 this.throwUnexpectedToken(this.lookahead);
2951 return this.finalize(node, new Node.Super());
2953 Parser.prototype.parseLeftHandSideExpression = function () {
2954 assert_1.assert(this.context.allowIn, 'callee of new expression always allow in keyword.');
2955 var node = this.startNode(this.lookahead);
2956 var expr = (this.matchKeyword('super') && this.context.inFunctionBody) ? this.parseSuper() :
2957 this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
2959 if (this.match('[')) {
2960 this.context.isBindingElement = false;
2961 this.context.isAssignmentTarget = true;
2963 var property = this.isolateCoverGrammar(this.parseExpression);
2965 expr = this.finalize(node, new Node.ComputedMemberExpression(expr, property));
2967 else if (this.match('.')) {
2968 this.context.isBindingElement = false;
2969 this.context.isAssignmentTarget = true;
2971 var property = this.parseIdentifierName();
2972 expr = this.finalize(node, new Node.StaticMemberExpression(expr, property));
2974 else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
2975 var quasi = this.parseTemplateLiteral();
2976 expr = this.finalize(node, new Node.TaggedTemplateExpression(expr, quasi));
2984 // https://tc39.github.io/ecma262/#sec-update-expressions
2985 Parser.prototype.parseUpdateExpression = function () {
2987 var startToken = this.lookahead;
2988 if (this.match('++') || this.match('--')) {
2989 var node = this.startNode(startToken);
2990 var token = this.nextToken();
2991 expr = this.inheritCoverGrammar(this.parseUnaryExpression);
2992 if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
2993 this.tolerateError(messages_1.Messages.StrictLHSPrefix);
2995 if (!this.context.isAssignmentTarget) {
2996 this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
2999 expr = this.finalize(node, new Node.UpdateExpression(token.value, expr, prefix));
3000 this.context.isAssignmentTarget = false;
3001 this.context.isBindingElement = false;
3004 expr = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
3005 if (!this.hasLineTerminator && this.lookahead.type === 7 /* Punctuator */) {
3006 if (this.match('++') || this.match('--')) {
3007 if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
3008 this.tolerateError(messages_1.Messages.StrictLHSPostfix);
3010 if (!this.context.isAssignmentTarget) {
3011 this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
3013 this.context.isAssignmentTarget = false;
3014 this.context.isBindingElement = false;
3015 var operator = this.nextToken().value;
3017 expr = this.finalize(this.startNode(startToken), new Node.UpdateExpression(operator, expr, prefix));
3023 // https://tc39.github.io/ecma262/#sec-unary-operators
3024 Parser.prototype.parseAwaitExpression = function () {
3025 var node = this.createNode();
3027 var argument = this.parseUnaryExpression();
3028 return this.finalize(node, new Node.AwaitExpression(argument));
3030 Parser.prototype.parseUnaryExpression = function () {
3032 if (this.match('+') || this.match('-') || this.match('~') || this.match('!') ||
3033 this.matchKeyword('delete') || this.matchKeyword('void') || this.matchKeyword('typeof')) {
3034 var node = this.startNode(this.lookahead);
3035 var token = this.nextToken();
3036 expr = this.inheritCoverGrammar(this.parseUnaryExpression);
3037 expr = this.finalize(node, new Node.UnaryExpression(token.value, expr));
3038 if (this.context.strict && expr.operator === 'delete' && expr.argument.type === syntax_1.Syntax.Identifier) {
3039 this.tolerateError(messages_1.Messages.StrictDelete);
3041 this.context.isAssignmentTarget = false;
3042 this.context.isBindingElement = false;
3044 else if (this.context.await && this.matchContextualKeyword('await')) {
3045 expr = this.parseAwaitExpression();
3048 expr = this.parseUpdateExpression();
3052 Parser.prototype.parseExponentiationExpression = function () {
3053 var startToken = this.lookahead;
3054 var expr = this.inheritCoverGrammar(this.parseUnaryExpression);
3055 if (expr.type !== syntax_1.Syntax.UnaryExpression && this.match('**')) {
3057 this.context.isAssignmentTarget = false;
3058 this.context.isBindingElement = false;
3060 var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
3061 expr = this.finalize(this.startNode(startToken), new Node.BinaryExpression('**', left, right));
3065 // https://tc39.github.io/ecma262/#sec-exp-operator
3066 // https://tc39.github.io/ecma262/#sec-multiplicative-operators
3067 // https://tc39.github.io/ecma262/#sec-additive-operators
3068 // https://tc39.github.io/ecma262/#sec-bitwise-shift-operators
3069 // https://tc39.github.io/ecma262/#sec-relational-operators
3070 // https://tc39.github.io/ecma262/#sec-equality-operators
3071 // https://tc39.github.io/ecma262/#sec-binary-bitwise-operators
3072 // https://tc39.github.io/ecma262/#sec-binary-logical-operators
3073 Parser.prototype.binaryPrecedence = function (token) {
3074 var op = token.value;
3076 if (token.type === 7 /* Punctuator */) {
3077 precedence = this.operatorPrecedence[op] || 0;
3079 else if (token.type === 4 /* Keyword */) {
3080 precedence = (op === 'instanceof' || (this.context.allowIn && op === 'in')) ? 7 : 0;
3087 Parser.prototype.parseBinaryExpression = function () {
3088 var startToken = this.lookahead;
3089 var expr = this.inheritCoverGrammar(this.parseExponentiationExpression);
3090 var token = this.lookahead;
3091 var prec = this.binaryPrecedence(token);
3094 this.context.isAssignmentTarget = false;
3095 this.context.isBindingElement = false;
3096 var markers = [startToken, this.lookahead];
3098 var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
3099 var stack = [left, token.value, right];
3100 var precedences = [prec];
3102 prec = this.binaryPrecedence(this.lookahead);
3106 // Reduce: make a binary expression from the three topmost entries.
3107 while ((stack.length > 2) && (prec <= precedences[precedences.length - 1])) {
3108 right = stack.pop();
3109 var operator = stack.pop();
3113 var node = this.startNode(markers[markers.length - 1]);
3114 stack.push(this.finalize(node, new Node.BinaryExpression(operator, left, right)));
3117 stack.push(this.nextToken().value);
3118 precedences.push(prec);
3119 markers.push(this.lookahead);
3120 stack.push(this.isolateCoverGrammar(this.parseExponentiationExpression));
3122 // Final reduce to clean-up the stack.
3123 var i = stack.length - 1;
3125 var lastMarker = markers.pop();
3127 var marker = markers.pop();
3128 var lastLineStart = lastMarker && lastMarker.lineStart;
3129 var node = this.startNode(marker, lastLineStart);
3130 var operator = stack[i - 1];
3131 expr = this.finalize(node, new Node.BinaryExpression(operator, stack[i - 2], expr));
3133 lastMarker = marker;
3138 // https://tc39.github.io/ecma262/#sec-conditional-operator
3139 Parser.prototype.parseConditionalExpression = function () {
3140 var startToken = this.lookahead;
3141 var expr = this.inheritCoverGrammar(this.parseBinaryExpression);
3142 if (this.match('?')) {
3144 var previousAllowIn = this.context.allowIn;
3145 this.context.allowIn = true;
3146 var consequent = this.isolateCoverGrammar(this.parseAssignmentExpression);
3147 this.context.allowIn = previousAllowIn;
3149 var alternate = this.isolateCoverGrammar(this.parseAssignmentExpression);
3150 expr = this.finalize(this.startNode(startToken), new Node.ConditionalExpression(expr, consequent, alternate));
3151 this.context.isAssignmentTarget = false;
3152 this.context.isBindingElement = false;
3156 // https://tc39.github.io/ecma262/#sec-assignment-operators
3157 Parser.prototype.checkPatternParam = function (options, param) {
3158 switch (param.type) {
3159 case syntax_1.Syntax.Identifier:
3160 this.validateParam(options, param, param.name);
3162 case syntax_1.Syntax.RestElement:
3163 this.checkPatternParam(options, param.argument);
3165 case syntax_1.Syntax.AssignmentPattern:
3166 this.checkPatternParam(options, param.left);
3168 case syntax_1.Syntax.ArrayPattern:
3169 for (var i = 0; i < param.elements.length; i++) {
3170 if (param.elements[i] !== null) {
3171 this.checkPatternParam(options, param.elements[i]);
3175 case syntax_1.Syntax.ObjectPattern:
3176 for (var i = 0; i < param.properties.length; i++) {
3177 this.checkPatternParam(options, param.properties[i].value);
3183 options.simple = options.simple && (param instanceof Node.Identifier);
3185 Parser.prototype.reinterpretAsCoverFormalsList = function (expr) {
3186 var params = [expr];
3188 var asyncArrow = false;
3189 switch (expr.type) {
3190 case syntax_1.Syntax.Identifier:
3192 case ArrowParameterPlaceHolder:
3193 params = expr.params;
3194 asyncArrow = expr.async;
3203 for (var i = 0; i < params.length; ++i) {
3204 var param = params[i];
3205 if (param.type === syntax_1.Syntax.AssignmentPattern) {
3206 if (param.right.type === syntax_1.Syntax.YieldExpression) {
3207 if (param.right.argument) {
3208 this.throwUnexpectedToken(this.lookahead);
3210 param.right.type = syntax_1.Syntax.Identifier;
3211 param.right.name = 'yield';
3212 delete param.right.argument;
3213 delete param.right.delegate;
3216 else if (asyncArrow && param.type === syntax_1.Syntax.Identifier && param.name === 'await') {
3217 this.throwUnexpectedToken(this.lookahead);
3219 this.checkPatternParam(options, param);
3222 if (this.context.strict || !this.context.allowYield) {
3223 for (var i = 0; i < params.length; ++i) {
3224 var param = params[i];
3225 if (param.type === syntax_1.Syntax.YieldExpression) {
3226 this.throwUnexpectedToken(this.lookahead);
3230 if (options.message === messages_1.Messages.StrictParamDupe) {
3231 var token = this.context.strict ? options.stricted : options.firstRestricted;
3232 this.throwUnexpectedToken(token, options.message);
3235 simple: options.simple,
3237 stricted: options.stricted,
3238 firstRestricted: options.firstRestricted,
3239 message: options.message
3242 Parser.prototype.parseAssignmentExpression = function () {
3244 if (!this.context.allowYield && this.matchKeyword('yield')) {
3245 expr = this.parseYieldExpression();
3248 var startToken = this.lookahead;
3249 var token = startToken;
3250 expr = this.parseConditionalExpression();
3251 if (token.type === 3 /* Identifier */ && (token.lineNumber === this.lookahead.lineNumber) && token.value === 'async') {
3252 if (this.lookahead.type === 3 /* Identifier */ || this.matchKeyword('yield')) {
3253 var arg = this.parsePrimaryExpression();
3254 this.reinterpretExpressionAsPattern(arg);
3256 type: ArrowParameterPlaceHolder,
3262 if (expr.type === ArrowParameterPlaceHolder || this.match('=>')) {
3263 // https://tc39.github.io/ecma262/#sec-arrow-function-definitions
3264 this.context.isAssignmentTarget = false;
3265 this.context.isBindingElement = false;
3266 var isAsync = expr.async;
3267 var list = this.reinterpretAsCoverFormalsList(expr);
3269 if (this.hasLineTerminator) {
3270 this.tolerateUnexpectedToken(this.lookahead);
3272 this.context.firstCoverInitializedNameError = null;
3273 var previousStrict = this.context.strict;
3274 var previousAllowStrictDirective = this.context.allowStrictDirective;
3275 this.context.allowStrictDirective = list.simple;
3276 var previousAllowYield = this.context.allowYield;
3277 var previousAwait = this.context.await;
3278 this.context.allowYield = true;
3279 this.context.await = isAsync;
3280 var node = this.startNode(startToken);
3283 if (this.match('{')) {
3284 var previousAllowIn = this.context.allowIn;
3285 this.context.allowIn = true;
3286 body = this.parseFunctionSourceElements();
3287 this.context.allowIn = previousAllowIn;
3290 body = this.isolateCoverGrammar(this.parseAssignmentExpression);
3292 var expression = body.type !== syntax_1.Syntax.BlockStatement;
3293 if (this.context.strict && list.firstRestricted) {
3294 this.throwUnexpectedToken(list.firstRestricted, list.message);
3296 if (this.context.strict && list.stricted) {
3297 this.tolerateUnexpectedToken(list.stricted, list.message);
3299 expr = isAsync ? this.finalize(node, new Node.AsyncArrowFunctionExpression(list.params, body, expression)) :
3300 this.finalize(node, new Node.ArrowFunctionExpression(list.params, body, expression));
3301 this.context.strict = previousStrict;
3302 this.context.allowStrictDirective = previousAllowStrictDirective;
3303 this.context.allowYield = previousAllowYield;
3304 this.context.await = previousAwait;
3308 if (this.matchAssign()) {
3309 if (!this.context.isAssignmentTarget) {
3310 this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
3312 if (this.context.strict && expr.type === syntax_1.Syntax.Identifier) {
3314 if (this.scanner.isRestrictedWord(id.name)) {
3315 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictLHSAssignment);
3317 if (this.scanner.isStrictModeReservedWord(id.name)) {
3318 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
3321 if (!this.match('=')) {
3322 this.context.isAssignmentTarget = false;
3323 this.context.isBindingElement = false;
3326 this.reinterpretExpressionAsPattern(expr);
3328 token = this.nextToken();
3329 var operator = token.value;
3330 var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
3331 expr = this.finalize(this.startNode(startToken), new Node.AssignmentExpression(operator, expr, right));
3332 this.context.firstCoverInitializedNameError = null;
3338 // https://tc39.github.io/ecma262/#sec-comma-operator
3339 Parser.prototype.parseExpression = function () {
3340 var startToken = this.lookahead;
3341 var expr = this.isolateCoverGrammar(this.parseAssignmentExpression);
3342 if (this.match(',')) {
3343 var expressions = [];
3344 expressions.push(expr);
3345 while (this.lookahead.type !== 2 /* EOF */) {
3346 if (!this.match(',')) {
3350 expressions.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
3352 expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
3356 // https://tc39.github.io/ecma262/#sec-block
3357 Parser.prototype.parseStatementListItem = function () {
3359 this.context.isAssignmentTarget = true;
3360 this.context.isBindingElement = true;
3361 if (this.lookahead.type === 4 /* Keyword */) {
3362 switch (this.lookahead.value) {
3364 if (!this.context.isModule) {
3365 this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalExportDeclaration);
3367 statement = this.parseExportDeclaration();
3370 if (!this.context.isModule) {
3371 this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalImportDeclaration);
3373 statement = this.parseImportDeclaration();
3376 statement = this.parseLexicalDeclaration({ inFor: false });
3379 statement = this.parseFunctionDeclaration();
3382 statement = this.parseClassDeclaration();
3385 statement = this.isLexicalDeclaration() ? this.parseLexicalDeclaration({ inFor: false }) : this.parseStatement();
3388 statement = this.parseStatement();
3393 statement = this.parseStatement();
3397 Parser.prototype.parseBlock = function () {
3398 var node = this.createNode();
3402 if (this.match('}')) {
3405 block.push(this.parseStatementListItem());
3408 return this.finalize(node, new Node.BlockStatement(block));
3410 // https://tc39.github.io/ecma262/#sec-let-and-const-declarations
3411 Parser.prototype.parseLexicalBinding = function (kind, options) {
3412 var node = this.createNode();
3414 var id = this.parsePattern(params, kind);
3415 if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
3416 if (this.scanner.isRestrictedWord(id.name)) {
3417 this.tolerateError(messages_1.Messages.StrictVarName);
3421 if (kind === 'const') {
3422 if (!this.matchKeyword('in') && !this.matchContextualKeyword('of')) {
3423 if (this.match('=')) {
3425 init = this.isolateCoverGrammar(this.parseAssignmentExpression);
3428 this.throwError(messages_1.Messages.DeclarationMissingInitializer, 'const');
3432 else if ((!options.inFor && id.type !== syntax_1.Syntax.Identifier) || this.match('=')) {
3434 init = this.isolateCoverGrammar(this.parseAssignmentExpression);
3436 return this.finalize(node, new Node.VariableDeclarator(id, init));
3438 Parser.prototype.parseBindingList = function (kind, options) {
3439 var list = [this.parseLexicalBinding(kind, options)];
3440 while (this.match(',')) {
3442 list.push(this.parseLexicalBinding(kind, options));
3446 Parser.prototype.isLexicalDeclaration = function () {
3447 var state = this.scanner.saveState();
3448 this.scanner.scanComments();
3449 var next = this.scanner.lex();
3450 this.scanner.restoreState(state);
3451 return (next.type === 3 /* Identifier */) ||
3452 (next.type === 7 /* Punctuator */ && next.value === '[') ||
3453 (next.type === 7 /* Punctuator */ && next.value === '{') ||
3454 (next.type === 4 /* Keyword */ && next.value === 'let') ||
3455 (next.type === 4 /* Keyword */ && next.value === 'yield');
3457 Parser.prototype.parseLexicalDeclaration = function (options) {
3458 var node = this.createNode();
3459 var kind = this.nextToken().value;
3460 assert_1.assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');
3461 var declarations = this.parseBindingList(kind, options);
3462 this.consumeSemicolon();
3463 return this.finalize(node, new Node.VariableDeclaration(declarations, kind));
3465 // https://tc39.github.io/ecma262/#sec-destructuring-binding-patterns
3466 Parser.prototype.parseBindingRestElement = function (params, kind) {
3467 var node = this.createNode();
3469 var arg = this.parsePattern(params, kind);
3470 return this.finalize(node, new Node.RestElement(arg));
3472 Parser.prototype.parseArrayPattern = function (params, kind) {
3473 var node = this.createNode();
3476 while (!this.match(']')) {
3477 if (this.match(',')) {
3479 elements.push(null);
3482 if (this.match('...')) {
3483 elements.push(this.parseBindingRestElement(params, kind));
3487 elements.push(this.parsePatternWithDefault(params, kind));
3489 if (!this.match(']')) {
3495 return this.finalize(node, new Node.ArrayPattern(elements));
3497 Parser.prototype.parsePropertyPattern = function (params, kind) {
3498 var node = this.createNode();
3499 var computed = false;
3500 var shorthand = false;
3504 if (this.lookahead.type === 3 /* Identifier */) {
3505 var keyToken = this.lookahead;
3506 key = this.parseVariableIdentifier();
3507 var init = this.finalize(node, new Node.Identifier(keyToken.value));
3508 if (this.match('=')) {
3509 params.push(keyToken);
3512 var expr = this.parseAssignmentExpression();
3513 value = this.finalize(this.startNode(keyToken), new Node.AssignmentPattern(init, expr));
3515 else if (!this.match(':')) {
3516 params.push(keyToken);
3522 value = this.parsePatternWithDefault(params, kind);
3526 computed = this.match('[');
3527 key = this.parseObjectPropertyKey();
3529 value = this.parsePatternWithDefault(params, kind);
3531 return this.finalize(node, new Node.Property('init', key, computed, value, method, shorthand));
3533 Parser.prototype.parseObjectPattern = function (params, kind) {
3534 var node = this.createNode();
3535 var properties = [];
3537 while (!this.match('}')) {
3538 properties.push(this.parsePropertyPattern(params, kind));
3539 if (!this.match('}')) {
3544 return this.finalize(node, new Node.ObjectPattern(properties));
3546 Parser.prototype.parsePattern = function (params, kind) {
3548 if (this.match('[')) {
3549 pattern = this.parseArrayPattern(params, kind);
3551 else if (this.match('{')) {
3552 pattern = this.parseObjectPattern(params, kind);
3555 if (this.matchKeyword('let') && (kind === 'const' || kind === 'let')) {
3556 this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.LetInLexicalBinding);
3558 params.push(this.lookahead);
3559 pattern = this.parseVariableIdentifier(kind);
3563 Parser.prototype.parsePatternWithDefault = function (params, kind) {
3564 var startToken = this.lookahead;
3565 var pattern = this.parsePattern(params, kind);
3566 if (this.match('=')) {
3568 var previousAllowYield = this.context.allowYield;
3569 this.context.allowYield = true;
3570 var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
3571 this.context.allowYield = previousAllowYield;
3572 pattern = this.finalize(this.startNode(startToken), new Node.AssignmentPattern(pattern, right));
3576 // https://tc39.github.io/ecma262/#sec-variable-statement
3577 Parser.prototype.parseVariableIdentifier = function (kind) {
3578 var node = this.createNode();
3579 var token = this.nextToken();
3580 if (token.type === 4 /* Keyword */ && token.value === 'yield') {
3581 if (this.context.strict) {
3582 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
3584 else if (!this.context.allowYield) {
3585 this.throwUnexpectedToken(token);
3588 else if (token.type !== 3 /* Identifier */) {
3589 if (this.context.strict && token.type === 4 /* Keyword */ && this.scanner.isStrictModeReservedWord(token.value)) {
3590 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
3593 if (this.context.strict || token.value !== 'let' || kind !== 'var') {
3594 this.throwUnexpectedToken(token);
3598 else if ((this.context.isModule || this.context.await) && token.type === 3 /* Identifier */ && token.value === 'await') {
3599 this.tolerateUnexpectedToken(token);
3601 return this.finalize(node, new Node.Identifier(token.value));
3603 Parser.prototype.parseVariableDeclaration = function (options) {
3604 var node = this.createNode();
3606 var id = this.parsePattern(params, 'var');
3607 if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
3608 if (this.scanner.isRestrictedWord(id.name)) {
3609 this.tolerateError(messages_1.Messages.StrictVarName);
3613 if (this.match('=')) {
3615 init = this.isolateCoverGrammar(this.parseAssignmentExpression);
3617 else if (id.type !== syntax_1.Syntax.Identifier && !options.inFor) {
3620 return this.finalize(node, new Node.VariableDeclarator(id, init));
3622 Parser.prototype.parseVariableDeclarationList = function (options) {
3623 var opt = { inFor: options.inFor };
3625 list.push(this.parseVariableDeclaration(opt));
3626 while (this.match(',')) {
3628 list.push(this.parseVariableDeclaration(opt));
3632 Parser.prototype.parseVariableStatement = function () {
3633 var node = this.createNode();
3634 this.expectKeyword('var');
3635 var declarations = this.parseVariableDeclarationList({ inFor: false });
3636 this.consumeSemicolon();
3637 return this.finalize(node, new Node.VariableDeclaration(declarations, 'var'));
3639 // https://tc39.github.io/ecma262/#sec-empty-statement
3640 Parser.prototype.parseEmptyStatement = function () {
3641 var node = this.createNode();
3643 return this.finalize(node, new Node.EmptyStatement());
3645 // https://tc39.github.io/ecma262/#sec-expression-statement
3646 Parser.prototype.parseExpressionStatement = function () {
3647 var node = this.createNode();
3648 var expr = this.parseExpression();
3649 this.consumeSemicolon();
3650 return this.finalize(node, new Node.ExpressionStatement(expr));
3652 // https://tc39.github.io/ecma262/#sec-if-statement
3653 Parser.prototype.parseIfClause = function () {
3654 if (this.context.strict && this.matchKeyword('function')) {
3655 this.tolerateError(messages_1.Messages.StrictFunction);
3657 return this.parseStatement();
3659 Parser.prototype.parseIfStatement = function () {
3660 var node = this.createNode();
3662 var alternate = null;
3663 this.expectKeyword('if');
3665 var test = this.parseExpression();
3666 if (!this.match(')') && this.config.tolerant) {
3667 this.tolerateUnexpectedToken(this.nextToken());
3668 consequent = this.finalize(this.createNode(), new Node.EmptyStatement());
3672 consequent = this.parseIfClause();
3673 if (this.matchKeyword('else')) {
3675 alternate = this.parseIfClause();
3678 return this.finalize(node, new Node.IfStatement(test, consequent, alternate));
3680 // https://tc39.github.io/ecma262/#sec-do-while-statement
3681 Parser.prototype.parseDoWhileStatement = function () {
3682 var node = this.createNode();
3683 this.expectKeyword('do');
3684 var previousInIteration = this.context.inIteration;
3685 this.context.inIteration = true;
3686 var body = this.parseStatement();
3687 this.context.inIteration = previousInIteration;
3688 this.expectKeyword('while');
3690 var test = this.parseExpression();
3691 if (!this.match(')') && this.config.tolerant) {
3692 this.tolerateUnexpectedToken(this.nextToken());
3696 if (this.match(';')) {
3700 return this.finalize(node, new Node.DoWhileStatement(body, test));
3702 // https://tc39.github.io/ecma262/#sec-while-statement
3703 Parser.prototype.parseWhileStatement = function () {
3704 var node = this.createNode();
3706 this.expectKeyword('while');
3708 var test = this.parseExpression();
3709 if (!this.match(')') && this.config.tolerant) {
3710 this.tolerateUnexpectedToken(this.nextToken());
3711 body = this.finalize(this.createNode(), new Node.EmptyStatement());
3715 var previousInIteration = this.context.inIteration;
3716 this.context.inIteration = true;
3717 body = this.parseStatement();
3718 this.context.inIteration = previousInIteration;
3720 return this.finalize(node, new Node.WhileStatement(test, body));
3722 // https://tc39.github.io/ecma262/#sec-for-statement
3723 // https://tc39.github.io/ecma262/#sec-for-in-and-for-of-statements
3724 Parser.prototype.parseForStatement = function () {
3730 var node = this.createNode();
3731 this.expectKeyword('for');
3733 if (this.match(';')) {
3737 if (this.matchKeyword('var')) {
3738 init = this.createNode();
3740 var previousAllowIn = this.context.allowIn;
3741 this.context.allowIn = false;
3742 var declarations = this.parseVariableDeclarationList({ inFor: true });
3743 this.context.allowIn = previousAllowIn;
3744 if (declarations.length === 1 && this.matchKeyword('in')) {
3745 var decl = declarations[0];
3746 if (decl.init && (decl.id.type === syntax_1.Syntax.ArrayPattern || decl.id.type === syntax_1.Syntax.ObjectPattern || this.context.strict)) {
3747 this.tolerateError(messages_1.Messages.ForInOfLoopInitializer, 'for-in');
3749 init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
3752 right = this.parseExpression();
3755 else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
3756 init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
3759 right = this.parseAssignmentExpression();
3764 init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
3768 else if (this.matchKeyword('const') || this.matchKeyword('let')) {
3769 init = this.createNode();
3770 var kind = this.nextToken().value;
3771 if (!this.context.strict && this.lookahead.value === 'in') {
3772 init = this.finalize(init, new Node.Identifier(kind));
3775 right = this.parseExpression();
3779 var previousAllowIn = this.context.allowIn;
3780 this.context.allowIn = false;
3781 var declarations = this.parseBindingList(kind, { inFor: true });
3782 this.context.allowIn = previousAllowIn;
3783 if (declarations.length === 1 && declarations[0].init === null && this.matchKeyword('in')) {
3784 init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
3787 right = this.parseExpression();
3790 else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
3791 init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
3794 right = this.parseAssignmentExpression();
3799 this.consumeSemicolon();
3800 init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
3805 var initStartToken = this.lookahead;
3806 var previousAllowIn = this.context.allowIn;
3807 this.context.allowIn = false;
3808 init = this.inheritCoverGrammar(this.parseAssignmentExpression);
3809 this.context.allowIn = previousAllowIn;
3810 if (this.matchKeyword('in')) {
3811 if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
3812 this.tolerateError(messages_1.Messages.InvalidLHSInForIn);
3815 this.reinterpretExpressionAsPattern(init);
3817 right = this.parseExpression();
3820 else if (this.matchContextualKeyword('of')) {
3821 if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
3822 this.tolerateError(messages_1.Messages.InvalidLHSInForLoop);
3825 this.reinterpretExpressionAsPattern(init);
3827 right = this.parseAssignmentExpression();
3832 if (this.match(',')) {
3833 var initSeq = [init];
3834 while (this.match(',')) {
3836 initSeq.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
3838 init = this.finalize(this.startNode(initStartToken), new Node.SequenceExpression(initSeq));
3844 if (typeof left === 'undefined') {
3845 if (!this.match(';')) {
3846 test = this.parseExpression();
3849 if (!this.match(')')) {
3850 update = this.parseExpression();
3854 if (!this.match(')') && this.config.tolerant) {
3855 this.tolerateUnexpectedToken(this.nextToken());
3856 body = this.finalize(this.createNode(), new Node.EmptyStatement());
3860 var previousInIteration = this.context.inIteration;
3861 this.context.inIteration = true;
3862 body = this.isolateCoverGrammar(this.parseStatement);
3863 this.context.inIteration = previousInIteration;
3865 return (typeof left === 'undefined') ?
3866 this.finalize(node, new Node.ForStatement(init, test, update, body)) :
3867 forIn ? this.finalize(node, new Node.ForInStatement(left, right, body)) :
3868 this.finalize(node, new Node.ForOfStatement(left, right, body));
3870 // https://tc39.github.io/ecma262/#sec-continue-statement
3871 Parser.prototype.parseContinueStatement = function () {
3872 var node = this.createNode();
3873 this.expectKeyword('continue');
3875 if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) {
3876 var id = this.parseVariableIdentifier();
3878 var key = '$' + id.name;
3879 if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
3880 this.throwError(messages_1.Messages.UnknownLabel, id.name);
3883 this.consumeSemicolon();
3884 if (label === null && !this.context.inIteration) {
3885 this.throwError(messages_1.Messages.IllegalContinue);
3887 return this.finalize(node, new Node.ContinueStatement(label));
3889 // https://tc39.github.io/ecma262/#sec-break-statement
3890 Parser.prototype.parseBreakStatement = function () {
3891 var node = this.createNode();
3892 this.expectKeyword('break');
3894 if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) {
3895 var id = this.parseVariableIdentifier();
3896 var key = '$' + id.name;
3897 if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
3898 this.throwError(messages_1.Messages.UnknownLabel, id.name);
3902 this.consumeSemicolon();
3903 if (label === null && !this.context.inIteration && !this.context.inSwitch) {
3904 this.throwError(messages_1.Messages.IllegalBreak);
3906 return this.finalize(node, new Node.BreakStatement(label));
3908 // https://tc39.github.io/ecma262/#sec-return-statement
3909 Parser.prototype.parseReturnStatement = function () {
3910 if (!this.context.inFunctionBody) {
3911 this.tolerateError(messages_1.Messages.IllegalReturn);
3913 var node = this.createNode();
3914 this.expectKeyword('return');
3915 var hasArgument = (!this.match(';') && !this.match('}') &&
3916 !this.hasLineTerminator && this.lookahead.type !== 2 /* EOF */) ||
3917 this.lookahead.type === 8 /* StringLiteral */ ||
3918 this.lookahead.type === 10 /* Template */;
3919 var argument = hasArgument ? this.parseExpression() : null;
3920 this.consumeSemicolon();
3921 return this.finalize(node, new Node.ReturnStatement(argument));
3923 // https://tc39.github.io/ecma262/#sec-with-statement
3924 Parser.prototype.parseWithStatement = function () {
3925 if (this.context.strict) {
3926 this.tolerateError(messages_1.Messages.StrictModeWith);
3928 var node = this.createNode();
3930 this.expectKeyword('with');
3932 var object = this.parseExpression();
3933 if (!this.match(')') && this.config.tolerant) {
3934 this.tolerateUnexpectedToken(this.nextToken());
3935 body = this.finalize(this.createNode(), new Node.EmptyStatement());
3939 body = this.parseStatement();
3941 return this.finalize(node, new Node.WithStatement(object, body));
3943 // https://tc39.github.io/ecma262/#sec-switch-statement
3944 Parser.prototype.parseSwitchCase = function () {
3945 var node = this.createNode();
3947 if (this.matchKeyword('default')) {
3952 this.expectKeyword('case');
3953 test = this.parseExpression();
3956 var consequent = [];
3958 if (this.match('}') || this.matchKeyword('default') || this.matchKeyword('case')) {
3961 consequent.push(this.parseStatementListItem());
3963 return this.finalize(node, new Node.SwitchCase(test, consequent));
3965 Parser.prototype.parseSwitchStatement = function () {
3966 var node = this.createNode();
3967 this.expectKeyword('switch');
3969 var discriminant = this.parseExpression();
3971 var previousInSwitch = this.context.inSwitch;
3972 this.context.inSwitch = true;
3974 var defaultFound = false;
3977 if (this.match('}')) {
3980 var clause = this.parseSwitchCase();
3981 if (clause.test === null) {
3983 this.throwError(messages_1.Messages.MultipleDefaultsInSwitch);
3985 defaultFound = true;
3990 this.context.inSwitch = previousInSwitch;
3991 return this.finalize(node, new Node.SwitchStatement(discriminant, cases));
3993 // https://tc39.github.io/ecma262/#sec-labelled-statements
3994 Parser.prototype.parseLabelledStatement = function () {
3995 var node = this.createNode();
3996 var expr = this.parseExpression();
3998 if ((expr.type === syntax_1.Syntax.Identifier) && this.match(':')) {
4001 var key = '$' + id.name;
4002 if (Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
4003 this.throwError(messages_1.Messages.Redeclaration, 'Label', id.name);
4005 this.context.labelSet[key] = true;
4007 if (this.matchKeyword('class')) {
4008 this.tolerateUnexpectedToken(this.lookahead);
4009 body = this.parseClassDeclaration();
4011 else if (this.matchKeyword('function')) {
4012 var token = this.lookahead;
4013 var declaration = this.parseFunctionDeclaration();
4014 if (this.context.strict) {
4015 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunction);
4017 else if (declaration.generator) {
4018 this.tolerateUnexpectedToken(token, messages_1.Messages.GeneratorInLegacyContext);
4023 body = this.parseStatement();
4025 delete this.context.labelSet[key];
4026 statement = new Node.LabeledStatement(id, body);
4029 this.consumeSemicolon();
4030 statement = new Node.ExpressionStatement(expr);
4032 return this.finalize(node, statement);
4034 // https://tc39.github.io/ecma262/#sec-throw-statement
4035 Parser.prototype.parseThrowStatement = function () {
4036 var node = this.createNode();
4037 this.expectKeyword('throw');
4038 if (this.hasLineTerminator) {
4039 this.throwError(messages_1.Messages.NewlineAfterThrow);
4041 var argument = this.parseExpression();
4042 this.consumeSemicolon();
4043 return this.finalize(node, new Node.ThrowStatement(argument));
4045 // https://tc39.github.io/ecma262/#sec-try-statement
4046 Parser.prototype.parseCatchClause = function () {
4047 var node = this.createNode();
4048 this.expectKeyword('catch');
4050 if (this.match(')')) {
4051 this.throwUnexpectedToken(this.lookahead);
4054 var param = this.parsePattern(params);
4056 for (var i = 0; i < params.length; i++) {
4057 var key = '$' + params[i].value;
4058 if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
4059 this.tolerateError(messages_1.Messages.DuplicateBinding, params[i].value);
4061 paramMap[key] = true;
4063 if (this.context.strict && param.type === syntax_1.Syntax.Identifier) {
4064 if (this.scanner.isRestrictedWord(param.name)) {
4065 this.tolerateError(messages_1.Messages.StrictCatchVariable);
4069 var body = this.parseBlock();
4070 return this.finalize(node, new Node.CatchClause(param, body));
4072 Parser.prototype.parseFinallyClause = function () {
4073 this.expectKeyword('finally');
4074 return this.parseBlock();
4076 Parser.prototype.parseTryStatement = function () {
4077 var node = this.createNode();
4078 this.expectKeyword('try');
4079 var block = this.parseBlock();
4080 var handler = this.matchKeyword('catch') ? this.parseCatchClause() : null;
4081 var finalizer = this.matchKeyword('finally') ? this.parseFinallyClause() : null;
4082 if (!handler && !finalizer) {
4083 this.throwError(messages_1.Messages.NoCatchOrFinally);
4085 return this.finalize(node, new Node.TryStatement(block, handler, finalizer));
4087 // https://tc39.github.io/ecma262/#sec-debugger-statement
4088 Parser.prototype.parseDebuggerStatement = function () {
4089 var node = this.createNode();
4090 this.expectKeyword('debugger');
4091 this.consumeSemicolon();
4092 return this.finalize(node, new Node.DebuggerStatement());
4094 // https://tc39.github.io/ecma262/#sec-ecmascript-language-statements-and-declarations
4095 Parser.prototype.parseStatement = function () {
4097 switch (this.lookahead.type) {
4098 case 1 /* BooleanLiteral */:
4099 case 5 /* NullLiteral */:
4100 case 6 /* NumericLiteral */:
4101 case 8 /* StringLiteral */:
4102 case 10 /* Template */:
4103 case 9 /* RegularExpression */:
4104 statement = this.parseExpressionStatement();
4106 case 7 /* Punctuator */:
4107 var value = this.lookahead.value;
4108 if (value === '{') {
4109 statement = this.parseBlock();
4111 else if (value === '(') {
4112 statement = this.parseExpressionStatement();
4114 else if (value === ';') {
4115 statement = this.parseEmptyStatement();
4118 statement = this.parseExpressionStatement();
4121 case 3 /* Identifier */:
4122 statement = this.matchAsyncFunction() ? this.parseFunctionDeclaration() : this.parseLabelledStatement();
4124 case 4 /* Keyword */:
4125 switch (this.lookahead.value) {
4127 statement = this.parseBreakStatement();
4130 statement = this.parseContinueStatement();
4133 statement = this.parseDebuggerStatement();
4136 statement = this.parseDoWhileStatement();
4139 statement = this.parseForStatement();
4142 statement = this.parseFunctionDeclaration();
4145 statement = this.parseIfStatement();
4148 statement = this.parseReturnStatement();
4151 statement = this.parseSwitchStatement();
4154 statement = this.parseThrowStatement();
4157 statement = this.parseTryStatement();
4160 statement = this.parseVariableStatement();
4163 statement = this.parseWhileStatement();
4166 statement = this.parseWithStatement();
4169 statement = this.parseExpressionStatement();
4174 statement = this.throwUnexpectedToken(this.lookahead);
4178 // https://tc39.github.io/ecma262/#sec-function-definitions
4179 Parser.prototype.parseFunctionSourceElements = function () {
4180 var node = this.createNode();
4182 var body = this.parseDirectivePrologues();
4183 var previousLabelSet = this.context.labelSet;
4184 var previousInIteration = this.context.inIteration;
4185 var previousInSwitch = this.context.inSwitch;
4186 var previousInFunctionBody = this.context.inFunctionBody;
4187 this.context.labelSet = {};
4188 this.context.inIteration = false;
4189 this.context.inSwitch = false;
4190 this.context.inFunctionBody = true;
4191 while (this.lookahead.type !== 2 /* EOF */) {
4192 if (this.match('}')) {
4195 body.push(this.parseStatementListItem());
4198 this.context.labelSet = previousLabelSet;
4199 this.context.inIteration = previousInIteration;
4200 this.context.inSwitch = previousInSwitch;
4201 this.context.inFunctionBody = previousInFunctionBody;
4202 return this.finalize(node, new Node.BlockStatement(body));
4204 Parser.prototype.validateParam = function (options, param, name) {
4205 var key = '$' + name;
4206 if (this.context.strict) {
4207 if (this.scanner.isRestrictedWord(name)) {
4208 options.stricted = param;
4209 options.message = messages_1.Messages.StrictParamName;
4211 if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
4212 options.stricted = param;
4213 options.message = messages_1.Messages.StrictParamDupe;
4216 else if (!options.firstRestricted) {
4217 if (this.scanner.isRestrictedWord(name)) {
4218 options.firstRestricted = param;
4219 options.message = messages_1.Messages.StrictParamName;
4221 else if (this.scanner.isStrictModeReservedWord(name)) {
4222 options.firstRestricted = param;
4223 options.message = messages_1.Messages.StrictReservedWord;
4225 else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
4226 options.stricted = param;
4227 options.message = messages_1.Messages.StrictParamDupe;
4230 /* istanbul ignore next */
4231 if (typeof Object.defineProperty === 'function') {
4232 Object.defineProperty(options.paramSet, key, { value: true, enumerable: true, writable: true, configurable: true });
4235 options.paramSet[key] = true;
4238 Parser.prototype.parseRestElement = function (params) {
4239 var node = this.createNode();
4241 var arg = this.parsePattern(params);
4242 if (this.match('=')) {
4243 this.throwError(messages_1.Messages.DefaultRestParameter);
4245 if (!this.match(')')) {
4246 this.throwError(messages_1.Messages.ParameterAfterRestParameter);
4248 return this.finalize(node, new Node.RestElement(arg));
4250 Parser.prototype.parseFormalParameter = function (options) {
4252 var param = this.match('...') ? this.parseRestElement(params) : this.parsePatternWithDefault(params);
4253 for (var i = 0; i < params.length; i++) {
4254 this.validateParam(options, params[i], params[i].value);
4256 options.simple = options.simple && (param instanceof Node.Identifier);
4257 options.params.push(param);
4259 Parser.prototype.parseFormalParameters = function (firstRestricted) {
4264 firstRestricted: firstRestricted
4267 if (!this.match(')')) {
4268 options.paramSet = {};
4269 while (this.lookahead.type !== 2 /* EOF */) {
4270 this.parseFormalParameter(options);
4271 if (this.match(')')) {
4275 if (this.match(')')) {
4282 simple: options.simple,
4283 params: options.params,
4284 stricted: options.stricted,
4285 firstRestricted: options.firstRestricted,
4286 message: options.message
4289 Parser.prototype.matchAsyncFunction = function () {
4290 var match = this.matchContextualKeyword('async');
4292 var state = this.scanner.saveState();
4293 this.scanner.scanComments();
4294 var next = this.scanner.lex();
4295 this.scanner.restoreState(state);
4296 match = (state.lineNumber === next.lineNumber) && (next.type === 4 /* Keyword */) && (next.value === 'function');
4300 Parser.prototype.parseFunctionDeclaration = function (identifierIsOptional) {
4301 var node = this.createNode();
4302 var isAsync = this.matchContextualKeyword('async');
4306 this.expectKeyword('function');
4307 var isGenerator = isAsync ? false : this.match('*');
4313 var firstRestricted = null;
4314 if (!identifierIsOptional || !this.match('(')) {
4315 var token = this.lookahead;
4316 id = this.parseVariableIdentifier();
4317 if (this.context.strict) {
4318 if (this.scanner.isRestrictedWord(token.value)) {
4319 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
4323 if (this.scanner.isRestrictedWord(token.value)) {
4324 firstRestricted = token;
4325 message = messages_1.Messages.StrictFunctionName;
4327 else if (this.scanner.isStrictModeReservedWord(token.value)) {
4328 firstRestricted = token;
4329 message = messages_1.Messages.StrictReservedWord;
4333 var previousAllowAwait = this.context.await;
4334 var previousAllowYield = this.context.allowYield;
4335 this.context.await = isAsync;
4336 this.context.allowYield = !isGenerator;
4337 var formalParameters = this.parseFormalParameters(firstRestricted);
4338 var params = formalParameters.params;
4339 var stricted = formalParameters.stricted;
4340 firstRestricted = formalParameters.firstRestricted;
4341 if (formalParameters.message) {
4342 message = formalParameters.message;
4344 var previousStrict = this.context.strict;
4345 var previousAllowStrictDirective = this.context.allowStrictDirective;
4346 this.context.allowStrictDirective = formalParameters.simple;
4347 var body = this.parseFunctionSourceElements();
4348 if (this.context.strict && firstRestricted) {
4349 this.throwUnexpectedToken(firstRestricted, message);
4351 if (this.context.strict && stricted) {
4352 this.tolerateUnexpectedToken(stricted, message);
4354 this.context.strict = previousStrict;
4355 this.context.allowStrictDirective = previousAllowStrictDirective;
4356 this.context.await = previousAllowAwait;
4357 this.context.allowYield = previousAllowYield;
4358 return isAsync ? this.finalize(node, new Node.AsyncFunctionDeclaration(id, params, body)) :
4359 this.finalize(node, new Node.FunctionDeclaration(id, params, body, isGenerator));
4361 Parser.prototype.parseFunctionExpression = function () {
4362 var node = this.createNode();
4363 var isAsync = this.matchContextualKeyword('async');
4367 this.expectKeyword('function');
4368 var isGenerator = isAsync ? false : this.match('*');
4374 var firstRestricted;
4375 var previousAllowAwait = this.context.await;
4376 var previousAllowYield = this.context.allowYield;
4377 this.context.await = isAsync;
4378 this.context.allowYield = !isGenerator;
4379 if (!this.match('(')) {
4380 var token = this.lookahead;
4381 id = (!this.context.strict && !isGenerator && this.matchKeyword('yield')) ? this.parseIdentifierName() : this.parseVariableIdentifier();
4382 if (this.context.strict) {
4383 if (this.scanner.isRestrictedWord(token.value)) {
4384 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
4388 if (this.scanner.isRestrictedWord(token.value)) {
4389 firstRestricted = token;
4390 message = messages_1.Messages.StrictFunctionName;
4392 else if (this.scanner.isStrictModeReservedWord(token.value)) {
4393 firstRestricted = token;
4394 message = messages_1.Messages.StrictReservedWord;
4398 var formalParameters = this.parseFormalParameters(firstRestricted);
4399 var params = formalParameters.params;
4400 var stricted = formalParameters.stricted;
4401 firstRestricted = formalParameters.firstRestricted;
4402 if (formalParameters.message) {
4403 message = formalParameters.message;
4405 var previousStrict = this.context.strict;
4406 var previousAllowStrictDirective = this.context.allowStrictDirective;
4407 this.context.allowStrictDirective = formalParameters.simple;
4408 var body = this.parseFunctionSourceElements();
4409 if (this.context.strict && firstRestricted) {
4410 this.throwUnexpectedToken(firstRestricted, message);
4412 if (this.context.strict && stricted) {
4413 this.tolerateUnexpectedToken(stricted, message);
4415 this.context.strict = previousStrict;
4416 this.context.allowStrictDirective = previousAllowStrictDirective;
4417 this.context.await = previousAllowAwait;
4418 this.context.allowYield = previousAllowYield;
4419 return isAsync ? this.finalize(node, new Node.AsyncFunctionExpression(id, params, body)) :
4420 this.finalize(node, new Node.FunctionExpression(id, params, body, isGenerator));
4422 // https://tc39.github.io/ecma262/#sec-directive-prologues-and-the-use-strict-directive
4423 Parser.prototype.parseDirective = function () {
4424 var token = this.lookahead;
4425 var node = this.createNode();
4426 var expr = this.parseExpression();
4427 var directive = (expr.type === syntax_1.Syntax.Literal) ? this.getTokenRaw(token).slice(1, -1) : null;
4428 this.consumeSemicolon();
4429 return this.finalize(node, directive ? new Node.Directive(expr, directive) : new Node.ExpressionStatement(expr));
4431 Parser.prototype.parseDirectivePrologues = function () {
4432 var firstRestricted = null;
4435 var token = this.lookahead;
4436 if (token.type !== 8 /* StringLiteral */) {
4439 var statement = this.parseDirective();
4440 body.push(statement);
4441 var directive = statement.directive;
4442 if (typeof directive !== 'string') {
4445 if (directive === 'use strict') {
4446 this.context.strict = true;
4447 if (firstRestricted) {
4448 this.tolerateUnexpectedToken(firstRestricted, messages_1.Messages.StrictOctalLiteral);
4450 if (!this.context.allowStrictDirective) {
4451 this.tolerateUnexpectedToken(token, messages_1.Messages.IllegalLanguageModeDirective);
4455 if (!firstRestricted && token.octal) {
4456 firstRestricted = token;
4462 // https://tc39.github.io/ecma262/#sec-method-definitions
4463 Parser.prototype.qualifiedPropertyName = function (token) {
4464 switch (token.type) {
4465 case 3 /* Identifier */:
4466 case 8 /* StringLiteral */:
4467 case 1 /* BooleanLiteral */:
4468 case 5 /* NullLiteral */:
4469 case 6 /* NumericLiteral */:
4470 case 4 /* Keyword */:
4472 case 7 /* Punctuator */:
4473 return token.value === '[';
4479 Parser.prototype.parseGetterMethod = function () {
4480 var node = this.createNode();
4481 var isGenerator = false;
4482 var previousAllowYield = this.context.allowYield;
4483 this.context.allowYield = !isGenerator;
4484 var formalParameters = this.parseFormalParameters();
4485 if (formalParameters.params.length > 0) {
4486 this.tolerateError(messages_1.Messages.BadGetterArity);
4488 var method = this.parsePropertyMethod(formalParameters);
4489 this.context.allowYield = previousAllowYield;
4490 return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
4492 Parser.prototype.parseSetterMethod = function () {
4493 var node = this.createNode();
4494 var isGenerator = false;
4495 var previousAllowYield = this.context.allowYield;
4496 this.context.allowYield = !isGenerator;
4497 var formalParameters = this.parseFormalParameters();
4498 if (formalParameters.params.length !== 1) {
4499 this.tolerateError(messages_1.Messages.BadSetterArity);
4501 else if (formalParameters.params[0] instanceof Node.RestElement) {
4502 this.tolerateError(messages_1.Messages.BadSetterRestParameter);
4504 var method = this.parsePropertyMethod(formalParameters);
4505 this.context.allowYield = previousAllowYield;
4506 return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
4508 Parser.prototype.parseGeneratorMethod = function () {
4509 var node = this.createNode();
4510 var isGenerator = true;
4511 var previousAllowYield = this.context.allowYield;
4512 this.context.allowYield = true;
4513 var params = this.parseFormalParameters();
4514 this.context.allowYield = false;
4515 var method = this.parsePropertyMethod(params);
4516 this.context.allowYield = previousAllowYield;
4517 return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
4519 // https://tc39.github.io/ecma262/#sec-generator-function-definitions
4520 Parser.prototype.isStartOfExpression = function () {
4522 var value = this.lookahead.value;
4523 switch (this.lookahead.type) {
4524 case 7 /* Punctuator */:
4525 start = (value === '[') || (value === '(') || (value === '{') ||
4526 (value === '+') || (value === '-') ||
4527 (value === '!') || (value === '~') ||
4528 (value === '++') || (value === '--') ||
4529 (value === '/') || (value === '/='); // regular expression literal
4531 case 4 /* Keyword */:
4532 start = (value === 'class') || (value === 'delete') ||
4533 (value === 'function') || (value === 'let') || (value === 'new') ||
4534 (value === 'super') || (value === 'this') || (value === 'typeof') ||
4535 (value === 'void') || (value === 'yield');
4542 Parser.prototype.parseYieldExpression = function () {
4543 var node = this.createNode();
4544 this.expectKeyword('yield');
4545 var argument = null;
4546 var delegate = false;
4547 if (!this.hasLineTerminator) {
4548 var previousAllowYield = this.context.allowYield;
4549 this.context.allowYield = false;
4550 delegate = this.match('*');
4553 argument = this.parseAssignmentExpression();
4555 else if (this.isStartOfExpression()) {
4556 argument = this.parseAssignmentExpression();
4558 this.context.allowYield = previousAllowYield;
4560 return this.finalize(node, new Node.YieldExpression(argument, delegate));
4562 // https://tc39.github.io/ecma262/#sec-class-definitions
4563 Parser.prototype.parseClassElement = function (hasConstructor) {
4564 var token = this.lookahead;
4565 var node = this.createNode();
4569 var computed = false;
4571 var isStatic = false;
4572 var isAsync = false;
4573 if (this.match('*')) {
4577 computed = this.match('[');
4578 key = this.parseObjectPropertyKey();
4580 if (id.name === 'static' && (this.qualifiedPropertyName(this.lookahead) || this.match('*'))) {
4581 token = this.lookahead;
4583 computed = this.match('[');
4584 if (this.match('*')) {
4588 key = this.parseObjectPropertyKey();
4591 if ((token.type === 3 /* Identifier */) && !this.hasLineTerminator && (token.value === 'async')) {
4592 var punctuator = this.lookahead.value;
4593 if (punctuator !== ':' && punctuator !== '(' && punctuator !== '*') {
4595 token = this.lookahead;
4596 key = this.parseObjectPropertyKey();
4597 if (token.type === 3 /* Identifier */ && token.value === 'constructor') {
4598 this.tolerateUnexpectedToken(token, messages_1.Messages.ConstructorIsAsync);
4603 var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
4604 if (token.type === 3 /* Identifier */) {
4605 if (token.value === 'get' && lookaheadPropertyKey) {
4607 computed = this.match('[');
4608 key = this.parseObjectPropertyKey();
4609 this.context.allowYield = false;
4610 value = this.parseGetterMethod();
4612 else if (token.value === 'set' && lookaheadPropertyKey) {
4614 computed = this.match('[');
4615 key = this.parseObjectPropertyKey();
4616 value = this.parseSetterMethod();
4619 else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
4621 computed = this.match('[');
4622 key = this.parseObjectPropertyKey();
4623 value = this.parseGeneratorMethod();
4626 if (!kind && key && this.match('(')) {
4628 value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
4632 this.throwUnexpectedToken(this.lookahead);
4634 if (kind === 'init') {
4638 if (isStatic && this.isPropertyKey(key, 'prototype')) {
4639 this.throwUnexpectedToken(token, messages_1.Messages.StaticPrototype);
4641 if (!isStatic && this.isPropertyKey(key, 'constructor')) {
4642 if (kind !== 'method' || !method || (value && value.generator)) {
4643 this.throwUnexpectedToken(token, messages_1.Messages.ConstructorSpecialMethod);
4645 if (hasConstructor.value) {
4646 this.throwUnexpectedToken(token, messages_1.Messages.DuplicateConstructor);
4649 hasConstructor.value = true;
4651 kind = 'constructor';
4654 return this.finalize(node, new Node.MethodDefinition(key, computed, value, kind, isStatic));
4656 Parser.prototype.parseClassElementList = function () {
4658 var hasConstructor = { value: false };
4660 while (!this.match('}')) {
4661 if (this.match(';')) {
4665 body.push(this.parseClassElement(hasConstructor));
4671 Parser.prototype.parseClassBody = function () {
4672 var node = this.createNode();
4673 var elementList = this.parseClassElementList();
4674 return this.finalize(node, new Node.ClassBody(elementList));
4676 Parser.prototype.parseClassDeclaration = function (identifierIsOptional) {
4677 var node = this.createNode();
4678 var previousStrict = this.context.strict;
4679 this.context.strict = true;
4680 this.expectKeyword('class');
4681 var id = (identifierIsOptional && (this.lookahead.type !== 3 /* Identifier */)) ? null : this.parseVariableIdentifier();
4682 var superClass = null;
4683 if (this.matchKeyword('extends')) {
4685 superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
4687 var classBody = this.parseClassBody();
4688 this.context.strict = previousStrict;
4689 return this.finalize(node, new Node.ClassDeclaration(id, superClass, classBody));
4691 Parser.prototype.parseClassExpression = function () {
4692 var node = this.createNode();
4693 var previousStrict = this.context.strict;
4694 this.context.strict = true;
4695 this.expectKeyword('class');
4696 var id = (this.lookahead.type === 3 /* Identifier */) ? this.parseVariableIdentifier() : null;
4697 var superClass = null;
4698 if (this.matchKeyword('extends')) {
4700 superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
4702 var classBody = this.parseClassBody();
4703 this.context.strict = previousStrict;
4704 return this.finalize(node, new Node.ClassExpression(id, superClass, classBody));
4706 // https://tc39.github.io/ecma262/#sec-scripts
4707 // https://tc39.github.io/ecma262/#sec-modules
4708 Parser.prototype.parseModule = function () {
4709 this.context.strict = true;
4710 this.context.isModule = true;
4711 this.scanner.isModule = true;
4712 var node = this.createNode();
4713 var body = this.parseDirectivePrologues();
4714 while (this.lookahead.type !== 2 /* EOF */) {
4715 body.push(this.parseStatementListItem());
4717 return this.finalize(node, new Node.Module(body));
4719 Parser.prototype.parseScript = function () {
4720 var node = this.createNode();
4721 var body = this.parseDirectivePrologues();
4722 while (this.lookahead.type !== 2 /* EOF */) {
4723 body.push(this.parseStatementListItem());
4725 return this.finalize(node, new Node.Script(body));
4727 // https://tc39.github.io/ecma262/#sec-imports
4728 Parser.prototype.parseModuleSpecifier = function () {
4729 var node = this.createNode();
4730 if (this.lookahead.type !== 8 /* StringLiteral */) {
4731 this.throwError(messages_1.Messages.InvalidModuleSpecifier);
4733 var token = this.nextToken();
4734 var raw = this.getTokenRaw(token);
4735 return this.finalize(node, new Node.Literal(token.value, raw));
4737 // import {<foo as bar>} ...;
4738 Parser.prototype.parseImportSpecifier = function () {
4739 var node = this.createNode();
4742 if (this.lookahead.type === 3 /* Identifier */) {
4743 imported = this.parseVariableIdentifier();
4745 if (this.matchContextualKeyword('as')) {
4747 local = this.parseVariableIdentifier();
4751 imported = this.parseIdentifierName();
4753 if (this.matchContextualKeyword('as')) {
4755 local = this.parseVariableIdentifier();
4758 this.throwUnexpectedToken(this.nextToken());
4761 return this.finalize(node, new Node.ImportSpecifier(local, imported));
4763 // {foo, bar as bas}
4764 Parser.prototype.parseNamedImports = function () {
4766 var specifiers = [];
4767 while (!this.match('}')) {
4768 specifiers.push(this.parseImportSpecifier());
4769 if (!this.match('}')) {
4776 // import <foo> ...;
4777 Parser.prototype.parseImportDefaultSpecifier = function () {
4778 var node = this.createNode();
4779 var local = this.parseIdentifierName();
4780 return this.finalize(node, new Node.ImportDefaultSpecifier(local));
4782 // import <* as foo> ...;
4783 Parser.prototype.parseImportNamespaceSpecifier = function () {
4784 var node = this.createNode();
4786 if (!this.matchContextualKeyword('as')) {
4787 this.throwError(messages_1.Messages.NoAsAfterImportNamespace);
4790 var local = this.parseIdentifierName();
4791 return this.finalize(node, new Node.ImportNamespaceSpecifier(local));
4793 Parser.prototype.parseImportDeclaration = function () {
4794 if (this.context.inFunctionBody) {
4795 this.throwError(messages_1.Messages.IllegalImportDeclaration);
4797 var node = this.createNode();
4798 this.expectKeyword('import');
4800 var specifiers = [];
4801 if (this.lookahead.type === 8 /* StringLiteral */) {
4803 src = this.parseModuleSpecifier();
4806 if (this.match('{')) {
4808 specifiers = specifiers.concat(this.parseNamedImports());
4810 else if (this.match('*')) {
4812 specifiers.push(this.parseImportNamespaceSpecifier());
4814 else if (this.isIdentifierName(this.lookahead) && !this.matchKeyword('default')) {
4816 specifiers.push(this.parseImportDefaultSpecifier());
4817 if (this.match(',')) {
4819 if (this.match('*')) {
4820 // import foo, * as foo
4821 specifiers.push(this.parseImportNamespaceSpecifier());
4823 else if (this.match('{')) {
4824 // import foo, {bar}
4825 specifiers = specifiers.concat(this.parseNamedImports());
4828 this.throwUnexpectedToken(this.lookahead);
4833 this.throwUnexpectedToken(this.nextToken());
4835 if (!this.matchContextualKeyword('from')) {
4836 var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
4837 this.throwError(message, this.lookahead.value);
4840 src = this.parseModuleSpecifier();
4842 this.consumeSemicolon();
4843 return this.finalize(node, new Node.ImportDeclaration(specifiers, src));
4845 // https://tc39.github.io/ecma262/#sec-exports
4846 Parser.prototype.parseExportSpecifier = function () {
4847 var node = this.createNode();
4848 var local = this.parseIdentifierName();
4849 var exported = local;
4850 if (this.matchContextualKeyword('as')) {
4852 exported = this.parseIdentifierName();
4854 return this.finalize(node, new Node.ExportSpecifier(local, exported));
4856 Parser.prototype.parseExportDeclaration = function () {
4857 if (this.context.inFunctionBody) {
4858 this.throwError(messages_1.Messages.IllegalExportDeclaration);
4860 var node = this.createNode();
4861 this.expectKeyword('export');
4862 var exportDeclaration;
4863 if (this.matchKeyword('default')) {
4864 // export default ...
4866 if (this.matchKeyword('function')) {
4867 // export default function foo () {}
4868 // export default function () {}
4869 var declaration = this.parseFunctionDeclaration(true);
4870 exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
4872 else if (this.matchKeyword('class')) {
4873 // export default class foo {}
4874 var declaration = this.parseClassDeclaration(true);
4875 exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
4877 else if (this.matchContextualKeyword('async')) {
4878 // export default async function f () {}
4879 // export default async function () {}
4880 // export default async x => x
4881 var declaration = this.matchAsyncFunction() ? this.parseFunctionDeclaration(true) : this.parseAssignmentExpression();
4882 exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
4885 if (this.matchContextualKeyword('from')) {
4886 this.throwError(messages_1.Messages.UnexpectedToken, this.lookahead.value);
4888 // export default {};
4889 // export default [];
4890 // export default (1 + 2);
4891 var declaration = this.match('{') ? this.parseObjectInitializer() :
4892 this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression();
4893 this.consumeSemicolon();
4894 exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
4897 else if (this.match('*')) {
4898 // export * from 'foo';
4900 if (!this.matchContextualKeyword('from')) {
4901 var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
4902 this.throwError(message, this.lookahead.value);
4905 var src = this.parseModuleSpecifier();
4906 this.consumeSemicolon();
4907 exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src));
4909 else if (this.lookahead.type === 4 /* Keyword */) {
4910 // export var f = 1;
4911 var declaration = void 0;
4912 switch (this.lookahead.value) {
4915 declaration = this.parseLexicalDeclaration({ inFor: false });
4920 declaration = this.parseStatementListItem();
4923 this.throwUnexpectedToken(this.lookahead);
4925 exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
4927 else if (this.matchAsyncFunction()) {
4928 var declaration = this.parseFunctionDeclaration();
4929 exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
4932 var specifiers = [];
4934 var isExportFromIdentifier = false;
4936 while (!this.match('}')) {
4937 isExportFromIdentifier = isExportFromIdentifier || this.matchKeyword('default');
4938 specifiers.push(this.parseExportSpecifier());
4939 if (!this.match('}')) {
4944 if (this.matchContextualKeyword('from')) {
4945 // export {default} from 'foo';
4946 // export {foo} from 'foo';
4948 source = this.parseModuleSpecifier();
4949 this.consumeSemicolon();
4951 else if (isExportFromIdentifier) {
4952 // export {default}; // missing fromClause
4953 var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
4954 this.throwError(message, this.lookahead.value);
4958 this.consumeSemicolon();
4960 exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(null, specifiers, source));
4962 return exportDeclaration;
4966 exports.Parser = Parser;
4971 /***/ function(module, exports) {
4974 // Ensure the condition is true, otherwise throw an error.
4975 // This is only to have a better contract semantic, i.e. another safety net
4976 // to catch a logic error. The condition shall be fulfilled in normal case.
4977 // Do NOT use this to enforce a certain condition on any user input.
4978 Object.defineProperty(exports, "__esModule", { value: true });
4979 function assert(condition, message) {
4980 /* istanbul ignore if */
4982 throw new Error('ASSERT: ' + message);
4985 exports.assert = assert;
4990 /***/ function(module, exports) {
4993 /* tslint:disable:max-classes-per-file */
4994 Object.defineProperty(exports, "__esModule", { value: true });
4995 var ErrorHandler = (function () {
4996 function ErrorHandler() {
4998 this.tolerant = false;
5000 ErrorHandler.prototype.recordError = function (error) {
5001 this.errors.push(error);
5003 ErrorHandler.prototype.tolerate = function (error) {
5004 if (this.tolerant) {
5005 this.recordError(error);
5011 ErrorHandler.prototype.constructError = function (msg, column) {
5012 var error = new Error(msg);
5017 /* istanbul ignore else */
5018 if (Object.create && Object.defineProperty) {
5019 error = Object.create(base);
5020 Object.defineProperty(error, 'column', { value: column });
5023 /* istanbul ignore next */
5026 ErrorHandler.prototype.createError = function (index, line, col, description) {
5027 var msg = 'Line ' + line + ': ' + description;
5028 var error = this.constructError(msg, col);
5029 error.index = index;
5030 error.lineNumber = line;
5031 error.description = description;
5034 ErrorHandler.prototype.throwError = function (index, line, col, description) {
5035 throw this.createError(index, line, col, description);
5037 ErrorHandler.prototype.tolerateError = function (index, line, col, description) {
5038 var error = this.createError(index, line, col, description);
5039 if (this.tolerant) {
5040 this.recordError(error);
5046 return ErrorHandler;
5048 exports.ErrorHandler = ErrorHandler;
5053 /***/ function(module, exports) {
5056 Object.defineProperty(exports, "__esModule", { value: true });
5057 // Error messages should be identical to V8.
5058 exports.Messages = {
5059 BadGetterArity: 'Getter must not have any formal parameters',
5060 BadSetterArity: 'Setter must have exactly one formal parameter',
5061 BadSetterRestParameter: 'Setter function argument must not be a rest parameter',
5062 ConstructorIsAsync: 'Class constructor may not be an async method',
5063 ConstructorSpecialMethod: 'Class constructor may not be an accessor',
5064 DeclarationMissingInitializer: 'Missing initializer in %0 declaration',
5065 DefaultRestParameter: 'Unexpected token =',
5066 DuplicateBinding: 'Duplicate binding %0',
5067 DuplicateConstructor: 'A class may only have one constructor',
5068 DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
5069 ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer',
5070 GeneratorInLegacyContext: 'Generator declarations are not allowed in legacy contexts',
5071 IllegalBreak: 'Illegal break statement',
5072 IllegalContinue: 'Illegal continue statement',
5073 IllegalExportDeclaration: 'Unexpected token',
5074 IllegalImportDeclaration: 'Unexpected token',
5075 IllegalLanguageModeDirective: 'Illegal \'use strict\' directive in function with non-simple parameter list',
5076 IllegalReturn: 'Illegal return statement',
5077 InvalidEscapedReservedWord: 'Keyword must not contain escaped characters',
5078 InvalidHexEscapeSequence: 'Invalid hexadecimal escape sequence',
5079 InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
5080 InvalidLHSInForIn: 'Invalid left-hand side in for-in',
5081 InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
5082 InvalidModuleSpecifier: 'Unexpected token',
5083 InvalidRegExp: 'Invalid regular expression',
5084 LetInLexicalBinding: 'let is disallowed as a lexically bound name',
5085 MissingFromClause: 'Unexpected token',
5086 MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
5087 NewlineAfterThrow: 'Illegal newline after throw',
5088 NoAsAfterImportNamespace: 'Unexpected token',
5089 NoCatchOrFinally: 'Missing catch or finally after try',
5090 ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
5091 Redeclaration: '%0 \'%1\' has already been declared',
5092 StaticPrototype: 'Classes may not have static property named prototype',
5093 StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
5094 StrictDelete: 'Delete of an unqualified identifier in strict mode.',
5095 StrictFunction: 'In strict mode code, functions can only be declared at top level or inside a block',
5096 StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
5097 StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
5098 StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
5099 StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
5100 StrictModeWith: 'Strict mode code may not include a with statement',
5101 StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
5102 StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
5103 StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
5104 StrictReservedWord: 'Use of future reserved word in strict mode',
5105 StrictVarName: 'Variable name may not be eval or arguments in strict mode',
5106 TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
5107 UnexpectedEOS: 'Unexpected end of input',
5108 UnexpectedIdentifier: 'Unexpected identifier',
5109 UnexpectedNumber: 'Unexpected number',
5110 UnexpectedReserved: 'Unexpected reserved word',
5111 UnexpectedString: 'Unexpected string',
5112 UnexpectedTemplate: 'Unexpected quasi %0',
5113 UnexpectedToken: 'Unexpected token %0',
5114 UnexpectedTokenIllegal: 'Unexpected token ILLEGAL',
5115 UnknownLabel: 'Undefined label \'%0\'',
5116 UnterminatedRegExp: 'Invalid regular expression: missing /'
5122 /***/ function(module, exports, __webpack_require__) {
5125 Object.defineProperty(exports, "__esModule", { value: true });
5126 var assert_1 = __webpack_require__(9);
5127 var character_1 = __webpack_require__(4);
5128 var messages_1 = __webpack_require__(11);
5129 function hexValue(ch) {
5130 return '0123456789abcdef'.indexOf(ch.toLowerCase());
5132 function octalValue(ch) {
5133 return '01234567'.indexOf(ch);
5135 var Scanner = (function () {
5136 function Scanner(code, handler) {
5138 this.errorHandler = handler;
5139 this.trackComment = false;
5140 this.isModule = false;
5141 this.length = code.length;
5143 this.lineNumber = (code.length > 0) ? 1 : 0;
5145 this.curlyStack = [];
5147 Scanner.prototype.saveState = function () {
5150 lineNumber: this.lineNumber,
5151 lineStart: this.lineStart
5154 Scanner.prototype.restoreState = function (state) {
5155 this.index = state.index;
5156 this.lineNumber = state.lineNumber;
5157 this.lineStart = state.lineStart;
5159 Scanner.prototype.eof = function () {
5160 return this.index >= this.length;
5162 Scanner.prototype.throwUnexpectedToken = function (message) {
5163 if (message === void 0) { message = messages_1.Messages.UnexpectedTokenIllegal; }
5164 return this.errorHandler.throwError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
5166 Scanner.prototype.tolerateUnexpectedToken = function (message) {
5167 if (message === void 0) { message = messages_1.Messages.UnexpectedTokenIllegal; }
5168 this.errorHandler.tolerateError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
5170 // https://tc39.github.io/ecma262/#sec-comments
5171 Scanner.prototype.skipSingleLineComment = function (offset) {
5174 if (this.trackComment) {
5176 start = this.index - offset;
5179 line: this.lineNumber,
5180 column: this.index - this.lineStart - offset
5185 while (!this.eof()) {
5186 var ch = this.source.charCodeAt(this.index);
5188 if (character_1.Character.isLineTerminator(ch)) {
5189 if (this.trackComment) {
5191 line: this.lineNumber,
5192 column: this.index - this.lineStart - 1
5196 slice: [start + offset, this.index - 1],
5197 range: [start, this.index - 1],
5200 comments.push(entry);
5202 if (ch === 13 && this.source.charCodeAt(this.index) === 10) {
5206 this.lineStart = this.index;
5210 if (this.trackComment) {
5212 line: this.lineNumber,
5213 column: this.index - this.lineStart
5217 slice: [start + offset, this.index],
5218 range: [start, this.index],
5221 comments.push(entry);
5225 Scanner.prototype.skipMultiLineComment = function () {
5228 if (this.trackComment) {
5230 start = this.index - 2;
5233 line: this.lineNumber,
5234 column: this.index - this.lineStart - 2
5239 while (!this.eof()) {
5240 var ch = this.source.charCodeAt(this.index);
5241 if (character_1.Character.isLineTerminator(ch)) {
5242 if (ch === 0x0D && this.source.charCodeAt(this.index + 1) === 0x0A) {
5247 this.lineStart = this.index;
5249 else if (ch === 0x2A) {
5250 // Block comment ends with '*/'.
5251 if (this.source.charCodeAt(this.index + 1) === 0x2F) {
5253 if (this.trackComment) {
5255 line: this.lineNumber,
5256 column: this.index - this.lineStart
5260 slice: [start + 2, this.index - 2],
5261 range: [start, this.index],
5264 comments.push(entry);
5274 // Ran off the end of the file - the whole thing is a comment
5275 if (this.trackComment) {
5277 line: this.lineNumber,
5278 column: this.index - this.lineStart
5282 slice: [start + 2, this.index],
5283 range: [start, this.index],
5286 comments.push(entry);
5288 this.tolerateUnexpectedToken();
5291 Scanner.prototype.scanComments = function () {
5293 if (this.trackComment) {
5296 var start = (this.index === 0);
5297 while (!this.eof()) {
5298 var ch = this.source.charCodeAt(this.index);
5299 if (character_1.Character.isWhiteSpace(ch)) {
5302 else if (character_1.Character.isLineTerminator(ch)) {
5304 if (ch === 0x0D && this.source.charCodeAt(this.index) === 0x0A) {
5308 this.lineStart = this.index;
5311 else if (ch === 0x2F) {
5312 ch = this.source.charCodeAt(this.index + 1);
5315 var comment = this.skipSingleLineComment(2);
5316 if (this.trackComment) {
5317 comments = comments.concat(comment);
5321 else if (ch === 0x2A) {
5323 var comment = this.skipMultiLineComment();
5324 if (this.trackComment) {
5325 comments = comments.concat(comment);
5332 else if (start && ch === 0x2D) {
5334 if ((this.source.charCodeAt(this.index + 1) === 0x2D) && (this.source.charCodeAt(this.index + 2) === 0x3E)) {
5335 // '-->' is a single-line comment
5337 var comment = this.skipSingleLineComment(3);
5338 if (this.trackComment) {
5339 comments = comments.concat(comment);
5346 else if (ch === 0x3C && !this.isModule) {
5347 if (this.source.slice(this.index + 1, this.index + 4) === '!--') {
5348 this.index += 4; // `<!--`
5349 var comment = this.skipSingleLineComment(4);
5350 if (this.trackComment) {
5351 comments = comments.concat(comment);
5364 // https://tc39.github.io/ecma262/#sec-future-reserved-words
5365 Scanner.prototype.isFutureReservedWord = function (id) {
5376 Scanner.prototype.isStrictModeReservedWord = function (id) {
5392 Scanner.prototype.isRestrictedWord = function (id) {
5393 return id === 'eval' || id === 'arguments';
5395 // https://tc39.github.io/ecma262/#sec-keywords
5396 Scanner.prototype.isKeyword = function (id) {
5397 switch (id.length) {
5399 return (id === 'if') || (id === 'in') || (id === 'do');
5401 return (id === 'var') || (id === 'for') || (id === 'new') ||
5402 (id === 'try') || (id === 'let');
5404 return (id === 'this') || (id === 'else') || (id === 'case') ||
5405 (id === 'void') || (id === 'with') || (id === 'enum');
5407 return (id === 'while') || (id === 'break') || (id === 'catch') ||
5408 (id === 'throw') || (id === 'const') || (id === 'yield') ||
5409 (id === 'class') || (id === 'super');
5411 return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
5412 (id === 'switch') || (id === 'export') || (id === 'import');
5414 return (id === 'default') || (id === 'finally') || (id === 'extends');
5416 return (id === 'function') || (id === 'continue') || (id === 'debugger');
5418 return (id === 'instanceof');
5423 Scanner.prototype.codePointAt = function (i) {
5424 var cp = this.source.charCodeAt(i);
5425 if (cp >= 0xD800 && cp <= 0xDBFF) {
5426 var second = this.source.charCodeAt(i + 1);
5427 if (second >= 0xDC00 && second <= 0xDFFF) {
5429 cp = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
5434 Scanner.prototype.scanHexEscape = function (prefix) {
5435 var len = (prefix === 'u') ? 4 : 2;
5437 for (var i = 0; i < len; ++i) {
5438 if (!this.eof() && character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
5439 code = code * 16 + hexValue(this.source[this.index++]);
5445 return String.fromCharCode(code);
5447 Scanner.prototype.scanUnicodeCodePointEscape = function () {
5448 var ch = this.source[this.index];
5450 // At least, one hex digit is required.
5452 this.throwUnexpectedToken();
5454 while (!this.eof()) {
5455 ch = this.source[this.index++];
5456 if (!character_1.Character.isHexDigit(ch.charCodeAt(0))) {
5459 code = code * 16 + hexValue(ch);
5461 if (code > 0x10FFFF || ch !== '}') {
5462 this.throwUnexpectedToken();
5464 return character_1.Character.fromCodePoint(code);
5466 Scanner.prototype.getIdentifier = function () {
5467 var start = this.index++;
5468 while (!this.eof()) {
5469 var ch = this.source.charCodeAt(this.index);
5471 // Blackslash (U+005C) marks Unicode escape sequence.
5473 return this.getComplexIdentifier();
5475 else if (ch >= 0xD800 && ch < 0xDFFF) {
5476 // Need to handle surrogate pairs.
5478 return this.getComplexIdentifier();
5480 if (character_1.Character.isIdentifierPart(ch)) {
5487 return this.source.slice(start, this.index);
5489 Scanner.prototype.getComplexIdentifier = function () {
5490 var cp = this.codePointAt(this.index);
5491 var id = character_1.Character.fromCodePoint(cp);
5492 this.index += id.length;
5493 // '\u' (U+005C, U+0075) denotes an escaped character.
5496 if (this.source.charCodeAt(this.index) !== 0x75) {
5497 this.throwUnexpectedToken();
5500 if (this.source[this.index] === '{') {
5502 ch = this.scanUnicodeCodePointEscape();
5505 ch = this.scanHexEscape('u');
5506 if (ch === null || ch === '\\' || !character_1.Character.isIdentifierStart(ch.charCodeAt(0))) {
5507 this.throwUnexpectedToken();
5512 while (!this.eof()) {
5513 cp = this.codePointAt(this.index);
5514 if (!character_1.Character.isIdentifierPart(cp)) {
5517 ch = character_1.Character.fromCodePoint(cp);
5519 this.index += ch.length;
5520 // '\u' (U+005C, U+0075) denotes an escaped character.
5522 id = id.substr(0, id.length - 1);
5523 if (this.source.charCodeAt(this.index) !== 0x75) {
5524 this.throwUnexpectedToken();
5527 if (this.source[this.index] === '{') {
5529 ch = this.scanUnicodeCodePointEscape();
5532 ch = this.scanHexEscape('u');
5533 if (ch === null || ch === '\\' || !character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
5534 this.throwUnexpectedToken();
5542 Scanner.prototype.octalToDecimal = function (ch) {
5543 // \0 is not octal escape sequence
5544 var octal = (ch !== '0');
5545 var code = octalValue(ch);
5546 if (!this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
5548 code = code * 8 + octalValue(this.source[this.index++]);
5549 // 3 digits are only allowed when string starts
5551 if ('0123'.indexOf(ch) >= 0 && !this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
5552 code = code * 8 + octalValue(this.source[this.index++]);
5560 // https://tc39.github.io/ecma262/#sec-names-and-keywords
5561 Scanner.prototype.scanIdentifier = function () {
5563 var start = this.index;
5564 // Backslash (U+005C) starts an escaped character.
5565 var id = (this.source.charCodeAt(start) === 0x5C) ? this.getComplexIdentifier() : this.getIdentifier();
5566 // There is no keyword or literal with only one character.
5567 // Thus, it must be an identifier.
5568 if (id.length === 1) {
5569 type = 3 /* Identifier */;
5571 else if (this.isKeyword(id)) {
5572 type = 4 /* Keyword */;
5574 else if (id === 'null') {
5575 type = 5 /* NullLiteral */;
5577 else if (id === 'true' || id === 'false') {
5578 type = 1 /* BooleanLiteral */;
5581 type = 3 /* Identifier */;
5583 if (type !== 3 /* Identifier */ && (start + id.length !== this.index)) {
5584 var restore = this.index;
5586 this.tolerateUnexpectedToken(messages_1.Messages.InvalidEscapedReservedWord);
5587 this.index = restore;
5592 lineNumber: this.lineNumber,
5593 lineStart: this.lineStart,
5598 // https://tc39.github.io/ecma262/#sec-punctuators
5599 Scanner.prototype.scanPunctuator = function () {
5600 var start = this.index;
5601 // Check for most common single-character punctuators.
5602 var str = this.source[this.index];
5607 this.curlyStack.push('{');
5613 if (this.source[this.index] === '.' && this.source[this.index + 1] === '.') {
5614 // Spread operator: ...
5621 this.curlyStack.pop();
5634 // 4-character punctuator.
5635 str = this.source.substr(this.index, 4);
5636 if (str === '>>>=') {
5640 // 3-character punctuators.
5641 str = str.substr(0, 3);
5642 if (str === '===' || str === '!==' || str === '>>>' ||
5643 str === '<<=' || str === '>>=' || str === '**=') {
5647 // 2-character punctuators.
5648 str = str.substr(0, 2);
5649 if (str === '&&' || str === '||' || str === '==' || str === '!=' ||
5650 str === '+=' || str === '-=' || str === '*=' || str === '/=' ||
5651 str === '++' || str === '--' || str === '<<' || str === '>>' ||
5652 str === '&=' || str === '|=' || str === '^=' || str === '%=' ||
5653 str === '<=' || str === '>=' || str === '=>' || str === '**') {
5657 // 1-character punctuators.
5658 str = this.source[this.index];
5659 if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {
5666 if (this.index === start) {
5667 this.throwUnexpectedToken();
5670 type: 7 /* Punctuator */,
5672 lineNumber: this.lineNumber,
5673 lineStart: this.lineStart,
5678 // https://tc39.github.io/ecma262/#sec-literals-numeric-literals
5679 Scanner.prototype.scanHexLiteral = function (start) {
5681 while (!this.eof()) {
5682 if (!character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
5685 num += this.source[this.index++];
5687 if (num.length === 0) {
5688 this.throwUnexpectedToken();
5690 if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
5691 this.throwUnexpectedToken();
5694 type: 6 /* NumericLiteral */,
5695 value: parseInt('0x' + num, 16),
5696 lineNumber: this.lineNumber,
5697 lineStart: this.lineStart,
5702 Scanner.prototype.scanBinaryLiteral = function (start) {
5705 while (!this.eof()) {
5706 ch = this.source[this.index];
5707 if (ch !== '0' && ch !== '1') {
5710 num += this.source[this.index++];
5712 if (num.length === 0) {
5714 this.throwUnexpectedToken();
5717 ch = this.source.charCodeAt(this.index);
5718 /* istanbul ignore else */
5719 if (character_1.Character.isIdentifierStart(ch) || character_1.Character.isDecimalDigit(ch)) {
5720 this.throwUnexpectedToken();
5724 type: 6 /* NumericLiteral */,
5725 value: parseInt(num, 2),
5726 lineNumber: this.lineNumber,
5727 lineStart: this.lineStart,
5732 Scanner.prototype.scanOctalLiteral = function (prefix, start) {
5735 if (character_1.Character.isOctalDigit(prefix.charCodeAt(0))) {
5737 num = '0' + this.source[this.index++];
5742 while (!this.eof()) {
5743 if (!character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
5746 num += this.source[this.index++];
5748 if (!octal && num.length === 0) {
5750 this.throwUnexpectedToken();
5752 if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index)) || character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
5753 this.throwUnexpectedToken();
5756 type: 6 /* NumericLiteral */,
5757 value: parseInt(num, 8),
5759 lineNumber: this.lineNumber,
5760 lineStart: this.lineStart,
5765 Scanner.prototype.isImplicitOctalLiteral = function () {
5766 // Implicit octal, unless there is a non-octal digit.
5767 // (Annex B.1.1 on Numeric Literals)
5768 for (var i = this.index + 1; i < this.length; ++i) {
5769 var ch = this.source[i];
5770 if (ch === '8' || ch === '9') {
5773 if (!character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
5779 Scanner.prototype.scanNumericLiteral = function () {
5780 var start = this.index;
5781 var ch = this.source[start];
5782 assert_1.assert(character_1.Character.isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'), 'Numeric literal must start with a decimal digit or a decimal point');
5785 num = this.source[this.index++];
5786 ch = this.source[this.index];
5787 // Hex number starts with '0x'.
5788 // Octal number starts with '0'.
5789 // Octal number in ES6 starts with '0o'.
5790 // Binary number in ES6 starts with '0b'.
5792 if (ch === 'x' || ch === 'X') {
5794 return this.scanHexLiteral(start);
5796 if (ch === 'b' || ch === 'B') {
5798 return this.scanBinaryLiteral(start);
5800 if (ch === 'o' || ch === 'O') {
5801 return this.scanOctalLiteral(ch, start);
5803 if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
5804 if (this.isImplicitOctalLiteral()) {
5805 return this.scanOctalLiteral(ch, start);
5809 while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
5810 num += this.source[this.index++];
5812 ch = this.source[this.index];
5815 num += this.source[this.index++];
5816 while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
5817 num += this.source[this.index++];
5819 ch = this.source[this.index];
5821 if (ch === 'e' || ch === 'E') {
5822 num += this.source[this.index++];
5823 ch = this.source[this.index];
5824 if (ch === '+' || ch === '-') {
5825 num += this.source[this.index++];
5827 if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
5828 while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
5829 num += this.source[this.index++];
5833 this.throwUnexpectedToken();
5836 if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
5837 this.throwUnexpectedToken();
5840 type: 6 /* NumericLiteral */,
5841 value: parseFloat(num),
5842 lineNumber: this.lineNumber,
5843 lineStart: this.lineStart,
5848 // https://tc39.github.io/ecma262/#sec-literals-string-literals
5849 Scanner.prototype.scanStringLiteral = function () {
5850 var start = this.index;
5851 var quote = this.source[start];
5852 assert_1.assert((quote === '\'' || quote === '"'), 'String literal must starts with a quote');
5856 while (!this.eof()) {
5857 var ch = this.source[this.index++];
5862 else if (ch === '\\') {
5863 ch = this.source[this.index++];
5864 if (!ch || !character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
5867 if (this.source[this.index] === '{') {
5869 str += this.scanUnicodeCodePointEscape();
5872 var unescaped_1 = this.scanHexEscape(ch);
5873 if (unescaped_1 === null) {
5874 this.throwUnexpectedToken();
5880 var unescaped = this.scanHexEscape(ch);
5881 if (unescaped === null) {
5882 this.throwUnexpectedToken(messages_1.Messages.InvalidHexEscapeSequence);
5907 this.tolerateUnexpectedToken();
5910 if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
5911 var octToDec = this.octalToDecimal(ch);
5912 octal = octToDec.octal || octal;
5913 str += String.fromCharCode(octToDec.code);
5923 if (ch === '\r' && this.source[this.index] === '\n') {
5926 this.lineStart = this.index;
5929 else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
5938 this.throwUnexpectedToken();
5941 type: 8 /* StringLiteral */,
5944 lineNumber: this.lineNumber,
5945 lineStart: this.lineStart,
5950 // https://tc39.github.io/ecma262/#sec-template-literal-lexical-components
5951 Scanner.prototype.scanTemplate = function () {
5953 var terminated = false;
5954 var start = this.index;
5955 var head = (this.source[start] === '`');
5959 while (!this.eof()) {
5960 var ch = this.source[this.index++];
5967 else if (ch === '$') {
5968 if (this.source[this.index] === '{') {
5969 this.curlyStack.push('${');
5976 else if (ch === '\\') {
5977 ch = this.source[this.index++];
5978 if (!character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
5990 if (this.source[this.index] === '{') {
5992 cooked += this.scanUnicodeCodePointEscape();
5995 var restore = this.index;
5996 var unescaped_2 = this.scanHexEscape(ch);
5997 if (unescaped_2 !== null) {
5998 cooked += unescaped_2;
6001 this.index = restore;
6007 var unescaped = this.scanHexEscape(ch);
6008 if (unescaped === null) {
6009 this.throwUnexpectedToken(messages_1.Messages.InvalidHexEscapeSequence);
6011 cooked += unescaped;
6024 if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
6025 // Illegal: \01 \02 and so on
6026 this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
6030 else if (character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
6032 this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
6042 if (ch === '\r' && this.source[this.index] === '\n') {
6045 this.lineStart = this.index;
6048 else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
6050 if (ch === '\r' && this.source[this.index] === '\n') {
6053 this.lineStart = this.index;
6061 this.throwUnexpectedToken();
6064 this.curlyStack.pop();
6067 type: 10 /* Template */,
6068 value: this.source.slice(start + 1, this.index - rawOffset),
6072 lineNumber: this.lineNumber,
6073 lineStart: this.lineStart,
6078 // https://tc39.github.io/ecma262/#sec-literals-regular-expression-literals
6079 Scanner.prototype.testRegExp = function (pattern, flags) {
6080 // The BMP character to use as a replacement for astral symbols when
6081 // translating an ES6 "u"-flagged pattern to an ES5-compatible
6083 // Note: replacing with '\uFFFF' enables false positives in unlikely
6084 // scenarios. For example, `[\u{1044f}-\u{10440}]` is an invalid
6085 // pattern that would not be detected by this substitution.
6086 var astralSubstitute = '\uFFFF';
6089 if (flags.indexOf('u') >= 0) {
6091 .replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, function ($0, $1, $2) {
6092 var codePoint = parseInt($1 || $2, 16);
6093 if (codePoint > 0x10FFFF) {
6094 self.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
6096 if (codePoint <= 0xFFFF) {
6097 return String.fromCharCode(codePoint);
6099 return astralSubstitute;
6101 .replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, astralSubstitute);
6103 // First, detect invalid regular expressions.
6108 this.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
6110 // Return a regular expression object for this pattern-flag pair, or
6111 // `null` in case the current environment doesn't support the flags it
6114 return new RegExp(pattern, flags);
6117 /* istanbul ignore next */
6121 Scanner.prototype.scanRegExpBody = function () {
6122 var ch = this.source[this.index];
6123 assert_1.assert(ch === '/', 'Regular expression literal must start with a slash');
6124 var str = this.source[this.index++];
6125 var classMarker = false;
6126 var terminated = false;
6127 while (!this.eof()) {
6128 ch = this.source[this.index++];
6131 ch = this.source[this.index++];
6132 // https://tc39.github.io/ecma262/#sec-literals-regular-expression-literals
6133 if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
6134 this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
6138 else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
6139 this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
6141 else if (classMarker) {
6143 classMarker = false;
6151 else if (ch === '[') {
6157 this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
6159 // Exclude leading and trailing slash.
6160 return str.substr(1, str.length - 2);
6162 Scanner.prototype.scanRegExpFlags = function () {
6165 while (!this.eof()) {
6166 var ch = this.source[this.index];
6167 if (!character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
6171 if (ch === '\\' && !this.eof()) {
6172 ch = this.source[this.index];
6175 var restore = this.index;
6176 var char = this.scanHexEscape('u');
6177 if (char !== null) {
6179 for (str += '\\u'; restore < this.index; ++restore) {
6180 str += this.source[restore];
6184 this.index = restore;
6188 this.tolerateUnexpectedToken();
6192 this.tolerateUnexpectedToken();
6202 Scanner.prototype.scanRegExp = function () {
6203 var start = this.index;
6204 var pattern = this.scanRegExpBody();
6205 var flags = this.scanRegExpFlags();
6206 var value = this.testRegExp(pattern, flags);
6208 type: 9 /* RegularExpression */,
6213 lineNumber: this.lineNumber,
6214 lineStart: this.lineStart,
6219 Scanner.prototype.lex = function () {
6224 lineNumber: this.lineNumber,
6225 lineStart: this.lineStart,
6230 var cp = this.source.charCodeAt(this.index);
6231 if (character_1.Character.isIdentifierStart(cp)) {
6232 return this.scanIdentifier();
6234 // Very common: ( and ) and ;
6235 if (cp === 0x28 || cp === 0x29 || cp === 0x3B) {
6236 return this.scanPunctuator();
6238 // String literal starts with single quote (U+0027) or double quote (U+0022).
6239 if (cp === 0x27 || cp === 0x22) {
6240 return this.scanStringLiteral();
6242 // Dot (.) U+002E can also start a floating-point number, hence the need
6243 // to check the next character.
6245 if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index + 1))) {
6246 return this.scanNumericLiteral();
6248 return this.scanPunctuator();
6250 if (character_1.Character.isDecimalDigit(cp)) {
6251 return this.scanNumericLiteral();
6253 // Template literals start with ` (U+0060) for template head
6254 // or } (U+007D) for template middle or template tail.
6255 if (cp === 0x60 || (cp === 0x7D && this.curlyStack[this.curlyStack.length - 1] === '${')) {
6256 return this.scanTemplate();
6258 // Possible identifier start in a surrogate pair.
6259 if (cp >= 0xD800 && cp < 0xDFFF) {
6260 if (character_1.Character.isIdentifierStart(this.codePointAt(this.index))) {
6261 return this.scanIdentifier();
6264 return this.scanPunctuator();
6268 exports.Scanner = Scanner;
6273 /***/ function(module, exports) {
6276 Object.defineProperty(exports, "__esModule", { value: true });
6277 exports.TokenName = {};
6278 exports.TokenName[1 /* BooleanLiteral */] = 'Boolean';
6279 exports.TokenName[2 /* EOF */] = '<end>';
6280 exports.TokenName[3 /* Identifier */] = 'Identifier';
6281 exports.TokenName[4 /* Keyword */] = 'Keyword';
6282 exports.TokenName[5 /* NullLiteral */] = 'Null';
6283 exports.TokenName[6 /* NumericLiteral */] = 'Numeric';
6284 exports.TokenName[7 /* Punctuator */] = 'Punctuator';
6285 exports.TokenName[8 /* StringLiteral */] = 'String';
6286 exports.TokenName[9 /* RegularExpression */] = 'RegularExpression';
6287 exports.TokenName[10 /* Template */] = 'Template';
6292 /***/ function(module, exports) {
6295 // Generated by generate-xhtml-entities.js. DO NOT MODIFY!
6296 Object.defineProperty(exports, "__esModule", { value: true });
6297 exports.XHTMLEntities = {
6555 /***/ function(module, exports, __webpack_require__) {
6558 Object.defineProperty(exports, "__esModule", { value: true });
6559 var error_handler_1 = __webpack_require__(10);
6560 var scanner_1 = __webpack_require__(12);
6561 var token_1 = __webpack_require__(13);
6562 var Reader = (function () {
6565 this.curly = this.paren = -1;
6567 // A function following one of those tokens is an expression.
6568 Reader.prototype.beforeFunctionExpression = function (t) {
6569 return ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
6570 'return', 'case', 'delete', 'throw', 'void',
6571 // assignment operators
6572 '=', '+=', '-=', '*=', '**=', '/=', '%=', '<<=', '>>=', '>>>=',
6573 '&=', '|=', '^=', ',',
6574 // binary/unary operators
6575 '+', '-', '*', '**', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
6576 '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
6577 '<=', '<', '>', '!=', '!=='].indexOf(t) >= 0;
6579 // Determine if forward slash (/) is an operator or part of a regular expression
6580 // https://github.com/mozilla/sweet.js/wiki/design
6581 Reader.prototype.isRegexStart = function () {
6582 var previous = this.values[this.values.length - 1];
6583 var regex = (previous !== null);
6590 var keyword = this.values[this.paren - 1];
6591 regex = (keyword === 'if' || keyword === 'while' || keyword === 'for' || keyword === 'with');
6594 // Dividing a function by anything makes little sense,
6595 // but we have to check for that.
6597 if (this.values[this.curly - 3] === 'function') {
6598 // Anonymous function, e.g. function(){} /42
6599 var check = this.values[this.curly - 4];
6600 regex = check ? !this.beforeFunctionExpression(check) : false;
6602 else if (this.values[this.curly - 4] === 'function') {
6603 // Named function, e.g. function f(){} /42/
6604 var check = this.values[this.curly - 5];
6605 regex = check ? !this.beforeFunctionExpression(check) : true;
6613 Reader.prototype.push = function (token) {
6614 if (token.type === 7 /* Punctuator */ || token.type === 4 /* Keyword */) {
6615 if (token.value === '{') {
6616 this.curly = this.values.length;
6618 else if (token.value === '(') {
6619 this.paren = this.values.length;
6621 this.values.push(token.value);
6624 this.values.push(null);
6629 var Tokenizer = (function () {
6630 function Tokenizer(code, config) {
6631 this.errorHandler = new error_handler_1.ErrorHandler();
6632 this.errorHandler.tolerant = config ? (typeof config.tolerant === 'boolean' && config.tolerant) : false;
6633 this.scanner = new scanner_1.Scanner(code, this.errorHandler);
6634 this.scanner.trackComment = config ? (typeof config.comment === 'boolean' && config.comment) : false;
6635 this.trackRange = config ? (typeof config.range === 'boolean' && config.range) : false;
6636 this.trackLoc = config ? (typeof config.loc === 'boolean' && config.loc) : false;
6638 this.reader = new Reader();
6640 Tokenizer.prototype.errors = function () {
6641 return this.errorHandler.errors;
6643 Tokenizer.prototype.getNextToken = function () {
6644 if (this.buffer.length === 0) {
6645 var comments = this.scanner.scanComments();
6646 if (this.scanner.trackComment) {
6647 for (var i = 0; i < comments.length; ++i) {
6648 var e = comments[i];
6649 var value = this.scanner.source.slice(e.slice[0], e.slice[1]);
6651 type: e.multiLine ? 'BlockComment' : 'LineComment',
6654 if (this.trackRange) {
6655 comment.range = e.range;
6657 if (this.trackLoc) {
6658 comment.loc = e.loc;
6660 this.buffer.push(comment);
6663 if (!this.scanner.eof()) {
6665 if (this.trackLoc) {
6668 line: this.scanner.lineNumber,
6669 column: this.scanner.index - this.scanner.lineStart
6674 var startRegex = (this.scanner.source[this.scanner.index] === '/') && this.reader.isRegexStart();
6675 var token = startRegex ? this.scanner.scanRegExp() : this.scanner.lex();
6676 this.reader.push(token);
6678 type: token_1.TokenName[token.type],
6679 value: this.scanner.source.slice(token.start, token.end)
6681 if (this.trackRange) {
6682 entry.range = [token.start, token.end];
6684 if (this.trackLoc) {
6686 line: this.scanner.lineNumber,
6687 column: this.scanner.index - this.scanner.lineStart
6691 if (token.type === 9 /* RegularExpression */) {
6692 var pattern = token.pattern;
6693 var flags = token.flags;
6694 entry.regex = { pattern: pattern, flags: flags };
6696 this.buffer.push(entry);
6699 return this.buffer.shift();
6703 exports.Tokenizer = Tokenizer;