react / wstein / node_modules / react / node_modules / envify / node_modules / jstransform / node_modules / esprima-fb / esprima.js
80551 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(function (root, factory) {33'use strict';3435// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,36// Rhino, and plain browser loading.3738/* istanbul ignore next */39if (typeof define === 'function' && define.amd) {40define(['exports'], factory);41} else if (typeof exports !== 'undefined') {42factory(exports);43} else {44factory((root.esprima = {}));45}46}(this, function (exports) {47'use strict';4849var Token,50TokenName,51FnExprTokens,52Syntax,53PropertyKind,54Messages,55Regex,56SyntaxTreeDelegate,57XHTMLEntities,58ClassPropertyType,59source,60strict,61index,62lineNumber,63lineStart,64length,65delegate,66lookahead,67state,68extra;6970Token = {71BooleanLiteral: 1,72EOF: 2,73Identifier: 3,74Keyword: 4,75NullLiteral: 5,76NumericLiteral: 6,77Punctuator: 7,78StringLiteral: 8,79RegularExpression: 9,80Template: 10,81JSXIdentifier: 11,82JSXText: 1283};8485TokenName = {};86TokenName[Token.BooleanLiteral] = 'Boolean';87TokenName[Token.EOF] = '<end>';88TokenName[Token.Identifier] = 'Identifier';89TokenName[Token.Keyword] = 'Keyword';90TokenName[Token.NullLiteral] = 'Null';91TokenName[Token.NumericLiteral] = 'Numeric';92TokenName[Token.Punctuator] = 'Punctuator';93TokenName[Token.StringLiteral] = 'String';94TokenName[Token.JSXIdentifier] = 'JSXIdentifier';95TokenName[Token.JSXText] = 'JSXText';96TokenName[Token.RegularExpression] = 'RegularExpression';9798// A function following one of those tokens is an expression.99FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',100'return', 'case', 'delete', 'throw', 'void',101// assignment operators102'=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',103'&=', '|=', '^=', ',',104// binary/unary operators105'+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',106'|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',107'<=', '<', '>', '!=', '!=='];108109Syntax = {110AnyTypeAnnotation: 'AnyTypeAnnotation',111ArrayExpression: 'ArrayExpression',112ArrayPattern: 'ArrayPattern',113ArrayTypeAnnotation: 'ArrayTypeAnnotation',114ArrowFunctionExpression: 'ArrowFunctionExpression',115AssignmentExpression: 'AssignmentExpression',116BinaryExpression: 'BinaryExpression',117BlockStatement: 'BlockStatement',118BooleanTypeAnnotation: 'BooleanTypeAnnotation',119BreakStatement: 'BreakStatement',120CallExpression: 'CallExpression',121CatchClause: 'CatchClause',122ClassBody: 'ClassBody',123ClassDeclaration: 'ClassDeclaration',124ClassExpression: 'ClassExpression',125ClassImplements: 'ClassImplements',126ClassProperty: 'ClassProperty',127ComprehensionBlock: 'ComprehensionBlock',128ComprehensionExpression: 'ComprehensionExpression',129ConditionalExpression: 'ConditionalExpression',130ContinueStatement: 'ContinueStatement',131DebuggerStatement: 'DebuggerStatement',132DeclareClass: 'DeclareClass',133DeclareFunction: 'DeclareFunction',134DeclareModule: 'DeclareModule',135DeclareVariable: 'DeclareVariable',136DoWhileStatement: 'DoWhileStatement',137EmptyStatement: 'EmptyStatement',138ExportDeclaration: 'ExportDeclaration',139ExportBatchSpecifier: 'ExportBatchSpecifier',140ExportSpecifier: 'ExportSpecifier',141ExpressionStatement: 'ExpressionStatement',142ForInStatement: 'ForInStatement',143ForOfStatement: 'ForOfStatement',144ForStatement: 'ForStatement',145FunctionDeclaration: 'FunctionDeclaration',146FunctionExpression: 'FunctionExpression',147FunctionTypeAnnotation: 'FunctionTypeAnnotation',148FunctionTypeParam: 'FunctionTypeParam',149GenericTypeAnnotation: 'GenericTypeAnnotation',150Identifier: 'Identifier',151IfStatement: 'IfStatement',152ImportDeclaration: 'ImportDeclaration',153ImportDefaultSpecifier: 'ImportDefaultSpecifier',154ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',155ImportSpecifier: 'ImportSpecifier',156InterfaceDeclaration: 'InterfaceDeclaration',157InterfaceExtends: 'InterfaceExtends',158IntersectionTypeAnnotation: 'IntersectionTypeAnnotation',159LabeledStatement: 'LabeledStatement',160Literal: 'Literal',161LogicalExpression: 'LogicalExpression',162MemberExpression: 'MemberExpression',163MethodDefinition: 'MethodDefinition',164ModuleSpecifier: 'ModuleSpecifier',165NewExpression: 'NewExpression',166NullableTypeAnnotation: 'NullableTypeAnnotation',167NumberTypeAnnotation: 'NumberTypeAnnotation',168ObjectExpression: 'ObjectExpression',169ObjectPattern: 'ObjectPattern',170ObjectTypeAnnotation: 'ObjectTypeAnnotation',171ObjectTypeCallProperty: 'ObjectTypeCallProperty',172ObjectTypeIndexer: 'ObjectTypeIndexer',173ObjectTypeProperty: 'ObjectTypeProperty',174Program: 'Program',175Property: 'Property',176QualifiedTypeIdentifier: 'QualifiedTypeIdentifier',177ReturnStatement: 'ReturnStatement',178SequenceExpression: 'SequenceExpression',179SpreadElement: 'SpreadElement',180SpreadProperty: 'SpreadProperty',181StringLiteralTypeAnnotation: 'StringLiteralTypeAnnotation',182StringTypeAnnotation: 'StringTypeAnnotation',183SwitchCase: 'SwitchCase',184SwitchStatement: 'SwitchStatement',185TaggedTemplateExpression: 'TaggedTemplateExpression',186TemplateElement: 'TemplateElement',187TemplateLiteral: 'TemplateLiteral',188ThisExpression: 'ThisExpression',189ThrowStatement: 'ThrowStatement',190TupleTypeAnnotation: 'TupleTypeAnnotation',191TryStatement: 'TryStatement',192TypeAlias: 'TypeAlias',193TypeAnnotation: 'TypeAnnotation',194TypeCastExpression: 'TypeCastExpression',195TypeofTypeAnnotation: 'TypeofTypeAnnotation',196TypeParameterDeclaration: 'TypeParameterDeclaration',197TypeParameterInstantiation: 'TypeParameterInstantiation',198UnaryExpression: 'UnaryExpression',199UnionTypeAnnotation: 'UnionTypeAnnotation',200UpdateExpression: 'UpdateExpression',201VariableDeclaration: 'VariableDeclaration',202VariableDeclarator: 'VariableDeclarator',203VoidTypeAnnotation: 'VoidTypeAnnotation',204WhileStatement: 'WhileStatement',205WithStatement: 'WithStatement',206JSXIdentifier: 'JSXIdentifier',207JSXNamespacedName: 'JSXNamespacedName',208JSXMemberExpression: 'JSXMemberExpression',209JSXEmptyExpression: 'JSXEmptyExpression',210JSXExpressionContainer: 'JSXExpressionContainer',211JSXElement: 'JSXElement',212JSXClosingElement: 'JSXClosingElement',213JSXOpeningElement: 'JSXOpeningElement',214JSXAttribute: 'JSXAttribute',215JSXSpreadAttribute: 'JSXSpreadAttribute',216JSXText: 'JSXText',217YieldExpression: 'YieldExpression',218AwaitExpression: 'AwaitExpression'219};220221PropertyKind = {222Data: 1,223Get: 2,224Set: 4225};226227ClassPropertyType = {228'static': 'static',229prototype: 'prototype'230};231232// Error messages should be identical to V8.233Messages = {234UnexpectedToken: 'Unexpected token %0',235UnexpectedNumber: 'Unexpected number',236UnexpectedString: 'Unexpected string',237UnexpectedIdentifier: 'Unexpected identifier',238UnexpectedReserved: 'Unexpected reserved word',239UnexpectedTemplate: 'Unexpected quasi %0',240UnexpectedEOS: 'Unexpected end of input',241NewlineAfterThrow: 'Illegal newline after throw',242InvalidRegExp: 'Invalid regular expression',243UnterminatedRegExp: 'Invalid regular expression: missing /',244InvalidLHSInAssignment: 'Invalid left-hand side in assignment',245InvalidLHSInFormalsList: 'Invalid left-hand side in formals list',246InvalidLHSInForIn: 'Invalid left-hand side in for-in',247MultipleDefaultsInSwitch: 'More than one default clause in switch statement',248NoCatchOrFinally: 'Missing catch or finally after try',249UnknownLabel: 'Undefined label \'%0\'',250Redeclaration: '%0 \'%1\' has already been declared',251IllegalContinue: 'Illegal continue statement',252IllegalBreak: 'Illegal break statement',253IllegalDuplicateClassProperty: 'Illegal duplicate property in class definition',254IllegalClassConstructorProperty: 'Illegal constructor property in class definition',255IllegalReturn: 'Illegal return statement',256IllegalSpread: 'Illegal spread element',257StrictModeWith: 'Strict mode code may not include a with statement',258StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',259StrictVarName: 'Variable name may not be eval or arguments in strict mode',260StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',261StrictParamDupe: 'Strict mode function may not have duplicate parameter names',262ParameterAfterRestParameter: 'Rest parameter must be final parameter of an argument list',263DefaultRestParameter: 'Rest parameter can not have a default value',264ElementAfterSpreadElement: 'Spread must be the final element of an element list',265PropertyAfterSpreadProperty: 'A rest property must be the final property of an object literal',266ObjectPatternAsRestParameter: 'Invalid rest parameter',267ObjectPatternAsSpread: 'Invalid spread argument',268StrictFunctionName: 'Function name may not be eval or arguments in strict mode',269StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',270StrictDelete: 'Delete of an unqualified identifier in strict mode.',271StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',272AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',273AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',274StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',275StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',276StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',277StrictReservedWord: 'Use of future reserved word in strict mode',278MissingFromClause: 'Missing from clause',279NoAsAfterImportNamespace: 'Missing as after import *',280InvalidModuleSpecifier: 'Invalid module specifier',281IllegalImportDeclaration: 'Illegal import declaration',282IllegalExportDeclaration: 'Illegal export declaration',283NoUninitializedConst: 'Const must be initialized',284ComprehensionRequiresBlock: 'Comprehension must have at least one block',285ComprehensionError: 'Comprehension Error',286EachNotAllowed: 'Each is not supported',287InvalidJSXAttributeValue: 'JSX value should be either an expression or a quoted JSX text',288ExpectedJSXClosingTag: 'Expected corresponding JSX closing tag for %0',289AdjacentJSXElements: 'Adjacent JSX elements must be wrapped in an enclosing tag',290ConfusedAboutFunctionType: 'Unexpected token =>. It looks like ' +291'you are trying to write a function type, but you ended up ' +292'writing a grouped type followed by an =>, which is a syntax ' +293'error. Remember, function type parameters are named so function ' +294'types look like (name1: type1, name2: type2) => returnType. You ' +295'probably wrote (type1) => returnType'296};297298// See also tools/generate-unicode-regex.py.299Regex = {300NonAsciiIdentifierStart: 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]'),301NonAsciiIdentifierPart: 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]'),302LeadingZeros: new RegExp('^0+(?!$)')303};304305// Ensure the condition is true, otherwise throw an error.306// This is only to have a better contract semantic, i.e. another safety net307// to catch a logic error. The condition shall be fulfilled in normal case.308// Do NOT use this to enforce a certain condition on any user input.309310function assert(condition, message) {311/* istanbul ignore if */312if (!condition) {313throw new Error('ASSERT: ' + message);314}315}316317function StringMap() {318this.$data = {};319}320321StringMap.prototype.get = function (key) {322key = '$' + key;323return this.$data[key];324};325326StringMap.prototype.set = function (key, value) {327key = '$' + key;328this.$data[key] = value;329return this;330};331332StringMap.prototype.has = function (key) {333key = '$' + key;334return Object.prototype.hasOwnProperty.call(this.$data, key);335};336337StringMap.prototype.delete = function (key) {338key = '$' + key;339return delete this.$data[key];340};341342function isDecimalDigit(ch) {343return (ch >= 48 && ch <= 57); // 0..9344}345346function isHexDigit(ch) {347return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;348}349350function isOctalDigit(ch) {351return '01234567'.indexOf(ch) >= 0;352}353354355// 7.2 White Space356357function isWhiteSpace(ch) {358return (ch === 32) || // space359(ch === 9) || // tab360(ch === 0xB) ||361(ch === 0xC) ||362(ch === 0xA0) ||363(ch >= 0x1680 && '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'.indexOf(String.fromCharCode(ch)) > 0);364}365366// 7.3 Line Terminators367368function isLineTerminator(ch) {369return (ch === 10) || (ch === 13) || (ch === 0x2028) || (ch === 0x2029);370}371372// 7.6 Identifier Names and Identifiers373374function isIdentifierStart(ch) {375return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)376(ch >= 65 && ch <= 90) || // A..Z377(ch >= 97 && ch <= 122) || // a..z378(ch === 92) || // \ (backslash)379((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));380}381382function isIdentifierPart(ch) {383return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)384(ch >= 65 && ch <= 90) || // A..Z385(ch >= 97 && ch <= 122) || // a..z386(ch >= 48 && ch <= 57) || // 0..9387(ch === 92) || // \ (backslash)388((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));389}390391// 7.6.1.2 Future Reserved Words392393function isFutureReservedWord(id) {394switch (id) {395case 'class':396case 'enum':397case 'export':398case 'extends':399case 'import':400case 'super':401return true;402default:403return false;404}405}406407function isStrictModeReservedWord(id) {408switch (id) {409case 'implements':410case 'interface':411case 'package':412case 'private':413case 'protected':414case 'public':415case 'static':416case 'yield':417case 'let':418return true;419default:420return false;421}422}423424function isRestrictedWord(id) {425return id === 'eval' || id === 'arguments';426}427428// 7.6.1.1 Keywords429430function isKeyword(id) {431if (strict && isStrictModeReservedWord(id)) {432return true;433}434435// 'const' is specialized as Keyword in V8.436// 'yield' is only treated as a keyword in strict mode.437// 'let' is for compatiblity with SpiderMonkey and ES.next.438// Some others are from future reserved words.439440switch (id.length) {441case 2:442return (id === 'if') || (id === 'in') || (id === 'do');443case 3:444return (id === 'var') || (id === 'for') || (id === 'new') ||445(id === 'try') || (id === 'let');446case 4:447return (id === 'this') || (id === 'else') || (id === 'case') ||448(id === 'void') || (id === 'with') || (id === 'enum');449case 5:450return (id === 'while') || (id === 'break') || (id === 'catch') ||451(id === 'throw') || (id === 'const') ||452(id === 'class') || (id === 'super');453case 6:454return (id === 'return') || (id === 'typeof') || (id === 'delete') ||455(id === 'switch') || (id === 'export') || (id === 'import');456case 7:457return (id === 'default') || (id === 'finally') || (id === 'extends');458case 8:459return (id === 'function') || (id === 'continue') || (id === 'debugger');460case 10:461return (id === 'instanceof');462default:463return false;464}465}466467// 7.4 Comments468469function addComment(type, value, start, end, loc) {470var comment;471assert(typeof start === 'number', 'Comment must have valid position');472473// Because the way the actual token is scanned, often the comments474// (if any) are skipped twice during the lexical analysis.475// Thus, we need to skip adding a comment if the comment array already476// handled it.477if (state.lastCommentStart >= start) {478return;479}480state.lastCommentStart = start;481482comment = {483type: type,484value: value485};486if (extra.range) {487comment.range = [start, end];488}489if (extra.loc) {490comment.loc = loc;491}492extra.comments.push(comment);493if (extra.attachComment) {494extra.leadingComments.push(comment);495extra.trailingComments.push(comment);496}497}498499function skipSingleLineComment() {500var start, loc, ch, comment;501502start = index - 2;503loc = {504start: {505line: lineNumber,506column: index - lineStart - 2507}508};509510while (index < length) {511ch = source.charCodeAt(index);512++index;513if (isLineTerminator(ch)) {514if (extra.comments) {515comment = source.slice(start + 2, index - 1);516loc.end = {517line: lineNumber,518column: index - lineStart - 1519};520addComment('Line', comment, start, index - 1, loc);521}522if (ch === 13 && source.charCodeAt(index) === 10) {523++index;524}525++lineNumber;526lineStart = index;527return;528}529}530531if (extra.comments) {532comment = source.slice(start + 2, index);533loc.end = {534line: lineNumber,535column: index - lineStart536};537addComment('Line', comment, start, index, loc);538}539}540541function skipMultiLineComment() {542var start, loc, ch, comment;543544if (extra.comments) {545start = index - 2;546loc = {547start: {548line: lineNumber,549column: index - lineStart - 2550}551};552}553554while (index < length) {555ch = source.charCodeAt(index);556if (isLineTerminator(ch)) {557if (ch === 13 && source.charCodeAt(index + 1) === 10) {558++index;559}560++lineNumber;561++index;562lineStart = index;563if (index >= length) {564throwError({}, Messages.UnexpectedToken, 'ILLEGAL');565}566} else if (ch === 42) {567// Block comment ends with '*/' (char #42, char #47).568if (source.charCodeAt(index + 1) === 47) {569++index;570++index;571if (extra.comments) {572comment = source.slice(start + 2, index - 2);573loc.end = {574line: lineNumber,575column: index - lineStart576};577addComment('Block', comment, start, index, loc);578}579return;580}581++index;582} else {583++index;584}585}586587throwError({}, Messages.UnexpectedToken, 'ILLEGAL');588}589590function skipComment() {591var ch;592593while (index < length) {594ch = source.charCodeAt(index);595596if (isWhiteSpace(ch)) {597++index;598} else if (isLineTerminator(ch)) {599++index;600if (ch === 13 && source.charCodeAt(index) === 10) {601++index;602}603++lineNumber;604lineStart = index;605} else if (ch === 47) { // 47 is '/'606ch = source.charCodeAt(index + 1);607if (ch === 47) {608++index;609++index;610skipSingleLineComment();611} else if (ch === 42) { // 42 is '*'612++index;613++index;614skipMultiLineComment();615} else {616break;617}618} else {619break;620}621}622}623624function scanHexEscape(prefix) {625var i, len, ch, code = 0;626627len = (prefix === 'u') ? 4 : 2;628for (i = 0; i < len; ++i) {629if (index < length && isHexDigit(source[index])) {630ch = source[index++];631code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());632} else {633return '';634}635}636return String.fromCharCode(code);637}638639function scanUnicodeCodePointEscape() {640var ch, code, cu1, cu2;641642ch = source[index];643code = 0;644645// At least, one hex digit is required.646if (ch === '}') {647throwError({}, Messages.UnexpectedToken, 'ILLEGAL');648}649650while (index < length) {651ch = source[index++];652if (!isHexDigit(ch)) {653break;654}655code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());656}657658if (code > 0x10FFFF || ch !== '}') {659throwError({}, Messages.UnexpectedToken, 'ILLEGAL');660}661662// UTF-16 Encoding663if (code <= 0xFFFF) {664return String.fromCharCode(code);665}666cu1 = ((code - 0x10000) >> 10) + 0xD800;667cu2 = ((code - 0x10000) & 1023) + 0xDC00;668return String.fromCharCode(cu1, cu2);669}670671function getEscapedIdentifier() {672var ch, id;673674ch = source.charCodeAt(index++);675id = String.fromCharCode(ch);676677// '\u' (char #92, char #117) denotes an escaped character.678if (ch === 92) {679if (source.charCodeAt(index) !== 117) {680throwError({}, Messages.UnexpectedToken, 'ILLEGAL');681}682++index;683ch = scanHexEscape('u');684if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {685throwError({}, Messages.UnexpectedToken, 'ILLEGAL');686}687id = ch;688}689690while (index < length) {691ch = source.charCodeAt(index);692if (!isIdentifierPart(ch)) {693break;694}695++index;696id += String.fromCharCode(ch);697698// '\u' (char #92, char #117) denotes an escaped character.699if (ch === 92) {700id = id.substr(0, id.length - 1);701if (source.charCodeAt(index) !== 117) {702throwError({}, Messages.UnexpectedToken, 'ILLEGAL');703}704++index;705ch = scanHexEscape('u');706if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {707throwError({}, Messages.UnexpectedToken, 'ILLEGAL');708}709id += ch;710}711}712713return id;714}715716function getIdentifier() {717var start, ch;718719start = index++;720while (index < length) {721ch = source.charCodeAt(index);722if (ch === 92) {723// Blackslash (char #92) marks Unicode escape sequence.724index = start;725return getEscapedIdentifier();726}727if (isIdentifierPart(ch)) {728++index;729} else {730break;731}732}733734return source.slice(start, index);735}736737function scanIdentifier() {738var start, id, type;739740start = index;741742// Backslash (char #92) starts an escaped character.743id = (source.charCodeAt(index) === 92) ? getEscapedIdentifier() : getIdentifier();744745// There is no keyword or literal with only one character.746// Thus, it must be an identifier.747if (id.length === 1) {748type = Token.Identifier;749} else if (isKeyword(id)) {750type = Token.Keyword;751} else if (id === 'null') {752type = Token.NullLiteral;753} else if (id === 'true' || id === 'false') {754type = Token.BooleanLiteral;755} else {756type = Token.Identifier;757}758759return {760type: type,761value: id,762lineNumber: lineNumber,763lineStart: lineStart,764range: [start, index]765};766}767768769// 7.7 Punctuators770771function scanPunctuator() {772var start = index,773code = source.charCodeAt(index),774code2,775ch1 = source[index],776ch2,777ch3,778ch4;779780if (state.inJSXTag || state.inJSXChild) {781// Don't need to check for '{' and '}' as it's already handled782// correctly by default.783switch (code) {784case 60: // <785case 62: // >786++index;787return {788type: Token.Punctuator,789value: String.fromCharCode(code),790lineNumber: lineNumber,791lineStart: lineStart,792range: [start, index]793};794}795}796797switch (code) {798// Check for most common single-character punctuators.799case 40: // ( open bracket800case 41: // ) close bracket801case 59: // ; semicolon802case 44: // , comma803case 123: // { open curly brace804case 125: // } close curly brace805case 91: // [806case 93: // ]807case 58: // :808case 63: // ?809case 126: // ~810++index;811if (extra.tokenize) {812if (code === 40) {813extra.openParenToken = extra.tokens.length;814} else if (code === 123) {815extra.openCurlyToken = extra.tokens.length;816}817}818return {819type: Token.Punctuator,820value: String.fromCharCode(code),821lineNumber: lineNumber,822lineStart: lineStart,823range: [start, index]824};825826default:827code2 = source.charCodeAt(index + 1);828829// '=' (char #61) marks an assignment or comparison operator.830if (code2 === 61) {831switch (code) {832case 37: // %833case 38: // &834case 42: // *:835case 43: // +836case 45: // -837case 47: // /838case 60: // <839case 62: // >840case 94: // ^841case 124: // |842index += 2;843return {844type: Token.Punctuator,845value: String.fromCharCode(code) + String.fromCharCode(code2),846lineNumber: lineNumber,847lineStart: lineStart,848range: [start, index]849};850851case 33: // !852case 61: // =853index += 2;854855// !== and ===856if (source.charCodeAt(index) === 61) {857++index;858}859return {860type: Token.Punctuator,861value: source.slice(start, index),862lineNumber: lineNumber,863lineStart: lineStart,864range: [start, index]865};866default:867break;868}869}870break;871}872873// Peek more characters.874875ch2 = source[index + 1];876ch3 = source[index + 2];877ch4 = source[index + 3];878879// 4-character punctuator: >>>=880881if (ch1 === '>' && ch2 === '>' && ch3 === '>') {882if (ch4 === '=') {883index += 4;884return {885type: Token.Punctuator,886value: '>>>=',887lineNumber: lineNumber,888lineStart: lineStart,889range: [start, index]890};891}892}893894// 3-character punctuators: === !== >>> <<= >>=895896if (ch1 === '>' && ch2 === '>' && ch3 === '>' && !state.inType) {897index += 3;898return {899type: Token.Punctuator,900value: '>>>',901lineNumber: lineNumber,902lineStart: lineStart,903range: [start, index]904};905}906907if (ch1 === '<' && ch2 === '<' && ch3 === '=') {908index += 3;909return {910type: Token.Punctuator,911value: '<<=',912lineNumber: lineNumber,913lineStart: lineStart,914range: [start, index]915};916}917918if (ch1 === '>' && ch2 === '>' && ch3 === '=') {919index += 3;920return {921type: Token.Punctuator,922value: '>>=',923lineNumber: lineNumber,924lineStart: lineStart,925range: [start, index]926};927}928929if (ch1 === '.' && ch2 === '.' && ch3 === '.') {930index += 3;931return {932type: Token.Punctuator,933value: '...',934lineNumber: lineNumber,935lineStart: lineStart,936range: [start, index]937};938}939940// Other 2-character punctuators: ++ -- << >> && ||941942// Don't match these tokens if we're in a type, since they never can943// occur and can mess up types like Map<string, Array<string>>944if (ch1 === ch2 && ('+-<>&|'.indexOf(ch1) >= 0) && !state.inType) {945index += 2;946return {947type: Token.Punctuator,948value: ch1 + ch2,949lineNumber: lineNumber,950lineStart: lineStart,951range: [start, index]952};953}954955if (ch1 === '=' && ch2 === '>') {956index += 2;957return {958type: Token.Punctuator,959value: '=>',960lineNumber: lineNumber,961lineStart: lineStart,962range: [start, index]963};964}965966if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {967++index;968return {969type: Token.Punctuator,970value: ch1,971lineNumber: lineNumber,972lineStart: lineStart,973range: [start, index]974};975}976977if (ch1 === '.') {978++index;979return {980type: Token.Punctuator,981value: ch1,982lineNumber: lineNumber,983lineStart: lineStart,984range: [start, index]985};986}987988throwError({}, Messages.UnexpectedToken, 'ILLEGAL');989}990991// 7.8.3 Numeric Literals992993function scanHexLiteral(start) {994var number = '';995996while (index < length) {997if (!isHexDigit(source[index])) {998break;999}1000number += source[index++];1001}10021003if (number.length === 0) {1004throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1005}10061007if (isIdentifierStart(source.charCodeAt(index))) {1008throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1009}10101011return {1012type: Token.NumericLiteral,1013value: parseInt('0x' + number, 16),1014lineNumber: lineNumber,1015lineStart: lineStart,1016range: [start, index]1017};1018}10191020function scanBinaryLiteral(start) {1021var ch, number;10221023number = '';10241025while (index < length) {1026ch = source[index];1027if (ch !== '0' && ch !== '1') {1028break;1029}1030number += source[index++];1031}10321033if (number.length === 0) {1034// only 0b or 0B1035throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1036}10371038if (index < length) {1039ch = source.charCodeAt(index);1040/* istanbul ignore else */1041if (isIdentifierStart(ch) || isDecimalDigit(ch)) {1042throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1043}1044}10451046return {1047type: Token.NumericLiteral,1048value: parseInt(number, 2),1049lineNumber: lineNumber,1050lineStart: lineStart,1051range: [start, index]1052};1053}10541055function scanOctalLiteral(prefix, start) {1056var number, octal;10571058if (isOctalDigit(prefix)) {1059octal = true;1060number = '0' + source[index++];1061} else {1062octal = false;1063++index;1064number = '';1065}10661067while (index < length) {1068if (!isOctalDigit(source[index])) {1069break;1070}1071number += source[index++];1072}10731074if (!octal && number.length === 0) {1075// only 0o or 0O1076throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1077}10781079if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {1080throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1081}10821083return {1084type: Token.NumericLiteral,1085value: parseInt(number, 8),1086octal: octal,1087lineNumber: lineNumber,1088lineStart: lineStart,1089range: [start, index]1090};1091}10921093function scanNumericLiteral() {1094var number, start, ch;10951096ch = source[index];1097assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),1098'Numeric literal must start with a decimal digit or a decimal point');10991100start = index;1101number = '';1102if (ch !== '.') {1103number = source[index++];1104ch = source[index];11051106// Hex number starts with '0x'.1107// Octal number starts with '0'.1108// Octal number in ES6 starts with '0o'.1109// Binary number in ES6 starts with '0b'.1110if (number === '0') {1111if (ch === 'x' || ch === 'X') {1112++index;1113return scanHexLiteral(start);1114}1115if (ch === 'b' || ch === 'B') {1116++index;1117return scanBinaryLiteral(start);1118}1119if (ch === 'o' || ch === 'O' || isOctalDigit(ch)) {1120return scanOctalLiteral(ch, start);1121}1122// decimal number starts with '0' such as '09' is illegal.1123if (ch && isDecimalDigit(ch.charCodeAt(0))) {1124throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1125}1126}11271128while (isDecimalDigit(source.charCodeAt(index))) {1129number += source[index++];1130}1131ch = source[index];1132}11331134if (ch === '.') {1135number += source[index++];1136while (isDecimalDigit(source.charCodeAt(index))) {1137number += source[index++];1138}1139ch = source[index];1140}11411142if (ch === 'e' || ch === 'E') {1143number += source[index++];11441145ch = source[index];1146if (ch === '+' || ch === '-') {1147number += source[index++];1148}1149if (isDecimalDigit(source.charCodeAt(index))) {1150while (isDecimalDigit(source.charCodeAt(index))) {1151number += source[index++];1152}1153} else {1154throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1155}1156}11571158if (isIdentifierStart(source.charCodeAt(index))) {1159throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1160}11611162return {1163type: Token.NumericLiteral,1164value: parseFloat(number),1165lineNumber: lineNumber,1166lineStart: lineStart,1167range: [start, index]1168};1169}11701171// 7.8.4 String Literals11721173function scanStringLiteral() {1174var str = '', quote, start, ch, code, unescaped, restore, octal = false;11751176quote = source[index];1177assert((quote === '\'' || quote === '"'),1178'String literal must starts with a quote');11791180start = index;1181++index;11821183while (index < length) {1184ch = source[index++];11851186if (ch === quote) {1187quote = '';1188break;1189} else if (ch === '\\') {1190ch = source[index++];1191if (!ch || !isLineTerminator(ch.charCodeAt(0))) {1192switch (ch) {1193case 'n':1194str += '\n';1195break;1196case 'r':1197str += '\r';1198break;1199case 't':1200str += '\t';1201break;1202case 'u':1203case 'x':1204if (source[index] === '{') {1205++index;1206str += scanUnicodeCodePointEscape();1207} else {1208restore = index;1209unescaped = scanHexEscape(ch);1210if (unescaped) {1211str += unescaped;1212} else {1213index = restore;1214str += ch;1215}1216}1217break;1218case 'b':1219str += '\b';1220break;1221case 'f':1222str += '\f';1223break;1224case 'v':1225str += '\x0B';1226break;12271228default:1229if (isOctalDigit(ch)) {1230code = '01234567'.indexOf(ch);12311232// \0 is not octal escape sequence1233if (code !== 0) {1234octal = true;1235}12361237/* istanbul ignore else */1238if (index < length && isOctalDigit(source[index])) {1239octal = true;1240code = code * 8 + '01234567'.indexOf(source[index++]);12411242// 3 digits are only allowed when string starts1243// with 0, 1, 2, 31244if ('0123'.indexOf(ch) >= 0 &&1245index < length &&1246isOctalDigit(source[index])) {1247code = code * 8 + '01234567'.indexOf(source[index++]);1248}1249}1250str += String.fromCharCode(code);1251} else {1252str += ch;1253}1254break;1255}1256} else {1257++lineNumber;1258if (ch === '\r' && source[index] === '\n') {1259++index;1260}1261lineStart = index;1262}1263} else if (isLineTerminator(ch.charCodeAt(0))) {1264break;1265} else {1266str += ch;1267}1268}12691270if (quote !== '') {1271throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1272}12731274return {1275type: Token.StringLiteral,1276value: str,1277octal: octal,1278lineNumber: lineNumber,1279lineStart: lineStart,1280range: [start, index]1281};1282}12831284function scanTemplate() {1285var cooked = '', ch, start, terminated, tail, restore, unescaped, code, octal;12861287terminated = false;1288tail = false;1289start = index;12901291++index;12921293while (index < length) {1294ch = source[index++];1295if (ch === '`') {1296tail = true;1297terminated = true;1298break;1299} else if (ch === '$') {1300if (source[index] === '{') {1301++index;1302terminated = true;1303break;1304}1305cooked += ch;1306} else if (ch === '\\') {1307ch = source[index++];1308if (!isLineTerminator(ch.charCodeAt(0))) {1309switch (ch) {1310case 'n':1311cooked += '\n';1312break;1313case 'r':1314cooked += '\r';1315break;1316case 't':1317cooked += '\t';1318break;1319case 'u':1320case 'x':1321if (source[index] === '{') {1322++index;1323cooked += scanUnicodeCodePointEscape();1324} else {1325restore = index;1326unescaped = scanHexEscape(ch);1327if (unescaped) {1328cooked += unescaped;1329} else {1330index = restore;1331cooked += ch;1332}1333}1334break;1335case 'b':1336cooked += '\b';1337break;1338case 'f':1339cooked += '\f';1340break;1341case 'v':1342cooked += '\v';1343break;13441345default:1346if (isOctalDigit(ch)) {1347code = '01234567'.indexOf(ch);13481349// \0 is not octal escape sequence1350if (code !== 0) {1351octal = true;1352}13531354/* istanbul ignore else */1355if (index < length && isOctalDigit(source[index])) {1356octal = true;1357code = code * 8 + '01234567'.indexOf(source[index++]);13581359// 3 digits are only allowed when string starts1360// with 0, 1, 2, 31361if ('0123'.indexOf(ch) >= 0 &&1362index < length &&1363isOctalDigit(source[index])) {1364code = code * 8 + '01234567'.indexOf(source[index++]);1365}1366}1367cooked += String.fromCharCode(code);1368} else {1369cooked += ch;1370}1371break;1372}1373} else {1374++lineNumber;1375if (ch === '\r' && source[index] === '\n') {1376++index;1377}1378lineStart = index;1379}1380} else if (isLineTerminator(ch.charCodeAt(0))) {1381++lineNumber;1382if (ch === '\r' && source[index] === '\n') {1383++index;1384}1385lineStart = index;1386cooked += '\n';1387} else {1388cooked += ch;1389}1390}13911392if (!terminated) {1393throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1394}13951396return {1397type: Token.Template,1398value: {1399cooked: cooked,1400raw: source.slice(start + 1, index - ((tail) ? 1 : 2))1401},1402tail: tail,1403octal: octal,1404lineNumber: lineNumber,1405lineStart: lineStart,1406range: [start, index]1407};1408}14091410function scanTemplateElement(option) {1411var startsWith, template;14121413lookahead = null;1414skipComment();14151416startsWith = (option.head) ? '`' : '}';14171418if (source[index] !== startsWith) {1419throwError({}, Messages.UnexpectedToken, 'ILLEGAL');1420}14211422template = scanTemplate();14231424peek();14251426return template;1427}14281429function testRegExp(pattern, flags) {1430var tmp = pattern,1431value;14321433if (flags.indexOf('u') >= 0) {1434// Replace each astral symbol and every Unicode code point1435// escape sequence with a single ASCII symbol to avoid throwing on1436// regular expressions that are only valid in combination with the1437// `/u` flag.1438// Note: replacing with the ASCII symbol `x` might cause false1439// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a1440// perfectly valid pattern that is equivalent to `[a-b]`, but it1441// would be replaced by `[x-b]` which throws an error.1442tmp = tmp1443.replace(/\\u\{([0-9a-fA-F]+)\}/g, function ($0, $1) {1444if (parseInt($1, 16) <= 0x10FFFF) {1445return 'x';1446}1447throwError({}, Messages.InvalidRegExp);1448})1449.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, 'x');1450}14511452// First, detect invalid regular expressions.1453try {1454value = new RegExp(tmp);1455} catch (e) {1456throwError({}, Messages.InvalidRegExp);1457}14581459// Return a regular expression object for this pattern-flag pair, or1460// `null` in case the current environment doesn't support the flags it1461// uses.1462try {1463return new RegExp(pattern, flags);1464} catch (exception) {1465return null;1466}1467}14681469function scanRegExpBody() {1470var ch, str, classMarker, terminated, body;14711472ch = source[index];1473assert(ch === '/', 'Regular expression literal must start with a slash');1474str = source[index++];14751476classMarker = false;1477terminated = false;1478while (index < length) {1479ch = source[index++];1480str += ch;1481if (ch === '\\') {1482ch = source[index++];1483// ECMA-262 7.8.51484if (isLineTerminator(ch.charCodeAt(0))) {1485throwError({}, Messages.UnterminatedRegExp);1486}1487str += ch;1488} else if (isLineTerminator(ch.charCodeAt(0))) {1489throwError({}, Messages.UnterminatedRegExp);1490} else if (classMarker) {1491if (ch === ']') {1492classMarker = false;1493}1494} else {1495if (ch === '/') {1496terminated = true;1497break;1498} else if (ch === '[') {1499classMarker = true;1500}1501}1502}15031504if (!terminated) {1505throwError({}, Messages.UnterminatedRegExp);1506}15071508// Exclude leading and trailing slash.1509body = str.substr(1, str.length - 2);1510return {1511value: body,1512literal: str1513};1514}15151516function scanRegExpFlags() {1517var ch, str, flags, restore;15181519str = '';1520flags = '';1521while (index < length) {1522ch = source[index];1523if (!isIdentifierPart(ch.charCodeAt(0))) {1524break;1525}15261527++index;1528if (ch === '\\' && index < length) {1529ch = source[index];1530if (ch === 'u') {1531++index;1532restore = index;1533ch = scanHexEscape('u');1534if (ch) {1535flags += ch;1536for (str += '\\u'; restore < index; ++restore) {1537str += source[restore];1538}1539} else {1540index = restore;1541flags += 'u';1542str += '\\u';1543}1544throwErrorTolerant({}, Messages.UnexpectedToken, 'ILLEGAL');1545} else {1546str += '\\';1547throwErrorTolerant({}, Messages.UnexpectedToken, 'ILLEGAL');1548}1549} else {1550flags += ch;1551str += ch;1552}1553}15541555return {1556value: flags,1557literal: str1558};1559}15601561function scanRegExp() {1562var start, body, flags, value;15631564lookahead = null;1565skipComment();1566start = index;15671568body = scanRegExpBody();1569flags = scanRegExpFlags();1570value = testRegExp(body.value, flags.value);15711572if (extra.tokenize) {1573return {1574type: Token.RegularExpression,1575value: value,1576regex: {1577pattern: body.value,1578flags: flags.value1579},1580lineNumber: lineNumber,1581lineStart: lineStart,1582range: [start, index]1583};1584}15851586return {1587literal: body.literal + flags.literal,1588value: value,1589regex: {1590pattern: body.value,1591flags: flags.value1592},1593range: [start, index]1594};1595}15961597function isIdentifierName(token) {1598return token.type === Token.Identifier ||1599token.type === Token.Keyword ||1600token.type === Token.BooleanLiteral ||1601token.type === Token.NullLiteral;1602}16031604function advanceSlash() {1605var prevToken,1606checkToken;1607// Using the following algorithm:1608// https://github.com/mozilla/sweet.js/wiki/design1609prevToken = extra.tokens[extra.tokens.length - 1];1610if (!prevToken) {1611// Nothing before that: it cannot be a division.1612return scanRegExp();1613}1614if (prevToken.type === 'Punctuator') {1615if (prevToken.value === ')') {1616checkToken = extra.tokens[extra.openParenToken - 1];1617if (checkToken &&1618checkToken.type === 'Keyword' &&1619(checkToken.value === 'if' ||1620checkToken.value === 'while' ||1621checkToken.value === 'for' ||1622checkToken.value === 'with')) {1623return scanRegExp();1624}1625return scanPunctuator();1626}1627if (prevToken.value === '}') {1628// Dividing a function by anything makes little sense,1629// but we have to check for that.1630if (extra.tokens[extra.openCurlyToken - 3] &&1631extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {1632// Anonymous function.1633checkToken = extra.tokens[extra.openCurlyToken - 4];1634if (!checkToken) {1635return scanPunctuator();1636}1637} else if (extra.tokens[extra.openCurlyToken - 4] &&1638extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {1639// Named function.1640checkToken = extra.tokens[extra.openCurlyToken - 5];1641if (!checkToken) {1642return scanRegExp();1643}1644} else {1645return scanPunctuator();1646}1647// checkToken determines whether the function is1648// a declaration or an expression.1649if (FnExprTokens.indexOf(checkToken.value) >= 0) {1650// It is an expression.1651return scanPunctuator();1652}1653// It is a declaration.1654return scanRegExp();1655}1656return scanRegExp();1657}1658if (prevToken.type === 'Keyword' && prevToken.value !== 'this') {1659return scanRegExp();1660}1661return scanPunctuator();1662}16631664function advance() {1665var ch;16661667if (!state.inJSXChild) {1668skipComment();1669}16701671if (index >= length) {1672return {1673type: Token.EOF,1674lineNumber: lineNumber,1675lineStart: lineStart,1676range: [index, index]1677};1678}16791680if (state.inJSXChild) {1681return advanceJSXChild();1682}16831684ch = source.charCodeAt(index);16851686// Very common: ( and ) and ;1687if (ch === 40 || ch === 41 || ch === 58) {1688return scanPunctuator();1689}16901691// String literal starts with single quote (#39) or double quote (#34).1692if (ch === 39 || ch === 34) {1693if (state.inJSXTag) {1694return scanJSXStringLiteral();1695}1696return scanStringLiteral();1697}16981699if (state.inJSXTag && isJSXIdentifierStart(ch)) {1700return scanJSXIdentifier();1701}17021703if (ch === 96) {1704return scanTemplate();1705}1706if (isIdentifierStart(ch)) {1707return scanIdentifier();1708}17091710// Dot (.) char #46 can also start a floating-point number, hence the need1711// to check the next character.1712if (ch === 46) {1713if (isDecimalDigit(source.charCodeAt(index + 1))) {1714return scanNumericLiteral();1715}1716return scanPunctuator();1717}17181719if (isDecimalDigit(ch)) {1720return scanNumericLiteral();1721}17221723// Slash (/) char #47 can also start a regex.1724if (extra.tokenize && ch === 47) {1725return advanceSlash();1726}17271728return scanPunctuator();1729}17301731function lex() {1732var token;17331734token = lookahead;1735index = token.range[1];1736lineNumber = token.lineNumber;1737lineStart = token.lineStart;17381739lookahead = advance();17401741index = token.range[1];1742lineNumber = token.lineNumber;1743lineStart = token.lineStart;17441745return token;1746}17471748function peek() {1749var pos, line, start;17501751pos = index;1752line = lineNumber;1753start = lineStart;1754lookahead = advance();1755index = pos;1756lineNumber = line;1757lineStart = start;1758}17591760function lookahead2() {1761var adv, pos, line, start, result;17621763// If we are collecting the tokens, don't grab the next one yet.1764/* istanbul ignore next */1765adv = (typeof extra.advance === 'function') ? extra.advance : advance;17661767pos = index;1768line = lineNumber;1769start = lineStart;17701771// Scan for the next immediate token.1772/* istanbul ignore if */1773if (lookahead === null) {1774lookahead = adv();1775}1776index = lookahead.range[1];1777lineNumber = lookahead.lineNumber;1778lineStart = lookahead.lineStart;17791780// Grab the token right after.1781result = adv();1782index = pos;1783lineNumber = line;1784lineStart = start;17851786return result;1787}17881789function rewind(token) {1790index = token.range[0];1791lineNumber = token.lineNumber;1792lineStart = token.lineStart;1793lookahead = token;1794}17951796function markerCreate() {1797if (!extra.loc && !extra.range) {1798return undefined;1799}1800skipComment();1801return {offset: index, line: lineNumber, col: index - lineStart};1802}18031804function markerCreatePreserveWhitespace() {1805if (!extra.loc && !extra.range) {1806return undefined;1807}1808return {offset: index, line: lineNumber, col: index - lineStart};1809}18101811function processComment(node) {1812var lastChild,1813trailingComments,1814bottomRight = extra.bottomRightStack,1815last = bottomRight[bottomRight.length - 1];18161817if (node.type === Syntax.Program) {1818/* istanbul ignore else */1819if (node.body.length > 0) {1820return;1821}1822}18231824if (extra.trailingComments.length > 0) {1825if (extra.trailingComments[0].range[0] >= node.range[1]) {1826trailingComments = extra.trailingComments;1827extra.trailingComments = [];1828} else {1829extra.trailingComments.length = 0;1830}1831} else {1832if (last && last.trailingComments && last.trailingComments[0].range[0] >= node.range[1]) {1833trailingComments = last.trailingComments;1834delete last.trailingComments;1835}1836}18371838// Eating the stack.1839if (last) {1840while (last && last.range[0] >= node.range[0]) {1841lastChild = last;1842last = bottomRight.pop();1843}1844}18451846if (lastChild) {1847if (lastChild.leadingComments && lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= node.range[0]) {1848node.leadingComments = lastChild.leadingComments;1849delete lastChild.leadingComments;1850}1851} else if (extra.leadingComments.length > 0 && extra.leadingComments[extra.leadingComments.length - 1].range[1] <= node.range[0]) {1852node.leadingComments = extra.leadingComments;1853extra.leadingComments = [];1854}18551856if (trailingComments) {1857node.trailingComments = trailingComments;1858}18591860bottomRight.push(node);1861}18621863function markerApply(marker, node) {1864if (extra.range) {1865node.range = [marker.offset, index];1866}1867if (extra.loc) {1868node.loc = {1869start: {1870line: marker.line,1871column: marker.col1872},1873end: {1874line: lineNumber,1875column: index - lineStart1876}1877};1878node = delegate.postProcess(node);1879}1880if (extra.attachComment) {1881processComment(node);1882}1883return node;1884}18851886SyntaxTreeDelegate = {18871888name: 'SyntaxTree',18891890postProcess: function (node) {1891return node;1892},18931894createArrayExpression: function (elements) {1895return {1896type: Syntax.ArrayExpression,1897elements: elements1898};1899},19001901createAssignmentExpression: function (operator, left, right) {1902return {1903type: Syntax.AssignmentExpression,1904operator: operator,1905left: left,1906right: right1907};1908},19091910createBinaryExpression: function (operator, left, right) {1911var type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression :1912Syntax.BinaryExpression;1913return {1914type: type,1915operator: operator,1916left: left,1917right: right1918};1919},19201921createBlockStatement: function (body) {1922return {1923type: Syntax.BlockStatement,1924body: body1925};1926},19271928createBreakStatement: function (label) {1929return {1930type: Syntax.BreakStatement,1931label: label1932};1933},19341935createCallExpression: function (callee, args) {1936return {1937type: Syntax.CallExpression,1938callee: callee,1939'arguments': args1940};1941},19421943createCatchClause: function (param, body) {1944return {1945type: Syntax.CatchClause,1946param: param,1947body: body1948};1949},19501951createConditionalExpression: function (test, consequent, alternate) {1952return {1953type: Syntax.ConditionalExpression,1954test: test,1955consequent: consequent,1956alternate: alternate1957};1958},19591960createContinueStatement: function (label) {1961return {1962type: Syntax.ContinueStatement,1963label: label1964};1965},19661967createDebuggerStatement: function () {1968return {1969type: Syntax.DebuggerStatement1970};1971},19721973createDoWhileStatement: function (body, test) {1974return {1975type: Syntax.DoWhileStatement,1976body: body,1977test: test1978};1979},19801981createEmptyStatement: function () {1982return {1983type: Syntax.EmptyStatement1984};1985},19861987createExpressionStatement: function (expression) {1988return {1989type: Syntax.ExpressionStatement,1990expression: expression1991};1992},19931994createForStatement: function (init, test, update, body) {1995return {1996type: Syntax.ForStatement,1997init: init,1998test: test,1999update: update,2000body: body2001};2002},20032004createForInStatement: function (left, right, body) {2005return {2006type: Syntax.ForInStatement,2007left: left,2008right: right,2009body: body,2010each: false2011};2012},20132014createForOfStatement: function (left, right, body) {2015return {2016type: Syntax.ForOfStatement,2017left: left,2018right: right,2019body: body2020};2021},20222023createFunctionDeclaration: function (id, params, defaults, body, rest, generator, expression,2024isAsync, returnType, typeParameters) {2025var funDecl = {2026type: Syntax.FunctionDeclaration,2027id: id,2028params: params,2029defaults: defaults,2030body: body,2031rest: rest,2032generator: generator,2033expression: expression,2034returnType: returnType,2035typeParameters: typeParameters2036};20372038if (isAsync) {2039funDecl.async = true;2040}20412042return funDecl;2043},20442045createFunctionExpression: function (id, params, defaults, body, rest, generator, expression,2046isAsync, returnType, typeParameters) {2047var funExpr = {2048type: Syntax.FunctionExpression,2049id: id,2050params: params,2051defaults: defaults,2052body: body,2053rest: rest,2054generator: generator,2055expression: expression,2056returnType: returnType,2057typeParameters: typeParameters2058};20592060if (isAsync) {2061funExpr.async = true;2062}20632064return funExpr;2065},20662067createIdentifier: function (name) {2068return {2069type: Syntax.Identifier,2070name: name,2071// Only here to initialize the shape of the object to ensure2072// that the 'typeAnnotation' key is ordered before others that2073// are added later (like 'loc' and 'range'). This just helps2074// keep the shape of Identifier nodes consistent with everything2075// else.2076typeAnnotation: undefined,2077optional: undefined2078};2079},20802081createTypeAnnotation: function (typeAnnotation) {2082return {2083type: Syntax.TypeAnnotation,2084typeAnnotation: typeAnnotation2085};2086},20872088createTypeCast: function (expression, typeAnnotation) {2089return {2090type: Syntax.TypeCastExpression,2091expression: expression,2092typeAnnotation: typeAnnotation2093};2094},20952096createFunctionTypeAnnotation: function (params, returnType, rest, typeParameters) {2097return {2098type: Syntax.FunctionTypeAnnotation,2099params: params,2100returnType: returnType,2101rest: rest,2102typeParameters: typeParameters2103};2104},21052106createFunctionTypeParam: function (name, typeAnnotation, optional) {2107return {2108type: Syntax.FunctionTypeParam,2109name: name,2110typeAnnotation: typeAnnotation,2111optional: optional2112};2113},21142115createNullableTypeAnnotation: function (typeAnnotation) {2116return {2117type: Syntax.NullableTypeAnnotation,2118typeAnnotation: typeAnnotation2119};2120},21212122createArrayTypeAnnotation: function (elementType) {2123return {2124type: Syntax.ArrayTypeAnnotation,2125elementType: elementType2126};2127},21282129createGenericTypeAnnotation: function (id, typeParameters) {2130return {2131type: Syntax.GenericTypeAnnotation,2132id: id,2133typeParameters: typeParameters2134};2135},21362137createQualifiedTypeIdentifier: function (qualification, id) {2138return {2139type: Syntax.QualifiedTypeIdentifier,2140qualification: qualification,2141id: id2142};2143},21442145createTypeParameterDeclaration: function (params) {2146return {2147type: Syntax.TypeParameterDeclaration,2148params: params2149};2150},21512152createTypeParameterInstantiation: function (params) {2153return {2154type: Syntax.TypeParameterInstantiation,2155params: params2156};2157},21582159createAnyTypeAnnotation: function () {2160return {2161type: Syntax.AnyTypeAnnotation2162};2163},21642165createBooleanTypeAnnotation: function () {2166return {2167type: Syntax.BooleanTypeAnnotation2168};2169},21702171createNumberTypeAnnotation: function () {2172return {2173type: Syntax.NumberTypeAnnotation2174};2175},21762177createStringTypeAnnotation: function () {2178return {2179type: Syntax.StringTypeAnnotation2180};2181},21822183createStringLiteralTypeAnnotation: function (token) {2184return {2185type: Syntax.StringLiteralTypeAnnotation,2186value: token.value,2187raw: source.slice(token.range[0], token.range[1])2188};2189},21902191createVoidTypeAnnotation: function () {2192return {2193type: Syntax.VoidTypeAnnotation2194};2195},21962197createTypeofTypeAnnotation: function (argument) {2198return {2199type: Syntax.TypeofTypeAnnotation,2200argument: argument2201};2202},22032204createTupleTypeAnnotation: function (types) {2205return {2206type: Syntax.TupleTypeAnnotation,2207types: types2208};2209},22102211createObjectTypeAnnotation: function (properties, indexers, callProperties) {2212return {2213type: Syntax.ObjectTypeAnnotation,2214properties: properties,2215indexers: indexers,2216callProperties: callProperties2217};2218},22192220createObjectTypeIndexer: function (id, key, value, isStatic) {2221return {2222type: Syntax.ObjectTypeIndexer,2223id: id,2224key: key,2225value: value,2226static: isStatic2227};2228},22292230createObjectTypeCallProperty: function (value, isStatic) {2231return {2232type: Syntax.ObjectTypeCallProperty,2233value: value,2234static: isStatic2235};2236},22372238createObjectTypeProperty: function (key, value, optional, isStatic) {2239return {2240type: Syntax.ObjectTypeProperty,2241key: key,2242value: value,2243optional: optional,2244static: isStatic2245};2246},22472248createUnionTypeAnnotation: function (types) {2249return {2250type: Syntax.UnionTypeAnnotation,2251types: types2252};2253},22542255createIntersectionTypeAnnotation: function (types) {2256return {2257type: Syntax.IntersectionTypeAnnotation,2258types: types2259};2260},22612262createTypeAlias: function (id, typeParameters, right) {2263return {2264type: Syntax.TypeAlias,2265id: id,2266typeParameters: typeParameters,2267right: right2268};2269},22702271createInterface: function (id, typeParameters, body, extended) {2272return {2273type: Syntax.InterfaceDeclaration,2274id: id,2275typeParameters: typeParameters,2276body: body,2277extends: extended2278};2279},22802281createInterfaceExtends: function (id, typeParameters) {2282return {2283type: Syntax.InterfaceExtends,2284id: id,2285typeParameters: typeParameters2286};2287},22882289createDeclareFunction: function (id) {2290return {2291type: Syntax.DeclareFunction,2292id: id2293};2294},22952296createDeclareVariable: function (id) {2297return {2298type: Syntax.DeclareVariable,2299id: id2300};2301},23022303createDeclareModule: function (id, body) {2304return {2305type: Syntax.DeclareModule,2306id: id,2307body: body2308};2309},23102311createJSXAttribute: function (name, value) {2312return {2313type: Syntax.JSXAttribute,2314name: name,2315value: value || null2316};2317},23182319createJSXSpreadAttribute: function (argument) {2320return {2321type: Syntax.JSXSpreadAttribute,2322argument: argument2323};2324},23252326createJSXIdentifier: function (name) {2327return {2328type: Syntax.JSXIdentifier,2329name: name2330};2331},23322333createJSXNamespacedName: function (namespace, name) {2334return {2335type: Syntax.JSXNamespacedName,2336namespace: namespace,2337name: name2338};2339},23402341createJSXMemberExpression: function (object, property) {2342return {2343type: Syntax.JSXMemberExpression,2344object: object,2345property: property2346};2347},23482349createJSXElement: function (openingElement, closingElement, children) {2350return {2351type: Syntax.JSXElement,2352openingElement: openingElement,2353closingElement: closingElement,2354children: children2355};2356},23572358createJSXEmptyExpression: function () {2359return {2360type: Syntax.JSXEmptyExpression2361};2362},23632364createJSXExpressionContainer: function (expression) {2365return {2366type: Syntax.JSXExpressionContainer,2367expression: expression2368};2369},23702371createJSXOpeningElement: function (name, attributes, selfClosing) {2372return {2373type: Syntax.JSXOpeningElement,2374name: name,2375selfClosing: selfClosing,2376attributes: attributes2377};2378},23792380createJSXClosingElement: function (name) {2381return {2382type: Syntax.JSXClosingElement,2383name: name2384};2385},23862387createIfStatement: function (test, consequent, alternate) {2388return {2389type: Syntax.IfStatement,2390test: test,2391consequent: consequent,2392alternate: alternate2393};2394},23952396createLabeledStatement: function (label, body) {2397return {2398type: Syntax.LabeledStatement,2399label: label,2400body: body2401};2402},24032404createLiteral: function (token) {2405var object = {2406type: Syntax.Literal,2407value: token.value,2408raw: source.slice(token.range[0], token.range[1])2409};2410if (token.regex) {2411object.regex = token.regex;2412}2413return object;2414},24152416createMemberExpression: function (accessor, object, property) {2417return {2418type: Syntax.MemberExpression,2419computed: accessor === '[',2420object: object,2421property: property2422};2423},24242425createNewExpression: function (callee, args) {2426return {2427type: Syntax.NewExpression,2428callee: callee,2429'arguments': args2430};2431},24322433createObjectExpression: function (properties) {2434return {2435type: Syntax.ObjectExpression,2436properties: properties2437};2438},24392440createPostfixExpression: function (operator, argument) {2441return {2442type: Syntax.UpdateExpression,2443operator: operator,2444argument: argument,2445prefix: false2446};2447},24482449createProgram: function (body) {2450return {2451type: Syntax.Program,2452body: body2453};2454},24552456createProperty: function (kind, key, value, method, shorthand, computed) {2457return {2458type: Syntax.Property,2459key: key,2460value: value,2461kind: kind,2462method: method,2463shorthand: shorthand,2464computed: computed2465};2466},24672468createReturnStatement: function (argument) {2469return {2470type: Syntax.ReturnStatement,2471argument: argument2472};2473},24742475createSequenceExpression: function (expressions) {2476return {2477type: Syntax.SequenceExpression,2478expressions: expressions2479};2480},24812482createSwitchCase: function (test, consequent) {2483return {2484type: Syntax.SwitchCase,2485test: test,2486consequent: consequent2487};2488},24892490createSwitchStatement: function (discriminant, cases) {2491return {2492type: Syntax.SwitchStatement,2493discriminant: discriminant,2494cases: cases2495};2496},24972498createThisExpression: function () {2499return {2500type: Syntax.ThisExpression2501};2502},25032504createThrowStatement: function (argument) {2505return {2506type: Syntax.ThrowStatement,2507argument: argument2508};2509},25102511createTryStatement: function (block, guardedHandlers, handlers, finalizer) {2512return {2513type: Syntax.TryStatement,2514block: block,2515guardedHandlers: guardedHandlers,2516handlers: handlers,2517finalizer: finalizer2518};2519},25202521createUnaryExpression: function (operator, argument) {2522if (operator === '++' || operator === '--') {2523return {2524type: Syntax.UpdateExpression,2525operator: operator,2526argument: argument,2527prefix: true2528};2529}2530return {2531type: Syntax.UnaryExpression,2532operator: operator,2533argument: argument,2534prefix: true2535};2536},25372538createVariableDeclaration: function (declarations, kind) {2539return {2540type: Syntax.VariableDeclaration,2541declarations: declarations,2542kind: kind2543};2544},25452546createVariableDeclarator: function (id, init) {2547return {2548type: Syntax.VariableDeclarator,2549id: id,2550init: init2551};2552},25532554createWhileStatement: function (test, body) {2555return {2556type: Syntax.WhileStatement,2557test: test,2558body: body2559};2560},25612562createWithStatement: function (object, body) {2563return {2564type: Syntax.WithStatement,2565object: object,2566body: body2567};2568},25692570createTemplateElement: function (value, tail) {2571return {2572type: Syntax.TemplateElement,2573value: value,2574tail: tail2575};2576},25772578createTemplateLiteral: function (quasis, expressions) {2579return {2580type: Syntax.TemplateLiteral,2581quasis: quasis,2582expressions: expressions2583};2584},25852586createSpreadElement: function (argument) {2587return {2588type: Syntax.SpreadElement,2589argument: argument2590};2591},25922593createSpreadProperty: function (argument) {2594return {2595type: Syntax.SpreadProperty,2596argument: argument2597};2598},25992600createTaggedTemplateExpression: function (tag, quasi) {2601return {2602type: Syntax.TaggedTemplateExpression,2603tag: tag,2604quasi: quasi2605};2606},26072608createArrowFunctionExpression: function (params, defaults, body, rest, expression, isAsync) {2609var arrowExpr = {2610type: Syntax.ArrowFunctionExpression,2611id: null,2612params: params,2613defaults: defaults,2614body: body,2615rest: rest,2616generator: false,2617expression: expression2618};26192620if (isAsync) {2621arrowExpr.async = true;2622}26232624return arrowExpr;2625},26262627createMethodDefinition: function (propertyType, kind, key, value, computed) {2628return {2629type: Syntax.MethodDefinition,2630key: key,2631value: value,2632kind: kind,2633'static': propertyType === ClassPropertyType.static,2634computed: computed2635};2636},26372638createClassProperty: function (key, typeAnnotation, computed, isStatic) {2639return {2640type: Syntax.ClassProperty,2641key: key,2642typeAnnotation: typeAnnotation,2643computed: computed,2644static: isStatic2645};2646},26472648createClassBody: function (body) {2649return {2650type: Syntax.ClassBody,2651body: body2652};2653},26542655createClassImplements: function (id, typeParameters) {2656return {2657type: Syntax.ClassImplements,2658id: id,2659typeParameters: typeParameters2660};2661},26622663createClassExpression: function (id, superClass, body, typeParameters, superTypeParameters, implemented) {2664return {2665type: Syntax.ClassExpression,2666id: id,2667superClass: superClass,2668body: body,2669typeParameters: typeParameters,2670superTypeParameters: superTypeParameters,2671implements: implemented2672};2673},26742675createClassDeclaration: function (id, superClass, body, typeParameters, superTypeParameters, implemented) {2676return {2677type: Syntax.ClassDeclaration,2678id: id,2679superClass: superClass,2680body: body,2681typeParameters: typeParameters,2682superTypeParameters: superTypeParameters,2683implements: implemented2684};2685},26862687createModuleSpecifier: function (token) {2688return {2689type: Syntax.ModuleSpecifier,2690value: token.value,2691raw: source.slice(token.range[0], token.range[1])2692};2693},26942695createExportSpecifier: function (id, name) {2696return {2697type: Syntax.ExportSpecifier,2698id: id,2699name: name2700};2701},27022703createExportBatchSpecifier: function () {2704return {2705type: Syntax.ExportBatchSpecifier2706};2707},27082709createImportDefaultSpecifier: function (id) {2710return {2711type: Syntax.ImportDefaultSpecifier,2712id: id2713};2714},27152716createImportNamespaceSpecifier: function (id) {2717return {2718type: Syntax.ImportNamespaceSpecifier,2719id: id2720};2721},27222723createExportDeclaration: function (isDefault, declaration, specifiers, src) {2724return {2725type: Syntax.ExportDeclaration,2726'default': !!isDefault,2727declaration: declaration,2728specifiers: specifiers,2729source: src2730};2731},27322733createImportSpecifier: function (id, name) {2734return {2735type: Syntax.ImportSpecifier,2736id: id,2737name: name2738};2739},27402741createImportDeclaration: function (specifiers, src, isType) {2742return {2743type: Syntax.ImportDeclaration,2744specifiers: specifiers,2745source: src,2746isType: isType2747};2748},27492750createYieldExpression: function (argument, dlg) {2751return {2752type: Syntax.YieldExpression,2753argument: argument,2754delegate: dlg2755};2756},27572758createAwaitExpression: function (argument) {2759return {2760type: Syntax.AwaitExpression,2761argument: argument2762};2763},27642765createComprehensionExpression: function (filter, blocks, body) {2766return {2767type: Syntax.ComprehensionExpression,2768filter: filter,2769blocks: blocks,2770body: body2771};2772}27732774};27752776// Return true if there is a line terminator before the next token.27772778function peekLineTerminator() {2779var pos, line, start, found;27802781pos = index;2782line = lineNumber;2783start = lineStart;2784skipComment();2785found = lineNumber !== line;2786index = pos;2787lineNumber = line;2788lineStart = start;27892790return found;2791}27922793// Throw an exception27942795function throwError(token, messageFormat) {2796var error,2797args = Array.prototype.slice.call(arguments, 2),2798msg = messageFormat.replace(2799/%(\d)/g,2800function (whole, idx) {2801assert(idx < args.length, 'Message reference must be in range');2802return args[idx];2803}2804);28052806if (typeof token.lineNumber === 'number') {2807error = new Error('Line ' + token.lineNumber + ': ' + msg);2808error.index = token.range[0];2809error.lineNumber = token.lineNumber;2810error.column = token.range[0] - lineStart + 1;2811} else {2812error = new Error('Line ' + lineNumber + ': ' + msg);2813error.index = index;2814error.lineNumber = lineNumber;2815error.column = index - lineStart + 1;2816}28172818error.description = msg;2819throw error;2820}28212822function throwErrorTolerant() {2823try {2824throwError.apply(null, arguments);2825} catch (e) {2826if (extra.errors) {2827extra.errors.push(e);2828} else {2829throw e;2830}2831}2832}283328342835// Throw an exception because of the token.28362837function throwUnexpected(token) {2838if (token.type === Token.EOF) {2839throwError(token, Messages.UnexpectedEOS);2840}28412842if (token.type === Token.NumericLiteral) {2843throwError(token, Messages.UnexpectedNumber);2844}28452846if (token.type === Token.StringLiteral || token.type === Token.JSXText) {2847throwError(token, Messages.UnexpectedString);2848}28492850if (token.type === Token.Identifier) {2851throwError(token, Messages.UnexpectedIdentifier);2852}28532854if (token.type === Token.Keyword) {2855if (isFutureReservedWord(token.value)) {2856throwError(token, Messages.UnexpectedReserved);2857} else if (strict && isStrictModeReservedWord(token.value)) {2858throwErrorTolerant(token, Messages.StrictReservedWord);2859return;2860}2861throwError(token, Messages.UnexpectedToken, token.value);2862}28632864if (token.type === Token.Template) {2865throwError(token, Messages.UnexpectedTemplate, token.value.raw);2866}28672868// BooleanLiteral, NullLiteral, or Punctuator.2869throwError(token, Messages.UnexpectedToken, token.value);2870}28712872// Expect the next token to match the specified punctuator.2873// If not, an exception will be thrown.28742875function expect(value) {2876var token = lex();2877if (token.type !== Token.Punctuator || token.value !== value) {2878throwUnexpected(token);2879}2880}28812882// Expect the next token to match the specified keyword.2883// If not, an exception will be thrown.28842885function expectKeyword(keyword, contextual) {2886var token = lex();2887if (token.type !== (contextual ? Token.Identifier : Token.Keyword) ||2888token.value !== keyword) {2889throwUnexpected(token);2890}2891}28922893// Expect the next token to match the specified contextual keyword.2894// If not, an exception will be thrown.28952896function expectContextualKeyword(keyword) {2897return expectKeyword(keyword, true);2898}28992900// Return true if the next token matches the specified punctuator.29012902function match(value) {2903return lookahead.type === Token.Punctuator && lookahead.value === value;2904}29052906// Return true if the next token matches the specified keyword29072908function matchKeyword(keyword, contextual) {2909var expectedType = contextual ? Token.Identifier : Token.Keyword;2910return lookahead.type === expectedType && lookahead.value === keyword;2911}29122913// Return true if the next token matches the specified contextual keyword29142915function matchContextualKeyword(keyword) {2916return matchKeyword(keyword, true);2917}29182919// Return true if the next token is an assignment operator29202921function matchAssign() {2922var op;29232924if (lookahead.type !== Token.Punctuator) {2925return false;2926}2927op = lookahead.value;2928return op === '=' ||2929op === '*=' ||2930op === '/=' ||2931op === '%=' ||2932op === '+=' ||2933op === '-=' ||2934op === '<<=' ||2935op === '>>=' ||2936op === '>>>=' ||2937op === '&=' ||2938op === '^=' ||2939op === '|=';2940}29412942// Note that 'yield' is treated as a keyword in strict mode, but a2943// contextual keyword (identifier) in non-strict mode, so we need to2944// use matchKeyword('yield', false) and matchKeyword('yield', true)2945// (i.e. matchContextualKeyword) appropriately.2946function matchYield() {2947return state.yieldAllowed && matchKeyword('yield', !strict);2948}29492950function matchAsync() {2951var backtrackToken = lookahead, matches = false;29522953if (matchContextualKeyword('async')) {2954lex(); // Make sure peekLineTerminator() starts after 'async'.2955matches = !peekLineTerminator();2956rewind(backtrackToken); // Revert the lex().2957}29582959return matches;2960}29612962function matchAwait() {2963return state.awaitAllowed && matchContextualKeyword('await');2964}29652966function consumeSemicolon() {2967var line, oldIndex = index, oldLineNumber = lineNumber,2968oldLineStart = lineStart, oldLookahead = lookahead;29692970// Catch the very common case first: immediately a semicolon (char #59).2971if (source.charCodeAt(index) === 59) {2972lex();2973return;2974}29752976line = lineNumber;2977skipComment();2978if (lineNumber !== line) {2979index = oldIndex;2980lineNumber = oldLineNumber;2981lineStart = oldLineStart;2982lookahead = oldLookahead;2983return;2984}29852986if (match(';')) {2987lex();2988return;2989}29902991if (lookahead.type !== Token.EOF && !match('}')) {2992throwUnexpected(lookahead);2993}2994}29952996// Return true if provided expression is LeftHandSideExpression29972998function isLeftHandSide(expr) {2999return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;3000}30013002function isAssignableLeftHandSide(expr) {3003return isLeftHandSide(expr) || expr.type === Syntax.ObjectPattern || expr.type === Syntax.ArrayPattern;3004}30053006// 11.1.4 Array Initialiser30073008function parseArrayInitialiser() {3009var elements = [], blocks = [], filter = null, tmp, possiblecomprehension = true,3010marker = markerCreate();30113012expect('[');3013while (!match(']')) {3014if (lookahead.value === 'for' &&3015lookahead.type === Token.Keyword) {3016if (!possiblecomprehension) {3017throwError({}, Messages.ComprehensionError);3018}3019matchKeyword('for');3020tmp = parseForStatement({ignoreBody: true});3021tmp.of = tmp.type === Syntax.ForOfStatement;3022tmp.type = Syntax.ComprehensionBlock;3023if (tmp.left.kind) { // can't be let or const3024throwError({}, Messages.ComprehensionError);3025}3026blocks.push(tmp);3027} else if (lookahead.value === 'if' &&3028lookahead.type === Token.Keyword) {3029if (!possiblecomprehension) {3030throwError({}, Messages.ComprehensionError);3031}3032expectKeyword('if');3033expect('(');3034filter = parseExpression();3035expect(')');3036} else if (lookahead.value === ',' &&3037lookahead.type === Token.Punctuator) {3038possiblecomprehension = false; // no longer allowed.3039lex();3040elements.push(null);3041} else {3042tmp = parseSpreadOrAssignmentExpression();3043elements.push(tmp);3044if (tmp && tmp.type === Syntax.SpreadElement) {3045if (!match(']')) {3046throwError({}, Messages.ElementAfterSpreadElement);3047}3048} else if (!(match(']') || matchKeyword('for') || matchKeyword('if'))) {3049expect(','); // this lexes.3050possiblecomprehension = false;3051}3052}3053}30543055expect(']');30563057if (filter && !blocks.length) {3058throwError({}, Messages.ComprehensionRequiresBlock);3059}30603061if (blocks.length) {3062if (elements.length !== 1) {3063throwError({}, Messages.ComprehensionError);3064}3065return markerApply(marker, delegate.createComprehensionExpression(filter, blocks, elements[0]));3066}3067return markerApply(marker, delegate.createArrayExpression(elements));3068}30693070// 11.1.5 Object Initialiser30713072function parsePropertyFunction(options) {3073var previousStrict, previousYieldAllowed, previousAwaitAllowed,3074params, defaults, body, marker = markerCreate();30753076previousStrict = strict;3077previousYieldAllowed = state.yieldAllowed;3078state.yieldAllowed = options.generator;3079previousAwaitAllowed = state.awaitAllowed;3080state.awaitAllowed = options.async;3081params = options.params || [];3082defaults = options.defaults || [];30833084body = parseConciseBody();3085if (options.name && strict && isRestrictedWord(params[0].name)) {3086throwErrorTolerant(options.name, Messages.StrictParamName);3087}3088strict = previousStrict;3089state.yieldAllowed = previousYieldAllowed;3090state.awaitAllowed = previousAwaitAllowed;30913092return markerApply(marker, delegate.createFunctionExpression(3093null,3094params,3095defaults,3096body,3097options.rest || null,3098options.generator,3099body.type !== Syntax.BlockStatement,3100options.async,3101options.returnType,3102options.typeParameters3103));3104}310531063107function parsePropertyMethodFunction(options) {3108var previousStrict, tmp, method;31093110previousStrict = strict;3111strict = true;31123113tmp = parseParams();31143115if (tmp.stricted) {3116throwErrorTolerant(tmp.stricted, tmp.message);3117}31183119method = parsePropertyFunction({3120params: tmp.params,3121defaults: tmp.defaults,3122rest: tmp.rest,3123generator: options.generator,3124async: options.async,3125returnType: tmp.returnType,3126typeParameters: options.typeParameters3127});31283129strict = previousStrict;31303131return method;3132}313331343135function parseObjectPropertyKey() {3136var marker = markerCreate(),3137token = lex(),3138propertyKey,3139result;31403141// Note: This function is called only from parseObjectProperty(), where3142// EOF and Punctuator tokens are already filtered out.31433144if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) {3145if (strict && token.octal) {3146throwErrorTolerant(token, Messages.StrictOctalLiteral);3147}3148return markerApply(marker, delegate.createLiteral(token));3149}31503151if (token.type === Token.Punctuator && token.value === '[') {3152// For computed properties we should skip the [ and ], and3153// capture in marker only the assignment expression itself.3154marker = markerCreate();3155propertyKey = parseAssignmentExpression();3156result = markerApply(marker, propertyKey);3157expect(']');3158return result;3159}31603161return markerApply(marker, delegate.createIdentifier(token.value));3162}31633164function parseObjectProperty() {3165var token, key, id, param, computed,3166marker = markerCreate(), returnType, typeParameters;31673168token = lookahead;3169computed = (token.value === '[' && token.type === Token.Punctuator);31703171if (token.type === Token.Identifier || computed || matchAsync()) {3172id = parseObjectPropertyKey();31733174if (match(':')) {3175lex();31763177return markerApply(3178marker,3179delegate.createProperty(3180'init',3181id,3182parseAssignmentExpression(),3183false,3184false,3185computed3186)3187);3188}31893190if (match('(') || match('<')) {3191if (match('<')) {3192typeParameters = parseTypeParameterDeclaration();3193}3194return markerApply(3195marker,3196delegate.createProperty(3197'init',3198id,3199parsePropertyMethodFunction({3200generator: false,3201async: false,3202typeParameters: typeParameters3203}),3204true,3205false,3206computed3207)3208);3209}32103211// Property Assignment: Getter and Setter.32123213if (token.value === 'get') {3214computed = (lookahead.value === '[');3215key = parseObjectPropertyKey();32163217expect('(');3218expect(')');3219if (match(':')) {3220returnType = parseTypeAnnotation();3221}32223223return markerApply(3224marker,3225delegate.createProperty(3226'get',3227key,3228parsePropertyFunction({3229generator: false,3230async: false,3231returnType: returnType3232}),3233false,3234false,3235computed3236)3237);3238}32393240if (token.value === 'set') {3241computed = (lookahead.value === '[');3242key = parseObjectPropertyKey();32433244expect('(');3245token = lookahead;3246param = [ parseTypeAnnotatableIdentifier() ];3247expect(')');3248if (match(':')) {3249returnType = parseTypeAnnotation();3250}32513252return markerApply(3253marker,3254delegate.createProperty(3255'set',3256key,3257parsePropertyFunction({3258params: param,3259generator: false,3260async: false,3261name: token,3262returnType: returnType3263}),3264false,3265false,3266computed3267)3268);3269}32703271if (token.value === 'async') {3272computed = (lookahead.value === '[');3273key = parseObjectPropertyKey();32743275if (match('<')) {3276typeParameters = parseTypeParameterDeclaration();3277}32783279return markerApply(3280marker,3281delegate.createProperty(3282'init',3283key,3284parsePropertyMethodFunction({3285generator: false,3286async: true,3287typeParameters: typeParameters3288}),3289true,3290false,3291computed3292)3293);3294}32953296if (computed) {3297// Computed properties can only be used with full notation.3298throwUnexpected(lookahead);3299}33003301return markerApply(3302marker,3303delegate.createProperty('init', id, id, false, true, false)3304);3305}33063307if (token.type === Token.EOF || token.type === Token.Punctuator) {3308if (!match('*')) {3309throwUnexpected(token);3310}3311lex();33123313computed = (lookahead.type === Token.Punctuator && lookahead.value === '[');33143315id = parseObjectPropertyKey();33163317if (match('<')) {3318typeParameters = parseTypeParameterDeclaration();3319}33203321if (!match('(')) {3322throwUnexpected(lex());3323}33243325return markerApply(marker, delegate.createProperty(3326'init',3327id,3328parsePropertyMethodFunction({3329generator: true,3330typeParameters: typeParameters3331}),3332true,3333false,3334computed3335));3336}3337key = parseObjectPropertyKey();3338if (match(':')) {3339lex();3340return markerApply(marker, delegate.createProperty('init', key, parseAssignmentExpression(), false, false, false));3341}3342if (match('(') || match('<')) {3343if (match('<')) {3344typeParameters = parseTypeParameterDeclaration();3345}3346return markerApply(marker, delegate.createProperty(3347'init',3348key,3349parsePropertyMethodFunction({3350generator: false,3351typeParameters: typeParameters3352}),3353true,3354false,3355false3356));3357}3358throwUnexpected(lex());3359}33603361function parseObjectSpreadProperty() {3362var marker = markerCreate();3363expect('...');3364return markerApply(marker, delegate.createSpreadProperty(parseAssignmentExpression()));3365}33663367function getFieldName(key) {3368var toString = String;3369if (key.type === Syntax.Identifier) {3370return key.name;3371}3372return toString(key.value);3373}33743375function parseObjectInitialiser() {3376var properties = [], property, name, kind, storedKind, map = new StringMap(),3377marker = markerCreate(), toString = String;33783379expect('{');33803381while (!match('}')) {3382if (match('...')) {3383property = parseObjectSpreadProperty();3384} else {3385property = parseObjectProperty();33863387if (property.key.type === Syntax.Identifier) {3388name = property.key.name;3389} else {3390name = toString(property.key.value);3391}3392kind = (property.kind === 'init') ? PropertyKind.Data : (property.kind === 'get') ? PropertyKind.Get : PropertyKind.Set;33933394if (map.has(name)) {3395storedKind = map.get(name);3396if (storedKind === PropertyKind.Data) {3397if (strict && kind === PropertyKind.Data) {3398throwErrorTolerant({}, Messages.StrictDuplicateProperty);3399} else if (kind !== PropertyKind.Data) {3400throwErrorTolerant({}, Messages.AccessorDataProperty);3401}3402} else {3403if (kind === PropertyKind.Data) {3404throwErrorTolerant({}, Messages.AccessorDataProperty);3405} else if (storedKind & kind) {3406throwErrorTolerant({}, Messages.AccessorGetSet);3407}3408}3409map.set(name, storedKind | kind);3410} else {3411map.set(name, kind);3412}3413}34143415properties.push(property);34163417if (!match('}')) {3418expect(',');3419}3420}34213422expect('}');34233424return markerApply(marker, delegate.createObjectExpression(properties));3425}34263427function parseTemplateElement(option) {3428var marker = markerCreate(),3429token = scanTemplateElement(option);3430if (strict && token.octal) {3431throwError(token, Messages.StrictOctalLiteral);3432}3433return markerApply(marker, delegate.createTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail));3434}34353436function parseTemplateLiteral() {3437var quasi, quasis, expressions, marker = markerCreate();34383439quasi = parseTemplateElement({ head: true });3440quasis = [ quasi ];3441expressions = [];34423443while (!quasi.tail) {3444expressions.push(parseExpression());3445quasi = parseTemplateElement({ head: false });3446quasis.push(quasi);3447}34483449return markerApply(marker, delegate.createTemplateLiteral(quasis, expressions));3450}34513452// 11.1.6 The Grouping Operator34533454function parseGroupExpression() {3455var expr, marker, typeAnnotation;34563457expect('(');34583459++state.parenthesizedCount;34603461marker = markerCreate();34623463expr = parseExpression();34643465if (match(':')) {3466typeAnnotation = parseTypeAnnotation();3467expr = markerApply(marker, delegate.createTypeCast(3468expr,3469typeAnnotation3470));3471}34723473expect(')');34743475return expr;3476}34773478function matchAsyncFuncExprOrDecl() {3479var token;34803481if (matchAsync()) {3482token = lookahead2();3483if (token.type === Token.Keyword && token.value === 'function') {3484return true;3485}3486}34873488return false;3489}34903491// 11.1 Primary Expressions34923493function parsePrimaryExpression() {3494var marker, type, token, expr;34953496type = lookahead.type;34973498if (type === Token.Identifier) {3499marker = markerCreate();3500return markerApply(marker, delegate.createIdentifier(lex().value));3501}35023503if (type === Token.StringLiteral || type === Token.NumericLiteral) {3504if (strict && lookahead.octal) {3505throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);3506}3507marker = markerCreate();3508return markerApply(marker, delegate.createLiteral(lex()));3509}35103511if (type === Token.Keyword) {3512if (matchKeyword('this')) {3513marker = markerCreate();3514lex();3515return markerApply(marker, delegate.createThisExpression());3516}35173518if (matchKeyword('function')) {3519return parseFunctionExpression();3520}35213522if (matchKeyword('class')) {3523return parseClassExpression();3524}35253526if (matchKeyword('super')) {3527marker = markerCreate();3528lex();3529return markerApply(marker, delegate.createIdentifier('super'));3530}3531}35323533if (type === Token.BooleanLiteral) {3534marker = markerCreate();3535token = lex();3536token.value = (token.value === 'true');3537return markerApply(marker, delegate.createLiteral(token));3538}35393540if (type === Token.NullLiteral) {3541marker = markerCreate();3542token = lex();3543token.value = null;3544return markerApply(marker, delegate.createLiteral(token));3545}35463547if (match('[')) {3548return parseArrayInitialiser();3549}35503551if (match('{')) {3552return parseObjectInitialiser();3553}35543555if (match('(')) {3556return parseGroupExpression();3557}35583559if (match('/') || match('/=')) {3560marker = markerCreate();3561expr = delegate.createLiteral(scanRegExp());3562peek();3563return markerApply(marker, expr);3564}35653566if (type === Token.Template) {3567return parseTemplateLiteral();3568}35693570if (match('<')) {3571return parseJSXElement();3572}35733574throwUnexpected(lex());3575}35763577// 11.2 Left-Hand-Side Expressions35783579function parseArguments() {3580var args = [], arg;35813582expect('(');35833584if (!match(')')) {3585while (index < length) {3586arg = parseSpreadOrAssignmentExpression();3587args.push(arg);35883589if (match(')')) {3590break;3591} else if (arg.type === Syntax.SpreadElement) {3592throwError({}, Messages.ElementAfterSpreadElement);3593}35943595expect(',');3596}3597}35983599expect(')');36003601return args;3602}36033604function parseSpreadOrAssignmentExpression() {3605if (match('...')) {3606var marker = markerCreate();3607lex();3608return markerApply(marker, delegate.createSpreadElement(parseAssignmentExpression()));3609}3610return parseAssignmentExpression();3611}36123613function parseNonComputedProperty() {3614var marker = markerCreate(),3615token = lex();36163617if (!isIdentifierName(token)) {3618throwUnexpected(token);3619}36203621return markerApply(marker, delegate.createIdentifier(token.value));3622}36233624function parseNonComputedMember() {3625expect('.');36263627return parseNonComputedProperty();3628}36293630function parseComputedMember() {3631var expr;36323633expect('[');36343635expr = parseExpression();36363637expect(']');36383639return expr;3640}36413642function parseNewExpression() {3643var callee, args, marker = markerCreate();36443645expectKeyword('new');3646callee = parseLeftHandSideExpression();3647args = match('(') ? parseArguments() : [];36483649return markerApply(marker, delegate.createNewExpression(callee, args));3650}36513652function parseLeftHandSideExpressionAllowCall() {3653var expr, args, marker = markerCreate();36543655expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();36563657while (match('.') || match('[') || match('(') || lookahead.type === Token.Template) {3658if (match('(')) {3659args = parseArguments();3660expr = markerApply(marker, delegate.createCallExpression(expr, args));3661} else if (match('[')) {3662expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));3663} else if (match('.')) {3664expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));3665} else {3666expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));3667}3668}36693670return expr;3671}36723673function parseLeftHandSideExpression() {3674var expr, marker = markerCreate();36753676expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();36773678while (match('.') || match('[') || lookahead.type === Token.Template) {3679if (match('[')) {3680expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));3681} else if (match('.')) {3682expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));3683} else {3684expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));3685}3686}36873688return expr;3689}36903691// 11.3 Postfix Expressions36923693function parsePostfixExpression() {3694var marker = markerCreate(),3695expr = parseLeftHandSideExpressionAllowCall(),3696token;36973698if (lookahead.type !== Token.Punctuator) {3699return expr;3700}37013702if ((match('++') || match('--')) && !peekLineTerminator()) {3703// 11.3.1, 11.3.23704if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3705throwErrorTolerant({}, Messages.StrictLHSPostfix);3706}37073708if (!isLeftHandSide(expr)) {3709throwError({}, Messages.InvalidLHSInAssignment);3710}37113712token = lex();3713expr = markerApply(marker, delegate.createPostfixExpression(token.value, expr));3714}37153716return expr;3717}37183719// 11.4 Unary Operators37203721function parseUnaryExpression() {3722var marker, token, expr;37233724if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {3725return parsePostfixExpression();3726}37273728if (match('++') || match('--')) {3729marker = markerCreate();3730token = lex();3731expr = parseUnaryExpression();3732// 11.4.4, 11.4.53733if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {3734throwErrorTolerant({}, Messages.StrictLHSPrefix);3735}37363737if (!isLeftHandSide(expr)) {3738throwError({}, Messages.InvalidLHSInAssignment);3739}37403741return markerApply(marker, delegate.createUnaryExpression(token.value, expr));3742}37433744if (match('+') || match('-') || match('~') || match('!')) {3745marker = markerCreate();3746token = lex();3747expr = parseUnaryExpression();3748return markerApply(marker, delegate.createUnaryExpression(token.value, expr));3749}37503751if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {3752marker = markerCreate();3753token = lex();3754expr = parseUnaryExpression();3755expr = markerApply(marker, delegate.createUnaryExpression(token.value, expr));3756if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {3757throwErrorTolerant({}, Messages.StrictDelete);3758}3759return expr;3760}37613762return parsePostfixExpression();3763}37643765function binaryPrecedence(token, allowIn) {3766var prec = 0;37673768if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {3769return 0;3770}37713772switch (token.value) {3773case '||':3774prec = 1;3775break;37763777case '&&':3778prec = 2;3779break;37803781case '|':3782prec = 3;3783break;37843785case '^':3786prec = 4;3787break;37883789case '&':3790prec = 5;3791break;37923793case '==':3794case '!=':3795case '===':3796case '!==':3797prec = 6;3798break;37993800case '<':3801case '>':3802case '<=':3803case '>=':3804case 'instanceof':3805prec = 7;3806break;38073808case 'in':3809prec = allowIn ? 7 : 0;3810break;38113812case '<<':3813case '>>':3814case '>>>':3815prec = 8;3816break;38173818case '+':3819case '-':3820prec = 9;3821break;38223823case '*':3824case '/':3825case '%':3826prec = 11;3827break;38283829default:3830break;3831}38323833return prec;3834}38353836// 11.5 Multiplicative Operators3837// 11.6 Additive Operators3838// 11.7 Bitwise Shift Operators3839// 11.8 Relational Operators3840// 11.9 Equality Operators3841// 11.10 Binary Bitwise Operators3842// 11.11 Binary Logical Operators38433844function parseBinaryExpression() {3845var expr, token, prec, previousAllowIn, stack, right, operator, left, i,3846marker, markers;38473848previousAllowIn = state.allowIn;3849state.allowIn = true;38503851marker = markerCreate();3852left = parseUnaryExpression();38533854token = lookahead;3855prec = binaryPrecedence(token, previousAllowIn);3856if (prec === 0) {3857return left;3858}3859token.prec = prec;3860lex();38613862markers = [marker, markerCreate()];3863right = parseUnaryExpression();38643865stack = [left, token, right];38663867while ((prec = binaryPrecedence(lookahead, previousAllowIn)) > 0) {38683869// Reduce: make a binary expression from the three topmost entries.3870while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {3871right = stack.pop();3872operator = stack.pop().value;3873left = stack.pop();3874expr = delegate.createBinaryExpression(operator, left, right);3875markers.pop();3876marker = markers.pop();3877markerApply(marker, expr);3878stack.push(expr);3879markers.push(marker);3880}38813882// Shift.3883token = lex();3884token.prec = prec;3885stack.push(token);3886markers.push(markerCreate());3887expr = parseUnaryExpression();3888stack.push(expr);3889}38903891state.allowIn = previousAllowIn;38923893// Final reduce to clean-up the stack.3894i = stack.length - 1;3895expr = stack[i];3896markers.pop();3897while (i > 1) {3898expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);3899i -= 2;3900marker = markers.pop();3901markerApply(marker, expr);3902}39033904return expr;3905}390639073908// 11.12 Conditional Operator39093910function parseConditionalExpression() {3911var expr, previousAllowIn, consequent, alternate, marker = markerCreate();3912expr = parseBinaryExpression();39133914if (match('?')) {3915lex();3916previousAllowIn = state.allowIn;3917state.allowIn = true;3918consequent = parseAssignmentExpression();3919state.allowIn = previousAllowIn;3920expect(':');3921alternate = parseAssignmentExpression();39223923expr = markerApply(marker, delegate.createConditionalExpression(expr, consequent, alternate));3924}39253926return expr;3927}39283929// 11.13 Assignment Operators39303931// 12.14.5 AssignmentPattern39323933function reinterpretAsAssignmentBindingPattern(expr) {3934var i, len, property, element;39353936if (expr.type === Syntax.ObjectExpression) {3937expr.type = Syntax.ObjectPattern;3938for (i = 0, len = expr.properties.length; i < len; i += 1) {3939property = expr.properties[i];3940if (property.type === Syntax.SpreadProperty) {3941if (i < len - 1) {3942throwError({}, Messages.PropertyAfterSpreadProperty);3943}3944reinterpretAsAssignmentBindingPattern(property.argument);3945} else {3946if (property.kind !== 'init') {3947throwError({}, Messages.InvalidLHSInAssignment);3948}3949reinterpretAsAssignmentBindingPattern(property.value);3950}3951}3952} else if (expr.type === Syntax.ArrayExpression) {3953expr.type = Syntax.ArrayPattern;3954for (i = 0, len = expr.elements.length; i < len; i += 1) {3955element = expr.elements[i];3956/* istanbul ignore else */3957if (element) {3958reinterpretAsAssignmentBindingPattern(element);3959}3960}3961} else if (expr.type === Syntax.Identifier) {3962if (isRestrictedWord(expr.name)) {3963throwError({}, Messages.InvalidLHSInAssignment);3964}3965} else if (expr.type === Syntax.SpreadElement) {3966reinterpretAsAssignmentBindingPattern(expr.argument);3967if (expr.argument.type === Syntax.ObjectPattern) {3968throwError({}, Messages.ObjectPatternAsSpread);3969}3970} else {3971/* istanbul ignore else */3972if (expr.type !== Syntax.MemberExpression && expr.type !== Syntax.CallExpression && expr.type !== Syntax.NewExpression) {3973throwError({}, Messages.InvalidLHSInAssignment);3974}3975}3976}39773978// 13.2.3 BindingPattern39793980function reinterpretAsDestructuredParameter(options, expr) {3981var i, len, property, element;39823983if (expr.type === Syntax.ObjectExpression) {3984expr.type = Syntax.ObjectPattern;3985for (i = 0, len = expr.properties.length; i < len; i += 1) {3986property = expr.properties[i];3987if (property.type === Syntax.SpreadProperty) {3988if (i < len - 1) {3989throwError({}, Messages.PropertyAfterSpreadProperty);3990}3991reinterpretAsDestructuredParameter(options, property.argument);3992} else {3993if (property.kind !== 'init') {3994throwError({}, Messages.InvalidLHSInFormalsList);3995}3996reinterpretAsDestructuredParameter(options, property.value);3997}3998}3999} else if (expr.type === Syntax.ArrayExpression) {4000expr.type = Syntax.ArrayPattern;4001for (i = 0, len = expr.elements.length; i < len; i += 1) {4002element = expr.elements[i];4003if (element) {4004reinterpretAsDestructuredParameter(options, element);4005}4006}4007} else if (expr.type === Syntax.Identifier) {4008validateParam(options, expr, expr.name);4009} else if (expr.type === Syntax.SpreadElement) {4010// BindingRestElement only allows BindingIdentifier4011if (expr.argument.type !== Syntax.Identifier) {4012throwError({}, Messages.InvalidLHSInFormalsList);4013}4014validateParam(options, expr.argument, expr.argument.name);4015} else {4016throwError({}, Messages.InvalidLHSInFormalsList);4017}4018}40194020function reinterpretAsCoverFormalsList(expressions) {4021var i, len, param, params, defaults, defaultCount, options, rest;40224023params = [];4024defaults = [];4025defaultCount = 0;4026rest = null;4027options = {4028paramSet: new StringMap()4029};40304031for (i = 0, len = expressions.length; i < len; i += 1) {4032param = expressions[i];4033if (param.type === Syntax.Identifier) {4034params.push(param);4035defaults.push(null);4036validateParam(options, param, param.name);4037} else if (param.type === Syntax.ObjectExpression || param.type === Syntax.ArrayExpression) {4038reinterpretAsDestructuredParameter(options, param);4039params.push(param);4040defaults.push(null);4041} else if (param.type === Syntax.SpreadElement) {4042assert(i === len - 1, 'It is guaranteed that SpreadElement is last element by parseExpression');4043if (param.argument.type !== Syntax.Identifier) {4044throwError({}, Messages.InvalidLHSInFormalsList);4045}4046reinterpretAsDestructuredParameter(options, param.argument);4047rest = param.argument;4048} else if (param.type === Syntax.AssignmentExpression) {4049params.push(param.left);4050defaults.push(param.right);4051++defaultCount;4052validateParam(options, param.left, param.left.name);4053} else {4054return null;4055}4056}40574058if (options.message === Messages.StrictParamDupe) {4059throwError(4060strict ? options.stricted : options.firstRestricted,4061options.message4062);4063}40644065if (defaultCount === 0) {4066defaults = [];4067}40684069return {4070params: params,4071defaults: defaults,4072rest: rest,4073stricted: options.stricted,4074firstRestricted: options.firstRestricted,4075message: options.message4076};4077}40784079function parseArrowFunctionExpression(options, marker) {4080var previousStrict, previousYieldAllowed, previousAwaitAllowed, body;40814082expect('=>');40834084previousStrict = strict;4085previousYieldAllowed = state.yieldAllowed;4086state.yieldAllowed = false;4087previousAwaitAllowed = state.awaitAllowed;4088state.awaitAllowed = !!options.async;4089body = parseConciseBody();40904091if (strict && options.firstRestricted) {4092throwError(options.firstRestricted, options.message);4093}4094if (strict && options.stricted) {4095throwErrorTolerant(options.stricted, options.message);4096}40974098strict = previousStrict;4099state.yieldAllowed = previousYieldAllowed;4100state.awaitAllowed = previousAwaitAllowed;41014102return markerApply(marker, delegate.createArrowFunctionExpression(4103options.params,4104options.defaults,4105body,4106options.rest,4107body.type !== Syntax.BlockStatement,4108!!options.async4109));4110}41114112function parseAssignmentExpression() {4113var marker, expr, token, params, oldParenthesizedCount,4114startsWithParen = false, backtrackToken = lookahead,4115possiblyAsync = false;41164117if (matchYield()) {4118return parseYieldExpression();4119}41204121if (matchAwait()) {4122return parseAwaitExpression();4123}41244125oldParenthesizedCount = state.parenthesizedCount;41264127marker = markerCreate();41284129if (matchAsyncFuncExprOrDecl()) {4130return parseFunctionExpression();4131}41324133if (matchAsync()) {4134// We can't be completely sure that this 'async' token is4135// actually a contextual keyword modifying a function4136// expression, so we might have to un-lex() it later by4137// calling rewind(backtrackToken).4138possiblyAsync = true;4139lex();4140}41414142if (match('(')) {4143token = lookahead2();4144if ((token.type === Token.Punctuator && token.value === ')') || token.value === '...') {4145params = parseParams();4146if (!match('=>')) {4147throwUnexpected(lex());4148}4149params.async = possiblyAsync;4150return parseArrowFunctionExpression(params, marker);4151}4152startsWithParen = true;4153}41544155token = lookahead;41564157// If the 'async' keyword is not followed by a '(' character or an4158// identifier, then it can't be an arrow function modifier, and we4159// should interpret it as a normal identifer.4160if (possiblyAsync && !match('(') && token.type !== Token.Identifier) {4161possiblyAsync = false;4162rewind(backtrackToken);4163}41644165expr = parseConditionalExpression();41664167if (match('=>') &&4168(state.parenthesizedCount === oldParenthesizedCount ||4169state.parenthesizedCount === (oldParenthesizedCount + 1))) {4170if (expr.type === Syntax.Identifier) {4171params = reinterpretAsCoverFormalsList([ expr ]);4172} else if (expr.type === Syntax.AssignmentExpression ||4173expr.type === Syntax.ArrayExpression ||4174expr.type === Syntax.ObjectExpression) {4175if (!startsWithParen) {4176throwUnexpected(lex());4177}4178params = reinterpretAsCoverFormalsList([ expr ]);4179} else if (expr.type === Syntax.SequenceExpression) {4180params = reinterpretAsCoverFormalsList(expr.expressions);4181}4182if (params) {4183params.async = possiblyAsync;4184return parseArrowFunctionExpression(params, marker);4185}4186}41874188// If we haven't returned by now, then the 'async' keyword was not4189// a function modifier, and we should rewind and interpret it as a4190// normal identifier.4191if (possiblyAsync) {4192possiblyAsync = false;4193rewind(backtrackToken);4194expr = parseConditionalExpression();4195}41964197if (matchAssign()) {4198// 11.13.14199if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {4200throwErrorTolerant(token, Messages.StrictLHSAssignment);4201}42024203// ES.next draf 11.13 Runtime Semantics step 14204if (match('=') && (expr.type === Syntax.ObjectExpression || expr.type === Syntax.ArrayExpression)) {4205reinterpretAsAssignmentBindingPattern(expr);4206} else if (!isLeftHandSide(expr)) {4207throwError({}, Messages.InvalidLHSInAssignment);4208}42094210expr = markerApply(marker, delegate.createAssignmentExpression(lex().value, expr, parseAssignmentExpression()));4211}42124213return expr;4214}42154216// 11.14 Comma Operator42174218function parseExpression() {4219var marker, expr, expressions, sequence, spreadFound;42204221marker = markerCreate();4222expr = parseAssignmentExpression();4223expressions = [ expr ];42244225if (match(',')) {4226while (index < length) {4227if (!match(',')) {4228break;4229}42304231lex();4232expr = parseSpreadOrAssignmentExpression();4233expressions.push(expr);42344235if (expr.type === Syntax.SpreadElement) {4236spreadFound = true;4237if (!match(')')) {4238throwError({}, Messages.ElementAfterSpreadElement);4239}4240break;4241}4242}42434244sequence = markerApply(marker, delegate.createSequenceExpression(expressions));4245}42464247if (spreadFound && lookahead2().value !== '=>') {4248throwError({}, Messages.IllegalSpread);4249}42504251return sequence || expr;4252}42534254// 12.1 Block42554256function parseStatementList() {4257var list = [],4258statement;42594260while (index < length) {4261if (match('}')) {4262break;4263}4264statement = parseSourceElement();4265if (typeof statement === 'undefined') {4266break;4267}4268list.push(statement);4269}42704271return list;4272}42734274function parseBlock() {4275var block, marker = markerCreate();42764277expect('{');42784279block = parseStatementList();42804281expect('}');42824283return markerApply(marker, delegate.createBlockStatement(block));4284}42854286// 12.2 Variable Statement42874288function parseTypeParameterDeclaration() {4289var marker = markerCreate(), paramTypes = [];42904291expect('<');4292while (!match('>')) {4293paramTypes.push(parseTypeAnnotatableIdentifier());4294if (!match('>')) {4295expect(',');4296}4297}4298expect('>');42994300return markerApply(marker, delegate.createTypeParameterDeclaration(4301paramTypes4302));4303}43044305function parseTypeParameterInstantiation() {4306var marker = markerCreate(), oldInType = state.inType, paramTypes = [];43074308state.inType = true;43094310expect('<');4311while (!match('>')) {4312paramTypes.push(parseType());4313if (!match('>')) {4314expect(',');4315}4316}4317expect('>');43184319state.inType = oldInType;43204321return markerApply(marker, delegate.createTypeParameterInstantiation(4322paramTypes4323));4324}43254326function parseObjectTypeIndexer(marker, isStatic) {4327var id, key, value;43284329expect('[');4330id = parseObjectPropertyKey();4331expect(':');4332key = parseType();4333expect(']');4334expect(':');4335value = parseType();43364337return markerApply(marker, delegate.createObjectTypeIndexer(4338id,4339key,4340value,4341isStatic4342));4343}43444345function parseObjectTypeMethodish(marker) {4346var params = [], rest = null, returnType, typeParameters = null;4347if (match('<')) {4348typeParameters = parseTypeParameterDeclaration();4349}43504351expect('(');4352while (lookahead.type === Token.Identifier) {4353params.push(parseFunctionTypeParam());4354if (!match(')')) {4355expect(',');4356}4357}43584359if (match('...')) {4360lex();4361rest = parseFunctionTypeParam();4362}4363expect(')');4364expect(':');4365returnType = parseType();43664367return markerApply(marker, delegate.createFunctionTypeAnnotation(4368params,4369returnType,4370rest,4371typeParameters4372));4373}43744375function parseObjectTypeMethod(marker, isStatic, key) {4376var optional = false, value;4377value = parseObjectTypeMethodish(marker);43784379return markerApply(marker, delegate.createObjectTypeProperty(4380key,4381value,4382optional,4383isStatic4384));4385}43864387function parseObjectTypeCallProperty(marker, isStatic) {4388var valueMarker = markerCreate();4389return markerApply(marker, delegate.createObjectTypeCallProperty(4390parseObjectTypeMethodish(valueMarker),4391isStatic4392));4393}43944395function parseObjectType(allowStatic) {4396var callProperties = [], indexers = [], marker, optional = false,4397properties = [], propertyKey, propertyTypeAnnotation,4398token, isStatic, matchStatic;43994400expect('{');44014402while (!match('}')) {4403marker = markerCreate();4404matchStatic =4405strict4406? matchKeyword('static')4407: matchContextualKeyword('static');44084409if (allowStatic && matchStatic) {4410token = lex();4411isStatic = true;4412}44134414if (match('[')) {4415indexers.push(parseObjectTypeIndexer(marker, isStatic));4416} else if (match('(') || match('<')) {4417callProperties.push(parseObjectTypeCallProperty(marker, allowStatic));4418} else {4419if (isStatic && match(':')) {4420propertyKey = markerApply(marker, delegate.createIdentifier(token));4421throwErrorTolerant(token, Messages.StrictReservedWord);4422} else {4423propertyKey = parseObjectPropertyKey();4424}4425if (match('<') || match('(')) {4426// This is a method property4427properties.push(parseObjectTypeMethod(marker, isStatic, propertyKey));4428} else {4429if (match('?')) {4430lex();4431optional = true;4432}4433expect(':');4434propertyTypeAnnotation = parseType();4435properties.push(markerApply(marker, delegate.createObjectTypeProperty(4436propertyKey,4437propertyTypeAnnotation,4438optional,4439isStatic4440)));4441}4442}44434444if (match(';')) {4445lex();4446} else if (!match('}')) {4447throwUnexpected(lookahead);4448}4449}44504451expect('}');44524453return delegate.createObjectTypeAnnotation(4454properties,4455indexers,4456callProperties4457);4458}44594460function parseGenericType() {4461var marker = markerCreate(),4462typeParameters = null, typeIdentifier;44634464typeIdentifier = parseVariableIdentifier();44654466while (match('.')) {4467expect('.');4468typeIdentifier = markerApply(marker, delegate.createQualifiedTypeIdentifier(4469typeIdentifier,4470parseVariableIdentifier()4471));4472}44734474if (match('<')) {4475typeParameters = parseTypeParameterInstantiation();4476}44774478return markerApply(marker, delegate.createGenericTypeAnnotation(4479typeIdentifier,4480typeParameters4481));4482}44834484function parseVoidType() {4485var marker = markerCreate();4486expectKeyword('void');4487return markerApply(marker, delegate.createVoidTypeAnnotation());4488}44894490function parseTypeofType() {4491var argument, marker = markerCreate();4492expectKeyword('typeof');4493argument = parsePrimaryType();4494return markerApply(marker, delegate.createTypeofTypeAnnotation(4495argument4496));4497}44984499function parseTupleType() {4500var marker = markerCreate(), types = [];4501expect('[');4502// We allow trailing commas4503while (index < length && !match(']')) {4504types.push(parseType());4505if (match(']')) {4506break;4507}4508expect(',');4509}4510expect(']');4511return markerApply(marker, delegate.createTupleTypeAnnotation(4512types4513));4514}45154516function parseFunctionTypeParam() {4517var marker = markerCreate(), name, optional = false, typeAnnotation;4518name = parseVariableIdentifier();4519if (match('?')) {4520lex();4521optional = true;4522}4523expect(':');4524typeAnnotation = parseType();4525return markerApply(marker, delegate.createFunctionTypeParam(4526name,4527typeAnnotation,4528optional4529));4530}45314532function parseFunctionTypeParams() {4533var ret = { params: [], rest: null };4534while (lookahead.type === Token.Identifier) {4535ret.params.push(parseFunctionTypeParam());4536if (!match(')')) {4537expect(',');4538}4539}45404541if (match('...')) {4542lex();4543ret.rest = parseFunctionTypeParam();4544}4545return ret;4546}45474548// The parsing of types roughly parallels the parsing of expressions, and4549// primary types are kind of like primary expressions...they're the4550// primitives with which other types are constructed.4551function parsePrimaryType() {4552var params = null, returnType = null,4553marker = markerCreate(), rest = null, tmp,4554typeParameters, token, type, isGroupedType = false;45554556switch (lookahead.type) {4557case Token.Identifier:4558switch (lookahead.value) {4559case 'any':4560lex();4561return markerApply(marker, delegate.createAnyTypeAnnotation());4562case 'bool': // fallthrough4563case 'boolean':4564lex();4565return markerApply(marker, delegate.createBooleanTypeAnnotation());4566case 'number':4567lex();4568return markerApply(marker, delegate.createNumberTypeAnnotation());4569case 'string':4570lex();4571return markerApply(marker, delegate.createStringTypeAnnotation());4572}4573return markerApply(marker, parseGenericType());4574case Token.Punctuator:4575switch (lookahead.value) {4576case '{':4577return markerApply(marker, parseObjectType());4578case '[':4579return parseTupleType();4580case '<':4581typeParameters = parseTypeParameterDeclaration();4582expect('(');4583tmp = parseFunctionTypeParams();4584params = tmp.params;4585rest = tmp.rest;4586expect(')');45874588expect('=>');45894590returnType = parseType();45914592return markerApply(marker, delegate.createFunctionTypeAnnotation(4593params,4594returnType,4595rest,4596typeParameters4597));4598case '(':4599lex();4600// Check to see if this is actually a grouped type4601if (!match(')') && !match('...')) {4602if (lookahead.type === Token.Identifier) {4603token = lookahead2();4604isGroupedType = token.value !== '?' && token.value !== ':';4605} else {4606isGroupedType = true;4607}4608}46094610if (isGroupedType) {4611type = parseType();4612expect(')');46134614// If we see a => next then someone was probably confused about4615// function types, so we can provide a better error message4616if (match('=>')) {4617throwError({}, Messages.ConfusedAboutFunctionType);4618}46194620return type;4621}46224623tmp = parseFunctionTypeParams();4624params = tmp.params;4625rest = tmp.rest;46264627expect(')');46284629expect('=>');46304631returnType = parseType();46324633return markerApply(marker, delegate.createFunctionTypeAnnotation(4634params,4635returnType,4636rest,4637null /* typeParameters */4638));4639}4640break;4641case Token.Keyword:4642switch (lookahead.value) {4643case 'void':4644return markerApply(marker, parseVoidType());4645case 'typeof':4646return markerApply(marker, parseTypeofType());4647}4648break;4649case Token.StringLiteral:4650token = lex();4651if (token.octal) {4652throwError(token, Messages.StrictOctalLiteral);4653}4654return markerApply(marker, delegate.createStringLiteralTypeAnnotation(4655token4656));4657}46584659throwUnexpected(lookahead);4660}46614662function parsePostfixType() {4663var marker = markerCreate(), t = parsePrimaryType();4664if (match('[')) {4665expect('[');4666expect(']');4667return markerApply(marker, delegate.createArrayTypeAnnotation(t));4668}4669return t;4670}46714672function parsePrefixType() {4673var marker = markerCreate();4674if (match('?')) {4675lex();4676return markerApply(marker, delegate.createNullableTypeAnnotation(4677parsePrefixType()4678));4679}4680return parsePostfixType();4681}468246834684function parseIntersectionType() {4685var marker = markerCreate(), type, types;4686type = parsePrefixType();4687types = [type];4688while (match('&')) {4689lex();4690types.push(parsePrefixType());4691}46924693return types.length === 1 ?4694type :4695markerApply(marker, delegate.createIntersectionTypeAnnotation(4696types4697));4698}46994700function parseUnionType() {4701var marker = markerCreate(), type, types;4702type = parseIntersectionType();4703types = [type];4704while (match('|')) {4705lex();4706types.push(parseIntersectionType());4707}4708return types.length === 1 ?4709type :4710markerApply(marker, delegate.createUnionTypeAnnotation(4711types4712));4713}47144715function parseType() {4716var oldInType = state.inType, type;4717state.inType = true;47184719type = parseUnionType();47204721state.inType = oldInType;4722return type;4723}47244725function parseTypeAnnotation() {4726var marker = markerCreate(), type;47274728expect(':');4729type = parseType();47304731return markerApply(marker, delegate.createTypeAnnotation(type));4732}47334734function parseVariableIdentifier() {4735var marker = markerCreate(),4736token = lex();47374738if (token.type !== Token.Identifier) {4739throwUnexpected(token);4740}47414742return markerApply(marker, delegate.createIdentifier(token.value));4743}47444745function parseTypeAnnotatableIdentifier(requireTypeAnnotation, canBeOptionalParam) {4746var marker = markerCreate(),4747ident = parseVariableIdentifier(),4748isOptionalParam = false;47494750if (canBeOptionalParam && match('?')) {4751expect('?');4752isOptionalParam = true;4753}47544755if (requireTypeAnnotation || match(':')) {4756ident.typeAnnotation = parseTypeAnnotation();4757ident = markerApply(marker, ident);4758}47594760if (isOptionalParam) {4761ident.optional = true;4762ident = markerApply(marker, ident);4763}47644765return ident;4766}47674768function parseVariableDeclaration(kind) {4769var id,4770marker = markerCreate(),4771init = null,4772typeAnnotationMarker = markerCreate();4773if (match('{')) {4774id = parseObjectInitialiser();4775reinterpretAsAssignmentBindingPattern(id);4776if (match(':')) {4777id.typeAnnotation = parseTypeAnnotation();4778markerApply(typeAnnotationMarker, id);4779}4780} else if (match('[')) {4781id = parseArrayInitialiser();4782reinterpretAsAssignmentBindingPattern(id);4783if (match(':')) {4784id.typeAnnotation = parseTypeAnnotation();4785markerApply(typeAnnotationMarker, id);4786}4787} else {4788/* istanbul ignore next */4789id = state.allowKeyword ? parseNonComputedProperty() : parseTypeAnnotatableIdentifier();4790// 12.2.14791if (strict && isRestrictedWord(id.name)) {4792throwErrorTolerant({}, Messages.StrictVarName);4793}4794}47954796if (kind === 'const') {4797if (!match('=')) {4798throwError({}, Messages.NoUninitializedConst);4799}4800expect('=');4801init = parseAssignmentExpression();4802} else if (match('=')) {4803lex();4804init = parseAssignmentExpression();4805}48064807return markerApply(marker, delegate.createVariableDeclarator(id, init));4808}48094810function parseVariableDeclarationList(kind) {4811var list = [];48124813do {4814list.push(parseVariableDeclaration(kind));4815if (!match(',')) {4816break;4817}4818lex();4819} while (index < length);48204821return list;4822}48234824function parseVariableStatement() {4825var declarations, marker = markerCreate();48264827expectKeyword('var');48284829declarations = parseVariableDeclarationList();48304831consumeSemicolon();48324833return markerApply(marker, delegate.createVariableDeclaration(declarations, 'var'));4834}48354836// kind may be `const` or `let`4837// Both are experimental and not in the specification yet.4838// see http://wiki.ecmascript.org/doku.php?id=harmony:const4839// and http://wiki.ecmascript.org/doku.php?id=harmony:let4840function parseConstLetDeclaration(kind) {4841var declarations, marker = markerCreate();48424843expectKeyword(kind);48444845declarations = parseVariableDeclarationList(kind);48464847consumeSemicolon();48484849return markerApply(marker, delegate.createVariableDeclaration(declarations, kind));4850}48514852// people.mozilla.org/~jorendorff/es6-draft.html48534854function parseModuleSpecifier() {4855var marker = markerCreate(),4856specifier;48574858if (lookahead.type !== Token.StringLiteral) {4859throwError({}, Messages.InvalidModuleSpecifier);4860}4861specifier = delegate.createModuleSpecifier(lookahead);4862lex();4863return markerApply(marker, specifier);4864}48654866function parseExportBatchSpecifier() {4867var marker = markerCreate();4868expect('*');4869return markerApply(marker, delegate.createExportBatchSpecifier());4870}48714872function parseExportSpecifier() {4873var id, name = null, marker = markerCreate(), from;4874if (matchKeyword('default')) {4875lex();4876id = markerApply(marker, delegate.createIdentifier('default'));4877// export {default} from "something";4878} else {4879id = parseVariableIdentifier();4880}4881if (matchContextualKeyword('as')) {4882lex();4883name = parseNonComputedProperty();4884}48854886return markerApply(marker, delegate.createExportSpecifier(id, name));4887}48884889function parseExportDeclaration() {4890var declaration = null,4891possibleIdentifierToken, sourceElement,4892isExportFromIdentifier,4893src = null, specifiers = [],4894marker = markerCreate();48954896expectKeyword('export');48974898if (matchKeyword('default')) {4899// covers:4900// export default ...4901lex();4902if (matchKeyword('function') || matchKeyword('class')) {4903possibleIdentifierToken = lookahead2();4904if (isIdentifierName(possibleIdentifierToken)) {4905// covers:4906// export default function foo () {}4907// export default class foo {}4908sourceElement = parseSourceElement();4909return markerApply(marker, delegate.createExportDeclaration(true, sourceElement, [sourceElement.id], null));4910}4911// covers:4912// export default function () {}4913// export default class {}4914switch (lookahead.value) {4915case 'class':4916return markerApply(marker, delegate.createExportDeclaration(true, parseClassExpression(), [], null));4917case 'function':4918return markerApply(marker, delegate.createExportDeclaration(true, parseFunctionExpression(), [], null));4919}4920}49214922if (matchContextualKeyword('from')) {4923throwError({}, Messages.UnexpectedToken, lookahead.value);4924}49254926// covers:4927// export default {};4928// export default [];4929if (match('{')) {4930declaration = parseObjectInitialiser();4931} else if (match('[')) {4932declaration = parseArrayInitialiser();4933} else {4934declaration = parseAssignmentExpression();4935}4936consumeSemicolon();4937return markerApply(marker, delegate.createExportDeclaration(true, declaration, [], null));4938}49394940// non-default export4941if (lookahead.type === Token.Keyword || matchContextualKeyword('type')) {4942// covers:4943// export var f = 1;4944switch (lookahead.value) {4945case 'type':4946case 'let':4947case 'const':4948case 'var':4949case 'class':4950case 'function':4951return markerApply(marker, delegate.createExportDeclaration(false, parseSourceElement(), specifiers, null));4952}4953}49544955if (match('*')) {4956// covers:4957// export * from "foo";4958specifiers.push(parseExportBatchSpecifier());49594960if (!matchContextualKeyword('from')) {4961throwError({}, lookahead.value ?4962Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4963}4964lex();4965src = parseModuleSpecifier();4966consumeSemicolon();49674968return markerApply(marker, delegate.createExportDeclaration(false, null, specifiers, src));4969}49704971expect('{');4972if (!match('}')) {4973do {4974isExportFromIdentifier = isExportFromIdentifier || matchKeyword('default');4975specifiers.push(parseExportSpecifier());4976} while (match(',') && lex());4977}4978expect('}');49794980if (matchContextualKeyword('from')) {4981// covering:4982// export {default} from "foo";4983// export {foo} from "foo";4984lex();4985src = parseModuleSpecifier();4986consumeSemicolon();4987} else if (isExportFromIdentifier) {4988// covering:4989// export {default}; // missing fromClause4990throwError({}, lookahead.value ?4991Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);4992} else {4993// cover4994// export {foo};4995consumeSemicolon();4996}4997return markerApply(marker, delegate.createExportDeclaration(false, declaration, specifiers, src));4998}499950005001function parseImportSpecifier() {5002// import {<foo as bar>} ...;5003var id, name = null, marker = markerCreate();50045005id = parseNonComputedProperty();5006if (matchContextualKeyword('as')) {5007lex();5008name = parseVariableIdentifier();5009}50105011return markerApply(marker, delegate.createImportSpecifier(id, name));5012}50135014function parseNamedImports() {5015var specifiers = [];5016// {foo, bar as bas}5017expect('{');5018if (!match('}')) {5019do {5020specifiers.push(parseImportSpecifier());5021} while (match(',') && lex());5022}5023expect('}');5024return specifiers;5025}50265027function parseImportDefaultSpecifier() {5028// import <foo> ...;5029var id, marker = markerCreate();50305031id = parseNonComputedProperty();50325033return markerApply(marker, delegate.createImportDefaultSpecifier(id));5034}50355036function parseImportNamespaceSpecifier() {5037// import <* as foo> ...;5038var id, marker = markerCreate();50395040expect('*');5041if (!matchContextualKeyword('as')) {5042throwError({}, Messages.NoAsAfterImportNamespace);5043}5044lex();5045id = parseNonComputedProperty();50465047return markerApply(marker, delegate.createImportNamespaceSpecifier(id));5048}50495050function parseImportDeclaration() {5051var specifiers, src, marker = markerCreate(), isType = false, token2;50525053expectKeyword('import');50545055if (matchContextualKeyword('type')) {5056token2 = lookahead2();5057if ((token2.type === Token.Identifier && token2.value !== 'from') ||5058(token2.type === Token.Punctuator &&5059(token2.value === '{' || token2.value === '*'))) {5060isType = true;5061lex();5062}5063}50645065specifiers = [];50665067if (lookahead.type === Token.StringLiteral) {5068// covers:5069// import "foo";5070src = parseModuleSpecifier();5071consumeSemicolon();5072return markerApply(marker, delegate.createImportDeclaration(specifiers, src, isType));5073}50745075if (!matchKeyword('default') && isIdentifierName(lookahead)) {5076// covers:5077// import foo5078// import foo, ...5079specifiers.push(parseImportDefaultSpecifier());5080if (match(',')) {5081lex();5082}5083}5084if (match('*')) {5085// covers:5086// import foo, * as foo5087// import * as foo5088specifiers.push(parseImportNamespaceSpecifier());5089} else if (match('{')) {5090// covers:5091// import foo, {bar}5092// import {bar}5093specifiers = specifiers.concat(parseNamedImports());5094}50955096if (!matchContextualKeyword('from')) {5097throwError({}, lookahead.value ?5098Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);5099}5100lex();5101src = parseModuleSpecifier();5102consumeSemicolon();51035104return markerApply(marker, delegate.createImportDeclaration(specifiers, src, isType));5105}51065107// 12.3 Empty Statement51085109function parseEmptyStatement() {5110var marker = markerCreate();5111expect(';');5112return markerApply(marker, delegate.createEmptyStatement());5113}51145115// 12.4 Expression Statement51165117function parseExpressionStatement() {5118var marker = markerCreate(), expr = parseExpression();5119consumeSemicolon();5120return markerApply(marker, delegate.createExpressionStatement(expr));5121}51225123// 12.5 If statement51245125function parseIfStatement() {5126var test, consequent, alternate, marker = markerCreate();51275128expectKeyword('if');51295130expect('(');51315132test = parseExpression();51335134expect(')');51355136consequent = parseStatement();51375138if (matchKeyword('else')) {5139lex();5140alternate = parseStatement();5141} else {5142alternate = null;5143}51445145return markerApply(marker, delegate.createIfStatement(test, consequent, alternate));5146}51475148// 12.6 Iteration Statements51495150function parseDoWhileStatement() {5151var body, test, oldInIteration, marker = markerCreate();51525153expectKeyword('do');51545155oldInIteration = state.inIteration;5156state.inIteration = true;51575158body = parseStatement();51595160state.inIteration = oldInIteration;51615162expectKeyword('while');51635164expect('(');51655166test = parseExpression();51675168expect(')');51695170if (match(';')) {5171lex();5172}51735174return markerApply(marker, delegate.createDoWhileStatement(body, test));5175}51765177function parseWhileStatement() {5178var test, body, oldInIteration, marker = markerCreate();51795180expectKeyword('while');51815182expect('(');51835184test = parseExpression();51855186expect(')');51875188oldInIteration = state.inIteration;5189state.inIteration = true;51905191body = parseStatement();51925193state.inIteration = oldInIteration;51945195return markerApply(marker, delegate.createWhileStatement(test, body));5196}51975198function parseForVariableDeclaration() {5199var marker = markerCreate(),5200token = lex(),5201declarations = parseVariableDeclarationList();52025203return markerApply(marker, delegate.createVariableDeclaration(declarations, token.value));5204}52055206function parseForStatement(opts) {5207var init, test, update, left, right, body, operator, oldInIteration,5208marker = markerCreate();5209init = test = update = null;5210expectKeyword('for');52115212// http://wiki.ecmascript.org/doku.php?id=proposals:iterators_and_generators&s=each5213if (matchContextualKeyword('each')) {5214throwError({}, Messages.EachNotAllowed);5215}52165217expect('(');52185219if (match(';')) {5220lex();5221} else {5222if (matchKeyword('var') || matchKeyword('let') || matchKeyword('const')) {5223state.allowIn = false;5224init = parseForVariableDeclaration();5225state.allowIn = true;52265227if (init.declarations.length === 1) {5228if (matchKeyword('in') || matchContextualKeyword('of')) {5229operator = lookahead;5230if (!((operator.value === 'in' || init.kind !== 'var') && init.declarations[0].init)) {5231lex();5232left = init;5233right = parseExpression();5234init = null;5235}5236}5237}5238} else {5239state.allowIn = false;5240init = parseExpression();5241state.allowIn = true;52425243if (matchContextualKeyword('of')) {5244operator = lex();5245left = init;5246right = parseExpression();5247init = null;5248} else if (matchKeyword('in')) {5249// LeftHandSideExpression5250if (!isAssignableLeftHandSide(init)) {5251throwError({}, Messages.InvalidLHSInForIn);5252}5253operator = lex();5254left = init;5255right = parseExpression();5256init = null;5257}5258}52595260if (typeof left === 'undefined') {5261expect(';');5262}5263}52645265if (typeof left === 'undefined') {52665267if (!match(';')) {5268test = parseExpression();5269}5270expect(';');52715272if (!match(')')) {5273update = parseExpression();5274}5275}52765277expect(')');52785279oldInIteration = state.inIteration;5280state.inIteration = true;52815282if (!(opts !== undefined && opts.ignoreBody)) {5283body = parseStatement();5284}52855286state.inIteration = oldInIteration;52875288if (typeof left === 'undefined') {5289return markerApply(marker, delegate.createForStatement(init, test, update, body));5290}52915292if (operator.value === 'in') {5293return markerApply(marker, delegate.createForInStatement(left, right, body));5294}5295return markerApply(marker, delegate.createForOfStatement(left, right, body));5296}52975298// 12.7 The continue statement52995300function parseContinueStatement() {5301var label = null, marker = markerCreate();53025303expectKeyword('continue');53045305// Optimize the most common form: 'continue;'.5306if (source.charCodeAt(index) === 59) {5307lex();53085309if (!state.inIteration) {5310throwError({}, Messages.IllegalContinue);5311}53125313return markerApply(marker, delegate.createContinueStatement(null));5314}53155316if (peekLineTerminator()) {5317if (!state.inIteration) {5318throwError({}, Messages.IllegalContinue);5319}53205321return markerApply(marker, delegate.createContinueStatement(null));5322}53235324if (lookahead.type === Token.Identifier) {5325label = parseVariableIdentifier();53265327if (!state.labelSet.has(label.name)) {5328throwError({}, Messages.UnknownLabel, label.name);5329}5330}53315332consumeSemicolon();53335334if (label === null && !state.inIteration) {5335throwError({}, Messages.IllegalContinue);5336}53375338return markerApply(marker, delegate.createContinueStatement(label));5339}53405341// 12.8 The break statement53425343function parseBreakStatement() {5344var label = null, marker = markerCreate();53455346expectKeyword('break');53475348// Catch the very common case first: immediately a semicolon (char #59).5349if (source.charCodeAt(index) === 59) {5350lex();53515352if (!(state.inIteration || state.inSwitch)) {5353throwError({}, Messages.IllegalBreak);5354}53555356return markerApply(marker, delegate.createBreakStatement(null));5357}53585359if (peekLineTerminator()) {5360if (!(state.inIteration || state.inSwitch)) {5361throwError({}, Messages.IllegalBreak);5362}53635364return markerApply(marker, delegate.createBreakStatement(null));5365}53665367if (lookahead.type === Token.Identifier) {5368label = parseVariableIdentifier();53695370if (!state.labelSet.has(label.name)) {5371throwError({}, Messages.UnknownLabel, label.name);5372}5373}53745375consumeSemicolon();53765377if (label === null && !(state.inIteration || state.inSwitch)) {5378throwError({}, Messages.IllegalBreak);5379}53805381return markerApply(marker, delegate.createBreakStatement(label));5382}53835384// 12.9 The return statement53855386function parseReturnStatement() {5387var argument = null, marker = markerCreate();53885389expectKeyword('return');53905391if (!state.inFunctionBody) {5392throwErrorTolerant({}, Messages.IllegalReturn);5393}53945395// 'return' followed by a space and an identifier is very common.5396if (source.charCodeAt(index) === 32) {5397if (isIdentifierStart(source.charCodeAt(index + 1))) {5398argument = parseExpression();5399consumeSemicolon();5400return markerApply(marker, delegate.createReturnStatement(argument));5401}5402}54035404if (peekLineTerminator()) {5405return markerApply(marker, delegate.createReturnStatement(null));5406}54075408if (!match(';')) {5409if (!match('}') && lookahead.type !== Token.EOF) {5410argument = parseExpression();5411}5412}54135414consumeSemicolon();54155416return markerApply(marker, delegate.createReturnStatement(argument));5417}54185419// 12.10 The with statement54205421function parseWithStatement() {5422var object, body, marker = markerCreate();54235424if (strict) {5425throwErrorTolerant({}, Messages.StrictModeWith);5426}54275428expectKeyword('with');54295430expect('(');54315432object = parseExpression();54335434expect(')');54355436body = parseStatement();54375438return markerApply(marker, delegate.createWithStatement(object, body));5439}54405441// 12.10 The swith statement54425443function parseSwitchCase() {5444var test,5445consequent = [],5446sourceElement,5447marker = markerCreate();54485449if (matchKeyword('default')) {5450lex();5451test = null;5452} else {5453expectKeyword('case');5454test = parseExpression();5455}5456expect(':');54575458while (index < length) {5459if (match('}') || matchKeyword('default') || matchKeyword('case')) {5460break;5461}5462sourceElement = parseSourceElement();5463if (typeof sourceElement === 'undefined') {5464break;5465}5466consequent.push(sourceElement);5467}54685469return markerApply(marker, delegate.createSwitchCase(test, consequent));5470}54715472function parseSwitchStatement() {5473var discriminant, cases, clause, oldInSwitch, defaultFound, marker = markerCreate();54745475expectKeyword('switch');54765477expect('(');54785479discriminant = parseExpression();54805481expect(')');54825483expect('{');54845485cases = [];54865487if (match('}')) {5488lex();5489return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));5490}54915492oldInSwitch = state.inSwitch;5493state.inSwitch = true;5494defaultFound = false;54955496while (index < length) {5497if (match('}')) {5498break;5499}5500clause = parseSwitchCase();5501if (clause.test === null) {5502if (defaultFound) {5503throwError({}, Messages.MultipleDefaultsInSwitch);5504}5505defaultFound = true;5506}5507cases.push(clause);5508}55095510state.inSwitch = oldInSwitch;55115512expect('}');55135514return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));5515}55165517// 12.13 The throw statement55185519function parseThrowStatement() {5520var argument, marker = markerCreate();55215522expectKeyword('throw');55235524if (peekLineTerminator()) {5525throwError({}, Messages.NewlineAfterThrow);5526}55275528argument = parseExpression();55295530consumeSemicolon();55315532return markerApply(marker, delegate.createThrowStatement(argument));5533}55345535// 12.14 The try statement55365537function parseCatchClause() {5538var param, body, marker = markerCreate();55395540expectKeyword('catch');55415542expect('(');5543if (match(')')) {5544throwUnexpected(lookahead);5545}55465547param = parseExpression();5548// 12.14.15549if (strict && param.type === Syntax.Identifier && isRestrictedWord(param.name)) {5550throwErrorTolerant({}, Messages.StrictCatchVariable);5551}55525553expect(')');5554body = parseBlock();5555return markerApply(marker, delegate.createCatchClause(param, body));5556}55575558function parseTryStatement() {5559var block, handlers = [], finalizer = null, marker = markerCreate();55605561expectKeyword('try');55625563block = parseBlock();55645565if (matchKeyword('catch')) {5566handlers.push(parseCatchClause());5567}55685569if (matchKeyword('finally')) {5570lex();5571finalizer = parseBlock();5572}55735574if (handlers.length === 0 && !finalizer) {5575throwError({}, Messages.NoCatchOrFinally);5576}55775578return markerApply(marker, delegate.createTryStatement(block, [], handlers, finalizer));5579}55805581// 12.15 The debugger statement55825583function parseDebuggerStatement() {5584var marker = markerCreate();5585expectKeyword('debugger');55865587consumeSemicolon();55885589return markerApply(marker, delegate.createDebuggerStatement());5590}55915592// 12 Statements55935594function parseStatement() {5595var type = lookahead.type,5596marker,5597expr,5598labeledBody;55995600if (type === Token.EOF) {5601throwUnexpected(lookahead);5602}56035604if (type === Token.Punctuator) {5605switch (lookahead.value) {5606case ';':5607return parseEmptyStatement();5608case '{':5609return parseBlock();5610case '(':5611return parseExpressionStatement();5612default:5613break;5614}5615}56165617if (type === Token.Keyword) {5618switch (lookahead.value) {5619case 'break':5620return parseBreakStatement();5621case 'continue':5622return parseContinueStatement();5623case 'debugger':5624return parseDebuggerStatement();5625case 'do':5626return parseDoWhileStatement();5627case 'for':5628return parseForStatement();5629case 'function':5630return parseFunctionDeclaration();5631case 'class':5632return parseClassDeclaration();5633case 'if':5634return parseIfStatement();5635case 'return':5636return parseReturnStatement();5637case 'switch':5638return parseSwitchStatement();5639case 'throw':5640return parseThrowStatement();5641case 'try':5642return parseTryStatement();5643case 'var':5644return parseVariableStatement();5645case 'while':5646return parseWhileStatement();5647case 'with':5648return parseWithStatement();5649default:5650break;5651}5652}56535654if (matchAsyncFuncExprOrDecl()) {5655return parseFunctionDeclaration();5656}56575658marker = markerCreate();5659expr = parseExpression();56605661// 12.12 Labelled Statements5662if ((expr.type === Syntax.Identifier) && match(':')) {5663lex();56645665if (state.labelSet.has(expr.name)) {5666throwError({}, Messages.Redeclaration, 'Label', expr.name);5667}56685669state.labelSet.set(expr.name, true);5670labeledBody = parseStatement();5671state.labelSet.delete(expr.name);5672return markerApply(marker, delegate.createLabeledStatement(expr, labeledBody));5673}56745675consumeSemicolon();56765677return markerApply(marker, delegate.createExpressionStatement(expr));5678}56795680// 13 Function Definition56815682function parseConciseBody() {5683if (match('{')) {5684return parseFunctionSourceElements();5685}5686return parseAssignmentExpression();5687}56885689function parseFunctionSourceElements() {5690var sourceElement, sourceElements = [], token, directive, firstRestricted,5691oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, oldParenthesizedCount,5692marker = markerCreate();56935694expect('{');56955696while (index < length) {5697if (lookahead.type !== Token.StringLiteral) {5698break;5699}5700token = lookahead;57015702sourceElement = parseSourceElement();5703sourceElements.push(sourceElement);5704if (sourceElement.expression.type !== Syntax.Literal) {5705// this is not directive5706break;5707}5708directive = source.slice(token.range[0] + 1, token.range[1] - 1);5709if (directive === 'use strict') {5710strict = true;5711if (firstRestricted) {5712throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);5713}5714} else {5715if (!firstRestricted && token.octal) {5716firstRestricted = token;5717}5718}5719}57205721oldLabelSet = state.labelSet;5722oldInIteration = state.inIteration;5723oldInSwitch = state.inSwitch;5724oldInFunctionBody = state.inFunctionBody;5725oldParenthesizedCount = state.parenthesizedCount;57265727state.labelSet = new StringMap();5728state.inIteration = false;5729state.inSwitch = false;5730state.inFunctionBody = true;5731state.parenthesizedCount = 0;57325733while (index < length) {5734if (match('}')) {5735break;5736}5737sourceElement = parseSourceElement();5738if (typeof sourceElement === 'undefined') {5739break;5740}5741sourceElements.push(sourceElement);5742}57435744expect('}');57455746state.labelSet = oldLabelSet;5747state.inIteration = oldInIteration;5748state.inSwitch = oldInSwitch;5749state.inFunctionBody = oldInFunctionBody;5750state.parenthesizedCount = oldParenthesizedCount;57515752return markerApply(marker, delegate.createBlockStatement(sourceElements));5753}57545755function validateParam(options, param, name) {5756if (strict) {5757if (isRestrictedWord(name)) {5758options.stricted = param;5759options.message = Messages.StrictParamName;5760}5761if (options.paramSet.has(name)) {5762options.stricted = param;5763options.message = Messages.StrictParamDupe;5764}5765} else if (!options.firstRestricted) {5766if (isRestrictedWord(name)) {5767options.firstRestricted = param;5768options.message = Messages.StrictParamName;5769} else if (isStrictModeReservedWord(name)) {5770options.firstRestricted = param;5771options.message = Messages.StrictReservedWord;5772} else if (options.paramSet.has(name)) {5773options.firstRestricted = param;5774options.message = Messages.StrictParamDupe;5775}5776}5777options.paramSet.set(name, true);5778}57795780function parseParam(options) {5781var marker, token, rest, param, def;57825783token = lookahead;5784if (token.value === '...') {5785token = lex();5786rest = true;5787}57885789if (match('[')) {5790marker = markerCreate();5791param = parseArrayInitialiser();5792reinterpretAsDestructuredParameter(options, param);5793if (match(':')) {5794param.typeAnnotation = parseTypeAnnotation();5795markerApply(marker, param);5796}5797} else if (match('{')) {5798marker = markerCreate();5799if (rest) {5800throwError({}, Messages.ObjectPatternAsRestParameter);5801}5802param = parseObjectInitialiser();5803reinterpretAsDestructuredParameter(options, param);5804if (match(':')) {5805param.typeAnnotation = parseTypeAnnotation();5806markerApply(marker, param);5807}5808} else {5809param =5810rest5811? parseTypeAnnotatableIdentifier(5812false, /* requireTypeAnnotation */5813false /* canBeOptionalParam */5814)5815: parseTypeAnnotatableIdentifier(5816false, /* requireTypeAnnotation */5817true /* canBeOptionalParam */5818);58195820validateParam(options, token, token.value);5821}58225823if (match('=')) {5824if (rest) {5825throwErrorTolerant(lookahead, Messages.DefaultRestParameter);5826}5827lex();5828def = parseAssignmentExpression();5829++options.defaultCount;5830}58315832if (rest) {5833if (!match(')')) {5834throwError({}, Messages.ParameterAfterRestParameter);5835}5836options.rest = param;5837return false;5838}58395840options.params.push(param);5841options.defaults.push(def);5842return !match(')');5843}58445845function parseParams(firstRestricted) {5846var options, marker = markerCreate();58475848options = {5849params: [],5850defaultCount: 0,5851defaults: [],5852rest: null,5853firstRestricted: firstRestricted5854};58555856expect('(');58575858if (!match(')')) {5859options.paramSet = new StringMap();5860while (index < length) {5861if (!parseParam(options)) {5862break;5863}5864expect(',');5865}5866}58675868expect(')');58695870if (options.defaultCount === 0) {5871options.defaults = [];5872}58735874if (match(':')) {5875options.returnType = parseTypeAnnotation();5876}58775878return markerApply(marker, options);5879}58805881function parseFunctionDeclaration() {5882var id, body, token, tmp, firstRestricted, message, generator, isAsync,5883previousStrict, previousYieldAllowed, previousAwaitAllowed,5884marker = markerCreate(), typeParameters;58855886isAsync = false;5887if (matchAsync()) {5888lex();5889isAsync = true;5890}58915892expectKeyword('function');58935894generator = false;5895if (match('*')) {5896lex();5897generator = true;5898}58995900token = lookahead;59015902id = parseVariableIdentifier();59035904if (match('<')) {5905typeParameters = parseTypeParameterDeclaration();5906}59075908if (strict) {5909if (isRestrictedWord(token.value)) {5910throwErrorTolerant(token, Messages.StrictFunctionName);5911}5912} else {5913if (isRestrictedWord(token.value)) {5914firstRestricted = token;5915message = Messages.StrictFunctionName;5916} else if (isStrictModeReservedWord(token.value)) {5917firstRestricted = token;5918message = Messages.StrictReservedWord;5919}5920}59215922tmp = parseParams(firstRestricted);5923firstRestricted = tmp.firstRestricted;5924if (tmp.message) {5925message = tmp.message;5926}59275928previousStrict = strict;5929previousYieldAllowed = state.yieldAllowed;5930state.yieldAllowed = generator;5931previousAwaitAllowed = state.awaitAllowed;5932state.awaitAllowed = isAsync;59335934body = parseFunctionSourceElements();59355936if (strict && firstRestricted) {5937throwError(firstRestricted, message);5938}5939if (strict && tmp.stricted) {5940throwErrorTolerant(tmp.stricted, message);5941}5942strict = previousStrict;5943state.yieldAllowed = previousYieldAllowed;5944state.awaitAllowed = previousAwaitAllowed;59455946return markerApply(5947marker,5948delegate.createFunctionDeclaration(5949id,5950tmp.params,5951tmp.defaults,5952body,5953tmp.rest,5954generator,5955false,5956isAsync,5957tmp.returnType,5958typeParameters5959)5960);5961}59625963function parseFunctionExpression() {5964var token, id = null, firstRestricted, message, tmp, body, generator, isAsync,5965previousStrict, previousYieldAllowed, previousAwaitAllowed,5966marker = markerCreate(), typeParameters;59675968isAsync = false;5969if (matchAsync()) {5970lex();5971isAsync = true;5972}59735974expectKeyword('function');59755976generator = false;59775978if (match('*')) {5979lex();5980generator = true;5981}59825983if (!match('(')) {5984if (!match('<')) {5985token = lookahead;5986id = parseVariableIdentifier();59875988if (strict) {5989if (isRestrictedWord(token.value)) {5990throwErrorTolerant(token, Messages.StrictFunctionName);5991}5992} else {5993if (isRestrictedWord(token.value)) {5994firstRestricted = token;5995message = Messages.StrictFunctionName;5996} else if (isStrictModeReservedWord(token.value)) {5997firstRestricted = token;5998message = Messages.StrictReservedWord;5999}6000}6001}60026003if (match('<')) {6004typeParameters = parseTypeParameterDeclaration();6005}6006}60076008tmp = parseParams(firstRestricted);6009firstRestricted = tmp.firstRestricted;6010if (tmp.message) {6011message = tmp.message;6012}60136014previousStrict = strict;6015previousYieldAllowed = state.yieldAllowed;6016state.yieldAllowed = generator;6017previousAwaitAllowed = state.awaitAllowed;6018state.awaitAllowed = isAsync;60196020body = parseFunctionSourceElements();60216022if (strict && firstRestricted) {6023throwError(firstRestricted, message);6024}6025if (strict && tmp.stricted) {6026throwErrorTolerant(tmp.stricted, message);6027}6028strict = previousStrict;6029state.yieldAllowed = previousYieldAllowed;6030state.awaitAllowed = previousAwaitAllowed;60316032return markerApply(6033marker,6034delegate.createFunctionExpression(6035id,6036tmp.params,6037tmp.defaults,6038body,6039tmp.rest,6040generator,6041false,6042isAsync,6043tmp.returnType,6044typeParameters6045)6046);6047}60486049function parseYieldExpression() {6050var delegateFlag, expr, marker = markerCreate();60516052expectKeyword('yield', !strict);60536054delegateFlag = false;6055if (match('*')) {6056lex();6057delegateFlag = true;6058}60596060expr = parseAssignmentExpression();60616062return markerApply(marker, delegate.createYieldExpression(expr, delegateFlag));6063}60646065function parseAwaitExpression() {6066var expr, marker = markerCreate();6067expectContextualKeyword('await');6068expr = parseAssignmentExpression();6069return markerApply(marker, delegate.createAwaitExpression(expr));6070}60716072// 14 Functions and classes60736074// 14.1 Functions is defined above (13 in ES5)6075// 14.2 Arrow Functions Definitions is defined in (7.3 assignments)60766077// 14.3 Method Definitions6078// 14.3.76079function specialMethod(methodDefinition) {6080return methodDefinition.kind === 'get' ||6081methodDefinition.kind === 'set' ||6082methodDefinition.value.generator;6083}60846085function parseMethodDefinition(key, isStatic, generator, computed) {6086var token, param, propType,6087isAsync, typeParameters, tokenValue, returnType;60886089propType = isStatic ? ClassPropertyType.static : ClassPropertyType.prototype;60906091if (generator) {6092return delegate.createMethodDefinition(6093propType,6094'',6095key,6096parsePropertyMethodFunction({ generator: true }),6097computed6098);6099}61006101tokenValue = key.type === 'Identifier' && key.name;61026103if (tokenValue === 'get' && !match('(')) {6104key = parseObjectPropertyKey();61056106expect('(');6107expect(')');6108if (match(':')) {6109returnType = parseTypeAnnotation();6110}6111return delegate.createMethodDefinition(6112propType,6113'get',6114key,6115parsePropertyFunction({ generator: false, returnType: returnType }),6116computed6117);6118}6119if (tokenValue === 'set' && !match('(')) {6120key = parseObjectPropertyKey();61216122expect('(');6123token = lookahead;6124param = [ parseTypeAnnotatableIdentifier() ];6125expect(')');6126if (match(':')) {6127returnType = parseTypeAnnotation();6128}6129return delegate.createMethodDefinition(6130propType,6131'set',6132key,6133parsePropertyFunction({6134params: param,6135generator: false,6136name: token,6137returnType: returnType6138}),6139computed6140);6141}61426143if (match('<')) {6144typeParameters = parseTypeParameterDeclaration();6145}61466147isAsync = tokenValue === 'async' && !match('(');6148if (isAsync) {6149key = parseObjectPropertyKey();6150}61516152return delegate.createMethodDefinition(6153propType,6154'',6155key,6156parsePropertyMethodFunction({6157generator: false,6158async: isAsync,6159typeParameters: typeParameters6160}),6161computed6162);6163}61646165function parseClassProperty(key, computed, isStatic) {6166var typeAnnotation;61676168typeAnnotation = parseTypeAnnotation();6169expect(';');61706171return delegate.createClassProperty(6172key,6173typeAnnotation,6174computed,6175isStatic6176);6177}61786179function parseClassElement() {6180var computed = false, generator = false, key, marker = markerCreate(),6181isStatic = false, possiblyOpenBracketToken;6182if (match(';')) {6183lex();6184return undefined;6185}61866187if (lookahead.value === 'static') {6188lex();6189isStatic = true;6190}61916192if (match('*')) {6193lex();6194generator = true;6195}61966197possiblyOpenBracketToken = lookahead;6198if (matchContextualKeyword('get') || matchContextualKeyword('set')) {6199possiblyOpenBracketToken = lookahead2();6200}62016202if (possiblyOpenBracketToken.type === Token.Punctuator6203&& possiblyOpenBracketToken.value === '[') {6204computed = true;6205}62066207key = parseObjectPropertyKey();62086209if (!generator && lookahead.value === ':') {6210return markerApply(marker, parseClassProperty(key, computed, isStatic));6211}62126213return markerApply(marker, parseMethodDefinition(6214key,6215isStatic,6216generator,6217computed6218));6219}62206221function parseClassBody() {6222var classElement, classElements = [], existingProps = {},6223marker = markerCreate(), propName, propType;62246225existingProps[ClassPropertyType.static] = new StringMap();6226existingProps[ClassPropertyType.prototype] = new StringMap();62276228expect('{');62296230while (index < length) {6231if (match('}')) {6232break;6233}6234classElement = parseClassElement(existingProps);62356236if (typeof classElement !== 'undefined') {6237classElements.push(classElement);62386239propName = !classElement.computed && getFieldName(classElement.key);6240if (propName !== false) {6241propType = classElement.static ?6242ClassPropertyType.static :6243ClassPropertyType.prototype;62446245if (classElement.type === Syntax.MethodDefinition) {6246if (propName === 'constructor' && !classElement.static) {6247if (specialMethod(classElement)) {6248throwError(classElement, Messages.IllegalClassConstructorProperty);6249}6250if (existingProps[ClassPropertyType.prototype].has('constructor')) {6251throwError(classElement.key, Messages.IllegalDuplicateClassProperty);6252}6253}6254existingProps[propType].set(propName, true);6255}6256}6257}6258}62596260expect('}');62616262return markerApply(marker, delegate.createClassBody(classElements));6263}62646265function parseClassImplements() {6266var id, implemented = [], marker, typeParameters;6267if (strict) {6268expectKeyword('implements');6269} else {6270expectContextualKeyword('implements');6271}6272while (index < length) {6273marker = markerCreate();6274id = parseVariableIdentifier();6275if (match('<')) {6276typeParameters = parseTypeParameterInstantiation();6277} else {6278typeParameters = null;6279}6280implemented.push(markerApply(marker, delegate.createClassImplements(6281id,6282typeParameters6283)));6284if (!match(',')) {6285break;6286}6287expect(',');6288}6289return implemented;6290}62916292function parseClassExpression() {6293var id, implemented, previousYieldAllowed, superClass = null,6294superTypeParameters, marker = markerCreate(), typeParameters,6295matchImplements;62966297expectKeyword('class');62986299matchImplements =6300strict6301? matchKeyword('implements')6302: matchContextualKeyword('implements');63036304if (!matchKeyword('extends') && !matchImplements && !match('{')) {6305id = parseVariableIdentifier();6306}63076308if (match('<')) {6309typeParameters = parseTypeParameterDeclaration();6310}63116312if (matchKeyword('extends')) {6313expectKeyword('extends');6314previousYieldAllowed = state.yieldAllowed;6315state.yieldAllowed = false;6316superClass = parseLeftHandSideExpressionAllowCall();6317if (match('<')) {6318superTypeParameters = parseTypeParameterInstantiation();6319}6320state.yieldAllowed = previousYieldAllowed;6321}63226323if (strict ? matchKeyword('implements') : matchContextualKeyword('implements')) {6324implemented = parseClassImplements();6325}63266327return markerApply(marker, delegate.createClassExpression(6328id,6329superClass,6330parseClassBody(),6331typeParameters,6332superTypeParameters,6333implemented6334));6335}63366337function parseClassDeclaration() {6338var id, implemented, previousYieldAllowed, superClass = null,6339superTypeParameters, marker = markerCreate(), typeParameters;63406341expectKeyword('class');63426343id = parseVariableIdentifier();63446345if (match('<')) {6346typeParameters = parseTypeParameterDeclaration();6347}63486349if (matchKeyword('extends')) {6350expectKeyword('extends');6351previousYieldAllowed = state.yieldAllowed;6352state.yieldAllowed = false;6353superClass = parseLeftHandSideExpressionAllowCall();6354if (match('<')) {6355superTypeParameters = parseTypeParameterInstantiation();6356}6357state.yieldAllowed = previousYieldAllowed;6358}63596360if (strict ? matchKeyword('implements') : matchContextualKeyword('implements')) {6361implemented = parseClassImplements();6362}63636364return markerApply(marker, delegate.createClassDeclaration(6365id,6366superClass,6367parseClassBody(),6368typeParameters,6369superTypeParameters,6370implemented6371));6372}63736374// 15 Program63756376function parseSourceElement() {6377var token;6378if (lookahead.type === Token.Keyword) {6379switch (lookahead.value) {6380case 'const':6381case 'let':6382return parseConstLetDeclaration(lookahead.value);6383case 'function':6384return parseFunctionDeclaration();6385case 'export':6386throwErrorTolerant({}, Messages.IllegalExportDeclaration);6387return parseExportDeclaration();6388case 'import':6389throwErrorTolerant({}, Messages.IllegalImportDeclaration);6390return parseImportDeclaration();6391case 'interface':6392if (lookahead2().type === Token.Identifier) {6393return parseInterface();6394}6395return parseStatement();6396default:6397return parseStatement();6398}6399}64006401if (matchContextualKeyword('type')6402&& lookahead2().type === Token.Identifier) {6403return parseTypeAlias();6404}64056406if (matchContextualKeyword('interface')6407&& lookahead2().type === Token.Identifier) {6408return parseInterface();6409}64106411if (matchContextualKeyword('declare')) {6412token = lookahead2();6413if (token.type === Token.Keyword) {6414switch (token.value) {6415case 'class':6416return parseDeclareClass();6417case 'function':6418return parseDeclareFunction();6419case 'var':6420return parseDeclareVariable();6421}6422} else if (token.type === Token.Identifier6423&& token.value === 'module') {6424return parseDeclareModule();6425}6426}64276428if (lookahead.type !== Token.EOF) {6429return parseStatement();6430}6431}64326433function parseProgramElement() {6434var isModule = extra.sourceType === 'module' || extra.sourceType === 'nonStrictModule';64356436if (isModule && lookahead.type === Token.Keyword) {6437switch (lookahead.value) {6438case 'export':6439return parseExportDeclaration();6440case 'import':6441return parseImportDeclaration();6442}6443}64446445return parseSourceElement();6446}64476448function parseProgramElements() {6449var sourceElement, sourceElements = [], token, directive, firstRestricted;64506451while (index < length) {6452token = lookahead;6453if (token.type !== Token.StringLiteral) {6454break;6455}64566457sourceElement = parseProgramElement();6458sourceElements.push(sourceElement);6459if (sourceElement.expression.type !== Syntax.Literal) {6460// this is not directive6461break;6462}6463directive = source.slice(token.range[0] + 1, token.range[1] - 1);6464if (directive === 'use strict') {6465strict = true;6466if (firstRestricted) {6467throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);6468}6469} else {6470if (!firstRestricted && token.octal) {6471firstRestricted = token;6472}6473}6474}64756476while (index < length) {6477sourceElement = parseProgramElement();6478if (typeof sourceElement === 'undefined') {6479break;6480}6481sourceElements.push(sourceElement);6482}6483return sourceElements;6484}64856486function parseProgram() {6487var body, marker = markerCreate();6488strict = extra.sourceType === 'module';6489peek();6490body = parseProgramElements();6491return markerApply(marker, delegate.createProgram(body));6492}64936494// 16 JSX64956496XHTMLEntities = {6497quot: '\u0022',6498amp: '&',6499apos: '\u0027',6500lt: '<',6501gt: '>',6502nbsp: '\u00A0',6503iexcl: '\u00A1',6504cent: '\u00A2',6505pound: '\u00A3',6506curren: '\u00A4',6507yen: '\u00A5',6508brvbar: '\u00A6',6509sect: '\u00A7',6510uml: '\u00A8',6511copy: '\u00A9',6512ordf: '\u00AA',6513laquo: '\u00AB',6514not: '\u00AC',6515shy: '\u00AD',6516reg: '\u00AE',6517macr: '\u00AF',6518deg: '\u00B0',6519plusmn: '\u00B1',6520sup2: '\u00B2',6521sup3: '\u00B3',6522acute: '\u00B4',6523micro: '\u00B5',6524para: '\u00B6',6525middot: '\u00B7',6526cedil: '\u00B8',6527sup1: '\u00B9',6528ordm: '\u00BA',6529raquo: '\u00BB',6530frac14: '\u00BC',6531frac12: '\u00BD',6532frac34: '\u00BE',6533iquest: '\u00BF',6534Agrave: '\u00C0',6535Aacute: '\u00C1',6536Acirc: '\u00C2',6537Atilde: '\u00C3',6538Auml: '\u00C4',6539Aring: '\u00C5',6540AElig: '\u00C6',6541Ccedil: '\u00C7',6542Egrave: '\u00C8',6543Eacute: '\u00C9',6544Ecirc: '\u00CA',6545Euml: '\u00CB',6546Igrave: '\u00CC',6547Iacute: '\u00CD',6548Icirc: '\u00CE',6549Iuml: '\u00CF',6550ETH: '\u00D0',6551Ntilde: '\u00D1',6552Ograve: '\u00D2',6553Oacute: '\u00D3',6554Ocirc: '\u00D4',6555Otilde: '\u00D5',6556Ouml: '\u00D6',6557times: '\u00D7',6558Oslash: '\u00D8',6559Ugrave: '\u00D9',6560Uacute: '\u00DA',6561Ucirc: '\u00DB',6562Uuml: '\u00DC',6563Yacute: '\u00DD',6564THORN: '\u00DE',6565szlig: '\u00DF',6566agrave: '\u00E0',6567aacute: '\u00E1',6568acirc: '\u00E2',6569atilde: '\u00E3',6570auml: '\u00E4',6571aring: '\u00E5',6572aelig: '\u00E6',6573ccedil: '\u00E7',6574egrave: '\u00E8',6575eacute: '\u00E9',6576ecirc: '\u00EA',6577euml: '\u00EB',6578igrave: '\u00EC',6579iacute: '\u00ED',6580icirc: '\u00EE',6581iuml: '\u00EF',6582eth: '\u00F0',6583ntilde: '\u00F1',6584ograve: '\u00F2',6585oacute: '\u00F3',6586ocirc: '\u00F4',6587otilde: '\u00F5',6588ouml: '\u00F6',6589divide: '\u00F7',6590oslash: '\u00F8',6591ugrave: '\u00F9',6592uacute: '\u00FA',6593ucirc: '\u00FB',6594uuml: '\u00FC',6595yacute: '\u00FD',6596thorn: '\u00FE',6597yuml: '\u00FF',6598OElig: '\u0152',6599oelig: '\u0153',6600Scaron: '\u0160',6601scaron: '\u0161',6602Yuml: '\u0178',6603fnof: '\u0192',6604circ: '\u02C6',6605tilde: '\u02DC',6606Alpha: '\u0391',6607Beta: '\u0392',6608Gamma: '\u0393',6609Delta: '\u0394',6610Epsilon: '\u0395',6611Zeta: '\u0396',6612Eta: '\u0397',6613Theta: '\u0398',6614Iota: '\u0399',6615Kappa: '\u039A',6616Lambda: '\u039B',6617Mu: '\u039C',6618Nu: '\u039D',6619Xi: '\u039E',6620Omicron: '\u039F',6621Pi: '\u03A0',6622Rho: '\u03A1',6623Sigma: '\u03A3',6624Tau: '\u03A4',6625Upsilon: '\u03A5',6626Phi: '\u03A6',6627Chi: '\u03A7',6628Psi: '\u03A8',6629Omega: '\u03A9',6630alpha: '\u03B1',6631beta: '\u03B2',6632gamma: '\u03B3',6633delta: '\u03B4',6634epsilon: '\u03B5',6635zeta: '\u03B6',6636eta: '\u03B7',6637theta: '\u03B8',6638iota: '\u03B9',6639kappa: '\u03BA',6640lambda: '\u03BB',6641mu: '\u03BC',6642nu: '\u03BD',6643xi: '\u03BE',6644omicron: '\u03BF',6645pi: '\u03C0',6646rho: '\u03C1',6647sigmaf: '\u03C2',6648sigma: '\u03C3',6649tau: '\u03C4',6650upsilon: '\u03C5',6651phi: '\u03C6',6652chi: '\u03C7',6653psi: '\u03C8',6654omega: '\u03C9',6655thetasym: '\u03D1',6656upsih: '\u03D2',6657piv: '\u03D6',6658ensp: '\u2002',6659emsp: '\u2003',6660thinsp: '\u2009',6661zwnj: '\u200C',6662zwj: '\u200D',6663lrm: '\u200E',6664rlm: '\u200F',6665ndash: '\u2013',6666mdash: '\u2014',6667lsquo: '\u2018',6668rsquo: '\u2019',6669sbquo: '\u201A',6670ldquo: '\u201C',6671rdquo: '\u201D',6672bdquo: '\u201E',6673dagger: '\u2020',6674Dagger: '\u2021',6675bull: '\u2022',6676hellip: '\u2026',6677permil: '\u2030',6678prime: '\u2032',6679Prime: '\u2033',6680lsaquo: '\u2039',6681rsaquo: '\u203A',6682oline: '\u203E',6683frasl: '\u2044',6684euro: '\u20AC',6685image: '\u2111',6686weierp: '\u2118',6687real: '\u211C',6688trade: '\u2122',6689alefsym: '\u2135',6690larr: '\u2190',6691uarr: '\u2191',6692rarr: '\u2192',6693darr: '\u2193',6694harr: '\u2194',6695crarr: '\u21B5',6696lArr: '\u21D0',6697uArr: '\u21D1',6698rArr: '\u21D2',6699dArr: '\u21D3',6700hArr: '\u21D4',6701forall: '\u2200',6702part: '\u2202',6703exist: '\u2203',6704empty: '\u2205',6705nabla: '\u2207',6706isin: '\u2208',6707notin: '\u2209',6708ni: '\u220B',6709prod: '\u220F',6710sum: '\u2211',6711minus: '\u2212',6712lowast: '\u2217',6713radic: '\u221A',6714prop: '\u221D',6715infin: '\u221E',6716ang: '\u2220',6717and: '\u2227',6718or: '\u2228',6719cap: '\u2229',6720cup: '\u222A',6721'int': '\u222B',6722there4: '\u2234',6723sim: '\u223C',6724cong: '\u2245',6725asymp: '\u2248',6726ne: '\u2260',6727equiv: '\u2261',6728le: '\u2264',6729ge: '\u2265',6730sub: '\u2282',6731sup: '\u2283',6732nsub: '\u2284',6733sube: '\u2286',6734supe: '\u2287',6735oplus: '\u2295',6736otimes: '\u2297',6737perp: '\u22A5',6738sdot: '\u22C5',6739lceil: '\u2308',6740rceil: '\u2309',6741lfloor: '\u230A',6742rfloor: '\u230B',6743lang: '\u2329',6744rang: '\u232A',6745loz: '\u25CA',6746spades: '\u2660',6747clubs: '\u2663',6748hearts: '\u2665',6749diams: '\u2666'6750};67516752function getQualifiedJSXName(object) {6753if (object.type === Syntax.JSXIdentifier) {6754return object.name;6755}6756if (object.type === Syntax.JSXNamespacedName) {6757return object.namespace.name + ':' + object.name.name;6758}6759/* istanbul ignore else */6760if (object.type === Syntax.JSXMemberExpression) {6761return (6762getQualifiedJSXName(object.object) + '.' +6763getQualifiedJSXName(object.property)6764);6765}6766/* istanbul ignore next */6767throwUnexpected(object);6768}67696770function isJSXIdentifierStart(ch) {6771// exclude backslash (\)6772return (ch !== 92) && isIdentifierStart(ch);6773}67746775function isJSXIdentifierPart(ch) {6776// exclude backslash (\) and add hyphen (-)6777return (ch !== 92) && (ch === 45 || isIdentifierPart(ch));6778}67796780function scanJSXIdentifier() {6781var ch, start, value = '';67826783start = index;6784while (index < length) {6785ch = source.charCodeAt(index);6786if (!isJSXIdentifierPart(ch)) {6787break;6788}6789value += source[index++];6790}67916792return {6793type: Token.JSXIdentifier,6794value: value,6795lineNumber: lineNumber,6796lineStart: lineStart,6797range: [start, index]6798};6799}68006801function scanJSXEntity() {6802var ch, str = '', start = index, count = 0, code;6803ch = source[index];6804assert(ch === '&', 'Entity must start with an ampersand');6805index++;6806while (index < length && count++ < 10) {6807ch = source[index++];6808if (ch === ';') {6809break;6810}6811str += ch;6812}68136814// Well-formed entity (ending was found).6815if (ch === ';') {6816// Numeric entity.6817if (str[0] === '#') {6818if (str[1] === 'x') {6819code = +('0' + str.substr(1));6820} else {6821// Removing leading zeros in order to avoid treating as octal in old browsers.6822code = +str.substr(1).replace(Regex.LeadingZeros, '');6823}68246825if (!isNaN(code)) {6826return String.fromCharCode(code);6827}6828/* istanbul ignore else */6829} else if (XHTMLEntities[str]) {6830return XHTMLEntities[str];6831}6832}68336834// Treat non-entity sequences as regular text.6835index = start + 1;6836return '&';6837}68386839function scanJSXText(stopChars) {6840var ch, str = '', start;6841start = index;6842while (index < length) {6843ch = source[index];6844if (stopChars.indexOf(ch) !== -1) {6845break;6846}6847if (ch === '&') {6848str += scanJSXEntity();6849} else {6850index++;6851if (ch === '\r' && source[index] === '\n') {6852str += ch;6853ch = source[index];6854index++;6855}6856if (isLineTerminator(ch.charCodeAt(0))) {6857++lineNumber;6858lineStart = index;6859}6860str += ch;6861}6862}6863return {6864type: Token.JSXText,6865value: str,6866lineNumber: lineNumber,6867lineStart: lineStart,6868range: [start, index]6869};6870}68716872function scanJSXStringLiteral() {6873var innerToken, quote, start;68746875quote = source[index];6876assert((quote === '\'' || quote === '"'),6877'String literal must starts with a quote');68786879start = index;6880++index;68816882innerToken = scanJSXText([quote]);68836884if (quote !== source[index]) {6885throwError({}, Messages.UnexpectedToken, 'ILLEGAL');6886}68876888++index;68896890innerToken.range = [start, index];68916892return innerToken;6893}68946895/**6896* Between JSX opening and closing tags (e.g. <foo>HERE</foo>), anything that6897* is not another JSX tag and is not an expression wrapped by {} is text.6898*/6899function advanceJSXChild() {6900var ch = source.charCodeAt(index);69016902// '<' 60, '>' 62, '{' 123, '}' 1256903if (ch !== 60 && ch !== 62 && ch !== 123 && ch !== 125) {6904return scanJSXText(['<', '>', '{', '}']);6905}69066907return scanPunctuator();6908}69096910function parseJSXIdentifier() {6911var token, marker = markerCreate();69126913if (lookahead.type !== Token.JSXIdentifier) {6914throwUnexpected(lookahead);6915}69166917token = lex();6918return markerApply(marker, delegate.createJSXIdentifier(token.value));6919}69206921function parseJSXNamespacedName() {6922var namespace, name, marker = markerCreate();69236924namespace = parseJSXIdentifier();6925expect(':');6926name = parseJSXIdentifier();69276928return markerApply(marker, delegate.createJSXNamespacedName(namespace, name));6929}69306931function parseJSXMemberExpression() {6932var marker = markerCreate(),6933expr = parseJSXIdentifier();69346935while (match('.')) {6936lex();6937expr = markerApply(marker, delegate.createJSXMemberExpression(expr, parseJSXIdentifier()));6938}69396940return expr;6941}69426943function parseJSXElementName() {6944if (lookahead2().value === ':') {6945return parseJSXNamespacedName();6946}6947if (lookahead2().value === '.') {6948return parseJSXMemberExpression();6949}69506951return parseJSXIdentifier();6952}69536954function parseJSXAttributeName() {6955if (lookahead2().value === ':') {6956return parseJSXNamespacedName();6957}69586959return parseJSXIdentifier();6960}69616962function parseJSXAttributeValue() {6963var value, marker;6964if (match('{')) {6965value = parseJSXExpressionContainer();6966if (value.expression.type === Syntax.JSXEmptyExpression) {6967throwError(6968value,6969'JSX attributes must only be assigned a non-empty ' +6970'expression'6971);6972}6973} else if (match('<')) {6974value = parseJSXElement();6975} else if (lookahead.type === Token.JSXText) {6976marker = markerCreate();6977value = markerApply(marker, delegate.createLiteral(lex()));6978} else {6979throwError({}, Messages.InvalidJSXAttributeValue);6980}6981return value;6982}69836984function parseJSXEmptyExpression() {6985var marker = markerCreatePreserveWhitespace();6986while (source.charAt(index) !== '}') {6987index++;6988}6989return markerApply(marker, delegate.createJSXEmptyExpression());6990}69916992function parseJSXExpressionContainer() {6993var expression, origInJSXChild, origInJSXTag, marker = markerCreate();69946995origInJSXChild = state.inJSXChild;6996origInJSXTag = state.inJSXTag;6997state.inJSXChild = false;6998state.inJSXTag = false;69997000expect('{');70017002if (match('}')) {7003expression = parseJSXEmptyExpression();7004} else {7005expression = parseExpression();7006}70077008state.inJSXChild = origInJSXChild;7009state.inJSXTag = origInJSXTag;70107011expect('}');70127013return markerApply(marker, delegate.createJSXExpressionContainer(expression));7014}70157016function parseJSXSpreadAttribute() {7017var expression, origInJSXChild, origInJSXTag, marker = markerCreate();70187019origInJSXChild = state.inJSXChild;7020origInJSXTag = state.inJSXTag;7021state.inJSXChild = false;7022state.inJSXTag = false;70237024expect('{');7025expect('...');70267027expression = parseAssignmentExpression();70287029state.inJSXChild = origInJSXChild;7030state.inJSXTag = origInJSXTag;70317032expect('}');70337034return markerApply(marker, delegate.createJSXSpreadAttribute(expression));7035}70367037function parseJSXAttribute() {7038var name, marker;70397040if (match('{')) {7041return parseJSXSpreadAttribute();7042}70437044marker = markerCreate();70457046name = parseJSXAttributeName();70477048// HTML empty attribute7049if (match('=')) {7050lex();7051return markerApply(marker, delegate.createJSXAttribute(name, parseJSXAttributeValue()));7052}70537054return markerApply(marker, delegate.createJSXAttribute(name));7055}70567057function parseJSXChild() {7058var token, marker;7059if (match('{')) {7060token = parseJSXExpressionContainer();7061} else if (lookahead.type === Token.JSXText) {7062marker = markerCreatePreserveWhitespace();7063token = markerApply(marker, delegate.createLiteral(lex()));7064} else if (match('<')) {7065token = parseJSXElement();7066} else {7067throwUnexpected(lookahead);7068}7069return token;7070}70717072function parseJSXClosingElement() {7073var name, origInJSXChild, origInJSXTag, marker = markerCreate();7074origInJSXChild = state.inJSXChild;7075origInJSXTag = state.inJSXTag;7076state.inJSXChild = false;7077state.inJSXTag = true;7078expect('<');7079expect('/');7080name = parseJSXElementName();7081// Because advance() (called by lex() called by expect()) expects there7082// to be a valid token after >, it needs to know whether to look for a7083// standard JS token or an JSX text node7084state.inJSXChild = origInJSXChild;7085state.inJSXTag = origInJSXTag;7086expect('>');7087return markerApply(marker, delegate.createJSXClosingElement(name));7088}70897090function parseJSXOpeningElement() {7091var name, attributes = [], selfClosing = false, origInJSXChild, origInJSXTag, marker = markerCreate();70927093origInJSXChild = state.inJSXChild;7094origInJSXTag = state.inJSXTag;7095state.inJSXChild = false;7096state.inJSXTag = true;70977098expect('<');70997100name = parseJSXElementName();71017102while (index < length &&7103lookahead.value !== '/' &&7104lookahead.value !== '>') {7105attributes.push(parseJSXAttribute());7106}71077108state.inJSXTag = origInJSXTag;71097110if (lookahead.value === '/') {7111expect('/');7112// Because advance() (called by lex() called by expect()) expects7113// there to be a valid token after >, it needs to know whether to7114// look for a standard JS token or an JSX text node7115state.inJSXChild = origInJSXChild;7116expect('>');7117selfClosing = true;7118} else {7119state.inJSXChild = true;7120expect('>');7121}7122return markerApply(marker, delegate.createJSXOpeningElement(name, attributes, selfClosing));7123}71247125function parseJSXElement() {7126var openingElement, closingElement = null, children = [], origInJSXChild, origInJSXTag, marker = markerCreate();71277128origInJSXChild = state.inJSXChild;7129origInJSXTag = state.inJSXTag;7130openingElement = parseJSXOpeningElement();71317132if (!openingElement.selfClosing) {7133while (index < length) {7134state.inJSXChild = false; // Call lookahead2() with inJSXChild = false because </ should not be considered in the child7135if (lookahead.value === '<' && lookahead2().value === '/') {7136break;7137}7138state.inJSXChild = true;7139children.push(parseJSXChild());7140}7141state.inJSXChild = origInJSXChild;7142state.inJSXTag = origInJSXTag;7143closingElement = parseJSXClosingElement();7144if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {7145throwError({}, Messages.ExpectedJSXClosingTag, getQualifiedJSXName(openingElement.name));7146}7147}71487149// When (erroneously) writing two adjacent tags like7150//7151// var x = <div>one</div><div>two</div>;7152//7153// the default error message is a bit incomprehensible. Since it's7154// rarely (never?) useful to write a less-than sign after an JSX7155// element, we disallow it here in the parser in order to provide a7156// better error message. (In the rare case that the less-than operator7157// was intended, the left tag can be wrapped in parentheses.)7158if (!origInJSXChild && match('<')) {7159throwError(lookahead, Messages.AdjacentJSXElements);7160}71617162return markerApply(marker, delegate.createJSXElement(openingElement, closingElement, children));7163}71647165function parseTypeAlias() {7166var id, marker = markerCreate(), typeParameters = null, right;7167expectContextualKeyword('type');7168id = parseVariableIdentifier();7169if (match('<')) {7170typeParameters = parseTypeParameterDeclaration();7171}7172expect('=');7173right = parseType();7174consumeSemicolon();7175return markerApply(marker, delegate.createTypeAlias(id, typeParameters, right));7176}71777178function parseInterfaceExtends() {7179var marker = markerCreate(), id, typeParameters = null;71807181id = parseVariableIdentifier();7182if (match('<')) {7183typeParameters = parseTypeParameterInstantiation();7184}71857186return markerApply(marker, delegate.createInterfaceExtends(7187id,7188typeParameters7189));7190}71917192function parseInterfaceish(marker, allowStatic) {7193var body, bodyMarker, extended = [], id,7194typeParameters = null;71957196id = parseVariableIdentifier();7197if (match('<')) {7198typeParameters = parseTypeParameterDeclaration();7199}72007201if (matchKeyword('extends')) {7202expectKeyword('extends');72037204while (index < length) {7205extended.push(parseInterfaceExtends());7206if (!match(',')) {7207break;7208}7209expect(',');7210}7211}72127213bodyMarker = markerCreate();7214body = markerApply(bodyMarker, parseObjectType(allowStatic));72157216return markerApply(marker, delegate.createInterface(7217id,7218typeParameters,7219body,7220extended7221));7222}72237224function parseInterface() {7225var marker = markerCreate();72267227if (strict) {7228expectKeyword('interface');7229} else {7230expectContextualKeyword('interface');7231}72327233return parseInterfaceish(marker, /* allowStatic */false);7234}72357236function parseDeclareClass() {7237var marker = markerCreate(), ret;7238expectContextualKeyword('declare');7239expectKeyword('class');72407241ret = parseInterfaceish(marker, /* allowStatic */true);7242ret.type = Syntax.DeclareClass;7243return ret;7244}72457246function parseDeclareFunction() {7247var id, idMarker,7248marker = markerCreate(), params, returnType, rest, tmp,7249typeParameters = null, value, valueMarker;72507251expectContextualKeyword('declare');7252expectKeyword('function');7253idMarker = markerCreate();7254id = parseVariableIdentifier();72557256valueMarker = markerCreate();7257if (match('<')) {7258typeParameters = parseTypeParameterDeclaration();7259}7260expect('(');7261tmp = parseFunctionTypeParams();7262params = tmp.params;7263rest = tmp.rest;7264expect(')');72657266expect(':');7267returnType = parseType();72687269value = markerApply(valueMarker, delegate.createFunctionTypeAnnotation(7270params,7271returnType,7272rest,7273typeParameters7274));72757276id.typeAnnotation = markerApply(valueMarker, delegate.createTypeAnnotation(7277value7278));7279markerApply(idMarker, id);72807281consumeSemicolon();72827283return markerApply(marker, delegate.createDeclareFunction(7284id7285));7286}72877288function parseDeclareVariable() {7289var id, marker = markerCreate();7290expectContextualKeyword('declare');7291expectKeyword('var');7292id = parseTypeAnnotatableIdentifier();72937294consumeSemicolon();72957296return markerApply(marker, delegate.createDeclareVariable(7297id7298));7299}73007301function parseDeclareModule() {7302var body = [], bodyMarker, id, idMarker, marker = markerCreate(), token;7303expectContextualKeyword('declare');7304expectContextualKeyword('module');73057306if (lookahead.type === Token.StringLiteral) {7307if (strict && lookahead.octal) {7308throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);7309}7310idMarker = markerCreate();7311id = markerApply(idMarker, delegate.createLiteral(lex()));7312} else {7313id = parseVariableIdentifier();7314}73157316bodyMarker = markerCreate();7317expect('{');7318while (index < length && !match('}')) {7319token = lookahead2();7320switch (token.value) {7321case 'class':7322body.push(parseDeclareClass());7323break;7324case 'function':7325body.push(parseDeclareFunction());7326break;7327case 'var':7328body.push(parseDeclareVariable());7329break;7330default:7331throwUnexpected(lookahead);7332}7333}7334expect('}');73357336return markerApply(marker, delegate.createDeclareModule(7337id,7338markerApply(bodyMarker, delegate.createBlockStatement(body))7339));7340}73417342function collectToken() {7343var loc, token, range, value, entry;73447345/* istanbul ignore else */7346if (!state.inJSXChild) {7347skipComment();7348}73497350loc = {7351start: {7352line: lineNumber,7353column: index - lineStart7354}7355};73567357token = extra.advance();7358loc.end = {7359line: lineNumber,7360column: index - lineStart7361};73627363if (token.type !== Token.EOF) {7364range = [token.range[0], token.range[1]];7365value = source.slice(token.range[0], token.range[1]);7366entry = {7367type: TokenName[token.type],7368value: value,7369range: range,7370loc: loc7371};7372if (token.regex) {7373entry.regex = {7374pattern: token.regex.pattern,7375flags: token.regex.flags7376};7377}7378extra.tokens.push(entry);7379}73807381return token;7382}73837384function collectRegex() {7385var pos, loc, regex, token;73867387skipComment();73887389pos = index;7390loc = {7391start: {7392line: lineNumber,7393column: index - lineStart7394}7395};73967397regex = extra.scanRegExp();7398loc.end = {7399line: lineNumber,7400column: index - lineStart7401};74027403if (!extra.tokenize) {7404/* istanbul ignore next */7405// Pop the previous token, which is likely '/' or '/='7406if (extra.tokens.length > 0) {7407token = extra.tokens[extra.tokens.length - 1];7408if (token.range[0] === pos && token.type === 'Punctuator') {7409if (token.value === '/' || token.value === '/=') {7410extra.tokens.pop();7411}7412}7413}74147415extra.tokens.push({7416type: 'RegularExpression',7417value: regex.literal,7418regex: regex.regex,7419range: [pos, index],7420loc: loc7421});7422}74237424return regex;7425}74267427function filterTokenLocation() {7428var i, entry, token, tokens = [];74297430for (i = 0; i < extra.tokens.length; ++i) {7431entry = extra.tokens[i];7432token = {7433type: entry.type,7434value: entry.value7435};7436if (entry.regex) {7437token.regex = {7438pattern: entry.regex.pattern,7439flags: entry.regex.flags7440};7441}7442if (extra.range) {7443token.range = entry.range;7444}7445if (extra.loc) {7446token.loc = entry.loc;7447}7448tokens.push(token);7449}74507451extra.tokens = tokens;7452}74537454function patch() {7455if (typeof extra.tokens !== 'undefined') {7456extra.advance = advance;7457extra.scanRegExp = scanRegExp;74587459advance = collectToken;7460scanRegExp = collectRegex;7461}7462}74637464function unpatch() {7465if (typeof extra.scanRegExp === 'function') {7466advance = extra.advance;7467scanRegExp = extra.scanRegExp;7468}7469}74707471// This is used to modify the delegate.74727473function extend(object, properties) {7474var entry, result = {};74757476for (entry in object) {7477/* istanbul ignore else */7478if (object.hasOwnProperty(entry)) {7479result[entry] = object[entry];7480}7481}74827483for (entry in properties) {7484/* istanbul ignore else */7485if (properties.hasOwnProperty(entry)) {7486result[entry] = properties[entry];7487}7488}74897490return result;7491}74927493function tokenize(code, options) {7494var toString,7495token,7496tokens;74977498toString = String;7499if (typeof code !== 'string' && !(code instanceof String)) {7500code = toString(code);7501}75027503delegate = SyntaxTreeDelegate;7504source = code;7505index = 0;7506lineNumber = (source.length > 0) ? 1 : 0;7507lineStart = 0;7508length = source.length;7509lookahead = null;7510state = {7511allowKeyword: true,7512allowIn: true,7513labelSet: new StringMap(),7514inFunctionBody: false,7515inIteration: false,7516inSwitch: false,7517lastCommentStart: -17518};75197520extra = {};75217522// Options matching.7523options = options || {};75247525// Of course we collect tokens here.7526options.tokens = true;7527extra.tokens = [];7528extra.tokenize = true;7529// The following two fields are necessary to compute the Regex tokens.7530extra.openParenToken = -1;7531extra.openCurlyToken = -1;75327533extra.range = (typeof options.range === 'boolean') && options.range;7534extra.loc = (typeof options.loc === 'boolean') && options.loc;75357536if (typeof options.comment === 'boolean' && options.comment) {7537extra.comments = [];7538}7539if (typeof options.tolerant === 'boolean' && options.tolerant) {7540extra.errors = [];7541}75427543patch();75447545try {7546peek();7547if (lookahead.type === Token.EOF) {7548return extra.tokens;7549}75507551token = lex();7552while (lookahead.type !== Token.EOF) {7553try {7554token = lex();7555} catch (lexError) {7556token = lookahead;7557if (extra.errors) {7558extra.errors.push(lexError);7559// We have to break on the first error7560// to avoid infinite loops.7561break;7562} else {7563throw lexError;7564}7565}7566}75677568filterTokenLocation();7569tokens = extra.tokens;7570if (typeof extra.comments !== 'undefined') {7571tokens.comments = extra.comments;7572}7573if (typeof extra.errors !== 'undefined') {7574tokens.errors = extra.errors;7575}7576} catch (e) {7577throw e;7578} finally {7579unpatch();7580extra = {};7581}7582return tokens;7583}75847585function parse(code, options) {7586var program, toString;75877588toString = String;7589if (typeof code !== 'string' && !(code instanceof String)) {7590code = toString(code);7591}75927593delegate = SyntaxTreeDelegate;7594source = code;7595index = 0;7596lineNumber = (source.length > 0) ? 1 : 0;7597lineStart = 0;7598length = source.length;7599lookahead = null;7600state = {7601allowKeyword: false,7602allowIn: true,7603labelSet: new StringMap(),7604parenthesizedCount: 0,7605inFunctionBody: false,7606inIteration: false,7607inSwitch: false,7608inJSXChild: false,7609inJSXTag: false,7610inType: false,7611lastCommentStart: -1,7612yieldAllowed: false,7613awaitAllowed: false7614};76157616extra = {};7617if (typeof options !== 'undefined') {7618extra.range = (typeof options.range === 'boolean') && options.range;7619extra.loc = (typeof options.loc === 'boolean') && options.loc;7620extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;76217622if (extra.loc && options.source !== null && options.source !== undefined) {7623delegate = extend(delegate, {7624'postProcess': function (node) {7625node.loc.source = toString(options.source);7626return node;7627}7628});7629}76307631extra.sourceType = options.sourceType;7632if (typeof options.tokens === 'boolean' && options.tokens) {7633extra.tokens = [];7634}7635if (typeof options.comment === 'boolean' && options.comment) {7636extra.comments = [];7637}7638if (typeof options.tolerant === 'boolean' && options.tolerant) {7639extra.errors = [];7640}7641if (extra.attachComment) {7642extra.range = true;7643extra.comments = [];7644extra.bottomRightStack = [];7645extra.trailingComments = [];7646extra.leadingComments = [];7647}7648}76497650patch();7651try {7652program = parseProgram();7653if (typeof extra.comments !== 'undefined') {7654program.comments = extra.comments;7655}7656if (typeof extra.tokens !== 'undefined') {7657filterTokenLocation();7658program.tokens = extra.tokens;7659}7660if (typeof extra.errors !== 'undefined') {7661program.errors = extra.errors;7662}7663} catch (e) {7664throw e;7665} finally {7666unpatch();7667extra = {};7668}76697670return program;7671}76727673// Sync with *.json manifests.7674exports.version = '13001.1001.0-dev-harmony-fb';76757676exports.tokenize = tokenize;76777678exports.parse = parse;76797680// Deep copy.7681/* istanbul ignore next */7682exports.Syntax = (function () {7683var name, types = {};76847685if (typeof Object.create === 'function') {7686types = Object.create(null);7687}76887689for (name in Syntax) {7690if (Syntax.hasOwnProperty(name)) {7691types[name] = Syntax[name];7692}7693}76947695if (typeof Object.freeze === 'function') {7696Object.freeze(types);7697}76987699return types;7700}());77017702}));7703/* vim: set sw=4 ts=4 et tw=80 : */770477057706