acorn.es.js 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696
  1. // Reserved word lists for various dialects of the language
  2. var reservedWords = {
  3. 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
  4. 5: "class enum extends super const export import",
  5. 6: "enum",
  6. strict: "implements interface let package private protected public static yield",
  7. strictBind: "eval arguments"
  8. };
  9. // And the keywords
  10. var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
  11. var keywords = {
  12. 5: ecma5AndLessKeywords,
  13. 6: ecma5AndLessKeywords + " const class extends export import super"
  14. };
  15. // ## Character categories
  16. // Big ugly regular expressions that match characters in the
  17. // whitespace, identifier, and identifier-start categories. These
  18. // are only applied when a character is found to actually have a
  19. // code point above 128.
  20. // Generated by `bin/generate-identifier-regex.js`.
  21. var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\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-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\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\u0af9\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-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\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-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\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\u2118-\u211d\u2124\u2126\u2128\u212a-\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\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fd5\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ae\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\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";
  22. var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d4-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d01-\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf8\u1cf9\u1dc0-\u1df5\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  23. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  24. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  25. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  26. // These are a run-length and offset encoded representation of the
  27. // >0xffff code points that are a valid part of identifiers. The
  28. // offset starts at 0x10000, and each pair of numbers represents an
  29. // offset to the next range, and then a size of the range. They were
  30. // generated by bin/generate-identifier-regex.js
  31. // eslint-disable-next-line comma-spacing
  32. var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,264,8,2,36,18,0,50,29,881,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,0,32,6124,20,754,9486,1,3071,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,10591,541];
  33. // eslint-disable-next-line comma-spacing
  34. var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,838,7,2,7,17,9,57,21,2,13,19882,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239];
  35. // This has a complexity linear to the value of the code. The
  36. // assumption is that looking up astral identifier characters is
  37. // rare.
  38. function isInAstralSet(code, set) {
  39. var pos = 0x10000;
  40. for (var i = 0; i < set.length; i += 2) {
  41. pos += set[i];
  42. if (pos > code) { return false }
  43. pos += set[i + 1];
  44. if (pos >= code) { return true }
  45. }
  46. }
  47. // Test whether a given character code starts an identifier.
  48. function isIdentifierStart(code, astral) {
  49. if (code < 65) { return code === 36 }
  50. if (code < 91) { return true }
  51. if (code < 97) { return code === 95 }
  52. if (code < 123) { return true }
  53. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  54. if (astral === false) { return false }
  55. return isInAstralSet(code, astralIdentifierStartCodes)
  56. }
  57. // Test whether a given character is part of an identifier.
  58. function isIdentifierChar(code, astral) {
  59. if (code < 48) { return code === 36 }
  60. if (code < 58) { return true }
  61. if (code < 65) { return false }
  62. if (code < 91) { return true }
  63. if (code < 97) { return code === 95 }
  64. if (code < 123) { return true }
  65. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  66. if (astral === false) { return false }
  67. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  68. }
  69. // ## Token types
  70. // The assignment of fine-grained, information-carrying type objects
  71. // allows the tokenizer to store the information it has about a
  72. // token in a way that is very cheap for the parser to look up.
  73. // All token type variables start with an underscore, to make them
  74. // easy to recognize.
  75. // The `beforeExpr` property is used to disambiguate between regular
  76. // expressions and divisions. It is set on all token types that can
  77. // be followed by an expression (thus, a slash after them would be a
  78. // regular expression).
  79. //
  80. // The `startsExpr` property is used to check if the token ends a
  81. // `yield` expression. It is set on all token types that either can
  82. // directly start an expression (like a quotation mark) or can
  83. // continue an expression (like the body of a string).
  84. //
  85. // `isLoop` marks a keyword as starting a loop, which is important
  86. // to know when parsing a label, in order to allow or disallow
  87. // continue jumps to that label.
  88. var TokenType = function TokenType(label, conf) {
  89. if ( conf === void 0 ) conf = {};
  90. this.label = label;
  91. this.keyword = conf.keyword;
  92. this.beforeExpr = !!conf.beforeExpr;
  93. this.startsExpr = !!conf.startsExpr;
  94. this.isLoop = !!conf.isLoop;
  95. this.isAssign = !!conf.isAssign;
  96. this.prefix = !!conf.prefix;
  97. this.postfix = !!conf.postfix;
  98. this.binop = conf.binop || null;
  99. this.updateContext = null;
  100. };
  101. function binop(name, prec) {
  102. return new TokenType(name, {beforeExpr: true, binop: prec})
  103. }
  104. var beforeExpr = {beforeExpr: true};
  105. var startsExpr = {startsExpr: true};
  106. // Map keyword names to token types.
  107. var keywords$1 = {};
  108. // Succinct definitions of keyword token types
  109. function kw(name, options) {
  110. if ( options === void 0 ) options = {};
  111. options.keyword = name;
  112. return keywords$1[name] = new TokenType(name, options)
  113. }
  114. var types = {
  115. num: new TokenType("num", startsExpr),
  116. regexp: new TokenType("regexp", startsExpr),
  117. string: new TokenType("string", startsExpr),
  118. name: new TokenType("name", startsExpr),
  119. eof: new TokenType("eof"),
  120. // Punctuation token types.
  121. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  122. bracketR: new TokenType("]"),
  123. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  124. braceR: new TokenType("}"),
  125. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  126. parenR: new TokenType(")"),
  127. comma: new TokenType(",", beforeExpr),
  128. semi: new TokenType(";", beforeExpr),
  129. colon: new TokenType(":", beforeExpr),
  130. dot: new TokenType("."),
  131. question: new TokenType("?", beforeExpr),
  132. arrow: new TokenType("=>", beforeExpr),
  133. template: new TokenType("template"),
  134. invalidTemplate: new TokenType("invalidTemplate"),
  135. ellipsis: new TokenType("...", beforeExpr),
  136. backQuote: new TokenType("`", startsExpr),
  137. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  138. // Operators. These carry several kinds of properties to help the
  139. // parser use them properly (the presence of these properties is
  140. // what categorizes them as operators).
  141. //
  142. // `binop`, when present, specifies that this operator is a binary
  143. // operator, and will refer to its precedence.
  144. //
  145. // `prefix` and `postfix` mark the operator as a prefix or postfix
  146. // unary operator.
  147. //
  148. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  149. // binary operators with a very low precedence, that should result
  150. // in AssignmentExpression nodes.
  151. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  152. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  153. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  154. prefix: new TokenType("prefix", {beforeExpr: true, prefix: true, startsExpr: true}),
  155. logicalOR: binop("||", 1),
  156. logicalAND: binop("&&", 2),
  157. bitwiseOR: binop("|", 3),
  158. bitwiseXOR: binop("^", 4),
  159. bitwiseAND: binop("&", 5),
  160. equality: binop("==/!=", 6),
  161. relational: binop("</>", 7),
  162. bitShift: binop("<</>>", 8),
  163. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  164. modulo: binop("%", 10),
  165. star: binop("*", 10),
  166. slash: binop("/", 10),
  167. starstar: new TokenType("**", {beforeExpr: true}),
  168. // Keyword token types.
  169. _break: kw("break"),
  170. _case: kw("case", beforeExpr),
  171. _catch: kw("catch"),
  172. _continue: kw("continue"),
  173. _debugger: kw("debugger"),
  174. _default: kw("default", beforeExpr),
  175. _do: kw("do", {isLoop: true, beforeExpr: true}),
  176. _else: kw("else", beforeExpr),
  177. _finally: kw("finally"),
  178. _for: kw("for", {isLoop: true}),
  179. _function: kw("function", startsExpr),
  180. _if: kw("if"),
  181. _return: kw("return", beforeExpr),
  182. _switch: kw("switch"),
  183. _throw: kw("throw", beforeExpr),
  184. _try: kw("try"),
  185. _var: kw("var"),
  186. _const: kw("const"),
  187. _while: kw("while", {isLoop: true}),
  188. _with: kw("with"),
  189. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  190. _this: kw("this", startsExpr),
  191. _super: kw("super", startsExpr),
  192. _class: kw("class", startsExpr),
  193. _extends: kw("extends", beforeExpr),
  194. _export: kw("export"),
  195. _import: kw("import"),
  196. _null: kw("null", startsExpr),
  197. _true: kw("true", startsExpr),
  198. _false: kw("false", startsExpr),
  199. _in: kw("in", {beforeExpr: true, binop: 7}),
  200. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  201. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  202. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  203. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  204. };
  205. // Matches a whole line break (where CRLF is considered a single
  206. // line break). Used to count lines.
  207. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  208. var lineBreakG = new RegExp(lineBreak.source, "g");
  209. function isNewLine(code) {
  210. return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
  211. }
  212. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  213. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  214. var ref = Object.prototype;
  215. var hasOwnProperty = ref.hasOwnProperty;
  216. var toString = ref.toString;
  217. // Checks if an object has a property.
  218. function has(obj, propName) {
  219. return hasOwnProperty.call(obj, propName)
  220. }
  221. var isArray = Array.isArray || (function (obj) { return (
  222. toString.call(obj) === "[object Array]"
  223. ); });
  224. // These are used when `options.locations` is on, for the
  225. // `startLoc` and `endLoc` properties.
  226. var Position = function Position(line, col) {
  227. this.line = line;
  228. this.column = col;
  229. };
  230. Position.prototype.offset = function offset (n) {
  231. return new Position(this.line, this.column + n)
  232. };
  233. var SourceLocation = function SourceLocation(p, start, end) {
  234. this.start = start;
  235. this.end = end;
  236. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  237. };
  238. // The `getLineInfo` function is mostly useful when the
  239. // `locations` option is off (for performance reasons) and you
  240. // want to find the line/column position for a given character
  241. // offset. `input` should be the code string that the offset refers
  242. // into.
  243. function getLineInfo(input, offset) {
  244. for (var line = 1, cur = 0;;) {
  245. lineBreakG.lastIndex = cur;
  246. var match = lineBreakG.exec(input);
  247. if (match && match.index < offset) {
  248. ++line;
  249. cur = match.index + match[0].length;
  250. } else {
  251. return new Position(line, offset - cur)
  252. }
  253. }
  254. }
  255. // A second optional argument can be given to further configure
  256. // the parser process. These options are recognized:
  257. var defaultOptions = {
  258. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  259. // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
  260. // for strict mode, the set of reserved words, and support for
  261. // new syntax features. The default is 7.
  262. ecmaVersion: 7,
  263. // `sourceType` indicates the mode the code should be parsed in.
  264. // Can be either `"script"` or `"module"`. This influences global
  265. // strict mode and parsing of `import` and `export` declarations.
  266. sourceType: "script",
  267. // `onInsertedSemicolon` can be a callback that will be called
  268. // when a semicolon is automatically inserted. It will be passed
  269. // th position of the comma as an offset, and if `locations` is
  270. // enabled, it is given the location as a `{line, column}` object
  271. // as second argument.
  272. onInsertedSemicolon: null,
  273. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  274. // trailing commas.
  275. onTrailingComma: null,
  276. // By default, reserved words are only enforced if ecmaVersion >= 5.
  277. // Set `allowReserved` to a boolean value to explicitly turn this on
  278. // an off. When this option has the value "never", reserved words
  279. // and keywords can also not be used as property names.
  280. allowReserved: null,
  281. // When enabled, a return at the top level is not considered an
  282. // error.
  283. allowReturnOutsideFunction: false,
  284. // When enabled, import/export statements are not constrained to
  285. // appearing at the top of the program.
  286. allowImportExportEverywhere: false,
  287. // When enabled, hashbang directive in the beginning of file
  288. // is allowed and treated as a line comment.
  289. allowHashBang: false,
  290. // When `locations` is on, `loc` properties holding objects with
  291. // `start` and `end` properties in `{line, column}` form (with
  292. // line being 1-based and column 0-based) will be attached to the
  293. // nodes.
  294. locations: false,
  295. // A function can be passed as `onToken` option, which will
  296. // cause Acorn to call that function with object in the same
  297. // format as tokens returned from `tokenizer().getToken()`. Note
  298. // that you are not allowed to call the parser from the
  299. // callback—that will corrupt its internal state.
  300. onToken: null,
  301. // A function can be passed as `onComment` option, which will
  302. // cause Acorn to call that function with `(block, text, start,
  303. // end)` parameters whenever a comment is skipped. `block` is a
  304. // boolean indicating whether this is a block (`/* */`) comment,
  305. // `text` is the content of the comment, and `start` and `end` are
  306. // character offsets that denote the start and end of the comment.
  307. // When the `locations` option is on, two more parameters are
  308. // passed, the full `{line, column}` locations of the start and
  309. // end of the comments. Note that you are not allowed to call the
  310. // parser from the callback—that will corrupt its internal state.
  311. onComment: null,
  312. // Nodes have their start and end characters offsets recorded in
  313. // `start` and `end` properties (directly on the node, rather than
  314. // the `loc` object, which holds line/column data. To also add a
  315. // [semi-standardized][range] `range` property holding a `[start,
  316. // end]` array with the same numbers, set the `ranges` option to
  317. // `true`.
  318. //
  319. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  320. ranges: false,
  321. // It is possible to parse multiple files into a single AST by
  322. // passing the tree produced by parsing the first file as
  323. // `program` option in subsequent parses. This will add the
  324. // toplevel forms of the parsed file to the `Program` (top) node
  325. // of an existing parse tree.
  326. program: null,
  327. // When `locations` is on, you can pass this to record the source
  328. // file in every node's `loc` object.
  329. sourceFile: null,
  330. // This value, if given, is stored in every node, whether
  331. // `locations` is on or off.
  332. directSourceFile: null,
  333. // When enabled, parenthesized expressions are represented by
  334. // (non-standard) ParenthesizedExpression nodes
  335. preserveParens: false,
  336. plugins: {}
  337. };
  338. // Interpret and default an options object
  339. function getOptions(opts) {
  340. var options = {};
  341. for (var opt in defaultOptions)
  342. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  343. if (options.ecmaVersion >= 2015)
  344. { options.ecmaVersion -= 2009; }
  345. if (options.allowReserved == null)
  346. { options.allowReserved = options.ecmaVersion < 5; }
  347. if (isArray(options.onToken)) {
  348. var tokens = options.onToken;
  349. options.onToken = function (token) { return tokens.push(token); };
  350. }
  351. if (isArray(options.onComment))
  352. { options.onComment = pushComment(options, options.onComment); }
  353. return options
  354. }
  355. function pushComment(options, array) {
  356. return function(block, text, start, end, startLoc, endLoc) {
  357. var comment = {
  358. type: block ? "Block" : "Line",
  359. value: text,
  360. start: start,
  361. end: end
  362. };
  363. if (options.locations)
  364. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  365. if (options.ranges)
  366. { comment.range = [start, end]; }
  367. array.push(comment);
  368. }
  369. }
  370. // Registered plugins
  371. var plugins = {};
  372. function keywordRegexp(words) {
  373. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  374. }
  375. var Parser = function Parser(options, input, startPos) {
  376. this.options = options = getOptions(options);
  377. this.sourceFile = options.sourceFile;
  378. this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  379. var reserved = "";
  380. if (!options.allowReserved) {
  381. for (var v = options.ecmaVersion;; v--)
  382. { if (reserved = reservedWords[v]) { break } }
  383. if (options.sourceType == "module") { reserved += " await"; }
  384. }
  385. this.reservedWords = keywordRegexp(reserved);
  386. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  387. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  388. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
  389. this.input = String(input);
  390. // Used to signal to callers of `readWord1` whether the word
  391. // contained any escape sequences. This is needed because words with
  392. // escape sequences must not be interpreted as keywords.
  393. this.containsEsc = false;
  394. // Load plugins
  395. this.loadPlugins(options.plugins);
  396. // Set up token state
  397. // The current position of the tokenizer in the input.
  398. if (startPos) {
  399. this.pos = startPos;
  400. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  401. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  402. } else {
  403. this.pos = this.lineStart = 0;
  404. this.curLine = 1;
  405. }
  406. // Properties of the current token:
  407. // Its type
  408. this.type = types.eof;
  409. // For tokens that include more information than their type, the value
  410. this.value = null;
  411. // Its start and end offset
  412. this.start = this.end = this.pos;
  413. // And, if locations are used, the {line, column} object
  414. // corresponding to those offsets
  415. this.startLoc = this.endLoc = this.curPosition();
  416. // Position information for the previous token
  417. this.lastTokEndLoc = this.lastTokStartLoc = null;
  418. this.lastTokStart = this.lastTokEnd = this.pos;
  419. // The context stack is used to superficially track syntactic
  420. // context to predict whether a regular expression is allowed in a
  421. // given position.
  422. this.context = this.initialContext();
  423. this.exprAllowed = true;
  424. // Figure out if it's a module code.
  425. this.inModule = options.sourceType === "module";
  426. this.strict = this.inModule || this.strictDirective(this.pos);
  427. // Used to signify the start of a potential arrow function
  428. this.potentialArrowAt = -1;
  429. // Flags to track whether we are in a function, a generator, an async function.
  430. this.inFunction = this.inGenerator = this.inAsync = false;
  431. // Positions to delayed-check that yield/await does not exist in default parameters.
  432. this.yieldPos = this.awaitPos = 0;
  433. // Labels in scope.
  434. this.labels = [];
  435. // If enabled, skip leading hashbang line.
  436. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  437. { this.skipLineComment(2); }
  438. // Scope tracking for duplicate variable names (see scope.js)
  439. this.scopeStack = [];
  440. this.enterFunctionScope();
  441. };
  442. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  443. Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
  444. Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
  445. Parser.prototype.extend = function extend (name, f) {
  446. this[name] = f(this[name]);
  447. };
  448. Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
  449. var this$1 = this;
  450. for (var name in pluginConfigs) {
  451. var plugin = plugins[name];
  452. if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
  453. plugin(this$1, pluginConfigs[name]);
  454. }
  455. };
  456. Parser.prototype.parse = function parse () {
  457. var node = this.options.program || this.startNode();
  458. this.nextToken();
  459. return this.parseTopLevel(node)
  460. };
  461. var pp = Parser.prototype;
  462. // ## Parser utilities
  463. var literal = /^(?:'((?:[^']|\.)*)'|"((?:[^"]|\.)*)"|;)/;
  464. pp.strictDirective = function(start) {
  465. var this$1 = this;
  466. for (;;) {
  467. skipWhiteSpace.lastIndex = start;
  468. start += skipWhiteSpace.exec(this$1.input)[0].length;
  469. var match = literal.exec(this$1.input.slice(start));
  470. if (!match) { return false }
  471. if ((match[1] || match[2]) == "use strict") { return true }
  472. start += match[0].length;
  473. }
  474. };
  475. // Predicate that tests whether the next token is of the given
  476. // type, and if yes, consumes it as a side effect.
  477. pp.eat = function(type) {
  478. if (this.type === type) {
  479. this.next();
  480. return true
  481. } else {
  482. return false
  483. }
  484. };
  485. // Tests whether parsed token is a contextual keyword.
  486. pp.isContextual = function(name) {
  487. return this.type === types.name && this.value === name
  488. };
  489. // Consumes contextual keyword if possible.
  490. pp.eatContextual = function(name) {
  491. return this.value === name && this.eat(types.name)
  492. };
  493. // Asserts that following token is given contextual keyword.
  494. pp.expectContextual = function(name) {
  495. if (!this.eatContextual(name)) { this.unexpected(); }
  496. };
  497. // Test whether a semicolon can be inserted at the current position.
  498. pp.canInsertSemicolon = function() {
  499. return this.type === types.eof ||
  500. this.type === types.braceR ||
  501. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  502. };
  503. pp.insertSemicolon = function() {
  504. if (this.canInsertSemicolon()) {
  505. if (this.options.onInsertedSemicolon)
  506. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  507. return true
  508. }
  509. };
  510. // Consume a semicolon, or, failing that, see if we are allowed to
  511. // pretend that there is a semicolon at this position.
  512. pp.semicolon = function() {
  513. if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
  514. };
  515. pp.afterTrailingComma = function(tokType, notNext) {
  516. if (this.type == tokType) {
  517. if (this.options.onTrailingComma)
  518. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  519. if (!notNext)
  520. { this.next(); }
  521. return true
  522. }
  523. };
  524. // Expect a token of a given type. If found, consume it, otherwise,
  525. // raise an unexpected token error.
  526. pp.expect = function(type) {
  527. this.eat(type) || this.unexpected();
  528. };
  529. // Raise an unexpected token error.
  530. pp.unexpected = function(pos) {
  531. this.raise(pos != null ? pos : this.start, "Unexpected token");
  532. };
  533. function DestructuringErrors() {
  534. this.shorthandAssign =
  535. this.trailingComma =
  536. this.parenthesizedAssign =
  537. this.parenthesizedBind =
  538. -1;
  539. }
  540. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  541. if (!refDestructuringErrors) { return }
  542. if (refDestructuringErrors.trailingComma > -1)
  543. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  544. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  545. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  546. };
  547. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  548. var pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1;
  549. if (!andThrow) { return pos >= 0 }
  550. if (pos > -1) { this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns"); }
  551. };
  552. pp.checkYieldAwaitInDefaultParams = function() {
  553. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  554. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  555. if (this.awaitPos)
  556. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  557. };
  558. pp.isSimpleAssignTarget = function(expr) {
  559. if (expr.type === "ParenthesizedExpression")
  560. { return this.isSimpleAssignTarget(expr.expression) }
  561. return expr.type === "Identifier" || expr.type === "MemberExpression"
  562. };
  563. var pp$1 = Parser.prototype;
  564. // ### Statement parsing
  565. // Parse a program. Initializes the parser, reads any number of
  566. // statements, and wraps them in a Program node. Optionally takes a
  567. // `program` argument. If present, the statements will be appended
  568. // to its body instead of creating a new node.
  569. pp$1.parseTopLevel = function(node) {
  570. var this$1 = this;
  571. var exports = {};
  572. if (!node.body) { node.body = []; }
  573. while (this.type !== types.eof) {
  574. var stmt = this$1.parseStatement(true, true, exports);
  575. node.body.push(stmt);
  576. }
  577. this.next();
  578. if (this.options.ecmaVersion >= 6) {
  579. node.sourceType = this.options.sourceType;
  580. }
  581. return this.finishNode(node, "Program")
  582. };
  583. var loopLabel = {kind: "loop"};
  584. var switchLabel = {kind: "switch"};
  585. pp$1.isLet = function() {
  586. if (this.type !== types.name || this.options.ecmaVersion < 6 || this.value != "let") { return false }
  587. skipWhiteSpace.lastIndex = this.pos;
  588. var skip = skipWhiteSpace.exec(this.input);
  589. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  590. if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
  591. if (isIdentifierStart(nextCh, true)) {
  592. var pos = next + 1;
  593. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  594. var ident = this.input.slice(next, pos);
  595. if (!this.isKeyword(ident)) { return true }
  596. }
  597. return false
  598. };
  599. // check 'async [no LineTerminator here] function'
  600. // - 'async /*foo*/ function' is OK.
  601. // - 'async /*\n*/ function' is invalid.
  602. pp$1.isAsyncFunction = function() {
  603. if (this.type !== types.name || this.options.ecmaVersion < 8 || this.value != "async")
  604. { return false }
  605. skipWhiteSpace.lastIndex = this.pos;
  606. var skip = skipWhiteSpace.exec(this.input);
  607. var next = this.pos + skip[0].length;
  608. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  609. this.input.slice(next, next + 8) === "function" &&
  610. (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  611. };
  612. // Parse a single statement.
  613. //
  614. // If expecting a statement and finding a slash operator, parse a
  615. // regular expression literal. This is to handle cases like
  616. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  617. // does not help.
  618. pp$1.parseStatement = function(declaration, topLevel, exports) {
  619. var starttype = this.type, node = this.startNode(), kind;
  620. if (this.isLet()) {
  621. starttype = types._var;
  622. kind = "let";
  623. }
  624. // Most types of statements are recognized by the keyword they
  625. // start with. Many are trivial to parse, some require a bit of
  626. // complexity.
  627. switch (starttype) {
  628. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  629. case types._debugger: return this.parseDebuggerStatement(node)
  630. case types._do: return this.parseDoStatement(node)
  631. case types._for: return this.parseForStatement(node)
  632. case types._function:
  633. if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
  634. return this.parseFunctionStatement(node, false)
  635. case types._class:
  636. if (!declaration) { this.unexpected(); }
  637. return this.parseClass(node, true)
  638. case types._if: return this.parseIfStatement(node)
  639. case types._return: return this.parseReturnStatement(node)
  640. case types._switch: return this.parseSwitchStatement(node)
  641. case types._throw: return this.parseThrowStatement(node)
  642. case types._try: return this.parseTryStatement(node)
  643. case types._const: case types._var:
  644. kind = kind || this.value;
  645. if (!declaration && kind != "var") { this.unexpected(); }
  646. return this.parseVarStatement(node, kind)
  647. case types._while: return this.parseWhileStatement(node)
  648. case types._with: return this.parseWithStatement(node)
  649. case types.braceL: return this.parseBlock()
  650. case types.semi: return this.parseEmptyStatement(node)
  651. case types._export:
  652. case types._import:
  653. if (!this.options.allowImportExportEverywhere) {
  654. if (!topLevel)
  655. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  656. if (!this.inModule)
  657. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  658. }
  659. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  660. // If the statement does not start with a statement keyword or a
  661. // brace, it's an ExpressionStatement or LabeledStatement. We
  662. // simply start parsing an expression, and afterwards, if the
  663. // next token is a colon and the expression was a simple
  664. // Identifier node, we switch to interpreting it as a label.
  665. default:
  666. if (this.isAsyncFunction() && declaration) {
  667. this.next();
  668. return this.parseFunctionStatement(node, true)
  669. }
  670. var maybeName = this.value, expr = this.parseExpression();
  671. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  672. { return this.parseLabeledStatement(node, maybeName, expr) }
  673. else { return this.parseExpressionStatement(node, expr) }
  674. }
  675. };
  676. pp$1.parseBreakContinueStatement = function(node, keyword) {
  677. var this$1 = this;
  678. var isBreak = keyword == "break";
  679. this.next();
  680. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  681. else if (this.type !== types.name) { this.unexpected(); }
  682. else {
  683. node.label = this.parseIdent();
  684. this.semicolon();
  685. }
  686. // Verify that there is an actual destination to break or
  687. // continue to.
  688. var i = 0;
  689. for (; i < this.labels.length; ++i) {
  690. var lab = this$1.labels[i];
  691. if (node.label == null || lab.name === node.label.name) {
  692. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  693. if (node.label && isBreak) { break }
  694. }
  695. }
  696. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  697. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  698. };
  699. pp$1.parseDebuggerStatement = function(node) {
  700. this.next();
  701. this.semicolon();
  702. return this.finishNode(node, "DebuggerStatement")
  703. };
  704. pp$1.parseDoStatement = function(node) {
  705. this.next();
  706. this.labels.push(loopLabel);
  707. node.body = this.parseStatement(false);
  708. this.labels.pop();
  709. this.expect(types._while);
  710. node.test = this.parseParenExpression();
  711. if (this.options.ecmaVersion >= 6)
  712. { this.eat(types.semi); }
  713. else
  714. { this.semicolon(); }
  715. return this.finishNode(node, "DoWhileStatement")
  716. };
  717. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  718. // loop is non-trivial. Basically, we have to parse the init `var`
  719. // statement or expression, disallowing the `in` operator (see
  720. // the second parameter to `parseExpression`), and then check
  721. // whether the next token is `in` or `of`. When there is no init
  722. // part (semicolon immediately after the opening parenthesis), it
  723. // is a regular `for` loop.
  724. pp$1.parseForStatement = function(node) {
  725. this.next();
  726. this.labels.push(loopLabel);
  727. this.enterLexicalScope();
  728. this.expect(types.parenL);
  729. if (this.type === types.semi) { return this.parseFor(node, null) }
  730. var isLet = this.isLet();
  731. if (this.type === types._var || this.type === types._const || isLet) {
  732. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  733. this.next();
  734. this.parseVar(init$1, true, kind);
  735. this.finishNode(init$1, "VariableDeclaration");
  736. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
  737. !(kind !== "var" && init$1.declarations[0].init))
  738. { return this.parseForIn(node, init$1) }
  739. return this.parseFor(node, init$1)
  740. }
  741. var refDestructuringErrors = new DestructuringErrors;
  742. var init = this.parseExpression(true, refDestructuringErrors);
  743. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  744. this.toAssignable(init);
  745. this.checkLVal(init);
  746. this.checkPatternErrors(refDestructuringErrors, true);
  747. return this.parseForIn(node, init)
  748. } else {
  749. this.checkExpressionErrors(refDestructuringErrors, true);
  750. }
  751. return this.parseFor(node, init)
  752. };
  753. pp$1.parseFunctionStatement = function(node, isAsync) {
  754. this.next();
  755. return this.parseFunction(node, true, false, isAsync)
  756. };
  757. pp$1.isFunction = function() {
  758. return this.type === types._function || this.isAsyncFunction()
  759. };
  760. pp$1.parseIfStatement = function(node) {
  761. this.next();
  762. node.test = this.parseParenExpression();
  763. // allow function declarations in branches, but only in non-strict mode
  764. node.consequent = this.parseStatement(!this.strict && this.isFunction());
  765. node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.isFunction()) : null;
  766. return this.finishNode(node, "IfStatement")
  767. };
  768. pp$1.parseReturnStatement = function(node) {
  769. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  770. { this.raise(this.start, "'return' outside of function"); }
  771. this.next();
  772. // In `return` (and `break`/`continue`), the keywords with
  773. // optional arguments, we eagerly look for a semicolon or the
  774. // possibility to insert one.
  775. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  776. else { node.argument = this.parseExpression(); this.semicolon(); }
  777. return this.finishNode(node, "ReturnStatement")
  778. };
  779. pp$1.parseSwitchStatement = function(node) {
  780. var this$1 = this;
  781. this.next();
  782. node.discriminant = this.parseParenExpression();
  783. node.cases = [];
  784. this.expect(types.braceL);
  785. this.labels.push(switchLabel);
  786. this.enterLexicalScope();
  787. // Statements under must be grouped (by label) in SwitchCase
  788. // nodes. `cur` is used to keep the node that we are currently
  789. // adding statements to.
  790. var cur;
  791. for (var sawDefault = false; this.type != types.braceR;) {
  792. if (this$1.type === types._case || this$1.type === types._default) {
  793. var isCase = this$1.type === types._case;
  794. if (cur) { this$1.finishNode(cur, "SwitchCase"); }
  795. node.cases.push(cur = this$1.startNode());
  796. cur.consequent = [];
  797. this$1.next();
  798. if (isCase) {
  799. cur.test = this$1.parseExpression();
  800. } else {
  801. if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
  802. sawDefault = true;
  803. cur.test = null;
  804. }
  805. this$1.expect(types.colon);
  806. } else {
  807. if (!cur) { this$1.unexpected(); }
  808. cur.consequent.push(this$1.parseStatement(true));
  809. }
  810. }
  811. this.exitLexicalScope();
  812. if (cur) { this.finishNode(cur, "SwitchCase"); }
  813. this.next(); // Closing brace
  814. this.labels.pop();
  815. return this.finishNode(node, "SwitchStatement")
  816. };
  817. pp$1.parseThrowStatement = function(node) {
  818. this.next();
  819. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  820. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  821. node.argument = this.parseExpression();
  822. this.semicolon();
  823. return this.finishNode(node, "ThrowStatement")
  824. };
  825. // Reused empty array added for node fields that are always empty.
  826. var empty = [];
  827. pp$1.parseTryStatement = function(node) {
  828. this.next();
  829. node.block = this.parseBlock();
  830. node.handler = null;
  831. if (this.type === types._catch) {
  832. var clause = this.startNode();
  833. this.next();
  834. this.expect(types.parenL);
  835. clause.param = this.parseBindingAtom();
  836. this.enterLexicalScope();
  837. this.checkLVal(clause.param, "let");
  838. this.expect(types.parenR);
  839. clause.body = this.parseBlock(false);
  840. this.exitLexicalScope();
  841. node.handler = this.finishNode(clause, "CatchClause");
  842. }
  843. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  844. if (!node.handler && !node.finalizer)
  845. { this.raise(node.start, "Missing catch or finally clause"); }
  846. return this.finishNode(node, "TryStatement")
  847. };
  848. pp$1.parseVarStatement = function(node, kind) {
  849. this.next();
  850. this.parseVar(node, false, kind);
  851. this.semicolon();
  852. return this.finishNode(node, "VariableDeclaration")
  853. };
  854. pp$1.parseWhileStatement = function(node) {
  855. this.next();
  856. node.test = this.parseParenExpression();
  857. this.labels.push(loopLabel);
  858. node.body = this.parseStatement(false);
  859. this.labels.pop();
  860. return this.finishNode(node, "WhileStatement")
  861. };
  862. pp$1.parseWithStatement = function(node) {
  863. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  864. this.next();
  865. node.object = this.parseParenExpression();
  866. node.body = this.parseStatement(false);
  867. return this.finishNode(node, "WithStatement")
  868. };
  869. pp$1.parseEmptyStatement = function(node) {
  870. this.next();
  871. return this.finishNode(node, "EmptyStatement")
  872. };
  873. pp$1.parseLabeledStatement = function(node, maybeName, expr) {
  874. var this$1 = this;
  875. for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
  876. {
  877. var label = list[i$1];
  878. if (label.name === maybeName)
  879. { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
  880. } }
  881. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  882. for (var i = this.labels.length - 1; i >= 0; i--) {
  883. var label$1 = this$1.labels[i];
  884. if (label$1.statementStart == node.start) {
  885. label$1.statementStart = this$1.start;
  886. label$1.kind = kind;
  887. } else { break }
  888. }
  889. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  890. node.body = this.parseStatement(true);
  891. if (node.body.type == "ClassDeclaration" ||
  892. node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
  893. node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
  894. { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
  895. this.labels.pop();
  896. node.label = expr;
  897. return this.finishNode(node, "LabeledStatement")
  898. };
  899. pp$1.parseExpressionStatement = function(node, expr) {
  900. node.expression = expr;
  901. this.semicolon();
  902. return this.finishNode(node, "ExpressionStatement")
  903. };
  904. // Parse a semicolon-enclosed block of statements, handling `"use
  905. // strict"` declarations when `allowStrict` is true (used for
  906. // function bodies).
  907. pp$1.parseBlock = function(createNewLexicalScope) {
  908. var this$1 = this;
  909. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  910. var node = this.startNode();
  911. node.body = [];
  912. this.expect(types.braceL);
  913. if (createNewLexicalScope) {
  914. this.enterLexicalScope();
  915. }
  916. while (!this.eat(types.braceR)) {
  917. var stmt = this$1.parseStatement(true);
  918. node.body.push(stmt);
  919. }
  920. if (createNewLexicalScope) {
  921. this.exitLexicalScope();
  922. }
  923. return this.finishNode(node, "BlockStatement")
  924. };
  925. // Parse a regular `for` loop. The disambiguation code in
  926. // `parseStatement` will already have parsed the init statement or
  927. // expression.
  928. pp$1.parseFor = function(node, init) {
  929. node.init = init;
  930. this.expect(types.semi);
  931. node.test = this.type === types.semi ? null : this.parseExpression();
  932. this.expect(types.semi);
  933. node.update = this.type === types.parenR ? null : this.parseExpression();
  934. this.expect(types.parenR);
  935. this.exitLexicalScope();
  936. node.body = this.parseStatement(false);
  937. this.labels.pop();
  938. return this.finishNode(node, "ForStatement")
  939. };
  940. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  941. // same from parser's perspective.
  942. pp$1.parseForIn = function(node, init) {
  943. var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
  944. this.next();
  945. node.left = init;
  946. node.right = this.parseExpression();
  947. this.expect(types.parenR);
  948. this.exitLexicalScope();
  949. node.body = this.parseStatement(false);
  950. this.labels.pop();
  951. return this.finishNode(node, type)
  952. };
  953. // Parse a list of variable declarations.
  954. pp$1.parseVar = function(node, isFor, kind) {
  955. var this$1 = this;
  956. node.declarations = [];
  957. node.kind = kind;
  958. for (;;) {
  959. var decl = this$1.startNode();
  960. this$1.parseVarId(decl, kind);
  961. if (this$1.eat(types.eq)) {
  962. decl.init = this$1.parseMaybeAssign(isFor);
  963. } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
  964. this$1.unexpected();
  965. } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
  966. this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
  967. } else {
  968. decl.init = null;
  969. }
  970. node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
  971. if (!this$1.eat(types.comma)) { break }
  972. }
  973. return node
  974. };
  975. pp$1.parseVarId = function(decl, kind) {
  976. decl.id = this.parseBindingAtom(kind);
  977. this.checkLVal(decl.id, kind, false);
  978. };
  979. // Parse a function declaration or literal (depending on the
  980. // `isStatement` parameter).
  981. pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
  982. this.initFunction(node);
  983. if (this.options.ecmaVersion >= 6 && !isAsync)
  984. { node.generator = this.eat(types.star); }
  985. if (this.options.ecmaVersion >= 8)
  986. { node.async = !!isAsync; }
  987. if (isStatement) {
  988. node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
  989. if (node.id) {
  990. this.checkLVal(node.id, "var");
  991. }
  992. }
  993. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  994. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  995. this.inGenerator = node.generator;
  996. this.inAsync = node.async;
  997. this.yieldPos = 0;
  998. this.awaitPos = 0;
  999. this.inFunction = true;
  1000. this.enterFunctionScope();
  1001. if (!isStatement)
  1002. { node.id = this.type == types.name ? this.parseIdent() : null; }
  1003. this.parseFunctionParams(node);
  1004. this.parseFunctionBody(node, allowExpressionBody);
  1005. this.inGenerator = oldInGen;
  1006. this.inAsync = oldInAsync;
  1007. this.yieldPos = oldYieldPos;
  1008. this.awaitPos = oldAwaitPos;
  1009. this.inFunction = oldInFunc;
  1010. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
  1011. };
  1012. pp$1.parseFunctionParams = function(node) {
  1013. this.expect(types.parenL);
  1014. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  1015. this.checkYieldAwaitInDefaultParams();
  1016. };
  1017. // Parse a class declaration or literal (depending on the
  1018. // `isStatement` parameter).
  1019. pp$1.parseClass = function(node, isStatement) {
  1020. var this$1 = this;
  1021. this.next();
  1022. this.parseClassId(node, isStatement);
  1023. this.parseClassSuper(node);
  1024. var classBody = this.startNode();
  1025. var hadConstructor = false;
  1026. classBody.body = [];
  1027. this.expect(types.braceL);
  1028. while (!this.eat(types.braceR)) {
  1029. if (this$1.eat(types.semi)) { continue }
  1030. var method = this$1.startNode();
  1031. var isGenerator = this$1.eat(types.star);
  1032. var isAsync = false;
  1033. var isMaybeStatic = this$1.type === types.name && this$1.value === "static";
  1034. this$1.parsePropertyName(method);
  1035. method.static = isMaybeStatic && this$1.type !== types.parenL;
  1036. if (method.static) {
  1037. if (isGenerator) { this$1.unexpected(); }
  1038. isGenerator = this$1.eat(types.star);
  1039. this$1.parsePropertyName(method);
  1040. }
  1041. if (this$1.options.ecmaVersion >= 8 && !isGenerator && !method.computed &&
  1042. method.key.type === "Identifier" && method.key.name === "async" && this$1.type !== types.parenL &&
  1043. !this$1.canInsertSemicolon()) {
  1044. isAsync = true;
  1045. this$1.parsePropertyName(method);
  1046. }
  1047. method.kind = "method";
  1048. var isGetSet = false;
  1049. if (!method.computed) {
  1050. var key = method.key;
  1051. if (!isGenerator && !isAsync && key.type === "Identifier" && this$1.type !== types.parenL && (key.name === "get" || key.name === "set")) {
  1052. isGetSet = true;
  1053. method.kind = key.name;
  1054. key = this$1.parsePropertyName(method);
  1055. }
  1056. if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
  1057. key.type === "Literal" && key.value === "constructor")) {
  1058. if (hadConstructor) { this$1.raise(key.start, "Duplicate constructor in the same class"); }
  1059. if (isGetSet) { this$1.raise(key.start, "Constructor can't have get/set modifier"); }
  1060. if (isGenerator) { this$1.raise(key.start, "Constructor can't be a generator"); }
  1061. if (isAsync) { this$1.raise(key.start, "Constructor can't be an async method"); }
  1062. method.kind = "constructor";
  1063. hadConstructor = true;
  1064. }
  1065. }
  1066. this$1.parseClassMethod(classBody, method, isGenerator, isAsync);
  1067. if (isGetSet) {
  1068. var paramCount = method.kind === "get" ? 0 : 1;
  1069. if (method.value.params.length !== paramCount) {
  1070. var start = method.value.start;
  1071. if (method.kind === "get")
  1072. { this$1.raiseRecoverable(start, "getter should have no params"); }
  1073. else
  1074. { this$1.raiseRecoverable(start, "setter should have exactly one param"); }
  1075. } else {
  1076. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  1077. { this$1.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  1078. }
  1079. }
  1080. }
  1081. node.body = this.finishNode(classBody, "ClassBody");
  1082. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1083. };
  1084. pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
  1085. method.value = this.parseMethod(isGenerator, isAsync);
  1086. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  1087. };
  1088. pp$1.parseClassId = function(node, isStatement) {
  1089. node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
  1090. };
  1091. pp$1.parseClassSuper = function(node) {
  1092. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  1093. };
  1094. // Parses module export declaration.
  1095. pp$1.parseExport = function(node, exports) {
  1096. var this$1 = this;
  1097. this.next();
  1098. // export * from '...'
  1099. if (this.eat(types.star)) {
  1100. this.expectContextual("from");
  1101. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1102. this.semicolon();
  1103. return this.finishNode(node, "ExportAllDeclaration")
  1104. }
  1105. if (this.eat(types._default)) { // export default ...
  1106. this.checkExport(exports, "default", this.lastTokStart);
  1107. var isAsync;
  1108. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  1109. var fNode = this.startNode();
  1110. this.next();
  1111. if (isAsync) { this.next(); }
  1112. node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
  1113. } else if (this.type === types._class) {
  1114. var cNode = this.startNode();
  1115. node.declaration = this.parseClass(cNode, "nullableID");
  1116. } else {
  1117. node.declaration = this.parseMaybeAssign();
  1118. this.semicolon();
  1119. }
  1120. return this.finishNode(node, "ExportDefaultDeclaration")
  1121. }
  1122. // export var|const|let|function|class ...
  1123. if (this.shouldParseExportStatement()) {
  1124. node.declaration = this.parseStatement(true);
  1125. if (node.declaration.type === "VariableDeclaration")
  1126. { this.checkVariableExport(exports, node.declaration.declarations); }
  1127. else
  1128. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1129. node.specifiers = [];
  1130. node.source = null;
  1131. } else { // export { x, y as z } [from '...']
  1132. node.declaration = null;
  1133. node.specifiers = this.parseExportSpecifiers(exports);
  1134. if (this.eatContextual("from")) {
  1135. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1136. } else {
  1137. // check for keywords used as local names
  1138. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1139. var spec = list[i];
  1140. this$1.checkUnreserved(spec.local);
  1141. }
  1142. node.source = null;
  1143. }
  1144. this.semicolon();
  1145. }
  1146. return this.finishNode(node, "ExportNamedDeclaration")
  1147. };
  1148. pp$1.checkExport = function(exports, name, pos) {
  1149. if (!exports) { return }
  1150. if (has(exports, name))
  1151. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1152. exports[name] = true;
  1153. };
  1154. pp$1.checkPatternExport = function(exports, pat) {
  1155. var this$1 = this;
  1156. var type = pat.type;
  1157. if (type == "Identifier")
  1158. { this.checkExport(exports, pat.name, pat.start); }
  1159. else if (type == "ObjectPattern")
  1160. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1161. {
  1162. var prop = list[i];
  1163. this$1.checkPatternExport(exports, prop.value);
  1164. } }
  1165. else if (type == "ArrayPattern")
  1166. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1167. var elt = list$1[i$1];
  1168. if (elt) { this$1.checkPatternExport(exports, elt); }
  1169. } }
  1170. else if (type == "AssignmentPattern")
  1171. { this.checkPatternExport(exports, pat.left); }
  1172. else if (type == "ParenthesizedExpression")
  1173. { this.checkPatternExport(exports, pat.expression); }
  1174. };
  1175. pp$1.checkVariableExport = function(exports, decls) {
  1176. var this$1 = this;
  1177. if (!exports) { return }
  1178. for (var i = 0, list = decls; i < list.length; i += 1)
  1179. {
  1180. var decl = list[i];
  1181. this$1.checkPatternExport(exports, decl.id);
  1182. }
  1183. };
  1184. pp$1.shouldParseExportStatement = function() {
  1185. return this.type.keyword === "var" ||
  1186. this.type.keyword === "const" ||
  1187. this.type.keyword === "class" ||
  1188. this.type.keyword === "function" ||
  1189. this.isLet() ||
  1190. this.isAsyncFunction()
  1191. };
  1192. // Parses a comma-separated list of module exports.
  1193. pp$1.parseExportSpecifiers = function(exports) {
  1194. var this$1 = this;
  1195. var nodes = [], first = true;
  1196. // export { x, y as z } [from '...']
  1197. this.expect(types.braceL);
  1198. while (!this.eat(types.braceR)) {
  1199. if (!first) {
  1200. this$1.expect(types.comma);
  1201. if (this$1.afterTrailingComma(types.braceR)) { break }
  1202. } else { first = false; }
  1203. var node = this$1.startNode();
  1204. node.local = this$1.parseIdent(true);
  1205. node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
  1206. this$1.checkExport(exports, node.exported.name, node.exported.start);
  1207. nodes.push(this$1.finishNode(node, "ExportSpecifier"));
  1208. }
  1209. return nodes
  1210. };
  1211. // Parses import declaration.
  1212. pp$1.parseImport = function(node) {
  1213. this.next();
  1214. // import '...'
  1215. if (this.type === types.string) {
  1216. node.specifiers = empty;
  1217. node.source = this.parseExprAtom();
  1218. } else {
  1219. node.specifiers = this.parseImportSpecifiers();
  1220. this.expectContextual("from");
  1221. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1222. }
  1223. this.semicolon();
  1224. return this.finishNode(node, "ImportDeclaration")
  1225. };
  1226. // Parses a comma-separated list of module imports.
  1227. pp$1.parseImportSpecifiers = function() {
  1228. var this$1 = this;
  1229. var nodes = [], first = true;
  1230. if (this.type === types.name) {
  1231. // import defaultObj, { x, y as z } from '...'
  1232. var node = this.startNode();
  1233. node.local = this.parseIdent();
  1234. this.checkLVal(node.local, "let");
  1235. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1236. if (!this.eat(types.comma)) { return nodes }
  1237. }
  1238. if (this.type === types.star) {
  1239. var node$1 = this.startNode();
  1240. this.next();
  1241. this.expectContextual("as");
  1242. node$1.local = this.parseIdent();
  1243. this.checkLVal(node$1.local, "let");
  1244. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1245. return nodes
  1246. }
  1247. this.expect(types.braceL);
  1248. while (!this.eat(types.braceR)) {
  1249. if (!first) {
  1250. this$1.expect(types.comma);
  1251. if (this$1.afterTrailingComma(types.braceR)) { break }
  1252. } else { first = false; }
  1253. var node$2 = this$1.startNode();
  1254. node$2.imported = this$1.parseIdent(true);
  1255. if (this$1.eatContextual("as")) {
  1256. node$2.local = this$1.parseIdent();
  1257. } else {
  1258. this$1.checkUnreserved(node$2.imported);
  1259. node$2.local = node$2.imported;
  1260. }
  1261. this$1.checkLVal(node$2.local, "let");
  1262. nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
  1263. }
  1264. return nodes
  1265. };
  1266. var pp$2 = Parser.prototype;
  1267. // Convert existing expression atom to assignable pattern
  1268. // if possible.
  1269. pp$2.toAssignable = function(node, isBinding) {
  1270. var this$1 = this;
  1271. if (this.options.ecmaVersion >= 6 && node) {
  1272. switch (node.type) {
  1273. case "Identifier":
  1274. if (this.inAsync && node.name === "await")
  1275. { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
  1276. break
  1277. case "ObjectPattern":
  1278. case "ArrayPattern":
  1279. break
  1280. case "ObjectExpression":
  1281. node.type = "ObjectPattern";
  1282. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1283. var prop = list[i];
  1284. if (prop.kind !== "init") { this$1.raise(prop.key.start, "Object pattern can't contain getter or setter"); }
  1285. this$1.toAssignable(prop.value, isBinding);
  1286. }
  1287. break
  1288. case "ArrayExpression":
  1289. node.type = "ArrayPattern";
  1290. this.toAssignableList(node.elements, isBinding);
  1291. break
  1292. case "AssignmentExpression":
  1293. if (node.operator === "=") {
  1294. node.type = "AssignmentPattern";
  1295. delete node.operator;
  1296. this.toAssignable(node.left, isBinding);
  1297. // falls through to AssignmentPattern
  1298. } else {
  1299. this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
  1300. break
  1301. }
  1302. case "AssignmentPattern":
  1303. break
  1304. case "ParenthesizedExpression":
  1305. this.toAssignable(node.expression, isBinding);
  1306. break
  1307. case "MemberExpression":
  1308. if (!isBinding) { break }
  1309. default:
  1310. this.raise(node.start, "Assigning to rvalue");
  1311. }
  1312. }
  1313. return node
  1314. };
  1315. // Convert list of expression atoms to binding list.
  1316. pp$2.toAssignableList = function(exprList, isBinding) {
  1317. var this$1 = this;
  1318. var end = exprList.length;
  1319. if (end) {
  1320. var last = exprList[end - 1];
  1321. if (last && last.type == "RestElement") {
  1322. --end;
  1323. } else if (last && last.type == "SpreadElement") {
  1324. last.type = "RestElement";
  1325. var arg = last.argument;
  1326. this.toAssignable(arg, isBinding);
  1327. --end;
  1328. }
  1329. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1330. { this.unexpected(last.argument.start); }
  1331. }
  1332. for (var i = 0; i < end; i++) {
  1333. var elt = exprList[i];
  1334. if (elt) { this$1.toAssignable(elt, isBinding); }
  1335. }
  1336. return exprList
  1337. };
  1338. // Parses spread element.
  1339. pp$2.parseSpread = function(refDestructuringErrors) {
  1340. var node = this.startNode();
  1341. this.next();
  1342. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1343. return this.finishNode(node, "SpreadElement")
  1344. };
  1345. pp$2.parseRestBinding = function() {
  1346. var node = this.startNode();
  1347. this.next();
  1348. // RestElement inside of a function parameter must be an identifier
  1349. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  1350. { this.unexpected(); }
  1351. node.argument = this.parseBindingAtom();
  1352. return this.finishNode(node, "RestElement")
  1353. };
  1354. // Parses lvalue (assignable) atom.
  1355. pp$2.parseBindingAtom = function() {
  1356. if (this.options.ecmaVersion < 6) { return this.parseIdent() }
  1357. switch (this.type) {
  1358. case types.name:
  1359. return this.parseIdent()
  1360. case types.bracketL:
  1361. var node = this.startNode();
  1362. this.next();
  1363. node.elements = this.parseBindingList(types.bracketR, true, true);
  1364. return this.finishNode(node, "ArrayPattern")
  1365. case types.braceL:
  1366. return this.parseObj(true)
  1367. default:
  1368. this.unexpected();
  1369. }
  1370. };
  1371. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1372. var this$1 = this;
  1373. var elts = [], first = true;
  1374. while (!this.eat(close)) {
  1375. if (first) { first = false; }
  1376. else { this$1.expect(types.comma); }
  1377. if (allowEmpty && this$1.type === types.comma) {
  1378. elts.push(null);
  1379. } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
  1380. break
  1381. } else if (this$1.type === types.ellipsis) {
  1382. var rest = this$1.parseRestBinding();
  1383. this$1.parseBindingListItem(rest);
  1384. elts.push(rest);
  1385. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1386. this$1.expect(close);
  1387. break
  1388. } else {
  1389. var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
  1390. this$1.parseBindingListItem(elem);
  1391. elts.push(elem);
  1392. }
  1393. }
  1394. return elts
  1395. };
  1396. pp$2.parseBindingListItem = function(param) {
  1397. return param
  1398. };
  1399. // Parses assignment pattern around given atom if possible.
  1400. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1401. left = left || this.parseBindingAtom();
  1402. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  1403. var node = this.startNodeAt(startPos, startLoc);
  1404. node.left = left;
  1405. node.right = this.parseMaybeAssign();
  1406. return this.finishNode(node, "AssignmentPattern")
  1407. };
  1408. // Verify that a node is an lval — something that can be assigned
  1409. // to.
  1410. // bindingType can be either:
  1411. // 'var' indicating that the lval creates a 'var' binding
  1412. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  1413. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  1414. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  1415. var this$1 = this;
  1416. switch (expr.type) {
  1417. case "Identifier":
  1418. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1419. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1420. if (checkClashes) {
  1421. if (has(checkClashes, expr.name))
  1422. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1423. checkClashes[expr.name] = true;
  1424. }
  1425. if (bindingType && bindingType !== "none") {
  1426. if (
  1427. bindingType === "var" && !this.canDeclareVarName(expr.name) ||
  1428. bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
  1429. ) {
  1430. this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
  1431. }
  1432. if (bindingType === "var") {
  1433. this.declareVarName(expr.name);
  1434. } else {
  1435. this.declareLexicalName(expr.name);
  1436. }
  1437. }
  1438. break
  1439. case "MemberExpression":
  1440. if (bindingType) { this.raiseRecoverable(expr.start, (bindingType ? "Binding" : "Assigning to") + " member expression"); }
  1441. break
  1442. case "ObjectPattern":
  1443. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  1444. {
  1445. var prop = list[i];
  1446. this$1.checkLVal(prop.value, bindingType, checkClashes);
  1447. }
  1448. break
  1449. case "ArrayPattern":
  1450. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1451. var elem = list$1[i$1];
  1452. if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
  1453. }
  1454. break
  1455. case "AssignmentPattern":
  1456. this.checkLVal(expr.left, bindingType, checkClashes);
  1457. break
  1458. case "RestElement":
  1459. this.checkLVal(expr.argument, bindingType, checkClashes);
  1460. break
  1461. case "ParenthesizedExpression":
  1462. this.checkLVal(expr.expression, bindingType, checkClashes);
  1463. break
  1464. default:
  1465. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  1466. }
  1467. };
  1468. // A recursive descent parser operates by defining functions for all
  1469. // syntactic elements, and recursively calling those, each function
  1470. // advancing the input stream and returning an AST node. Precedence
  1471. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  1472. // instead of `(!x)[1]` is handled by the fact that the parser
  1473. // function that parses unary prefix operators is called first, and
  1474. // in turn calls the function that parses `[]` subscripts — that
  1475. // way, it'll receive the node for `x[1]` already parsed, and wraps
  1476. // *that* in the unary operator node.
  1477. //
  1478. // Acorn uses an [operator precedence parser][opp] to handle binary
  1479. // operator precedence, because it is much more compact than using
  1480. // the technique outlined above, which uses different, nesting
  1481. // functions to specify precedence, for all of the ten binary
  1482. // precedence levels that JavaScript defines.
  1483. //
  1484. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  1485. var pp$3 = Parser.prototype;
  1486. // Check if property name clashes with already added.
  1487. // Object/class getters and setters are not allowed to clash —
  1488. // either with each other or with an init property — and in
  1489. // strict mode, init properties are also not allowed to be repeated.
  1490. pp$3.checkPropClash = function(prop, propHash) {
  1491. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1492. { return }
  1493. var key = prop.key;
  1494. var name;
  1495. switch (key.type) {
  1496. case "Identifier": name = key.name; break
  1497. case "Literal": name = String(key.value); break
  1498. default: return
  1499. }
  1500. var kind = prop.kind;
  1501. if (this.options.ecmaVersion >= 6) {
  1502. if (name === "__proto__" && kind === "init") {
  1503. if (propHash.proto) { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  1504. propHash.proto = true;
  1505. }
  1506. return
  1507. }
  1508. name = "$" + name;
  1509. var other = propHash[name];
  1510. if (other) {
  1511. var redefinition;
  1512. if (kind === "init") {
  1513. redefinition = this.strict && other.init || other.get || other.set;
  1514. } else {
  1515. redefinition = other.init || other[kind];
  1516. }
  1517. if (redefinition)
  1518. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  1519. } else {
  1520. other = propHash[name] = {
  1521. init: false,
  1522. get: false,
  1523. set: false
  1524. };
  1525. }
  1526. other[kind] = true;
  1527. };
  1528. // ### Expression parsing
  1529. // These nest, from the most general expression type at the top to
  1530. // 'atomic', nondivisible expression types at the bottom. Most of
  1531. // the functions will simply let the function(s) below them parse,
  1532. // and, *if* the syntactic construct they handle is present, wrap
  1533. // the AST node that the inner parser gave them in another node.
  1534. // Parse a full expression. The optional arguments are used to
  1535. // forbid the `in` operator (in for loops initalization expressions)
  1536. // and provide reference for storing '=' operator inside shorthand
  1537. // property assignment in contexts where both object expression
  1538. // and object pattern might appear (so it's possible to raise
  1539. // delayed syntax error at correct position).
  1540. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1541. var this$1 = this;
  1542. var startPos = this.start, startLoc = this.startLoc;
  1543. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1544. if (this.type === types.comma) {
  1545. var node = this.startNodeAt(startPos, startLoc);
  1546. node.expressions = [expr];
  1547. while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
  1548. return this.finishNode(node, "SequenceExpression")
  1549. }
  1550. return expr
  1551. };
  1552. // Parse an assignment expression. This includes applications of
  1553. // operators like `+=`.
  1554. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1555. if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
  1556. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
  1557. if (refDestructuringErrors) {
  1558. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  1559. oldTrailingComma = refDestructuringErrors.trailingComma;
  1560. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  1561. } else {
  1562. refDestructuringErrors = new DestructuringErrors;
  1563. ownDestructuringErrors = true;
  1564. }
  1565. var startPos = this.start, startLoc = this.startLoc;
  1566. if (this.type == types.parenL || this.type == types.name)
  1567. { this.potentialArrowAt = this.start; }
  1568. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1569. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  1570. if (this.type.isAssign) {
  1571. this.checkPatternErrors(refDestructuringErrors, true);
  1572. if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
  1573. var node = this.startNodeAt(startPos, startLoc);
  1574. node.operator = this.value;
  1575. node.left = this.type === types.eq ? this.toAssignable(left) : left;
  1576. refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
  1577. this.checkLVal(left);
  1578. this.next();
  1579. node.right = this.parseMaybeAssign(noIn);
  1580. return this.finishNode(node, "AssignmentExpression")
  1581. } else {
  1582. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  1583. }
  1584. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  1585. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  1586. return left
  1587. };
  1588. // Parse a ternary conditional (`?:`) operator.
  1589. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1590. var startPos = this.start, startLoc = this.startLoc;
  1591. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1592. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1593. if (this.eat(types.question)) {
  1594. var node = this.startNodeAt(startPos, startLoc);
  1595. node.test = expr;
  1596. node.consequent = this.parseMaybeAssign();
  1597. this.expect(types.colon);
  1598. node.alternate = this.parseMaybeAssign(noIn);
  1599. return this.finishNode(node, "ConditionalExpression")
  1600. }
  1601. return expr
  1602. };
  1603. // Start the precedence parser.
  1604. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1605. var startPos = this.start, startLoc = this.startLoc;
  1606. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1607. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1608. return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1609. };
  1610. // Parse binary operators with the operator precedence parsing
  1611. // algorithm. `left` is the left-hand side of the operator.
  1612. // `minPrec` provides context that allows the function to stop and
  1613. // defer further parser to one of its callers when it encounters an
  1614. // operator that has a lower precedence than the set it is parsing.
  1615. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1616. var prec = this.type.binop;
  1617. if (prec != null && (!noIn || this.type !== types._in)) {
  1618. if (prec > minPrec) {
  1619. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  1620. var op = this.value;
  1621. this.next();
  1622. var startPos = this.start, startLoc = this.startLoc;
  1623. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1624. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  1625. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1626. }
  1627. }
  1628. return left
  1629. };
  1630. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1631. var node = this.startNodeAt(startPos, startLoc);
  1632. node.left = left;
  1633. node.operator = op;
  1634. node.right = right;
  1635. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1636. };
  1637. // Parse unary operators, both prefix and postfix.
  1638. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1639. var this$1 = this;
  1640. var startPos = this.start, startLoc = this.startLoc, expr;
  1641. if (this.inAsync && this.isContextual("await")) {
  1642. expr = this.parseAwait(refDestructuringErrors);
  1643. sawUnary = true;
  1644. } else if (this.type.prefix) {
  1645. var node = this.startNode(), update = this.type === types.incDec;
  1646. node.operator = this.value;
  1647. node.prefix = true;
  1648. this.next();
  1649. node.argument = this.parseMaybeUnary(null, true);
  1650. this.checkExpressionErrors(refDestructuringErrors, true);
  1651. if (update) { this.checkLVal(node.argument); }
  1652. else if (this.strict && node.operator === "delete" &&
  1653. node.argument.type === "Identifier")
  1654. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  1655. else { sawUnary = true; }
  1656. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1657. } else {
  1658. expr = this.parseExprSubscripts(refDestructuringErrors);
  1659. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1660. while (this.type.postfix && !this.canInsertSemicolon()) {
  1661. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1662. node$1.operator = this$1.value;
  1663. node$1.prefix = false;
  1664. node$1.argument = expr;
  1665. this$1.checkLVal(expr);
  1666. this$1.next();
  1667. expr = this$1.finishNode(node$1, "UpdateExpression");
  1668. }
  1669. }
  1670. if (!sawUnary && this.eat(types.starstar))
  1671. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  1672. else
  1673. { return expr }
  1674. };
  1675. // Parse call, dot, and `[]`-subscript expressions.
  1676. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1677. var startPos = this.start, startLoc = this.startLoc;
  1678. var expr = this.parseExprAtom(refDestructuringErrors);
  1679. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  1680. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
  1681. var result = this.parseSubscripts(expr, startPos, startLoc);
  1682. if (refDestructuringErrors && result.type === "MemberExpression") {
  1683. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  1684. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  1685. }
  1686. return result
  1687. };
  1688. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1689. var this$1 = this;
  1690. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  1691. this.lastTokEnd == base.end && !this.canInsertSemicolon();
  1692. for (var computed = (void 0);;) {
  1693. if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
  1694. var node = this$1.startNodeAt(startPos, startLoc);
  1695. node.object = base;
  1696. node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
  1697. node.computed = !!computed;
  1698. if (computed) { this$1.expect(types.bracketR); }
  1699. base = this$1.finishNode(node, "MemberExpression");
  1700. } else if (!noCalls && this$1.eat(types.parenL)) {
  1701. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
  1702. this$1.yieldPos = 0;
  1703. this$1.awaitPos = 0;
  1704. var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
  1705. if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
  1706. this$1.checkPatternErrors(refDestructuringErrors, false);
  1707. this$1.checkYieldAwaitInDefaultParams();
  1708. this$1.yieldPos = oldYieldPos;
  1709. this$1.awaitPos = oldAwaitPos;
  1710. return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
  1711. }
  1712. this$1.checkExpressionErrors(refDestructuringErrors, true);
  1713. this$1.yieldPos = oldYieldPos || this$1.yieldPos;
  1714. this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
  1715. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1716. node$1.callee = base;
  1717. node$1.arguments = exprList;
  1718. base = this$1.finishNode(node$1, "CallExpression");
  1719. } else if (this$1.type === types.backQuote) {
  1720. var node$2 = this$1.startNodeAt(startPos, startLoc);
  1721. node$2.tag = base;
  1722. node$2.quasi = this$1.parseTemplate({isTagged: true});
  1723. base = this$1.finishNode(node$2, "TaggedTemplateExpression");
  1724. } else {
  1725. return base
  1726. }
  1727. }
  1728. };
  1729. // Parse an atomic expression — either a single token that is an
  1730. // expression, an expression started by a keyword like `function` or
  1731. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1732. // or `{}`.
  1733. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1734. var node, canBeArrow = this.potentialArrowAt == this.start;
  1735. switch (this.type) {
  1736. case types._super:
  1737. if (!this.inFunction)
  1738. { this.raise(this.start, "'super' outside of function or class"); }
  1739. case types._this:
  1740. var type = this.type === types._this ? "ThisExpression" : "Super";
  1741. node = this.startNode();
  1742. this.next();
  1743. return this.finishNode(node, type)
  1744. case types.name:
  1745. var startPos = this.start, startLoc = this.startLoc;
  1746. var id = this.parseIdent(this.type !== types.name);
  1747. if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  1748. { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
  1749. if (canBeArrow && !this.canInsertSemicolon()) {
  1750. if (this.eat(types.arrow))
  1751. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  1752. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name) {
  1753. id = this.parseIdent();
  1754. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  1755. { this.unexpected(); }
  1756. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  1757. }
  1758. }
  1759. return id
  1760. case types.regexp:
  1761. var value = this.value;
  1762. node = this.parseLiteral(value.value);
  1763. node.regex = {pattern: value.pattern, flags: value.flags};
  1764. return node
  1765. case types.num: case types.string:
  1766. return this.parseLiteral(this.value)
  1767. case types._null: case types._true: case types._false:
  1768. node = this.startNode();
  1769. node.value = this.type === types._null ? null : this.type === types._true;
  1770. node.raw = this.type.keyword;
  1771. this.next();
  1772. return this.finishNode(node, "Literal")
  1773. case types.parenL:
  1774. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  1775. if (refDestructuringErrors) {
  1776. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  1777. { refDestructuringErrors.parenthesizedAssign = start; }
  1778. if (refDestructuringErrors.parenthesizedBind < 0)
  1779. { refDestructuringErrors.parenthesizedBind = start; }
  1780. }
  1781. return expr
  1782. case types.bracketL:
  1783. node = this.startNode();
  1784. this.next();
  1785. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  1786. return this.finishNode(node, "ArrayExpression")
  1787. case types.braceL:
  1788. return this.parseObj(false, refDestructuringErrors)
  1789. case types._function:
  1790. node = this.startNode();
  1791. this.next();
  1792. return this.parseFunction(node, false)
  1793. case types._class:
  1794. return this.parseClass(this.startNode(), false)
  1795. case types._new:
  1796. return this.parseNew()
  1797. case types.backQuote:
  1798. return this.parseTemplate()
  1799. default:
  1800. this.unexpected();
  1801. }
  1802. };
  1803. pp$3.parseLiteral = function(value) {
  1804. var node = this.startNode();
  1805. node.value = value;
  1806. node.raw = this.input.slice(this.start, this.end);
  1807. this.next();
  1808. return this.finishNode(node, "Literal")
  1809. };
  1810. pp$3.parseParenExpression = function() {
  1811. this.expect(types.parenL);
  1812. var val = this.parseExpression();
  1813. this.expect(types.parenR);
  1814. return val
  1815. };
  1816. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  1817. var this$1 = this;
  1818. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  1819. if (this.options.ecmaVersion >= 6) {
  1820. this.next();
  1821. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  1822. var exprList = [], first = true, lastIsComma = false;
  1823. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart, innerParenStart;
  1824. this.yieldPos = 0;
  1825. this.awaitPos = 0;
  1826. while (this.type !== types.parenR) {
  1827. first ? first = false : this$1.expect(types.comma);
  1828. if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
  1829. lastIsComma = true;
  1830. break
  1831. } else if (this$1.type === types.ellipsis) {
  1832. spreadStart = this$1.start;
  1833. exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
  1834. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1835. break
  1836. } else {
  1837. if (this$1.type === types.parenL && !innerParenStart) {
  1838. innerParenStart = this$1.start;
  1839. }
  1840. exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
  1841. }
  1842. }
  1843. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  1844. this.expect(types.parenR);
  1845. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  1846. this.checkPatternErrors(refDestructuringErrors, false);
  1847. this.checkYieldAwaitInDefaultParams();
  1848. if (innerParenStart) { this.unexpected(innerParenStart); }
  1849. this.yieldPos = oldYieldPos;
  1850. this.awaitPos = oldAwaitPos;
  1851. return this.parseParenArrowList(startPos, startLoc, exprList)
  1852. }
  1853. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  1854. if (spreadStart) { this.unexpected(spreadStart); }
  1855. this.checkExpressionErrors(refDestructuringErrors, true);
  1856. this.yieldPos = oldYieldPos || this.yieldPos;
  1857. this.awaitPos = oldAwaitPos || this.awaitPos;
  1858. if (exprList.length > 1) {
  1859. val = this.startNodeAt(innerStartPos, innerStartLoc);
  1860. val.expressions = exprList;
  1861. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  1862. } else {
  1863. val = exprList[0];
  1864. }
  1865. } else {
  1866. val = this.parseParenExpression();
  1867. }
  1868. if (this.options.preserveParens) {
  1869. var par = this.startNodeAt(startPos, startLoc);
  1870. par.expression = val;
  1871. return this.finishNode(par, "ParenthesizedExpression")
  1872. } else {
  1873. return val
  1874. }
  1875. };
  1876. pp$3.parseParenItem = function(item) {
  1877. return item
  1878. };
  1879. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  1880. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  1881. };
  1882. // New's precedence is slightly tricky. It must allow its argument to
  1883. // be a `[]` or dot subscript expression, but not a call — at least,
  1884. // not without wrapping it in parentheses. Thus, it uses the noCalls
  1885. // argument to parseSubscripts to prevent it from consuming the
  1886. // argument list.
  1887. var empty$1 = [];
  1888. pp$3.parseNew = function() {
  1889. var node = this.startNode();
  1890. var meta = this.parseIdent(true);
  1891. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  1892. node.meta = meta;
  1893. node.property = this.parseIdent(true);
  1894. if (node.property.name !== "target")
  1895. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
  1896. if (!this.inFunction)
  1897. { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
  1898. return this.finishNode(node, "MetaProperty")
  1899. }
  1900. var startPos = this.start, startLoc = this.startLoc;
  1901. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  1902. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
  1903. else { node.arguments = empty$1; }
  1904. return this.finishNode(node, "NewExpression")
  1905. };
  1906. // Parse template expression.
  1907. pp$3.parseTemplateElement = function(ref) {
  1908. var isTagged = ref.isTagged;
  1909. var elem = this.startNode();
  1910. if (this.type === types.invalidTemplate) {
  1911. if (!isTagged) {
  1912. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  1913. }
  1914. elem.value = {
  1915. raw: this.value,
  1916. cooked: null
  1917. };
  1918. } else {
  1919. elem.value = {
  1920. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  1921. cooked: this.value
  1922. };
  1923. }
  1924. this.next();
  1925. elem.tail = this.type === types.backQuote;
  1926. return this.finishNode(elem, "TemplateElement")
  1927. };
  1928. pp$3.parseTemplate = function(ref) {
  1929. var this$1 = this;
  1930. if ( ref === void 0 ) ref = {};
  1931. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  1932. var node = this.startNode();
  1933. this.next();
  1934. node.expressions = [];
  1935. var curElt = this.parseTemplateElement({isTagged: isTagged});
  1936. node.quasis = [curElt];
  1937. while (!curElt.tail) {
  1938. this$1.expect(types.dollarBraceL);
  1939. node.expressions.push(this$1.parseExpression());
  1940. this$1.expect(types.braceR);
  1941. node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
  1942. }
  1943. this.next();
  1944. return this.finishNode(node, "TemplateLiteral")
  1945. };
  1946. // Parse an object literal or binding pattern.
  1947. pp$3.isAsyncProp = function(prop) {
  1948. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  1949. (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL) &&
  1950. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  1951. };
  1952. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  1953. var this$1 = this;
  1954. var node = this.startNode(), first = true, propHash = {};
  1955. node.properties = [];
  1956. this.next();
  1957. while (!this.eat(types.braceR)) {
  1958. if (!first) {
  1959. this$1.expect(types.comma);
  1960. if (this$1.afterTrailingComma(types.braceR)) { break }
  1961. } else { first = false; }
  1962. var prop = this$1.startNode(), isGenerator = (void 0), isAsync = (void 0), startPos = (void 0), startLoc = (void 0);
  1963. if (this$1.options.ecmaVersion >= 6) {
  1964. prop.method = false;
  1965. prop.shorthand = false;
  1966. if (isPattern || refDestructuringErrors) {
  1967. startPos = this$1.start;
  1968. startLoc = this$1.startLoc;
  1969. }
  1970. if (!isPattern)
  1971. { isGenerator = this$1.eat(types.star); }
  1972. }
  1973. this$1.parsePropertyName(prop);
  1974. if (!isPattern && this$1.options.ecmaVersion >= 8 && !isGenerator && this$1.isAsyncProp(prop)) {
  1975. isAsync = true;
  1976. this$1.parsePropertyName(prop, refDestructuringErrors);
  1977. } else {
  1978. isAsync = false;
  1979. }
  1980. this$1.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
  1981. this$1.checkPropClash(prop, propHash);
  1982. node.properties.push(this$1.finishNode(prop, "Property"));
  1983. }
  1984. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  1985. };
  1986. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
  1987. if ((isGenerator || isAsync) && this.type === types.colon)
  1988. { this.unexpected(); }
  1989. if (this.eat(types.colon)) {
  1990. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  1991. prop.kind = "init";
  1992. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  1993. if (isPattern) { this.unexpected(); }
  1994. prop.kind = "init";
  1995. prop.method = true;
  1996. prop.value = this.parseMethod(isGenerator, isAsync);
  1997. } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  1998. (prop.key.name === "get" || prop.key.name === "set") &&
  1999. (this.type != types.comma && this.type != types.braceR)) {
  2000. if (isGenerator || isAsync || isPattern) { this.unexpected(); }
  2001. prop.kind = prop.key.name;
  2002. this.parsePropertyName(prop);
  2003. prop.value = this.parseMethod(false);
  2004. var paramCount = prop.kind === "get" ? 0 : 1;
  2005. if (prop.value.params.length !== paramCount) {
  2006. var start = prop.value.start;
  2007. if (prop.kind === "get")
  2008. { this.raiseRecoverable(start, "getter should have no params"); }
  2009. else
  2010. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2011. } else {
  2012. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2013. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2014. }
  2015. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2016. this.checkUnreserved(prop.key);
  2017. prop.kind = "init";
  2018. if (isPattern) {
  2019. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2020. } else if (this.type === types.eq && refDestructuringErrors) {
  2021. if (refDestructuringErrors.shorthandAssign < 0)
  2022. { refDestructuringErrors.shorthandAssign = this.start; }
  2023. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2024. } else {
  2025. prop.value = prop.key;
  2026. }
  2027. prop.shorthand = true;
  2028. } else { this.unexpected(); }
  2029. };
  2030. pp$3.parsePropertyName = function(prop) {
  2031. if (this.options.ecmaVersion >= 6) {
  2032. if (this.eat(types.bracketL)) {
  2033. prop.computed = true;
  2034. prop.key = this.parseMaybeAssign();
  2035. this.expect(types.bracketR);
  2036. return prop.key
  2037. } else {
  2038. prop.computed = false;
  2039. }
  2040. }
  2041. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
  2042. };
  2043. // Initialize empty function node.
  2044. pp$3.initFunction = function(node) {
  2045. node.id = null;
  2046. if (this.options.ecmaVersion >= 6) {
  2047. node.generator = false;
  2048. node.expression = false;
  2049. }
  2050. if (this.options.ecmaVersion >= 8)
  2051. { node.async = false; }
  2052. };
  2053. // Parse object or class method.
  2054. pp$3.parseMethod = function(isGenerator, isAsync) {
  2055. var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2056. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2057. this.initFunction(node);
  2058. if (this.options.ecmaVersion >= 6)
  2059. { node.generator = isGenerator; }
  2060. if (this.options.ecmaVersion >= 8)
  2061. { node.async = !!isAsync; }
  2062. this.inGenerator = node.generator;
  2063. this.inAsync = node.async;
  2064. this.yieldPos = 0;
  2065. this.awaitPos = 0;
  2066. this.inFunction = true;
  2067. this.enterFunctionScope();
  2068. this.expect(types.parenL);
  2069. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2070. this.checkYieldAwaitInDefaultParams();
  2071. this.parseFunctionBody(node, false);
  2072. this.inGenerator = oldInGen;
  2073. this.inAsync = oldInAsync;
  2074. this.yieldPos = oldYieldPos;
  2075. this.awaitPos = oldAwaitPos;
  2076. this.inFunction = oldInFunc;
  2077. return this.finishNode(node, "FunctionExpression")
  2078. };
  2079. // Parse arrow function expression with given parameters.
  2080. pp$3.parseArrowExpression = function(node, params, isAsync) {
  2081. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2082. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2083. this.enterFunctionScope();
  2084. this.initFunction(node);
  2085. if (this.options.ecmaVersion >= 8)
  2086. { node.async = !!isAsync; }
  2087. this.inGenerator = false;
  2088. this.inAsync = node.async;
  2089. this.yieldPos = 0;
  2090. this.awaitPos = 0;
  2091. this.inFunction = true;
  2092. node.params = this.toAssignableList(params, true);
  2093. this.parseFunctionBody(node, true);
  2094. this.inGenerator = oldInGen;
  2095. this.inAsync = oldInAsync;
  2096. this.yieldPos = oldYieldPos;
  2097. this.awaitPos = oldAwaitPos;
  2098. this.inFunction = oldInFunc;
  2099. return this.finishNode(node, "ArrowFunctionExpression")
  2100. };
  2101. // Parse function body and check parameters.
  2102. pp$3.parseFunctionBody = function(node, isArrowFunction) {
  2103. var isExpression = isArrowFunction && this.type !== types.braceL;
  2104. var oldStrict = this.strict, useStrict = false;
  2105. if (isExpression) {
  2106. node.body = this.parseMaybeAssign();
  2107. node.expression = true;
  2108. this.checkParams(node, false);
  2109. } else {
  2110. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2111. if (!oldStrict || nonSimple) {
  2112. useStrict = this.strictDirective(this.end);
  2113. // If this is a strict mode function, verify that argument names
  2114. // are not repeated, and it does not try to bind the words `eval`
  2115. // or `arguments`.
  2116. if (useStrict && nonSimple)
  2117. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2118. }
  2119. // Start a new scope with regard to labels and the `inFunction`
  2120. // flag (restore them to their old value afterwards).
  2121. var oldLabels = this.labels;
  2122. this.labels = [];
  2123. if (useStrict) { this.strict = true; }
  2124. // Add the params to varDeclaredNames to ensure that an error is thrown
  2125. // if a let/const declaration in the function clashes with one of the params.
  2126. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
  2127. node.body = this.parseBlock(false);
  2128. node.expression = false;
  2129. this.labels = oldLabels;
  2130. }
  2131. this.exitFunctionScope();
  2132. if (this.strict && node.id) {
  2133. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2134. this.checkLVal(node.id, "none");
  2135. }
  2136. this.strict = oldStrict;
  2137. };
  2138. pp$3.isSimpleParamList = function(params) {
  2139. for (var i = 0, list = params; i < list.length; i += 1)
  2140. {
  2141. var param = list[i];
  2142. if (param.type !== "Identifier") { return false
  2143. } }
  2144. return true
  2145. };
  2146. // Checks function params for various disallowed patterns such as using "eval"
  2147. // or "arguments" and duplicate parameters.
  2148. pp$3.checkParams = function(node, allowDuplicates) {
  2149. var this$1 = this;
  2150. var nameHash = {};
  2151. for (var i = 0, list = node.params; i < list.length; i += 1)
  2152. {
  2153. var param = list[i];
  2154. this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
  2155. }
  2156. };
  2157. // Parses a comma-separated list of expressions, and returns them as
  2158. // an array. `close` is the token type that ends the list, and
  2159. // `allowEmpty` can be turned on to allow subsequent commas with
  2160. // nothing in between them to be parsed as `null` (which is needed
  2161. // for array literals).
  2162. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2163. var this$1 = this;
  2164. var elts = [], first = true;
  2165. while (!this.eat(close)) {
  2166. if (!first) {
  2167. this$1.expect(types.comma);
  2168. if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
  2169. } else { first = false; }
  2170. var elt = (void 0);
  2171. if (allowEmpty && this$1.type === types.comma)
  2172. { elt = null; }
  2173. else if (this$1.type === types.ellipsis) {
  2174. elt = this$1.parseSpread(refDestructuringErrors);
  2175. if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
  2176. { refDestructuringErrors.trailingComma = this$1.start; }
  2177. } else {
  2178. elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
  2179. }
  2180. elts.push(elt);
  2181. }
  2182. return elts
  2183. };
  2184. // Parse the next token as an identifier. If `liberal` is true (used
  2185. // when parsing properties), it will also convert keywords into
  2186. // identifiers.
  2187. pp$3.checkUnreserved = function(ref) {
  2188. var start = ref.start;
  2189. var end = ref.end;
  2190. var name = ref.name;
  2191. if (this.inGenerator && name === "yield")
  2192. { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
  2193. if (this.inAsync && name === "await")
  2194. { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
  2195. if (this.isKeyword(name))
  2196. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2197. if (this.options.ecmaVersion < 6 &&
  2198. this.input.slice(start, end).indexOf("\\") != -1) { return }
  2199. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2200. if (re.test(name))
  2201. { this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved")); }
  2202. };
  2203. pp$3.parseIdent = function(liberal, isBinding) {
  2204. var node = this.startNode();
  2205. if (liberal && this.options.allowReserved == "never") { liberal = false; }
  2206. if (this.type === types.name) {
  2207. node.name = this.value;
  2208. } else if (this.type.keyword) {
  2209. node.name = this.type.keyword;
  2210. } else {
  2211. this.unexpected();
  2212. }
  2213. this.next();
  2214. this.finishNode(node, "Identifier");
  2215. if (!liberal) { this.checkUnreserved(node); }
  2216. return node
  2217. };
  2218. // Parses yield expression inside generator.
  2219. pp$3.parseYield = function() {
  2220. if (!this.yieldPos) { this.yieldPos = this.start; }
  2221. var node = this.startNode();
  2222. this.next();
  2223. if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
  2224. node.delegate = false;
  2225. node.argument = null;
  2226. } else {
  2227. node.delegate = this.eat(types.star);
  2228. node.argument = this.parseMaybeAssign();
  2229. }
  2230. return this.finishNode(node, "YieldExpression")
  2231. };
  2232. pp$3.parseAwait = function() {
  2233. if (!this.awaitPos) { this.awaitPos = this.start; }
  2234. var node = this.startNode();
  2235. this.next();
  2236. node.argument = this.parseMaybeUnary(null, true);
  2237. return this.finishNode(node, "AwaitExpression")
  2238. };
  2239. var pp$4 = Parser.prototype;
  2240. // This function is used to raise exceptions on parse errors. It
  2241. // takes an offset integer (into the current `input`) to indicate
  2242. // the location of the error, attaches the position to the end
  2243. // of the error message, and then raises a `SyntaxError` with that
  2244. // message.
  2245. pp$4.raise = function(pos, message) {
  2246. var loc = getLineInfo(this.input, pos);
  2247. message += " (" + loc.line + ":" + loc.column + ")";
  2248. var err = new SyntaxError(message);
  2249. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  2250. throw err
  2251. };
  2252. pp$4.raiseRecoverable = pp$4.raise;
  2253. pp$4.curPosition = function() {
  2254. if (this.options.locations) {
  2255. return new Position(this.curLine, this.pos - this.lineStart)
  2256. }
  2257. };
  2258. var pp$5 = Parser.prototype;
  2259. // Object.assign polyfill
  2260. var assign = Object.assign || function(target) {
  2261. var sources = [], len = arguments.length - 1;
  2262. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  2263. for (var i = 0, list = sources; i < list.length; i += 1) {
  2264. var source = list[i];
  2265. for (var key in source) {
  2266. if (has(source, key)) {
  2267. target[key] = source[key];
  2268. }
  2269. }
  2270. }
  2271. return target
  2272. };
  2273. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  2274. pp$5.enterFunctionScope = function() {
  2275. // var: a hash of var-declared names in the current lexical scope
  2276. // lexical: a hash of lexically-declared names in the current lexical scope
  2277. // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
  2278. // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
  2279. this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
  2280. };
  2281. pp$5.exitFunctionScope = function() {
  2282. this.scopeStack.pop();
  2283. };
  2284. pp$5.enterLexicalScope = function() {
  2285. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2286. var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
  2287. this.scopeStack.push(childScope);
  2288. assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
  2289. };
  2290. pp$5.exitLexicalScope = function() {
  2291. var childScope = this.scopeStack.pop();
  2292. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2293. assign(parentScope.childVar, childScope.var, childScope.childVar);
  2294. };
  2295. /**
  2296. * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
  2297. * in the current lexical scope or any of the parent lexical scopes in this function.
  2298. */
  2299. pp$5.canDeclareVarName = function(name) {
  2300. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2301. return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
  2302. };
  2303. /**
  2304. * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
  2305. * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
  2306. * any child lexical scopes in this function.
  2307. */
  2308. pp$5.canDeclareLexicalName = function(name) {
  2309. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2310. return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
  2311. };
  2312. pp$5.declareVarName = function(name) {
  2313. this.scopeStack[this.scopeStack.length - 1].var[name] = true;
  2314. };
  2315. pp$5.declareLexicalName = function(name) {
  2316. this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
  2317. };
  2318. var Node = function Node(parser, pos, loc) {
  2319. this.type = "";
  2320. this.start = pos;
  2321. this.end = 0;
  2322. if (parser.options.locations)
  2323. { this.loc = new SourceLocation(parser, loc); }
  2324. if (parser.options.directSourceFile)
  2325. { this.sourceFile = parser.options.directSourceFile; }
  2326. if (parser.options.ranges)
  2327. { this.range = [pos, 0]; }
  2328. };
  2329. // Start an AST node, attaching a start offset.
  2330. var pp$6 = Parser.prototype;
  2331. pp$6.startNode = function() {
  2332. return new Node(this, this.start, this.startLoc)
  2333. };
  2334. pp$6.startNodeAt = function(pos, loc) {
  2335. return new Node(this, pos, loc)
  2336. };
  2337. // Finish an AST node, adding `type` and `end` properties.
  2338. function finishNodeAt(node, type, pos, loc) {
  2339. node.type = type;
  2340. node.end = pos;
  2341. if (this.options.locations)
  2342. { node.loc.end = loc; }
  2343. if (this.options.ranges)
  2344. { node.range[1] = pos; }
  2345. return node
  2346. }
  2347. pp$6.finishNode = function(node, type) {
  2348. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  2349. };
  2350. // Finish node at given position
  2351. pp$6.finishNodeAt = function(node, type, pos, loc) {
  2352. return finishNodeAt.call(this, node, type, pos, loc)
  2353. };
  2354. // The algorithm used to determine whether a regexp can appear at a
  2355. // given point in the program is loosely based on sweet.js' approach.
  2356. // See https://github.com/mozilla/sweet.js/wiki/design
  2357. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2358. this.token = token;
  2359. this.isExpr = !!isExpr;
  2360. this.preserveSpace = !!preserveSpace;
  2361. this.override = override;
  2362. this.generator = !!generator;
  2363. };
  2364. var types$1 = {
  2365. b_stat: new TokContext("{", false),
  2366. b_expr: new TokContext("{", true),
  2367. b_tmpl: new TokContext("${", false),
  2368. p_stat: new TokContext("(", false),
  2369. p_expr: new TokContext("(", true),
  2370. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2371. f_stat: new TokContext("function", false),
  2372. f_expr: new TokContext("function", true),
  2373. f_expr_gen: new TokContext("function", true, false, null, true),
  2374. f_gen: new TokContext("function", false, false, null, true)
  2375. };
  2376. var pp$7 = Parser.prototype;
  2377. pp$7.initialContext = function() {
  2378. return [types$1.b_stat]
  2379. };
  2380. pp$7.braceIsBlock = function(prevType) {
  2381. var parent = this.curContext();
  2382. if (parent === types$1.f_expr || parent === types$1.f_stat)
  2383. { return true }
  2384. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  2385. { return !parent.isExpr }
  2386. // The check for `tt.name && exprAllowed` detects whether we are
  2387. // after a `yield` or `of` construct. See the `updateContext` for
  2388. // `tt.name`.
  2389. if (prevType === types._return || prevType == types.name && this.exprAllowed)
  2390. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2391. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
  2392. { return true }
  2393. if (prevType == types.braceL)
  2394. { return parent === types$1.b_stat }
  2395. if (prevType == types._var || prevType == types.name)
  2396. { return false }
  2397. return !this.exprAllowed
  2398. };
  2399. pp$7.inGeneratorContext = function() {
  2400. var this$1 = this;
  2401. for (var i = this.context.length - 1; i >= 1; i--) {
  2402. var context = this$1.context[i];
  2403. if (context.token === "function")
  2404. { return context.generator }
  2405. }
  2406. return false
  2407. };
  2408. pp$7.updateContext = function(prevType) {
  2409. var update, type = this.type;
  2410. if (type.keyword && prevType == types.dot)
  2411. { this.exprAllowed = false; }
  2412. else if (update = type.updateContext)
  2413. { update.call(this, prevType); }
  2414. else
  2415. { this.exprAllowed = type.beforeExpr; }
  2416. };
  2417. // Token-specific context update code
  2418. types.parenR.updateContext = types.braceR.updateContext = function() {
  2419. if (this.context.length == 1) {
  2420. this.exprAllowed = true;
  2421. return
  2422. }
  2423. var out = this.context.pop();
  2424. if (out === types$1.b_stat && this.curContext().token === "function") {
  2425. out = this.context.pop();
  2426. }
  2427. this.exprAllowed = !out.isExpr;
  2428. };
  2429. types.braceL.updateContext = function(prevType) {
  2430. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  2431. this.exprAllowed = true;
  2432. };
  2433. types.dollarBraceL.updateContext = function() {
  2434. this.context.push(types$1.b_tmpl);
  2435. this.exprAllowed = true;
  2436. };
  2437. types.parenL.updateContext = function(prevType) {
  2438. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  2439. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  2440. this.exprAllowed = true;
  2441. };
  2442. types.incDec.updateContext = function() {
  2443. // tokExprAllowed stays unchanged
  2444. };
  2445. types._function.updateContext = types._class.updateContext = function(prevType) {
  2446. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  2447. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  2448. { this.context.push(types$1.f_expr); }
  2449. else
  2450. { this.context.push(types$1.f_stat); }
  2451. this.exprAllowed = false;
  2452. };
  2453. types.backQuote.updateContext = function() {
  2454. if (this.curContext() === types$1.q_tmpl)
  2455. { this.context.pop(); }
  2456. else
  2457. { this.context.push(types$1.q_tmpl); }
  2458. this.exprAllowed = false;
  2459. };
  2460. types.star.updateContext = function(prevType) {
  2461. if (prevType == types._function) {
  2462. var index = this.context.length - 1;
  2463. if (this.context[index] === types$1.f_expr)
  2464. { this.context[index] = types$1.f_expr_gen; }
  2465. else
  2466. { this.context[index] = types$1.f_gen; }
  2467. }
  2468. this.exprAllowed = true;
  2469. };
  2470. types.name.updateContext = function(prevType) {
  2471. var allowed = false;
  2472. if (this.options.ecmaVersion >= 6) {
  2473. if (this.value == "of" && !this.exprAllowed ||
  2474. this.value == "yield" && this.inGeneratorContext())
  2475. { allowed = true; }
  2476. }
  2477. this.exprAllowed = allowed;
  2478. };
  2479. // Object type used to represent tokens. Note that normally, tokens
  2480. // simply exist as properties on the parser object. This is only
  2481. // used for the onToken callback and the external tokenizer.
  2482. var Token = function Token(p) {
  2483. this.type = p.type;
  2484. this.value = p.value;
  2485. this.start = p.start;
  2486. this.end = p.end;
  2487. if (p.options.locations)
  2488. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  2489. if (p.options.ranges)
  2490. { this.range = [p.start, p.end]; }
  2491. };
  2492. // ## Tokenizer
  2493. var pp$8 = Parser.prototype;
  2494. // Are we running under Rhino?
  2495. var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
  2496. // Move to the next token
  2497. pp$8.next = function() {
  2498. if (this.options.onToken)
  2499. { this.options.onToken(new Token(this)); }
  2500. this.lastTokEnd = this.end;
  2501. this.lastTokStart = this.start;
  2502. this.lastTokEndLoc = this.endLoc;
  2503. this.lastTokStartLoc = this.startLoc;
  2504. this.nextToken();
  2505. };
  2506. pp$8.getToken = function() {
  2507. this.next();
  2508. return new Token(this)
  2509. };
  2510. // If we're in an ES6 environment, make parsers iterable
  2511. if (typeof Symbol !== "undefined")
  2512. { pp$8[Symbol.iterator] = function() {
  2513. var this$1 = this;
  2514. return {
  2515. next: function () {
  2516. var token = this$1.getToken();
  2517. return {
  2518. done: token.type === types.eof,
  2519. value: token
  2520. }
  2521. }
  2522. }
  2523. }; }
  2524. // Toggle strict mode. Re-reads the next number or string to please
  2525. // pedantic tests (`"use strict"; 010;` should fail).
  2526. pp$8.curContext = function() {
  2527. return this.context[this.context.length - 1]
  2528. };
  2529. // Read a single token, updating the parser object's token-related
  2530. // properties.
  2531. pp$8.nextToken = function() {
  2532. var curContext = this.curContext();
  2533. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  2534. this.start = this.pos;
  2535. if (this.options.locations) { this.startLoc = this.curPosition(); }
  2536. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  2537. if (curContext.override) { return curContext.override(this) }
  2538. else { this.readToken(this.fullCharCodeAtPos()); }
  2539. };
  2540. pp$8.readToken = function(code) {
  2541. // Identifier or keyword. '\uXXXX' sequences are allowed in
  2542. // identifiers, so '\' also dispatches to that.
  2543. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  2544. { return this.readWord() }
  2545. return this.getTokenFromCode(code)
  2546. };
  2547. pp$8.fullCharCodeAtPos = function() {
  2548. var code = this.input.charCodeAt(this.pos);
  2549. if (code <= 0xd7ff || code >= 0xe000) { return code }
  2550. var next = this.input.charCodeAt(this.pos + 1);
  2551. return (code << 10) + next - 0x35fdc00
  2552. };
  2553. pp$8.skipBlockComment = function() {
  2554. var this$1 = this;
  2555. var startLoc = this.options.onComment && this.curPosition();
  2556. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  2557. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  2558. this.pos = end + 2;
  2559. if (this.options.locations) {
  2560. lineBreakG.lastIndex = start;
  2561. var match;
  2562. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  2563. ++this$1.curLine;
  2564. this$1.lineStart = match.index + match[0].length;
  2565. }
  2566. }
  2567. if (this.options.onComment)
  2568. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  2569. startLoc, this.curPosition()); }
  2570. };
  2571. pp$8.skipLineComment = function(startSkip) {
  2572. var this$1 = this;
  2573. var start = this.pos;
  2574. var startLoc = this.options.onComment && this.curPosition();
  2575. var ch = this.input.charCodeAt(this.pos += startSkip);
  2576. while (this.pos < this.input.length && !isNewLine(ch)) {
  2577. ch = this$1.input.charCodeAt(++this$1.pos);
  2578. }
  2579. if (this.options.onComment)
  2580. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  2581. startLoc, this.curPosition()); }
  2582. };
  2583. // Called at the start of the parse and after every token. Skips
  2584. // whitespace and comments, and.
  2585. pp$8.skipSpace = function() {
  2586. var this$1 = this;
  2587. loop: while (this.pos < this.input.length) {
  2588. var ch = this$1.input.charCodeAt(this$1.pos);
  2589. switch (ch) {
  2590. case 32: case 160: // ' '
  2591. ++this$1.pos;
  2592. break
  2593. case 13:
  2594. if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
  2595. ++this$1.pos;
  2596. }
  2597. case 10: case 8232: case 8233:
  2598. ++this$1.pos;
  2599. if (this$1.options.locations) {
  2600. ++this$1.curLine;
  2601. this$1.lineStart = this$1.pos;
  2602. }
  2603. break
  2604. case 47: // '/'
  2605. switch (this$1.input.charCodeAt(this$1.pos + 1)) {
  2606. case 42: // '*'
  2607. this$1.skipBlockComment();
  2608. break
  2609. case 47:
  2610. this$1.skipLineComment(2);
  2611. break
  2612. default:
  2613. break loop
  2614. }
  2615. break
  2616. default:
  2617. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  2618. ++this$1.pos;
  2619. } else {
  2620. break loop
  2621. }
  2622. }
  2623. }
  2624. };
  2625. // Called at the end of every token. Sets `end`, `val`, and
  2626. // maintains `context` and `exprAllowed`, and skips the space after
  2627. // the token, so that the next one's `start` will point at the
  2628. // right position.
  2629. pp$8.finishToken = function(type, val) {
  2630. this.end = this.pos;
  2631. if (this.options.locations) { this.endLoc = this.curPosition(); }
  2632. var prevType = this.type;
  2633. this.type = type;
  2634. this.value = val;
  2635. this.updateContext(prevType);
  2636. };
  2637. // ### Token reading
  2638. // This is the function that is called to fetch the next token. It
  2639. // is somewhat obscure, because it works in character codes rather
  2640. // than characters, and because operator parsing has been inlined
  2641. // into it.
  2642. //
  2643. // All in the name of speed.
  2644. //
  2645. pp$8.readToken_dot = function() {
  2646. var next = this.input.charCodeAt(this.pos + 1);
  2647. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  2648. var next2 = this.input.charCodeAt(this.pos + 2);
  2649. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  2650. this.pos += 3;
  2651. return this.finishToken(types.ellipsis)
  2652. } else {
  2653. ++this.pos;
  2654. return this.finishToken(types.dot)
  2655. }
  2656. };
  2657. pp$8.readToken_slash = function() { // '/'
  2658. var next = this.input.charCodeAt(this.pos + 1);
  2659. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  2660. if (next === 61) { return this.finishOp(types.assign, 2) }
  2661. return this.finishOp(types.slash, 1)
  2662. };
  2663. pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
  2664. var next = this.input.charCodeAt(this.pos + 1);
  2665. var size = 1;
  2666. var tokentype = code === 42 ? types.star : types.modulo;
  2667. // exponentiation operator ** and **=
  2668. if (this.options.ecmaVersion >= 7 && next === 42) {
  2669. ++size;
  2670. tokentype = types.starstar;
  2671. next = this.input.charCodeAt(this.pos + 2);
  2672. }
  2673. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  2674. return this.finishOp(tokentype, size)
  2675. };
  2676. pp$8.readToken_pipe_amp = function(code) { // '|&'
  2677. var next = this.input.charCodeAt(this.pos + 1);
  2678. if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
  2679. if (next === 61) { return this.finishOp(types.assign, 2) }
  2680. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  2681. };
  2682. pp$8.readToken_caret = function() { // '^'
  2683. var next = this.input.charCodeAt(this.pos + 1);
  2684. if (next === 61) { return this.finishOp(types.assign, 2) }
  2685. return this.finishOp(types.bitwiseXOR, 1)
  2686. };
  2687. pp$8.readToken_plus_min = function(code) { // '+-'
  2688. var next = this.input.charCodeAt(this.pos + 1);
  2689. if (next === code) {
  2690. if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 &&
  2691. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  2692. // A `-->` line comment
  2693. this.skipLineComment(3);
  2694. this.skipSpace();
  2695. return this.nextToken()
  2696. }
  2697. return this.finishOp(types.incDec, 2)
  2698. }
  2699. if (next === 61) { return this.finishOp(types.assign, 2) }
  2700. return this.finishOp(types.plusMin, 1)
  2701. };
  2702. pp$8.readToken_lt_gt = function(code) { // '<>'
  2703. var next = this.input.charCodeAt(this.pos + 1);
  2704. var size = 1;
  2705. if (next === code) {
  2706. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  2707. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  2708. return this.finishOp(types.bitShift, size)
  2709. }
  2710. if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 &&
  2711. this.input.charCodeAt(this.pos + 3) == 45) {
  2712. if (this.inModule) { this.unexpected(); }
  2713. // `<!--`, an XML-style comment that should be interpreted as a line comment
  2714. this.skipLineComment(4);
  2715. this.skipSpace();
  2716. return this.nextToken()
  2717. }
  2718. if (next === 61) { size = 2; }
  2719. return this.finishOp(types.relational, size)
  2720. };
  2721. pp$8.readToken_eq_excl = function(code) { // '=!'
  2722. var next = this.input.charCodeAt(this.pos + 1);
  2723. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  2724. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  2725. this.pos += 2;
  2726. return this.finishToken(types.arrow)
  2727. }
  2728. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  2729. };
  2730. pp$8.getTokenFromCode = function(code) {
  2731. switch (code) {
  2732. // The interpretation of a dot depends on whether it is followed
  2733. // by a digit or another two dots.
  2734. case 46: // '.'
  2735. return this.readToken_dot()
  2736. // Punctuation tokens.
  2737. case 40: ++this.pos; return this.finishToken(types.parenL)
  2738. case 41: ++this.pos; return this.finishToken(types.parenR)
  2739. case 59: ++this.pos; return this.finishToken(types.semi)
  2740. case 44: ++this.pos; return this.finishToken(types.comma)
  2741. case 91: ++this.pos; return this.finishToken(types.bracketL)
  2742. case 93: ++this.pos; return this.finishToken(types.bracketR)
  2743. case 123: ++this.pos; return this.finishToken(types.braceL)
  2744. case 125: ++this.pos; return this.finishToken(types.braceR)
  2745. case 58: ++this.pos; return this.finishToken(types.colon)
  2746. case 63: ++this.pos; return this.finishToken(types.question)
  2747. case 96: // '`'
  2748. if (this.options.ecmaVersion < 6) { break }
  2749. ++this.pos;
  2750. return this.finishToken(types.backQuote)
  2751. case 48: // '0'
  2752. var next = this.input.charCodeAt(this.pos + 1);
  2753. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  2754. if (this.options.ecmaVersion >= 6) {
  2755. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  2756. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  2757. }
  2758. // Anything else beginning with a digit is an integer, octal
  2759. // number, or float.
  2760. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  2761. return this.readNumber(false)
  2762. // Quotes produce strings.
  2763. case 34: case 39: // '"', "'"
  2764. return this.readString(code)
  2765. // Operators are parsed inline in tiny state machines. '=' (61) is
  2766. // often referred to. `finishOp` simply skips the amount of
  2767. // characters it is given as second argument, and returns a token
  2768. // of the type given by its first argument.
  2769. case 47: // '/'
  2770. return this.readToken_slash()
  2771. case 37: case 42: // '%*'
  2772. return this.readToken_mult_modulo_exp(code)
  2773. case 124: case 38: // '|&'
  2774. return this.readToken_pipe_amp(code)
  2775. case 94: // '^'
  2776. return this.readToken_caret()
  2777. case 43: case 45: // '+-'
  2778. return this.readToken_plus_min(code)
  2779. case 60: case 62: // '<>'
  2780. return this.readToken_lt_gt(code)
  2781. case 61: case 33: // '=!'
  2782. return this.readToken_eq_excl(code)
  2783. case 126: // '~'
  2784. return this.finishOp(types.prefix, 1)
  2785. }
  2786. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  2787. };
  2788. pp$8.finishOp = function(type, size) {
  2789. var str = this.input.slice(this.pos, this.pos + size);
  2790. this.pos += size;
  2791. return this.finishToken(type, str)
  2792. };
  2793. // Parse a regular expression. Some context-awareness is necessary,
  2794. // since a '/' inside a '[]' set does not end the expression.
  2795. function tryCreateRegexp(src, flags, throwErrorAt, parser) {
  2796. try {
  2797. return new RegExp(src, flags)
  2798. } catch (e) {
  2799. if (throwErrorAt !== undefined) {
  2800. if (e instanceof SyntaxError) { parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message); }
  2801. throw e
  2802. }
  2803. }
  2804. }
  2805. var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
  2806. pp$8.readRegexp = function() {
  2807. var this$1 = this;
  2808. var escaped, inClass, start = this.pos;
  2809. for (;;) {
  2810. if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
  2811. var ch = this$1.input.charAt(this$1.pos);
  2812. if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
  2813. if (!escaped) {
  2814. if (ch === "[") { inClass = true; }
  2815. else if (ch === "]" && inClass) { inClass = false; }
  2816. else if (ch === "/" && !inClass) { break }
  2817. escaped = ch === "\\";
  2818. } else { escaped = false; }
  2819. ++this$1.pos;
  2820. }
  2821. var content = this.input.slice(start, this.pos);
  2822. ++this.pos;
  2823. // Need to use `readWord1` because '\uXXXX' sequences are allowed
  2824. // here (don't ask).
  2825. var mods = this.readWord1();
  2826. var tmp = content, tmpFlags = "";
  2827. if (mods) {
  2828. var validFlags = /^[gim]*$/;
  2829. if (this.options.ecmaVersion >= 6) { validFlags = /^[gimuy]*$/; }
  2830. if (!validFlags.test(mods)) { this.raise(start, "Invalid regular expression flag"); }
  2831. if (mods.indexOf("u") >= 0) {
  2832. if (regexpUnicodeSupport) {
  2833. tmpFlags = "u";
  2834. } else {
  2835. // Replace each astral symbol and every Unicode escape sequence that
  2836. // possibly represents an astral symbol or a paired surrogate with a
  2837. // single ASCII symbol to avoid throwing on regular expressions that
  2838. // are only valid in combination with the `/u` flag.
  2839. // Note: replacing with the ASCII symbol `x` might cause false
  2840. // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
  2841. // perfectly valid pattern that is equivalent to `[a-b]`, but it would
  2842. // be replaced by `[x-b]` which throws an error.
  2843. tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
  2844. code = Number("0x" + code);
  2845. if (code > 0x10FFFF) { this$1.raise(start + offset + 3, "Code point out of bounds"); }
  2846. return "x"
  2847. });
  2848. tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
  2849. tmpFlags = tmpFlags.replace("u", "");
  2850. }
  2851. }
  2852. }
  2853. // Detect invalid regular expressions.
  2854. var value = null;
  2855. // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
  2856. // so don't do detection if we are running under Rhino
  2857. if (!isRhino) {
  2858. tryCreateRegexp(tmp, tmpFlags, start, this);
  2859. // Get a regular expression object for this pattern-flag pair, or `null` in
  2860. // case the current environment doesn't support the flags it uses.
  2861. value = tryCreateRegexp(content, mods);
  2862. }
  2863. return this.finishToken(types.regexp, {pattern: content, flags: mods, value: value})
  2864. };
  2865. // Read an integer in the given radix. Return null if zero digits
  2866. // were read, the integer value otherwise. When `len` is given, this
  2867. // will return `null` unless the integer has exactly `len` digits.
  2868. pp$8.readInt = function(radix, len) {
  2869. var this$1 = this;
  2870. var start = this.pos, total = 0;
  2871. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2872. var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
  2873. if (code >= 97) { val = code - 97 + 10; } // a
  2874. else if (code >= 65) { val = code - 65 + 10; } // A
  2875. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  2876. else { val = Infinity; }
  2877. if (val >= radix) { break }
  2878. ++this$1.pos;
  2879. total = total * radix + val;
  2880. }
  2881. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  2882. return total
  2883. };
  2884. pp$8.readRadixNumber = function(radix) {
  2885. this.pos += 2; // 0x
  2886. var val = this.readInt(radix);
  2887. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  2888. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  2889. return this.finishToken(types.num, val)
  2890. };
  2891. // Read an integer, octal integer, or floating-point number.
  2892. pp$8.readNumber = function(startsWithDot) {
  2893. var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48;
  2894. if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  2895. if (octal && this.pos == start + 1) { octal = false; }
  2896. var next = this.input.charCodeAt(this.pos);
  2897. if (next === 46 && !octal) { // '.'
  2898. ++this.pos;
  2899. this.readInt(10);
  2900. isFloat = true;
  2901. next = this.input.charCodeAt(this.pos);
  2902. }
  2903. if ((next === 69 || next === 101) && !octal) { // 'eE'
  2904. next = this.input.charCodeAt(++this.pos);
  2905. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  2906. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  2907. isFloat = true;
  2908. }
  2909. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  2910. var str = this.input.slice(start, this.pos), val;
  2911. if (isFloat) { val = parseFloat(str); }
  2912. else if (!octal || str.length === 1) { val = parseInt(str, 10); }
  2913. else if (this.strict) { this.raise(start, "Invalid number"); }
  2914. else if (/[89]/.test(str)) { val = parseInt(str, 10); }
  2915. else { val = parseInt(str, 8); }
  2916. return this.finishToken(types.num, val)
  2917. };
  2918. // Read a string value, interpreting backslash-escapes.
  2919. pp$8.readCodePoint = function() {
  2920. var ch = this.input.charCodeAt(this.pos), code;
  2921. if (ch === 123) { // '{'
  2922. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  2923. var codePos = ++this.pos;
  2924. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  2925. ++this.pos;
  2926. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  2927. } else {
  2928. code = this.readHexChar(4);
  2929. }
  2930. return code
  2931. };
  2932. function codePointToString(code) {
  2933. // UTF-16 Decoding
  2934. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  2935. code -= 0x10000;
  2936. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  2937. }
  2938. pp$8.readString = function(quote) {
  2939. var this$1 = this;
  2940. var out = "", chunkStart = ++this.pos;
  2941. for (;;) {
  2942. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
  2943. var ch = this$1.input.charCodeAt(this$1.pos);
  2944. if (ch === quote) { break }
  2945. if (ch === 92) { // '\'
  2946. out += this$1.input.slice(chunkStart, this$1.pos);
  2947. out += this$1.readEscapedChar(false);
  2948. chunkStart = this$1.pos;
  2949. } else {
  2950. if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
  2951. ++this$1.pos;
  2952. }
  2953. }
  2954. out += this.input.slice(chunkStart, this.pos++);
  2955. return this.finishToken(types.string, out)
  2956. };
  2957. // Reads template string tokens.
  2958. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  2959. pp$8.tryReadTemplateToken = function() {
  2960. this.inTemplateElement = true;
  2961. try {
  2962. this.readTmplToken();
  2963. } catch (err) {
  2964. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  2965. this.readInvalidTemplateToken();
  2966. } else {
  2967. throw err
  2968. }
  2969. }
  2970. this.inTemplateElement = false;
  2971. };
  2972. pp$8.invalidStringToken = function(position, message) {
  2973. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  2974. throw INVALID_TEMPLATE_ESCAPE_ERROR
  2975. } else {
  2976. this.raise(position, message);
  2977. }
  2978. };
  2979. pp$8.readTmplToken = function() {
  2980. var this$1 = this;
  2981. var out = "", chunkStart = this.pos;
  2982. for (;;) {
  2983. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
  2984. var ch = this$1.input.charCodeAt(this$1.pos);
  2985. if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
  2986. if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
  2987. if (ch === 36) {
  2988. this$1.pos += 2;
  2989. return this$1.finishToken(types.dollarBraceL)
  2990. } else {
  2991. ++this$1.pos;
  2992. return this$1.finishToken(types.backQuote)
  2993. }
  2994. }
  2995. out += this$1.input.slice(chunkStart, this$1.pos);
  2996. return this$1.finishToken(types.template, out)
  2997. }
  2998. if (ch === 92) { // '\'
  2999. out += this$1.input.slice(chunkStart, this$1.pos);
  3000. out += this$1.readEscapedChar(true);
  3001. chunkStart = this$1.pos;
  3002. } else if (isNewLine(ch)) {
  3003. out += this$1.input.slice(chunkStart, this$1.pos);
  3004. ++this$1.pos;
  3005. switch (ch) {
  3006. case 13:
  3007. if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
  3008. case 10:
  3009. out += "\n";
  3010. break
  3011. default:
  3012. out += String.fromCharCode(ch);
  3013. break
  3014. }
  3015. if (this$1.options.locations) {
  3016. ++this$1.curLine;
  3017. this$1.lineStart = this$1.pos;
  3018. }
  3019. chunkStart = this$1.pos;
  3020. } else {
  3021. ++this$1.pos;
  3022. }
  3023. }
  3024. };
  3025. // Reads a template token to search for the end, without validating any escape sequences
  3026. pp$8.readInvalidTemplateToken = function() {
  3027. var this$1 = this;
  3028. for (; this.pos < this.input.length; this.pos++) {
  3029. switch (this$1.input[this$1.pos]) {
  3030. case "\\":
  3031. ++this$1.pos;
  3032. break
  3033. case "$":
  3034. if (this$1.input[this$1.pos + 1] !== "{") {
  3035. break
  3036. }
  3037. // falls through
  3038. case "`":
  3039. return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
  3040. // no default
  3041. }
  3042. }
  3043. this.raise(this.start, "Unterminated template");
  3044. };
  3045. // Used to read escaped characters
  3046. pp$8.readEscapedChar = function(inTemplate) {
  3047. var ch = this.input.charCodeAt(++this.pos);
  3048. ++this.pos;
  3049. switch (ch) {
  3050. case 110: return "\n" // 'n' -> '\n'
  3051. case 114: return "\r" // 'r' -> '\r'
  3052. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  3053. case 117: return codePointToString(this.readCodePoint()) // 'u'
  3054. case 116: return "\t" // 't' -> '\t'
  3055. case 98: return "\b" // 'b' -> '\b'
  3056. case 118: return "\u000b" // 'v' -> '\u000b'
  3057. case 102: return "\f" // 'f' -> '\f'
  3058. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  3059. case 10: // ' \n'
  3060. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  3061. return ""
  3062. default:
  3063. if (ch >= 48 && ch <= 55) {
  3064. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  3065. var octal = parseInt(octalStr, 8);
  3066. if (octal > 255) {
  3067. octalStr = octalStr.slice(0, -1);
  3068. octal = parseInt(octalStr, 8);
  3069. }
  3070. if (octalStr !== "0" && (this.strict || inTemplate)) {
  3071. this.invalidStringToken(this.pos - 2, "Octal literal in strict mode");
  3072. }
  3073. this.pos += octalStr.length - 1;
  3074. return String.fromCharCode(octal)
  3075. }
  3076. return String.fromCharCode(ch)
  3077. }
  3078. };
  3079. // Used to read character escape sequences ('\x', '\u', '\U').
  3080. pp$8.readHexChar = function(len) {
  3081. var codePos = this.pos;
  3082. var n = this.readInt(16, len);
  3083. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  3084. return n
  3085. };
  3086. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  3087. // to whether the word contained a '\u' escape.
  3088. //
  3089. // Incrementally adds only escaped chars, adding other chunks as-is
  3090. // as a micro-optimization.
  3091. pp$8.readWord1 = function() {
  3092. var this$1 = this;
  3093. this.containsEsc = false;
  3094. var word = "", first = true, chunkStart = this.pos;
  3095. var astral = this.options.ecmaVersion >= 6;
  3096. while (this.pos < this.input.length) {
  3097. var ch = this$1.fullCharCodeAtPos();
  3098. if (isIdentifierChar(ch, astral)) {
  3099. this$1.pos += ch <= 0xffff ? 1 : 2;
  3100. } else if (ch === 92) { // "\"
  3101. this$1.containsEsc = true;
  3102. word += this$1.input.slice(chunkStart, this$1.pos);
  3103. var escStart = this$1.pos;
  3104. if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
  3105. { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  3106. ++this$1.pos;
  3107. var esc = this$1.readCodePoint();
  3108. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  3109. { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
  3110. word += codePointToString(esc);
  3111. chunkStart = this$1.pos;
  3112. } else {
  3113. break
  3114. }
  3115. first = false;
  3116. }
  3117. return word + this.input.slice(chunkStart, this.pos)
  3118. };
  3119. // Read an identifier or keyword token. Will check for reserved
  3120. // words when necessary.
  3121. pp$8.readWord = function() {
  3122. var word = this.readWord1();
  3123. var type = types.name;
  3124. if (this.keywords.test(word)) {
  3125. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
  3126. type = keywords$1[word];
  3127. }
  3128. return this.finishToken(type, word)
  3129. };
  3130. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  3131. //
  3132. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  3133. // various contributors and released under an MIT license.
  3134. //
  3135. // Git repositories for Acorn are available at
  3136. //
  3137. // http://marijnhaverbeke.nl/git/acorn
  3138. // https://github.com/ternjs/acorn.git
  3139. //
  3140. // Please use the [github bug tracker][ghbt] to report issues.
  3141. //
  3142. // [ghbt]: https://github.com/ternjs/acorn/issues
  3143. //
  3144. // This file defines the main parser interface. The library also comes
  3145. // with a [error-tolerant parser][dammit] and an
  3146. // [abstract syntax tree walker][walk], defined in other files.
  3147. //
  3148. // [dammit]: acorn_loose.js
  3149. // [walk]: util/walk.js
  3150. var version = "5.1.1";
  3151. // The main exported interface (under `self.acorn` when in the
  3152. // browser) is a `parse` function that takes a code string and
  3153. // returns an abstract syntax tree as specified by [Mozilla parser
  3154. // API][api].
  3155. //
  3156. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  3157. function parse(input, options) {
  3158. return new Parser(options, input).parse()
  3159. }
  3160. // This function tries to parse a single expression at a given
  3161. // offset in a string. Useful for parsing mixed-language formats
  3162. // that embed JavaScript expressions.
  3163. function parseExpressionAt(input, pos, options) {
  3164. var p = new Parser(options, input, pos);
  3165. p.nextToken();
  3166. return p.parseExpression()
  3167. }
  3168. // Acorn is organized as a tokenizer and a recursive-descent parser.
  3169. // The `tokenizer` export provides an interface to the tokenizer.
  3170. function tokenizer(input, options) {
  3171. return new Parser(options, input)
  3172. }
  3173. // This is a terrible kludge to support the existing, pre-ES6
  3174. // interface where the loose parser module retroactively adds exports
  3175. // to this module.
  3176. var parse_dammit;
  3177. var LooseParser;
  3178. var pluginsLoose; // eslint-disable-line camelcase
  3179. function addLooseExports(parse, Parser$$1, plugins$$1) {
  3180. parse_dammit = parse; // eslint-disable-line camelcase
  3181. LooseParser = Parser$$1;
  3182. pluginsLoose = plugins$$1;
  3183. }
  3184. export { version, parse, parseExpressionAt, tokenizer, parse_dammit, LooseParser, pluginsLoose, addLooseExports, Parser, plugins, defaultOptions, Position, SourceLocation, getLineInfo, Node, TokenType, types as tokTypes, keywords$1 as keywordTypes, TokContext, types$1 as tokContexts, isIdentifierChar, isIdentifierStart, Token, isNewLine, lineBreak, lineBreakG, nonASCIIwhitespace };