react / wstein / node_modules / jest-cli / node_modules / node-haste / node_modules / esprima-fb / esprima.js
80669 views/*1Copyright (C) 2013 Ariya Hidayat <[email protected]>2Copyright (C) 2013 Thaddee Tyl <[email protected]>3Copyright (C) 2012 Ariya Hidayat <[email protected]>4Copyright (C) 2012 Mathias Bynens <[email protected]>5Copyright (C) 2012 Joost-Wim Boekesteijn <[email protected]>6Copyright (C) 2012 Kris Kowal <[email protected]>7Copyright (C) 2012 Yusuke Suzuki <[email protected]>8Copyright (C) 2012 Arpad Borsos <[email protected]>9Copyright (C) 2011 Ariya Hidayat <[email protected]>1011Redistribution and use in source and binary forms, with or without12modification, are permitted provided that the following conditions are met:1314* Redistributions of source code must retain the above copyright15notice, this list of conditions and the following disclaimer.16* Redistributions in binary form must reproduce the above copyright17notice, this list of conditions and the following disclaimer in the18documentation and/or other materials provided with the distribution.1920THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY24DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF29THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132/*jslint bitwise:true plusplus:true */33/*global esprima:true, define:true, exports:true, window: true,34throwError: true, generateStatement: true, peek: true,35parseAssignmentExpression: true, parseBlock: true,36parseClassExpression: true, parseClassDeclaration: true, parseExpression: true,37parseForStatement: true,38parseFunctionDeclaration: true, parseFunctionExpression: true,39parseFunctionSourceElements: true, parseVariableIdentifier: true,40parseImportSpecifier: true,41parseLeftHandSideExpression: true, parseParams: true, validateParam: true,42parseSpreadOrAssignmentExpression: true,43parseStatement: true, parseSourceElement: true, parseModuleBlock: true, parseConciseBody: true,44advanceXJSChild: true, isXJSIdentifierStart: true, isXJSIdentifierPart: true,45scanXJSStringLiteral: true, scanXJSIdentifier: true,46parseXJSAttributeValue: true, parseXJSChild: true, parseXJSElement: true, parseXJSExpressionContainer: true, parseXJSEmptyExpression: true,47parseTypeAnnotation: true, parseTypeAnnotatableIdentifier: true,48parseYieldExpression: true49*/5051(function (root, factory) {52'use strict';5354// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,55// Rhino, and plain browser loading.56if (typeof define === 'function' && define.amd) {57define(['exports'], factory);58} else if (typeof exports !== 'undefined') {59factory(exports);60} else {61factory((root.esprima = {}));62}63}(this, function (exports) {64'use strict';6566var Token,67TokenName,68FnExprTokens,69Syntax,70PropertyKind,71Messages,72Regex,73SyntaxTreeDelegate,74XHTMLEntities,75ClassPropertyType,76source,77strict,78index,79lineNumber,80lineStart,81length,82delegate,83lookahead,84state,85extra;8687Token = {88BooleanLiteral: 1,89EOF: 2,90Identifier: 3,91Keyword: 4,92NullLiteral: 5,93NumericLiteral: 6,94Punctuator: 7,95StringLiteral: 8,96RegularExpression: 9,97Template: 10,98XJSIdentifier: 11,99XJSText: 12100};101102TokenName = {};103TokenName[Token.BooleanLiteral] = 'Boolean';104TokenName[Token.EOF] = '<end>';105TokenName[Token.Identifier] = 'Identifier';106TokenName[Token.Keyword] = 'Keyword';107TokenName[Token.NullLiteral] = 'Null';108TokenName[Token.NumericLiteral] = 'Numeric';109TokenName[Token.Punctuator] = 'Punctuator';110TokenName[Token.StringLiteral] = 'String';111TokenName[Token.XJSIdentifier] = 'XJSIdentifier';112TokenName[Token.XJSText] = 'XJSText';113TokenName[Token.RegularExpression] = 'RegularExpression';114115// A function following one of those tokens is an expression.116FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',117'return', 'case', 'delete', 'throw', 'void',118// assignment operators119'=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',120'&=', '|=', '^=', ',',121// binary/unary operators122'+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',123'|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',124'<=', '<', '>', '!=', '!=='];125126Syntax = {127ArrayExpression: 'ArrayExpression',128ArrayPattern: 'ArrayPattern',129ArrowFunctionExpression: 'ArrowFunctionExpression',130AssignmentExpression: 'AssignmentExpression',131BinaryExpression: 'BinaryExpression',132BlockStatement: 'BlockStatement',133BreakStatement: 'BreakStatement',134CallExpression: 'CallExpression',135CatchClause: 'CatchClause',136ClassBody: 'ClassBody',137ClassDeclaration: 'ClassDeclaration',138ClassExpression: 'ClassExpression',139ComprehensionBlock: 'ComprehensionBlock',140ComprehensionExpression: 'ComprehensionExpression',141ConditionalExpression: 'ConditionalExpression',142ContinueStatement: 'ContinueStatement',143DebuggerStatement: 'DebuggerStatement',144DoWhileStatement: 'DoWhileStatement',145EmptyStatement: 'EmptyStatement',146ExportDeclaration: 'ExportDeclaration',147ExportBatchSpecifier: 'ExportBatchSpecifier',148ExportSpecifier: 'ExportSpecifier',149ExpressionStatement: 'ExpressionStatement',150ForInStatement: 'ForInStatement',151ForOfStatement: 'ForOfStatement',152ForStatement: 'ForStatement',153FunctionDeclaration: 'FunctionDeclaration',154FunctionExpression: 'FunctionExpression',155Identifier: 'Identifier',156IfStatement: 'IfStatement',157ImportDeclaration: 'ImportDeclaration',158ImportSpecifier: 'ImportSpecifier',159LabeledStatement: 'LabeledStatement',160Literal: 'Literal',161LogicalExpression: 'LogicalExpression',162MemberExpression: 'MemberExpression',163MethodDefinition: 'MethodDefinition',164ModuleDeclaration: 'ModuleDeclaration',165NewExpression: 'NewExpression',166ObjectExpression: 'ObjectExpression',167ObjectPattern: 'ObjectPattern',168Program: 'Program',169Property: 'Property',170ReturnStatement: 'ReturnStatement',171SequenceExpression: 'SequenceExpression',172SpreadElement: 'SpreadElement',173SpreadProperty: 'SpreadProperty',174SwitchCase: 'SwitchCase',175SwitchStatement: 'SwitchStatement',176TaggedTemplateExpression: 'TaggedTemplateExpression',177TemplateElement: 'TemplateElement',178TemplateLiteral: 'TemplateLiteral',179ThisExpression: 'ThisExpression',180ThrowStatement: 'ThrowStatement',181TryStatement: 'TryStatement',182TypeAnnotatedIdentifier: 'TypeAnnotatedIdentifier',183TypeAnnotation: 'TypeAnnotation',184UnaryExpression: 'UnaryExpression',185UpdateExpression: 'UpdateExpression',186VariableDeclaration: 'VariableDeclaration',187VariableDeclarator: 'VariableDeclarator',188WhileStatement: 'WhileStatement',189WithStatement: 'WithStatement',190XJSIdentifier: 'XJSIdentifier',191XJSNamespacedName: 'XJSNamespacedName',192XJSMemberExpression: 'XJSMemberExpression',193XJSEmptyExpression: 'XJSEmptyExpression',194XJSExpressionContainer: 'XJSExpressionContainer',195XJSElement: 'XJSElement',196XJSClosingElement: 'XJSClosingElement',197XJSOpeningElement: 'XJSOpeningElement',198XJSAttribute: 'XJSAttribute',199XJSSpreadAttribute: 'XJSSpreadAttribute',200XJSText: 'XJSText',201YieldExpression: 'YieldExpression'202};203204PropertyKind = {205Data: 1,206Get: 2,207Set: 4208};209210ClassPropertyType = {211'static': 'static',212prototype: 'prototype'213};214215// Error messages should be identical to V8.216Messages = {217UnexpectedToken: 'Unexpected token %0',218UnexpectedNumber: 'Unexpected number',219UnexpectedString: 'Unexpected string',220UnexpectedIdentifier: 'Unexpected identifier',221UnexpectedReserved: 'Unexpected reserved word',222UnexpectedTemplate: 'Unexpected quasi %0',223UnexpectedEOS: 'Unexpected end of input',224NewlineAfterThrow: 'Illegal newline after throw',225InvalidRegExp: 'Invalid regular expression',226UnterminatedRegExp: 'Invalid regular expression: missing /',227InvalidLHSInAssignment: 'Invalid left-hand side in assignment',228InvalidLHSInFormalsList: 'Invalid left-hand side in formals list',229InvalidLHSInForIn: 'Invalid left-hand side in for-in',230MultipleDefaultsInSwitch: 'More than one default clause in switch statement',231NoCatchOrFinally: 'Missing catch or finally after try',232UnknownLabel: 'Undefined label \'%0\'',233Redeclaration: '%0 \'%1\' has already been declared',234IllegalContinue: 'Illegal continue statement',235IllegalBreak: 'Illegal break statement',236IllegalDuplicateClassProperty: 'Illegal duplicate property in class definition',237IllegalReturn: 'Illegal return statement',238IllegalYield: 'Illegal yield expression',239IllegalSpread: 'Illegal spread element',240StrictModeWith: 'Strict mode code may not include a with statement',241StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',242StrictVarName: 'Variable name may not be eval or arguments in strict mode',243StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',244StrictParamDupe: 'Strict mode function may not have duplicate parameter names',245ParameterAfterRestParameter: 'Rest parameter must be final parameter of an argument list',246DefaultRestParameter: 'Rest parameter can not have a default value',247ElementAfterSpreadElement: 'Spread must be the final element of an element list',248PropertyAfterSpreadProperty: 'A rest property must be the final property of an object literal',249ObjectPatternAsRestParameter: 'Invalid rest parameter',250ObjectPatternAsSpread: 'Invalid spread argument',251StrictFunctionName: 'Function name may not be eval or arguments in strict mode',252StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',253StrictDelete: 'Delete of an unqualified identifier in strict mode.',254StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',255AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',256AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',257StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',258StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',259StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',260StrictReservedWord: 'Use of future reserved word in strict mode',261NewlineAfterModule: 'Illegal newline after module',262NoFromAfterImport: 'Missing from after import',263InvalidModuleSpecifier: 'Invalid module specifier',264NestedModule: 'Module declaration can not be nested',265NoUnintializedConst: 'Const must be initialized',266ComprehensionRequiresBlock: 'Comprehension must have at least one block',267ComprehensionError: 'Comprehension Error',268EachNotAllowed: 'Each is not supported',269InvalidXJSAttributeValue: 'XJS value should be either an expression or a quoted XJS text',270ExpectedXJSClosingTag: 'Expected corresponding XJS closing tag for %0',271AdjacentXJSElements: 'Adjacent XJS elements must be wrapped in an enclosing tag'272};273274// See also tools/generate-unicode-regex.py.275Regex = {276NonAsciiIdentifierStart: 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]'),277NonAsciiIdentifierPart: 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]')278};279280// Ensure the condition is true, otherwise throw an error.281// This is only to have a better contract semantic, i.e. another safety net282// to catch a logic error. The condition shall be fulfilled in normal case.283// Do NOT use this to enforce a certain condition on any user input.284285function assert(condition, message) {286if (!condition) {287throw new Error('ASSERT: ' + message);288}289}290291function isDecimalDigit(ch) {292return (ch >= 48 && ch <= 57); // 0..9293}294295function isHexDigit(ch) {296return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;297}298299function isOctalDigit(ch) {300return '01234567'.indexOf(ch) >= 0;301}302303304// 7.2 White Space305306function isWhiteSpace(ch) {307return (ch === 32) || // space308(ch === 9) || // tab309(ch === 0xB) ||310(ch === 0xC) ||311(ch === 0xA0) ||312(ch >= 0x1680 && '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'.indexOf(String.fromCharCode(ch)) > 0);313}314315// 7.3 Line Terminators316317function isLineTerminator(ch) {318return (ch === 10) || (ch === 13) || (ch === 0x2028) || (ch === 0x2029);319}320321// 7.6 Identifier Names and Identifiers322323function isIdentifierStart(ch) {324return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)325(ch >= 65 && ch <= 90) || // A..Z326(ch >= 97 && ch <= 122) || // a..z327(ch === 92) || // \ (backslash)328((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));329}330331function isIdentifierPart(ch) {332return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)333(ch >= 65 && ch <= 90) || // A..Z334(ch >= 97 && ch <= 122) || // a..z335(ch >= 48 && ch <= 57) || // 0..9336(ch === 92) || // \ (backslash)337((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));338}339340// 7.6.1.2 Future Reserved Words341342function isFutureReservedWord(id) {343switch (id) {344case 'class':345case 'enum':346case 'export':347case 'extends':348case 'import':349case 'super':350return true;351default:352return false;353}354}355356function isStrictModeReservedWord(id) {357switch (id) {358case 'implements':359case 'interface':360case 'package':361case 'private':362case 'protected':363case 'public':364case 'static':365case 'yield':366case 'let':367return true;368default:369return false;370}371}372373function isRestrictedWord(id) {374return id === 'eval' || id === 'arguments';375}376377// 7.6.1.1 Keywords378379function isKeyword(id) {380if (strict && isStrictModeReservedWord(id)) {381return true;382}383384// 'const' is specialized as Keyword in V8.385// 'yield' is only treated as a keyword in strict mode.386// 'let' is for compatiblity with SpiderMonkey and ES.next.387// Some others are from future reserved words.388389switch (id.length) {390case 2:391return (id === 'if') || (id === 'in') || (id === 'do');392case 3:393return (id === 'var') || (id === 'for') || (id === 'new') ||394(id === 'try') || (id === 'let');395case 4:396return (id === 'this') || (id === 'else') || (id === 'case') ||397(id === 'void') || (id === 'with') || (id === 'enum');398case 5:399return (id === 'while') || (id === 'break') || (id === 'catch') ||400(id === 'throw') || (id === 'const') ||401(id === 'class') || (id === 'super');402case 6:403return (id === 'return') || (id === 'typeof') || (id === 'delete') ||404(id === 'switch') || (id === 'export') || (id === 'import');405case 7:406return (id === 'default') || (id === 'finally') || (id === 'extends');407case 8:408return (id === 'function') || (id === 'continue') || (id === 'debugger');409case 10:410return (id === 'instanceof');411default:412return false;413}414}415416// 7.4 Comments417418function skipComment() {419var ch, blockComment, lineComment;420421blockComment = false;422lineComment = false;423424while (index < length) {425ch = source.charCodeAt(index);426427if (lineComment) {428++index;429if (isLineTerminator(ch)) {430lineComment = false;431if (ch === 13 && source.charCodeAt(index) === 10) {432++index;433}434++lineNumber;435lineStart = index;436}437} else if (blockComment) {438if (isLineTerminator(ch)) {439if (ch === 13 && source.charCodeAt(index + 1) === 10) {440++index;441}442++lineNumber;443++index;444lineStart = index;445if (index >= length) {446throwError({}, Messages.UnexpectedToken, 'ILLEGAL');447}448} else {449ch = source.charCodeAt(index++);450if (index >= length) {451throwError({}, Messages.UnexpectedToken, 'ILLEGAL');452}453// Block comment ends with '*/' (char #42, char #47).454if (ch === 42) {455ch = source.charCodeAt(index);456if (ch === 47) {457++index;458blockComment = false;459}460}461}462} else if (ch === 47) {463ch = source.charCodeAt(index + 1);464// Line comment starts with '//' (char #47, char #47).465if (ch === 47) {466index += 2;467lineComment = true;468} else if (ch === 42) {469// Block comment starts with '/*' (char #47, char #42).470index += 2;471blockComment = true;472if (index >= length) {473throwError({}, Messages.UnexpectedToken, 'ILLEGAL');474}475} else {476break;477}478} else if (isWhiteSpace(ch)) {479++index;480} else if (isLineTerminator(ch)) {481++index;482if (ch === 13 && source.charCodeAt(index) === 10) {483++index;484}485++lineNumber;486lineStart = index;487} else {488break;489}490}491}492493function scanHexEscape(prefix) {494var i, len, ch, code = 0;495496len = (prefix === 'u') ? 4 : 2;497for (i = 0; i < len; ++i) {498if (index < length && isHexDigit(source[index])) {499ch = source[index++];500code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());501} else {502return '';503}504}505return String.fromCharCode(code);506}507508function scanUnicodeCodePointEscape() {509var ch, code, cu1, cu2;510511ch = source[index];512code = 0;513514// At least, one hex digit is required.515if (ch === '}') {516throwError({}, Messages.UnexpectedToken, 'ILLEGAL');517}518519while (index < length) {520ch = source[index++];521if (!isHexDigit(ch)) {522break;523}524code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());525}526527if (code > 0x10FFFF || ch !== '}') {528throwError({}, Messages.UnexpectedToken, 'ILLEGAL');529}530531// UTF-16 Encoding532if (code <= 0xFFFF) {533return String.fromCharCode(code);534}535cu1 = ((code - 0x10000) >> 10) + 0xD800;536cu2 = ((code - 0x10000) & 1023) + 0xDC00;537return String.fromCharCode(cu1, cu2);538}539540function getEscapedIdentifier() {541var ch, id;542543ch = source.charCodeAt(index++);544id = String.fromCharCode(ch);545546// '\u' (char #92, char #117) denotes an escaped character.547if (ch === 92) {548if (source.charCodeAt(index) !== 117) {549throwError({}, Messages.UnexpectedToken, 'ILLEGAL');550}551++index;552ch = scanHexEscape('u');553if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {554throwError({}, Messages.UnexpectedToken, 'ILLEGAL');555}556id = ch;557}558559while (index < length) {560ch = source.charCodeAt(index);561if (!isIdentifierPart(ch)) {562break;563}564++index;565id += String.fromCharCode(ch);566567// '\u' (char #92, char #117) denotes an escaped character.568if (ch === 92) {569id = id.substr(0, id.length - 1);570if (source.charCodeAt(index) !== 117) {571throwError({}, Messages.UnexpectedToken, 'ILLEGAL');572}573++index;574ch = scanHexEscape('u');575if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {576throwError({}, Messages.UnexpectedToken, 'ILLEGAL');577}578id += ch;579}580}581582return id;583}584585function getIdentifier() {586var start, ch;587588start = index++;589while (index < length) {590ch = source.charCodeAt(index);591if (ch === 92) {592// Blackslash (char #92) marks Unicode escape sequence.593index = start;594return getEscapedIdentifier();595}596if (isIdentifierPart(ch)) {597++index;598} else {599break;600}601}602603return source.slice(start, index);604}605606function scanIdentifier() {607var start, id, type;608609start = index;610611// Backslash (char #92) starts an escaped character.612id = (source.charCodeAt(index) === 92) ? getEscapedIdentifier() : getIdentifier();613614// There is no keyword or literal with only one character.615// Thus, it must be an identifier.616if (id.length === 1) {617type = Token.Identifier;618} else if (isKeyword(id)) {619type = Token.Keyword;620} else if (id === 'null') {621type = Token.NullLiteral;622} else if (id === 'true' || id === 'false') {623type = Token.BooleanLiteral;624} else {625type = Token.Identifier;626}627628return {629type: type,630value: id,631lineNumber: lineNumber,632lineStart: lineStart,633range: [start, index]634};635}636637638// 7.7 Punctuators639640function scanPunctuator() {641var start = index,642code = source.charCodeAt(index),643code2,644ch1 = source[index],645ch2,646ch3,647ch4;648649switch (code) {650// Check for most common single-character punctuators.651case 40: // ( open bracket652case 41: // ) close bracket653case 59: // ; semicolon654case 44: // , comma655case 123: // { open curly brace656case 125: // } close curly brace657case 91: // [658case 93: // ]659case 58: // :660case 63: // ?661case 126: // ~662++index;663if (extra.tokenize) {664if (code === 40) {665extra.openParenToken = extra.tokens.length;666} else if (code === 123) {667extra.openCurlyToken = extra.tokens.length;668}669}670return {671type: Token.Punctuator,672value: String.fromCharCode(code),673lineNumber: lineNumber,674lineStart: lineStart,675range: [start, index]676};677678default:679code2 = source.charCodeAt(index + 1);680681// '=' (char #61) marks an assignment or comparison operator.682if (code2 === 61) {683switch (code) {684case 37: // %685case 38: // &686case 42: // *:687case 43: // +688case 45: // -689case 47: // /690case 60: // <691case 62: // >692case 94: // ^693case 124: // |694index += 2;695return {696type: Token.Punctuator,697value: String.fromCharCode(code) + String.fromCharCode(code2),698lineNumber: lineNumber,699lineStart: lineStart,700range: [start, index]701};702703case 33: // !704case 61: // =705index += 2;706707// !== and ===708if (source.charCodeAt(index) === 61) {709++index;710}711return {712type: Token.Punctuator,713value: source.slice(start, index),714lineNumber: lineNumber,715lineStart: lineStart,716range: [start, index]717};718default:719break;720}721}722break;723}724725// Peek more characters.726727ch2 = source[index + 1];728ch3 = source[index + 2];729ch4 = source[index + 3];730731// 4-character punctuator: >>>=732733if (ch1 === '>' && ch2 === '>' && ch3 === '>') {734if (ch4 === '=') {735index += 4;736return {737type: Token.Punctuator,738value: '>>>=',739lineNumber: lineNumber,740lineStart: lineStart,741range: [start, index]742};743}744}745746// 3-character punctuators: === !== >>> <<= >>=747748if (ch1 === '>' && ch2 === '>' && ch3 === '>') {749index += 3;750return {751type: Token.Punctuator,752value: '>>>',753lineNumber: lineNumber,754lineStart: lineStart,755range: [start, index]756};757}758759if (ch1 === '<' && ch2 === '<' && ch3 === '=') {760index += 3;761return {762type: Token.Punctuator,763value: '<<=',764lineNumber: lineNumber,765lineStart: lineStart,766range: [start, index]767};768}769770if (ch1 === '>' && ch2 === '>' && ch3 === '=') {771index += 3;772return {773type: Token.Punctuator,774value: '>>=',775lineNumber: lineNumber,776lineStart: lineStart,777range: [start, index]778};779}780781if (ch1 === '.' && ch2 === '.' && ch3 === '.') {782index += 3;783return {784type: Token.Punctuator,785value: '...',786lineNumber: lineNumber,787lineStart: lineStart,788range: [start, index]789};790}791792// Other 2-character punctuators: ++ -- << >> && ||793794if (ch1 === ch2 && ('+-<>&|'.indexOf(ch1) >= 0)) {795index += 2;796return {797type: Token.Punctuator,798value: ch1 + ch2,799lineNumber: lineNumber,800lineStart: lineStart,801range: [start, index]802};803}804805if (ch1 === '=' && ch2 === '>') {806index += 2;807return {808type: Token.Punctuator,809value: '=>',810lineNumber: lineNumber,811lineStart: lineStart,812range: [start, index]813};814}815816if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {817++index;818return {819type: Token.Punctuator,820value: ch1,821lineNumber: lineNumber,822lineStart: lineStart,823range: [start, index]824};825}826827if (ch1 === '.') {828++index;829return {830type: Token.Punctuator,831value: ch1,832lineNumber: lineNumber,833lineStart: lineStart,834range: [start, index]835};836}837838throwError({}, Messages.UnexpectedToken, 'ILLEGAL');839}840841// 7.8.3 Numeric Literals842843function scanHexLiteral(start) {844var number = '';845846while (index < length) {847if (!isHexDigit(source[index])) {848break;849}850number += source[index++];851}852853if (number.length === 0) {854throwError({}, Messages.UnexpectedToken, 'ILLEGAL');855}856857if (isIdentifierStart(source.charCodeAt(index))) {858throwError({}, Messages.UnexpectedToken, 'ILLEGAL');859}860861return {862type: Token.NumericLiteral,863value: parseInt('0x' + number, 16),864lineNumber: lineNumber,865lineStart: lineStart,866range: [start, index]867};868}869870function scanOctalLiteral(prefix, start) {871var number, octal;872873if (isOctalDigit(prefix)) {874octal = true;875number = '0' + source[index++];876} else {877octal = false;878++index;879number = '';880}881882while (index < length) {883if (!isOctalDigit(source[index])) {884break;885}886number += source[index++];887}888889if (!octal && number.length === 0) {890// only 0o or 0O891throwError({}, Messages.UnexpectedToken, 'ILLEGAL');892}893894if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {895throwError({}, Messages.UnexpectedToken, 'ILLEGAL');896}897898return {899type: Token.NumericLiteral,900value: parseInt(number, 8),901octal: octal,902lineNumber: lineNumber,903lineStart: lineStart,904range: [start, index]905};906}907908function scanNumericLiteral() {909var number, start, ch, octal;910911ch = source[index];912assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),913'Numeric literal must start with a decimal digit or a decimal point');914915start = index;916number = '';917if (ch !== '.') {918number = source[index++];919ch = source[index];920921// Hex number starts with '0x'.922// Octal number starts with '0'.923// Octal number in ES6 starts with '0o'.924// Binary number in ES6 starts with '0b'.925if (number === '0') {926if (ch === 'x' || ch === 'X') {927++index;928return scanHexLiteral(start);929}930if (ch === 'b' || ch === 'B') {931++index;932number = '';933934while (index < length) {935ch = source[index];936if (ch !== '0' && ch !== '1') {937break;938}939number += source[index++];940}941942if (number.length === 0) {943// only 0b or 0B944throwError({}, Messages.UnexpectedToken, 'ILLEGAL');945}946947if (index < length) {948ch = source.charCodeAt(index);949if (isIdentifierStart(ch) || isDecimalDigit(ch)) {950throwError({}, Messages.UnexpectedToken, 'ILLEGAL');951}952}953return {954type: Token.NumericLiteral,955value: parseInt(number, 2),956lineNumber: lineNumber,957lineStart: lineStart,958range: [start, index]959};960}961if (ch === 'o' || ch === 'O' || isOctalDigit(ch)) {962return scanOctalLiteral(ch, start);963}964// decimal number starts with '0' such as '09' is illegal.965if (ch && isDecimalDigit(ch.charCodeAt(0))) {966throwError({}, Messages.UnexpectedToken, 'ILLEGAL');967}968}969970while (isDecimalDigit(source.charCodeAt(index))) {971number += source[index++];972}973ch = source[index];974}975976if (ch === '.') {977number += source[index++];978while (isDecimalDigit(source.charCodeAt(index))) {979number += source[index++];980}981ch = source[index];982}983984if (ch === 'e' || ch === 'E') {985number += source[index++];986987ch = source[index];988if (ch === '+' || ch === '-') {989number += source[index++];990}991if (isDecimalDigit(source.charCodeAt(index))) {992while (isDecimalDigit(source.charCodeAt(index))) {993number += source[index++];994}995} else {996throwError({}, Messages.UnexpectedToken, 'ILLEGAL');997}998}9991000if (isIdentifierStart(source.charCodeAt(index))) {1001throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1002}10031004return {1005type: Token.NumericLiteral,1006value: parseFloat(number),1007lineNumber: lineNumber,1008lineStart: lineStart,1009range: [start, index]1010};1011}10121013// 7.8.4 String Literals10141015function scanStringLiteral() {1016var str = '', quote, start, ch, code, unescaped, restore, octal = false;10171018quote = source[index];1019assert((quote === '\'' || quote === '"'),1020'String literal must starts with a quote');10211022start = index;1023++index;10241025while (index < length) {1026ch = source[index++];10271028if (ch === quote) {1029quote = '';1030break;1031} else if (ch === '\\') {1032ch = source[index++];1033if (!ch || !isLineTerminator(ch.charCodeAt(0))) {1034switch (ch) {1035case 'n':1036str += '\n';1037break;1038case 'r':1039str += '\r';1040break;1041case 't':1042str += '\t';1043break;1044case 'u':1045case 'x':1046if (source[index] === '{') {1047++index;1048str += scanUnicodeCodePointEscape();1049} else {1050restore = index;1051unescaped = scanHexEscape(ch);1052if (unescaped) {1053str += unescaped;1054} else {1055index = restore;1056str += ch;1057}1058}1059break;1060case 'b':1061str += '\b';1062break;1063case 'f':1064str += '\f';1065break;1066case 'v':1067str += '\x0B';1068break;10691070default:1071if (isOctalDigit(ch)) {1072code = '01234567'.indexOf(ch);10731074// \0 is not octal escape sequence1075if (code !== 0) {1076octal = true;1077}10781079if (index < length && isOctalDigit(source[index])) {1080octal = true;1081code = code * 8 + '01234567'.indexOf(source[index++]);10821083// 3 digits are only allowed when string starts1084// with 0, 1, 2, 31085if ('0123'.indexOf(ch) >= 0 &&1086index < length &&1087isOctalDigit(source[index])) {1088code = code * 8 + '01234567'.indexOf(source[index++]);1089}1090}1091str += String.fromCharCode(code);1092} else {1093str += ch;1094}1095break;1096}1097} else {1098++lineNumber;1099if (ch === '\r' && source[index] === '\n') {1100++index;1101}1102}1103} else if (isLineTerminator(ch.charCodeAt(0))) {1104break;1105} else {1106str += ch;1107}1108}11091110if (quote !== '') {1111throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1112}11131114return {1115type: Token.StringLiteral,1116value: str,1117octal: octal,1118lineNumber: lineNumber,1119lineStart: lineStart,1120range: [start, index]1121};1122}11231124function scanTemplate() {1125var cooked = '', ch, start, terminated, tail, restore, unescaped, code, octal;11261127terminated = false;1128tail = false;1129start = index;11301131++index;11321133while (index < length) {1134ch = source[index++];1135if (ch === '`') {1136tail = true;1137terminated = true;1138break;1139} else if (ch === '$') {1140if (source[index] === '{') {1141++index;1142terminated = true;1143break;1144}1145cooked += ch;1146} else if (ch === '\\') {1147ch = source[index++];1148if (!isLineTerminator(ch.charCodeAt(0))) {1149switch (ch) {1150case 'n':1151cooked += '\n';1152break;1153case 'r':1154cooked += '\r';1155break;1156case 't':1157cooked += '\t';1158break;1159case 'u':1160case 'x':1161if (source[index] === '{') {1162++index;1163cooked += scanUnicodeCodePointEscape();1164} else {1165restore = index;1166unescaped = scanHexEscape(ch);1167if (unescaped) {1168cooked += unescaped;1169} else {1170index = restore;1171cooked += ch;1172}1173}1174break;1175case 'b':1176cooked += '\b';1177break;1178case 'f':1179cooked += '\f';1180break;1181case 'v':1182cooked += '\v';1183break;11841185default:1186if (isOctalDigit(ch)) {1187code = '01234567'.indexOf(ch);11881189// \0 is not octal escape sequence1190if (code !== 0) {1191octal = true;1192}11931194if (index < length && isOctalDigit(source[index])) {1195octal = true;1196code = code * 8 + '01234567'.indexOf(source[index++]);11971198// 3 digits are only allowed when string starts1199// with 0, 1, 2, 31200if ('0123'.indexOf(ch) >= 0 &&1201index < length &&1202isOctalDigit(source[index])) {1203code = code * 8 + '01234567'.indexOf(source[index++]);1204}1205}1206cooked += String.fromCharCode(code);1207} else {1208cooked += ch;1209}1210break;1211}1212} else {1213++lineNumber;1214if (ch === '\r' && source[index] === '\n') {1215++index;1216}1217}1218} else if (isLineTerminator(ch.charCodeAt(0))) {1219++lineNumber;1220if (ch === '\r' && source[index] === '\n') {1221++index;1222}1223cooked += '\n';1224} else {1225cooked += ch;1226}1227}12281229if (!terminated) {1230throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1231}12321233return {1234type: Token.Template,1235value: {1236cooked: cooked,1237raw: source.slice(start + 1, index - ((tail) ? 1 : 2))1238},1239tail: tail,1240octal: octal,1241lineNumber: lineNumber,1242lineStart: lineStart,1243range: [start, index]1244};1245}12461247function scanTemplateElement(option) {1248var startsWith, template;12491250lookahead = null;1251skipComment();12521253startsWith = (option.head) ? '`' : '}';12541255if (source[index] !== startsWith) {1256throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1257}12581259template = scanTemplate();12601261peek();12621263return template;1264}12651266function scanRegExp() {1267var str, ch, start, pattern, flags, value, classMarker = false, restore, terminated = false;12681269lookahead = null;1270skipComment();12711272start = index;1273ch = source[index];1274assert(ch === '/', 'Regular expression literal must start with a slash');1275str = source[index++];12761277while (index < length) {1278ch = source[index++];1279str += ch;1280if (classMarker) {1281if (ch === ']') {1282classMarker = false;1283}1284} else {1285if (ch === '\\') {1286ch = source[index++];1287// ECMA-262 7.8.51288if (isLineTerminator(ch.charCodeAt(0))) {1289throwError({}, Messages.UnterminatedRegExp);1290}1291str += ch;1292} else if (ch === '/') {1293terminated = true;1294break;1295} else if (ch === '[') {1296classMarker = true;1297} else if (isLineTerminator(ch.charCodeAt(0))) {1298throwError({}, Messages.UnterminatedRegExp);1299}1300}1301}13021303if (!terminated) {1304throwError({}, Messages.UnterminatedRegExp);1305}13061307// Exclude leading and trailing slash.1308pattern = str.substr(1, str.length - 2);13091310flags = '';1311while (index < length) {1312ch = source[index];1313if (!isIdentifierPart(ch.charCodeAt(0))) {1314break;1315}13161317++index;1318if (ch === '\\' && index < length) {1319ch = source[index];1320if (ch === 'u') {1321++index;1322restore = index;1323ch = scanHexEscape('u');1324if (ch) {1325flags += ch;1326for (str += '\\u'; restore < index; ++restore) {1327str += source[restore];1328}1329} else {1330index = restore;1331flags += 'u';1332str += '\\u';1333}1334} else {1335str += '\\';1336}1337} else {1338flags += ch;1339str += ch;1340}1341}13421343try {1344value = new RegExp(pattern, flags);1345} catch (e) {1346throwError({}, Messages.InvalidRegExp);1347}13481349peek();135013511352if (extra.tokenize) {1353return {1354type: Token.RegularExpression,1355value: value,1356lineNumber: lineNumber,1357lineStart: lineStart,1358range: [start, index]1359};1360}1361return {1362literal: str,1363value: value,1364range: [start, index]1365};1366}13671368function isIdentifierName(token) {1369return token.type === Token.Identifier ||1370token.type === Token.Keyword ||1371token.type === Token.BooleanLiteral ||1372token.type === Token.NullLiteral;1373}13741375function advanceSlash() {1376var prevToken,1377checkToken;1378// Using the following algorithm:1379// https://github.com/mozilla/sweet.js/wiki/design1380prevToken = extra.tokens[extra.tokens.length - 1];1381if (!prevToken) {1382// Nothing before that: it cannot be a division.1383return scanRegExp();1384}1385if (prevToken.type === 'Punctuator') {1386if (prevToken.value === ')') {1387checkToken = extra.tokens[extra.openParenToken - 1];1388if (checkToken &&1389checkToken.type === 'Keyword' &&1390(checkToken.value === 'if' ||1391checkToken.value === 'while' ||1392checkToken.value === 'for' ||1393checkToken.value === 'with')) {1394return scanRegExp();1395}1396return scanPunctuator();1397}1398if (prevToken.value === '}') {1399// Dividing a function by anything makes little sense,1400// but we have to check for that.1401if (extra.tokens[extra.openCurlyToken - 3] &&1402extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {1403// Anonymous function.1404checkToken = extra.tokens[extra.openCurlyToken - 4];1405if (!checkToken) {1406return scanPunctuator();1407}1408} else if (extra.tokens[extra.openCurlyToken - 4] &&1409extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {1410// Named function.1411checkToken = extra.tokens[extra.openCurlyToken - 5];1412if (!checkToken) {1413return scanRegExp();1414}1415} else {1416return scanPunctuator();1417}1418// checkToken determines whether the function is1419// a declaration or an expression.1420if (FnExprTokens.indexOf(checkToken.value) >= 0) {1421// It is an expression.1422return scanPunctuator();1423}1424// It is a declaration.1425return scanRegExp();1426}1427return scanRegExp();1428}1429if (prevToken.type === 'Keyword') {1430return scanRegExp();1431}1432return scanPunctuator();1433}14341435function advance() {1436var ch;14371438if (!state.inXJSChild) {1439skipComment();1440}14411442if (index >= length) {1443return {1444type: Token.EOF,1445lineNumber: lineNumber,1446lineStart: lineStart,1447range: [index, index]1448};1449}14501451if (state.inXJSChild) {1452return advanceXJSChild();1453}14541455ch = source.charCodeAt(index);14561457// Very common: ( and ) and ;1458if (ch === 40 || ch === 41 || ch === 58) {1459return scanPunctuator();1460}14611462// String literal starts with single quote (#39) or double quote (#34).1463if (ch === 39 || ch === 34) {1464if (state.inXJSTag) {1465return scanXJSStringLiteral();1466}1467return scanStringLiteral();1468}14691470if (state.inXJSTag && isXJSIdentifierStart(ch)) {1471return scanXJSIdentifier();1472}14731474if (ch === 96) {1475return scanTemplate();1476}1477if (isIdentifierStart(ch)) {1478return scanIdentifier();1479}14801481// Dot (.) char #46 can also start a floating-point number, hence the need1482// to check the next character.1483if (ch === 46) {1484if (isDecimalDigit(source.charCodeAt(index + 1))) {1485return scanNumericLiteral();1486}1487return scanPunctuator();1488}14891490if (isDecimalDigit(ch)) {1491return scanNumericLiteral();1492}14931494// Slash (/) char #47 can also start a regex.1495if (extra.tokenize && ch === 47) {1496return advanceSlash();1497}14981499return scanPunctuator();1500}15011502function lex() {1503var token;15041505token = lookahead;1506index = token.range[1];1507lineNumber = token.lineNumber;1508lineStart = token.lineStart;15091510lookahead = advance();15111512index = token.range[1];1513lineNumber = token.lineNumber;1514lineStart = token.lineStart;15151516return token;1517}15181519function peek() {1520var pos, line, start;15211522pos = index;1523line = lineNumber;1524start = lineStart;1525lookahead = advance();1526index = pos;1527lineNumber = line;1528lineStart = start;1529}15301531function lookahead2() {1532var adv, pos, line, start, result;15331534// If we are collecting the tokens, don't grab the next one yet.1535adv = (typeof extra.advance === 'function') ? extra.advance : advance;15361537pos = index;1538line = lineNumber;1539start = lineStart;15401541// Scan for the next immediate token.1542if (lookahead === null) {1543lookahead = adv();1544}1545index = lookahead.range[1];1546lineNumber = lookahead.lineNumber;1547lineStart = lookahead.lineStart;15481549// Grab the token right after.1550result = adv();1551index = pos;1552lineNumber = line;1553lineStart = start;15541555return result;1556}15571558function markerCreate() {1559if (!extra.loc && !extra.range) {1560return undefined;1561}1562skipComment();1563return {offset: index, line: lineNumber, col: index - lineStart};1564}15651566function markerCreatePreserveWhitespace() {1567if (!extra.loc && !extra.range) {1568return undefined;1569}1570return {offset: index, line: lineNumber, col: index - lineStart};1571}15721573function markerApply(marker, node) {1574if (extra.range) {1575node.range = [marker.offset, index];1576}1577if (extra.loc) {1578node.loc = {1579start: {1580line: marker.line,1581column: marker.col1582},1583end: {1584line: lineNumber,1585column: index - lineStart1586}1587};1588node = delegate.postProcess(node);1589}1590return node;1591}15921593SyntaxTreeDelegate = {15941595name: 'SyntaxTree',15961597postProcess: function (node) {1598return node;1599},16001601createArrayExpression: function (elements) {1602return {1603type: Syntax.ArrayExpression,1604elements: elements1605};1606},16071608createAssignmentExpression: function (operator, left, right) {1609return {1610type: Syntax.AssignmentExpression,1611operator: operator,1612left: left,1613right: right1614};1615},16161617createBinaryExpression: function (operator, left, right) {1618var type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression :1619Syntax.BinaryExpression;1620return {1621type: type,1622operator: operator,1623left: left,1624right: right1625};1626},16271628createBlockStatement: function (body) {1629return {1630type: Syntax.BlockStatement,1631body: body1632};1633},16341635createBreakStatement: function (label) {1636return {1637type: Syntax.BreakStatement,1638label: label1639};1640},16411642createCallExpression: function (callee, args) {1643return {1644type: Syntax.CallExpression,1645callee: callee,1646'arguments': args1647};1648},16491650createCatchClause: function (param, body) {1651return {1652type: Syntax.CatchClause,1653param: param,1654body: body1655};1656},16571658createConditionalExpression: function (test, consequent, alternate) {1659return {1660type: Syntax.ConditionalExpression,1661test: test,1662consequent: consequent,1663alternate: alternate1664};1665},16661667createContinueStatement: function (label) {1668return {1669type: Syntax.ContinueStatement,1670label: label1671};1672},16731674createDebuggerStatement: function () {1675return {1676type: Syntax.DebuggerStatement1677};1678},16791680createDoWhileStatement: function (body, test) {1681return {1682type: Syntax.DoWhileStatement,1683body: body,1684test: test1685};1686},16871688createEmptyStatement: function () {1689return {1690type: Syntax.EmptyStatement1691};1692},16931694createExpressionStatement: function (expression) {1695return {1696type: Syntax.ExpressionStatement,1697expression: expression1698};1699},17001701createForStatement: function (init, test, update, body) {1702return {1703type: Syntax.ForStatement,1704init: init,1705test: test,1706update: update,1707body: body1708};1709},17101711createForInStatement: function (left, right, body) {1712return {1713type: Syntax.ForInStatement,1714left: left,1715right: right,1716body: body,1717each: false1718};1719},17201721createForOfStatement: function (left, right, body) {1722return {1723type: Syntax.ForOfStatement,1724left: left,1725right: right,1726body: body1727};1728},17291730createFunctionDeclaration: function (id, params, defaults, body, rest, generator, expression,1731returnType) {1732return {1733type: Syntax.FunctionDeclaration,1734id: id,1735params: params,1736defaults: defaults,1737body: body,1738rest: rest,1739generator: generator,1740expression: expression,1741returnType: returnType1742};1743},17441745createFunctionExpression: function (id, params, defaults, body, rest, generator, expression,1746returnType) {1747return {1748type: Syntax.FunctionExpression,1749id: id,1750params: params,1751defaults: defaults,1752body: body,1753rest: rest,1754generator: generator,1755expression: expression,1756returnType: returnType1757};1758},17591760createIdentifier: function (name) {1761return {1762type: Syntax.Identifier,1763name: name,1764// Only here to initialize the shape of the object to ensure1765// that the 'typeAnnotation' key is ordered before others that1766// are added later (like 'loc' and 'range'). This just helps1767// keep the shape of Identifier nodes consistent with everything1768// else.1769typeAnnotation: undefined1770};1771},17721773createTypeAnnotation: function (typeIdentifier, paramTypes, returnType, nullable) {1774return {1775type: Syntax.TypeAnnotation,1776id: typeIdentifier,1777paramTypes: paramTypes,1778returnType: returnType,1779nullable: nullable1780};1781},17821783createTypeAnnotatedIdentifier: function (identifier, annotation) {1784return {1785type: Syntax.TypeAnnotatedIdentifier,1786id: identifier,1787annotation: annotation1788};1789},17901791createXJSAttribute: function (name, value) {1792return {1793type: Syntax.XJSAttribute,1794name: name,1795value: value1796};1797},17981799createXJSSpreadAttribute: function (argument) {1800return {1801type: Syntax.XJSSpreadAttribute,1802argument: argument1803};1804},18051806createXJSIdentifier: function (name) {1807return {1808type: Syntax.XJSIdentifier,1809name: name1810};1811},18121813createXJSNamespacedName: function (namespace, name) {1814return {1815type: Syntax.XJSNamespacedName,1816namespace: namespace,1817name: name1818};1819},18201821createXJSMemberExpression: function (object, property) {1822return {1823type: Syntax.XJSMemberExpression,1824object: object,1825property: property1826};1827},18281829createXJSElement: function (openingElement, closingElement, children) {1830return {1831type: Syntax.XJSElement,1832openingElement: openingElement,1833closingElement: closingElement,1834children: children1835};1836},18371838createXJSEmptyExpression: function () {1839return {1840type: Syntax.XJSEmptyExpression1841};1842},18431844createXJSExpressionContainer: function (expression) {1845return {1846type: Syntax.XJSExpressionContainer,1847expression: expression1848};1849},18501851createXJSOpeningElement: function (name, attributes, selfClosing) {1852return {1853type: Syntax.XJSOpeningElement,1854name: name,1855selfClosing: selfClosing,1856attributes: attributes1857};1858},18591860createXJSClosingElement: function (name) {1861return {1862type: Syntax.XJSClosingElement,1863name: name1864};1865},18661867createIfStatement: function (test, consequent, alternate) {1868return {1869type: Syntax.IfStatement,1870test: test,1871consequent: consequent,1872alternate: alternate1873};1874},18751876createLabeledStatement: function (label, body) {1877return {1878type: Syntax.LabeledStatement,1879label: label,1880body: body1881};1882},18831884createLiteral: function (token) {1885return {1886type: Syntax.Literal,1887value: token.value,1888raw: source.slice(token.range[0], token.range[1])1889};1890},18911892createMemberExpression: function (accessor, object, property) {1893return {1894type: Syntax.MemberExpression,1895computed: accessor === '[',1896object: object,1897property: property1898};1899},19001901createNewExpression: function (callee, args) {1902return {1903type: Syntax.NewExpression,1904callee: callee,1905'arguments': args1906};1907},19081909createObjectExpression: function (properties) {1910return {1911type: Syntax.ObjectExpression,1912properties: properties1913};1914},19151916createPostfixExpression: function (operator, argument) {1917return {1918type: Syntax.UpdateExpression,1919operator: operator,1920argument: argument,1921prefix: false1922};1923},19241925createProgram: function (body) {1926return {1927type: Syntax.Program,1928body: body1929};1930},19311932createProperty: function (kind, key, value, method, shorthand, computed) {1933return {1934type: Syntax.Property,1935key: key,1936value: value,1937kind: kind,1938method: method,1939shorthand: shorthand,1940computed: computed1941};1942},19431944createReturnStatement: function (argument) {1945return {1946type: Syntax.ReturnStatement,1947argument: argument1948};1949},19501951createSequenceExpression: function (expressions) {1952return {1953type: Syntax.SequenceExpression,1954expressions: expressions1955};1956},19571958createSwitchCase: function (test, consequent) {1959return {1960type: Syntax.SwitchCase,1961test: test,1962consequent: consequent1963};1964},19651966createSwitchStatement: function (discriminant, cases) {1967return {1968type: Syntax.SwitchStatement,1969discriminant: discriminant,1970cases: cases1971};1972},19731974createThisExpression: function () {1975return {1976type: Syntax.ThisExpression1977};1978},19791980createThrowStatement: function (argument) {1981return {1982type: Syntax.ThrowStatement,1983argument: argument1984};1985},19861987createTryStatement: function (block, guardedHandlers, handlers, finalizer) {1988return {1989type: Syntax.TryStatement,1990block: block,1991guardedHandlers: guardedHandlers,1992handlers: handlers,1993finalizer: finalizer1994};1995},19961997createUnaryExpression: function (operator, argument) {1998if (operator === '++' || operator === '--') {1999return {2000type: Syntax.UpdateExpression,2001operator: operator,2002argument: argument,2003prefix: true2004};2005}2006return {2007type: Syntax.UnaryExpression,2008operator: operator,2009argument: argument,2010prefix: true2011};2012},20132014createVariableDeclaration: function (declarations, kind) {2015return {2016type: Syntax.VariableDeclaration,2017declarations: declarations,2018kind: kind2019};2020},20212022createVariableDeclarator: function (id, init) {2023return {2024type: Syntax.VariableDeclarator,2025id: id,2026init: init2027};2028},20292030createWhileStatement: function (test, body) {2031return {2032type: Syntax.WhileStatement,2033test: test,2034body: body2035};2036},20372038createWithStatement: function (object, body) {2039return {2040type: Syntax.WithStatement,2041object: object,2042body: body2043};2044},20452046createTemplateElement: function (value, tail) {2047return {2048type: Syntax.TemplateElement,2049value: value,2050tail: tail2051};2052},20532054createTemplateLiteral: function (quasis, expressions) {2055return {2056type: Syntax.TemplateLiteral,2057quasis: quasis,2058expressions: expressions2059};2060},20612062createSpreadElement: function (argument) {2063return {2064type: Syntax.SpreadElement,2065argument: argument2066};2067},20682069createSpreadProperty: function (argument) {2070return {2071type: Syntax.SpreadProperty,2072argument: argument2073};2074},20752076createTaggedTemplateExpression: function (tag, quasi) {2077return {2078type: Syntax.TaggedTemplateExpression,2079tag: tag,2080quasi: quasi2081};2082},20832084createArrowFunctionExpression: function (params, defaults, body, rest, expression) {2085return {2086type: Syntax.ArrowFunctionExpression,2087id: null,2088params: params,2089defaults: defaults,2090body: body,2091rest: rest,2092generator: false,2093expression: expression2094};2095},20962097createMethodDefinition: function (propertyType, kind, key, value) {2098return {2099type: Syntax.MethodDefinition,2100key: key,2101value: value,2102kind: kind,2103'static': propertyType === ClassPropertyType.static2104};2105},21062107createClassBody: function (body) {2108return {2109type: Syntax.ClassBody,2110body: body2111};2112},21132114createClassExpression: function (id, superClass, body) {2115return {2116type: Syntax.ClassExpression,2117id: id,2118superClass: superClass,2119body: body2120};2121},21222123createClassDeclaration: function (id, superClass, body) {2124return {2125type: Syntax.ClassDeclaration,2126id: id,2127superClass: superClass,2128body: body2129};2130},21312132createExportSpecifier: function (id, name) {2133return {2134type: Syntax.ExportSpecifier,2135id: id,2136name: name2137};2138},21392140createExportBatchSpecifier: function () {2141return {2142type: Syntax.ExportBatchSpecifier2143};2144},21452146createExportDeclaration: function (declaration, specifiers, source) {2147return {2148type: Syntax.ExportDeclaration,2149declaration: declaration,2150specifiers: specifiers,2151source: source2152};2153},21542155createImportSpecifier: function (id, name) {2156return {2157type: Syntax.ImportSpecifier,2158id: id,2159name: name2160};2161},21622163createImportDeclaration: function (specifiers, kind, source) {2164return {2165type: Syntax.ImportDeclaration,2166specifiers: specifiers,2167kind: kind,2168source: source2169};2170},21712172createYieldExpression: function (argument, delegate) {2173return {2174type: Syntax.YieldExpression,2175argument: argument,2176delegate: delegate2177};2178},21792180createModuleDeclaration: function (id, source, body) {2181return {2182type: Syntax.ModuleDeclaration,2183id: id,2184source: source,2185body: body2186};2187},21882189createComprehensionExpression: function (filter, blocks, body) {2190return {2191type: Syntax.ComprehensionExpression,2192filter: filter,2193blocks: blocks,2194body: body2195};2196}21972198};21992200// Return true if there is a line terminator before the next token.22012202function peekLineTerminator() {2203var pos, line, start, found;22042205pos = index;2206line = lineNumber;2207start = lineStart;2208skipComment();2209found = lineNumber !== line;2210index = pos;2211lineNumber = line;2212lineStart = start;22132214return found;2215}22162217// Throw an exception22182219function throwError(token, messageFormat) {2220var error,2221args = Array.prototype.slice.call(arguments, 2),2222msg = messageFormat.replace(2223/%(\d)/g,2224function (whole, index) {2225assert(index < args.length, 'Message reference must be in range');2226return args[index];2227}2228);22292230if (typeof token.lineNumber === 'number') {2231error = new Error('Line ' + token.lineNumber + ': ' + msg);2232error.index = token.range[0];2233error.lineNumber = token.lineNumber;2234error.column = token.range[0] - lineStart + 1;2235} else {2236error = new Error('Line ' + lineNumber + ': ' + msg);2237error.index = index;2238error.lineNumber = lineNumber;2239error.column = index - lineStart + 1;2240}22412242error.description = msg;2243throw error;2244}22452246function throwErrorTolerant() {2247try {2248throwError.apply(null, arguments);2249} catch (e) {2250if (extra.errors) {2251extra.errors.push(e);2252} else {2253throw e;2254}2255}2256}225722582259// Throw an exception because of the token.22602261function throwUnexpected(token) {2262if (token.type === Token.EOF) {2263throwError(token, Messages.UnexpectedEOS);2264}22652266if (token.type === Token.NumericLiteral) {2267throwError(token, Messages.UnexpectedNumber);2268}22692270if (token.type === Token.StringLiteral || token.type === Token.XJSText) {2271throwError(token, Messages.UnexpectedString);2272}22732274if (token.type === Token.Identifier) {2275throwError(token, Messages.UnexpectedIdentifier);2276}22772278if (token.type === Token.Keyword) {2279if (isFutureReservedWord(token.value)) {2280throwError(token, Messages.UnexpectedReserved);2281} else if (strict && isStrictModeReservedWord(token.value)) {2282throwErrorTolerant(token, Messages.StrictReservedWord);2283return;2284}2285throwError(token, Messages.UnexpectedToken, token.value);2286}22872288if (token.type === Token.Template) {2289throwError(token, Messages.UnexpectedTemplate, token.value.raw);2290}22912292// BooleanLiteral, NullLiteral, or Punctuator.2293throwError(token, Messages.UnexpectedToken, token.value);2294}22952296// Expect the next token to match the specified punctuator.2297// If not, an exception will be thrown.22982299function expect(value) {2300var token = lex();2301if (token.type !== Token.Punctuator || token.value !== value) {2302throwUnexpected(token);2303}2304}23052306// Expect the next token to match the specified keyword.2307// If not, an exception will be thrown.23082309function expectKeyword(keyword) {2310var token = lex();2311if (token.type !== Token.Keyword || token.value !== keyword) {2312throwUnexpected(token);2313}2314}23152316// Return true if the next token matches the specified punctuator.23172318function match(value) {2319return lookahead.type === Token.Punctuator && lookahead.value === value;2320}23212322// Return true if the next token matches the specified keyword23232324function matchKeyword(keyword) {2325return lookahead.type === Token.Keyword && lookahead.value === keyword;2326}232723282329// Return true if the next token matches the specified contextual keyword23302331function matchContextualKeyword(keyword) {2332return lookahead.type === Token.Identifier && lookahead.value === keyword;2333}23342335// Return true if the next token is an assignment operator23362337function matchAssign() {2338var op;23392340if (lookahead.type !== Token.Punctuator) {2341return false;2342}2343op = lookahead.value;2344return op === '=' ||2345op === '*=' ||2346op === '/=' ||2347op === '%=' ||2348op === '+=' ||2349op === '-=' ||2350op === '<<=' ||2351op === '>>=' ||2352op === '>>>=' ||2353op === '&=' ||2354op === '^=' ||2355op === '|=';2356}23572358function consumeSemicolon() {2359var line;23602361// Catch the very common case first: immediately a semicolon (char #59).2362if (source.charCodeAt(index) === 59) {2363lex();2364return;2365}23662367line = lineNumber;2368skipComment();2369if (lineNumber !== line) {2370return;2371}23722373if (match(';')) {2374lex();2375return;2376}23772378if (lookahead.type !== Token.EOF && !match('}')) {2379throwUnexpected(lookahead);2380}2381}23822383// Return true if provided expression is LeftHandSideExpression23842385function isLeftHandSide(expr) {2386return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;2387}23882389function isAssignableLeftHandSide(expr) {2390return isLeftHandSide(expr) || expr.type === Syntax.ObjectPattern || expr.type === Syntax.ArrayPattern;2391}23922393// 11.1.4 Array Initialiser23942395function parseArrayInitialiser() {2396var elements = [], blocks = [], filter = null, tmp, possiblecomprehension = true, body,2397marker = markerCreate();23982399expect('[');2400while (!match(']')) {2401if (lookahead.value === 'for' &&2402lookahead.type === Token.Keyword) {2403if (!possiblecomprehension) {2404throwError({}, Messages.ComprehensionError);2405}2406matchKeyword('for');2407tmp = parseForStatement({ignoreBody: true});2408tmp.of = tmp.type === Syntax.ForOfStatement;2409tmp.type = Syntax.ComprehensionBlock;2410if (tmp.left.kind) { // can't be let or const2411throwError({}, Messages.ComprehensionError);2412}2413blocks.push(tmp);2414} else if (lookahead.value === 'if' &&2415lookahead.type === Token.Keyword) {2416if (!possiblecomprehension) {2417throwError({}, Messages.ComprehensionError);2418}2419expectKeyword('if');2420expect('(');2421filter = parseExpression();2422expect(')');2423} else if (lookahead.value === ',' &&2424lookahead.type === Token.Punctuator) {2425possiblecomprehension = false; // no longer allowed.2426lex();2427elements.push(null);2428} else {2429tmp = parseSpreadOrAssignmentExpression();2430elements.push(tmp);2431if (tmp && tmp.type === Syntax.SpreadElement) {2432if (!match(']')) {2433throwError({}, Messages.ElementAfterSpreadElement);2434}2435} else if (!(match(']') || matchKeyword('for') || matchKeyword('if'))) {2436expect(','); // this lexes.2437possiblecomprehension = false;2438}2439}2440}24412442expect(']');24432444if (filter && !blocks.length) {2445throwError({}, Messages.ComprehensionRequiresBlock);2446}24472448if (blocks.length) {2449if (elements.length !== 1) {2450throwError({}, Messages.ComprehensionError);2451}2452return markerApply(marker, delegate.createComprehensionExpression(filter, blocks, elements[0]));2453}2454return markerApply(marker, delegate.createArrayExpression(elements));2455}24562457// 11.1.5 Object Initialiser24582459function parsePropertyFunction(options) {2460var previousStrict, previousYieldAllowed, params, defaults, body,2461marker = markerCreate();24622463previousStrict = strict;2464previousYieldAllowed = state.yieldAllowed;2465state.yieldAllowed = options.generator;2466params = options.params || [];2467defaults = options.defaults || [];24682469body = parseConciseBody();2470if (options.name && strict && isRestrictedWord(params[0].name)) {2471throwErrorTolerant(options.name, Messages.StrictParamName);2472}2473strict = previousStrict;2474state.yieldAllowed = previousYieldAllowed;24752476return markerApply(marker, delegate.createFunctionExpression(2477null,2478params,2479defaults,2480body,2481options.rest || null,2482options.generator,2483body.type !== Syntax.BlockStatement,2484options.returnTypeAnnotation2485));2486}248724882489function parsePropertyMethodFunction(options) {2490var previousStrict, tmp, method;24912492previousStrict = strict;2493strict = true;24942495tmp = parseParams();24962497if (tmp.stricted) {2498throwErrorTolerant(tmp.stricted, tmp.message);2499}250025012502method = parsePropertyFunction({2503params: tmp.params,2504defaults: tmp.defaults,2505rest: tmp.rest,2506generator: options.generator,2507returnTypeAnnotation: tmp.returnTypeAnnotation2508});25092510strict = previousStrict;25112512return method;2513}251425152516function parseObjectPropertyKey() {2517var marker = markerCreate(),2518token = lex(),2519propertyKey,2520result;25212522// Note: This function is called only from parseObjectProperty(), where2523// EOF and Punctuator tokens are already filtered out.25242525if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) {2526if (strict && token.octal) {2527throwErrorTolerant(token, Messages.StrictOctalLiteral);2528}2529return markerApply(marker, delegate.createLiteral(token));2530}25312532if (token.type === Token.Punctuator && token.value === '[') {2533// For computed properties we should skip the [ and ], and2534// capture in marker only the assignment expression itself.2535marker = markerCreate();2536propertyKey = parseAssignmentExpression();2537result = markerApply(marker, propertyKey);2538expect(']');2539return result;2540}25412542return markerApply(marker, delegate.createIdentifier(token.value));2543}25442545function parseObjectProperty() {2546var token, key, id, value, param, expr, computed,2547marker = markerCreate();25482549token = lookahead;2550computed = (token.value === '[');25512552if (token.type === Token.Identifier || computed) {25532554id = parseObjectPropertyKey();25552556// Property Assignment: Getter and Setter.25572558if (token.value === 'get' && !(match(':') || match('('))) {2559computed = (lookahead.value === '[');2560key = parseObjectPropertyKey();2561expect('(');2562expect(')');2563return markerApply(marker, delegate.createProperty('get', key, parsePropertyFunction({ generator: false }), false, false, computed));2564}2565if (token.value === 'set' && !(match(':') || match('('))) {2566computed = (lookahead.value === '[');2567key = parseObjectPropertyKey();2568expect('(');2569token = lookahead;2570param = [ parseTypeAnnotatableIdentifier() ];2571expect(')');2572return markerApply(marker, delegate.createProperty('set', key, parsePropertyFunction({ params: param, generator: false, name: token }), false, false, computed));2573}2574if (match(':')) {2575lex();2576return markerApply(marker, delegate.createProperty('init', id, parseAssignmentExpression(), false, false, computed));2577}2578if (match('(')) {2579return markerApply(marker, delegate.createProperty('init', id, parsePropertyMethodFunction({ generator: false }), true, false, computed));2580}2581if (computed) {2582// Computed properties can only be used with full notation.2583throwUnexpected(lookahead);2584}2585return markerApply(marker, delegate.createProperty('init', id, id, false, true, false));2586}2587if (token.type === Token.EOF || token.type === Token.Punctuator) {2588if (!match('*')) {2589throwUnexpected(token);2590}2591lex();25922593computed = (lookahead.type === Token.Punctuator && lookahead.value === '[');25942595id = parseObjectPropertyKey();25962597if (!match('(')) {2598throwUnexpected(lex());2599}26002601return markerApply(marker, delegate.createProperty('init', id, parsePropertyMethodFunction({ generator: true }), true, false, computed));2602}2603key = parseObjectPropertyKey();2604if (match(':')) {2605lex();2606return markerApply(marker, delegate.createProperty('init', key, parseAssignmentExpression(), false, false, false));2607}2608if (match('(')) {2609return markerApply(marker, delegate.createProperty('init', key, parsePropertyMethodFunction({ generator: false }), true, false, false));2610}2611throwUnexpected(lex());2612}26132614function parseObjectSpreadProperty() {2615var marker = markerCreate();2616expect('...');2617return markerApply(marker, delegate.createSpreadProperty(parseAssignmentExpression()));2618}26192620function parseObjectInitialiser() {2621var properties = [], property, name, key, kind, map = {}, toString = String,2622marker = markerCreate();26232624expect('{');26252626while (!match('}')) {2627if (match('...')) {2628property = parseObjectSpreadProperty();2629} else {2630property = parseObjectProperty();26312632if (property.key.type === Syntax.Identifier) {2633name = property.key.name;2634} else {2635name = toString(property.key.value);2636}2637kind = (property.kind === 'init') ? PropertyKind.Data : (property.kind === 'get') ? PropertyKind.Get : PropertyKind.Set;26382639key = '$' + name;2640if (Object.prototype.hasOwnProperty.call(map, key)) {2641if (map[key] === PropertyKind.Data) {2642if (strict && kind === PropertyKind.Data) {2643throwErrorTolerant({}, Messages.StrictDuplicateProperty);2644} else if (kind !== PropertyKind.Data) {2645throwErrorTolerant({}, Messages.AccessorDataProperty);2646}2647} else {2648if (kind === PropertyKind.Data) {2649throwErrorTolerant({}, Messages.AccessorDataProperty);2650} else if (map[key] & kind) {2651throwErrorTolerant({}, Messages.AccessorGetSet);2652}2653}2654map[key] |= kind;2655} else {2656map[key] = kind;2657}2658}26592660properties.push(property);26612662if (!match('}')) {2663expect(',');2664}2665}26662667expect('}');26682669return markerApply(marker, delegate.createObjectExpression(properties));2670}26712672function parseTemplateElement(option) {2673var marker = markerCreate(),2674token = scanTemplateElement(option);2675if (strict && token.octal) {2676throwError(token, Messages.StrictOctalLiteral);2677}2678return markerApply(marker, delegate.createTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail));2679}26802681function parseTemplateLiteral() {2682var quasi, quasis, expressions, marker = markerCreate();26832684quasi = parseTemplateElement({ head: true });2685quasis = [ quasi ];2686expressions = [];26872688while (!quasi.tail) {2689expressions.push(parseExpression());2690quasi = parseTemplateElement({ head: false });2691quasis.push(quasi);2692}26932694return markerApply(marker, delegate.createTemplateLiteral(quasis, expressions));2695}26962697// 11.1.6 The Grouping Operator26982699function parseGroupExpression() {2700var expr;27012702expect('(');27032704++state.parenthesizedCount;27052706expr = parseExpression();27072708expect(')');27092710return expr;2711}271227132714// 11.1 Primary Expressions27152716function parsePrimaryExpression() {2717var marker, type, token, expr;27182719type = lookahead.type;27202721if (type === Token.Identifier) {2722marker = markerCreate();2723return markerApply(marker, delegate.createIdentifier(lex().value));2724}27252726if (type === Token.StringLiteral || type === Token.NumericLiteral) {2727if (strict && lookahead.octal) {2728throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);2729}2730marker = markerCreate();2731return markerApply(marker, delegate.createLiteral(lex()));2732}27332734if (type === Token.Keyword) {2735if (matchKeyword('this')) {2736marker = markerCreate();2737lex();2738return markerApply(marker, delegate.createThisExpression());2739}27402741if (matchKeyword('function')) {2742return parseFunctionExpression();2743}27442745if (matchKeyword('class')) {2746return parseClassExpression();2747}27482749if (matchKeyword('super')) {2750marker = markerCreate();2751lex();2752return markerApply(marker, delegate.createIdentifier('super'));2753}2754}27552756if (type === Token.BooleanLiteral) {2757marker = markerCreate();2758token = lex();2759token.value = (token.value === 'true');2760return markerApply(marker, delegate.createLiteral(token));2761}27622763if (type === Token.NullLiteral) {2764marker = markerCreate();2765token = lex();2766token.value = null;2767return markerApply(marker, delegate.createLiteral(token));2768}27692770if (match('[')) {2771return parseArrayInitialiser();2772}27732774if (match('{')) {2775return parseObjectInitialiser();2776}27772778if (match('(')) {2779return parseGroupExpression();2780}27812782if (match('/') || match('/=')) {2783marker = markerCreate();2784return markerApply(marker, delegate.createLiteral(scanRegExp()));2785}27862787if (type === Token.Template) {2788return parseTemplateLiteral();2789}27902791if (match('<')) {2792return parseXJSElement();2793}27942795throwUnexpected(lex());2796}27972798// 11.2 Left-Hand-Side Expressions27992800function parseArguments() {2801var args = [], arg;28022803expect('(');28042805if (!match(')')) {2806while (index < length) {2807arg = parseSpreadOrAssignmentExpression();2808args.push(arg);28092810if (match(')')) {2811break;2812} else if (arg.type === Syntax.SpreadElement) {2813throwError({}, Messages.ElementAfterSpreadElement);2814}28152816expect(',');2817}2818}28192820expect(')');28212822return args;2823}28242825function parseSpreadOrAssignmentExpression() {2826if (match('...')) {2827var marker = markerCreate();2828lex();2829return markerApply(marker, delegate.createSpreadElement(parseAssignmentExpression()));2830}2831return parseAssignmentExpression();2832}28332834function parseNonComputedProperty() {2835var marker = markerCreate(),2836token = lex();28372838if (!isIdentifierName(token)) {2839throwUnexpected(token);2840}28412842return markerApply(marker, delegate.createIdentifier(token.value));2843}28442845function parseNonComputedMember() {2846expect('.');28472848return parseNonComputedProperty();2849}28502851function parseComputedMember() {2852var expr;28532854expect('[');28552856expr = parseExpression();28572858expect(']');28592860return expr;2861}28622863function parseNewExpression() {2864var callee, args, marker = markerCreate();28652866expectKeyword('new');2867callee = parseLeftHandSideExpression();2868args = match('(') ? parseArguments() : [];28692870return markerApply(marker, delegate.createNewExpression(callee, args));2871}28722873function parseLeftHandSideExpressionAllowCall() {2874var expr, args, marker = markerCreate();28752876expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();28772878while (match('.') || match('[') || match('(') || lookahead.type === Token.Template) {2879if (match('(')) {2880args = parseArguments();2881expr = markerApply(marker, delegate.createCallExpression(expr, args));2882} else if (match('[')) {2883expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));2884} else if (match('.')) {2885expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));2886} else {2887expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));2888}2889}28902891return expr;2892}28932894function parseLeftHandSideExpression() {2895var expr, marker = markerCreate();28962897expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();28982899while (match('.') || match('[') || lookahead.type === Token.Template) {2900if (match('[')) {2901expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));2902} else if (match('.')) {2903expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));2904} else {2905expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));2906}2907}29082909return expr;2910}29112912// 11.3 Postfix Expressions29132914function parsePostfixExpression() {2915var marker = markerCreate(),2916expr = parseLeftHandSideExpressionAllowCall(),2917token;29182919if (lookahead.type !== Token.Punctuator) {2920return expr;2921}29222923if ((match('++') || match('--')) && !peekLineTerminator()) {2924// 11.3.1, 11.3.22925if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {2926throwErrorTolerant({}, Messages.StrictLHSPostfix);2927}29282929if (!isLeftHandSide(expr)) {2930throwError({}, Messages.InvalidLHSInAssignment);2931}29322933token = lex();2934expr = markerApply(marker, delegate.createPostfixExpression(token.value, expr));2935}29362937return expr;2938}29392940// 11.4 Unary Operators29412942function parseUnaryExpression() {2943var marker, token, expr;29442945if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {2946return parsePostfixExpression();2947}29482949if (match('++') || match('--')) {2950marker = markerCreate();2951token = lex();2952expr = parseUnaryExpression();2953// 11.4.4, 11.4.52954if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {2955throwErrorTolerant({}, Messages.StrictLHSPrefix);2956}29572958if (!isLeftHandSide(expr)) {2959throwError({}, Messages.InvalidLHSInAssignment);2960}29612962return markerApply(marker, delegate.createUnaryExpression(token.value, expr));2963}29642965if (match('+') || match('-') || match('~') || match('!')) {2966marker = markerCreate();2967token = lex();2968expr = parseUnaryExpression();2969return markerApply(marker, delegate.createUnaryExpression(token.value, expr));2970}29712972if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {2973marker = markerCreate();2974token = lex();2975expr = parseUnaryExpression();2976expr = markerApply(marker, delegate.createUnaryExpression(token.value, expr));2977if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {2978throwErrorTolerant({}, Messages.StrictDelete);2979}2980return expr;2981}29822983return parsePostfixExpression();2984}29852986function binaryPrecedence(token, allowIn) {2987var prec = 0;29882989if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {2990return 0;2991}29922993switch (token.value) {2994case '||':2995prec = 1;2996break;29972998case '&&':2999prec = 2;3000break;30013002case '|':3003prec = 3;3004break;30053006case '^':3007prec = 4;3008break;30093010case '&':3011prec = 5;3012break;30133014case '==':3015case '!=':3016case '===':3017case '!==':3018prec = 6;3019break;30203021case '<':3022case '>':3023case '<=':3024case '>=':3025case 'instanceof':3026prec = 7;3027break;30283029case 'in':3030prec = allowIn ? 7 : 0;3031break;30323033case '<<':3034case '>>':3035case '>>>':3036prec = 8;3037break;30383039case '+':3040case '-':3041prec = 9;3042break;30433044case '*':3045case '/':3046case '%':3047prec = 11;3048break;30493050default:3051break;3052}30533054return prec;3055}30563057// 11.5 Multiplicative Operators3058// 11.6 Additive Operators3059// 11.7 Bitwise Shift Operators3060// 11.8 Relational Operators3061// 11.9 Equality Operators3062// 11.10 Binary Bitwise Operators3063// 11.11 Binary Logical Operators30643065function parseBinaryExpression() {3066var expr, token, prec, previousAllowIn, stack, right, operator, left, i,3067marker, markers;30683069previousAllowIn = state.allowIn;3070state.allowIn = true;30713072marker = markerCreate();3073left = parseUnaryExpression();30743075token = lookahead;3076prec = binaryPrecedence(token, previousAllowIn);3077if (prec === 0) {3078return left;3079}3080token.prec = prec;3081lex();30823083markers = [marker, markerCreate()];3084right = parseUnaryExpression();30853086stack = [left, token, right];30873088while ((prec = binaryPrecedence(lookahead, previousAllowIn)) > 0) {30893090// Reduce: make a binary expression from the three topmost entries.3091while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {3092right = stack.pop();3093operator = stack.pop().value;3094left = stack.pop();3095expr = delegate.createBinaryExpression(operator, left, right);3096markers.pop();3097marker = markers.pop();3098markerApply(marker, expr);3099stack.push(expr);3100markers.push(marker);3101}31023103// Shift.3104token = lex();3105token.prec = prec;3106stack.push(token);3107markers.push(markerCreate());3108expr = parseUnaryExpression();3109stack.push(expr);3110}31113112state.allowIn = previousAllowIn;31133114// Final reduce to clean-up the stack.3115i = stack.length - 1;3116expr = stack[i];3117markers.pop();3118while (i > 1) {3119expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);3120i -= 2;3121marker = markers.pop();3122markerApply(marker, expr);3123}31243125return expr;3126}312731283129// 11.12 Conditional Operator31303131function parseConditionalExpression() {3132var expr, previousAllowIn, consequent, alternate, marker = markerCreate();3133expr = parseBinaryExpression();31343135if (match('?')) {3136lex();3137previousAllowIn = state.allowIn;3138state.allowIn = true;3139consequent = parseAssignmentExpression();3140state.allowIn = previousAllowIn;3141expect(':');3142alternate = parseAssignmentExpression();31433144expr = markerApply(marker, delegate.createConditionalExpression(expr, consequent, alternate));3145}31463147return expr;3148}31493150// 11.13 Assignment Operators31513152function reinterpretAsAssignmentBindingPattern(expr) {3153var i, len, property, element;31543155if (expr.type === Syntax.ObjectExpression) {3156expr.type = Syntax.ObjectPattern;3157for (i = 0, len = expr.properties.length; i < len; i += 1) {3158property = expr.properties[i];3159if (property.type === Syntax.SpreadProperty) {3160if (i < len - 1) {3161throwError({}, Messages.PropertyAfterSpreadProperty);3162}3163reinterpretAsAssignmentBindingPattern(property.argument);3164} else {3165if (property.kind !== 'init') {3166throwError({}, Messages.InvalidLHSInAssignment);3167}3168reinterpretAsAssignmentBindingPattern(property.value);3169}3170}3171} else if (expr.type === Syntax.ArrayExpression) {3172expr.type = Syntax.ArrayPattern;3173for (i = 0, len = expr.elements.length; i < len; i += 1) {3174element = expr.elements[i];3175if (element) {3176reinterpretAsAssignmentBindingPattern(element);3177}3178}3179} else if (expr.type === Syntax.Identifier) {3180if (isRestrictedWord(expr.name)) {3181throwError({}, Messages.InvalidLHSInAssignment);3182}3183} else if (expr.type === Syntax.SpreadElement) {3184reinterpretAsAssignmentBindingPattern(expr.argument);3185if (expr.argument.type === Syntax.ObjectPattern) {3186throwError({}, Messages.ObjectPatternAsSpread);3187}3188} else {3189if (expr.type !== Syntax.MemberExpression && expr.type !== Syntax.CallExpression && expr.type !== Syntax.NewExpression) {3190throwError({}, Messages.InvalidLHSInAssignment);3191}3192}3193}319431953196function reinterpretAsDestructuredParameter(options, expr) {3197var i, len, property, element;31983199if (expr.type === Syntax.ObjectExpression) {3200expr.type = Syntax.ObjectPattern;3201for (i = 0, len = expr.properties.length; i < len; i += 1) {3202property = expr.properties[i];3203if (property.kind !== 'init') {3204throwError({}, Messages.InvalidLHSInFormalsList);3205}3206reinterpretAsDestructuredParameter(options, property.value);3207}3208} else if (expr.type === Syntax.ArrayExpression) {3209expr.type = Syntax.ArrayPattern;3210for (i = 0, len = expr.elements.length; i < len; i += 1) {3211element = expr.elements[i];3212if (element) {3213reinterpretAsDestructuredParameter(options, element);3214}3215}3216} else if (expr.type === Syntax.Identifier) {3217validateParam(options, expr, expr.name);3218} else {3219if (expr.type !== Syntax.MemberExpression) {3220throwError({}, Messages.InvalidLHSInFormalsList);3221}3222}3223}32243225function reinterpretAsCoverFormalsList(expressions) {3226var i, len, param, params, defaults, defaultCount, options, rest;32273228params = [];3229defaults = [];3230defaultCount = 0;3231rest = null;3232options = {3233paramSet: {}3234};32353236for (i = 0, len = expressions.length; i < len; i += 1) {3237param = expressions[i];3238if (param.type === Syntax.Identifier) {3239params.push(param);3240defaults.push(null);3241validateParam(options, param, param.name);3242} else if (param.type === Syntax.ObjectExpression || param.type === Syntax.ArrayExpression) {3243reinterpretAsDestructuredParameter(options, param);3244params.push(param);3245defaults.push(null);3246} else if (param.type === Syntax.SpreadElement) {3247assert(i === len - 1, 'It is guaranteed that SpreadElement is last element by parseExpression');3248reinterpretAsDestructuredParameter(options, param.argument);3249rest = param.argument;3250} else if (param.type === Syntax.AssignmentExpression) {3251params.push(param.left);3252defaults.push(param.right);3253++defaultCount;3254validateParam(options, param.left, param.left.name);3255} else {3256return null;3257}3258}32593260if (options.message === Messages.StrictParamDupe) {3261throwError(3262strict ? options.stricted : options.firstRestricted,3263options.message3264);3265}32663267if (defaultCount === 0) {3268defaults = [];3269}32703271return {3272params: params,3273defaults: defaults,3274rest: rest,3275stricted: options.stricted,3276firstRestricted: options.firstRestricted,3277message: options.message3278};3279}32803281function parseArrowFunctionExpression(options, marker) {3282var previousStrict, previousYieldAllowed, body;32833284expect('=>');32853286previousStrict = strict;3287previousYieldAllowed = state.yieldAllowed;3288state.yieldAllowed = false;3289body = parseConciseBody();32903291if (strict && options.firstRestricted) {3292throwError(options.firstRestricted, options.message);3293}3294if (strict && options.stricted) {3295throwErrorTolerant(options.stricted, options.message);3296}32973298strict = previousStrict;3299state.yieldAllowed = previousYieldAllowed;33003301return markerApply(marker, delegate.createArrowFunctionExpression(3302options.params,3303options.defaults,3304body,3305options.rest,3306body.type !== Syntax.BlockStatement3307));3308}33093310function parseAssignmentExpression() {3311var marker, expr, token, params, oldParenthesizedCount;33123313// Note that 'yield' is treated as a keyword in strict mode, but a3314// contextual keyword (identifier) in non-strict mode, so we need3315// to use matchKeyword and matchContextualKeyword appropriately.3316if ((state.yieldAllowed && matchContextualKeyword('yield')) || (strict && matchKeyword('yield'))) {3317return parseYieldExpression();3318}33193320oldParenthesizedCount = state.parenthesizedCount;33213322marker = markerCreate();33233324if (match('(')) {3325token = lookahead2();3326if ((token.type === Token.Punctuator && token.value === ')') || token.value === '...') {3327params = parseParams();3328if (!match('=>')) {3329throwUnexpected(lex());3330}3331return parseArrowFunctionExpression(params, marker);3332}3333}33343335token = lookahead;3336expr = parseConditionalExpression();33373338if (match('=>') &&3339(state.parenthesizedCount === oldParenthesizedCount ||3340state.parenthesizedCount === (oldParenthesizedCount + 1))) {3341if (expr.type === Syntax.Identifier) {3342params = reinterpretAsCoverFormalsList([ expr ]);3343} else if (expr.type === Syntax.SequenceExpression) {3344params = reinterpretAsCoverFormalsList(expr.expressions);3345}3346if (params) {3347return parseArrowFunctionExpression(params, marker);3348}3349}33503351if (matchAssign()) {3352// 11.13.13353if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3354throwErrorTolerant(token, Messages.StrictLHSAssignment);3355}33563357// ES.next draf 11.13 Runtime Semantics step 13358if (match('=') && (expr.type === Syntax.ObjectExpression || expr.type === Syntax.ArrayExpression)) {3359reinterpretAsAssignmentBindingPattern(expr);3360} else if (!isLeftHandSide(expr)) {3361throwError({}, Messages.InvalidLHSInAssignment);3362}33633364expr = markerApply(marker, delegate.createAssignmentExpression(lex().value, expr, parseAssignmentExpression()));3365}33663367return expr;3368}33693370// 11.14 Comma Operator33713372function parseExpression() {3373var marker, expr, expressions, sequence, coverFormalsList, spreadFound, oldParenthesizedCount;33743375oldParenthesizedCount = state.parenthesizedCount;33763377marker = markerCreate();3378expr = parseAssignmentExpression();3379expressions = [ expr ];33803381if (match(',')) {3382while (index < length) {3383if (!match(',')) {3384break;3385}33863387lex();3388expr = parseSpreadOrAssignmentExpression();3389expressions.push(expr);33903391if (expr.type === Syntax.SpreadElement) {3392spreadFound = true;3393if (!match(')')) {3394throwError({}, Messages.ElementAfterSpreadElement);3395}3396break;3397}3398}33993400sequence = markerApply(marker, delegate.createSequenceExpression(expressions));3401}34023403if (match('=>')) {3404// Do not allow nested parentheses on the LHS of the =>.3405if (state.parenthesizedCount === oldParenthesizedCount || state.parenthesizedCount === (oldParenthesizedCount + 1)) {3406expr = expr.type === Syntax.SequenceExpression ? expr.expressions : expressions;3407coverFormalsList = reinterpretAsCoverFormalsList(expr);3408if (coverFormalsList) {3409return parseArrowFunctionExpression(coverFormalsList, marker);3410}3411}3412throwUnexpected(lex());3413}34143415if (spreadFound && lookahead2().value !== '=>') {3416throwError({}, Messages.IllegalSpread);3417}34183419return sequence || expr;3420}34213422// 12.1 Block34233424function parseStatementList() {3425var list = [],3426statement;34273428while (index < length) {3429if (match('}')) {3430break;3431}3432statement = parseSourceElement();3433if (typeof statement === 'undefined') {3434break;3435}3436list.push(statement);3437}34383439return list;3440}34413442function parseBlock() {3443var block, marker = markerCreate();34443445expect('{');34463447block = parseStatementList();34483449expect('}');34503451return markerApply(marker, delegate.createBlockStatement(block));3452}34533454// 12.2 Variable Statement34553456function parseTypeAnnotation(dontExpectColon) {3457var typeIdentifier = null, paramTypes = null, returnType = null,3458nullable = false, marker = markerCreate();34593460if (!dontExpectColon) {3461expect(':');3462}34633464if (match('?')) {3465lex();3466nullable = true;3467}34683469if (lookahead.type === Token.Identifier) {3470typeIdentifier = parseVariableIdentifier();3471}34723473if (match('(')) {3474lex();3475paramTypes = [];3476while (lookahead.type === Token.Identifier || match('?')) {3477paramTypes.push(parseTypeAnnotation(true));3478if (!match(')')) {3479expect(',');3480}3481}3482expect(')');3483expect('=>');34843485if (matchKeyword('void')) {3486lex();3487} else {3488returnType = parseTypeAnnotation(true);3489}3490}34913492return markerApply(marker, delegate.createTypeAnnotation(3493typeIdentifier,3494paramTypes,3495returnType,3496nullable3497));3498}34993500function parseVariableIdentifier() {3501var marker = markerCreate(),3502token = lex();35033504if (token.type !== Token.Identifier) {3505throwUnexpected(token);3506}35073508return markerApply(marker, delegate.createIdentifier(token.value));3509}35103511function parseTypeAnnotatableIdentifier() {3512var marker = markerCreate(),3513ident = parseVariableIdentifier();35143515if (match(':')) {3516return markerApply(marker, delegate.createTypeAnnotatedIdentifier(ident, parseTypeAnnotation()));3517}35183519return ident;3520}35213522function parseVariableDeclaration(kind) {3523var id,3524marker = markerCreate(),3525init = null;3526if (match('{')) {3527id = parseObjectInitialiser();3528reinterpretAsAssignmentBindingPattern(id);3529} else if (match('[')) {3530id = parseArrayInitialiser();3531reinterpretAsAssignmentBindingPattern(id);3532} else {3533id = state.allowKeyword ? parseNonComputedProperty() : parseTypeAnnotatableIdentifier();3534// 12.2.13535if (strict && isRestrictedWord(id.name)) {3536throwErrorTolerant({}, Messages.StrictVarName);3537}3538}35393540if (kind === 'const') {3541if (!match('=')) {3542throwError({}, Messages.NoUnintializedConst);3543}3544expect('=');3545init = parseAssignmentExpression();3546} else if (match('=')) {3547lex();3548init = parseAssignmentExpression();3549}35503551return markerApply(marker, delegate.createVariableDeclarator(id, init));3552}35533554function parseVariableDeclarationList(kind) {3555var list = [];35563557do {3558list.push(parseVariableDeclaration(kind));3559if (!match(',')) {3560break;3561}3562lex();3563} while (index < length);35643565return list;3566}35673568function parseVariableStatement() {3569var declarations, marker = markerCreate();35703571expectKeyword('var');35723573declarations = parseVariableDeclarationList();35743575consumeSemicolon();35763577return markerApply(marker, delegate.createVariableDeclaration(declarations, 'var'));3578}35793580// kind may be `const` or `let`3581// Both are experimental and not in the specification yet.3582// see http://wiki.ecmascript.org/doku.php?id=harmony:const3583// and http://wiki.ecmascript.org/doku.php?id=harmony:let3584function parseConstLetDeclaration(kind) {3585var declarations, marker = markerCreate();35863587expectKeyword(kind);35883589declarations = parseVariableDeclarationList(kind);35903591consumeSemicolon();35923593return markerApply(marker, delegate.createVariableDeclaration(declarations, kind));3594}35953596// http://wiki.ecmascript.org/doku.php?id=harmony:modules35973598function parseModuleDeclaration() {3599var id, src, body, marker = markerCreate();36003601lex(); // 'module'36023603if (peekLineTerminator()) {3604throwError({}, Messages.NewlineAfterModule);3605}36063607switch (lookahead.type) {36083609case Token.StringLiteral:3610id = parsePrimaryExpression();3611body = parseModuleBlock();3612src = null;3613break;36143615case Token.Identifier:3616id = parseVariableIdentifier();3617body = null;3618if (!matchContextualKeyword('from')) {3619throwUnexpected(lex());3620}3621lex();3622src = parsePrimaryExpression();3623if (src.type !== Syntax.Literal) {3624throwError({}, Messages.InvalidModuleSpecifier);3625}3626break;3627}36283629consumeSemicolon();3630return markerApply(marker, delegate.createModuleDeclaration(id, src, body));3631}36323633function parseExportBatchSpecifier() {3634var marker = markerCreate();3635expect('*');3636return markerApply(marker, delegate.createExportBatchSpecifier());3637}36383639function parseExportSpecifier() {3640var id, name = null, marker = markerCreate();36413642id = parseVariableIdentifier();3643if (matchContextualKeyword('as')) {3644lex();3645name = parseNonComputedProperty();3646}36473648return markerApply(marker, delegate.createExportSpecifier(id, name));3649}36503651function parseExportDeclaration() {3652var previousAllowKeyword, decl, def, src, specifiers,3653marker = markerCreate();36543655expectKeyword('export');36563657if (lookahead.type === Token.Keyword) {3658switch (lookahead.value) {3659case 'let':3660case 'const':3661case 'var':3662case 'class':3663case 'function':3664return markerApply(marker, delegate.createExportDeclaration(parseSourceElement(), null, null));3665}3666}36673668if (isIdentifierName(lookahead)) {3669previousAllowKeyword = state.allowKeyword;3670state.allowKeyword = true;3671decl = parseVariableDeclarationList('let');3672state.allowKeyword = previousAllowKeyword;3673return markerApply(marker, delegate.createExportDeclaration(decl, null, null));3674}36753676specifiers = [];3677src = null;36783679if (match('*')) {3680specifiers.push(parseExportBatchSpecifier());3681} else {3682expect('{');3683do {3684specifiers.push(parseExportSpecifier());3685} while (match(',') && lex());3686expect('}');3687}36883689if (matchContextualKeyword('from')) {3690lex();3691src = parsePrimaryExpression();3692if (src.type !== Syntax.Literal) {3693throwError({}, Messages.InvalidModuleSpecifier);3694}3695}36963697consumeSemicolon();36983699return markerApply(marker, delegate.createExportDeclaration(null, specifiers, src));3700}37013702function parseImportDeclaration() {3703var specifiers, kind, src, marker = markerCreate();37043705expectKeyword('import');3706specifiers = [];37073708if (isIdentifierName(lookahead)) {3709kind = 'default';3710specifiers.push(parseImportSpecifier());37113712if (!matchContextualKeyword('from')) {3713throwError({}, Messages.NoFromAfterImport);3714}3715lex();3716} else if (match('{')) {3717kind = 'named';3718lex();3719do {3720specifiers.push(parseImportSpecifier());3721} while (match(',') && lex());3722expect('}');37233724if (!matchContextualKeyword('from')) {3725throwError({}, Messages.NoFromAfterImport);3726}3727lex();3728}37293730src = parsePrimaryExpression();3731if (src.type !== Syntax.Literal) {3732throwError({}, Messages.InvalidModuleSpecifier);3733}37343735consumeSemicolon();37363737return markerApply(marker, delegate.createImportDeclaration(specifiers, kind, src));3738}37393740function parseImportSpecifier() {3741var id, name = null, marker = markerCreate();37423743id = parseNonComputedProperty();3744if (matchContextualKeyword('as')) {3745lex();3746name = parseVariableIdentifier();3747}37483749return markerApply(marker, delegate.createImportSpecifier(id, name));3750}37513752// 12.3 Empty Statement37533754function parseEmptyStatement() {3755var marker = markerCreate();3756expect(';');3757return markerApply(marker, delegate.createEmptyStatement());3758}37593760// 12.4 Expression Statement37613762function parseExpressionStatement() {3763var marker = markerCreate(), expr = parseExpression();3764consumeSemicolon();3765return markerApply(marker, delegate.createExpressionStatement(expr));3766}37673768// 12.5 If statement37693770function parseIfStatement() {3771var test, consequent, alternate, marker = markerCreate();37723773expectKeyword('if');37743775expect('(');37763777test = parseExpression();37783779expect(')');37803781consequent = parseStatement();37823783if (matchKeyword('else')) {3784lex();3785alternate = parseStatement();3786} else {3787alternate = null;3788}37893790return markerApply(marker, delegate.createIfStatement(test, consequent, alternate));3791}37923793// 12.6 Iteration Statements37943795function parseDoWhileStatement() {3796var body, test, oldInIteration, marker = markerCreate();37973798expectKeyword('do');37993800oldInIteration = state.inIteration;3801state.inIteration = true;38023803body = parseStatement();38043805state.inIteration = oldInIteration;38063807expectKeyword('while');38083809expect('(');38103811test = parseExpression();38123813expect(')');38143815if (match(';')) {3816lex();3817}38183819return markerApply(marker, delegate.createDoWhileStatement(body, test));3820}38213822function parseWhileStatement() {3823var test, body, oldInIteration, marker = markerCreate();38243825expectKeyword('while');38263827expect('(');38283829test = parseExpression();38303831expect(')');38323833oldInIteration = state.inIteration;3834state.inIteration = true;38353836body = parseStatement();38373838state.inIteration = oldInIteration;38393840return markerApply(marker, delegate.createWhileStatement(test, body));3841}38423843function parseForVariableDeclaration() {3844var marker = markerCreate(),3845token = lex(),3846declarations = parseVariableDeclarationList();38473848return markerApply(marker, delegate.createVariableDeclaration(declarations, token.value));3849}38503851function parseForStatement(opts) {3852var init, test, update, left, right, body, operator, oldInIteration,3853marker = markerCreate();3854init = test = update = null;3855expectKeyword('for');38563857// http://wiki.ecmascript.org/doku.php?id=proposals:iterators_and_generators&s=each3858if (matchContextualKeyword('each')) {3859throwError({}, Messages.EachNotAllowed);3860}38613862expect('(');38633864if (match(';')) {3865lex();3866} else {3867if (matchKeyword('var') || matchKeyword('let') || matchKeyword('const')) {3868state.allowIn = false;3869init = parseForVariableDeclaration();3870state.allowIn = true;38713872if (init.declarations.length === 1) {3873if (matchKeyword('in') || matchContextualKeyword('of')) {3874operator = lookahead;3875if (!((operator.value === 'in' || init.kind !== 'var') && init.declarations[0].init)) {3876lex();3877left = init;3878right = parseExpression();3879init = null;3880}3881}3882}3883} else {3884state.allowIn = false;3885init = parseExpression();3886state.allowIn = true;38873888if (matchContextualKeyword('of')) {3889operator = lex();3890left = init;3891right = parseExpression();3892init = null;3893} else if (matchKeyword('in')) {3894// LeftHandSideExpression3895if (!isAssignableLeftHandSide(init)) {3896throwError({}, Messages.InvalidLHSInForIn);3897}3898operator = lex();3899left = init;3900right = parseExpression();3901init = null;3902}3903}39043905if (typeof left === 'undefined') {3906expect(';');3907}3908}39093910if (typeof left === 'undefined') {39113912if (!match(';')) {3913test = parseExpression();3914}3915expect(';');39163917if (!match(')')) {3918update = parseExpression();3919}3920}39213922expect(')');39233924oldInIteration = state.inIteration;3925state.inIteration = true;39263927if (!(opts !== undefined && opts.ignoreBody)) {3928body = parseStatement();3929}39303931state.inIteration = oldInIteration;39323933if (typeof left === 'undefined') {3934return markerApply(marker, delegate.createForStatement(init, test, update, body));3935}39363937if (operator.value === 'in') {3938return markerApply(marker, delegate.createForInStatement(left, right, body));3939}3940return markerApply(marker, delegate.createForOfStatement(left, right, body));3941}39423943// 12.7 The continue statement39443945function parseContinueStatement() {3946var label = null, key, marker = markerCreate();39473948expectKeyword('continue');39493950// Optimize the most common form: 'continue;'.3951if (source.charCodeAt(index) === 59) {3952lex();39533954if (!state.inIteration) {3955throwError({}, Messages.IllegalContinue);3956}39573958return markerApply(marker, delegate.createContinueStatement(null));3959}39603961if (peekLineTerminator()) {3962if (!state.inIteration) {3963throwError({}, Messages.IllegalContinue);3964}39653966return markerApply(marker, delegate.createContinueStatement(null));3967}39683969if (lookahead.type === Token.Identifier) {3970label = parseVariableIdentifier();39713972key = '$' + label.name;3973if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {3974throwError({}, Messages.UnknownLabel, label.name);3975}3976}39773978consumeSemicolon();39793980if (label === null && !state.inIteration) {3981throwError({}, Messages.IllegalContinue);3982}39833984return markerApply(marker, delegate.createContinueStatement(label));3985}39863987// 12.8 The break statement39883989function parseBreakStatement() {3990var label = null, key, marker = markerCreate();39913992expectKeyword('break');39933994// Catch the very common case first: immediately a semicolon (char #59).3995if (source.charCodeAt(index) === 59) {3996lex();39973998if (!(state.inIteration || state.inSwitch)) {3999throwError({}, Messages.IllegalBreak);4000}40014002return markerApply(marker, delegate.createBreakStatement(null));4003}40044005if (peekLineTerminator()) {4006if (!(state.inIteration || state.inSwitch)) {4007throwError({}, Messages.IllegalBreak);4008}40094010return markerApply(marker, delegate.createBreakStatement(null));4011}40124013if (lookahead.type === Token.Identifier) {4014label = parseVariableIdentifier();40154016key = '$' + label.name;4017if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {4018throwError({}, Messages.UnknownLabel, label.name);4019}4020}40214022consumeSemicolon();40234024if (label === null && !(state.inIteration || state.inSwitch)) {4025throwError({}, Messages.IllegalBreak);4026}40274028return markerApply(marker, delegate.createBreakStatement(label));4029}40304031// 12.9 The return statement40324033function parseReturnStatement() {4034var argument = null, marker = markerCreate();40354036expectKeyword('return');40374038if (!state.inFunctionBody) {4039throwErrorTolerant({}, Messages.IllegalReturn);4040}40414042// 'return' followed by a space and an identifier is very common.4043if (source.charCodeAt(index) === 32) {4044if (isIdentifierStart(source.charCodeAt(index + 1))) {4045argument = parseExpression();4046consumeSemicolon();4047return markerApply(marker, delegate.createReturnStatement(argument));4048}4049}40504051if (peekLineTerminator()) {4052return markerApply(marker, delegate.createReturnStatement(null));4053}40544055if (!match(';')) {4056if (!match('}') && lookahead.type !== Token.EOF) {4057argument = parseExpression();4058}4059}40604061consumeSemicolon();40624063return markerApply(marker, delegate.createReturnStatement(argument));4064}40654066// 12.10 The with statement40674068function parseWithStatement() {4069var object, body, marker = markerCreate();40704071if (strict) {4072throwErrorTolerant({}, Messages.StrictModeWith);4073}40744075expectKeyword('with');40764077expect('(');40784079object = parseExpression();40804081expect(')');40824083body = parseStatement();40844085return markerApply(marker, delegate.createWithStatement(object, body));4086}40874088// 12.10 The swith statement40894090function parseSwitchCase() {4091var test,4092consequent = [],4093sourceElement,4094marker = markerCreate();40954096if (matchKeyword('default')) {4097lex();4098test = null;4099} else {4100expectKeyword('case');4101test = parseExpression();4102}4103expect(':');41044105while (index < length) {4106if (match('}') || matchKeyword('default') || matchKeyword('case')) {4107break;4108}4109sourceElement = parseSourceElement();4110if (typeof sourceElement === 'undefined') {4111break;4112}4113consequent.push(sourceElement);4114}41154116return markerApply(marker, delegate.createSwitchCase(test, consequent));4117}41184119function parseSwitchStatement() {4120var discriminant, cases, clause, oldInSwitch, defaultFound, marker = markerCreate();41214122expectKeyword('switch');41234124expect('(');41254126discriminant = parseExpression();41274128expect(')');41294130expect('{');41314132cases = [];41334134if (match('}')) {4135lex();4136return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));4137}41384139oldInSwitch = state.inSwitch;4140state.inSwitch = true;4141defaultFound = false;41424143while (index < length) {4144if (match('}')) {4145break;4146}4147clause = parseSwitchCase();4148if (clause.test === null) {4149if (defaultFound) {4150throwError({}, Messages.MultipleDefaultsInSwitch);4151}4152defaultFound = true;4153}4154cases.push(clause);4155}41564157state.inSwitch = oldInSwitch;41584159expect('}');41604161return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));4162}41634164// 12.13 The throw statement41654166function parseThrowStatement() {4167var argument, marker = markerCreate();41684169expectKeyword('throw');41704171if (peekLineTerminator()) {4172throwError({}, Messages.NewlineAfterThrow);4173}41744175argument = parseExpression();41764177consumeSemicolon();41784179return markerApply(marker, delegate.createThrowStatement(argument));4180}41814182// 12.14 The try statement41834184function parseCatchClause() {4185var param, body, marker = markerCreate();41864187expectKeyword('catch');41884189expect('(');4190if (match(')')) {4191throwUnexpected(lookahead);4192}41934194param = parseExpression();4195// 12.14.14196if (strict && param.type === Syntax.Identifier && isRestrictedWord(param.name)) {4197throwErrorTolerant({}, Messages.StrictCatchVariable);4198}41994200expect(')');4201body = parseBlock();4202return markerApply(marker, delegate.createCatchClause(param, body));4203}42044205function parseTryStatement() {4206var block, handlers = [], finalizer = null, marker = markerCreate();42074208expectKeyword('try');42094210block = parseBlock();42114212if (matchKeyword('catch')) {4213handlers.push(parseCatchClause());4214}42154216if (matchKeyword('finally')) {4217lex();4218finalizer = parseBlock();4219}42204221if (handlers.length === 0 && !finalizer) {4222throwError({}, Messages.NoCatchOrFinally);4223}42244225return markerApply(marker, delegate.createTryStatement(block, [], handlers, finalizer));4226}42274228// 12.15 The debugger statement42294230function parseDebuggerStatement() {4231var marker = markerCreate();4232expectKeyword('debugger');42334234consumeSemicolon();42354236return markerApply(marker, delegate.createDebuggerStatement());4237}42384239// 12 Statements42404241function parseStatement() {4242var type = lookahead.type,4243marker,4244expr,4245labeledBody,4246key;42474248if (type === Token.EOF) {4249throwUnexpected(lookahead);4250}42514252if (type === Token.Punctuator) {4253switch (lookahead.value) {4254case ';':4255return parseEmptyStatement();4256case '{':4257return parseBlock();4258case '(':4259return parseExpressionStatement();4260default:4261break;4262}4263}42644265if (type === Token.Keyword) {4266switch (lookahead.value) {4267case 'break':4268return parseBreakStatement();4269case 'continue':4270return parseContinueStatement();4271case 'debugger':4272return parseDebuggerStatement();4273case 'do':4274return parseDoWhileStatement();4275case 'for':4276return parseForStatement();4277case 'function':4278return parseFunctionDeclaration();4279case 'class':4280return parseClassDeclaration();4281case 'if':4282return parseIfStatement();4283case 'return':4284return parseReturnStatement();4285case 'switch':4286return parseSwitchStatement();4287case 'throw':4288return parseThrowStatement();4289case 'try':4290return parseTryStatement();4291case 'var':4292return parseVariableStatement();4293case 'while':4294return parseWhileStatement();4295case 'with':4296return parseWithStatement();4297default:4298break;4299}4300}43014302marker = markerCreate();4303expr = parseExpression();43044305// 12.12 Labelled Statements4306if ((expr.type === Syntax.Identifier) && match(':')) {4307lex();43084309key = '$' + expr.name;4310if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {4311throwError({}, Messages.Redeclaration, 'Label', expr.name);4312}43134314state.labelSet[key] = true;4315labeledBody = parseStatement();4316delete state.labelSet[key];4317return markerApply(marker, delegate.createLabeledStatement(expr, labeledBody));4318}43194320consumeSemicolon();43214322return markerApply(marker, delegate.createExpressionStatement(expr));4323}43244325// 13 Function Definition43264327function parseConciseBody() {4328if (match('{')) {4329return parseFunctionSourceElements();4330}4331return parseAssignmentExpression();4332}43334334function parseFunctionSourceElements() {4335var sourceElement, sourceElements = [], token, directive, firstRestricted,4336oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, oldParenthesizedCount,4337marker = markerCreate();43384339expect('{');43404341while (index < length) {4342if (lookahead.type !== Token.StringLiteral) {4343break;4344}4345token = lookahead;43464347sourceElement = parseSourceElement();4348sourceElements.push(sourceElement);4349if (sourceElement.expression.type !== Syntax.Literal) {4350// this is not directive4351break;4352}4353directive = source.slice(token.range[0] + 1, token.range[1] - 1);4354if (directive === 'use strict') {4355strict = true;4356if (firstRestricted) {4357throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);4358}4359} else {4360if (!firstRestricted && token.octal) {4361firstRestricted = token;4362}4363}4364}43654366oldLabelSet = state.labelSet;4367oldInIteration = state.inIteration;4368oldInSwitch = state.inSwitch;4369oldInFunctionBody = state.inFunctionBody;4370oldParenthesizedCount = state.parenthesizedCount;43714372state.labelSet = {};4373state.inIteration = false;4374state.inSwitch = false;4375state.inFunctionBody = true;4376state.parenthesizedCount = 0;43774378while (index < length) {4379if (match('}')) {4380break;4381}4382sourceElement = parseSourceElement();4383if (typeof sourceElement === 'undefined') {4384break;4385}4386sourceElements.push(sourceElement);4387}43884389expect('}');43904391state.labelSet = oldLabelSet;4392state.inIteration = oldInIteration;4393state.inSwitch = oldInSwitch;4394state.inFunctionBody = oldInFunctionBody;4395state.parenthesizedCount = oldParenthesizedCount;43964397return markerApply(marker, delegate.createBlockStatement(sourceElements));4398}43994400function validateParam(options, param, name) {4401var key = '$' + name;4402if (strict) {4403if (isRestrictedWord(name)) {4404options.stricted = param;4405options.message = Messages.StrictParamName;4406}4407if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {4408options.stricted = param;4409options.message = Messages.StrictParamDupe;4410}4411} else if (!options.firstRestricted) {4412if (isRestrictedWord(name)) {4413options.firstRestricted = param;4414options.message = Messages.StrictParamName;4415} else if (isStrictModeReservedWord(name)) {4416options.firstRestricted = param;4417options.message = Messages.StrictReservedWord;4418} else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {4419options.firstRestricted = param;4420options.message = Messages.StrictParamDupe;4421}4422}4423options.paramSet[key] = true;4424}44254426function parseParam(options) {4427var token, rest, param, def;44284429token = lookahead;4430if (token.value === '...') {4431token = lex();4432rest = true;4433}44344435if (match('[')) {4436param = parseArrayInitialiser();4437reinterpretAsDestructuredParameter(options, param);4438} else if (match('{')) {4439if (rest) {4440throwError({}, Messages.ObjectPatternAsRestParameter);4441}4442param = parseObjectInitialiser();4443reinterpretAsDestructuredParameter(options, param);4444} else {4445// Typing rest params is awkward, so punting on that for now4446param = rest4447? parseVariableIdentifier()4448: parseTypeAnnotatableIdentifier();4449validateParam(options, token, token.value);4450}44514452if (match('=')) {4453if (rest) {4454throwErrorTolerant(lookahead, Messages.DefaultRestParameter);4455}4456lex();4457def = parseAssignmentExpression();4458++options.defaultCount;4459}44604461if (rest) {4462if (!match(')')) {4463throwError({}, Messages.ParameterAfterRestParameter);4464}4465options.rest = param;4466return false;4467}44684469options.params.push(param);4470options.defaults.push(def);4471return !match(')');4472}44734474function parseParams(firstRestricted) {4475var options, marker = markerCreate();44764477options = {4478params: [],4479defaultCount: 0,4480defaults: [],4481rest: null,4482firstRestricted: firstRestricted4483};44844485expect('(');44864487if (!match(')')) {4488options.paramSet = {};4489while (index < length) {4490if (!parseParam(options)) {4491break;4492}4493expect(',');4494}4495}44964497expect(')');44984499if (options.defaultCount === 0) {4500options.defaults = [];4501}45024503if (match(':')) {4504options.returnTypeAnnotation = parseTypeAnnotation();4505}45064507return markerApply(marker, options);4508}45094510function parseFunctionDeclaration() {4511var id, body, token, tmp, firstRestricted, message, previousStrict, previousYieldAllowed, generator,4512marker = markerCreate();45134514expectKeyword('function');45154516generator = false;4517if (match('*')) {4518lex();4519generator = true;4520}45214522token = lookahead;45234524id = parseVariableIdentifier();45254526if (strict) {4527if (isRestrictedWord(token.value)) {4528throwErrorTolerant(token, Messages.StrictFunctionName);4529}4530} else {4531if (isRestrictedWord(token.value)) {4532firstRestricted = token;4533message = Messages.StrictFunctionName;4534} else if (isStrictModeReservedWord(token.value)) {4535firstRestricted = token;4536message = Messages.StrictReservedWord;4537}4538}45394540tmp = parseParams(firstRestricted);4541firstRestricted = tmp.firstRestricted;4542if (tmp.message) {4543message = tmp.message;4544}45454546previousStrict = strict;4547previousYieldAllowed = state.yieldAllowed;4548state.yieldAllowed = generator;45494550body = parseFunctionSourceElements();45514552if (strict && firstRestricted) {4553throwError(firstRestricted, message);4554}4555if (strict && tmp.stricted) {4556throwErrorTolerant(tmp.stricted, message);4557}4558strict = previousStrict;4559state.yieldAllowed = previousYieldAllowed;45604561return markerApply(marker, delegate.createFunctionDeclaration(id, tmp.params, tmp.defaults, body, tmp.rest, generator, false,4562tmp.returnTypeAnnotation));4563}45644565function parseFunctionExpression() {4566var token, id = null, firstRestricted, message, tmp, body, previousStrict, previousYieldAllowed, generator,4567marker = markerCreate();45684569expectKeyword('function');45704571generator = false;45724573if (match('*')) {4574lex();4575generator = true;4576}45774578if (!match('(')) {4579token = lookahead;4580id = parseVariableIdentifier();4581if (strict) {4582if (isRestrictedWord(token.value)) {4583throwErrorTolerant(token, Messages.StrictFunctionName);4584}4585} else {4586if (isRestrictedWord(token.value)) {4587firstRestricted = token;4588message = Messages.StrictFunctionName;4589} else if (isStrictModeReservedWord(token.value)) {4590firstRestricted = token;4591message = Messages.StrictReservedWord;4592}4593}4594}45954596tmp = parseParams(firstRestricted);4597firstRestricted = tmp.firstRestricted;4598if (tmp.message) {4599message = tmp.message;4600}46014602previousStrict = strict;4603previousYieldAllowed = state.yieldAllowed;4604state.yieldAllowed = generator;46054606body = parseFunctionSourceElements();46074608if (strict && firstRestricted) {4609throwError(firstRestricted, message);4610}4611if (strict && tmp.stricted) {4612throwErrorTolerant(tmp.stricted, message);4613}4614strict = previousStrict;4615state.yieldAllowed = previousYieldAllowed;46164617return markerApply(marker, delegate.createFunctionExpression(id, tmp.params, tmp.defaults, body, tmp.rest, generator, false,4618tmp.returnTypeAnnotation));4619}46204621function parseYieldExpression() {4622var yieldToken, delegateFlag, expr, marker = markerCreate();46234624yieldToken = lex();4625assert(yieldToken.value === 'yield', 'Called parseYieldExpression with non-yield lookahead.');46264627if (!state.yieldAllowed) {4628throwErrorTolerant({}, Messages.IllegalYield);4629}46304631delegateFlag = false;4632if (match('*')) {4633lex();4634delegateFlag = true;4635}46364637expr = parseAssignmentExpression();46384639return markerApply(marker, delegate.createYieldExpression(expr, delegateFlag));4640}46414642// 14 Classes46434644function parseMethodDefinition(existingPropNames) {4645var token, key, param, propType, isValidDuplicateProp = false,4646marker = markerCreate();46474648if (lookahead.value === 'static') {4649propType = ClassPropertyType.static;4650lex();4651} else {4652propType = ClassPropertyType.prototype;4653}46544655if (match('*')) {4656lex();4657return markerApply(marker, delegate.createMethodDefinition(4658propType,4659'',4660parseObjectPropertyKey(),4661parsePropertyMethodFunction({ generator: true })4662));4663}46644665token = lookahead;4666key = parseObjectPropertyKey();46674668if (token.value === 'get' && !match('(')) {4669key = parseObjectPropertyKey();46704671// It is a syntax error if any other properties have a name4672// duplicating this one unless they are a setter4673if (existingPropNames[propType].hasOwnProperty(key.name)) {4674isValidDuplicateProp =4675// There isn't already a getter for this prop4676existingPropNames[propType][key.name].get === undefined4677// There isn't already a data prop by this name4678&& existingPropNames[propType][key.name].data === undefined4679// The only existing prop by this name is a setter4680&& existingPropNames[propType][key.name].set !== undefined;4681if (!isValidDuplicateProp) {4682throwError(key, Messages.IllegalDuplicateClassProperty);4683}4684} else {4685existingPropNames[propType][key.name] = {};4686}4687existingPropNames[propType][key.name].get = true;46884689expect('(');4690expect(')');4691return markerApply(marker, delegate.createMethodDefinition(4692propType,4693'get',4694key,4695parsePropertyFunction({ generator: false })4696));4697}4698if (token.value === 'set' && !match('(')) {4699key = parseObjectPropertyKey();47004701// It is a syntax error if any other properties have a name4702// duplicating this one unless they are a getter4703if (existingPropNames[propType].hasOwnProperty(key.name)) {4704isValidDuplicateProp =4705// There isn't already a setter for this prop4706existingPropNames[propType][key.name].set === undefined4707// There isn't already a data prop by this name4708&& existingPropNames[propType][key.name].data === undefined4709// The only existing prop by this name is a getter4710&& existingPropNames[propType][key.name].get !== undefined;4711if (!isValidDuplicateProp) {4712throwError(key, Messages.IllegalDuplicateClassProperty);4713}4714} else {4715existingPropNames[propType][key.name] = {};4716}4717existingPropNames[propType][key.name].set = true;47184719expect('(');4720token = lookahead;4721param = [ parseTypeAnnotatableIdentifier() ];4722expect(')');4723return markerApply(marker, delegate.createMethodDefinition(4724propType,4725'set',4726key,4727parsePropertyFunction({ params: param, generator: false, name: token })4728));4729}47304731// It is a syntax error if any other properties have the same name as a4732// non-getter, non-setter method4733if (existingPropNames[propType].hasOwnProperty(key.name)) {4734throwError(key, Messages.IllegalDuplicateClassProperty);4735} else {4736existingPropNames[propType][key.name] = {};4737}4738existingPropNames[propType][key.name].data = true;47394740return markerApply(marker, delegate.createMethodDefinition(4741propType,4742'',4743key,4744parsePropertyMethodFunction({ generator: false })4745));4746}47474748function parseClassElement(existingProps) {4749if (match(';')) {4750lex();4751return;4752}4753return parseMethodDefinition(existingProps);4754}47554756function parseClassBody() {4757var classElement, classElements = [], existingProps = {}, marker = markerCreate();47584759existingProps[ClassPropertyType.static] = {};4760existingProps[ClassPropertyType.prototype] = {};47614762expect('{');47634764while (index < length) {4765if (match('}')) {4766break;4767}4768classElement = parseClassElement(existingProps);47694770if (typeof classElement !== 'undefined') {4771classElements.push(classElement);4772}4773}47744775expect('}');47764777return markerApply(marker, delegate.createClassBody(classElements));4778}47794780function parseClassExpression() {4781var id, previousYieldAllowed, superClass = null, marker = markerCreate();47824783expectKeyword('class');47844785if (!matchKeyword('extends') && !match('{')) {4786id = parseVariableIdentifier();4787}47884789if (matchKeyword('extends')) {4790expectKeyword('extends');4791previousYieldAllowed = state.yieldAllowed;4792state.yieldAllowed = false;4793superClass = parseAssignmentExpression();4794state.yieldAllowed = previousYieldAllowed;4795}47964797return markerApply(marker, delegate.createClassExpression(id, superClass, parseClassBody()));4798}47994800function parseClassDeclaration() {4801var id, previousYieldAllowed, superClass = null, marker = markerCreate();48024803expectKeyword('class');48044805id = parseVariableIdentifier();48064807if (matchKeyword('extends')) {4808expectKeyword('extends');4809previousYieldAllowed = state.yieldAllowed;4810state.yieldAllowed = false;4811superClass = parseAssignmentExpression();4812state.yieldAllowed = previousYieldAllowed;4813}48144815return markerApply(marker, delegate.createClassDeclaration(id, superClass, parseClassBody()));4816}48174818// 15 Program48194820function matchModuleDeclaration() {4821var id;4822if (matchContextualKeyword('module')) {4823id = lookahead2();4824return id.type === Token.StringLiteral || id.type === Token.Identifier;4825}4826return false;4827}48284829function parseSourceElement() {4830if (lookahead.type === Token.Keyword) {4831switch (lookahead.value) {4832case 'const':4833case 'let':4834return parseConstLetDeclaration(lookahead.value);4835case 'function':4836return parseFunctionDeclaration();4837case 'export':4838return parseExportDeclaration();4839case 'import':4840return parseImportDeclaration();4841default:4842return parseStatement();4843}4844}48454846if (matchModuleDeclaration()) {4847throwError({}, Messages.NestedModule);4848}48494850if (lookahead.type !== Token.EOF) {4851return parseStatement();4852}4853}48544855function parseProgramElement() {4856if (lookahead.type === Token.Keyword) {4857switch (lookahead.value) {4858case 'export':4859return parseExportDeclaration();4860case 'import':4861return parseImportDeclaration();4862}4863}48644865if (matchModuleDeclaration()) {4866return parseModuleDeclaration();4867}48684869return parseSourceElement();4870}48714872function parseProgramElements() {4873var sourceElement, sourceElements = [], token, directive, firstRestricted;48744875while (index < length) {4876token = lookahead;4877if (token.type !== Token.StringLiteral) {4878break;4879}48804881sourceElement = parseProgramElement();4882sourceElements.push(sourceElement);4883if (sourceElement.expression.type !== Syntax.Literal) {4884// this is not directive4885break;4886}4887directive = source.slice(token.range[0] + 1, token.range[1] - 1);4888if (directive === 'use strict') {4889strict = true;4890if (firstRestricted) {4891throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);4892}4893} else {4894if (!firstRestricted && token.octal) {4895firstRestricted = token;4896}4897}4898}48994900while (index < length) {4901sourceElement = parseProgramElement();4902if (typeof sourceElement === 'undefined') {4903break;4904}4905sourceElements.push(sourceElement);4906}4907return sourceElements;4908}49094910function parseModuleElement() {4911return parseSourceElement();4912}49134914function parseModuleElements() {4915var list = [],4916statement;49174918while (index < length) {4919if (match('}')) {4920break;4921}4922statement = parseModuleElement();4923if (typeof statement === 'undefined') {4924break;4925}4926list.push(statement);4927}49284929return list;4930}49314932function parseModuleBlock() {4933var block, marker = markerCreate();49344935expect('{');49364937block = parseModuleElements();49384939expect('}');49404941return markerApply(marker, delegate.createBlockStatement(block));4942}49434944function parseProgram() {4945var body, marker = markerCreate();4946strict = false;4947peek();4948body = parseProgramElements();4949return markerApply(marker, delegate.createProgram(body));4950}49514952// The following functions are needed only when the option to preserve4953// the comments is active.49544955function addComment(type, value, start, end, loc) {4956var comment;49574958assert(typeof start === 'number', 'Comment must have valid position');49594960// Because the way the actual token is scanned, often the comments4961// (if any) are skipped twice during the lexical analysis.4962// Thus, we need to skip adding a comment if the comment array already4963// handled it.4964if (state.lastCommentStart >= start) {4965return;4966}4967state.lastCommentStart = start;49684969comment = {4970type: type,4971value: value4972};4973if (extra.range) {4974comment.range = [start, end];4975}4976if (extra.loc) {4977comment.loc = loc;4978}4979extra.comments.push(comment);4980}49814982function scanComment() {4983var comment, ch, loc, start, blockComment, lineComment;49844985comment = '';4986blockComment = false;4987lineComment = false;49884989while (index < length) {4990ch = source[index];49914992if (lineComment) {4993ch = source[index++];4994if (isLineTerminator(ch.charCodeAt(0))) {4995loc.end = {4996line: lineNumber,4997column: index - lineStart - 14998};4999lineComment = false;5000addComment('Line', comment, start, index - 1, loc);5001if (ch === '\r' && source[index] === '\n') {5002++index;5003}5004++lineNumber;5005lineStart = index;5006comment = '';5007} else if (index >= length) {5008lineComment = false;5009comment += ch;5010loc.end = {5011line: lineNumber,5012column: length - lineStart5013};5014addComment('Line', comment, start, length, loc);5015} else {5016comment += ch;5017}5018} else if (blockComment) {5019if (isLineTerminator(ch.charCodeAt(0))) {5020if (ch === '\r' && source[index + 1] === '\n') {5021++index;5022comment += '\r\n';5023} else {5024comment += ch;5025}5026++lineNumber;5027++index;5028lineStart = index;5029if (index >= length) {5030throwError({}, Messages.UnexpectedToken, 'ILLEGAL');5031}5032} else {5033ch = source[index++];5034if (index >= length) {5035throwError({}, Messages.UnexpectedToken, 'ILLEGAL');5036}5037comment += ch;5038if (ch === '*') {5039ch = source[index];5040if (ch === '/') {5041comment = comment.substr(0, comment.length - 1);5042blockComment = false;5043++index;5044loc.end = {5045line: lineNumber,5046column: index - lineStart5047};5048addComment('Block', comment, start, index, loc);5049comment = '';5050}5051}5052}5053} else if (ch === '/') {5054ch = source[index + 1];5055if (ch === '/') {5056loc = {5057start: {5058line: lineNumber,5059column: index - lineStart5060}5061};5062start = index;5063index += 2;5064lineComment = true;5065if (index >= length) {5066loc.end = {5067line: lineNumber,5068column: index - lineStart5069};5070lineComment = false;5071addComment('Line', comment, start, index, loc);5072}5073} else if (ch === '*') {5074start = index;5075index += 2;5076blockComment = true;5077loc = {5078start: {5079line: lineNumber,5080column: index - lineStart - 25081}5082};5083if (index >= length) {5084throwError({}, Messages.UnexpectedToken, 'ILLEGAL');5085}5086} else {5087break;5088}5089} else if (isWhiteSpace(ch.charCodeAt(0))) {5090++index;5091} else if (isLineTerminator(ch.charCodeAt(0))) {5092++index;5093if (ch === '\r' && source[index] === '\n') {5094++index;5095}5096++lineNumber;5097lineStart = index;5098} else {5099break;5100}5101}5102}51035104// 16 XJS51055106XHTMLEntities = {5107quot: '\u0022',5108amp: '&',5109apos: '\u0027',5110lt: '<',5111gt: '>',5112nbsp: '\u00A0',5113iexcl: '\u00A1',5114cent: '\u00A2',5115pound: '\u00A3',5116curren: '\u00A4',5117yen: '\u00A5',5118brvbar: '\u00A6',5119sect: '\u00A7',5120uml: '\u00A8',5121copy: '\u00A9',5122ordf: '\u00AA',5123laquo: '\u00AB',5124not: '\u00AC',5125shy: '\u00AD',5126reg: '\u00AE',5127macr: '\u00AF',5128deg: '\u00B0',5129plusmn: '\u00B1',5130sup2: '\u00B2',5131sup3: '\u00B3',5132acute: '\u00B4',5133micro: '\u00B5',5134para: '\u00B6',5135middot: '\u00B7',5136cedil: '\u00B8',5137sup1: '\u00B9',5138ordm: '\u00BA',5139raquo: '\u00BB',5140frac14: '\u00BC',5141frac12: '\u00BD',5142frac34: '\u00BE',5143iquest: '\u00BF',5144Agrave: '\u00C0',5145Aacute: '\u00C1',5146Acirc: '\u00C2',5147Atilde: '\u00C3',5148Auml: '\u00C4',5149Aring: '\u00C5',5150AElig: '\u00C6',5151Ccedil: '\u00C7',5152Egrave: '\u00C8',5153Eacute: '\u00C9',5154Ecirc: '\u00CA',5155Euml: '\u00CB',5156Igrave: '\u00CC',5157Iacute: '\u00CD',5158Icirc: '\u00CE',5159Iuml: '\u00CF',5160ETH: '\u00D0',5161Ntilde: '\u00D1',5162Ograve: '\u00D2',5163Oacute: '\u00D3',5164Ocirc: '\u00D4',5165Otilde: '\u00D5',5166Ouml: '\u00D6',5167times: '\u00D7',5168Oslash: '\u00D8',5169Ugrave: '\u00D9',5170Uacute: '\u00DA',5171Ucirc: '\u00DB',5172Uuml: '\u00DC',5173Yacute: '\u00DD',5174THORN: '\u00DE',5175szlig: '\u00DF',5176agrave: '\u00E0',5177aacute: '\u00E1',5178acirc: '\u00E2',5179atilde: '\u00E3',5180auml: '\u00E4',5181aring: '\u00E5',5182aelig: '\u00E6',5183ccedil: '\u00E7',5184egrave: '\u00E8',5185eacute: '\u00E9',5186ecirc: '\u00EA',5187euml: '\u00EB',5188igrave: '\u00EC',5189iacute: '\u00ED',5190icirc: '\u00EE',5191iuml: '\u00EF',5192eth: '\u00F0',5193ntilde: '\u00F1',5194ograve: '\u00F2',5195oacute: '\u00F3',5196ocirc: '\u00F4',5197otilde: '\u00F5',5198ouml: '\u00F6',5199divide: '\u00F7',5200oslash: '\u00F8',5201ugrave: '\u00F9',5202uacute: '\u00FA',5203ucirc: '\u00FB',5204uuml: '\u00FC',5205yacute: '\u00FD',5206thorn: '\u00FE',5207yuml: '\u00FF',5208OElig: '\u0152',5209oelig: '\u0153',5210Scaron: '\u0160',5211scaron: '\u0161',5212Yuml: '\u0178',5213fnof: '\u0192',5214circ: '\u02C6',5215tilde: '\u02DC',5216Alpha: '\u0391',5217Beta: '\u0392',5218Gamma: '\u0393',5219Delta: '\u0394',5220Epsilon: '\u0395',5221Zeta: '\u0396',5222Eta: '\u0397',5223Theta: '\u0398',5224Iota: '\u0399',5225Kappa: '\u039A',5226Lambda: '\u039B',5227Mu: '\u039C',5228Nu: '\u039D',5229Xi: '\u039E',5230Omicron: '\u039F',5231Pi: '\u03A0',5232Rho: '\u03A1',5233Sigma: '\u03A3',5234Tau: '\u03A4',5235Upsilon: '\u03A5',5236Phi: '\u03A6',5237Chi: '\u03A7',5238Psi: '\u03A8',5239Omega: '\u03A9',5240alpha: '\u03B1',5241beta: '\u03B2',5242gamma: '\u03B3',5243delta: '\u03B4',5244epsilon: '\u03B5',5245zeta: '\u03B6',5246eta: '\u03B7',5247theta: '\u03B8',5248iota: '\u03B9',5249kappa: '\u03BA',5250lambda: '\u03BB',5251mu: '\u03BC',5252nu: '\u03BD',5253xi: '\u03BE',5254omicron: '\u03BF',5255pi: '\u03C0',5256rho: '\u03C1',5257sigmaf: '\u03C2',5258sigma: '\u03C3',5259tau: '\u03C4',5260upsilon: '\u03C5',5261phi: '\u03C6',5262chi: '\u03C7',5263psi: '\u03C8',5264omega: '\u03C9',5265thetasym: '\u03D1',5266upsih: '\u03D2',5267piv: '\u03D6',5268ensp: '\u2002',5269emsp: '\u2003',5270thinsp: '\u2009',5271zwnj: '\u200C',5272zwj: '\u200D',5273lrm: '\u200E',5274rlm: '\u200F',5275ndash: '\u2013',5276mdash: '\u2014',5277lsquo: '\u2018',5278rsquo: '\u2019',5279sbquo: '\u201A',5280ldquo: '\u201C',5281rdquo: '\u201D',5282bdquo: '\u201E',5283dagger: '\u2020',5284Dagger: '\u2021',5285bull: '\u2022',5286hellip: '\u2026',5287permil: '\u2030',5288prime: '\u2032',5289Prime: '\u2033',5290lsaquo: '\u2039',5291rsaquo: '\u203A',5292oline: '\u203E',5293frasl: '\u2044',5294euro: '\u20AC',5295image: '\u2111',5296weierp: '\u2118',5297real: '\u211C',5298trade: '\u2122',5299alefsym: '\u2135',5300larr: '\u2190',5301uarr: '\u2191',5302rarr: '\u2192',5303darr: '\u2193',5304harr: '\u2194',5305crarr: '\u21B5',5306lArr: '\u21D0',5307uArr: '\u21D1',5308rArr: '\u21D2',5309dArr: '\u21D3',5310hArr: '\u21D4',5311forall: '\u2200',5312part: '\u2202',5313exist: '\u2203',5314empty: '\u2205',5315nabla: '\u2207',5316isin: '\u2208',5317notin: '\u2209',5318ni: '\u220B',5319prod: '\u220F',5320sum: '\u2211',5321minus: '\u2212',5322lowast: '\u2217',5323radic: '\u221A',5324prop: '\u221D',5325infin: '\u221E',5326ang: '\u2220',5327and: '\u2227',5328or: '\u2228',5329cap: '\u2229',5330cup: '\u222A',5331'int': '\u222B',5332there4: '\u2234',5333sim: '\u223C',5334cong: '\u2245',5335asymp: '\u2248',5336ne: '\u2260',5337equiv: '\u2261',5338le: '\u2264',5339ge: '\u2265',5340sub: '\u2282',5341sup: '\u2283',5342nsub: '\u2284',5343sube: '\u2286',5344supe: '\u2287',5345oplus: '\u2295',5346otimes: '\u2297',5347perp: '\u22A5',5348sdot: '\u22C5',5349lceil: '\u2308',5350rceil: '\u2309',5351lfloor: '\u230A',5352rfloor: '\u230B',5353lang: '\u2329',5354rang: '\u232A',5355loz: '\u25CA',5356spades: '\u2660',5357clubs: '\u2663',5358hearts: '\u2665',5359diams: '\u2666'5360};53615362function getQualifiedXJSName(object) {5363if (object.type === Syntax.XJSIdentifier) {5364return object.name;5365}5366if (object.type === Syntax.XJSNamespacedName) {5367return object.namespace.name + ':' + object.name.name;5368}5369if (object.type === Syntax.XJSMemberExpression) {5370return (5371getQualifiedXJSName(object.object) + '.' +5372getQualifiedXJSName(object.property)5373);5374}5375}53765377function isXJSIdentifierStart(ch) {5378// exclude backslash (\)5379return (ch !== 92) && isIdentifierStart(ch);5380}53815382function isXJSIdentifierPart(ch) {5383// exclude backslash (\) and add hyphen (-)5384return (ch !== 92) && (ch === 45 || isIdentifierPart(ch));5385}53865387function scanXJSIdentifier() {5388var ch, start, value = '';53895390start = index;5391while (index < length) {5392ch = source.charCodeAt(index);5393if (!isXJSIdentifierPart(ch)) {5394break;5395}5396value += source[index++];5397}53985399return {5400type: Token.XJSIdentifier,5401value: value,5402lineNumber: lineNumber,5403lineStart: lineStart,5404range: [start, index]5405};5406}54075408function scanXJSEntity() {5409var ch, str = '', count = 0, entity;5410ch = source[index];5411assert(ch === '&', 'Entity must start with an ampersand');5412index++;5413while (index < length && count++ < 10) {5414ch = source[index++];5415if (ch === ';') {5416break;5417}5418str += ch;5419}54205421if (str[0] === '#' && str[1] === 'x') {5422entity = String.fromCharCode(parseInt(str.substr(2), 16));5423} else if (str[0] === '#') {5424entity = String.fromCharCode(parseInt(str.substr(1), 10));5425} else {5426entity = XHTMLEntities[str];5427}5428return entity;5429}54305431function scanXJSText(stopChars) {5432var ch, str = '', start;5433start = index;5434while (index < length) {5435ch = source[index];5436if (stopChars.indexOf(ch) !== -1) {5437break;5438}5439if (ch === '&') {5440str += scanXJSEntity();5441} else {5442index++;5443if (isLineTerminator(ch.charCodeAt(0))) {5444++lineNumber;5445lineStart = index;5446}5447str += ch;5448}5449}5450return {5451type: Token.XJSText,5452value: str,5453lineNumber: lineNumber,5454lineStart: lineStart,5455range: [start, index]5456};5457}54585459function scanXJSStringLiteral() {5460var innerToken, quote, start;54615462quote = source[index];5463assert((quote === '\'' || quote === '"'),5464'String literal must starts with a quote');54655466start = index;5467++index;54685469innerToken = scanXJSText([quote]);54705471if (quote !== source[index]) {5472throwError({}, Messages.UnexpectedToken, 'ILLEGAL');5473}54745475++index;54765477innerToken.range = [start, index];54785479return innerToken;5480}54815482/**5483* Between XJS opening and closing tags (e.g. <foo>HERE</foo>), anything that5484* is not another XJS tag and is not an expression wrapped by {} is text.5485*/5486function advanceXJSChild() {5487var ch = source.charCodeAt(index);54885489// { (123) and < (60)5490if (ch !== 123 && ch !== 60) {5491return scanXJSText(['<', '{']);5492}54935494return scanPunctuator();5495}54965497function parseXJSIdentifier() {5498var token, marker = markerCreate();54995500if (lookahead.type !== Token.XJSIdentifier) {5501throwUnexpected(lookahead);5502}55035504token = lex();5505return markerApply(marker, delegate.createXJSIdentifier(token.value));5506}55075508function parseXJSNamespacedName() {5509var namespace, name, marker = markerCreate();55105511namespace = parseXJSIdentifier();5512expect(':');5513name = parseXJSIdentifier();55145515return markerApply(marker, delegate.createXJSNamespacedName(namespace, name));5516}55175518function parseXJSMemberExpression() {5519var marker = markerCreate(),5520expr = parseXJSIdentifier();55215522while (match('.')) {5523lex();5524expr = markerApply(marker, delegate.createXJSMemberExpression(expr, parseXJSIdentifier()));5525}55265527return expr;5528}55295530function parseXJSElementName() {5531if (lookahead2().value === ':') {5532return parseXJSNamespacedName();5533}5534if (lookahead2().value === '.') {5535return parseXJSMemberExpression();5536}55375538return parseXJSIdentifier();5539}55405541function parseXJSAttributeName() {5542if (lookahead2().value === ':') {5543return parseXJSNamespacedName();5544}55455546return parseXJSIdentifier();5547}55485549function parseXJSAttributeValue() {5550var value, marker;5551if (match('{')) {5552value = parseXJSExpressionContainer();5553if (value.expression.type === Syntax.XJSEmptyExpression) {5554throwError(5555value,5556'XJS attributes must only be assigned a non-empty ' +5557'expression'5558);5559}5560} else if (match('<')) {5561value = parseXJSElement();5562} else if (lookahead.type === Token.XJSText) {5563marker = markerCreate();5564value = markerApply(marker, delegate.createLiteral(lex()));5565} else {5566throwError({}, Messages.InvalidXJSAttributeValue);5567}5568return value;5569}55705571function parseXJSEmptyExpression() {5572var marker = markerCreatePreserveWhitespace();5573while (source.charAt(index) !== '}') {5574index++;5575}5576return markerApply(marker, delegate.createXJSEmptyExpression());5577}55785579function parseXJSExpressionContainer() {5580var expression, origInXJSChild, origInXJSTag, marker = markerCreate();55815582origInXJSChild = state.inXJSChild;5583origInXJSTag = state.inXJSTag;5584state.inXJSChild = false;5585state.inXJSTag = false;55865587expect('{');55885589if (match('}')) {5590expression = parseXJSEmptyExpression();5591} else {5592expression = parseExpression();5593}55945595state.inXJSChild = origInXJSChild;5596state.inXJSTag = origInXJSTag;55975598expect('}');55995600return markerApply(marker, delegate.createXJSExpressionContainer(expression));5601}56025603function parseXJSSpreadAttribute() {5604var expression, origInXJSChild, origInXJSTag, marker = markerCreate();56055606origInXJSChild = state.inXJSChild;5607origInXJSTag = state.inXJSTag;5608state.inXJSChild = false;5609state.inXJSTag = false;56105611expect('{');5612expect('...');56135614expression = parseAssignmentExpression();56155616state.inXJSChild = origInXJSChild;5617state.inXJSTag = origInXJSTag;56185619expect('}');56205621return markerApply(marker, delegate.createXJSSpreadAttribute(expression));5622}56235624function parseXJSAttribute() {5625var name, marker;56265627if (match('{')) {5628return parseXJSSpreadAttribute();5629}56305631marker = markerCreate();56325633name = parseXJSAttributeName();56345635// HTML empty attribute5636if (match('=')) {5637lex();5638return markerApply(marker, delegate.createXJSAttribute(name, parseXJSAttributeValue()));5639}56405641return markerApply(marker, delegate.createXJSAttribute(name));5642}56435644function parseXJSChild() {5645var token, marker;5646if (match('{')) {5647token = parseXJSExpressionContainer();5648} else if (lookahead.type === Token.XJSText) {5649marker = markerCreatePreserveWhitespace();5650token = markerApply(marker, delegate.createLiteral(lex()));5651} else {5652token = parseXJSElement();5653}5654return token;5655}56565657function parseXJSClosingElement() {5658var name, origInXJSChild, origInXJSTag, marker = markerCreate();5659origInXJSChild = state.inXJSChild;5660origInXJSTag = state.inXJSTag;5661state.inXJSChild = false;5662state.inXJSTag = true;5663expect('<');5664expect('/');5665name = parseXJSElementName();5666// Because advance() (called by lex() called by expect()) expects there5667// to be a valid token after >, it needs to know whether to look for a5668// standard JS token or an XJS text node5669state.inXJSChild = origInXJSChild;5670state.inXJSTag = origInXJSTag;5671expect('>');5672return markerApply(marker, delegate.createXJSClosingElement(name));5673}56745675function parseXJSOpeningElement() {5676var name, attribute, attributes = [], selfClosing = false, origInXJSChild, origInXJSTag, marker = markerCreate();56775678origInXJSChild = state.inXJSChild;5679origInXJSTag = state.inXJSTag;5680state.inXJSChild = false;5681state.inXJSTag = true;56825683expect('<');56845685name = parseXJSElementName();56865687while (index < length &&5688lookahead.value !== '/' &&5689lookahead.value !== '>') {5690attributes.push(parseXJSAttribute());5691}56925693state.inXJSTag = origInXJSTag;56945695if (lookahead.value === '/') {5696expect('/');5697// Because advance() (called by lex() called by expect()) expects5698// there to be a valid token after >, it needs to know whether to5699// look for a standard JS token or an XJS text node5700state.inXJSChild = origInXJSChild;5701expect('>');5702selfClosing = true;5703} else {5704state.inXJSChild = true;5705expect('>');5706}5707return markerApply(marker, delegate.createXJSOpeningElement(name, attributes, selfClosing));5708}57095710function parseXJSElement() {5711var openingElement, closingElement, children = [], origInXJSChild, origInXJSTag, marker = markerCreate();57125713origInXJSChild = state.inXJSChild;5714origInXJSTag = state.inXJSTag;5715openingElement = parseXJSOpeningElement();57165717if (!openingElement.selfClosing) {5718while (index < length) {5719state.inXJSChild = false; // Call lookahead2() with inXJSChild = false because </ should not be considered in the child5720if (lookahead.value === '<' && lookahead2().value === '/') {5721break;5722}5723state.inXJSChild = true;5724children.push(parseXJSChild());5725}5726state.inXJSChild = origInXJSChild;5727state.inXJSTag = origInXJSTag;5728closingElement = parseXJSClosingElement();5729if (getQualifiedXJSName(closingElement.name) !== getQualifiedXJSName(openingElement.name)) {5730throwError({}, Messages.ExpectedXJSClosingTag, getQualifiedXJSName(openingElement.name));5731}5732}57335734// When (erroneously) writing two adjacent tags like5735//5736// var x = <div>one</div><div>two</div>;5737//5738// the default error message is a bit incomprehensible. Since it's5739// rarely (never?) useful to write a less-than sign after an XJS5740// element, we disallow it here in the parser in order to provide a5741// better error message. (In the rare case that the less-than operator5742// was intended, the left tag can be wrapped in parentheses.)5743if (!origInXJSChild && match('<')) {5744throwError(lookahead, Messages.AdjacentXJSElements);5745}57465747return markerApply(marker, delegate.createXJSElement(openingElement, closingElement, children));5748}57495750function collectToken() {5751var start, loc, token, range, value;57525753if (!state.inXJSChild) {5754skipComment();5755}57565757start = index;5758loc = {5759start: {5760line: lineNumber,5761column: index - lineStart5762}5763};57645765token = extra.advance();5766loc.end = {5767line: lineNumber,5768column: index - lineStart5769};57705771if (token.type !== Token.EOF) {5772range = [token.range[0], token.range[1]];5773value = source.slice(token.range[0], token.range[1]);5774extra.tokens.push({5775type: TokenName[token.type],5776value: value,5777range: range,5778loc: loc5779});5780}57815782return token;5783}57845785function collectRegex() {5786var pos, loc, regex, token;57875788skipComment();57895790pos = index;5791loc = {5792start: {5793line: lineNumber,5794column: index - lineStart5795}5796};57975798regex = extra.scanRegExp();5799loc.end = {5800line: lineNumber,5801column: index - lineStart5802};58035804if (!extra.tokenize) {5805// Pop the previous token, which is likely '/' or '/='5806if (extra.tokens.length > 0) {5807token = extra.tokens[extra.tokens.length - 1];5808if (token.range[0] === pos && token.type === 'Punctuator') {5809if (token.value === '/' || token.value === '/=') {5810extra.tokens.pop();5811}5812}5813}58145815extra.tokens.push({5816type: 'RegularExpression',5817value: regex.literal,5818range: [pos, index],5819loc: loc5820});5821}58225823return regex;5824}58255826function filterTokenLocation() {5827var i, entry, token, tokens = [];58285829for (i = 0; i < extra.tokens.length; ++i) {5830entry = extra.tokens[i];5831token = {5832type: entry.type,5833value: entry.value5834};5835if (extra.range) {5836token.range = entry.range;5837}5838if (extra.loc) {5839token.loc = entry.loc;5840}5841tokens.push(token);5842}58435844extra.tokens = tokens;5845}58465847function patch() {5848if (extra.comments) {5849extra.skipComment = skipComment;5850skipComment = scanComment;5851}58525853if (typeof extra.tokens !== 'undefined') {5854extra.advance = advance;5855extra.scanRegExp = scanRegExp;58565857advance = collectToken;5858scanRegExp = collectRegex;5859}5860}58615862function unpatch() {5863if (typeof extra.skipComment === 'function') {5864skipComment = extra.skipComment;5865}58665867if (typeof extra.scanRegExp === 'function') {5868advance = extra.advance;5869scanRegExp = extra.scanRegExp;5870}5871}58725873// This is used to modify the delegate.58745875function extend(object, properties) {5876var entry, result = {};58775878for (entry in object) {5879if (object.hasOwnProperty(entry)) {5880result[entry] = object[entry];5881}5882}58835884for (entry in properties) {5885if (properties.hasOwnProperty(entry)) {5886result[entry] = properties[entry];5887}5888}58895890return result;5891}58925893function tokenize(code, options) {5894var toString,5895token,5896tokens;58975898toString = String;5899if (typeof code !== 'string' && !(code instanceof String)) {5900code = toString(code);5901}59025903delegate = SyntaxTreeDelegate;5904source = code;5905index = 0;5906lineNumber = (source.length > 0) ? 1 : 0;5907lineStart = 0;5908length = source.length;5909lookahead = null;5910state = {5911allowKeyword: true,5912allowIn: true,5913labelSet: {},5914inFunctionBody: false,5915inIteration: false,5916inSwitch: false,5917lastCommentStart: -15918};59195920extra = {};59215922// Options matching.5923options = options || {};59245925// Of course we collect tokens here.5926options.tokens = true;5927extra.tokens = [];5928extra.tokenize = true;5929// The following two fields are necessary to compute the Regex tokens.5930extra.openParenToken = -1;5931extra.openCurlyToken = -1;59325933extra.range = (typeof options.range === 'boolean') && options.range;5934extra.loc = (typeof options.loc === 'boolean') && options.loc;59355936if (typeof options.comment === 'boolean' && options.comment) {5937extra.comments = [];5938}5939if (typeof options.tolerant === 'boolean' && options.tolerant) {5940extra.errors = [];5941}59425943if (length > 0) {5944if (typeof source[0] === 'undefined') {5945// Try first to convert to a string. This is good as fast path5946// for old IE which understands string indexing for string5947// literals only and not for string object.5948if (code instanceof String) {5949source = code.valueOf();5950}5951}5952}59535954patch();59555956try {5957peek();5958if (lookahead.type === Token.EOF) {5959return extra.tokens;5960}59615962token = lex();5963while (lookahead.type !== Token.EOF) {5964try {5965token = lex();5966} catch (lexError) {5967token = lookahead;5968if (extra.errors) {5969extra.errors.push(lexError);5970// We have to break on the first error5971// to avoid infinite loops.5972break;5973} else {5974throw lexError;5975}5976}5977}59785979filterTokenLocation();5980tokens = extra.tokens;5981if (typeof extra.comments !== 'undefined') {5982tokens.comments = extra.comments;5983}5984if (typeof extra.errors !== 'undefined') {5985tokens.errors = extra.errors;5986}5987} catch (e) {5988throw e;5989} finally {5990unpatch();5991extra = {};5992}5993return tokens;5994}59955996function parse(code, options) {5997var program, toString;59985999toString = String;6000if (typeof code !== 'string' && !(code instanceof String)) {6001code = toString(code);6002}60036004delegate = SyntaxTreeDelegate;6005source = code;6006index = 0;6007lineNumber = (source.length > 0) ? 1 : 0;6008lineStart = 0;6009length = source.length;6010lookahead = null;6011state = {6012allowKeyword: false,6013allowIn: true,6014labelSet: {},6015parenthesizedCount: 0,6016inFunctionBody: false,6017inIteration: false,6018inSwitch: false,6019inXJSChild: false,6020inXJSTag: false,6021lastCommentStart: -1,6022yieldAllowed: false6023};60246025extra = {};6026if (typeof options !== 'undefined') {6027extra.range = (typeof options.range === 'boolean') && options.range;6028extra.loc = (typeof options.loc === 'boolean') && options.loc;60296030if (extra.loc && options.source !== null && options.source !== undefined) {6031delegate = extend(delegate, {6032'postProcess': function (node) {6033node.loc.source = toString(options.source);6034return node;6035}6036});6037}60386039if (typeof options.tokens === 'boolean' && options.tokens) {6040extra.tokens = [];6041}6042if (typeof options.comment === 'boolean' && options.comment) {6043extra.comments = [];6044}6045if (typeof options.tolerant === 'boolean' && options.tolerant) {6046extra.errors = [];6047}6048}60496050if (length > 0) {6051if (typeof source[0] === 'undefined') {6052// Try first to convert to a string. This is good as fast path6053// for old IE which understands string indexing for string6054// literals only and not for string object.6055if (code instanceof String) {6056source = code.valueOf();6057}6058}6059}60606061patch();6062try {6063program = parseProgram();6064if (typeof extra.comments !== 'undefined') {6065program.comments = extra.comments;6066}6067if (typeof extra.tokens !== 'undefined') {6068filterTokenLocation();6069program.tokens = extra.tokens;6070}6071if (typeof extra.errors !== 'undefined') {6072program.errors = extra.errors;6073}6074} catch (e) {6075throw e;6076} finally {6077unpatch();6078extra = {};6079}60806081return program;6082}60836084// Sync with *.json manifests.6085exports.version = '4001.1001.0000-dev-harmony-fb';60866087exports.tokenize = tokenize;60886089exports.parse = parse;60906091// Deep copy.6092exports.Syntax = (function () {6093var name, types = {};60946095if (typeof Object.create === 'function') {6096types = Object.create(null);6097}60986099for (name in Syntax) {6100if (Syntax.hasOwnProperty(name)) {6101types[name] = Syntax[name];6102}6103}61046105if (typeof Object.freeze === 'function') {6106Object.freeze(types);6107}61086109return types;6110}());61116112}));6113/* vim: set sw=4 ts=4 et tw=80 : */611461156116