react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / esprima / esprima.js
80681 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,59index,60lineNumber,61lineStart,62hasLineTerminator,63lastIndex,64lastLineNumber,65lastLineStart,66startIndex,67startLineNumber,68startLineStart,69scanning,70length,71lookahead,72state,73extra;7475Token = {76BooleanLiteral: 1,77EOF: 2,78Identifier: 3,79Keyword: 4,80NullLiteral: 5,81NumericLiteral: 6,82Punctuator: 7,83StringLiteral: 8,84RegularExpression: 985};8687TokenName = {};88TokenName[Token.BooleanLiteral] = 'Boolean';89TokenName[Token.EOF] = '<end>';90TokenName[Token.Identifier] = 'Identifier';91TokenName[Token.Keyword] = 'Keyword';92TokenName[Token.NullLiteral] = 'Null';93TokenName[Token.NumericLiteral] = 'Numeric';94TokenName[Token.Punctuator] = 'Punctuator';95TokenName[Token.StringLiteral] = 'String';96TokenName[Token.RegularExpression] = 'RegularExpression';9798// A function following one of those tokens is an expression.99FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',100'return', 'case', 'delete', 'throw', 'void',101// assignment operators102'=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',103'&=', '|=', '^=', ',',104// binary/unary operators105'+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',106'|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',107'<=', '<', '>', '!=', '!=='];108109Syntax = {110AssignmentExpression: 'AssignmentExpression',111ArrayExpression: 'ArrayExpression',112ArrowFunctionExpression: 'ArrowFunctionExpression',113BlockStatement: 'BlockStatement',114BinaryExpression: 'BinaryExpression',115BreakStatement: 'BreakStatement',116CallExpression: 'CallExpression',117CatchClause: 'CatchClause',118ClassBody: 'ClassBody',119ClassDeclaration: 'ClassDeclaration',120ClassExpression: 'ClassExpression',121ConditionalExpression: 'ConditionalExpression',122ContinueStatement: 'ContinueStatement',123DoWhileStatement: 'DoWhileStatement',124DebuggerStatement: 'DebuggerStatement',125EmptyStatement: 'EmptyStatement',126ExpressionStatement: 'ExpressionStatement',127ForStatement: 'ForStatement',128ForInStatement: 'ForInStatement',129FunctionDeclaration: 'FunctionDeclaration',130FunctionExpression: 'FunctionExpression',131Identifier: 'Identifier',132IfStatement: 'IfStatement',133Literal: 'Literal',134LabeledStatement: 'LabeledStatement',135LogicalExpression: 'LogicalExpression',136MemberExpression: 'MemberExpression',137MethodDefinition: 'MethodDefinition',138NewExpression: 'NewExpression',139ObjectExpression: 'ObjectExpression',140Program: 'Program',141Property: 'Property',142RestElement: 'RestElement',143ReturnStatement: 'ReturnStatement',144SequenceExpression: 'SequenceExpression',145SwitchStatement: 'SwitchStatement',146SwitchCase: 'SwitchCase',147ThisExpression: 'ThisExpression',148ThrowStatement: 'ThrowStatement',149TryStatement: 'TryStatement',150UnaryExpression: 'UnaryExpression',151UpdateExpression: 'UpdateExpression',152VariableDeclaration: 'VariableDeclaration',153VariableDeclarator: 'VariableDeclarator',154WhileStatement: 'WhileStatement',155WithStatement: 'WithStatement'156};157158PlaceHolders = {159ArrowParameterPlaceHolder: 'ArrowParameterPlaceHolder'160};161162// Error messages should be identical to V8.163Messages = {164UnexpectedToken: 'Unexpected token %0',165UnexpectedNumber: 'Unexpected number',166UnexpectedString: 'Unexpected string',167UnexpectedIdentifier: 'Unexpected identifier',168UnexpectedReserved: 'Unexpected reserved word',169UnexpectedEOS: 'Unexpected end of input',170NewlineAfterThrow: 'Illegal newline after throw',171InvalidRegExp: 'Invalid regular expression',172UnterminatedRegExp: 'Invalid regular expression: missing /',173InvalidLHSInAssignment: 'Invalid left-hand side in assignment',174InvalidLHSInForIn: 'Invalid left-hand side in for-in',175MultipleDefaultsInSwitch: 'More than one default clause in switch statement',176NoCatchOrFinally: 'Missing catch or finally after try',177UnknownLabel: 'Undefined label \'%0\'',178Redeclaration: '%0 \'%1\' has already been declared',179IllegalContinue: 'Illegal continue statement',180IllegalBreak: 'Illegal break statement',181IllegalReturn: 'Illegal return statement',182StrictModeWith: 'Strict mode code may not include a with statement',183StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',184StrictVarName: 'Variable name may not be eval or arguments in strict mode',185StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',186StrictParamDupe: 'Strict mode function may not have duplicate parameter names',187StrictFunctionName: 'Function name may not be eval or arguments in strict mode',188StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',189StrictDelete: 'Delete of an unqualified identifier in strict mode.',190StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',191StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',192StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',193StrictReservedWord: 'Use of future reserved word in strict mode',194ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',195DefaultRestParameter: 'Unexpected token =',196ObjectPatternAsRestParameter: 'Unexpected token {',197DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',198ConstructorSpecialMethod: 'Class constructor may not be an accessor',199DuplicateConstructor: 'A class may only have one constructor',200StaticPrototype: 'Classes may not have static property named prototype'201};202203// See also tools/generate-unicode-regex.py.204Regex = {205NonAsciiIdentifierStart: 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]'),206NonAsciiIdentifierPart: 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]')207};208209// Ensure the condition is true, otherwise throw an error.210// This is only to have a better contract semantic, i.e. another safety net211// to catch a logic error. The condition shall be fulfilled in normal case.212// Do NOT use this to enforce a certain condition on any user input.213214function assert(condition, message) {215/* istanbul ignore if */216if (!condition) {217throw new Error('ASSERT: ' + message);218}219}220221function isDecimalDigit(ch) {222return (ch >= 0x30 && ch <= 0x39); // 0..9223}224225function isHexDigit(ch) {226return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;227}228229function isOctalDigit(ch) {230return '01234567'.indexOf(ch) >= 0;231}232233234// 7.2 White Space235236function isWhiteSpace(ch) {237return (ch === 0x20) || (ch === 0x09) || (ch === 0x0B) || (ch === 0x0C) || (ch === 0xA0) ||238(ch >= 0x1680 && [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(ch) >= 0);239}240241// 7.3 Line Terminators242243function isLineTerminator(ch) {244return (ch === 0x0A) || (ch === 0x0D) || (ch === 0x2028) || (ch === 0x2029);245}246247// 7.6 Identifier Names and Identifiers248249function isIdentifierStart(ch) {250return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)251(ch >= 0x41 && ch <= 0x5A) || // A..Z252(ch >= 0x61 && ch <= 0x7A) || // a..z253(ch === 0x5C) || // \ (backslash)254((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));255}256257function isIdentifierPart(ch) {258return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)259(ch >= 0x41 && ch <= 0x5A) || // A..Z260(ch >= 0x61 && ch <= 0x7A) || // a..z261(ch >= 0x30 && ch <= 0x39) || // 0..9262(ch === 0x5C) || // \ (backslash)263((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));264}265266// 7.6.1.2 Future Reserved Words267268function isFutureReservedWord(id) {269switch (id) {270case 'enum':271case 'export':272case 'import':273case 'super':274return true;275default:276return false;277}278}279280// 11.6.2.2 Future Reserved Words281282function isStrictModeReservedWord(id) {283switch (id) {284case 'implements':285case 'interface':286case 'package':287case 'private':288case 'protected':289case 'public':290case 'static':291case 'yield':292case 'let':293return true;294default:295return false;296}297}298299function isRestrictedWord(id) {300return id === 'eval' || id === 'arguments';301}302303// 7.6.1.1 Keywords304305function isKeyword(id) {306if (strict && isStrictModeReservedWord(id)) {307return true;308}309310// 'const' is specialized as Keyword in V8.311// 'yield' and 'let' are for compatibility with SpiderMonkey and ES.next.312// Some others are from future reserved words.313314switch (id.length) {315case 2:316return (id === 'if') || (id === 'in') || (id === 'do');317case 3:318return (id === 'var') || (id === 'for') || (id === 'new') ||319(id === 'try') || (id === 'let');320case 4:321return (id === 'this') || (id === 'else') || (id === 'case') ||322(id === 'void') || (id === 'with') || (id === 'enum');323case 5:324return (id === 'while') || (id === 'break') || (id === 'catch') ||325(id === 'throw') || (id === 'const') || (id === 'yield') ||326(id === 'class') || (id === 'super');327case 6:328return (id === 'return') || (id === 'typeof') || (id === 'delete') ||329(id === 'switch') || (id === 'export') || (id === 'import');330case 7:331return (id === 'default') || (id === 'finally') || (id === 'extends');332case 8:333return (id === 'function') || (id === 'continue') || (id === 'debugger');334case 10:335return (id === 'instanceof');336default:337return false;338}339}340341// 7.4 Comments342343function addComment(type, value, start, end, loc) {344var comment;345346assert(typeof start === 'number', 'Comment must have valid position');347348state.lastCommentStart = start;349350comment = {351type: type,352value: value353};354if (extra.range) {355comment.range = [start, end];356}357if (extra.loc) {358comment.loc = loc;359}360extra.comments.push(comment);361if (extra.attachComment) {362extra.leadingComments.push(comment);363extra.trailingComments.push(comment);364}365}366367function skipSingleLineComment(offset) {368var start, loc, ch, comment;369370start = index - offset;371loc = {372start: {373line: lineNumber,374column: index - lineStart - offset375}376};377378while (index < length) {379ch = source.charCodeAt(index);380++index;381if (isLineTerminator(ch)) {382hasLineTerminator = true;383if (extra.comments) {384comment = source.slice(start + offset, index - 1);385loc.end = {386line: lineNumber,387column: index - lineStart - 1388};389addComment('Line', comment, start, index - 1, loc);390}391if (ch === 13 && source.charCodeAt(index) === 10) {392++index;393}394++lineNumber;395lineStart = index;396return;397}398}399400if (extra.comments) {401comment = source.slice(start + offset, index);402loc.end = {403line: lineNumber,404column: index - lineStart405};406addComment('Line', comment, start, index, loc);407}408}409410function skipMultiLineComment() {411var start, loc, ch, comment;412413if (extra.comments) {414start = index - 2;415loc = {416start: {417line: lineNumber,418column: index - lineStart - 2419}420};421}422423while (index < length) {424ch = source.charCodeAt(index);425if (isLineTerminator(ch)) {426if (ch === 0x0D && source.charCodeAt(index + 1) === 0x0A) {427++index;428}429hasLineTerminator = true;430++lineNumber;431++index;432lineStart = index;433} else if (ch === 0x2A) {434// Block comment ends with '*/'.435if (source.charCodeAt(index + 1) === 0x2F) {436++index;437++index;438if (extra.comments) {439comment = source.slice(start + 2, index - 2);440loc.end = {441line: lineNumber,442column: index - lineStart443};444addComment('Block', comment, start, index, loc);445}446return;447}448++index;449} else {450++index;451}452}453454if (extra.errors && index >= length) {455//ran off the end of the file - the whole thing is a comment456if (extra.comments) {457loc.end = {458line: lineNumber,459column: index - lineStart460};461comment = source.slice(start + 2, index);462addComment('Block', comment, start, index, loc);463}464tolerateUnexpectedToken();465} else {466throwUnexpectedToken();467}468}469470function skipComment() {471var ch, start;472hasLineTerminator = false;473474start = (index === 0);475while (index < length) {476ch = source.charCodeAt(index);477478if (isWhiteSpace(ch)) {479++index;480} else if (isLineTerminator(ch)) {481hasLineTerminator = true;482++index;483if (ch === 0x0D && source.charCodeAt(index) === 0x0A) {484++index;485}486++lineNumber;487lineStart = index;488start = true;489} else if (ch === 0x2F) { // U+002F is '/'490ch = source.charCodeAt(index + 1);491if (ch === 0x2F) {492++index;493++index;494skipSingleLineComment(2);495start = true;496} else if (ch === 0x2A) { // U+002A is '*'497++index;498++index;499skipMultiLineComment();500} else {501break;502}503} else if (start && ch === 0x2D) { // U+002D is '-'504// U+003E is '>'505if ((source.charCodeAt(index + 1) === 0x2D) && (source.charCodeAt(index + 2) === 0x3E)) {506// '-->' is a single-line comment507index += 3;508skipSingleLineComment(3);509} else {510break;511}512} else if (ch === 0x3C) { // U+003C is '<'513if (source.slice(index + 1, index + 4) === '!--') {514++index; // `<`515++index; // `!`516++index; // `-`517++index; // `-`518skipSingleLineComment(4);519} else {520break;521}522} else {523break;524}525}526}527528function scanHexEscape(prefix) {529var i, len, ch, code = 0;530531len = (prefix === 'u') ? 4 : 2;532for (i = 0; i < len; ++i) {533if (index < length && isHexDigit(source[index])) {534ch = source[index++];535code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());536} else {537return '';538}539}540return String.fromCharCode(code);541}542543function scanUnicodeCodePointEscape() {544var ch, code, cu1, cu2;545546ch = source[index];547code = 0;548549// At least, one hex digit is required.550if (ch === '}') {551throwUnexpectedToken();552}553554while (index < length) {555ch = source[index++];556if (!isHexDigit(ch)) {557break;558}559code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());560}561562if (code > 0x10FFFF || ch !== '}') {563throwUnexpectedToken();564}565566// UTF-16 Encoding567if (code <= 0xFFFF) {568return String.fromCharCode(code);569}570cu1 = ((code - 0x10000) >> 10) + 0xD800;571cu2 = ((code - 0x10000) & 1023) + 0xDC00;572return String.fromCharCode(cu1, cu2);573}574575function getEscapedIdentifier() {576var ch, id;577578ch = source.charCodeAt(index++);579id = String.fromCharCode(ch);580581// '\u' (U+005C, U+0075) denotes an escaped character.582if (ch === 0x5C) {583if (source.charCodeAt(index) !== 0x75) {584throwUnexpectedToken();585}586++index;587ch = scanHexEscape('u');588if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {589throwUnexpectedToken();590}591id = ch;592}593594while (index < length) {595ch = source.charCodeAt(index);596if (!isIdentifierPart(ch)) {597break;598}599++index;600id += String.fromCharCode(ch);601602// '\u' (U+005C, U+0075) denotes an escaped character.603if (ch === 0x5C) {604id = id.substr(0, id.length - 1);605if (source.charCodeAt(index) !== 0x75) {606throwUnexpectedToken();607}608++index;609ch = scanHexEscape('u');610if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {611throwUnexpectedToken();612}613id += ch;614}615}616617return id;618}619620function getIdentifier() {621var start, ch;622623start = index++;624while (index < length) {625ch = source.charCodeAt(index);626if (ch === 0x5C) {627// Blackslash (U+005C) marks Unicode escape sequence.628index = start;629return getEscapedIdentifier();630}631if (isIdentifierPart(ch)) {632++index;633} else {634break;635}636}637638return source.slice(start, index);639}640641function scanIdentifier() {642var start, id, type;643644start = index;645646// Backslash (U+005C) starts an escaped character.647id = (source.charCodeAt(index) === 0x5C) ? getEscapedIdentifier() : getIdentifier();648649// There is no keyword or literal with only one character.650// Thus, it must be an identifier.651if (id.length === 1) {652type = Token.Identifier;653} else if (isKeyword(id)) {654type = Token.Keyword;655} else if (id === 'null') {656type = Token.NullLiteral;657} else if (id === 'true' || id === 'false') {658type = Token.BooleanLiteral;659} else {660type = Token.Identifier;661}662663return {664type: type,665value: id,666lineNumber: lineNumber,667lineStart: lineStart,668start: start,669end: index670};671}672673674// 7.7 Punctuators675676function scanPunctuator() {677var token, str;678679token = {680type: Token.Punctuator,681value: '',682lineNumber: lineNumber,683lineStart: lineStart,684start: index,685end: index686};687688// Check for most common single-character punctuators.689str = source[index];690switch (str) {691692case '(':693if (extra.tokenize) {694extra.openParenToken = extra.tokens.length;695}696++index;697break;698699case '{':700if (extra.tokenize) {701extra.openCurlyToken = extra.tokens.length;702}703++index;704break;705706case '.':707++index;708if (source[index] === '.' && source[index + 1] === '.') {709// Spread operator: ...710index += 2;711str = '...';712}713break;714715case ')':716case ';':717case ',':718case '}':719case '[':720case ']':721case ':':722case '?':723case '~':724++index;725break;726727default:728// 4-character punctuator.729str = source.substr(index, 4);730if (str === '>>>=') {731index += 4;732} else {733734// 3-character punctuators.735str = str.substr(0, 3);736if (str === '===' || str === '!==' || str === '>>>' ||737str === '<<=' || str === '>>=') {738index += 3;739} else {740741// 2-character punctuators.742str = str.substr(0, 2);743if (str === '&&' || str === '||' || str === '==' || str === '!=' ||744str === '+=' || str === '-=' || str === '*=' || str === '/=' ||745str === '++' || str === '--' || str === '<<' || str === '>>' ||746str === '&=' || str === '|=' || str === '^=' || str === '%=' ||747str === '<=' || str === '>=' || str === '=>') {748index += 2;749} else {750751// 1-character punctuators.752str = source[index];753if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {754++index;755}756}757}758}759}760761if (index === token.start) {762throwUnexpectedToken();763}764765token.end = index;766token.value = str;767return token;768}769770// 7.8.3 Numeric Literals771772function scanHexLiteral(start) {773var number = '';774775while (index < length) {776if (!isHexDigit(source[index])) {777break;778}779number += source[index++];780}781782if (number.length === 0) {783throwUnexpectedToken();784}785786if (isIdentifierStart(source.charCodeAt(index))) {787throwUnexpectedToken();788}789790return {791type: Token.NumericLiteral,792value: parseInt('0x' + number, 16),793lineNumber: lineNumber,794lineStart: lineStart,795start: start,796end: index797};798}799800function scanBinaryLiteral(start) {801var ch, number;802803number = '';804805while (index < length) {806ch = source[index];807if (ch !== '0' && ch !== '1') {808break;809}810number += source[index++];811}812813if (number.length === 0) {814// only 0b or 0B815throwUnexpectedToken();816}817818if (index < length) {819ch = source.charCodeAt(index);820/* istanbul ignore else */821if (isIdentifierStart(ch) || isDecimalDigit(ch)) {822throwUnexpectedToken();823}824}825826return {827type: Token.NumericLiteral,828value: parseInt(number, 2),829lineNumber: lineNumber,830lineStart: lineStart,831start: start,832end: index833};834}835836function scanOctalLiteral(prefix, start) {837var number, octal;838839if (isOctalDigit(prefix)) {840octal = true;841number = '0' + source[index++];842} else {843octal = false;844++index;845number = '';846}847848while (index < length) {849if (!isOctalDigit(source[index])) {850break;851}852number += source[index++];853}854855if (!octal && number.length === 0) {856// only 0o or 0O857throwUnexpectedToken();858}859860if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {861throwUnexpectedToken();862}863864return {865type: Token.NumericLiteral,866value: parseInt(number, 8),867octal: octal,868lineNumber: lineNumber,869lineStart: lineStart,870start: start,871end: index872};873}874875function isImplicitOctalLiteral() {876var i, ch;877878// Implicit octal, unless there is a non-octal digit.879// (Annex B.1.1 on Numeric Literals)880for (i = index + 1; i < length; ++i) {881ch = source[i];882if (ch === '8' || ch === '9') {883return false;884}885if (!isOctalDigit(ch)) {886return true;887}888}889890return true;891}892893function scanNumericLiteral() {894var number, start, ch;895896ch = source[index];897assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),898'Numeric literal must start with a decimal digit or a decimal point');899900start = index;901number = '';902if (ch !== '.') {903number = source[index++];904ch = source[index];905906// Hex number starts with '0x'.907// Octal number starts with '0'.908// Octal number in ES6 starts with '0o'.909// Binary number in ES6 starts with '0b'.910if (number === '0') {911if (ch === 'x' || ch === 'X') {912++index;913return scanHexLiteral(start);914}915if (ch === 'b' || ch === 'B') {916++index;917return scanBinaryLiteral(start);918}919if (ch === 'o' || ch === 'O') {920return scanOctalLiteral(ch, start);921}922923if (isOctalDigit(ch)) {924if (isImplicitOctalLiteral()) {925return scanOctalLiteral(ch, start);926}927}928}929930while (isDecimalDigit(source.charCodeAt(index))) {931number += source[index++];932}933ch = source[index];934}935936if (ch === '.') {937number += source[index++];938while (isDecimalDigit(source.charCodeAt(index))) {939number += source[index++];940}941ch = source[index];942}943944if (ch === 'e' || ch === 'E') {945number += source[index++];946947ch = source[index];948if (ch === '+' || ch === '-') {949number += source[index++];950}951if (isDecimalDigit(source.charCodeAt(index))) {952while (isDecimalDigit(source.charCodeAt(index))) {953number += source[index++];954}955} else {956throwUnexpectedToken();957}958}959960if (isIdentifierStart(source.charCodeAt(index))) {961throwUnexpectedToken();962}963964return {965type: Token.NumericLiteral,966value: parseFloat(number),967lineNumber: lineNumber,968lineStart: lineStart,969start: start,970end: index971};972}973974// 7.8.4 String Literals975976function scanStringLiteral() {977var str = '', quote, start, ch, code, unescaped, restore, octal = false;978979quote = source[index];980assert((quote === '\'' || quote === '"'),981'String literal must starts with a quote');982983start = index;984++index;985986while (index < length) {987ch = source[index++];988989if (ch === quote) {990quote = '';991break;992} else if (ch === '\\') {993ch = source[index++];994if (!ch || !isLineTerminator(ch.charCodeAt(0))) {995switch (ch) {996case 'u':997case 'x':998if (source[index] === '{') {999++index;1000str += scanUnicodeCodePointEscape();1001} else {1002restore = index;1003unescaped = scanHexEscape(ch);1004if (unescaped) {1005str += unescaped;1006} else {1007index = restore;1008str += ch;1009}1010}1011break;1012case 'n':1013str += '\n';1014break;1015case 'r':1016str += '\r';1017break;1018case 't':1019str += '\t';1020break;1021case 'b':1022str += '\b';1023break;1024case 'f':1025str += '\f';1026break;1027case 'v':1028str += '\x0B';1029break;10301031default:1032if (isOctalDigit(ch)) {1033code = '01234567'.indexOf(ch);10341035// \0 is not octal escape sequence1036if (code !== 0) {1037octal = true;1038}10391040if (index < length && isOctalDigit(source[index])) {1041octal = true;1042code = code * 8 + '01234567'.indexOf(source[index++]);10431044// 3 digits are only allowed when string starts1045// with 0, 1, 2, 31046if ('0123'.indexOf(ch) >= 0 &&1047index < length &&1048isOctalDigit(source[index])) {1049code = code * 8 + '01234567'.indexOf(source[index++]);1050}1051}1052str += String.fromCharCode(code);1053} else {1054str += ch;1055}1056break;1057}1058} else {1059++lineNumber;1060if (ch === '\r' && source[index] === '\n') {1061++index;1062}1063lineStart = index;1064}1065} else if (isLineTerminator(ch.charCodeAt(0))) {1066break;1067} else {1068str += ch;1069}1070}10711072if (quote !== '') {1073throwUnexpectedToken();1074}10751076return {1077type: Token.StringLiteral,1078value: str,1079octal: octal,1080lineNumber: startLineNumber,1081lineStart: startLineStart,1082start: start,1083end: index1084};1085}10861087function testRegExp(pattern, flags) {1088var tmp = pattern;10891090if (flags.indexOf('u') >= 0) {1091// Replace each astral symbol and every Unicode code point1092// escape sequence with a single ASCII symbol to avoid throwing on1093// regular expressions that are only valid in combination with the1094// `/u` flag.1095// Note: replacing with the ASCII symbol `x` might cause false1096// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a1097// perfectly valid pattern that is equivalent to `[a-b]`, but it1098// would be replaced by `[x-b]` which throws an error.1099tmp = tmp1100.replace(/\\u\{([0-9a-fA-F]+)\}/g, function ($0, $1) {1101if (parseInt($1, 16) <= 0x10FFFF) {1102return 'x';1103}1104throwUnexpectedToken(null, Messages.InvalidRegExp);1105})1106.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, 'x');1107}11081109// First, detect invalid regular expressions.1110try {1111RegExp(tmp);1112} catch (e) {1113throwUnexpectedToken(null, Messages.InvalidRegExp);1114}11151116// Return a regular expression object for this pattern-flag pair, or1117// `null` in case the current environment doesn't support the flags it1118// uses.1119try {1120return new RegExp(pattern, flags);1121} catch (exception) {1122return null;1123}1124}11251126function scanRegExpBody() {1127var ch, str, classMarker, terminated, body;11281129ch = source[index];1130assert(ch === '/', 'Regular expression literal must start with a slash');1131str = source[index++];11321133classMarker = false;1134terminated = false;1135while (index < length) {1136ch = source[index++];1137str += ch;1138if (ch === '\\') {1139ch = source[index++];1140// ECMA-262 7.8.51141if (isLineTerminator(ch.charCodeAt(0))) {1142throwUnexpectedToken(null, Messages.UnterminatedRegExp);1143}1144str += ch;1145} else if (isLineTerminator(ch.charCodeAt(0))) {1146throwUnexpectedToken(null, Messages.UnterminatedRegExp);1147} else if (classMarker) {1148if (ch === ']') {1149classMarker = false;1150}1151} else {1152if (ch === '/') {1153terminated = true;1154break;1155} else if (ch === '[') {1156classMarker = true;1157}1158}1159}11601161if (!terminated) {1162throwUnexpectedToken(null, Messages.UnterminatedRegExp);1163}11641165// Exclude leading and trailing slash.1166body = str.substr(1, str.length - 2);1167return {1168value: body,1169literal: str1170};1171}11721173function scanRegExpFlags() {1174var ch, str, flags, restore;11751176str = '';1177flags = '';1178while (index < length) {1179ch = source[index];1180if (!isIdentifierPart(ch.charCodeAt(0))) {1181break;1182}11831184++index;1185if (ch === '\\' && index < length) {1186ch = source[index];1187if (ch === 'u') {1188++index;1189restore = index;1190ch = scanHexEscape('u');1191if (ch) {1192flags += ch;1193for (str += '\\u'; restore < index; ++restore) {1194str += source[restore];1195}1196} else {1197index = restore;1198flags += 'u';1199str += '\\u';1200}1201tolerateUnexpectedToken();1202} else {1203str += '\\';1204tolerateUnexpectedToken();1205}1206} else {1207flags += ch;1208str += ch;1209}1210}12111212return {1213value: flags,1214literal: str1215};1216}12171218function scanRegExp() {1219scanning = true;1220var start, body, flags, value;12211222lookahead = null;1223skipComment();1224start = index;12251226body = scanRegExpBody();1227flags = scanRegExpFlags();1228value = testRegExp(body.value, flags.value);1229scanning = false;1230if (extra.tokenize) {1231return {1232type: Token.RegularExpression,1233value: value,1234regex: {1235pattern: body.value,1236flags: flags.value1237},1238lineNumber: lineNumber,1239lineStart: lineStart,1240start: start,1241end: index1242};1243}12441245return {1246literal: body.literal + flags.literal,1247value: value,1248regex: {1249pattern: body.value,1250flags: flags.value1251},1252start: start,1253end: index1254};1255}12561257function collectRegex() {1258var pos, loc, regex, token;12591260skipComment();12611262pos = index;1263loc = {1264start: {1265line: lineNumber,1266column: index - lineStart1267}1268};12691270regex = scanRegExp();12711272loc.end = {1273line: lineNumber,1274column: index - lineStart1275};12761277/* istanbul ignore next */1278if (!extra.tokenize) {1279// Pop the previous token, which is likely '/' or '/='1280if (extra.tokens.length > 0) {1281token = extra.tokens[extra.tokens.length - 1];1282if (token.range[0] === pos && token.type === 'Punctuator') {1283if (token.value === '/' || token.value === '/=') {1284extra.tokens.pop();1285}1286}1287}12881289extra.tokens.push({1290type: 'RegularExpression',1291value: regex.literal,1292regex: regex.regex,1293range: [pos, index],1294loc: loc1295});1296}12971298return regex;1299}13001301function isIdentifierName(token) {1302return token.type === Token.Identifier ||1303token.type === Token.Keyword ||1304token.type === Token.BooleanLiteral ||1305token.type === Token.NullLiteral;1306}13071308function advanceSlash() {1309var prevToken,1310checkToken;1311// Using the following algorithm:1312// https://github.com/mozilla/sweet.js/wiki/design1313prevToken = extra.tokens[extra.tokens.length - 1];1314if (!prevToken) {1315// Nothing before that: it cannot be a division.1316return collectRegex();1317}1318if (prevToken.type === 'Punctuator') {1319if (prevToken.value === ']') {1320return scanPunctuator();1321}1322if (prevToken.value === ')') {1323checkToken = extra.tokens[extra.openParenToken - 1];1324if (checkToken &&1325checkToken.type === 'Keyword' &&1326(checkToken.value === 'if' ||1327checkToken.value === 'while' ||1328checkToken.value === 'for' ||1329checkToken.value === 'with')) {1330return collectRegex();1331}1332return scanPunctuator();1333}1334if (prevToken.value === '}') {1335// Dividing a function by anything makes little sense,1336// but we have to check for that.1337if (extra.tokens[extra.openCurlyToken - 3] &&1338extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {1339// Anonymous function.1340checkToken = extra.tokens[extra.openCurlyToken - 4];1341if (!checkToken) {1342return scanPunctuator();1343}1344} else if (extra.tokens[extra.openCurlyToken - 4] &&1345extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {1346// Named function.1347checkToken = extra.tokens[extra.openCurlyToken - 5];1348if (!checkToken) {1349return collectRegex();1350}1351} else {1352return scanPunctuator();1353}1354// checkToken determines whether the function is1355// a declaration or an expression.1356if (FnExprTokens.indexOf(checkToken.value) >= 0) {1357// It is an expression.1358return scanPunctuator();1359}1360// It is a declaration.1361return collectRegex();1362}1363return collectRegex();1364}1365if (prevToken.type === 'Keyword' && prevToken.value !== 'this') {1366return collectRegex();1367}1368return scanPunctuator();1369}13701371function advance() {1372var ch;13731374if (index >= length) {1375return {1376type: Token.EOF,1377lineNumber: lineNumber,1378lineStart: lineStart,1379start: index,1380end: index1381};1382}13831384ch = source.charCodeAt(index);13851386if (isIdentifierStart(ch)) {1387return scanIdentifier();1388}13891390// Very common: ( and ) and ;1391if (ch === 0x28 || ch === 0x29 || ch === 0x3B) {1392return scanPunctuator();1393}13941395// String literal starts with single quote (U+0027) or double quote (U+0022).1396if (ch === 0x27 || ch === 0x22) {1397return scanStringLiteral();1398}139914001401// Dot (.) U+002E can also start a floating-point number, hence the need1402// to check the next character.1403if (ch === 0x2E) {1404if (isDecimalDigit(source.charCodeAt(index + 1))) {1405return scanNumericLiteral();1406}1407return scanPunctuator();1408}14091410if (isDecimalDigit(ch)) {1411return scanNumericLiteral();1412}14131414// Slash (/) U+002F can also start a regex.1415if (extra.tokenize && ch === 0x2F) {1416return advanceSlash();1417}14181419return scanPunctuator();1420}14211422function collectToken() {1423var loc, token, value, entry;14241425loc = {1426start: {1427line: lineNumber,1428column: index - lineStart1429}1430};14311432token = advance();1433loc.end = {1434line: lineNumber,1435column: index - lineStart1436};14371438if (token.type !== Token.EOF) {1439value = source.slice(token.start, token.end);1440entry = {1441type: TokenName[token.type],1442value: value,1443range: [token.start, token.end],1444loc: loc1445};1446if (token.regex) {1447entry.regex = {1448pattern: token.regex.pattern,1449flags: token.regex.flags1450};1451}1452extra.tokens.push(entry);1453}14541455return token;1456}14571458function lex() {1459var token;1460scanning = true;14611462lastIndex = index;1463lastLineNumber = lineNumber;1464lastLineStart = lineStart;14651466skipComment();14671468token = lookahead;14691470startIndex = index;1471startLineNumber = lineNumber;1472startLineStart = lineStart;14731474lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();1475scanning = false;1476return token;1477}14781479function peek() {1480scanning = true;14811482skipComment();14831484lastIndex = index;1485lastLineNumber = lineNumber;1486lastLineStart = lineStart;14871488startIndex = index;1489startLineNumber = lineNumber;1490startLineStart = lineStart;14911492lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();1493scanning = false;1494}14951496function Position() {1497this.line = startLineNumber;1498this.column = startIndex - startLineStart;1499}15001501function SourceLocation() {1502this.start = new Position();1503this.end = null;1504}15051506function WrappingSourceLocation(startToken) {1507this.start = {1508line: startToken.lineNumber,1509column: startToken.start - startToken.lineStart1510};1511this.end = null;1512}15131514function Node() {1515if (extra.range) {1516this.range = [startIndex, 0];1517}1518if (extra.loc) {1519this.loc = new SourceLocation();1520}1521}15221523function WrappingNode(startToken) {1524if (extra.range) {1525this.range = [startToken.start, 0];1526}1527if (extra.loc) {1528this.loc = new WrappingSourceLocation(startToken);1529}1530}15311532WrappingNode.prototype = Node.prototype = {15331534processComment: function () {1535var lastChild,1536leadingComments,1537trailingComments,1538bottomRight = extra.bottomRightStack,1539i,1540comment,1541last = bottomRight[bottomRight.length - 1];15421543if (this.type === Syntax.Program) {1544if (this.body.length > 0) {1545return;1546}1547}15481549if (extra.trailingComments.length > 0) {1550trailingComments = [];1551for (i = extra.trailingComments.length - 1; i >= 0; --i) {1552comment = extra.trailingComments[i];1553if (comment.range[0] >= this.range[1]) {1554trailingComments.unshift(comment);1555extra.trailingComments.splice(i, 1);1556}1557}1558extra.trailingComments = [];1559} else {1560if (last && last.trailingComments && last.trailingComments[0].range[0] >= this.range[1]) {1561trailingComments = last.trailingComments;1562delete last.trailingComments;1563}1564}15651566// Eating the stack.1567if (last) {1568while (last && last.range[0] >= this.range[0]) {1569lastChild = last;1570last = bottomRight.pop();1571}1572}15731574if (lastChild) {1575if (lastChild.leadingComments && lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= this.range[0]) {1576this.leadingComments = lastChild.leadingComments;1577lastChild.leadingComments = undefined;1578}1579} else if (extra.leadingComments.length > 0) {1580leadingComments = [];1581for (i = extra.leadingComments.length - 1; i >= 0; --i) {1582comment = extra.leadingComments[i];1583if (comment.range[1] <= this.range[0]) {1584leadingComments.unshift(comment);1585extra.leadingComments.splice(i, 1);1586}1587}1588}158915901591if (leadingComments && leadingComments.length > 0) {1592this.leadingComments = leadingComments;1593}1594if (trailingComments && trailingComments.length > 0) {1595this.trailingComments = trailingComments;1596}15971598bottomRight.push(this);1599},16001601finish: function () {1602if (extra.range) {1603this.range[1] = lastIndex;1604}1605if (extra.loc) {1606this.loc.end = {1607line: lastLineNumber,1608column: lastIndex - lastLineStart1609};1610if (extra.source) {1611this.loc.source = extra.source;1612}1613}16141615if (extra.attachComment) {1616this.processComment();1617}1618},16191620finishArrayExpression: function (elements) {1621this.type = Syntax.ArrayExpression;1622this.elements = elements;1623this.finish();1624return this;1625},16261627finishArrowFunctionExpression: function (params, defaults, body, expression) {1628this.type = Syntax.ArrowFunctionExpression;1629this.id = null;1630this.params = params;1631this.defaults = defaults;1632this.body = body;1633this.generator = false;1634this.expression = expression;1635this.finish();1636return this;1637},16381639finishAssignmentExpression: function (operator, left, right) {1640this.type = Syntax.AssignmentExpression;1641this.operator = operator;1642this.left = left;1643this.right = right;1644this.finish();1645return this;1646},16471648finishBinaryExpression: function (operator, left, right) {1649this.type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression : Syntax.BinaryExpression;1650this.operator = operator;1651this.left = left;1652this.right = right;1653this.finish();1654return this;1655},16561657finishBlockStatement: function (body) {1658this.type = Syntax.BlockStatement;1659this.body = body;1660this.finish();1661return this;1662},16631664finishBreakStatement: function (label) {1665this.type = Syntax.BreakStatement;1666this.label = label;1667this.finish();1668return this;1669},16701671finishCallExpression: function (callee, args) {1672this.type = Syntax.CallExpression;1673this.callee = callee;1674this.arguments = args;1675this.finish();1676return this;1677},16781679finishCatchClause: function (param, body) {1680this.type = Syntax.CatchClause;1681this.param = param;1682this.body = body;1683this.finish();1684return this;1685},16861687finishClassBody: function (body) {1688this.type = Syntax.ClassBody;1689this.body = body;1690this.finish();1691return this;1692},16931694finishClassDeclaration: function (id, superClass, body) {1695this.type = Syntax.ClassDeclaration;1696this.id = id;1697this.superClass = superClass;1698this.body = body;1699this.finish();1700return this;1701},17021703finishClassExpression: function (id, superClass, body) {1704this.type = Syntax.ClassExpression;1705this.id = id;1706this.superClass = superClass;1707this.body = body;1708this.finish();1709return this;1710},17111712finishConditionalExpression: function (test, consequent, alternate) {1713this.type = Syntax.ConditionalExpression;1714this.test = test;1715this.consequent = consequent;1716this.alternate = alternate;1717this.finish();1718return this;1719},17201721finishContinueStatement: function (label) {1722this.type = Syntax.ContinueStatement;1723this.label = label;1724this.finish();1725return this;1726},17271728finishDebuggerStatement: function () {1729this.type = Syntax.DebuggerStatement;1730this.finish();1731return this;1732},17331734finishDoWhileStatement: function (body, test) {1735this.type = Syntax.DoWhileStatement;1736this.body = body;1737this.test = test;1738this.finish();1739return this;1740},17411742finishEmptyStatement: function () {1743this.type = Syntax.EmptyStatement;1744this.finish();1745return this;1746},17471748finishExpressionStatement: function (expression) {1749this.type = Syntax.ExpressionStatement;1750this.expression = expression;1751this.finish();1752return this;1753},17541755finishForStatement: function (init, test, update, body) {1756this.type = Syntax.ForStatement;1757this.init = init;1758this.test = test;1759this.update = update;1760this.body = body;1761this.finish();1762return this;1763},17641765finishForInStatement: function (left, right, body) {1766this.type = Syntax.ForInStatement;1767this.left = left;1768this.right = right;1769this.body = body;1770this.each = false;1771this.finish();1772return this;1773},17741775finishFunctionDeclaration: function (id, params, defaults, body) {1776this.type = Syntax.FunctionDeclaration;1777this.id = id;1778this.params = params;1779this.defaults = defaults;1780this.body = body;1781this.generator = false;1782this.expression = false;1783this.finish();1784return this;1785},17861787finishFunctionExpression: function (id, params, defaults, body) {1788this.type = Syntax.FunctionExpression;1789this.id = id;1790this.params = params;1791this.defaults = defaults;1792this.body = body;1793this.generator = false;1794this.expression = false;1795this.finish();1796return this;1797},17981799finishIdentifier: function (name) {1800this.type = Syntax.Identifier;1801this.name = name;1802this.finish();1803return this;1804},18051806finishIfStatement: function (test, consequent, alternate) {1807this.type = Syntax.IfStatement;1808this.test = test;1809this.consequent = consequent;1810this.alternate = alternate;1811this.finish();1812return this;1813},18141815finishLabeledStatement: function (label, body) {1816this.type = Syntax.LabeledStatement;1817this.label = label;1818this.body = body;1819this.finish();1820return this;1821},18221823finishLiteral: function (token) {1824this.type = Syntax.Literal;1825this.value = token.value;1826this.raw = source.slice(token.start, token.end);1827if (token.regex) {1828this.regex = token.regex;1829}1830this.finish();1831return this;1832},18331834finishMemberExpression: function (accessor, object, property) {1835this.type = Syntax.MemberExpression;1836this.computed = accessor === '[';1837this.object = object;1838this.property = property;1839this.finish();1840return this;1841},18421843finishNewExpression: function (callee, args) {1844this.type = Syntax.NewExpression;1845this.callee = callee;1846this.arguments = args;1847this.finish();1848return this;1849},18501851finishObjectExpression: function (properties) {1852this.type = Syntax.ObjectExpression;1853this.properties = properties;1854this.finish();1855return this;1856},18571858finishPostfixExpression: function (operator, argument) {1859this.type = Syntax.UpdateExpression;1860this.operator = operator;1861this.argument = argument;1862this.prefix = false;1863this.finish();1864return this;1865},18661867finishProgram: function (body) {1868this.type = Syntax.Program;1869this.body = body;1870this.finish();1871return this;1872},18731874finishProperty: function (kind, key, computed, value, method, shorthand) {1875this.type = Syntax.Property;1876this.key = key;1877this.computed = computed;1878this.value = value;1879this.kind = kind;1880this.method = method;1881this.shorthand = shorthand;1882this.finish();1883return this;1884},18851886finishRestElement: function (argument) {1887this.type = Syntax.RestElement;1888this.argument = argument;1889this.finish();1890return this;1891},18921893finishReturnStatement: function (argument) {1894this.type = Syntax.ReturnStatement;1895this.argument = argument;1896this.finish();1897return this;1898},18991900finishSequenceExpression: function (expressions) {1901this.type = Syntax.SequenceExpression;1902this.expressions = expressions;1903this.finish();1904return this;1905},19061907finishSwitchCase: function (test, consequent) {1908this.type = Syntax.SwitchCase;1909this.test = test;1910this.consequent = consequent;1911this.finish();1912return this;1913},19141915finishSwitchStatement: function (discriminant, cases) {1916this.type = Syntax.SwitchStatement;1917this.discriminant = discriminant;1918this.cases = cases;1919this.finish();1920return this;1921},19221923finishThisExpression: function () {1924this.type = Syntax.ThisExpression;1925this.finish();1926return this;1927},19281929finishThrowStatement: function (argument) {1930this.type = Syntax.ThrowStatement;1931this.argument = argument;1932this.finish();1933return this;1934},19351936finishTryStatement: function (block, handler, finalizer) {1937this.type = Syntax.TryStatement;1938this.block = block;1939this.guardedHandlers = [];1940this.handlers = handler ? [ handler ] : [];1941this.handler = handler;1942this.finalizer = finalizer;1943this.finish();1944return this;1945},19461947finishUnaryExpression: function (operator, argument) {1948this.type = (operator === '++' || operator === '--') ? Syntax.UpdateExpression : Syntax.UnaryExpression;1949this.operator = operator;1950this.argument = argument;1951this.prefix = true;1952this.finish();1953return this;1954},19551956finishVariableDeclaration: function (declarations) {1957this.type = Syntax.VariableDeclaration;1958this.declarations = declarations;1959this.kind = 'var';1960this.finish();1961return this;1962},19631964finishLexicalDeclaration: function (declarations, kind) {1965this.type = Syntax.VariableDeclaration;1966this.declarations = declarations;1967this.kind = kind;1968this.finish();1969return this;1970},19711972finishVariableDeclarator: function (id, init) {1973this.type = Syntax.VariableDeclarator;1974this.id = id;1975this.init = init;1976this.finish();1977return this;1978},19791980finishWhileStatement: function (test, body) {1981this.type = Syntax.WhileStatement;1982this.test = test;1983this.body = body;1984this.finish();1985return this;1986},19871988finishWithStatement: function (object, body) {1989this.type = Syntax.WithStatement;1990this.object = object;1991this.body = body;1992this.finish();1993return this;1994}1995};199619971998function recordError(error) {1999var e, existing;20002001for (e = 0; e < extra.errors.length; e++) {2002existing = extra.errors[e];2003// Prevent duplicated error.2004/* istanbul ignore next */2005if (existing.index === error.index && existing.message === error.message) {2006return;2007}2008}20092010extra.errors.push(error);2011}20122013function createError(line, pos, description) {2014var error = new Error('Line ' + line + ': ' + description);2015error.index = pos;2016error.lineNumber = line;2017error.column = pos - (scanning ? lineStart : lastLineStart) + 1;2018error.description = description;2019return error;2020}20212022// Throw an exception20232024function throwError(messageFormat) {2025var args, msg;20262027args = Array.prototype.slice.call(arguments, 1);2028msg = messageFormat.replace(/%(\d)/g,2029function (whole, idx) {2030assert(idx < args.length, 'Message reference must be in range');2031return args[idx];2032}2033);20342035throw createError(lastLineNumber, lastIndex, msg);2036}20372038function tolerateError(messageFormat) {2039var args, msg, error;20402041args = Array.prototype.slice.call(arguments, 1);2042/* istanbul ignore next */2043msg = messageFormat.replace(/%(\d)/g,2044function (whole, idx) {2045assert(idx < args.length, 'Message reference must be in range');2046return args[idx];2047}2048);20492050error = createError(lineNumber, lastIndex, msg);2051if (extra.errors) {2052recordError(error);2053} else {2054throw error;2055}2056}20572058// Throw an exception because of the token.20592060function unexpectedTokenError(token, message) {2061var msg = message || Messages.UnexpectedToken;20622063if (token && !message) {2064msg = (token.type === Token.EOF) ? Messages.UnexpectedEOS :2065(token.type === Token.Identifier) ? Messages.UnexpectedIdentifier :2066(token.type === Token.NumericLiteral) ? Messages.UnexpectedNumber :2067(token.type === Token.StringLiteral) ? Messages.UnexpectedString :2068Messages.UnexpectedToken;20692070if (token.type === Token.Keyword) {2071if (isFutureReservedWord(token.value)) {2072msg = Messages.UnexpectedReserved;2073} else if (strict && isStrictModeReservedWord(token.value)) {2074msg = Messages.StrictReservedWord;2075}2076}2077}20782079msg = msg.replace('%0', token ? token.value : 'ILLEGAL');20802081return (token && typeof token.lineNumber === 'number') ?2082createError(token.lineNumber, token.start, msg) :2083createError(scanning ? lineNumber : lastLineNumber, scanning ? index : lastIndex, msg);2084}20852086function throwUnexpectedToken(token, message) {2087throw unexpectedTokenError(token, message);2088}20892090function tolerateUnexpectedToken(token, message) {2091var error = unexpectedTokenError(token, message);2092if (extra.errors) {2093recordError(error);2094} else {2095throw error;2096}2097}20982099// Expect the next token to match the specified punctuator.2100// If not, an exception will be thrown.21012102function expect(value) {2103var token = lex();2104if (token.type !== Token.Punctuator || token.value !== value) {2105throwUnexpectedToken(token);2106}2107}21082109/**2110* @name expectCommaSeparator2111* @description Quietly expect a comma when in tolerant mode, otherwise delegates2112* to <code>expect(value)</code>2113* @since 2.02114*/2115function expectCommaSeparator() {2116var token;21172118if (extra.errors) {2119token = lookahead;2120if (token.type === Token.Punctuator && token.value === ',') {2121lex();2122} else if (token.type === Token.Punctuator && token.value === ';') {2123lex();2124tolerateUnexpectedToken(token);2125} else {2126tolerateUnexpectedToken(token, Messages.UnexpectedToken);2127}2128} else {2129expect(',');2130}2131}21322133// Expect the next token to match the specified keyword.2134// If not, an exception will be thrown.21352136function expectKeyword(keyword) {2137var token = lex();2138if (token.type !== Token.Keyword || token.value !== keyword) {2139throwUnexpectedToken(token);2140}2141}21422143// Return true if the next token matches the specified punctuator.21442145function match(value) {2146return lookahead.type === Token.Punctuator && lookahead.value === value;2147}21482149// Return true if the next token matches the specified keyword21502151function matchKeyword(keyword) {2152return lookahead.type === Token.Keyword && lookahead.value === keyword;2153}21542155// Return true if the next token is an assignment operator21562157function matchAssign() {2158var op;21592160if (lookahead.type !== Token.Punctuator) {2161return false;2162}2163op = lookahead.value;2164return op === '=' ||2165op === '*=' ||2166op === '/=' ||2167op === '%=' ||2168op === '+=' ||2169op === '-=' ||2170op === '<<=' ||2171op === '>>=' ||2172op === '>>>=' ||2173op === '&=' ||2174op === '^=' ||2175op === '|=';2176}21772178function consumeSemicolon() {2179// Catch the very common case first: immediately a semicolon (U+003B).2180if (source.charCodeAt(startIndex) === 0x3B || match(';')) {2181lex();2182return;2183}21842185if (hasLineTerminator) {2186return;2187}21882189// FIXME(ikarienator): this is seemingly an issue in the previous location info convention.2190lastIndex = startIndex;2191lastLineNumber = startLineNumber;2192lastLineStart = startLineStart;21932194if (lookahead.type !== Token.EOF && !match('}')) {2195throwUnexpectedToken(lookahead);2196}2197}21982199// Return true if provided expression is LeftHandSideExpression22002201function isLeftHandSide(expr) {2202return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;2203}22042205// 11.1.4 Array Initialiser22062207function parseArrayInitialiser() {2208var elements = [], node = new Node();22092210expect('[');22112212while (!match(']')) {2213if (match(',')) {2214lex();2215elements.push(null);2216} else {2217elements.push(parseAssignmentExpression());22182219if (!match(']')) {2220expect(',');2221}2222}2223}22242225lex();22262227return node.finishArrayExpression(elements);2228}22292230// 11.1.5 Object Initialiser22312232function parsePropertyFunction(node, paramInfo) {2233var previousStrict, body;22342235previousStrict = strict;2236body = parseFunctionSourceElements();22372238if (strict && paramInfo.firstRestricted) {2239tolerateUnexpectedToken(paramInfo.firstRestricted, paramInfo.message);2240}2241if (strict && paramInfo.stricted) {2242tolerateUnexpectedToken(paramInfo.stricted, paramInfo.message);2243}22442245strict = previousStrict;2246return node.finishFunctionExpression(null, paramInfo.params, paramInfo.defaults, body);2247}22482249function parsePropertyMethodFunction() {2250var params, method, node = new Node();22512252params = parseParams();2253method = parsePropertyFunction(node, params);22542255return method;2256}22572258// This function returns a tuple `[PropertyName, boolean]` where the PropertyName is the key being consumed and the second2259// element indicate whether its a computed PropertyName or a static PropertyName.2260function parseObjectPropertyKey() {2261var token, node = new Node(), expr;22622263token = lex();22642265// Note: This function is called only from parseObjectProperty(), where2266// EOF and Punctuator tokens are already filtered out.22672268switch (token.type) {2269case Token.StringLiteral:2270case Token.NumericLiteral:2271if (strict && token.octal) {2272tolerateUnexpectedToken(token, Messages.StrictOctalLiteral);2273}2274return node.finishLiteral(token);2275case Token.Identifier:2276case Token.BooleanLiteral:2277case Token.NullLiteral:2278case Token.Keyword:2279return node.finishIdentifier(token.value);2280case Token.Punctuator:2281if (token.value === '[') {2282expr = parseAssignmentExpression();2283expect(']');2284return expr;2285}2286break;2287}2288throwUnexpectedToken(token);2289}22902291function lookaheadPropertyName() {2292switch (lookahead.type) {2293case Token.Identifier:2294case Token.StringLiteral:2295case Token.BooleanLiteral:2296case Token.NullLiteral:2297case Token.NumericLiteral:2298case Token.Keyword:2299return true;2300case Token.Punctuator:2301return lookahead.value === '[';2302}2303return false;2304}23052306// This function is to try to parse a MethodDefinition as defined in 14.3. But in the case of object literals,2307// it might be called at a position where there is in fact a short hand identifier pattern or a data property.2308// This can only be determined after we consumed up to the left parentheses.2309//2310// In order to avoid back tracking, it returns `null` if the position is not a MethodDefinition and the caller2311// is responsible to visit other options.2312function tryParseMethodDefinition(token, key, computed, node) {2313var value, options, methodNode;23142315if (token.type === Token.Identifier) {2316// check for `get` and `set`;23172318if (token.value === 'get' && lookaheadPropertyName()) {2319computed = match('[');2320key = parseObjectPropertyKey();2321methodNode = new Node();2322expect('(');2323expect(')');2324value = parsePropertyFunction(methodNode, {2325params: [],2326defaults: [],2327stricted: null,2328firstRestricted: null,2329message: null2330});2331return node.finishProperty('get', key, computed, value, false, false);2332} else if (token.value === 'set' && lookaheadPropertyName()) {2333computed = match('[');2334key = parseObjectPropertyKey();2335methodNode = new Node();2336expect('(');23372338options = {2339params: [],2340defaultCount: 0,2341defaults: [],2342firstRestricted: null,2343paramSet: {}2344};2345if (match(')')) {2346tolerateUnexpectedToken(lookahead);2347} else {2348parseParam(options);2349if (options.defaultCount === 0) {2350options.defaults = [];2351}2352}2353expect(')');23542355value = parsePropertyFunction(methodNode, options);2356return node.finishProperty('set', key, computed, value, false, false);2357}2358}23592360if (match('(')) {2361value = parsePropertyMethodFunction();2362return node.finishProperty('init', key, computed, value, true, false);2363}23642365// Not a MethodDefinition.2366return null;2367}23682369function checkProto(key, computed, hasProto) {2370if (computed === false && (key.type === Syntax.Identifier && key.name === '__proto__' ||2371key.type === Syntax.Literal && key.value === '__proto__')) {2372if (hasProto.value) {2373tolerateError(Messages.DuplicateProtoProperty);2374} else {2375hasProto.value = true;2376}2377}2378}23792380function parseObjectProperty(hasProto) {2381var token = lookahead, node = new Node(), computed, key, maybeMethod, value;23822383computed = match('[');2384key = parseObjectPropertyKey();2385maybeMethod = tryParseMethodDefinition(token, key, computed, node);23862387if (maybeMethod) {2388checkProto(maybeMethod.key, maybeMethod.computed, hasProto);2389// finished2390return maybeMethod;2391}23922393// init property or short hand property.2394checkProto(key, computed, hasProto);23952396if (match(':')) {2397lex();2398value = parseAssignmentExpression();2399return node.finishProperty('init', key, computed, value, false, false);2400}24012402if (token.type === Token.Identifier) {2403return node.finishProperty('init', key, computed, key, false, true);2404}24052406throwUnexpectedToken(lookahead);2407}24082409function parseObjectInitialiser() {2410var properties = [], hasProto = {value: false}, node = new Node();24112412expect('{');24132414while (!match('}')) {2415properties.push(parseObjectProperty(hasProto));24162417if (!match('}')) {2418expectCommaSeparator();2419}2420}24212422expect('}');24232424return node.finishObjectExpression(properties);2425}24262427// 11.1.6 The Grouping Operator24282429function parseGroupExpression() {2430var expr, expressions, startToken, isValidArrowParameter = true;24312432expect('(');24332434if (match(')')) {2435lex();2436if (!match('=>')) {2437expect('=>');2438}2439return {2440type: PlaceHolders.ArrowParameterPlaceHolder,2441params: []2442};2443}24442445startToken = lookahead;2446if (match('...')) {2447expr = parseRestElement();2448expect(')');2449if (!match('=>')) {2450expect('=>');2451}2452return {2453type: PlaceHolders.ArrowParameterPlaceHolder,2454params: [expr]2455};2456}24572458if (match('(')) {2459isValidArrowParameter = false;2460}24612462expr = parseAssignmentExpression();24632464if (match(',')) {2465expressions = [expr];24662467while (startIndex < length) {2468if (!match(',')) {2469break;2470}2471lex();24722473if (match('...')) {2474if (!isValidArrowParameter) {2475throwUnexpectedToken(lookahead);2476}2477expressions.push(parseRestElement());2478expect(')');2479if (!match('=>')) {2480expect('=>');2481}2482return {2483type: PlaceHolders.ArrowParameterPlaceHolder,2484params: expressions2485};2486} else if (match('(')) {2487isValidArrowParameter = false;2488}24892490expressions.push(parseAssignmentExpression());2491}24922493expr = new WrappingNode(startToken).finishSequenceExpression(expressions);2494}249524962497expect(')');24982499if (match('=>') && !isValidArrowParameter) {2500throwUnexpectedToken(lookahead);2501}25022503return expr;2504}250525062507// 11.1 Primary Expressions25082509function parsePrimaryExpression() {2510var type, token, expr, node;25112512if (match('(')) {2513return parseGroupExpression();2514}25152516if (match('[')) {2517return parseArrayInitialiser();2518}25192520if (match('{')) {2521return parseObjectInitialiser();2522}25232524type = lookahead.type;2525node = new Node();25262527if (type === Token.Identifier) {2528expr = node.finishIdentifier(lex().value);2529} else if (type === Token.StringLiteral || type === Token.NumericLiteral) {2530if (strict && lookahead.octal) {2531tolerateUnexpectedToken(lookahead, Messages.StrictOctalLiteral);2532}2533expr = node.finishLiteral(lex());2534} else if (type === Token.Keyword) {2535if (matchKeyword('function')) {2536return parseFunctionExpression();2537}2538if (matchKeyword('this')) {2539lex();2540return node.finishThisExpression();2541}2542if (matchKeyword('class')) {2543return parseClassExpression();2544}2545throwUnexpectedToken(lex());2546} else if (type === Token.BooleanLiteral) {2547token = lex();2548token.value = (token.value === 'true');2549expr = node.finishLiteral(token);2550} else if (type === Token.NullLiteral) {2551token = lex();2552token.value = null;2553expr = node.finishLiteral(token);2554} else if (match('/') || match('/=')) {2555index = startIndex;25562557if (typeof extra.tokens !== 'undefined') {2558token = collectRegex();2559} else {2560token = scanRegExp();2561}2562lex();2563expr = node.finishLiteral(token);2564} else {2565throwUnexpectedToken(lex());2566}25672568return expr;2569}25702571// 11.2 Left-Hand-Side Expressions25722573function parseArguments() {2574var args = [];25752576expect('(');25772578if (!match(')')) {2579while (startIndex < length) {2580args.push(parseAssignmentExpression());2581if (match(')')) {2582break;2583}2584expectCommaSeparator();2585}2586}25872588expect(')');25892590return args;2591}25922593function parseNonComputedProperty() {2594var token, node = new Node();25952596token = lex();25972598if (!isIdentifierName(token)) {2599throwUnexpectedToken(token);2600}26012602return node.finishIdentifier(token.value);2603}26042605function parseNonComputedMember() {2606expect('.');26072608return parseNonComputedProperty();2609}26102611function parseComputedMember() {2612var expr;26132614expect('[');26152616expr = parseExpression();26172618expect(']');26192620return expr;2621}26222623function parseNewExpression() {2624var callee, args, node = new Node();26252626expectKeyword('new');2627callee = parseLeftHandSideExpression();2628args = match('(') ? parseArguments() : [];26292630return node.finishNewExpression(callee, args);2631}26322633function parseLeftHandSideExpressionAllowCall() {2634var expr, args, property, startToken, previousAllowIn = state.allowIn;26352636startToken = lookahead;2637state.allowIn = true;2638expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();26392640for (;;) {2641if (match('.')) {2642property = parseNonComputedMember();2643expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);2644} else if (match('(')) {2645args = parseArguments();2646expr = new WrappingNode(startToken).finishCallExpression(expr, args);2647} else if (match('[')) {2648property = parseComputedMember();2649expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);2650} else {2651break;2652}2653}2654state.allowIn = previousAllowIn;26552656return expr;2657}26582659function parseLeftHandSideExpression() {2660var expr, property, startToken;2661assert(state.allowIn, 'callee of new expression always allow in keyword.');26622663startToken = lookahead;26642665expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();26662667for (;;) {2668if (match('[')) {2669property = parseComputedMember();2670expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);2671} else if (match('.')) {2672property = parseNonComputedMember();2673expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);2674} else {2675break;2676}2677}2678return expr;2679}26802681// 11.3 Postfix Expressions26822683function parsePostfixExpression() {2684var expr, token, startToken = lookahead;26852686expr = parseLeftHandSideExpressionAllowCall();26872688if (!hasLineTerminator && lookahead.type === Token.Punctuator) {2689if (match('++') || match('--')) {2690// 11.3.1, 11.3.22691if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {2692tolerateError(Messages.StrictLHSPostfix);2693}26942695if (!isLeftHandSide(expr)) {2696tolerateError(Messages.InvalidLHSInAssignment);2697}26982699token = lex();2700expr = new WrappingNode(startToken).finishPostfixExpression(token.value, expr);2701}2702}27032704return expr;2705}27062707// 11.4 Unary Operators27082709function parseUnaryExpression() {2710var token, expr, startToken;27112712if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {2713expr = parsePostfixExpression();2714} else if (match('++') || match('--')) {2715startToken = lookahead;2716token = lex();2717expr = parseUnaryExpression();2718// 11.4.4, 11.4.52719if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {2720tolerateError(Messages.StrictLHSPrefix);2721}27222723if (!isLeftHandSide(expr)) {2724tolerateError(Messages.InvalidLHSInAssignment);2725}27262727expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);2728} else if (match('+') || match('-') || match('~') || match('!')) {2729startToken = lookahead;2730token = lex();2731expr = parseUnaryExpression();2732expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);2733} else if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {2734startToken = lookahead;2735token = lex();2736expr = parseUnaryExpression();2737expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);2738if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {2739tolerateError(Messages.StrictDelete);2740}2741} else {2742expr = parsePostfixExpression();2743}27442745return expr;2746}27472748function binaryPrecedence(token, allowIn) {2749var prec = 0;27502751if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {2752return 0;2753}27542755switch (token.value) {2756case '||':2757prec = 1;2758break;27592760case '&&':2761prec = 2;2762break;27632764case '|':2765prec = 3;2766break;27672768case '^':2769prec = 4;2770break;27712772case '&':2773prec = 5;2774break;27752776case '==':2777case '!=':2778case '===':2779case '!==':2780prec = 6;2781break;27822783case '<':2784case '>':2785case '<=':2786case '>=':2787case 'instanceof':2788prec = 7;2789break;27902791case 'in':2792prec = allowIn ? 7 : 0;2793break;27942795case '<<':2796case '>>':2797case '>>>':2798prec = 8;2799break;28002801case '+':2802case '-':2803prec = 9;2804break;28052806case '*':2807case '/':2808case '%':2809prec = 11;2810break;28112812default:2813break;2814}28152816return prec;2817}28182819// 11.5 Multiplicative Operators2820// 11.6 Additive Operators2821// 11.7 Bitwise Shift Operators2822// 11.8 Relational Operators2823// 11.9 Equality Operators2824// 11.10 Binary Bitwise Operators2825// 11.11 Binary Logical Operators28262827function parseBinaryExpression() {2828var marker, markers, expr, token, prec, stack, right, operator, left, i;28292830marker = lookahead;2831left = parseUnaryExpression();28322833token = lookahead;2834prec = binaryPrecedence(token, state.allowIn);2835if (prec === 0) {2836return left;2837}2838token.prec = prec;2839lex();28402841markers = [marker, lookahead];2842right = parseUnaryExpression();28432844stack = [left, token, right];28452846while ((prec = binaryPrecedence(lookahead, state.allowIn)) > 0) {28472848// Reduce: make a binary expression from the three topmost entries.2849while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {2850right = stack.pop();2851operator = stack.pop().value;2852left = stack.pop();2853markers.pop();2854expr = new WrappingNode(markers[markers.length - 1]).finishBinaryExpression(operator, left, right);2855stack.push(expr);2856}28572858// Shift.2859token = lex();2860token.prec = prec;2861stack.push(token);2862markers.push(lookahead);2863expr = parseUnaryExpression();2864stack.push(expr);2865}28662867// Final reduce to clean-up the stack.2868i = stack.length - 1;2869expr = stack[i];2870markers.pop();2871while (i > 1) {2872expr = new WrappingNode(markers.pop()).finishBinaryExpression(stack[i - 1].value, stack[i - 2], expr);2873i -= 2;2874}28752876return expr;2877}287828792880// 11.12 Conditional Operator28812882function parseConditionalExpression() {2883var expr, previousAllowIn, consequent, alternate, startToken;28842885startToken = lookahead;28862887expr = parseBinaryExpression();2888if (match('?')) {2889lex();2890previousAllowIn = state.allowIn;2891state.allowIn = true;2892consequent = parseAssignmentExpression();2893state.allowIn = previousAllowIn;2894expect(':');2895alternate = parseAssignmentExpression();28962897expr = new WrappingNode(startToken).finishConditionalExpression(expr, consequent, alternate);2898}28992900return expr;2901}29022903// [ES6] 14.2 Arrow Function29042905function parseConciseBody() {2906if (match('{')) {2907return parseFunctionSourceElements();2908}2909return parseAssignmentExpression();2910}29112912function reinterpretAsCoverFormalsList(expr) {2913var i, len, param, params, defaults, defaultCount, options, token;29142915defaults = [];2916defaultCount = 0;2917params = [expr];29182919switch (expr.type) {2920case Syntax.Identifier:2921case Syntax.AssignmentExpression:2922break;2923case Syntax.SequenceExpression:2924params = expr.expressions;2925break;2926case PlaceHolders.ArrowParameterPlaceHolder:2927params = expr.params;2928break;2929default:2930return null;2931}29322933options = {2934paramSet: {}2935};29362937for (i = 0, len = params.length; i < len; i += 1) {2938param = params[i];2939if (param.type === Syntax.Identifier) {2940params[i] = param;2941defaults.push(null);2942validateParam(options, param, param.name);2943} else if (param.type === Syntax.RestElement) {2944params[i] = param;2945defaults.push(null);2946validateParam(options, param.argument, param.argument.name);2947} else if (param.type === Syntax.AssignmentExpression) {2948params[i] = param.left;2949defaults.push(param.right);2950++defaultCount;2951validateParam(options, param.left, param.left.name);2952} else {2953return null;2954}2955}29562957if (options.message === Messages.StrictParamDupe) {2958token = strict ? options.stricted : options.firstRestricted;2959throwUnexpectedToken(token, options.message);2960}29612962if (defaultCount === 0) {2963defaults = [];2964}29652966return {2967params: params,2968defaults: defaults,2969stricted: options.stricted,2970firstRestricted: options.firstRestricted,2971message: options.message2972};2973}29742975function parseArrowFunctionExpression(options, node) {2976var previousStrict, body;29772978expect('=>');2979previousStrict = strict;29802981body = parseConciseBody();29822983if (strict && options.firstRestricted) {2984throwUnexpectedToken(options.firstRestricted, options.message);2985}2986if (strict && options.stricted) {2987tolerateUnexpectedToken(options.stricted, options.message);2988}29892990strict = previousStrict;29912992return node.finishArrowFunctionExpression(options.params, options.defaults, body, body.type !== Syntax.BlockStatement);2993}29942995// 11.13 Assignment Operators29962997function parseAssignmentExpression() {2998var token, expr, right, list, startToken;29993000startToken = lookahead;3001token = lookahead;30023003expr = parseConditionalExpression();30043005if (expr.type === PlaceHolders.ArrowParameterPlaceHolder || match('=>')) {3006list = reinterpretAsCoverFormalsList(expr);30073008if (list) {3009return parseArrowFunctionExpression(list, new WrappingNode(startToken));3010}3011}30123013if (matchAssign()) {3014// LeftHandSideExpression3015if (!isLeftHandSide(expr)) {3016tolerateError(Messages.InvalidLHSInAssignment);3017}30183019// 11.13.13020if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3021tolerateUnexpectedToken(token, Messages.StrictLHSAssignment);3022}30233024token = lex();3025right = parseAssignmentExpression();3026expr = new WrappingNode(startToken).finishAssignmentExpression(token.value, expr, right);3027}30283029return expr;3030}30313032// 11.14 Comma Operator30333034function parseExpression() {3035var expr, startToken = lookahead, expressions;30363037expr = parseAssignmentExpression();30383039if (match(',')) {3040expressions = [expr];30413042while (startIndex < length) {3043if (!match(',')) {3044break;3045}3046lex();3047expressions.push(parseAssignmentExpression());3048}30493050expr = new WrappingNode(startToken).finishSequenceExpression(expressions);3051}30523053return expr;3054}30553056// 12.1 Block30573058function parseStatementListItem() {3059if (lookahead.type === Token.Keyword) {3060switch (lookahead.value) {3061case 'const':3062case 'let':3063return parseLexicalDeclaration();3064case 'function':3065return parseFunctionDeclaration(new Node());3066case 'class':3067return parseClassDeclaration();3068}3069}30703071return parseStatement();3072}30733074function parseStatementList() {3075var list = [];3076while (startIndex < length) {3077if (match('}')) {3078break;3079}3080list.push(parseStatementListItem());3081}30823083return list;3084}30853086function parseBlock() {3087var block, node = new Node();30883089expect('{');30903091block = parseStatementList();30923093expect('}');30943095return node.finishBlockStatement(block);3096}30973098// 12.2 Variable Statement30993100function parseVariableIdentifier() {3101var token, node = new Node();31023103token = lex();31043105if (token.type !== Token.Identifier) {3106if (strict && token.type === Token.Keyword && isStrictModeReservedWord(token.value)) {3107tolerateUnexpectedToken(token, Messages.StrictReservedWord);3108} else {3109throwUnexpectedToken(token);3110}3111}31123113return node.finishIdentifier(token.value);3114}31153116function parseVariableDeclaration() {3117var init = null, id, node = new Node();31183119id = parseVariableIdentifier();31203121// 12.2.13122if (strict && isRestrictedWord(id.name)) {3123tolerateError(Messages.StrictVarName);3124}31253126if (match('=')) {3127lex();3128init = parseAssignmentExpression();3129}31303131return node.finishVariableDeclarator(id, init);3132}31333134function parseVariableDeclarationList() {3135var list = [];31363137do {3138list.push(parseVariableDeclaration());3139if (!match(',')) {3140break;3141}3142lex();3143} while (startIndex < length);31443145return list;3146}31473148function parseVariableStatement(node) {3149var declarations;31503151expectKeyword('var');31523153declarations = parseVariableDeclarationList();31543155consumeSemicolon();31563157return node.finishVariableDeclaration(declarations);3158}31593160function parseLexicalBinding(kind) {3161var init = null, id, node = new Node();31623163id = parseVariableIdentifier();31643165// 12.2.13166if (strict && isRestrictedWord(id.name)) {3167tolerateError(Messages.StrictVarName);3168}31693170if (kind === 'const') {3171if (!matchKeyword('in')) {3172expect('=');3173init = parseAssignmentExpression();3174}3175} else if (match('=')) {3176lex();3177init = parseAssignmentExpression();3178}31793180return node.finishVariableDeclarator(id, init);3181}31823183function parseBindingList(kind) {3184var list = [];31853186do {3187list.push(parseLexicalBinding(kind));3188if (!match(',')) {3189break;3190}3191lex();3192} while (startIndex < length);31933194return list;3195}31963197function parseLexicalDeclaration() {3198var kind, declarations, node = new Node();31993200kind = lex().value;3201assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');32023203declarations = parseBindingList(kind);32043205consumeSemicolon();32063207return node.finishLexicalDeclaration(declarations, kind);3208}32093210function parseRestElement() {3211var param, node = new Node();32123213lex();32143215if (match('{')) {3216throwError(Messages.ObjectPatternAsRestParameter);3217}32183219param = parseVariableIdentifier();32203221if (match('=')) {3222throwError(Messages.DefaultRestParameter);3223}32243225if (!match(')')) {3226throwError(Messages.ParameterAfterRestParameter);3227}32283229return node.finishRestElement(param);3230}32313232// 12.3 Empty Statement32333234function parseEmptyStatement(node) {3235expect(';');3236return node.finishEmptyStatement();3237}32383239// 12.4 Expression Statement32403241function parseExpressionStatement(node) {3242var expr = parseExpression();3243consumeSemicolon();3244return node.finishExpressionStatement(expr);3245}32463247// 12.5 If statement32483249function parseIfStatement(node) {3250var test, consequent, alternate;32513252expectKeyword('if');32533254expect('(');32553256test = parseExpression();32573258expect(')');32593260consequent = parseStatement();32613262if (matchKeyword('else')) {3263lex();3264alternate = parseStatement();3265} else {3266alternate = null;3267}32683269return node.finishIfStatement(test, consequent, alternate);3270}32713272// 12.6 Iteration Statements32733274function parseDoWhileStatement(node) {3275var body, test, oldInIteration;32763277expectKeyword('do');32783279oldInIteration = state.inIteration;3280state.inIteration = true;32813282body = parseStatement();32833284state.inIteration = oldInIteration;32853286expectKeyword('while');32873288expect('(');32893290test = parseExpression();32913292expect(')');32933294if (match(';')) {3295lex();3296}32973298return node.finishDoWhileStatement(body, test);3299}33003301function parseWhileStatement(node) {3302var test, body, oldInIteration;33033304expectKeyword('while');33053306expect('(');33073308test = parseExpression();33093310expect(')');33113312oldInIteration = state.inIteration;3313state.inIteration = true;33143315body = parseStatement();33163317state.inIteration = oldInIteration;33183319return node.finishWhileStatement(test, body);3320}33213322function parseForStatement(node) {3323var init, test, update, left, right, kind, declarations,3324body, oldInIteration, previousAllowIn = state.allowIn;33253326init = test = update = null;33273328expectKeyword('for');33293330expect('(');33313332if (match(';')) {3333lex();3334} else {3335if (matchKeyword('var')) {3336init = new Node();3337lex();33383339state.allowIn = false;3340init = init.finishVariableDeclaration(parseVariableDeclarationList());3341state.allowIn = previousAllowIn;33423343if (init.declarations.length === 1 && matchKeyword('in')) {3344lex();3345left = init;3346right = parseExpression();3347init = null;3348} else {3349expect(';');3350}3351} else if (matchKeyword('const') || matchKeyword('let')) {3352init = new Node();3353kind = lex().value;33543355state.allowIn = false;3356declarations = parseBindingList(kind);3357state.allowIn = previousAllowIn;33583359if (declarations.length === 1 && declarations[0].init === null && matchKeyword('in')) {3360init = init.finishLexicalDeclaration(declarations, kind);3361lex();3362left = init;3363right = parseExpression();3364init = null;3365} else {3366consumeSemicolon();3367init = init.finishLexicalDeclaration(declarations, kind);3368}3369} else {3370state.allowIn = false;3371init = parseExpression();3372state.allowIn = previousAllowIn;33733374if (matchKeyword('in')) {3375// LeftHandSideExpression3376if (!isLeftHandSide(init)) {3377tolerateError(Messages.InvalidLHSInForIn);3378}33793380lex();3381left = init;3382right = parseExpression();3383init = null;3384} else {3385expect(';');3386}3387}3388}33893390if (typeof left === 'undefined') {33913392if (!match(';')) {3393test = parseExpression();3394}3395expect(';');33963397if (!match(')')) {3398update = parseExpression();3399}3400}34013402expect(')');34033404oldInIteration = state.inIteration;3405state.inIteration = true;34063407body = parseStatement();34083409state.inIteration = oldInIteration;34103411return (typeof left === 'undefined') ?3412node.finishForStatement(init, test, update, body) :3413node.finishForInStatement(left, right, body);3414}34153416// 12.7 The continue statement34173418function parseContinueStatement(node) {3419var label = null, key;34203421expectKeyword('continue');34223423// Optimize the most common form: 'continue;'.3424if (source.charCodeAt(startIndex) === 0x3B) {3425lex();34263427if (!state.inIteration) {3428throwError(Messages.IllegalContinue);3429}34303431return node.finishContinueStatement(null);3432}34333434if (hasLineTerminator) {3435if (!state.inIteration) {3436throwError(Messages.IllegalContinue);3437}34383439return node.finishContinueStatement(null);3440}34413442if (lookahead.type === Token.Identifier) {3443label = parseVariableIdentifier();34443445key = '$' + label.name;3446if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {3447throwError(Messages.UnknownLabel, label.name);3448}3449}34503451consumeSemicolon();34523453if (label === null && !state.inIteration) {3454throwError(Messages.IllegalContinue);3455}34563457return node.finishContinueStatement(label);3458}34593460// 12.8 The break statement34613462function parseBreakStatement(node) {3463var label = null, key;34643465expectKeyword('break');34663467// Catch the very common case first: immediately a semicolon (U+003B).3468if (source.charCodeAt(lastIndex) === 0x3B) {3469lex();34703471if (!(state.inIteration || state.inSwitch)) {3472throwError(Messages.IllegalBreak);3473}34743475return node.finishBreakStatement(null);3476}34773478if (hasLineTerminator) {3479if (!(state.inIteration || state.inSwitch)) {3480throwError(Messages.IllegalBreak);3481}34823483return node.finishBreakStatement(null);3484}34853486if (lookahead.type === Token.Identifier) {3487label = parseVariableIdentifier();34883489key = '$' + label.name;3490if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {3491throwError(Messages.UnknownLabel, label.name);3492}3493}34943495consumeSemicolon();34963497if (label === null && !(state.inIteration || state.inSwitch)) {3498throwError(Messages.IllegalBreak);3499}35003501return node.finishBreakStatement(label);3502}35033504// 12.9 The return statement35053506function parseReturnStatement(node) {3507var argument = null;35083509expectKeyword('return');35103511if (!state.inFunctionBody) {3512tolerateError(Messages.IllegalReturn);3513}35143515// 'return' followed by a space and an identifier is very common.3516if (source.charCodeAt(lastIndex) === 0x20) {3517if (isIdentifierStart(source.charCodeAt(lastIndex + 1))) {3518argument = parseExpression();3519consumeSemicolon();3520return node.finishReturnStatement(argument);3521}3522}35233524if (hasLineTerminator) {3525// HACK3526return node.finishReturnStatement(null);3527}35283529if (!match(';')) {3530if (!match('}') && lookahead.type !== Token.EOF) {3531argument = parseExpression();3532}3533}35343535consumeSemicolon();35363537return node.finishReturnStatement(argument);3538}35393540// 12.10 The with statement35413542function parseWithStatement(node) {3543var object, body;35443545if (strict) {3546tolerateError(Messages.StrictModeWith);3547}35483549expectKeyword('with');35503551expect('(');35523553object = parseExpression();35543555expect(')');35563557body = parseStatement();35583559return node.finishWithStatement(object, body);3560}35613562// 12.10 The swith statement35633564function parseSwitchCase() {3565var test, consequent = [], statement, node = new Node();35663567if (matchKeyword('default')) {3568lex();3569test = null;3570} else {3571expectKeyword('case');3572test = parseExpression();3573}3574expect(':');35753576while (startIndex < length) {3577if (match('}') || matchKeyword('default') || matchKeyword('case')) {3578break;3579}3580statement = parseStatementListItem();3581consequent.push(statement);3582}35833584return node.finishSwitchCase(test, consequent);3585}35863587function parseSwitchStatement(node) {3588var discriminant, cases, clause, oldInSwitch, defaultFound;35893590expectKeyword('switch');35913592expect('(');35933594discriminant = parseExpression();35953596expect(')');35973598expect('{');35993600cases = [];36013602if (match('}')) {3603lex();3604return node.finishSwitchStatement(discriminant, cases);3605}36063607oldInSwitch = state.inSwitch;3608state.inSwitch = true;3609defaultFound = false;36103611while (startIndex < length) {3612if (match('}')) {3613break;3614}3615clause = parseSwitchCase();3616if (clause.test === null) {3617if (defaultFound) {3618throwError(Messages.MultipleDefaultsInSwitch);3619}3620defaultFound = true;3621}3622cases.push(clause);3623}36243625state.inSwitch = oldInSwitch;36263627expect('}');36283629return node.finishSwitchStatement(discriminant, cases);3630}36313632// 12.13 The throw statement36333634function parseThrowStatement(node) {3635var argument;36363637expectKeyword('throw');36383639if (hasLineTerminator) {3640throwError(Messages.NewlineAfterThrow);3641}36423643argument = parseExpression();36443645consumeSemicolon();36463647return node.finishThrowStatement(argument);3648}36493650// 12.14 The try statement36513652function parseCatchClause() {3653var param, body, node = new Node();36543655expectKeyword('catch');36563657expect('(');3658if (match(')')) {3659throwUnexpectedToken(lookahead);3660}36613662param = parseVariableIdentifier();3663// 12.14.13664if (strict && isRestrictedWord(param.name)) {3665tolerateError(Messages.StrictCatchVariable);3666}36673668expect(')');3669body = parseBlock();3670return node.finishCatchClause(param, body);3671}36723673function parseTryStatement(node) {3674var block, handler = null, finalizer = null;36753676expectKeyword('try');36773678block = parseBlock();36793680if (matchKeyword('catch')) {3681handler = parseCatchClause();3682}36833684if (matchKeyword('finally')) {3685lex();3686finalizer = parseBlock();3687}36883689if (!handler && !finalizer) {3690throwError(Messages.NoCatchOrFinally);3691}36923693return node.finishTryStatement(block, handler, finalizer);3694}36953696// 12.15 The debugger statement36973698function parseDebuggerStatement(node) {3699expectKeyword('debugger');37003701consumeSemicolon();37023703return node.finishDebuggerStatement();3704}37053706// 12 Statements37073708function parseStatement() {3709var type = lookahead.type,3710expr,3711labeledBody,3712key,3713node;37143715if (type === Token.EOF) {3716throwUnexpectedToken(lookahead);3717}37183719if (type === Token.Punctuator && lookahead.value === '{') {3720return parseBlock();3721}37223723node = new Node();37243725if (type === Token.Punctuator) {3726switch (lookahead.value) {3727case ';':3728return parseEmptyStatement(node);3729case '(':3730return parseExpressionStatement(node);3731default:3732break;3733}3734} else if (type === Token.Keyword) {3735switch (lookahead.value) {3736case 'break':3737return parseBreakStatement(node);3738case 'continue':3739return parseContinueStatement(node);3740case 'debugger':3741return parseDebuggerStatement(node);3742case 'do':3743return parseDoWhileStatement(node);3744case 'for':3745return parseForStatement(node);3746case 'function':3747return parseFunctionDeclaration(node);3748case 'if':3749return parseIfStatement(node);3750case 'return':3751return parseReturnStatement(node);3752case 'switch':3753return parseSwitchStatement(node);3754case 'throw':3755return parseThrowStatement(node);3756case 'try':3757return parseTryStatement(node);3758case 'var':3759return parseVariableStatement(node);3760case 'while':3761return parseWhileStatement(node);3762case 'with':3763return parseWithStatement(node);3764default:3765break;3766}3767}37683769expr = parseExpression();37703771// 12.12 Labelled Statements3772if ((expr.type === Syntax.Identifier) && match(':')) {3773lex();37743775key = '$' + expr.name;3776if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {3777throwError(Messages.Redeclaration, 'Label', expr.name);3778}37793780state.labelSet[key] = true;3781labeledBody = parseStatement();3782delete state.labelSet[key];3783return node.finishLabeledStatement(expr, labeledBody);3784}37853786consumeSemicolon();37873788return node.finishExpressionStatement(expr);3789}37903791// 13 Function Definition37923793function parseFunctionSourceElements() {3794var statement, body = [], token, directive, firstRestricted,3795oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, oldParenthesisCount,3796node = new Node();37973798expect('{');37993800while (startIndex < length) {3801if (lookahead.type !== Token.StringLiteral) {3802break;3803}3804token = lookahead;38053806statement = parseStatementListItem();3807body.push(statement);3808if (statement.expression.type !== Syntax.Literal) {3809// this is not directive3810break;3811}3812directive = source.slice(token.start + 1, token.end - 1);3813if (directive === 'use strict') {3814strict = true;3815if (firstRestricted) {3816tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);3817}3818} else {3819if (!firstRestricted && token.octal) {3820firstRestricted = token;3821}3822}3823}38243825oldLabelSet = state.labelSet;3826oldInIteration = state.inIteration;3827oldInSwitch = state.inSwitch;3828oldInFunctionBody = state.inFunctionBody;3829oldParenthesisCount = state.parenthesizedCount;38303831state.labelSet = {};3832state.inIteration = false;3833state.inSwitch = false;3834state.inFunctionBody = true;3835state.parenthesizedCount = 0;38363837while (startIndex < length) {3838if (match('}')) {3839break;3840}3841body.push(parseStatementListItem());3842}38433844expect('}');38453846state.labelSet = oldLabelSet;3847state.inIteration = oldInIteration;3848state.inSwitch = oldInSwitch;3849state.inFunctionBody = oldInFunctionBody;3850state.parenthesizedCount = oldParenthesisCount;38513852return node.finishBlockStatement(body);3853}38543855function validateParam(options, param, name) {3856var key = '$' + name;3857if (strict) {3858if (isRestrictedWord(name)) {3859options.stricted = param;3860options.message = Messages.StrictParamName;3861}3862if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {3863options.stricted = param;3864options.message = Messages.StrictParamDupe;3865}3866} else if (!options.firstRestricted) {3867if (isRestrictedWord(name)) {3868options.firstRestricted = param;3869options.message = Messages.StrictParamName;3870} else if (isStrictModeReservedWord(name)) {3871options.firstRestricted = param;3872options.message = Messages.StrictReservedWord;3873} else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {3874options.firstRestricted = param;3875options.message = Messages.StrictParamDupe;3876}3877}3878options.paramSet[key] = true;3879}38803881function parseParam(options) {3882var token, param, def;38833884token = lookahead;3885if (token.value === '...') {3886param = parseRestElement();3887validateParam(options, param.argument, param.argument.name);3888options.params.push(param);3889options.defaults.push(null);3890return false;3891}38923893param = parseVariableIdentifier();3894validateParam(options, token, token.value);38953896if (match('=')) {3897lex();3898def = parseAssignmentExpression();3899++options.defaultCount;3900}39013902options.params.push(param);3903options.defaults.push(def);39043905return !match(')');3906}39073908function parseParams(firstRestricted) {3909var options;39103911options = {3912params: [],3913defaultCount: 0,3914defaults: [],3915firstRestricted: firstRestricted3916};39173918expect('(');39193920if (!match(')')) {3921options.paramSet = {};3922while (startIndex < length) {3923if (!parseParam(options)) {3924break;3925}3926expect(',');3927}3928}39293930expect(')');39313932if (options.defaultCount === 0) {3933options.defaults = [];3934}39353936return {3937params: options.params,3938defaults: options.defaults,3939stricted: options.stricted,3940firstRestricted: options.firstRestricted,3941message: options.message3942};3943}39443945function parseFunctionDeclaration(node) {3946var id, params = [], defaults = [], body, token, stricted, tmp, firstRestricted, message, previousStrict;39473948expectKeyword('function');3949token = lookahead;3950id = parseVariableIdentifier();3951if (strict) {3952if (isRestrictedWord(token.value)) {3953tolerateUnexpectedToken(token, Messages.StrictFunctionName);3954}3955} else {3956if (isRestrictedWord(token.value)) {3957firstRestricted = token;3958message = Messages.StrictFunctionName;3959} else if (isStrictModeReservedWord(token.value)) {3960firstRestricted = token;3961message = Messages.StrictReservedWord;3962}3963}39643965tmp = parseParams(firstRestricted);3966params = tmp.params;3967defaults = tmp.defaults;3968stricted = tmp.stricted;3969firstRestricted = tmp.firstRestricted;3970if (tmp.message) {3971message = tmp.message;3972}39733974previousStrict = strict;3975body = parseFunctionSourceElements();3976if (strict && firstRestricted) {3977throwUnexpectedToken(firstRestricted, message);3978}3979if (strict && stricted) {3980tolerateUnexpectedToken(stricted, message);3981}3982strict = previousStrict;39833984return node.finishFunctionDeclaration(id, params, defaults, body);3985}39863987function parseFunctionExpression() {3988var token, id = null, stricted, firstRestricted, message, tmp,3989params = [], defaults = [], body, previousStrict, node = new Node();39903991expectKeyword('function');39923993if (!match('(')) {3994token = lookahead;3995id = parseVariableIdentifier();3996if (strict) {3997if (isRestrictedWord(token.value)) {3998tolerateUnexpectedToken(token, Messages.StrictFunctionName);3999}4000} else {4001if (isRestrictedWord(token.value)) {4002firstRestricted = token;4003message = Messages.StrictFunctionName;4004} else if (isStrictModeReservedWord(token.value)) {4005firstRestricted = token;4006message = Messages.StrictReservedWord;4007}4008}4009}40104011tmp = parseParams(firstRestricted);4012params = tmp.params;4013defaults = tmp.defaults;4014stricted = tmp.stricted;4015firstRestricted = tmp.firstRestricted;4016if (tmp.message) {4017message = tmp.message;4018}40194020previousStrict = strict;4021body = parseFunctionSourceElements();4022if (strict && firstRestricted) {4023throwUnexpectedToken(firstRestricted, message);4024}4025if (strict && stricted) {4026tolerateUnexpectedToken(stricted, message);4027}4028strict = previousStrict;40294030return node.finishFunctionExpression(id, params, defaults, body);4031}403240334034function parseClassBody() {4035var classBody, token, isStatic, hasConstructor = false, body, method, computed, key;40364037classBody = new Node();40384039expect('{');4040body = [];4041while (!match('}')) {4042if (match(';')) {4043lex();4044} else {4045method = new Node();4046token = lookahead;4047isStatic = false;4048computed = match('[');4049key = parseObjectPropertyKey();4050if (key.name === 'static' && lookaheadPropertyName()) {4051token = lookahead;4052isStatic = true;4053computed = match('[');4054key = parseObjectPropertyKey();4055}4056method = tryParseMethodDefinition(token, key, computed, method);4057if (method) {4058method.static = isStatic;4059if (method.kind === 'init') {4060method.kind = 'method';4061}4062if (!isStatic) {4063if (!method.computed && (method.key.name || method.key.value.toString()) === 'constructor') {4064if (method.kind !== 'method' || !method.method || method.value.generator) {4065throwUnexpectedToken(token, Messages.ConstructorSpecialMethod);4066}4067if (hasConstructor) {4068throwUnexpectedToken(token, Messages.DuplicateConstructor);4069} else {4070hasConstructor = true;4071}4072method.kind = 'constructor';4073}4074} else {4075if (!method.computed && (method.key.name || method.key.value.toString()) === 'prototype') {4076throwUnexpectedToken(token, Messages.StaticPrototype);4077}4078}4079method.type = Syntax.MethodDefinition;4080delete method.method;4081delete method.shorthand;4082body.push(method);4083} else {4084throwUnexpectedToken(lookahead);4085}4086}4087}4088lex();4089return classBody.finishClassBody(body);4090}40914092function parseClassDeclaration() {4093var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;4094strict = true;40954096expectKeyword('class');40974098id = parseVariableIdentifier();40994100if (matchKeyword('extends')) {4101lex();4102superClass = parseLeftHandSideExpressionAllowCall();4103}4104classBody = parseClassBody();4105strict = previousStrict;41064107return classNode.finishClassDeclaration(id, superClass, classBody);4108}41094110function parseClassExpression() {4111var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;4112strict = true;41134114expectKeyword('class');41154116if (lookahead.type === Token.Identifier) {4117id = parseVariableIdentifier();4118}41194120if (matchKeyword('extends')) {4121lex();4122superClass = parseLeftHandSideExpressionAllowCall();4123}4124classBody = parseClassBody();4125strict = previousStrict;41264127return classNode.finishClassExpression(id, superClass, classBody);4128}41294130// 14 Program41314132function parseScriptBody() {4133var statement, body = [], token, directive, firstRestricted;41344135while (startIndex < length) {4136token = lookahead;4137if (token.type !== Token.StringLiteral) {4138break;4139}41404141statement = parseStatementListItem();4142body.push(statement);4143if (statement.expression.type !== Syntax.Literal) {4144// this is not directive4145break;4146}4147directive = source.slice(token.start + 1, token.end - 1);4148if (directive === 'use strict') {4149strict = true;4150if (firstRestricted) {4151tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);4152}4153} else {4154if (!firstRestricted && token.octal) {4155firstRestricted = token;4156}4157}4158}41594160while (startIndex < length) {4161statement = parseStatementListItem();4162/* istanbul ignore if */4163if (typeof statement === 'undefined') {4164break;4165}4166body.push(statement);4167}4168return body;4169}41704171function parseProgram() {4172var body, node;41734174peek();4175node = new Node();4176strict = false;41774178body = parseScriptBody();4179return node.finishProgram(body);4180}41814182function filterTokenLocation() {4183var i, entry, token, tokens = [];41844185for (i = 0; i < extra.tokens.length; ++i) {4186entry = extra.tokens[i];4187token = {4188type: entry.type,4189value: entry.value4190};4191if (entry.regex) {4192token.regex = {4193pattern: entry.regex.pattern,4194flags: entry.regex.flags4195};4196}4197if (extra.range) {4198token.range = entry.range;4199}4200if (extra.loc) {4201token.loc = entry.loc;4202}4203tokens.push(token);4204}42054206extra.tokens = tokens;4207}42084209function tokenize(code, options) {4210var toString,4211tokens;42124213toString = String;4214if (typeof code !== 'string' && !(code instanceof String)) {4215code = toString(code);4216}42174218source = code;4219index = 0;4220lineNumber = (source.length > 0) ? 1 : 0;4221lineStart = 0;4222startIndex = index;4223startLineNumber = lineNumber;4224startLineStart = lineStart;4225length = source.length;4226lookahead = null;4227state = {4228allowIn: true,4229labelSet: {},4230inFunctionBody: false,4231inIteration: false,4232inSwitch: false,4233lastCommentStart: -14234};42354236extra = {};42374238// Options matching.4239options = options || {};42404241// Of course we collect tokens here.4242options.tokens = true;4243extra.tokens = [];4244extra.tokenize = true;4245// The following two fields are necessary to compute the Regex tokens.4246extra.openParenToken = -1;4247extra.openCurlyToken = -1;42484249extra.range = (typeof options.range === 'boolean') && options.range;4250extra.loc = (typeof options.loc === 'boolean') && options.loc;42514252if (typeof options.comment === 'boolean' && options.comment) {4253extra.comments = [];4254}4255if (typeof options.tolerant === 'boolean' && options.tolerant) {4256extra.errors = [];4257}42584259try {4260peek();4261if (lookahead.type === Token.EOF) {4262return extra.tokens;4263}42644265lex();4266while (lookahead.type !== Token.EOF) {4267try {4268lex();4269} catch (lexError) {4270if (extra.errors) {4271recordError(lexError);4272// We have to break on the first error4273// to avoid infinite loops.4274break;4275} else {4276throw lexError;4277}4278}4279}42804281filterTokenLocation();4282tokens = extra.tokens;4283if (typeof extra.comments !== 'undefined') {4284tokens.comments = extra.comments;4285}4286if (typeof extra.errors !== 'undefined') {4287tokens.errors = extra.errors;4288}4289} catch (e) {4290throw e;4291} finally {4292extra = {};4293}4294return tokens;4295}42964297function parse(code, options) {4298var program, toString;42994300toString = String;4301if (typeof code !== 'string' && !(code instanceof String)) {4302code = toString(code);4303}43044305source = code;4306index = 0;4307lineNumber = (source.length > 0) ? 1 : 0;4308lineStart = 0;4309startIndex = index;4310startLineNumber = lineNumber;4311startLineStart = lineStart;4312length = source.length;4313lookahead = null;4314state = {4315allowIn: true,4316labelSet: {},4317inFunctionBody: false,4318inIteration: false,4319inSwitch: false,4320lastCommentStart: -14321};43224323extra = {};4324if (typeof options !== 'undefined') {4325extra.range = (typeof options.range === 'boolean') && options.range;4326extra.loc = (typeof options.loc === 'boolean') && options.loc;4327extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;43284329if (extra.loc && options.source !== null && options.source !== undefined) {4330extra.source = toString(options.source);4331}43324333if (typeof options.tokens === 'boolean' && options.tokens) {4334extra.tokens = [];4335}4336if (typeof options.comment === 'boolean' && options.comment) {4337extra.comments = [];4338}4339if (typeof options.tolerant === 'boolean' && options.tolerant) {4340extra.errors = [];4341}4342if (extra.attachComment) {4343extra.range = true;4344extra.comments = [];4345extra.bottomRightStack = [];4346extra.trailingComments = [];4347extra.leadingComments = [];4348}4349}43504351try {4352program = parseProgram();4353if (typeof extra.comments !== 'undefined') {4354program.comments = extra.comments;4355}4356if (typeof extra.tokens !== 'undefined') {4357filterTokenLocation();4358program.tokens = extra.tokens;4359}4360if (typeof extra.errors !== 'undefined') {4361program.errors = extra.errors;4362}4363} catch (e) {4364throw e;4365} finally {4366extra = {};4367}43684369return program;4370}43714372// Sync with *.json manifests.4373exports.version = '2.1.0';43744375exports.tokenize = tokenize;43764377exports.parse = parse;43784379// Deep copy.4380/* istanbul ignore next */4381exports.Syntax = (function () {4382var name, types = {};43834384if (typeof Object.create === 'function') {4385types = Object.create(null);4386}43874388for (name in Syntax) {4389if (Syntax.hasOwnProperty(name)) {4390types[name] = Syntax[name];4391}4392}43934394if (typeof Object.freeze === 'function') {4395Object.freeze(types);4396}43974398return types;4399}());44004401}));4402/* vim: set sw=4 ts=4 et tw=80 : */440344044405