react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / jstransform / node_modules / esprima-fb / esprima.js
81153 views/*1Copyright (C) 2013 Ariya Hidayat <[email protected]>2Copyright (C) 2013 Thaddee Tyl <[email protected]>3Copyright (C) 2012 Ariya Hidayat <[email protected]>4Copyright (C) 2012 Mathias Bynens <[email protected]>5Copyright (C) 2012 Joost-Wim Boekesteijn <[email protected]>6Copyright (C) 2012 Kris Kowal <[email protected]>7Copyright (C) 2012 Yusuke Suzuki <[email protected]>8Copyright (C) 2012 Arpad Borsos <[email protected]>9Copyright (C) 2011 Ariya Hidayat <[email protected]>1011Redistribution and use in source and binary forms, with or without12modification, are permitted provided that the following conditions are met:1314* Redistributions of source code must retain the above copyright15notice, this list of conditions and the following disclaimer.16* Redistributions in binary form must reproduce the above copyright17notice, this list of conditions and the following disclaimer in the18documentation and/or other materials provided with the distribution.1920THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY24DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF29THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132/*jslint bitwise:true plusplus:true */33/*global esprima:true, define:true, exports:true, window: true,34throwError: true, generateStatement: true, peek: true,35parseAssignmentExpression: true, parseBlock: true,36parseClassExpression: true, parseClassDeclaration: true, parseExpression: true,37parseDeclareClass: true, parseDeclareFunction: true,38parseDeclareModule: true, parseDeclareVariable: true,39parseForStatement: true,40parseFunctionDeclaration: true, parseFunctionExpression: true,41parseFunctionSourceElements: true, parseVariableIdentifier: true,42parseImportSpecifier: true, parseInterface: true,43parseLeftHandSideExpression: true, parseParams: true, validateParam: true,44parseSpreadOrAssignmentExpression: true,45parseStatement: true, parseSourceElement: true, parseConciseBody: true,46advanceXJSChild: true, isXJSIdentifierStart: true, isXJSIdentifierPart: true,47scanXJSStringLiteral: true, scanXJSIdentifier: true,48parseXJSAttributeValue: true, parseXJSChild: true, parseXJSElement: true, parseXJSExpressionContainer: true, parseXJSEmptyExpression: true,49parseFunctionTypeParam: true,50parsePrimaryType: true,51parseTypeAlias: true,52parseType: true, parseTypeAnnotatableIdentifier: true, parseTypeAnnotation: true,53parseYieldExpression: true, parseAwaitExpression: true54*/5556(function (root, factory) {57'use strict';5859// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,60// Rhino, and plain browser loading.61if (typeof define === 'function' && define.amd) {62define(['exports'], factory);63} else if (typeof exports !== 'undefined') {64factory(exports);65} else {66factory((root.esprima = {}));67}68}(this, function (exports) {69'use strict';7071var Token,72TokenName,73FnExprTokens,74Syntax,75PropertyKind,76Messages,77Regex,78SyntaxTreeDelegate,79XHTMLEntities,80ClassPropertyType,81source,82strict,83index,84lineNumber,85lineStart,86length,87delegate,88lookahead,89state,90extra;9192Token = {93BooleanLiteral: 1,94EOF: 2,95Identifier: 3,96Keyword: 4,97NullLiteral: 5,98NumericLiteral: 6,99Punctuator: 7,100StringLiteral: 8,101RegularExpression: 9,102Template: 10,103XJSIdentifier: 11,104XJSText: 12105};106107TokenName = {};108TokenName[Token.BooleanLiteral] = 'Boolean';109TokenName[Token.EOF] = '<end>';110TokenName[Token.Identifier] = 'Identifier';111TokenName[Token.Keyword] = 'Keyword';112TokenName[Token.NullLiteral] = 'Null';113TokenName[Token.NumericLiteral] = 'Numeric';114TokenName[Token.Punctuator] = 'Punctuator';115TokenName[Token.StringLiteral] = 'String';116TokenName[Token.XJSIdentifier] = 'XJSIdentifier';117TokenName[Token.XJSText] = 'XJSText';118TokenName[Token.RegularExpression] = 'RegularExpression';119120// A function following one of those tokens is an expression.121FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',122'return', 'case', 'delete', 'throw', 'void',123// assignment operators124'=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',125'&=', '|=', '^=', ',',126// binary/unary operators127'+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',128'|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',129'<=', '<', '>', '!=', '!=='];130131Syntax = {132AnyTypeAnnotation: 'AnyTypeAnnotation',133ArrayExpression: 'ArrayExpression',134ArrayPattern: 'ArrayPattern',135ArrayTypeAnnotation: 'ArrayTypeAnnotation',136ArrowFunctionExpression: 'ArrowFunctionExpression',137AssignmentExpression: 'AssignmentExpression',138BinaryExpression: 'BinaryExpression',139BlockStatement: 'BlockStatement',140BooleanTypeAnnotation: 'BooleanTypeAnnotation',141BreakStatement: 'BreakStatement',142CallExpression: 'CallExpression',143CatchClause: 'CatchClause',144ClassBody: 'ClassBody',145ClassDeclaration: 'ClassDeclaration',146ClassExpression: 'ClassExpression',147ClassImplements: 'ClassImplements',148ClassProperty: 'ClassProperty',149ComprehensionBlock: 'ComprehensionBlock',150ComprehensionExpression: 'ComprehensionExpression',151ConditionalExpression: 'ConditionalExpression',152ContinueStatement: 'ContinueStatement',153DebuggerStatement: 'DebuggerStatement',154DeclareClass: 'DeclareClass',155DeclareFunction: 'DeclareFunction',156DeclareModule: 'DeclareModule',157DeclareVariable: 'DeclareVariable',158DoWhileStatement: 'DoWhileStatement',159EmptyStatement: 'EmptyStatement',160ExportDeclaration: 'ExportDeclaration',161ExportBatchSpecifier: 'ExportBatchSpecifier',162ExportSpecifier: 'ExportSpecifier',163ExpressionStatement: 'ExpressionStatement',164ForInStatement: 'ForInStatement',165ForOfStatement: 'ForOfStatement',166ForStatement: 'ForStatement',167FunctionDeclaration: 'FunctionDeclaration',168FunctionExpression: 'FunctionExpression',169FunctionTypeAnnotation: 'FunctionTypeAnnotation',170FunctionTypeParam: 'FunctionTypeParam',171GenericTypeAnnotation: 'GenericTypeAnnotation',172Identifier: 'Identifier',173IfStatement: 'IfStatement',174ImportDeclaration: 'ImportDeclaration',175ImportDefaultSpecifier: 'ImportDefaultSpecifier',176ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',177ImportSpecifier: 'ImportSpecifier',178InterfaceDeclaration: 'InterfaceDeclaration',179InterfaceExtends: 'InterfaceExtends',180IntersectionTypeAnnotation: 'IntersectionTypeAnnotation',181LabeledStatement: 'LabeledStatement',182Literal: 'Literal',183LogicalExpression: 'LogicalExpression',184MemberExpression: 'MemberExpression',185MethodDefinition: 'MethodDefinition',186ModuleSpecifier: 'ModuleSpecifier',187NewExpression: 'NewExpression',188NullableTypeAnnotation: 'NullableTypeAnnotation',189NumberTypeAnnotation: 'NumberTypeAnnotation',190ObjectExpression: 'ObjectExpression',191ObjectPattern: 'ObjectPattern',192ObjectTypeAnnotation: 'ObjectTypeAnnotation',193ObjectTypeCallProperty: 'ObjectTypeCallProperty',194ObjectTypeIndexer: 'ObjectTypeIndexer',195ObjectTypeProperty: 'ObjectTypeProperty',196Program: 'Program',197Property: 'Property',198QualifiedTypeIdentifier: 'QualifiedTypeIdentifier',199ReturnStatement: 'ReturnStatement',200SequenceExpression: 'SequenceExpression',201SpreadElement: 'SpreadElement',202SpreadProperty: 'SpreadProperty',203StringLiteralTypeAnnotation: 'StringLiteralTypeAnnotation',204StringTypeAnnotation: 'StringTypeAnnotation',205SwitchCase: 'SwitchCase',206SwitchStatement: 'SwitchStatement',207TaggedTemplateExpression: 'TaggedTemplateExpression',208TemplateElement: 'TemplateElement',209TemplateLiteral: 'TemplateLiteral',210ThisExpression: 'ThisExpression',211ThrowStatement: 'ThrowStatement',212TupleTypeAnnotation: 'TupleTypeAnnotation',213TryStatement: 'TryStatement',214TypeAlias: 'TypeAlias',215TypeAnnotation: 'TypeAnnotation',216TypeofTypeAnnotation: 'TypeofTypeAnnotation',217TypeParameterDeclaration: 'TypeParameterDeclaration',218TypeParameterInstantiation: 'TypeParameterInstantiation',219UnaryExpression: 'UnaryExpression',220UnionTypeAnnotation: 'UnionTypeAnnotation',221UpdateExpression: 'UpdateExpression',222VariableDeclaration: 'VariableDeclaration',223VariableDeclarator: 'VariableDeclarator',224VoidTypeAnnotation: 'VoidTypeAnnotation',225WhileStatement: 'WhileStatement',226WithStatement: 'WithStatement',227XJSIdentifier: 'XJSIdentifier',228XJSNamespacedName: 'XJSNamespacedName',229XJSMemberExpression: 'XJSMemberExpression',230XJSEmptyExpression: 'XJSEmptyExpression',231XJSExpressionContainer: 'XJSExpressionContainer',232XJSElement: 'XJSElement',233XJSClosingElement: 'XJSClosingElement',234XJSOpeningElement: 'XJSOpeningElement',235XJSAttribute: 'XJSAttribute',236XJSSpreadAttribute: 'XJSSpreadAttribute',237XJSText: 'XJSText',238YieldExpression: 'YieldExpression',239AwaitExpression: 'AwaitExpression'240};241242PropertyKind = {243Data: 1,244Get: 2,245Set: 4246};247248ClassPropertyType = {249'static': 'static',250prototype: 'prototype'251};252253// Error messages should be identical to V8.254Messages = {255UnexpectedToken: 'Unexpected token %0',256UnexpectedNumber: 'Unexpected number',257UnexpectedString: 'Unexpected string',258UnexpectedIdentifier: 'Unexpected identifier',259UnexpectedReserved: 'Unexpected reserved word',260UnexpectedTemplate: 'Unexpected quasi %0',261UnexpectedEOS: 'Unexpected end of input',262NewlineAfterThrow: 'Illegal newline after throw',263InvalidRegExp: 'Invalid regular expression',264UnterminatedRegExp: 'Invalid regular expression: missing /',265InvalidLHSInAssignment: 'Invalid left-hand side in assignment',266InvalidLHSInFormalsList: 'Invalid left-hand side in formals list',267InvalidLHSInForIn: 'Invalid left-hand side in for-in',268MultipleDefaultsInSwitch: 'More than one default clause in switch statement',269NoCatchOrFinally: 'Missing catch or finally after try',270UnknownLabel: 'Undefined label \'%0\'',271Redeclaration: '%0 \'%1\' has already been declared',272IllegalContinue: 'Illegal continue statement',273IllegalBreak: 'Illegal break statement',274IllegalDuplicateClassProperty: 'Illegal duplicate property in class definition',275IllegalReturn: 'Illegal return statement',276IllegalSpread: 'Illegal spread element',277StrictModeWith: 'Strict mode code may not include a with statement',278StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',279StrictVarName: 'Variable name may not be eval or arguments in strict mode',280StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',281StrictParamDupe: 'Strict mode function may not have duplicate parameter names',282ParameterAfterRestParameter: 'Rest parameter must be final parameter of an argument list',283DefaultRestParameter: 'Rest parameter can not have a default value',284ElementAfterSpreadElement: 'Spread must be the final element of an element list',285PropertyAfterSpreadProperty: 'A rest property must be the final property of an object literal',286ObjectPatternAsRestParameter: 'Invalid rest parameter',287ObjectPatternAsSpread: 'Invalid spread argument',288StrictFunctionName: 'Function name may not be eval or arguments in strict mode',289StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',290StrictDelete: 'Delete of an unqualified identifier in strict mode.',291StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',292AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',293AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',294StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',295StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',296StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',297StrictReservedWord: 'Use of future reserved word in strict mode',298MissingFromClause: 'Missing from clause',299NoAsAfterImportNamespace: 'Missing as after import *',300InvalidModuleSpecifier: 'Invalid module specifier',301NoUnintializedConst: 'Const must be initialized',302ComprehensionRequiresBlock: 'Comprehension must have at least one block',303ComprehensionError: 'Comprehension Error',304EachNotAllowed: 'Each is not supported',305InvalidXJSAttributeValue: 'XJS value should be either an expression or a quoted XJS text',306ExpectedXJSClosingTag: 'Expected corresponding XJS closing tag for %0',307AdjacentXJSElements: 'Adjacent XJS elements must be wrapped in an enclosing tag',308ConfusedAboutFunctionType: 'Unexpected token =>. It looks like ' +309'you are trying to write a function type, but you ended up ' +310'writing a grouped type followed by an =>, which is a syntax ' +311'error. Remember, function type parameters are named so function ' +312'types look like (name1: type1, name2: type2) => returnType. You ' +313'probably wrote (type1) => returnType'314};315316// See also tools/generate-unicode-regex.py.317Regex = {318NonAsciiIdentifierStart: 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]'),319NonAsciiIdentifierPart: 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]'),320LeadingZeros: new RegExp('^0+(?!$)')321};322323// Ensure the condition is true, otherwise throw an error.324// This is only to have a better contract semantic, i.e. another safety net325// to catch a logic error. The condition shall be fulfilled in normal case.326// Do NOT use this to enforce a certain condition on any user input.327328function assert(condition, message) {329if (!condition) {330throw new Error('ASSERT: ' + message);331}332}333334function isDecimalDigit(ch) {335return (ch >= 48 && ch <= 57); // 0..9336}337338function isHexDigit(ch) {339return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;340}341342function isOctalDigit(ch) {343return '01234567'.indexOf(ch) >= 0;344}345346347// 7.2 White Space348349function isWhiteSpace(ch) {350return (ch === 32) || // space351(ch === 9) || // tab352(ch === 0xB) ||353(ch === 0xC) ||354(ch === 0xA0) ||355(ch >= 0x1680 && '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'.indexOf(String.fromCharCode(ch)) > 0);356}357358// 7.3 Line Terminators359360function isLineTerminator(ch) {361return (ch === 10) || (ch === 13) || (ch === 0x2028) || (ch === 0x2029);362}363364// 7.6 Identifier Names and Identifiers365366function isIdentifierStart(ch) {367return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)368(ch >= 65 && ch <= 90) || // A..Z369(ch >= 97 && ch <= 122) || // a..z370(ch === 92) || // \ (backslash)371((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));372}373374function isIdentifierPart(ch) {375return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)376(ch >= 65 && ch <= 90) || // A..Z377(ch >= 97 && ch <= 122) || // a..z378(ch >= 48 && ch <= 57) || // 0..9379(ch === 92) || // \ (backslash)380((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));381}382383// 7.6.1.2 Future Reserved Words384385function isFutureReservedWord(id) {386switch (id) {387case 'class':388case 'enum':389case 'export':390case 'extends':391case 'import':392case 'super':393return true;394default:395return false;396}397}398399function isStrictModeReservedWord(id) {400switch (id) {401case 'implements':402case 'interface':403case 'package':404case 'private':405case 'protected':406case 'public':407case 'static':408case 'yield':409case 'let':410return true;411default:412return false;413}414}415416function isRestrictedWord(id) {417return id === 'eval' || id === 'arguments';418}419420// 7.6.1.1 Keywords421422function isKeyword(id) {423if (strict && isStrictModeReservedWord(id)) {424return true;425}426427// 'const' is specialized as Keyword in V8.428// 'yield' is only treated as a keyword in strict mode.429// 'let' is for compatiblity with SpiderMonkey and ES.next.430// Some others are from future reserved words.431432switch (id.length) {433case 2:434return (id === 'if') || (id === 'in') || (id === 'do');435case 3:436return (id === 'var') || (id === 'for') || (id === 'new') ||437(id === 'try') || (id === 'let');438case 4:439return (id === 'this') || (id === 'else') || (id === 'case') ||440(id === 'void') || (id === 'with') || (id === 'enum');441case 5:442return (id === 'while') || (id === 'break') || (id === 'catch') ||443(id === 'throw') || (id === 'const') ||444(id === 'class') || (id === 'super');445case 6:446return (id === 'return') || (id === 'typeof') || (id === 'delete') ||447(id === 'switch') || (id === 'export') || (id === 'import');448case 7:449return (id === 'default') || (id === 'finally') || (id === 'extends');450case 8:451return (id === 'function') || (id === 'continue') || (id === 'debugger');452case 10:453return (id === 'instanceof');454default:455return false;456}457}458459// 7.4 Comments460461function skipComment() {462var ch, blockComment, lineComment;463464blockComment = false;465lineComment = false;466467while (index < length) {468ch = source.charCodeAt(index);469470if (lineComment) {471++index;472if (isLineTerminator(ch)) {473lineComment = false;474if (ch === 13 && source.charCodeAt(index) === 10) {475++index;476}477++lineNumber;478lineStart = index;479}480} else if (blockComment) {481if (isLineTerminator(ch)) {482if (ch === 13) {483++index;484}485if (ch !== 13 || source.charCodeAt(index) === 10) {486++lineNumber;487++index;488lineStart = index;489if (index >= length) {490throwError({}, Messages.UnexpectedToken, 'ILLEGAL');491}492}493} else {494ch = source.charCodeAt(index++);495if (index >= length) {496throwError({}, Messages.UnexpectedToken, 'ILLEGAL');497}498// Block comment ends with '*/' (char #42, char #47).499if (ch === 42) {500ch = source.charCodeAt(index);501if (ch === 47) {502++index;503blockComment = false;504}505}506}507} else if (ch === 47) {508ch = source.charCodeAt(index + 1);509// Line comment starts with '//' (char #47, char #47).510if (ch === 47) {511index += 2;512lineComment = true;513} else if (ch === 42) {514// Block comment starts with '/*' (char #47, char #42).515index += 2;516blockComment = true;517if (index >= length) {518throwError({}, Messages.UnexpectedToken, 'ILLEGAL');519}520} else {521break;522}523} else if (isWhiteSpace(ch)) {524++index;525} else if (isLineTerminator(ch)) {526++index;527if (ch === 13 && source.charCodeAt(index) === 10) {528++index;529}530++lineNumber;531lineStart = index;532} else {533break;534}535}536}537538function scanHexEscape(prefix) {539var i, len, ch, code = 0;540541len = (prefix === 'u') ? 4 : 2;542for (i = 0; i < len; ++i) {543if (index < length && isHexDigit(source[index])) {544ch = source[index++];545code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());546} else {547return '';548}549}550return String.fromCharCode(code);551}552553function scanUnicodeCodePointEscape() {554var ch, code, cu1, cu2;555556ch = source[index];557code = 0;558559// At least, one hex digit is required.560if (ch === '}') {561throwError({}, Messages.UnexpectedToken, 'ILLEGAL');562}563564while (index < length) {565ch = source[index++];566if (!isHexDigit(ch)) {567break;568}569code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());570}571572if (code > 0x10FFFF || ch !== '}') {573throwError({}, Messages.UnexpectedToken, 'ILLEGAL');574}575576// UTF-16 Encoding577if (code <= 0xFFFF) {578return String.fromCharCode(code);579}580cu1 = ((code - 0x10000) >> 10) + 0xD800;581cu2 = ((code - 0x10000) & 1023) + 0xDC00;582return String.fromCharCode(cu1, cu2);583}584585function getEscapedIdentifier() {586var ch, id;587588ch = source.charCodeAt(index++);589id = String.fromCharCode(ch);590591// '\u' (char #92, char #117) denotes an escaped character.592if (ch === 92) {593if (source.charCodeAt(index) !== 117) {594throwError({}, Messages.UnexpectedToken, 'ILLEGAL');595}596++index;597ch = scanHexEscape('u');598if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {599throwError({}, Messages.UnexpectedToken, 'ILLEGAL');600}601id = ch;602}603604while (index < length) {605ch = source.charCodeAt(index);606if (!isIdentifierPart(ch)) {607break;608}609++index;610id += String.fromCharCode(ch);611612// '\u' (char #92, char #117) denotes an escaped character.613if (ch === 92) {614id = id.substr(0, id.length - 1);615if (source.charCodeAt(index) !== 117) {616throwError({}, Messages.UnexpectedToken, 'ILLEGAL');617}618++index;619ch = scanHexEscape('u');620if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {621throwError({}, Messages.UnexpectedToken, 'ILLEGAL');622}623id += ch;624}625}626627return id;628}629630function getIdentifier() {631var start, ch;632633start = index++;634while (index < length) {635ch = source.charCodeAt(index);636if (ch === 92) {637// Blackslash (char #92) marks Unicode escape sequence.638index = start;639return getEscapedIdentifier();640}641if (isIdentifierPart(ch)) {642++index;643} else {644break;645}646}647648return source.slice(start, index);649}650651function scanIdentifier() {652var start, id, type;653654start = index;655656// Backslash (char #92) starts an escaped character.657id = (source.charCodeAt(index) === 92) ? getEscapedIdentifier() : getIdentifier();658659// There is no keyword or literal with only one character.660// Thus, it must be an identifier.661if (id.length === 1) {662type = Token.Identifier;663} else if (isKeyword(id)) {664type = Token.Keyword;665} else if (id === 'null') {666type = Token.NullLiteral;667} else if (id === 'true' || id === 'false') {668type = Token.BooleanLiteral;669} else {670type = Token.Identifier;671}672673return {674type: type,675value: id,676lineNumber: lineNumber,677lineStart: lineStart,678range: [start, index]679};680}681682683// 7.7 Punctuators684685function scanPunctuator() {686var start = index,687code = source.charCodeAt(index),688code2,689ch1 = source[index],690ch2,691ch3,692ch4;693694switch (code) {695// Check for most common single-character punctuators.696case 40: // ( open bracket697case 41: // ) close bracket698case 59: // ; semicolon699case 44: // , comma700case 123: // { open curly brace701case 125: // } close curly brace702case 91: // [703case 93: // ]704case 58: // :705case 63: // ?706case 126: // ~707++index;708if (extra.tokenize) {709if (code === 40) {710extra.openParenToken = extra.tokens.length;711} else if (code === 123) {712extra.openCurlyToken = extra.tokens.length;713}714}715return {716type: Token.Punctuator,717value: String.fromCharCode(code),718lineNumber: lineNumber,719lineStart: lineStart,720range: [start, index]721};722723default:724code2 = source.charCodeAt(index + 1);725726// '=' (char #61) marks an assignment or comparison operator.727if (code2 === 61) {728switch (code) {729case 37: // %730case 38: // &731case 42: // *:732case 43: // +733case 45: // -734case 47: // /735case 60: // <736case 62: // >737case 94: // ^738case 124: // |739index += 2;740return {741type: Token.Punctuator,742value: String.fromCharCode(code) + String.fromCharCode(code2),743lineNumber: lineNumber,744lineStart: lineStart,745range: [start, index]746};747748case 33: // !749case 61: // =750index += 2;751752// !== and ===753if (source.charCodeAt(index) === 61) {754++index;755}756return {757type: Token.Punctuator,758value: source.slice(start, index),759lineNumber: lineNumber,760lineStart: lineStart,761range: [start, index]762};763default:764break;765}766}767break;768}769770// Peek more characters.771772ch2 = source[index + 1];773ch3 = source[index + 2];774ch4 = source[index + 3];775776// 4-character punctuator: >>>=777778if (ch1 === '>' && ch2 === '>' && ch3 === '>') {779if (ch4 === '=') {780index += 4;781return {782type: Token.Punctuator,783value: '>>>=',784lineNumber: lineNumber,785lineStart: lineStart,786range: [start, index]787};788}789}790791// 3-character punctuators: === !== >>> <<= >>=792793if (ch1 === '>' && ch2 === '>' && ch3 === '>') {794index += 3;795return {796type: Token.Punctuator,797value: '>>>',798lineNumber: lineNumber,799lineStart: lineStart,800range: [start, index]801};802}803804if (ch1 === '<' && ch2 === '<' && ch3 === '=') {805index += 3;806return {807type: Token.Punctuator,808value: '<<=',809lineNumber: lineNumber,810lineStart: lineStart,811range: [start, index]812};813}814815if (ch1 === '>' && ch2 === '>' && ch3 === '=') {816index += 3;817return {818type: Token.Punctuator,819value: '>>=',820lineNumber: lineNumber,821lineStart: lineStart,822range: [start, index]823};824}825826if (ch1 === '.' && ch2 === '.' && ch3 === '.') {827index += 3;828return {829type: Token.Punctuator,830value: '...',831lineNumber: lineNumber,832lineStart: lineStart,833range: [start, index]834};835}836837// Other 2-character punctuators: ++ -- << >> && ||838839// Don't match these tokens if we're in a type, since they never can840// occur and can mess up types like Map<string, Array<string>>841if (ch1 === ch2 && ('+-<>&|'.indexOf(ch1) >= 0) && !state.inType) {842index += 2;843return {844type: Token.Punctuator,845value: ch1 + ch2,846lineNumber: lineNumber,847lineStart: lineStart,848range: [start, index]849};850}851852if (ch1 === '=' && ch2 === '>') {853index += 2;854return {855type: Token.Punctuator,856value: '=>',857lineNumber: lineNumber,858lineStart: lineStart,859range: [start, index]860};861}862863if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {864++index;865return {866type: Token.Punctuator,867value: ch1,868lineNumber: lineNumber,869lineStart: lineStart,870range: [start, index]871};872}873874if (ch1 === '.') {875++index;876return {877type: Token.Punctuator,878value: ch1,879lineNumber: lineNumber,880lineStart: lineStart,881range: [start, index]882};883}884885throwError({}, Messages.UnexpectedToken, 'ILLEGAL');886}887888// 7.8.3 Numeric Literals889890function scanHexLiteral(start) {891var number = '';892893while (index < length) {894if (!isHexDigit(source[index])) {895break;896}897number += source[index++];898}899900if (number.length === 0) {901throwError({}, Messages.UnexpectedToken, 'ILLEGAL');902}903904if (isIdentifierStart(source.charCodeAt(index))) {905throwError({}, Messages.UnexpectedToken, 'ILLEGAL');906}907908return {909type: Token.NumericLiteral,910value: parseInt('0x' + number, 16),911lineNumber: lineNumber,912lineStart: lineStart,913range: [start, index]914};915}916917function scanOctalLiteral(prefix, start) {918var number, octal;919920if (isOctalDigit(prefix)) {921octal = true;922number = '0' + source[index++];923} else {924octal = false;925++index;926number = '';927}928929while (index < length) {930if (!isOctalDigit(source[index])) {931break;932}933number += source[index++];934}935936if (!octal && number.length === 0) {937// only 0o or 0O938throwError({}, Messages.UnexpectedToken, 'ILLEGAL');939}940941if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {942throwError({}, Messages.UnexpectedToken, 'ILLEGAL');943}944945return {946type: Token.NumericLiteral,947value: parseInt(number, 8),948octal: octal,949lineNumber: lineNumber,950lineStart: lineStart,951range: [start, index]952};953}954955function scanNumericLiteral() {956var number, start, ch, octal;957958ch = source[index];959assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),960'Numeric literal must start with a decimal digit or a decimal point');961962start = index;963number = '';964if (ch !== '.') {965number = source[index++];966ch = source[index];967968// Hex number starts with '0x'.969// Octal number starts with '0'.970// Octal number in ES6 starts with '0o'.971// Binary number in ES6 starts with '0b'.972if (number === '0') {973if (ch === 'x' || ch === 'X') {974++index;975return scanHexLiteral(start);976}977if (ch === 'b' || ch === 'B') {978++index;979number = '';980981while (index < length) {982ch = source[index];983if (ch !== '0' && ch !== '1') {984break;985}986number += source[index++];987}988989if (number.length === 0) {990// only 0b or 0B991throwError({}, Messages.UnexpectedToken, 'ILLEGAL');992}993994if (index < length) {995ch = source.charCodeAt(index);996if (isIdentifierStart(ch) || isDecimalDigit(ch)) {997throwError({}, Messages.UnexpectedToken, 'ILLEGAL');998}999}1000return {1001type: Token.NumericLiteral,1002value: parseInt(number, 2),1003lineNumber: lineNumber,1004lineStart: lineStart,1005range: [start, index]1006};1007}1008if (ch === 'o' || ch === 'O' || isOctalDigit(ch)) {1009return scanOctalLiteral(ch, start);1010}1011// decimal number starts with '0' such as '09' is illegal.1012if (ch && isDecimalDigit(ch.charCodeAt(0))) {1013throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1014}1015}10161017while (isDecimalDigit(source.charCodeAt(index))) {1018number += source[index++];1019}1020ch = source[index];1021}10221023if (ch === '.') {1024number += source[index++];1025while (isDecimalDigit(source.charCodeAt(index))) {1026number += source[index++];1027}1028ch = source[index];1029}10301031if (ch === 'e' || ch === 'E') {1032number += source[index++];10331034ch = source[index];1035if (ch === '+' || ch === '-') {1036number += source[index++];1037}1038if (isDecimalDigit(source.charCodeAt(index))) {1039while (isDecimalDigit(source.charCodeAt(index))) {1040number += source[index++];1041}1042} else {1043throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1044}1045}10461047if (isIdentifierStart(source.charCodeAt(index))) {1048throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1049}10501051return {1052type: Token.NumericLiteral,1053value: parseFloat(number),1054lineNumber: lineNumber,1055lineStart: lineStart,1056range: [start, index]1057};1058}10591060// 7.8.4 String Literals10611062function scanStringLiteral() {1063var str = '', quote, start, ch, code, unescaped, restore, octal = false;10641065quote = source[index];1066assert((quote === '\'' || quote === '"'),1067'String literal must starts with a quote');10681069start = index;1070++index;10711072while (index < length) {1073ch = source[index++];10741075if (ch === quote) {1076quote = '';1077break;1078} else if (ch === '\\') {1079ch = source[index++];1080if (!ch || !isLineTerminator(ch.charCodeAt(0))) {1081switch (ch) {1082case 'n':1083str += '\n';1084break;1085case 'r':1086str += '\r';1087break;1088case 't':1089str += '\t';1090break;1091case 'u':1092case 'x':1093if (source[index] === '{') {1094++index;1095str += scanUnicodeCodePointEscape();1096} else {1097restore = index;1098unescaped = scanHexEscape(ch);1099if (unescaped) {1100str += unescaped;1101} else {1102index = restore;1103str += ch;1104}1105}1106break;1107case 'b':1108str += '\b';1109break;1110case 'f':1111str += '\f';1112break;1113case 'v':1114str += '\x0B';1115break;11161117default:1118if (isOctalDigit(ch)) {1119code = '01234567'.indexOf(ch);11201121// \0 is not octal escape sequence1122if (code !== 0) {1123octal = true;1124}11251126if (index < length && isOctalDigit(source[index])) {1127octal = true;1128code = code * 8 + '01234567'.indexOf(source[index++]);11291130// 3 digits are only allowed when string starts1131// with 0, 1, 2, 31132if ('0123'.indexOf(ch) >= 0 &&1133index < length &&1134isOctalDigit(source[index])) {1135code = code * 8 + '01234567'.indexOf(source[index++]);1136}1137}1138str += String.fromCharCode(code);1139} else {1140str += ch;1141}1142break;1143}1144} else {1145++lineNumber;1146if (ch === '\r' && source[index] === '\n') {1147++index;1148}1149lineStart = index;1150}1151} else if (isLineTerminator(ch.charCodeAt(0))) {1152break;1153} else {1154str += ch;1155}1156}11571158if (quote !== '') {1159throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1160}11611162return {1163type: Token.StringLiteral,1164value: str,1165octal: octal,1166lineNumber: lineNumber,1167lineStart: lineStart,1168range: [start, index]1169};1170}11711172function scanTemplate() {1173var cooked = '', ch, start, terminated, tail, restore, unescaped, code, octal;11741175terminated = false;1176tail = false;1177start = index;11781179++index;11801181while (index < length) {1182ch = source[index++];1183if (ch === '`') {1184tail = true;1185terminated = true;1186break;1187} else if (ch === '$') {1188if (source[index] === '{') {1189++index;1190terminated = true;1191break;1192}1193cooked += ch;1194} else if (ch === '\\') {1195ch = source[index++];1196if (!isLineTerminator(ch.charCodeAt(0))) {1197switch (ch) {1198case 'n':1199cooked += '\n';1200break;1201case 'r':1202cooked += '\r';1203break;1204case 't':1205cooked += '\t';1206break;1207case 'u':1208case 'x':1209if (source[index] === '{') {1210++index;1211cooked += scanUnicodeCodePointEscape();1212} else {1213restore = index;1214unescaped = scanHexEscape(ch);1215if (unescaped) {1216cooked += unescaped;1217} else {1218index = restore;1219cooked += ch;1220}1221}1222break;1223case 'b':1224cooked += '\b';1225break;1226case 'f':1227cooked += '\f';1228break;1229case 'v':1230cooked += '\v';1231break;12321233default:1234if (isOctalDigit(ch)) {1235code = '01234567'.indexOf(ch);12361237// \0 is not octal escape sequence1238if (code !== 0) {1239octal = true;1240}12411242if (index < length && isOctalDigit(source[index])) {1243octal = true;1244code = code * 8 + '01234567'.indexOf(source[index++]);12451246// 3 digits are only allowed when string starts1247// with 0, 1, 2, 31248if ('0123'.indexOf(ch) >= 0 &&1249index < length &&1250isOctalDigit(source[index])) {1251code = code * 8 + '01234567'.indexOf(source[index++]);1252}1253}1254cooked += String.fromCharCode(code);1255} else {1256cooked += ch;1257}1258break;1259}1260} else {1261++lineNumber;1262if (ch === '\r' && source[index] === '\n') {1263++index;1264}1265lineStart = index;1266}1267} else if (isLineTerminator(ch.charCodeAt(0))) {1268++lineNumber;1269if (ch === '\r' && source[index] === '\n') {1270++index;1271}1272lineStart = index;1273cooked += '\n';1274} else {1275cooked += ch;1276}1277}12781279if (!terminated) {1280throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1281}12821283return {1284type: Token.Template,1285value: {1286cooked: cooked,1287raw: source.slice(start + 1, index - ((tail) ? 1 : 2))1288},1289tail: tail,1290octal: octal,1291lineNumber: lineNumber,1292lineStart: lineStart,1293range: [start, index]1294};1295}12961297function scanTemplateElement(option) {1298var startsWith, template;12991300lookahead = null;1301skipComment();13021303startsWith = (option.head) ? '`' : '}';13041305if (source[index] !== startsWith) {1306throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1307}13081309template = scanTemplate();13101311peek();13121313return template;1314}13151316function scanRegExp() {1317var str, ch, start, pattern, flags, value, classMarker = false, restore, terminated = false, tmp;13181319lookahead = null;1320skipComment();13211322start = index;1323ch = source[index];1324assert(ch === '/', 'Regular expression literal must start with a slash');1325str = source[index++];13261327while (index < length) {1328ch = source[index++];1329str += ch;1330if (classMarker) {1331if (ch === ']') {1332classMarker = false;1333}1334} else {1335if (ch === '\\') {1336ch = source[index++];1337// ECMA-262 7.8.51338if (isLineTerminator(ch.charCodeAt(0))) {1339throwError({}, Messages.UnterminatedRegExp);1340}1341str += ch;1342} else if (ch === '/') {1343terminated = true;1344break;1345} else if (ch === '[') {1346classMarker = true;1347} else if (isLineTerminator(ch.charCodeAt(0))) {1348throwError({}, Messages.UnterminatedRegExp);1349}1350}1351}13521353if (!terminated) {1354throwError({}, Messages.UnterminatedRegExp);1355}13561357// Exclude leading and trailing slash.1358pattern = str.substr(1, str.length - 2);13591360flags = '';1361while (index < length) {1362ch = source[index];1363if (!isIdentifierPart(ch.charCodeAt(0))) {1364break;1365}13661367++index;1368if (ch === '\\' && index < length) {1369ch = source[index];1370if (ch === 'u') {1371++index;1372restore = index;1373ch = scanHexEscape('u');1374if (ch) {1375flags += ch;1376for (str += '\\u'; restore < index; ++restore) {1377str += source[restore];1378}1379} else {1380index = restore;1381flags += 'u';1382str += '\\u';1383}1384} else {1385str += '\\';1386}1387} else {1388flags += ch;1389str += ch;1390}1391}13921393tmp = pattern;1394if (flags.indexOf('u') >= 0) {1395// Replace each astral symbol and every Unicode code point1396// escape sequence that represents such a symbol with a single1397// ASCII symbol to avoid throwing on regular expressions that1398// are only valid in combination with the `/u` flag.1399tmp = tmp1400.replace(/\\u\{([0-9a-fA-F]{5,6})\}/g, 'x')1401.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, 'x');1402}14031404// First, detect invalid regular expressions.1405try {1406value = new RegExp(tmp);1407} catch (e) {1408throwError({}, Messages.InvalidRegExp);1409}14101411// Return a regular expression object for this pattern-flag pair, or1412// `null` in case the current environment doesn't support the flags it1413// uses.1414try {1415value = new RegExp(pattern, flags);1416} catch (exception) {1417value = null;1418}14191420peek();14211422if (extra.tokenize) {1423return {1424type: Token.RegularExpression,1425value: value,1426regex: {1427pattern: pattern,1428flags: flags1429},1430lineNumber: lineNumber,1431lineStart: lineStart,1432range: [start, index]1433};1434}1435return {1436literal: str,1437value: value,1438regex: {1439pattern: pattern,1440flags: flags1441},1442range: [start, index]1443};1444}14451446function isIdentifierName(token) {1447return token.type === Token.Identifier ||1448token.type === Token.Keyword ||1449token.type === Token.BooleanLiteral ||1450token.type === Token.NullLiteral;1451}14521453function advanceSlash() {1454var prevToken,1455checkToken;1456// Using the following algorithm:1457// https://github.com/mozilla/sweet.js/wiki/design1458prevToken = extra.tokens[extra.tokens.length - 1];1459if (!prevToken) {1460// Nothing before that: it cannot be a division.1461return scanRegExp();1462}1463if (prevToken.type === 'Punctuator') {1464if (prevToken.value === ')') {1465checkToken = extra.tokens[extra.openParenToken - 1];1466if (checkToken &&1467checkToken.type === 'Keyword' &&1468(checkToken.value === 'if' ||1469checkToken.value === 'while' ||1470checkToken.value === 'for' ||1471checkToken.value === 'with')) {1472return scanRegExp();1473}1474return scanPunctuator();1475}1476if (prevToken.value === '}') {1477// Dividing a function by anything makes little sense,1478// but we have to check for that.1479if (extra.tokens[extra.openCurlyToken - 3] &&1480extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {1481// Anonymous function.1482checkToken = extra.tokens[extra.openCurlyToken - 4];1483if (!checkToken) {1484return scanPunctuator();1485}1486} else if (extra.tokens[extra.openCurlyToken - 4] &&1487extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {1488// Named function.1489checkToken = extra.tokens[extra.openCurlyToken - 5];1490if (!checkToken) {1491return scanRegExp();1492}1493} else {1494return scanPunctuator();1495}1496// checkToken determines whether the function is1497// a declaration or an expression.1498if (FnExprTokens.indexOf(checkToken.value) >= 0) {1499// It is an expression.1500return scanPunctuator();1501}1502// It is a declaration.1503return scanRegExp();1504}1505return scanRegExp();1506}1507if (prevToken.type === 'Keyword') {1508return scanRegExp();1509}1510return scanPunctuator();1511}15121513function advance() {1514var ch;15151516if (!state.inXJSChild) {1517skipComment();1518}15191520if (index >= length) {1521return {1522type: Token.EOF,1523lineNumber: lineNumber,1524lineStart: lineStart,1525range: [index, index]1526};1527}15281529if (state.inXJSChild) {1530return advanceXJSChild();1531}15321533ch = source.charCodeAt(index);15341535// Very common: ( and ) and ;1536if (ch === 40 || ch === 41 || ch === 58) {1537return scanPunctuator();1538}15391540// String literal starts with single quote (#39) or double quote (#34).1541if (ch === 39 || ch === 34) {1542if (state.inXJSTag) {1543return scanXJSStringLiteral();1544}1545return scanStringLiteral();1546}15471548if (state.inXJSTag && isXJSIdentifierStart(ch)) {1549return scanXJSIdentifier();1550}15511552if (ch === 96) {1553return scanTemplate();1554}1555if (isIdentifierStart(ch)) {1556return scanIdentifier();1557}15581559// Dot (.) char #46 can also start a floating-point number, hence the need1560// to check the next character.1561if (ch === 46) {1562if (isDecimalDigit(source.charCodeAt(index + 1))) {1563return scanNumericLiteral();1564}1565return scanPunctuator();1566}15671568if (isDecimalDigit(ch)) {1569return scanNumericLiteral();1570}15711572// Slash (/) char #47 can also start a regex.1573if (extra.tokenize && ch === 47) {1574return advanceSlash();1575}15761577return scanPunctuator();1578}15791580function lex() {1581var token;15821583token = lookahead;1584index = token.range[1];1585lineNumber = token.lineNumber;1586lineStart = token.lineStart;15871588lookahead = advance();15891590index = token.range[1];1591lineNumber = token.lineNumber;1592lineStart = token.lineStart;15931594return token;1595}15961597function peek() {1598var pos, line, start;15991600pos = index;1601line = lineNumber;1602start = lineStart;1603lookahead = advance();1604index = pos;1605lineNumber = line;1606lineStart = start;1607}16081609function lookahead2() {1610var adv, pos, line, start, result;16111612// If we are collecting the tokens, don't grab the next one yet.1613adv = (typeof extra.advance === 'function') ? extra.advance : advance;16141615pos = index;1616line = lineNumber;1617start = lineStart;16181619// Scan for the next immediate token.1620if (lookahead === null) {1621lookahead = adv();1622}1623index = lookahead.range[1];1624lineNumber = lookahead.lineNumber;1625lineStart = lookahead.lineStart;16261627// Grab the token right after.1628result = adv();1629index = pos;1630lineNumber = line;1631lineStart = start;16321633return result;1634}16351636function rewind(token) {1637index = token.range[0];1638lineNumber = token.lineNumber;1639lineStart = token.lineStart;1640lookahead = token;1641}16421643function markerCreate() {1644if (!extra.loc && !extra.range) {1645return undefined;1646}1647skipComment();1648return {offset: index, line: lineNumber, col: index - lineStart};1649}16501651function markerCreatePreserveWhitespace() {1652if (!extra.loc && !extra.range) {1653return undefined;1654}1655return {offset: index, line: lineNumber, col: index - lineStart};1656}16571658function processComment(node) {1659var lastChild,1660trailingComments,1661bottomRight = extra.bottomRightStack,1662last = bottomRight[bottomRight.length - 1];16631664if (node.type === Syntax.Program) {1665if (node.body.length > 0) {1666return;1667}1668}16691670if (extra.trailingComments.length > 0) {1671if (extra.trailingComments[0].range[0] >= node.range[1]) {1672trailingComments = extra.trailingComments;1673extra.trailingComments = [];1674} else {1675extra.trailingComments.length = 0;1676}1677} else {1678if (last && last.trailingComments && last.trailingComments[0].range[0] >= node.range[1]) {1679trailingComments = last.trailingComments;1680delete last.trailingComments;1681}1682}16831684// Eating the stack.1685if (last) {1686while (last && last.range[0] >= node.range[0]) {1687lastChild = last;1688last = bottomRight.pop();1689}1690}16911692if (lastChild) {1693if (lastChild.leadingComments && lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= node.range[0]) {1694node.leadingComments = lastChild.leadingComments;1695delete lastChild.leadingComments;1696}1697} else if (extra.leadingComments.length > 0 && extra.leadingComments[extra.leadingComments.length - 1].range[1] <= node.range[0]) {1698node.leadingComments = extra.leadingComments;1699extra.leadingComments = [];1700}17011702if (trailingComments) {1703node.trailingComments = trailingComments;1704}17051706bottomRight.push(node);1707}17081709function markerApply(marker, node) {1710if (extra.range) {1711node.range = [marker.offset, index];1712}1713if (extra.loc) {1714node.loc = {1715start: {1716line: marker.line,1717column: marker.col1718},1719end: {1720line: lineNumber,1721column: index - lineStart1722}1723};1724node = delegate.postProcess(node);1725}1726if (extra.attachComment) {1727processComment(node);1728}1729return node;1730}17311732SyntaxTreeDelegate = {17331734name: 'SyntaxTree',17351736postProcess: function (node) {1737return node;1738},17391740createArrayExpression: function (elements) {1741return {1742type: Syntax.ArrayExpression,1743elements: elements1744};1745},17461747createAssignmentExpression: function (operator, left, right) {1748return {1749type: Syntax.AssignmentExpression,1750operator: operator,1751left: left,1752right: right1753};1754},17551756createBinaryExpression: function (operator, left, right) {1757var type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression :1758Syntax.BinaryExpression;1759return {1760type: type,1761operator: operator,1762left: left,1763right: right1764};1765},17661767createBlockStatement: function (body) {1768return {1769type: Syntax.BlockStatement,1770body: body1771};1772},17731774createBreakStatement: function (label) {1775return {1776type: Syntax.BreakStatement,1777label: label1778};1779},17801781createCallExpression: function (callee, args) {1782return {1783type: Syntax.CallExpression,1784callee: callee,1785'arguments': args1786};1787},17881789createCatchClause: function (param, body) {1790return {1791type: Syntax.CatchClause,1792param: param,1793body: body1794};1795},17961797createConditionalExpression: function (test, consequent, alternate) {1798return {1799type: Syntax.ConditionalExpression,1800test: test,1801consequent: consequent,1802alternate: alternate1803};1804},18051806createContinueStatement: function (label) {1807return {1808type: Syntax.ContinueStatement,1809label: label1810};1811},18121813createDebuggerStatement: function () {1814return {1815type: Syntax.DebuggerStatement1816};1817},18181819createDoWhileStatement: function (body, test) {1820return {1821type: Syntax.DoWhileStatement,1822body: body,1823test: test1824};1825},18261827createEmptyStatement: function () {1828return {1829type: Syntax.EmptyStatement1830};1831},18321833createExpressionStatement: function (expression) {1834return {1835type: Syntax.ExpressionStatement,1836expression: expression1837};1838},18391840createForStatement: function (init, test, update, body) {1841return {1842type: Syntax.ForStatement,1843init: init,1844test: test,1845update: update,1846body: body1847};1848},18491850createForInStatement: function (left, right, body) {1851return {1852type: Syntax.ForInStatement,1853left: left,1854right: right,1855body: body,1856each: false1857};1858},18591860createForOfStatement: function (left, right, body) {1861return {1862type: Syntax.ForOfStatement,1863left: left,1864right: right,1865body: body1866};1867},18681869createFunctionDeclaration: function (id, params, defaults, body, rest, generator, expression,1870isAsync, returnType, typeParameters) {1871var funDecl = {1872type: Syntax.FunctionDeclaration,1873id: id,1874params: params,1875defaults: defaults,1876body: body,1877rest: rest,1878generator: generator,1879expression: expression,1880returnType: returnType,1881typeParameters: typeParameters1882};18831884if (isAsync) {1885funDecl.async = true;1886}18871888return funDecl;1889},18901891createFunctionExpression: function (id, params, defaults, body, rest, generator, expression,1892isAsync, returnType, typeParameters) {1893var funExpr = {1894type: Syntax.FunctionExpression,1895id: id,1896params: params,1897defaults: defaults,1898body: body,1899rest: rest,1900generator: generator,1901expression: expression,1902returnType: returnType,1903typeParameters: typeParameters1904};19051906if (isAsync) {1907funExpr.async = true;1908}19091910return funExpr;1911},19121913createIdentifier: function (name) {1914return {1915type: Syntax.Identifier,1916name: name,1917// Only here to initialize the shape of the object to ensure1918// that the 'typeAnnotation' key is ordered before others that1919// are added later (like 'loc' and 'range'). This just helps1920// keep the shape of Identifier nodes consistent with everything1921// else.1922typeAnnotation: undefined,1923optional: undefined1924};1925},19261927createTypeAnnotation: function (typeAnnotation) {1928return {1929type: Syntax.TypeAnnotation,1930typeAnnotation: typeAnnotation1931};1932},19331934createFunctionTypeAnnotation: function (params, returnType, rest, typeParameters) {1935return {1936type: Syntax.FunctionTypeAnnotation,1937params: params,1938returnType: returnType,1939rest: rest,1940typeParameters: typeParameters1941};1942},19431944createFunctionTypeParam: function (name, typeAnnotation, optional) {1945return {1946type: Syntax.FunctionTypeParam,1947name: name,1948typeAnnotation: typeAnnotation,1949optional: optional1950};1951},19521953createNullableTypeAnnotation: function (typeAnnotation) {1954return {1955type: Syntax.NullableTypeAnnotation,1956typeAnnotation: typeAnnotation1957};1958},19591960createArrayTypeAnnotation: function (elementType) {1961return {1962type: Syntax.ArrayTypeAnnotation,1963elementType: elementType1964};1965},19661967createGenericTypeAnnotation: function (id, typeParameters) {1968return {1969type: Syntax.GenericTypeAnnotation,1970id: id,1971typeParameters: typeParameters1972};1973},19741975createQualifiedTypeIdentifier: function (qualification, id) {1976return {1977type: Syntax.QualifiedTypeIdentifier,1978qualification: qualification,1979id: id1980};1981},19821983createTypeParameterDeclaration: function (params) {1984return {1985type: Syntax.TypeParameterDeclaration,1986params: params1987};1988},19891990createTypeParameterInstantiation: function (params) {1991return {1992type: Syntax.TypeParameterInstantiation,1993params: params1994};1995},19961997createAnyTypeAnnotation: function () {1998return {1999type: Syntax.AnyTypeAnnotation2000};2001},20022003createBooleanTypeAnnotation: function () {2004return {2005type: Syntax.BooleanTypeAnnotation2006};2007},20082009createNumberTypeAnnotation: function () {2010return {2011type: Syntax.NumberTypeAnnotation2012};2013},20142015createStringTypeAnnotation: function () {2016return {2017type: Syntax.StringTypeAnnotation2018};2019},20202021createStringLiteralTypeAnnotation: function (token) {2022return {2023type: Syntax.StringLiteralTypeAnnotation,2024value: token.value,2025raw: source.slice(token.range[0], token.range[1])2026};2027},20282029createVoidTypeAnnotation: function () {2030return {2031type: Syntax.VoidTypeAnnotation2032};2033},20342035createTypeofTypeAnnotation: function (argument) {2036return {2037type: Syntax.TypeofTypeAnnotation,2038argument: argument2039};2040},20412042createTupleTypeAnnotation: function (types) {2043return {2044type: Syntax.TupleTypeAnnotation,2045types: types2046};2047},20482049createObjectTypeAnnotation: function (properties, indexers, callProperties) {2050return {2051type: Syntax.ObjectTypeAnnotation,2052properties: properties,2053indexers: indexers,2054callProperties: callProperties2055};2056},20572058createObjectTypeIndexer: function (id, key, value, isStatic) {2059return {2060type: Syntax.ObjectTypeIndexer,2061id: id,2062key: key,2063value: value,2064static: isStatic2065};2066},20672068createObjectTypeCallProperty: function (value, isStatic) {2069return {2070type: Syntax.ObjectTypeCallProperty,2071value: value,2072static: isStatic2073};2074},20752076createObjectTypeProperty: function (key, value, optional, isStatic) {2077return {2078type: Syntax.ObjectTypeProperty,2079key: key,2080value: value,2081optional: optional,2082static: isStatic2083};2084},20852086createUnionTypeAnnotation: function (types) {2087return {2088type: Syntax.UnionTypeAnnotation,2089types: types2090};2091},20922093createIntersectionTypeAnnotation: function (types) {2094return {2095type: Syntax.IntersectionTypeAnnotation,2096types: types2097};2098},20992100createTypeAlias: function (id, typeParameters, right) {2101return {2102type: Syntax.TypeAlias,2103id: id,2104typeParameters: typeParameters,2105right: right2106};2107},21082109createInterface: function (id, typeParameters, body, extended) {2110return {2111type: Syntax.InterfaceDeclaration,2112id: id,2113typeParameters: typeParameters,2114body: body,2115extends: extended2116};2117},21182119createInterfaceExtends: function (id, typeParameters) {2120return {2121type: Syntax.InterfaceExtends,2122id: id,2123typeParameters: typeParameters2124};2125},21262127createDeclareFunction: function (id) {2128return {2129type: Syntax.DeclareFunction,2130id: id2131};2132},21332134createDeclareVariable: function (id) {2135return {2136type: Syntax.DeclareVariable,2137id: id2138};2139},21402141createDeclareModule: function (id, body) {2142return {2143type: Syntax.DeclareModule,2144id: id,2145body: body2146};2147},21482149createXJSAttribute: function (name, value) {2150return {2151type: Syntax.XJSAttribute,2152name: name,2153value: value || null2154};2155},21562157createXJSSpreadAttribute: function (argument) {2158return {2159type: Syntax.XJSSpreadAttribute,2160argument: argument2161};2162},21632164createXJSIdentifier: function (name) {2165return {2166type: Syntax.XJSIdentifier,2167name: name2168};2169},21702171createXJSNamespacedName: function (namespace, name) {2172return {2173type: Syntax.XJSNamespacedName,2174namespace: namespace,2175name: name2176};2177},21782179createXJSMemberExpression: function (object, property) {2180return {2181type: Syntax.XJSMemberExpression,2182object: object,2183property: property2184};2185},21862187createXJSElement: function (openingElement, closingElement, children) {2188return {2189type: Syntax.XJSElement,2190openingElement: openingElement,2191closingElement: closingElement,2192children: children2193};2194},21952196createXJSEmptyExpression: function () {2197return {2198type: Syntax.XJSEmptyExpression2199};2200},22012202createXJSExpressionContainer: function (expression) {2203return {2204type: Syntax.XJSExpressionContainer,2205expression: expression2206};2207},22082209createXJSOpeningElement: function (name, attributes, selfClosing) {2210return {2211type: Syntax.XJSOpeningElement,2212name: name,2213selfClosing: selfClosing,2214attributes: attributes2215};2216},22172218createXJSClosingElement: function (name) {2219return {2220type: Syntax.XJSClosingElement,2221name: name2222};2223},22242225createIfStatement: function (test, consequent, alternate) {2226return {2227type: Syntax.IfStatement,2228test: test,2229consequent: consequent,2230alternate: alternate2231};2232},22332234createLabeledStatement: function (label, body) {2235return {2236type: Syntax.LabeledStatement,2237label: label,2238body: body2239};2240},22412242createLiteral: function (token) {2243var object = {2244type: Syntax.Literal,2245value: token.value,2246raw: source.slice(token.range[0], token.range[1])2247};2248if (token.regex) {2249object.regex = token.regex;2250}2251return object;2252},22532254createMemberExpression: function (accessor, object, property) {2255return {2256type: Syntax.MemberExpression,2257computed: accessor === '[',2258object: object,2259property: property2260};2261},22622263createNewExpression: function (callee, args) {2264return {2265type: Syntax.NewExpression,2266callee: callee,2267'arguments': args2268};2269},22702271createObjectExpression: function (properties) {2272return {2273type: Syntax.ObjectExpression,2274properties: properties2275};2276},22772278createPostfixExpression: function (operator, argument) {2279return {2280type: Syntax.UpdateExpression,2281operator: operator,2282argument: argument,2283prefix: false2284};2285},22862287createProgram: function (body) {2288return {2289type: Syntax.Program,2290body: body2291};2292},22932294createProperty: function (kind, key, value, method, shorthand, computed) {2295return {2296type: Syntax.Property,2297key: key,2298value: value,2299kind: kind,2300method: method,2301shorthand: shorthand,2302computed: computed2303};2304},23052306createReturnStatement: function (argument) {2307return {2308type: Syntax.ReturnStatement,2309argument: argument2310};2311},23122313createSequenceExpression: function (expressions) {2314return {2315type: Syntax.SequenceExpression,2316expressions: expressions2317};2318},23192320createSwitchCase: function (test, consequent) {2321return {2322type: Syntax.SwitchCase,2323test: test,2324consequent: consequent2325};2326},23272328createSwitchStatement: function (discriminant, cases) {2329return {2330type: Syntax.SwitchStatement,2331discriminant: discriminant,2332cases: cases2333};2334},23352336createThisExpression: function () {2337return {2338type: Syntax.ThisExpression2339};2340},23412342createThrowStatement: function (argument) {2343return {2344type: Syntax.ThrowStatement,2345argument: argument2346};2347},23482349createTryStatement: function (block, guardedHandlers, handlers, finalizer) {2350return {2351type: Syntax.TryStatement,2352block: block,2353guardedHandlers: guardedHandlers,2354handlers: handlers,2355finalizer: finalizer2356};2357},23582359createUnaryExpression: function (operator, argument) {2360if (operator === '++' || operator === '--') {2361return {2362type: Syntax.UpdateExpression,2363operator: operator,2364argument: argument,2365prefix: true2366};2367}2368return {2369type: Syntax.UnaryExpression,2370operator: operator,2371argument: argument,2372prefix: true2373};2374},23752376createVariableDeclaration: function (declarations, kind) {2377return {2378type: Syntax.VariableDeclaration,2379declarations: declarations,2380kind: kind2381};2382},23832384createVariableDeclarator: function (id, init) {2385return {2386type: Syntax.VariableDeclarator,2387id: id,2388init: init2389};2390},23912392createWhileStatement: function (test, body) {2393return {2394type: Syntax.WhileStatement,2395test: test,2396body: body2397};2398},23992400createWithStatement: function (object, body) {2401return {2402type: Syntax.WithStatement,2403object: object,2404body: body2405};2406},24072408createTemplateElement: function (value, tail) {2409return {2410type: Syntax.TemplateElement,2411value: value,2412tail: tail2413};2414},24152416createTemplateLiteral: function (quasis, expressions) {2417return {2418type: Syntax.TemplateLiteral,2419quasis: quasis,2420expressions: expressions2421};2422},24232424createSpreadElement: function (argument) {2425return {2426type: Syntax.SpreadElement,2427argument: argument2428};2429},24302431createSpreadProperty: function (argument) {2432return {2433type: Syntax.SpreadProperty,2434argument: argument2435};2436},24372438createTaggedTemplateExpression: function (tag, quasi) {2439return {2440type: Syntax.TaggedTemplateExpression,2441tag: tag,2442quasi: quasi2443};2444},24452446createArrowFunctionExpression: function (params, defaults, body, rest, expression, isAsync) {2447var arrowExpr = {2448type: Syntax.ArrowFunctionExpression,2449id: null,2450params: params,2451defaults: defaults,2452body: body,2453rest: rest,2454generator: false,2455expression: expression2456};24572458if (isAsync) {2459arrowExpr.async = true;2460}24612462return arrowExpr;2463},24642465createMethodDefinition: function (propertyType, kind, key, value) {2466return {2467type: Syntax.MethodDefinition,2468key: key,2469value: value,2470kind: kind,2471'static': propertyType === ClassPropertyType.static2472};2473},24742475createClassProperty: function (key, typeAnnotation, computed, isStatic) {2476return {2477type: Syntax.ClassProperty,2478key: key,2479typeAnnotation: typeAnnotation,2480computed: computed,2481static: isStatic2482};2483},24842485createClassBody: function (body) {2486return {2487type: Syntax.ClassBody,2488body: body2489};2490},24912492createClassImplements: function (id, typeParameters) {2493return {2494type: Syntax.ClassImplements,2495id: id,2496typeParameters: typeParameters2497};2498},24992500createClassExpression: function (id, superClass, body, typeParameters, superTypeParameters, implemented) {2501return {2502type: Syntax.ClassExpression,2503id: id,2504superClass: superClass,2505body: body,2506typeParameters: typeParameters,2507superTypeParameters: superTypeParameters,2508implements: implemented2509};2510},25112512createClassDeclaration: function (id, superClass, body, typeParameters, superTypeParameters, implemented) {2513return {2514type: Syntax.ClassDeclaration,2515id: id,2516superClass: superClass,2517body: body,2518typeParameters: typeParameters,2519superTypeParameters: superTypeParameters,2520implements: implemented2521};2522},25232524createModuleSpecifier: function (token) {2525return {2526type: Syntax.ModuleSpecifier,2527value: token.value,2528raw: source.slice(token.range[0], token.range[1])2529};2530},25312532createExportSpecifier: function (id, name) {2533return {2534type: Syntax.ExportSpecifier,2535id: id,2536name: name2537};2538},25392540createExportBatchSpecifier: function () {2541return {2542type: Syntax.ExportBatchSpecifier2543};2544},25452546createImportDefaultSpecifier: function (id) {2547return {2548type: Syntax.ImportDefaultSpecifier,2549id: id2550};2551},25522553createImportNamespaceSpecifier: function (id) {2554return {2555type: Syntax.ImportNamespaceSpecifier,2556id: id2557};2558},25592560createExportDeclaration: function (isDefault, declaration, specifiers, source) {2561return {2562type: Syntax.ExportDeclaration,2563'default': !!isDefault,2564declaration: declaration,2565specifiers: specifiers,2566source: source2567};2568},25692570createImportSpecifier: function (id, name) {2571return {2572type: Syntax.ImportSpecifier,2573id: id,2574name: name2575};2576},25772578createImportDeclaration: function (specifiers, source) {2579return {2580type: Syntax.ImportDeclaration,2581specifiers: specifiers,2582source: source2583};2584},25852586createYieldExpression: function (argument, delegate) {2587return {2588type: Syntax.YieldExpression,2589argument: argument,2590delegate: delegate2591};2592},25932594createAwaitExpression: function (argument) {2595return {2596type: Syntax.AwaitExpression,2597argument: argument2598};2599},26002601createComprehensionExpression: function (filter, blocks, body) {2602return {2603type: Syntax.ComprehensionExpression,2604filter: filter,2605blocks: blocks,2606body: body2607};2608}26092610};26112612// Return true if there is a line terminator before the next token.26132614function peekLineTerminator() {2615var pos, line, start, found;26162617pos = index;2618line = lineNumber;2619start = lineStart;2620skipComment();2621found = lineNumber !== line;2622index = pos;2623lineNumber = line;2624lineStart = start;26252626return found;2627}26282629// Throw an exception26302631function throwError(token, messageFormat) {2632var error,2633args = Array.prototype.slice.call(arguments, 2),2634msg = messageFormat.replace(2635/%(\d)/g,2636function (whole, index) {2637assert(index < args.length, 'Message reference must be in range');2638return args[index];2639}2640);26412642if (typeof token.lineNumber === 'number') {2643error = new Error('Line ' + token.lineNumber + ': ' + msg);2644error.index = token.range[0];2645error.lineNumber = token.lineNumber;2646error.column = token.range[0] - lineStart + 1;2647} else {2648error = new Error('Line ' + lineNumber + ': ' + msg);2649error.index = index;2650error.lineNumber = lineNumber;2651error.column = index - lineStart + 1;2652}26532654error.description = msg;2655throw error;2656}26572658function throwErrorTolerant() {2659try {2660throwError.apply(null, arguments);2661} catch (e) {2662if (extra.errors) {2663extra.errors.push(e);2664} else {2665throw e;2666}2667}2668}266926702671// Throw an exception because of the token.26722673function throwUnexpected(token) {2674if (token.type === Token.EOF) {2675throwError(token, Messages.UnexpectedEOS);2676}26772678if (token.type === Token.NumericLiteral) {2679throwError(token, Messages.UnexpectedNumber);2680}26812682if (token.type === Token.StringLiteral || token.type === Token.XJSText) {2683throwError(token, Messages.UnexpectedString);2684}26852686if (token.type === Token.Identifier) {2687throwError(token, Messages.UnexpectedIdentifier);2688}26892690if (token.type === Token.Keyword) {2691if (isFutureReservedWord(token.value)) {2692throwError(token, Messages.UnexpectedReserved);2693} else if (strict && isStrictModeReservedWord(token.value)) {2694throwErrorTolerant(token, Messages.StrictReservedWord);2695return;2696}2697throwError(token, Messages.UnexpectedToken, token.value);2698}26992700if (token.type === Token.Template) {2701throwError(token, Messages.UnexpectedTemplate, token.value.raw);2702}27032704// BooleanLiteral, NullLiteral, or Punctuator.2705throwError(token, Messages.UnexpectedToken, token.value);2706}27072708// Expect the next token to match the specified punctuator.2709// If not, an exception will be thrown.27102711function expect(value) {2712var token = lex();2713if (token.type !== Token.Punctuator || token.value !== value) {2714throwUnexpected(token);2715}2716}27172718// Expect the next token to match the specified keyword.2719// If not, an exception will be thrown.27202721function expectKeyword(keyword, contextual) {2722var token = lex();2723if (token.type !== (contextual ? Token.Identifier : Token.Keyword) ||2724token.value !== keyword) {2725throwUnexpected(token);2726}2727}27282729// Expect the next token to match the specified contextual keyword.2730// If not, an exception will be thrown.27312732function expectContextualKeyword(keyword) {2733return expectKeyword(keyword, true);2734}27352736// Return true if the next token matches the specified punctuator.27372738function match(value) {2739return lookahead.type === Token.Punctuator && lookahead.value === value;2740}27412742// Return true if the next token matches the specified keyword27432744function matchKeyword(keyword, contextual) {2745var expectedType = contextual ? Token.Identifier : Token.Keyword;2746return lookahead.type === expectedType && lookahead.value === keyword;2747}27482749// Return true if the next token matches the specified contextual keyword27502751function matchContextualKeyword(keyword) {2752return matchKeyword(keyword, true);2753}27542755// Return true if the next token is an assignment operator27562757function matchAssign() {2758var op;27592760if (lookahead.type !== Token.Punctuator) {2761return false;2762}2763op = lookahead.value;2764return op === '=' ||2765op === '*=' ||2766op === '/=' ||2767op === '%=' ||2768op === '+=' ||2769op === '-=' ||2770op === '<<=' ||2771op === '>>=' ||2772op === '>>>=' ||2773op === '&=' ||2774op === '^=' ||2775op === '|=';2776}27772778// Note that 'yield' is treated as a keyword in strict mode, but a2779// contextual keyword (identifier) in non-strict mode, so we need to2780// use matchKeyword('yield', false) and matchKeyword('yield', true)2781// (i.e. matchContextualKeyword) appropriately.2782function matchYield() {2783return state.yieldAllowed && matchKeyword('yield', !strict);2784}27852786function matchAsync() {2787var backtrackToken = lookahead, matches = false;27882789if (matchContextualKeyword('async')) {2790lex(); // Make sure peekLineTerminator() starts after 'async'.2791matches = !peekLineTerminator();2792rewind(backtrackToken); // Revert the lex().2793}27942795return matches;2796}27972798function matchAwait() {2799return state.awaitAllowed && matchContextualKeyword('await');2800}28012802function consumeSemicolon() {2803var line, oldIndex = index, oldLineNumber = lineNumber,2804oldLineStart = lineStart, oldLookahead = lookahead;28052806// Catch the very common case first: immediately a semicolon (char #59).2807if (source.charCodeAt(index) === 59) {2808lex();2809return;2810}28112812line = lineNumber;2813skipComment();2814if (lineNumber !== line) {2815index = oldIndex;2816lineNumber = oldLineNumber;2817lineStart = oldLineStart;2818lookahead = oldLookahead;2819return;2820}28212822if (match(';')) {2823lex();2824return;2825}28262827if (lookahead.type !== Token.EOF && !match('}')) {2828throwUnexpected(lookahead);2829}2830}28312832// Return true if provided expression is LeftHandSideExpression28332834function isLeftHandSide(expr) {2835return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;2836}28372838function isAssignableLeftHandSide(expr) {2839return isLeftHandSide(expr) || expr.type === Syntax.ObjectPattern || expr.type === Syntax.ArrayPattern;2840}28412842// 11.1.4 Array Initialiser28432844function parseArrayInitialiser() {2845var elements = [], blocks = [], filter = null, tmp, possiblecomprehension = true, body,2846marker = markerCreate();28472848expect('[');2849while (!match(']')) {2850if (lookahead.value === 'for' &&2851lookahead.type === Token.Keyword) {2852if (!possiblecomprehension) {2853throwError({}, Messages.ComprehensionError);2854}2855matchKeyword('for');2856tmp = parseForStatement({ignoreBody: true});2857tmp.of = tmp.type === Syntax.ForOfStatement;2858tmp.type = Syntax.ComprehensionBlock;2859if (tmp.left.kind) { // can't be let or const2860throwError({}, Messages.ComprehensionError);2861}2862blocks.push(tmp);2863} else if (lookahead.value === 'if' &&2864lookahead.type === Token.Keyword) {2865if (!possiblecomprehension) {2866throwError({}, Messages.ComprehensionError);2867}2868expectKeyword('if');2869expect('(');2870filter = parseExpression();2871expect(')');2872} else if (lookahead.value === ',' &&2873lookahead.type === Token.Punctuator) {2874possiblecomprehension = false; // no longer allowed.2875lex();2876elements.push(null);2877} else {2878tmp = parseSpreadOrAssignmentExpression();2879elements.push(tmp);2880if (tmp && tmp.type === Syntax.SpreadElement) {2881if (!match(']')) {2882throwError({}, Messages.ElementAfterSpreadElement);2883}2884} else if (!(match(']') || matchKeyword('for') || matchKeyword('if'))) {2885expect(','); // this lexes.2886possiblecomprehension = false;2887}2888}2889}28902891expect(']');28922893if (filter && !blocks.length) {2894throwError({}, Messages.ComprehensionRequiresBlock);2895}28962897if (blocks.length) {2898if (elements.length !== 1) {2899throwError({}, Messages.ComprehensionError);2900}2901return markerApply(marker, delegate.createComprehensionExpression(filter, blocks, elements[0]));2902}2903return markerApply(marker, delegate.createArrayExpression(elements));2904}29052906// 11.1.5 Object Initialiser29072908function parsePropertyFunction(options) {2909var previousStrict, previousYieldAllowed, previousAwaitAllowed,2910params, defaults, body, marker = markerCreate();29112912previousStrict = strict;2913previousYieldAllowed = state.yieldAllowed;2914state.yieldAllowed = options.generator;2915previousAwaitAllowed = state.awaitAllowed;2916state.awaitAllowed = options.async;2917params = options.params || [];2918defaults = options.defaults || [];29192920body = parseConciseBody();2921if (options.name && strict && isRestrictedWord(params[0].name)) {2922throwErrorTolerant(options.name, Messages.StrictParamName);2923}2924strict = previousStrict;2925state.yieldAllowed = previousYieldAllowed;2926state.awaitAllowed = previousAwaitAllowed;29272928return markerApply(marker, delegate.createFunctionExpression(2929null,2930params,2931defaults,2932body,2933options.rest || null,2934options.generator,2935body.type !== Syntax.BlockStatement,2936options.async,2937options.returnType,2938options.typeParameters2939));2940}294129422943function parsePropertyMethodFunction(options) {2944var previousStrict, tmp, method;29452946previousStrict = strict;2947strict = true;29482949tmp = parseParams();29502951if (tmp.stricted) {2952throwErrorTolerant(tmp.stricted, tmp.message);2953}29542955method = parsePropertyFunction({2956params: tmp.params,2957defaults: tmp.defaults,2958rest: tmp.rest,2959generator: options.generator,2960async: options.async,2961returnType: tmp.returnType,2962typeParameters: options.typeParameters2963});29642965strict = previousStrict;29662967return method;2968}296929702971function parseObjectPropertyKey() {2972var marker = markerCreate(),2973token = lex(),2974propertyKey,2975result;29762977// Note: This function is called only from parseObjectProperty(), where2978// EOF and Punctuator tokens are already filtered out.29792980if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) {2981if (strict && token.octal) {2982throwErrorTolerant(token, Messages.StrictOctalLiteral);2983}2984return markerApply(marker, delegate.createLiteral(token));2985}29862987if (token.type === Token.Punctuator && token.value === '[') {2988// For computed properties we should skip the [ and ], and2989// capture in marker only the assignment expression itself.2990marker = markerCreate();2991propertyKey = parseAssignmentExpression();2992result = markerApply(marker, propertyKey);2993expect(']');2994return result;2995}29962997return markerApply(marker, delegate.createIdentifier(token.value));2998}29993000function parseObjectProperty() {3001var token, key, id, value, param, expr, computed,3002marker = markerCreate(), returnType;30033004token = lookahead;3005computed = (token.value === '[');30063007if (token.type === Token.Identifier || computed || matchAsync()) {3008id = parseObjectPropertyKey();30093010if (match(':')) {3011lex();30123013return markerApply(3014marker,3015delegate.createProperty(3016'init',3017id,3018parseAssignmentExpression(),3019false,3020false,3021computed3022)3023);3024}30253026if (match('(')) {3027return markerApply(3028marker,3029delegate.createProperty(3030'init',3031id,3032parsePropertyMethodFunction({3033generator: false,3034async: false3035}),3036true,3037false,3038computed3039)3040);3041}30423043// Property Assignment: Getter and Setter.30443045if (token.value === 'get') {3046computed = (lookahead.value === '[');3047key = parseObjectPropertyKey();30483049expect('(');3050expect(')');3051if (match(':')) {3052returnType = parseTypeAnnotation();3053}30543055return markerApply(3056marker,3057delegate.createProperty(3058'get',3059key,3060parsePropertyFunction({3061generator: false,3062async: false,3063returnType: returnType3064}),3065false,3066false,3067computed3068)3069);3070}30713072if (token.value === 'set') {3073computed = (lookahead.value === '[');3074key = parseObjectPropertyKey();30753076expect('(');3077token = lookahead;3078param = [ parseTypeAnnotatableIdentifier() ];3079expect(')');3080if (match(':')) {3081returnType = parseTypeAnnotation();3082}30833084return markerApply(3085marker,3086delegate.createProperty(3087'set',3088key,3089parsePropertyFunction({3090params: param,3091generator: false,3092async: false,3093name: token,3094returnType: returnType3095}),3096false,3097false,3098computed3099)3100);3101}31023103if (token.value === 'async') {3104computed = (lookahead.value === '[');3105key = parseObjectPropertyKey();31063107return markerApply(3108marker,3109delegate.createProperty(3110'init',3111key,3112parsePropertyMethodFunction({3113generator: false,3114async: true3115}),3116true,3117false,3118computed3119)3120);3121}31223123if (computed) {3124// Computed properties can only be used with full notation.3125throwUnexpected(lookahead);3126}31273128return markerApply(3129marker,3130delegate.createProperty('init', id, id, false, true, false)3131);3132}31333134if (token.type === Token.EOF || token.type === Token.Punctuator) {3135if (!match('*')) {3136throwUnexpected(token);3137}3138lex();31393140computed = (lookahead.type === Token.Punctuator && lookahead.value === '[');31413142id = parseObjectPropertyKey();31433144if (!match('(')) {3145throwUnexpected(lex());3146}31473148return markerApply(marker, delegate.createProperty('init', id, parsePropertyMethodFunction({ generator: true }), true, false, computed));3149}3150key = parseObjectPropertyKey();3151if (match(':')) {3152lex();3153return markerApply(marker, delegate.createProperty('init', key, parseAssignmentExpression(), false, false, false));3154}3155if (match('(')) {3156return markerApply(marker, delegate.createProperty('init', key, parsePropertyMethodFunction({ generator: false }), true, false, false));3157}3158throwUnexpected(lex());3159}31603161function parseObjectSpreadProperty() {3162var marker = markerCreate();3163expect('...');3164return markerApply(marker, delegate.createSpreadProperty(parseAssignmentExpression()));3165}31663167function parseObjectInitialiser() {3168var properties = [], property, name, key, kind, map = {}, toString = String,3169marker = markerCreate();31703171expect('{');31723173while (!match('}')) {3174if (match('...')) {3175property = parseObjectSpreadProperty();3176} else {3177property = parseObjectProperty();31783179if (property.key.type === Syntax.Identifier) {3180name = property.key.name;3181} else {3182name = toString(property.key.value);3183}3184kind = (property.kind === 'init') ? PropertyKind.Data : (property.kind === 'get') ? PropertyKind.Get : PropertyKind.Set;31853186key = '$' + name;3187if (Object.prototype.hasOwnProperty.call(map, key)) {3188if (map[key] === PropertyKind.Data) {3189if (strict && kind === PropertyKind.Data) {3190throwErrorTolerant({}, Messages.StrictDuplicateProperty);3191} else if (kind !== PropertyKind.Data) {3192throwErrorTolerant({}, Messages.AccessorDataProperty);3193}3194} else {3195if (kind === PropertyKind.Data) {3196throwErrorTolerant({}, Messages.AccessorDataProperty);3197} else if (map[key] & kind) {3198throwErrorTolerant({}, Messages.AccessorGetSet);3199}3200}3201map[key] |= kind;3202} else {3203map[key] = kind;3204}3205}32063207properties.push(property);32083209if (!match('}')) {3210expect(',');3211}3212}32133214expect('}');32153216return markerApply(marker, delegate.createObjectExpression(properties));3217}32183219function parseTemplateElement(option) {3220var marker = markerCreate(),3221token = scanTemplateElement(option);3222if (strict && token.octal) {3223throwError(token, Messages.StrictOctalLiteral);3224}3225return markerApply(marker, delegate.createTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail));3226}32273228function parseTemplateLiteral() {3229var quasi, quasis, expressions, marker = markerCreate();32303231quasi = parseTemplateElement({ head: true });3232quasis = [ quasi ];3233expressions = [];32343235while (!quasi.tail) {3236expressions.push(parseExpression());3237quasi = parseTemplateElement({ head: false });3238quasis.push(quasi);3239}32403241return markerApply(marker, delegate.createTemplateLiteral(quasis, expressions));3242}32433244// 11.1.6 The Grouping Operator32453246function parseGroupExpression() {3247var expr;32483249expect('(');32503251++state.parenthesizedCount;32523253expr = parseExpression();32543255expect(')');32563257return expr;3258}32593260function matchAsyncFuncExprOrDecl() {3261var token;32623263if (matchAsync()) {3264token = lookahead2();3265if (token.type === Token.Keyword && token.value === 'function') {3266return true;3267}3268}32693270return false;3271}32723273// 11.1 Primary Expressions32743275function parsePrimaryExpression() {3276var marker, type, token, expr;32773278type = lookahead.type;32793280if (type === Token.Identifier) {3281marker = markerCreate();3282return markerApply(marker, delegate.createIdentifier(lex().value));3283}32843285if (type === Token.StringLiteral || type === Token.NumericLiteral) {3286if (strict && lookahead.octal) {3287throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);3288}3289marker = markerCreate();3290return markerApply(marker, delegate.createLiteral(lex()));3291}32923293if (type === Token.Keyword) {3294if (matchKeyword('this')) {3295marker = markerCreate();3296lex();3297return markerApply(marker, delegate.createThisExpression());3298}32993300if (matchKeyword('function')) {3301return parseFunctionExpression();3302}33033304if (matchKeyword('class')) {3305return parseClassExpression();3306}33073308if (matchKeyword('super')) {3309marker = markerCreate();3310lex();3311return markerApply(marker, delegate.createIdentifier('super'));3312}3313}33143315if (type === Token.BooleanLiteral) {3316marker = markerCreate();3317token = lex();3318token.value = (token.value === 'true');3319return markerApply(marker, delegate.createLiteral(token));3320}33213322if (type === Token.NullLiteral) {3323marker = markerCreate();3324token = lex();3325token.value = null;3326return markerApply(marker, delegate.createLiteral(token));3327}33283329if (match('[')) {3330return parseArrayInitialiser();3331}33323333if (match('{')) {3334return parseObjectInitialiser();3335}33363337if (match('(')) {3338return parseGroupExpression();3339}33403341if (match('/') || match('/=')) {3342marker = markerCreate();3343return markerApply(marker, delegate.createLiteral(scanRegExp()));3344}33453346if (type === Token.Template) {3347return parseTemplateLiteral();3348}33493350if (match('<')) {3351return parseXJSElement();3352}33533354throwUnexpected(lex());3355}33563357// 11.2 Left-Hand-Side Expressions33583359function parseArguments() {3360var args = [], arg;33613362expect('(');33633364if (!match(')')) {3365while (index < length) {3366arg = parseSpreadOrAssignmentExpression();3367args.push(arg);33683369if (match(')')) {3370break;3371} else if (arg.type === Syntax.SpreadElement) {3372throwError({}, Messages.ElementAfterSpreadElement);3373}33743375expect(',');3376}3377}33783379expect(')');33803381return args;3382}33833384function parseSpreadOrAssignmentExpression() {3385if (match('...')) {3386var marker = markerCreate();3387lex();3388return markerApply(marker, delegate.createSpreadElement(parseAssignmentExpression()));3389}3390return parseAssignmentExpression();3391}33923393function parseNonComputedProperty() {3394var marker = markerCreate(),3395token = lex();33963397if (!isIdentifierName(token)) {3398throwUnexpected(token);3399}34003401return markerApply(marker, delegate.createIdentifier(token.value));3402}34033404function parseNonComputedMember() {3405expect('.');34063407return parseNonComputedProperty();3408}34093410function parseComputedMember() {3411var expr;34123413expect('[');34143415expr = parseExpression();34163417expect(']');34183419return expr;3420}34213422function parseNewExpression() {3423var callee, args, marker = markerCreate();34243425expectKeyword('new');3426callee = parseLeftHandSideExpression();3427args = match('(') ? parseArguments() : [];34283429return markerApply(marker, delegate.createNewExpression(callee, args));3430}34313432function parseLeftHandSideExpressionAllowCall() {3433var expr, args, marker = markerCreate();34343435expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();34363437while (match('.') || match('[') || match('(') || lookahead.type === Token.Template) {3438if (match('(')) {3439args = parseArguments();3440expr = markerApply(marker, delegate.createCallExpression(expr, args));3441} else if (match('[')) {3442expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));3443} else if (match('.')) {3444expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));3445} else {3446expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));3447}3448}34493450return expr;3451}34523453function parseLeftHandSideExpression() {3454var expr, marker = markerCreate();34553456expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();34573458while (match('.') || match('[') || lookahead.type === Token.Template) {3459if (match('[')) {3460expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));3461} else if (match('.')) {3462expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));3463} else {3464expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));3465}3466}34673468return expr;3469}34703471// 11.3 Postfix Expressions34723473function parsePostfixExpression() {3474var marker = markerCreate(),3475expr = parseLeftHandSideExpressionAllowCall(),3476token;34773478if (lookahead.type !== Token.Punctuator) {3479return expr;3480}34813482if ((match('++') || match('--')) && !peekLineTerminator()) {3483// 11.3.1, 11.3.23484if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3485throwErrorTolerant({}, Messages.StrictLHSPostfix);3486}34873488if (!isLeftHandSide(expr)) {3489throwError({}, Messages.InvalidLHSInAssignment);3490}34913492token = lex();3493expr = markerApply(marker, delegate.createPostfixExpression(token.value, expr));3494}34953496return expr;3497}34983499// 11.4 Unary Operators35003501function parseUnaryExpression() {3502var marker, token, expr;35033504if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {3505return parsePostfixExpression();3506}35073508if (match('++') || match('--')) {3509marker = markerCreate();3510token = lex();3511expr = parseUnaryExpression();3512// 11.4.4, 11.4.53513if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3514throwErrorTolerant({}, Messages.StrictLHSPrefix);3515}35163517if (!isLeftHandSide(expr)) {3518throwError({}, Messages.InvalidLHSInAssignment);3519}35203521return markerApply(marker, delegate.createUnaryExpression(token.value, expr));3522}35233524if (match('+') || match('-') || match('~') || match('!')) {3525marker = markerCreate();3526token = lex();3527expr = parseUnaryExpression();3528return markerApply(marker, delegate.createUnaryExpression(token.value, expr));3529}35303531if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {3532marker = markerCreate();3533token = lex();3534expr = parseUnaryExpression();3535expr = markerApply(marker, delegate.createUnaryExpression(token.value, expr));3536if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {3537throwErrorTolerant({}, Messages.StrictDelete);3538}3539return expr;3540}35413542return parsePostfixExpression();3543}35443545function binaryPrecedence(token, allowIn) {3546var prec = 0;35473548if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {3549return 0;3550}35513552switch (token.value) {3553case '||':3554prec = 1;3555break;35563557case '&&':3558prec = 2;3559break;35603561case '|':3562prec = 3;3563break;35643565case '^':3566prec = 4;3567break;35683569case '&':3570prec = 5;3571break;35723573case '==':3574case '!=':3575case '===':3576case '!==':3577prec = 6;3578break;35793580case '<':3581case '>':3582case '<=':3583case '>=':3584case 'instanceof':3585prec = 7;3586break;35873588case 'in':3589prec = allowIn ? 7 : 0;3590break;35913592case '<<':3593case '>>':3594case '>>>':3595prec = 8;3596break;35973598case '+':3599case '-':3600prec = 9;3601break;36023603case '*':3604case '/':3605case '%':3606prec = 11;3607break;36083609default:3610break;3611}36123613return prec;3614}36153616// 11.5 Multiplicative Operators3617// 11.6 Additive Operators3618// 11.7 Bitwise Shift Operators3619// 11.8 Relational Operators3620// 11.9 Equality Operators3621// 11.10 Binary Bitwise Operators3622// 11.11 Binary Logical Operators36233624function parseBinaryExpression() {3625var expr, token, prec, previousAllowIn, stack, right, operator, left, i,3626marker, markers;36273628previousAllowIn = state.allowIn;3629state.allowIn = true;36303631marker = markerCreate();3632left = parseUnaryExpression();36333634token = lookahead;3635prec = binaryPrecedence(token, previousAllowIn);3636if (prec === 0) {3637return left;3638}3639token.prec = prec;3640lex();36413642markers = [marker, markerCreate()];3643right = parseUnaryExpression();36443645stack = [left, token, right];36463647while ((prec = binaryPrecedence(lookahead, previousAllowIn)) > 0) {36483649// Reduce: make a binary expression from the three topmost entries.3650while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {3651right = stack.pop();3652operator = stack.pop().value;3653left = stack.pop();3654expr = delegate.createBinaryExpression(operator, left, right);3655markers.pop();3656marker = markers.pop();3657markerApply(marker, expr);3658stack.push(expr);3659markers.push(marker);3660}36613662// Shift.3663token = lex();3664token.prec = prec;3665stack.push(token);3666markers.push(markerCreate());3667expr = parseUnaryExpression();3668stack.push(expr);3669}36703671state.allowIn = previousAllowIn;36723673// Final reduce to clean-up the stack.3674i = stack.length - 1;3675expr = stack[i];3676markers.pop();3677while (i > 1) {3678expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);3679i -= 2;3680marker = markers.pop();3681markerApply(marker, expr);3682}36833684return expr;3685}368636873688// 11.12 Conditional Operator36893690function parseConditionalExpression() {3691var expr, previousAllowIn, consequent, alternate, marker = markerCreate();3692expr = parseBinaryExpression();36933694if (match('?')) {3695lex();3696previousAllowIn = state.allowIn;3697state.allowIn = true;3698consequent = parseAssignmentExpression();3699state.allowIn = previousAllowIn;3700expect(':');3701alternate = parseAssignmentExpression();37023703expr = markerApply(marker, delegate.createConditionalExpression(expr, consequent, alternate));3704}37053706return expr;3707}37083709// 11.13 Assignment Operators37103711function reinterpretAsAssignmentBindingPattern(expr) {3712var i, len, property, element;37133714if (expr.type === Syntax.ObjectExpression) {3715expr.type = Syntax.ObjectPattern;3716for (i = 0, len = expr.properties.length; i < len; i += 1) {3717property = expr.properties[i];3718if (property.type === Syntax.SpreadProperty) {3719if (i < len - 1) {3720throwError({}, Messages.PropertyAfterSpreadProperty);3721}3722reinterpretAsAssignmentBindingPattern(property.argument);3723} else {3724if (property.kind !== 'init') {3725throwError({}, Messages.InvalidLHSInAssignment);3726}3727reinterpretAsAssignmentBindingPattern(property.value);3728}3729}3730} else if (expr.type === Syntax.ArrayExpression) {3731expr.type = Syntax.ArrayPattern;3732for (i = 0, len = expr.elements.length; i < len; i += 1) {3733element = expr.elements[i];3734if (element) {3735reinterpretAsAssignmentBindingPattern(element);3736}3737}3738} else if (expr.type === Syntax.Identifier) {3739if (isRestrictedWord(expr.name)) {3740throwError({}, Messages.InvalidLHSInAssignment);3741}3742} else if (expr.type === Syntax.SpreadElement) {3743reinterpretAsAssignmentBindingPattern(expr.argument);3744if (expr.argument.type === Syntax.ObjectPattern) {3745throwError({}, Messages.ObjectPatternAsSpread);3746}3747} else {3748if (expr.type !== Syntax.MemberExpression && expr.type !== Syntax.CallExpression && expr.type !== Syntax.NewExpression) {3749throwError({}, Messages.InvalidLHSInAssignment);3750}3751}3752}375337543755function reinterpretAsDestructuredParameter(options, expr) {3756var i, len, property, element;37573758if (expr.type === Syntax.ObjectExpression) {3759expr.type = Syntax.ObjectPattern;3760for (i = 0, len = expr.properties.length; i < len; i += 1) {3761property = expr.properties[i];3762if (property.type === Syntax.SpreadProperty) {3763if (i < len - 1) {3764throwError({}, Messages.PropertyAfterSpreadProperty);3765}3766reinterpretAsDestructuredParameter(options, property.argument);3767} else {3768if (property.kind !== 'init') {3769throwError({}, Messages.InvalidLHSInFormalsList);3770}3771reinterpretAsDestructuredParameter(options, property.value);3772}3773}3774} else if (expr.type === Syntax.ArrayExpression) {3775expr.type = Syntax.ArrayPattern;3776for (i = 0, len = expr.elements.length; i < len; i += 1) {3777element = expr.elements[i];3778if (element) {3779reinterpretAsDestructuredParameter(options, element);3780}3781}3782} else if (expr.type === Syntax.Identifier) {3783validateParam(options, expr, expr.name);3784} else {3785if (expr.type !== Syntax.MemberExpression) {3786throwError({}, Messages.InvalidLHSInFormalsList);3787}3788}3789}37903791function reinterpretAsCoverFormalsList(expressions) {3792var i, len, param, params, defaults, defaultCount, options, rest;37933794params = [];3795defaults = [];3796defaultCount = 0;3797rest = null;3798options = {3799paramSet: {}3800};38013802for (i = 0, len = expressions.length; i < len; i += 1) {3803param = expressions[i];3804if (param.type === Syntax.Identifier) {3805params.push(param);3806defaults.push(null);3807validateParam(options, param, param.name);3808} else if (param.type === Syntax.ObjectExpression || param.type === Syntax.ArrayExpression) {3809reinterpretAsDestructuredParameter(options, param);3810params.push(param);3811defaults.push(null);3812} else if (param.type === Syntax.SpreadElement) {3813assert(i === len - 1, 'It is guaranteed that SpreadElement is last element by parseExpression');3814reinterpretAsDestructuredParameter(options, param.argument);3815rest = param.argument;3816} else if (param.type === Syntax.AssignmentExpression) {3817params.push(param.left);3818defaults.push(param.right);3819++defaultCount;3820validateParam(options, param.left, param.left.name);3821} else {3822return null;3823}3824}38253826if (options.message === Messages.StrictParamDupe) {3827throwError(3828strict ? options.stricted : options.firstRestricted,3829options.message3830);3831}38323833if (defaultCount === 0) {3834defaults = [];3835}38363837return {3838params: params,3839defaults: defaults,3840rest: rest,3841stricted: options.stricted,3842firstRestricted: options.firstRestricted,3843message: options.message3844};3845}38463847function parseArrowFunctionExpression(options, marker) {3848var previousStrict, previousYieldAllowed, previousAwaitAllowed, body;38493850expect('=>');38513852previousStrict = strict;3853previousYieldAllowed = state.yieldAllowed;3854state.yieldAllowed = false;3855previousAwaitAllowed = state.awaitAllowed;3856state.awaitAllowed = !!options.async;3857body = parseConciseBody();38583859if (strict && options.firstRestricted) {3860throwError(options.firstRestricted, options.message);3861}3862if (strict && options.stricted) {3863throwErrorTolerant(options.stricted, options.message);3864}38653866strict = previousStrict;3867state.yieldAllowed = previousYieldAllowed;3868state.awaitAllowed = previousAwaitAllowed;38693870return markerApply(marker, delegate.createArrowFunctionExpression(3871options.params,3872options.defaults,3873body,3874options.rest,3875body.type !== Syntax.BlockStatement,3876!!options.async3877));3878}38793880function parseAssignmentExpression() {3881var marker, expr, token, params, oldParenthesizedCount,3882backtrackToken = lookahead, possiblyAsync = false;38833884if (matchYield()) {3885return parseYieldExpression();3886}38873888if (matchAwait()) {3889return parseAwaitExpression();3890}38913892oldParenthesizedCount = state.parenthesizedCount;38933894marker = markerCreate();38953896if (matchAsyncFuncExprOrDecl()) {3897return parseFunctionExpression();3898}38993900if (matchAsync()) {3901// We can't be completely sure that this 'async' token is3902// actually a contextual keyword modifying a function3903// expression, so we might have to un-lex() it later by3904// calling rewind(backtrackToken).3905possiblyAsync = true;3906lex();3907}39083909if (match('(')) {3910token = lookahead2();3911if ((token.type === Token.Punctuator && token.value === ')') || token.value === '...') {3912params = parseParams();3913if (!match('=>')) {3914throwUnexpected(lex());3915}3916params.async = possiblyAsync;3917return parseArrowFunctionExpression(params, marker);3918}3919}39203921token = lookahead;39223923// If the 'async' keyword is not followed by a '(' character or an3924// identifier, then it can't be an arrow function modifier, and we3925// should interpret it as a normal identifer.3926if (possiblyAsync && !match('(') && token.type !== Token.Identifier) {3927possiblyAsync = false;3928rewind(backtrackToken);3929}39303931expr = parseConditionalExpression();39323933if (match('=>') &&3934(state.parenthesizedCount === oldParenthesizedCount ||3935state.parenthesizedCount === (oldParenthesizedCount + 1))) {3936if (expr.type === Syntax.Identifier) {3937params = reinterpretAsCoverFormalsList([ expr ]);3938} else if (expr.type === Syntax.SequenceExpression) {3939params = reinterpretAsCoverFormalsList(expr.expressions);3940}3941if (params) {3942params.async = possiblyAsync;3943return parseArrowFunctionExpression(params, marker);3944}3945}39463947// If we haven't returned by now, then the 'async' keyword was not3948// a function modifier, and we should rewind and interpret it as a3949// normal identifier.3950if (possiblyAsync) {3951possiblyAsync = false;3952rewind(backtrackToken);3953expr = parseConditionalExpression();3954}39553956if (matchAssign()) {3957// 11.13.13958if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3959throwErrorTolerant(token, Messages.StrictLHSAssignment);3960}39613962// ES.next draf 11.13 Runtime Semantics step 13963if (match('=') && (expr.type === Syntax.ObjectExpression || expr.type === Syntax.ArrayExpression)) {3964reinterpretAsAssignmentBindingPattern(expr);3965} else if (!isLeftHandSide(expr)) {3966throwError({}, Messages.InvalidLHSInAssignment);3967}39683969expr = markerApply(marker, delegate.createAssignmentExpression(lex().value, expr, parseAssignmentExpression()));3970}39713972return expr;3973}39743975// 11.14 Comma Operator39763977function parseExpression() {3978var marker, expr, expressions, sequence, coverFormalsList, spreadFound, oldParenthesizedCount;39793980oldParenthesizedCount = state.parenthesizedCount;39813982marker = markerCreate();3983expr = parseAssignmentExpression();3984expressions = [ expr ];39853986if (match(',')) {3987while (index < length) {3988if (!match(',')) {3989break;3990}39913992lex();3993expr = parseSpreadOrAssignmentExpression();3994expressions.push(expr);39953996if (expr.type === Syntax.SpreadElement) {3997spreadFound = true;3998if (!match(')')) {3999throwError({}, Messages.ElementAfterSpreadElement);4000}4001break;4002}4003}40044005sequence = markerApply(marker, delegate.createSequenceExpression(expressions));4006}40074008if (match('=>')) {4009// Do not allow nested parentheses on the LHS of the =>.4010if (state.parenthesizedCount === oldParenthesizedCount || state.parenthesizedCount === (oldParenthesizedCount + 1)) {4011expr = expr.type === Syntax.SequenceExpression ? expr.expressions : expressions;4012coverFormalsList = reinterpretAsCoverFormalsList(expr);4013if (coverFormalsList) {4014return parseArrowFunctionExpression(coverFormalsList, marker);4015}4016}4017throwUnexpected(lex());4018}40194020if (spreadFound && lookahead2().value !== '=>') {4021throwError({}, Messages.IllegalSpread);4022}40234024return sequence || expr;4025}40264027// 12.1 Block40284029function parseStatementList() {4030var list = [],4031statement;40324033while (index < length) {4034if (match('}')) {4035break;4036}4037statement = parseSourceElement();4038if (typeof statement === 'undefined') {4039break;4040}4041list.push(statement);4042}40434044return list;4045}40464047function parseBlock() {4048var block, marker = markerCreate();40494050expect('{');40514052block = parseStatementList();40534054expect('}');40554056return markerApply(marker, delegate.createBlockStatement(block));4057}40584059// 12.2 Variable Statement40604061function parseTypeParameterDeclaration() {4062var marker = markerCreate(), paramTypes = [];40634064expect('<');4065while (!match('>')) {4066paramTypes.push(parseVariableIdentifier());4067if (!match('>')) {4068expect(',');4069}4070}4071expect('>');40724073return markerApply(marker, delegate.createTypeParameterDeclaration(4074paramTypes4075));4076}40774078function parseTypeParameterInstantiation() {4079var marker = markerCreate(), oldInType = state.inType, paramTypes = [];40804081state.inType = true;40824083expect('<');4084while (!match('>')) {4085paramTypes.push(parseType());4086if (!match('>')) {4087expect(',');4088}4089}4090expect('>');40914092state.inType = oldInType;40934094return markerApply(marker, delegate.createTypeParameterInstantiation(4095paramTypes4096));4097}40984099function parseObjectTypeIndexer(marker, isStatic) {4100var id, key, value;41014102expect('[');4103id = parseObjectPropertyKey();4104expect(':');4105key = parseType();4106expect(']');4107expect(':');4108value = parseType();41094110return markerApply(marker, delegate.createObjectTypeIndexer(4111id,4112key,4113value,4114isStatic4115));4116}41174118function parseObjectTypeMethodish(marker) {4119var params = [], rest = null, returnType, typeParameters = null;4120if (match('<')) {4121typeParameters = parseTypeParameterDeclaration();4122}41234124expect('(');4125while (lookahead.type === Token.Identifier) {4126params.push(parseFunctionTypeParam());4127if (!match(')')) {4128expect(',');4129}4130}41314132if (match('...')) {4133lex();4134rest = parseFunctionTypeParam();4135}4136expect(')');4137expect(':');4138returnType = parseType();41394140return markerApply(marker, delegate.createFunctionTypeAnnotation(4141params,4142returnType,4143rest,4144typeParameters4145));4146}41474148function parseObjectTypeMethod(marker, isStatic, key) {4149var optional = false, value;4150value = parseObjectTypeMethodish(marker);41514152return markerApply(marker, delegate.createObjectTypeProperty(4153key,4154value,4155optional,4156isStatic4157));4158}41594160function parseObjectTypeCallProperty(marker, isStatic) {4161var valueMarker = markerCreate();4162return markerApply(marker, delegate.createObjectTypeCallProperty(4163parseObjectTypeMethodish(valueMarker),4164isStatic4165));4166}41674168function parseObjectType(allowStatic) {4169var callProperties = [], indexers = [], marker, optional = false,4170properties = [], property, propertyKey, propertyTypeAnnotation,4171token, isStatic;41724173expect('{');41744175while (!match('}')) {4176marker = markerCreate();4177if (allowStatic && matchContextualKeyword('static')) {4178token = lex();4179isStatic = true;4180}41814182if (match('[')) {4183indexers.push(parseObjectTypeIndexer(marker, isStatic));4184} else if (match('(') || match('<')) {4185callProperties.push(parseObjectTypeCallProperty(marker, allowStatic));4186} else {4187if (isStatic && match(':')) {4188propertyKey = markerApply(marker, delegate.createIdentifier(token));4189throwErrorTolerant(token, Messages.StrictReservedWord);4190} else {4191propertyKey = parseObjectPropertyKey();4192}4193if (match('<') || match('(')) {4194// This is a method property4195properties.push(parseObjectTypeMethod(marker, isStatic, propertyKey));4196} else {4197if (match('?')) {4198lex();4199optional = true;4200}4201expect(':');4202propertyTypeAnnotation = parseType();4203properties.push(markerApply(marker, delegate.createObjectTypeProperty(4204propertyKey,4205propertyTypeAnnotation,4206optional,4207isStatic4208)));4209}4210}42114212if (match(';')) {4213lex();4214} else if (!match('}')) {4215throwUnexpected(lookahead);4216}4217}42184219expect('}');42204221return delegate.createObjectTypeAnnotation(4222properties,4223indexers,4224callProperties4225);4226}42274228function parseGenericType() {4229var marker = markerCreate(), returnType = null,4230typeParameters = null, typeIdentifier,4231typeIdentifierMarker = markerCreate;42324233typeIdentifier = parseVariableIdentifier();42344235while (match('.')) {4236expect('.');4237typeIdentifier = markerApply(marker, delegate.createQualifiedTypeIdentifier(4238typeIdentifier,4239parseVariableIdentifier()4240));4241}42424243if (match('<')) {4244typeParameters = parseTypeParameterInstantiation();4245}42464247return markerApply(marker, delegate.createGenericTypeAnnotation(4248typeIdentifier,4249typeParameters4250));4251}42524253function parseVoidType() {4254var marker = markerCreate();4255expectKeyword('void');4256return markerApply(marker, delegate.createVoidTypeAnnotation());4257}42584259function parseTypeofType() {4260var argument, marker = markerCreate();4261expectKeyword('typeof');4262argument = parsePrimaryType();4263return markerApply(marker, delegate.createTypeofTypeAnnotation(4264argument4265));4266}42674268function parseTupleType() {4269var marker = markerCreate(), types = [];4270expect('[');4271// We allow trailing commas4272while (index < length && !match(']')) {4273types.push(parseType());4274if (match(']')) {4275break;4276}4277expect(',');4278}4279expect(']');4280return markerApply(marker, delegate.createTupleTypeAnnotation(4281types4282));4283}42844285function parseFunctionTypeParam() {4286var marker = markerCreate(), name, optional = false, typeAnnotation;4287name = parseVariableIdentifier();4288if (match('?')) {4289lex();4290optional = true;4291}4292expect(':');4293typeAnnotation = parseType();4294return markerApply(marker, delegate.createFunctionTypeParam(4295name,4296typeAnnotation,4297optional4298));4299}43004301function parseFunctionTypeParams() {4302var ret = { params: [], rest: null };4303while (lookahead.type === Token.Identifier) {4304ret.params.push(parseFunctionTypeParam());4305if (!match(')')) {4306expect(',');4307}4308}43094310if (match('...')) {4311lex();4312ret.rest = parseFunctionTypeParam();4313}4314return ret;4315}43164317// The parsing of types roughly parallels the parsing of expressions, and4318// primary types are kind of like primary expressions...they're the4319// primitives with which other types are constructed.4320function parsePrimaryType() {4321var typeIdentifier = null, params = null, returnType = null,4322marker = markerCreate(), rest = null, tmp,4323typeParameters, token, type, isGroupedType = false;43244325switch (lookahead.type) {4326case Token.Identifier:4327switch (lookahead.value) {4328case 'any':4329lex();4330return markerApply(marker, delegate.createAnyTypeAnnotation());4331case 'bool': // fallthrough4332case 'boolean':4333lex();4334return markerApply(marker, delegate.createBooleanTypeAnnotation());4335case 'number':4336lex();4337return markerApply(marker, delegate.createNumberTypeAnnotation());4338case 'string':4339lex();4340return markerApply(marker, delegate.createStringTypeAnnotation());4341}4342return markerApply(marker, parseGenericType());4343case Token.Punctuator:4344switch (lookahead.value) {4345case '{':4346return markerApply(marker, parseObjectType());4347case '[':4348return parseTupleType();4349case '<':4350typeParameters = parseTypeParameterDeclaration();4351expect('(');4352tmp = parseFunctionTypeParams();4353params = tmp.params;4354rest = tmp.rest;4355expect(')');43564357expect('=>');43584359returnType = parseType();43604361return markerApply(marker, delegate.createFunctionTypeAnnotation(4362params,4363returnType,4364rest,4365typeParameters4366));4367case '(':4368lex();4369// Check to see if this is actually a grouped type4370if (!match(')') && !match('...')) {4371if (lookahead.type === Token.Identifier) {4372token = lookahead2();4373isGroupedType = token.value !== '?' && token.value !== ':';4374} else {4375isGroupedType = true;4376}4377}43784379if (isGroupedType) {4380type = parseType();4381expect(')');43824383// If we see a => next then someone was probably confused about4384// function types, so we can provide a better error message4385if (match('=>')) {4386throwError({}, Messages.ConfusedAboutFunctionType);4387}43884389return type;4390}43914392tmp = parseFunctionTypeParams();4393params = tmp.params;4394rest = tmp.rest;43954396expect(')');43974398expect('=>');43994400returnType = parseType();44014402return markerApply(marker, delegate.createFunctionTypeAnnotation(4403params,4404returnType,4405rest,4406null /* typeParameters */4407));4408}4409break;4410case Token.Keyword:4411switch (lookahead.value) {4412case 'void':4413return markerApply(marker, parseVoidType());4414case 'typeof':4415return markerApply(marker, parseTypeofType());4416}4417break;4418case Token.StringLiteral:4419token = lex();4420if (token.octal) {4421throwError(token, Messages.StrictOctalLiteral);4422}4423return markerApply(marker, delegate.createStringLiteralTypeAnnotation(4424token4425));4426}44274428throwUnexpected(lookahead);4429}44304431function parsePostfixType() {4432var marker = markerCreate(), t = parsePrimaryType();4433if (match('[')) {4434expect('[');4435expect(']');4436return markerApply(marker, delegate.createArrayTypeAnnotation(t));4437}4438return t;4439}44404441function parsePrefixType() {4442var marker = markerCreate();4443if (match('?')) {4444lex();4445return markerApply(marker, delegate.createNullableTypeAnnotation(4446parsePrefixType()4447));4448}4449return parsePostfixType();4450}445144524453function parseIntersectionType() {4454var marker = markerCreate(), type, types;4455type = parsePrefixType();4456types = [type];4457while (match('&')) {4458lex();4459types.push(parsePrefixType());4460}44614462return types.length === 1 ?4463type :4464markerApply(marker, delegate.createIntersectionTypeAnnotation(4465types4466));4467}44684469function parseUnionType() {4470var marker = markerCreate(), type, types;4471type = parseIntersectionType();4472types = [type];4473while (match('|')) {4474lex();4475types.push(parseIntersectionType());4476}4477return types.length === 1 ?4478type :4479markerApply(marker, delegate.createUnionTypeAnnotation(4480types4481));4482}44834484function parseType() {4485var oldInType = state.inType, type;4486state.inType = true;44874488type = parseUnionType();44894490state.inType = oldInType;4491return type;4492}44934494function parseTypeAnnotation() {4495var marker = markerCreate(), type;44964497expect(':');4498type = parseType();44994500return markerApply(marker, delegate.createTypeAnnotation(type));4501}45024503function parseVariableIdentifier() {4504var marker = markerCreate(),4505token = lex();45064507if (token.type !== Token.Identifier) {4508throwUnexpected(token);4509}45104511return markerApply(marker, delegate.createIdentifier(token.value));4512}45134514function parseTypeAnnotatableIdentifier(requireTypeAnnotation, canBeOptionalParam) {4515var marker = markerCreate(),4516ident = parseVariableIdentifier(),4517isOptionalParam = false;45184519if (canBeOptionalParam && match('?')) {4520expect('?');4521isOptionalParam = true;4522}45234524if (requireTypeAnnotation || match(':')) {4525ident.typeAnnotation = parseTypeAnnotation();4526ident = markerApply(marker, ident);4527}45284529if (isOptionalParam) {4530ident.optional = true;4531ident = markerApply(marker, ident);4532}45334534return ident;4535}45364537function parseVariableDeclaration(kind) {4538var id,4539marker = markerCreate(),4540init = null,4541typeAnnotationMarker = markerCreate();4542if (match('{')) {4543id = parseObjectInitialiser();4544reinterpretAsAssignmentBindingPattern(id);4545if (match(':')) {4546id.typeAnnotation = parseTypeAnnotation();4547markerApply(typeAnnotationMarker, id);4548}4549} else if (match('[')) {4550id = parseArrayInitialiser();4551reinterpretAsAssignmentBindingPattern(id);4552if (match(':')) {4553id.typeAnnotation = parseTypeAnnotation();4554markerApply(typeAnnotationMarker, id);4555}4556} else {4557id = state.allowKeyword ? parseNonComputedProperty() : parseTypeAnnotatableIdentifier();4558// 12.2.14559if (strict && isRestrictedWord(id.name)) {4560throwErrorTolerant({}, Messages.StrictVarName);4561}4562}45634564if (kind === 'const') {4565if (!match('=')) {4566throwError({}, Messages.NoUnintializedConst);4567}4568expect('=');4569init = parseAssignmentExpression();4570} else if (match('=')) {4571lex();4572init = parseAssignmentExpression();4573}45744575return markerApply(marker, delegate.createVariableDeclarator(id, init));4576}45774578function parseVariableDeclarationList(kind) {4579var list = [];45804581do {4582list.push(parseVariableDeclaration(kind));4583if (!match(',')) {4584break;4585}4586lex();4587} while (index < length);45884589return list;4590}45914592function parseVariableStatement() {4593var declarations, marker = markerCreate();45944595expectKeyword('var');45964597declarations = parseVariableDeclarationList();45984599consumeSemicolon();46004601return markerApply(marker, delegate.createVariableDeclaration(declarations, 'var'));4602}46034604// kind may be `const` or `let`4605// Both are experimental and not in the specification yet.4606// see http://wiki.ecmascript.org/doku.php?id=harmony:const4607// and http://wiki.ecmascript.org/doku.php?id=harmony:let4608function parseConstLetDeclaration(kind) {4609var declarations, marker = markerCreate();46104611expectKeyword(kind);46124613declarations = parseVariableDeclarationList(kind);46144615consumeSemicolon();46164617return markerApply(marker, delegate.createVariableDeclaration(declarations, kind));4618}46194620// people.mozilla.org/~jorendorff/es6-draft.html46214622function parseModuleSpecifier() {4623var marker = markerCreate(),4624specifier;46254626if (lookahead.type !== Token.StringLiteral) {4627throwError({}, Messages.InvalidModuleSpecifier);4628}4629specifier = delegate.createModuleSpecifier(lookahead);4630lex();4631return markerApply(marker, specifier);4632}46334634function parseExportBatchSpecifier() {4635var marker = markerCreate();4636expect('*');4637return markerApply(marker, delegate.createExportBatchSpecifier());4638}46394640function parseExportSpecifier() {4641var id, name = null, marker = markerCreate(), from;4642if (matchKeyword('default')) {4643lex();4644id = markerApply(marker, delegate.createIdentifier('default'));4645// export {default} from "something";4646} else {4647id = parseVariableIdentifier();4648}4649if (matchContextualKeyword('as')) {4650lex();4651name = parseNonComputedProperty();4652}46534654return markerApply(marker, delegate.createExportSpecifier(id, name));4655}46564657function parseExportDeclaration() {4658var backtrackToken, id, previousAllowKeyword, declaration = null,4659isExportFromIdentifier,4660src = null, specifiers = [],4661marker = markerCreate();46624663expectKeyword('export');46644665if (matchKeyword('default')) {4666// covers:4667// export default ...4668lex();4669if (matchKeyword('function') || matchKeyword('class')) {4670backtrackToken = lookahead;4671lex();4672if (isIdentifierName(lookahead)) {4673// covers:4674// export default function foo () {}4675// export default class foo {}4676id = parseNonComputedProperty();4677rewind(backtrackToken);4678return markerApply(marker, delegate.createExportDeclaration(true, parseSourceElement(), [id], null));4679}4680// covers:4681// export default function () {}4682// export default class {}4683rewind(backtrackToken);4684switch (lookahead.value) {4685case 'class':4686return markerApply(marker, delegate.createExportDeclaration(true, parseClassExpression(), [], null));4687case 'function':4688return markerApply(marker, delegate.createExportDeclaration(true, parseFunctionExpression(), [], null));4689}4690}46914692if (matchContextualKeyword('from')) {4693throwError({}, Messages.UnexpectedToken, lookahead.value);4694}46954696// covers:4697// export default {};4698// export default [];4699if (match('{')) {4700declaration = parseObjectInitialiser();4701} else if (match('[')) {4702declaration = parseArrayInitialiser();4703} else {4704declaration = parseAssignmentExpression();4705}4706consumeSemicolon();4707return markerApply(marker, delegate.createExportDeclaration(true, declaration, [], null));4708}47094710// non-default export4711if (lookahead.type === Token.Keyword) {4712// covers:4713// export var f = 1;4714switch (lookahead.value) {4715case 'let':4716case 'const':4717case 'var':4718case 'class':4719case 'function':4720return markerApply(marker, delegate.createExportDeclaration(false, parseSourceElement(), specifiers, null));4721}4722}47234724if (match('*')) {4725// covers:4726// export * from "foo";4727specifiers.push(parseExportBatchSpecifier());47284729if (!matchContextualKeyword('from')) {4730throwError({}, lookahead.value ?4731Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4732}4733lex();4734src = parseModuleSpecifier();4735consumeSemicolon();47364737return markerApply(marker, delegate.createExportDeclaration(false, null, specifiers, src));4738}47394740expect('{');4741do {4742isExportFromIdentifier = isExportFromIdentifier || matchKeyword('default');4743specifiers.push(parseExportSpecifier());4744} while (match(',') && lex());4745expect('}');47464747if (matchContextualKeyword('from')) {4748// covering:4749// export {default} from "foo";4750// export {foo} from "foo";4751lex();4752src = parseModuleSpecifier();4753consumeSemicolon();4754} else if (isExportFromIdentifier) {4755// covering:4756// export {default}; // missing fromClause4757throwError({}, lookahead.value ?4758Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4759} else {4760// cover4761// export {foo};4762consumeSemicolon();4763}4764return markerApply(marker, delegate.createExportDeclaration(false, declaration, specifiers, src));4765}476647674768function parseImportSpecifier() {4769// import {<foo as bar>} ...;4770var id, name = null, marker = markerCreate();47714772id = parseNonComputedProperty();4773if (matchContextualKeyword('as')) {4774lex();4775name = parseVariableIdentifier();4776}47774778return markerApply(marker, delegate.createImportSpecifier(id, name));4779}47804781function parseNamedImports() {4782var specifiers = [];4783// {foo, bar as bas}4784expect('{');4785do {4786specifiers.push(parseImportSpecifier());4787} while (match(',') && lex());4788expect('}');4789return specifiers;4790}47914792function parseImportDefaultSpecifier() {4793// import <foo> ...;4794var id, marker = markerCreate();47954796id = parseNonComputedProperty();47974798return markerApply(marker, delegate.createImportDefaultSpecifier(id));4799}48004801function parseImportNamespaceSpecifier() {4802// import <* as foo> ...;4803var id, marker = markerCreate();48044805expect('*');4806if (!matchContextualKeyword('as')) {4807throwError({}, Messages.NoAsAfterImportNamespace);4808}4809lex();4810id = parseNonComputedProperty();48114812return markerApply(marker, delegate.createImportNamespaceSpecifier(id));4813}48144815function parseImportDeclaration() {4816var specifiers, src, marker = markerCreate();48174818expectKeyword('import');4819specifiers = [];48204821if (lookahead.type === Token.StringLiteral) {4822// covers:4823// import "foo";4824src = parseModuleSpecifier();4825consumeSemicolon();4826return markerApply(marker, delegate.createImportDeclaration(specifiers, src));4827}48284829if (!matchKeyword('default') && isIdentifierName(lookahead)) {4830// covers:4831// import foo4832// import foo, ...4833specifiers.push(parseImportDefaultSpecifier());4834if (match(',')) {4835lex();4836}4837}4838if (match('*')) {4839// covers:4840// import foo, * as foo4841// import * as foo4842specifiers.push(parseImportNamespaceSpecifier());4843} else if (match('{')) {4844// covers:4845// import foo, {bar}4846// import {bar}4847specifiers = specifiers.concat(parseNamedImports());4848}48494850if (!matchContextualKeyword('from')) {4851throwError({}, lookahead.value ?4852Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4853}4854lex();4855src = parseModuleSpecifier();4856consumeSemicolon();48574858return markerApply(marker, delegate.createImportDeclaration(specifiers, src));4859}48604861// 12.3 Empty Statement48624863function parseEmptyStatement() {4864var marker = markerCreate();4865expect(';');4866return markerApply(marker, delegate.createEmptyStatement());4867}48684869// 12.4 Expression Statement48704871function parseExpressionStatement() {4872var marker = markerCreate(), expr = parseExpression();4873consumeSemicolon();4874return markerApply(marker, delegate.createExpressionStatement(expr));4875}48764877// 12.5 If statement48784879function parseIfStatement() {4880var test, consequent, alternate, marker = markerCreate();48814882expectKeyword('if');48834884expect('(');48854886test = parseExpression();48874888expect(')');48894890consequent = parseStatement();48914892if (matchKeyword('else')) {4893lex();4894alternate = parseStatement();4895} else {4896alternate = null;4897}48984899return markerApply(marker, delegate.createIfStatement(test, consequent, alternate));4900}49014902// 12.6 Iteration Statements49034904function parseDoWhileStatement() {4905var body, test, oldInIteration, marker = markerCreate();49064907expectKeyword('do');49084909oldInIteration = state.inIteration;4910state.inIteration = true;49114912body = parseStatement();49134914state.inIteration = oldInIteration;49154916expectKeyword('while');49174918expect('(');49194920test = parseExpression();49214922expect(')');49234924if (match(';')) {4925lex();4926}49274928return markerApply(marker, delegate.createDoWhileStatement(body, test));4929}49304931function parseWhileStatement() {4932var test, body, oldInIteration, marker = markerCreate();49334934expectKeyword('while');49354936expect('(');49374938test = parseExpression();49394940expect(')');49414942oldInIteration = state.inIteration;4943state.inIteration = true;49444945body = parseStatement();49464947state.inIteration = oldInIteration;49484949return markerApply(marker, delegate.createWhileStatement(test, body));4950}49514952function parseForVariableDeclaration() {4953var marker = markerCreate(),4954token = lex(),4955declarations = parseVariableDeclarationList();49564957return markerApply(marker, delegate.createVariableDeclaration(declarations, token.value));4958}49594960function parseForStatement(opts) {4961var init, test, update, left, right, body, operator, oldInIteration,4962marker = markerCreate();4963init = test = update = null;4964expectKeyword('for');49654966// http://wiki.ecmascript.org/doku.php?id=proposals:iterators_and_generators&s=each4967if (matchContextualKeyword('each')) {4968throwError({}, Messages.EachNotAllowed);4969}49704971expect('(');49724973if (match(';')) {4974lex();4975} else {4976if (matchKeyword('var') || matchKeyword('let') || matchKeyword('const')) {4977state.allowIn = false;4978init = parseForVariableDeclaration();4979state.allowIn = true;49804981if (init.declarations.length === 1) {4982if (matchKeyword('in') || matchContextualKeyword('of')) {4983operator = lookahead;4984if (!((operator.value === 'in' || init.kind !== 'var') && init.declarations[0].init)) {4985lex();4986left = init;4987right = parseExpression();4988init = null;4989}4990}4991}4992} else {4993state.allowIn = false;4994init = parseExpression();4995state.allowIn = true;49964997if (matchContextualKeyword('of')) {4998operator = lex();4999left = init;5000right = parseExpression();5001init = null;5002} else if (matchKeyword('in')) {5003// LeftHandSideExpression5004if (!isAssignableLeftHandSide(init)) {5005throwError({}, Messages.InvalidLHSInForIn);5006}5007operator = lex();5008left = init;5009right = parseExpression();5010init = null;5011}5012}50135014if (typeof left === 'undefined') {5015expect(';');5016}5017}50185019if (typeof left === 'undefined') {50205021if (!match(';')) {5022test = parseExpression();5023}5024expect(';');50255026if (!match(')')) {5027update = parseExpression();5028}5029}50305031expect(')');50325033oldInIteration = state.inIteration;5034state.inIteration = true;50355036if (!(opts !== undefined && opts.ignoreBody)) {5037body = parseStatement();5038}50395040state.inIteration = oldInIteration;50415042if (typeof left === 'undefined') {5043return markerApply(marker, delegate.createForStatement(init, test, update, body));5044}50455046if (operator.value === 'in') {5047return markerApply(marker, delegate.createForInStatement(left, right, body));5048}5049return markerApply(marker, delegate.createForOfStatement(left, right, body));5050}50515052// 12.7 The continue statement50535054function parseContinueStatement() {5055var label = null, key, marker = markerCreate();50565057expectKeyword('continue');50585059// Optimize the most common form: 'continue;'.5060if (source.charCodeAt(index) === 59) {5061lex();50625063if (!state.inIteration) {5064throwError({}, Messages.IllegalContinue);5065}50665067return markerApply(marker, delegate.createContinueStatement(null));5068}50695070if (peekLineTerminator()) {5071if (!state.inIteration) {5072throwError({}, Messages.IllegalContinue);5073}50745075return markerApply(marker, delegate.createContinueStatement(null));5076}50775078if (lookahead.type === Token.Identifier) {5079label = parseVariableIdentifier();50805081key = '$' + label.name;5082if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {5083throwError({}, Messages.UnknownLabel, label.name);5084}5085}50865087consumeSemicolon();50885089if (label === null && !state.inIteration) {5090throwError({}, Messages.IllegalContinue);5091}50925093return markerApply(marker, delegate.createContinueStatement(label));5094}50955096// 12.8 The break statement50975098function parseBreakStatement() {5099var label = null, key, marker = markerCreate();51005101expectKeyword('break');51025103// Catch the very common case first: immediately a semicolon (char #59).5104if (source.charCodeAt(index) === 59) {5105lex();51065107if (!(state.inIteration || state.inSwitch)) {5108throwError({}, Messages.IllegalBreak);5109}51105111return markerApply(marker, delegate.createBreakStatement(null));5112}51135114if (peekLineTerminator()) {5115if (!(state.inIteration || state.inSwitch)) {5116throwError({}, Messages.IllegalBreak);5117}51185119return markerApply(marker, delegate.createBreakStatement(null));5120}51215122if (lookahead.type === Token.Identifier) {5123label = parseVariableIdentifier();51245125key = '$' + label.name;5126if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {5127throwError({}, Messages.UnknownLabel, label.name);5128}5129}51305131consumeSemicolon();51325133if (label === null && !(state.inIteration || state.inSwitch)) {5134throwError({}, Messages.IllegalBreak);5135}51365137return markerApply(marker, delegate.createBreakStatement(label));5138}51395140// 12.9 The return statement51415142function parseReturnStatement() {5143var argument = null, marker = markerCreate();51445145expectKeyword('return');51465147if (!state.inFunctionBody) {5148throwErrorTolerant({}, Messages.IllegalReturn);5149}51505151// 'return' followed by a space and an identifier is very common.5152if (source.charCodeAt(index) === 32) {5153if (isIdentifierStart(source.charCodeAt(index + 1))) {5154argument = parseExpression();5155consumeSemicolon();5156return markerApply(marker, delegate.createReturnStatement(argument));5157}5158}51595160if (peekLineTerminator()) {5161return markerApply(marker, delegate.createReturnStatement(null));5162}51635164if (!match(';')) {5165if (!match('}') && lookahead.type !== Token.EOF) {5166argument = parseExpression();5167}5168}51695170consumeSemicolon();51715172return markerApply(marker, delegate.createReturnStatement(argument));5173}51745175// 12.10 The with statement51765177function parseWithStatement() {5178var object, body, marker = markerCreate();51795180if (strict) {5181throwErrorTolerant({}, Messages.StrictModeWith);5182}51835184expectKeyword('with');51855186expect('(');51875188object = parseExpression();51895190expect(')');51915192body = parseStatement();51935194return markerApply(marker, delegate.createWithStatement(object, body));5195}51965197// 12.10 The swith statement51985199function parseSwitchCase() {5200var test,5201consequent = [],5202sourceElement,5203marker = markerCreate();52045205if (matchKeyword('default')) {5206lex();5207test = null;5208} else {5209expectKeyword('case');5210test = parseExpression();5211}5212expect(':');52135214while (index < length) {5215if (match('}') || matchKeyword('default') || matchKeyword('case')) {5216break;5217}5218sourceElement = parseSourceElement();5219if (typeof sourceElement === 'undefined') {5220break;5221}5222consequent.push(sourceElement);5223}52245225return markerApply(marker, delegate.createSwitchCase(test, consequent));5226}52275228function parseSwitchStatement() {5229var discriminant, cases, clause, oldInSwitch, defaultFound, marker = markerCreate();52305231expectKeyword('switch');52325233expect('(');52345235discriminant = parseExpression();52365237expect(')');52385239expect('{');52405241cases = [];52425243if (match('}')) {5244lex();5245return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));5246}52475248oldInSwitch = state.inSwitch;5249state.inSwitch = true;5250defaultFound = false;52515252while (index < length) {5253if (match('}')) {5254break;5255}5256clause = parseSwitchCase();5257if (clause.test === null) {5258if (defaultFound) {5259throwError({}, Messages.MultipleDefaultsInSwitch);5260}5261defaultFound = true;5262}5263cases.push(clause);5264}52655266state.inSwitch = oldInSwitch;52675268expect('}');52695270return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));5271}52725273// 12.13 The throw statement52745275function parseThrowStatement() {5276var argument, marker = markerCreate();52775278expectKeyword('throw');52795280if (peekLineTerminator()) {5281throwError({}, Messages.NewlineAfterThrow);5282}52835284argument = parseExpression();52855286consumeSemicolon();52875288return markerApply(marker, delegate.createThrowStatement(argument));5289}52905291// 12.14 The try statement52925293function parseCatchClause() {5294var param, body, marker = markerCreate();52955296expectKeyword('catch');52975298expect('(');5299if (match(')')) {5300throwUnexpected(lookahead);5301}53025303param = parseExpression();5304// 12.14.15305if (strict && param.type === Syntax.Identifier && isRestrictedWord(param.name)) {5306throwErrorTolerant({}, Messages.StrictCatchVariable);5307}53085309expect(')');5310body = parseBlock();5311return markerApply(marker, delegate.createCatchClause(param, body));5312}53135314function parseTryStatement() {5315var block, handlers = [], finalizer = null, marker = markerCreate();53165317expectKeyword('try');53185319block = parseBlock();53205321if (matchKeyword('catch')) {5322handlers.push(parseCatchClause());5323}53245325if (matchKeyword('finally')) {5326lex();5327finalizer = parseBlock();5328}53295330if (handlers.length === 0 && !finalizer) {5331throwError({}, Messages.NoCatchOrFinally);5332}53335334return markerApply(marker, delegate.createTryStatement(block, [], handlers, finalizer));5335}53365337// 12.15 The debugger statement53385339function parseDebuggerStatement() {5340var marker = markerCreate();5341expectKeyword('debugger');53425343consumeSemicolon();53445345return markerApply(marker, delegate.createDebuggerStatement());5346}53475348// 12 Statements53495350function parseStatement() {5351var type = lookahead.type,5352marker,5353expr,5354labeledBody,5355key;53565357if (type === Token.EOF) {5358throwUnexpected(lookahead);5359}53605361if (type === Token.Punctuator) {5362switch (lookahead.value) {5363case ';':5364return parseEmptyStatement();5365case '{':5366return parseBlock();5367case '(':5368return parseExpressionStatement();5369default:5370break;5371}5372}53735374if (type === Token.Keyword) {5375switch (lookahead.value) {5376case 'break':5377return parseBreakStatement();5378case 'continue':5379return parseContinueStatement();5380case 'debugger':5381return parseDebuggerStatement();5382case 'do':5383return parseDoWhileStatement();5384case 'for':5385return parseForStatement();5386case 'function':5387return parseFunctionDeclaration();5388case 'class':5389return parseClassDeclaration();5390case 'if':5391return parseIfStatement();5392case 'return':5393return parseReturnStatement();5394case 'switch':5395return parseSwitchStatement();5396case 'throw':5397return parseThrowStatement();5398case 'try':5399return parseTryStatement();5400case 'var':5401return parseVariableStatement();5402case 'while':5403return parseWhileStatement();5404case 'with':5405return parseWithStatement();5406default:5407break;5408}5409}54105411if (matchAsyncFuncExprOrDecl()) {5412return parseFunctionDeclaration();5413}54145415marker = markerCreate();5416expr = parseExpression();54175418// 12.12 Labelled Statements5419if ((expr.type === Syntax.Identifier) && match(':')) {5420lex();54215422key = '$' + expr.name;5423if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {5424throwError({}, Messages.Redeclaration, 'Label', expr.name);5425}54265427state.labelSet[key] = true;5428labeledBody = parseStatement();5429delete state.labelSet[key];5430return markerApply(marker, delegate.createLabeledStatement(expr, labeledBody));5431}54325433consumeSemicolon();54345435return markerApply(marker, delegate.createExpressionStatement(expr));5436}54375438// 13 Function Definition54395440function parseConciseBody() {5441if (match('{')) {5442return parseFunctionSourceElements();5443}5444return parseAssignmentExpression();5445}54465447function parseFunctionSourceElements() {5448var sourceElement, sourceElements = [], token, directive, firstRestricted,5449oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, oldParenthesizedCount,5450marker = markerCreate();54515452expect('{');54535454while (index < length) {5455if (lookahead.type !== Token.StringLiteral) {5456break;5457}5458token = lookahead;54595460sourceElement = parseSourceElement();5461sourceElements.push(sourceElement);5462if (sourceElement.expression.type !== Syntax.Literal) {5463// this is not directive5464break;5465}5466directive = source.slice(token.range[0] + 1, token.range[1] - 1);5467if (directive === 'use strict') {5468strict = true;5469if (firstRestricted) {5470throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);5471}5472} else {5473if (!firstRestricted && token.octal) {5474firstRestricted = token;5475}5476}5477}54785479oldLabelSet = state.labelSet;5480oldInIteration = state.inIteration;5481oldInSwitch = state.inSwitch;5482oldInFunctionBody = state.inFunctionBody;5483oldParenthesizedCount = state.parenthesizedCount;54845485state.labelSet = {};5486state.inIteration = false;5487state.inSwitch = false;5488state.inFunctionBody = true;5489state.parenthesizedCount = 0;54905491while (index < length) {5492if (match('}')) {5493break;5494}5495sourceElement = parseSourceElement();5496if (typeof sourceElement === 'undefined') {5497break;5498}5499sourceElements.push(sourceElement);5500}55015502expect('}');55035504state.labelSet = oldLabelSet;5505state.inIteration = oldInIteration;5506state.inSwitch = oldInSwitch;5507state.inFunctionBody = oldInFunctionBody;5508state.parenthesizedCount = oldParenthesizedCount;55095510return markerApply(marker, delegate.createBlockStatement(sourceElements));5511}55125513function validateParam(options, param, name) {5514var key = '$' + name;5515if (strict) {5516if (isRestrictedWord(name)) {5517options.stricted = param;5518options.message = Messages.StrictParamName;5519}5520if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {5521options.stricted = param;5522options.message = Messages.StrictParamDupe;5523}5524} else if (!options.firstRestricted) {5525if (isRestrictedWord(name)) {5526options.firstRestricted = param;5527options.message = Messages.StrictParamName;5528} else if (isStrictModeReservedWord(name)) {5529options.firstRestricted = param;5530options.message = Messages.StrictReservedWord;5531} else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {5532options.firstRestricted = param;5533options.message = Messages.StrictParamDupe;5534}5535}5536options.paramSet[key] = true;5537}55385539function parseParam(options) {5540var marker, token, rest, param, def;55415542token = lookahead;5543if (token.value === '...') {5544token = lex();5545rest = true;5546}55475548if (match('[')) {5549marker = markerCreate();5550param = parseArrayInitialiser();5551reinterpretAsDestructuredParameter(options, param);5552if (match(':')) {5553param.typeAnnotation = parseTypeAnnotation();5554markerApply(marker, param);5555}5556} else if (match('{')) {5557marker = markerCreate();5558if (rest) {5559throwError({}, Messages.ObjectPatternAsRestParameter);5560}5561param = parseObjectInitialiser();5562reinterpretAsDestructuredParameter(options, param);5563if (match(':')) {5564param.typeAnnotation = parseTypeAnnotation();5565markerApply(marker, param);5566}5567} else {5568param =5569rest5570? parseTypeAnnotatableIdentifier(5571false, /* requireTypeAnnotation */5572false /* canBeOptionalParam */5573)5574: parseTypeAnnotatableIdentifier(5575false, /* requireTypeAnnotation */5576true /* canBeOptionalParam */5577);55785579validateParam(options, token, token.value);5580}55815582if (match('=')) {5583if (rest) {5584throwErrorTolerant(lookahead, Messages.DefaultRestParameter);5585}5586lex();5587def = parseAssignmentExpression();5588++options.defaultCount;5589}55905591if (rest) {5592if (!match(')')) {5593throwError({}, Messages.ParameterAfterRestParameter);5594}5595options.rest = param;5596return false;5597}55985599options.params.push(param);5600options.defaults.push(def);5601return !match(')');5602}56035604function parseParams(firstRestricted) {5605var options, marker = markerCreate();56065607options = {5608params: [],5609defaultCount: 0,5610defaults: [],5611rest: null,5612firstRestricted: firstRestricted5613};56145615expect('(');56165617if (!match(')')) {5618options.paramSet = {};5619while (index < length) {5620if (!parseParam(options)) {5621break;5622}5623expect(',');5624}5625}56265627expect(')');56285629if (options.defaultCount === 0) {5630options.defaults = [];5631}56325633if (match(':')) {5634options.returnType = parseTypeAnnotation();5635}56365637return markerApply(marker, options);5638}56395640function parseFunctionDeclaration() {5641var id, body, token, tmp, firstRestricted, message, generator, isAsync,5642previousStrict, previousYieldAllowed, previousAwaitAllowed,5643marker = markerCreate(), typeParameters;56445645isAsync = false;5646if (matchAsync()) {5647lex();5648isAsync = true;5649}56505651expectKeyword('function');56525653generator = false;5654if (match('*')) {5655lex();5656generator = true;5657}56585659token = lookahead;56605661id = parseVariableIdentifier();56625663if (match('<')) {5664typeParameters = parseTypeParameterDeclaration();5665}56665667if (strict) {5668if (isRestrictedWord(token.value)) {5669throwErrorTolerant(token, Messages.StrictFunctionName);5670}5671} else {5672if (isRestrictedWord(token.value)) {5673firstRestricted = token;5674message = Messages.StrictFunctionName;5675} else if (isStrictModeReservedWord(token.value)) {5676firstRestricted = token;5677message = Messages.StrictReservedWord;5678}5679}56805681tmp = parseParams(firstRestricted);5682firstRestricted = tmp.firstRestricted;5683if (tmp.message) {5684message = tmp.message;5685}56865687previousStrict = strict;5688previousYieldAllowed = state.yieldAllowed;5689state.yieldAllowed = generator;5690previousAwaitAllowed = state.awaitAllowed;5691state.awaitAllowed = isAsync;56925693body = parseFunctionSourceElements();56945695if (strict && firstRestricted) {5696throwError(firstRestricted, message);5697}5698if (strict && tmp.stricted) {5699throwErrorTolerant(tmp.stricted, message);5700}5701strict = previousStrict;5702state.yieldAllowed = previousYieldAllowed;5703state.awaitAllowed = previousAwaitAllowed;57045705return markerApply(5706marker,5707delegate.createFunctionDeclaration(5708id,5709tmp.params,5710tmp.defaults,5711body,5712tmp.rest,5713generator,5714false,5715isAsync,5716tmp.returnType,5717typeParameters5718)5719);5720}57215722function parseFunctionExpression() {5723var token, id = null, firstRestricted, message, tmp, body, generator, isAsync,5724previousStrict, previousYieldAllowed, previousAwaitAllowed,5725marker = markerCreate(), typeParameters;57265727isAsync = false;5728if (matchAsync()) {5729lex();5730isAsync = true;5731}57325733expectKeyword('function');57345735generator = false;57365737if (match('*')) {5738lex();5739generator = true;5740}57415742if (!match('(')) {5743if (!match('<')) {5744token = lookahead;5745id = parseVariableIdentifier();57465747if (strict) {5748if (isRestrictedWord(token.value)) {5749throwErrorTolerant(token, Messages.StrictFunctionName);5750}5751} else {5752if (isRestrictedWord(token.value)) {5753firstRestricted = token;5754message = Messages.StrictFunctionName;5755} else if (isStrictModeReservedWord(token.value)) {5756firstRestricted = token;5757message = Messages.StrictReservedWord;5758}5759}5760}57615762if (match('<')) {5763typeParameters = parseTypeParameterDeclaration();5764}5765}57665767tmp = parseParams(firstRestricted);5768firstRestricted = tmp.firstRestricted;5769if (tmp.message) {5770message = tmp.message;5771}57725773previousStrict = strict;5774previousYieldAllowed = state.yieldAllowed;5775state.yieldAllowed = generator;5776previousAwaitAllowed = state.awaitAllowed;5777state.awaitAllowed = isAsync;57785779body = parseFunctionSourceElements();57805781if (strict && firstRestricted) {5782throwError(firstRestricted, message);5783}5784if (strict && tmp.stricted) {5785throwErrorTolerant(tmp.stricted, message);5786}5787strict = previousStrict;5788state.yieldAllowed = previousYieldAllowed;5789state.awaitAllowed = previousAwaitAllowed;57905791return markerApply(5792marker,5793delegate.createFunctionExpression(5794id,5795tmp.params,5796tmp.defaults,5797body,5798tmp.rest,5799generator,5800false,5801isAsync,5802tmp.returnType,5803typeParameters5804)5805);5806}58075808function parseYieldExpression() {5809var delegateFlag, expr, marker = markerCreate();58105811expectKeyword('yield', !strict);58125813delegateFlag = false;5814if (match('*')) {5815lex();5816delegateFlag = true;5817}58185819expr = parseAssignmentExpression();58205821return markerApply(marker, delegate.createYieldExpression(expr, delegateFlag));5822}58235824function parseAwaitExpression() {5825var expr, marker = markerCreate();5826expectContextualKeyword('await');5827expr = parseAssignmentExpression();5828return markerApply(marker, delegate.createAwaitExpression(expr));5829}58305831// 14 Classes58325833function parseMethodDefinition(existingPropNames, key, isStatic, generator, computed) {5834var token, param, propType, isValidDuplicateProp = false,5835isAsync, typeParameters, tokenValue, returnType,5836annotationMarker;58375838propType = isStatic ? ClassPropertyType.static : ClassPropertyType.prototype;58395840if (generator) {5841return delegate.createMethodDefinition(5842propType,5843'',5844key,5845parsePropertyMethodFunction({ generator: true })5846);5847}58485849tokenValue = key.type === 'Identifier' && key.name;58505851if (tokenValue === 'get' && !match('(')) {5852key = parseObjectPropertyKey();58535854// It is a syntax error if any other properties have a name5855// duplicating this one unless they are a setter5856if (existingPropNames[propType].hasOwnProperty(key.name)) {5857isValidDuplicateProp =5858// There isn't already a getter for this prop5859existingPropNames[propType][key.name].get === undefined5860// There isn't already a data prop by this name5861&& existingPropNames[propType][key.name].data === undefined5862// The only existing prop by this name is a setter5863&& existingPropNames[propType][key.name].set !== undefined;5864if (!isValidDuplicateProp) {5865throwError(key, Messages.IllegalDuplicateClassProperty);5866}5867} else {5868existingPropNames[propType][key.name] = {};5869}5870existingPropNames[propType][key.name].get = true;58715872expect('(');5873expect(')');5874if (match(':')) {5875returnType = parseTypeAnnotation();5876}5877return delegate.createMethodDefinition(5878propType,5879'get',5880key,5881parsePropertyFunction({ generator: false, returnType: returnType })5882);5883}5884if (tokenValue === 'set' && !match('(')) {5885key = parseObjectPropertyKey();58865887// It is a syntax error if any other properties have a name5888// duplicating this one unless they are a getter5889if (existingPropNames[propType].hasOwnProperty(key.name)) {5890isValidDuplicateProp =5891// There isn't already a setter for this prop5892existingPropNames[propType][key.name].set === undefined5893// There isn't already a data prop by this name5894&& existingPropNames[propType][key.name].data === undefined5895// The only existing prop by this name is a getter5896&& existingPropNames[propType][key.name].get !== undefined;5897if (!isValidDuplicateProp) {5898throwError(key, Messages.IllegalDuplicateClassProperty);5899}5900} else {5901existingPropNames[propType][key.name] = {};5902}5903existingPropNames[propType][key.name].set = true;59045905expect('(');5906token = lookahead;5907param = [ parseTypeAnnotatableIdentifier() ];5908expect(')');5909if (match(':')) {5910returnType = parseTypeAnnotation();5911}5912return delegate.createMethodDefinition(5913propType,5914'set',5915key,5916parsePropertyFunction({5917params: param,5918generator: false,5919name: token,5920returnType: returnType5921})5922);5923}59245925if (match('<')) {5926typeParameters = parseTypeParameterDeclaration();5927}59285929isAsync = tokenValue === 'async' && !match('(');5930if (isAsync) {5931key = parseObjectPropertyKey();5932}59335934// It is a syntax error if any other properties have the same name as a5935// non-getter, non-setter method5936if (existingPropNames[propType].hasOwnProperty(key.name)) {5937throwError(key, Messages.IllegalDuplicateClassProperty);5938} else {5939existingPropNames[propType][key.name] = {};5940}5941existingPropNames[propType][key.name].data = true;59425943return delegate.createMethodDefinition(5944propType,5945'',5946key,5947parsePropertyMethodFunction({5948generator: false,5949async: isAsync,5950typeParameters: typeParameters5951})5952);5953}59545955function parseClassProperty(existingPropNames, key, computed, isStatic) {5956var typeAnnotation;59575958typeAnnotation = parseTypeAnnotation();5959expect(';');59605961return delegate.createClassProperty(5962key,5963typeAnnotation,5964computed,5965isStatic5966);5967}59685969function parseClassElement(existingProps) {5970var computed, generator = false, key, marker = markerCreate(),5971isStatic = false;5972if (match(';')) {5973lex();5974return;5975}59765977if (lookahead.value === 'static') {5978lex();5979isStatic = true;5980}59815982if (match('*')) {5983lex();5984generator = true;5985}59865987computed = (lookahead.value === '[');5988key = parseObjectPropertyKey();59895990if (!generator && lookahead.value === ':') {5991return markerApply(marker, parseClassProperty(existingProps, key, computed, isStatic));5992}59935994return markerApply(marker, parseMethodDefinition(5995existingProps,5996key,5997isStatic,5998generator,5999computed6000));6001}60026003function parseClassBody() {6004var classElement, classElements = [], existingProps = {}, marker = markerCreate();60056006existingProps[ClassPropertyType.static] = {};6007existingProps[ClassPropertyType.prototype] = {};60086009expect('{');60106011while (index < length) {6012if (match('}')) {6013break;6014}6015classElement = parseClassElement(existingProps);60166017if (typeof classElement !== 'undefined') {6018classElements.push(classElement);6019}6020}60216022expect('}');60236024return markerApply(marker, delegate.createClassBody(classElements));6025}60266027function parseClassImplements() {6028var id, implemented = [], marker, typeParameters;6029expectContextualKeyword('implements');6030while (index < length) {6031marker = markerCreate();6032id = parseVariableIdentifier();6033if (match('<')) {6034typeParameters = parseTypeParameterInstantiation();6035} else {6036typeParameters = null;6037}6038implemented.push(markerApply(marker, delegate.createClassImplements(6039id,6040typeParameters6041)));6042if (!match(',')) {6043break;6044}6045expect(',');6046}6047return implemented;6048}60496050function parseClassExpression() {6051var id, implemented, previousYieldAllowed, superClass = null,6052superTypeParameters, marker = markerCreate(), typeParameters;60536054expectKeyword('class');60556056if (!matchKeyword('extends') && !matchContextualKeyword('implements') && !match('{')) {6057id = parseVariableIdentifier();6058}60596060if (match('<')) {6061typeParameters = parseTypeParameterDeclaration();6062}60636064if (matchKeyword('extends')) {6065expectKeyword('extends');6066previousYieldAllowed = state.yieldAllowed;6067state.yieldAllowed = false;6068superClass = parseLeftHandSideExpressionAllowCall();6069if (match('<')) {6070superTypeParameters = parseTypeParameterInstantiation();6071}6072state.yieldAllowed = previousYieldAllowed;6073}60746075if (matchContextualKeyword('implements')) {6076implemented = parseClassImplements();6077}60786079return markerApply(marker, delegate.createClassExpression(6080id,6081superClass,6082parseClassBody(),6083typeParameters,6084superTypeParameters,6085implemented6086));6087}60886089function parseClassDeclaration() {6090var id, implemented, previousYieldAllowed, superClass = null,6091superTypeParameters, marker = markerCreate(), typeParameters;60926093expectKeyword('class');60946095id = parseVariableIdentifier();60966097if (match('<')) {6098typeParameters = parseTypeParameterDeclaration();6099}61006101if (matchKeyword('extends')) {6102expectKeyword('extends');6103previousYieldAllowed = state.yieldAllowed;6104state.yieldAllowed = false;6105superClass = parseLeftHandSideExpressionAllowCall();6106if (match('<')) {6107superTypeParameters = parseTypeParameterInstantiation();6108}6109state.yieldAllowed = previousYieldAllowed;6110}61116112if (matchContextualKeyword('implements')) {6113implemented = parseClassImplements();6114}61156116return markerApply(marker, delegate.createClassDeclaration(6117id,6118superClass,6119parseClassBody(),6120typeParameters,6121superTypeParameters,6122implemented6123));6124}61256126// 15 Program61276128function parseSourceElement() {6129var token;6130if (lookahead.type === Token.Keyword) {6131switch (lookahead.value) {6132case 'const':6133case 'let':6134return parseConstLetDeclaration(lookahead.value);6135case 'function':6136return parseFunctionDeclaration();6137default:6138return parseStatement();6139}6140}61416142if (matchContextualKeyword('type')6143&& lookahead2().type === Token.Identifier) {6144return parseTypeAlias();6145}61466147if (matchContextualKeyword('interface')6148&& lookahead2().type === Token.Identifier) {6149return parseInterface();6150}61516152if (matchContextualKeyword('declare')) {6153token = lookahead2();6154if (token.type === Token.Keyword) {6155switch (token.value) {6156case 'class':6157return parseDeclareClass();6158case 'function':6159return parseDeclareFunction();6160case 'var':6161return parseDeclareVariable();6162}6163} else if (token.type === Token.Identifier6164&& token.value === 'module') {6165return parseDeclareModule();6166}6167}61686169if (lookahead.type !== Token.EOF) {6170return parseStatement();6171}6172}61736174function parseProgramElement() {6175if (lookahead.type === Token.Keyword) {6176switch (lookahead.value) {6177case 'export':6178return parseExportDeclaration();6179case 'import':6180return parseImportDeclaration();6181}6182}61836184return parseSourceElement();6185}61866187function parseProgramElements() {6188var sourceElement, sourceElements = [], token, directive, firstRestricted;61896190while (index < length) {6191token = lookahead;6192if (token.type !== Token.StringLiteral) {6193break;6194}61956196sourceElement = parseProgramElement();6197sourceElements.push(sourceElement);6198if (sourceElement.expression.type !== Syntax.Literal) {6199// this is not directive6200break;6201}6202directive = source.slice(token.range[0] + 1, token.range[1] - 1);6203if (directive === 'use strict') {6204strict = true;6205if (firstRestricted) {6206throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);6207}6208} else {6209if (!firstRestricted && token.octal) {6210firstRestricted = token;6211}6212}6213}62146215while (index < length) {6216sourceElement = parseProgramElement();6217if (typeof sourceElement === 'undefined') {6218break;6219}6220sourceElements.push(sourceElement);6221}6222return sourceElements;6223}62246225function parseProgram() {6226var body, marker = markerCreate();6227strict = false;6228peek();6229body = parseProgramElements();6230return markerApply(marker, delegate.createProgram(body));6231}62326233// The following functions are needed only when the option to preserve6234// the comments is active.62356236function addComment(type, value, start, end, loc) {6237var comment;62386239assert(typeof start === 'number', 'Comment must have valid position');62406241// Because the way the actual token is scanned, often the comments6242// (if any) are skipped twice during the lexical analysis.6243// Thus, we need to skip adding a comment if the comment array already6244// handled it.6245if (state.lastCommentStart >= start) {6246return;6247}6248state.lastCommentStart = start;62496250comment = {6251type: type,6252value: value6253};6254if (extra.range) {6255comment.range = [start, end];6256}6257if (extra.loc) {6258comment.loc = loc;6259}6260extra.comments.push(comment);6261if (extra.attachComment) {6262extra.leadingComments.push(comment);6263extra.trailingComments.push(comment);6264}6265}62666267function scanComment() {6268var comment, ch, loc, start, blockComment, lineComment;62696270comment = '';6271blockComment = false;6272lineComment = false;62736274while (index < length) {6275ch = source[index];62766277if (lineComment) {6278ch = source[index++];6279if (isLineTerminator(ch.charCodeAt(0))) {6280loc.end = {6281line: lineNumber,6282column: index - lineStart - 16283};6284lineComment = false;6285addComment('Line', comment, start, index - 1, loc);6286if (ch === '\r' && source[index] === '\n') {6287++index;6288}6289++lineNumber;6290lineStart = index;6291comment = '';6292} else if (index >= length) {6293lineComment = false;6294comment += ch;6295loc.end = {6296line: lineNumber,6297column: length - lineStart6298};6299addComment('Line', comment, start, length, loc);6300} else {6301comment += ch;6302}6303} else if (blockComment) {6304if (isLineTerminator(ch.charCodeAt(0))) {6305if (ch === '\r') {6306++index;6307comment += '\r';6308}6309if (ch !== '\r' || source[index] === '\n') {6310comment += source[index];6311++lineNumber;6312++index;6313lineStart = index;6314if (index >= length) {6315throwError({}, Messages.UnexpectedToken, 'ILLEGAL');6316}6317}6318} else {6319ch = source[index++];6320if (index >= length) {6321throwError({}, Messages.UnexpectedToken, 'ILLEGAL');6322}6323comment += ch;6324if (ch === '*') {6325ch = source[index];6326if (ch === '/') {6327comment = comment.substr(0, comment.length - 1);6328blockComment = false;6329++index;6330loc.end = {6331line: lineNumber,6332column: index - lineStart6333};6334addComment('Block', comment, start, index, loc);6335comment = '';6336}6337}6338}6339} else if (ch === '/') {6340ch = source[index + 1];6341if (ch === '/') {6342loc = {6343start: {6344line: lineNumber,6345column: index - lineStart6346}6347};6348start = index;6349index += 2;6350lineComment = true;6351if (index >= length) {6352loc.end = {6353line: lineNumber,6354column: index - lineStart6355};6356lineComment = false;6357addComment('Line', comment, start, index, loc);6358}6359} else if (ch === '*') {6360start = index;6361index += 2;6362blockComment = true;6363loc = {6364start: {6365line: lineNumber,6366column: index - lineStart - 26367}6368};6369if (index >= length) {6370throwError({}, Messages.UnexpectedToken, 'ILLEGAL');6371}6372} else {6373break;6374}6375} else if (isWhiteSpace(ch.charCodeAt(0))) {6376++index;6377} else if (isLineTerminator(ch.charCodeAt(0))) {6378++index;6379if (ch === '\r' && source[index] === '\n') {6380++index;6381}6382++lineNumber;6383lineStart = index;6384} else {6385break;6386}6387}6388}63896390// 16 XJS63916392XHTMLEntities = {6393quot: '\u0022',6394amp: '&',6395apos: '\u0027',6396lt: '<',6397gt: '>',6398nbsp: '\u00A0',6399iexcl: '\u00A1',6400cent: '\u00A2',6401pound: '\u00A3',6402curren: '\u00A4',6403yen: '\u00A5',6404brvbar: '\u00A6',6405sect: '\u00A7',6406uml: '\u00A8',6407copy: '\u00A9',6408ordf: '\u00AA',6409laquo: '\u00AB',6410not: '\u00AC',6411shy: '\u00AD',6412reg: '\u00AE',6413macr: '\u00AF',6414deg: '\u00B0',6415plusmn: '\u00B1',6416sup2: '\u00B2',6417sup3: '\u00B3',6418acute: '\u00B4',6419micro: '\u00B5',6420para: '\u00B6',6421middot: '\u00B7',6422cedil: '\u00B8',6423sup1: '\u00B9',6424ordm: '\u00BA',6425raquo: '\u00BB',6426frac14: '\u00BC',6427frac12: '\u00BD',6428frac34: '\u00BE',6429iquest: '\u00BF',6430Agrave: '\u00C0',6431Aacute: '\u00C1',6432Acirc: '\u00C2',6433Atilde: '\u00C3',6434Auml: '\u00C4',6435Aring: '\u00C5',6436AElig: '\u00C6',6437Ccedil: '\u00C7',6438Egrave: '\u00C8',6439Eacute: '\u00C9',6440Ecirc: '\u00CA',6441Euml: '\u00CB',6442Igrave: '\u00CC',6443Iacute: '\u00CD',6444Icirc: '\u00CE',6445Iuml: '\u00CF',6446ETH: '\u00D0',6447Ntilde: '\u00D1',6448Ograve: '\u00D2',6449Oacute: '\u00D3',6450Ocirc: '\u00D4',6451Otilde: '\u00D5',6452Ouml: '\u00D6',6453times: '\u00D7',6454Oslash: '\u00D8',6455Ugrave: '\u00D9',6456Uacute: '\u00DA',6457Ucirc: '\u00DB',6458Uuml: '\u00DC',6459Yacute: '\u00DD',6460THORN: '\u00DE',6461szlig: '\u00DF',6462agrave: '\u00E0',6463aacute: '\u00E1',6464acirc: '\u00E2',6465atilde: '\u00E3',6466auml: '\u00E4',6467aring: '\u00E5',6468aelig: '\u00E6',6469ccedil: '\u00E7',6470egrave: '\u00E8',6471eacute: '\u00E9',6472ecirc: '\u00EA',6473euml: '\u00EB',6474igrave: '\u00EC',6475iacute: '\u00ED',6476icirc: '\u00EE',6477iuml: '\u00EF',6478eth: '\u00F0',6479ntilde: '\u00F1',6480ograve: '\u00F2',6481oacute: '\u00F3',6482ocirc: '\u00F4',6483otilde: '\u00F5',6484ouml: '\u00F6',6485divide: '\u00F7',6486oslash: '\u00F8',6487ugrave: '\u00F9',6488uacute: '\u00FA',6489ucirc: '\u00FB',6490uuml: '\u00FC',6491yacute: '\u00FD',6492thorn: '\u00FE',6493yuml: '\u00FF',6494OElig: '\u0152',6495oelig: '\u0153',6496Scaron: '\u0160',6497scaron: '\u0161',6498Yuml: '\u0178',6499fnof: '\u0192',6500circ: '\u02C6',6501tilde: '\u02DC',6502Alpha: '\u0391',6503Beta: '\u0392',6504Gamma: '\u0393',6505Delta: '\u0394',6506Epsilon: '\u0395',6507Zeta: '\u0396',6508Eta: '\u0397',6509Theta: '\u0398',6510Iota: '\u0399',6511Kappa: '\u039A',6512Lambda: '\u039B',6513Mu: '\u039C',6514Nu: '\u039D',6515Xi: '\u039E',6516Omicron: '\u039F',6517Pi: '\u03A0',6518Rho: '\u03A1',6519Sigma: '\u03A3',6520Tau: '\u03A4',6521Upsilon: '\u03A5',6522Phi: '\u03A6',6523Chi: '\u03A7',6524Psi: '\u03A8',6525Omega: '\u03A9',6526alpha: '\u03B1',6527beta: '\u03B2',6528gamma: '\u03B3',6529delta: '\u03B4',6530epsilon: '\u03B5',6531zeta: '\u03B6',6532eta: '\u03B7',6533theta: '\u03B8',6534iota: '\u03B9',6535kappa: '\u03BA',6536lambda: '\u03BB',6537mu: '\u03BC',6538nu: '\u03BD',6539xi: '\u03BE',6540omicron: '\u03BF',6541pi: '\u03C0',6542rho: '\u03C1',6543sigmaf: '\u03C2',6544sigma: '\u03C3',6545tau: '\u03C4',6546upsilon: '\u03C5',6547phi: '\u03C6',6548chi: '\u03C7',6549psi: '\u03C8',6550omega: '\u03C9',6551thetasym: '\u03D1',6552upsih: '\u03D2',6553piv: '\u03D6',6554ensp: '\u2002',6555emsp: '\u2003',6556thinsp: '\u2009',6557zwnj: '\u200C',6558zwj: '\u200D',6559lrm: '\u200E',6560rlm: '\u200F',6561ndash: '\u2013',6562mdash: '\u2014',6563lsquo: '\u2018',6564rsquo: '\u2019',6565sbquo: '\u201A',6566ldquo: '\u201C',6567rdquo: '\u201D',6568bdquo: '\u201E',6569dagger: '\u2020',6570Dagger: '\u2021',6571bull: '\u2022',6572hellip: '\u2026',6573permil: '\u2030',6574prime: '\u2032',6575Prime: '\u2033',6576lsaquo: '\u2039',6577rsaquo: '\u203A',6578oline: '\u203E',6579frasl: '\u2044',6580euro: '\u20AC',6581image: '\u2111',6582weierp: '\u2118',6583real: '\u211C',6584trade: '\u2122',6585alefsym: '\u2135',6586larr: '\u2190',6587uarr: '\u2191',6588rarr: '\u2192',6589darr: '\u2193',6590harr: '\u2194',6591crarr: '\u21B5',6592lArr: '\u21D0',6593uArr: '\u21D1',6594rArr: '\u21D2',6595dArr: '\u21D3',6596hArr: '\u21D4',6597forall: '\u2200',6598part: '\u2202',6599exist: '\u2203',6600empty: '\u2205',6601nabla: '\u2207',6602isin: '\u2208',6603notin: '\u2209',6604ni: '\u220B',6605prod: '\u220F',6606sum: '\u2211',6607minus: '\u2212',6608lowast: '\u2217',6609radic: '\u221A',6610prop: '\u221D',6611infin: '\u221E',6612ang: '\u2220',6613and: '\u2227',6614or: '\u2228',6615cap: '\u2229',6616cup: '\u222A',6617'int': '\u222B',6618there4: '\u2234',6619sim: '\u223C',6620cong: '\u2245',6621asymp: '\u2248',6622ne: '\u2260',6623equiv: '\u2261',6624le: '\u2264',6625ge: '\u2265',6626sub: '\u2282',6627sup: '\u2283',6628nsub: '\u2284',6629sube: '\u2286',6630supe: '\u2287',6631oplus: '\u2295',6632otimes: '\u2297',6633perp: '\u22A5',6634sdot: '\u22C5',6635lceil: '\u2308',6636rceil: '\u2309',6637lfloor: '\u230A',6638rfloor: '\u230B',6639lang: '\u2329',6640rang: '\u232A',6641loz: '\u25CA',6642spades: '\u2660',6643clubs: '\u2663',6644hearts: '\u2665',6645diams: '\u2666'6646};66476648function getQualifiedXJSName(object) {6649if (object.type === Syntax.XJSIdentifier) {6650return object.name;6651}6652if (object.type === Syntax.XJSNamespacedName) {6653return object.namespace.name + ':' + object.name.name;6654}6655if (object.type === Syntax.XJSMemberExpression) {6656return (6657getQualifiedXJSName(object.object) + '.' +6658getQualifiedXJSName(object.property)6659);6660}6661}66626663function isXJSIdentifierStart(ch) {6664// exclude backslash (\)6665return (ch !== 92) && isIdentifierStart(ch);6666}66676668function isXJSIdentifierPart(ch) {6669// exclude backslash (\) and add hyphen (-)6670return (ch !== 92) && (ch === 45 || isIdentifierPart(ch));6671}66726673function scanXJSIdentifier() {6674var ch, start, value = '';66756676start = index;6677while (index < length) {6678ch = source.charCodeAt(index);6679if (!isXJSIdentifierPart(ch)) {6680break;6681}6682value += source[index++];6683}66846685return {6686type: Token.XJSIdentifier,6687value: value,6688lineNumber: lineNumber,6689lineStart: lineStart,6690range: [start, index]6691};6692}66936694function scanXJSEntity() {6695var ch, str = '', start = index, count = 0, code;6696ch = source[index];6697assert(ch === '&', 'Entity must start with an ampersand');6698index++;6699while (index < length && count++ < 10) {6700ch = source[index++];6701if (ch === ';') {6702break;6703}6704str += ch;6705}67066707// Well-formed entity (ending was found).6708if (ch === ';') {6709// Numeric entity.6710if (str[0] === '#') {6711if (str[1] === 'x') {6712code = +('0' + str.substr(1));6713} else {6714// Removing leading zeros in order to avoid treating as octal in old browsers.6715code = +str.substr(1).replace(Regex.LeadingZeros, '');6716}67176718if (!isNaN(code)) {6719return String.fromCharCode(code);6720}6721} else if (XHTMLEntities[str]) {6722return XHTMLEntities[str];6723}6724}67256726// Treat non-entity sequences as regular text.6727index = start + 1;6728return '&';6729}67306731function scanXJSText(stopChars) {6732var ch, str = '', start;6733start = index;6734while (index < length) {6735ch = source[index];6736if (stopChars.indexOf(ch) !== -1) {6737break;6738}6739if (ch === '&') {6740str += scanXJSEntity();6741} else {6742index++;6743if (ch === '\r' && source[index] === '\n') {6744str += ch;6745ch = source[index];6746index++;6747}6748if (isLineTerminator(ch.charCodeAt(0))) {6749++lineNumber;6750lineStart = index;6751}6752str += ch;6753}6754}6755return {6756type: Token.XJSText,6757value: str,6758lineNumber: lineNumber,6759lineStart: lineStart,6760range: [start, index]6761};6762}67636764function scanXJSStringLiteral() {6765var innerToken, quote, start;67666767quote = source[index];6768assert((quote === '\'' || quote === '"'),6769'String literal must starts with a quote');67706771start = index;6772++index;67736774innerToken = scanXJSText([quote]);67756776if (quote !== source[index]) {6777throwError({}, Messages.UnexpectedToken, 'ILLEGAL');6778}67796780++index;67816782innerToken.range = [start, index];67836784return innerToken;6785}67866787/**6788* Between XJS opening and closing tags (e.g. <foo>HERE</foo>), anything that6789* is not another XJS tag and is not an expression wrapped by {} is text.6790*/6791function advanceXJSChild() {6792var ch = source.charCodeAt(index);67936794// { (123) and < (60)6795if (ch !== 123 && ch !== 60) {6796return scanXJSText(['<', '{']);6797}67986799return scanPunctuator();6800}68016802function parseXJSIdentifier() {6803var token, marker = markerCreate();68046805if (lookahead.type !== Token.XJSIdentifier) {6806throwUnexpected(lookahead);6807}68086809token = lex();6810return markerApply(marker, delegate.createXJSIdentifier(token.value));6811}68126813function parseXJSNamespacedName() {6814var namespace, name, marker = markerCreate();68156816namespace = parseXJSIdentifier();6817expect(':');6818name = parseXJSIdentifier();68196820return markerApply(marker, delegate.createXJSNamespacedName(namespace, name));6821}68226823function parseXJSMemberExpression() {6824var marker = markerCreate(),6825expr = parseXJSIdentifier();68266827while (match('.')) {6828lex();6829expr = markerApply(marker, delegate.createXJSMemberExpression(expr, parseXJSIdentifier()));6830}68316832return expr;6833}68346835function parseXJSElementName() {6836if (lookahead2().value === ':') {6837return parseXJSNamespacedName();6838}6839if (lookahead2().value === '.') {6840return parseXJSMemberExpression();6841}68426843return parseXJSIdentifier();6844}68456846function parseXJSAttributeName() {6847if (lookahead2().value === ':') {6848return parseXJSNamespacedName();6849}68506851return parseXJSIdentifier();6852}68536854function parseXJSAttributeValue() {6855var value, marker;6856if (match('{')) {6857value = parseXJSExpressionContainer();6858if (value.expression.type === Syntax.XJSEmptyExpression) {6859throwError(6860value,6861'XJS attributes must only be assigned a non-empty ' +6862'expression'6863);6864}6865} else if (match('<')) {6866value = parseXJSElement();6867} else if (lookahead.type === Token.XJSText) {6868marker = markerCreate();6869value = markerApply(marker, delegate.createLiteral(lex()));6870} else {6871throwError({}, Messages.InvalidXJSAttributeValue);6872}6873return value;6874}68756876function parseXJSEmptyExpression() {6877var marker = markerCreatePreserveWhitespace();6878while (source.charAt(index) !== '}') {6879index++;6880}6881return markerApply(marker, delegate.createXJSEmptyExpression());6882}68836884function parseXJSExpressionContainer() {6885var expression, origInXJSChild, origInXJSTag, marker = markerCreate();68866887origInXJSChild = state.inXJSChild;6888origInXJSTag = state.inXJSTag;6889state.inXJSChild = false;6890state.inXJSTag = false;68916892expect('{');68936894if (match('}')) {6895expression = parseXJSEmptyExpression();6896} else {6897expression = parseExpression();6898}68996900state.inXJSChild = origInXJSChild;6901state.inXJSTag = origInXJSTag;69026903expect('}');69046905return markerApply(marker, delegate.createXJSExpressionContainer(expression));6906}69076908function parseXJSSpreadAttribute() {6909var expression, origInXJSChild, origInXJSTag, marker = markerCreate();69106911origInXJSChild = state.inXJSChild;6912origInXJSTag = state.inXJSTag;6913state.inXJSChild = false;6914state.inXJSTag = false;69156916expect('{');6917expect('...');69186919expression = parseAssignmentExpression();69206921state.inXJSChild = origInXJSChild;6922state.inXJSTag = origInXJSTag;69236924expect('}');69256926return markerApply(marker, delegate.createXJSSpreadAttribute(expression));6927}69286929function parseXJSAttribute() {6930var name, marker;69316932if (match('{')) {6933return parseXJSSpreadAttribute();6934}69356936marker = markerCreate();69376938name = parseXJSAttributeName();69396940// HTML empty attribute6941if (match('=')) {6942lex();6943return markerApply(marker, delegate.createXJSAttribute(name, parseXJSAttributeValue()));6944}69456946return markerApply(marker, delegate.createXJSAttribute(name));6947}69486949function parseXJSChild() {6950var token, marker;6951if (match('{')) {6952token = parseXJSExpressionContainer();6953} else if (lookahead.type === Token.XJSText) {6954marker = markerCreatePreserveWhitespace();6955token = markerApply(marker, delegate.createLiteral(lex()));6956} else {6957token = parseXJSElement();6958}6959return token;6960}69616962function parseXJSClosingElement() {6963var name, origInXJSChild, origInXJSTag, marker = markerCreate();6964origInXJSChild = state.inXJSChild;6965origInXJSTag = state.inXJSTag;6966state.inXJSChild = false;6967state.inXJSTag = true;6968expect('<');6969expect('/');6970name = parseXJSElementName();6971// Because advance() (called by lex() called by expect()) expects there6972// to be a valid token after >, it needs to know whether to look for a6973// standard JS token or an XJS text node6974state.inXJSChild = origInXJSChild;6975state.inXJSTag = origInXJSTag;6976expect('>');6977return markerApply(marker, delegate.createXJSClosingElement(name));6978}69796980function parseXJSOpeningElement() {6981var name, attribute, attributes = [], selfClosing = false, origInXJSChild, origInXJSTag, marker = markerCreate();69826983origInXJSChild = state.inXJSChild;6984origInXJSTag = state.inXJSTag;6985state.inXJSChild = false;6986state.inXJSTag = true;69876988expect('<');69896990name = parseXJSElementName();69916992while (index < length &&6993lookahead.value !== '/' &&6994lookahead.value !== '>') {6995attributes.push(parseXJSAttribute());6996}69976998state.inXJSTag = origInXJSTag;69997000if (lookahead.value === '/') {7001expect('/');7002// Because advance() (called by lex() called by expect()) expects7003// there to be a valid token after >, it needs to know whether to7004// look for a standard JS token or an XJS text node7005state.inXJSChild = origInXJSChild;7006expect('>');7007selfClosing = true;7008} else {7009state.inXJSChild = true;7010expect('>');7011}7012return markerApply(marker, delegate.createXJSOpeningElement(name, attributes, selfClosing));7013}70147015function parseXJSElement() {7016var openingElement, closingElement = null, children = [], origInXJSChild, origInXJSTag, marker = markerCreate();70177018origInXJSChild = state.inXJSChild;7019origInXJSTag = state.inXJSTag;7020openingElement = parseXJSOpeningElement();70217022if (!openingElement.selfClosing) {7023while (index < length) {7024state.inXJSChild = false; // Call lookahead2() with inXJSChild = false because </ should not be considered in the child7025if (lookahead.value === '<' && lookahead2().value === '/') {7026break;7027}7028state.inXJSChild = true;7029children.push(parseXJSChild());7030}7031state.inXJSChild = origInXJSChild;7032state.inXJSTag = origInXJSTag;7033closingElement = parseXJSClosingElement();7034if (getQualifiedXJSName(closingElement.name) !== getQualifiedXJSName(openingElement.name)) {7035throwError({}, Messages.ExpectedXJSClosingTag, getQualifiedXJSName(openingElement.name));7036}7037}70387039// When (erroneously) writing two adjacent tags like7040//7041// var x = <div>one</div><div>two</div>;7042//7043// the default error message is a bit incomprehensible. Since it's7044// rarely (never?) useful to write a less-than sign after an XJS7045// element, we disallow it here in the parser in order to provide a7046// better error message. (In the rare case that the less-than operator7047// was intended, the left tag can be wrapped in parentheses.)7048if (!origInXJSChild && match('<')) {7049throwError(lookahead, Messages.AdjacentXJSElements);7050}70517052return markerApply(marker, delegate.createXJSElement(openingElement, closingElement, children));7053}70547055function parseTypeAlias() {7056var id, marker = markerCreate(), typeParameters = null, right;7057expectContextualKeyword('type');7058id = parseVariableIdentifier();7059if (match('<')) {7060typeParameters = parseTypeParameterDeclaration();7061}7062expect('=');7063right = parseType();7064consumeSemicolon();7065return markerApply(marker, delegate.createTypeAlias(id, typeParameters, right));7066}70677068function parseInterfaceExtends() {7069var marker = markerCreate(), id, typeParameters = null;70707071id = parseVariableIdentifier();7072if (match('<')) {7073typeParameters = parseTypeParameterInstantiation();7074}70757076return markerApply(marker, delegate.createInterfaceExtends(7077id,7078typeParameters7079));7080}70817082function parseInterfaceish(marker, allowStatic) {7083var body, bodyMarker, extended = [], id,7084typeParameters = null;70857086id = parseVariableIdentifier();7087if (match('<')) {7088typeParameters = parseTypeParameterDeclaration();7089}70907091if (matchKeyword('extends')) {7092expectKeyword('extends');70937094while (index < length) {7095extended.push(parseInterfaceExtends());7096if (!match(',')) {7097break;7098}7099expect(',');7100}7101}71027103bodyMarker = markerCreate();7104body = markerApply(bodyMarker, parseObjectType(allowStatic));71057106return markerApply(marker, delegate.createInterface(7107id,7108typeParameters,7109body,7110extended7111));7112}71137114function parseInterface() {7115var body, bodyMarker, extended = [], id, marker = markerCreate(),7116typeParameters = null;71177118expectContextualKeyword('interface');7119return parseInterfaceish(marker, /* allowStatic */false);7120}71217122function parseDeclareClass() {7123var marker = markerCreate(), ret;7124expectContextualKeyword('declare');7125expectKeyword('class');71267127ret = parseInterfaceish(marker, /* allowStatic */true);7128ret.type = Syntax.DeclareClass;7129return ret;7130}71317132function parseDeclareFunction() {7133var id, idMarker,7134marker = markerCreate(), params, returnType, rest, tmp,7135typeParameters = null, value, valueMarker;71367137expectContextualKeyword('declare');7138expectKeyword('function');7139idMarker = markerCreate();7140id = parseVariableIdentifier();71417142valueMarker = markerCreate();7143if (match('<')) {7144typeParameters = parseTypeParameterDeclaration();7145}7146expect('(');7147tmp = parseFunctionTypeParams();7148params = tmp.params;7149rest = tmp.rest;7150expect(')');71517152expect(':');7153returnType = parseType();71547155value = markerApply(valueMarker, delegate.createFunctionTypeAnnotation(7156params,7157returnType,7158rest,7159typeParameters7160));71617162id.typeAnnotation = markerApply(valueMarker, delegate.createTypeAnnotation(7163value7164));7165markerApply(idMarker, id);71667167consumeSemicolon();71687169return markerApply(marker, delegate.createDeclareFunction(7170id7171));7172}71737174function parseDeclareVariable() {7175var id, marker = markerCreate();7176expectContextualKeyword('declare');7177expectKeyword('var');7178id = parseTypeAnnotatableIdentifier();71797180consumeSemicolon();71817182return markerApply(marker, delegate.createDeclareVariable(7183id7184));7185}71867187function parseDeclareModule() {7188var body = [], bodyMarker, id, idMarker, marker = markerCreate(), token;7189expectContextualKeyword('declare');7190expectContextualKeyword('module');71917192if (lookahead.type === Token.StringLiteral) {7193if (strict && lookahead.octal) {7194throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);7195}7196idMarker = markerCreate();7197id = markerApply(idMarker, delegate.createLiteral(lex()));7198} else {7199id = parseVariableIdentifier();7200}72017202bodyMarker = markerCreate();7203expect('{');7204while (index < length && !match('}')) {7205token = lookahead2();7206switch (token.value) {7207case 'class':7208body.push(parseDeclareClass());7209break;7210case 'function':7211body.push(parseDeclareFunction());7212break;7213case 'var':7214body.push(parseDeclareVariable());7215break;7216default:7217throwUnexpected(lookahead);7218}7219}7220expect('}');72217222return markerApply(marker, delegate.createDeclareModule(7223id,7224markerApply(bodyMarker, delegate.createBlockStatement(body))7225));7226}72277228function collectToken() {7229var start, loc, token, range, value, entry;72307231if (!state.inXJSChild) {7232skipComment();7233}72347235start = index;7236loc = {7237start: {7238line: lineNumber,7239column: index - lineStart7240}7241};72427243token = extra.advance();7244loc.end = {7245line: lineNumber,7246column: index - lineStart7247};72487249if (token.type !== Token.EOF) {7250range = [token.range[0], token.range[1]];7251value = source.slice(token.range[0], token.range[1]);7252entry = {7253type: TokenName[token.type],7254value: value,7255range: range,7256loc: loc7257};7258if (token.regex) {7259entry.regex = {7260pattern: token.regex.pattern,7261flags: token.regex.flags7262};7263}7264extra.tokens.push(entry);7265}72667267return token;7268}72697270function collectRegex() {7271var pos, loc, regex, token;72727273skipComment();72747275pos = index;7276loc = {7277start: {7278line: lineNumber,7279column: index - lineStart7280}7281};72827283regex = extra.scanRegExp();7284loc.end = {7285line: lineNumber,7286column: index - lineStart7287};72887289if (!extra.tokenize) {7290// Pop the previous token, which is likely '/' or '/='7291if (extra.tokens.length > 0) {7292token = extra.tokens[extra.tokens.length - 1];7293if (token.range[0] === pos && token.type === 'Punctuator') {7294if (token.value === '/' || token.value === '/=') {7295extra.tokens.pop();7296}7297}7298}72997300extra.tokens.push({7301type: 'RegularExpression',7302value: regex.literal,7303regex: regex.regex,7304range: [pos, index],7305loc: loc7306});7307}73087309return regex;7310}73117312function filterTokenLocation() {7313var i, entry, token, tokens = [];73147315for (i = 0; i < extra.tokens.length; ++i) {7316entry = extra.tokens[i];7317token = {7318type: entry.type,7319value: entry.value7320};7321if (entry.regex) {7322token.regex = {7323pattern: entry.regex.pattern,7324flags: entry.regex.flags7325};7326}7327if (extra.range) {7328token.range = entry.range;7329}7330if (extra.loc) {7331token.loc = entry.loc;7332}7333tokens.push(token);7334}73357336extra.tokens = tokens;7337}73387339function patch() {7340if (extra.comments) {7341extra.skipComment = skipComment;7342skipComment = scanComment;7343}73447345if (typeof extra.tokens !== 'undefined') {7346extra.advance = advance;7347extra.scanRegExp = scanRegExp;73487349advance = collectToken;7350scanRegExp = collectRegex;7351}7352}73537354function unpatch() {7355if (typeof extra.skipComment === 'function') {7356skipComment = extra.skipComment;7357}73587359if (typeof extra.scanRegExp === 'function') {7360advance = extra.advance;7361scanRegExp = extra.scanRegExp;7362}7363}73647365// This is used to modify the delegate.73667367function extend(object, properties) {7368var entry, result = {};73697370for (entry in object) {7371if (object.hasOwnProperty(entry)) {7372result[entry] = object[entry];7373}7374}73757376for (entry in properties) {7377if (properties.hasOwnProperty(entry)) {7378result[entry] = properties[entry];7379}7380}73817382return result;7383}73847385function tokenize(code, options) {7386var toString,7387token,7388tokens;73897390toString = String;7391if (typeof code !== 'string' && !(code instanceof String)) {7392code = toString(code);7393}73947395delegate = SyntaxTreeDelegate;7396source = code;7397index = 0;7398lineNumber = (source.length > 0) ? 1 : 0;7399lineStart = 0;7400length = source.length;7401lookahead = null;7402state = {7403allowKeyword: true,7404allowIn: true,7405labelSet: {},7406inFunctionBody: false,7407inIteration: false,7408inSwitch: false,7409lastCommentStart: -17410};74117412extra = {};74137414// Options matching.7415options = options || {};74167417// Of course we collect tokens here.7418options.tokens = true;7419extra.tokens = [];7420extra.tokenize = true;7421// The following two fields are necessary to compute the Regex tokens.7422extra.openParenToken = -1;7423extra.openCurlyToken = -1;74247425extra.range = (typeof options.range === 'boolean') && options.range;7426extra.loc = (typeof options.loc === 'boolean') && options.loc;74277428if (typeof options.comment === 'boolean' && options.comment) {7429extra.comments = [];7430}7431if (typeof options.tolerant === 'boolean' && options.tolerant) {7432extra.errors = [];7433}74347435if (length > 0) {7436if (typeof source[0] === 'undefined') {7437// Try first to convert to a string. This is good as fast path7438// for old IE which understands string indexing for string7439// literals only and not for string object.7440if (code instanceof String) {7441source = code.valueOf();7442}7443}7444}74457446patch();74477448try {7449peek();7450if (lookahead.type === Token.EOF) {7451return extra.tokens;7452}74537454token = lex();7455while (lookahead.type !== Token.EOF) {7456try {7457token = lex();7458} catch (lexError) {7459token = lookahead;7460if (extra.errors) {7461extra.errors.push(lexError);7462// We have to break on the first error7463// to avoid infinite loops.7464break;7465} else {7466throw lexError;7467}7468}7469}74707471filterTokenLocation();7472tokens = extra.tokens;7473if (typeof extra.comments !== 'undefined') {7474tokens.comments = extra.comments;7475}7476if (typeof extra.errors !== 'undefined') {7477tokens.errors = extra.errors;7478}7479} catch (e) {7480throw e;7481} finally {7482unpatch();7483extra = {};7484}7485return tokens;7486}74877488function parse(code, options) {7489var program, toString;74907491toString = String;7492if (typeof code !== 'string' && !(code instanceof String)) {7493code = toString(code);7494}74957496delegate = SyntaxTreeDelegate;7497source = code;7498index = 0;7499lineNumber = (source.length > 0) ? 1 : 0;7500lineStart = 0;7501length = source.length;7502lookahead = null;7503state = {7504allowKeyword: false,7505allowIn: true,7506labelSet: {},7507parenthesizedCount: 0,7508inFunctionBody: false,7509inIteration: false,7510inSwitch: false,7511inXJSChild: false,7512inXJSTag: false,7513inType: false,7514lastCommentStart: -1,7515yieldAllowed: false,7516awaitAllowed: false7517};75187519extra = {};7520if (typeof options !== 'undefined') {7521extra.range = (typeof options.range === 'boolean') && options.range;7522extra.loc = (typeof options.loc === 'boolean') && options.loc;7523extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;75247525if (extra.loc && options.source !== null && options.source !== undefined) {7526delegate = extend(delegate, {7527'postProcess': function (node) {7528node.loc.source = toString(options.source);7529return node;7530}7531});7532}75337534if (typeof options.tokens === 'boolean' && options.tokens) {7535extra.tokens = [];7536}7537if (typeof options.comment === 'boolean' && options.comment) {7538extra.comments = [];7539}7540if (typeof options.tolerant === 'boolean' && options.tolerant) {7541extra.errors = [];7542}7543if (extra.attachComment) {7544extra.range = true;7545extra.comments = [];7546extra.bottomRightStack = [];7547extra.trailingComments = [];7548extra.leadingComments = [];7549}7550}75517552if (length > 0) {7553if (typeof source[0] === 'undefined') {7554// Try first to convert to a string. This is good as fast path7555// for old IE which understands string indexing for string7556// literals only and not for string object.7557if (code instanceof String) {7558source = code.valueOf();7559}7560}7561}75627563patch();7564try {7565program = parseProgram();7566if (typeof extra.comments !== 'undefined') {7567program.comments = extra.comments;7568}7569if (typeof extra.tokens !== 'undefined') {7570filterTokenLocation();7571program.tokens = extra.tokens;7572}7573if (typeof extra.errors !== 'undefined') {7574program.errors = extra.errors;7575}7576} catch (e) {7577throw e;7578} finally {7579unpatch();7580extra = {};7581}75827583return program;7584}75857586// Sync with *.json manifests.7587exports.version = '8001.1001.0-dev-harmony-fb';75887589exports.tokenize = tokenize;75907591exports.parse = parse;75927593// Deep copy.7594exports.Syntax = (function () {7595var name, types = {};75967597if (typeof Object.create === 'function') {7598types = Object.create(null);7599}76007601for (name in Syntax) {7602if (Syntax.hasOwnProperty(name)) {7603types[name] = Syntax[name];7604}7605}76067607if (typeof Object.freeze === 'function') {7608Object.freeze(types);7609}76107611return types;7612}());76137614}));7615/* vim: set sw=4 ts=4 et tw=80 : */761676177618