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__) {
61 Copyright JS Foundation and other contributors, https://js.foundation/
63 Redistribution and use in source and binary forms, with or without
64 modification, are permitted provided that the following conditions are met:
66 * Redistributions of source code must retain the above copyright
67 notice, this list of conditions and the following disclaimer.
68 * Redistributions in binary form must reproduce the above copyright
69 notice, this list of conditions and the following disclaimer in the
70 documentation and/or other materials provided with the distribution.
72 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
73 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
74 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
75 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
76 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
77 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
78 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
79 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
80 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
81 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84 var comment_handler_1 = __webpack_require__(1);
85 var parser_1 = __webpack_require__(3);
86 var jsx_parser_1 = __webpack_require__(11);
87 var tokenizer_1 = __webpack_require__(15);
88 function parse(code, options, delegate) {
89 var commentHandler = null;
90 var proxyDelegate = function (node, metadata) {
92 delegate(node, metadata);
95 commentHandler.visit(node, metadata);
98 var parserDelegate = (typeof delegate === 'function') ? proxyDelegate : null;
99 var collectComment = false;
101 collectComment = (typeof options.comment === 'boolean' && options.comment);
102 var attachComment = (typeof options.attachComment === 'boolean' && options.attachComment);
103 if (collectComment || attachComment) {
104 commentHandler = new comment_handler_1.CommentHandler();
105 commentHandler.attach = attachComment;
106 options.comment = true;
107 parserDelegate = proxyDelegate;
111 if (options && typeof options.jsx === 'boolean' && options.jsx) {
112 parser = new jsx_parser_1.JSXParser(code, options, parserDelegate);
115 parser = new parser_1.Parser(code, options, parserDelegate);
117 var ast = (parser.parseProgram());
118 if (collectComment) {
119 ast.comments = commentHandler.comments;
121 if (parser.config.tokens) {
122 ast.tokens = parser.tokens;
124 if (parser.config.tolerant) {
125 ast.errors = parser.errorHandler.errors;
129 exports.parse = parse;
130 function tokenize(code, options, delegate) {
131 var tokenizer = new tokenizer_1.Tokenizer(code, options);
136 var token = tokenizer.getNextToken();
141 token = delegate(token);
147 tokenizer.errorHandler.tolerate(e);
149 if (tokenizer.errorHandler.tolerant) {
150 tokens.errors = tokenizer.errors();
154 exports.tokenize = tokenize;
155 var syntax_1 = __webpack_require__(2);
156 exports.Syntax = syntax_1.Syntax;
157 // Sync with *.json manifests.
158 exports.version = '3.1.3';
163 /***/ function(module, exports, __webpack_require__) {
166 var syntax_1 = __webpack_require__(2);
167 var CommentHandler = (function () {
168 function CommentHandler() {
175 CommentHandler.prototype.insertInnerComments = function (node, metadata) {
176 // innnerComments for properties empty block
177 // `function a() {/** comments **\/}`
178 if (node.type === syntax_1.Syntax.BlockStatement && node.body.length === 0) {
179 var innerComments = [];
180 for (var i = this.leading.length - 1; i >= 0; --i) {
181 var entry = this.leading[i];
182 if (metadata.end.offset >= entry.start) {
183 innerComments.unshift(entry.comment);
184 this.leading.splice(i, 1);
185 this.trailing.splice(i, 1);
188 if (innerComments.length) {
189 node.innerComments = innerComments;
193 CommentHandler.prototype.findTrailingComments = function (node, metadata) {
194 var trailingComments = [];
195 if (this.trailing.length > 0) {
196 for (var i = this.trailing.length - 1; i >= 0; --i) {
197 var entry_1 = this.trailing[i];
198 if (entry_1.start >= metadata.end.offset) {
199 trailingComments.unshift(entry_1.comment);
202 this.trailing.length = 0;
203 return trailingComments;
205 var entry = this.stack[this.stack.length - 1];
206 if (entry && entry.node.trailingComments) {
207 var firstComment = entry.node.trailingComments[0];
208 if (firstComment && firstComment.range[0] >= metadata.end.offset) {
209 trailingComments = entry.node.trailingComments;
210 delete entry.node.trailingComments;
213 return trailingComments;
215 CommentHandler.prototype.findLeadingComments = function (node, metadata) {
216 var leadingComments = [];
218 while (this.stack.length > 0) {
219 var entry = this.stack[this.stack.length - 1];
220 if (entry && entry.start >= metadata.start.offset) {
221 target = this.stack.pop().node;
228 var count = target.leadingComments ? target.leadingComments.length : 0;
229 for (var i = count - 1; i >= 0; --i) {
230 var comment = target.leadingComments[i];
231 if (comment.range[1] <= metadata.start.offset) {
232 leadingComments.unshift(comment);
233 target.leadingComments.splice(i, 1);
236 if (target.leadingComments && target.leadingComments.length === 0) {
237 delete target.leadingComments;
239 return leadingComments;
241 for (var i = this.leading.length - 1; i >= 0; --i) {
242 var entry = this.leading[i];
243 if (entry.start <= metadata.start.offset) {
244 leadingComments.unshift(entry.comment);
245 this.leading.splice(i, 1);
248 return leadingComments;
250 CommentHandler.prototype.visitNode = function (node, metadata) {
251 if (node.type === syntax_1.Syntax.Program && node.body.length > 0) {
254 this.insertInnerComments(node, metadata);
255 var trailingComments = this.findTrailingComments(node, metadata);
256 var leadingComments = this.findLeadingComments(node, metadata);
257 if (leadingComments.length > 0) {
258 node.leadingComments = leadingComments;
260 if (trailingComments.length > 0) {
261 node.trailingComments = trailingComments;
265 start: metadata.start.offset
268 CommentHandler.prototype.visitComment = function (node, metadata) {
269 var type = (node.type[0] === 'L') ? 'Line' : 'Block';
275 comment.range = node.range;
278 comment.loc = node.loc;
280 this.comments.push(comment);
286 range: [metadata.start.offset, metadata.end.offset]
288 start: metadata.start.offset
291 entry.comment.loc = node.loc;
294 this.leading.push(entry);
295 this.trailing.push(entry);
298 CommentHandler.prototype.visit = function (node, metadata) {
299 if (node.type === 'LineComment') {
300 this.visitComment(node, metadata);
302 else if (node.type === 'BlockComment') {
303 this.visitComment(node, metadata);
305 else if (this.attach) {
306 this.visitNode(node, metadata);
309 return CommentHandler;
311 exports.CommentHandler = CommentHandler;
316 /***/ function(module, exports) {
320 AssignmentExpression: 'AssignmentExpression',
321 AssignmentPattern: 'AssignmentPattern',
322 ArrayExpression: 'ArrayExpression',
323 ArrayPattern: 'ArrayPattern',
324 ArrowFunctionExpression: 'ArrowFunctionExpression',
325 BlockStatement: 'BlockStatement',
326 BinaryExpression: 'BinaryExpression',
327 BreakStatement: 'BreakStatement',
328 CallExpression: 'CallExpression',
329 CatchClause: 'CatchClause',
330 ClassBody: 'ClassBody',
331 ClassDeclaration: 'ClassDeclaration',
332 ClassExpression: 'ClassExpression',
333 ConditionalExpression: 'ConditionalExpression',
334 ContinueStatement: 'ContinueStatement',
335 DoWhileStatement: 'DoWhileStatement',
336 DebuggerStatement: 'DebuggerStatement',
337 EmptyStatement: 'EmptyStatement',
338 ExportAllDeclaration: 'ExportAllDeclaration',
339 ExportDefaultDeclaration: 'ExportDefaultDeclaration',
340 ExportNamedDeclaration: 'ExportNamedDeclaration',
341 ExportSpecifier: 'ExportSpecifier',
342 ExpressionStatement: 'ExpressionStatement',
343 ForStatement: 'ForStatement',
344 ForOfStatement: 'ForOfStatement',
345 ForInStatement: 'ForInStatement',
346 FunctionDeclaration: 'FunctionDeclaration',
347 FunctionExpression: 'FunctionExpression',
348 Identifier: 'Identifier',
349 IfStatement: 'IfStatement',
350 ImportDeclaration: 'ImportDeclaration',
351 ImportDefaultSpecifier: 'ImportDefaultSpecifier',
352 ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
353 ImportSpecifier: 'ImportSpecifier',
355 LabeledStatement: 'LabeledStatement',
356 LogicalExpression: 'LogicalExpression',
357 MemberExpression: 'MemberExpression',
358 MetaProperty: 'MetaProperty',
359 MethodDefinition: 'MethodDefinition',
360 NewExpression: 'NewExpression',
361 ObjectExpression: 'ObjectExpression',
362 ObjectPattern: 'ObjectPattern',
364 Property: 'Property',
365 RestElement: 'RestElement',
366 ReturnStatement: 'ReturnStatement',
367 SequenceExpression: 'SequenceExpression',
368 SpreadElement: 'SpreadElement',
370 SwitchCase: 'SwitchCase',
371 SwitchStatement: 'SwitchStatement',
372 TaggedTemplateExpression: 'TaggedTemplateExpression',
373 TemplateElement: 'TemplateElement',
374 TemplateLiteral: 'TemplateLiteral',
375 ThisExpression: 'ThisExpression',
376 ThrowStatement: 'ThrowStatement',
377 TryStatement: 'TryStatement',
378 UnaryExpression: 'UnaryExpression',
379 UpdateExpression: 'UpdateExpression',
380 VariableDeclaration: 'VariableDeclaration',
381 VariableDeclarator: 'VariableDeclarator',
382 WhileStatement: 'WhileStatement',
383 WithStatement: 'WithStatement',
384 YieldExpression: 'YieldExpression'
390 /***/ function(module, exports, __webpack_require__) {
393 var assert_1 = __webpack_require__(4);
394 var messages_1 = __webpack_require__(5);
395 var error_handler_1 = __webpack_require__(6);
396 var token_1 = __webpack_require__(7);
397 var scanner_1 = __webpack_require__(8);
398 var syntax_1 = __webpack_require__(2);
399 var Node = __webpack_require__(10);
400 var ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder';
401 var Parser = (function () {
402 function Parser(code, options, delegate) {
403 if (options === void 0) { options = {}; }
405 range: (typeof options.range === 'boolean') && options.range,
406 loc: (typeof options.loc === 'boolean') && options.loc,
408 tokens: (typeof options.tokens === 'boolean') && options.tokens,
409 comment: (typeof options.comment === 'boolean') && options.comment,
410 tolerant: (typeof options.tolerant === 'boolean') && options.tolerant
412 if (this.config.loc && options.source && options.source !== null) {
413 this.config.source = String(options.source);
415 this.delegate = delegate;
416 this.errorHandler = new error_handler_1.ErrorHandler();
417 this.errorHandler.tolerant = this.config.tolerant;
418 this.scanner = new scanner_1.Scanner(code, this.errorHandler);
419 this.scanner.trackComment = this.config.comment;
420 this.operatorPrecedence = {
448 this.sourceType = (options && options.sourceType === 'module') ? 'module' : 'script';
449 this.lookahead = null;
450 this.hasLineTerminator = false;
454 firstCoverInitializedNameError: null,
455 isAssignmentTarget: false,
456 isBindingElement: false,
457 inFunctionBody: false,
461 strict: (this.sourceType === 'module')
466 lineNumber: this.scanner.lineNumber,
471 lineNumber: this.scanner.lineNumber,
476 index: this.scanner.index,
477 lineNumber: this.scanner.lineNumber,
478 lineStart: this.scanner.lineStart
481 Parser.prototype.throwError = function (messageFormat) {
483 for (var _i = 1; _i < arguments.length; _i++) {
484 values[_i - 1] = arguments[_i];
486 var args = Array.prototype.slice.call(arguments, 1);
487 var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
488 assert_1.assert(idx < args.length, 'Message reference must be in range');
491 var index = this.lastMarker.index;
492 var line = this.lastMarker.lineNumber;
493 var column = this.lastMarker.index - this.lastMarker.lineStart + 1;
494 throw this.errorHandler.createError(index, line, column, msg);
496 Parser.prototype.tolerateError = function (messageFormat) {
498 for (var _i = 1; _i < arguments.length; _i++) {
499 values[_i - 1] = arguments[_i];
501 var args = Array.prototype.slice.call(arguments, 1);
502 var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
503 assert_1.assert(idx < args.length, 'Message reference must be in range');
506 var index = this.lastMarker.index;
507 var line = this.scanner.lineNumber;
508 var column = this.lastMarker.index - this.lastMarker.lineStart + 1;
509 this.errorHandler.tolerateError(index, line, column, msg);
511 // Throw an exception because of the token.
512 Parser.prototype.unexpectedTokenError = function (token, message) {
513 var msg = message || messages_1.Messages.UnexpectedToken;
517 msg = (token.type === token_1.Token.EOF) ? messages_1.Messages.UnexpectedEOS :
518 (token.type === token_1.Token.Identifier) ? messages_1.Messages.UnexpectedIdentifier :
519 (token.type === token_1.Token.NumericLiteral) ? messages_1.Messages.UnexpectedNumber :
520 (token.type === token_1.Token.StringLiteral) ? messages_1.Messages.UnexpectedString :
521 (token.type === token_1.Token.Template) ? messages_1.Messages.UnexpectedTemplate :
522 messages_1.Messages.UnexpectedToken;
523 if (token.type === token_1.Token.Keyword) {
524 if (this.scanner.isFutureReservedWord(token.value)) {
525 msg = messages_1.Messages.UnexpectedReserved;
527 else if (this.context.strict && this.scanner.isStrictModeReservedWord(token.value)) {
528 msg = messages_1.Messages.StrictReservedWord;
532 value = (token.type === token_1.Token.Template) ? token.value.raw : token.value;
537 msg = msg.replace('%0', value);
538 if (token && typeof token.lineNumber === 'number') {
539 var index = token.start;
540 var line = token.lineNumber;
541 var column = token.start - this.lastMarker.lineStart + 1;
542 return this.errorHandler.createError(index, line, column, msg);
545 var index = this.lastMarker.index;
546 var line = this.lastMarker.lineNumber;
547 var column = index - this.lastMarker.lineStart + 1;
548 return this.errorHandler.createError(index, line, column, msg);
551 Parser.prototype.throwUnexpectedToken = function (token, message) {
552 throw this.unexpectedTokenError(token, message);
554 Parser.prototype.tolerateUnexpectedToken = function (token, message) {
555 this.errorHandler.tolerate(this.unexpectedTokenError(token, message));
557 Parser.prototype.collectComments = function () {
558 if (!this.config.comment) {
559 this.scanner.scanComments();
562 var comments = this.scanner.scanComments();
563 if (comments.length > 0 && this.delegate) {
564 for (var i = 0; i < comments.length; ++i) {
568 type: e.multiLine ? 'BlockComment' : 'LineComment',
569 value: this.scanner.source.slice(e.slice[0], e.slice[1])
571 if (this.config.range) {
572 node.range = e.range;
574 if (this.config.loc) {
579 line: e.loc.start.line,
580 column: e.loc.start.column,
584 line: e.loc.end.line,
585 column: e.loc.end.column,
589 this.delegate(node, metadata);
594 // From internal representation to an external structure
595 Parser.prototype.getTokenRaw = function (token) {
596 return this.scanner.source.slice(token.start, token.end);
598 Parser.prototype.convertToken = function (token) {
601 type: token_1.TokenName[token.type],
602 value: this.getTokenRaw(token)
604 if (this.config.range) {
605 t.range = [token.start, token.end];
607 if (this.config.loc) {
610 line: this.startMarker.lineNumber,
611 column: this.startMarker.index - this.startMarker.lineStart
614 line: this.scanner.lineNumber,
615 column: this.scanner.index - this.scanner.lineStart
620 t.regex = token.regex;
624 Parser.prototype.nextToken = function () {
625 var token = this.lookahead;
626 this.lastMarker.index = this.scanner.index;
627 this.lastMarker.lineNumber = this.scanner.lineNumber;
628 this.lastMarker.lineStart = this.scanner.lineStart;
629 this.collectComments();
630 this.startMarker.index = this.scanner.index;
631 this.startMarker.lineNumber = this.scanner.lineNumber;
632 this.startMarker.lineStart = this.scanner.lineStart;
634 next = this.scanner.lex();
635 this.hasLineTerminator = (token && next) ? (token.lineNumber !== next.lineNumber) : false;
636 if (next && this.context.strict && next.type === token_1.Token.Identifier) {
637 if (this.scanner.isStrictModeReservedWord(next.value)) {
638 next.type = token_1.Token.Keyword;
641 this.lookahead = next;
642 if (this.config.tokens && next.type !== token_1.Token.EOF) {
643 this.tokens.push(this.convertToken(next));
647 Parser.prototype.nextRegexToken = function () {
648 this.collectComments();
649 var token = this.scanner.scanRegExp();
650 if (this.config.tokens) {
651 // Pop the previous token, '/' or '/='
652 // This is added from the lookahead token.
654 this.tokens.push(this.convertToken(token));
656 // Prime the next lookahead.
657 this.lookahead = token;
661 Parser.prototype.createNode = function () {
663 index: this.startMarker.index,
664 line: this.startMarker.lineNumber,
665 column: this.startMarker.index - this.startMarker.lineStart
668 Parser.prototype.startNode = function (token) {
671 line: token.lineNumber,
672 column: token.start - token.lineStart
675 Parser.prototype.finalize = function (meta, node) {
676 if (this.config.range) {
677 node.range = [meta.index, this.lastMarker.index];
679 if (this.config.loc) {
686 line: this.lastMarker.lineNumber,
687 column: this.lastMarker.index - this.lastMarker.lineStart
690 if (this.config.source) {
691 node.loc.source = this.config.source;
702 line: this.lastMarker.lineNumber,
703 column: this.lastMarker.index - this.lastMarker.lineStart,
704 offset: this.lastMarker.index
707 this.delegate(node, metadata);
711 // Expect the next token to match the specified punctuator.
712 // If not, an exception will be thrown.
713 Parser.prototype.expect = function (value) {
714 var token = this.nextToken();
715 if (token.type !== token_1.Token.Punctuator || token.value !== value) {
716 this.throwUnexpectedToken(token);
719 // Quietly expect a comma when in tolerant mode, otherwise delegates to expect().
720 Parser.prototype.expectCommaSeparator = function () {
721 if (this.config.tolerant) {
722 var token = this.lookahead;
723 if (token.type === token_1.Token.Punctuator && token.value === ',') {
726 else if (token.type === token_1.Token.Punctuator && token.value === ';') {
728 this.tolerateUnexpectedToken(token);
731 this.tolerateUnexpectedToken(token, messages_1.Messages.UnexpectedToken);
738 // Expect the next token to match the specified keyword.
739 // If not, an exception will be thrown.
740 Parser.prototype.expectKeyword = function (keyword) {
741 var token = this.nextToken();
742 if (token.type !== token_1.Token.Keyword || token.value !== keyword) {
743 this.throwUnexpectedToken(token);
746 // Return true if the next token matches the specified punctuator.
747 Parser.prototype.match = function (value) {
748 return this.lookahead.type === token_1.Token.Punctuator && this.lookahead.value === value;
750 // Return true if the next token matches the specified keyword
751 Parser.prototype.matchKeyword = function (keyword) {
752 return this.lookahead.type === token_1.Token.Keyword && this.lookahead.value === keyword;
754 // Return true if the next token matches the specified contextual keyword
755 // (where an identifier is sometimes a keyword depending on the context)
756 Parser.prototype.matchContextualKeyword = function (keyword) {
757 return this.lookahead.type === token_1.Token.Identifier && this.lookahead.value === keyword;
759 // Return true if the next token is an assignment operator
760 Parser.prototype.matchAssign = function () {
761 if (this.lookahead.type !== token_1.Token.Punctuator) {
764 var op = this.lookahead.value;
779 // Cover grammar support.
781 // When an assignment expression position starts with an left parenthesis, the determination of the type
782 // of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
783 // or the first comma. This situation also defers the determination of all the expressions nested in the pair.
785 // There are three productions that can be parsed in a parentheses pair that needs to be determined
786 // after the outermost pair is closed. They are:
788 // 1. AssignmentExpression
789 // 2. BindingElements
790 // 3. AssignmentTargets
792 // In order to avoid exponential backtracking, we use two flags to denote if the production can be
793 // binding element or assignment target.
795 // The three productions have the relationship:
797 // BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
799 // with a single exception that CoverInitializedName when used directly in an Expression, generates
800 // an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
801 // first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
803 // isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
804 // effect the current flags. This means the production the parser parses is only used as an expression. Therefore
805 // the CoverInitializedName check is conducted.
807 // inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
808 // the flags outside of the parser. This means the production the parser parses is used as a part of a potential
809 // pattern. The CoverInitializedName check is deferred.
810 Parser.prototype.isolateCoverGrammar = function (parseFunction) {
811 var previousIsBindingElement = this.context.isBindingElement;
812 var previousIsAssignmentTarget = this.context.isAssignmentTarget;
813 var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
814 this.context.isBindingElement = true;
815 this.context.isAssignmentTarget = true;
816 this.context.firstCoverInitializedNameError = null;
817 var result = parseFunction.call(this);
818 if (this.context.firstCoverInitializedNameError !== null) {
819 this.throwUnexpectedToken(this.context.firstCoverInitializedNameError);
821 this.context.isBindingElement = previousIsBindingElement;
822 this.context.isAssignmentTarget = previousIsAssignmentTarget;
823 this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError;
826 Parser.prototype.inheritCoverGrammar = function (parseFunction) {
827 var previousIsBindingElement = this.context.isBindingElement;
828 var previousIsAssignmentTarget = this.context.isAssignmentTarget;
829 var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
830 this.context.isBindingElement = true;
831 this.context.isAssignmentTarget = true;
832 this.context.firstCoverInitializedNameError = null;
833 var result = parseFunction.call(this);
834 this.context.isBindingElement = this.context.isBindingElement && previousIsBindingElement;
835 this.context.isAssignmentTarget = this.context.isAssignmentTarget && previousIsAssignmentTarget;
836 this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError || this.context.firstCoverInitializedNameError;
839 Parser.prototype.consumeSemicolon = function () {
840 if (this.match(';')) {
843 else if (!this.hasLineTerminator) {
844 if (this.lookahead.type !== token_1.Token.EOF && !this.match('}')) {
845 this.throwUnexpectedToken(this.lookahead);
847 this.lastMarker.index = this.startMarker.index;
848 this.lastMarker.lineNumber = this.startMarker.lineNumber;
849 this.lastMarker.lineStart = this.startMarker.lineStart;
852 // ECMA-262 12.2 Primary Expressions
853 Parser.prototype.parsePrimaryExpression = function () {
854 var node = this.createNode();
856 var value, token, raw;
857 switch (this.lookahead.type) {
858 case token_1.Token.Identifier:
859 if (this.sourceType === 'module' && this.lookahead.value === 'await') {
860 this.tolerateUnexpectedToken(this.lookahead);
862 expr = this.finalize(node, new Node.Identifier(this.nextToken().value));
864 case token_1.Token.NumericLiteral:
865 case token_1.Token.StringLiteral:
866 if (this.context.strict && this.lookahead.octal) {
867 this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.StrictOctalLiteral);
869 this.context.isAssignmentTarget = false;
870 this.context.isBindingElement = false;
871 token = this.nextToken();
872 raw = this.getTokenRaw(token);
873 expr = this.finalize(node, new Node.Literal(token.value, raw));
875 case token_1.Token.BooleanLiteral:
876 this.context.isAssignmentTarget = false;
877 this.context.isBindingElement = false;
878 token = this.nextToken();
879 token.value = (token.value === 'true');
880 raw = this.getTokenRaw(token);
881 expr = this.finalize(node, new Node.Literal(token.value, raw));
883 case token_1.Token.NullLiteral:
884 this.context.isAssignmentTarget = false;
885 this.context.isBindingElement = false;
886 token = this.nextToken();
888 raw = this.getTokenRaw(token);
889 expr = this.finalize(node, new Node.Literal(token.value, raw));
891 case token_1.Token.Template:
892 expr = this.parseTemplateLiteral();
894 case token_1.Token.Punctuator:
895 value = this.lookahead.value;
898 this.context.isBindingElement = false;
899 expr = this.inheritCoverGrammar(this.parseGroupExpression);
902 expr = this.inheritCoverGrammar(this.parseArrayInitializer);
905 expr = this.inheritCoverGrammar(this.parseObjectInitializer);
909 this.context.isAssignmentTarget = false;
910 this.context.isBindingElement = false;
911 this.scanner.index = this.startMarker.index;
912 token = this.nextRegexToken();
913 raw = this.getTokenRaw(token);
914 expr = this.finalize(node, new Node.RegexLiteral(token.value, raw, token.regex));
917 this.throwUnexpectedToken(this.nextToken());
920 case token_1.Token.Keyword:
921 if (!this.context.strict && this.context.allowYield && this.matchKeyword('yield')) {
922 expr = this.parseIdentifierName();
924 else if (!this.context.strict && this.matchKeyword('let')) {
925 expr = this.finalize(node, new Node.Identifier(this.nextToken().value));
928 this.context.isAssignmentTarget = false;
929 this.context.isBindingElement = false;
930 if (this.matchKeyword('function')) {
931 expr = this.parseFunctionExpression();
933 else if (this.matchKeyword('this')) {
935 expr = this.finalize(node, new Node.ThisExpression());
937 else if (this.matchKeyword('class')) {
938 expr = this.parseClassExpression();
941 this.throwUnexpectedToken(this.nextToken());
946 this.throwUnexpectedToken(this.nextToken());
950 // ECMA-262 12.2.5 Array Initializer
951 Parser.prototype.parseSpreadElement = function () {
952 var node = this.createNode();
954 var arg = this.inheritCoverGrammar(this.parseAssignmentExpression);
955 return this.finalize(node, new Node.SpreadElement(arg));
957 Parser.prototype.parseArrayInitializer = function () {
958 var node = this.createNode();
961 while (!this.match(']')) {
962 if (this.match(',')) {
966 else if (this.match('...')) {
967 var element = this.parseSpreadElement();
968 if (!this.match(']')) {
969 this.context.isAssignmentTarget = false;
970 this.context.isBindingElement = false;
973 elements.push(element);
976 elements.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
977 if (!this.match(']')) {
983 return this.finalize(node, new Node.ArrayExpression(elements));
985 // ECMA-262 12.2.6 Object Initializer
986 Parser.prototype.parsePropertyMethod = function (params) {
987 this.context.isAssignmentTarget = false;
988 this.context.isBindingElement = false;
989 var previousStrict = this.context.strict;
990 var body = this.isolateCoverGrammar(this.parseFunctionSourceElements);
991 if (this.context.strict && params.firstRestricted) {
992 this.tolerateUnexpectedToken(params.firstRestricted, params.message);
994 if (this.context.strict && params.stricted) {
995 this.tolerateUnexpectedToken(params.stricted, params.message);
997 this.context.strict = previousStrict;
1000 Parser.prototype.parsePropertyMethodFunction = function () {
1001 var isGenerator = false;
1002 var node = this.createNode();
1003 var previousAllowYield = this.context.allowYield;
1004 this.context.allowYield = false;
1005 var params = this.parseFormalParameters();
1006 var method = this.parsePropertyMethod(params);
1007 this.context.allowYield = previousAllowYield;
1008 return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
1010 Parser.prototype.parseObjectPropertyKey = function () {
1011 var node = this.createNode();
1012 var token = this.nextToken();
1014 switch (token.type) {
1015 case token_1.Token.StringLiteral:
1016 case token_1.Token.NumericLiteral:
1017 if (this.context.strict && token.octal) {
1018 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictOctalLiteral);
1020 var raw = this.getTokenRaw(token);
1021 key = this.finalize(node, new Node.Literal(token.value, raw));
1023 case token_1.Token.Identifier:
1024 case token_1.Token.BooleanLiteral:
1025 case token_1.Token.NullLiteral:
1026 case token_1.Token.Keyword:
1027 key = this.finalize(node, new Node.Identifier(token.value));
1029 case token_1.Token.Punctuator:
1030 if (token.value === '[') {
1031 key = this.isolateCoverGrammar(this.parseAssignmentExpression);
1035 this.throwUnexpectedToken(token);
1039 this.throwUnexpectedToken(token);
1043 Parser.prototype.isPropertyKey = function (key, value) {
1044 return (key.type === syntax_1.Syntax.Identifier && key.name === value) ||
1045 (key.type === syntax_1.Syntax.Literal && key.value === value);
1047 Parser.prototype.parseObjectProperty = function (hasProto) {
1048 var node = this.createNode();
1049 var token = this.lookahead;
1053 var computed = false;
1055 var shorthand = false;
1056 if (token.type === token_1.Token.Identifier) {
1058 key = this.finalize(node, new Node.Identifier(token.value));
1060 else if (this.match('*')) {
1064 computed = this.match('[');
1065 key = this.parseObjectPropertyKey();
1067 var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
1068 if (token.type === token_1.Token.Identifier && token.value === 'get' && lookaheadPropertyKey) {
1070 computed = this.match('[');
1071 key = this.parseObjectPropertyKey();
1072 this.context.allowYield = false;
1073 value = this.parseGetterMethod();
1075 else if (token.type === token_1.Token.Identifier && token.value === 'set' && lookaheadPropertyKey) {
1077 computed = this.match('[');
1078 key = this.parseObjectPropertyKey();
1079 value = this.parseSetterMethod();
1081 else if (token.type === token_1.Token.Punctuator && token.value === '*' && lookaheadPropertyKey) {
1083 computed = this.match('[');
1084 key = this.parseObjectPropertyKey();
1085 value = this.parseGeneratorMethod();
1090 this.throwUnexpectedToken(this.lookahead);
1093 if (this.match(':')) {
1094 if (!computed && this.isPropertyKey(key, '__proto__')) {
1095 if (hasProto.value) {
1096 this.tolerateError(messages_1.Messages.DuplicateProtoProperty);
1098 hasProto.value = true;
1101 value = this.inheritCoverGrammar(this.parseAssignmentExpression);
1103 else if (this.match('(')) {
1104 value = this.parsePropertyMethodFunction();
1107 else if (token.type === token_1.Token.Identifier) {
1108 var id = this.finalize(node, new Node.Identifier(token.value));
1109 if (this.match('=')) {
1110 this.context.firstCoverInitializedNameError = this.lookahead;
1113 var init = this.isolateCoverGrammar(this.parseAssignmentExpression);
1114 value = this.finalize(node, new Node.AssignmentPattern(id, init));
1122 this.throwUnexpectedToken(this.nextToken());
1125 return this.finalize(node, new Node.Property(kind, key, computed, value, method, shorthand));
1127 Parser.prototype.parseObjectInitializer = function () {
1128 var node = this.createNode();
1130 var properties = [];
1131 var hasProto = { value: false };
1132 while (!this.match('}')) {
1133 properties.push(this.parseObjectProperty(hasProto));
1134 if (!this.match('}')) {
1135 this.expectCommaSeparator();
1139 return this.finalize(node, new Node.ObjectExpression(properties));
1141 // ECMA-262 12.2.9 Template Literals
1142 Parser.prototype.parseTemplateHead = function () {
1143 assert_1.assert(this.lookahead.head, 'Template literal must start with a template head');
1144 var node = this.createNode();
1145 var token = this.nextToken();
1147 raw: token.value.raw,
1148 cooked: token.value.cooked
1150 return this.finalize(node, new Node.TemplateElement(value, token.tail));
1152 Parser.prototype.parseTemplateElement = function () {
1153 if (this.lookahead.type !== token_1.Token.Template) {
1154 this.throwUnexpectedToken();
1156 var node = this.createNode();
1157 var token = this.nextToken();
1159 raw: token.value.raw,
1160 cooked: token.value.cooked
1162 return this.finalize(node, new Node.TemplateElement(value, token.tail));
1164 Parser.prototype.parseTemplateLiteral = function () {
1165 var node = this.createNode();
1166 var expressions = [];
1168 var quasi = this.parseTemplateHead();
1170 while (!quasi.tail) {
1171 expressions.push(this.parseExpression());
1172 quasi = this.parseTemplateElement();
1175 return this.finalize(node, new Node.TemplateLiteral(quasis, expressions));
1177 // ECMA-262 12.2.10 The Grouping Operator
1178 Parser.prototype.reinterpretExpressionAsPattern = function (expr) {
1179 switch (expr.type) {
1180 case syntax_1.Syntax.Identifier:
1181 case syntax_1.Syntax.MemberExpression:
1182 case syntax_1.Syntax.RestElement:
1183 case syntax_1.Syntax.AssignmentPattern:
1185 case syntax_1.Syntax.SpreadElement:
1186 expr.type = syntax_1.Syntax.RestElement;
1187 this.reinterpretExpressionAsPattern(expr.argument);
1189 case syntax_1.Syntax.ArrayExpression:
1190 expr.type = syntax_1.Syntax.ArrayPattern;
1191 for (var i = 0; i < expr.elements.length; i++) {
1192 if (expr.elements[i] !== null) {
1193 this.reinterpretExpressionAsPattern(expr.elements[i]);
1197 case syntax_1.Syntax.ObjectExpression:
1198 expr.type = syntax_1.Syntax.ObjectPattern;
1199 for (var i = 0; i < expr.properties.length; i++) {
1200 this.reinterpretExpressionAsPattern(expr.properties[i].value);
1203 case syntax_1.Syntax.AssignmentExpression:
1204 expr.type = syntax_1.Syntax.AssignmentPattern;
1205 delete expr.operator;
1206 this.reinterpretExpressionAsPattern(expr.left);
1209 // Allow other node type for tolerant parsing.
1213 Parser.prototype.parseGroupExpression = function () {
1216 if (this.match(')')) {
1218 if (!this.match('=>')) {
1222 type: ArrowParameterPlaceHolder,
1227 var startToken = this.lookahead;
1229 if (this.match('...')) {
1230 expr = this.parseRestElement(params);
1232 if (!this.match('=>')) {
1236 type: ArrowParameterPlaceHolder,
1242 this.context.isBindingElement = true;
1243 expr = this.inheritCoverGrammar(this.parseAssignmentExpression);
1244 if (this.match(',')) {
1245 var expressions = [];
1246 this.context.isAssignmentTarget = false;
1247 expressions.push(expr);
1248 while (this.startMarker.index < this.scanner.length) {
1249 if (!this.match(',')) {
1253 if (this.match('...')) {
1254 if (!this.context.isBindingElement) {
1255 this.throwUnexpectedToken(this.lookahead);
1257 expressions.push(this.parseRestElement(params));
1259 if (!this.match('=>')) {
1262 this.context.isBindingElement = false;
1263 for (var i = 0; i < expressions.length; i++) {
1264 this.reinterpretExpressionAsPattern(expressions[i]);
1268 type: ArrowParameterPlaceHolder,
1273 expressions.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
1280 expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
1285 if (this.match('=>')) {
1286 if (expr.type === syntax_1.Syntax.Identifier && expr.name === 'yield') {
1289 type: ArrowParameterPlaceHolder,
1294 if (!this.context.isBindingElement) {
1295 this.throwUnexpectedToken(this.lookahead);
1297 if (expr.type === syntax_1.Syntax.SequenceExpression) {
1298 for (var i = 0; i < expr.expressions.length; i++) {
1299 this.reinterpretExpressionAsPattern(expr.expressions[i]);
1303 this.reinterpretExpressionAsPattern(expr);
1305 var params_1 = (expr.type === syntax_1.Syntax.SequenceExpression ? expr.expressions : [expr]);
1307 type: ArrowParameterPlaceHolder,
1312 this.context.isBindingElement = false;
1318 // ECMA-262 12.3 Left-Hand-Side Expressions
1319 Parser.prototype.parseArguments = function () {
1322 if (!this.match(')')) {
1324 var expr = this.match('...') ? this.parseSpreadElement() :
1325 this.isolateCoverGrammar(this.parseAssignmentExpression);
1327 if (this.match(')')) {
1330 this.expectCommaSeparator();
1336 Parser.prototype.isIdentifierName = function (token) {
1337 return token.type === token_1.Token.Identifier ||
1338 token.type === token_1.Token.Keyword ||
1339 token.type === token_1.Token.BooleanLiteral ||
1340 token.type === token_1.Token.NullLiteral;
1342 Parser.prototype.parseIdentifierName = function () {
1343 var node = this.createNode();
1344 var token = this.nextToken();
1345 if (!this.isIdentifierName(token)) {
1346 this.throwUnexpectedToken(token);
1348 return this.finalize(node, new Node.Identifier(token.value));
1350 Parser.prototype.parseNewExpression = function () {
1351 var node = this.createNode();
1352 var id = this.parseIdentifierName();
1353 assert_1.assert(id.name === 'new', 'New expression must start with `new`');
1355 if (this.match('.')) {
1357 if (this.lookahead.type === token_1.Token.Identifier && this.context.inFunctionBody && this.lookahead.value === 'target') {
1358 var property = this.parseIdentifierName();
1359 expr = new Node.MetaProperty(id, property);
1362 this.throwUnexpectedToken(this.lookahead);
1366 var callee = this.isolateCoverGrammar(this.parseLeftHandSideExpression);
1367 var args = this.match('(') ? this.parseArguments() : [];
1368 expr = new Node.NewExpression(callee, args);
1369 this.context.isAssignmentTarget = false;
1370 this.context.isBindingElement = false;
1372 return this.finalize(node, expr);
1374 Parser.prototype.parseLeftHandSideExpressionAllowCall = function () {
1375 var startToken = this.lookahead;
1376 var previousAllowIn = this.context.allowIn;
1377 this.context.allowIn = true;
1379 if (this.matchKeyword('super') && this.context.inFunctionBody) {
1380 expr = this.createNode();
1382 expr = this.finalize(expr, new Node.Super());
1383 if (!this.match('(') && !this.match('.') && !this.match('[')) {
1384 this.throwUnexpectedToken(this.lookahead);
1388 expr = this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
1391 if (this.match('.')) {
1392 this.context.isBindingElement = false;
1393 this.context.isAssignmentTarget = true;
1395 var property = this.parseIdentifierName();
1396 expr = this.finalize(this.startNode(startToken), new Node.StaticMemberExpression(expr, property));
1398 else if (this.match('(')) {
1399 this.context.isBindingElement = false;
1400 this.context.isAssignmentTarget = false;
1401 var args = this.parseArguments();
1402 expr = this.finalize(this.startNode(startToken), new Node.CallExpression(expr, args));
1404 else if (this.match('[')) {
1405 this.context.isBindingElement = false;
1406 this.context.isAssignmentTarget = true;
1408 var property = this.isolateCoverGrammar(this.parseExpression);
1410 expr = this.finalize(this.startNode(startToken), new Node.ComputedMemberExpression(expr, property));
1412 else if (this.lookahead.type === token_1.Token.Template && this.lookahead.head) {
1413 var quasi = this.parseTemplateLiteral();
1414 expr = this.finalize(this.startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi));
1420 this.context.allowIn = previousAllowIn;
1423 Parser.prototype.parseSuper = function () {
1424 var node = this.createNode();
1425 this.expectKeyword('super');
1426 if (!this.match('[') && !this.match('.')) {
1427 this.throwUnexpectedToken(this.lookahead);
1429 return this.finalize(node, new Node.Super());
1431 Parser.prototype.parseLeftHandSideExpression = function () {
1432 assert_1.assert(this.context.allowIn, 'callee of new expression always allow in keyword.');
1433 var node = this.startNode(this.lookahead);
1434 var expr = (this.matchKeyword('super') && this.context.inFunctionBody) ? this.parseSuper() :
1435 this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
1437 if (this.match('[')) {
1438 this.context.isBindingElement = false;
1439 this.context.isAssignmentTarget = true;
1441 var property = this.isolateCoverGrammar(this.parseExpression);
1443 expr = this.finalize(node, new Node.ComputedMemberExpression(expr, property));
1445 else if (this.match('.')) {
1446 this.context.isBindingElement = false;
1447 this.context.isAssignmentTarget = true;
1449 var property = this.parseIdentifierName();
1450 expr = this.finalize(node, new Node.StaticMemberExpression(expr, property));
1452 else if (this.lookahead.type === token_1.Token.Template && this.lookahead.head) {
1453 var quasi = this.parseTemplateLiteral();
1454 expr = this.finalize(node, new Node.TaggedTemplateExpression(expr, quasi));
1462 // ECMA-262 12.4 Update Expressions
1463 Parser.prototype.parseUpdateExpression = function () {
1465 var startToken = this.lookahead;
1466 if (this.match('++') || this.match('--')) {
1467 var node = this.startNode(startToken);
1468 var token = this.nextToken();
1469 expr = this.inheritCoverGrammar(this.parseUnaryExpression);
1470 if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
1471 this.tolerateError(messages_1.Messages.StrictLHSPrefix);
1473 if (!this.context.isAssignmentTarget) {
1474 this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
1477 expr = this.finalize(node, new Node.UpdateExpression(token.value, expr, prefix));
1478 this.context.isAssignmentTarget = false;
1479 this.context.isBindingElement = false;
1482 expr = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
1483 if (!this.hasLineTerminator && this.lookahead.type === token_1.Token.Punctuator) {
1484 if (this.match('++') || this.match('--')) {
1485 if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
1486 this.tolerateError(messages_1.Messages.StrictLHSPostfix);
1488 if (!this.context.isAssignmentTarget) {
1489 this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
1491 this.context.isAssignmentTarget = false;
1492 this.context.isBindingElement = false;
1493 var operator = this.nextToken().value;
1495 expr = this.finalize(this.startNode(startToken), new Node.UpdateExpression(operator, expr, prefix));
1501 // ECMA-262 12.5 Unary Operators
1502 Parser.prototype.parseUnaryExpression = function () {
1504 if (this.match('+') || this.match('-') || this.match('~') || this.match('!') ||
1505 this.matchKeyword('delete') || this.matchKeyword('void') || this.matchKeyword('typeof')) {
1506 var node = this.startNode(this.lookahead);
1507 var token = this.nextToken();
1508 expr = this.inheritCoverGrammar(this.parseUnaryExpression);
1509 expr = this.finalize(node, new Node.UnaryExpression(token.value, expr));
1510 if (this.context.strict && expr.operator === 'delete' && expr.argument.type === syntax_1.Syntax.Identifier) {
1511 this.tolerateError(messages_1.Messages.StrictDelete);
1513 this.context.isAssignmentTarget = false;
1514 this.context.isBindingElement = false;
1517 expr = this.parseUpdateExpression();
1521 Parser.prototype.parseExponentiationExpression = function () {
1522 var startToken = this.lookahead;
1523 var expr = this.inheritCoverGrammar(this.parseUnaryExpression);
1524 if (expr.type !== syntax_1.Syntax.UnaryExpression && this.match('**')) {
1526 this.context.isAssignmentTarget = false;
1527 this.context.isBindingElement = false;
1529 var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
1530 expr = this.finalize(this.startNode(startToken), new Node.BinaryExpression('**', left, right));
1534 // ECMA-262 12.6 Exponentiation Operators
1535 // ECMA-262 12.7 Multiplicative Operators
1536 // ECMA-262 12.8 Additive Operators
1537 // ECMA-262 12.9 Bitwise Shift Operators
1538 // ECMA-262 12.10 Relational Operators
1539 // ECMA-262 12.11 Equality Operators
1540 // ECMA-262 12.12 Binary Bitwise Operators
1541 // ECMA-262 12.13 Binary Logical Operators
1542 Parser.prototype.binaryPrecedence = function (token) {
1543 var op = token.value;
1545 if (token.type === token_1.Token.Punctuator) {
1546 precedence = this.operatorPrecedence[op] || 0;
1548 else if (token.type === token_1.Token.Keyword) {
1549 precedence = (op === 'instanceof' || (this.context.allowIn && op === 'in')) ? 7 : 0;
1556 Parser.prototype.parseBinaryExpression = function () {
1557 var startToken = this.lookahead;
1558 var expr = this.inheritCoverGrammar(this.parseExponentiationExpression);
1559 var token = this.lookahead;
1560 var prec = this.binaryPrecedence(token);
1564 this.context.isAssignmentTarget = false;
1565 this.context.isBindingElement = false;
1566 var markers = [startToken, this.lookahead];
1568 var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
1569 var stack = [left, token, right];
1571 prec = this.binaryPrecedence(this.lookahead);
1575 // Reduce: make a binary expression from the three topmost entries.
1576 while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
1577 right = stack.pop();
1578 var operator = stack.pop().value;
1581 var node = this.startNode(markers[markers.length - 1]);
1582 stack.push(this.finalize(node, new Node.BinaryExpression(operator, left, right)));
1585 token = this.nextToken();
1588 markers.push(this.lookahead);
1589 stack.push(this.isolateCoverGrammar(this.parseExponentiationExpression));
1591 // Final reduce to clean-up the stack.
1592 var i = stack.length - 1;
1596 var node = this.startNode(markers.pop());
1597 expr = this.finalize(node, new Node.BinaryExpression(stack[i - 1].value, stack[i - 2], expr));
1603 // ECMA-262 12.14 Conditional Operator
1604 Parser.prototype.parseConditionalExpression = function () {
1605 var startToken = this.lookahead;
1606 var expr = this.inheritCoverGrammar(this.parseBinaryExpression);
1607 if (this.match('?')) {
1609 var previousAllowIn = this.context.allowIn;
1610 this.context.allowIn = true;
1611 var consequent = this.isolateCoverGrammar(this.parseAssignmentExpression);
1612 this.context.allowIn = previousAllowIn;
1614 var alternate = this.isolateCoverGrammar(this.parseAssignmentExpression);
1615 expr = this.finalize(this.startNode(startToken), new Node.ConditionalExpression(expr, consequent, alternate));
1616 this.context.isAssignmentTarget = false;
1617 this.context.isBindingElement = false;
1621 // ECMA-262 12.15 Assignment Operators
1622 Parser.prototype.checkPatternParam = function (options, param) {
1623 switch (param.type) {
1624 case syntax_1.Syntax.Identifier:
1625 this.validateParam(options, param, param.name);
1627 case syntax_1.Syntax.RestElement:
1628 this.checkPatternParam(options, param.argument);
1630 case syntax_1.Syntax.AssignmentPattern:
1631 this.checkPatternParam(options, param.left);
1633 case syntax_1.Syntax.ArrayPattern:
1634 for (var i = 0; i < param.elements.length; i++) {
1635 if (param.elements[i] !== null) {
1636 this.checkPatternParam(options, param.elements[i]);
1640 case syntax_1.Syntax.YieldExpression:
1643 assert_1.assert(param.type === syntax_1.Syntax.ObjectPattern, 'Invalid type');
1644 for (var i = 0; i < param.properties.length; i++) {
1645 this.checkPatternParam(options, param.properties[i].value);
1650 Parser.prototype.reinterpretAsCoverFormalsList = function (expr) {
1651 var params = [expr];
1653 switch (expr.type) {
1654 case syntax_1.Syntax.Identifier:
1656 case ArrowParameterPlaceHolder:
1657 params = expr.params;
1665 for (var i = 0; i < params.length; ++i) {
1666 var param = params[i];
1667 if (param.type === syntax_1.Syntax.AssignmentPattern) {
1668 if (param.right.type === syntax_1.Syntax.YieldExpression) {
1669 if (param.right.argument) {
1670 this.throwUnexpectedToken(this.lookahead);
1672 param.right.type = syntax_1.Syntax.Identifier;
1673 param.right.name = 'yield';
1674 delete param.right.argument;
1675 delete param.right.delegate;
1678 this.checkPatternParam(options, param);
1681 if (this.context.strict || !this.context.allowYield) {
1682 for (var i = 0; i < params.length; ++i) {
1683 var param = params[i];
1684 if (param.type === syntax_1.Syntax.YieldExpression) {
1685 this.throwUnexpectedToken(this.lookahead);
1689 if (options.message === messages_1.Messages.StrictParamDupe) {
1690 var token = this.context.strict ? options.stricted : options.firstRestricted;
1691 this.throwUnexpectedToken(token, options.message);
1695 stricted: options.stricted,
1696 firstRestricted: options.firstRestricted,
1697 message: options.message
1700 Parser.prototype.parseAssignmentExpression = function () {
1702 if (!this.context.allowYield && this.matchKeyword('yield')) {
1703 expr = this.parseYieldExpression();
1706 var startToken = this.lookahead;
1707 var token = startToken;
1708 expr = this.parseConditionalExpression();
1709 if (expr.type === ArrowParameterPlaceHolder || this.match('=>')) {
1710 // ECMA-262 14.2 Arrow Function Definitions
1711 this.context.isAssignmentTarget = false;
1712 this.context.isBindingElement = false;
1713 var list = this.reinterpretAsCoverFormalsList(expr);
1715 if (this.hasLineTerminator) {
1716 this.tolerateUnexpectedToken(this.lookahead);
1718 this.context.firstCoverInitializedNameError = null;
1719 var previousStrict = this.context.strict;
1720 var previousAllowYield = this.context.allowYield;
1721 this.context.allowYield = true;
1722 var node = this.startNode(startToken);
1724 var body = this.match('{') ? this.parseFunctionSourceElements() :
1725 this.isolateCoverGrammar(this.parseAssignmentExpression);
1726 var expression = body.type !== syntax_1.Syntax.BlockStatement;
1727 if (this.context.strict && list.firstRestricted) {
1728 this.throwUnexpectedToken(list.firstRestricted, list.message);
1730 if (this.context.strict && list.stricted) {
1731 this.tolerateUnexpectedToken(list.stricted, list.message);
1733 expr = this.finalize(node, new Node.ArrowFunctionExpression(list.params, body, expression));
1734 this.context.strict = previousStrict;
1735 this.context.allowYield = previousAllowYield;
1739 if (this.matchAssign()) {
1740 if (!this.context.isAssignmentTarget) {
1741 this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
1743 if (this.context.strict && expr.type === syntax_1.Syntax.Identifier) {
1745 if (this.scanner.isRestrictedWord(id.name)) {
1746 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictLHSAssignment);
1748 if (this.scanner.isStrictModeReservedWord(id.name)) {
1749 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
1752 if (!this.match('=')) {
1753 this.context.isAssignmentTarget = false;
1754 this.context.isBindingElement = false;
1757 this.reinterpretExpressionAsPattern(expr);
1759 token = this.nextToken();
1760 var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
1761 expr = this.finalize(this.startNode(startToken), new Node.AssignmentExpression(token.value, expr, right));
1762 this.context.firstCoverInitializedNameError = null;
1768 // ECMA-262 12.16 Comma Operator
1769 Parser.prototype.parseExpression = function () {
1770 var startToken = this.lookahead;
1771 var expr = this.isolateCoverGrammar(this.parseAssignmentExpression);
1772 if (this.match(',')) {
1773 var expressions = [];
1774 expressions.push(expr);
1775 while (this.startMarker.index < this.scanner.length) {
1776 if (!this.match(',')) {
1780 expressions.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
1782 expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
1786 // ECMA-262 13.2 Block
1787 Parser.prototype.parseStatementListItem = function () {
1788 var statement = null;
1789 this.context.isAssignmentTarget = true;
1790 this.context.isBindingElement = true;
1791 if (this.lookahead.type === token_1.Token.Keyword) {
1792 switch (this.lookahead.value) {
1794 if (this.sourceType !== 'module') {
1795 this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalExportDeclaration);
1797 statement = this.parseExportDeclaration();
1800 if (this.sourceType !== 'module') {
1801 this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalImportDeclaration);
1803 statement = this.parseImportDeclaration();
1806 statement = this.parseLexicalDeclaration({ inFor: false });
1809 statement = this.parseFunctionDeclaration();
1812 statement = this.parseClassDeclaration();
1815 statement = this.isLexicalDeclaration() ? this.parseLexicalDeclaration({ inFor: false }) : this.parseStatement();
1818 statement = this.parseStatement();
1823 statement = this.parseStatement();
1827 Parser.prototype.parseBlock = function () {
1828 var node = this.createNode();
1832 if (this.match('}')) {
1835 block.push(this.parseStatementListItem());
1838 return this.finalize(node, new Node.BlockStatement(block));
1840 // ECMA-262 13.3.1 Let and Const Declarations
1841 Parser.prototype.parseLexicalBinding = function (kind, options) {
1842 var node = this.createNode();
1844 var id = this.parsePattern(params, kind);
1846 if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
1847 if (this.scanner.isRestrictedWord((id).name)) {
1848 this.tolerateError(messages_1.Messages.StrictVarName);
1852 if (kind === 'const') {
1853 if (!this.matchKeyword('in') && !this.matchContextualKeyword('of')) {
1855 init = this.isolateCoverGrammar(this.parseAssignmentExpression);
1858 else if ((!options.inFor && id.type !== syntax_1.Syntax.Identifier) || this.match('=')) {
1860 init = this.isolateCoverGrammar(this.parseAssignmentExpression);
1862 return this.finalize(node, new Node.VariableDeclarator(id, init));
1864 Parser.prototype.parseBindingList = function (kind, options) {
1865 var list = [this.parseLexicalBinding(kind, options)];
1866 while (this.match(',')) {
1868 list.push(this.parseLexicalBinding(kind, options));
1872 Parser.prototype.isLexicalDeclaration = function () {
1873 var previousIndex = this.scanner.index;
1874 var previousLineNumber = this.scanner.lineNumber;
1875 var previousLineStart = this.scanner.lineStart;
1876 this.collectComments();
1877 var next = this.scanner.lex();
1878 this.scanner.index = previousIndex;
1879 this.scanner.lineNumber = previousLineNumber;
1880 this.scanner.lineStart = previousLineStart;
1881 return (next.type === token_1.Token.Identifier) ||
1882 (next.type === token_1.Token.Punctuator && next.value === '[') ||
1883 (next.type === token_1.Token.Punctuator && next.value === '{') ||
1884 (next.type === token_1.Token.Keyword && next.value === 'let') ||
1885 (next.type === token_1.Token.Keyword && next.value === 'yield');
1887 Parser.prototype.parseLexicalDeclaration = function (options) {
1888 var node = this.createNode();
1889 var kind = this.nextToken().value;
1890 assert_1.assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');
1891 var declarations = this.parseBindingList(kind, options);
1892 this.consumeSemicolon();
1893 return this.finalize(node, new Node.VariableDeclaration(declarations, kind));
1895 // ECMA-262 13.3.3 Destructuring Binding Patterns
1896 Parser.prototype.parseBindingRestElement = function (params, kind) {
1897 var node = this.createNode();
1899 var arg = this.parsePattern(params, kind);
1900 return this.finalize(node, new Node.RestElement(arg));
1902 Parser.prototype.parseArrayPattern = function (params, kind) {
1903 var node = this.createNode();
1906 while (!this.match(']')) {
1907 if (this.match(',')) {
1909 elements.push(null);
1912 if (this.match('...')) {
1913 elements.push(this.parseBindingRestElement(params, kind));
1917 elements.push(this.parsePatternWithDefault(params, kind));
1919 if (!this.match(']')) {
1925 return this.finalize(node, new Node.ArrayPattern(elements));
1927 Parser.prototype.parsePropertyPattern = function (params, kind) {
1928 var node = this.createNode();
1929 var computed = false;
1930 var shorthand = false;
1934 if (this.lookahead.type === token_1.Token.Identifier) {
1935 var keyToken = this.lookahead;
1936 key = this.parseVariableIdentifier();
1937 var init = this.finalize(node, new Node.Identifier(keyToken.value));
1938 if (this.match('=')) {
1939 params.push(keyToken);
1942 var expr = this.parseAssignmentExpression();
1943 value = this.finalize(this.startNode(keyToken), new Node.AssignmentPattern(init, expr));
1945 else if (!this.match(':')) {
1946 params.push(keyToken);
1952 value = this.parsePatternWithDefault(params, kind);
1956 computed = this.match('[');
1957 key = this.parseObjectPropertyKey();
1959 value = this.parsePatternWithDefault(params, kind);
1961 return this.finalize(node, new Node.Property('init', key, computed, value, method, shorthand));
1963 Parser.prototype.parseObjectPattern = function (params, kind) {
1964 var node = this.createNode();
1965 var properties = [];
1967 while (!this.match('}')) {
1968 properties.push(this.parsePropertyPattern(params, kind));
1969 if (!this.match('}')) {
1974 return this.finalize(node, new Node.ObjectPattern(properties));
1976 Parser.prototype.parsePattern = function (params, kind) {
1978 if (this.match('[')) {
1979 pattern = this.parseArrayPattern(params, kind);
1981 else if (this.match('{')) {
1982 pattern = this.parseObjectPattern(params, kind);
1985 if (this.matchKeyword('let') && (kind === 'const' || kind === 'let')) {
1986 this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.UnexpectedToken);
1988 params.push(this.lookahead);
1989 pattern = this.parseVariableIdentifier(kind);
1993 Parser.prototype.parsePatternWithDefault = function (params, kind) {
1994 var startToken = this.lookahead;
1995 var pattern = this.parsePattern(params, kind);
1996 if (this.match('=')) {
1998 var previousAllowYield = this.context.allowYield;
1999 this.context.allowYield = true;
2000 var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
2001 this.context.allowYield = previousAllowYield;
2002 pattern = this.finalize(this.startNode(startToken), new Node.AssignmentPattern(pattern, right));
2006 // ECMA-262 13.3.2 Variable Statement
2007 Parser.prototype.parseVariableIdentifier = function (kind) {
2008 var node = this.createNode();
2009 var token = this.nextToken();
2010 if (token.type === token_1.Token.Keyword && token.value === 'yield') {
2011 if (this.context.strict) {
2012 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
2014 if (!this.context.allowYield) {
2015 this.throwUnexpectedToken(token);
2018 else if (token.type !== token_1.Token.Identifier) {
2019 if (this.context.strict && token.type === token_1.Token.Keyword && this.scanner.isStrictModeReservedWord(token.value)) {
2020 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
2023 if (this.context.strict || token.value !== 'let' || kind !== 'var') {
2024 this.throwUnexpectedToken(token);
2028 else if (this.sourceType === 'module' && token.type === token_1.Token.Identifier && token.value === 'await') {
2029 this.tolerateUnexpectedToken(token);
2031 return this.finalize(node, new Node.Identifier(token.value));
2033 Parser.prototype.parseVariableDeclaration = function (options) {
2034 var node = this.createNode();
2036 var id = this.parsePattern(params, 'var');
2038 if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
2039 if (this.scanner.isRestrictedWord((id).name)) {
2040 this.tolerateError(messages_1.Messages.StrictVarName);
2044 if (this.match('=')) {
2046 init = this.isolateCoverGrammar(this.parseAssignmentExpression);
2048 else if (id.type !== syntax_1.Syntax.Identifier && !options.inFor) {
2051 return this.finalize(node, new Node.VariableDeclarator(id, init));
2053 Parser.prototype.parseVariableDeclarationList = function (options) {
2054 var opt = { inFor: options.inFor };
2056 list.push(this.parseVariableDeclaration(opt));
2057 while (this.match(',')) {
2059 list.push(this.parseVariableDeclaration(opt));
2063 Parser.prototype.parseVariableStatement = function () {
2064 var node = this.createNode();
2065 this.expectKeyword('var');
2066 var declarations = this.parseVariableDeclarationList({ inFor: false });
2067 this.consumeSemicolon();
2068 return this.finalize(node, new Node.VariableDeclaration(declarations, 'var'));
2070 // ECMA-262 13.4 Empty Statement
2071 Parser.prototype.parseEmptyStatement = function () {
2072 var node = this.createNode();
2074 return this.finalize(node, new Node.EmptyStatement());
2076 // ECMA-262 13.5 Expression Statement
2077 Parser.prototype.parseExpressionStatement = function () {
2078 var node = this.createNode();
2079 var expr = this.parseExpression();
2080 this.consumeSemicolon();
2081 return this.finalize(node, new Node.ExpressionStatement(expr));
2083 // ECMA-262 13.6 If statement
2084 Parser.prototype.parseIfStatement = function () {
2085 var node = this.createNode();
2087 var alternate = null;
2088 this.expectKeyword('if');
2090 var test = this.parseExpression();
2091 if (!this.match(')') && this.config.tolerant) {
2092 this.tolerateUnexpectedToken(this.nextToken());
2093 consequent = this.finalize(this.createNode(), new Node.EmptyStatement());
2097 consequent = this.parseStatement();
2098 if (this.matchKeyword('else')) {
2100 alternate = this.parseStatement();
2103 return this.finalize(node, new Node.IfStatement(test, consequent, alternate));
2105 // ECMA-262 13.7.2 The do-while Statement
2106 Parser.prototype.parseDoWhileStatement = function () {
2107 var node = this.createNode();
2108 this.expectKeyword('do');
2109 var previousInIteration = this.context.inIteration;
2110 this.context.inIteration = true;
2111 var body = this.parseStatement();
2112 this.context.inIteration = previousInIteration;
2113 this.expectKeyword('while');
2115 var test = this.parseExpression();
2117 if (this.match(';')) {
2120 return this.finalize(node, new Node.DoWhileStatement(body, test));
2122 // ECMA-262 13.7.3 The while Statement
2123 Parser.prototype.parseWhileStatement = function () {
2124 var node = this.createNode();
2126 this.expectKeyword('while');
2128 var test = this.parseExpression();
2129 if (!this.match(')') && this.config.tolerant) {
2130 this.tolerateUnexpectedToken(this.nextToken());
2131 body = this.finalize(this.createNode(), new Node.EmptyStatement());
2135 var previousInIteration = this.context.inIteration;
2136 this.context.inIteration = true;
2137 body = this.parseStatement();
2138 this.context.inIteration = previousInIteration;
2140 return this.finalize(node, new Node.WhileStatement(test, body));
2142 // ECMA-262 13.7.4 The for Statement
2143 // ECMA-262 13.7.5 The for-in and for-of Statements
2144 Parser.prototype.parseForStatement = function () {
2150 var node = this.createNode();
2151 this.expectKeyword('for');
2153 if (this.match(';')) {
2157 if (this.matchKeyword('var')) {
2158 init = this.createNode();
2160 var previousAllowIn = this.context.allowIn;
2161 this.context.allowIn = false;
2162 var declarations = this.parseVariableDeclarationList({ inFor: true });
2163 this.context.allowIn = previousAllowIn;
2164 if (declarations.length === 1 && this.matchKeyword('in')) {
2165 var decl = declarations[0];
2166 if (decl.init && (decl.id.type === syntax_1.Syntax.ArrayPattern || decl.id.type === syntax_1.Syntax.ObjectPattern || this.context.strict)) {
2167 this.tolerateError(messages_1.Messages.ForInOfLoopInitializer, 'for-in');
2169 init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
2172 right = this.parseExpression();
2175 else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
2176 init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
2179 right = this.parseAssignmentExpression();
2184 init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
2188 else if (this.matchKeyword('const') || this.matchKeyword('let')) {
2189 init = this.createNode();
2190 var kind = this.nextToken().value;
2191 if (!this.context.strict && this.lookahead.value === 'in') {
2192 init = this.finalize(init, new Node.Identifier(kind));
2195 right = this.parseExpression();
2199 var previousAllowIn = this.context.allowIn;
2200 this.context.allowIn = false;
2201 var declarations = this.parseBindingList(kind, { inFor: true });
2202 this.context.allowIn = previousAllowIn;
2203 if (declarations.length === 1 && declarations[0].init === null && this.matchKeyword('in')) {
2204 init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
2207 right = this.parseExpression();
2210 else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
2211 init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
2214 right = this.parseAssignmentExpression();
2219 this.consumeSemicolon();
2220 init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
2225 var initStartToken = this.lookahead;
2226 var previousAllowIn = this.context.allowIn;
2227 this.context.allowIn = false;
2228 init = this.inheritCoverGrammar(this.parseAssignmentExpression);
2229 this.context.allowIn = previousAllowIn;
2230 if (this.matchKeyword('in')) {
2231 if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
2232 this.tolerateError(messages_1.Messages.InvalidLHSInForIn);
2235 this.reinterpretExpressionAsPattern(init);
2237 right = this.parseExpression();
2240 else if (this.matchContextualKeyword('of')) {
2241 if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
2242 this.tolerateError(messages_1.Messages.InvalidLHSInForLoop);
2245 this.reinterpretExpressionAsPattern(init);
2247 right = this.parseAssignmentExpression();
2252 if (this.match(',')) {
2253 var initSeq = [init];
2254 while (this.match(',')) {
2256 initSeq.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
2258 init = this.finalize(this.startNode(initStartToken), new Node.SequenceExpression(initSeq));
2264 if (typeof left === 'undefined') {
2265 if (!this.match(';')) {
2266 test = this.parseExpression();
2269 if (!this.match(')')) {
2270 update = this.parseExpression();
2274 if (!this.match(')') && this.config.tolerant) {
2275 this.tolerateUnexpectedToken(this.nextToken());
2276 body = this.finalize(this.createNode(), new Node.EmptyStatement());
2280 var previousInIteration = this.context.inIteration;
2281 this.context.inIteration = true;
2282 body = this.isolateCoverGrammar(this.parseStatement);
2283 this.context.inIteration = previousInIteration;
2285 return (typeof left === 'undefined') ?
2286 this.finalize(node, new Node.ForStatement(init, test, update, body)) :
2287 forIn ? this.finalize(node, new Node.ForInStatement(left, right, body)) :
2288 this.finalize(node, new Node.ForOfStatement(left, right, body));
2290 // ECMA-262 13.8 The continue statement
2291 Parser.prototype.parseContinueStatement = function () {
2292 var node = this.createNode();
2293 this.expectKeyword('continue');
2295 if (this.lookahead.type === token_1.Token.Identifier && !this.hasLineTerminator) {
2296 label = this.parseVariableIdentifier();
2297 var key = '$' + label.name;
2298 if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
2299 this.throwError(messages_1.Messages.UnknownLabel, label.name);
2302 this.consumeSemicolon();
2303 if (label === null && !this.context.inIteration) {
2304 this.throwError(messages_1.Messages.IllegalContinue);
2306 return this.finalize(node, new Node.ContinueStatement(label));
2308 // ECMA-262 13.9 The break statement
2309 Parser.prototype.parseBreakStatement = function () {
2310 var node = this.createNode();
2311 this.expectKeyword('break');
2313 if (this.lookahead.type === token_1.Token.Identifier && !this.hasLineTerminator) {
2314 label = this.parseVariableIdentifier();
2315 var key = '$' + label.name;
2316 if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
2317 this.throwError(messages_1.Messages.UnknownLabel, label.name);
2320 this.consumeSemicolon();
2321 if (label === null && !this.context.inIteration && !this.context.inSwitch) {
2322 this.throwError(messages_1.Messages.IllegalBreak);
2324 return this.finalize(node, new Node.BreakStatement(label));
2326 // ECMA-262 13.10 The return statement
2327 Parser.prototype.parseReturnStatement = function () {
2328 if (!this.context.inFunctionBody) {
2329 this.tolerateError(messages_1.Messages.IllegalReturn);
2331 var node = this.createNode();
2332 this.expectKeyword('return');
2333 var hasArgument = !this.match(';') && !this.match('}') &&
2334 !this.hasLineTerminator && this.lookahead.type !== token_1.Token.EOF;
2335 var argument = hasArgument ? this.parseExpression() : null;
2336 this.consumeSemicolon();
2337 return this.finalize(node, new Node.ReturnStatement(argument));
2339 // ECMA-262 13.11 The with statement
2340 Parser.prototype.parseWithStatement = function () {
2341 if (this.context.strict) {
2342 this.tolerateError(messages_1.Messages.StrictModeWith);
2344 var node = this.createNode();
2345 this.expectKeyword('with');
2347 var object = this.parseExpression();
2349 var body = this.parseStatement();
2350 return this.finalize(node, new Node.WithStatement(object, body));
2352 // ECMA-262 13.12 The switch statement
2353 Parser.prototype.parseSwitchCase = function () {
2354 var node = this.createNode();
2356 if (this.matchKeyword('default')) {
2361 this.expectKeyword('case');
2362 test = this.parseExpression();
2365 var consequent = [];
2367 if (this.match('}') || this.matchKeyword('default') || this.matchKeyword('case')) {
2370 consequent.push(this.parseStatementListItem());
2372 return this.finalize(node, new Node.SwitchCase(test, consequent));
2374 Parser.prototype.parseSwitchStatement = function () {
2375 var node = this.createNode();
2376 this.expectKeyword('switch');
2378 var discriminant = this.parseExpression();
2380 var previousInSwitch = this.context.inSwitch;
2381 this.context.inSwitch = true;
2383 var defaultFound = false;
2386 if (this.match('}')) {
2389 var clause = this.parseSwitchCase();
2390 if (clause.test === null) {
2392 this.throwError(messages_1.Messages.MultipleDefaultsInSwitch);
2394 defaultFound = true;
2399 this.context.inSwitch = previousInSwitch;
2400 return this.finalize(node, new Node.SwitchStatement(discriminant, cases));
2402 // ECMA-262 13.13 Labelled Statements
2403 Parser.prototype.parseLabelledStatement = function () {
2404 var node = this.createNode();
2405 var expr = this.parseExpression();
2407 if ((expr.type === syntax_1.Syntax.Identifier) && this.match(':')) {
2410 var key = '$' + id.name;
2411 if (Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
2412 this.throwError(messages_1.Messages.Redeclaration, 'Label', id.name);
2414 this.context.labelSet[key] = true;
2415 var labeledBody = this.parseStatement();
2416 delete this.context.labelSet[key];
2417 statement = new Node.LabeledStatement(id, labeledBody);
2420 this.consumeSemicolon();
2421 statement = new Node.ExpressionStatement(expr);
2423 return this.finalize(node, statement);
2425 // ECMA-262 13.14 The throw statement
2426 Parser.prototype.parseThrowStatement = function () {
2427 var node = this.createNode();
2428 this.expectKeyword('throw');
2429 if (this.hasLineTerminator) {
2430 this.throwError(messages_1.Messages.NewlineAfterThrow);
2432 var argument = this.parseExpression();
2433 this.consumeSemicolon();
2434 return this.finalize(node, new Node.ThrowStatement(argument));
2436 // ECMA-262 13.15 The try statement
2437 Parser.prototype.parseCatchClause = function () {
2438 var node = this.createNode();
2439 this.expectKeyword('catch');
2441 if (this.match(')')) {
2442 this.throwUnexpectedToken(this.lookahead);
2445 var param = this.parsePattern(params);
2447 for (var i = 0; i < params.length; i++) {
2448 var key = '$' + params[i].value;
2449 if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
2450 this.tolerateError(messages_1.Messages.DuplicateBinding, params[i].value);
2452 paramMap[key] = true;
2454 if (this.context.strict && param.type === syntax_1.Syntax.Identifier) {
2455 if (this.scanner.isRestrictedWord((param).name)) {
2456 this.tolerateError(messages_1.Messages.StrictCatchVariable);
2460 var body = this.parseBlock();
2461 return this.finalize(node, new Node.CatchClause(param, body));
2463 Parser.prototype.parseFinallyClause = function () {
2464 this.expectKeyword('finally');
2465 return this.parseBlock();
2467 Parser.prototype.parseTryStatement = function () {
2468 var node = this.createNode();
2469 this.expectKeyword('try');
2470 var block = this.parseBlock();
2471 var handler = this.matchKeyword('catch') ? this.parseCatchClause() : null;
2472 var finalizer = this.matchKeyword('finally') ? this.parseFinallyClause() : null;
2473 if (!handler && !finalizer) {
2474 this.throwError(messages_1.Messages.NoCatchOrFinally);
2476 return this.finalize(node, new Node.TryStatement(block, handler, finalizer));
2478 // ECMA-262 13.16 The debugger statement
2479 Parser.prototype.parseDebuggerStatement = function () {
2480 var node = this.createNode();
2481 this.expectKeyword('debugger');
2482 this.consumeSemicolon();
2483 return this.finalize(node, new Node.DebuggerStatement());
2485 // ECMA-262 13 Statements
2486 Parser.prototype.parseStatement = function () {
2487 var statement = null;
2488 switch (this.lookahead.type) {
2489 case token_1.Token.BooleanLiteral:
2490 case token_1.Token.NullLiteral:
2491 case token_1.Token.NumericLiteral:
2492 case token_1.Token.StringLiteral:
2493 case token_1.Token.Template:
2494 case token_1.Token.RegularExpression:
2495 statement = this.parseExpressionStatement();
2497 case token_1.Token.Punctuator:
2498 var value = this.lookahead.value;
2499 if (value === '{') {
2500 statement = this.parseBlock();
2502 else if (value === '(') {
2503 statement = this.parseExpressionStatement();
2505 else if (value === ';') {
2506 statement = this.parseEmptyStatement();
2509 statement = this.parseExpressionStatement();
2512 case token_1.Token.Identifier:
2513 statement = this.parseLabelledStatement();
2515 case token_1.Token.Keyword:
2516 switch (this.lookahead.value) {
2518 statement = this.parseBreakStatement();
2521 statement = this.parseContinueStatement();
2524 statement = this.parseDebuggerStatement();
2527 statement = this.parseDoWhileStatement();
2530 statement = this.parseForStatement();
2533 statement = this.parseFunctionDeclaration();
2536 statement = this.parseIfStatement();
2539 statement = this.parseReturnStatement();
2542 statement = this.parseSwitchStatement();
2545 statement = this.parseThrowStatement();
2548 statement = this.parseTryStatement();
2551 statement = this.parseVariableStatement();
2554 statement = this.parseWhileStatement();
2557 statement = this.parseWithStatement();
2560 statement = this.parseExpressionStatement();
2565 this.throwUnexpectedToken(this.lookahead);
2569 // ECMA-262 14.1 Function Definition
2570 Parser.prototype.parseFunctionSourceElements = function () {
2571 var node = this.createNode();
2573 var body = this.parseDirectivePrologues();
2574 var previousLabelSet = this.context.labelSet;
2575 var previousInIteration = this.context.inIteration;
2576 var previousInSwitch = this.context.inSwitch;
2577 var previousInFunctionBody = this.context.inFunctionBody;
2578 this.context.labelSet = {};
2579 this.context.inIteration = false;
2580 this.context.inSwitch = false;
2581 this.context.inFunctionBody = true;
2582 while (this.startMarker.index < this.scanner.length) {
2583 if (this.match('}')) {
2586 body.push(this.parseStatementListItem());
2589 this.context.labelSet = previousLabelSet;
2590 this.context.inIteration = previousInIteration;
2591 this.context.inSwitch = previousInSwitch;
2592 this.context.inFunctionBody = previousInFunctionBody;
2593 return this.finalize(node, new Node.BlockStatement(body));
2595 Parser.prototype.validateParam = function (options, param, name) {
2596 var key = '$' + name;
2597 if (this.context.strict) {
2598 if (this.scanner.isRestrictedWord(name)) {
2599 options.stricted = param;
2600 options.message = messages_1.Messages.StrictParamName;
2602 if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
2603 options.stricted = param;
2604 options.message = messages_1.Messages.StrictParamDupe;
2607 else if (!options.firstRestricted) {
2608 if (this.scanner.isRestrictedWord(name)) {
2609 options.firstRestricted = param;
2610 options.message = messages_1.Messages.StrictParamName;
2612 else if (this.scanner.isStrictModeReservedWord(name)) {
2613 options.firstRestricted = param;
2614 options.message = messages_1.Messages.StrictReservedWord;
2616 else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
2617 options.stricted = param;
2618 options.message = messages_1.Messages.StrictParamDupe;
2621 /* istanbul ignore next */
2622 if (typeof Object.defineProperty === 'function') {
2623 Object.defineProperty(options.paramSet, key, { value: true, enumerable: true, writable: true, configurable: true });
2626 options.paramSet[key] = true;
2629 Parser.prototype.parseRestElement = function (params) {
2630 var node = this.createNode();
2632 var arg = this.parsePattern(params);
2633 if (this.match('=')) {
2634 this.throwError(messages_1.Messages.DefaultRestParameter);
2636 if (!this.match(')')) {
2637 this.throwError(messages_1.Messages.ParameterAfterRestParameter);
2639 return this.finalize(node, new Node.RestElement(arg));
2641 Parser.prototype.parseFormalParameter = function (options) {
2643 var param = this.match('...') ? this.parseRestElement(params) : this.parsePatternWithDefault(params);
2644 for (var i = 0; i < params.length; i++) {
2645 this.validateParam(options, params[i], params[i].value);
2647 options.params.push(param);
2648 return !this.match(')');
2650 Parser.prototype.parseFormalParameters = function (firstRestricted) {
2654 firstRestricted: firstRestricted
2657 if (!this.match(')')) {
2658 options.paramSet = {};
2659 while (this.startMarker.index < this.scanner.length) {
2660 if (!this.parseFormalParameter(options)) {
2668 params: options.params,
2669 stricted: options.stricted,
2670 firstRestricted: options.firstRestricted,
2671 message: options.message
2674 Parser.prototype.parseFunctionDeclaration = function (identifierIsOptional) {
2675 var node = this.createNode();
2676 this.expectKeyword('function');
2677 var isGenerator = this.match('*');
2683 var firstRestricted = null;
2684 if (!identifierIsOptional || !this.match('(')) {
2685 var token = this.lookahead;
2686 id = this.parseVariableIdentifier();
2687 if (this.context.strict) {
2688 if (this.scanner.isRestrictedWord(token.value)) {
2689 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
2693 if (this.scanner.isRestrictedWord(token.value)) {
2694 firstRestricted = token;
2695 message = messages_1.Messages.StrictFunctionName;
2697 else if (this.scanner.isStrictModeReservedWord(token.value)) {
2698 firstRestricted = token;
2699 message = messages_1.Messages.StrictReservedWord;
2703 var previousAllowYield = this.context.allowYield;
2704 this.context.allowYield = !isGenerator;
2705 var formalParameters = this.parseFormalParameters(firstRestricted);
2706 var params = formalParameters.params;
2707 var stricted = formalParameters.stricted;
2708 firstRestricted = formalParameters.firstRestricted;
2709 if (formalParameters.message) {
2710 message = formalParameters.message;
2712 var previousStrict = this.context.strict;
2713 var body = this.parseFunctionSourceElements();
2714 if (this.context.strict && firstRestricted) {
2715 this.throwUnexpectedToken(firstRestricted, message);
2717 if (this.context.strict && stricted) {
2718 this.tolerateUnexpectedToken(stricted, message);
2720 this.context.strict = previousStrict;
2721 this.context.allowYield = previousAllowYield;
2722 return this.finalize(node, new Node.FunctionDeclaration(id, params, body, isGenerator));
2724 Parser.prototype.parseFunctionExpression = function () {
2725 var node = this.createNode();
2726 this.expectKeyword('function');
2727 var isGenerator = this.match('*');
2733 var firstRestricted;
2734 var previousAllowYield = this.context.allowYield;
2735 this.context.allowYield = !isGenerator;
2736 if (!this.match('(')) {
2737 var token = this.lookahead;
2738 id = (!this.context.strict && !isGenerator && this.matchKeyword('yield')) ? this.parseIdentifierName() : this.parseVariableIdentifier();
2739 if (this.context.strict) {
2740 if (this.scanner.isRestrictedWord(token.value)) {
2741 this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
2745 if (this.scanner.isRestrictedWord(token.value)) {
2746 firstRestricted = token;
2747 message = messages_1.Messages.StrictFunctionName;
2749 else if (this.scanner.isStrictModeReservedWord(token.value)) {
2750 firstRestricted = token;
2751 message = messages_1.Messages.StrictReservedWord;
2755 var formalParameters = this.parseFormalParameters(firstRestricted);
2756 var params = formalParameters.params;
2757 var stricted = formalParameters.stricted;
2758 firstRestricted = formalParameters.firstRestricted;
2759 if (formalParameters.message) {
2760 message = formalParameters.message;
2762 var previousStrict = this.context.strict;
2763 var body = this.parseFunctionSourceElements();
2764 if (this.context.strict && firstRestricted) {
2765 this.throwUnexpectedToken(firstRestricted, message);
2767 if (this.context.strict && stricted) {
2768 this.tolerateUnexpectedToken(stricted, message);
2770 this.context.strict = previousStrict;
2771 this.context.allowYield = previousAllowYield;
2772 return this.finalize(node, new Node.FunctionExpression(id, params, body, isGenerator));
2774 // ECMA-262 14.1.1 Directive Prologues
2775 Parser.prototype.parseDirective = function () {
2776 var token = this.lookahead;
2777 var directive = null;
2778 var node = this.createNode();
2779 var expr = this.parseExpression();
2780 if (expr.type === syntax_1.Syntax.Literal) {
2781 directive = this.getTokenRaw(token).slice(1, -1);
2783 this.consumeSemicolon();
2784 return this.finalize(node, directive ? new Node.Directive(expr, directive) :
2785 new Node.ExpressionStatement(expr));
2787 Parser.prototype.parseDirectivePrologues = function () {
2788 var firstRestricted = null;
2791 var token = this.lookahead;
2792 if (token.type !== token_1.Token.StringLiteral) {
2795 var statement = this.parseDirective();
2796 body.push(statement);
2797 var directive = statement.directive;
2798 if (typeof directive !== 'string') {
2801 if (directive === 'use strict') {
2802 this.context.strict = true;
2803 if (firstRestricted) {
2804 this.tolerateUnexpectedToken(firstRestricted, messages_1.Messages.StrictOctalLiteral);
2808 if (!firstRestricted && token.octal) {
2809 firstRestricted = token;
2815 // ECMA-262 14.3 Method Definitions
2816 Parser.prototype.qualifiedPropertyName = function (token) {
2817 switch (token.type) {
2818 case token_1.Token.Identifier:
2819 case token_1.Token.StringLiteral:
2820 case token_1.Token.BooleanLiteral:
2821 case token_1.Token.NullLiteral:
2822 case token_1.Token.NumericLiteral:
2823 case token_1.Token.Keyword:
2825 case token_1.Token.Punctuator:
2826 return token.value === '[';
2830 Parser.prototype.parseGetterMethod = function () {
2831 var node = this.createNode();
2834 var isGenerator = false;
2838 firstRestricted: null,
2841 var previousAllowYield = this.context.allowYield;
2842 this.context.allowYield = false;
2843 var method = this.parsePropertyMethod(params);
2844 this.context.allowYield = previousAllowYield;
2845 return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
2847 Parser.prototype.parseSetterMethod = function () {
2848 var node = this.createNode();
2851 firstRestricted: null,
2854 var isGenerator = false;
2855 var previousAllowYield = this.context.allowYield;
2856 this.context.allowYield = false;
2858 if (this.match(')')) {
2859 this.tolerateUnexpectedToken(this.lookahead);
2862 this.parseFormalParameter(options);
2865 var method = this.parsePropertyMethod(options);
2866 this.context.allowYield = previousAllowYield;
2867 return this.finalize(node, new Node.FunctionExpression(null, options.params, method, isGenerator));
2869 Parser.prototype.parseGeneratorMethod = function () {
2870 var node = this.createNode();
2871 var isGenerator = true;
2872 var previousAllowYield = this.context.allowYield;
2873 this.context.allowYield = true;
2874 var params = this.parseFormalParameters();
2875 this.context.allowYield = false;
2876 var method = this.parsePropertyMethod(params);
2877 this.context.allowYield = previousAllowYield;
2878 return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
2880 // ECMA-262 14.4 Generator Function Definitions
2881 Parser.prototype.isStartOfExpression = function () {
2883 var value = this.lookahead.value;
2884 switch (this.lookahead.type) {
2885 case token_1.Token.Punctuator:
2886 start = (value === '[') || (value === '(') || (value === '{') ||
2887 (value === '+') || (value === '-') ||
2888 (value === '!') || (value === '~') ||
2889 (value === '++') || (value === '--') ||
2890 (value === '/') || (value === '/='); // regular expression literal
2892 case token_1.Token.Keyword:
2893 start = (value === 'class') || (value === 'delete') ||
2894 (value === 'function') || (value === 'let') || (value === 'new') ||
2895 (value === 'super') || (value === 'this') || (value === 'typeof') ||
2896 (value === 'void') || (value === 'yield');
2903 Parser.prototype.parseYieldExpression = function () {
2904 var node = this.createNode();
2905 this.expectKeyword('yield');
2906 var argument = null;
2907 var delegate = false;
2908 if (!this.hasLineTerminator) {
2909 var previousAllowYield = this.context.allowYield;
2910 this.context.allowYield = false;
2911 delegate = this.match('*');
2914 argument = this.parseAssignmentExpression();
2916 else if (this.isStartOfExpression()) {
2917 argument = this.parseAssignmentExpression();
2919 this.context.allowYield = previousAllowYield;
2921 return this.finalize(node, new Node.YieldExpression(argument, delegate));
2923 // ECMA-262 14.5 Class Definitions
2924 Parser.prototype.parseClassElement = function (hasConstructor) {
2925 var token = this.lookahead;
2926 var node = this.createNode();
2930 var computed = false;
2932 var isStatic = false;
2933 if (this.match('*')) {
2937 computed = this.match('[');
2938 key = this.parseObjectPropertyKey();
2940 if (id.name === 'static' && (this.qualifiedPropertyName(this.lookahead) || this.match('*'))) {
2941 token = this.lookahead;
2943 computed = this.match('[');
2944 if (this.match('*')) {
2948 key = this.parseObjectPropertyKey();
2952 var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
2953 if (token.type === token_1.Token.Identifier) {
2954 if (token.value === 'get' && lookaheadPropertyKey) {
2956 computed = this.match('[');
2957 key = this.parseObjectPropertyKey();
2958 this.context.allowYield = false;
2959 value = this.parseGetterMethod();
2961 else if (token.value === 'set' && lookaheadPropertyKey) {
2963 computed = this.match('[');
2964 key = this.parseObjectPropertyKey();
2965 value = this.parseSetterMethod();
2968 else if (token.type === token_1.Token.Punctuator && token.value === '*' && lookaheadPropertyKey) {
2970 computed = this.match('[');
2971 key = this.parseObjectPropertyKey();
2972 value = this.parseGeneratorMethod();
2975 if (!kind && key && this.match('(')) {
2977 value = this.parsePropertyMethodFunction();
2981 this.throwUnexpectedToken(this.lookahead);
2983 if (kind === 'init') {
2987 if (isStatic && this.isPropertyKey(key, 'prototype')) {
2988 this.throwUnexpectedToken(token, messages_1.Messages.StaticPrototype);
2990 if (!isStatic && this.isPropertyKey(key, 'constructor')) {
2991 if (kind !== 'method' || !method || value.generator) {
2992 this.throwUnexpectedToken(token, messages_1.Messages.ConstructorSpecialMethod);
2994 if (hasConstructor.value) {
2995 this.throwUnexpectedToken(token, messages_1.Messages.DuplicateConstructor);
2998 hasConstructor.value = true;
3000 kind = 'constructor';
3003 return this.finalize(node, new Node.MethodDefinition(key, computed, value, kind, isStatic));
3005 Parser.prototype.parseClassElementList = function () {
3007 var hasConstructor = { value: false };
3009 while (!this.match('}')) {
3010 if (this.match(';')) {
3014 body.push(this.parseClassElement(hasConstructor));
3020 Parser.prototype.parseClassBody = function () {
3021 var node = this.createNode();
3022 var elementList = this.parseClassElementList();
3023 return this.finalize(node, new Node.ClassBody(elementList));
3025 Parser.prototype.parseClassDeclaration = function (identifierIsOptional) {
3026 var node = this.createNode();
3027 var previousStrict = this.context.strict;
3028 this.context.strict = true;
3029 this.expectKeyword('class');
3030 var id = (identifierIsOptional && (this.lookahead.type !== token_1.Token.Identifier)) ? null : this.parseVariableIdentifier();
3031 var superClass = null;
3032 if (this.matchKeyword('extends')) {
3034 superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
3036 var classBody = this.parseClassBody();
3037 this.context.strict = previousStrict;
3038 return this.finalize(node, new Node.ClassDeclaration(id, superClass, classBody));
3040 Parser.prototype.parseClassExpression = function () {
3041 var node = this.createNode();
3042 var previousStrict = this.context.strict;
3043 this.context.strict = true;
3044 this.expectKeyword('class');
3045 var id = (this.lookahead.type === token_1.Token.Identifier) ? this.parseVariableIdentifier() : null;
3046 var superClass = null;
3047 if (this.matchKeyword('extends')) {
3049 superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
3051 var classBody = this.parseClassBody();
3052 this.context.strict = previousStrict;
3053 return this.finalize(node, new Node.ClassExpression(id, superClass, classBody));
3055 // ECMA-262 15.1 Scripts
3056 // ECMA-262 15.2 Modules
3057 Parser.prototype.parseProgram = function () {
3058 var node = this.createNode();
3059 var body = this.parseDirectivePrologues();
3060 while (this.startMarker.index < this.scanner.length) {
3061 body.push(this.parseStatementListItem());
3063 return this.finalize(node, new Node.Program(body, this.sourceType));
3065 // ECMA-262 15.2.2 Imports
3066 Parser.prototype.parseModuleSpecifier = function () {
3067 var node = this.createNode();
3068 if (this.lookahead.type !== token_1.Token.StringLiteral) {
3069 this.throwError(messages_1.Messages.InvalidModuleSpecifier);
3071 var token = this.nextToken();
3072 var raw = this.getTokenRaw(token);
3073 return this.finalize(node, new Node.Literal(token.value, raw));
3075 // import {<foo as bar>} ...;
3076 Parser.prototype.parseImportSpecifier = function () {
3077 var node = this.createNode();
3080 if (this.lookahead.type === token_1.Token.Identifier) {
3081 imported = this.parseVariableIdentifier();
3083 if (this.matchContextualKeyword('as')) {
3085 local = this.parseVariableIdentifier();
3089 imported = this.parseIdentifierName();
3091 if (this.matchContextualKeyword('as')) {
3093 local = this.parseVariableIdentifier();
3096 this.throwUnexpectedToken(this.nextToken());
3099 return this.finalize(node, new Node.ImportSpecifier(local, imported));
3101 // {foo, bar as bas}
3102 Parser.prototype.parseNamedImports = function () {
3104 var specifiers = [];
3105 while (!this.match('}')) {
3106 specifiers.push(this.parseImportSpecifier());
3107 if (!this.match('}')) {
3114 // import <foo> ...;
3115 Parser.prototype.parseImportDefaultSpecifier = function () {
3116 var node = this.createNode();
3117 var local = this.parseIdentifierName();
3118 return this.finalize(node, new Node.ImportDefaultSpecifier(local));
3120 // import <* as foo> ...;
3121 Parser.prototype.parseImportNamespaceSpecifier = function () {
3122 var node = this.createNode();
3124 if (!this.matchContextualKeyword('as')) {
3125 this.throwError(messages_1.Messages.NoAsAfterImportNamespace);
3128 var local = this.parseIdentifierName();
3129 return this.finalize(node, new Node.ImportNamespaceSpecifier(local));
3131 Parser.prototype.parseImportDeclaration = function () {
3132 if (this.context.inFunctionBody) {
3133 this.throwError(messages_1.Messages.IllegalImportDeclaration);
3135 var node = this.createNode();
3136 this.expectKeyword('import');
3138 var specifiers = [];
3139 if (this.lookahead.type === token_1.Token.StringLiteral) {
3141 src = this.parseModuleSpecifier();
3144 if (this.match('{')) {
3146 specifiers = specifiers.concat(this.parseNamedImports());
3148 else if (this.match('*')) {
3150 specifiers.push(this.parseImportNamespaceSpecifier());
3152 else if (this.isIdentifierName(this.lookahead) && !this.matchKeyword('default')) {
3154 specifiers.push(this.parseImportDefaultSpecifier());
3155 if (this.match(',')) {
3157 if (this.match('*')) {
3158 // import foo, * as foo
3159 specifiers.push(this.parseImportNamespaceSpecifier());
3161 else if (this.match('{')) {
3162 // import foo, {bar}
3163 specifiers = specifiers.concat(this.parseNamedImports());
3166 this.throwUnexpectedToken(this.lookahead);
3171 this.throwUnexpectedToken(this.nextToken());
3173 if (!this.matchContextualKeyword('from')) {
3174 var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
3175 this.throwError(message, this.lookahead.value);
3178 src = this.parseModuleSpecifier();
3180 this.consumeSemicolon();
3181 return this.finalize(node, new Node.ImportDeclaration(specifiers, src));
3183 // ECMA-262 15.2.3 Exports
3184 Parser.prototype.parseExportSpecifier = function () {
3185 var node = this.createNode();
3186 var local = this.parseIdentifierName();
3187 var exported = local;
3188 if (this.matchContextualKeyword('as')) {
3190 exported = this.parseIdentifierName();
3192 return this.finalize(node, new Node.ExportSpecifier(local, exported));
3194 Parser.prototype.parseExportDeclaration = function () {
3195 if (this.context.inFunctionBody) {
3196 this.throwError(messages_1.Messages.IllegalExportDeclaration);
3198 var node = this.createNode();
3199 this.expectKeyword('export');
3200 var exportDeclaration;
3201 if (this.matchKeyword('default')) {
3202 // export default ...
3204 if (this.matchKeyword('function')) {
3205 // export default function foo () {}
3206 // export default function () {}
3207 var declaration = this.parseFunctionDeclaration(true);
3208 exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
3210 else if (this.matchKeyword('class')) {
3211 // export default class foo {}
3212 var declaration = this.parseClassDeclaration(true);
3213 exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
3216 if (this.matchContextualKeyword('from')) {
3217 this.throwError(messages_1.Messages.UnexpectedToken, this.lookahead.value);
3219 // export default {};
3220 // export default [];
3221 // export default (1 + 2);
3222 var declaration = this.match('{') ? this.parseObjectInitializer() :
3223 this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression();
3224 this.consumeSemicolon();
3225 exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
3228 else if (this.match('*')) {
3229 // export * from 'foo';
3231 if (!this.matchContextualKeyword('from')) {
3232 var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
3233 this.throwError(message, this.lookahead.value);
3236 var src = this.parseModuleSpecifier();
3237 this.consumeSemicolon();
3238 exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src));
3240 else if (this.lookahead.type === token_1.Token.Keyword) {
3241 // export var f = 1;
3242 var declaration = void 0;
3243 switch (this.lookahead.value) {
3246 declaration = this.parseLexicalDeclaration({ inFor: false });
3251 declaration = this.parseStatementListItem();
3254 this.throwUnexpectedToken(this.lookahead);
3256 exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
3259 var specifiers = [];
3261 var isExportFromIdentifier = false;
3263 while (!this.match('}')) {
3264 isExportFromIdentifier = isExportFromIdentifier || this.matchKeyword('default');
3265 specifiers.push(this.parseExportSpecifier());
3266 if (!this.match('}')) {
3271 if (this.matchContextualKeyword('from')) {
3272 // export {default} from 'foo';
3273 // export {foo} from 'foo';
3275 source = this.parseModuleSpecifier();
3276 this.consumeSemicolon();
3278 else if (isExportFromIdentifier) {
3279 // export {default}; // missing fromClause
3280 var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
3281 this.throwError(message, this.lookahead.value);
3285 this.consumeSemicolon();
3287 exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(null, specifiers, source));
3289 return exportDeclaration;
3293 exports.Parser = Parser;
3298 /***/ function(module, exports) {
3300 // Ensure the condition is true, otherwise throw an error.
3301 // This is only to have a better contract semantic, i.e. another safety net
3302 // to catch a logic error. The condition shall be fulfilled in normal case.
3303 // Do NOT use this to enforce a certain condition on any user input.
3305 function assert(condition, message) {
3306 /* istanbul ignore if */
3308 throw new Error('ASSERT: ' + message);
3311 exports.assert = assert;
3316 /***/ function(module, exports) {
3319 // Error messages should be identical to V8.
3320 exports.Messages = {
3321 UnexpectedToken: 'Unexpected token %0',
3322 UnexpectedTokenIllegal: 'Unexpected token ILLEGAL',
3323 UnexpectedNumber: 'Unexpected number',
3324 UnexpectedString: 'Unexpected string',
3325 UnexpectedIdentifier: 'Unexpected identifier',
3326 UnexpectedReserved: 'Unexpected reserved word',
3327 UnexpectedTemplate: 'Unexpected quasi %0',
3328 UnexpectedEOS: 'Unexpected end of input',
3329 NewlineAfterThrow: 'Illegal newline after throw',
3330 InvalidRegExp: 'Invalid regular expression',
3331 UnterminatedRegExp: 'Invalid regular expression: missing /',
3332 InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
3333 InvalidLHSInForIn: 'Invalid left-hand side in for-in',
3334 InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
3335 MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
3336 NoCatchOrFinally: 'Missing catch or finally after try',
3337 UnknownLabel: 'Undefined label \'%0\'',
3338 Redeclaration: '%0 \'%1\' has already been declared',
3339 IllegalContinue: 'Illegal continue statement',
3340 IllegalBreak: 'Illegal break statement',
3341 IllegalReturn: 'Illegal return statement',
3342 StrictModeWith: 'Strict mode code may not include a with statement',
3343 StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
3344 StrictVarName: 'Variable name may not be eval or arguments in strict mode',
3345 StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
3346 StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
3347 StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
3348 StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
3349 StrictDelete: 'Delete of an unqualified identifier in strict mode.',
3350 StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
3351 StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
3352 StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
3353 StrictReservedWord: 'Use of future reserved word in strict mode',
3354 TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
3355 ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
3356 DefaultRestParameter: 'Unexpected token =',
3357 DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
3358 ConstructorSpecialMethod: 'Class constructor may not be an accessor',
3359 DuplicateConstructor: 'A class may only have one constructor',
3360 StaticPrototype: 'Classes may not have static property named prototype',
3361 MissingFromClause: 'Unexpected token',
3362 NoAsAfterImportNamespace: 'Unexpected token',
3363 InvalidModuleSpecifier: 'Unexpected token',
3364 IllegalImportDeclaration: 'Unexpected token',
3365 IllegalExportDeclaration: 'Unexpected token',
3366 DuplicateBinding: 'Duplicate binding %0',
3367 ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer'
3373 /***/ function(module, exports) {
3376 var ErrorHandler = (function () {
3377 function ErrorHandler() {
3379 this.tolerant = false;
3382 ErrorHandler.prototype.recordError = function (error) {
3383 this.errors.push(error);
3386 ErrorHandler.prototype.tolerate = function (error) {
3387 if (this.tolerant) {
3388 this.recordError(error);
3395 ErrorHandler.prototype.constructError = function (msg, column) {
3396 var error = new Error(msg);
3401 /* istanbul ignore else */
3402 if (Object.create && Object.defineProperty) {
3403 error = Object.create(base);
3404 Object.defineProperty(error, 'column', { value: column });
3412 ErrorHandler.prototype.createError = function (index, line, col, description) {
3413 var msg = 'Line ' + line + ': ' + description;
3414 var error = this.constructError(msg, col);
3415 error.index = index;
3416 error.lineNumber = line;
3417 error.description = description;
3421 ErrorHandler.prototype.throwError = function (index, line, col, description) {
3422 throw this.createError(index, line, col, description);
3425 ErrorHandler.prototype.tolerateError = function (index, line, col, description) {
3426 var error = this.createError(index, line, col, description);
3427 if (this.tolerant) {
3428 this.recordError(error);
3435 return ErrorHandler;
3437 exports.ErrorHandler = ErrorHandler;
3442 /***/ function(module, exports) {
3446 Token[Token["BooleanLiteral"] = 1] = "BooleanLiteral";
3447 Token[Token["EOF"] = 2] = "EOF";
3448 Token[Token["Identifier"] = 3] = "Identifier";
3449 Token[Token["Keyword"] = 4] = "Keyword";
3450 Token[Token["NullLiteral"] = 5] = "NullLiteral";
3451 Token[Token["NumericLiteral"] = 6] = "NumericLiteral";
3452 Token[Token["Punctuator"] = 7] = "Punctuator";
3453 Token[Token["StringLiteral"] = 8] = "StringLiteral";
3454 Token[Token["RegularExpression"] = 9] = "RegularExpression";
3455 Token[Token["Template"] = 10] = "Template";
3456 })(exports.Token || (exports.Token = {}));
3457 var Token = exports.Token;
3459 exports.TokenName = {};
3460 exports.TokenName[Token.BooleanLiteral] = 'Boolean';
3461 exports.TokenName[Token.EOF] = '<end>';
3462 exports.TokenName[Token.Identifier] = 'Identifier';
3463 exports.TokenName[Token.Keyword] = 'Keyword';
3464 exports.TokenName[Token.NullLiteral] = 'Null';
3465 exports.TokenName[Token.NumericLiteral] = 'Numeric';
3466 exports.TokenName[Token.Punctuator] = 'Punctuator';
3467 exports.TokenName[Token.StringLiteral] = 'String';
3468 exports.TokenName[Token.RegularExpression] = 'RegularExpression';
3469 exports.TokenName[Token.Template] = 'Template';
3474 /***/ function(module, exports, __webpack_require__) {
3477 var assert_1 = __webpack_require__(4);
3478 var messages_1 = __webpack_require__(5);
3479 var character_1 = __webpack_require__(9);
3480 var token_1 = __webpack_require__(7);
3481 function hexValue(ch) {
3482 return '0123456789abcdef'.indexOf(ch.toLowerCase());
3484 function octalValue(ch) {
3485 return '01234567'.indexOf(ch);
3487 var Scanner = (function () {
3488 function Scanner(code, handler) {
3490 this.errorHandler = handler;
3491 this.trackComment = false;
3492 this.length = code.length;
3494 this.lineNumber = (code.length > 0) ? 1 : 0;
3496 this.curlyStack = [];
3499 Scanner.prototype.eof = function () {
3500 return this.index >= this.length;
3503 Scanner.prototype.throwUnexpectedToken = function (message) {
3504 if (message === void 0) { message = messages_1.Messages.UnexpectedTokenIllegal; }
3505 this.errorHandler.throwError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
3508 Scanner.prototype.tolerateUnexpectedToken = function () {
3509 this.errorHandler.tolerateError(this.index, this.lineNumber, this.index - this.lineStart + 1, messages_1.Messages.UnexpectedTokenIllegal);
3512 // ECMA-262 11.4 Comments
3513 Scanner.prototype.skipSingleLineComment = function (offset) {
3516 if (this.trackComment) {
3518 start = this.index - offset;
3521 line: this.lineNumber,
3522 column: this.index - this.lineStart - offset
3527 while (!this.eof()) {
3528 var ch = this.source.charCodeAt(this.index);
3530 if (character_1.Character.isLineTerminator(ch)) {
3531 if (this.trackComment) {
3533 line: this.lineNumber,
3534 column: this.index - this.lineStart - 1
3538 slice: [start + offset, this.index - 1],
3539 range: [start, this.index - 1],
3542 comments.push(entry);
3544 if (ch === 13 && this.source.charCodeAt(this.index) === 10) {
3548 this.lineStart = this.index;
3552 if (this.trackComment) {
3554 line: this.lineNumber,
3555 column: this.index - this.lineStart
3559 slice: [start + offset, this.index],
3560 range: [start, this.index],
3563 comments.push(entry);
3568 Scanner.prototype.skipMultiLineComment = function () {
3571 if (this.trackComment) {
3573 start = this.index - 2;
3576 line: this.lineNumber,
3577 column: this.index - this.lineStart - 2
3582 while (!this.eof()) {
3583 var ch = this.source.charCodeAt(this.index);
3584 if (character_1.Character.isLineTerminator(ch)) {
3585 if (ch === 0x0D && this.source.charCodeAt(this.index + 1) === 0x0A) {
3590 this.lineStart = this.index;
3592 else if (ch === 0x2A) {
3593 // Block comment ends with '*/'.
3594 if (this.source.charCodeAt(this.index + 1) === 0x2F) {
3596 if (this.trackComment) {
3598 line: this.lineNumber,
3599 column: this.index - this.lineStart
3603 slice: [start + 2, this.index - 2],
3604 range: [start, this.index],
3607 comments.push(entry);
3617 // Ran off the end of the file - the whole thing is a comment
3618 if (this.trackComment) {
3620 line: this.lineNumber,
3621 column: this.index - this.lineStart
3625 slice: [start + 2, this.index],
3626 range: [start, this.index],
3629 comments.push(entry);
3631 this.tolerateUnexpectedToken();
3635 Scanner.prototype.scanComments = function () {
3637 if (this.trackComment) {
3640 var start = (this.index === 0);
3641 while (!this.eof()) {
3642 var ch = this.source.charCodeAt(this.index);
3643 if (character_1.Character.isWhiteSpace(ch)) {
3646 else if (character_1.Character.isLineTerminator(ch)) {
3648 if (ch === 0x0D && this.source.charCodeAt(this.index) === 0x0A) {
3652 this.lineStart = this.index;
3655 else if (ch === 0x2F) {
3656 ch = this.source.charCodeAt(this.index + 1);
3659 var comment = this.skipSingleLineComment(2);
3660 if (this.trackComment) {
3661 comments = comments.concat(comment);
3665 else if (ch === 0x2A) {
3667 var comment = this.skipMultiLineComment();
3668 if (this.trackComment) {
3669 comments = comments.concat(comment);
3676 else if (start && ch === 0x2D) {
3678 if ((this.source.charCodeAt(this.index + 1) === 0x2D) && (this.source.charCodeAt(this.index + 2) === 0x3E)) {
3679 // '-->' is a single-line comment
3681 var comment = this.skipSingleLineComment(3);
3682 if (this.trackComment) {
3683 comments = comments.concat(comment);
3690 else if (ch === 0x3C) {
3691 if (this.source.slice(this.index + 1, this.index + 4) === '!--') {
3692 this.index += 4; // `<!--`
3693 var comment = this.skipSingleLineComment(4);
3694 if (this.trackComment) {
3695 comments = comments.concat(comment);
3709 // ECMA-262 11.6.2.2 Future Reserved Words
3710 Scanner.prototype.isFutureReservedWord = function (id) {
3722 Scanner.prototype.isStrictModeReservedWord = function (id) {
3739 Scanner.prototype.isRestrictedWord = function (id) {
3740 return id === 'eval' || id === 'arguments';
3743 // ECMA-262 11.6.2.1 Keywords
3744 Scanner.prototype.isKeyword = function (id) {
3745 switch (id.length) {
3747 return (id === 'if') || (id === 'in') || (id === 'do');
3749 return (id === 'var') || (id === 'for') || (id === 'new') ||
3750 (id === 'try') || (id === 'let');
3752 return (id === 'this') || (id === 'else') || (id === 'case') ||
3753 (id === 'void') || (id === 'with') || (id === 'enum');
3755 return (id === 'while') || (id === 'break') || (id === 'catch') ||
3756 (id === 'throw') || (id === 'const') || (id === 'yield') ||
3757 (id === 'class') || (id === 'super');
3759 return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
3760 (id === 'switch') || (id === 'export') || (id === 'import');
3762 return (id === 'default') || (id === 'finally') || (id === 'extends');
3764 return (id === 'function') || (id === 'continue') || (id === 'debugger');
3766 return (id === 'instanceof');
3772 Scanner.prototype.codePointAt = function (i) {
3773 var cp = this.source.charCodeAt(i);
3774 if (cp >= 0xD800 && cp <= 0xDBFF) {
3775 var second = this.source.charCodeAt(i + 1);
3776 if (second >= 0xDC00 && second <= 0xDFFF) {
3778 cp = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
3784 Scanner.prototype.scanHexEscape = function (prefix) {
3785 var len = (prefix === 'u') ? 4 : 2;
3787 for (var i = 0; i < len; ++i) {
3788 if (!this.eof() && character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
3789 code = code * 16 + hexValue(this.source[this.index++]);
3795 return String.fromCharCode(code);
3798 Scanner.prototype.scanUnicodeCodePointEscape = function () {
3799 var ch = this.source[this.index];
3801 // At least, one hex digit is required.
3803 this.throwUnexpectedToken();
3805 while (!this.eof()) {
3806 ch = this.source[this.index++];
3807 if (!character_1.Character.isHexDigit(ch.charCodeAt(0))) {
3810 code = code * 16 + hexValue(ch);
3812 if (code > 0x10FFFF || ch !== '}') {
3813 this.throwUnexpectedToken();
3815 return character_1.Character.fromCodePoint(code);
3818 Scanner.prototype.getIdentifier = function () {
3819 var start = this.index++;
3820 while (!this.eof()) {
3821 var ch = this.source.charCodeAt(this.index);
3823 // Blackslash (U+005C) marks Unicode escape sequence.
3825 return this.getComplexIdentifier();
3827 else if (ch >= 0xD800 && ch < 0xDFFF) {
3828 // Need to handle surrogate pairs.
3830 return this.getComplexIdentifier();
3832 if (character_1.Character.isIdentifierPart(ch)) {
3839 return this.source.slice(start, this.index);
3842 Scanner.prototype.getComplexIdentifier = function () {
3843 var cp = this.codePointAt(this.index);
3844 var id = character_1.Character.fromCodePoint(cp);
3845 this.index += id.length;
3846 // '\u' (U+005C, U+0075) denotes an escaped character.
3849 if (this.source.charCodeAt(this.index) !== 0x75) {
3850 this.throwUnexpectedToken();
3853 if (this.source[this.index] === '{') {
3855 ch = this.scanUnicodeCodePointEscape();
3858 ch = this.scanHexEscape('u');
3859 cp = ch.charCodeAt(0);
3860 if (!ch || ch === '\\' || !character_1.Character.isIdentifierStart(cp)) {
3861 this.throwUnexpectedToken();
3866 while (!this.eof()) {
3867 cp = this.codePointAt(this.index);
3868 if (!character_1.Character.isIdentifierPart(cp)) {
3871 ch = character_1.Character.fromCodePoint(cp);
3873 this.index += ch.length;
3874 // '\u' (U+005C, U+0075) denotes an escaped character.
3876 id = id.substr(0, id.length - 1);
3877 if (this.source.charCodeAt(this.index) !== 0x75) {
3878 this.throwUnexpectedToken();
3881 if (this.source[this.index] === '{') {
3883 ch = this.scanUnicodeCodePointEscape();
3886 ch = this.scanHexEscape('u');
3887 cp = ch.charCodeAt(0);
3888 if (!ch || ch === '\\' || !character_1.Character.isIdentifierPart(cp)) {
3889 this.throwUnexpectedToken();
3898 Scanner.prototype.octalToDecimal = function (ch) {
3899 // \0 is not octal escape sequence
3900 var octal = (ch !== '0');
3901 var code = octalValue(ch);
3902 if (!this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
3904 code = code * 8 + octalValue(this.source[this.index++]);
3905 // 3 digits are only allowed when string starts
3907 if ('0123'.indexOf(ch) >= 0 && !this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
3908 code = code * 8 + octalValue(this.source[this.index++]);
3917 // ECMA-262 11.6 Names and Keywords
3918 Scanner.prototype.scanIdentifier = function () {
3920 var start = this.index;
3921 // Backslash (U+005C) starts an escaped character.
3922 var id = (this.source.charCodeAt(start) === 0x5C) ? this.getComplexIdentifier() : this.getIdentifier();
3923 // There is no keyword or literal with only one character.
3924 // Thus, it must be an identifier.
3925 if (id.length === 1) {
3926 type = token_1.Token.Identifier;
3928 else if (this.isKeyword(id)) {
3929 type = token_1.Token.Keyword;
3931 else if (id === 'null') {
3932 type = token_1.Token.NullLiteral;
3934 else if (id === 'true' || id === 'false') {
3935 type = token_1.Token.BooleanLiteral;
3938 type = token_1.Token.Identifier;
3943 lineNumber: this.lineNumber,
3944 lineStart: this.lineStart,
3950 // ECMA-262 11.7 Punctuators
3951 Scanner.prototype.scanPunctuator = function () {
3953 type: token_1.Token.Punctuator,
3955 lineNumber: this.lineNumber,
3956 lineStart: this.lineStart,
3960 // Check for most common single-character punctuators.
3961 var str = this.source[this.index];
3966 this.curlyStack.push('{');
3972 if (this.source[this.index] === '.' && this.source[this.index + 1] === '.') {
3973 // Spread operator: ...
3980 this.curlyStack.pop();
3993 // 4-character punctuator.
3994 str = this.source.substr(this.index, 4);
3995 if (str === '>>>=') {
3999 // 3-character punctuators.
4000 str = str.substr(0, 3);
4001 if (str === '===' || str === '!==' || str === '>>>' ||
4002 str === '<<=' || str === '>>=' || str === '**=') {
4006 // 2-character punctuators.
4007 str = str.substr(0, 2);
4008 if (str === '&&' || str === '||' || str === '==' || str === '!=' ||
4009 str === '+=' || str === '-=' || str === '*=' || str === '/=' ||
4010 str === '++' || str === '--' || str === '<<' || str === '>>' ||
4011 str === '&=' || str === '|=' || str === '^=' || str === '%=' ||
4012 str === '<=' || str === '>=' || str === '=>' || str === '**') {
4016 // 1-character punctuators.
4017 str = this.source[this.index];
4018 if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {
4025 if (this.index === token.start) {
4026 this.throwUnexpectedToken();
4028 token.end = this.index;
4033 // ECMA-262 11.8.3 Numeric Literals
4034 Scanner.prototype.scanHexLiteral = function (start) {
4036 while (!this.eof()) {
4037 if (!character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
4040 number += this.source[this.index++];
4042 if (number.length === 0) {
4043 this.throwUnexpectedToken();
4045 if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
4046 this.throwUnexpectedToken();
4049 type: token_1.Token.NumericLiteral,
4050 value: parseInt('0x' + number, 16),
4051 lineNumber: this.lineNumber,
4052 lineStart: this.lineStart,
4058 Scanner.prototype.scanBinaryLiteral = function (start) {
4061 while (!this.eof()) {
4062 ch = this.source[this.index];
4063 if (ch !== '0' && ch !== '1') {
4066 number += this.source[this.index++];
4068 if (number.length === 0) {
4070 this.throwUnexpectedToken();
4073 ch = this.source.charCodeAt(this.index);
4074 /* istanbul ignore else */
4075 if (character_1.Character.isIdentifierStart(ch) || character_1.Character.isDecimalDigit(ch)) {
4076 this.throwUnexpectedToken();
4080 type: token_1.Token.NumericLiteral,
4081 value: parseInt(number, 2),
4082 lineNumber: this.lineNumber,
4083 lineStart: this.lineStart,
4089 Scanner.prototype.scanOctalLiteral = function (prefix, start) {
4092 if (character_1.Character.isOctalDigit(prefix.charCodeAt(0))) {
4094 number = '0' + this.source[this.index++];
4099 while (!this.eof()) {
4100 if (!character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
4103 number += this.source[this.index++];
4105 if (!octal && number.length === 0) {
4107 this.throwUnexpectedToken();
4109 if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index)) || character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
4110 this.throwUnexpectedToken();
4113 type: token_1.Token.NumericLiteral,
4114 value: parseInt(number, 8),
4116 lineNumber: this.lineNumber,
4117 lineStart: this.lineStart,
4123 Scanner.prototype.isImplicitOctalLiteral = function () {
4124 // Implicit octal, unless there is a non-octal digit.
4125 // (Annex B.1.1 on Numeric Literals)
4126 for (var i = this.index + 1; i < this.length; ++i) {
4127 var ch = this.source[i];
4128 if (ch === '8' || ch === '9') {
4131 if (!character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
4138 Scanner.prototype.scanNumericLiteral = function () {
4139 var start = this.index;
4140 var ch = this.source[start];
4141 assert_1.assert(character_1.Character.isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'), 'Numeric literal must start with a decimal digit or a decimal point');
4144 number = this.source[this.index++];
4145 ch = this.source[this.index];
4146 // Hex number starts with '0x'.
4147 // Octal number starts with '0'.
4148 // Octal number in ES6 starts with '0o'.
4149 // Binary number in ES6 starts with '0b'.
4150 if (number === '0') {
4151 if (ch === 'x' || ch === 'X') {
4153 return this.scanHexLiteral(start);
4155 if (ch === 'b' || ch === 'B') {
4157 return this.scanBinaryLiteral(start);
4159 if (ch === 'o' || ch === 'O') {
4160 return this.scanOctalLiteral(ch, start);
4162 if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
4163 if (this.isImplicitOctalLiteral()) {
4164 return this.scanOctalLiteral(ch, start);
4168 while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
4169 number += this.source[this.index++];
4171 ch = this.source[this.index];
4174 number += this.source[this.index++];
4175 while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
4176 number += this.source[this.index++];
4178 ch = this.source[this.index];
4180 if (ch === 'e' || ch === 'E') {
4181 number += this.source[this.index++];
4182 ch = this.source[this.index];
4183 if (ch === '+' || ch === '-') {
4184 number += this.source[this.index++];
4186 if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
4187 while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
4188 number += this.source[this.index++];
4192 this.throwUnexpectedToken();
4195 if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
4196 this.throwUnexpectedToken();
4199 type: token_1.Token.NumericLiteral,
4200 value: parseFloat(number),
4201 lineNumber: this.lineNumber,
4202 lineStart: this.lineStart,
4208 // ECMA-262 11.8.4 String Literals
4209 Scanner.prototype.scanStringLiteral = function () {
4210 var start = this.index;
4211 var quote = this.source[start];
4212 assert_1.assert((quote === '\'' || quote === '"'), 'String literal must starts with a quote');
4216 while (!this.eof()) {
4217 var ch = this.source[this.index++];
4222 else if (ch === '\\') {
4223 ch = this.source[this.index++];
4224 if (!ch || !character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
4228 if (this.source[this.index] === '{') {
4230 str += this.scanUnicodeCodePointEscape();
4233 var unescaped = this.scanHexEscape(ch);
4235 this.throwUnexpectedToken();
4261 this.tolerateUnexpectedToken();
4264 if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
4265 var octToDec = this.octalToDecimal(ch);
4266 octal = octToDec.octal || octal;
4267 str += String.fromCharCode(octToDec.code);
4277 if (ch === '\r' && this.source[this.index] === '\n') {
4280 this.lineStart = this.index;
4283 else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
4292 this.throwUnexpectedToken();
4295 type: token_1.Token.StringLiteral,
4298 lineNumber: this.lineNumber,
4299 lineStart: this.lineStart,
4305 // ECMA-262 11.8.6 Template Literal Lexical Components
4306 Scanner.prototype.scanTemplate = function () {
4308 var terminated = false;
4309 var start = this.index;
4310 var head = (this.source[start] === '`');
4314 while (!this.eof()) {
4315 var ch = this.source[this.index++];
4322 else if (ch === '$') {
4323 if (this.source[this.index] === '{') {
4324 this.curlyStack.push('${');
4331 else if (ch === '\\') {
4332 ch = this.source[this.index++];
4333 if (!character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
4346 if (this.source[this.index] === '{') {
4348 cooked += this.scanUnicodeCodePointEscape();
4351 var restore = this.index;
4352 var unescaped = this.scanHexEscape(ch);
4354 cooked += unescaped;
4357 this.index = restore;
4373 if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
4374 // Illegal: \01 \02 and so on
4375 this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
4379 else if (character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
4381 this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
4391 if (ch === '\r' && this.source[this.index] === '\n') {
4394 this.lineStart = this.index;
4397 else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
4399 if (ch === '\r' && this.source[this.index] === '\n') {
4402 this.lineStart = this.index;
4410 this.throwUnexpectedToken();
4413 this.curlyStack.pop();
4416 type: token_1.Token.Template,
4419 raw: this.source.slice(start + 1, this.index - rawOffset)
4423 lineNumber: this.lineNumber,
4424 lineStart: this.lineStart,
4430 // ECMA-262 11.8.5 Regular Expression Literals
4431 Scanner.prototype.testRegExp = function (pattern, flags) {
4432 // The BMP character to use as a replacement for astral symbols when
4433 // translating an ES6 "u"-flagged pattern to an ES5-compatible
4435 // Note: replacing with '\uFFFF' enables false positives in unlikely
4436 // scenarios. For example, `[\u{1044f}-\u{10440}]` is an invalid
4437 // pattern that would not be detected by this substitution.
4438 var astralSubstitute = '\uFFFF';
4441 if (flags.indexOf('u') >= 0) {
4443 .replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, function ($0, $1, $2) {
4444 var codePoint = parseInt($1 || $2, 16);
4445 if (codePoint > 0x10FFFF) {
4446 self.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
4448 if (codePoint <= 0xFFFF) {
4449 return String.fromCharCode(codePoint);
4451 return astralSubstitute;
4453 .replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, astralSubstitute);
4455 // First, detect invalid regular expressions.
4460 this.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
4462 // Return a regular expression object for this pattern-flag pair, or
4463 // `null` in case the current environment doesn't support the flags it
4466 return new RegExp(pattern, flags);
4469 /* istanbul ignore next */
4474 Scanner.prototype.scanRegExpBody = function () {
4475 var ch = this.source[this.index];
4476 assert_1.assert(ch === '/', 'Regular expression literal must start with a slash');
4477 var str = this.source[this.index++];
4478 var classMarker = false;
4479 var terminated = false;
4480 while (!this.eof()) {
4481 ch = this.source[this.index++];
4484 ch = this.source[this.index++];
4486 if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
4487 this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
4491 else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
4492 this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
4494 else if (classMarker) {
4496 classMarker = false;
4504 else if (ch === '[') {
4510 this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
4512 // Exclude leading and trailing slash.
4513 var body = str.substr(1, str.length - 2);
4520 Scanner.prototype.scanRegExpFlags = function () {
4523 while (!this.eof()) {
4524 var ch = this.source[this.index];
4525 if (!character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
4529 if (ch === '\\' && !this.eof()) {
4530 ch = this.source[this.index];
4533 var restore = this.index;
4534 ch = this.scanHexEscape('u');
4537 for (str += '\\u'; restore < this.index; ++restore) {
4538 str += this.source[restore];
4542 this.index = restore;
4546 this.tolerateUnexpectedToken();
4550 this.tolerateUnexpectedToken();
4564 Scanner.prototype.scanRegExp = function () {
4565 var start = this.index;
4566 var body = this.scanRegExpBody();
4567 var flags = this.scanRegExpFlags();
4568 var value = this.testRegExp(body.value, flags.value);
4570 type: token_1.Token.RegularExpression,
4572 literal: body.literal + flags.literal,
4574 pattern: body.value,
4577 lineNumber: this.lineNumber,
4578 lineStart: this.lineStart,
4584 Scanner.prototype.lex = function () {
4587 type: token_1.Token.EOF,
4588 lineNumber: this.lineNumber,
4589 lineStart: this.lineStart,
4594 var cp = this.source.charCodeAt(this.index);
4595 if (character_1.Character.isIdentifierStart(cp)) {
4596 return this.scanIdentifier();
4598 // Very common: ( and ) and ;
4599 if (cp === 0x28 || cp === 0x29 || cp === 0x3B) {
4600 return this.scanPunctuator();
4602 // String literal starts with single quote (U+0027) or double quote (U+0022).
4603 if (cp === 0x27 || cp === 0x22) {
4604 return this.scanStringLiteral();
4606 // Dot (.) U+002E can also start a floating-point number, hence the need
4607 // to check the next character.
4609 if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index + 1))) {
4610 return this.scanNumericLiteral();
4612 return this.scanPunctuator();
4614 if (character_1.Character.isDecimalDigit(cp)) {
4615 return this.scanNumericLiteral();
4617 // Template literals start with ` (U+0060) for template head
4618 // or } (U+007D) for template middle or template tail.
4619 if (cp === 0x60 || (cp === 0x7D && this.curlyStack[this.curlyStack.length - 1] === '${')) {
4620 return this.scanTemplate();
4622 // Possible identifier start in a surrogate pair.
4623 if (cp >= 0xD800 && cp < 0xDFFF) {
4624 if (character_1.Character.isIdentifierStart(this.codePointAt(this.index))) {
4625 return this.scanIdentifier();
4628 return this.scanPunctuator();
4633 exports.Scanner = Scanner;
4638 /***/ function(module, exports) {
4641 // See also tools/generate-unicode-regex.js.
4643 // Unicode v8.0.0 NonAsciiIdentifierStart:
4644 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]/,
4645 // Unicode v8.0.0 NonAsciiIdentifierPart:
4646 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]/
4648 exports.Character = {
4649 fromCodePoint: function (cp) {
4650 return (cp < 0x10000) ? String.fromCharCode(cp) :
4651 String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) +
4652 String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023));
4654 // ECMA-262 11.2 White Space
4655 isWhiteSpace: function (cp) {
4656 return (cp === 0x20) || (cp === 0x09) || (cp === 0x0B) || (cp === 0x0C) || (cp === 0xA0) ||
4657 (cp >= 0x1680 && [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(cp) >= 0);
4659 // ECMA-262 11.3 Line Terminators
4660 isLineTerminator: function (cp) {
4661 return (cp === 0x0A) || (cp === 0x0D) || (cp === 0x2028) || (cp === 0x2029);
4663 // ECMA-262 11.6 Identifier Names and Identifiers
4664 isIdentifierStart: function (cp) {
4665 return (cp === 0x24) || (cp === 0x5F) ||
4666 (cp >= 0x41 && cp <= 0x5A) ||
4667 (cp >= 0x61 && cp <= 0x7A) ||
4669 ((cp >= 0x80) && Regex.NonAsciiIdentifierStart.test(exports.Character.fromCodePoint(cp)));
4671 isIdentifierPart: function (cp) {
4672 return (cp === 0x24) || (cp === 0x5F) ||
4673 (cp >= 0x41 && cp <= 0x5A) ||
4674 (cp >= 0x61 && cp <= 0x7A) ||
4675 (cp >= 0x30 && cp <= 0x39) ||
4677 ((cp >= 0x80) && Regex.NonAsciiIdentifierPart.test(exports.Character.fromCodePoint(cp)));
4679 // ECMA-262 11.8.3 Numeric Literals
4680 isDecimalDigit: function (cp) {
4681 return (cp >= 0x30 && cp <= 0x39); // 0..9
4683 isHexDigit: function (cp) {
4684 return (cp >= 0x30 && cp <= 0x39) ||
4685 (cp >= 0x41 && cp <= 0x46) ||
4686 (cp >= 0x61 && cp <= 0x66); // a..f
4688 isOctalDigit: function (cp) {
4689 return (cp >= 0x30 && cp <= 0x37); // 0..7
4696 /***/ function(module, exports, __webpack_require__) {
4699 var syntax_1 = __webpack_require__(2);
4700 var ArrayExpression = (function () {
4701 function ArrayExpression(elements) {
4702 this.type = syntax_1.Syntax.ArrayExpression;
4703 this.elements = elements;
4705 return ArrayExpression;
4707 exports.ArrayExpression = ArrayExpression;
4708 var ArrayPattern = (function () {
4709 function ArrayPattern(elements) {
4710 this.type = syntax_1.Syntax.ArrayPattern;
4711 this.elements = elements;
4713 return ArrayPattern;
4715 exports.ArrayPattern = ArrayPattern;
4716 var ArrowFunctionExpression = (function () {
4717 function ArrowFunctionExpression(params, body, expression) {
4718 this.type = syntax_1.Syntax.ArrowFunctionExpression;
4720 this.params = params;
4722 this.generator = false;
4723 this.expression = expression;
4725 return ArrowFunctionExpression;
4727 exports.ArrowFunctionExpression = ArrowFunctionExpression;
4728 var AssignmentExpression = (function () {
4729 function AssignmentExpression(operator, left, right) {
4730 this.type = syntax_1.Syntax.AssignmentExpression;
4731 this.operator = operator;
4735 return AssignmentExpression;
4737 exports.AssignmentExpression = AssignmentExpression;
4738 var AssignmentPattern = (function () {
4739 function AssignmentPattern(left, right) {
4740 this.type = syntax_1.Syntax.AssignmentPattern;
4744 return AssignmentPattern;
4746 exports.AssignmentPattern = AssignmentPattern;
4747 var BinaryExpression = (function () {
4748 function BinaryExpression(operator, left, right) {
4749 var logical = (operator === '||' || operator === '&&');
4750 this.type = logical ? syntax_1.Syntax.LogicalExpression : syntax_1.Syntax.BinaryExpression;
4751 this.operator = operator;
4755 return BinaryExpression;
4757 exports.BinaryExpression = BinaryExpression;
4758 var BlockStatement = (function () {
4759 function BlockStatement(body) {
4760 this.type = syntax_1.Syntax.BlockStatement;
4763 return BlockStatement;
4765 exports.BlockStatement = BlockStatement;
4766 var BreakStatement = (function () {
4767 function BreakStatement(label) {
4768 this.type = syntax_1.Syntax.BreakStatement;
4771 return BreakStatement;
4773 exports.BreakStatement = BreakStatement;
4774 var CallExpression = (function () {
4775 function CallExpression(callee, args) {
4776 this.type = syntax_1.Syntax.CallExpression;
4777 this.callee = callee;
4778 this.arguments = args;
4780 return CallExpression;
4782 exports.CallExpression = CallExpression;
4783 var CatchClause = (function () {
4784 function CatchClause(param, body) {
4785 this.type = syntax_1.Syntax.CatchClause;
4791 exports.CatchClause = CatchClause;
4792 var ClassBody = (function () {
4793 function ClassBody(body) {
4794 this.type = syntax_1.Syntax.ClassBody;
4799 exports.ClassBody = ClassBody;
4800 var ClassDeclaration = (function () {
4801 function ClassDeclaration(id, superClass, body) {
4802 this.type = syntax_1.Syntax.ClassDeclaration;
4804 this.superClass = superClass;
4807 return ClassDeclaration;
4809 exports.ClassDeclaration = ClassDeclaration;
4810 var ClassExpression = (function () {
4811 function ClassExpression(id, superClass, body) {
4812 this.type = syntax_1.Syntax.ClassExpression;
4814 this.superClass = superClass;
4817 return ClassExpression;
4819 exports.ClassExpression = ClassExpression;
4820 var ComputedMemberExpression = (function () {
4821 function ComputedMemberExpression(object, property) {
4822 this.type = syntax_1.Syntax.MemberExpression;
4823 this.computed = true;
4824 this.object = object;
4825 this.property = property;
4827 return ComputedMemberExpression;
4829 exports.ComputedMemberExpression = ComputedMemberExpression;
4830 var ConditionalExpression = (function () {
4831 function ConditionalExpression(test, consequent, alternate) {
4832 this.type = syntax_1.Syntax.ConditionalExpression;
4834 this.consequent = consequent;
4835 this.alternate = alternate;
4837 return ConditionalExpression;
4839 exports.ConditionalExpression = ConditionalExpression;
4840 var ContinueStatement = (function () {
4841 function ContinueStatement(label) {
4842 this.type = syntax_1.Syntax.ContinueStatement;
4845 return ContinueStatement;
4847 exports.ContinueStatement = ContinueStatement;
4848 var DebuggerStatement = (function () {
4849 function DebuggerStatement() {
4850 this.type = syntax_1.Syntax.DebuggerStatement;
4852 return DebuggerStatement;
4854 exports.DebuggerStatement = DebuggerStatement;
4855 var Directive = (function () {
4856 function Directive(expression, directive) {
4857 this.type = syntax_1.Syntax.ExpressionStatement;
4858 this.expression = expression;
4859 this.directive = directive;
4863 exports.Directive = Directive;
4864 var DoWhileStatement = (function () {
4865 function DoWhileStatement(body, test) {
4866 this.type = syntax_1.Syntax.DoWhileStatement;
4870 return DoWhileStatement;
4872 exports.DoWhileStatement = DoWhileStatement;
4873 var EmptyStatement = (function () {
4874 function EmptyStatement() {
4875 this.type = syntax_1.Syntax.EmptyStatement;
4877 return EmptyStatement;
4879 exports.EmptyStatement = EmptyStatement;
4880 var ExportAllDeclaration = (function () {
4881 function ExportAllDeclaration(source) {
4882 this.type = syntax_1.Syntax.ExportAllDeclaration;
4883 this.source = source;
4885 return ExportAllDeclaration;
4887 exports.ExportAllDeclaration = ExportAllDeclaration;
4888 var ExportDefaultDeclaration = (function () {
4889 function ExportDefaultDeclaration(declaration) {
4890 this.type = syntax_1.Syntax.ExportDefaultDeclaration;
4891 this.declaration = declaration;
4893 return ExportDefaultDeclaration;
4895 exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
4896 var ExportNamedDeclaration = (function () {
4897 function ExportNamedDeclaration(declaration, specifiers, source) {
4898 this.type = syntax_1.Syntax.ExportNamedDeclaration;
4899 this.declaration = declaration;
4900 this.specifiers = specifiers;
4901 this.source = source;
4903 return ExportNamedDeclaration;
4905 exports.ExportNamedDeclaration = ExportNamedDeclaration;
4906 var ExportSpecifier = (function () {
4907 function ExportSpecifier(local, exported) {
4908 this.type = syntax_1.Syntax.ExportSpecifier;
4909 this.exported = exported;
4912 return ExportSpecifier;
4914 exports.ExportSpecifier = ExportSpecifier;
4915 var ExpressionStatement = (function () {
4916 function ExpressionStatement(expression) {
4917 this.type = syntax_1.Syntax.ExpressionStatement;
4918 this.expression = expression;
4920 return ExpressionStatement;
4922 exports.ExpressionStatement = ExpressionStatement;
4923 var ForInStatement = (function () {
4924 function ForInStatement(left, right, body) {
4925 this.type = syntax_1.Syntax.ForInStatement;
4931 return ForInStatement;
4933 exports.ForInStatement = ForInStatement;
4934 var ForOfStatement = (function () {
4935 function ForOfStatement(left, right, body) {
4936 this.type = syntax_1.Syntax.ForOfStatement;
4941 return ForOfStatement;
4943 exports.ForOfStatement = ForOfStatement;
4944 var ForStatement = (function () {
4945 function ForStatement(init, test, update, body) {
4946 this.type = syntax_1.Syntax.ForStatement;
4949 this.update = update;
4952 return ForStatement;
4954 exports.ForStatement = ForStatement;
4955 var FunctionDeclaration = (function () {
4956 function FunctionDeclaration(id, params, body, generator) {
4957 this.type = syntax_1.Syntax.FunctionDeclaration;
4959 this.params = params;
4961 this.generator = generator;
4962 this.expression = false;
4964 return FunctionDeclaration;
4966 exports.FunctionDeclaration = FunctionDeclaration;
4967 var FunctionExpression = (function () {
4968 function FunctionExpression(id, params, body, generator) {
4969 this.type = syntax_1.Syntax.FunctionExpression;
4971 this.params = params;
4973 this.generator = generator;
4974 this.expression = false;
4976 return FunctionExpression;
4978 exports.FunctionExpression = FunctionExpression;
4979 var Identifier = (function () {
4980 function Identifier(name) {
4981 this.type = syntax_1.Syntax.Identifier;
4986 exports.Identifier = Identifier;
4987 var IfStatement = (function () {
4988 function IfStatement(test, consequent, alternate) {
4989 this.type = syntax_1.Syntax.IfStatement;
4991 this.consequent = consequent;
4992 this.alternate = alternate;
4996 exports.IfStatement = IfStatement;
4997 var ImportDeclaration = (function () {
4998 function ImportDeclaration(specifiers, source) {
4999 this.type = syntax_1.Syntax.ImportDeclaration;
5000 this.specifiers = specifiers;
5001 this.source = source;
5003 return ImportDeclaration;
5005 exports.ImportDeclaration = ImportDeclaration;
5006 var ImportDefaultSpecifier = (function () {
5007 function ImportDefaultSpecifier(local) {
5008 this.type = syntax_1.Syntax.ImportDefaultSpecifier;
5011 return ImportDefaultSpecifier;
5013 exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
5014 var ImportNamespaceSpecifier = (function () {
5015 function ImportNamespaceSpecifier(local) {
5016 this.type = syntax_1.Syntax.ImportNamespaceSpecifier;
5019 return ImportNamespaceSpecifier;
5021 exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
5022 var ImportSpecifier = (function () {
5023 function ImportSpecifier(local, imported) {
5024 this.type = syntax_1.Syntax.ImportSpecifier;
5026 this.imported = imported;
5028 return ImportSpecifier;
5030 exports.ImportSpecifier = ImportSpecifier;
5031 var LabeledStatement = (function () {
5032 function LabeledStatement(label, body) {
5033 this.type = syntax_1.Syntax.LabeledStatement;
5037 return LabeledStatement;
5039 exports.LabeledStatement = LabeledStatement;
5040 var Literal = (function () {
5041 function Literal(value, raw) {
5042 this.type = syntax_1.Syntax.Literal;
5048 exports.Literal = Literal;
5049 var MetaProperty = (function () {
5050 function MetaProperty(meta, property) {
5051 this.type = syntax_1.Syntax.MetaProperty;
5053 this.property = property;
5055 return MetaProperty;
5057 exports.MetaProperty = MetaProperty;
5058 var MethodDefinition = (function () {
5059 function MethodDefinition(key, computed, value, kind, isStatic) {
5060 this.type = syntax_1.Syntax.MethodDefinition;
5062 this.computed = computed;
5065 this.static = isStatic;
5067 return MethodDefinition;
5069 exports.MethodDefinition = MethodDefinition;
5070 var NewExpression = (function () {
5071 function NewExpression(callee, args) {
5072 this.type = syntax_1.Syntax.NewExpression;
5073 this.callee = callee;
5074 this.arguments = args;
5076 return NewExpression;
5078 exports.NewExpression = NewExpression;
5079 var ObjectExpression = (function () {
5080 function ObjectExpression(properties) {
5081 this.type = syntax_1.Syntax.ObjectExpression;
5082 this.properties = properties;
5084 return ObjectExpression;
5086 exports.ObjectExpression = ObjectExpression;
5087 var ObjectPattern = (function () {
5088 function ObjectPattern(properties) {
5089 this.type = syntax_1.Syntax.ObjectPattern;
5090 this.properties = properties;
5092 return ObjectPattern;
5094 exports.ObjectPattern = ObjectPattern;
5095 var Program = (function () {
5096 function Program(body, sourceType) {
5097 this.type = syntax_1.Syntax.Program;
5099 this.sourceType = sourceType;
5103 exports.Program = Program;
5104 var Property = (function () {
5105 function Property(kind, key, computed, value, method, shorthand) {
5106 this.type = syntax_1.Syntax.Property;
5108 this.computed = computed;
5111 this.method = method;
5112 this.shorthand = shorthand;
5116 exports.Property = Property;
5117 var RegexLiteral = (function () {
5118 function RegexLiteral(value, raw, regex) {
5119 this.type = syntax_1.Syntax.Literal;
5124 return RegexLiteral;
5126 exports.RegexLiteral = RegexLiteral;
5127 var RestElement = (function () {
5128 function RestElement(argument) {
5129 this.type = syntax_1.Syntax.RestElement;
5130 this.argument = argument;
5134 exports.RestElement = RestElement;
5135 var ReturnStatement = (function () {
5136 function ReturnStatement(argument) {
5137 this.type = syntax_1.Syntax.ReturnStatement;
5138 this.argument = argument;
5140 return ReturnStatement;
5142 exports.ReturnStatement = ReturnStatement;
5143 var SequenceExpression = (function () {
5144 function SequenceExpression(expressions) {
5145 this.type = syntax_1.Syntax.SequenceExpression;
5146 this.expressions = expressions;
5148 return SequenceExpression;
5150 exports.SequenceExpression = SequenceExpression;
5151 var SpreadElement = (function () {
5152 function SpreadElement(argument) {
5153 this.type = syntax_1.Syntax.SpreadElement;
5154 this.argument = argument;
5156 return SpreadElement;
5158 exports.SpreadElement = SpreadElement;
5159 var StaticMemberExpression = (function () {
5160 function StaticMemberExpression(object, property) {
5161 this.type = syntax_1.Syntax.MemberExpression;
5162 this.computed = false;
5163 this.object = object;
5164 this.property = property;
5166 return StaticMemberExpression;
5168 exports.StaticMemberExpression = StaticMemberExpression;
5169 var Super = (function () {
5171 this.type = syntax_1.Syntax.Super;
5175 exports.Super = Super;
5176 var SwitchCase = (function () {
5177 function SwitchCase(test, consequent) {
5178 this.type = syntax_1.Syntax.SwitchCase;
5180 this.consequent = consequent;
5184 exports.SwitchCase = SwitchCase;
5185 var SwitchStatement = (function () {
5186 function SwitchStatement(discriminant, cases) {
5187 this.type = syntax_1.Syntax.SwitchStatement;
5188 this.discriminant = discriminant;
5191 return SwitchStatement;
5193 exports.SwitchStatement = SwitchStatement;
5194 var TaggedTemplateExpression = (function () {
5195 function TaggedTemplateExpression(tag, quasi) {
5196 this.type = syntax_1.Syntax.TaggedTemplateExpression;
5200 return TaggedTemplateExpression;
5202 exports.TaggedTemplateExpression = TaggedTemplateExpression;
5203 var TemplateElement = (function () {
5204 function TemplateElement(value, tail) {
5205 this.type = syntax_1.Syntax.TemplateElement;
5209 return TemplateElement;
5211 exports.TemplateElement = TemplateElement;
5212 var TemplateLiteral = (function () {
5213 function TemplateLiteral(quasis, expressions) {
5214 this.type = syntax_1.Syntax.TemplateLiteral;
5215 this.quasis = quasis;
5216 this.expressions = expressions;
5218 return TemplateLiteral;
5220 exports.TemplateLiteral = TemplateLiteral;
5221 var ThisExpression = (function () {
5222 function ThisExpression() {
5223 this.type = syntax_1.Syntax.ThisExpression;
5225 return ThisExpression;
5227 exports.ThisExpression = ThisExpression;
5228 var ThrowStatement = (function () {
5229 function ThrowStatement(argument) {
5230 this.type = syntax_1.Syntax.ThrowStatement;
5231 this.argument = argument;
5233 return ThrowStatement;
5235 exports.ThrowStatement = ThrowStatement;
5236 var TryStatement = (function () {
5237 function TryStatement(block, handler, finalizer) {
5238 this.type = syntax_1.Syntax.TryStatement;
5240 this.handler = handler;
5241 this.finalizer = finalizer;
5243 return TryStatement;
5245 exports.TryStatement = TryStatement;
5246 var UnaryExpression = (function () {
5247 function UnaryExpression(operator, argument) {
5248 this.type = syntax_1.Syntax.UnaryExpression;
5249 this.operator = operator;
5250 this.argument = argument;
5253 return UnaryExpression;
5255 exports.UnaryExpression = UnaryExpression;
5256 var UpdateExpression = (function () {
5257 function UpdateExpression(operator, argument, prefix) {
5258 this.type = syntax_1.Syntax.UpdateExpression;
5259 this.operator = operator;
5260 this.argument = argument;
5261 this.prefix = prefix;
5263 return UpdateExpression;
5265 exports.UpdateExpression = UpdateExpression;
5266 var VariableDeclaration = (function () {
5267 function VariableDeclaration(declarations, kind) {
5268 this.type = syntax_1.Syntax.VariableDeclaration;
5269 this.declarations = declarations;
5272 return VariableDeclaration;
5274 exports.VariableDeclaration = VariableDeclaration;
5275 var VariableDeclarator = (function () {
5276 function VariableDeclarator(id, init) {
5277 this.type = syntax_1.Syntax.VariableDeclarator;
5281 return VariableDeclarator;
5283 exports.VariableDeclarator = VariableDeclarator;
5284 var WhileStatement = (function () {
5285 function WhileStatement(test, body) {
5286 this.type = syntax_1.Syntax.WhileStatement;
5290 return WhileStatement;
5292 exports.WhileStatement = WhileStatement;
5293 var WithStatement = (function () {
5294 function WithStatement(object, body) {
5295 this.type = syntax_1.Syntax.WithStatement;
5296 this.object = object;
5299 return WithStatement;
5301 exports.WithStatement = WithStatement;
5302 var YieldExpression = (function () {
5303 function YieldExpression(argument, delegate) {
5304 this.type = syntax_1.Syntax.YieldExpression;
5305 this.argument = argument;
5306 this.delegate = delegate;
5308 return YieldExpression;
5310 exports.YieldExpression = YieldExpression;
5315 /***/ function(module, exports, __webpack_require__) {
5318 /* istanbul ignore next */
5319 var __extends = (this && this.__extends) || function (d, b) {
5320 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
5321 function __() { this.constructor = d; }
5322 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5324 var character_1 = __webpack_require__(9);
5325 var token_1 = __webpack_require__(7);
5326 var parser_1 = __webpack_require__(3);
5327 var xhtml_entities_1 = __webpack_require__(12);
5328 var jsx_syntax_1 = __webpack_require__(13);
5329 var Node = __webpack_require__(10);
5330 var JSXNode = __webpack_require__(14);
5332 (function (JSXToken) {
5333 JSXToken[JSXToken["Identifier"] = 100] = "Identifier";
5334 JSXToken[JSXToken["Text"] = 101] = "Text";
5335 })(JSXToken || (JSXToken = {}));
5336 token_1.TokenName[JSXToken.Identifier] = 'JSXIdentifier';
5337 token_1.TokenName[JSXToken.Text] = 'JSXText';
5338 // Fully qualified element name, e.g. <svg:path> returns "svg:path"
5339 function getQualifiedElementName(elementName) {
5341 switch (elementName.type) {
5342 case jsx_syntax_1.JSXSyntax.JSXIdentifier:
5343 var id = (elementName);
5344 qualifiedName = id.name;
5346 case jsx_syntax_1.JSXSyntax.JSXNamespacedName:
5347 var ns = (elementName);
5348 qualifiedName = getQualifiedElementName(ns.namespace) + ':' +
5349 getQualifiedElementName(ns.name);
5351 case jsx_syntax_1.JSXSyntax.JSXMemberExpression:
5352 var expr = (elementName);
5353 qualifiedName = getQualifiedElementName(expr.object) + '.' +
5354 getQualifiedElementName(expr.property);
5357 return qualifiedName;
5359 var JSXParser = (function (_super) {
5360 __extends(JSXParser, _super);
5361 function JSXParser(code, options, delegate) {
5362 _super.call(this, code, options, delegate);
5364 JSXParser.prototype.parsePrimaryExpression = function () {
5365 return this.match('<') ? this.parseJSXRoot() : _super.prototype.parsePrimaryExpression.call(this);
5367 JSXParser.prototype.startJSX = function () {
5368 // Unwind the scanner before the lookahead token.
5369 this.scanner.index = this.startMarker.index;
5370 this.scanner.lineNumber = this.startMarker.lineNumber;
5371 this.scanner.lineStart = this.startMarker.lineStart;
5373 JSXParser.prototype.finishJSX = function () {
5374 // Prime the next lookahead.
5377 JSXParser.prototype.reenterJSX = function () {
5379 this.expectJSX('}');
5380 // Pop the closing '}' added from the lookahead.
5381 if (this.config.tokens) {
5385 JSXParser.prototype.createJSXNode = function () {
5386 this.collectComments();
5388 index: this.scanner.index,
5389 line: this.scanner.lineNumber,
5390 column: this.scanner.index - this.scanner.lineStart
5393 JSXParser.prototype.createJSXChildNode = function () {
5395 index: this.scanner.index,
5396 line: this.scanner.lineNumber,
5397 column: this.scanner.index - this.scanner.lineStart
5400 JSXParser.prototype.scanXHTMLEntity = function (quote) {
5403 var terminated = false;
5404 var numeric = false;
5406 while (!this.scanner.eof() && valid && !terminated) {
5407 var ch = this.scanner.source[this.scanner.index];
5411 terminated = (ch === ';');
5413 ++this.scanner.index;
5415 switch (result.length) {
5418 numeric = (ch === '#');
5424 valid = hex || character_1.Character.isDecimalDigit(ch.charCodeAt(0));
5425 numeric = numeric && !hex;
5429 valid = valid && !(numeric && !character_1.Character.isDecimalDigit(ch.charCodeAt(0)));
5430 valid = valid && !(hex && !character_1.Character.isHexDigit(ch.charCodeAt(0)));
5435 if (valid && terminated && result.length > 2) {
5436 // e.g. 'A' becomes just '#x41'
5437 var str = result.substr(1, result.length - 2);
5438 if (numeric && str.length > 1) {
5439 result = String.fromCharCode(parseInt(str.substr(1), 10));
5441 else if (hex && str.length > 2) {
5442 result = String.fromCharCode(parseInt('0' + str.substr(1), 16));
5444 else if (!numeric && !hex && xhtml_entities_1.XHTMLEntities[str]) {
5445 result = xhtml_entities_1.XHTMLEntities[str];
5450 // Scan the next JSX token. This replaces Scanner#lex when in JSX mode.
5451 JSXParser.prototype.lexJSX = function () {
5452 var cp = this.scanner.source.charCodeAt(this.scanner.index);
5454 if (cp === 60 || cp === 62 || cp === 47 || cp === 58 || cp === 61 || cp === 123 || cp === 125) {
5455 var value = this.scanner.source[this.scanner.index++];
5457 type: token_1.Token.Punctuator,
5459 lineNumber: this.scanner.lineNumber,
5460 lineStart: this.scanner.lineStart,
5461 start: this.scanner.index - 1,
5462 end: this.scanner.index
5466 if (cp === 34 || cp === 39) {
5467 var start = this.scanner.index;
5468 var quote = this.scanner.source[this.scanner.index++];
5470 while (!this.scanner.eof()) {
5471 var ch = this.scanner.source[this.scanner.index++];
5475 else if (ch === '&') {
5476 str += this.scanXHTMLEntity(quote);
5483 type: token_1.Token.StringLiteral,
5485 lineNumber: this.scanner.lineNumber,
5486 lineStart: this.scanner.lineStart,
5488 end: this.scanner.index
5493 var n1 = this.scanner.source.charCodeAt(this.scanner.index + 1);
5494 var n2 = this.scanner.source.charCodeAt(this.scanner.index + 2);
5495 var value = (n1 === 46 && n2 === 46) ? '...' : '.';
5496 var start = this.scanner.index;
5497 this.scanner.index += value.length;
5499 type: token_1.Token.Punctuator,
5501 lineNumber: this.scanner.lineNumber,
5502 lineStart: this.scanner.lineStart,
5504 end: this.scanner.index
5509 // Only placeholder, since it will be rescanned as a real assignment expression.
5511 type: token_1.Token.Template,
5512 lineNumber: this.scanner.lineNumber,
5513 lineStart: this.scanner.lineStart,
5514 start: this.scanner.index,
5515 end: this.scanner.index
5518 // Identifer can not contain backslash (char code 92).
5519 if (character_1.Character.isIdentifierStart(cp) && (cp !== 92)) {
5520 var start = this.scanner.index;
5521 ++this.scanner.index;
5522 while (!this.scanner.eof()) {
5523 var ch = this.scanner.source.charCodeAt(this.scanner.index);
5524 if (character_1.Character.isIdentifierPart(ch) && (ch !== 92)) {
5525 ++this.scanner.index;
5527 else if (ch === 45) {
5528 // Hyphen (char code 45) can be part of an identifier.
5529 ++this.scanner.index;
5535 var id = this.scanner.source.slice(start, this.scanner.index);
5537 type: JSXToken.Identifier,
5539 lineNumber: this.scanner.lineNumber,
5540 lineStart: this.scanner.lineStart,
5542 end: this.scanner.index
5545 this.scanner.throwUnexpectedToken();
5547 JSXParser.prototype.nextJSXToken = function () {
5548 this.collectComments();
5549 this.startMarker.index = this.scanner.index;
5550 this.startMarker.lineNumber = this.scanner.lineNumber;
5551 this.startMarker.lineStart = this.scanner.lineStart;
5552 var token = this.lexJSX();
5553 this.lastMarker.index = this.scanner.index;
5554 this.lastMarker.lineNumber = this.scanner.lineNumber;
5555 this.lastMarker.lineStart = this.scanner.lineStart;
5556 if (this.config.tokens) {
5557 this.tokens.push(this.convertToken(token));
5561 JSXParser.prototype.nextJSXText = function () {
5562 this.startMarker.index = this.scanner.index;
5563 this.startMarker.lineNumber = this.scanner.lineNumber;
5564 this.startMarker.lineStart = this.scanner.lineStart;
5565 var start = this.scanner.index;
5567 while (!this.scanner.eof()) {
5568 var ch = this.scanner.source[this.scanner.index];
5569 if (ch === '{' || ch === '<') {
5572 ++this.scanner.index;
5574 if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
5575 ++this.scanner.lineNumber;
5576 if (ch === '\r' && this.scanner.source[this.scanner.index] === '\n') {
5577 ++this.scanner.index;
5579 this.scanner.lineStart = this.scanner.index;
5582 this.lastMarker.index = this.scanner.index;
5583 this.lastMarker.lineNumber = this.scanner.lineNumber;
5584 this.lastMarker.lineStart = this.scanner.lineStart;
5586 type: JSXToken.Text,
5588 lineNumber: this.scanner.lineNumber,
5589 lineStart: this.scanner.lineStart,
5591 end: this.scanner.index
5593 if ((text.length > 0) && this.config.tokens) {
5594 this.tokens.push(this.convertToken(token));
5598 JSXParser.prototype.peekJSXToken = function () {
5599 var previousIndex = this.scanner.index;
5600 var previousLineNumber = this.scanner.lineNumber;
5601 var previousLineStart = this.scanner.lineStart;
5602 this.scanner.scanComments();
5603 var next = this.lexJSX();
5604 this.scanner.index = previousIndex;
5605 this.scanner.lineNumber = previousLineNumber;
5606 this.scanner.lineStart = previousLineStart;
5609 // Expect the next JSX token to match the specified punctuator.
5610 // If not, an exception will be thrown.
5611 JSXParser.prototype.expectJSX = function (value) {
5612 var token = this.nextJSXToken();
5613 if (token.type !== token_1.Token.Punctuator || token.value !== value) {
5614 this.throwUnexpectedToken(token);
5617 // Return true if the next JSX token matches the specified punctuator.
5618 JSXParser.prototype.matchJSX = function (value) {
5619 var next = this.peekJSXToken();
5620 return next.type === token_1.Token.Punctuator && next.value === value;
5622 JSXParser.prototype.parseJSXIdentifier = function () {
5623 var node = this.createJSXNode();
5624 var token = this.nextJSXToken();
5625 if (token.type !== JSXToken.Identifier) {
5626 this.throwUnexpectedToken(token);
5628 return this.finalize(node, new JSXNode.JSXIdentifier(token.value));
5630 JSXParser.prototype.parseJSXElementName = function () {
5631 var node = this.createJSXNode();
5632 var elementName = this.parseJSXIdentifier();
5633 if (this.matchJSX(':')) {
5634 var namespace = elementName;
5635 this.expectJSX(':');
5636 var name_1 = this.parseJSXIdentifier();
5637 elementName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_1));
5639 else if (this.matchJSX('.')) {
5640 while (this.matchJSX('.')) {
5641 var object = elementName;
5642 this.expectJSX('.');
5643 var property = this.parseJSXIdentifier();
5644 elementName = this.finalize(node, new JSXNode.JSXMemberExpression(object, property));
5649 JSXParser.prototype.parseJSXAttributeName = function () {
5650 var node = this.createJSXNode();
5652 var identifier = this.parseJSXIdentifier();
5653 if (this.matchJSX(':')) {
5654 var namespace = identifier;
5655 this.expectJSX(':');
5656 var name_2 = this.parseJSXIdentifier();
5657 attributeName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_2));
5660 attributeName = identifier;
5662 return attributeName;
5664 JSXParser.prototype.parseJSXStringLiteralAttribute = function () {
5665 var node = this.createJSXNode();
5666 var token = this.nextJSXToken();
5667 if (token.type !== token_1.Token.StringLiteral) {
5668 this.throwUnexpectedToken(token);
5670 var raw = this.getTokenRaw(token);
5671 return this.finalize(node, new Node.Literal(token.value, raw));
5673 JSXParser.prototype.parseJSXExpressionAttribute = function () {
5674 var node = this.createJSXNode();
5675 this.expectJSX('{');
5677 if (this.match('}')) {
5678 this.tolerateError('JSX attributes must only be assigned a non-empty expression');
5680 var expression = this.parseAssignmentExpression();
5682 return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
5684 JSXParser.prototype.parseJSXAttributeValue = function () {
5685 return this.matchJSX('{') ? this.parseJSXExpressionAttribute() :
5686 this.matchJSX('<') ? this.parseJSXElement() : this.parseJSXStringLiteralAttribute();
5688 JSXParser.prototype.parseJSXNameValueAttribute = function () {
5689 var node = this.createJSXNode();
5690 var name = this.parseJSXAttributeName();
5692 if (this.matchJSX('=')) {
5693 this.expectJSX('=');
5694 value = this.parseJSXAttributeValue();
5696 return this.finalize(node, new JSXNode.JSXAttribute(name, value));
5698 JSXParser.prototype.parseJSXSpreadAttribute = function () {
5699 var node = this.createJSXNode();
5700 this.expectJSX('{');
5701 this.expectJSX('...');
5703 var argument = this.parseAssignmentExpression();
5705 return this.finalize(node, new JSXNode.JSXSpreadAttribute(argument));
5707 JSXParser.prototype.parseJSXAttributes = function () {
5708 var attributes = [];
5709 while (!this.matchJSX('/') && !this.matchJSX('>')) {
5710 var attribute = this.matchJSX('{') ? this.parseJSXSpreadAttribute() :
5711 this.parseJSXNameValueAttribute();
5712 attributes.push(attribute);
5716 JSXParser.prototype.parseJSXOpeningElement = function () {
5717 var node = this.createJSXNode();
5718 this.expectJSX('<');
5719 var name = this.parseJSXElementName();
5720 var attributes = this.parseJSXAttributes();
5721 var selfClosing = this.matchJSX('/');
5723 this.expectJSX('/');
5725 this.expectJSX('>');
5726 return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
5728 JSXParser.prototype.parseJSXBoundaryElement = function () {
5729 var node = this.createJSXNode();
5730 this.expectJSX('<');
5731 if (this.matchJSX('/')) {
5732 this.expectJSX('/');
5733 var name_3 = this.parseJSXElementName();
5734 this.expectJSX('>');
5735 return this.finalize(node, new JSXNode.JSXClosingElement(name_3));
5737 var name = this.parseJSXElementName();
5738 var attributes = this.parseJSXAttributes();
5739 var selfClosing = this.matchJSX('/');
5741 this.expectJSX('/');
5743 this.expectJSX('>');
5744 return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
5746 JSXParser.prototype.parseJSXEmptyExpression = function () {
5747 var node = this.createJSXChildNode();
5748 this.collectComments();
5749 this.lastMarker.index = this.scanner.index;
5750 this.lastMarker.lineNumber = this.scanner.lineNumber;
5751 this.lastMarker.lineStart = this.scanner.lineStart;
5752 return this.finalize(node, new JSXNode.JSXEmptyExpression());
5754 JSXParser.prototype.parseJSXExpressionContainer = function () {
5755 var node = this.createJSXNode();
5756 this.expectJSX('{');
5758 if (this.matchJSX('}')) {
5759 expression = this.parseJSXEmptyExpression();
5760 this.expectJSX('}');
5764 expression = this.parseAssignmentExpression();
5767 return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
5769 JSXParser.prototype.parseJSXChildren = function () {
5771 while (!this.scanner.eof()) {
5772 var node = this.createJSXChildNode();
5773 var token = this.nextJSXText();
5774 if (token.start < token.end) {
5775 var raw = this.getTokenRaw(token);
5776 var child = this.finalize(node, new JSXNode.JSXText(token.value, raw));
5777 children.push(child);
5779 if (this.scanner.source[this.scanner.index] === '{') {
5780 var container = this.parseJSXExpressionContainer();
5781 children.push(container);
5789 JSXParser.prototype.parseComplexJSXElement = function (el) {
5791 while (!this.scanner.eof()) {
5792 el.children = el.children.concat(this.parseJSXChildren());
5793 var node = this.createJSXChildNode();
5794 var element = this.parseJSXBoundaryElement();
5795 if (element.type === jsx_syntax_1.JSXSyntax.JSXOpeningElement) {
5796 var opening = (element);
5797 if (opening.selfClosing) {
5798 var child = this.finalize(node, new JSXNode.JSXElement(opening, [], null));
5799 el.children.push(child);
5803 el = { node: node, opening: opening, closing: null, children: [] };
5806 if (element.type === jsx_syntax_1.JSXSyntax.JSXClosingElement) {
5807 el.closing = (element);
5808 var open_1 = getQualifiedElementName(el.opening.name);
5809 var close_1 = getQualifiedElementName(el.closing.name);
5810 if (open_1 !== close_1) {
5811 this.tolerateError('Expected corresponding JSX closing tag for %0', open_1);
5813 if (stack.length > 0) {
5814 var child = this.finalize(el.node, new JSXNode.JSXElement(el.opening, el.children, el.closing));
5816 el.children.push(child);
5825 JSXParser.prototype.parseJSXElement = function () {
5826 var node = this.createJSXNode();
5827 var opening = this.parseJSXOpeningElement();
5830 if (!opening.selfClosing) {
5831 var el = this.parseComplexJSXElement({ node: node, opening: opening, closing: closing, children: children });
5832 children = el.children;
5833 closing = el.closing;
5835 return this.finalize(node, new JSXNode.JSXElement(opening, children, closing));
5837 JSXParser.prototype.parseJSXRoot = function () {
5838 // Pop the opening '<' added from the lookahead.
5839 if (this.config.tokens) {
5843 var element = this.parseJSXElement();
5848 }(parser_1.Parser));
5849 exports.JSXParser = JSXParser;
5854 /***/ function(module, exports) {
5856 // Generated by generate-xhtml-entities.js. DO NOT MODIFY!
5858 exports.XHTMLEntities = {
6116 /***/ function(module, exports) {
6119 exports.JSXSyntax = {
6120 JSXAttribute: 'JSXAttribute',
6121 JSXClosingElement: 'JSXClosingElement',
6122 JSXElement: 'JSXElement',
6123 JSXEmptyExpression: 'JSXEmptyExpression',
6124 JSXExpressionContainer: 'JSXExpressionContainer',
6125 JSXIdentifier: 'JSXIdentifier',
6126 JSXMemberExpression: 'JSXMemberExpression',
6127 JSXNamespacedName: 'JSXNamespacedName',
6128 JSXOpeningElement: 'JSXOpeningElement',
6129 JSXSpreadAttribute: 'JSXSpreadAttribute',
6136 /***/ function(module, exports, __webpack_require__) {
6139 var jsx_syntax_1 = __webpack_require__(13);
6140 var JSXClosingElement = (function () {
6141 function JSXClosingElement(name) {
6142 this.type = jsx_syntax_1.JSXSyntax.JSXClosingElement;
6145 return JSXClosingElement;
6147 exports.JSXClosingElement = JSXClosingElement;
6148 var JSXElement = (function () {
6149 function JSXElement(openingElement, children, closingElement) {
6150 this.type = jsx_syntax_1.JSXSyntax.JSXElement;
6151 this.openingElement = openingElement;
6152 this.children = children;
6153 this.closingElement = closingElement;
6157 exports.JSXElement = JSXElement;
6158 var JSXEmptyExpression = (function () {
6159 function JSXEmptyExpression() {
6160 this.type = jsx_syntax_1.JSXSyntax.JSXEmptyExpression;
6162 return JSXEmptyExpression;
6164 exports.JSXEmptyExpression = JSXEmptyExpression;
6165 var JSXExpressionContainer = (function () {
6166 function JSXExpressionContainer(expression) {
6167 this.type = jsx_syntax_1.JSXSyntax.JSXExpressionContainer;
6168 this.expression = expression;
6170 return JSXExpressionContainer;
6172 exports.JSXExpressionContainer = JSXExpressionContainer;
6173 var JSXIdentifier = (function () {
6174 function JSXIdentifier(name) {
6175 this.type = jsx_syntax_1.JSXSyntax.JSXIdentifier;
6178 return JSXIdentifier;
6180 exports.JSXIdentifier = JSXIdentifier;
6181 var JSXMemberExpression = (function () {
6182 function JSXMemberExpression(object, property) {
6183 this.type = jsx_syntax_1.JSXSyntax.JSXMemberExpression;
6184 this.object = object;
6185 this.property = property;
6187 return JSXMemberExpression;
6189 exports.JSXMemberExpression = JSXMemberExpression;
6190 var JSXAttribute = (function () {
6191 function JSXAttribute(name, value) {
6192 this.type = jsx_syntax_1.JSXSyntax.JSXAttribute;
6196 return JSXAttribute;
6198 exports.JSXAttribute = JSXAttribute;
6199 var JSXNamespacedName = (function () {
6200 function JSXNamespacedName(namespace, name) {
6201 this.type = jsx_syntax_1.JSXSyntax.JSXNamespacedName;
6202 this.namespace = namespace;
6205 return JSXNamespacedName;
6207 exports.JSXNamespacedName = JSXNamespacedName;
6208 var JSXOpeningElement = (function () {
6209 function JSXOpeningElement(name, selfClosing, attributes) {
6210 this.type = jsx_syntax_1.JSXSyntax.JSXOpeningElement;
6212 this.selfClosing = selfClosing;
6213 this.attributes = attributes;
6215 return JSXOpeningElement;
6217 exports.JSXOpeningElement = JSXOpeningElement;
6218 var JSXSpreadAttribute = (function () {
6219 function JSXSpreadAttribute(argument) {
6220 this.type = jsx_syntax_1.JSXSyntax.JSXSpreadAttribute;
6221 this.argument = argument;
6223 return JSXSpreadAttribute;
6225 exports.JSXSpreadAttribute = JSXSpreadAttribute;
6226 var JSXText = (function () {
6227 function JSXText(value, raw) {
6228 this.type = jsx_syntax_1.JSXSyntax.JSXText;
6234 exports.JSXText = JSXText;
6239 /***/ function(module, exports, __webpack_require__) {
6242 var scanner_1 = __webpack_require__(8);
6243 var error_handler_1 = __webpack_require__(6);
6244 var token_1 = __webpack_require__(7);
6245 var Reader = (function () {
6248 this.curly = this.paren = -1;
6251 // A function following one of those tokens is an expression.
6252 Reader.prototype.beforeFunctionExpression = function (t) {
6253 return ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
6254 'return', 'case', 'delete', 'throw', 'void',
6255 // assignment operators
6256 '=', '+=', '-=', '*=', '**=', '/=', '%=', '<<=', '>>=', '>>>=',
6257 '&=', '|=', '^=', ',',
6258 // binary/unary operators
6259 '+', '-', '*', '**', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
6260 '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
6261 '<=', '<', '>', '!=', '!=='].indexOf(t) >= 0;
6264 // Determine if forward slash (/) is an operator or part of a regular expression
6265 // https://github.com/mozilla/sweet.js/wiki/design
6266 Reader.prototype.isRegexStart = function () {
6267 var previous = this.values[this.values.length - 1];
6268 var regex = (previous !== null);
6275 var check = this.values[this.paren - 1];
6276 regex = (check === 'if' || check === 'while' || check === 'for' || check === 'with');
6279 // Dividing a function by anything makes little sense,
6280 // but we have to check for that.
6282 if (this.values[this.curly - 3] === 'function') {
6283 // Anonymous function, e.g. function(){} /42
6284 var check_1 = this.values[this.curly - 4];
6285 regex = check_1 ? !this.beforeFunctionExpression(check_1) : false;
6287 else if (this.values[this.curly - 4] === 'function') {
6288 // Named function, e.g. function f(){} /42/
6289 var check_2 = this.values[this.curly - 5];
6290 regex = check_2 ? !this.beforeFunctionExpression(check_2) : true;
6296 Reader.prototype.push = function (token) {
6297 if (token.type === token_1.Token.Punctuator || token.type === token_1.Token.Keyword) {
6298 if (token.value === '{') {
6299 this.curly = this.values.length;
6301 else if (token.value === '(') {
6302 this.paren = this.values.length;
6304 this.values.push(token.value);
6307 this.values.push(null);
6313 var Tokenizer = (function () {
6314 function Tokenizer(code, config) {
6315 this.errorHandler = new error_handler_1.ErrorHandler();
6316 this.errorHandler.tolerant = config ? (typeof config.tolerant === 'boolean' && config.tolerant) : false;
6317 this.scanner = new scanner_1.Scanner(code, this.errorHandler);
6318 this.scanner.trackComment = config ? (typeof config.comment === 'boolean' && config.comment) : false;
6319 this.trackRange = config ? (typeof config.range === 'boolean' && config.range) : false;
6320 this.trackLoc = config ? (typeof config.loc === 'boolean' && config.loc) : false;
6322 this.reader = new Reader();
6325 Tokenizer.prototype.errors = function () {
6326 return this.errorHandler.errors;
6329 Tokenizer.prototype.getNextToken = function () {
6330 if (this.buffer.length === 0) {
6331 var comments = this.scanner.scanComments();
6332 if (this.scanner.trackComment) {
6333 for (var i = 0; i < comments.length; ++i) {
6334 var e = comments[i];
6335 var comment = void 0;
6336 var value = this.scanner.source.slice(e.slice[0], e.slice[1]);
6338 type: e.multiLine ? 'BlockComment' : 'LineComment',
6341 if (this.trackRange) {
6342 comment.range = e.range;
6344 if (this.trackLoc) {
6345 comment.loc = e.loc;
6347 this.buffer.push(comment);
6350 if (!this.scanner.eof()) {
6352 if (this.trackLoc) {
6355 line: this.scanner.lineNumber,
6356 column: this.scanner.index - this.scanner.lineStart
6362 if (this.scanner.source[this.scanner.index] === '/') {
6363 token = this.reader.isRegexStart() ? this.scanner.scanRegExp() : this.scanner.scanPunctuator();
6366 token = this.scanner.lex();
6368 this.reader.push(token);
6371 type: token_1.TokenName[token.type],
6372 value: this.scanner.source.slice(token.start, token.end)
6374 if (this.trackRange) {
6375 entry.range = [token.start, token.end];
6377 if (this.trackLoc) {
6379 line: this.scanner.lineNumber,
6380 column: this.scanner.index - this.scanner.lineStart
6385 entry.regex = token.regex;
6387 this.buffer.push(entry);
6390 return this.buffer.shift();
6395 exports.Tokenizer = Tokenizer;