react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / esprima / esprima.js
80699 views/*1Copyright (C) 2013 Ariya Hidayat <[email protected]>2Copyright (C) 2013 Thaddee Tyl <[email protected]>3Copyright (C) 2013 Mathias Bynens <[email protected]>4Copyright (C) 2012 Ariya Hidayat <[email protected]>5Copyright (C) 2012 Mathias Bynens <[email protected]>6Copyright (C) 2012 Joost-Wim Boekesteijn <[email protected]>7Copyright (C) 2012 Kris Kowal <[email protected]>8Copyright (C) 2012 Yusuke Suzuki <[email protected]>9Copyright (C) 2012 Arpad Borsos <[email protected]>10Copyright (C) 2011 Ariya Hidayat <[email protected]>1112Redistribution and use in source and binary forms, with or without13modification, are permitted provided that the following conditions are met:1415* Redistributions of source code must retain the above copyright16notice, this list of conditions and the following disclaimer.17* Redistributions in binary form must reproduce the above copyright18notice, this list of conditions and the following disclaimer in the19documentation and/or other materials provided with the distribution.2021THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"22AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY25DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES26(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;27LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND28ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF30THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233(function (root, factory) {34'use strict';3536// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,37// Rhino, and plain browser loading.3839/* istanbul ignore next */40if (typeof define === 'function' && define.amd) {41define(['exports'], factory);42} else if (typeof exports !== 'undefined') {43factory(exports);44} else {45factory((root.esprima = {}));46}47}(this, function (exports) {48'use strict';4950var Token,51TokenName,52FnExprTokens,53Syntax,54PlaceHolders,55Messages,56Regex,57source,58strict,59sourceType,60index,61lineNumber,62lineStart,63hasLineTerminator,64lastIndex,65lastLineNumber,66lastLineStart,67startIndex,68startLineNumber,69startLineStart,70scanning,71length,72lookahead,73state,74extra,75isBindingElement,76isAssignmentTarget,77firstCoverInitializedNameError;7879Token = {80BooleanLiteral: 1,81EOF: 2,82Identifier: 3,83Keyword: 4,84NullLiteral: 5,85NumericLiteral: 6,86Punctuator: 7,87StringLiteral: 8,88RegularExpression: 9,89Template: 1090};9192TokenName = {};93TokenName[Token.BooleanLiteral] = 'Boolean';94TokenName[Token.EOF] = '<end>';95TokenName[Token.Identifier] = 'Identifier';96TokenName[Token.Keyword] = 'Keyword';97TokenName[Token.NullLiteral] = 'Null';98TokenName[Token.NumericLiteral] = 'Numeric';99TokenName[Token.Punctuator] = 'Punctuator';100TokenName[Token.StringLiteral] = 'String';101TokenName[Token.RegularExpression] = 'RegularExpression';102TokenName[Token.Template] = 'Template';103104// A function following one of those tokens is an expression.105FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',106'return', 'case', 'delete', 'throw', 'void',107// assignment operators108'=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',109'&=', '|=', '^=', ',',110// binary/unary operators111'+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',112'|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',113'<=', '<', '>', '!=', '!=='];114115Syntax = {116AssignmentExpression: 'AssignmentExpression',117AssignmentPattern: 'AssignmentPattern',118ArrayExpression: 'ArrayExpression',119ArrayPattern: 'ArrayPattern',120ArrowFunctionExpression: 'ArrowFunctionExpression',121BlockStatement: 'BlockStatement',122BinaryExpression: 'BinaryExpression',123BreakStatement: 'BreakStatement',124CallExpression: 'CallExpression',125CatchClause: 'CatchClause',126ClassBody: 'ClassBody',127ClassDeclaration: 'ClassDeclaration',128ClassExpression: 'ClassExpression',129ConditionalExpression: 'ConditionalExpression',130ContinueStatement: 'ContinueStatement',131DoWhileStatement: 'DoWhileStatement',132DebuggerStatement: 'DebuggerStatement',133EmptyStatement: 'EmptyStatement',134ExportAllDeclaration: 'ExportAllDeclaration',135ExportDefaultDeclaration: 'ExportDefaultDeclaration',136ExportNamedDeclaration: 'ExportNamedDeclaration',137ExportSpecifier: 'ExportSpecifier',138ExpressionStatement: 'ExpressionStatement',139ForStatement: 'ForStatement',140ForInStatement: 'ForInStatement',141FunctionDeclaration: 'FunctionDeclaration',142FunctionExpression: 'FunctionExpression',143Identifier: 'Identifier',144IfStatement: 'IfStatement',145ImportDeclaration: 'ImportDeclaration',146ImportDefaultSpecifier: 'ImportDefaultSpecifier',147ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',148ImportSpecifier: 'ImportSpecifier',149Literal: 'Literal',150LabeledStatement: 'LabeledStatement',151LogicalExpression: 'LogicalExpression',152MemberExpression: 'MemberExpression',153MethodDefinition: 'MethodDefinition',154NewExpression: 'NewExpression',155ObjectExpression: 'ObjectExpression',156ObjectPattern: 'ObjectPattern',157Program: 'Program',158Property: 'Property',159RestElement: 'RestElement',160ReturnStatement: 'ReturnStatement',161SequenceExpression: 'SequenceExpression',162SpreadElement: 'SpreadElement',163Super: 'Super',164SwitchCase: 'SwitchCase',165SwitchStatement: 'SwitchStatement',166TaggedTemplateExpression: 'TaggedTemplateExpression',167TemplateElement: 'TemplateElement',168TemplateLiteral: 'TemplateLiteral',169ThisExpression: 'ThisExpression',170ThrowStatement: 'ThrowStatement',171TryStatement: 'TryStatement',172UnaryExpression: 'UnaryExpression',173UpdateExpression: 'UpdateExpression',174VariableDeclaration: 'VariableDeclaration',175VariableDeclarator: 'VariableDeclarator',176WhileStatement: 'WhileStatement',177WithStatement: 'WithStatement'178};179180PlaceHolders = {181ArrowParameterPlaceHolder: 'ArrowParameterPlaceHolder'182};183184// Error messages should be identical to V8.185Messages = {186UnexpectedToken: 'Unexpected token %0',187UnexpectedNumber: 'Unexpected number',188UnexpectedString: 'Unexpected string',189UnexpectedIdentifier: 'Unexpected identifier',190UnexpectedReserved: 'Unexpected reserved word',191UnexpectedTemplate: 'Unexpected quasi %0',192UnexpectedEOS: 'Unexpected end of input',193NewlineAfterThrow: 'Illegal newline after throw',194InvalidRegExp: 'Invalid regular expression',195UnterminatedRegExp: 'Invalid regular expression: missing /',196InvalidLHSInAssignment: 'Invalid left-hand side in assignment',197InvalidLHSInForIn: 'Invalid left-hand side in for-in',198MultipleDefaultsInSwitch: 'More than one default clause in switch statement',199NoCatchOrFinally: 'Missing catch or finally after try',200UnknownLabel: 'Undefined label \'%0\'',201Redeclaration: '%0 \'%1\' has already been declared',202IllegalContinue: 'Illegal continue statement',203IllegalBreak: 'Illegal break statement',204IllegalReturn: 'Illegal return statement',205StrictModeWith: 'Strict mode code may not include a with statement',206StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',207StrictVarName: 'Variable name may not be eval or arguments in strict mode',208StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',209StrictParamDupe: 'Strict mode function may not have duplicate parameter names',210StrictFunctionName: 'Function name may not be eval or arguments in strict mode',211StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',212StrictDelete: 'Delete of an unqualified identifier in strict mode.',213StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',214StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',215StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',216StrictReservedWord: 'Use of future reserved word in strict mode',217TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',218ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',219DefaultRestParameter: 'Unexpected token =',220ObjectPatternAsRestParameter: 'Unexpected token {',221DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',222ConstructorSpecialMethod: 'Class constructor may not be an accessor',223DuplicateConstructor: 'A class may only have one constructor',224StaticPrototype: 'Classes may not have static property named prototype',225MissingFromClause: 'Unexpected token',226NoAsAfterImportNamespace: 'Unexpected token',227InvalidModuleSpecifier: 'Unexpected token',228IllegalImportDeclaration: 'Unexpected token',229IllegalExportDeclaration: 'Unexpected token'230};231232// See also tools/generate-unicode-regex.py.233Regex = {234NonAsciiIdentifierStart: new RegExp('[\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-\u08B2\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\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\u0C59\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\u0D60\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-\u13F4\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\u19C1-\u19C7\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\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\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\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\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-\uAB5F\uAB64\uAB65\uABC0-\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]'),235NonAsciiIdentifierPart: new RegExp('[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\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-\u08B2\u08E4-\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\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\u0C59\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\u0D60-\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\u1380-\u138F\u13A0-\u13F4\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-\u19D9\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\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\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\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\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-\uAB5F\uAB64\uAB65\uABC0-\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-\uFE2D\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]')236};237238// Ensure the condition is true, otherwise throw an error.239// This is only to have a better contract semantic, i.e. another safety net240// to catch a logic error. The condition shall be fulfilled in normal case.241// Do NOT use this to enforce a certain condition on any user input.242243function assert(condition, message) {244/* istanbul ignore if */245if (!condition) {246throw new Error('ASSERT: ' + message);247}248}249250function isDecimalDigit(ch) {251return (ch >= 0x30 && ch <= 0x39); // 0..9252}253254function isHexDigit(ch) {255return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;256}257258function isOctalDigit(ch) {259return '01234567'.indexOf(ch) >= 0;260}261262function octalToDecimal(ch) {263// \0 is not octal escape sequence264var octal = (ch !== '0'), code = '01234567'.indexOf(ch);265266if (index < length && isOctalDigit(source[index])) {267octal = true;268code = code * 8 + '01234567'.indexOf(source[index++]);269270// 3 digits are only allowed when string starts271// with 0, 1, 2, 3272if ('0123'.indexOf(ch) >= 0 &&273index < length &&274isOctalDigit(source[index])) {275code = code * 8 + '01234567'.indexOf(source[index++]);276}277}278279return {280code: code,281octal: octal282};283}284285// 7.2 White Space286287function isWhiteSpace(ch) {288return (ch === 0x20) || (ch === 0x09) || (ch === 0x0B) || (ch === 0x0C) || (ch === 0xA0) ||289(ch >= 0x1680 && [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(ch) >= 0);290}291292// 7.3 Line Terminators293294function isLineTerminator(ch) {295return (ch === 0x0A) || (ch === 0x0D) || (ch === 0x2028) || (ch === 0x2029);296}297298// 7.6 Identifier Names and Identifiers299300function isIdentifierStart(ch) {301return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)302(ch >= 0x41 && ch <= 0x5A) || // A..Z303(ch >= 0x61 && ch <= 0x7A) || // a..z304(ch === 0x5C) || // \ (backslash)305((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));306}307308function isIdentifierPart(ch) {309return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)310(ch >= 0x41 && ch <= 0x5A) || // A..Z311(ch >= 0x61 && ch <= 0x7A) || // a..z312(ch >= 0x30 && ch <= 0x39) || // 0..9313(ch === 0x5C) || // \ (backslash)314((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));315}316317// 7.6.1.2 Future Reserved Words318319function isFutureReservedWord(id) {320switch (id) {321case 'enum':322case 'export':323case 'import':324case 'super':325return true;326default:327return false;328}329}330331// 11.6.2.2 Future Reserved Words332333function isStrictModeReservedWord(id) {334switch (id) {335case 'implements':336case 'interface':337case 'package':338case 'private':339case 'protected':340case 'public':341case 'static':342case 'yield':343case 'let':344return true;345default:346return false;347}348}349350function isRestrictedWord(id) {351return id === 'eval' || id === 'arguments';352}353354// 7.6.1.1 Keywords355356function isKeyword(id) {357358// 'const' is specialized as Keyword in V8.359// 'yield' and 'let' are for compatibility with SpiderMonkey and ES.next.360// Some others are from future reserved words.361362switch (id.length) {363case 2:364return (id === 'if') || (id === 'in') || (id === 'do');365case 3:366return (id === 'var') || (id === 'for') || (id === 'new') ||367(id === 'try') || (id === 'let');368case 4:369return (id === 'this') || (id === 'else') || (id === 'case') ||370(id === 'void') || (id === 'with') || (id === 'enum');371case 5:372return (id === 'while') || (id === 'break') || (id === 'catch') ||373(id === 'throw') || (id === 'const') || (id === 'yield') ||374(id === 'class') || (id === 'super');375case 6:376return (id === 'return') || (id === 'typeof') || (id === 'delete') ||377(id === 'switch') || (id === 'export') || (id === 'import');378case 7:379return (id === 'default') || (id === 'finally') || (id === 'extends');380case 8:381return (id === 'function') || (id === 'continue') || (id === 'debugger');382case 10:383return (id === 'instanceof');384default:385return false;386}387}388389// 7.4 Comments390391function addComment(type, value, start, end, loc) {392var comment;393394assert(typeof start === 'number', 'Comment must have valid position');395396state.lastCommentStart = start;397398comment = {399type: type,400value: value401};402if (extra.range) {403comment.range = [start, end];404}405if (extra.loc) {406comment.loc = loc;407}408extra.comments.push(comment);409if (extra.attachComment) {410extra.leadingComments.push(comment);411extra.trailingComments.push(comment);412}413}414415function skipSingleLineComment(offset) {416var start, loc, ch, comment;417418start = index - offset;419loc = {420start: {421line: lineNumber,422column: index - lineStart - offset423}424};425426while (index < length) {427ch = source.charCodeAt(index);428++index;429if (isLineTerminator(ch)) {430hasLineTerminator = true;431if (extra.comments) {432comment = source.slice(start + offset, index - 1);433loc.end = {434line: lineNumber,435column: index - lineStart - 1436};437addComment('Line', comment, start, index - 1, loc);438}439if (ch === 13 && source.charCodeAt(index) === 10) {440++index;441}442++lineNumber;443lineStart = index;444return;445}446}447448if (extra.comments) {449comment = source.slice(start + offset, index);450loc.end = {451line: lineNumber,452column: index - lineStart453};454addComment('Line', comment, start, index, loc);455}456}457458function skipMultiLineComment() {459var start, loc, ch, comment;460461if (extra.comments) {462start = index - 2;463loc = {464start: {465line: lineNumber,466column: index - lineStart - 2467}468};469}470471while (index < length) {472ch = source.charCodeAt(index);473if (isLineTerminator(ch)) {474if (ch === 0x0D && source.charCodeAt(index + 1) === 0x0A) {475++index;476}477hasLineTerminator = true;478++lineNumber;479++index;480lineStart = index;481} else if (ch === 0x2A) {482// Block comment ends with '*/'.483if (source.charCodeAt(index + 1) === 0x2F) {484++index;485++index;486if (extra.comments) {487comment = source.slice(start + 2, index - 2);488loc.end = {489line: lineNumber,490column: index - lineStart491};492addComment('Block', comment, start, index, loc);493}494return;495}496++index;497} else {498++index;499}500}501502// Ran off the end of the file - the whole thing is a comment503if (extra.comments) {504loc.end = {505line: lineNumber,506column: index - lineStart507};508comment = source.slice(start + 2, index);509addComment('Block', comment, start, index, loc);510}511tolerateUnexpectedToken();512}513514function skipComment() {515var ch, start;516hasLineTerminator = false;517518start = (index === 0);519while (index < length) {520ch = source.charCodeAt(index);521522if (isWhiteSpace(ch)) {523++index;524} else if (isLineTerminator(ch)) {525hasLineTerminator = true;526++index;527if (ch === 0x0D && source.charCodeAt(index) === 0x0A) {528++index;529}530++lineNumber;531lineStart = index;532start = true;533} else if (ch === 0x2F) { // U+002F is '/'534ch = source.charCodeAt(index + 1);535if (ch === 0x2F) {536++index;537++index;538skipSingleLineComment(2);539start = true;540} else if (ch === 0x2A) { // U+002A is '*'541++index;542++index;543skipMultiLineComment();544} else {545break;546}547} else if (start && ch === 0x2D) { // U+002D is '-'548// U+003E is '>'549if ((source.charCodeAt(index + 1) === 0x2D) && (source.charCodeAt(index + 2) === 0x3E)) {550// '-->' is a single-line comment551index += 3;552skipSingleLineComment(3);553} else {554break;555}556} else if (ch === 0x3C) { // U+003C is '<'557if (source.slice(index + 1, index + 4) === '!--') {558++index; // `<`559++index; // `!`560++index; // `-`561++index; // `-`562skipSingleLineComment(4);563} else {564break;565}566} else {567break;568}569}570}571572function scanHexEscape(prefix) {573var i, len, ch, code = 0;574575len = (prefix === 'u') ? 4 : 2;576for (i = 0; i < len; ++i) {577if (index < length && isHexDigit(source[index])) {578ch = source[index++];579code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());580} else {581return '';582}583}584return String.fromCharCode(code);585}586587function scanUnicodeCodePointEscape() {588var ch, code, cu1, cu2;589590ch = source[index];591code = 0;592593// At least, one hex digit is required.594if (ch === '}') {595throwUnexpectedToken();596}597598while (index < length) {599ch = source[index++];600if (!isHexDigit(ch)) {601break;602}603code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());604}605606if (code > 0x10FFFF || ch !== '}') {607throwUnexpectedToken();608}609610// UTF-16 Encoding611if (code <= 0xFFFF) {612return String.fromCharCode(code);613}614cu1 = ((code - 0x10000) >> 10) + 0xD800;615cu2 = ((code - 0x10000) & 1023) + 0xDC00;616return String.fromCharCode(cu1, cu2);617}618619function getEscapedIdentifier() {620var ch, id;621622ch = source.charCodeAt(index++);623id = String.fromCharCode(ch);624625// '\u' (U+005C, U+0075) denotes an escaped character.626if (ch === 0x5C) {627if (source.charCodeAt(index) !== 0x75) {628throwUnexpectedToken();629}630++index;631ch = scanHexEscape('u');632if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {633throwUnexpectedToken();634}635id = ch;636}637638while (index < length) {639ch = source.charCodeAt(index);640if (!isIdentifierPart(ch)) {641break;642}643++index;644id += String.fromCharCode(ch);645646// '\u' (U+005C, U+0075) denotes an escaped character.647if (ch === 0x5C) {648id = id.substr(0, id.length - 1);649if (source.charCodeAt(index) !== 0x75) {650throwUnexpectedToken();651}652++index;653ch = scanHexEscape('u');654if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {655throwUnexpectedToken();656}657id += ch;658}659}660661return id;662}663664function getIdentifier() {665var start, ch;666667start = index++;668while (index < length) {669ch = source.charCodeAt(index);670if (ch === 0x5C) {671// Blackslash (U+005C) marks Unicode escape sequence.672index = start;673return getEscapedIdentifier();674}675if (isIdentifierPart(ch)) {676++index;677} else {678break;679}680}681682return source.slice(start, index);683}684685function scanIdentifier() {686var start, id, type;687688start = index;689690// Backslash (U+005C) starts an escaped character.691id = (source.charCodeAt(index) === 0x5C) ? getEscapedIdentifier() : getIdentifier();692693// There is no keyword or literal with only one character.694// Thus, it must be an identifier.695if (id.length === 1) {696type = Token.Identifier;697} else if (isKeyword(id)) {698type = Token.Keyword;699} else if (id === 'null') {700type = Token.NullLiteral;701} else if (id === 'true' || id === 'false') {702type = Token.BooleanLiteral;703} else {704type = Token.Identifier;705}706707return {708type: type,709value: id,710lineNumber: lineNumber,711lineStart: lineStart,712start: start,713end: index714};715}716717718// 7.7 Punctuators719720function scanPunctuator() {721var token, str;722723token = {724type: Token.Punctuator,725value: '',726lineNumber: lineNumber,727lineStart: lineStart,728start: index,729end: index730};731732// Check for most common single-character punctuators.733str = source[index];734switch (str) {735736case '(':737if (extra.tokenize) {738extra.openParenToken = extra.tokens.length;739}740++index;741break;742743case '{':744if (extra.tokenize) {745extra.openCurlyToken = extra.tokens.length;746}747state.curlyStack.push('{');748++index;749break;750751case '.':752++index;753if (source[index] === '.' && source[index + 1] === '.') {754// Spread operator: ...755index += 2;756str = '...';757}758break;759760case '}':761++index;762state.curlyStack.pop();763break;764case ')':765case ';':766case ',':767case '[':768case ']':769case ':':770case '?':771case '~':772++index;773break;774775default:776// 4-character punctuator.777str = source.substr(index, 4);778if (str === '>>>=') {779index += 4;780} else {781782// 3-character punctuators.783str = str.substr(0, 3);784if (str === '===' || str === '!==' || str === '>>>' ||785str === '<<=' || str === '>>=') {786index += 3;787} else {788789// 2-character punctuators.790str = str.substr(0, 2);791if (str === '&&' || str === '||' || str === '==' || str === '!=' ||792str === '+=' || str === '-=' || str === '*=' || str === '/=' ||793str === '++' || str === '--' || str === '<<' || str === '>>' ||794str === '&=' || str === '|=' || str === '^=' || str === '%=' ||795str === '<=' || str === '>=' || str === '=>') {796index += 2;797} else {798799// 1-character punctuators.800str = source[index];801if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {802++index;803}804}805}806}807}808809if (index === token.start) {810throwUnexpectedToken();811}812813token.end = index;814token.value = str;815return token;816}817818// 7.8.3 Numeric Literals819820function scanHexLiteral(start) {821var number = '';822823while (index < length) {824if (!isHexDigit(source[index])) {825break;826}827number += source[index++];828}829830if (number.length === 0) {831throwUnexpectedToken();832}833834if (isIdentifierStart(source.charCodeAt(index))) {835throwUnexpectedToken();836}837838return {839type: Token.NumericLiteral,840value: parseInt('0x' + number, 16),841lineNumber: lineNumber,842lineStart: lineStart,843start: start,844end: index845};846}847848function scanBinaryLiteral(start) {849var ch, number;850851number = '';852853while (index < length) {854ch = source[index];855if (ch !== '0' && ch !== '1') {856break;857}858number += source[index++];859}860861if (number.length === 0) {862// only 0b or 0B863throwUnexpectedToken();864}865866if (index < length) {867ch = source.charCodeAt(index);868/* istanbul ignore else */869if (isIdentifierStart(ch) || isDecimalDigit(ch)) {870throwUnexpectedToken();871}872}873874return {875type: Token.NumericLiteral,876value: parseInt(number, 2),877lineNumber: lineNumber,878lineStart: lineStart,879start: start,880end: index881};882}883884function scanOctalLiteral(prefix, start) {885var number, octal;886887if (isOctalDigit(prefix)) {888octal = true;889number = '0' + source[index++];890} else {891octal = false;892++index;893number = '';894}895896while (index < length) {897if (!isOctalDigit(source[index])) {898break;899}900number += source[index++];901}902903if (!octal && number.length === 0) {904// only 0o or 0O905throwUnexpectedToken();906}907908if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {909throwUnexpectedToken();910}911912return {913type: Token.NumericLiteral,914value: parseInt(number, 8),915octal: octal,916lineNumber: lineNumber,917lineStart: lineStart,918start: start,919end: index920};921}922923function isImplicitOctalLiteral() {924var i, ch;925926// Implicit octal, unless there is a non-octal digit.927// (Annex B.1.1 on Numeric Literals)928for (i = index + 1; i < length; ++i) {929ch = source[i];930if (ch === '8' || ch === '9') {931return false;932}933if (!isOctalDigit(ch)) {934return true;935}936}937938return true;939}940941function scanNumericLiteral() {942var number, start, ch;943944ch = source[index];945assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),946'Numeric literal must start with a decimal digit or a decimal point');947948start = index;949number = '';950if (ch !== '.') {951number = source[index++];952ch = source[index];953954// Hex number starts with '0x'.955// Octal number starts with '0'.956// Octal number in ES6 starts with '0o'.957// Binary number in ES6 starts with '0b'.958if (number === '0') {959if (ch === 'x' || ch === 'X') {960++index;961return scanHexLiteral(start);962}963if (ch === 'b' || ch === 'B') {964++index;965return scanBinaryLiteral(start);966}967if (ch === 'o' || ch === 'O') {968return scanOctalLiteral(ch, start);969}970971if (isOctalDigit(ch)) {972if (isImplicitOctalLiteral()) {973return scanOctalLiteral(ch, start);974}975}976}977978while (isDecimalDigit(source.charCodeAt(index))) {979number += source[index++];980}981ch = source[index];982}983984if (ch === '.') {985number += source[index++];986while (isDecimalDigit(source.charCodeAt(index))) {987number += source[index++];988}989ch = source[index];990}991992if (ch === 'e' || ch === 'E') {993number += source[index++];994995ch = source[index];996if (ch === '+' || ch === '-') {997number += source[index++];998}999if (isDecimalDigit(source.charCodeAt(index))) {1000while (isDecimalDigit(source.charCodeAt(index))) {1001number += source[index++];1002}1003} else {1004throwUnexpectedToken();1005}1006}10071008if (isIdentifierStart(source.charCodeAt(index))) {1009throwUnexpectedToken();1010}10111012return {1013type: Token.NumericLiteral,1014value: parseFloat(number),1015lineNumber: lineNumber,1016lineStart: lineStart,1017start: start,1018end: index1019};1020}10211022// 7.8.4 String Literals10231024function scanStringLiteral() {1025var str = '', quote, start, ch, unescaped, octToDec, octal = false;10261027quote = source[index];1028assert((quote === '\'' || quote === '"'),1029'String literal must starts with a quote');10301031start = index;1032++index;10331034while (index < length) {1035ch = source[index++];10361037if (ch === quote) {1038quote = '';1039break;1040} else if (ch === '\\') {1041ch = source[index++];1042if (!ch || !isLineTerminator(ch.charCodeAt(0))) {1043switch (ch) {1044case 'u':1045case 'x':1046if (source[index] === '{') {1047++index;1048str += scanUnicodeCodePointEscape();1049} else {1050unescaped = scanHexEscape(ch);1051if (!unescaped) {1052throw throwUnexpectedToken();1053}1054str += unescaped;1055}1056break;1057case 'n':1058str += '\n';1059break;1060case 'r':1061str += '\r';1062break;1063case 't':1064str += '\t';1065break;1066case 'b':1067str += '\b';1068break;1069case 'f':1070str += '\f';1071break;1072case 'v':1073str += '\x0B';1074break;1075case '8':1076case '9':1077throw throwUnexpectedToken();10781079default:1080if (isOctalDigit(ch)) {1081octToDec = octalToDecimal(ch);10821083octal = octToDec.octal || octal;1084str += String.fromCharCode(octToDec.code);1085} else {1086str += ch;1087}1088break;1089}1090} else {1091++lineNumber;1092if (ch === '\r' && source[index] === '\n') {1093++index;1094}1095lineStart = index;1096}1097} else if (isLineTerminator(ch.charCodeAt(0))) {1098break;1099} else {1100str += ch;1101}1102}11031104if (quote !== '') {1105throwUnexpectedToken();1106}11071108return {1109type: Token.StringLiteral,1110value: str,1111octal: octal,1112lineNumber: startLineNumber,1113lineStart: startLineStart,1114start: start,1115end: index1116};1117}11181119function scanTemplate() {1120var cooked = '', ch, start, rawOffset, terminated, head, tail, restore, unescaped;11211122terminated = false;1123tail = false;1124start = index;1125head = (source[index] === '`');1126rawOffset = 2;11271128++index;11291130while (index < length) {1131ch = source[index++];1132if (ch === '`') {1133rawOffset = 1;1134tail = true;1135terminated = true;1136break;1137} else if (ch === '$') {1138if (source[index] === '{') {1139state.curlyStack.push('${');1140++index;1141terminated = true;1142break;1143}1144cooked += ch;1145} else if (ch === '\\') {1146ch = source[index++];1147if (!isLineTerminator(ch.charCodeAt(0))) {1148switch (ch) {1149case 'n':1150cooked += '\n';1151break;1152case 'r':1153cooked += '\r';1154break;1155case 't':1156cooked += '\t';1157break;1158case 'u':1159case 'x':1160if (source[index] === '{') {1161++index;1162cooked += scanUnicodeCodePointEscape();1163} else {1164restore = index;1165unescaped = scanHexEscape(ch);1166if (unescaped) {1167cooked += unescaped;1168} else {1169index = restore;1170cooked += ch;1171}1172}1173break;1174case 'b':1175cooked += '\b';1176break;1177case 'f':1178cooked += '\f';1179break;1180case 'v':1181cooked += '\v';1182break;11831184default:1185if (ch === '0') {1186if (isDecimalDigit(source.charCodeAt(index))) {1187// Illegal: \01 \02 and so on1188throwError(Messages.TemplateOctalLiteral);1189}1190cooked += '\0';1191} else if (isOctalDigit(ch)) {1192// Illegal: \1 \21193throwError(Messages.TemplateOctalLiteral);1194} else {1195cooked += ch;1196}1197break;1198}1199} else {1200++lineNumber;1201if (ch === '\r' && source[index] === '\n') {1202++index;1203}1204lineStart = index;1205}1206} else if (isLineTerminator(ch.charCodeAt(0))) {1207++lineNumber;1208if (ch === '\r' && source[index] === '\n') {1209++index;1210}1211lineStart = index;1212cooked += '\n';1213} else {1214cooked += ch;1215}1216}12171218if (!terminated) {1219throwUnexpectedToken();1220}12211222if (!head) {1223state.curlyStack.pop();1224}12251226return {1227type: Token.Template,1228value: {1229cooked: cooked,1230raw: source.slice(start + 1, index - rawOffset)1231},1232head: head,1233tail: tail,1234lineNumber: lineNumber,1235lineStart: lineStart,1236start: start,1237end: index1238};1239}12401241function testRegExp(pattern, flags) {1242var tmp = pattern;12431244if (flags.indexOf('u') >= 0) {1245// Replace each astral symbol and every Unicode escape sequence1246// that possibly represents an astral symbol or a paired surrogate1247// with a single ASCII symbol to avoid throwing on regular1248// expressions that are only valid in combination with the `/u`1249// flag.1250// Note: replacing with the ASCII symbol `x` might cause false1251// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a1252// perfectly valid pattern that is equivalent to `[a-b]`, but it1253// would be replaced by `[x-b]` which throws an error.1254tmp = tmp1255.replace(/\\u\{([0-9a-fA-F]+)\}/g, function ($0, $1) {1256if (parseInt($1, 16) <= 0x10FFFF) {1257return 'x';1258}1259throwUnexpectedToken(null, Messages.InvalidRegExp);1260})1261.replace(1262/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,1263'x'1264);1265}12661267// First, detect invalid regular expressions.1268try {1269RegExp(tmp);1270} catch (e) {1271throwUnexpectedToken(null, Messages.InvalidRegExp);1272}12731274// Return a regular expression object for this pattern-flag pair, or1275// `null` in case the current environment doesn't support the flags it1276// uses.1277try {1278return new RegExp(pattern, flags);1279} catch (exception) {1280return null;1281}1282}12831284function scanRegExpBody() {1285var ch, str, classMarker, terminated, body;12861287ch = source[index];1288assert(ch === '/', 'Regular expression literal must start with a slash');1289str = source[index++];12901291classMarker = false;1292terminated = false;1293while (index < length) {1294ch = source[index++];1295str += ch;1296if (ch === '\\') {1297ch = source[index++];1298// ECMA-262 7.8.51299if (isLineTerminator(ch.charCodeAt(0))) {1300throwUnexpectedToken(null, Messages.UnterminatedRegExp);1301}1302str += ch;1303} else if (isLineTerminator(ch.charCodeAt(0))) {1304throwUnexpectedToken(null, Messages.UnterminatedRegExp);1305} else if (classMarker) {1306if (ch === ']') {1307classMarker = false;1308}1309} else {1310if (ch === '/') {1311terminated = true;1312break;1313} else if (ch === '[') {1314classMarker = true;1315}1316}1317}13181319if (!terminated) {1320throwUnexpectedToken(null, Messages.UnterminatedRegExp);1321}13221323// Exclude leading and trailing slash.1324body = str.substr(1, str.length - 2);1325return {1326value: body,1327literal: str1328};1329}13301331function scanRegExpFlags() {1332var ch, str, flags, restore;13331334str = '';1335flags = '';1336while (index < length) {1337ch = source[index];1338if (!isIdentifierPart(ch.charCodeAt(0))) {1339break;1340}13411342++index;1343if (ch === '\\' && index < length) {1344ch = source[index];1345if (ch === 'u') {1346++index;1347restore = index;1348ch = scanHexEscape('u');1349if (ch) {1350flags += ch;1351for (str += '\\u'; restore < index; ++restore) {1352str += source[restore];1353}1354} else {1355index = restore;1356flags += 'u';1357str += '\\u';1358}1359tolerateUnexpectedToken();1360} else {1361str += '\\';1362tolerateUnexpectedToken();1363}1364} else {1365flags += ch;1366str += ch;1367}1368}13691370return {1371value: flags,1372literal: str1373};1374}13751376function scanRegExp() {1377scanning = true;1378var start, body, flags, value;13791380lookahead = null;1381skipComment();1382start = index;13831384body = scanRegExpBody();1385flags = scanRegExpFlags();1386value = testRegExp(body.value, flags.value);1387scanning = false;1388if (extra.tokenize) {1389return {1390type: Token.RegularExpression,1391value: value,1392regex: {1393pattern: body.value,1394flags: flags.value1395},1396lineNumber: lineNumber,1397lineStart: lineStart,1398start: start,1399end: index1400};1401}14021403return {1404literal: body.literal + flags.literal,1405value: value,1406regex: {1407pattern: body.value,1408flags: flags.value1409},1410start: start,1411end: index1412};1413}14141415function collectRegex() {1416var pos, loc, regex, token;14171418skipComment();14191420pos = index;1421loc = {1422start: {1423line: lineNumber,1424column: index - lineStart1425}1426};14271428regex = scanRegExp();14291430loc.end = {1431line: lineNumber,1432column: index - lineStart1433};14341435/* istanbul ignore next */1436if (!extra.tokenize) {1437// Pop the previous token, which is likely '/' or '/='1438if (extra.tokens.length > 0) {1439token = extra.tokens[extra.tokens.length - 1];1440if (token.range[0] === pos && token.type === 'Punctuator') {1441if (token.value === '/' || token.value === '/=') {1442extra.tokens.pop();1443}1444}1445}14461447extra.tokens.push({1448type: 'RegularExpression',1449value: regex.literal,1450regex: regex.regex,1451range: [pos, index],1452loc: loc1453});1454}14551456return regex;1457}14581459function isIdentifierName(token) {1460return token.type === Token.Identifier ||1461token.type === Token.Keyword ||1462token.type === Token.BooleanLiteral ||1463token.type === Token.NullLiteral;1464}14651466function advanceSlash() {1467var prevToken,1468checkToken;1469// Using the following algorithm:1470// https://github.com/mozilla/sweet.js/wiki/design1471prevToken = extra.tokens[extra.tokens.length - 1];1472if (!prevToken) {1473// Nothing before that: it cannot be a division.1474return collectRegex();1475}1476if (prevToken.type === 'Punctuator') {1477if (prevToken.value === ']') {1478return scanPunctuator();1479}1480if (prevToken.value === ')') {1481checkToken = extra.tokens[extra.openParenToken - 1];1482if (checkToken &&1483checkToken.type === 'Keyword' &&1484(checkToken.value === 'if' ||1485checkToken.value === 'while' ||1486checkToken.value === 'for' ||1487checkToken.value === 'with')) {1488return collectRegex();1489}1490return scanPunctuator();1491}1492if (prevToken.value === '}') {1493// Dividing a function by anything makes little sense,1494// but we have to check for that.1495if (extra.tokens[extra.openCurlyToken - 3] &&1496extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {1497// Anonymous function.1498checkToken = extra.tokens[extra.openCurlyToken - 4];1499if (!checkToken) {1500return scanPunctuator();1501}1502} else if (extra.tokens[extra.openCurlyToken - 4] &&1503extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {1504// Named function.1505checkToken = extra.tokens[extra.openCurlyToken - 5];1506if (!checkToken) {1507return collectRegex();1508}1509} else {1510return scanPunctuator();1511}1512// checkToken determines whether the function is1513// a declaration or an expression.1514if (FnExprTokens.indexOf(checkToken.value) >= 0) {1515// It is an expression.1516return scanPunctuator();1517}1518// It is a declaration.1519return collectRegex();1520}1521return collectRegex();1522}1523if (prevToken.type === 'Keyword' && prevToken.value !== 'this') {1524return collectRegex();1525}1526return scanPunctuator();1527}15281529function advance() {1530var ch, token;15311532if (index >= length) {1533return {1534type: Token.EOF,1535lineNumber: lineNumber,1536lineStart: lineStart,1537start: index,1538end: index1539};1540}15411542ch = source.charCodeAt(index);15431544if (isIdentifierStart(ch)) {1545token = scanIdentifier();1546if (strict && isStrictModeReservedWord(token.value)) {1547token.type = Token.Keyword;1548}1549return token;1550}15511552// Very common: ( and ) and ;1553if (ch === 0x28 || ch === 0x29 || ch === 0x3B) {1554return scanPunctuator();1555}15561557// String literal starts with single quote (U+0027) or double quote (U+0022).1558if (ch === 0x27 || ch === 0x22) {1559return scanStringLiteral();1560}15611562// Dot (.) U+002E can also start a floating-point number, hence the need1563// to check the next character.1564if (ch === 0x2E) {1565if (isDecimalDigit(source.charCodeAt(index + 1))) {1566return scanNumericLiteral();1567}1568return scanPunctuator();1569}15701571if (isDecimalDigit(ch)) {1572return scanNumericLiteral();1573}15741575// Slash (/) U+002F can also start a regex.1576if (extra.tokenize && ch === 0x2F) {1577return advanceSlash();1578}15791580// Template literals start with ` (U+0060) for template head1581// or } (U+007D) for template middle or template tail.1582if (ch === 0x60 || (ch === 0x7D && state.curlyStack[state.curlyStack.length - 1] === '${')) {1583return scanTemplate();1584}15851586return scanPunctuator();1587}15881589function collectToken() {1590var loc, token, value, entry;15911592loc = {1593start: {1594line: lineNumber,1595column: index - lineStart1596}1597};15981599token = advance();1600loc.end = {1601line: lineNumber,1602column: index - lineStart1603};16041605if (token.type !== Token.EOF) {1606value = source.slice(token.start, token.end);1607entry = {1608type: TokenName[token.type],1609value: value,1610range: [token.start, token.end],1611loc: loc1612};1613if (token.regex) {1614entry.regex = {1615pattern: token.regex.pattern,1616flags: token.regex.flags1617};1618}1619extra.tokens.push(entry);1620}16211622return token;1623}16241625function lex() {1626var token;1627scanning = true;16281629lastIndex = index;1630lastLineNumber = lineNumber;1631lastLineStart = lineStart;16321633skipComment();16341635token = lookahead;16361637startIndex = index;1638startLineNumber = lineNumber;1639startLineStart = lineStart;16401641lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();1642scanning = false;1643return token;1644}16451646function peek() {1647scanning = true;16481649skipComment();16501651lastIndex = index;1652lastLineNumber = lineNumber;1653lastLineStart = lineStart;16541655startIndex = index;1656startLineNumber = lineNumber;1657startLineStart = lineStart;16581659lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();1660scanning = false;1661}16621663function Position() {1664this.line = startLineNumber;1665this.column = startIndex - startLineStart;1666}16671668function SourceLocation() {1669this.start = new Position();1670this.end = null;1671}16721673function WrappingSourceLocation(startToken) {1674this.start = {1675line: startToken.lineNumber,1676column: startToken.start - startToken.lineStart1677};1678this.end = null;1679}16801681function Node() {1682if (extra.range) {1683this.range = [startIndex, 0];1684}1685if (extra.loc) {1686this.loc = new SourceLocation();1687}1688}16891690function WrappingNode(startToken) {1691if (extra.range) {1692this.range = [startToken.start, 0];1693}1694if (extra.loc) {1695this.loc = new WrappingSourceLocation(startToken);1696}1697}16981699WrappingNode.prototype = Node.prototype = {17001701processComment: function () {1702var lastChild,1703leadingComments,1704trailingComments,1705bottomRight = extra.bottomRightStack,1706i,1707comment,1708last = bottomRight[bottomRight.length - 1];17091710if (this.type === Syntax.Program) {1711if (this.body.length > 0) {1712return;1713}1714}17151716if (extra.trailingComments.length > 0) {1717trailingComments = [];1718for (i = extra.trailingComments.length - 1; i >= 0; --i) {1719comment = extra.trailingComments[i];1720if (comment.range[0] >= this.range[1]) {1721trailingComments.unshift(comment);1722extra.trailingComments.splice(i, 1);1723}1724}1725extra.trailingComments = [];1726} else {1727if (last && last.trailingComments && last.trailingComments[0].range[0] >= this.range[1]) {1728trailingComments = last.trailingComments;1729delete last.trailingComments;1730}1731}17321733// Eating the stack.1734if (last) {1735while (last && last.range[0] >= this.range[0]) {1736lastChild = last;1737last = bottomRight.pop();1738}1739}17401741if (lastChild) {1742if (lastChild.leadingComments && lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= this.range[0]) {1743this.leadingComments = lastChild.leadingComments;1744lastChild.leadingComments = undefined;1745}1746} else if (extra.leadingComments.length > 0) {1747leadingComments = [];1748for (i = extra.leadingComments.length - 1; i >= 0; --i) {1749comment = extra.leadingComments[i];1750if (comment.range[1] <= this.range[0]) {1751leadingComments.unshift(comment);1752extra.leadingComments.splice(i, 1);1753}1754}1755}175617571758if (leadingComments && leadingComments.length > 0) {1759this.leadingComments = leadingComments;1760}1761if (trailingComments && trailingComments.length > 0) {1762this.trailingComments = trailingComments;1763}17641765bottomRight.push(this);1766},17671768finish: function () {1769if (extra.range) {1770this.range[1] = lastIndex;1771}1772if (extra.loc) {1773this.loc.end = {1774line: lastLineNumber,1775column: lastIndex - lastLineStart1776};1777if (extra.source) {1778this.loc.source = extra.source;1779}1780}17811782if (extra.attachComment) {1783this.processComment();1784}1785},17861787finishArrayExpression: function (elements) {1788this.type = Syntax.ArrayExpression;1789this.elements = elements;1790this.finish();1791return this;1792},17931794finishArrayPattern: function (elements) {1795this.type = Syntax.ArrayPattern;1796this.elements = elements;1797this.finish();1798return this;1799},18001801finishArrowFunctionExpression: function (params, defaults, body, expression) {1802this.type = Syntax.ArrowFunctionExpression;1803this.id = null;1804this.params = params;1805this.defaults = defaults;1806this.body = body;1807this.generator = false;1808this.expression = expression;1809this.finish();1810return this;1811},18121813finishAssignmentExpression: function (operator, left, right) {1814this.type = Syntax.AssignmentExpression;1815this.operator = operator;1816this.left = left;1817this.right = right;1818this.finish();1819return this;1820},18211822finishAssignmentPattern: function (left, right) {1823this.type = Syntax.AssignmentPattern;1824this.left = left;1825this.right = right;1826this.finish();1827return this;1828},18291830finishBinaryExpression: function (operator, left, right) {1831this.type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression : Syntax.BinaryExpression;1832this.operator = operator;1833this.left = left;1834this.right = right;1835this.finish();1836return this;1837},18381839finishBlockStatement: function (body) {1840this.type = Syntax.BlockStatement;1841this.body = body;1842this.finish();1843return this;1844},18451846finishBreakStatement: function (label) {1847this.type = Syntax.BreakStatement;1848this.label = label;1849this.finish();1850return this;1851},18521853finishCallExpression: function (callee, args) {1854this.type = Syntax.CallExpression;1855this.callee = callee;1856this.arguments = args;1857this.finish();1858return this;1859},18601861finishCatchClause: function (param, body) {1862this.type = Syntax.CatchClause;1863this.param = param;1864this.body = body;1865this.finish();1866return this;1867},18681869finishClassBody: function (body) {1870this.type = Syntax.ClassBody;1871this.body = body;1872this.finish();1873return this;1874},18751876finishClassDeclaration: function (id, superClass, body) {1877this.type = Syntax.ClassDeclaration;1878this.id = id;1879this.superClass = superClass;1880this.body = body;1881this.finish();1882return this;1883},18841885finishClassExpression: function (id, superClass, body) {1886this.type = Syntax.ClassExpression;1887this.id = id;1888this.superClass = superClass;1889this.body = body;1890this.finish();1891return this;1892},18931894finishConditionalExpression: function (test, consequent, alternate) {1895this.type = Syntax.ConditionalExpression;1896this.test = test;1897this.consequent = consequent;1898this.alternate = alternate;1899this.finish();1900return this;1901},19021903finishContinueStatement: function (label) {1904this.type = Syntax.ContinueStatement;1905this.label = label;1906this.finish();1907return this;1908},19091910finishDebuggerStatement: function () {1911this.type = Syntax.DebuggerStatement;1912this.finish();1913return this;1914},19151916finishDoWhileStatement: function (body, test) {1917this.type = Syntax.DoWhileStatement;1918this.body = body;1919this.test = test;1920this.finish();1921return this;1922},19231924finishEmptyStatement: function () {1925this.type = Syntax.EmptyStatement;1926this.finish();1927return this;1928},19291930finishExpressionStatement: function (expression) {1931this.type = Syntax.ExpressionStatement;1932this.expression = expression;1933this.finish();1934return this;1935},19361937finishForStatement: function (init, test, update, body) {1938this.type = Syntax.ForStatement;1939this.init = init;1940this.test = test;1941this.update = update;1942this.body = body;1943this.finish();1944return this;1945},19461947finishForInStatement: function (left, right, body) {1948this.type = Syntax.ForInStatement;1949this.left = left;1950this.right = right;1951this.body = body;1952this.each = false;1953this.finish();1954return this;1955},19561957finishFunctionDeclaration: function (id, params, defaults, body) {1958this.type = Syntax.FunctionDeclaration;1959this.id = id;1960this.params = params;1961this.defaults = defaults;1962this.body = body;1963this.generator = false;1964this.expression = false;1965this.finish();1966return this;1967},19681969finishFunctionExpression: function (id, params, defaults, body) {1970this.type = Syntax.FunctionExpression;1971this.id = id;1972this.params = params;1973this.defaults = defaults;1974this.body = body;1975this.generator = false;1976this.expression = false;1977this.finish();1978return this;1979},19801981finishIdentifier: function (name) {1982this.type = Syntax.Identifier;1983this.name = name;1984this.finish();1985return this;1986},19871988finishIfStatement: function (test, consequent, alternate) {1989this.type = Syntax.IfStatement;1990this.test = test;1991this.consequent = consequent;1992this.alternate = alternate;1993this.finish();1994return this;1995},19961997finishLabeledStatement: function (label, body) {1998this.type = Syntax.LabeledStatement;1999this.label = label;2000this.body = body;2001this.finish();2002return this;2003},20042005finishLiteral: function (token) {2006this.type = Syntax.Literal;2007this.value = token.value;2008this.raw = source.slice(token.start, token.end);2009if (token.regex) {2010this.regex = token.regex;2011}2012this.finish();2013return this;2014},20152016finishMemberExpression: function (accessor, object, property) {2017this.type = Syntax.MemberExpression;2018this.computed = accessor === '[';2019this.object = object;2020this.property = property;2021this.finish();2022return this;2023},20242025finishNewExpression: function (callee, args) {2026this.type = Syntax.NewExpression;2027this.callee = callee;2028this.arguments = args;2029this.finish();2030return this;2031},20322033finishObjectExpression: function (properties) {2034this.type = Syntax.ObjectExpression;2035this.properties = properties;2036this.finish();2037return this;2038},20392040finishObjectPattern: function (properties) {2041this.type = Syntax.ObjectPattern;2042this.properties = properties;2043this.finish();2044return this;2045},20462047finishPostfixExpression: function (operator, argument) {2048this.type = Syntax.UpdateExpression;2049this.operator = operator;2050this.argument = argument;2051this.prefix = false;2052this.finish();2053return this;2054},20552056finishProgram: function (body) {2057this.type = Syntax.Program;2058this.body = body;2059if (sourceType === 'module') {2060// very restrictive for now2061this.sourceType = sourceType;2062}2063this.finish();2064return this;2065},20662067finishProperty: function (kind, key, computed, value, method, shorthand) {2068this.type = Syntax.Property;2069this.key = key;2070this.computed = computed;2071this.value = value;2072this.kind = kind;2073this.method = method;2074this.shorthand = shorthand;2075this.finish();2076return this;2077},20782079finishRestElement: function (argument) {2080this.type = Syntax.RestElement;2081this.argument = argument;2082this.finish();2083return this;2084},20852086finishReturnStatement: function (argument) {2087this.type = Syntax.ReturnStatement;2088this.argument = argument;2089this.finish();2090return this;2091},20922093finishSequenceExpression: function (expressions) {2094this.type = Syntax.SequenceExpression;2095this.expressions = expressions;2096this.finish();2097return this;2098},20992100finishSpreadElement: function (argument) {2101this.type = Syntax.SpreadElement;2102this.argument = argument;2103this.finish();2104return this;2105},21062107finishSwitchCase: function (test, consequent) {2108this.type = Syntax.SwitchCase;2109this.test = test;2110this.consequent = consequent;2111this.finish();2112return this;2113},21142115finishSuper: function () {2116this.type = Syntax.Super;2117this.finish();2118return this;2119},21202121finishSwitchStatement: function (discriminant, cases) {2122this.type = Syntax.SwitchStatement;2123this.discriminant = discriminant;2124this.cases = cases;2125this.finish();2126return this;2127},21282129finishTaggedTemplateExpression: function (tag, quasi) {2130this.type = Syntax.TaggedTemplateExpression;2131this.tag = tag;2132this.quasi = quasi;2133this.finish();2134return this;2135},21362137finishTemplateElement: function (value, tail) {2138this.type = Syntax.TemplateElement;2139this.value = value;2140this.tail = tail;2141this.finish();2142return this;2143},21442145finishTemplateLiteral: function (quasis, expressions) {2146this.type = Syntax.TemplateLiteral;2147this.quasis = quasis;2148this.expressions = expressions;2149this.finish();2150return this;2151},21522153finishThisExpression: function () {2154this.type = Syntax.ThisExpression;2155this.finish();2156return this;2157},21582159finishThrowStatement: function (argument) {2160this.type = Syntax.ThrowStatement;2161this.argument = argument;2162this.finish();2163return this;2164},21652166finishTryStatement: function (block, handler, finalizer) {2167this.type = Syntax.TryStatement;2168this.block = block;2169this.guardedHandlers = [];2170this.handlers = handler ? [ handler ] : [];2171this.handler = handler;2172this.finalizer = finalizer;2173this.finish();2174return this;2175},21762177finishUnaryExpression: function (operator, argument) {2178this.type = (operator === '++' || operator === '--') ? Syntax.UpdateExpression : Syntax.UnaryExpression;2179this.operator = operator;2180this.argument = argument;2181this.prefix = true;2182this.finish();2183return this;2184},21852186finishVariableDeclaration: function (declarations) {2187this.type = Syntax.VariableDeclaration;2188this.declarations = declarations;2189this.kind = 'var';2190this.finish();2191return this;2192},21932194finishLexicalDeclaration: function (declarations, kind) {2195this.type = Syntax.VariableDeclaration;2196this.declarations = declarations;2197this.kind = kind;2198this.finish();2199return this;2200},22012202finishVariableDeclarator: function (id, init) {2203this.type = Syntax.VariableDeclarator;2204this.id = id;2205this.init = init;2206this.finish();2207return this;2208},22092210finishWhileStatement: function (test, body) {2211this.type = Syntax.WhileStatement;2212this.test = test;2213this.body = body;2214this.finish();2215return this;2216},22172218finishWithStatement: function (object, body) {2219this.type = Syntax.WithStatement;2220this.object = object;2221this.body = body;2222this.finish();2223return this;2224},22252226finishExportSpecifier: function (local, exported) {2227this.type = Syntax.ExportSpecifier;2228this.exported = exported || local;2229this.local = local;2230this.finish();2231return this;2232},22332234finishImportDefaultSpecifier: function (local) {2235this.type = Syntax.ImportDefaultSpecifier;2236this.local = local;2237this.finish();2238return this;2239},22402241finishImportNamespaceSpecifier: function (local) {2242this.type = Syntax.ImportNamespaceSpecifier;2243this.local = local;2244this.finish();2245return this;2246},22472248finishExportNamedDeclaration: function (declaration, specifiers, src) {2249this.type = Syntax.ExportNamedDeclaration;2250this.declaration = declaration;2251this.specifiers = specifiers;2252this.source = src;2253this.finish();2254return this;2255},22562257finishExportDefaultDeclaration: function (declaration) {2258this.type = Syntax.ExportDefaultDeclaration;2259this.declaration = declaration;2260this.finish();2261return this;2262},22632264finishExportAllDeclaration: function (src) {2265this.type = Syntax.ExportAllDeclaration;2266this.source = src;2267this.finish();2268return this;2269},22702271finishImportSpecifier: function (local, imported) {2272this.type = Syntax.ImportSpecifier;2273this.local = local || imported;2274this.imported = imported;2275this.finish();2276return this;2277},22782279finishImportDeclaration: function (specifiers, src) {2280this.type = Syntax.ImportDeclaration;2281this.specifiers = specifiers;2282this.source = src;2283this.finish();2284return this;2285}2286};228722882289function recordError(error) {2290var e, existing;22912292for (e = 0; e < extra.errors.length; e++) {2293existing = extra.errors[e];2294// Prevent duplicated error.2295/* istanbul ignore next */2296if (existing.index === error.index && existing.message === error.message) {2297return;2298}2299}23002301extra.errors.push(error);2302}23032304function createError(line, pos, description) {2305var error = new Error('Line ' + line + ': ' + description);2306error.index = pos;2307error.lineNumber = line;2308error.column = pos - (scanning ? lineStart : lastLineStart) + 1;2309error.description = description;2310return error;2311}23122313// Throw an exception23142315function throwError(messageFormat) {2316var args, msg;23172318args = Array.prototype.slice.call(arguments, 1);2319msg = messageFormat.replace(/%(\d)/g,2320function (whole, idx) {2321assert(idx < args.length, 'Message reference must be in range');2322return args[idx];2323}2324);23252326throw createError(lastLineNumber, lastIndex, msg);2327}23282329function tolerateError(messageFormat) {2330var args, msg, error;23312332args = Array.prototype.slice.call(arguments, 1);2333/* istanbul ignore next */2334msg = messageFormat.replace(/%(\d)/g,2335function (whole, idx) {2336assert(idx < args.length, 'Message reference must be in range');2337return args[idx];2338}2339);23402341error = createError(lineNumber, lastIndex, msg);2342if (extra.errors) {2343recordError(error);2344} else {2345throw error;2346}2347}23482349// Throw an exception because of the token.23502351function unexpectedTokenError(token, message) {2352var value, msg = message || Messages.UnexpectedToken;23532354if (token) {2355if (!message) {2356msg = (token.type === Token.EOF) ? Messages.UnexpectedEOS :2357(token.type === Token.Identifier) ? Messages.UnexpectedIdentifier :2358(token.type === Token.NumericLiteral) ? Messages.UnexpectedNumber :2359(token.type === Token.StringLiteral) ? Messages.UnexpectedString :2360(token.type === Token.Template) ? Messages.UnexpectedTemplate :2361Messages.UnexpectedToken;23622363if (token.type === Token.Keyword) {2364if (isFutureReservedWord(token.value)) {2365msg = Messages.UnexpectedReserved;2366} else if (strict && isStrictModeReservedWord(token.value)) {2367msg = Messages.StrictReservedWord;2368}2369}2370}23712372value = (token.type === Token.Template) ? token.value.raw : token.value;2373} else {2374value = 'ILLEGAL';2375}23762377msg = msg.replace('%0', value);23782379return (token && typeof token.lineNumber === 'number') ?2380createError(token.lineNumber, token.start, msg) :2381createError(scanning ? lineNumber : lastLineNumber, scanning ? index : lastIndex, msg);2382}23832384function throwUnexpectedToken(token, message) {2385throw unexpectedTokenError(token, message);2386}23872388function tolerateUnexpectedToken(token, message) {2389var error = unexpectedTokenError(token, message);2390if (extra.errors) {2391recordError(error);2392} else {2393throw error;2394}2395}23962397// Expect the next token to match the specified punctuator.2398// If not, an exception will be thrown.23992400function expect(value) {2401var token = lex();2402if (token.type !== Token.Punctuator || token.value !== value) {2403throwUnexpectedToken(token);2404}2405}24062407/**2408* @name expectCommaSeparator2409* @description Quietly expect a comma when in tolerant mode, otherwise delegates2410* to <code>expect(value)</code>2411* @since 2.02412*/2413function expectCommaSeparator() {2414var token;24152416if (extra.errors) {2417token = lookahead;2418if (token.type === Token.Punctuator && token.value === ',') {2419lex();2420} else if (token.type === Token.Punctuator && token.value === ';') {2421lex();2422tolerateUnexpectedToken(token);2423} else {2424tolerateUnexpectedToken(token, Messages.UnexpectedToken);2425}2426} else {2427expect(',');2428}2429}24302431// Expect the next token to match the specified keyword.2432// If not, an exception will be thrown.24332434function expectKeyword(keyword) {2435var token = lex();2436if (token.type !== Token.Keyword || token.value !== keyword) {2437throwUnexpectedToken(token);2438}2439}24402441// Return true if the next token matches the specified punctuator.24422443function match(value) {2444return lookahead.type === Token.Punctuator && lookahead.value === value;2445}24462447// Return true if the next token matches the specified keyword24482449function matchKeyword(keyword) {2450return lookahead.type === Token.Keyword && lookahead.value === keyword;2451}24522453// Return true if the next token matches the specified contextual keyword2454// (where an identifier is sometimes a keyword depending on the context)24552456function matchContextualKeyword(keyword) {2457return lookahead.type === Token.Identifier && lookahead.value === keyword;2458}24592460// Return true if the next token is an assignment operator24612462function matchAssign() {2463var op;24642465if (lookahead.type !== Token.Punctuator) {2466return false;2467}2468op = lookahead.value;2469return op === '=' ||2470op === '*=' ||2471op === '/=' ||2472op === '%=' ||2473op === '+=' ||2474op === '-=' ||2475op === '<<=' ||2476op === '>>=' ||2477op === '>>>=' ||2478op === '&=' ||2479op === '^=' ||2480op === '|=';2481}24822483function consumeSemicolon() {2484// Catch the very common case first: immediately a semicolon (U+003B).2485if (source.charCodeAt(startIndex) === 0x3B || match(';')) {2486lex();2487return;2488}24892490if (hasLineTerminator) {2491return;2492}24932494// FIXME(ikarienator): this is seemingly an issue in the previous location info convention.2495lastIndex = startIndex;2496lastLineNumber = startLineNumber;2497lastLineStart = startLineStart;24982499if (lookahead.type !== Token.EOF && !match('}')) {2500throwUnexpectedToken(lookahead);2501}2502}25032504// Cover grammar support.2505//2506// When an assignment expression position starts with an left parenthesis, the determination of the type2507// of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)2508// or the first comma. This situation also defers the determination of all the expressions nested in the pair.2509//2510// There are three productions that can be parsed in a parentheses pair that needs to be determined2511// after the outermost pair is closed. They are:2512//2513// 1. AssignmentExpression2514// 2. BindingElements2515// 3. AssignmentTargets2516//2517// In order to avoid exponential backtracking, we use two flags to denote if the production can be2518// binding element or assignment target.2519//2520// The three productions have the relationship:2521//2522// BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression2523//2524// with a single exception that CoverInitializedName when used directly in an Expression, generates2525// an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the2526// first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.2527//2528// isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not2529// effect the current flags. This means the production the parser parses is only used as an expression. Therefore2530// the CoverInitializedName check is conducted.2531//2532// inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates2533// the flags outside of the parser. This means the production the parser parses is used as a part of a potential2534// pattern. The CoverInitializedName check is deferred.2535function isolateCoverGrammar(parser) {2536var oldIsBindingElement = isBindingElement,2537oldIsAssignmentTarget = isAssignmentTarget,2538oldFirstCoverInitializedNameError = firstCoverInitializedNameError,2539result;2540isBindingElement = true;2541isAssignmentTarget = true;2542firstCoverInitializedNameError = null;2543result = parser();2544if (firstCoverInitializedNameError !== null) {2545throwUnexpectedToken(firstCoverInitializedNameError);2546}2547isBindingElement = oldIsBindingElement;2548isAssignmentTarget = oldIsAssignmentTarget;2549firstCoverInitializedNameError = oldFirstCoverInitializedNameError;2550return result;2551}25522553function inheritCoverGrammar(parser) {2554var oldIsBindingElement = isBindingElement,2555oldIsAssignmentTarget = isAssignmentTarget,2556oldFirstCoverInitializedNameError = firstCoverInitializedNameError,2557result;2558isBindingElement = true;2559isAssignmentTarget = true;2560firstCoverInitializedNameError = null;2561result = parser();2562isBindingElement = isBindingElement && oldIsBindingElement;2563isAssignmentTarget = isAssignmentTarget && oldIsAssignmentTarget;2564firstCoverInitializedNameError = oldFirstCoverInitializedNameError || firstCoverInitializedNameError;2565return result;2566}25672568function parseArrayPattern() {2569var node = new Node(), elements = [], rest, restNode;2570expect('[');25712572while (!match(']')) {2573if (match(',')) {2574lex();2575elements.push(null);2576} else {2577if (match('...')) {2578restNode = new Node();2579lex();2580rest = parseVariableIdentifier();2581elements.push(restNode.finishRestElement(rest));2582break;2583} else {2584elements.push(parsePatternWithDefault());2585}2586if (!match(']')) {2587expect(',');2588}2589}25902591}25922593expect(']');25942595return node.finishArrayPattern(elements);2596}25972598function parsePropertyPattern() {2599var node = new Node(), key, computed = match('['), init;2600if (lookahead.type === Token.Identifier) {2601key = parseVariableIdentifier();2602if (match('=')) {2603lex();2604init = parseAssignmentExpression();2605return node.finishProperty(2606'init', key, false,2607new WrappingNode(key).finishAssignmentPattern(key, init), false, false);2608} else if (!match(':')) {2609return node.finishProperty('init', key, false, key, false, true);2610}2611} else {2612key = parseObjectPropertyKey();2613}2614expect(':');2615init = parsePatternWithDefault();2616return node.finishProperty('init', key, computed, init, false, false);2617}26182619function parseObjectPattern() {2620var node = new Node(), properties = [];26212622expect('{');26232624while (!match('}')) {2625properties.push(parsePropertyPattern());2626if (!match('}')) {2627expect(',');2628}2629}26302631lex();26322633return node.finishObjectPattern(properties);2634}26352636function parsePattern() {2637if (lookahead.type === Token.Identifier) {2638return parseVariableIdentifier();2639} else if (match('[')) {2640return parseArrayPattern();2641} else if (match('{')) {2642return parseObjectPattern();2643}2644throwUnexpectedToken(lookahead);2645}26462647function parsePatternWithDefault() {2648var startToken = lookahead, pattern, right;2649pattern = parsePattern();2650if (match('=')) {2651lex();2652right = isolateCoverGrammar(parseAssignmentExpression);2653pattern = new WrappingNode(startToken).finishAssignmentPattern(pattern, right);2654}2655return pattern;2656}26572658// 11.1.4 Array Initialiser26592660function parseArrayInitialiser() {2661var elements = [], node = new Node(), restSpread;26622663expect('[');26642665while (!match(']')) {2666if (match(',')) {2667lex();2668elements.push(null);2669} else if (match('...')) {2670restSpread = new Node();2671lex();2672restSpread.finishSpreadElement(inheritCoverGrammar(parseAssignmentExpression));26732674if (!match(']')) {2675isAssignmentTarget = isBindingElement = false;2676expect(',');2677}2678elements.push(restSpread);2679} else {2680elements.push(inheritCoverGrammar(parseAssignmentExpression));26812682if (!match(']')) {2683expect(',');2684}2685}2686}26872688lex();26892690return node.finishArrayExpression(elements);2691}26922693// 11.1.5 Object Initialiser26942695function parsePropertyFunction(node, paramInfo) {2696var previousStrict, body;26972698isAssignmentTarget = isBindingElement = false;26992700previousStrict = strict;2701body = isolateCoverGrammar(parseFunctionSourceElements);27022703if (strict && paramInfo.firstRestricted) {2704tolerateUnexpectedToken(paramInfo.firstRestricted, paramInfo.message);2705}2706if (strict && paramInfo.stricted) {2707tolerateUnexpectedToken(paramInfo.stricted, paramInfo.message);2708}27092710strict = previousStrict;2711return node.finishFunctionExpression(null, paramInfo.params, paramInfo.defaults, body);2712}27132714function parsePropertyMethodFunction() {2715var params, method, node = new Node();27162717params = parseParams();2718method = parsePropertyFunction(node, params);27192720return method;2721}27222723function parseObjectPropertyKey() {2724var token, node = new Node(), expr;27252726token = lex();27272728// Note: This function is called only from parseObjectProperty(), where2729// EOF and Punctuator tokens are already filtered out.27302731switch (token.type) {2732case Token.StringLiteral:2733case Token.NumericLiteral:2734if (strict && token.octal) {2735tolerateUnexpectedToken(token, Messages.StrictOctalLiteral);2736}2737return node.finishLiteral(token);2738case Token.Identifier:2739case Token.BooleanLiteral:2740case Token.NullLiteral:2741case Token.Keyword:2742return node.finishIdentifier(token.value);2743case Token.Punctuator:2744if (token.value === '[') {2745expr = isolateCoverGrammar(parseAssignmentExpression);2746expect(']');2747return expr;2748}2749break;2750}2751throwUnexpectedToken(token);2752}27532754function lookaheadPropertyName() {2755switch (lookahead.type) {2756case Token.Identifier:2757case Token.StringLiteral:2758case Token.BooleanLiteral:2759case Token.NullLiteral:2760case Token.NumericLiteral:2761case Token.Keyword:2762return true;2763case Token.Punctuator:2764return lookahead.value === '[';2765}2766return false;2767}27682769// This function is to try to parse a MethodDefinition as defined in 14.3. But in the case of object literals,2770// it might be called at a position where there is in fact a short hand identifier pattern or a data property.2771// This can only be determined after we consumed up to the left parentheses.2772//2773// In order to avoid back tracking, it returns `null` if the position is not a MethodDefinition and the caller2774// is responsible to visit other options.2775function tryParseMethodDefinition(token, key, computed, node) {2776var value, options, methodNode;27772778if (token.type === Token.Identifier) {2779// check for `get` and `set`;27802781if (token.value === 'get' && lookaheadPropertyName()) {2782computed = match('[');2783key = parseObjectPropertyKey();2784methodNode = new Node();2785expect('(');2786expect(')');2787value = parsePropertyFunction(methodNode, {2788params: [],2789defaults: [],2790stricted: null,2791firstRestricted: null,2792message: null2793});2794return node.finishProperty('get', key, computed, value, false, false);2795} else if (token.value === 'set' && lookaheadPropertyName()) {2796computed = match('[');2797key = parseObjectPropertyKey();2798methodNode = new Node();2799expect('(');28002801options = {2802params: [],2803defaultCount: 0,2804defaults: [],2805firstRestricted: null,2806paramSet: {}2807};2808if (match(')')) {2809tolerateUnexpectedToken(lookahead);2810} else {2811parseParam(options);2812if (options.defaultCount === 0) {2813options.defaults = [];2814}2815}2816expect(')');28172818value = parsePropertyFunction(methodNode, options);2819return node.finishProperty('set', key, computed, value, false, false);2820}2821}28222823if (match('(')) {2824value = parsePropertyMethodFunction();2825return node.finishProperty('init', key, computed, value, true, false);2826}28272828// Not a MethodDefinition.2829return null;2830}28312832function checkProto(key, computed, hasProto) {2833if (computed === false && (key.type === Syntax.Identifier && key.name === '__proto__' ||2834key.type === Syntax.Literal && key.value === '__proto__')) {2835if (hasProto.value) {2836tolerateError(Messages.DuplicateProtoProperty);2837} else {2838hasProto.value = true;2839}2840}2841}28422843function parseObjectProperty(hasProto) {2844var token = lookahead, node = new Node(), computed, key, maybeMethod, value;28452846computed = match('[');2847key = parseObjectPropertyKey();2848maybeMethod = tryParseMethodDefinition(token, key, computed, node);28492850if (maybeMethod) {2851checkProto(maybeMethod.key, maybeMethod.computed, hasProto);2852// finished2853return maybeMethod;2854}28552856// init property or short hand property.2857checkProto(key, computed, hasProto);28582859if (match(':')) {2860lex();2861value = inheritCoverGrammar(parseAssignmentExpression);2862return node.finishProperty('init', key, computed, value, false, false);2863}28642865if (token.type === Token.Identifier) {2866if (match('=')) {2867firstCoverInitializedNameError = lookahead;2868lex();2869value = isolateCoverGrammar(parseAssignmentExpression);2870return node.finishProperty('init', key, computed,2871new WrappingNode(token).finishAssignmentPattern(key, value), false, true);2872}2873return node.finishProperty('init', key, computed, key, false, true);2874}28752876throwUnexpectedToken(lookahead);2877}28782879function parseObjectInitialiser() {2880var properties = [], hasProto = {value: false}, node = new Node();28812882expect('{');28832884while (!match('}')) {2885properties.push(parseObjectProperty(hasProto));28862887if (!match('}')) {2888expectCommaSeparator();2889}2890}28912892expect('}');28932894return node.finishObjectExpression(properties);2895}28962897function reinterpretExpressionAsPattern(expr) {2898var i;2899switch (expr.type) {2900case Syntax.Identifier:2901case Syntax.MemberExpression:2902case Syntax.RestElement:2903case Syntax.AssignmentPattern:2904break;2905case Syntax.SpreadElement:2906expr.type = Syntax.RestElement;2907reinterpretExpressionAsPattern(expr.argument);2908break;2909case Syntax.ArrayExpression:2910expr.type = Syntax.ArrayPattern;2911for (i = 0; i < expr.elements.length; i++) {2912if (expr.elements[i] !== null) {2913reinterpretExpressionAsPattern(expr.elements[i]);2914}2915}2916break;2917case Syntax.ObjectExpression:2918expr.type = Syntax.ObjectPattern;2919for (i = 0; i < expr.properties.length; i++) {2920reinterpretExpressionAsPattern(expr.properties[i].value);2921}2922break;2923case Syntax.AssignmentExpression:2924expr.type = Syntax.AssignmentPattern;2925reinterpretExpressionAsPattern(expr.left);2926break;2927default:2928// Allow other node type for tolerant parsing.2929break;2930}2931}29322933function parseTemplateElement(option) {2934var node, token;29352936if (lookahead.type !== Token.Template || (option.head && !lookahead.head)) {2937throwUnexpectedToken();2938}29392940node = new Node();2941token = lex();29422943return node.finishTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail);2944}29452946function parseTemplateLiteral() {2947var quasi, quasis, expressions, node = new Node();29482949quasi = parseTemplateElement({ head: true });2950quasis = [ quasi ];2951expressions = [];29522953while (!quasi.tail) {2954expressions.push(parseExpression());2955quasi = parseTemplateElement({ head: false });2956quasis.push(quasi);2957}29582959return node.finishTemplateLiteral(quasis, expressions);2960}29612962// 11.1.6 The Grouping Operator29632964function parseGroupExpression() {2965var expr, expressions, startToken, i;29662967expect('(');29682969if (match(')')) {2970lex();2971if (!match('=>')) {2972expect('=>');2973}2974return {2975type: PlaceHolders.ArrowParameterPlaceHolder,2976params: []2977};2978}29792980startToken = lookahead;2981if (match('...')) {2982expr = parseRestElement();2983expect(')');2984if (!match('=>')) {2985expect('=>');2986}2987return {2988type: PlaceHolders.ArrowParameterPlaceHolder,2989params: [expr]2990};2991}29922993isBindingElement = true;2994expr = inheritCoverGrammar(parseAssignmentExpression);29952996if (match(',')) {2997isAssignmentTarget = false;2998expressions = [expr];29993000while (startIndex < length) {3001if (!match(',')) {3002break;3003}3004lex();30053006if (match('...')) {3007if (!isBindingElement) {3008throwUnexpectedToken(lookahead);3009}3010expressions.push(parseRestElement());3011expect(')');3012if (!match('=>')) {3013expect('=>');3014}3015isBindingElement = false;3016for (i = 0; i < expressions.length; i++) {3017reinterpretExpressionAsPattern(expressions[i]);3018}3019return {3020type: PlaceHolders.ArrowParameterPlaceHolder,3021params: expressions3022};3023}30243025expressions.push(inheritCoverGrammar(parseAssignmentExpression));3026}30273028expr = new WrappingNode(startToken).finishSequenceExpression(expressions);3029}303030313032expect(')');30333034if (match('=>')) {3035if (!isBindingElement) {3036throwUnexpectedToken(lookahead);3037}30383039if (expr.type === Syntax.SequenceExpression) {3040for (i = 0; i < expr.expressions.length; i++) {3041reinterpretExpressionAsPattern(expr.expressions[i]);3042}3043} else {3044reinterpretExpressionAsPattern(expr);3045}30463047expr = {3048type: PlaceHolders.ArrowParameterPlaceHolder,3049params: expr.type === Syntax.SequenceExpression ? expr.expressions : [expr]3050};3051}3052isBindingElement = false;3053return expr;3054}305530563057// 11.1 Primary Expressions30583059function parsePrimaryExpression() {3060var type, token, expr, node;30613062if (match('(')) {3063isBindingElement = false;3064return inheritCoverGrammar(parseGroupExpression);3065}30663067if (match('[')) {3068return inheritCoverGrammar(parseArrayInitialiser);3069}30703071if (match('{')) {3072return inheritCoverGrammar(parseObjectInitialiser);3073}30743075type = lookahead.type;3076node = new Node();30773078if (type === Token.Identifier) {3079expr = node.finishIdentifier(lex().value);3080} else if (type === Token.StringLiteral || type === Token.NumericLiteral) {3081isAssignmentTarget = isBindingElement = false;3082if (strict && lookahead.octal) {3083tolerateUnexpectedToken(lookahead, Messages.StrictOctalLiteral);3084}3085expr = node.finishLiteral(lex());3086} else if (type === Token.Keyword) {3087isAssignmentTarget = isBindingElement = false;3088if (matchKeyword('function')) {3089return parseFunctionExpression();3090}3091if (matchKeyword('this')) {3092lex();3093return node.finishThisExpression();3094}3095if (matchKeyword('class')) {3096return parseClassExpression();3097}3098throwUnexpectedToken(lex());3099} else if (type === Token.BooleanLiteral) {3100isAssignmentTarget = isBindingElement = false;3101token = lex();3102token.value = (token.value === 'true');3103expr = node.finishLiteral(token);3104} else if (type === Token.NullLiteral) {3105isAssignmentTarget = isBindingElement = false;3106token = lex();3107token.value = null;3108expr = node.finishLiteral(token);3109} else if (match('/') || match('/=')) {3110isAssignmentTarget = isBindingElement = false;3111index = startIndex;31123113if (typeof extra.tokens !== 'undefined') {3114token = collectRegex();3115} else {3116token = scanRegExp();3117}3118lex();3119expr = node.finishLiteral(token);3120} else if (type === Token.Template) {3121expr = parseTemplateLiteral();3122} else {3123throwUnexpectedToken(lex());3124}31253126return expr;3127}31283129// 11.2 Left-Hand-Side Expressions31303131function parseArguments() {3132var args = [];31333134expect('(');31353136if (!match(')')) {3137while (startIndex < length) {3138args.push(isolateCoverGrammar(parseAssignmentExpression));3139if (match(')')) {3140break;3141}3142expectCommaSeparator();3143}3144}31453146expect(')');31473148return args;3149}31503151function parseNonComputedProperty() {3152var token, node = new Node();31533154token = lex();31553156if (!isIdentifierName(token)) {3157throwUnexpectedToken(token);3158}31593160return node.finishIdentifier(token.value);3161}31623163function parseNonComputedMember() {3164expect('.');31653166return parseNonComputedProperty();3167}31683169function parseComputedMember() {3170var expr;31713172expect('[');31733174expr = isolateCoverGrammar(parseExpression);31753176expect(']');31773178return expr;3179}31803181function parseNewExpression() {3182var callee, args, node = new Node();31833184expectKeyword('new');3185callee = isolateCoverGrammar(parseLeftHandSideExpression);3186args = match('(') ? parseArguments() : [];31873188isAssignmentTarget = isBindingElement = false;31893190return node.finishNewExpression(callee, args);3191}31923193function parseLeftHandSideExpressionAllowCall() {3194var quasi, expr, args, property, startToken, previousAllowIn = state.allowIn;31953196startToken = lookahead;3197state.allowIn = true;31983199if (matchKeyword('super') && state.inFunctionBody) {3200expr = new Node();3201lex();3202expr = expr.finishSuper();3203if (!match('(') && !match('.') && !match('[')) {3204throwUnexpectedToken(lookahead);3205}3206} else {3207expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);3208}32093210for (;;) {3211if (match('.')) {3212isBindingElement = false;3213isAssignmentTarget = true;3214property = parseNonComputedMember();3215expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);3216} else if (match('(')) {3217isBindingElement = false;3218isAssignmentTarget = false;3219args = parseArguments();3220expr = new WrappingNode(startToken).finishCallExpression(expr, args);3221} else if (match('[')) {3222isBindingElement = false;3223isAssignmentTarget = true;3224property = parseComputedMember();3225expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);3226} else if (lookahead.type === Token.Template && lookahead.head) {3227quasi = parseTemplateLiteral();3228expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);3229} else {3230break;3231}3232}3233state.allowIn = previousAllowIn;32343235return expr;3236}32373238function parseLeftHandSideExpression() {3239var quasi, expr, property, startToken;3240assert(state.allowIn, 'callee of new expression always allow in keyword.');32413242startToken = lookahead;32433244if (matchKeyword('super') && state.inFunctionBody) {3245expr = new Node();3246lex();3247expr = expr.finishSuper();3248if (!match('[') && !match('.')) {3249throwUnexpectedToken(lookahead);3250}3251} else {3252expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);3253}32543255for (;;) {3256if (match('[')) {3257isBindingElement = false;3258isAssignmentTarget = true;3259property = parseComputedMember();3260expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);3261} else if (match('.')) {3262isBindingElement = false;3263isAssignmentTarget = true;3264property = parseNonComputedMember();3265expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);3266} else if (lookahead.type === Token.Template && lookahead.head) {3267quasi = parseTemplateLiteral();3268expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);3269} else {3270break;3271}3272}3273return expr;3274}32753276// 11.3 Postfix Expressions32773278function parsePostfixExpression() {3279var expr, token, startToken = lookahead;32803281expr = inheritCoverGrammar(parseLeftHandSideExpressionAllowCall);32823283if (!hasLineTerminator && lookahead.type === Token.Punctuator) {3284if (match('++') || match('--')) {3285// 11.3.1, 11.3.23286if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3287tolerateError(Messages.StrictLHSPostfix);3288}32893290if (!isAssignmentTarget) {3291tolerateError(Messages.InvalidLHSInAssignment);3292}32933294isAssignmentTarget = isBindingElement = false;32953296token = lex();3297expr = new WrappingNode(startToken).finishPostfixExpression(token.value, expr);3298}3299}33003301return expr;3302}33033304// 11.4 Unary Operators33053306function parseUnaryExpression() {3307var token, expr, startToken;33083309if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {3310expr = parsePostfixExpression();3311} else if (match('++') || match('--')) {3312startToken = lookahead;3313token = lex();3314expr = inheritCoverGrammar(parseUnaryExpression);3315// 11.4.4, 11.4.53316if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3317tolerateError(Messages.StrictLHSPrefix);3318}33193320if (!isAssignmentTarget) {3321tolerateError(Messages.InvalidLHSInAssignment);3322}3323expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);3324isAssignmentTarget = isBindingElement = false;3325} else if (match('+') || match('-') || match('~') || match('!')) {3326startToken = lookahead;3327token = lex();3328expr = inheritCoverGrammar(parseUnaryExpression);3329expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);3330isAssignmentTarget = isBindingElement = false;3331} else if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {3332startToken = lookahead;3333token = lex();3334expr = inheritCoverGrammar(parseUnaryExpression);3335expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);3336if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {3337tolerateError(Messages.StrictDelete);3338}3339isAssignmentTarget = isBindingElement = false;3340} else {3341expr = parsePostfixExpression();3342}33433344return expr;3345}33463347function binaryPrecedence(token, allowIn) {3348var prec = 0;33493350if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {3351return 0;3352}33533354switch (token.value) {3355case '||':3356prec = 1;3357break;33583359case '&&':3360prec = 2;3361break;33623363case '|':3364prec = 3;3365break;33663367case '^':3368prec = 4;3369break;33703371case '&':3372prec = 5;3373break;33743375case '==':3376case '!=':3377case '===':3378case '!==':3379prec = 6;3380break;33813382case '<':3383case '>':3384case '<=':3385case '>=':3386case 'instanceof':3387prec = 7;3388break;33893390case 'in':3391prec = allowIn ? 7 : 0;3392break;33933394case '<<':3395case '>>':3396case '>>>':3397prec = 8;3398break;33993400case '+':3401case '-':3402prec = 9;3403break;34043405case '*':3406case '/':3407case '%':3408prec = 11;3409break;34103411default:3412break;3413}34143415return prec;3416}34173418// 11.5 Multiplicative Operators3419// 11.6 Additive Operators3420// 11.7 Bitwise Shift Operators3421// 11.8 Relational Operators3422// 11.9 Equality Operators3423// 11.10 Binary Bitwise Operators3424// 11.11 Binary Logical Operators34253426function parseBinaryExpression() {3427var marker, markers, expr, token, prec, stack, right, operator, left, i;34283429marker = lookahead;3430left = inheritCoverGrammar(parseUnaryExpression);34313432token = lookahead;3433prec = binaryPrecedence(token, state.allowIn);3434if (prec === 0) {3435return left;3436}3437isAssignmentTarget = isBindingElement = false;3438token.prec = prec;3439lex();34403441markers = [marker, lookahead];3442right = isolateCoverGrammar(parseUnaryExpression);34433444stack = [left, token, right];34453446while ((prec = binaryPrecedence(lookahead, state.allowIn)) > 0) {34473448// Reduce: make a binary expression from the three topmost entries.3449while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {3450right = stack.pop();3451operator = stack.pop().value;3452left = stack.pop();3453markers.pop();3454expr = new WrappingNode(markers[markers.length - 1]).finishBinaryExpression(operator, left, right);3455stack.push(expr);3456}34573458// Shift.3459token = lex();3460token.prec = prec;3461stack.push(token);3462markers.push(lookahead);3463expr = isolateCoverGrammar(parseUnaryExpression);3464stack.push(expr);3465}34663467// Final reduce to clean-up the stack.3468i = stack.length - 1;3469expr = stack[i];3470markers.pop();3471while (i > 1) {3472expr = new WrappingNode(markers.pop()).finishBinaryExpression(stack[i - 1].value, stack[i - 2], expr);3473i -= 2;3474}34753476return expr;3477}347834793480// 11.12 Conditional Operator34813482function parseConditionalExpression() {3483var expr, previousAllowIn, consequent, alternate, startToken;34843485startToken = lookahead;34863487expr = inheritCoverGrammar(parseBinaryExpression);3488if (match('?')) {3489lex();3490previousAllowIn = state.allowIn;3491state.allowIn = true;3492consequent = isolateCoverGrammar(parseAssignmentExpression);3493state.allowIn = previousAllowIn;3494expect(':');3495alternate = isolateCoverGrammar(parseAssignmentExpression);34963497expr = new WrappingNode(startToken).finishConditionalExpression(expr, consequent, alternate);3498isAssignmentTarget = isBindingElement = false;3499}35003501return expr;3502}35033504// [ES6] 14.2 Arrow Function35053506function parseConciseBody() {3507if (match('{')) {3508return parseFunctionSourceElements();3509}3510return isolateCoverGrammar(parseAssignmentExpression);3511}35123513function checkPatternParam(options, param) {3514var i;3515switch (param.type) {3516case Syntax.Identifier:3517validateParam(options, param, param.name);3518break;3519case Syntax.RestElement:3520checkPatternParam(options, param.argument);3521break;3522case Syntax.AssignmentPattern:3523checkPatternParam(options, param.left);3524break;3525case Syntax.ArrayPattern:3526for (i = 0; i < param.elements.length; i++) {3527if (param.elements[i] !== null) {3528checkPatternParam(options, param.elements[i]);3529}3530}3531break;3532default:3533assert(param.type === Syntax.ObjectPattern, 'Invalid type');3534for (i = 0; i < param.properties.length; i++) {3535checkPatternParam(options, param.properties[i].value);3536}3537break;3538}3539}3540function reinterpretAsCoverFormalsList(expr) {3541var i, len, param, params, defaults, defaultCount, options, token;35423543defaults = [];3544defaultCount = 0;3545params = [expr];35463547switch (expr.type) {3548case Syntax.Identifier:3549break;3550case PlaceHolders.ArrowParameterPlaceHolder:3551params = expr.params;3552break;3553default:3554return null;3555}35563557options = {3558paramSet: {}3559};35603561for (i = 0, len = params.length; i < len; i += 1) {3562param = params[i];3563switch (param.type) {3564case Syntax.AssignmentPattern:3565params[i] = param.left;3566defaults.push(param.right);3567++defaultCount;3568checkPatternParam(options, param.left);3569break;3570default:3571checkPatternParam(options, param);3572params[i] = param;3573defaults.push(null);3574break;3575}3576}35773578if (options.message === Messages.StrictParamDupe) {3579token = strict ? options.stricted : options.firstRestricted;3580throwUnexpectedToken(token, options.message);3581}35823583if (defaultCount === 0) {3584defaults = [];3585}35863587return {3588params: params,3589defaults: defaults,3590stricted: options.stricted,3591firstRestricted: options.firstRestricted,3592message: options.message3593};3594}35953596function parseArrowFunctionExpression(options, node) {3597var previousStrict, body;35983599if (hasLineTerminator) {3600tolerateUnexpectedToken(lookahead);3601}3602expect('=>');3603previousStrict = strict;36043605body = parseConciseBody();36063607if (strict && options.firstRestricted) {3608throwUnexpectedToken(options.firstRestricted, options.message);3609}3610if (strict && options.stricted) {3611tolerateUnexpectedToken(options.stricted, options.message);3612}36133614strict = previousStrict;36153616return node.finishArrowFunctionExpression(options.params, options.defaults, body, body.type !== Syntax.BlockStatement);3617}36183619// 11.13 Assignment Operators36203621function parseAssignmentExpression() {3622var token, expr, right, list, startToken;36233624startToken = lookahead;3625token = lookahead;36263627expr = parseConditionalExpression();36283629if (expr.type === PlaceHolders.ArrowParameterPlaceHolder || match('=>')) {3630isAssignmentTarget = isBindingElement = false;3631list = reinterpretAsCoverFormalsList(expr);36323633if (list) {3634firstCoverInitializedNameError = null;3635return parseArrowFunctionExpression(list, new WrappingNode(startToken));3636}36373638return expr;3639}36403641if (matchAssign()) {3642if (!isAssignmentTarget) {3643tolerateError(Messages.InvalidLHSInAssignment);3644}36453646// 11.13.13647if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3648tolerateUnexpectedToken(token, Messages.StrictLHSAssignment);3649}36503651if (!match('=')) {3652isAssignmentTarget = isBindingElement = false;3653} else {3654reinterpretExpressionAsPattern(expr);3655}36563657token = lex();3658right = isolateCoverGrammar(parseAssignmentExpression);3659expr = new WrappingNode(startToken).finishAssignmentExpression(token.value, expr, right);3660firstCoverInitializedNameError = null;3661}36623663return expr;3664}36653666// 11.14 Comma Operator36673668function parseExpression() {3669var expr, startToken = lookahead, expressions;36703671expr = isolateCoverGrammar(parseAssignmentExpression);36723673if (match(',')) {3674expressions = [expr];36753676while (startIndex < length) {3677if (!match(',')) {3678break;3679}3680lex();3681expressions.push(isolateCoverGrammar(parseAssignmentExpression));3682}36833684expr = new WrappingNode(startToken).finishSequenceExpression(expressions);3685}36863687return expr;3688}36893690// 12.1 Block36913692function parseStatementListItem() {3693if (lookahead.type === Token.Keyword) {3694switch (lookahead.value) {3695case 'export':3696if (sourceType !== 'module') {3697tolerateUnexpectedToken(lookahead, Messages.IllegalExportDeclaration);3698}3699return parseExportDeclaration();3700case 'import':3701if (sourceType !== 'module') {3702tolerateUnexpectedToken(lookahead, Messages.IllegalImportDeclaration);3703}3704return parseImportDeclaration();3705case 'const':3706case 'let':3707return parseLexicalDeclaration({inFor: false});3708case 'function':3709return parseFunctionDeclaration(new Node());3710case 'class':3711return parseClassDeclaration();3712}3713}37143715return parseStatement();3716}37173718function parseStatementList() {3719var list = [];3720while (startIndex < length) {3721if (match('}')) {3722break;3723}3724list.push(parseStatementListItem());3725}37263727return list;3728}37293730function parseBlock() {3731var block, node = new Node();37323733expect('{');37343735block = parseStatementList();37363737expect('}');37383739return node.finishBlockStatement(block);3740}37413742// 12.2 Variable Statement37433744function parseVariableIdentifier() {3745var token, node = new Node();37463747token = lex();37483749if (token.type !== Token.Identifier) {3750if (strict && token.type === Token.Keyword && isStrictModeReservedWord(token.value)) {3751tolerateUnexpectedToken(token, Messages.StrictReservedWord);3752} else {3753throwUnexpectedToken(token);3754}3755}37563757return node.finishIdentifier(token.value);3758}37593760function parseVariableDeclaration() {3761var init = null, id, node = new Node();37623763id = parsePattern();37643765// 12.2.13766if (strict && isRestrictedWord(id.name)) {3767tolerateError(Messages.StrictVarName);3768}37693770if (match('=')) {3771lex();3772init = isolateCoverGrammar(parseAssignmentExpression);3773} else if (id.type !== Syntax.Identifier) {3774expect('=');3775}37763777return node.finishVariableDeclarator(id, init);3778}37793780function parseVariableDeclarationList() {3781var list = [];37823783do {3784list.push(parseVariableDeclaration());3785if (!match(',')) {3786break;3787}3788lex();3789} while (startIndex < length);37903791return list;3792}37933794function parseVariableStatement(node) {3795var declarations;37963797expectKeyword('var');37983799declarations = parseVariableDeclarationList();38003801consumeSemicolon();38023803return node.finishVariableDeclaration(declarations);3804}38053806function parseLexicalBinding(kind, options) {3807var init = null, id, node = new Node();38083809id = parsePattern();38103811// 12.2.13812if (strict && id.type === Syntax.Identifier && isRestrictedWord(id.name)) {3813tolerateError(Messages.StrictVarName);3814}38153816if (kind === 'const') {3817if (!matchKeyword('in')) {3818expect('=');3819init = isolateCoverGrammar(parseAssignmentExpression);3820}3821} else if ((!options.inFor && id.type !== Syntax.Identifier) || match('=')) {3822expect('=');3823init = isolateCoverGrammar(parseAssignmentExpression);3824}38253826return node.finishVariableDeclarator(id, init);3827}38283829function parseBindingList(kind, options) {3830var list = [];38313832do {3833list.push(parseLexicalBinding(kind, options));3834if (!match(',')) {3835break;3836}3837lex();3838} while (startIndex < length);38393840return list;3841}38423843function parseLexicalDeclaration(options) {3844var kind, declarations, node = new Node();38453846kind = lex().value;3847assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');38483849declarations = parseBindingList(kind, options);38503851consumeSemicolon();38523853return node.finishLexicalDeclaration(declarations, kind);3854}38553856function parseRestElement() {3857var param, node = new Node();38583859lex();38603861if (match('{')) {3862throwError(Messages.ObjectPatternAsRestParameter);3863}38643865param = parseVariableIdentifier();38663867if (match('=')) {3868throwError(Messages.DefaultRestParameter);3869}38703871if (!match(')')) {3872throwError(Messages.ParameterAfterRestParameter);3873}38743875return node.finishRestElement(param);3876}38773878// 12.3 Empty Statement38793880function parseEmptyStatement(node) {3881expect(';');3882return node.finishEmptyStatement();3883}38843885// 12.4 Expression Statement38863887function parseExpressionStatement(node) {3888var expr = parseExpression();3889consumeSemicolon();3890return node.finishExpressionStatement(expr);3891}38923893// 12.5 If statement38943895function parseIfStatement(node) {3896var test, consequent, alternate;38973898expectKeyword('if');38993900expect('(');39013902test = parseExpression();39033904expect(')');39053906consequent = parseStatement();39073908if (matchKeyword('else')) {3909lex();3910alternate = parseStatement();3911} else {3912alternate = null;3913}39143915return node.finishIfStatement(test, consequent, alternate);3916}39173918// 12.6 Iteration Statements39193920function parseDoWhileStatement(node) {3921var body, test, oldInIteration;39223923expectKeyword('do');39243925oldInIteration = state.inIteration;3926state.inIteration = true;39273928body = parseStatement();39293930state.inIteration = oldInIteration;39313932expectKeyword('while');39333934expect('(');39353936test = parseExpression();39373938expect(')');39393940if (match(';')) {3941lex();3942}39433944return node.finishDoWhileStatement(body, test);3945}39463947function parseWhileStatement(node) {3948var test, body, oldInIteration;39493950expectKeyword('while');39513952expect('(');39533954test = parseExpression();39553956expect(')');39573958oldInIteration = state.inIteration;3959state.inIteration = true;39603961body = parseStatement();39623963state.inIteration = oldInIteration;39643965return node.finishWhileStatement(test, body);3966}39673968function parseForStatement(node) {3969var init, initSeq, initStartToken, test, update, left, right, kind, declarations,3970body, oldInIteration, previousAllowIn = state.allowIn;39713972init = test = update = null;39733974expectKeyword('for');39753976expect('(');39773978if (match(';')) {3979lex();3980} else {3981if (matchKeyword('var')) {3982init = new Node();3983lex();39843985state.allowIn = false;3986init = init.finishVariableDeclaration(parseVariableDeclarationList());3987state.allowIn = previousAllowIn;39883989if (init.declarations.length === 1 && matchKeyword('in')) {3990lex();3991left = init;3992right = parseExpression();3993init = null;3994} else {3995expect(';');3996}3997} else if (matchKeyword('const') || matchKeyword('let')) {3998init = new Node();3999kind = lex().value;40004001state.allowIn = false;4002declarations = parseBindingList(kind, {inFor: true});4003state.allowIn = previousAllowIn;40044005if (declarations.length === 1 && declarations[0].init === null && matchKeyword('in')) {4006init = init.finishLexicalDeclaration(declarations, kind);4007lex();4008left = init;4009right = parseExpression();4010init = null;4011} else {4012consumeSemicolon();4013init = init.finishLexicalDeclaration(declarations, kind);4014}4015} else {4016initStartToken = lookahead;4017state.allowIn = false;4018init = inheritCoverGrammar(parseAssignmentExpression);4019state.allowIn = previousAllowIn;40204021if (matchKeyword('in')) {4022if (!isAssignmentTarget) {4023tolerateError(Messages.InvalidLHSInForIn);4024}40254026lex();4027reinterpretExpressionAsPattern(init);4028left = init;4029right = parseExpression();4030init = null;4031} else {4032if (match(',')) {4033initSeq = [init];4034while (match(',')) {4035lex();4036initSeq.push(isolateCoverGrammar(parseAssignmentExpression));4037}4038init = new WrappingNode(initStartToken).finishSequenceExpression(initSeq);4039}4040expect(';');4041}4042}4043}40444045if (typeof left === 'undefined') {40464047if (!match(';')) {4048test = parseExpression();4049}4050expect(';');40514052if (!match(')')) {4053update = parseExpression();4054}4055}40564057expect(')');40584059oldInIteration = state.inIteration;4060state.inIteration = true;40614062body = isolateCoverGrammar(parseStatement);40634064state.inIteration = oldInIteration;40654066return (typeof left === 'undefined') ?4067node.finishForStatement(init, test, update, body) :4068node.finishForInStatement(left, right, body);4069}40704071// 12.7 The continue statement40724073function parseContinueStatement(node) {4074var label = null, key;40754076expectKeyword('continue');40774078// Optimize the most common form: 'continue;'.4079if (source.charCodeAt(startIndex) === 0x3B) {4080lex();40814082if (!state.inIteration) {4083throwError(Messages.IllegalContinue);4084}40854086return node.finishContinueStatement(null);4087}40884089if (hasLineTerminator) {4090if (!state.inIteration) {4091throwError(Messages.IllegalContinue);4092}40934094return node.finishContinueStatement(null);4095}40964097if (lookahead.type === Token.Identifier) {4098label = parseVariableIdentifier();40994100key = '$' + label.name;4101if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {4102throwError(Messages.UnknownLabel, label.name);4103}4104}41054106consumeSemicolon();41074108if (label === null && !state.inIteration) {4109throwError(Messages.IllegalContinue);4110}41114112return node.finishContinueStatement(label);4113}41144115// 12.8 The break statement41164117function parseBreakStatement(node) {4118var label = null, key;41194120expectKeyword('break');41214122// Catch the very common case first: immediately a semicolon (U+003B).4123if (source.charCodeAt(lastIndex) === 0x3B) {4124lex();41254126if (!(state.inIteration || state.inSwitch)) {4127throwError(Messages.IllegalBreak);4128}41294130return node.finishBreakStatement(null);4131}41324133if (hasLineTerminator) {4134if (!(state.inIteration || state.inSwitch)) {4135throwError(Messages.IllegalBreak);4136}41374138return node.finishBreakStatement(null);4139}41404141if (lookahead.type === Token.Identifier) {4142label = parseVariableIdentifier();41434144key = '$' + label.name;4145if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {4146throwError(Messages.UnknownLabel, label.name);4147}4148}41494150consumeSemicolon();41514152if (label === null && !(state.inIteration || state.inSwitch)) {4153throwError(Messages.IllegalBreak);4154}41554156return node.finishBreakStatement(label);4157}41584159// 12.9 The return statement41604161function parseReturnStatement(node) {4162var argument = null;41634164expectKeyword('return');41654166if (!state.inFunctionBody) {4167tolerateError(Messages.IllegalReturn);4168}41694170// 'return' followed by a space and an identifier is very common.4171if (source.charCodeAt(lastIndex) === 0x20) {4172if (isIdentifierStart(source.charCodeAt(lastIndex + 1))) {4173argument = parseExpression();4174consumeSemicolon();4175return node.finishReturnStatement(argument);4176}4177}41784179if (hasLineTerminator) {4180// HACK4181return node.finishReturnStatement(null);4182}41834184if (!match(';')) {4185if (!match('}') && lookahead.type !== Token.EOF) {4186argument = parseExpression();4187}4188}41894190consumeSemicolon();41914192return node.finishReturnStatement(argument);4193}41944195// 12.10 The with statement41964197function parseWithStatement(node) {4198var object, body;41994200if (strict) {4201tolerateError(Messages.StrictModeWith);4202}42034204expectKeyword('with');42054206expect('(');42074208object = parseExpression();42094210expect(')');42114212body = parseStatement();42134214return node.finishWithStatement(object, body);4215}42164217// 12.10 The swith statement42184219function parseSwitchCase() {4220var test, consequent = [], statement, node = new Node();42214222if (matchKeyword('default')) {4223lex();4224test = null;4225} else {4226expectKeyword('case');4227test = parseExpression();4228}4229expect(':');42304231while (startIndex < length) {4232if (match('}') || matchKeyword('default') || matchKeyword('case')) {4233break;4234}4235statement = parseStatementListItem();4236consequent.push(statement);4237}42384239return node.finishSwitchCase(test, consequent);4240}42414242function parseSwitchStatement(node) {4243var discriminant, cases, clause, oldInSwitch, defaultFound;42444245expectKeyword('switch');42464247expect('(');42484249discriminant = parseExpression();42504251expect(')');42524253expect('{');42544255cases = [];42564257if (match('}')) {4258lex();4259return node.finishSwitchStatement(discriminant, cases);4260}42614262oldInSwitch = state.inSwitch;4263state.inSwitch = true;4264defaultFound = false;42654266while (startIndex < length) {4267if (match('}')) {4268break;4269}4270clause = parseSwitchCase();4271if (clause.test === null) {4272if (defaultFound) {4273throwError(Messages.MultipleDefaultsInSwitch);4274}4275defaultFound = true;4276}4277cases.push(clause);4278}42794280state.inSwitch = oldInSwitch;42814282expect('}');42834284return node.finishSwitchStatement(discriminant, cases);4285}42864287// 12.13 The throw statement42884289function parseThrowStatement(node) {4290var argument;42914292expectKeyword('throw');42934294if (hasLineTerminator) {4295throwError(Messages.NewlineAfterThrow);4296}42974298argument = parseExpression();42994300consumeSemicolon();43014302return node.finishThrowStatement(argument);4303}43044305// 12.14 The try statement43064307function parseCatchClause() {4308var param, body, node = new Node();43094310expectKeyword('catch');43114312expect('(');4313if (match(')')) {4314throwUnexpectedToken(lookahead);4315}43164317param = parsePattern();43184319// 12.14.14320if (strict && isRestrictedWord(param.name)) {4321tolerateError(Messages.StrictCatchVariable);4322}43234324expect(')');4325body = parseBlock();4326return node.finishCatchClause(param, body);4327}43284329function parseTryStatement(node) {4330var block, handler = null, finalizer = null;43314332expectKeyword('try');43334334block = parseBlock();43354336if (matchKeyword('catch')) {4337handler = parseCatchClause();4338}43394340if (matchKeyword('finally')) {4341lex();4342finalizer = parseBlock();4343}43444345if (!handler && !finalizer) {4346throwError(Messages.NoCatchOrFinally);4347}43484349return node.finishTryStatement(block, handler, finalizer);4350}43514352// 12.15 The debugger statement43534354function parseDebuggerStatement(node) {4355expectKeyword('debugger');43564357consumeSemicolon();43584359return node.finishDebuggerStatement();4360}43614362// 12 Statements43634364function parseStatement() {4365var type = lookahead.type,4366expr,4367labeledBody,4368key,4369node;43704371if (type === Token.EOF) {4372throwUnexpectedToken(lookahead);4373}43744375if (type === Token.Punctuator && lookahead.value === '{') {4376return parseBlock();4377}4378isAssignmentTarget = isBindingElement = true;4379node = new Node();43804381if (type === Token.Punctuator) {4382switch (lookahead.value) {4383case ';':4384return parseEmptyStatement(node);4385case '(':4386return parseExpressionStatement(node);4387default:4388break;4389}4390} else if (type === Token.Keyword) {4391switch (lookahead.value) {4392case 'break':4393return parseBreakStatement(node);4394case 'continue':4395return parseContinueStatement(node);4396case 'debugger':4397return parseDebuggerStatement(node);4398case 'do':4399return parseDoWhileStatement(node);4400case 'for':4401return parseForStatement(node);4402case 'function':4403return parseFunctionDeclaration(node);4404case 'if':4405return parseIfStatement(node);4406case 'return':4407return parseReturnStatement(node);4408case 'switch':4409return parseSwitchStatement(node);4410case 'throw':4411return parseThrowStatement(node);4412case 'try':4413return parseTryStatement(node);4414case 'var':4415return parseVariableStatement(node);4416case 'while':4417return parseWhileStatement(node);4418case 'with':4419return parseWithStatement(node);4420default:4421break;4422}4423}44244425expr = parseExpression();44264427// 12.12 Labelled Statements4428if ((expr.type === Syntax.Identifier) && match(':')) {4429lex();44304431key = '$' + expr.name;4432if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {4433throwError(Messages.Redeclaration, 'Label', expr.name);4434}44354436state.labelSet[key] = true;4437labeledBody = parseStatement();4438delete state.labelSet[key];4439return node.finishLabeledStatement(expr, labeledBody);4440}44414442consumeSemicolon();44434444return node.finishExpressionStatement(expr);4445}44464447// 13 Function Definition44484449function parseFunctionSourceElements() {4450var statement, body = [], token, directive, firstRestricted,4451oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, oldParenthesisCount,4452node = new Node();44534454expect('{');44554456while (startIndex < length) {4457if (lookahead.type !== Token.StringLiteral) {4458break;4459}4460token = lookahead;44614462statement = parseStatementListItem();4463body.push(statement);4464if (statement.expression.type !== Syntax.Literal) {4465// this is not directive4466break;4467}4468directive = source.slice(token.start + 1, token.end - 1);4469if (directive === 'use strict') {4470strict = true;4471if (firstRestricted) {4472tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);4473}4474} else {4475if (!firstRestricted && token.octal) {4476firstRestricted = token;4477}4478}4479}44804481oldLabelSet = state.labelSet;4482oldInIteration = state.inIteration;4483oldInSwitch = state.inSwitch;4484oldInFunctionBody = state.inFunctionBody;4485oldParenthesisCount = state.parenthesizedCount;44864487state.labelSet = {};4488state.inIteration = false;4489state.inSwitch = false;4490state.inFunctionBody = true;4491state.parenthesizedCount = 0;44924493while (startIndex < length) {4494if (match('}')) {4495break;4496}4497body.push(parseStatementListItem());4498}44994500expect('}');45014502state.labelSet = oldLabelSet;4503state.inIteration = oldInIteration;4504state.inSwitch = oldInSwitch;4505state.inFunctionBody = oldInFunctionBody;4506state.parenthesizedCount = oldParenthesisCount;45074508return node.finishBlockStatement(body);4509}45104511function validateParam(options, param, name) {4512var key = '$' + name;4513if (strict) {4514if (isRestrictedWord(name)) {4515options.stricted = param;4516options.message = Messages.StrictParamName;4517}4518if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {4519options.stricted = param;4520options.message = Messages.StrictParamDupe;4521}4522} else if (!options.firstRestricted) {4523if (isRestrictedWord(name)) {4524options.firstRestricted = param;4525options.message = Messages.StrictParamName;4526} else if (isStrictModeReservedWord(name)) {4527options.firstRestricted = param;4528options.message = Messages.StrictReservedWord;4529} else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {4530options.firstRestricted = param;4531options.message = Messages.StrictParamDupe;4532}4533}4534options.paramSet[key] = true;4535}45364537function parseParam(options) {4538var token, param, def;45394540token = lookahead;4541if (token.value === '...') {4542param = parseRestElement();4543validateParam(options, param.argument, param.argument.name);4544options.params.push(param);4545options.defaults.push(null);4546return false;4547}45484549param = parsePatternWithDefault();4550validateParam(options, token, token.value);45514552if (param.type === Syntax.AssignmentPattern) {4553def = param.right;4554param = param.left;4555++options.defaultCount;4556}45574558options.params.push(param);4559options.defaults.push(def);45604561return !match(')');4562}45634564function parseParams(firstRestricted) {4565var options;45664567options = {4568params: [],4569defaultCount: 0,4570defaults: [],4571firstRestricted: firstRestricted4572};45734574expect('(');45754576if (!match(')')) {4577options.paramSet = {};4578while (startIndex < length) {4579if (!parseParam(options)) {4580break;4581}4582expect(',');4583}4584}45854586expect(')');45874588if (options.defaultCount === 0) {4589options.defaults = [];4590}45914592return {4593params: options.params,4594defaults: options.defaults,4595stricted: options.stricted,4596firstRestricted: options.firstRestricted,4597message: options.message4598};4599}46004601function parseFunctionDeclaration(node, identifierIsOptional) {4602var id = null, params = [], defaults = [], body, token, stricted, tmp, firstRestricted, message, previousStrict;46034604expectKeyword('function');4605if (!identifierIsOptional || !match('(')) {4606token = lookahead;4607id = parseVariableIdentifier();4608if (strict) {4609if (isRestrictedWord(token.value)) {4610tolerateUnexpectedToken(token, Messages.StrictFunctionName);4611}4612} else {4613if (isRestrictedWord(token.value)) {4614firstRestricted = token;4615message = Messages.StrictFunctionName;4616} else if (isStrictModeReservedWord(token.value)) {4617firstRestricted = token;4618message = Messages.StrictReservedWord;4619}4620}4621}46224623tmp = parseParams(firstRestricted);4624params = tmp.params;4625defaults = tmp.defaults;4626stricted = tmp.stricted;4627firstRestricted = tmp.firstRestricted;4628if (tmp.message) {4629message = tmp.message;4630}46314632previousStrict = strict;4633body = parseFunctionSourceElements();4634if (strict && firstRestricted) {4635throwUnexpectedToken(firstRestricted, message);4636}4637if (strict && stricted) {4638tolerateUnexpectedToken(stricted, message);4639}4640strict = previousStrict;46414642return node.finishFunctionDeclaration(id, params, defaults, body);4643}46444645function parseFunctionExpression() {4646var token, id = null, stricted, firstRestricted, message, tmp,4647params = [], defaults = [], body, previousStrict, node = new Node();46484649expectKeyword('function');46504651if (!match('(')) {4652token = lookahead;4653id = parseVariableIdentifier();4654if (strict) {4655if (isRestrictedWord(token.value)) {4656tolerateUnexpectedToken(token, Messages.StrictFunctionName);4657}4658} else {4659if (isRestrictedWord(token.value)) {4660firstRestricted = token;4661message = Messages.StrictFunctionName;4662} else if (isStrictModeReservedWord(token.value)) {4663firstRestricted = token;4664message = Messages.StrictReservedWord;4665}4666}4667}46684669tmp = parseParams(firstRestricted);4670params = tmp.params;4671defaults = tmp.defaults;4672stricted = tmp.stricted;4673firstRestricted = tmp.firstRestricted;4674if (tmp.message) {4675message = tmp.message;4676}46774678previousStrict = strict;4679body = parseFunctionSourceElements();4680if (strict && firstRestricted) {4681throwUnexpectedToken(firstRestricted, message);4682}4683if (strict && stricted) {4684tolerateUnexpectedToken(stricted, message);4685}4686strict = previousStrict;46874688return node.finishFunctionExpression(id, params, defaults, body);4689}469046914692function parseClassBody() {4693var classBody, token, isStatic, hasConstructor = false, body, method, computed, key;46944695classBody = new Node();46964697expect('{');4698body = [];4699while (!match('}')) {4700if (match(';')) {4701lex();4702} else {4703method = new Node();4704token = lookahead;4705isStatic = false;4706computed = match('[');4707key = parseObjectPropertyKey();4708if (key.name === 'static' && lookaheadPropertyName()) {4709token = lookahead;4710isStatic = true;4711computed = match('[');4712key = parseObjectPropertyKey();4713}4714method = tryParseMethodDefinition(token, key, computed, method);4715if (method) {4716method['static'] = isStatic;4717if (method.kind === 'init') {4718method.kind = 'method';4719}4720if (!isStatic) {4721if (!method.computed && (method.key.name || method.key.value.toString()) === 'constructor') {4722if (method.kind !== 'method' || !method.method || method.value.generator) {4723throwUnexpectedToken(token, Messages.ConstructorSpecialMethod);4724}4725if (hasConstructor) {4726throwUnexpectedToken(token, Messages.DuplicateConstructor);4727} else {4728hasConstructor = true;4729}4730method.kind = 'constructor';4731}4732} else {4733if (!method.computed && (method.key.name || method.key.value.toString()) === 'prototype') {4734throwUnexpectedToken(token, Messages.StaticPrototype);4735}4736}4737method.type = Syntax.MethodDefinition;4738delete method.method;4739delete method.shorthand;4740body.push(method);4741} else {4742throwUnexpectedToken(lookahead);4743}4744}4745}4746lex();4747return classBody.finishClassBody(body);4748}47494750function parseClassDeclaration(identifierIsOptional) {4751var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;4752strict = true;47534754expectKeyword('class');47554756if (!identifierIsOptional || lookahead.type === Token.Identifier) {4757id = parseVariableIdentifier();4758}47594760if (matchKeyword('extends')) {4761lex();4762superClass = isolateCoverGrammar(parseLeftHandSideExpressionAllowCall);4763}4764classBody = parseClassBody();4765strict = previousStrict;47664767return classNode.finishClassDeclaration(id, superClass, classBody);4768}47694770function parseClassExpression() {4771var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;4772strict = true;47734774expectKeyword('class');47754776if (lookahead.type === Token.Identifier) {4777id = parseVariableIdentifier();4778}47794780if (matchKeyword('extends')) {4781lex();4782superClass = isolateCoverGrammar(parseLeftHandSideExpressionAllowCall);4783}4784classBody = parseClassBody();4785strict = previousStrict;47864787return classNode.finishClassExpression(id, superClass, classBody);4788}47894790// Modules grammar from:4791// people.mozilla.org/~jorendorff/es6-draft.html47924793function parseModuleSpecifier() {4794var node = new Node();47954796if (lookahead.type !== Token.StringLiteral) {4797throwError(Messages.InvalidModuleSpecifier);4798}4799return node.finishLiteral(lex());4800}48014802function parseExportSpecifier() {4803var exported, local, node = new Node(), def;4804if (matchKeyword('default')) {4805// export {default} from 'something';4806def = new Node();4807lex();4808local = def.finishIdentifier('default');4809} else {4810local = parseVariableIdentifier();4811}4812if (matchContextualKeyword('as')) {4813lex();4814exported = parseNonComputedProperty();4815}4816return node.finishExportSpecifier(local, exported);4817}48184819function parseExportNamedDeclaration(node) {4820var declaration = null,4821isExportFromIdentifier,4822src = null, specifiers = [];48234824// non-default export4825if (lookahead.type === Token.Keyword) {4826// covers:4827// export var f = 1;4828switch (lookahead.value) {4829case 'let':4830case 'const':4831case 'var':4832case 'class':4833case 'function':4834declaration = parseStatementListItem();4835return node.finishExportNamedDeclaration(declaration, specifiers, null);4836}4837}48384839expect('{');4840if (!match('}')) {4841do {4842isExportFromIdentifier = isExportFromIdentifier || matchKeyword('default');4843specifiers.push(parseExportSpecifier());4844} while (match(',') && lex());4845}4846expect('}');48474848if (matchContextualKeyword('from')) {4849// covering:4850// export {default} from 'foo';4851// export {foo} from 'foo';4852lex();4853src = parseModuleSpecifier();4854consumeSemicolon();4855} else if (isExportFromIdentifier) {4856// covering:4857// export {default}; // missing fromClause4858throwError(lookahead.value ?4859Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4860} else {4861// cover4862// export {foo};4863consumeSemicolon();4864}4865return node.finishExportNamedDeclaration(declaration, specifiers, src);4866}48674868function parseExportDefaultDeclaration(node) {4869var declaration = null,4870expression = null;48714872// covers:4873// export default ...4874expectKeyword('default');48754876if (matchKeyword('function')) {4877// covers:4878// export default function foo () {}4879// export default function () {}4880declaration = parseFunctionDeclaration(new Node(), true);4881return node.finishExportDefaultDeclaration(declaration);4882}4883if (matchKeyword('class')) {4884declaration = parseClassDeclaration(true);4885return node.finishExportDefaultDeclaration(declaration);4886}48874888if (matchContextualKeyword('from')) {4889throwError(Messages.UnexpectedToken, lookahead.value);4890}48914892// covers:4893// export default {};4894// export default [];4895// export default (1 + 2);4896if (match('{')) {4897expression = parseObjectInitialiser();4898} else if (match('[')) {4899expression = parseArrayInitialiser();4900} else {4901expression = parseAssignmentExpression();4902}4903consumeSemicolon();4904return node.finishExportDefaultDeclaration(expression);4905}49064907function parseExportAllDeclaration(node) {4908var src;49094910// covers:4911// export * from 'foo';4912expect('*');4913if (!matchContextualKeyword('from')) {4914throwError(lookahead.value ?4915Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4916}4917lex();4918src = parseModuleSpecifier();4919consumeSemicolon();49204921return node.finishExportAllDeclaration(src);4922}49234924function parseExportDeclaration() {4925var node = new Node();4926if (state.inFunctionBody) {4927throwError(Messages.IllegalExportDeclaration);4928}49294930expectKeyword('export');49314932if (matchKeyword('default')) {4933return parseExportDefaultDeclaration(node);4934}4935if (match('*')) {4936return parseExportAllDeclaration(node);4937}4938return parseExportNamedDeclaration(node);4939}49404941function parseImportSpecifier() {4942// import {<foo as bar>} ...;4943var local, imported, node = new Node();49444945imported = parseNonComputedProperty();4946if (matchContextualKeyword('as')) {4947lex();4948local = parseVariableIdentifier();4949}49504951return node.finishImportSpecifier(local, imported);4952}49534954function parseNamedImports() {4955var specifiers = [];4956// {foo, bar as bas}4957expect('{');4958if (!match('}')) {4959do {4960specifiers.push(parseImportSpecifier());4961} while (match(',') && lex());4962}4963expect('}');4964return specifiers;4965}49664967function parseImportDefaultSpecifier() {4968// import <foo> ...;4969var local, node = new Node();49704971local = parseNonComputedProperty();49724973return node.finishImportDefaultSpecifier(local);4974}49754976function parseImportNamespaceSpecifier() {4977// import <* as foo> ...;4978var local, node = new Node();49794980expect('*');4981if (!matchContextualKeyword('as')) {4982throwError(Messages.NoAsAfterImportNamespace);4983}4984lex();4985local = parseNonComputedProperty();49864987return node.finishImportNamespaceSpecifier(local);4988}49894990function parseImportDeclaration() {4991var specifiers, src, node = new Node();49924993if (state.inFunctionBody) {4994throwError(Messages.IllegalImportDeclaration);4995}49964997expectKeyword('import');4998specifiers = [];49995000if (lookahead.type === Token.StringLiteral) {5001// covers:5002// import 'foo';5003src = parseModuleSpecifier();5004consumeSemicolon();5005return node.finishImportDeclaration(specifiers, src);5006}50075008if (!matchKeyword('default') && isIdentifierName(lookahead)) {5009// covers:5010// import foo5011// import foo, ...5012specifiers.push(parseImportDefaultSpecifier());5013if (match(',')) {5014lex();5015}5016}5017if (match('*')) {5018// covers:5019// import foo, * as foo5020// import * as foo5021specifiers.push(parseImportNamespaceSpecifier());5022} else if (match('{')) {5023// covers:5024// import foo, {bar}5025// import {bar}5026specifiers = specifiers.concat(parseNamedImports());5027}50285029if (!matchContextualKeyword('from')) {5030throwError(lookahead.value ?5031Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);5032}5033lex();5034src = parseModuleSpecifier();5035consumeSemicolon();50365037return node.finishImportDeclaration(specifiers, src);5038}50395040// 14 Program50415042function parseScriptBody() {5043var statement, body = [], token, directive, firstRestricted;50445045while (startIndex < length) {5046token = lookahead;5047if (token.type !== Token.StringLiteral) {5048break;5049}50505051statement = parseStatementListItem();5052body.push(statement);5053if (statement.expression.type !== Syntax.Literal) {5054// this is not directive5055break;5056}5057directive = source.slice(token.start + 1, token.end - 1);5058if (directive === 'use strict') {5059strict = true;5060if (firstRestricted) {5061tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);5062}5063} else {5064if (!firstRestricted && token.octal) {5065firstRestricted = token;5066}5067}5068}50695070while (startIndex < length) {5071statement = parseStatementListItem();5072/* istanbul ignore if */5073if (typeof statement === 'undefined') {5074break;5075}5076body.push(statement);5077}5078return body;5079}50805081function parseProgram() {5082var body, node;50835084peek();5085node = new Node();50865087body = parseScriptBody();5088return node.finishProgram(body);5089}50905091function filterTokenLocation() {5092var i, entry, token, tokens = [];50935094for (i = 0; i < extra.tokens.length; ++i) {5095entry = extra.tokens[i];5096token = {5097type: entry.type,5098value: entry.value5099};5100if (entry.regex) {5101token.regex = {5102pattern: entry.regex.pattern,5103flags: entry.regex.flags5104};5105}5106if (extra.range) {5107token.range = entry.range;5108}5109if (extra.loc) {5110token.loc = entry.loc;5111}5112tokens.push(token);5113}51145115extra.tokens = tokens;5116}51175118function tokenize(code, options) {5119var toString,5120tokens;51215122toString = String;5123if (typeof code !== 'string' && !(code instanceof String)) {5124code = toString(code);5125}51265127source = code;5128index = 0;5129lineNumber = (source.length > 0) ? 1 : 0;5130lineStart = 0;5131startIndex = index;5132startLineNumber = lineNumber;5133startLineStart = lineStart;5134length = source.length;5135lookahead = null;5136state = {5137allowIn: true,5138labelSet: {},5139inFunctionBody: false,5140inIteration: false,5141inSwitch: false,5142lastCommentStart: -1,5143curlyStack: []5144};51455146extra = {};51475148// Options matching.5149options = options || {};51505151// Of course we collect tokens here.5152options.tokens = true;5153extra.tokens = [];5154extra.tokenize = true;5155// The following two fields are necessary to compute the Regex tokens.5156extra.openParenToken = -1;5157extra.openCurlyToken = -1;51585159extra.range = (typeof options.range === 'boolean') && options.range;5160extra.loc = (typeof options.loc === 'boolean') && options.loc;51615162if (typeof options.comment === 'boolean' && options.comment) {5163extra.comments = [];5164}5165if (typeof options.tolerant === 'boolean' && options.tolerant) {5166extra.errors = [];5167}51685169try {5170peek();5171if (lookahead.type === Token.EOF) {5172return extra.tokens;5173}51745175lex();5176while (lookahead.type !== Token.EOF) {5177try {5178lex();5179} catch (lexError) {5180if (extra.errors) {5181recordError(lexError);5182// We have to break on the first error5183// to avoid infinite loops.5184break;5185} else {5186throw lexError;5187}5188}5189}51905191filterTokenLocation();5192tokens = extra.tokens;5193if (typeof extra.comments !== 'undefined') {5194tokens.comments = extra.comments;5195}5196if (typeof extra.errors !== 'undefined') {5197tokens.errors = extra.errors;5198}5199} catch (e) {5200throw e;5201} finally {5202extra = {};5203}5204return tokens;5205}52065207function parse(code, options) {5208var program, toString;52095210toString = String;5211if (typeof code !== 'string' && !(code instanceof String)) {5212code = toString(code);5213}52145215source = code;5216index = 0;5217lineNumber = (source.length > 0) ? 1 : 0;5218lineStart = 0;5219startIndex = index;5220startLineNumber = lineNumber;5221startLineStart = lineStart;5222length = source.length;5223lookahead = null;5224state = {5225allowIn: true,5226labelSet: {},5227inFunctionBody: false,5228inIteration: false,5229inSwitch: false,5230lastCommentStart: -1,5231curlyStack: []5232};5233sourceType = 'script';5234strict = false;52355236extra = {};5237if (typeof options !== 'undefined') {5238extra.range = (typeof options.range === 'boolean') && options.range;5239extra.loc = (typeof options.loc === 'boolean') && options.loc;5240extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;52415242if (extra.loc && options.source !== null && options.source !== undefined) {5243extra.source = toString(options.source);5244}52455246if (typeof options.tokens === 'boolean' && options.tokens) {5247extra.tokens = [];5248}5249if (typeof options.comment === 'boolean' && options.comment) {5250extra.comments = [];5251}5252if (typeof options.tolerant === 'boolean' && options.tolerant) {5253extra.errors = [];5254}5255if (extra.attachComment) {5256extra.range = true;5257extra.comments = [];5258extra.bottomRightStack = [];5259extra.trailingComments = [];5260extra.leadingComments = [];5261}5262if (options.sourceType === 'module') {5263// very restrictive condition for now5264sourceType = options.sourceType;5265strict = true;5266}5267}52685269try {5270program = parseProgram();5271if (typeof extra.comments !== 'undefined') {5272program.comments = extra.comments;5273}5274if (typeof extra.tokens !== 'undefined') {5275filterTokenLocation();5276program.tokens = extra.tokens;5277}5278if (typeof extra.errors !== 'undefined') {5279program.errors = extra.errors;5280}5281} catch (e) {5282throw e;5283} finally {5284extra = {};5285}52865287return program;5288}52895290// Sync with *.json manifests.5291exports.version = '2.2.0';52925293exports.tokenize = tokenize;52945295exports.parse = parse;52965297// Deep copy.5298/* istanbul ignore next */5299exports.Syntax = (function () {5300var name, types = {};53015302if (typeof Object.create === 'function') {5303types = Object.create(null);5304}53055306for (name in Syntax) {5307if (Syntax.hasOwnProperty(name)) {5308types[name] = Syntax[name];5309}5310}53115312if (typeof Object.freeze === 'function') {5313Object.freeze(types);5314}53155316return types;5317}());53185319}));5320/* vim: set sw=4 ts=4 et tw=80 : */532153225323