react / wstein / node_modules / browserify / node_modules / module-deps / node_modules / detective / node_modules / escodegen / node_modules / esprima / esprima.js
80575 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/*jslint bitwise:true plusplus:true */34/*global esprima:true, define:true, exports:true, window: true,35throwErrorTolerant: true,36throwError: true, generateStatement: true, peek: true,37parseAssignmentExpression: true, parseBlock: true, parseExpression: true,38parseFunctionDeclaration: true, parseFunctionExpression: true,39parseFunctionSourceElements: true, parseVariableIdentifier: true,40parseLeftHandSideExpression: true,41parseUnaryExpression: true,42parseStatement: true, parseSourceElement: true */4344(function (root, factory) {45'use strict';4647// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,48// Rhino, and plain browser loading.4950/* istanbul ignore next */51if (typeof define === 'function' && define.amd) {52define(['exports'], factory);53} else if (typeof exports !== 'undefined') {54factory(exports);55} else {56factory((root.esprima = {}));57}58}(this, function (exports) {59'use strict';6061var Token,62TokenName,63FnExprTokens,64Syntax,65PropertyKind,66Messages,67Regex,68SyntaxTreeDelegate,69source,70strict,71index,72lineNumber,73lineStart,74length,75delegate,76lookahead,77state,78extra;7980Token = {81BooleanLiteral: 1,82EOF: 2,83Identifier: 3,84Keyword: 4,85NullLiteral: 5,86NumericLiteral: 6,87Punctuator: 7,88StringLiteral: 8,89RegularExpression: 990};9192TokenName = {};93TokenName[Token.BooleanLiteral] = 'Boolean';94TokenName[Token.EOF] = '<end>';95TokenName[Token.Identifier] = 'Identifier';96TokenName[Token.Keyword] = 'Keyword';97TokenName[Token.NullLiteral] = 'Null';98TokenName[Token.NumericLiteral] = 'Numeric';99TokenName[Token.Punctuator] = 'Punctuator';100TokenName[Token.StringLiteral] = 'String';101TokenName[Token.RegularExpression] = 'RegularExpression';102103// A function following one of those tokens is an expression.104FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',105'return', 'case', 'delete', 'throw', 'void',106// assignment operators107'=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',108'&=', '|=', '^=', ',',109// binary/unary operators110'+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',111'|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',112'<=', '<', '>', '!=', '!=='];113114Syntax = {115AssignmentExpression: 'AssignmentExpression',116ArrayExpression: 'ArrayExpression',117BlockStatement: 'BlockStatement',118BinaryExpression: 'BinaryExpression',119BreakStatement: 'BreakStatement',120CallExpression: 'CallExpression',121CatchClause: 'CatchClause',122ConditionalExpression: 'ConditionalExpression',123ContinueStatement: 'ContinueStatement',124DoWhileStatement: 'DoWhileStatement',125DebuggerStatement: 'DebuggerStatement',126EmptyStatement: 'EmptyStatement',127ExpressionStatement: 'ExpressionStatement',128ForStatement: 'ForStatement',129ForInStatement: 'ForInStatement',130FunctionDeclaration: 'FunctionDeclaration',131FunctionExpression: 'FunctionExpression',132Identifier: 'Identifier',133IfStatement: 'IfStatement',134Literal: 'Literal',135LabeledStatement: 'LabeledStatement',136LogicalExpression: 'LogicalExpression',137MemberExpression: 'MemberExpression',138NewExpression: 'NewExpression',139ObjectExpression: 'ObjectExpression',140Program: 'Program',141Property: 'Property',142ReturnStatement: 'ReturnStatement',143SequenceExpression: 'SequenceExpression',144SwitchStatement: 'SwitchStatement',145SwitchCase: 'SwitchCase',146ThisExpression: 'ThisExpression',147ThrowStatement: 'ThrowStatement',148TryStatement: 'TryStatement',149UnaryExpression: 'UnaryExpression',150UpdateExpression: 'UpdateExpression',151VariableDeclaration: 'VariableDeclaration',152VariableDeclarator: 'VariableDeclarator',153WhileStatement: 'WhileStatement',154WithStatement: 'WithStatement'155};156157PropertyKind = {158Data: 1,159Get: 2,160Set: 4161};162163// Error messages should be identical to V8.164Messages = {165UnexpectedToken: 'Unexpected token %0',166UnexpectedNumber: 'Unexpected number',167UnexpectedString: 'Unexpected string',168UnexpectedIdentifier: 'Unexpected identifier',169UnexpectedReserved: 'Unexpected reserved word',170UnexpectedEOS: 'Unexpected end of input',171NewlineAfterThrow: 'Illegal newline after throw',172InvalidRegExp: 'Invalid regular expression',173UnterminatedRegExp: 'Invalid regular expression: missing /',174InvalidLHSInAssignment: 'Invalid left-hand side in assignment',175InvalidLHSInForIn: 'Invalid left-hand side in for-in',176MultipleDefaultsInSwitch: 'More than one default clause in switch statement',177NoCatchOrFinally: 'Missing catch or finally after try',178UnknownLabel: 'Undefined label \'%0\'',179Redeclaration: '%0 \'%1\' has already been declared',180IllegalContinue: 'Illegal continue statement',181IllegalBreak: 'Illegal break statement',182IllegalReturn: 'Illegal return statement',183StrictModeWith: 'Strict mode code may not include a with statement',184StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',185StrictVarName: 'Variable name may not be eval or arguments in strict mode',186StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',187StrictParamDupe: 'Strict mode function may not have duplicate parameter names',188StrictFunctionName: 'Function name may not be eval or arguments in strict mode',189StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',190StrictDelete: 'Delete of an unqualified identifier in strict mode.',191StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',192AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',193AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',194StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',195StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',196StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',197StrictReservedWord: 'Use of future reserved word in strict mode'198};199200// See also tools/generate-unicode-regex.py.201Regex = {202NonAsciiIdentifierStart: new RegExp('[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\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\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\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-\u0C33\u0C35-\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-\u16F0\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\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-\uA697\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\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]'),203NonAsciiIdentifierPart: new RegExp('[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u0527\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\u08A2-\u08AC\u08E4-\u08FE\u0900-\u0963\u0966-\u096F\u0971-\u0977\u0979-\u097F\u0981-\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\u0C01-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C82\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\u0D02\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\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-\u16F0\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-\u191C\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\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1D00-\u1DE6\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-\uA697\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A\uAA7B\uAA80-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\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-\uFE26\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]')204};205206// Ensure the condition is true, otherwise throw an error.207// This is only to have a better contract semantic, i.e. another safety net208// to catch a logic error. The condition shall be fulfilled in normal case.209// Do NOT use this to enforce a certain condition on any user input.210211function assert(condition, message) {212/* istanbul ignore if */213if (!condition) {214throw new Error('ASSERT: ' + message);215}216}217218function isDecimalDigit(ch) {219return (ch >= 48 && ch <= 57); // 0..9220}221222function isHexDigit(ch) {223return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;224}225226function isOctalDigit(ch) {227return '01234567'.indexOf(ch) >= 0;228}229230231// 7.2 White Space232233function isWhiteSpace(ch) {234return (ch === 0x20) || (ch === 0x09) || (ch === 0x0B) || (ch === 0x0C) || (ch === 0xA0) ||235(ch >= 0x1680 && [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(ch) >= 0);236}237238// 7.3 Line Terminators239240function isLineTerminator(ch) {241return (ch === 0x0A) || (ch === 0x0D) || (ch === 0x2028) || (ch === 0x2029);242}243244// 7.6 Identifier Names and Identifiers245246function isIdentifierStart(ch) {247return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)248(ch >= 0x41 && ch <= 0x5A) || // A..Z249(ch >= 0x61 && ch <= 0x7A) || // a..z250(ch === 0x5C) || // \ (backslash)251((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));252}253254function isIdentifierPart(ch) {255return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)256(ch >= 0x41 && ch <= 0x5A) || // A..Z257(ch >= 0x61 && ch <= 0x7A) || // a..z258(ch >= 0x30 && ch <= 0x39) || // 0..9259(ch === 0x5C) || // \ (backslash)260((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));261}262263// 7.6.1.2 Future Reserved Words264265function isFutureReservedWord(id) {266switch (id) {267case 'class':268case 'enum':269case 'export':270case 'extends':271case 'import':272case 'super':273return true;274default:275return false;276}277}278279function isStrictModeReservedWord(id) {280switch (id) {281case 'implements':282case 'interface':283case 'package':284case 'private':285case 'protected':286case 'public':287case 'static':288case 'yield':289case 'let':290return true;291default:292return false;293}294}295296function isRestrictedWord(id) {297return id === 'eval' || id === 'arguments';298}299300// 7.6.1.1 Keywords301302function isKeyword(id) {303if (strict && isStrictModeReservedWord(id)) {304return true;305}306307// 'const' is specialized as Keyword in V8.308// 'yield' and 'let' are for compatiblity with SpiderMonkey and ES.next.309// Some others are from future reserved words.310311switch (id.length) {312case 2:313return (id === 'if') || (id === 'in') || (id === 'do');314case 3:315return (id === 'var') || (id === 'for') || (id === 'new') ||316(id === 'try') || (id === 'let');317case 4:318return (id === 'this') || (id === 'else') || (id === 'case') ||319(id === 'void') || (id === 'with') || (id === 'enum');320case 5:321return (id === 'while') || (id === 'break') || (id === 'catch') ||322(id === 'throw') || (id === 'const') || (id === 'yield') ||323(id === 'class') || (id === 'super');324case 6:325return (id === 'return') || (id === 'typeof') || (id === 'delete') ||326(id === 'switch') || (id === 'export') || (id === 'import');327case 7:328return (id === 'default') || (id === 'finally') || (id === 'extends');329case 8:330return (id === 'function') || (id === 'continue') || (id === 'debugger');331case 10:332return (id === 'instanceof');333default:334return false;335}336}337338// 7.4 Comments339340function addComment(type, value, start, end, loc) {341var comment, attacher;342343assert(typeof start === 'number', 'Comment must have valid position');344345// Because the way the actual token is scanned, often the comments346// (if any) are skipped twice during the lexical analysis.347// Thus, we need to skip adding a comment if the comment array already348// handled it.349if (state.lastCommentStart >= start) {350return;351}352state.lastCommentStart = start;353354comment = {355type: type,356value: value357};358if (extra.range) {359comment.range = [start, end];360}361if (extra.loc) {362comment.loc = loc;363}364extra.comments.push(comment);365if (extra.attachComment) {366extra.leadingComments.push(comment);367extra.trailingComments.push(comment);368}369}370371function skipSingleLineComment(offset) {372var start, loc, ch, comment;373374start = index - offset;375loc = {376start: {377line: lineNumber,378column: index - lineStart - offset379}380};381382while (index < length) {383ch = source.charCodeAt(index);384++index;385if (isLineTerminator(ch)) {386if (extra.comments) {387comment = source.slice(start + offset, index - 1);388loc.end = {389line: lineNumber,390column: index - lineStart - 1391};392addComment('Line', comment, start, index - 1, loc);393}394if (ch === 13 && source.charCodeAt(index) === 10) {395++index;396}397++lineNumber;398lineStart = index;399return;400}401}402403if (extra.comments) {404comment = source.slice(start + offset, index);405loc.end = {406line: lineNumber,407column: index - lineStart408};409addComment('Line', comment, start, index, loc);410}411}412413function skipMultiLineComment() {414var start, loc, ch, comment;415416if (extra.comments) {417start = index - 2;418loc = {419start: {420line: lineNumber,421column: index - lineStart - 2422}423};424}425426while (index < length) {427ch = source.charCodeAt(index);428if (isLineTerminator(ch)) {429if (ch === 0x0D && source.charCodeAt(index + 1) === 0x0A) {430++index;431}432++lineNumber;433++index;434lineStart = index;435if (index >= length) {436throwError({}, Messages.UnexpectedToken, 'ILLEGAL');437}438} else if (ch === 0x2A) {439// Block comment ends with '*/'.440if (source.charCodeAt(index + 1) === 0x2F) {441++index;442++index;443if (extra.comments) {444comment = source.slice(start + 2, index - 2);445loc.end = {446line: lineNumber,447column: index - lineStart448};449addComment('Block', comment, start, index, loc);450}451return;452}453++index;454} else {455++index;456}457}458459throwError({}, Messages.UnexpectedToken, 'ILLEGAL');460}461462function skipComment() {463var ch, start;464465start = (index === 0);466while (index < length) {467ch = source.charCodeAt(index);468469if (isWhiteSpace(ch)) {470++index;471} else if (isLineTerminator(ch)) {472++index;473if (ch === 0x0D && source.charCodeAt(index) === 0x0A) {474++index;475}476++lineNumber;477lineStart = index;478start = true;479} else if (ch === 0x2F) { // U+002F is '/'480ch = source.charCodeAt(index + 1);481if (ch === 0x2F) {482++index;483++index;484skipSingleLineComment(2);485start = true;486} else if (ch === 0x2A) { // U+002A is '*'487++index;488++index;489skipMultiLineComment();490} else {491break;492}493} else if (start && ch === 0x2D) { // U+002D is '-'494// U+003E is '>'495if ((source.charCodeAt(index + 1) === 0x2D) && (source.charCodeAt(index + 2) === 0x3E)) {496// '-->' is a single-line comment497index += 3;498skipSingleLineComment(3);499} else {500break;501}502} else if (ch === 0x3C) { // U+003C is '<'503if (source.slice(index + 1, index + 4) === '!--') {504++index; // `<`505++index; // `!`506++index; // `-`507++index; // `-`508skipSingleLineComment(4);509} else {510break;511}512} else {513break;514}515}516}517518function scanHexEscape(prefix) {519var i, len, ch, code = 0;520521len = (prefix === 'u') ? 4 : 2;522for (i = 0; i < len; ++i) {523if (index < length && isHexDigit(source[index])) {524ch = source[index++];525code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());526} else {527return '';528}529}530return String.fromCharCode(code);531}532533function getEscapedIdentifier() {534var ch, id;535536ch = source.charCodeAt(index++);537id = String.fromCharCode(ch);538539// '\u' (U+005C, U+0075) denotes an escaped character.540if (ch === 0x5C) {541if (source.charCodeAt(index) !== 0x75) {542throwError({}, Messages.UnexpectedToken, 'ILLEGAL');543}544++index;545ch = scanHexEscape('u');546if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {547throwError({}, Messages.UnexpectedToken, 'ILLEGAL');548}549id = ch;550}551552while (index < length) {553ch = source.charCodeAt(index);554if (!isIdentifierPart(ch)) {555break;556}557++index;558id += String.fromCharCode(ch);559560// '\u' (U+005C, U+0075) denotes an escaped character.561if (ch === 0x5C) {562id = id.substr(0, id.length - 1);563if (source.charCodeAt(index) !== 0x75) {564throwError({}, Messages.UnexpectedToken, 'ILLEGAL');565}566++index;567ch = scanHexEscape('u');568if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {569throwError({}, Messages.UnexpectedToken, 'ILLEGAL');570}571id += ch;572}573}574575return id;576}577578function getIdentifier() {579var start, ch;580581start = index++;582while (index < length) {583ch = source.charCodeAt(index);584if (ch === 0x5C) {585// Blackslash (U+005C) marks Unicode escape sequence.586index = start;587return getEscapedIdentifier();588}589if (isIdentifierPart(ch)) {590++index;591} else {592break;593}594}595596return source.slice(start, index);597}598599function scanIdentifier() {600var start, id, type;601602start = index;603604// Backslash (U+005C) starts an escaped character.605id = (source.charCodeAt(index) === 0x5C) ? getEscapedIdentifier() : getIdentifier();606607// There is no keyword or literal with only one character.608// Thus, it must be an identifier.609if (id.length === 1) {610type = Token.Identifier;611} else if (isKeyword(id)) {612type = Token.Keyword;613} else if (id === 'null') {614type = Token.NullLiteral;615} else if (id === 'true' || id === 'false') {616type = Token.BooleanLiteral;617} else {618type = Token.Identifier;619}620621return {622type: type,623value: id,624lineNumber: lineNumber,625lineStart: lineStart,626start: start,627end: index628};629}630631632// 7.7 Punctuators633634function scanPunctuator() {635var start = index,636code = source.charCodeAt(index),637code2,638ch1 = source[index],639ch2,640ch3,641ch4;642643switch (code) {644645// Check for most common single-character punctuators.646case 0x2E: // . dot647case 0x28: // ( open bracket648case 0x29: // ) close bracket649case 0x3B: // ; semicolon650case 0x2C: // , comma651case 0x7B: // { open curly brace652case 0x7D: // } close curly brace653case 0x5B: // [654case 0x5D: // ]655case 0x3A: // :656case 0x3F: // ?657case 0x7E: // ~658++index;659if (extra.tokenize) {660if (code === 0x28) {661extra.openParenToken = extra.tokens.length;662} else if (code === 0x7B) {663extra.openCurlyToken = extra.tokens.length;664}665}666return {667type: Token.Punctuator,668value: String.fromCharCode(code),669lineNumber: lineNumber,670lineStart: lineStart,671start: start,672end: index673};674675default:676code2 = source.charCodeAt(index + 1);677678// '=' (U+003D) marks an assignment or comparison operator.679if (code2 === 0x3D) {680switch (code) {681case 0x2B: // +682case 0x2D: // -683case 0x2F: // /684case 0x3C: // <685case 0x3E: // >686case 0x5E: // ^687case 0x7C: // |688case 0x25: // %689case 0x26: // &690case 0x2A: // *691index += 2;692return {693type: Token.Punctuator,694value: String.fromCharCode(code) + String.fromCharCode(code2),695lineNumber: lineNumber,696lineStart: lineStart,697start: start,698end: index699};700701case 0x21: // !702case 0x3D: // =703index += 2;704705// !== and ===706if (source.charCodeAt(index) === 0x3D) {707++index;708}709return {710type: Token.Punctuator,711value: source.slice(start, index),712lineNumber: lineNumber,713lineStart: lineStart,714start: start,715end: index716};717}718}719}720721// 4-character punctuator: >>>=722723ch4 = source.substr(index, 4);724725if (ch4 === '>>>=') {726index += 4;727return {728type: Token.Punctuator,729value: ch4,730lineNumber: lineNumber,731lineStart: lineStart,732start: start,733end: index734};735}736737// 3-character punctuators: === !== >>> <<= >>=738739ch3 = ch4.substr(0, 3);740741if (ch3 === '>>>' || ch3 === '<<=' || ch3 === '>>=') {742index += 3;743return {744type: Token.Punctuator,745value: ch3,746lineNumber: lineNumber,747lineStart: lineStart,748start: start,749end: index750};751}752753// Other 2-character punctuators: ++ -- << >> && ||754ch2 = ch3.substr(0, 2);755756if ((ch1 === ch2[1] && ('+-<>&|'.indexOf(ch1) >= 0)) || ch2 === '=>') {757index += 2;758return {759type: Token.Punctuator,760value: ch2,761lineNumber: lineNumber,762lineStart: lineStart,763start: start,764end: index765};766}767768// 1-character punctuators: < > = ! + - * % & | ^ /769if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {770++index;771return {772type: Token.Punctuator,773value: ch1,774lineNumber: lineNumber,775lineStart: lineStart,776start: start,777end: index778};779}780781throwError({}, Messages.UnexpectedToken, 'ILLEGAL');782}783784// 7.8.3 Numeric Literals785786function scanHexLiteral(start) {787var number = '';788789while (index < length) {790if (!isHexDigit(source[index])) {791break;792}793number += source[index++];794}795796if (number.length === 0) {797throwError({}, Messages.UnexpectedToken, 'ILLEGAL');798}799800if (isIdentifierStart(source.charCodeAt(index))) {801throwError({}, Messages.UnexpectedToken, 'ILLEGAL');802}803804return {805type: Token.NumericLiteral,806value: parseInt('0x' + number, 16),807lineNumber: lineNumber,808lineStart: lineStart,809start: start,810end: index811};812}813814function scanOctalLiteral(start) {815var number = '0' + source[index++];816while (index < length) {817if (!isOctalDigit(source[index])) {818break;819}820number += source[index++];821}822823if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {824throwError({}, Messages.UnexpectedToken, 'ILLEGAL');825}826827return {828type: Token.NumericLiteral,829value: parseInt(number, 8),830octal: true,831lineNumber: lineNumber,832lineStart: lineStart,833start: start,834end: index835};836}837838function isImplicitOctalLiteral() {839var i, ch;840841// Implicit octal, unless there is a non-octal digit.842// (Annex B.1.1 on Numeric Literals)843for (i = index + 1; i < length; ++i) {844ch = source[i];845if (ch === '8' || ch === '9') {846return false;847}848if (!isOctalDigit(ch)) {849return true;850}851}852853return true;854}855856function scanNumericLiteral() {857var number, start, ch;858859ch = source[index];860assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),861'Numeric literal must start with a decimal digit or a decimal point');862863start = index;864number = '';865if (ch !== '.') {866number = source[index++];867ch = source[index];868869// Hex number starts with '0x'.870// Octal number starts with '0'.871if (number === '0') {872if (ch === 'x' || ch === 'X') {873++index;874return scanHexLiteral(start);875}876if (isOctalDigit(ch)) {877if (isImplicitOctalLiteral()) {878return scanOctalLiteral(start);879}880}881}882883while (isDecimalDigit(source.charCodeAt(index))) {884number += source[index++];885}886ch = source[index];887}888889if (ch === '.') {890number += source[index++];891while (isDecimalDigit(source.charCodeAt(index))) {892number += source[index++];893}894ch = source[index];895}896897if (ch === 'e' || ch === 'E') {898number += source[index++];899900ch = source[index];901if (ch === '+' || ch === '-') {902number += source[index++];903}904if (isDecimalDigit(source.charCodeAt(index))) {905while (isDecimalDigit(source.charCodeAt(index))) {906number += source[index++];907}908} else {909throwError({}, Messages.UnexpectedToken, 'ILLEGAL');910}911}912913if (isIdentifierStart(source.charCodeAt(index))) {914throwError({}, Messages.UnexpectedToken, 'ILLEGAL');915}916917return {918type: Token.NumericLiteral,919value: parseFloat(number),920lineNumber: lineNumber,921lineStart: lineStart,922start: start,923end: index924};925}926927// 7.8.4 String Literals928929function scanStringLiteral() {930var str = '', quote, start, ch, code, unescaped, restore, octal = false, startLineNumber, startLineStart;931startLineNumber = lineNumber;932startLineStart = lineStart;933934quote = source[index];935assert((quote === '\'' || quote === '"'),936'String literal must starts with a quote');937938start = index;939++index;940941while (index < length) {942ch = source[index++];943944if (ch === quote) {945quote = '';946break;947} else if (ch === '\\') {948ch = source[index++];949if (!ch || !isLineTerminator(ch.charCodeAt(0))) {950switch (ch) {951case 'u':952case 'x':953restore = index;954unescaped = scanHexEscape(ch);955if (unescaped) {956str += unescaped;957} else {958index = restore;959str += ch;960}961break;962case 'n':963str += '\n';964break;965case 'r':966str += '\r';967break;968case 't':969str += '\t';970break;971case 'b':972str += '\b';973break;974case 'f':975str += '\f';976break;977case 'v':978str += '\x0B';979break;980981default:982if (isOctalDigit(ch)) {983code = '01234567'.indexOf(ch);984985// \0 is not octal escape sequence986if (code !== 0) {987octal = true;988}989990if (index < length && isOctalDigit(source[index])) {991octal = true;992code = code * 8 + '01234567'.indexOf(source[index++]);993994// 3 digits are only allowed when string starts995// with 0, 1, 2, 3996if ('0123'.indexOf(ch) >= 0 &&997index < length &&998isOctalDigit(source[index])) {999code = code * 8 + '01234567'.indexOf(source[index++]);1000}1001}1002str += String.fromCharCode(code);1003} else {1004str += ch;1005}1006break;1007}1008} else {1009++lineNumber;1010if (ch === '\r' && source[index] === '\n') {1011++index;1012}1013lineStart = index;1014}1015} else if (isLineTerminator(ch.charCodeAt(0))) {1016break;1017} else {1018str += ch;1019}1020}10211022if (quote !== '') {1023throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1024}10251026return {1027type: Token.StringLiteral,1028value: str,1029octal: octal,1030startLineNumber: startLineNumber,1031startLineStart: startLineStart,1032lineNumber: lineNumber,1033lineStart: lineStart,1034start: start,1035end: index1036};1037}10381039function testRegExp(pattern, flags) {1040var value;1041try {1042value = new RegExp(pattern, flags);1043} catch (e) {1044throwError({}, Messages.InvalidRegExp);1045}1046return value;1047}10481049function scanRegExpBody() {1050var ch, str, classMarker, terminated, body;10511052ch = source[index];1053assert(ch === '/', 'Regular expression literal must start with a slash');1054str = source[index++];10551056classMarker = false;1057terminated = false;1058while (index < length) {1059ch = source[index++];1060str += ch;1061if (ch === '\\') {1062ch = source[index++];1063// ECMA-262 7.8.51064if (isLineTerminator(ch.charCodeAt(0))) {1065throwError({}, Messages.UnterminatedRegExp);1066}1067str += ch;1068} else if (isLineTerminator(ch.charCodeAt(0))) {1069throwError({}, Messages.UnterminatedRegExp);1070} else if (classMarker) {1071if (ch === ']') {1072classMarker = false;1073}1074} else {1075if (ch === '/') {1076terminated = true;1077break;1078} else if (ch === '[') {1079classMarker = true;1080}1081}1082}10831084if (!terminated) {1085throwError({}, Messages.UnterminatedRegExp);1086}10871088// Exclude leading and trailing slash.1089body = str.substr(1, str.length - 2);1090return {1091value: body,1092literal: str1093};1094}10951096function scanRegExpFlags() {1097var ch, str, flags, restore;10981099str = '';1100flags = '';1101while (index < length) {1102ch = source[index];1103if (!isIdentifierPart(ch.charCodeAt(0))) {1104break;1105}11061107++index;1108if (ch === '\\' && index < length) {1109ch = source[index];1110if (ch === 'u') {1111++index;1112restore = index;1113ch = scanHexEscape('u');1114if (ch) {1115flags += ch;1116for (str += '\\u'; restore < index; ++restore) {1117str += source[restore];1118}1119} else {1120index = restore;1121flags += 'u';1122str += '\\u';1123}1124throwErrorTolerant({}, Messages.UnexpectedToken, 'ILLEGAL');1125} else {1126str += '\\';1127throwErrorTolerant({}, Messages.UnexpectedToken, 'ILLEGAL');1128}1129} else {1130flags += ch;1131str += ch;1132}1133}11341135return {1136value: flags,1137literal: str1138};1139}11401141function scanRegExp() {1142var start, body, flags, pattern, value;11431144lookahead = null;1145skipComment();1146start = index;11471148body = scanRegExpBody();1149flags = scanRegExpFlags();1150value = testRegExp(body.value, flags.value);11511152if (extra.tokenize) {1153return {1154type: Token.RegularExpression,1155value: value,1156lineNumber: lineNumber,1157lineStart: lineStart,1158start: start,1159end: index1160};1161}11621163return {1164literal: body.literal + flags.literal,1165value: value,1166start: start,1167end: index1168};1169}11701171function collectRegex() {1172var pos, loc, regex, token;11731174skipComment();11751176pos = index;1177loc = {1178start: {1179line: lineNumber,1180column: index - lineStart1181}1182};11831184regex = scanRegExp();1185loc.end = {1186line: lineNumber,1187column: index - lineStart1188};11891190/* istanbul ignore next */1191if (!extra.tokenize) {1192// Pop the previous token, which is likely '/' or '/='1193if (extra.tokens.length > 0) {1194token = extra.tokens[extra.tokens.length - 1];1195if (token.range[0] === pos && token.type === 'Punctuator') {1196if (token.value === '/' || token.value === '/=') {1197extra.tokens.pop();1198}1199}1200}12011202extra.tokens.push({1203type: 'RegularExpression',1204value: regex.literal,1205range: [pos, index],1206loc: loc1207});1208}12091210return regex;1211}12121213function isIdentifierName(token) {1214return token.type === Token.Identifier ||1215token.type === Token.Keyword ||1216token.type === Token.BooleanLiteral ||1217token.type === Token.NullLiteral;1218}12191220function advanceSlash() {1221var prevToken,1222checkToken;1223// Using the following algorithm:1224// https://github.com/mozilla/sweet.js/wiki/design1225prevToken = extra.tokens[extra.tokens.length - 1];1226if (!prevToken) {1227// Nothing before that: it cannot be a division.1228return collectRegex();1229}1230if (prevToken.type === 'Punctuator') {1231if (prevToken.value === ']') {1232return scanPunctuator();1233}1234if (prevToken.value === ')') {1235checkToken = extra.tokens[extra.openParenToken - 1];1236if (checkToken &&1237checkToken.type === 'Keyword' &&1238(checkToken.value === 'if' ||1239checkToken.value === 'while' ||1240checkToken.value === 'for' ||1241checkToken.value === 'with')) {1242return collectRegex();1243}1244return scanPunctuator();1245}1246if (prevToken.value === '}') {1247// Dividing a function by anything makes little sense,1248// but we have to check for that.1249if (extra.tokens[extra.openCurlyToken - 3] &&1250extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {1251// Anonymous function.1252checkToken = extra.tokens[extra.openCurlyToken - 4];1253if (!checkToken) {1254return scanPunctuator();1255}1256} else if (extra.tokens[extra.openCurlyToken - 4] &&1257extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {1258// Named function.1259checkToken = extra.tokens[extra.openCurlyToken - 5];1260if (!checkToken) {1261return collectRegex();1262}1263} else {1264return scanPunctuator();1265}1266// checkToken determines whether the function is1267// a declaration or an expression.1268if (FnExprTokens.indexOf(checkToken.value) >= 0) {1269// It is an expression.1270return scanPunctuator();1271}1272// It is a declaration.1273return collectRegex();1274}1275return collectRegex();1276}1277if (prevToken.type === 'Keyword' && prevToken.value !== 'this') {1278return collectRegex();1279}1280return scanPunctuator();1281}12821283function advance() {1284var ch;12851286skipComment();12871288if (index >= length) {1289return {1290type: Token.EOF,1291lineNumber: lineNumber,1292lineStart: lineStart,1293start: index,1294end: index1295};1296}12971298ch = source.charCodeAt(index);12991300if (isIdentifierStart(ch)) {1301return scanIdentifier();1302}13031304// Very common: ( and ) and ;1305if (ch === 0x28 || ch === 0x29 || ch === 0x3B) {1306return scanPunctuator();1307}13081309// String literal starts with single quote (U+0027) or double quote (U+0022).1310if (ch === 0x27 || ch === 0x22) {1311return scanStringLiteral();1312}131313141315// Dot (.) U+002E can also start a floating-point number, hence the need1316// to check the next character.1317if (ch === 0x2E) {1318if (isDecimalDigit(source.charCodeAt(index + 1))) {1319return scanNumericLiteral();1320}1321return scanPunctuator();1322}13231324if (isDecimalDigit(ch)) {1325return scanNumericLiteral();1326}13271328// Slash (/) U+002F can also start a regex.1329if (extra.tokenize && ch === 0x2F) {1330return advanceSlash();1331}13321333return scanPunctuator();1334}13351336function collectToken() {1337var loc, token, range, value;13381339skipComment();1340loc = {1341start: {1342line: lineNumber,1343column: index - lineStart1344}1345};13461347token = advance();1348loc.end = {1349line: lineNumber,1350column: index - lineStart1351};13521353if (token.type !== Token.EOF) {1354value = source.slice(token.start, token.end);1355extra.tokens.push({1356type: TokenName[token.type],1357value: value,1358range: [token.start, token.end],1359loc: loc1360});1361}13621363return token;1364}13651366function lex() {1367var token;13681369token = lookahead;1370index = token.end;1371lineNumber = token.lineNumber;1372lineStart = token.lineStart;13731374lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();13751376index = token.end;1377lineNumber = token.lineNumber;1378lineStart = token.lineStart;13791380return token;1381}13821383function peek() {1384var pos, line, start;13851386pos = index;1387line = lineNumber;1388start = lineStart;1389lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();1390index = pos;1391lineNumber = line;1392lineStart = start;1393}13941395function Position(line, column) {1396this.line = line;1397this.column = column;1398}13991400function SourceLocation(startLine, startColumn, line, column) {1401this.start = new Position(startLine, startColumn);1402this.end = new Position(line, column);1403}14041405SyntaxTreeDelegate = {14061407name: 'SyntaxTree',14081409processComment: function (node) {1410var lastChild, trailingComments;14111412if (node.type === Syntax.Program) {1413if (node.body.length > 0) {1414return;1415}1416}14171418if (extra.trailingComments.length > 0) {1419if (extra.trailingComments[0].range[0] >= node.range[1]) {1420trailingComments = extra.trailingComments;1421extra.trailingComments = [];1422} else {1423extra.trailingComments.length = 0;1424}1425} else {1426if (extra.bottomRightStack.length > 0 &&1427extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments &&1428extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments[0].range[0] >= node.range[1]) {1429trailingComments = extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;1430delete extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;1431}1432}14331434// Eating the stack.1435while (extra.bottomRightStack.length > 0 && extra.bottomRightStack[extra.bottomRightStack.length - 1].range[0] >= node.range[0]) {1436lastChild = extra.bottomRightStack.pop();1437}14381439if (lastChild) {1440if (lastChild.leadingComments && lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= node.range[0]) {1441node.leadingComments = lastChild.leadingComments;1442delete lastChild.leadingComments;1443}1444} else if (extra.leadingComments.length > 0 && extra.leadingComments[extra.leadingComments.length - 1].range[1] <= node.range[0]) {1445node.leadingComments = extra.leadingComments;1446extra.leadingComments = [];1447}144814491450if (trailingComments) {1451node.trailingComments = trailingComments;1452}14531454extra.bottomRightStack.push(node);1455},14561457markEnd: function (node, startToken) {1458if (extra.range) {1459node.range = [startToken.start, index];1460}1461if (extra.loc) {1462node.loc = new SourceLocation(1463startToken.startLineNumber === undefined ? startToken.lineNumber : startToken.startLineNumber,1464startToken.start - (startToken.startLineStart === undefined ? startToken.lineStart : startToken.startLineStart),1465lineNumber,1466index - lineStart1467);1468this.postProcess(node);1469}14701471if (extra.attachComment) {1472this.processComment(node);1473}1474return node;1475},14761477postProcess: function (node) {1478if (extra.source) {1479node.loc.source = extra.source;1480}1481return node;1482},14831484createArrayExpression: function (elements) {1485return {1486type: Syntax.ArrayExpression,1487elements: elements1488};1489},14901491createAssignmentExpression: function (operator, left, right) {1492return {1493type: Syntax.AssignmentExpression,1494operator: operator,1495left: left,1496right: right1497};1498},14991500createBinaryExpression: function (operator, left, right) {1501var type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression :1502Syntax.BinaryExpression;1503return {1504type: type,1505operator: operator,1506left: left,1507right: right1508};1509},15101511createBlockStatement: function (body) {1512return {1513type: Syntax.BlockStatement,1514body: body1515};1516},15171518createBreakStatement: function (label) {1519return {1520type: Syntax.BreakStatement,1521label: label1522};1523},15241525createCallExpression: function (callee, args) {1526return {1527type: Syntax.CallExpression,1528callee: callee,1529'arguments': args1530};1531},15321533createCatchClause: function (param, body) {1534return {1535type: Syntax.CatchClause,1536param: param,1537body: body1538};1539},15401541createConditionalExpression: function (test, consequent, alternate) {1542return {1543type: Syntax.ConditionalExpression,1544test: test,1545consequent: consequent,1546alternate: alternate1547};1548},15491550createContinueStatement: function (label) {1551return {1552type: Syntax.ContinueStatement,1553label: label1554};1555},15561557createDebuggerStatement: function () {1558return {1559type: Syntax.DebuggerStatement1560};1561},15621563createDoWhileStatement: function (body, test) {1564return {1565type: Syntax.DoWhileStatement,1566body: body,1567test: test1568};1569},15701571createEmptyStatement: function () {1572return {1573type: Syntax.EmptyStatement1574};1575},15761577createExpressionStatement: function (expression) {1578return {1579type: Syntax.ExpressionStatement,1580expression: expression1581};1582},15831584createForStatement: function (init, test, update, body) {1585return {1586type: Syntax.ForStatement,1587init: init,1588test: test,1589update: update,1590body: body1591};1592},15931594createForInStatement: function (left, right, body) {1595return {1596type: Syntax.ForInStatement,1597left: left,1598right: right,1599body: body,1600each: false1601};1602},16031604createFunctionDeclaration: function (id, params, defaults, body) {1605return {1606type: Syntax.FunctionDeclaration,1607id: id,1608params: params,1609defaults: defaults,1610body: body,1611rest: null,1612generator: false,1613expression: false1614};1615},16161617createFunctionExpression: function (id, params, defaults, body) {1618return {1619type: Syntax.FunctionExpression,1620id: id,1621params: params,1622defaults: defaults,1623body: body,1624rest: null,1625generator: false,1626expression: false1627};1628},16291630createIdentifier: function (name) {1631return {1632type: Syntax.Identifier,1633name: name1634};1635},16361637createIfStatement: function (test, consequent, alternate) {1638return {1639type: Syntax.IfStatement,1640test: test,1641consequent: consequent,1642alternate: alternate1643};1644},16451646createLabeledStatement: function (label, body) {1647return {1648type: Syntax.LabeledStatement,1649label: label,1650body: body1651};1652},16531654createLiteral: function (token) {1655return {1656type: Syntax.Literal,1657value: token.value,1658raw: source.slice(token.start, token.end)1659};1660},16611662createMemberExpression: function (accessor, object, property) {1663return {1664type: Syntax.MemberExpression,1665computed: accessor === '[',1666object: object,1667property: property1668};1669},16701671createNewExpression: function (callee, args) {1672return {1673type: Syntax.NewExpression,1674callee: callee,1675'arguments': args1676};1677},16781679createObjectExpression: function (properties) {1680return {1681type: Syntax.ObjectExpression,1682properties: properties1683};1684},16851686createPostfixExpression: function (operator, argument) {1687return {1688type: Syntax.UpdateExpression,1689operator: operator,1690argument: argument,1691prefix: false1692};1693},16941695createProgram: function (body) {1696return {1697type: Syntax.Program,1698body: body1699};1700},17011702createProperty: function (kind, key, value) {1703return {1704type: Syntax.Property,1705key: key,1706value: value,1707kind: kind1708};1709},17101711createReturnStatement: function (argument) {1712return {1713type: Syntax.ReturnStatement,1714argument: argument1715};1716},17171718createSequenceExpression: function (expressions) {1719return {1720type: Syntax.SequenceExpression,1721expressions: expressions1722};1723},17241725createSwitchCase: function (test, consequent) {1726return {1727type: Syntax.SwitchCase,1728test: test,1729consequent: consequent1730};1731},17321733createSwitchStatement: function (discriminant, cases) {1734return {1735type: Syntax.SwitchStatement,1736discriminant: discriminant,1737cases: cases1738};1739},17401741createThisExpression: function () {1742return {1743type: Syntax.ThisExpression1744};1745},17461747createThrowStatement: function (argument) {1748return {1749type: Syntax.ThrowStatement,1750argument: argument1751};1752},17531754createTryStatement: function (block, guardedHandlers, handlers, finalizer) {1755return {1756type: Syntax.TryStatement,1757block: block,1758guardedHandlers: guardedHandlers,1759handlers: handlers,1760finalizer: finalizer1761};1762},17631764createUnaryExpression: function (operator, argument) {1765if (operator === '++' || operator === '--') {1766return {1767type: Syntax.UpdateExpression,1768operator: operator,1769argument: argument,1770prefix: true1771};1772}1773return {1774type: Syntax.UnaryExpression,1775operator: operator,1776argument: argument,1777prefix: true1778};1779},17801781createVariableDeclaration: function (declarations, kind) {1782return {1783type: Syntax.VariableDeclaration,1784declarations: declarations,1785kind: kind1786};1787},17881789createVariableDeclarator: function (id, init) {1790return {1791type: Syntax.VariableDeclarator,1792id: id,1793init: init1794};1795},17961797createWhileStatement: function (test, body) {1798return {1799type: Syntax.WhileStatement,1800test: test,1801body: body1802};1803},18041805createWithStatement: function (object, body) {1806return {1807type: Syntax.WithStatement,1808object: object,1809body: body1810};1811}1812};18131814// Return true if there is a line terminator before the next token.18151816function peekLineTerminator() {1817var pos, line, start, found;18181819pos = index;1820line = lineNumber;1821start = lineStart;1822skipComment();1823found = lineNumber !== line;1824index = pos;1825lineNumber = line;1826lineStart = start;18271828return found;1829}18301831// Throw an exception18321833function throwError(token, messageFormat) {1834var error,1835args = Array.prototype.slice.call(arguments, 2),1836msg = messageFormat.replace(1837/%(\d)/g,1838function (whole, index) {1839assert(index < args.length, 'Message reference must be in range');1840return args[index];1841}1842);18431844if (typeof token.lineNumber === 'number') {1845error = new Error('Line ' + token.lineNumber + ': ' + msg);1846error.index = token.start;1847error.lineNumber = token.lineNumber;1848error.column = token.start - lineStart + 1;1849} else {1850error = new Error('Line ' + lineNumber + ': ' + msg);1851error.index = index;1852error.lineNumber = lineNumber;1853error.column = index - lineStart + 1;1854}18551856error.description = msg;1857throw error;1858}18591860function throwErrorTolerant() {1861try {1862throwError.apply(null, arguments);1863} catch (e) {1864if (extra.errors) {1865extra.errors.push(e);1866} else {1867throw e;1868}1869}1870}187118721873// Throw an exception because of the token.18741875function throwUnexpected(token) {1876if (token.type === Token.EOF) {1877throwError(token, Messages.UnexpectedEOS);1878}18791880if (token.type === Token.NumericLiteral) {1881throwError(token, Messages.UnexpectedNumber);1882}18831884if (token.type === Token.StringLiteral) {1885throwError(token, Messages.UnexpectedString);1886}18871888if (token.type === Token.Identifier) {1889throwError(token, Messages.UnexpectedIdentifier);1890}18911892if (token.type === Token.Keyword) {1893if (isFutureReservedWord(token.value)) {1894throwError(token, Messages.UnexpectedReserved);1895} else if (strict && isStrictModeReservedWord(token.value)) {1896throwErrorTolerant(token, Messages.StrictReservedWord);1897return;1898}1899throwError(token, Messages.UnexpectedToken, token.value);1900}19011902// BooleanLiteral, NullLiteral, or Punctuator.1903throwError(token, Messages.UnexpectedToken, token.value);1904}19051906// Expect the next token to match the specified punctuator.1907// If not, an exception will be thrown.19081909function expect(value) {1910var token = lex();1911if (token.type !== Token.Punctuator || token.value !== value) {1912throwUnexpected(token);1913}1914}19151916// Expect the next token to match the specified keyword.1917// If not, an exception will be thrown.19181919function expectKeyword(keyword) {1920var token = lex();1921if (token.type !== Token.Keyword || token.value !== keyword) {1922throwUnexpected(token);1923}1924}19251926// Return true if the next token matches the specified punctuator.19271928function match(value) {1929return lookahead.type === Token.Punctuator && lookahead.value === value;1930}19311932// Return true if the next token matches the specified keyword19331934function matchKeyword(keyword) {1935return lookahead.type === Token.Keyword && lookahead.value === keyword;1936}19371938// Return true if the next token is an assignment operator19391940function matchAssign() {1941var op;19421943if (lookahead.type !== Token.Punctuator) {1944return false;1945}1946op = lookahead.value;1947return op === '=' ||1948op === '*=' ||1949op === '/=' ||1950op === '%=' ||1951op === '+=' ||1952op === '-=' ||1953op === '<<=' ||1954op === '>>=' ||1955op === '>>>=' ||1956op === '&=' ||1957op === '^=' ||1958op === '|=';1959}19601961function consumeSemicolon() {1962var line, oldIndex = index, oldLineNumber = lineNumber,1963oldLineStart = lineStart, oldLookahead = lookahead;19641965// Catch the very common case first: immediately a semicolon (U+003B).1966if (source.charCodeAt(index) === 0x3B || match(';')) {1967lex();1968return;1969}19701971line = lineNumber;1972skipComment();1973if (lineNumber !== line) {1974index = oldIndex;1975lineNumber = oldLineNumber;1976lineStart = oldLineStart;1977lookahead = oldLookahead;1978return;1979}19801981if (lookahead.type !== Token.EOF && !match('}')) {1982throwUnexpected(lookahead);1983}1984}19851986// Return true if provided expression is LeftHandSideExpression19871988function isLeftHandSide(expr) {1989return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;1990}19911992// 11.1.4 Array Initialiser19931994function parseArrayInitialiser() {1995var elements = [], startToken;19961997startToken = lookahead;1998expect('[');19992000while (!match(']')) {2001if (match(',')) {2002lex();2003elements.push(null);2004} else {2005elements.push(parseAssignmentExpression());20062007if (!match(']')) {2008expect(',');2009}2010}2011}20122013lex();20142015return delegate.markEnd(delegate.createArrayExpression(elements), startToken);2016}20172018// 11.1.5 Object Initialiser20192020function parsePropertyFunction(param, first) {2021var previousStrict, body, startToken;20222023previousStrict = strict;2024startToken = lookahead;2025body = parseFunctionSourceElements();2026if (first && strict && isRestrictedWord(param[0].name)) {2027throwErrorTolerant(first, Messages.StrictParamName);2028}2029strict = previousStrict;2030return delegate.markEnd(delegate.createFunctionExpression(null, param, [], body), startToken);2031}20322033function parseObjectPropertyKey() {2034var token, startToken;20352036startToken = lookahead;2037token = lex();20382039// Note: This function is called only from parseObjectProperty(), where2040// EOF and Punctuator tokens are already filtered out.20412042if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) {2043if (strict && token.octal) {2044throwErrorTolerant(token, Messages.StrictOctalLiteral);2045}2046return delegate.markEnd(delegate.createLiteral(token), startToken);2047}20482049return delegate.markEnd(delegate.createIdentifier(token.value), startToken);2050}20512052function parseObjectProperty() {2053var token, key, id, value, param, startToken;20542055token = lookahead;2056startToken = lookahead;20572058if (token.type === Token.Identifier) {20592060id = parseObjectPropertyKey();20612062// Property Assignment: Getter and Setter.20632064if (token.value === 'get' && !match(':')) {2065key = parseObjectPropertyKey();2066expect('(');2067expect(')');2068value = parsePropertyFunction([]);2069return delegate.markEnd(delegate.createProperty('get', key, value), startToken);2070}2071if (token.value === 'set' && !match(':')) {2072key = parseObjectPropertyKey();2073expect('(');2074token = lookahead;2075if (token.type !== Token.Identifier) {2076expect(')');2077throwErrorTolerant(token, Messages.UnexpectedToken, token.value);2078value = parsePropertyFunction([]);2079} else {2080param = [ parseVariableIdentifier() ];2081expect(')');2082value = parsePropertyFunction(param, token);2083}2084return delegate.markEnd(delegate.createProperty('set', key, value), startToken);2085}2086expect(':');2087value = parseAssignmentExpression();2088return delegate.markEnd(delegate.createProperty('init', id, value), startToken);2089}2090if (token.type === Token.EOF || token.type === Token.Punctuator) {2091throwUnexpected(token);2092} else {2093key = parseObjectPropertyKey();2094expect(':');2095value = parseAssignmentExpression();2096return delegate.markEnd(delegate.createProperty('init', key, value), startToken);2097}2098}20992100function parseObjectInitialiser() {2101var properties = [], property, name, key, kind, map = {}, toString = String, startToken;21022103startToken = lookahead;21042105expect('{');21062107while (!match('}')) {2108property = parseObjectProperty();21092110if (property.key.type === Syntax.Identifier) {2111name = property.key.name;2112} else {2113name = toString(property.key.value);2114}2115kind = (property.kind === 'init') ? PropertyKind.Data : (property.kind === 'get') ? PropertyKind.Get : PropertyKind.Set;21162117key = '$' + name;2118if (Object.prototype.hasOwnProperty.call(map, key)) {2119if (map[key] === PropertyKind.Data) {2120if (strict && kind === PropertyKind.Data) {2121throwErrorTolerant({}, Messages.StrictDuplicateProperty);2122} else if (kind !== PropertyKind.Data) {2123throwErrorTolerant({}, Messages.AccessorDataProperty);2124}2125} else {2126if (kind === PropertyKind.Data) {2127throwErrorTolerant({}, Messages.AccessorDataProperty);2128} else if (map[key] & kind) {2129throwErrorTolerant({}, Messages.AccessorGetSet);2130}2131}2132map[key] |= kind;2133} else {2134map[key] = kind;2135}21362137properties.push(property);21382139if (!match('}')) {2140expect(',');2141}2142}21432144expect('}');21452146return delegate.markEnd(delegate.createObjectExpression(properties), startToken);2147}21482149// 11.1.6 The Grouping Operator21502151function parseGroupExpression() {2152var expr;21532154expect('(');21552156expr = parseExpression();21572158expect(')');21592160return expr;2161}216221632164// 11.1 Primary Expressions21652166function parsePrimaryExpression() {2167var type, token, expr, startToken;21682169if (match('(')) {2170return parseGroupExpression();2171}21722173if (match('[')) {2174return parseArrayInitialiser();2175}21762177if (match('{')) {2178return parseObjectInitialiser();2179}21802181type = lookahead.type;2182startToken = lookahead;21832184if (type === Token.Identifier) {2185expr = delegate.createIdentifier(lex().value);2186} else if (type === Token.StringLiteral || type === Token.NumericLiteral) {2187if (strict && lookahead.octal) {2188throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);2189}2190expr = delegate.createLiteral(lex());2191} else if (type === Token.Keyword) {2192if (matchKeyword('function')) {2193return parseFunctionExpression();2194}2195if (matchKeyword('this')) {2196lex();2197expr = delegate.createThisExpression();2198} else {2199throwUnexpected(lex());2200}2201} else if (type === Token.BooleanLiteral) {2202token = lex();2203token.value = (token.value === 'true');2204expr = delegate.createLiteral(token);2205} else if (type === Token.NullLiteral) {2206token = lex();2207token.value = null;2208expr = delegate.createLiteral(token);2209} else if (match('/') || match('/=')) {2210if (typeof extra.tokens !== 'undefined') {2211expr = delegate.createLiteral(collectRegex());2212} else {2213expr = delegate.createLiteral(scanRegExp());2214}2215peek();2216} else {2217throwUnexpected(lex());2218}22192220return delegate.markEnd(expr, startToken);2221}22222223// 11.2 Left-Hand-Side Expressions22242225function parseArguments() {2226var args = [];22272228expect('(');22292230if (!match(')')) {2231while (index < length) {2232args.push(parseAssignmentExpression());2233if (match(')')) {2234break;2235}2236expect(',');2237}2238}22392240expect(')');22412242return args;2243}22442245function parseNonComputedProperty() {2246var token, startToken;22472248startToken = lookahead;2249token = lex();22502251if (!isIdentifierName(token)) {2252throwUnexpected(token);2253}22542255return delegate.markEnd(delegate.createIdentifier(token.value), startToken);2256}22572258function parseNonComputedMember() {2259expect('.');22602261return parseNonComputedProperty();2262}22632264function parseComputedMember() {2265var expr;22662267expect('[');22682269expr = parseExpression();22702271expect(']');22722273return expr;2274}22752276function parseNewExpression() {2277var callee, args, startToken;22782279startToken = lookahead;2280expectKeyword('new');2281callee = parseLeftHandSideExpression();2282args = match('(') ? parseArguments() : [];22832284return delegate.markEnd(delegate.createNewExpression(callee, args), startToken);2285}22862287function parseLeftHandSideExpressionAllowCall() {2288var expr, args, property, startToken, previousAllowIn = state.allowIn;22892290startToken = lookahead;2291state.allowIn = true;2292expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();22932294for (;;) {2295if (match('.')) {2296property = parseNonComputedMember();2297expr = delegate.createMemberExpression('.', expr, property);2298} else if (match('(')) {2299args = parseArguments();2300expr = delegate.createCallExpression(expr, args);2301} else if (match('[')) {2302property = parseComputedMember();2303expr = delegate.createMemberExpression('[', expr, property);2304} else {2305break;2306}2307delegate.markEnd(expr, startToken);2308}2309state.allowIn = previousAllowIn;23102311return expr;2312}23132314function parseLeftHandSideExpression() {2315var expr, property, startToken;2316assert(state.allowIn, 'callee of new expression always allow in keyword.');23172318startToken = lookahead;23192320expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();23212322while (match('.') || match('[')) {2323if (match('[')) {2324property = parseComputedMember();2325expr = delegate.createMemberExpression('[', expr, property);2326} else {2327property = parseNonComputedMember();2328expr = delegate.createMemberExpression('.', expr, property);2329}2330delegate.markEnd(expr, startToken);2331}2332return expr;2333}23342335// 11.3 Postfix Expressions23362337function parsePostfixExpression() {2338var expr, token, startToken = lookahead;23392340expr = parseLeftHandSideExpressionAllowCall();23412342if (lookahead.type === Token.Punctuator) {2343if ((match('++') || match('--')) && !peekLineTerminator()) {2344// 11.3.1, 11.3.22345if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {2346throwErrorTolerant({}, Messages.StrictLHSPostfix);2347}23482349if (!isLeftHandSide(expr)) {2350throwErrorTolerant({}, Messages.InvalidLHSInAssignment);2351}23522353token = lex();2354expr = delegate.markEnd(delegate.createPostfixExpression(token.value, expr), startToken);2355}2356}23572358return expr;2359}23602361// 11.4 Unary Operators23622363function parseUnaryExpression() {2364var token, expr, startToken;23652366if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {2367expr = parsePostfixExpression();2368} else if (match('++') || match('--')) {2369startToken = lookahead;2370token = lex();2371expr = parseUnaryExpression();2372// 11.4.4, 11.4.52373if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {2374throwErrorTolerant({}, Messages.StrictLHSPrefix);2375}23762377if (!isLeftHandSide(expr)) {2378throwErrorTolerant({}, Messages.InvalidLHSInAssignment);2379}23802381expr = delegate.createUnaryExpression(token.value, expr);2382expr = delegate.markEnd(expr, startToken);2383} else if (match('+') || match('-') || match('~') || match('!')) {2384startToken = lookahead;2385token = lex();2386expr = parseUnaryExpression();2387expr = delegate.createUnaryExpression(token.value, expr);2388expr = delegate.markEnd(expr, startToken);2389} else if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {2390startToken = lookahead;2391token = lex();2392expr = parseUnaryExpression();2393expr = delegate.createUnaryExpression(token.value, expr);2394expr = delegate.markEnd(expr, startToken);2395if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {2396throwErrorTolerant({}, Messages.StrictDelete);2397}2398} else {2399expr = parsePostfixExpression();2400}24012402return expr;2403}24042405function binaryPrecedence(token, allowIn) {2406var prec = 0;24072408if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {2409return 0;2410}24112412switch (token.value) {2413case '||':2414prec = 1;2415break;24162417case '&&':2418prec = 2;2419break;24202421case '|':2422prec = 3;2423break;24242425case '^':2426prec = 4;2427break;24282429case '&':2430prec = 5;2431break;24322433case '==':2434case '!=':2435case '===':2436case '!==':2437prec = 6;2438break;24392440case '<':2441case '>':2442case '<=':2443case '>=':2444case 'instanceof':2445prec = 7;2446break;24472448case 'in':2449prec = allowIn ? 7 : 0;2450break;24512452case '<<':2453case '>>':2454case '>>>':2455prec = 8;2456break;24572458case '+':2459case '-':2460prec = 9;2461break;24622463case '*':2464case '/':2465case '%':2466prec = 11;2467break;24682469default:2470break;2471}24722473return prec;2474}24752476// 11.5 Multiplicative Operators2477// 11.6 Additive Operators2478// 11.7 Bitwise Shift Operators2479// 11.8 Relational Operators2480// 11.9 Equality Operators2481// 11.10 Binary Bitwise Operators2482// 11.11 Binary Logical Operators24832484function parseBinaryExpression() {2485var marker, markers, expr, token, prec, stack, right, operator, left, i;24862487marker = lookahead;2488left = parseUnaryExpression();24892490token = lookahead;2491prec = binaryPrecedence(token, state.allowIn);2492if (prec === 0) {2493return left;2494}2495token.prec = prec;2496lex();24972498markers = [marker, lookahead];2499right = parseUnaryExpression();25002501stack = [left, token, right];25022503while ((prec = binaryPrecedence(lookahead, state.allowIn)) > 0) {25042505// Reduce: make a binary expression from the three topmost entries.2506while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {2507right = stack.pop();2508operator = stack.pop().value;2509left = stack.pop();2510expr = delegate.createBinaryExpression(operator, left, right);2511markers.pop();2512marker = markers[markers.length - 1];2513delegate.markEnd(expr, marker);2514stack.push(expr);2515}25162517// Shift.2518token = lex();2519token.prec = prec;2520stack.push(token);2521markers.push(lookahead);2522expr = parseUnaryExpression();2523stack.push(expr);2524}25252526// Final reduce to clean-up the stack.2527i = stack.length - 1;2528expr = stack[i];2529markers.pop();2530while (i > 1) {2531expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);2532i -= 2;2533marker = markers.pop();2534delegate.markEnd(expr, marker);2535}25362537return expr;2538}253925402541// 11.12 Conditional Operator25422543function parseConditionalExpression() {2544var expr, previousAllowIn, consequent, alternate, startToken;25452546startToken = lookahead;25472548expr = parseBinaryExpression();25492550if (match('?')) {2551lex();2552previousAllowIn = state.allowIn;2553state.allowIn = true;2554consequent = parseAssignmentExpression();2555state.allowIn = previousAllowIn;2556expect(':');2557alternate = parseAssignmentExpression();25582559expr = delegate.createConditionalExpression(expr, consequent, alternate);2560delegate.markEnd(expr, startToken);2561}25622563return expr;2564}25652566// 11.13 Assignment Operators25672568function parseAssignmentExpression() {2569var token, left, right, node, startToken;25702571token = lookahead;2572startToken = lookahead;25732574node = left = parseConditionalExpression();25752576if (matchAssign()) {2577// LeftHandSideExpression2578if (!isLeftHandSide(left)) {2579throwErrorTolerant({}, Messages.InvalidLHSInAssignment);2580}25812582// 11.13.12583if (strict && left.type === Syntax.Identifier && isRestrictedWord(left.name)) {2584throwErrorTolerant(token, Messages.StrictLHSAssignment);2585}25862587token = lex();2588right = parseAssignmentExpression();2589node = delegate.markEnd(delegate.createAssignmentExpression(token.value, left, right), startToken);2590}25912592return node;2593}25942595// 11.14 Comma Operator25962597function parseExpression() {2598var expr, startToken = lookahead;25992600expr = parseAssignmentExpression();26012602if (match(',')) {2603expr = delegate.createSequenceExpression([ expr ]);26042605while (index < length) {2606if (!match(',')) {2607break;2608}2609lex();2610expr.expressions.push(parseAssignmentExpression());2611}26122613delegate.markEnd(expr, startToken);2614}26152616return expr;2617}26182619// 12.1 Block26202621function parseStatementList() {2622var list = [],2623statement;26242625while (index < length) {2626if (match('}')) {2627break;2628}2629statement = parseSourceElement();2630if (typeof statement === 'undefined') {2631break;2632}2633list.push(statement);2634}26352636return list;2637}26382639function parseBlock() {2640var block, startToken;26412642startToken = lookahead;2643expect('{');26442645block = parseStatementList();26462647expect('}');26482649return delegate.markEnd(delegate.createBlockStatement(block), startToken);2650}26512652// 12.2 Variable Statement26532654function parseVariableIdentifier() {2655var token, startToken;26562657startToken = lookahead;2658token = lex();26592660if (token.type !== Token.Identifier) {2661throwUnexpected(token);2662}26632664return delegate.markEnd(delegate.createIdentifier(token.value), startToken);2665}26662667function parseVariableDeclaration(kind) {2668var init = null, id, startToken;26692670startToken = lookahead;2671id = parseVariableIdentifier();26722673// 12.2.12674if (strict && isRestrictedWord(id.name)) {2675throwErrorTolerant({}, Messages.StrictVarName);2676}26772678if (kind === 'const') {2679expect('=');2680init = parseAssignmentExpression();2681} else if (match('=')) {2682lex();2683init = parseAssignmentExpression();2684}26852686return delegate.markEnd(delegate.createVariableDeclarator(id, init), startToken);2687}26882689function parseVariableDeclarationList(kind) {2690var list = [];26912692do {2693list.push(parseVariableDeclaration(kind));2694if (!match(',')) {2695break;2696}2697lex();2698} while (index < length);26992700return list;2701}27022703function parseVariableStatement() {2704var declarations;27052706expectKeyword('var');27072708declarations = parseVariableDeclarationList();27092710consumeSemicolon();27112712return delegate.createVariableDeclaration(declarations, 'var');2713}27142715// kind may be `const` or `let`2716// Both are experimental and not in the specification yet.2717// see http://wiki.ecmascript.org/doku.php?id=harmony:const2718// and http://wiki.ecmascript.org/doku.php?id=harmony:let2719function parseConstLetDeclaration(kind) {2720var declarations, startToken;27212722startToken = lookahead;27232724expectKeyword(kind);27252726declarations = parseVariableDeclarationList(kind);27272728consumeSemicolon();27292730return delegate.markEnd(delegate.createVariableDeclaration(declarations, kind), startToken);2731}27322733// 12.3 Empty Statement27342735function parseEmptyStatement() {2736expect(';');2737return delegate.createEmptyStatement();2738}27392740// 12.4 Expression Statement27412742function parseExpressionStatement() {2743var expr = parseExpression();2744consumeSemicolon();2745return delegate.createExpressionStatement(expr);2746}27472748// 12.5 If statement27492750function parseIfStatement() {2751var test, consequent, alternate;27522753expectKeyword('if');27542755expect('(');27562757test = parseExpression();27582759expect(')');27602761consequent = parseStatement();27622763if (matchKeyword('else')) {2764lex();2765alternate = parseStatement();2766} else {2767alternate = null;2768}27692770return delegate.createIfStatement(test, consequent, alternate);2771}27722773// 12.6 Iteration Statements27742775function parseDoWhileStatement() {2776var body, test, oldInIteration;27772778expectKeyword('do');27792780oldInIteration = state.inIteration;2781state.inIteration = true;27822783body = parseStatement();27842785state.inIteration = oldInIteration;27862787expectKeyword('while');27882789expect('(');27902791test = parseExpression();27922793expect(')');27942795if (match(';')) {2796lex();2797}27982799return delegate.createDoWhileStatement(body, test);2800}28012802function parseWhileStatement() {2803var test, body, oldInIteration;28042805expectKeyword('while');28062807expect('(');28082809test = parseExpression();28102811expect(')');28122813oldInIteration = state.inIteration;2814state.inIteration = true;28152816body = parseStatement();28172818state.inIteration = oldInIteration;28192820return delegate.createWhileStatement(test, body);2821}28222823function parseForVariableDeclaration() {2824var token, declarations, startToken;28252826startToken = lookahead;2827token = lex();2828declarations = parseVariableDeclarationList();28292830return delegate.markEnd(delegate.createVariableDeclaration(declarations, token.value), startToken);2831}28322833function parseForStatement() {2834var init, test, update, left, right, body, oldInIteration, previousAllowIn = state.allowIn;28352836init = test = update = null;28372838expectKeyword('for');28392840expect('(');28412842if (match(';')) {2843lex();2844} else {2845if (matchKeyword('var') || matchKeyword('let')) {2846state.allowIn = false;2847init = parseForVariableDeclaration();2848state.allowIn = previousAllowIn;28492850if (init.declarations.length === 1 && matchKeyword('in')) {2851lex();2852left = init;2853right = parseExpression();2854init = null;2855}2856} else {2857state.allowIn = false;2858init = parseExpression();2859state.allowIn = previousAllowIn;28602861if (matchKeyword('in')) {2862// LeftHandSideExpression2863if (!isLeftHandSide(init)) {2864throwErrorTolerant({}, Messages.InvalidLHSInForIn);2865}28662867lex();2868left = init;2869right = parseExpression();2870init = null;2871}2872}28732874if (typeof left === 'undefined') {2875expect(';');2876}2877}28782879if (typeof left === 'undefined') {28802881if (!match(';')) {2882test = parseExpression();2883}2884expect(';');28852886if (!match(')')) {2887update = parseExpression();2888}2889}28902891expect(')');28922893oldInIteration = state.inIteration;2894state.inIteration = true;28952896body = parseStatement();28972898state.inIteration = oldInIteration;28992900return (typeof left === 'undefined') ?2901delegate.createForStatement(init, test, update, body) :2902delegate.createForInStatement(left, right, body);2903}29042905// 12.7 The continue statement29062907function parseContinueStatement() {2908var label = null, key;29092910expectKeyword('continue');29112912// Optimize the most common form: 'continue;'.2913if (source.charCodeAt(index) === 0x3B) {2914lex();29152916if (!state.inIteration) {2917throwError({}, Messages.IllegalContinue);2918}29192920return delegate.createContinueStatement(null);2921}29222923if (peekLineTerminator()) {2924if (!state.inIteration) {2925throwError({}, Messages.IllegalContinue);2926}29272928return delegate.createContinueStatement(null);2929}29302931if (lookahead.type === Token.Identifier) {2932label = parseVariableIdentifier();29332934key = '$' + label.name;2935if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {2936throwError({}, Messages.UnknownLabel, label.name);2937}2938}29392940consumeSemicolon();29412942if (label === null && !state.inIteration) {2943throwError({}, Messages.IllegalContinue);2944}29452946return delegate.createContinueStatement(label);2947}29482949// 12.8 The break statement29502951function parseBreakStatement() {2952var label = null, key;29532954expectKeyword('break');29552956// Catch the very common case first: immediately a semicolon (U+003B).2957if (source.charCodeAt(index) === 0x3B) {2958lex();29592960if (!(state.inIteration || state.inSwitch)) {2961throwError({}, Messages.IllegalBreak);2962}29632964return delegate.createBreakStatement(null);2965}29662967if (peekLineTerminator()) {2968if (!(state.inIteration || state.inSwitch)) {2969throwError({}, Messages.IllegalBreak);2970}29712972return delegate.createBreakStatement(null);2973}29742975if (lookahead.type === Token.Identifier) {2976label = parseVariableIdentifier();29772978key = '$' + label.name;2979if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {2980throwError({}, Messages.UnknownLabel, label.name);2981}2982}29832984consumeSemicolon();29852986if (label === null && !(state.inIteration || state.inSwitch)) {2987throwError({}, Messages.IllegalBreak);2988}29892990return delegate.createBreakStatement(label);2991}29922993// 12.9 The return statement29942995function parseReturnStatement() {2996var argument = null;29972998expectKeyword('return');29993000if (!state.inFunctionBody) {3001throwErrorTolerant({}, Messages.IllegalReturn);3002}30033004// 'return' followed by a space and an identifier is very common.3005if (source.charCodeAt(index) === 0x20) {3006if (isIdentifierStart(source.charCodeAt(index + 1))) {3007argument = parseExpression();3008consumeSemicolon();3009return delegate.createReturnStatement(argument);3010}3011}30123013if (peekLineTerminator()) {3014return delegate.createReturnStatement(null);3015}30163017if (!match(';')) {3018if (!match('}') && lookahead.type !== Token.EOF) {3019argument = parseExpression();3020}3021}30223023consumeSemicolon();30243025return delegate.createReturnStatement(argument);3026}30273028// 12.10 The with statement30293030function parseWithStatement() {3031var object, body;30323033if (strict) {3034// TODO(ikarienator): Should we update the test cases instead?3035skipComment();3036throwErrorTolerant({}, Messages.StrictModeWith);3037}30383039expectKeyword('with');30403041expect('(');30423043object = parseExpression();30443045expect(')');30463047body = parseStatement();30483049return delegate.createWithStatement(object, body);3050}30513052// 12.10 The swith statement30533054function parseSwitchCase() {3055var test, consequent = [], statement, startToken;30563057startToken = lookahead;3058if (matchKeyword('default')) {3059lex();3060test = null;3061} else {3062expectKeyword('case');3063test = parseExpression();3064}3065expect(':');30663067while (index < length) {3068if (match('}') || matchKeyword('default') || matchKeyword('case')) {3069break;3070}3071statement = parseStatement();3072consequent.push(statement);3073}30743075return delegate.markEnd(delegate.createSwitchCase(test, consequent), startToken);3076}30773078function parseSwitchStatement() {3079var discriminant, cases, clause, oldInSwitch, defaultFound;30803081expectKeyword('switch');30823083expect('(');30843085discriminant = parseExpression();30863087expect(')');30883089expect('{');30903091cases = [];30923093if (match('}')) {3094lex();3095return delegate.createSwitchStatement(discriminant, cases);3096}30973098oldInSwitch = state.inSwitch;3099state.inSwitch = true;3100defaultFound = false;31013102while (index < length) {3103if (match('}')) {3104break;3105}3106clause = parseSwitchCase();3107if (clause.test === null) {3108if (defaultFound) {3109throwError({}, Messages.MultipleDefaultsInSwitch);3110}3111defaultFound = true;3112}3113cases.push(clause);3114}31153116state.inSwitch = oldInSwitch;31173118expect('}');31193120return delegate.createSwitchStatement(discriminant, cases);3121}31223123// 12.13 The throw statement31243125function parseThrowStatement() {3126var argument;31273128expectKeyword('throw');31293130if (peekLineTerminator()) {3131throwError({}, Messages.NewlineAfterThrow);3132}31333134argument = parseExpression();31353136consumeSemicolon();31373138return delegate.createThrowStatement(argument);3139}31403141// 12.14 The try statement31423143function parseCatchClause() {3144var param, body, startToken;31453146startToken = lookahead;3147expectKeyword('catch');31483149expect('(');3150if (match(')')) {3151throwUnexpected(lookahead);3152}31533154param = parseVariableIdentifier();3155// 12.14.13156if (strict && isRestrictedWord(param.name)) {3157throwErrorTolerant({}, Messages.StrictCatchVariable);3158}31593160expect(')');3161body = parseBlock();3162return delegate.markEnd(delegate.createCatchClause(param, body), startToken);3163}31643165function parseTryStatement() {3166var block, handlers = [], finalizer = null;31673168expectKeyword('try');31693170block = parseBlock();31713172if (matchKeyword('catch')) {3173handlers.push(parseCatchClause());3174}31753176if (matchKeyword('finally')) {3177lex();3178finalizer = parseBlock();3179}31803181if (handlers.length === 0 && !finalizer) {3182throwError({}, Messages.NoCatchOrFinally);3183}31843185return delegate.createTryStatement(block, [], handlers, finalizer);3186}31873188// 12.15 The debugger statement31893190function parseDebuggerStatement() {3191expectKeyword('debugger');31923193consumeSemicolon();31943195return delegate.createDebuggerStatement();3196}31973198// 12 Statements31993200function parseStatement() {3201var type = lookahead.type,3202expr,3203labeledBody,3204key,3205startToken;32063207if (type === Token.EOF) {3208throwUnexpected(lookahead);3209}32103211if (type === Token.Punctuator && lookahead.value === '{') {3212return parseBlock();3213}32143215startToken = lookahead;32163217if (type === Token.Punctuator) {3218switch (lookahead.value) {3219case ';':3220return delegate.markEnd(parseEmptyStatement(), startToken);3221case '(':3222return delegate.markEnd(parseExpressionStatement(), startToken);3223default:3224break;3225}3226}32273228if (type === Token.Keyword) {3229switch (lookahead.value) {3230case 'break':3231return delegate.markEnd(parseBreakStatement(), startToken);3232case 'continue':3233return delegate.markEnd(parseContinueStatement(), startToken);3234case 'debugger':3235return delegate.markEnd(parseDebuggerStatement(), startToken);3236case 'do':3237return delegate.markEnd(parseDoWhileStatement(), startToken);3238case 'for':3239return delegate.markEnd(parseForStatement(), startToken);3240case 'function':3241return delegate.markEnd(parseFunctionDeclaration(), startToken);3242case 'if':3243return delegate.markEnd(parseIfStatement(), startToken);3244case 'return':3245return delegate.markEnd(parseReturnStatement(), startToken);3246case 'switch':3247return delegate.markEnd(parseSwitchStatement(), startToken);3248case 'throw':3249return delegate.markEnd(parseThrowStatement(), startToken);3250case 'try':3251return delegate.markEnd(parseTryStatement(), startToken);3252case 'var':3253return delegate.markEnd(parseVariableStatement(), startToken);3254case 'while':3255return delegate.markEnd(parseWhileStatement(), startToken);3256case 'with':3257return delegate.markEnd(parseWithStatement(), startToken);3258default:3259break;3260}3261}32623263expr = parseExpression();32643265// 12.12 Labelled Statements3266if ((expr.type === Syntax.Identifier) && match(':')) {3267lex();32683269key = '$' + expr.name;3270if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {3271throwError({}, Messages.Redeclaration, 'Label', expr.name);3272}32733274state.labelSet[key] = true;3275labeledBody = parseStatement();3276delete state.labelSet[key];3277return delegate.markEnd(delegate.createLabeledStatement(expr, labeledBody), startToken);3278}32793280consumeSemicolon();32813282return delegate.markEnd(delegate.createExpressionStatement(expr), startToken);3283}32843285// 13 Function Definition32863287function parseFunctionSourceElements() {3288var sourceElement, sourceElements = [], token, directive, firstRestricted,3289oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, startToken;32903291startToken = lookahead;3292expect('{');32933294while (index < length) {3295if (lookahead.type !== Token.StringLiteral) {3296break;3297}3298token = lookahead;32993300sourceElement = parseSourceElement();3301sourceElements.push(sourceElement);3302if (sourceElement.expression.type !== Syntax.Literal) {3303// this is not directive3304break;3305}3306directive = source.slice(token.start + 1, token.end - 1);3307if (directive === 'use strict') {3308strict = true;3309if (firstRestricted) {3310throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);3311}3312} else {3313if (!firstRestricted && token.octal) {3314firstRestricted = token;3315}3316}3317}33183319oldLabelSet = state.labelSet;3320oldInIteration = state.inIteration;3321oldInSwitch = state.inSwitch;3322oldInFunctionBody = state.inFunctionBody;33233324state.labelSet = {};3325state.inIteration = false;3326state.inSwitch = false;3327state.inFunctionBody = true;33283329while (index < length) {3330if (match('}')) {3331break;3332}3333sourceElement = parseSourceElement();3334if (typeof sourceElement === 'undefined') {3335break;3336}3337sourceElements.push(sourceElement);3338}33393340expect('}');33413342state.labelSet = oldLabelSet;3343state.inIteration = oldInIteration;3344state.inSwitch = oldInSwitch;3345state.inFunctionBody = oldInFunctionBody;33463347return delegate.markEnd(delegate.createBlockStatement(sourceElements), startToken);3348}33493350function parseParams(firstRestricted) {3351var param, params = [], token, stricted, paramSet, key, message;3352expect('(');33533354if (!match(')')) {3355paramSet = {};3356while (index < length) {3357token = lookahead;3358param = parseVariableIdentifier();3359key = '$' + token.value;3360if (strict) {3361if (isRestrictedWord(token.value)) {3362stricted = token;3363message = Messages.StrictParamName;3364}3365if (Object.prototype.hasOwnProperty.call(paramSet, key)) {3366stricted = token;3367message = Messages.StrictParamDupe;3368}3369} else if (!firstRestricted) {3370if (isRestrictedWord(token.value)) {3371firstRestricted = token;3372message = Messages.StrictParamName;3373} else if (isStrictModeReservedWord(token.value)) {3374firstRestricted = token;3375message = Messages.StrictReservedWord;3376} else if (Object.prototype.hasOwnProperty.call(paramSet, key)) {3377firstRestricted = token;3378message = Messages.StrictParamDupe;3379}3380}3381params.push(param);3382paramSet[key] = true;3383if (match(')')) {3384break;3385}3386expect(',');3387}3388}33893390expect(')');33913392return {3393params: params,3394stricted: stricted,3395firstRestricted: firstRestricted,3396message: message3397};3398}33993400function parseFunctionDeclaration() {3401var id, params = [], body, token, stricted, tmp, firstRestricted, message, previousStrict, startToken;34023403startToken = lookahead;34043405expectKeyword('function');3406token = lookahead;3407id = parseVariableIdentifier();3408if (strict) {3409if (isRestrictedWord(token.value)) {3410throwErrorTolerant(token, Messages.StrictFunctionName);3411}3412} else {3413if (isRestrictedWord(token.value)) {3414firstRestricted = token;3415message = Messages.StrictFunctionName;3416} else if (isStrictModeReservedWord(token.value)) {3417firstRestricted = token;3418message = Messages.StrictReservedWord;3419}3420}34213422tmp = parseParams(firstRestricted);3423params = tmp.params;3424stricted = tmp.stricted;3425firstRestricted = tmp.firstRestricted;3426if (tmp.message) {3427message = tmp.message;3428}34293430previousStrict = strict;3431body = parseFunctionSourceElements();3432if (strict && firstRestricted) {3433throwError(firstRestricted, message);3434}3435if (strict && stricted) {3436throwErrorTolerant(stricted, message);3437}3438strict = previousStrict;34393440return delegate.markEnd(delegate.createFunctionDeclaration(id, params, [], body), startToken);3441}34423443function parseFunctionExpression() {3444var token, id = null, stricted, firstRestricted, message, tmp, params = [], body, previousStrict, startToken;34453446startToken = lookahead;3447expectKeyword('function');34483449if (!match('(')) {3450token = lookahead;3451id = parseVariableIdentifier();3452if (strict) {3453if (isRestrictedWord(token.value)) {3454throwErrorTolerant(token, Messages.StrictFunctionName);3455}3456} else {3457if (isRestrictedWord(token.value)) {3458firstRestricted = token;3459message = Messages.StrictFunctionName;3460} else if (isStrictModeReservedWord(token.value)) {3461firstRestricted = token;3462message = Messages.StrictReservedWord;3463}3464}3465}34663467tmp = parseParams(firstRestricted);3468params = tmp.params;3469stricted = tmp.stricted;3470firstRestricted = tmp.firstRestricted;3471if (tmp.message) {3472message = tmp.message;3473}34743475previousStrict = strict;3476body = parseFunctionSourceElements();3477if (strict && firstRestricted) {3478throwError(firstRestricted, message);3479}3480if (strict && stricted) {3481throwErrorTolerant(stricted, message);3482}3483strict = previousStrict;34843485return delegate.markEnd(delegate.createFunctionExpression(id, params, [], body), startToken);3486}34873488// 14 Program34893490function parseSourceElement() {3491if (lookahead.type === Token.Keyword) {3492switch (lookahead.value) {3493case 'const':3494case 'let':3495return parseConstLetDeclaration(lookahead.value);3496case 'function':3497return parseFunctionDeclaration();3498default:3499return parseStatement();3500}3501}35023503if (lookahead.type !== Token.EOF) {3504return parseStatement();3505}3506}35073508function parseSourceElements() {3509var sourceElement, sourceElements = [], token, directive, firstRestricted;35103511while (index < length) {3512token = lookahead;3513if (token.type !== Token.StringLiteral) {3514break;3515}35163517sourceElement = parseSourceElement();3518sourceElements.push(sourceElement);3519if (sourceElement.expression.type !== Syntax.Literal) {3520// this is not directive3521break;3522}3523directive = source.slice(token.start + 1, token.end - 1);3524if (directive === 'use strict') {3525strict = true;3526if (firstRestricted) {3527throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);3528}3529} else {3530if (!firstRestricted && token.octal) {3531firstRestricted = token;3532}3533}3534}35353536while (index < length) {3537sourceElement = parseSourceElement();3538/* istanbul ignore if */3539if (typeof sourceElement === 'undefined') {3540break;3541}3542sourceElements.push(sourceElement);3543}3544return sourceElements;3545}35463547function parseProgram() {3548var body, startToken;35493550skipComment();3551peek();3552startToken = lookahead;3553strict = false;35543555body = parseSourceElements();3556return delegate.markEnd(delegate.createProgram(body), startToken);3557}35583559function filterTokenLocation() {3560var i, entry, token, tokens = [];35613562for (i = 0; i < extra.tokens.length; ++i) {3563entry = extra.tokens[i];3564token = {3565type: entry.type,3566value: entry.value3567};3568if (extra.range) {3569token.range = entry.range;3570}3571if (extra.loc) {3572token.loc = entry.loc;3573}3574tokens.push(token);3575}35763577extra.tokens = tokens;3578}35793580function tokenize(code, options) {3581var toString,3582token,3583tokens;35843585toString = String;3586if (typeof code !== 'string' && !(code instanceof String)) {3587code = toString(code);3588}35893590delegate = SyntaxTreeDelegate;3591source = code;3592index = 0;3593lineNumber = (source.length > 0) ? 1 : 0;3594lineStart = 0;3595length = source.length;3596lookahead = null;3597state = {3598allowIn: true,3599labelSet: {},3600inFunctionBody: false,3601inIteration: false,3602inSwitch: false,3603lastCommentStart: -13604};36053606extra = {};36073608// Options matching.3609options = options || {};36103611// Of course we collect tokens here.3612options.tokens = true;3613extra.tokens = [];3614extra.tokenize = true;3615// The following two fields are necessary to compute the Regex tokens.3616extra.openParenToken = -1;3617extra.openCurlyToken = -1;36183619extra.range = (typeof options.range === 'boolean') && options.range;3620extra.loc = (typeof options.loc === 'boolean') && options.loc;36213622if (typeof options.comment === 'boolean' && options.comment) {3623extra.comments = [];3624}3625if (typeof options.tolerant === 'boolean' && options.tolerant) {3626extra.errors = [];3627}36283629try {3630peek();3631if (lookahead.type === Token.EOF) {3632return extra.tokens;3633}36343635token = lex();3636while (lookahead.type !== Token.EOF) {3637try {3638token = lex();3639} catch (lexError) {3640token = lookahead;3641if (extra.errors) {3642extra.errors.push(lexError);3643// We have to break on the first error3644// to avoid infinite loops.3645break;3646} else {3647throw lexError;3648}3649}3650}36513652filterTokenLocation();3653tokens = extra.tokens;3654if (typeof extra.comments !== 'undefined') {3655tokens.comments = extra.comments;3656}3657if (typeof extra.errors !== 'undefined') {3658tokens.errors = extra.errors;3659}3660} catch (e) {3661throw e;3662} finally {3663extra = {};3664}3665return tokens;3666}36673668function parse(code, options) {3669var program, toString;36703671toString = String;3672if (typeof code !== 'string' && !(code instanceof String)) {3673code = toString(code);3674}36753676delegate = SyntaxTreeDelegate;3677source = code;3678index = 0;3679lineNumber = (source.length > 0) ? 1 : 0;3680lineStart = 0;3681length = source.length;3682lookahead = null;3683state = {3684allowIn: true,3685labelSet: {},3686inFunctionBody: false,3687inIteration: false,3688inSwitch: false,3689lastCommentStart: -13690};36913692extra = {};3693if (typeof options !== 'undefined') {3694extra.range = (typeof options.range === 'boolean') && options.range;3695extra.loc = (typeof options.loc === 'boolean') && options.loc;3696extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;36973698if (extra.loc && options.source !== null && options.source !== undefined) {3699extra.source = toString(options.source);3700}37013702if (typeof options.tokens === 'boolean' && options.tokens) {3703extra.tokens = [];3704}3705if (typeof options.comment === 'boolean' && options.comment) {3706extra.comments = [];3707}3708if (typeof options.tolerant === 'boolean' && options.tolerant) {3709extra.errors = [];3710}3711if (extra.attachComment) {3712extra.range = true;3713extra.comments = [];3714extra.bottomRightStack = [];3715extra.trailingComments = [];3716extra.leadingComments = [];3717}3718}37193720try {3721program = parseProgram();3722if (typeof extra.comments !== 'undefined') {3723program.comments = extra.comments;3724}3725if (typeof extra.tokens !== 'undefined') {3726filterTokenLocation();3727program.tokens = extra.tokens;3728}3729if (typeof extra.errors !== 'undefined') {3730program.errors = extra.errors;3731}3732} catch (e) {3733throw e;3734} finally {3735extra = {};3736}37373738return program;3739}37403741// Sync with *.json manifests.3742exports.version = '1.2.5';37433744exports.tokenize = tokenize;37453746exports.parse = parse;37473748// Deep copy.3749/* istanbul ignore next */3750exports.Syntax = (function () {3751var name, types = {};37523753if (typeof Object.create === 'function') {3754types = Object.create(null);3755}37563757for (name in Syntax) {3758if (Syntax.hasOwnProperty(name)) {3759types[name] = Syntax[name];3760}3761}37623763if (typeof Object.freeze === 'function') {3764Object.freeze(types);3765}37663767return types;3768}());37693770}));3771/* vim: set sw=4 ts=4 et tw=80 : */377237733774