react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / node_modules / commoner / node_modules / recast / node_modules / esprima-fb / esprima.js
81174 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,34throwErrorTolerant: true,35throwError: true, generateStatement: true, peek: true,36parseAssignmentExpression: true, parseBlock: true,37parseClassExpression: true, parseClassDeclaration: true, parseExpression: true,38parseDeclareClass: true, parseDeclareFunction: true,39parseDeclareModule: true, parseDeclareVariable: true,40parseForStatement: true,41parseFunctionDeclaration: true, parseFunctionExpression: true,42parseFunctionSourceElements: true, parseVariableIdentifier: true,43parseImportSpecifier: true, parseInterface: true,44parseLeftHandSideExpression: true, parseParams: true, validateParam: true,45parseSpreadOrAssignmentExpression: true,46parseStatement: true, parseSourceElement: true, parseConciseBody: true,47advanceXJSChild: true, isXJSIdentifierStart: true, isXJSIdentifierPart: true,48scanXJSStringLiteral: true, scanXJSIdentifier: true,49parseXJSAttributeValue: true, parseXJSChild: true, parseXJSElement: true, parseXJSExpressionContainer: true, parseXJSEmptyExpression: true,50parseFunctionTypeParam: true,51parsePrimaryType: true,52parseTypeAlias: true,53parseType: true, parseTypeAnnotatableIdentifier: true, parseTypeAnnotation: true,54parseTypeParameterDeclaration: true,55parseYieldExpression: true, parseAwaitExpression: true56*/5758(function (root, factory) {59'use strict';6061// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,62// Rhino, and plain browser loading.6364/* istanbul ignore next */65if (typeof define === 'function' && define.amd) {66define(['exports'], factory);67} else if (typeof exports !== 'undefined') {68factory(exports);69} else {70factory((root.esprima = {}));71}72}(this, function (exports) {73'use strict';7475var Token,76TokenName,77FnExprTokens,78Syntax,79PropertyKind,80Messages,81Regex,82SyntaxTreeDelegate,83XHTMLEntities,84ClassPropertyType,85source,86strict,87index,88lineNumber,89lineStart,90length,91delegate,92lookahead,93state,94extra;9596Token = {97BooleanLiteral: 1,98EOF: 2,99Identifier: 3,100Keyword: 4,101NullLiteral: 5,102NumericLiteral: 6,103Punctuator: 7,104StringLiteral: 8,105RegularExpression: 9,106Template: 10,107XJSIdentifier: 11,108XJSText: 12109};110111TokenName = {};112TokenName[Token.BooleanLiteral] = 'Boolean';113TokenName[Token.EOF] = '<end>';114TokenName[Token.Identifier] = 'Identifier';115TokenName[Token.Keyword] = 'Keyword';116TokenName[Token.NullLiteral] = 'Null';117TokenName[Token.NumericLiteral] = 'Numeric';118TokenName[Token.Punctuator] = 'Punctuator';119TokenName[Token.StringLiteral] = 'String';120TokenName[Token.XJSIdentifier] = 'XJSIdentifier';121TokenName[Token.XJSText] = 'XJSText';122TokenName[Token.RegularExpression] = 'RegularExpression';123124// A function following one of those tokens is an expression.125FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',126'return', 'case', 'delete', 'throw', 'void',127// assignment operators128'=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',129'&=', '|=', '^=', ',',130// binary/unary operators131'+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',132'|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',133'<=', '<', '>', '!=', '!=='];134135Syntax = {136AnyTypeAnnotation: 'AnyTypeAnnotation',137ArrayExpression: 'ArrayExpression',138ArrayPattern: 'ArrayPattern',139ArrayTypeAnnotation: 'ArrayTypeAnnotation',140ArrowFunctionExpression: 'ArrowFunctionExpression',141AssignmentExpression: 'AssignmentExpression',142BinaryExpression: 'BinaryExpression',143BlockStatement: 'BlockStatement',144BooleanTypeAnnotation: 'BooleanTypeAnnotation',145BreakStatement: 'BreakStatement',146CallExpression: 'CallExpression',147CatchClause: 'CatchClause',148ClassBody: 'ClassBody',149ClassDeclaration: 'ClassDeclaration',150ClassExpression: 'ClassExpression',151ClassImplements: 'ClassImplements',152ClassProperty: 'ClassProperty',153ComprehensionBlock: 'ComprehensionBlock',154ComprehensionExpression: 'ComprehensionExpression',155ConditionalExpression: 'ConditionalExpression',156ContinueStatement: 'ContinueStatement',157DebuggerStatement: 'DebuggerStatement',158DeclareClass: 'DeclareClass',159DeclareFunction: 'DeclareFunction',160DeclareModule: 'DeclareModule',161DeclareVariable: 'DeclareVariable',162DoWhileStatement: 'DoWhileStatement',163EmptyStatement: 'EmptyStatement',164ExportDeclaration: 'ExportDeclaration',165ExportBatchSpecifier: 'ExportBatchSpecifier',166ExportSpecifier: 'ExportSpecifier',167ExpressionStatement: 'ExpressionStatement',168ForInStatement: 'ForInStatement',169ForOfStatement: 'ForOfStatement',170ForStatement: 'ForStatement',171FunctionDeclaration: 'FunctionDeclaration',172FunctionExpression: 'FunctionExpression',173FunctionTypeAnnotation: 'FunctionTypeAnnotation',174FunctionTypeParam: 'FunctionTypeParam',175GenericTypeAnnotation: 'GenericTypeAnnotation',176Identifier: 'Identifier',177IfStatement: 'IfStatement',178ImportDeclaration: 'ImportDeclaration',179ImportDefaultSpecifier: 'ImportDefaultSpecifier',180ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',181ImportSpecifier: 'ImportSpecifier',182InterfaceDeclaration: 'InterfaceDeclaration',183InterfaceExtends: 'InterfaceExtends',184IntersectionTypeAnnotation: 'IntersectionTypeAnnotation',185LabeledStatement: 'LabeledStatement',186Literal: 'Literal',187LogicalExpression: 'LogicalExpression',188MemberExpression: 'MemberExpression',189MethodDefinition: 'MethodDefinition',190ModuleSpecifier: 'ModuleSpecifier',191NewExpression: 'NewExpression',192NullableTypeAnnotation: 'NullableTypeAnnotation',193NumberTypeAnnotation: 'NumberTypeAnnotation',194ObjectExpression: 'ObjectExpression',195ObjectPattern: 'ObjectPattern',196ObjectTypeAnnotation: 'ObjectTypeAnnotation',197ObjectTypeCallProperty: 'ObjectTypeCallProperty',198ObjectTypeIndexer: 'ObjectTypeIndexer',199ObjectTypeProperty: 'ObjectTypeProperty',200Program: 'Program',201Property: 'Property',202QualifiedTypeIdentifier: 'QualifiedTypeIdentifier',203ReturnStatement: 'ReturnStatement',204SequenceExpression: 'SequenceExpression',205SpreadElement: 'SpreadElement',206SpreadProperty: 'SpreadProperty',207StringLiteralTypeAnnotation: 'StringLiteralTypeAnnotation',208StringTypeAnnotation: 'StringTypeAnnotation',209SwitchCase: 'SwitchCase',210SwitchStatement: 'SwitchStatement',211TaggedTemplateExpression: 'TaggedTemplateExpression',212TemplateElement: 'TemplateElement',213TemplateLiteral: 'TemplateLiteral',214ThisExpression: 'ThisExpression',215ThrowStatement: 'ThrowStatement',216TupleTypeAnnotation: 'TupleTypeAnnotation',217TryStatement: 'TryStatement',218TypeAlias: 'TypeAlias',219TypeAnnotation: 'TypeAnnotation',220TypeofTypeAnnotation: 'TypeofTypeAnnotation',221TypeParameterDeclaration: 'TypeParameterDeclaration',222TypeParameterInstantiation: 'TypeParameterInstantiation',223UnaryExpression: 'UnaryExpression',224UnionTypeAnnotation: 'UnionTypeAnnotation',225UpdateExpression: 'UpdateExpression',226VariableDeclaration: 'VariableDeclaration',227VariableDeclarator: 'VariableDeclarator',228VoidTypeAnnotation: 'VoidTypeAnnotation',229WhileStatement: 'WhileStatement',230WithStatement: 'WithStatement',231XJSIdentifier: 'XJSIdentifier',232XJSNamespacedName: 'XJSNamespacedName',233XJSMemberExpression: 'XJSMemberExpression',234XJSEmptyExpression: 'XJSEmptyExpression',235XJSExpressionContainer: 'XJSExpressionContainer',236XJSElement: 'XJSElement',237XJSClosingElement: 'XJSClosingElement',238XJSOpeningElement: 'XJSOpeningElement',239XJSAttribute: 'XJSAttribute',240XJSSpreadAttribute: 'XJSSpreadAttribute',241XJSText: 'XJSText',242YieldExpression: 'YieldExpression',243AwaitExpression: 'AwaitExpression'244};245246PropertyKind = {247Data: 1,248Get: 2,249Set: 4250};251252ClassPropertyType = {253'static': 'static',254prototype: 'prototype'255};256257// Error messages should be identical to V8.258Messages = {259UnexpectedToken: 'Unexpected token %0',260UnexpectedNumber: 'Unexpected number',261UnexpectedString: 'Unexpected string',262UnexpectedIdentifier: 'Unexpected identifier',263UnexpectedReserved: 'Unexpected reserved word',264UnexpectedTemplate: 'Unexpected quasi %0',265UnexpectedEOS: 'Unexpected end of input',266NewlineAfterThrow: 'Illegal newline after throw',267InvalidRegExp: 'Invalid regular expression',268UnterminatedRegExp: 'Invalid regular expression: missing /',269InvalidLHSInAssignment: 'Invalid left-hand side in assignment',270InvalidLHSInFormalsList: 'Invalid left-hand side in formals list',271InvalidLHSInForIn: 'Invalid left-hand side in for-in',272MultipleDefaultsInSwitch: 'More than one default clause in switch statement',273NoCatchOrFinally: 'Missing catch or finally after try',274UnknownLabel: 'Undefined label \'%0\'',275Redeclaration: '%0 \'%1\' has already been declared',276IllegalContinue: 'Illegal continue statement',277IllegalBreak: 'Illegal break statement',278IllegalDuplicateClassProperty: 'Illegal duplicate property in class definition',279IllegalReturn: 'Illegal return statement',280IllegalSpread: 'Illegal spread element',281StrictModeWith: 'Strict mode code may not include a with statement',282StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',283StrictVarName: 'Variable name may not be eval or arguments in strict mode',284StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',285StrictParamDupe: 'Strict mode function may not have duplicate parameter names',286ParameterAfterRestParameter: 'Rest parameter must be final parameter of an argument list',287DefaultRestParameter: 'Rest parameter can not have a default value',288ElementAfterSpreadElement: 'Spread must be the final element of an element list',289PropertyAfterSpreadProperty: 'A rest property must be the final property of an object literal',290ObjectPatternAsRestParameter: 'Invalid rest parameter',291ObjectPatternAsSpread: 'Invalid spread argument',292StrictFunctionName: 'Function name may not be eval or arguments in strict mode',293StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',294StrictDelete: 'Delete of an unqualified identifier in strict mode.',295StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',296AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',297AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',298StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',299StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',300StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',301StrictReservedWord: 'Use of future reserved word in strict mode',302MissingFromClause: 'Missing from clause',303NoAsAfterImportNamespace: 'Missing as after import *',304InvalidModuleSpecifier: 'Invalid module specifier',305IllegalImportDeclaration: 'Illegal import declaration',306IllegalExportDeclaration: 'Illegal export declaration',307NoUnintializedConst: 'Const must be initialized',308ComprehensionRequiresBlock: 'Comprehension must have at least one block',309ComprehensionError: 'Comprehension Error',310EachNotAllowed: 'Each is not supported',311InvalidXJSAttributeValue: 'XJS value should be either an expression or a quoted XJS text',312ExpectedXJSClosingTag: 'Expected corresponding XJS closing tag for %0',313AdjacentXJSElements: 'Adjacent XJS elements must be wrapped in an enclosing tag',314ConfusedAboutFunctionType: 'Unexpected token =>. It looks like ' +315'you are trying to write a function type, but you ended up ' +316'writing a grouped type followed by an =>, which is a syntax ' +317'error. Remember, function type parameters are named so function ' +318'types look like (name1: type1, name2: type2) => returnType. You ' +319'probably wrote (type1) => returnType'320};321322// See also tools/generate-unicode-regex.py.323Regex = {324NonAsciiIdentifierStart: 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]'),325NonAsciiIdentifierPart: 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]'),326LeadingZeros: new RegExp('^0+(?!$)')327};328329// Ensure the condition is true, otherwise throw an error.330// This is only to have a better contract semantic, i.e. another safety net331// to catch a logic error. The condition shall be fulfilled in normal case.332// Do NOT use this to enforce a certain condition on any user input.333334function assert(condition, message) {335/* istanbul ignore if */336if (!condition) {337throw new Error('ASSERT: ' + message);338}339}340341function StringMap() {342this.$data = {};343}344345StringMap.prototype.get = function (key) {346key = '$' + key;347return this.$data[key];348};349350StringMap.prototype.set = function (key, value) {351key = '$' + key;352this.$data[key] = value;353return this;354};355356StringMap.prototype.has = function (key) {357key = '$' + key;358return Object.prototype.hasOwnProperty.call(this.$data, key);359};360361StringMap.prototype['delete'] = function (key) {362key = '$' + key;363return delete this.$data[key];364};365366function isDecimalDigit(ch) {367return (ch >= 48 && ch <= 57); // 0..9368}369370function isHexDigit(ch) {371return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;372}373374function isOctalDigit(ch) {375return '01234567'.indexOf(ch) >= 0;376}377378379// 7.2 White Space380381function isWhiteSpace(ch) {382return (ch === 32) || // space383(ch === 9) || // tab384(ch === 0xB) ||385(ch === 0xC) ||386(ch === 0xA0) ||387(ch >= 0x1680 && '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'.indexOf(String.fromCharCode(ch)) > 0);388}389390// 7.3 Line Terminators391392function isLineTerminator(ch) {393return (ch === 10) || (ch === 13) || (ch === 0x2028) || (ch === 0x2029);394}395396// 7.6 Identifier Names and Identifiers397398function isIdentifierStart(ch) {399return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)400(ch >= 65 && ch <= 90) || // A..Z401(ch >= 97 && ch <= 122) || // a..z402(ch === 92) || // \ (backslash)403((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));404}405406function isIdentifierPart(ch) {407return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)408(ch >= 65 && ch <= 90) || // A..Z409(ch >= 97 && ch <= 122) || // a..z410(ch >= 48 && ch <= 57) || // 0..9411(ch === 92) || // \ (backslash)412((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));413}414415// 7.6.1.2 Future Reserved Words416417function isFutureReservedWord(id) {418switch (id) {419case 'class':420case 'enum':421case 'export':422case 'extends':423case 'import':424case 'super':425return true;426default:427return false;428}429}430431function isStrictModeReservedWord(id) {432switch (id) {433case 'implements':434case 'interface':435case 'package':436case 'private':437case 'protected':438case 'public':439case 'static':440case 'yield':441case 'let':442return true;443default:444return false;445}446}447448function isRestrictedWord(id) {449return id === 'eval' || id === 'arguments';450}451452// 7.6.1.1 Keywords453454function isKeyword(id) {455if (strict && isStrictModeReservedWord(id)) {456return true;457}458459// 'const' is specialized as Keyword in V8.460// 'yield' is only treated as a keyword in strict mode.461// 'let' is for compatiblity with SpiderMonkey and ES.next.462// Some others are from future reserved words.463464switch (id.length) {465case 2:466return (id === 'if') || (id === 'in') || (id === 'do');467case 3:468return (id === 'var') || (id === 'for') || (id === 'new') ||469(id === 'try') || (id === 'let');470case 4:471return (id === 'this') || (id === 'else') || (id === 'case') ||472(id === 'void') || (id === 'with') || (id === 'enum');473case 5:474return (id === 'while') || (id === 'break') || (id === 'catch') ||475(id === 'throw') || (id === 'const') ||476(id === 'class') || (id === 'super');477case 6:478return (id === 'return') || (id === 'typeof') || (id === 'delete') ||479(id === 'switch') || (id === 'export') || (id === 'import');480case 7:481return (id === 'default') || (id === 'finally') || (id === 'extends');482case 8:483return (id === 'function') || (id === 'continue') || (id === 'debugger');484case 10:485return (id === 'instanceof');486default:487return false;488}489}490491// 7.4 Comments492493function skipComment() {494var ch, blockComment, lineComment;495496blockComment = false;497lineComment = false;498499while (index < length) {500ch = source.charCodeAt(index);501502if (lineComment) {503++index;504if (isLineTerminator(ch)) {505lineComment = false;506if (ch === 13 && source.charCodeAt(index) === 10) {507++index;508}509++lineNumber;510lineStart = index;511}512} else if (blockComment) {513if (isLineTerminator(ch)) {514if (ch === 13) {515++index;516}517if (ch !== 13 || source.charCodeAt(index) === 10) {518++lineNumber;519++index;520lineStart = index;521if (index >= length) {522throwError({}, Messages.UnexpectedToken, 'ILLEGAL');523}524}525} else {526ch = source.charCodeAt(index++);527if (index >= length) {528throwError({}, Messages.UnexpectedToken, 'ILLEGAL');529}530// Block comment ends with '*/' (char #42, char #47).531if (ch === 42) {532ch = source.charCodeAt(index);533if (ch === 47) {534++index;535blockComment = false;536}537}538}539} else if (ch === 47) {540ch = source.charCodeAt(index + 1);541// Line comment starts with '//' (char #47, char #47).542if (ch === 47) {543index += 2;544lineComment = true;545} else if (ch === 42) {546// Block comment starts with '/*' (char #47, char #42).547index += 2;548blockComment = true;549if (index >= length) {550throwError({}, Messages.UnexpectedToken, 'ILLEGAL');551}552} else {553break;554}555} else if (isWhiteSpace(ch)) {556++index;557} else if (isLineTerminator(ch)) {558++index;559if (ch === 13 && source.charCodeAt(index) === 10) {560++index;561}562++lineNumber;563lineStart = index;564} else {565break;566}567}568}569570function scanHexEscape(prefix) {571var i, len, ch, code = 0;572573len = (prefix === 'u') ? 4 : 2;574for (i = 0; i < len; ++i) {575if (index < length && isHexDigit(source[index])) {576ch = source[index++];577code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());578} else {579return '';580}581}582return String.fromCharCode(code);583}584585function scanUnicodeCodePointEscape() {586var ch, code, cu1, cu2;587588ch = source[index];589code = 0;590591// At least, one hex digit is required.592if (ch === '}') {593throwError({}, Messages.UnexpectedToken, 'ILLEGAL');594}595596while (index < length) {597ch = source[index++];598if (!isHexDigit(ch)) {599break;600}601code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());602}603604if (code > 0x10FFFF || ch !== '}') {605throwError({}, Messages.UnexpectedToken, 'ILLEGAL');606}607608// UTF-16 Encoding609if (code <= 0xFFFF) {610return String.fromCharCode(code);611}612cu1 = ((code - 0x10000) >> 10) + 0xD800;613cu2 = ((code - 0x10000) & 1023) + 0xDC00;614return String.fromCharCode(cu1, cu2);615}616617function getEscapedIdentifier() {618var ch, id;619620ch = source.charCodeAt(index++);621id = String.fromCharCode(ch);622623// '\u' (char #92, char #117) denotes an escaped character.624if (ch === 92) {625if (source.charCodeAt(index) !== 117) {626throwError({}, Messages.UnexpectedToken, 'ILLEGAL');627}628++index;629ch = scanHexEscape('u');630if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {631throwError({}, Messages.UnexpectedToken, 'ILLEGAL');632}633id = ch;634}635636while (index < length) {637ch = source.charCodeAt(index);638if (!isIdentifierPart(ch)) {639break;640}641++index;642id += String.fromCharCode(ch);643644// '\u' (char #92, char #117) denotes an escaped character.645if (ch === 92) {646id = id.substr(0, id.length - 1);647if (source.charCodeAt(index) !== 117) {648throwError({}, Messages.UnexpectedToken, 'ILLEGAL');649}650++index;651ch = scanHexEscape('u');652if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {653throwError({}, Messages.UnexpectedToken, 'ILLEGAL');654}655id += ch;656}657}658659return id;660}661662function getIdentifier() {663var start, ch;664665start = index++;666while (index < length) {667ch = source.charCodeAt(index);668if (ch === 92) {669// Blackslash (char #92) marks Unicode escape sequence.670index = start;671return getEscapedIdentifier();672}673if (isIdentifierPart(ch)) {674++index;675} else {676break;677}678}679680return source.slice(start, index);681}682683function scanIdentifier() {684var start, id, type;685686start = index;687688// Backslash (char #92) starts an escaped character.689id = (source.charCodeAt(index) === 92) ? getEscapedIdentifier() : getIdentifier();690691// There is no keyword or literal with only one character.692// Thus, it must be an identifier.693if (id.length === 1) {694type = Token.Identifier;695} else if (isKeyword(id)) {696type = Token.Keyword;697} else if (id === 'null') {698type = Token.NullLiteral;699} else if (id === 'true' || id === 'false') {700type = Token.BooleanLiteral;701} else {702type = Token.Identifier;703}704705return {706type: type,707value: id,708lineNumber: lineNumber,709lineStart: lineStart,710range: [start, index]711};712}713714715// 7.7 Punctuators716717function scanPunctuator() {718var start = index,719code = source.charCodeAt(index),720code2,721ch1 = source[index],722ch2,723ch3,724ch4;725726switch (code) {727// Check for most common single-character punctuators.728case 40: // ( open bracket729case 41: // ) close bracket730case 59: // ; semicolon731case 44: // , comma732case 123: // { open curly brace733case 125: // } close curly brace734case 91: // [735case 93: // ]736case 58: // :737case 63: // ?738case 126: // ~739++index;740if (extra.tokenize) {741if (code === 40) {742extra.openParenToken = extra.tokens.length;743} else if (code === 123) {744extra.openCurlyToken = extra.tokens.length;745}746}747return {748type: Token.Punctuator,749value: String.fromCharCode(code),750lineNumber: lineNumber,751lineStart: lineStart,752range: [start, index]753};754755default:756code2 = source.charCodeAt(index + 1);757758// '=' (char #61) marks an assignment or comparison operator.759if (code2 === 61) {760switch (code) {761case 37: // %762case 38: // &763case 42: // *:764case 43: // +765case 45: // -766case 47: // /767case 60: // <768case 62: // >769case 94: // ^770case 124: // |771index += 2;772return {773type: Token.Punctuator,774value: String.fromCharCode(code) + String.fromCharCode(code2),775lineNumber: lineNumber,776lineStart: lineStart,777range: [start, index]778};779780case 33: // !781case 61: // =782index += 2;783784// !== and ===785if (source.charCodeAt(index) === 61) {786++index;787}788return {789type: Token.Punctuator,790value: source.slice(start, index),791lineNumber: lineNumber,792lineStart: lineStart,793range: [start, index]794};795default:796break;797}798}799break;800}801802// Peek more characters.803804ch2 = source[index + 1];805ch3 = source[index + 2];806ch4 = source[index + 3];807808// 4-character punctuator: >>>=809810if (ch1 === '>' && ch2 === '>' && ch3 === '>') {811if (ch4 === '=') {812index += 4;813return {814type: Token.Punctuator,815value: '>>>=',816lineNumber: lineNumber,817lineStart: lineStart,818range: [start, index]819};820}821}822823// 3-character punctuators: === !== >>> <<= >>=824825if (ch1 === '>' && ch2 === '>' && ch3 === '>') {826index += 3;827return {828type: Token.Punctuator,829value: '>>>',830lineNumber: lineNumber,831lineStart: lineStart,832range: [start, index]833};834}835836if (ch1 === '<' && ch2 === '<' && ch3 === '=') {837index += 3;838return {839type: Token.Punctuator,840value: '<<=',841lineNumber: lineNumber,842lineStart: lineStart,843range: [start, index]844};845}846847if (ch1 === '>' && ch2 === '>' && ch3 === '=') {848index += 3;849return {850type: Token.Punctuator,851value: '>>=',852lineNumber: lineNumber,853lineStart: lineStart,854range: [start, index]855};856}857858if (ch1 === '.' && ch2 === '.' && ch3 === '.') {859index += 3;860return {861type: Token.Punctuator,862value: '...',863lineNumber: lineNumber,864lineStart: lineStart,865range: [start, index]866};867}868869// Other 2-character punctuators: ++ -- << >> && ||870871// Don't match these tokens if we're in a type, since they never can872// occur and can mess up types like Map<string, Array<string>>873if (ch1 === ch2 && ('+-<>&|'.indexOf(ch1) >= 0) && !state.inType) {874index += 2;875return {876type: Token.Punctuator,877value: ch1 + ch2,878lineNumber: lineNumber,879lineStart: lineStart,880range: [start, index]881};882}883884if (ch1 === '=' && ch2 === '>') {885index += 2;886return {887type: Token.Punctuator,888value: '=>',889lineNumber: lineNumber,890lineStart: lineStart,891range: [start, index]892};893}894895if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {896++index;897return {898type: Token.Punctuator,899value: ch1,900lineNumber: lineNumber,901lineStart: lineStart,902range: [start, index]903};904}905906if (ch1 === '.') {907++index;908return {909type: Token.Punctuator,910value: ch1,911lineNumber: lineNumber,912lineStart: lineStart,913range: [start, index]914};915}916917throwError({}, Messages.UnexpectedToken, 'ILLEGAL');918}919920// 7.8.3 Numeric Literals921922function scanHexLiteral(start) {923var number = '';924925while (index < length) {926if (!isHexDigit(source[index])) {927break;928}929number += source[index++];930}931932if (number.length === 0) {933throwError({}, Messages.UnexpectedToken, 'ILLEGAL');934}935936if (isIdentifierStart(source.charCodeAt(index))) {937throwError({}, Messages.UnexpectedToken, 'ILLEGAL');938}939940return {941type: Token.NumericLiteral,942value: parseInt('0x' + number, 16),943lineNumber: lineNumber,944lineStart: lineStart,945range: [start, index]946};947}948949function scanOctalLiteral(prefix, start) {950var number, octal;951952if (isOctalDigit(prefix)) {953octal = true;954number = '0' + source[index++];955} else {956octal = false;957++index;958number = '';959}960961while (index < length) {962if (!isOctalDigit(source[index])) {963break;964}965number += source[index++];966}967968if (!octal && number.length === 0) {969// only 0o or 0O970throwError({}, Messages.UnexpectedToken, 'ILLEGAL');971}972973if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {974throwError({}, Messages.UnexpectedToken, 'ILLEGAL');975}976977return {978type: Token.NumericLiteral,979value: parseInt(number, 8),980octal: octal,981lineNumber: lineNumber,982lineStart: lineStart,983range: [start, index]984};985}986987function scanNumericLiteral() {988var number, start, ch, octal;989990ch = source[index];991assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),992'Numeric literal must start with a decimal digit or a decimal point');993994start = index;995number = '';996if (ch !== '.') {997number = source[index++];998ch = source[index];9991000// Hex number starts with '0x'.1001// Octal number starts with '0'.1002// Octal number in ES6 starts with '0o'.1003// Binary number in ES6 starts with '0b'.1004if (number === '0') {1005if (ch === 'x' || ch === 'X') {1006++index;1007return scanHexLiteral(start);1008}1009if (ch === 'b' || ch === 'B') {1010++index;1011number = '';10121013while (index < length) {1014ch = source[index];1015if (ch !== '0' && ch !== '1') {1016break;1017}1018number += source[index++];1019}10201021if (number.length === 0) {1022// only 0b or 0B1023throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1024}10251026if (index < length) {1027ch = source.charCodeAt(index);1028/* istanbul ignore else */1029if (isIdentifierStart(ch) || isDecimalDigit(ch)) {1030throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1031}1032}1033return {1034type: Token.NumericLiteral,1035value: parseInt(number, 2),1036lineNumber: lineNumber,1037lineStart: lineStart,1038range: [start, index]1039};1040}1041if (ch === 'o' || ch === 'O' || isOctalDigit(ch)) {1042return scanOctalLiteral(ch, start);1043}1044// decimal number starts with '0' such as '09' is illegal.1045if (ch && isDecimalDigit(ch.charCodeAt(0))) {1046throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1047}1048}10491050while (isDecimalDigit(source.charCodeAt(index))) {1051number += source[index++];1052}1053ch = source[index];1054}10551056if (ch === '.') {1057number += source[index++];1058while (isDecimalDigit(source.charCodeAt(index))) {1059number += source[index++];1060}1061ch = source[index];1062}10631064if (ch === 'e' || ch === 'E') {1065number += source[index++];10661067ch = source[index];1068if (ch === '+' || ch === '-') {1069number += source[index++];1070}1071if (isDecimalDigit(source.charCodeAt(index))) {1072while (isDecimalDigit(source.charCodeAt(index))) {1073number += source[index++];1074}1075} else {1076throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1077}1078}10791080if (isIdentifierStart(source.charCodeAt(index))) {1081throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1082}10831084return {1085type: Token.NumericLiteral,1086value: parseFloat(number),1087lineNumber: lineNumber,1088lineStart: lineStart,1089range: [start, index]1090};1091}10921093// 7.8.4 String Literals10941095function scanStringLiteral() {1096var str = '', quote, start, ch, code, unescaped, restore, octal = false;10971098quote = source[index];1099assert((quote === '\'' || quote === '"'),1100'String literal must starts with a quote');11011102start = index;1103++index;11041105while (index < length) {1106ch = source[index++];11071108if (ch === quote) {1109quote = '';1110break;1111} else if (ch === '\\') {1112ch = source[index++];1113if (!ch || !isLineTerminator(ch.charCodeAt(0))) {1114switch (ch) {1115case 'n':1116str += '\n';1117break;1118case 'r':1119str += '\r';1120break;1121case 't':1122str += '\t';1123break;1124case 'u':1125case 'x':1126if (source[index] === '{') {1127++index;1128str += scanUnicodeCodePointEscape();1129} else {1130restore = index;1131unescaped = scanHexEscape(ch);1132if (unescaped) {1133str += unescaped;1134} else {1135index = restore;1136str += ch;1137}1138}1139break;1140case 'b':1141str += '\b';1142break;1143case 'f':1144str += '\f';1145break;1146case 'v':1147str += '\x0B';1148break;11491150default:1151if (isOctalDigit(ch)) {1152code = '01234567'.indexOf(ch);11531154// \0 is not octal escape sequence1155if (code !== 0) {1156octal = true;1157}11581159/* istanbul ignore else */1160if (index < length && isOctalDigit(source[index])) {1161octal = true;1162code = code * 8 + '01234567'.indexOf(source[index++]);11631164// 3 digits are only allowed when string starts1165// with 0, 1, 2, 31166if ('0123'.indexOf(ch) >= 0 &&1167index < length &&1168isOctalDigit(source[index])) {1169code = code * 8 + '01234567'.indexOf(source[index++]);1170}1171}1172str += String.fromCharCode(code);1173} else {1174str += ch;1175}1176break;1177}1178} else {1179++lineNumber;1180if (ch === '\r' && source[index] === '\n') {1181++index;1182}1183lineStart = index;1184}1185} else if (isLineTerminator(ch.charCodeAt(0))) {1186break;1187} else {1188str += ch;1189}1190}11911192if (quote !== '') {1193throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1194}11951196return {1197type: Token.StringLiteral,1198value: str,1199octal: octal,1200lineNumber: lineNumber,1201lineStart: lineStart,1202range: [start, index]1203};1204}12051206function scanTemplate() {1207var cooked = '', ch, start, terminated, tail, restore, unescaped, code, octal;12081209terminated = false;1210tail = false;1211start = index;12121213++index;12141215while (index < length) {1216ch = source[index++];1217if (ch === '`') {1218tail = true;1219terminated = true;1220break;1221} else if (ch === '$') {1222if (source[index] === '{') {1223++index;1224terminated = true;1225break;1226}1227cooked += ch;1228} else if (ch === '\\') {1229ch = source[index++];1230if (!isLineTerminator(ch.charCodeAt(0))) {1231switch (ch) {1232case 'n':1233cooked += '\n';1234break;1235case 'r':1236cooked += '\r';1237break;1238case 't':1239cooked += '\t';1240break;1241case 'u':1242case 'x':1243if (source[index] === '{') {1244++index;1245cooked += scanUnicodeCodePointEscape();1246} else {1247restore = index;1248unescaped = scanHexEscape(ch);1249if (unescaped) {1250cooked += unescaped;1251} else {1252index = restore;1253cooked += ch;1254}1255}1256break;1257case 'b':1258cooked += '\b';1259break;1260case 'f':1261cooked += '\f';1262break;1263case 'v':1264cooked += '\v';1265break;12661267default:1268if (isOctalDigit(ch)) {1269code = '01234567'.indexOf(ch);12701271// \0 is not octal escape sequence1272if (code !== 0) {1273octal = true;1274}12751276/* istanbul ignore else */1277if (index < length && isOctalDigit(source[index])) {1278octal = true;1279code = code * 8 + '01234567'.indexOf(source[index++]);12801281// 3 digits are only allowed when string starts1282// with 0, 1, 2, 31283if ('0123'.indexOf(ch) >= 0 &&1284index < length &&1285isOctalDigit(source[index])) {1286code = code * 8 + '01234567'.indexOf(source[index++]);1287}1288}1289cooked += String.fromCharCode(code);1290} else {1291cooked += ch;1292}1293break;1294}1295} else {1296++lineNumber;1297if (ch === '\r' && source[index] === '\n') {1298++index;1299}1300lineStart = index;1301}1302} else if (isLineTerminator(ch.charCodeAt(0))) {1303++lineNumber;1304if (ch === '\r' && source[index] === '\n') {1305++index;1306}1307lineStart = index;1308cooked += '\n';1309} else {1310cooked += ch;1311}1312}13131314if (!terminated) {1315throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1316}13171318return {1319type: Token.Template,1320value: {1321cooked: cooked,1322raw: source.slice(start + 1, index - ((tail) ? 1 : 2))1323},1324tail: tail,1325octal: octal,1326lineNumber: lineNumber,1327lineStart: lineStart,1328range: [start, index]1329};1330}13311332function scanTemplateElement(option) {1333var startsWith, template;13341335lookahead = null;1336skipComment();13371338startsWith = (option.head) ? '`' : '}';13391340if (source[index] !== startsWith) {1341throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1342}13431344template = scanTemplate();13451346peek();13471348return template;1349}13501351function scanRegExp() {1352var str, ch, start, pattern, flags, value, classMarker = false, restore, terminated = false, tmp;13531354lookahead = null;1355skipComment();13561357start = index;1358ch = source[index];1359assert(ch === '/', 'Regular expression literal must start with a slash');1360str = source[index++];13611362while (index < length) {1363ch = source[index++];1364str += ch;1365if (classMarker) {1366if (ch === ']') {1367classMarker = false;1368}1369} else {1370if (ch === '\\') {1371ch = source[index++];1372// ECMA-262 7.8.51373if (isLineTerminator(ch.charCodeAt(0))) {1374throwError({}, Messages.UnterminatedRegExp);1375}1376str += ch;1377} else if (ch === '/') {1378terminated = true;1379break;1380} else if (ch === '[') {1381classMarker = true;1382} else if (isLineTerminator(ch.charCodeAt(0))) {1383throwError({}, Messages.UnterminatedRegExp);1384}1385}1386}13871388if (!terminated) {1389throwError({}, Messages.UnterminatedRegExp);1390}13911392// Exclude leading and trailing slash.1393pattern = str.substr(1, str.length - 2);13941395flags = '';1396while (index < length) {1397ch = source[index];1398if (!isIdentifierPart(ch.charCodeAt(0))) {1399break;1400}14011402++index;1403if (ch === '\\' && index < length) {1404ch = source[index];1405if (ch === 'u') {1406++index;1407restore = index;1408ch = scanHexEscape('u');1409/* istanbul ignore else */1410if (ch) {1411flags += ch;1412for (str += '\\u'; restore < index; ++restore) {1413str += source[restore];1414}1415} else {1416index = restore;1417flags += 'u';1418str += '\\u';1419}1420throwErrorTolerant({}, Messages.UnexpectedToken, 'ILLEGAL');1421} else {1422str += '\\';1423}1424} else {1425flags += ch;1426str += ch;1427}1428}14291430tmp = pattern;1431if (flags.indexOf('u') >= 0) {1432// Replace each astral symbol and every Unicode code point1433// escape sequence with a single ASCII symbol to avoid throwing on1434// regular expressions that are only valid in combination with the1435// `/u` flag.1436// Note: replacing with the ASCII symbol `x` might cause false1437// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a1438// perfectly valid pattern that is equivalent to `[a-b]`, but it1439// would be replaced by `[x-b]` which throws an error.1440tmp = tmp1441.replace(/\\u\{([0-9a-fA-F]+)\}/g, function ($0, $1) {1442if (parseInt($1, 16) <= 0x10FFFF) {1443return 'x';1444}1445throwError({}, Messages.InvalidRegExp);1446})1447.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, 'x');1448}14491450// First, detect invalid regular expressions.1451try {1452value = new RegExp(tmp);1453} catch (e) {1454throwError({}, Messages.InvalidRegExp);1455}14561457// Return a regular expression object for this pattern-flag pair, or1458// `null` in case the current environment doesn't support the flags it1459// uses.1460try {1461value = new RegExp(pattern, flags);1462} catch (exception) {1463value = null;1464}14651466if (extra.tokenize) {1467return {1468type: Token.RegularExpression,1469value: value,1470regex: {1471pattern: pattern,1472flags: flags1473},1474lineNumber: lineNumber,1475lineStart: lineStart,1476range: [start, index]1477};1478}1479return {1480literal: str,1481value: value,1482regex: {1483pattern: pattern,1484flags: flags1485},1486range: [start, index]1487};1488}14891490function isIdentifierName(token) {1491return token.type === Token.Identifier ||1492token.type === Token.Keyword ||1493token.type === Token.BooleanLiteral ||1494token.type === Token.NullLiteral;1495}14961497function advanceSlash() {1498var prevToken,1499checkToken;1500// Using the following algorithm:1501// https://github.com/mozilla/sweet.js/wiki/design1502prevToken = extra.tokens[extra.tokens.length - 1];1503if (!prevToken) {1504// Nothing before that: it cannot be a division.1505return scanRegExp();1506}1507if (prevToken.type === 'Punctuator') {1508if (prevToken.value === ')') {1509checkToken = extra.tokens[extra.openParenToken - 1];1510if (checkToken &&1511checkToken.type === 'Keyword' &&1512(checkToken.value === 'if' ||1513checkToken.value === 'while' ||1514checkToken.value === 'for' ||1515checkToken.value === 'with')) {1516return scanRegExp();1517}1518return scanPunctuator();1519}1520if (prevToken.value === '}') {1521// Dividing a function by anything makes little sense,1522// but we have to check for that.1523if (extra.tokens[extra.openCurlyToken - 3] &&1524extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {1525// Anonymous function.1526checkToken = extra.tokens[extra.openCurlyToken - 4];1527if (!checkToken) {1528return scanPunctuator();1529}1530} else if (extra.tokens[extra.openCurlyToken - 4] &&1531extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {1532// Named function.1533checkToken = extra.tokens[extra.openCurlyToken - 5];1534if (!checkToken) {1535return scanRegExp();1536}1537} else {1538return scanPunctuator();1539}1540// checkToken determines whether the function is1541// a declaration or an expression.1542if (FnExprTokens.indexOf(checkToken.value) >= 0) {1543// It is an expression.1544return scanPunctuator();1545}1546// It is a declaration.1547return scanRegExp();1548}1549return scanRegExp();1550}1551if (prevToken.type === 'Keyword') {1552return scanRegExp();1553}1554return scanPunctuator();1555}15561557function advance() {1558var ch;15591560if (!state.inXJSChild) {1561skipComment();1562}15631564if (index >= length) {1565return {1566type: Token.EOF,1567lineNumber: lineNumber,1568lineStart: lineStart,1569range: [index, index]1570};1571}15721573if (state.inXJSChild) {1574return advanceXJSChild();1575}15761577ch = source.charCodeAt(index);15781579// Very common: ( and ) and ;1580if (ch === 40 || ch === 41 || ch === 58) {1581return scanPunctuator();1582}15831584// String literal starts with single quote (#39) or double quote (#34).1585if (ch === 39 || ch === 34) {1586if (state.inXJSTag) {1587return scanXJSStringLiteral();1588}1589return scanStringLiteral();1590}15911592if (state.inXJSTag && isXJSIdentifierStart(ch)) {1593return scanXJSIdentifier();1594}15951596if (ch === 96) {1597return scanTemplate();1598}1599if (isIdentifierStart(ch)) {1600return scanIdentifier();1601}16021603// Dot (.) char #46 can also start a floating-point number, hence the need1604// to check the next character.1605if (ch === 46) {1606if (isDecimalDigit(source.charCodeAt(index + 1))) {1607return scanNumericLiteral();1608}1609return scanPunctuator();1610}16111612if (isDecimalDigit(ch)) {1613return scanNumericLiteral();1614}16151616// Slash (/) char #47 can also start a regex.1617if (extra.tokenize && ch === 47) {1618return advanceSlash();1619}16201621return scanPunctuator();1622}16231624function lex() {1625var token;16261627token = lookahead;1628index = token.range[1];1629lineNumber = token.lineNumber;1630lineStart = token.lineStart;16311632lookahead = advance();16331634index = token.range[1];1635lineNumber = token.lineNumber;1636lineStart = token.lineStart;16371638return token;1639}16401641function peek() {1642var pos, line, start;16431644pos = index;1645line = lineNumber;1646start = lineStart;1647lookahead = advance();1648index = pos;1649lineNumber = line;1650lineStart = start;1651}16521653function lookahead2() {1654var adv, pos, line, start, result;16551656// If we are collecting the tokens, don't grab the next one yet.1657/* istanbul ignore next */1658adv = (typeof extra.advance === 'function') ? extra.advance : advance;16591660pos = index;1661line = lineNumber;1662start = lineStart;16631664// Scan for the next immediate token.1665/* istanbul ignore if */1666if (lookahead === null) {1667lookahead = adv();1668}1669index = lookahead.range[1];1670lineNumber = lookahead.lineNumber;1671lineStart = lookahead.lineStart;16721673// Grab the token right after.1674result = adv();1675index = pos;1676lineNumber = line;1677lineStart = start;16781679return result;1680}16811682function rewind(token) {1683index = token.range[0];1684lineNumber = token.lineNumber;1685lineStart = token.lineStart;1686lookahead = token;1687}16881689function markerCreate() {1690if (!extra.loc && !extra.range) {1691return undefined;1692}1693skipComment();1694return {offset: index, line: lineNumber, col: index - lineStart};1695}16961697function markerCreatePreserveWhitespace() {1698if (!extra.loc && !extra.range) {1699return undefined;1700}1701return {offset: index, line: lineNumber, col: index - lineStart};1702}17031704function processComment(node) {1705var lastChild,1706trailingComments,1707bottomRight = extra.bottomRightStack,1708last = bottomRight[bottomRight.length - 1];17091710if (node.type === Syntax.Program) {1711/* istanbul ignore else */1712if (node.body.length > 0) {1713return;1714}1715}17161717if (extra.trailingComments.length > 0) {1718if (extra.trailingComments[0].range[0] >= node.range[1]) {1719trailingComments = extra.trailingComments;1720extra.trailingComments = [];1721} else {1722extra.trailingComments.length = 0;1723}1724} else {1725if (last && last.trailingComments && last.trailingComments[0].range[0] >= node.range[1]) {1726trailingComments = last.trailingComments;1727delete last.trailingComments;1728}1729}17301731// Eating the stack.1732if (last) {1733while (last && last.range[0] >= node.range[0]) {1734lastChild = last;1735last = bottomRight.pop();1736}1737}17381739if (lastChild) {1740if (lastChild.leadingComments && lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= node.range[0]) {1741node.leadingComments = lastChild.leadingComments;1742delete lastChild.leadingComments;1743}1744} else if (extra.leadingComments.length > 0 && extra.leadingComments[extra.leadingComments.length - 1].range[1] <= node.range[0]) {1745node.leadingComments = extra.leadingComments;1746extra.leadingComments = [];1747}17481749if (trailingComments) {1750node.trailingComments = trailingComments;1751}17521753bottomRight.push(node);1754}17551756function markerApply(marker, node) {1757if (extra.range) {1758node.range = [marker.offset, index];1759}1760if (extra.loc) {1761node.loc = {1762start: {1763line: marker.line,1764column: marker.col1765},1766end: {1767line: lineNumber,1768column: index - lineStart1769}1770};1771node = delegate.postProcess(node);1772}1773if (extra.attachComment) {1774processComment(node);1775}1776return node;1777}17781779SyntaxTreeDelegate = {17801781name: 'SyntaxTree',17821783postProcess: function (node) {1784return node;1785},17861787createArrayExpression: function (elements) {1788return {1789type: Syntax.ArrayExpression,1790elements: elements1791};1792},17931794createAssignmentExpression: function (operator, left, right) {1795return {1796type: Syntax.AssignmentExpression,1797operator: operator,1798left: left,1799right: right1800};1801},18021803createBinaryExpression: function (operator, left, right) {1804var type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression :1805Syntax.BinaryExpression;1806return {1807type: type,1808operator: operator,1809left: left,1810right: right1811};1812},18131814createBlockStatement: function (body) {1815return {1816type: Syntax.BlockStatement,1817body: body1818};1819},18201821createBreakStatement: function (label) {1822return {1823type: Syntax.BreakStatement,1824label: label1825};1826},18271828createCallExpression: function (callee, args) {1829return {1830type: Syntax.CallExpression,1831callee: callee,1832'arguments': args1833};1834},18351836createCatchClause: function (param, body) {1837return {1838type: Syntax.CatchClause,1839param: param,1840body: body1841};1842},18431844createConditionalExpression: function (test, consequent, alternate) {1845return {1846type: Syntax.ConditionalExpression,1847test: test,1848consequent: consequent,1849alternate: alternate1850};1851},18521853createContinueStatement: function (label) {1854return {1855type: Syntax.ContinueStatement,1856label: label1857};1858},18591860createDebuggerStatement: function () {1861return {1862type: Syntax.DebuggerStatement1863};1864},18651866createDoWhileStatement: function (body, test) {1867return {1868type: Syntax.DoWhileStatement,1869body: body,1870test: test1871};1872},18731874createEmptyStatement: function () {1875return {1876type: Syntax.EmptyStatement1877};1878},18791880createExpressionStatement: function (expression) {1881return {1882type: Syntax.ExpressionStatement,1883expression: expression1884};1885},18861887createForStatement: function (init, test, update, body) {1888return {1889type: Syntax.ForStatement,1890init: init,1891test: test,1892update: update,1893body: body1894};1895},18961897createForInStatement: function (left, right, body) {1898return {1899type: Syntax.ForInStatement,1900left: left,1901right: right,1902body: body,1903each: false1904};1905},19061907createForOfStatement: function (left, right, body) {1908return {1909type: Syntax.ForOfStatement,1910left: left,1911right: right,1912body: body1913};1914},19151916createFunctionDeclaration: function (id, params, defaults, body, rest, generator, expression,1917isAsync, returnType, typeParameters) {1918var funDecl = {1919type: Syntax.FunctionDeclaration,1920id: id,1921params: params,1922defaults: defaults,1923body: body,1924rest: rest,1925generator: generator,1926expression: expression,1927returnType: returnType,1928typeParameters: typeParameters1929};19301931if (isAsync) {1932funDecl.async = true;1933}19341935return funDecl;1936},19371938createFunctionExpression: function (id, params, defaults, body, rest, generator, expression,1939isAsync, returnType, typeParameters) {1940var funExpr = {1941type: Syntax.FunctionExpression,1942id: id,1943params: params,1944defaults: defaults,1945body: body,1946rest: rest,1947generator: generator,1948expression: expression,1949returnType: returnType,1950typeParameters: typeParameters1951};19521953if (isAsync) {1954funExpr.async = true;1955}19561957return funExpr;1958},19591960createIdentifier: function (name) {1961return {1962type: Syntax.Identifier,1963name: name,1964// Only here to initialize the shape of the object to ensure1965// that the 'typeAnnotation' key is ordered before others that1966// are added later (like 'loc' and 'range'). This just helps1967// keep the shape of Identifier nodes consistent with everything1968// else.1969typeAnnotation: undefined,1970optional: undefined1971};1972},19731974createTypeAnnotation: function (typeAnnotation) {1975return {1976type: Syntax.TypeAnnotation,1977typeAnnotation: typeAnnotation1978};1979},19801981createFunctionTypeAnnotation: function (params, returnType, rest, typeParameters) {1982return {1983type: Syntax.FunctionTypeAnnotation,1984params: params,1985returnType: returnType,1986rest: rest,1987typeParameters: typeParameters1988};1989},19901991createFunctionTypeParam: function (name, typeAnnotation, optional) {1992return {1993type: Syntax.FunctionTypeParam,1994name: name,1995typeAnnotation: typeAnnotation,1996optional: optional1997};1998},19992000createNullableTypeAnnotation: function (typeAnnotation) {2001return {2002type: Syntax.NullableTypeAnnotation,2003typeAnnotation: typeAnnotation2004};2005},20062007createArrayTypeAnnotation: function (elementType) {2008return {2009type: Syntax.ArrayTypeAnnotation,2010elementType: elementType2011};2012},20132014createGenericTypeAnnotation: function (id, typeParameters) {2015return {2016type: Syntax.GenericTypeAnnotation,2017id: id,2018typeParameters: typeParameters2019};2020},20212022createQualifiedTypeIdentifier: function (qualification, id) {2023return {2024type: Syntax.QualifiedTypeIdentifier,2025qualification: qualification,2026id: id2027};2028},20292030createTypeParameterDeclaration: function (params) {2031return {2032type: Syntax.TypeParameterDeclaration,2033params: params2034};2035},20362037createTypeParameterInstantiation: function (params) {2038return {2039type: Syntax.TypeParameterInstantiation,2040params: params2041};2042},20432044createAnyTypeAnnotation: function () {2045return {2046type: Syntax.AnyTypeAnnotation2047};2048},20492050createBooleanTypeAnnotation: function () {2051return {2052type: Syntax.BooleanTypeAnnotation2053};2054},20552056createNumberTypeAnnotation: function () {2057return {2058type: Syntax.NumberTypeAnnotation2059};2060},20612062createStringTypeAnnotation: function () {2063return {2064type: Syntax.StringTypeAnnotation2065};2066},20672068createStringLiteralTypeAnnotation: function (token) {2069return {2070type: Syntax.StringLiteralTypeAnnotation,2071value: token.value,2072raw: source.slice(token.range[0], token.range[1])2073};2074},20752076createVoidTypeAnnotation: function () {2077return {2078type: Syntax.VoidTypeAnnotation2079};2080},20812082createTypeofTypeAnnotation: function (argument) {2083return {2084type: Syntax.TypeofTypeAnnotation,2085argument: argument2086};2087},20882089createTupleTypeAnnotation: function (types) {2090return {2091type: Syntax.TupleTypeAnnotation,2092types: types2093};2094},20952096createObjectTypeAnnotation: function (properties, indexers, callProperties) {2097return {2098type: Syntax.ObjectTypeAnnotation,2099properties: properties,2100indexers: indexers,2101callProperties: callProperties2102};2103},21042105createObjectTypeIndexer: function (id, key, value, isStatic) {2106return {2107type: Syntax.ObjectTypeIndexer,2108id: id,2109key: key,2110value: value,2111static: isStatic2112};2113},21142115createObjectTypeCallProperty: function (value, isStatic) {2116return {2117type: Syntax.ObjectTypeCallProperty,2118value: value,2119static: isStatic2120};2121},21222123createObjectTypeProperty: function (key, value, optional, isStatic) {2124return {2125type: Syntax.ObjectTypeProperty,2126key: key,2127value: value,2128optional: optional,2129static: isStatic2130};2131},21322133createUnionTypeAnnotation: function (types) {2134return {2135type: Syntax.UnionTypeAnnotation,2136types: types2137};2138},21392140createIntersectionTypeAnnotation: function (types) {2141return {2142type: Syntax.IntersectionTypeAnnotation,2143types: types2144};2145},21462147createTypeAlias: function (id, typeParameters, right) {2148return {2149type: Syntax.TypeAlias,2150id: id,2151typeParameters: typeParameters,2152right: right2153};2154},21552156createInterface: function (id, typeParameters, body, extended) {2157return {2158type: Syntax.InterfaceDeclaration,2159id: id,2160typeParameters: typeParameters,2161body: body,2162extends: extended2163};2164},21652166createInterfaceExtends: function (id, typeParameters) {2167return {2168type: Syntax.InterfaceExtends,2169id: id,2170typeParameters: typeParameters2171};2172},21732174createDeclareFunction: function (id) {2175return {2176type: Syntax.DeclareFunction,2177id: id2178};2179},21802181createDeclareVariable: function (id) {2182return {2183type: Syntax.DeclareVariable,2184id: id2185};2186},21872188createDeclareModule: function (id, body) {2189return {2190type: Syntax.DeclareModule,2191id: id,2192body: body2193};2194},21952196createXJSAttribute: function (name, value) {2197return {2198type: Syntax.XJSAttribute,2199name: name,2200value: value || null2201};2202},22032204createXJSSpreadAttribute: function (argument) {2205return {2206type: Syntax.XJSSpreadAttribute,2207argument: argument2208};2209},22102211createXJSIdentifier: function (name) {2212return {2213type: Syntax.XJSIdentifier,2214name: name2215};2216},22172218createXJSNamespacedName: function (namespace, name) {2219return {2220type: Syntax.XJSNamespacedName,2221namespace: namespace,2222name: name2223};2224},22252226createXJSMemberExpression: function (object, property) {2227return {2228type: Syntax.XJSMemberExpression,2229object: object,2230property: property2231};2232},22332234createXJSElement: function (openingElement, closingElement, children) {2235return {2236type: Syntax.XJSElement,2237openingElement: openingElement,2238closingElement: closingElement,2239children: children2240};2241},22422243createXJSEmptyExpression: function () {2244return {2245type: Syntax.XJSEmptyExpression2246};2247},22482249createXJSExpressionContainer: function (expression) {2250return {2251type: Syntax.XJSExpressionContainer,2252expression: expression2253};2254},22552256createXJSOpeningElement: function (name, attributes, selfClosing) {2257return {2258type: Syntax.XJSOpeningElement,2259name: name,2260selfClosing: selfClosing,2261attributes: attributes2262};2263},22642265createXJSClosingElement: function (name) {2266return {2267type: Syntax.XJSClosingElement,2268name: name2269};2270},22712272createIfStatement: function (test, consequent, alternate) {2273return {2274type: Syntax.IfStatement,2275test: test,2276consequent: consequent,2277alternate: alternate2278};2279},22802281createLabeledStatement: function (label, body) {2282return {2283type: Syntax.LabeledStatement,2284label: label,2285body: body2286};2287},22882289createLiteral: function (token) {2290var object = {2291type: Syntax.Literal,2292value: token.value,2293raw: source.slice(token.range[0], token.range[1])2294};2295if (token.regex) {2296object.regex = token.regex;2297}2298return object;2299},23002301createMemberExpression: function (accessor, object, property) {2302return {2303type: Syntax.MemberExpression,2304computed: accessor === '[',2305object: object,2306property: property2307};2308},23092310createNewExpression: function (callee, args) {2311return {2312type: Syntax.NewExpression,2313callee: callee,2314'arguments': args2315};2316},23172318createObjectExpression: function (properties) {2319return {2320type: Syntax.ObjectExpression,2321properties: properties2322};2323},23242325createPostfixExpression: function (operator, argument) {2326return {2327type: Syntax.UpdateExpression,2328operator: operator,2329argument: argument,2330prefix: false2331};2332},23332334createProgram: function (body) {2335return {2336type: Syntax.Program,2337body: body2338};2339},23402341createProperty: function (kind, key, value, method, shorthand, computed) {2342return {2343type: Syntax.Property,2344key: key,2345value: value,2346kind: kind,2347method: method,2348shorthand: shorthand,2349computed: computed2350};2351},23522353createReturnStatement: function (argument) {2354return {2355type: Syntax.ReturnStatement,2356argument: argument2357};2358},23592360createSequenceExpression: function (expressions) {2361return {2362type: Syntax.SequenceExpression,2363expressions: expressions2364};2365},23662367createSwitchCase: function (test, consequent) {2368return {2369type: Syntax.SwitchCase,2370test: test,2371consequent: consequent2372};2373},23742375createSwitchStatement: function (discriminant, cases) {2376return {2377type: Syntax.SwitchStatement,2378discriminant: discriminant,2379cases: cases2380};2381},23822383createThisExpression: function () {2384return {2385type: Syntax.ThisExpression2386};2387},23882389createThrowStatement: function (argument) {2390return {2391type: Syntax.ThrowStatement,2392argument: argument2393};2394},23952396createTryStatement: function (block, guardedHandlers, handlers, finalizer) {2397return {2398type: Syntax.TryStatement,2399block: block,2400guardedHandlers: guardedHandlers,2401handlers: handlers,2402finalizer: finalizer2403};2404},24052406createUnaryExpression: function (operator, argument) {2407if (operator === '++' || operator === '--') {2408return {2409type: Syntax.UpdateExpression,2410operator: operator,2411argument: argument,2412prefix: true2413};2414}2415return {2416type: Syntax.UnaryExpression,2417operator: operator,2418argument: argument,2419prefix: true2420};2421},24222423createVariableDeclaration: function (declarations, kind) {2424return {2425type: Syntax.VariableDeclaration,2426declarations: declarations,2427kind: kind2428};2429},24302431createVariableDeclarator: function (id, init) {2432return {2433type: Syntax.VariableDeclarator,2434id: id,2435init: init2436};2437},24382439createWhileStatement: function (test, body) {2440return {2441type: Syntax.WhileStatement,2442test: test,2443body: body2444};2445},24462447createWithStatement: function (object, body) {2448return {2449type: Syntax.WithStatement,2450object: object,2451body: body2452};2453},24542455createTemplateElement: function (value, tail) {2456return {2457type: Syntax.TemplateElement,2458value: value,2459tail: tail2460};2461},24622463createTemplateLiteral: function (quasis, expressions) {2464return {2465type: Syntax.TemplateLiteral,2466quasis: quasis,2467expressions: expressions2468};2469},24702471createSpreadElement: function (argument) {2472return {2473type: Syntax.SpreadElement,2474argument: argument2475};2476},24772478createSpreadProperty: function (argument) {2479return {2480type: Syntax.SpreadProperty,2481argument: argument2482};2483},24842485createTaggedTemplateExpression: function (tag, quasi) {2486return {2487type: Syntax.TaggedTemplateExpression,2488tag: tag,2489quasi: quasi2490};2491},24922493createArrowFunctionExpression: function (params, defaults, body, rest, expression, isAsync) {2494var arrowExpr = {2495type: Syntax.ArrowFunctionExpression,2496id: null,2497params: params,2498defaults: defaults,2499body: body,2500rest: rest,2501generator: false,2502expression: expression2503};25042505if (isAsync) {2506arrowExpr.async = true;2507}25082509return arrowExpr;2510},25112512createMethodDefinition: function (propertyType, kind, key, value, computed) {2513return {2514type: Syntax.MethodDefinition,2515key: key,2516value: value,2517kind: kind,2518'static': propertyType === ClassPropertyType.static,2519computed: computed2520};2521},25222523createClassProperty: function (key, typeAnnotation, computed, isStatic) {2524return {2525type: Syntax.ClassProperty,2526key: key,2527typeAnnotation: typeAnnotation,2528computed: computed,2529static: isStatic2530};2531},25322533createClassBody: function (body) {2534return {2535type: Syntax.ClassBody,2536body: body2537};2538},25392540createClassImplements: function (id, typeParameters) {2541return {2542type: Syntax.ClassImplements,2543id: id,2544typeParameters: typeParameters2545};2546},25472548createClassExpression: function (id, superClass, body, typeParameters, superTypeParameters, implemented) {2549return {2550type: Syntax.ClassExpression,2551id: id,2552superClass: superClass,2553body: body,2554typeParameters: typeParameters,2555superTypeParameters: superTypeParameters,2556implements: implemented2557};2558},25592560createClassDeclaration: function (id, superClass, body, typeParameters, superTypeParameters, implemented) {2561return {2562type: Syntax.ClassDeclaration,2563id: id,2564superClass: superClass,2565body: body,2566typeParameters: typeParameters,2567superTypeParameters: superTypeParameters,2568implements: implemented2569};2570},25712572createModuleSpecifier: function (token) {2573return {2574type: Syntax.ModuleSpecifier,2575value: token.value,2576raw: source.slice(token.range[0], token.range[1])2577};2578},25792580createExportSpecifier: function (id, name) {2581return {2582type: Syntax.ExportSpecifier,2583id: id,2584name: name2585};2586},25872588createExportBatchSpecifier: function () {2589return {2590type: Syntax.ExportBatchSpecifier2591};2592},25932594createImportDefaultSpecifier: function (id) {2595return {2596type: Syntax.ImportDefaultSpecifier,2597id: id2598};2599},26002601createImportNamespaceSpecifier: function (id) {2602return {2603type: Syntax.ImportNamespaceSpecifier,2604id: id2605};2606},26072608createExportDeclaration: function (isDefault, declaration, specifiers, source) {2609return {2610type: Syntax.ExportDeclaration,2611'default': !!isDefault,2612declaration: declaration,2613specifiers: specifiers,2614source: source2615};2616},26172618createImportSpecifier: function (id, name) {2619return {2620type: Syntax.ImportSpecifier,2621id: id,2622name: name2623};2624},26252626createImportDeclaration: function (specifiers, source) {2627return {2628type: Syntax.ImportDeclaration,2629specifiers: specifiers,2630source: source2631};2632},26332634createYieldExpression: function (argument, delegate) {2635return {2636type: Syntax.YieldExpression,2637argument: argument,2638delegate: delegate2639};2640},26412642createAwaitExpression: function (argument) {2643return {2644type: Syntax.AwaitExpression,2645argument: argument2646};2647},26482649createComprehensionExpression: function (filter, blocks, body) {2650return {2651type: Syntax.ComprehensionExpression,2652filter: filter,2653blocks: blocks,2654body: body2655};2656}26572658};26592660// Return true if there is a line terminator before the next token.26612662function peekLineTerminator() {2663var pos, line, start, found;26642665pos = index;2666line = lineNumber;2667start = lineStart;2668skipComment();2669found = lineNumber !== line;2670index = pos;2671lineNumber = line;2672lineStart = start;26732674return found;2675}26762677// Throw an exception26782679function throwError(token, messageFormat) {2680var error,2681args = Array.prototype.slice.call(arguments, 2),2682msg = messageFormat.replace(2683/%(\d)/g,2684function (whole, index) {2685assert(index < args.length, 'Message reference must be in range');2686return args[index];2687}2688);26892690if (typeof token.lineNumber === 'number') {2691error = new Error('Line ' + token.lineNumber + ': ' + msg);2692error.index = token.range[0];2693error.lineNumber = token.lineNumber;2694error.column = token.range[0] - lineStart + 1;2695} else {2696error = new Error('Line ' + lineNumber + ': ' + msg);2697error.index = index;2698error.lineNumber = lineNumber;2699error.column = index - lineStart + 1;2700}27012702error.description = msg;2703throw error;2704}27052706function throwErrorTolerant() {2707try {2708throwError.apply(null, arguments);2709} catch (e) {2710if (extra.errors) {2711extra.errors.push(e);2712} else {2713throw e;2714}2715}2716}271727182719// Throw an exception because of the token.27202721function throwUnexpected(token) {2722if (token.type === Token.EOF) {2723throwError(token, Messages.UnexpectedEOS);2724}27252726if (token.type === Token.NumericLiteral) {2727throwError(token, Messages.UnexpectedNumber);2728}27292730if (token.type === Token.StringLiteral || token.type === Token.XJSText) {2731throwError(token, Messages.UnexpectedString);2732}27332734if (token.type === Token.Identifier) {2735throwError(token, Messages.UnexpectedIdentifier);2736}27372738if (token.type === Token.Keyword) {2739if (isFutureReservedWord(token.value)) {2740throwError(token, Messages.UnexpectedReserved);2741} else if (strict && isStrictModeReservedWord(token.value)) {2742throwErrorTolerant(token, Messages.StrictReservedWord);2743return;2744}2745throwError(token, Messages.UnexpectedToken, token.value);2746}27472748if (token.type === Token.Template) {2749throwError(token, Messages.UnexpectedTemplate, token.value.raw);2750}27512752// BooleanLiteral, NullLiteral, or Punctuator.2753throwError(token, Messages.UnexpectedToken, token.value);2754}27552756// Expect the next token to match the specified punctuator.2757// If not, an exception will be thrown.27582759function expect(value) {2760var token = lex();2761if (token.type !== Token.Punctuator || token.value !== value) {2762throwUnexpected(token);2763}2764}27652766// Expect the next token to match the specified keyword.2767// If not, an exception will be thrown.27682769function expectKeyword(keyword, contextual) {2770var token = lex();2771if (token.type !== (contextual ? Token.Identifier : Token.Keyword) ||2772token.value !== keyword) {2773throwUnexpected(token);2774}2775}27762777// Expect the next token to match the specified contextual keyword.2778// If not, an exception will be thrown.27792780function expectContextualKeyword(keyword) {2781return expectKeyword(keyword, true);2782}27832784// Return true if the next token matches the specified punctuator.27852786function match(value) {2787return lookahead.type === Token.Punctuator && lookahead.value === value;2788}27892790// Return true if the next token matches the specified keyword27912792function matchKeyword(keyword, contextual) {2793var expectedType = contextual ? Token.Identifier : Token.Keyword;2794return lookahead.type === expectedType && lookahead.value === keyword;2795}27962797// Return true if the next token matches the specified contextual keyword27982799function matchContextualKeyword(keyword) {2800return matchKeyword(keyword, true);2801}28022803// Return true if the next token is an assignment operator28042805function matchAssign() {2806var op;28072808if (lookahead.type !== Token.Punctuator) {2809return false;2810}2811op = lookahead.value;2812return op === '=' ||2813op === '*=' ||2814op === '/=' ||2815op === '%=' ||2816op === '+=' ||2817op === '-=' ||2818op === '<<=' ||2819op === '>>=' ||2820op === '>>>=' ||2821op === '&=' ||2822op === '^=' ||2823op === '|=';2824}28252826// Note that 'yield' is treated as a keyword in strict mode, but a2827// contextual keyword (identifier) in non-strict mode, so we need to2828// use matchKeyword('yield', false) and matchKeyword('yield', true)2829// (i.e. matchContextualKeyword) appropriately.2830function matchYield() {2831return state.yieldAllowed && matchKeyword('yield', !strict);2832}28332834function matchAsync() {2835var backtrackToken = lookahead, matches = false;28362837if (matchContextualKeyword('async')) {2838lex(); // Make sure peekLineTerminator() starts after 'async'.2839matches = !peekLineTerminator();2840rewind(backtrackToken); // Revert the lex().2841}28422843return matches;2844}28452846function matchAwait() {2847return state.awaitAllowed && matchContextualKeyword('await');2848}28492850function consumeSemicolon() {2851var line, oldIndex = index, oldLineNumber = lineNumber,2852oldLineStart = lineStart, oldLookahead = lookahead;28532854// Catch the very common case first: immediately a semicolon (char #59).2855if (source.charCodeAt(index) === 59) {2856lex();2857return;2858}28592860line = lineNumber;2861skipComment();2862if (lineNumber !== line) {2863index = oldIndex;2864lineNumber = oldLineNumber;2865lineStart = oldLineStart;2866lookahead = oldLookahead;2867return;2868}28692870if (match(';')) {2871lex();2872return;2873}28742875if (lookahead.type !== Token.EOF && !match('}')) {2876throwUnexpected(lookahead);2877}2878}28792880// Return true if provided expression is LeftHandSideExpression28812882function isLeftHandSide(expr) {2883return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;2884}28852886function isAssignableLeftHandSide(expr) {2887return isLeftHandSide(expr) || expr.type === Syntax.ObjectPattern || expr.type === Syntax.ArrayPattern;2888}28892890// 11.1.4 Array Initialiser28912892function parseArrayInitialiser() {2893var elements = [], blocks = [], filter = null, tmp, possiblecomprehension = true, body,2894marker = markerCreate();28952896expect('[');2897while (!match(']')) {2898if (lookahead.value === 'for' &&2899lookahead.type === Token.Keyword) {2900if (!possiblecomprehension) {2901throwError({}, Messages.ComprehensionError);2902}2903matchKeyword('for');2904tmp = parseForStatement({ignoreBody: true});2905tmp.of = tmp.type === Syntax.ForOfStatement;2906tmp.type = Syntax.ComprehensionBlock;2907if (tmp.left.kind) { // can't be let or const2908throwError({}, Messages.ComprehensionError);2909}2910blocks.push(tmp);2911} else if (lookahead.value === 'if' &&2912lookahead.type === Token.Keyword) {2913if (!possiblecomprehension) {2914throwError({}, Messages.ComprehensionError);2915}2916expectKeyword('if');2917expect('(');2918filter = parseExpression();2919expect(')');2920} else if (lookahead.value === ',' &&2921lookahead.type === Token.Punctuator) {2922possiblecomprehension = false; // no longer allowed.2923lex();2924elements.push(null);2925} else {2926tmp = parseSpreadOrAssignmentExpression();2927elements.push(tmp);2928if (tmp && tmp.type === Syntax.SpreadElement) {2929if (!match(']')) {2930throwError({}, Messages.ElementAfterSpreadElement);2931}2932} else if (!(match(']') || matchKeyword('for') || matchKeyword('if'))) {2933expect(','); // this lexes.2934possiblecomprehension = false;2935}2936}2937}29382939expect(']');29402941if (filter && !blocks.length) {2942throwError({}, Messages.ComprehensionRequiresBlock);2943}29442945if (blocks.length) {2946if (elements.length !== 1) {2947throwError({}, Messages.ComprehensionError);2948}2949return markerApply(marker, delegate.createComprehensionExpression(filter, blocks, elements[0]));2950}2951return markerApply(marker, delegate.createArrayExpression(elements));2952}29532954// 11.1.5 Object Initialiser29552956function parsePropertyFunction(options) {2957var previousStrict, previousYieldAllowed, previousAwaitAllowed,2958params, defaults, body, marker = markerCreate();29592960previousStrict = strict;2961previousYieldAllowed = state.yieldAllowed;2962state.yieldAllowed = options.generator;2963previousAwaitAllowed = state.awaitAllowed;2964state.awaitAllowed = options.async;2965params = options.params || [];2966defaults = options.defaults || [];29672968body = parseConciseBody();2969if (options.name && strict && isRestrictedWord(params[0].name)) {2970throwErrorTolerant(options.name, Messages.StrictParamName);2971}2972strict = previousStrict;2973state.yieldAllowed = previousYieldAllowed;2974state.awaitAllowed = previousAwaitAllowed;29752976return markerApply(marker, delegate.createFunctionExpression(2977null,2978params,2979defaults,2980body,2981options.rest || null,2982options.generator,2983body.type !== Syntax.BlockStatement,2984options.async,2985options.returnType,2986options.typeParameters2987));2988}298929902991function parsePropertyMethodFunction(options) {2992var previousStrict, tmp, method;29932994previousStrict = strict;2995strict = true;29962997tmp = parseParams();29982999if (tmp.stricted) {3000throwErrorTolerant(tmp.stricted, tmp.message);3001}30023003method = parsePropertyFunction({3004params: tmp.params,3005defaults: tmp.defaults,3006rest: tmp.rest,3007generator: options.generator,3008async: options.async,3009returnType: tmp.returnType,3010typeParameters: options.typeParameters3011});30123013strict = previousStrict;30143015return method;3016}301730183019function parseObjectPropertyKey() {3020var marker = markerCreate(),3021token = lex(),3022propertyKey,3023result;30243025// Note: This function is called only from parseObjectProperty(), where3026// EOF and Punctuator tokens are already filtered out.30273028if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) {3029if (strict && token.octal) {3030throwErrorTolerant(token, Messages.StrictOctalLiteral);3031}3032return markerApply(marker, delegate.createLiteral(token));3033}30343035if (token.type === Token.Punctuator && token.value === '[') {3036// For computed properties we should skip the [ and ], and3037// capture in marker only the assignment expression itself.3038marker = markerCreate();3039propertyKey = parseAssignmentExpression();3040result = markerApply(marker, propertyKey);3041expect(']');3042return result;3043}30443045return markerApply(marker, delegate.createIdentifier(token.value));3046}30473048function parseObjectProperty() {3049var token, key, id, value, param, expr, computed,3050marker = markerCreate(), returnType, typeParameters;30513052token = lookahead;3053computed = (token.value === '[' && token.type === Token.Punctuator);30543055if (token.type === Token.Identifier || computed || matchAsync()) {3056id = parseObjectPropertyKey();30573058if (match(':')) {3059lex();30603061return markerApply(3062marker,3063delegate.createProperty(3064'init',3065id,3066parseAssignmentExpression(),3067false,3068false,3069computed3070)3071);3072}30733074if (match('(') || match('<')) {3075if (match('<')) {3076typeParameters = parseTypeParameterDeclaration();3077}3078return markerApply(3079marker,3080delegate.createProperty(3081'init',3082id,3083parsePropertyMethodFunction({3084generator: false,3085async: false,3086typeParameters: typeParameters3087}),3088true,3089false,3090computed3091)3092);3093}30943095// Property Assignment: Getter and Setter.30963097if (token.value === 'get') {3098computed = (lookahead.value === '[');3099key = parseObjectPropertyKey();31003101expect('(');3102expect(')');3103if (match(':')) {3104returnType = parseTypeAnnotation();3105}31063107return markerApply(3108marker,3109delegate.createProperty(3110'get',3111key,3112parsePropertyFunction({3113generator: false,3114async: false,3115returnType: returnType3116}),3117false,3118false,3119computed3120)3121);3122}31233124if (token.value === 'set') {3125computed = (lookahead.value === '[');3126key = parseObjectPropertyKey();31273128expect('(');3129token = lookahead;3130param = [ parseTypeAnnotatableIdentifier() ];3131expect(')');3132if (match(':')) {3133returnType = parseTypeAnnotation();3134}31353136return markerApply(3137marker,3138delegate.createProperty(3139'set',3140key,3141parsePropertyFunction({3142params: param,3143generator: false,3144async: false,3145name: token,3146returnType: returnType3147}),3148false,3149false,3150computed3151)3152);3153}31543155if (token.value === 'async') {3156computed = (lookahead.value === '[');3157key = parseObjectPropertyKey();31583159if (match('<')) {3160typeParameters = parseTypeParameterDeclaration();3161}31623163return markerApply(3164marker,3165delegate.createProperty(3166'init',3167key,3168parsePropertyMethodFunction({3169generator: false,3170async: true,3171typeParameters: typeParameters3172}),3173true,3174false,3175computed3176)3177);3178}31793180if (computed) {3181// Computed properties can only be used with full notation.3182throwUnexpected(lookahead);3183}31843185return markerApply(3186marker,3187delegate.createProperty('init', id, id, false, true, false)3188);3189}31903191if (token.type === Token.EOF || token.type === Token.Punctuator) {3192if (!match('*')) {3193throwUnexpected(token);3194}3195lex();31963197computed = (lookahead.type === Token.Punctuator && lookahead.value === '[');31983199id = parseObjectPropertyKey();32003201if (match('<')) {3202typeParameters = parseTypeParameterDeclaration();3203}32043205if (!match('(')) {3206throwUnexpected(lex());3207}32083209return markerApply(marker, delegate.createProperty(3210'init',3211id,3212parsePropertyMethodFunction({3213generator: true,3214typeParameters: typeParameters3215}),3216true,3217false,3218computed3219));3220}3221key = parseObjectPropertyKey();3222if (match(':')) {3223lex();3224return markerApply(marker, delegate.createProperty('init', key, parseAssignmentExpression(), false, false, false));3225}3226if (match('(') || match('<')) {3227if (match('<')) {3228typeParameters = parseTypeParameterDeclaration();3229}3230return markerApply(marker, delegate.createProperty(3231'init',3232key,3233parsePropertyMethodFunction({3234generator: false,3235typeParameters: typeParameters3236}),3237true,3238false,3239false3240));3241}3242throwUnexpected(lex());3243}32443245function parseObjectSpreadProperty() {3246var marker = markerCreate();3247expect('...');3248return markerApply(marker, delegate.createSpreadProperty(parseAssignmentExpression()));3249}32503251function getFieldName(key) {3252var toString = String;3253if (key.type === Syntax.Identifier) {3254return key.name;3255}3256return toString(key.value);3257}32583259function parseObjectInitialiser() {3260var properties = [], property, name, kind, storedKind, map = new StringMap(),3261marker = markerCreate(), toString = String;32623263expect('{');32643265while (!match('}')) {3266if (match('...')) {3267property = parseObjectSpreadProperty();3268} else {3269property = parseObjectProperty();32703271if (property.key.type === Syntax.Identifier) {3272name = property.key.name;3273} else {3274name = toString(property.key.value);3275}3276kind = (property.kind === 'init') ? PropertyKind.Data : (property.kind === 'get') ? PropertyKind.Get : PropertyKind.Set;32773278if (map.has(name)) {3279storedKind = map.get(name);3280if (storedKind === PropertyKind.Data) {3281if (strict && kind === PropertyKind.Data) {3282throwErrorTolerant({}, Messages.StrictDuplicateProperty);3283} else if (kind !== PropertyKind.Data) {3284throwErrorTolerant({}, Messages.AccessorDataProperty);3285}3286} else {3287if (kind === PropertyKind.Data) {3288throwErrorTolerant({}, Messages.AccessorDataProperty);3289} else if (storedKind & kind) {3290throwErrorTolerant({}, Messages.AccessorGetSet);3291}3292}3293map.set(name, storedKind | kind);3294} else {3295map.set(name, kind);3296}3297}32983299properties.push(property);33003301if (!match('}')) {3302expect(',');3303}3304}33053306expect('}');33073308return markerApply(marker, delegate.createObjectExpression(properties));3309}33103311function parseTemplateElement(option) {3312var marker = markerCreate(),3313token = scanTemplateElement(option);3314if (strict && token.octal) {3315throwError(token, Messages.StrictOctalLiteral);3316}3317return markerApply(marker, delegate.createTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail));3318}33193320function parseTemplateLiteral() {3321var quasi, quasis, expressions, marker = markerCreate();33223323quasi = parseTemplateElement({ head: true });3324quasis = [ quasi ];3325expressions = [];33263327while (!quasi.tail) {3328expressions.push(parseExpression());3329quasi = parseTemplateElement({ head: false });3330quasis.push(quasi);3331}33323333return markerApply(marker, delegate.createTemplateLiteral(quasis, expressions));3334}33353336// 11.1.6 The Grouping Operator33373338function parseGroupExpression() {3339var expr;33403341expect('(');33423343++state.parenthesizedCount;33443345expr = parseExpression();33463347expect(')');33483349return expr;3350}33513352function matchAsyncFuncExprOrDecl() {3353var token;33543355if (matchAsync()) {3356token = lookahead2();3357if (token.type === Token.Keyword && token.value === 'function') {3358return true;3359}3360}33613362return false;3363}33643365// 11.1 Primary Expressions33663367function parsePrimaryExpression() {3368var marker, type, token, expr;33693370type = lookahead.type;33713372if (type === Token.Identifier) {3373marker = markerCreate();3374return markerApply(marker, delegate.createIdentifier(lex().value));3375}33763377if (type === Token.StringLiteral || type === Token.NumericLiteral) {3378if (strict && lookahead.octal) {3379throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);3380}3381marker = markerCreate();3382return markerApply(marker, delegate.createLiteral(lex()));3383}33843385if (type === Token.Keyword) {3386if (matchKeyword('this')) {3387marker = markerCreate();3388lex();3389return markerApply(marker, delegate.createThisExpression());3390}33913392if (matchKeyword('function')) {3393return parseFunctionExpression();3394}33953396if (matchKeyword('class')) {3397return parseClassExpression();3398}33993400if (matchKeyword('super')) {3401marker = markerCreate();3402lex();3403return markerApply(marker, delegate.createIdentifier('super'));3404}3405}34063407if (type === Token.BooleanLiteral) {3408marker = markerCreate();3409token = lex();3410token.value = (token.value === 'true');3411return markerApply(marker, delegate.createLiteral(token));3412}34133414if (type === Token.NullLiteral) {3415marker = markerCreate();3416token = lex();3417token.value = null;3418return markerApply(marker, delegate.createLiteral(token));3419}34203421if (match('[')) {3422return parseArrayInitialiser();3423}34243425if (match('{')) {3426return parseObjectInitialiser();3427}34283429if (match('(')) {3430return parseGroupExpression();3431}34323433if (match('/') || match('/=')) {3434marker = markerCreate();3435expr = delegate.createLiteral(scanRegExp());3436peek();3437return markerApply(marker, expr);3438}34393440if (type === Token.Template) {3441return parseTemplateLiteral();3442}34433444if (match('<')) {3445return parseXJSElement();3446}34473448throwUnexpected(lex());3449}34503451// 11.2 Left-Hand-Side Expressions34523453function parseArguments() {3454var args = [], arg;34553456expect('(');34573458if (!match(')')) {3459while (index < length) {3460arg = parseSpreadOrAssignmentExpression();3461args.push(arg);34623463if (match(')')) {3464break;3465} else if (arg.type === Syntax.SpreadElement) {3466throwError({}, Messages.ElementAfterSpreadElement);3467}34683469expect(',');3470}3471}34723473expect(')');34743475return args;3476}34773478function parseSpreadOrAssignmentExpression() {3479if (match('...')) {3480var marker = markerCreate();3481lex();3482return markerApply(marker, delegate.createSpreadElement(parseAssignmentExpression()));3483}3484return parseAssignmentExpression();3485}34863487function parseNonComputedProperty() {3488var marker = markerCreate(),3489token = lex();34903491if (!isIdentifierName(token)) {3492throwUnexpected(token);3493}34943495return markerApply(marker, delegate.createIdentifier(token.value));3496}34973498function parseNonComputedMember() {3499expect('.');35003501return parseNonComputedProperty();3502}35033504function parseComputedMember() {3505var expr;35063507expect('[');35083509expr = parseExpression();35103511expect(']');35123513return expr;3514}35153516function parseNewExpression() {3517var callee, args, marker = markerCreate();35183519expectKeyword('new');3520callee = parseLeftHandSideExpression();3521args = match('(') ? parseArguments() : [];35223523return markerApply(marker, delegate.createNewExpression(callee, args));3524}35253526function parseLeftHandSideExpressionAllowCall() {3527var expr, args, marker = markerCreate();35283529expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();35303531while (match('.') || match('[') || match('(') || lookahead.type === Token.Template) {3532if (match('(')) {3533args = parseArguments();3534expr = markerApply(marker, delegate.createCallExpression(expr, args));3535} else if (match('[')) {3536expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));3537} else if (match('.')) {3538expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));3539} else {3540expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));3541}3542}35433544return expr;3545}35463547function parseLeftHandSideExpression() {3548var expr, marker = markerCreate();35493550expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();35513552while (match('.') || match('[') || lookahead.type === Token.Template) {3553if (match('[')) {3554expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));3555} else if (match('.')) {3556expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));3557} else {3558expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));3559}3560}35613562return expr;3563}35643565// 11.3 Postfix Expressions35663567function parsePostfixExpression() {3568var marker = markerCreate(),3569expr = parseLeftHandSideExpressionAllowCall(),3570token;35713572if (lookahead.type !== Token.Punctuator) {3573return expr;3574}35753576if ((match('++') || match('--')) && !peekLineTerminator()) {3577// 11.3.1, 11.3.23578if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3579throwErrorTolerant({}, Messages.StrictLHSPostfix);3580}35813582if (!isLeftHandSide(expr)) {3583throwError({}, Messages.InvalidLHSInAssignment);3584}35853586token = lex();3587expr = markerApply(marker, delegate.createPostfixExpression(token.value, expr));3588}35893590return expr;3591}35923593// 11.4 Unary Operators35943595function parseUnaryExpression() {3596var marker, token, expr;35973598if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {3599return parsePostfixExpression();3600}36013602if (match('++') || match('--')) {3603marker = markerCreate();3604token = lex();3605expr = parseUnaryExpression();3606// 11.4.4, 11.4.53607if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3608throwErrorTolerant({}, Messages.StrictLHSPrefix);3609}36103611if (!isLeftHandSide(expr)) {3612throwError({}, Messages.InvalidLHSInAssignment);3613}36143615return markerApply(marker, delegate.createUnaryExpression(token.value, expr));3616}36173618if (match('+') || match('-') || match('~') || match('!')) {3619marker = markerCreate();3620token = lex();3621expr = parseUnaryExpression();3622return markerApply(marker, delegate.createUnaryExpression(token.value, expr));3623}36243625if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {3626marker = markerCreate();3627token = lex();3628expr = parseUnaryExpression();3629expr = markerApply(marker, delegate.createUnaryExpression(token.value, expr));3630if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {3631throwErrorTolerant({}, Messages.StrictDelete);3632}3633return expr;3634}36353636return parsePostfixExpression();3637}36383639function binaryPrecedence(token, allowIn) {3640var prec = 0;36413642if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {3643return 0;3644}36453646switch (token.value) {3647case '||':3648prec = 1;3649break;36503651case '&&':3652prec = 2;3653break;36543655case '|':3656prec = 3;3657break;36583659case '^':3660prec = 4;3661break;36623663case '&':3664prec = 5;3665break;36663667case '==':3668case '!=':3669case '===':3670case '!==':3671prec = 6;3672break;36733674case '<':3675case '>':3676case '<=':3677case '>=':3678case 'instanceof':3679prec = 7;3680break;36813682case 'in':3683prec = allowIn ? 7 : 0;3684break;36853686case '<<':3687case '>>':3688case '>>>':3689prec = 8;3690break;36913692case '+':3693case '-':3694prec = 9;3695break;36963697case '*':3698case '/':3699case '%':3700prec = 11;3701break;37023703default:3704break;3705}37063707return prec;3708}37093710// 11.5 Multiplicative Operators3711// 11.6 Additive Operators3712// 11.7 Bitwise Shift Operators3713// 11.8 Relational Operators3714// 11.9 Equality Operators3715// 11.10 Binary Bitwise Operators3716// 11.11 Binary Logical Operators37173718function parseBinaryExpression() {3719var expr, token, prec, previousAllowIn, stack, right, operator, left, i,3720marker, markers;37213722previousAllowIn = state.allowIn;3723state.allowIn = true;37243725marker = markerCreate();3726left = parseUnaryExpression();37273728token = lookahead;3729prec = binaryPrecedence(token, previousAllowIn);3730if (prec === 0) {3731return left;3732}3733token.prec = prec;3734lex();37353736markers = [marker, markerCreate()];3737right = parseUnaryExpression();37383739stack = [left, token, right];37403741while ((prec = binaryPrecedence(lookahead, previousAllowIn)) > 0) {37423743// Reduce: make a binary expression from the three topmost entries.3744while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {3745right = stack.pop();3746operator = stack.pop().value;3747left = stack.pop();3748expr = delegate.createBinaryExpression(operator, left, right);3749markers.pop();3750marker = markers.pop();3751markerApply(marker, expr);3752stack.push(expr);3753markers.push(marker);3754}37553756// Shift.3757token = lex();3758token.prec = prec;3759stack.push(token);3760markers.push(markerCreate());3761expr = parseUnaryExpression();3762stack.push(expr);3763}37643765state.allowIn = previousAllowIn;37663767// Final reduce to clean-up the stack.3768i = stack.length - 1;3769expr = stack[i];3770markers.pop();3771while (i > 1) {3772expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);3773i -= 2;3774marker = markers.pop();3775markerApply(marker, expr);3776}37773778return expr;3779}378037813782// 11.12 Conditional Operator37833784function parseConditionalExpression() {3785var expr, previousAllowIn, consequent, alternate, marker = markerCreate();3786expr = parseBinaryExpression();37873788if (match('?')) {3789lex();3790previousAllowIn = state.allowIn;3791state.allowIn = true;3792consequent = parseAssignmentExpression();3793state.allowIn = previousAllowIn;3794expect(':');3795alternate = parseAssignmentExpression();37963797expr = markerApply(marker, delegate.createConditionalExpression(expr, consequent, alternate));3798}37993800return expr;3801}38023803// 11.13 Assignment Operators38043805// 12.14.5 AssignmentPattern38063807function reinterpretAsAssignmentBindingPattern(expr) {3808var i, len, property, element;38093810if (expr.type === Syntax.ObjectExpression) {3811expr.type = Syntax.ObjectPattern;3812for (i = 0, len = expr.properties.length; i < len; i += 1) {3813property = expr.properties[i];3814if (property.type === Syntax.SpreadProperty) {3815if (i < len - 1) {3816throwError({}, Messages.PropertyAfterSpreadProperty);3817}3818reinterpretAsAssignmentBindingPattern(property.argument);3819} else {3820if (property.kind !== 'init') {3821throwError({}, Messages.InvalidLHSInAssignment);3822}3823reinterpretAsAssignmentBindingPattern(property.value);3824}3825}3826} else if (expr.type === Syntax.ArrayExpression) {3827expr.type = Syntax.ArrayPattern;3828for (i = 0, len = expr.elements.length; i < len; i += 1) {3829element = expr.elements[i];3830/* istanbul ignore else */3831if (element) {3832reinterpretAsAssignmentBindingPattern(element);3833}3834}3835} else if (expr.type === Syntax.Identifier) {3836if (isRestrictedWord(expr.name)) {3837throwError({}, Messages.InvalidLHSInAssignment);3838}3839} else if (expr.type === Syntax.SpreadElement) {3840reinterpretAsAssignmentBindingPattern(expr.argument);3841if (expr.argument.type === Syntax.ObjectPattern) {3842throwError({}, Messages.ObjectPatternAsSpread);3843}3844} else {3845/* istanbul ignore else */3846if (expr.type !== Syntax.MemberExpression && expr.type !== Syntax.CallExpression && expr.type !== Syntax.NewExpression) {3847throwError({}, Messages.InvalidLHSInAssignment);3848}3849}3850}38513852// 13.2.3 BindingPattern38533854function reinterpretAsDestructuredParameter(options, expr) {3855var i, len, property, element;38563857if (expr.type === Syntax.ObjectExpression) {3858expr.type = Syntax.ObjectPattern;3859for (i = 0, len = expr.properties.length; i < len; i += 1) {3860property = expr.properties[i];3861if (property.type === Syntax.SpreadProperty) {3862if (i < len - 1) {3863throwError({}, Messages.PropertyAfterSpreadProperty);3864}3865reinterpretAsDestructuredParameter(options, property.argument);3866} else {3867if (property.kind !== 'init') {3868throwError({}, Messages.InvalidLHSInFormalsList);3869}3870reinterpretAsDestructuredParameter(options, property.value);3871}3872}3873} else if (expr.type === Syntax.ArrayExpression) {3874expr.type = Syntax.ArrayPattern;3875for (i = 0, len = expr.elements.length; i < len; i += 1) {3876element = expr.elements[i];3877if (element) {3878reinterpretAsDestructuredParameter(options, element);3879}3880}3881} else if (expr.type === Syntax.Identifier) {3882validateParam(options, expr, expr.name);3883} else if (expr.type === Syntax.SpreadElement) {3884// BindingRestElement only allows BindingIdentifier3885if (expr.argument.type !== Syntax.Identifier) {3886throwError({}, Messages.InvalidLHSInFormalsList);3887}3888validateParam(options, expr.argument, expr.argument.name);3889} else {3890throwError({}, Messages.InvalidLHSInFormalsList);3891}3892}38933894function reinterpretAsCoverFormalsList(expressions) {3895var i, len, param, params, defaults, defaultCount, options, rest;38963897params = [];3898defaults = [];3899defaultCount = 0;3900rest = null;3901options = {3902paramSet: new StringMap()3903};39043905for (i = 0, len = expressions.length; i < len; i += 1) {3906param = expressions[i];3907if (param.type === Syntax.Identifier) {3908params.push(param);3909defaults.push(null);3910validateParam(options, param, param.name);3911} else if (param.type === Syntax.ObjectExpression || param.type === Syntax.ArrayExpression) {3912reinterpretAsDestructuredParameter(options, param);3913params.push(param);3914defaults.push(null);3915} else if (param.type === Syntax.SpreadElement) {3916assert(i === len - 1, 'It is guaranteed that SpreadElement is last element by parseExpression');3917if (param.argument.type !== Syntax.Identifier) {3918throwError({}, Messages.InvalidLHSInFormalsList);3919}3920reinterpretAsDestructuredParameter(options, param.argument);3921rest = param.argument;3922} else if (param.type === Syntax.AssignmentExpression) {3923params.push(param.left);3924defaults.push(param.right);3925++defaultCount;3926validateParam(options, param.left, param.left.name);3927} else {3928return null;3929}3930}39313932if (options.message === Messages.StrictParamDupe) {3933throwError(3934strict ? options.stricted : options.firstRestricted,3935options.message3936);3937}39383939if (defaultCount === 0) {3940defaults = [];3941}39423943return {3944params: params,3945defaults: defaults,3946rest: rest,3947stricted: options.stricted,3948firstRestricted: options.firstRestricted,3949message: options.message3950};3951}39523953function parseArrowFunctionExpression(options, marker) {3954var previousStrict, previousYieldAllowed, previousAwaitAllowed, body;39553956expect('=>');39573958previousStrict = strict;3959previousYieldAllowed = state.yieldAllowed;3960state.yieldAllowed = false;3961previousAwaitAllowed = state.awaitAllowed;3962state.awaitAllowed = !!options.async;3963body = parseConciseBody();39643965if (strict && options.firstRestricted) {3966throwError(options.firstRestricted, options.message);3967}3968if (strict && options.stricted) {3969throwErrorTolerant(options.stricted, options.message);3970}39713972strict = previousStrict;3973state.yieldAllowed = previousYieldAllowed;3974state.awaitAllowed = previousAwaitAllowed;39753976return markerApply(marker, delegate.createArrowFunctionExpression(3977options.params,3978options.defaults,3979body,3980options.rest,3981body.type !== Syntax.BlockStatement,3982!!options.async3983));3984}39853986function parseAssignmentExpression() {3987var marker, expr, token, params, oldParenthesizedCount,3988backtrackToken = lookahead, possiblyAsync = false;39893990if (matchYield()) {3991return parseYieldExpression();3992}39933994if (matchAwait()) {3995return parseAwaitExpression();3996}39973998oldParenthesizedCount = state.parenthesizedCount;39994000marker = markerCreate();40014002if (matchAsyncFuncExprOrDecl()) {4003return parseFunctionExpression();4004}40054006if (matchAsync()) {4007// We can't be completely sure that this 'async' token is4008// actually a contextual keyword modifying a function4009// expression, so we might have to un-lex() it later by4010// calling rewind(backtrackToken).4011possiblyAsync = true;4012lex();4013}40144015if (match('(')) {4016token = lookahead2();4017if ((token.type === Token.Punctuator && token.value === ')') || token.value === '...') {4018params = parseParams();4019if (!match('=>')) {4020throwUnexpected(lex());4021}4022params.async = possiblyAsync;4023return parseArrowFunctionExpression(params, marker);4024}4025}40264027token = lookahead;40284029// If the 'async' keyword is not followed by a '(' character or an4030// identifier, then it can't be an arrow function modifier, and we4031// should interpret it as a normal identifer.4032if (possiblyAsync && !match('(') && token.type !== Token.Identifier) {4033possiblyAsync = false;4034rewind(backtrackToken);4035}40364037expr = parseConditionalExpression();40384039if (match('=>') &&4040(state.parenthesizedCount === oldParenthesizedCount ||4041state.parenthesizedCount === (oldParenthesizedCount + 1))) {4042if (expr.type === Syntax.Identifier) {4043params = reinterpretAsCoverFormalsList([ expr ]);4044} else if (expr.type === Syntax.SequenceExpression) {4045params = reinterpretAsCoverFormalsList(expr.expressions);4046}4047if (params) {4048params.async = possiblyAsync;4049return parseArrowFunctionExpression(params, marker);4050}4051}40524053// If we haven't returned by now, then the 'async' keyword was not4054// a function modifier, and we should rewind and interpret it as a4055// normal identifier.4056if (possiblyAsync) {4057possiblyAsync = false;4058rewind(backtrackToken);4059expr = parseConditionalExpression();4060}40614062if (matchAssign()) {4063// 11.13.14064if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {4065throwErrorTolerant(token, Messages.StrictLHSAssignment);4066}40674068// ES.next draf 11.13 Runtime Semantics step 14069if (match('=') && (expr.type === Syntax.ObjectExpression || expr.type === Syntax.ArrayExpression)) {4070reinterpretAsAssignmentBindingPattern(expr);4071} else if (!isLeftHandSide(expr)) {4072throwError({}, Messages.InvalidLHSInAssignment);4073}40744075expr = markerApply(marker, delegate.createAssignmentExpression(lex().value, expr, parseAssignmentExpression()));4076}40774078return expr;4079}40804081// 11.14 Comma Operator40824083function parseExpression() {4084var marker, expr, expressions, sequence, coverFormalsList, spreadFound, oldParenthesizedCount;40854086oldParenthesizedCount = state.parenthesizedCount;40874088marker = markerCreate();4089expr = parseAssignmentExpression();4090expressions = [ expr ];40914092if (match(',')) {4093while (index < length) {4094if (!match(',')) {4095break;4096}40974098lex();4099expr = parseSpreadOrAssignmentExpression();4100expressions.push(expr);41014102if (expr.type === Syntax.SpreadElement) {4103spreadFound = true;4104if (!match(')')) {4105throwError({}, Messages.ElementAfterSpreadElement);4106}4107break;4108}4109}41104111sequence = markerApply(marker, delegate.createSequenceExpression(expressions));4112}41134114if (match('=>')) {4115// Do not allow nested parentheses on the LHS of the =>.4116if (state.parenthesizedCount === oldParenthesizedCount || state.parenthesizedCount === (oldParenthesizedCount + 1)) {4117expr = expr.type === Syntax.SequenceExpression ? expr.expressions : expressions;4118coverFormalsList = reinterpretAsCoverFormalsList(expr);4119if (coverFormalsList) {4120return parseArrowFunctionExpression(coverFormalsList, marker);4121}4122}4123throwUnexpected(lex());4124}41254126if (spreadFound && lookahead2().value !== '=>') {4127throwError({}, Messages.IllegalSpread);4128}41294130return sequence || expr;4131}41324133// 12.1 Block41344135function parseStatementList() {4136var list = [],4137statement;41384139while (index < length) {4140if (match('}')) {4141break;4142}4143statement = parseSourceElement();4144if (typeof statement === 'undefined') {4145break;4146}4147list.push(statement);4148}41494150return list;4151}41524153function parseBlock() {4154var block, marker = markerCreate();41554156expect('{');41574158block = parseStatementList();41594160expect('}');41614162return markerApply(marker, delegate.createBlockStatement(block));4163}41644165// 12.2 Variable Statement41664167function parseTypeParameterDeclaration() {4168var marker = markerCreate(), paramTypes = [];41694170expect('<');4171while (!match('>')) {4172paramTypes.push(parseVariableIdentifier());4173if (!match('>')) {4174expect(',');4175}4176}4177expect('>');41784179return markerApply(marker, delegate.createTypeParameterDeclaration(4180paramTypes4181));4182}41834184function parseTypeParameterInstantiation() {4185var marker = markerCreate(), oldInType = state.inType, paramTypes = [];41864187state.inType = true;41884189expect('<');4190while (!match('>')) {4191paramTypes.push(parseType());4192if (!match('>')) {4193expect(',');4194}4195}4196expect('>');41974198state.inType = oldInType;41994200return markerApply(marker, delegate.createTypeParameterInstantiation(4201paramTypes4202));4203}42044205function parseObjectTypeIndexer(marker, isStatic) {4206var id, key, value;42074208expect('[');4209id = parseObjectPropertyKey();4210expect(':');4211key = parseType();4212expect(']');4213expect(':');4214value = parseType();42154216return markerApply(marker, delegate.createObjectTypeIndexer(4217id,4218key,4219value,4220isStatic4221));4222}42234224function parseObjectTypeMethodish(marker) {4225var params = [], rest = null, returnType, typeParameters = null;4226if (match('<')) {4227typeParameters = parseTypeParameterDeclaration();4228}42294230expect('(');4231while (lookahead.type === Token.Identifier) {4232params.push(parseFunctionTypeParam());4233if (!match(')')) {4234expect(',');4235}4236}42374238if (match('...')) {4239lex();4240rest = parseFunctionTypeParam();4241}4242expect(')');4243expect(':');4244returnType = parseType();42454246return markerApply(marker, delegate.createFunctionTypeAnnotation(4247params,4248returnType,4249rest,4250typeParameters4251));4252}42534254function parseObjectTypeMethod(marker, isStatic, key) {4255var optional = false, value;4256value = parseObjectTypeMethodish(marker);42574258return markerApply(marker, delegate.createObjectTypeProperty(4259key,4260value,4261optional,4262isStatic4263));4264}42654266function parseObjectTypeCallProperty(marker, isStatic) {4267var valueMarker = markerCreate();4268return markerApply(marker, delegate.createObjectTypeCallProperty(4269parseObjectTypeMethodish(valueMarker),4270isStatic4271));4272}42734274function parseObjectType(allowStatic) {4275var callProperties = [], indexers = [], marker, optional = false,4276properties = [], property, propertyKey, propertyTypeAnnotation,4277token, isStatic;42784279expect('{');42804281while (!match('}')) {4282marker = markerCreate();4283if (allowStatic && matchContextualKeyword('static')) {4284token = lex();4285isStatic = true;4286}42874288if (match('[')) {4289indexers.push(parseObjectTypeIndexer(marker, isStatic));4290} else if (match('(') || match('<')) {4291callProperties.push(parseObjectTypeCallProperty(marker, allowStatic));4292} else {4293if (isStatic && match(':')) {4294propertyKey = markerApply(marker, delegate.createIdentifier(token));4295throwErrorTolerant(token, Messages.StrictReservedWord);4296} else {4297propertyKey = parseObjectPropertyKey();4298}4299if (match('<') || match('(')) {4300// This is a method property4301properties.push(parseObjectTypeMethod(marker, isStatic, propertyKey));4302} else {4303if (match('?')) {4304lex();4305optional = true;4306}4307expect(':');4308propertyTypeAnnotation = parseType();4309properties.push(markerApply(marker, delegate.createObjectTypeProperty(4310propertyKey,4311propertyTypeAnnotation,4312optional,4313isStatic4314)));4315}4316}43174318if (match(';')) {4319lex();4320} else if (!match('}')) {4321throwUnexpected(lookahead);4322}4323}43244325expect('}');43264327return delegate.createObjectTypeAnnotation(4328properties,4329indexers,4330callProperties4331);4332}43334334function parseGenericType() {4335var marker = markerCreate(), returnType = null,4336typeParameters = null, typeIdentifier,4337typeIdentifierMarker = markerCreate;43384339typeIdentifier = parseVariableIdentifier();43404341while (match('.')) {4342expect('.');4343typeIdentifier = markerApply(marker, delegate.createQualifiedTypeIdentifier(4344typeIdentifier,4345parseVariableIdentifier()4346));4347}43484349if (match('<')) {4350typeParameters = parseTypeParameterInstantiation();4351}43524353return markerApply(marker, delegate.createGenericTypeAnnotation(4354typeIdentifier,4355typeParameters4356));4357}43584359function parseVoidType() {4360var marker = markerCreate();4361expectKeyword('void');4362return markerApply(marker, delegate.createVoidTypeAnnotation());4363}43644365function parseTypeofType() {4366var argument, marker = markerCreate();4367expectKeyword('typeof');4368argument = parsePrimaryType();4369return markerApply(marker, delegate.createTypeofTypeAnnotation(4370argument4371));4372}43734374function parseTupleType() {4375var marker = markerCreate(), types = [];4376expect('[');4377// We allow trailing commas4378while (index < length && !match(']')) {4379types.push(parseType());4380if (match(']')) {4381break;4382}4383expect(',');4384}4385expect(']');4386return markerApply(marker, delegate.createTupleTypeAnnotation(4387types4388));4389}43904391function parseFunctionTypeParam() {4392var marker = markerCreate(), name, optional = false, typeAnnotation;4393name = parseVariableIdentifier();4394if (match('?')) {4395lex();4396optional = true;4397}4398expect(':');4399typeAnnotation = parseType();4400return markerApply(marker, delegate.createFunctionTypeParam(4401name,4402typeAnnotation,4403optional4404));4405}44064407function parseFunctionTypeParams() {4408var ret = { params: [], rest: null };4409while (lookahead.type === Token.Identifier) {4410ret.params.push(parseFunctionTypeParam());4411if (!match(')')) {4412expect(',');4413}4414}44154416if (match('...')) {4417lex();4418ret.rest = parseFunctionTypeParam();4419}4420return ret;4421}44224423// The parsing of types roughly parallels the parsing of expressions, and4424// primary types are kind of like primary expressions...they're the4425// primitives with which other types are constructed.4426function parsePrimaryType() {4427var typeIdentifier = null, params = null, returnType = null,4428marker = markerCreate(), rest = null, tmp,4429typeParameters, token, type, isGroupedType = false;44304431switch (lookahead.type) {4432case Token.Identifier:4433switch (lookahead.value) {4434case 'any':4435lex();4436return markerApply(marker, delegate.createAnyTypeAnnotation());4437case 'bool': // fallthrough4438case 'boolean':4439lex();4440return markerApply(marker, delegate.createBooleanTypeAnnotation());4441case 'number':4442lex();4443return markerApply(marker, delegate.createNumberTypeAnnotation());4444case 'string':4445lex();4446return markerApply(marker, delegate.createStringTypeAnnotation());4447}4448return markerApply(marker, parseGenericType());4449case Token.Punctuator:4450switch (lookahead.value) {4451case '{':4452return markerApply(marker, parseObjectType());4453case '[':4454return parseTupleType();4455case '<':4456typeParameters = parseTypeParameterDeclaration();4457expect('(');4458tmp = parseFunctionTypeParams();4459params = tmp.params;4460rest = tmp.rest;4461expect(')');44624463expect('=>');44644465returnType = parseType();44664467return markerApply(marker, delegate.createFunctionTypeAnnotation(4468params,4469returnType,4470rest,4471typeParameters4472));4473case '(':4474lex();4475// Check to see if this is actually a grouped type4476if (!match(')') && !match('...')) {4477if (lookahead.type === Token.Identifier) {4478token = lookahead2();4479isGroupedType = token.value !== '?' && token.value !== ':';4480} else {4481isGroupedType = true;4482}4483}44844485if (isGroupedType) {4486type = parseType();4487expect(')');44884489// If we see a => next then someone was probably confused about4490// function types, so we can provide a better error message4491if (match('=>')) {4492throwError({}, Messages.ConfusedAboutFunctionType);4493}44944495return type;4496}44974498tmp = parseFunctionTypeParams();4499params = tmp.params;4500rest = tmp.rest;45014502expect(')');45034504expect('=>');45054506returnType = parseType();45074508return markerApply(marker, delegate.createFunctionTypeAnnotation(4509params,4510returnType,4511rest,4512null /* typeParameters */4513));4514}4515break;4516case Token.Keyword:4517switch (lookahead.value) {4518case 'void':4519return markerApply(marker, parseVoidType());4520case 'typeof':4521return markerApply(marker, parseTypeofType());4522}4523break;4524case Token.StringLiteral:4525token = lex();4526if (token.octal) {4527throwError(token, Messages.StrictOctalLiteral);4528}4529return markerApply(marker, delegate.createStringLiteralTypeAnnotation(4530token4531));4532}45334534throwUnexpected(lookahead);4535}45364537function parsePostfixType() {4538var marker = markerCreate(), t = parsePrimaryType();4539if (match('[')) {4540expect('[');4541expect(']');4542return markerApply(marker, delegate.createArrayTypeAnnotation(t));4543}4544return t;4545}45464547function parsePrefixType() {4548var marker = markerCreate();4549if (match('?')) {4550lex();4551return markerApply(marker, delegate.createNullableTypeAnnotation(4552parsePrefixType()4553));4554}4555return parsePostfixType();4556}455745584559function parseIntersectionType() {4560var marker = markerCreate(), type, types;4561type = parsePrefixType();4562types = [type];4563while (match('&')) {4564lex();4565types.push(parsePrefixType());4566}45674568return types.length === 1 ?4569type :4570markerApply(marker, delegate.createIntersectionTypeAnnotation(4571types4572));4573}45744575function parseUnionType() {4576var marker = markerCreate(), type, types;4577type = parseIntersectionType();4578types = [type];4579while (match('|')) {4580lex();4581types.push(parseIntersectionType());4582}4583return types.length === 1 ?4584type :4585markerApply(marker, delegate.createUnionTypeAnnotation(4586types4587));4588}45894590function parseType() {4591var oldInType = state.inType, type;4592state.inType = true;45934594type = parseUnionType();45954596state.inType = oldInType;4597return type;4598}45994600function parseTypeAnnotation() {4601var marker = markerCreate(), type;46024603expect(':');4604type = parseType();46054606return markerApply(marker, delegate.createTypeAnnotation(type));4607}46084609function parseVariableIdentifier() {4610var marker = markerCreate(),4611token = lex();46124613if (token.type !== Token.Identifier) {4614throwUnexpected(token);4615}46164617return markerApply(marker, delegate.createIdentifier(token.value));4618}46194620function parseTypeAnnotatableIdentifier(requireTypeAnnotation, canBeOptionalParam) {4621var marker = markerCreate(),4622ident = parseVariableIdentifier(),4623isOptionalParam = false;46244625if (canBeOptionalParam && match('?')) {4626expect('?');4627isOptionalParam = true;4628}46294630if (requireTypeAnnotation || match(':')) {4631ident.typeAnnotation = parseTypeAnnotation();4632ident = markerApply(marker, ident);4633}46344635if (isOptionalParam) {4636ident.optional = true;4637ident = markerApply(marker, ident);4638}46394640return ident;4641}46424643function parseVariableDeclaration(kind) {4644var id,4645marker = markerCreate(),4646init = null,4647typeAnnotationMarker = markerCreate();4648if (match('{')) {4649id = parseObjectInitialiser();4650reinterpretAsAssignmentBindingPattern(id);4651if (match(':')) {4652id.typeAnnotation = parseTypeAnnotation();4653markerApply(typeAnnotationMarker, id);4654}4655} else if (match('[')) {4656id = parseArrayInitialiser();4657reinterpretAsAssignmentBindingPattern(id);4658if (match(':')) {4659id.typeAnnotation = parseTypeAnnotation();4660markerApply(typeAnnotationMarker, id);4661}4662} else {4663/* istanbul ignore next */4664id = state.allowKeyword ? parseNonComputedProperty() : parseTypeAnnotatableIdentifier();4665// 12.2.14666if (strict && isRestrictedWord(id.name)) {4667throwErrorTolerant({}, Messages.StrictVarName);4668}4669}46704671if (kind === 'const') {4672if (!match('=')) {4673throwError({}, Messages.NoUnintializedConst);4674}4675expect('=');4676init = parseAssignmentExpression();4677} else if (match('=')) {4678lex();4679init = parseAssignmentExpression();4680}46814682return markerApply(marker, delegate.createVariableDeclarator(id, init));4683}46844685function parseVariableDeclarationList(kind) {4686var list = [];46874688do {4689list.push(parseVariableDeclaration(kind));4690if (!match(',')) {4691break;4692}4693lex();4694} while (index < length);46954696return list;4697}46984699function parseVariableStatement() {4700var declarations, marker = markerCreate();47014702expectKeyword('var');47034704declarations = parseVariableDeclarationList();47054706consumeSemicolon();47074708return markerApply(marker, delegate.createVariableDeclaration(declarations, 'var'));4709}47104711// kind may be `const` or `let`4712// Both are experimental and not in the specification yet.4713// see http://wiki.ecmascript.org/doku.php?id=harmony:const4714// and http://wiki.ecmascript.org/doku.php?id=harmony:let4715function parseConstLetDeclaration(kind) {4716var declarations, marker = markerCreate();47174718expectKeyword(kind);47194720declarations = parseVariableDeclarationList(kind);47214722consumeSemicolon();47234724return markerApply(marker, delegate.createVariableDeclaration(declarations, kind));4725}47264727// people.mozilla.org/~jorendorff/es6-draft.html47284729function parseModuleSpecifier() {4730var marker = markerCreate(),4731specifier;47324733if (lookahead.type !== Token.StringLiteral) {4734throwError({}, Messages.InvalidModuleSpecifier);4735}4736specifier = delegate.createModuleSpecifier(lookahead);4737lex();4738return markerApply(marker, specifier);4739}47404741function parseExportBatchSpecifier() {4742var marker = markerCreate();4743expect('*');4744return markerApply(marker, delegate.createExportBatchSpecifier());4745}47464747function parseExportSpecifier() {4748var id, name = null, marker = markerCreate(), from;4749if (matchKeyword('default')) {4750lex();4751id = markerApply(marker, delegate.createIdentifier('default'));4752// export {default} from "something";4753} else {4754id = parseVariableIdentifier();4755}4756if (matchContextualKeyword('as')) {4757lex();4758name = parseNonComputedProperty();4759}47604761return markerApply(marker, delegate.createExportSpecifier(id, name));4762}47634764function parseExportDeclaration() {4765var backtrackToken, id, previousAllowKeyword, declaration = null,4766isExportFromIdentifier,4767src = null, specifiers = [],4768marker = markerCreate();47694770expectKeyword('export');47714772if (matchKeyword('default')) {4773// covers:4774// export default ...4775lex();4776if (matchKeyword('function') || matchKeyword('class')) {4777backtrackToken = lookahead;4778lex();4779if (isIdentifierName(lookahead)) {4780// covers:4781// export default function foo () {}4782// export default class foo {}4783id = parseNonComputedProperty();4784rewind(backtrackToken);4785return markerApply(marker, delegate.createExportDeclaration(true, parseSourceElement(), [id], null));4786}4787// covers:4788// export default function () {}4789// export default class {}4790rewind(backtrackToken);4791switch (lookahead.value) {4792case 'class':4793return markerApply(marker, delegate.createExportDeclaration(true, parseClassExpression(), [], null));4794case 'function':4795return markerApply(marker, delegate.createExportDeclaration(true, parseFunctionExpression(), [], null));4796}4797}47984799if (matchContextualKeyword('from')) {4800throwError({}, Messages.UnexpectedToken, lookahead.value);4801}48024803// covers:4804// export default {};4805// export default [];4806if (match('{')) {4807declaration = parseObjectInitialiser();4808} else if (match('[')) {4809declaration = parseArrayInitialiser();4810} else {4811declaration = parseAssignmentExpression();4812}4813consumeSemicolon();4814return markerApply(marker, delegate.createExportDeclaration(true, declaration, [], null));4815}48164817// non-default export4818if (lookahead.type === Token.Keyword) {4819// covers:4820// export var f = 1;4821switch (lookahead.value) {4822case 'let':4823case 'const':4824case 'var':4825case 'class':4826case 'function':4827return markerApply(marker, delegate.createExportDeclaration(false, parseSourceElement(), specifiers, null));4828}4829}48304831if (match('*')) {4832// covers:4833// export * from "foo";4834specifiers.push(parseExportBatchSpecifier());48354836if (!matchContextualKeyword('from')) {4837throwError({}, lookahead.value ?4838Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4839}4840lex();4841src = parseModuleSpecifier();4842consumeSemicolon();48434844return markerApply(marker, delegate.createExportDeclaration(false, null, specifiers, src));4845}48464847expect('{');4848if (!match('}')) {4849do {4850isExportFromIdentifier = isExportFromIdentifier || matchKeyword('default');4851specifiers.push(parseExportSpecifier());4852} while (match(',') && lex());4853}4854expect('}');48554856if (matchContextualKeyword('from')) {4857// covering:4858// export {default} from "foo";4859// export {foo} from "foo";4860lex();4861src = parseModuleSpecifier();4862consumeSemicolon();4863} else if (isExportFromIdentifier) {4864// covering:4865// export {default}; // missing fromClause4866throwError({}, lookahead.value ?4867Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4868} else {4869// cover4870// export {foo};4871consumeSemicolon();4872}4873return markerApply(marker, delegate.createExportDeclaration(false, declaration, specifiers, src));4874}487548764877function parseImportSpecifier() {4878// import {<foo as bar>} ...;4879var id, name = null, marker = markerCreate();48804881id = parseNonComputedProperty();4882if (matchContextualKeyword('as')) {4883lex();4884name = parseVariableIdentifier();4885}48864887return markerApply(marker, delegate.createImportSpecifier(id, name));4888}48894890function parseNamedImports() {4891var specifiers = [];4892// {foo, bar as bas}4893expect('{');4894if (!match('}')) {4895do {4896specifiers.push(parseImportSpecifier());4897} while (match(',') && lex());4898}4899expect('}');4900return specifiers;4901}49024903function parseImportDefaultSpecifier() {4904// import <foo> ...;4905var id, marker = markerCreate();49064907id = parseNonComputedProperty();49084909return markerApply(marker, delegate.createImportDefaultSpecifier(id));4910}49114912function parseImportNamespaceSpecifier() {4913// import <* as foo> ...;4914var id, marker = markerCreate();49154916expect('*');4917if (!matchContextualKeyword('as')) {4918throwError({}, Messages.NoAsAfterImportNamespace);4919}4920lex();4921id = parseNonComputedProperty();49224923return markerApply(marker, delegate.createImportNamespaceSpecifier(id));4924}49254926function parseImportDeclaration() {4927var specifiers, src, marker = markerCreate();49284929expectKeyword('import');4930specifiers = [];49314932if (lookahead.type === Token.StringLiteral) {4933// covers:4934// import "foo";4935src = parseModuleSpecifier();4936consumeSemicolon();4937return markerApply(marker, delegate.createImportDeclaration(specifiers, src));4938}49394940if (!matchKeyword('default') && isIdentifierName(lookahead)) {4941// covers:4942// import foo4943// import foo, ...4944specifiers.push(parseImportDefaultSpecifier());4945if (match(',')) {4946lex();4947}4948}4949if (match('*')) {4950// covers:4951// import foo, * as foo4952// import * as foo4953specifiers.push(parseImportNamespaceSpecifier());4954} else if (match('{')) {4955// covers:4956// import foo, {bar}4957// import {bar}4958specifiers = specifiers.concat(parseNamedImports());4959}49604961if (!matchContextualKeyword('from')) {4962throwError({}, lookahead.value ?4963Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4964}4965lex();4966src = parseModuleSpecifier();4967consumeSemicolon();49684969return markerApply(marker, delegate.createImportDeclaration(specifiers, src));4970}49714972// 12.3 Empty Statement49734974function parseEmptyStatement() {4975var marker = markerCreate();4976expect(';');4977return markerApply(marker, delegate.createEmptyStatement());4978}49794980// 12.4 Expression Statement49814982function parseExpressionStatement() {4983var marker = markerCreate(), expr = parseExpression();4984consumeSemicolon();4985return markerApply(marker, delegate.createExpressionStatement(expr));4986}49874988// 12.5 If statement49894990function parseIfStatement() {4991var test, consequent, alternate, marker = markerCreate();49924993expectKeyword('if');49944995expect('(');49964997test = parseExpression();49984999expect(')');50005001consequent = parseStatement();50025003if (matchKeyword('else')) {5004lex();5005alternate = parseStatement();5006} else {5007alternate = null;5008}50095010return markerApply(marker, delegate.createIfStatement(test, consequent, alternate));5011}50125013// 12.6 Iteration Statements50145015function parseDoWhileStatement() {5016var body, test, oldInIteration, marker = markerCreate();50175018expectKeyword('do');50195020oldInIteration = state.inIteration;5021state.inIteration = true;50225023body = parseStatement();50245025state.inIteration = oldInIteration;50265027expectKeyword('while');50285029expect('(');50305031test = parseExpression();50325033expect(')');50345035if (match(';')) {5036lex();5037}50385039return markerApply(marker, delegate.createDoWhileStatement(body, test));5040}50415042function parseWhileStatement() {5043var test, body, oldInIteration, marker = markerCreate();50445045expectKeyword('while');50465047expect('(');50485049test = parseExpression();50505051expect(')');50525053oldInIteration = state.inIteration;5054state.inIteration = true;50555056body = parseStatement();50575058state.inIteration = oldInIteration;50595060return markerApply(marker, delegate.createWhileStatement(test, body));5061}50625063function parseForVariableDeclaration() {5064var marker = markerCreate(),5065token = lex(),5066declarations = parseVariableDeclarationList();50675068return markerApply(marker, delegate.createVariableDeclaration(declarations, token.value));5069}50705071function parseForStatement(opts) {5072var init, test, update, left, right, body, operator, oldInIteration,5073marker = markerCreate();5074init = test = update = null;5075expectKeyword('for');50765077// http://wiki.ecmascript.org/doku.php?id=proposals:iterators_and_generators&s=each5078if (matchContextualKeyword('each')) {5079throwError({}, Messages.EachNotAllowed);5080}50815082expect('(');50835084if (match(';')) {5085lex();5086} else {5087if (matchKeyword('var') || matchKeyword('let') || matchKeyword('const')) {5088state.allowIn = false;5089init = parseForVariableDeclaration();5090state.allowIn = true;50915092if (init.declarations.length === 1) {5093if (matchKeyword('in') || matchContextualKeyword('of')) {5094operator = lookahead;5095if (!((operator.value === 'in' || init.kind !== 'var') && init.declarations[0].init)) {5096lex();5097left = init;5098right = parseExpression();5099init = null;5100}5101}5102}5103} else {5104state.allowIn = false;5105init = parseExpression();5106state.allowIn = true;51075108if (matchContextualKeyword('of')) {5109operator = lex();5110left = init;5111right = parseExpression();5112init = null;5113} else if (matchKeyword('in')) {5114// LeftHandSideExpression5115if (!isAssignableLeftHandSide(init)) {5116throwError({}, Messages.InvalidLHSInForIn);5117}5118operator = lex();5119left = init;5120right = parseExpression();5121init = null;5122}5123}51245125if (typeof left === 'undefined') {5126expect(';');5127}5128}51295130if (typeof left === 'undefined') {51315132if (!match(';')) {5133test = parseExpression();5134}5135expect(';');51365137if (!match(')')) {5138update = parseExpression();5139}5140}51415142expect(')');51435144oldInIteration = state.inIteration;5145state.inIteration = true;51465147if (!(opts !== undefined && opts.ignoreBody)) {5148body = parseStatement();5149}51505151state.inIteration = oldInIteration;51525153if (typeof left === 'undefined') {5154return markerApply(marker, delegate.createForStatement(init, test, update, body));5155}51565157if (operator.value === 'in') {5158return markerApply(marker, delegate.createForInStatement(left, right, body));5159}5160return markerApply(marker, delegate.createForOfStatement(left, right, body));5161}51625163// 12.7 The continue statement51645165function parseContinueStatement() {5166var label = null, marker = markerCreate();51675168expectKeyword('continue');51695170// Optimize the most common form: 'continue;'.5171if (source.charCodeAt(index) === 59) {5172lex();51735174if (!state.inIteration) {5175throwError({}, Messages.IllegalContinue);5176}51775178return markerApply(marker, delegate.createContinueStatement(null));5179}51805181if (peekLineTerminator()) {5182if (!state.inIteration) {5183throwError({}, Messages.IllegalContinue);5184}51855186return markerApply(marker, delegate.createContinueStatement(null));5187}51885189if (lookahead.type === Token.Identifier) {5190label = parseVariableIdentifier();51915192if (!state.labelSet.has(label.name)) {5193throwError({}, Messages.UnknownLabel, label.name);5194}5195}51965197consumeSemicolon();51985199if (label === null && !state.inIteration) {5200throwError({}, Messages.IllegalContinue);5201}52025203return markerApply(marker, delegate.createContinueStatement(label));5204}52055206// 12.8 The break statement52075208function parseBreakStatement() {5209var label = null, marker = markerCreate();52105211expectKeyword('break');52125213// Catch the very common case first: immediately a semicolon (char #59).5214if (source.charCodeAt(index) === 59) {5215lex();52165217if (!(state.inIteration || state.inSwitch)) {5218throwError({}, Messages.IllegalBreak);5219}52205221return markerApply(marker, delegate.createBreakStatement(null));5222}52235224if (peekLineTerminator()) {5225if (!(state.inIteration || state.inSwitch)) {5226throwError({}, Messages.IllegalBreak);5227}52285229return markerApply(marker, delegate.createBreakStatement(null));5230}52315232if (lookahead.type === Token.Identifier) {5233label = parseVariableIdentifier();52345235if (!state.labelSet.has(label.name)) {5236throwError({}, Messages.UnknownLabel, label.name);5237}5238}52395240consumeSemicolon();52415242if (label === null && !(state.inIteration || state.inSwitch)) {5243throwError({}, Messages.IllegalBreak);5244}52455246return markerApply(marker, delegate.createBreakStatement(label));5247}52485249// 12.9 The return statement52505251function parseReturnStatement() {5252var argument = null, marker = markerCreate();52535254expectKeyword('return');52555256if (!state.inFunctionBody) {5257throwErrorTolerant({}, Messages.IllegalReturn);5258}52595260// 'return' followed by a space and an identifier is very common.5261if (source.charCodeAt(index) === 32) {5262if (isIdentifierStart(source.charCodeAt(index + 1))) {5263argument = parseExpression();5264consumeSemicolon();5265return markerApply(marker, delegate.createReturnStatement(argument));5266}5267}52685269if (peekLineTerminator()) {5270return markerApply(marker, delegate.createReturnStatement(null));5271}52725273if (!match(';')) {5274if (!match('}') && lookahead.type !== Token.EOF) {5275argument = parseExpression();5276}5277}52785279consumeSemicolon();52805281return markerApply(marker, delegate.createReturnStatement(argument));5282}52835284// 12.10 The with statement52855286function parseWithStatement() {5287var object, body, marker = markerCreate();52885289if (strict) {5290throwErrorTolerant({}, Messages.StrictModeWith);5291}52925293expectKeyword('with');52945295expect('(');52965297object = parseExpression();52985299expect(')');53005301body = parseStatement();53025303return markerApply(marker, delegate.createWithStatement(object, body));5304}53055306// 12.10 The swith statement53075308function parseSwitchCase() {5309var test,5310consequent = [],5311sourceElement,5312marker = markerCreate();53135314if (matchKeyword('default')) {5315lex();5316test = null;5317} else {5318expectKeyword('case');5319test = parseExpression();5320}5321expect(':');53225323while (index < length) {5324if (match('}') || matchKeyword('default') || matchKeyword('case')) {5325break;5326}5327sourceElement = parseSourceElement();5328if (typeof sourceElement === 'undefined') {5329break;5330}5331consequent.push(sourceElement);5332}53335334return markerApply(marker, delegate.createSwitchCase(test, consequent));5335}53365337function parseSwitchStatement() {5338var discriminant, cases, clause, oldInSwitch, defaultFound, marker = markerCreate();53395340expectKeyword('switch');53415342expect('(');53435344discriminant = parseExpression();53455346expect(')');53475348expect('{');53495350cases = [];53515352if (match('}')) {5353lex();5354return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));5355}53565357oldInSwitch = state.inSwitch;5358state.inSwitch = true;5359defaultFound = false;53605361while (index < length) {5362if (match('}')) {5363break;5364}5365clause = parseSwitchCase();5366if (clause.test === null) {5367if (defaultFound) {5368throwError({}, Messages.MultipleDefaultsInSwitch);5369}5370defaultFound = true;5371}5372cases.push(clause);5373}53745375state.inSwitch = oldInSwitch;53765377expect('}');53785379return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));5380}53815382// 12.13 The throw statement53835384function parseThrowStatement() {5385var argument, marker = markerCreate();53865387expectKeyword('throw');53885389if (peekLineTerminator()) {5390throwError({}, Messages.NewlineAfterThrow);5391}53925393argument = parseExpression();53945395consumeSemicolon();53965397return markerApply(marker, delegate.createThrowStatement(argument));5398}53995400// 12.14 The try statement54015402function parseCatchClause() {5403var param, body, marker = markerCreate();54045405expectKeyword('catch');54065407expect('(');5408if (match(')')) {5409throwUnexpected(lookahead);5410}54115412param = parseExpression();5413// 12.14.15414if (strict && param.type === Syntax.Identifier && isRestrictedWord(param.name)) {5415throwErrorTolerant({}, Messages.StrictCatchVariable);5416}54175418expect(')');5419body = parseBlock();5420return markerApply(marker, delegate.createCatchClause(param, body));5421}54225423function parseTryStatement() {5424var block, handlers = [], finalizer = null, marker = markerCreate();54255426expectKeyword('try');54275428block = parseBlock();54295430if (matchKeyword('catch')) {5431handlers.push(parseCatchClause());5432}54335434if (matchKeyword('finally')) {5435lex();5436finalizer = parseBlock();5437}54385439if (handlers.length === 0 && !finalizer) {5440throwError({}, Messages.NoCatchOrFinally);5441}54425443return markerApply(marker, delegate.createTryStatement(block, [], handlers, finalizer));5444}54455446// 12.15 The debugger statement54475448function parseDebuggerStatement() {5449var marker = markerCreate();5450expectKeyword('debugger');54515452consumeSemicolon();54535454return markerApply(marker, delegate.createDebuggerStatement());5455}54565457// 12 Statements54585459function parseStatement() {5460var type = lookahead.type,5461marker,5462expr,5463labeledBody;54645465if (type === Token.EOF) {5466throwUnexpected(lookahead);5467}54685469if (type === Token.Punctuator) {5470switch (lookahead.value) {5471case ';':5472return parseEmptyStatement();5473case '{':5474return parseBlock();5475case '(':5476return parseExpressionStatement();5477default:5478break;5479}5480}54815482if (type === Token.Keyword) {5483switch (lookahead.value) {5484case 'break':5485return parseBreakStatement();5486case 'continue':5487return parseContinueStatement();5488case 'debugger':5489return parseDebuggerStatement();5490case 'do':5491return parseDoWhileStatement();5492case 'for':5493return parseForStatement();5494case 'function':5495return parseFunctionDeclaration();5496case 'class':5497return parseClassDeclaration();5498case 'if':5499return parseIfStatement();5500case 'return':5501return parseReturnStatement();5502case 'switch':5503return parseSwitchStatement();5504case 'throw':5505return parseThrowStatement();5506case 'try':5507return parseTryStatement();5508case 'var':5509return parseVariableStatement();5510case 'while':5511return parseWhileStatement();5512case 'with':5513return parseWithStatement();5514default:5515break;5516}5517}55185519if (matchAsyncFuncExprOrDecl()) {5520return parseFunctionDeclaration();5521}55225523marker = markerCreate();5524expr = parseExpression();55255526// 12.12 Labelled Statements5527if ((expr.type === Syntax.Identifier) && match(':')) {5528lex();55295530if (state.labelSet.has(expr.name)) {5531throwError({}, Messages.Redeclaration, 'Label', expr.name);5532}55335534state.labelSet.set(expr.name, true);5535labeledBody = parseStatement();5536state.labelSet['delete'](expr.name);5537return markerApply(marker, delegate.createLabeledStatement(expr, labeledBody));5538}55395540consumeSemicolon();55415542return markerApply(marker, delegate.createExpressionStatement(expr));5543}55445545// 13 Function Definition55465547function parseConciseBody() {5548if (match('{')) {5549return parseFunctionSourceElements();5550}5551return parseAssignmentExpression();5552}55535554function parseFunctionSourceElements() {5555var sourceElement, sourceElements = [], token, directive, firstRestricted,5556oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, oldParenthesizedCount,5557marker = markerCreate();55585559expect('{');55605561while (index < length) {5562if (lookahead.type !== Token.StringLiteral) {5563break;5564}5565token = lookahead;55665567sourceElement = parseSourceElement();5568sourceElements.push(sourceElement);5569if (sourceElement.expression.type !== Syntax.Literal) {5570// this is not directive5571break;5572}5573directive = source.slice(token.range[0] + 1, token.range[1] - 1);5574if (directive === 'use strict') {5575strict = true;5576if (firstRestricted) {5577throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);5578}5579} else {5580if (!firstRestricted && token.octal) {5581firstRestricted = token;5582}5583}5584}55855586oldLabelSet = state.labelSet;5587oldInIteration = state.inIteration;5588oldInSwitch = state.inSwitch;5589oldInFunctionBody = state.inFunctionBody;5590oldParenthesizedCount = state.parenthesizedCount;55915592state.labelSet = new StringMap();5593state.inIteration = false;5594state.inSwitch = false;5595state.inFunctionBody = true;5596state.parenthesizedCount = 0;55975598while (index < length) {5599if (match('}')) {5600break;5601}5602sourceElement = parseSourceElement();5603if (typeof sourceElement === 'undefined') {5604break;5605}5606sourceElements.push(sourceElement);5607}56085609expect('}');56105611state.labelSet = oldLabelSet;5612state.inIteration = oldInIteration;5613state.inSwitch = oldInSwitch;5614state.inFunctionBody = oldInFunctionBody;5615state.parenthesizedCount = oldParenthesizedCount;56165617return markerApply(marker, delegate.createBlockStatement(sourceElements));5618}56195620function validateParam(options, param, name) {5621if (strict) {5622if (isRestrictedWord(name)) {5623options.stricted = param;5624options.message = Messages.StrictParamName;5625}5626if (options.paramSet.has(name)) {5627options.stricted = param;5628options.message = Messages.StrictParamDupe;5629}5630} else if (!options.firstRestricted) {5631if (isRestrictedWord(name)) {5632options.firstRestricted = param;5633options.message = Messages.StrictParamName;5634} else if (isStrictModeReservedWord(name)) {5635options.firstRestricted = param;5636options.message = Messages.StrictReservedWord;5637} else if (options.paramSet.has(name)) {5638options.firstRestricted = param;5639options.message = Messages.StrictParamDupe;5640}5641}5642options.paramSet.set(name, true);5643}56445645function parseParam(options) {5646var marker, token, rest, param, def;56475648token = lookahead;5649if (token.value === '...') {5650token = lex();5651rest = true;5652}56535654if (match('[')) {5655marker = markerCreate();5656param = parseArrayInitialiser();5657reinterpretAsDestructuredParameter(options, param);5658if (match(':')) {5659param.typeAnnotation = parseTypeAnnotation();5660markerApply(marker, param);5661}5662} else if (match('{')) {5663marker = markerCreate();5664if (rest) {5665throwError({}, Messages.ObjectPatternAsRestParameter);5666}5667param = parseObjectInitialiser();5668reinterpretAsDestructuredParameter(options, param);5669if (match(':')) {5670param.typeAnnotation = parseTypeAnnotation();5671markerApply(marker, param);5672}5673} else {5674param =5675rest5676? parseTypeAnnotatableIdentifier(5677false, /* requireTypeAnnotation */5678false /* canBeOptionalParam */5679)5680: parseTypeAnnotatableIdentifier(5681false, /* requireTypeAnnotation */5682true /* canBeOptionalParam */5683);56845685validateParam(options, token, token.value);5686}56875688if (match('=')) {5689if (rest) {5690throwErrorTolerant(lookahead, Messages.DefaultRestParameter);5691}5692lex();5693def = parseAssignmentExpression();5694++options.defaultCount;5695}56965697if (rest) {5698if (!match(')')) {5699throwError({}, Messages.ParameterAfterRestParameter);5700}5701options.rest = param;5702return false;5703}57045705options.params.push(param);5706options.defaults.push(def);5707return !match(')');5708}57095710function parseParams(firstRestricted) {5711var options, marker = markerCreate();57125713options = {5714params: [],5715defaultCount: 0,5716defaults: [],5717rest: null,5718firstRestricted: firstRestricted5719};57205721expect('(');57225723if (!match(')')) {5724options.paramSet = new StringMap();5725while (index < length) {5726if (!parseParam(options)) {5727break;5728}5729expect(',');5730}5731}57325733expect(')');57345735if (options.defaultCount === 0) {5736options.defaults = [];5737}57385739if (match(':')) {5740options.returnType = parseTypeAnnotation();5741}57425743return markerApply(marker, options);5744}57455746function parseFunctionDeclaration() {5747var id, body, token, tmp, firstRestricted, message, generator, isAsync,5748previousStrict, previousYieldAllowed, previousAwaitAllowed,5749marker = markerCreate(), typeParameters;57505751isAsync = false;5752if (matchAsync()) {5753lex();5754isAsync = true;5755}57565757expectKeyword('function');57585759generator = false;5760if (match('*')) {5761lex();5762generator = true;5763}57645765token = lookahead;57665767id = parseVariableIdentifier();57685769if (match('<')) {5770typeParameters = parseTypeParameterDeclaration();5771}57725773if (strict) {5774if (isRestrictedWord(token.value)) {5775throwErrorTolerant(token, Messages.StrictFunctionName);5776}5777} else {5778if (isRestrictedWord(token.value)) {5779firstRestricted = token;5780message = Messages.StrictFunctionName;5781} else if (isStrictModeReservedWord(token.value)) {5782firstRestricted = token;5783message = Messages.StrictReservedWord;5784}5785}57865787tmp = parseParams(firstRestricted);5788firstRestricted = tmp.firstRestricted;5789if (tmp.message) {5790message = tmp.message;5791}57925793previousStrict = strict;5794previousYieldAllowed = state.yieldAllowed;5795state.yieldAllowed = generator;5796previousAwaitAllowed = state.awaitAllowed;5797state.awaitAllowed = isAsync;57985799body = parseFunctionSourceElements();58005801if (strict && firstRestricted) {5802throwError(firstRestricted, message);5803}5804if (strict && tmp.stricted) {5805throwErrorTolerant(tmp.stricted, message);5806}5807strict = previousStrict;5808state.yieldAllowed = previousYieldAllowed;5809state.awaitAllowed = previousAwaitAllowed;58105811return markerApply(5812marker,5813delegate.createFunctionDeclaration(5814id,5815tmp.params,5816tmp.defaults,5817body,5818tmp.rest,5819generator,5820false,5821isAsync,5822tmp.returnType,5823typeParameters5824)5825);5826}58275828function parseFunctionExpression() {5829var token, id = null, firstRestricted, message, tmp, body, generator, isAsync,5830previousStrict, previousYieldAllowed, previousAwaitAllowed,5831marker = markerCreate(), typeParameters;58325833isAsync = false;5834if (matchAsync()) {5835lex();5836isAsync = true;5837}58385839expectKeyword('function');58405841generator = false;58425843if (match('*')) {5844lex();5845generator = true;5846}58475848if (!match('(')) {5849if (!match('<')) {5850token = lookahead;5851id = parseVariableIdentifier();58525853if (strict) {5854if (isRestrictedWord(token.value)) {5855throwErrorTolerant(token, Messages.StrictFunctionName);5856}5857} else {5858if (isRestrictedWord(token.value)) {5859firstRestricted = token;5860message = Messages.StrictFunctionName;5861} else if (isStrictModeReservedWord(token.value)) {5862firstRestricted = token;5863message = Messages.StrictReservedWord;5864}5865}5866}58675868if (match('<')) {5869typeParameters = parseTypeParameterDeclaration();5870}5871}58725873tmp = parseParams(firstRestricted);5874firstRestricted = tmp.firstRestricted;5875if (tmp.message) {5876message = tmp.message;5877}58785879previousStrict = strict;5880previousYieldAllowed = state.yieldAllowed;5881state.yieldAllowed = generator;5882previousAwaitAllowed = state.awaitAllowed;5883state.awaitAllowed = isAsync;58845885body = parseFunctionSourceElements();58865887if (strict && firstRestricted) {5888throwError(firstRestricted, message);5889}5890if (strict && tmp.stricted) {5891throwErrorTolerant(tmp.stricted, message);5892}5893strict = previousStrict;5894state.yieldAllowed = previousYieldAllowed;5895state.awaitAllowed = previousAwaitAllowed;58965897return markerApply(5898marker,5899delegate.createFunctionExpression(5900id,5901tmp.params,5902tmp.defaults,5903body,5904tmp.rest,5905generator,5906false,5907isAsync,5908tmp.returnType,5909typeParameters5910)5911);5912}59135914function parseYieldExpression() {5915var delegateFlag, expr, marker = markerCreate();59165917expectKeyword('yield', !strict);59185919delegateFlag = false;5920if (match('*')) {5921lex();5922delegateFlag = true;5923}59245925expr = parseAssignmentExpression();59265927return markerApply(marker, delegate.createYieldExpression(expr, delegateFlag));5928}59295930function parseAwaitExpression() {5931var expr, marker = markerCreate();5932expectContextualKeyword('await');5933expr = parseAssignmentExpression();5934return markerApply(marker, delegate.createAwaitExpression(expr));5935}59365937// 14 Classes59385939function validateDuplicateProp(propMap, key, accessor) {5940var propInfo, reversed, name, isValidDuplicateProp;59415942name = getFieldName(key);59435944if (propMap.has(name)) {5945propInfo = propMap.get(name);5946if (accessor === 'data') {5947isValidDuplicateProp = false;5948} else {5949if (accessor === 'get') {5950reversed = 'set';5951} else {5952reversed = 'get';5953}59545955isValidDuplicateProp =5956// There isn't already a specified accessor for this prop5957propInfo[accessor] === undefined5958// There isn't already a data prop by this name5959&& propInfo.data === undefined5960// The only existing prop by this name is a reversed accessor5961&& propInfo[reversed] !== undefined;5962}5963if (!isValidDuplicateProp) {5964throwError(key, Messages.IllegalDuplicateClassProperty);5965}5966} else {5967propInfo = {5968get: undefined,5969set: undefined,5970data: undefined5971};5972propMap.set(name, propInfo);5973}5974propInfo[accessor] = true;5975}59765977function parseMethodDefinition(existingPropNames, key, isStatic, generator, computed) {5978var token, param, propType, isValidDuplicateProp = false,5979isAsync, typeParameters, tokenValue, returnType,5980annotationMarker, propMap;59815982propType = isStatic ? ClassPropertyType.static : ClassPropertyType.prototype;59835984propMap = existingPropNames[propType];59855986if (generator) {5987return delegate.createMethodDefinition(5988propType,5989'',5990key,5991parsePropertyMethodFunction({ generator: true }),5992computed5993);5994}59955996tokenValue = key.type === 'Identifier' && key.name;59975998if (tokenValue === 'get' && !match('(')) {5999key = parseObjectPropertyKey();60006001// It is a syntax error if any other properties have a name6002// duplicating this one unless they are a setter6003if (!computed) {6004validateDuplicateProp(propMap, key, 'get');6005}60066007expect('(');6008expect(')');6009if (match(':')) {6010returnType = parseTypeAnnotation();6011}6012return delegate.createMethodDefinition(6013propType,6014'get',6015key,6016parsePropertyFunction({ generator: false, returnType: returnType }),6017computed6018);6019}6020if (tokenValue === 'set' && !match('(')) {6021key = parseObjectPropertyKey();60226023// It is a syntax error if any other properties have a name6024// duplicating this one unless they are a getter6025if (!computed) {6026validateDuplicateProp(propMap, key, 'set');6027}60286029expect('(');6030token = lookahead;6031param = [ parseTypeAnnotatableIdentifier() ];6032expect(')');6033if (match(':')) {6034returnType = parseTypeAnnotation();6035}6036return delegate.createMethodDefinition(6037propType,6038'set',6039key,6040parsePropertyFunction({6041params: param,6042generator: false,6043name: token,6044returnType: returnType6045}),6046computed6047);6048}60496050if (match('<')) {6051typeParameters = parseTypeParameterDeclaration();6052}60536054isAsync = tokenValue === 'async' && !match('(');6055if (isAsync) {6056key = parseObjectPropertyKey();6057}60586059// It is a syntax error if any other properties have the same name as a6060// non-getter, non-setter method6061if (!computed) {6062validateDuplicateProp(propMap, key, 'data');6063}60646065return delegate.createMethodDefinition(6066propType,6067'',6068key,6069parsePropertyMethodFunction({6070generator: false,6071async: isAsync,6072typeParameters: typeParameters6073}),6074computed6075);6076}60776078function parseClassProperty(existingPropNames, key, computed, isStatic) {6079var typeAnnotation;60806081typeAnnotation = parseTypeAnnotation();6082expect(';');60836084return delegate.createClassProperty(6085key,6086typeAnnotation,6087computed,6088isStatic6089);6090}60916092function parseClassElement(existingProps) {6093var computed = false, generator = false, key, marker = markerCreate(),6094isStatic = false, possiblyOpenBracketToken;6095if (match(';')) {6096lex();6097return;6098}60996100if (lookahead.value === 'static') {6101lex();6102isStatic = true;6103}61046105if (match('*')) {6106lex();6107generator = true;6108}61096110possiblyOpenBracketToken = lookahead;6111if (matchContextualKeyword('get') || matchContextualKeyword('set')) {6112possiblyOpenBracketToken = lookahead2();6113}61146115if (possiblyOpenBracketToken.type === Token.Punctuator6116&& possiblyOpenBracketToken.value === '[') {6117computed = true;6118}61196120key = parseObjectPropertyKey();61216122if (!generator && lookahead.value === ':') {6123return markerApply(marker, parseClassProperty(existingProps, key, computed, isStatic));6124}61256126return markerApply(marker, parseMethodDefinition(6127existingProps,6128key,6129isStatic,6130generator,6131computed6132));6133}61346135function parseClassBody() {6136var classElement, classElements = [], existingProps = {}, marker = markerCreate();61376138existingProps[ClassPropertyType.static] = new StringMap();6139existingProps[ClassPropertyType.prototype] = new StringMap();61406141expect('{');61426143while (index < length) {6144if (match('}')) {6145break;6146}6147classElement = parseClassElement(existingProps);61486149if (typeof classElement !== 'undefined') {6150classElements.push(classElement);6151}6152}61536154expect('}');61556156return markerApply(marker, delegate.createClassBody(classElements));6157}61586159function parseClassImplements() {6160var id, implemented = [], marker, typeParameters;6161expectContextualKeyword('implements');6162while (index < length) {6163marker = markerCreate();6164id = parseVariableIdentifier();6165if (match('<')) {6166typeParameters = parseTypeParameterInstantiation();6167} else {6168typeParameters = null;6169}6170implemented.push(markerApply(marker, delegate.createClassImplements(6171id,6172typeParameters6173)));6174if (!match(',')) {6175break;6176}6177expect(',');6178}6179return implemented;6180}61816182function parseClassExpression() {6183var id, implemented, previousYieldAllowed, superClass = null,6184superTypeParameters, marker = markerCreate(), typeParameters;61856186expectKeyword('class');61876188if (!matchKeyword('extends') && !matchContextualKeyword('implements') && !match('{')) {6189id = parseVariableIdentifier();6190}61916192if (match('<')) {6193typeParameters = parseTypeParameterDeclaration();6194}61956196if (matchKeyword('extends')) {6197expectKeyword('extends');6198previousYieldAllowed = state.yieldAllowed;6199state.yieldAllowed = false;6200superClass = parseLeftHandSideExpressionAllowCall();6201if (match('<')) {6202superTypeParameters = parseTypeParameterInstantiation();6203}6204state.yieldAllowed = previousYieldAllowed;6205}62066207if (matchContextualKeyword('implements')) {6208implemented = parseClassImplements();6209}62106211return markerApply(marker, delegate.createClassExpression(6212id,6213superClass,6214parseClassBody(),6215typeParameters,6216superTypeParameters,6217implemented6218));6219}62206221function parseClassDeclaration() {6222var id, implemented, previousYieldAllowed, superClass = null,6223superTypeParameters, marker = markerCreate(), typeParameters;62246225expectKeyword('class');62266227id = parseVariableIdentifier();62286229if (match('<')) {6230typeParameters = parseTypeParameterDeclaration();6231}62326233if (matchKeyword('extends')) {6234expectKeyword('extends');6235previousYieldAllowed = state.yieldAllowed;6236state.yieldAllowed = false;6237superClass = parseLeftHandSideExpressionAllowCall();6238if (match('<')) {6239superTypeParameters = parseTypeParameterInstantiation();6240}6241state.yieldAllowed = previousYieldAllowed;6242}62436244if (matchContextualKeyword('implements')) {6245implemented = parseClassImplements();6246}62476248return markerApply(marker, delegate.createClassDeclaration(6249id,6250superClass,6251parseClassBody(),6252typeParameters,6253superTypeParameters,6254implemented6255));6256}62576258// 15 Program62596260function parseSourceElement() {6261var token;6262if (lookahead.type === Token.Keyword) {6263switch (lookahead.value) {6264case 'const':6265case 'let':6266return parseConstLetDeclaration(lookahead.value);6267case 'function':6268return parseFunctionDeclaration();6269case 'export':6270throwErrorTolerant({}, Messages.IllegalExportDeclaration);6271return parseExportDeclaration();6272case 'import':6273throwErrorTolerant({}, Messages.IllegalImportDeclaration);6274return parseImportDeclaration();6275default:6276return parseStatement();6277}6278}62796280if (matchContextualKeyword('type')6281&& lookahead2().type === Token.Identifier) {6282return parseTypeAlias();6283}62846285if (matchContextualKeyword('interface')6286&& lookahead2().type === Token.Identifier) {6287return parseInterface();6288}62896290if (matchContextualKeyword('declare')) {6291token = lookahead2();6292if (token.type === Token.Keyword) {6293switch (token.value) {6294case 'class':6295return parseDeclareClass();6296case 'function':6297return parseDeclareFunction();6298case 'var':6299return parseDeclareVariable();6300}6301} else if (token.type === Token.Identifier6302&& token.value === 'module') {6303return parseDeclareModule();6304}6305}63066307if (lookahead.type !== Token.EOF) {6308return parseStatement();6309}6310}63116312function parseProgramElement() {6313if (extra.isModule && lookahead.type === Token.Keyword) {6314switch (lookahead.value) {6315case 'export':6316return parseExportDeclaration();6317case 'import':6318return parseImportDeclaration();6319}6320}63216322return parseSourceElement();6323}63246325function parseProgramElements() {6326var sourceElement, sourceElements = [], token, directive, firstRestricted;63276328while (index < length) {6329token = lookahead;6330if (token.type !== Token.StringLiteral) {6331break;6332}63336334sourceElement = parseProgramElement();6335sourceElements.push(sourceElement);6336if (sourceElement.expression.type !== Syntax.Literal) {6337// this is not directive6338break;6339}6340directive = source.slice(token.range[0] + 1, token.range[1] - 1);6341if (directive === 'use strict') {6342strict = true;6343if (firstRestricted) {6344throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);6345}6346} else {6347if (!firstRestricted && token.octal) {6348firstRestricted = token;6349}6350}6351}63526353while (index < length) {6354sourceElement = parseProgramElement();6355if (typeof sourceElement === 'undefined') {6356break;6357}6358sourceElements.push(sourceElement);6359}6360return sourceElements;6361}63626363function parseProgram() {6364var body, marker = markerCreate();6365strict = !!extra.isModule;6366peek();6367body = parseProgramElements();6368return markerApply(marker, delegate.createProgram(body));6369}63706371// The following functions are needed only when the option to preserve6372// the comments is active.63736374function addComment(type, value, start, end, loc) {6375var comment;63766377assert(typeof start === 'number', 'Comment must have valid position');63786379// Because the way the actual token is scanned, often the comments6380// (if any) are skipped twice during the lexical analysis.6381// Thus, we need to skip adding a comment if the comment array already6382// handled it.6383if (state.lastCommentStart >= start) {6384return;6385}6386state.lastCommentStart = start;63876388comment = {6389type: type,6390value: value6391};6392if (extra.range) {6393comment.range = [start, end];6394}6395if (extra.loc) {6396comment.loc = loc;6397}6398extra.comments.push(comment);6399if (extra.attachComment) {6400extra.leadingComments.push(comment);6401extra.trailingComments.push(comment);6402}6403}64046405function scanComment() {6406var comment, ch, loc, start, blockComment, lineComment;64076408comment = '';6409blockComment = false;6410lineComment = false;64116412while (index < length) {6413ch = source[index];64146415if (lineComment) {6416ch = source[index++];6417if (isLineTerminator(ch.charCodeAt(0))) {6418loc.end = {6419line: lineNumber,6420column: index - lineStart - 16421};6422lineComment = false;6423addComment('Line', comment, start, index - 1, loc);6424if (ch === '\r' && source[index] === '\n') {6425++index;6426}6427++lineNumber;6428lineStart = index;6429comment = '';6430} else if (index >= length) {6431lineComment = false;6432comment += ch;6433loc.end = {6434line: lineNumber,6435column: length - lineStart6436};6437addComment('Line', comment, start, length, loc);6438} else {6439comment += ch;6440}6441} else if (blockComment) {6442if (isLineTerminator(ch.charCodeAt(0))) {6443if (ch === '\r') {6444++index;6445comment += '\r';6446}6447if (ch !== '\r' || source[index] === '\n') {6448comment += source[index];6449++lineNumber;6450++index;6451lineStart = index;6452if (index >= length) {6453throwError({}, Messages.UnexpectedToken, 'ILLEGAL');6454}6455}6456} else {6457ch = source[index++];6458if (index >= length) {6459throwError({}, Messages.UnexpectedToken, 'ILLEGAL');6460}6461comment += ch;6462if (ch === '*') {6463ch = source[index];6464if (ch === '/') {6465comment = comment.substr(0, comment.length - 1);6466blockComment = false;6467++index;6468loc.end = {6469line: lineNumber,6470column: index - lineStart6471};6472addComment('Block', comment, start, index, loc);6473comment = '';6474}6475}6476}6477} else if (ch === '/') {6478ch = source[index + 1];6479if (ch === '/') {6480loc = {6481start: {6482line: lineNumber,6483column: index - lineStart6484}6485};6486start = index;6487index += 2;6488lineComment = true;6489if (index >= length) {6490loc.end = {6491line: lineNumber,6492column: index - lineStart6493};6494lineComment = false;6495addComment('Line', comment, start, index, loc);6496}6497} else if (ch === '*') {6498start = index;6499index += 2;6500blockComment = true;6501loc = {6502start: {6503line: lineNumber,6504column: index - lineStart - 26505}6506};6507if (index >= length) {6508throwError({}, Messages.UnexpectedToken, 'ILLEGAL');6509}6510} else {6511break;6512}6513} else if (isWhiteSpace(ch.charCodeAt(0))) {6514++index;6515} else if (isLineTerminator(ch.charCodeAt(0))) {6516++index;6517if (ch === '\r' && source[index] === '\n') {6518++index;6519}6520++lineNumber;6521lineStart = index;6522} else {6523break;6524}6525}6526}65276528// 16 XJS65296530XHTMLEntities = {6531quot: '\u0022',6532amp: '&',6533apos: '\u0027',6534lt: '<',6535gt: '>',6536nbsp: '\u00A0',6537iexcl: '\u00A1',6538cent: '\u00A2',6539pound: '\u00A3',6540curren: '\u00A4',6541yen: '\u00A5',6542brvbar: '\u00A6',6543sect: '\u00A7',6544uml: '\u00A8',6545copy: '\u00A9',6546ordf: '\u00AA',6547laquo: '\u00AB',6548not: '\u00AC',6549shy: '\u00AD',6550reg: '\u00AE',6551macr: '\u00AF',6552deg: '\u00B0',6553plusmn: '\u00B1',6554sup2: '\u00B2',6555sup3: '\u00B3',6556acute: '\u00B4',6557micro: '\u00B5',6558para: '\u00B6',6559middot: '\u00B7',6560cedil: '\u00B8',6561sup1: '\u00B9',6562ordm: '\u00BA',6563raquo: '\u00BB',6564frac14: '\u00BC',6565frac12: '\u00BD',6566frac34: '\u00BE',6567iquest: '\u00BF',6568Agrave: '\u00C0',6569Aacute: '\u00C1',6570Acirc: '\u00C2',6571Atilde: '\u00C3',6572Auml: '\u00C4',6573Aring: '\u00C5',6574AElig: '\u00C6',6575Ccedil: '\u00C7',6576Egrave: '\u00C8',6577Eacute: '\u00C9',6578Ecirc: '\u00CA',6579Euml: '\u00CB',6580Igrave: '\u00CC',6581Iacute: '\u00CD',6582Icirc: '\u00CE',6583Iuml: '\u00CF',6584ETH: '\u00D0',6585Ntilde: '\u00D1',6586Ograve: '\u00D2',6587Oacute: '\u00D3',6588Ocirc: '\u00D4',6589Otilde: '\u00D5',6590Ouml: '\u00D6',6591times: '\u00D7',6592Oslash: '\u00D8',6593Ugrave: '\u00D9',6594Uacute: '\u00DA',6595Ucirc: '\u00DB',6596Uuml: '\u00DC',6597Yacute: '\u00DD',6598THORN: '\u00DE',6599szlig: '\u00DF',6600agrave: '\u00E0',6601aacute: '\u00E1',6602acirc: '\u00E2',6603atilde: '\u00E3',6604auml: '\u00E4',6605aring: '\u00E5',6606aelig: '\u00E6',6607ccedil: '\u00E7',6608egrave: '\u00E8',6609eacute: '\u00E9',6610ecirc: '\u00EA',6611euml: '\u00EB',6612igrave: '\u00EC',6613iacute: '\u00ED',6614icirc: '\u00EE',6615iuml: '\u00EF',6616eth: '\u00F0',6617ntilde: '\u00F1',6618ograve: '\u00F2',6619oacute: '\u00F3',6620ocirc: '\u00F4',6621otilde: '\u00F5',6622ouml: '\u00F6',6623divide: '\u00F7',6624oslash: '\u00F8',6625ugrave: '\u00F9',6626uacute: '\u00FA',6627ucirc: '\u00FB',6628uuml: '\u00FC',6629yacute: '\u00FD',6630thorn: '\u00FE',6631yuml: '\u00FF',6632OElig: '\u0152',6633oelig: '\u0153',6634Scaron: '\u0160',6635scaron: '\u0161',6636Yuml: '\u0178',6637fnof: '\u0192',6638circ: '\u02C6',6639tilde: '\u02DC',6640Alpha: '\u0391',6641Beta: '\u0392',6642Gamma: '\u0393',6643Delta: '\u0394',6644Epsilon: '\u0395',6645Zeta: '\u0396',6646Eta: '\u0397',6647Theta: '\u0398',6648Iota: '\u0399',6649Kappa: '\u039A',6650Lambda: '\u039B',6651Mu: '\u039C',6652Nu: '\u039D',6653Xi: '\u039E',6654Omicron: '\u039F',6655Pi: '\u03A0',6656Rho: '\u03A1',6657Sigma: '\u03A3',6658Tau: '\u03A4',6659Upsilon: '\u03A5',6660Phi: '\u03A6',6661Chi: '\u03A7',6662Psi: '\u03A8',6663Omega: '\u03A9',6664alpha: '\u03B1',6665beta: '\u03B2',6666gamma: '\u03B3',6667delta: '\u03B4',6668epsilon: '\u03B5',6669zeta: '\u03B6',6670eta: '\u03B7',6671theta: '\u03B8',6672iota: '\u03B9',6673kappa: '\u03BA',6674lambda: '\u03BB',6675mu: '\u03BC',6676nu: '\u03BD',6677xi: '\u03BE',6678omicron: '\u03BF',6679pi: '\u03C0',6680rho: '\u03C1',6681sigmaf: '\u03C2',6682sigma: '\u03C3',6683tau: '\u03C4',6684upsilon: '\u03C5',6685phi: '\u03C6',6686chi: '\u03C7',6687psi: '\u03C8',6688omega: '\u03C9',6689thetasym: '\u03D1',6690upsih: '\u03D2',6691piv: '\u03D6',6692ensp: '\u2002',6693emsp: '\u2003',6694thinsp: '\u2009',6695zwnj: '\u200C',6696zwj: '\u200D',6697lrm: '\u200E',6698rlm: '\u200F',6699ndash: '\u2013',6700mdash: '\u2014',6701lsquo: '\u2018',6702rsquo: '\u2019',6703sbquo: '\u201A',6704ldquo: '\u201C',6705rdquo: '\u201D',6706bdquo: '\u201E',6707dagger: '\u2020',6708Dagger: '\u2021',6709bull: '\u2022',6710hellip: '\u2026',6711permil: '\u2030',6712prime: '\u2032',6713Prime: '\u2033',6714lsaquo: '\u2039',6715rsaquo: '\u203A',6716oline: '\u203E',6717frasl: '\u2044',6718euro: '\u20AC',6719image: '\u2111',6720weierp: '\u2118',6721real: '\u211C',6722trade: '\u2122',6723alefsym: '\u2135',6724larr: '\u2190',6725uarr: '\u2191',6726rarr: '\u2192',6727darr: '\u2193',6728harr: '\u2194',6729crarr: '\u21B5',6730lArr: '\u21D0',6731uArr: '\u21D1',6732rArr: '\u21D2',6733dArr: '\u21D3',6734hArr: '\u21D4',6735forall: '\u2200',6736part: '\u2202',6737exist: '\u2203',6738empty: '\u2205',6739nabla: '\u2207',6740isin: '\u2208',6741notin: '\u2209',6742ni: '\u220B',6743prod: '\u220F',6744sum: '\u2211',6745minus: '\u2212',6746lowast: '\u2217',6747radic: '\u221A',6748prop: '\u221D',6749infin: '\u221E',6750ang: '\u2220',6751and: '\u2227',6752or: '\u2228',6753cap: '\u2229',6754cup: '\u222A',6755'int': '\u222B',6756there4: '\u2234',6757sim: '\u223C',6758cong: '\u2245',6759asymp: '\u2248',6760ne: '\u2260',6761equiv: '\u2261',6762le: '\u2264',6763ge: '\u2265',6764sub: '\u2282',6765sup: '\u2283',6766nsub: '\u2284',6767sube: '\u2286',6768supe: '\u2287',6769oplus: '\u2295',6770otimes: '\u2297',6771perp: '\u22A5',6772sdot: '\u22C5',6773lceil: '\u2308',6774rceil: '\u2309',6775lfloor: '\u230A',6776rfloor: '\u230B',6777lang: '\u2329',6778rang: '\u232A',6779loz: '\u25CA',6780spades: '\u2660',6781clubs: '\u2663',6782hearts: '\u2665',6783diams: '\u2666'6784};67856786function getQualifiedXJSName(object) {6787if (object.type === Syntax.XJSIdentifier) {6788return object.name;6789}6790if (object.type === Syntax.XJSNamespacedName) {6791return object.namespace.name + ':' + object.name.name;6792}6793/* istanbul ignore else */6794if (object.type === Syntax.XJSMemberExpression) {6795return (6796getQualifiedXJSName(object.object) + '.' +6797getQualifiedXJSName(object.property)6798);6799}6800/* istanbul ignore next */6801throwUnexpected(object);6802}68036804function isXJSIdentifierStart(ch) {6805// exclude backslash (\)6806return (ch !== 92) && isIdentifierStart(ch);6807}68086809function isXJSIdentifierPart(ch) {6810// exclude backslash (\) and add hyphen (-)6811return (ch !== 92) && (ch === 45 || isIdentifierPart(ch));6812}68136814function scanXJSIdentifier() {6815var ch, start, value = '';68166817start = index;6818while (index < length) {6819ch = source.charCodeAt(index);6820if (!isXJSIdentifierPart(ch)) {6821break;6822}6823value += source[index++];6824}68256826return {6827type: Token.XJSIdentifier,6828value: value,6829lineNumber: lineNumber,6830lineStart: lineStart,6831range: [start, index]6832};6833}68346835function scanXJSEntity() {6836var ch, str = '', start = index, count = 0, code;6837ch = source[index];6838assert(ch === '&', 'Entity must start with an ampersand');6839index++;6840while (index < length && count++ < 10) {6841ch = source[index++];6842if (ch === ';') {6843break;6844}6845str += ch;6846}68476848// Well-formed entity (ending was found).6849if (ch === ';') {6850// Numeric entity.6851if (str[0] === '#') {6852if (str[1] === 'x') {6853code = +('0' + str.substr(1));6854} else {6855// Removing leading zeros in order to avoid treating as octal in old browsers.6856code = +str.substr(1).replace(Regex.LeadingZeros, '');6857}68586859if (!isNaN(code)) {6860return String.fromCharCode(code);6861}6862/* istanbul ignore else */6863} else if (XHTMLEntities[str]) {6864return XHTMLEntities[str];6865}6866}68676868// Treat non-entity sequences as regular text.6869index = start + 1;6870return '&';6871}68726873function scanXJSText(stopChars) {6874var ch, str = '', start;6875start = index;6876while (index < length) {6877ch = source[index];6878if (stopChars.indexOf(ch) !== -1) {6879break;6880}6881if (ch === '&') {6882str += scanXJSEntity();6883} else {6884index++;6885if (ch === '\r' && source[index] === '\n') {6886str += ch;6887ch = source[index];6888index++;6889}6890if (isLineTerminator(ch.charCodeAt(0))) {6891++lineNumber;6892lineStart = index;6893}6894str += ch;6895}6896}6897return {6898type: Token.XJSText,6899value: str,6900lineNumber: lineNumber,6901lineStart: lineStart,6902range: [start, index]6903};6904}69056906function scanXJSStringLiteral() {6907var innerToken, quote, start;69086909quote = source[index];6910assert((quote === '\'' || quote === '"'),6911'String literal must starts with a quote');69126913start = index;6914++index;69156916innerToken = scanXJSText([quote]);69176918if (quote !== source[index]) {6919throwError({}, Messages.UnexpectedToken, 'ILLEGAL');6920}69216922++index;69236924innerToken.range = [start, index];69256926return innerToken;6927}69286929/**6930* Between XJS opening and closing tags (e.g. <foo>HERE</foo>), anything that6931* is not another XJS tag and is not an expression wrapped by {} is text.6932*/6933function advanceXJSChild() {6934var ch = source.charCodeAt(index);69356936// { (123) and < (60)6937if (ch !== 123 && ch !== 60) {6938return scanXJSText(['<', '{']);6939}69406941return scanPunctuator();6942}69436944function parseXJSIdentifier() {6945var token, marker = markerCreate();69466947if (lookahead.type !== Token.XJSIdentifier) {6948throwUnexpected(lookahead);6949}69506951token = lex();6952return markerApply(marker, delegate.createXJSIdentifier(token.value));6953}69546955function parseXJSNamespacedName() {6956var namespace, name, marker = markerCreate();69576958namespace = parseXJSIdentifier();6959expect(':');6960name = parseXJSIdentifier();69616962return markerApply(marker, delegate.createXJSNamespacedName(namespace, name));6963}69646965function parseXJSMemberExpression() {6966var marker = markerCreate(),6967expr = parseXJSIdentifier();69686969while (match('.')) {6970lex();6971expr = markerApply(marker, delegate.createXJSMemberExpression(expr, parseXJSIdentifier()));6972}69736974return expr;6975}69766977function parseXJSElementName() {6978if (lookahead2().value === ':') {6979return parseXJSNamespacedName();6980}6981if (lookahead2().value === '.') {6982return parseXJSMemberExpression();6983}69846985return parseXJSIdentifier();6986}69876988function parseXJSAttributeName() {6989if (lookahead2().value === ':') {6990return parseXJSNamespacedName();6991}69926993return parseXJSIdentifier();6994}69956996function parseXJSAttributeValue() {6997var value, marker;6998if (match('{')) {6999value = parseXJSExpressionContainer();7000if (value.expression.type === Syntax.XJSEmptyExpression) {7001throwError(7002value,7003'XJS attributes must only be assigned a non-empty ' +7004'expression'7005);7006}7007} else if (match('<')) {7008value = parseXJSElement();7009} else if (lookahead.type === Token.XJSText) {7010marker = markerCreate();7011value = markerApply(marker, delegate.createLiteral(lex()));7012} else {7013throwError({}, Messages.InvalidXJSAttributeValue);7014}7015return value;7016}70177018function parseXJSEmptyExpression() {7019var marker = markerCreatePreserveWhitespace();7020while (source.charAt(index) !== '}') {7021index++;7022}7023return markerApply(marker, delegate.createXJSEmptyExpression());7024}70257026function parseXJSExpressionContainer() {7027var expression, origInXJSChild, origInXJSTag, marker = markerCreate();70287029origInXJSChild = state.inXJSChild;7030origInXJSTag = state.inXJSTag;7031state.inXJSChild = false;7032state.inXJSTag = false;70337034expect('{');70357036if (match('}')) {7037expression = parseXJSEmptyExpression();7038} else {7039expression = parseExpression();7040}70417042state.inXJSChild = origInXJSChild;7043state.inXJSTag = origInXJSTag;70447045expect('}');70467047return markerApply(marker, delegate.createXJSExpressionContainer(expression));7048}70497050function parseXJSSpreadAttribute() {7051var expression, origInXJSChild, origInXJSTag, marker = markerCreate();70527053origInXJSChild = state.inXJSChild;7054origInXJSTag = state.inXJSTag;7055state.inXJSChild = false;7056state.inXJSTag = false;70577058expect('{');7059expect('...');70607061expression = parseAssignmentExpression();70627063state.inXJSChild = origInXJSChild;7064state.inXJSTag = origInXJSTag;70657066expect('}');70677068return markerApply(marker, delegate.createXJSSpreadAttribute(expression));7069}70707071function parseXJSAttribute() {7072var name, marker;70737074if (match('{')) {7075return parseXJSSpreadAttribute();7076}70777078marker = markerCreate();70797080name = parseXJSAttributeName();70817082// HTML empty attribute7083if (match('=')) {7084lex();7085return markerApply(marker, delegate.createXJSAttribute(name, parseXJSAttributeValue()));7086}70877088return markerApply(marker, delegate.createXJSAttribute(name));7089}70907091function parseXJSChild() {7092var token, marker;7093if (match('{')) {7094token = parseXJSExpressionContainer();7095} else if (lookahead.type === Token.XJSText) {7096marker = markerCreatePreserveWhitespace();7097token = markerApply(marker, delegate.createLiteral(lex()));7098} else {7099token = parseXJSElement();7100}7101return token;7102}71037104function parseXJSClosingElement() {7105var name, origInXJSChild, origInXJSTag, marker = markerCreate();7106origInXJSChild = state.inXJSChild;7107origInXJSTag = state.inXJSTag;7108state.inXJSChild = false;7109state.inXJSTag = true;7110expect('<');7111expect('/');7112name = parseXJSElementName();7113// Because advance() (called by lex() called by expect()) expects there7114// to be a valid token after >, it needs to know whether to look for a7115// standard JS token or an XJS text node7116state.inXJSChild = origInXJSChild;7117state.inXJSTag = origInXJSTag;7118expect('>');7119return markerApply(marker, delegate.createXJSClosingElement(name));7120}71217122function parseXJSOpeningElement() {7123var name, attribute, attributes = [], selfClosing = false, origInXJSChild, origInXJSTag, marker = markerCreate();71247125origInXJSChild = state.inXJSChild;7126origInXJSTag = state.inXJSTag;7127state.inXJSChild = false;7128state.inXJSTag = true;71297130expect('<');71317132name = parseXJSElementName();71337134while (index < length &&7135lookahead.value !== '/' &&7136lookahead.value !== '>') {7137attributes.push(parseXJSAttribute());7138}71397140state.inXJSTag = origInXJSTag;71417142if (lookahead.value === '/') {7143expect('/');7144// Because advance() (called by lex() called by expect()) expects7145// there to be a valid token after >, it needs to know whether to7146// look for a standard JS token or an XJS text node7147state.inXJSChild = origInXJSChild;7148expect('>');7149selfClosing = true;7150} else {7151state.inXJSChild = true;7152expect('>');7153}7154return markerApply(marker, delegate.createXJSOpeningElement(name, attributes, selfClosing));7155}71567157function parseXJSElement() {7158var openingElement, closingElement = null, children = [], origInXJSChild, origInXJSTag, marker = markerCreate();71597160origInXJSChild = state.inXJSChild;7161origInXJSTag = state.inXJSTag;7162openingElement = parseXJSOpeningElement();71637164if (!openingElement.selfClosing) {7165while (index < length) {7166state.inXJSChild = false; // Call lookahead2() with inXJSChild = false because </ should not be considered in the child7167if (lookahead.value === '<' && lookahead2().value === '/') {7168break;7169}7170state.inXJSChild = true;7171children.push(parseXJSChild());7172}7173state.inXJSChild = origInXJSChild;7174state.inXJSTag = origInXJSTag;7175closingElement = parseXJSClosingElement();7176if (getQualifiedXJSName(closingElement.name) !== getQualifiedXJSName(openingElement.name)) {7177throwError({}, Messages.ExpectedXJSClosingTag, getQualifiedXJSName(openingElement.name));7178}7179}71807181// When (erroneously) writing two adjacent tags like7182//7183// var x = <div>one</div><div>two</div>;7184//7185// the default error message is a bit incomprehensible. Since it's7186// rarely (never?) useful to write a less-than sign after an XJS7187// element, we disallow it here in the parser in order to provide a7188// better error message. (In the rare case that the less-than operator7189// was intended, the left tag can be wrapped in parentheses.)7190if (!origInXJSChild && match('<')) {7191throwError(lookahead, Messages.AdjacentXJSElements);7192}71937194return markerApply(marker, delegate.createXJSElement(openingElement, closingElement, children));7195}71967197function parseTypeAlias() {7198var id, marker = markerCreate(), typeParameters = null, right;7199expectContextualKeyword('type');7200id = parseVariableIdentifier();7201if (match('<')) {7202typeParameters = parseTypeParameterDeclaration();7203}7204expect('=');7205right = parseType();7206consumeSemicolon();7207return markerApply(marker, delegate.createTypeAlias(id, typeParameters, right));7208}72097210function parseInterfaceExtends() {7211var marker = markerCreate(), id, typeParameters = null;72127213id = parseVariableIdentifier();7214if (match('<')) {7215typeParameters = parseTypeParameterInstantiation();7216}72177218return markerApply(marker, delegate.createInterfaceExtends(7219id,7220typeParameters7221));7222}72237224function parseInterfaceish(marker, allowStatic) {7225var body, bodyMarker, extended = [], id,7226typeParameters = null;72277228id = parseVariableIdentifier();7229if (match('<')) {7230typeParameters = parseTypeParameterDeclaration();7231}72327233if (matchKeyword('extends')) {7234expectKeyword('extends');72357236while (index < length) {7237extended.push(parseInterfaceExtends());7238if (!match(',')) {7239break;7240}7241expect(',');7242}7243}72447245bodyMarker = markerCreate();7246body = markerApply(bodyMarker, parseObjectType(allowStatic));72477248return markerApply(marker, delegate.createInterface(7249id,7250typeParameters,7251body,7252extended7253));7254}72557256function parseInterface() {7257var body, bodyMarker, extended = [], id, marker = markerCreate(),7258typeParameters = null;72597260expectContextualKeyword('interface');7261return parseInterfaceish(marker, /* allowStatic */false);7262}72637264function parseDeclareClass() {7265var marker = markerCreate(), ret;7266expectContextualKeyword('declare');7267expectKeyword('class');72687269ret = parseInterfaceish(marker, /* allowStatic */true);7270ret.type = Syntax.DeclareClass;7271return ret;7272}72737274function parseDeclareFunction() {7275var id, idMarker,7276marker = markerCreate(), params, returnType, rest, tmp,7277typeParameters = null, value, valueMarker;72787279expectContextualKeyword('declare');7280expectKeyword('function');7281idMarker = markerCreate();7282id = parseVariableIdentifier();72837284valueMarker = markerCreate();7285if (match('<')) {7286typeParameters = parseTypeParameterDeclaration();7287}7288expect('(');7289tmp = parseFunctionTypeParams();7290params = tmp.params;7291rest = tmp.rest;7292expect(')');72937294expect(':');7295returnType = parseType();72967297value = markerApply(valueMarker, delegate.createFunctionTypeAnnotation(7298params,7299returnType,7300rest,7301typeParameters7302));73037304id.typeAnnotation = markerApply(valueMarker, delegate.createTypeAnnotation(7305value7306));7307markerApply(idMarker, id);73087309consumeSemicolon();73107311return markerApply(marker, delegate.createDeclareFunction(7312id7313));7314}73157316function parseDeclareVariable() {7317var id, marker = markerCreate();7318expectContextualKeyword('declare');7319expectKeyword('var');7320id = parseTypeAnnotatableIdentifier();73217322consumeSemicolon();73237324return markerApply(marker, delegate.createDeclareVariable(7325id7326));7327}73287329function parseDeclareModule() {7330var body = [], bodyMarker, id, idMarker, marker = markerCreate(), token;7331expectContextualKeyword('declare');7332expectContextualKeyword('module');73337334if (lookahead.type === Token.StringLiteral) {7335if (strict && lookahead.octal) {7336throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);7337}7338idMarker = markerCreate();7339id = markerApply(idMarker, delegate.createLiteral(lex()));7340} else {7341id = parseVariableIdentifier();7342}73437344bodyMarker = markerCreate();7345expect('{');7346while (index < length && !match('}')) {7347token = lookahead2();7348switch (token.value) {7349case 'class':7350body.push(parseDeclareClass());7351break;7352case 'function':7353body.push(parseDeclareFunction());7354break;7355case 'var':7356body.push(parseDeclareVariable());7357break;7358default:7359throwUnexpected(lookahead);7360}7361}7362expect('}');73637364return markerApply(marker, delegate.createDeclareModule(7365id,7366markerApply(bodyMarker, delegate.createBlockStatement(body))7367));7368}73697370function collectToken() {7371var start, loc, token, range, value, entry;73727373/* istanbul ignore else */7374if (!state.inXJSChild) {7375skipComment();7376}73777378start = index;7379loc = {7380start: {7381line: lineNumber,7382column: index - lineStart7383}7384};73857386token = extra.advance();7387loc.end = {7388line: lineNumber,7389column: index - lineStart7390};73917392if (token.type !== Token.EOF) {7393range = [token.range[0], token.range[1]];7394value = source.slice(token.range[0], token.range[1]);7395entry = {7396type: TokenName[token.type],7397value: value,7398range: range,7399loc: loc7400};7401if (token.regex) {7402entry.regex = {7403pattern: token.regex.pattern,7404flags: token.regex.flags7405};7406}7407extra.tokens.push(entry);7408}74097410return token;7411}74127413function collectRegex() {7414var pos, loc, regex, token;74157416skipComment();74177418pos = index;7419loc = {7420start: {7421line: lineNumber,7422column: index - lineStart7423}7424};74257426regex = extra.scanRegExp();7427loc.end = {7428line: lineNumber,7429column: index - lineStart7430};74317432if (!extra.tokenize) {7433/* istanbul ignore next */7434// Pop the previous token, which is likely '/' or '/='7435if (extra.tokens.length > 0) {7436token = extra.tokens[extra.tokens.length - 1];7437if (token.range[0] === pos && token.type === 'Punctuator') {7438if (token.value === '/' || token.value === '/=') {7439extra.tokens.pop();7440}7441}7442}74437444extra.tokens.push({7445type: 'RegularExpression',7446value: regex.literal,7447regex: regex.regex,7448range: [pos, index],7449loc: loc7450});7451}74527453return regex;7454}74557456function filterTokenLocation() {7457var i, entry, token, tokens = [];74587459for (i = 0; i < extra.tokens.length; ++i) {7460entry = extra.tokens[i];7461token = {7462type: entry.type,7463value: entry.value7464};7465if (entry.regex) {7466token.regex = {7467pattern: entry.regex.pattern,7468flags: entry.regex.flags7469};7470}7471if (extra.range) {7472token.range = entry.range;7473}7474if (extra.loc) {7475token.loc = entry.loc;7476}7477tokens.push(token);7478}74797480extra.tokens = tokens;7481}74827483function patch() {7484if (extra.comments) {7485extra.skipComment = skipComment;7486skipComment = scanComment;7487}74887489if (typeof extra.tokens !== 'undefined') {7490extra.advance = advance;7491extra.scanRegExp = scanRegExp;74927493advance = collectToken;7494scanRegExp = collectRegex;7495}7496}74977498function unpatch() {7499if (typeof extra.skipComment === 'function') {7500skipComment = extra.skipComment;7501}75027503if (typeof extra.scanRegExp === 'function') {7504advance = extra.advance;7505scanRegExp = extra.scanRegExp;7506}7507}75087509// This is used to modify the delegate.75107511function extend(object, properties) {7512var entry, result = {};75137514for (entry in object) {7515/* istanbul ignore else */7516if (object.hasOwnProperty(entry)) {7517result[entry] = object[entry];7518}7519}75207521for (entry in properties) {7522/* istanbul ignore else */7523if (properties.hasOwnProperty(entry)) {7524result[entry] = properties[entry];7525}7526}75277528return result;7529}75307531function tokenize(code, options) {7532var toString,7533token,7534tokens;75357536toString = String;7537if (typeof code !== 'string' && !(code instanceof String)) {7538code = toString(code);7539}75407541delegate = SyntaxTreeDelegate;7542source = code;7543index = 0;7544lineNumber = (source.length > 0) ? 1 : 0;7545lineStart = 0;7546length = source.length;7547lookahead = null;7548state = {7549allowKeyword: true,7550allowIn: true,7551labelSet: new StringMap(),7552inFunctionBody: false,7553inIteration: false,7554inSwitch: false,7555lastCommentStart: -17556};75577558extra = {};75597560// Options matching.7561options = options || {};75627563// Of course we collect tokens here.7564options.tokens = true;7565extra.tokens = [];7566extra.tokenize = true;7567// The following two fields are necessary to compute the Regex tokens.7568extra.openParenToken = -1;7569extra.openCurlyToken = -1;75707571extra.range = (typeof options.range === 'boolean') && options.range;7572extra.loc = (typeof options.loc === 'boolean') && options.loc;75737574if (typeof options.comment === 'boolean' && options.comment) {7575extra.comments = [];7576}7577if (typeof options.tolerant === 'boolean' && options.tolerant) {7578extra.errors = [];7579}75807581patch();75827583try {7584peek();7585if (lookahead.type === Token.EOF) {7586return extra.tokens;7587}75887589token = lex();7590while (lookahead.type !== Token.EOF) {7591try {7592token = lex();7593} catch (lexError) {7594token = lookahead;7595if (extra.errors) {7596extra.errors.push(lexError);7597// We have to break on the first error7598// to avoid infinite loops.7599break;7600} else {7601throw lexError;7602}7603}7604}76057606filterTokenLocation();7607tokens = extra.tokens;7608if (typeof extra.comments !== 'undefined') {7609tokens.comments = extra.comments;7610}7611if (typeof extra.errors !== 'undefined') {7612tokens.errors = extra.errors;7613}7614} catch (e) {7615throw e;7616} finally {7617unpatch();7618extra = {};7619}7620return tokens;7621}76227623function parse(code, options) {7624var program, toString;76257626toString = String;7627if (typeof code !== 'string' && !(code instanceof String)) {7628code = toString(code);7629}76307631delegate = SyntaxTreeDelegate;7632source = code;7633index = 0;7634lineNumber = (source.length > 0) ? 1 : 0;7635lineStart = 0;7636length = source.length;7637lookahead = null;7638state = {7639allowKeyword: false,7640allowIn: true,7641labelSet: new StringMap(),7642parenthesizedCount: 0,7643inFunctionBody: false,7644inIteration: false,7645inSwitch: false,7646inXJSChild: false,7647inXJSTag: false,7648inType: false,7649lastCommentStart: -1,7650yieldAllowed: false,7651awaitAllowed: false7652};76537654extra = {};7655if (typeof options !== 'undefined') {7656extra.range = (typeof options.range === 'boolean') && options.range;7657extra.loc = (typeof options.loc === 'boolean') && options.loc;7658extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;76597660if (extra.loc && options.source !== null && options.source !== undefined) {7661delegate = extend(delegate, {7662'postProcess': function (node) {7663node.loc.source = toString(options.source);7664return node;7665}7666});7667}76687669if (options.sourceType === 'module') {7670extra.isModule = true;7671}7672if (typeof options.tokens === 'boolean' && options.tokens) {7673extra.tokens = [];7674}7675if (typeof options.comment === 'boolean' && options.comment) {7676extra.comments = [];7677}7678if (typeof options.tolerant === 'boolean' && options.tolerant) {7679extra.errors = [];7680}7681if (extra.attachComment) {7682extra.range = true;7683extra.comments = [];7684extra.bottomRightStack = [];7685extra.trailingComments = [];7686extra.leadingComments = [];7687}7688}76897690patch();7691try {7692program = parseProgram();7693if (typeof extra.comments !== 'undefined') {7694program.comments = extra.comments;7695}7696if (typeof extra.tokens !== 'undefined') {7697filterTokenLocation();7698program.tokens = extra.tokens;7699}7700if (typeof extra.errors !== 'undefined') {7701program.errors = extra.errors;7702}7703} catch (e) {7704throw e;7705} finally {7706unpatch();7707extra = {};7708}77097710return program;7711}77127713// Sync with *.json manifests.7714exports.version = '10001.1.0-dev-harmony-fb';77157716exports.tokenize = tokenize;77177718exports.parse = parse;77197720// Deep copy.7721/* istanbul ignore next */7722exports.Syntax = (function () {7723var name, types = {};77247725if (typeof Object.create === 'function') {7726types = Object.create(null);7727}77287729for (name in Syntax) {7730if (Syntax.hasOwnProperty(name)) {7731types[name] = Syntax[name];7732}7733}77347735if (typeof Object.freeze === 'function') {7736Object.freeze(types);7737}77387739return types;7740}());77417742}));7743/* vim: set sw=4 ts=4 et tw=80 : */774477457746