You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

acorn.js 187KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.acorn = {}));
  5. }(this, function (exports) { 'use strict';
  6. // Reserved word lists for various dialects of the language
  7. var reservedWords = {
  8. 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",
  9. 5: "class enum extends super const export import",
  10. 6: "enum",
  11. strict: "implements interface let package private protected public static yield",
  12. strictBind: "eval arguments"
  13. };
  14. // And the keywords
  15. 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";
  16. var keywords = {
  17. 5: ecma5AndLessKeywords,
  18. "5module": ecma5AndLessKeywords + " export import",
  19. 6: ecma5AndLessKeywords + " const class extends export import super"
  20. };
  21. var keywordRelationalOperator = /^in(stanceof)?$/;
  22. // ## Character categories
  23. // Big ugly regular expressions that match characters in the
  24. // whitespace, identifier, and identifier-start categories. These
  25. // are only applied when a character is found to actually have a
  26. // code point above 128.
  27. // Generated by `bin/generate-identifier-regex.js`.
  28. 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\u0560-\u0588\u05d0-\u05ea\u05ef-\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\u0860-\u086a\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\u09fc\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\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\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-\u1878\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\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\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-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7c6\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\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-\uab67\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";
  29. 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\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\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\u09fe\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\u0afa-\u0aff\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-\u0c04\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\u0d00-\u0d03\u0d3b\u0d3c\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-\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\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\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\ua8ff-\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";
  30. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  31. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  32. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  33. // These are a run-length and offset encoded representation of the
  34. // >0xffff code points that are a valid part of identifiers. The
  35. // offset starts at 0x10000, and each pair of numbers represents an
  36. // offset to the next range, and then a size of the range. They were
  37. // generated by bin/generate-identifier-regex.js
  38. // eslint-disable-next-line comma-spacing
  39. var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,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,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,155,22,13,52,76,44,33,24,27,35,30,0,12,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,21,0,33,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,0,161,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,754,9486,286,50,2,18,3,9,395,2309,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,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,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,15,7472,3104,541];
  40. // eslint-disable-next-line comma-spacing
  41. var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,232,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,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,262,6,10,9,419,13,1495,6,110,6,6,9,792487,239];
  42. // This has a complexity linear to the value of the code. The
  43. // assumption is that looking up astral identifier characters is
  44. // rare.
  45. function isInAstralSet(code, set) {
  46. var pos = 0x10000;
  47. for (var i = 0; i < set.length; i += 2) {
  48. pos += set[i];
  49. if (pos > code) { return false }
  50. pos += set[i + 1];
  51. if (pos >= code) { return true }
  52. }
  53. }
  54. // Test whether a given character code starts an identifier.
  55. function isIdentifierStart(code, astral) {
  56. if (code < 65) { return code === 36 }
  57. if (code < 91) { return true }
  58. if (code < 97) { return code === 95 }
  59. if (code < 123) { return true }
  60. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  61. if (astral === false) { return false }
  62. return isInAstralSet(code, astralIdentifierStartCodes)
  63. }
  64. // Test whether a given character is part of an identifier.
  65. function isIdentifierChar(code, astral) {
  66. if (code < 48) { return code === 36 }
  67. if (code < 58) { return true }
  68. if (code < 65) { return false }
  69. if (code < 91) { return true }
  70. if (code < 97) { return code === 95 }
  71. if (code < 123) { return true }
  72. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  73. if (astral === false) { return false }
  74. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  75. }
  76. // ## Token types
  77. // The assignment of fine-grained, information-carrying type objects
  78. // allows the tokenizer to store the information it has about a
  79. // token in a way that is very cheap for the parser to look up.
  80. // All token type variables start with an underscore, to make them
  81. // easy to recognize.
  82. // The `beforeExpr` property is used to disambiguate between regular
  83. // expressions and divisions. It is set on all token types that can
  84. // be followed by an expression (thus, a slash after them would be a
  85. // regular expression).
  86. //
  87. // The `startsExpr` property is used to check if the token ends a
  88. // `yield` expression. It is set on all token types that either can
  89. // directly start an expression (like a quotation mark) or can
  90. // continue an expression (like the body of a string).
  91. //
  92. // `isLoop` marks a keyword as starting a loop, which is important
  93. // to know when parsing a label, in order to allow or disallow
  94. // continue jumps to that label.
  95. var TokenType = function TokenType(label, conf) {
  96. if ( conf === void 0 ) conf = {};
  97. this.label = label;
  98. this.keyword = conf.keyword;
  99. this.beforeExpr = !!conf.beforeExpr;
  100. this.startsExpr = !!conf.startsExpr;
  101. this.isLoop = !!conf.isLoop;
  102. this.isAssign = !!conf.isAssign;
  103. this.prefix = !!conf.prefix;
  104. this.postfix = !!conf.postfix;
  105. this.binop = conf.binop || null;
  106. this.updateContext = null;
  107. };
  108. function binop(name, prec) {
  109. return new TokenType(name, {beforeExpr: true, binop: prec})
  110. }
  111. var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
  112. // Map keyword names to token types.
  113. var keywords$1 = {};
  114. // Succinct definitions of keyword token types
  115. function kw(name, options) {
  116. if ( options === void 0 ) options = {};
  117. options.keyword = name;
  118. return keywords$1[name] = new TokenType(name, options)
  119. }
  120. var types = {
  121. num: new TokenType("num", startsExpr),
  122. regexp: new TokenType("regexp", startsExpr),
  123. string: new TokenType("string", startsExpr),
  124. name: new TokenType("name", startsExpr),
  125. eof: new TokenType("eof"),
  126. // Punctuation token types.
  127. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  128. bracketR: new TokenType("]"),
  129. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  130. braceR: new TokenType("}"),
  131. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  132. parenR: new TokenType(")"),
  133. comma: new TokenType(",", beforeExpr),
  134. semi: new TokenType(";", beforeExpr),
  135. colon: new TokenType(":", beforeExpr),
  136. dot: new TokenType("."),
  137. question: new TokenType("?", beforeExpr),
  138. arrow: new TokenType("=>", beforeExpr),
  139. template: new TokenType("template"),
  140. invalidTemplate: new TokenType("invalidTemplate"),
  141. ellipsis: new TokenType("...", beforeExpr),
  142. backQuote: new TokenType("`", startsExpr),
  143. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  144. // Operators. These carry several kinds of properties to help the
  145. // parser use them properly (the presence of these properties is
  146. // what categorizes them as operators).
  147. //
  148. // `binop`, when present, specifies that this operator is a binary
  149. // operator, and will refer to its precedence.
  150. //
  151. // `prefix` and `postfix` mark the operator as a prefix or postfix
  152. // unary operator.
  153. //
  154. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  155. // binary operators with a very low precedence, that should result
  156. // in AssignmentExpression nodes.
  157. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  158. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  159. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  160. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  161. logicalOR: binop("||", 1),
  162. logicalAND: binop("&&", 2),
  163. bitwiseOR: binop("|", 3),
  164. bitwiseXOR: binop("^", 4),
  165. bitwiseAND: binop("&", 5),
  166. equality: binop("==/!=/===/!==", 6),
  167. relational: binop("</>/<=/>=", 7),
  168. bitShift: binop("<</>>/>>>", 8),
  169. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  170. modulo: binop("%", 10),
  171. star: binop("*", 10),
  172. slash: binop("/", 10),
  173. starstar: new TokenType("**", {beforeExpr: true}),
  174. // Keyword token types.
  175. _break: kw("break"),
  176. _case: kw("case", beforeExpr),
  177. _catch: kw("catch"),
  178. _continue: kw("continue"),
  179. _debugger: kw("debugger"),
  180. _default: kw("default", beforeExpr),
  181. _do: kw("do", {isLoop: true, beforeExpr: true}),
  182. _else: kw("else", beforeExpr),
  183. _finally: kw("finally"),
  184. _for: kw("for", {isLoop: true}),
  185. _function: kw("function", startsExpr),
  186. _if: kw("if"),
  187. _return: kw("return", beforeExpr),
  188. _switch: kw("switch"),
  189. _throw: kw("throw", beforeExpr),
  190. _try: kw("try"),
  191. _var: kw("var"),
  192. _const: kw("const"),
  193. _while: kw("while", {isLoop: true}),
  194. _with: kw("with"),
  195. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  196. _this: kw("this", startsExpr),
  197. _super: kw("super", startsExpr),
  198. _class: kw("class", startsExpr),
  199. _extends: kw("extends", beforeExpr),
  200. _export: kw("export"),
  201. _import: kw("import", startsExpr),
  202. _null: kw("null", startsExpr),
  203. _true: kw("true", startsExpr),
  204. _false: kw("false", startsExpr),
  205. _in: kw("in", {beforeExpr: true, binop: 7}),
  206. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  207. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  208. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  209. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  210. };
  211. // Matches a whole line break (where CRLF is considered a single
  212. // line break). Used to count lines.
  213. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  214. var lineBreakG = new RegExp(lineBreak.source, "g");
  215. function isNewLine(code, ecma2019String) {
  216. return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
  217. }
  218. var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  219. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  220. var ref = Object.prototype;
  221. var hasOwnProperty = ref.hasOwnProperty;
  222. var toString = ref.toString;
  223. // Checks if an object has a property.
  224. function has(obj, propName) {
  225. return hasOwnProperty.call(obj, propName)
  226. }
  227. var isArray = Array.isArray || (function (obj) { return (
  228. toString.call(obj) === "[object Array]"
  229. ); });
  230. function wordsRegexp(words) {
  231. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  232. }
  233. // These are used when `options.locations` is on, for the
  234. // `startLoc` and `endLoc` properties.
  235. var Position = function Position(line, col) {
  236. this.line = line;
  237. this.column = col;
  238. };
  239. Position.prototype.offset = function offset (n) {
  240. return new Position(this.line, this.column + n)
  241. };
  242. var SourceLocation = function SourceLocation(p, start, end) {
  243. this.start = start;
  244. this.end = end;
  245. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  246. };
  247. // The `getLineInfo` function is mostly useful when the
  248. // `locations` option is off (for performance reasons) and you
  249. // want to find the line/column position for a given character
  250. // offset. `input` should be the code string that the offset refers
  251. // into.
  252. function getLineInfo(input, offset) {
  253. for (var line = 1, cur = 0;;) {
  254. lineBreakG.lastIndex = cur;
  255. var match = lineBreakG.exec(input);
  256. if (match && match.index < offset) {
  257. ++line;
  258. cur = match.index + match[0].length;
  259. } else {
  260. return new Position(line, offset - cur)
  261. }
  262. }
  263. }
  264. // A second optional argument can be given to further configure
  265. // the parser process. These options are recognized:
  266. var defaultOptions = {
  267. // `ecmaVersion` indicates the ECMAScript version to parse. Must be
  268. // either 3, 5, 6 (2015), 7 (2016), 8 (2017), 9 (2018), or 10
  269. // (2019). This influences support for strict mode, the set of
  270. // reserved words, and support for new syntax features. The default
  271. // is 9.
  272. ecmaVersion: 9,
  273. // `sourceType` indicates the mode the code should be parsed in.
  274. // Can be either `"script"` or `"module"`. This influences global
  275. // strict mode and parsing of `import` and `export` declarations.
  276. sourceType: "script",
  277. // `onInsertedSemicolon` can be a callback that will be called
  278. // when a semicolon is automatically inserted. It will be passed
  279. // the position of the comma as an offset, and if `locations` is
  280. // enabled, it is given the location as a `{line, column}` object
  281. // as second argument.
  282. onInsertedSemicolon: null,
  283. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  284. // trailing commas.
  285. onTrailingComma: null,
  286. // By default, reserved words are only enforced if ecmaVersion >= 5.
  287. // Set `allowReserved` to a boolean value to explicitly turn this on
  288. // an off. When this option has the value "never", reserved words
  289. // and keywords can also not be used as property names.
  290. allowReserved: null,
  291. // When enabled, a return at the top level is not considered an
  292. // error.
  293. allowReturnOutsideFunction: false,
  294. // When enabled, import/export statements are not constrained to
  295. // appearing at the top of the program.
  296. allowImportExportEverywhere: false,
  297. // When enabled, await identifiers are allowed to appear at the top-level scope,
  298. // but they are still not allowed in non-async functions.
  299. allowAwaitOutsideFunction: false,
  300. // When enabled, hashbang directive in the beginning of file
  301. // is allowed and treated as a line comment.
  302. allowHashBang: false,
  303. // When `locations` is on, `loc` properties holding objects with
  304. // `start` and `end` properties in `{line, column}` form (with
  305. // line being 1-based and column 0-based) will be attached to the
  306. // nodes.
  307. locations: false,
  308. // A function can be passed as `onToken` option, which will
  309. // cause Acorn to call that function with object in the same
  310. // format as tokens returned from `tokenizer().getToken()`. Note
  311. // that you are not allowed to call the parser from the
  312. // callback—that will corrupt its internal state.
  313. onToken: null,
  314. // A function can be passed as `onComment` option, which will
  315. // cause Acorn to call that function with `(block, text, start,
  316. // end)` parameters whenever a comment is skipped. `block` is a
  317. // boolean indicating whether this is a block (`/* */`) comment,
  318. // `text` is the content of the comment, and `start` and `end` are
  319. // character offsets that denote the start and end of the comment.
  320. // When the `locations` option is on, two more parameters are
  321. // passed, the full `{line, column}` locations of the start and
  322. // end of the comments. Note that you are not allowed to call the
  323. // parser from the callback—that will corrupt its internal state.
  324. onComment: null,
  325. // Nodes have their start and end characters offsets recorded in
  326. // `start` and `end` properties (directly on the node, rather than
  327. // the `loc` object, which holds line/column data. To also add a
  328. // [semi-standardized][range] `range` property holding a `[start,
  329. // end]` array with the same numbers, set the `ranges` option to
  330. // `true`.
  331. //
  332. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  333. ranges: false,
  334. // It is possible to parse multiple files into a single AST by
  335. // passing the tree produced by parsing the first file as
  336. // `program` option in subsequent parses. This will add the
  337. // toplevel forms of the parsed file to the `Program` (top) node
  338. // of an existing parse tree.
  339. program: null,
  340. // When `locations` is on, you can pass this to record the source
  341. // file in every node's `loc` object.
  342. sourceFile: null,
  343. // This value, if given, is stored in every node, whether
  344. // `locations` is on or off.
  345. directSourceFile: null,
  346. // When enabled, parenthesized expressions are represented by
  347. // (non-standard) ParenthesizedExpression nodes
  348. preserveParens: false
  349. };
  350. // Interpret and default an options object
  351. function getOptions(opts) {
  352. var options = {};
  353. for (var opt in defaultOptions)
  354. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  355. if (options.ecmaVersion >= 2015)
  356. { options.ecmaVersion -= 2009; }
  357. if (options.allowReserved == null)
  358. { options.allowReserved = options.ecmaVersion < 5; }
  359. if (isArray(options.onToken)) {
  360. var tokens = options.onToken;
  361. options.onToken = function (token) { return tokens.push(token); };
  362. }
  363. if (isArray(options.onComment))
  364. { options.onComment = pushComment(options, options.onComment); }
  365. return options
  366. }
  367. function pushComment(options, array) {
  368. return function(block, text, start, end, startLoc, endLoc) {
  369. var comment = {
  370. type: block ? "Block" : "Line",
  371. value: text,
  372. start: start,
  373. end: end
  374. };
  375. if (options.locations)
  376. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  377. if (options.ranges)
  378. { comment.range = [start, end]; }
  379. array.push(comment);
  380. }
  381. }
  382. // Each scope gets a bitset that may contain these flags
  383. var
  384. SCOPE_TOP = 1,
  385. SCOPE_FUNCTION = 2,
  386. SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION,
  387. SCOPE_ASYNC = 4,
  388. SCOPE_GENERATOR = 8,
  389. SCOPE_ARROW = 16,
  390. SCOPE_SIMPLE_CATCH = 32,
  391. SCOPE_SUPER = 64,
  392. SCOPE_DIRECT_SUPER = 128;
  393. function functionFlags(async, generator) {
  394. return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
  395. }
  396. // Used in checkLVal and declareName to determine the type of a binding
  397. var
  398. BIND_NONE = 0, // Not a binding
  399. BIND_VAR = 1, // Var-style binding
  400. BIND_LEXICAL = 2, // Let- or const-style binding
  401. BIND_FUNCTION = 3, // Function declaration
  402. BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
  403. BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
  404. var Parser = function Parser(options, input, startPos) {
  405. this.options = options = getOptions(options);
  406. this.sourceFile = options.sourceFile;
  407. this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
  408. var reserved = "";
  409. if (options.allowReserved !== true) {
  410. for (var v = options.ecmaVersion;; v--)
  411. { if (reserved = reservedWords[v]) { break } }
  412. if (options.sourceType === "module") { reserved += " await"; }
  413. }
  414. this.reservedWords = wordsRegexp(reserved);
  415. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  416. this.reservedWordsStrict = wordsRegexp(reservedStrict);
  417. this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
  418. this.input = String(input);
  419. // Used to signal to callers of `readWord1` whether the word
  420. // contained any escape sequences. This is needed because words with
  421. // escape sequences must not be interpreted as keywords.
  422. this.containsEsc = false;
  423. // Set up token state
  424. // The current position of the tokenizer in the input.
  425. if (startPos) {
  426. this.pos = startPos;
  427. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  428. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  429. } else {
  430. this.pos = this.lineStart = 0;
  431. this.curLine = 1;
  432. }
  433. // Properties of the current token:
  434. // Its type
  435. this.type = types.eof;
  436. // For tokens that include more information than their type, the value
  437. this.value = null;
  438. // Its start and end offset
  439. this.start = this.end = this.pos;
  440. // And, if locations are used, the {line, column} object
  441. // corresponding to those offsets
  442. this.startLoc = this.endLoc = this.curPosition();
  443. // Position information for the previous token
  444. this.lastTokEndLoc = this.lastTokStartLoc = null;
  445. this.lastTokStart = this.lastTokEnd = this.pos;
  446. // The context stack is used to superficially track syntactic
  447. // context to predict whether a regular expression is allowed in a
  448. // given position.
  449. this.context = this.initialContext();
  450. this.exprAllowed = true;
  451. // Figure out if it's a module code.
  452. this.inModule = options.sourceType === "module";
  453. this.strict = this.inModule || this.strictDirective(this.pos);
  454. // Used to signify the start of a potential arrow function
  455. this.potentialArrowAt = -1;
  456. // Positions to delayed-check that yield/await does not exist in default parameters.
  457. this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
  458. // Labels in scope.
  459. this.labels = [];
  460. // Thus-far undefined exports.
  461. this.undefinedExports = {};
  462. // If enabled, skip leading hashbang line.
  463. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  464. { this.skipLineComment(2); }
  465. // Scope tracking for duplicate variable names (see scope.js)
  466. this.scopeStack = [];
  467. this.enterScope(SCOPE_TOP);
  468. // For RegExp validation
  469. this.regexpState = null;
  470. };
  471. var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true } };
  472. Parser.prototype.parse = function parse () {
  473. var node = this.options.program || this.startNode();
  474. this.nextToken();
  475. return this.parseTopLevel(node)
  476. };
  477. prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
  478. prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 };
  479. prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 };
  480. prototypeAccessors.allowSuper.get = function () { return (this.currentThisScope().flags & SCOPE_SUPER) > 0 };
  481. prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
  482. prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
  483. // Switch to a getter for 7.0.0.
  484. Parser.prototype.inNonArrowFunction = function inNonArrowFunction () { return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0 };
  485. Parser.extend = function extend () {
  486. var plugins = [], len = arguments.length;
  487. while ( len-- ) plugins[ len ] = arguments[ len ];
  488. var cls = this;
  489. for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
  490. return cls
  491. };
  492. Parser.parse = function parse (input, options) {
  493. return new this(options, input).parse()
  494. };
  495. Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
  496. var parser = new this(options, input, pos);
  497. parser.nextToken();
  498. return parser.parseExpression()
  499. };
  500. Parser.tokenizer = function tokenizer (input, options) {
  501. return new this(options, input)
  502. };
  503. Object.defineProperties( Parser.prototype, prototypeAccessors );
  504. var pp = Parser.prototype;
  505. // ## Parser utilities
  506. var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)")/;
  507. pp.strictDirective = function(start) {
  508. for (;;) {
  509. // Try to find string literal.
  510. skipWhiteSpace.lastIndex = start;
  511. start += skipWhiteSpace.exec(this.input)[0].length;
  512. var match = literal.exec(this.input.slice(start));
  513. if (!match) { return false }
  514. if ((match[1] || match[2]) === "use strict") { return true }
  515. start += match[0].length;
  516. // Skip semicolon, if any.
  517. skipWhiteSpace.lastIndex = start;
  518. start += skipWhiteSpace.exec(this.input)[0].length;
  519. if (this.input[start] === ";")
  520. { start++; }
  521. }
  522. };
  523. // Predicate that tests whether the next token is of the given
  524. // type, and if yes, consumes it as a side effect.
  525. pp.eat = function(type) {
  526. if (this.type === type) {
  527. this.next();
  528. return true
  529. } else {
  530. return false
  531. }
  532. };
  533. // Tests whether parsed token is a contextual keyword.
  534. pp.isContextual = function(name) {
  535. return this.type === types.name && this.value === name && !this.containsEsc
  536. };
  537. // Consumes contextual keyword if possible.
  538. pp.eatContextual = function(name) {
  539. if (!this.isContextual(name)) { return false }
  540. this.next();
  541. return true
  542. };
  543. // Asserts that following token is given contextual keyword.
  544. pp.expectContextual = function(name) {
  545. if (!this.eatContextual(name)) { this.unexpected(); }
  546. };
  547. // Test whether a semicolon can be inserted at the current position.
  548. pp.canInsertSemicolon = function() {
  549. return this.type === types.eof ||
  550. this.type === types.braceR ||
  551. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  552. };
  553. pp.insertSemicolon = function() {
  554. if (this.canInsertSemicolon()) {
  555. if (this.options.onInsertedSemicolon)
  556. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  557. return true
  558. }
  559. };
  560. // Consume a semicolon, or, failing that, see if we are allowed to
  561. // pretend that there is a semicolon at this position.
  562. pp.semicolon = function() {
  563. if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
  564. };
  565. pp.afterTrailingComma = function(tokType, notNext) {
  566. if (this.type === tokType) {
  567. if (this.options.onTrailingComma)
  568. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  569. if (!notNext)
  570. { this.next(); }
  571. return true
  572. }
  573. };
  574. // Expect a token of a given type. If found, consume it, otherwise,
  575. // raise an unexpected token error.
  576. pp.expect = function(type) {
  577. this.eat(type) || this.unexpected();
  578. };
  579. // Raise an unexpected token error.
  580. pp.unexpected = function(pos) {
  581. this.raise(pos != null ? pos : this.start, "Unexpected token");
  582. };
  583. function DestructuringErrors() {
  584. this.shorthandAssign =
  585. this.trailingComma =
  586. this.parenthesizedAssign =
  587. this.parenthesizedBind =
  588. this.doubleProto =
  589. -1;
  590. }
  591. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  592. if (!refDestructuringErrors) { return }
  593. if (refDestructuringErrors.trailingComma > -1)
  594. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  595. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  596. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  597. };
  598. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  599. if (!refDestructuringErrors) { return false }
  600. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  601. var doubleProto = refDestructuringErrors.doubleProto;
  602. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  603. if (shorthandAssign >= 0)
  604. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  605. if (doubleProto >= 0)
  606. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  607. };
  608. pp.checkYieldAwaitInDefaultParams = function() {
  609. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  610. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  611. if (this.awaitPos)
  612. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  613. };
  614. pp.isSimpleAssignTarget = function(expr) {
  615. if (expr.type === "ParenthesizedExpression")
  616. { return this.isSimpleAssignTarget(expr.expression) }
  617. return expr.type === "Identifier" || expr.type === "MemberExpression"
  618. };
  619. var pp$1 = Parser.prototype;
  620. // ### Statement parsing
  621. // Parse a program. Initializes the parser, reads any number of
  622. // statements, and wraps them in a Program node. Optionally takes a
  623. // `program` argument. If present, the statements will be appended
  624. // to its body instead of creating a new node.
  625. pp$1.parseTopLevel = function(node) {
  626. var exports = {};
  627. if (!node.body) { node.body = []; }
  628. while (this.type !== types.eof) {
  629. var stmt = this.parseStatement(null, true, exports);
  630. node.body.push(stmt);
  631. }
  632. if (this.inModule)
  633. { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
  634. {
  635. var name = list[i];
  636. this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
  637. } }
  638. this.adaptDirectivePrologue(node.body);
  639. this.next();
  640. node.sourceType = this.options.sourceType;
  641. return this.finishNode(node, "Program")
  642. };
  643. var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
  644. pp$1.isLet = function(context) {
  645. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  646. skipWhiteSpace.lastIndex = this.pos;
  647. var skip = skipWhiteSpace.exec(this.input);
  648. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  649. // For ambiguous cases, determine if a LexicalDeclaration (or only a
  650. // Statement) is allowed here. If context is not empty then only a Statement
  651. // is allowed. However, `let [` is an explicit negative lookahead for
  652. // ExpressionStatement, so special-case it first.
  653. if (nextCh === 91) { return true } // '['
  654. if (context) { return false }
  655. if (nextCh === 123) { return true } // '{'
  656. if (isIdentifierStart(nextCh, true)) {
  657. var pos = next + 1;
  658. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  659. var ident = this.input.slice(next, pos);
  660. if (!keywordRelationalOperator.test(ident)) { return true }
  661. }
  662. return false
  663. };
  664. // check 'async [no LineTerminator here] function'
  665. // - 'async /*foo*/ function' is OK.
  666. // - 'async /*\n*/ function' is invalid.
  667. pp$1.isAsyncFunction = function() {
  668. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  669. { return false }
  670. skipWhiteSpace.lastIndex = this.pos;
  671. var skip = skipWhiteSpace.exec(this.input);
  672. var next = this.pos + skip[0].length;
  673. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  674. this.input.slice(next, next + 8) === "function" &&
  675. (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  676. };
  677. // Parse a single statement.
  678. //
  679. // If expecting a statement and finding a slash operator, parse a
  680. // regular expression literal. This is to handle cases like
  681. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  682. // does not help.
  683. pp$1.parseStatement = function(context, topLevel, exports) {
  684. var starttype = this.type, node = this.startNode(), kind;
  685. if (this.isLet(context)) {
  686. starttype = types._var;
  687. kind = "let";
  688. }
  689. // Most types of statements are recognized by the keyword they
  690. // start with. Many are trivial to parse, some require a bit of
  691. // complexity.
  692. switch (starttype) {
  693. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  694. case types._debugger: return this.parseDebuggerStatement(node)
  695. case types._do: return this.parseDoStatement(node)
  696. case types._for: return this.parseForStatement(node)
  697. case types._function:
  698. // Function as sole body of either an if statement or a labeled statement
  699. // works, but not when it is part of a labeled statement that is the sole
  700. // body of an if statement.
  701. if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
  702. return this.parseFunctionStatement(node, false, !context)
  703. case types._class:
  704. if (context) { this.unexpected(); }
  705. return this.parseClass(node, true)
  706. case types._if: return this.parseIfStatement(node)
  707. case types._return: return this.parseReturnStatement(node)
  708. case types._switch: return this.parseSwitchStatement(node)
  709. case types._throw: return this.parseThrowStatement(node)
  710. case types._try: return this.parseTryStatement(node)
  711. case types._const: case types._var:
  712. kind = kind || this.value;
  713. if (context && kind !== "var") { this.unexpected(); }
  714. return this.parseVarStatement(node, kind)
  715. case types._while: return this.parseWhileStatement(node)
  716. case types._with: return this.parseWithStatement(node)
  717. case types.braceL: return this.parseBlock(true, node)
  718. case types.semi: return this.parseEmptyStatement(node)
  719. case types._export:
  720. case types._import:
  721. if (this.options.ecmaVersion > 10 && starttype === types._import) {
  722. skipWhiteSpace.lastIndex = this.pos;
  723. var skip = skipWhiteSpace.exec(this.input);
  724. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  725. if (nextCh === 40) // '('
  726. { return this.parseExpressionStatement(node, this.parseExpression()) }
  727. }
  728. if (!this.options.allowImportExportEverywhere) {
  729. if (!topLevel)
  730. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  731. if (!this.inModule)
  732. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  733. }
  734. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  735. // If the statement does not start with a statement keyword or a
  736. // brace, it's an ExpressionStatement or LabeledStatement. We
  737. // simply start parsing an expression, and afterwards, if the
  738. // next token is a colon and the expression was a simple
  739. // Identifier node, we switch to interpreting it as a label.
  740. default:
  741. if (this.isAsyncFunction()) {
  742. if (context) { this.unexpected(); }
  743. this.next();
  744. return this.parseFunctionStatement(node, true, !context)
  745. }
  746. var maybeName = this.value, expr = this.parseExpression();
  747. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  748. { return this.parseLabeledStatement(node, maybeName, expr, context) }
  749. else { return this.parseExpressionStatement(node, expr) }
  750. }
  751. };
  752. pp$1.parseBreakContinueStatement = function(node, keyword) {
  753. var isBreak = keyword === "break";
  754. this.next();
  755. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  756. else if (this.type !== types.name) { this.unexpected(); }
  757. else {
  758. node.label = this.parseIdent();
  759. this.semicolon();
  760. }
  761. // Verify that there is an actual destination to break or
  762. // continue to.
  763. var i = 0;
  764. for (; i < this.labels.length; ++i) {
  765. var lab = this.labels[i];
  766. if (node.label == null || lab.name === node.label.name) {
  767. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  768. if (node.label && isBreak) { break }
  769. }
  770. }
  771. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  772. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  773. };
  774. pp$1.parseDebuggerStatement = function(node) {
  775. this.next();
  776. this.semicolon();
  777. return this.finishNode(node, "DebuggerStatement")
  778. };
  779. pp$1.parseDoStatement = function(node) {
  780. this.next();
  781. this.labels.push(loopLabel);
  782. node.body = this.parseStatement("do");
  783. this.labels.pop();
  784. this.expect(types._while);
  785. node.test = this.parseParenExpression();
  786. if (this.options.ecmaVersion >= 6)
  787. { this.eat(types.semi); }
  788. else
  789. { this.semicolon(); }
  790. return this.finishNode(node, "DoWhileStatement")
  791. };
  792. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  793. // loop is non-trivial. Basically, we have to parse the init `var`
  794. // statement or expression, disallowing the `in` operator (see
  795. // the second parameter to `parseExpression`), and then check
  796. // whether the next token is `in` or `of`. When there is no init
  797. // part (semicolon immediately after the opening parenthesis), it
  798. // is a regular `for` loop.
  799. pp$1.parseForStatement = function(node) {
  800. this.next();
  801. var awaitAt = (this.options.ecmaVersion >= 9 && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction)) && this.eatContextual("await")) ? this.lastTokStart : -1;
  802. this.labels.push(loopLabel);
  803. this.enterScope(0);
  804. this.expect(types.parenL);
  805. if (this.type === types.semi) {
  806. if (awaitAt > -1) { this.unexpected(awaitAt); }
  807. return this.parseFor(node, null)
  808. }
  809. var isLet = this.isLet();
  810. if (this.type === types._var || this.type === types._const || isLet) {
  811. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  812. this.next();
  813. this.parseVar(init$1, true, kind);
  814. this.finishNode(init$1, "VariableDeclaration");
  815. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
  816. if (this.options.ecmaVersion >= 9) {
  817. if (this.type === types._in) {
  818. if (awaitAt > -1) { this.unexpected(awaitAt); }
  819. } else { node.await = awaitAt > -1; }
  820. }
  821. return this.parseForIn(node, init$1)
  822. }
  823. if (awaitAt > -1) { this.unexpected(awaitAt); }
  824. return this.parseFor(node, init$1)
  825. }
  826. var refDestructuringErrors = new DestructuringErrors;
  827. var init = this.parseExpression(true, refDestructuringErrors);
  828. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  829. if (this.options.ecmaVersion >= 9) {
  830. if (this.type === types._in) {
  831. if (awaitAt > -1) { this.unexpected(awaitAt); }
  832. } else { node.await = awaitAt > -1; }
  833. }
  834. this.toAssignable(init, false, refDestructuringErrors);
  835. this.checkLVal(init);
  836. return this.parseForIn(node, init)
  837. } else {
  838. this.checkExpressionErrors(refDestructuringErrors, true);
  839. }
  840. if (awaitAt > -1) { this.unexpected(awaitAt); }
  841. return this.parseFor(node, init)
  842. };
  843. pp$1.parseFunctionStatement = function(node, isAsync, declarationPosition) {
  844. this.next();
  845. return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
  846. };
  847. pp$1.parseIfStatement = function(node) {
  848. this.next();
  849. node.test = this.parseParenExpression();
  850. // allow function declarations in branches, but only in non-strict mode
  851. node.consequent = this.parseStatement("if");
  852. node.alternate = this.eat(types._else) ? this.parseStatement("if") : null;
  853. return this.finishNode(node, "IfStatement")
  854. };
  855. pp$1.parseReturnStatement = function(node) {
  856. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  857. { this.raise(this.start, "'return' outside of function"); }
  858. this.next();
  859. // In `return` (and `break`/`continue`), the keywords with
  860. // optional arguments, we eagerly look for a semicolon or the
  861. // possibility to insert one.
  862. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  863. else { node.argument = this.parseExpression(); this.semicolon(); }
  864. return this.finishNode(node, "ReturnStatement")
  865. };
  866. pp$1.parseSwitchStatement = function(node) {
  867. this.next();
  868. node.discriminant = this.parseParenExpression();
  869. node.cases = [];
  870. this.expect(types.braceL);
  871. this.labels.push(switchLabel);
  872. this.enterScope(0);
  873. // Statements under must be grouped (by label) in SwitchCase
  874. // nodes. `cur` is used to keep the node that we are currently
  875. // adding statements to.
  876. var cur;
  877. for (var sawDefault = false; this.type !== types.braceR;) {
  878. if (this.type === types._case || this.type === types._default) {
  879. var isCase = this.type === types._case;
  880. if (cur) { this.finishNode(cur, "SwitchCase"); }
  881. node.cases.push(cur = this.startNode());
  882. cur.consequent = [];
  883. this.next();
  884. if (isCase) {
  885. cur.test = this.parseExpression();
  886. } else {
  887. if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
  888. sawDefault = true;
  889. cur.test = null;
  890. }
  891. this.expect(types.colon);
  892. } else {
  893. if (!cur) { this.unexpected(); }
  894. cur.consequent.push(this.parseStatement(null));
  895. }
  896. }
  897. this.exitScope();
  898. if (cur) { this.finishNode(cur, "SwitchCase"); }
  899. this.next(); // Closing brace
  900. this.labels.pop();
  901. return this.finishNode(node, "SwitchStatement")
  902. };
  903. pp$1.parseThrowStatement = function(node) {
  904. this.next();
  905. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  906. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  907. node.argument = this.parseExpression();
  908. this.semicolon();
  909. return this.finishNode(node, "ThrowStatement")
  910. };
  911. // Reused empty array added for node fields that are always empty.
  912. var empty = [];
  913. pp$1.parseTryStatement = function(node) {
  914. this.next();
  915. node.block = this.parseBlock();
  916. node.handler = null;
  917. if (this.type === types._catch) {
  918. var clause = this.startNode();
  919. this.next();
  920. if (this.eat(types.parenL)) {
  921. clause.param = this.parseBindingAtom();
  922. var simple = clause.param.type === "Identifier";
  923. this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
  924. this.checkLVal(clause.param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
  925. this.expect(types.parenR);
  926. } else {
  927. if (this.options.ecmaVersion < 10) { this.unexpected(); }
  928. clause.param = null;
  929. this.enterScope(0);
  930. }
  931. clause.body = this.parseBlock(false);
  932. this.exitScope();
  933. node.handler = this.finishNode(clause, "CatchClause");
  934. }
  935. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  936. if (!node.handler && !node.finalizer)
  937. { this.raise(node.start, "Missing catch or finally clause"); }
  938. return this.finishNode(node, "TryStatement")
  939. };
  940. pp$1.parseVarStatement = function(node, kind) {
  941. this.next();
  942. this.parseVar(node, false, kind);
  943. this.semicolon();
  944. return this.finishNode(node, "VariableDeclaration")
  945. };
  946. pp$1.parseWhileStatement = function(node) {
  947. this.next();
  948. node.test = this.parseParenExpression();
  949. this.labels.push(loopLabel);
  950. node.body = this.parseStatement("while");
  951. this.labels.pop();
  952. return this.finishNode(node, "WhileStatement")
  953. };
  954. pp$1.parseWithStatement = function(node) {
  955. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  956. this.next();
  957. node.object = this.parseParenExpression();
  958. node.body = this.parseStatement("with");
  959. return this.finishNode(node, "WithStatement")
  960. };
  961. pp$1.parseEmptyStatement = function(node) {
  962. this.next();
  963. return this.finishNode(node, "EmptyStatement")
  964. };
  965. pp$1.parseLabeledStatement = function(node, maybeName, expr, context) {
  966. for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
  967. {
  968. var label = list[i$1];
  969. if (label.name === maybeName)
  970. { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
  971. } }
  972. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  973. for (var i = this.labels.length - 1; i >= 0; i--) {
  974. var label$1 = this.labels[i];
  975. if (label$1.statementStart === node.start) {
  976. // Update information about previous labels on this node
  977. label$1.statementStart = this.start;
  978. label$1.kind = kind;
  979. } else { break }
  980. }
  981. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  982. node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
  983. this.labels.pop();
  984. node.label = expr;
  985. return this.finishNode(node, "LabeledStatement")
  986. };
  987. pp$1.parseExpressionStatement = function(node, expr) {
  988. node.expression = expr;
  989. this.semicolon();
  990. return this.finishNode(node, "ExpressionStatement")
  991. };
  992. // Parse a semicolon-enclosed block of statements, handling `"use
  993. // strict"` declarations when `allowStrict` is true (used for
  994. // function bodies).
  995. pp$1.parseBlock = function(createNewLexicalScope, node) {
  996. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  997. if ( node === void 0 ) node = this.startNode();
  998. node.body = [];
  999. this.expect(types.braceL);
  1000. if (createNewLexicalScope) { this.enterScope(0); }
  1001. while (!this.eat(types.braceR)) {
  1002. var stmt = this.parseStatement(null);
  1003. node.body.push(stmt);
  1004. }
  1005. if (createNewLexicalScope) { this.exitScope(); }
  1006. return this.finishNode(node, "BlockStatement")
  1007. };
  1008. // Parse a regular `for` loop. The disambiguation code in
  1009. // `parseStatement` will already have parsed the init statement or
  1010. // expression.
  1011. pp$1.parseFor = function(node, init) {
  1012. node.init = init;
  1013. this.expect(types.semi);
  1014. node.test = this.type === types.semi ? null : this.parseExpression();
  1015. this.expect(types.semi);
  1016. node.update = this.type === types.parenR ? null : this.parseExpression();
  1017. this.expect(types.parenR);
  1018. node.body = this.parseStatement("for");
  1019. this.exitScope();
  1020. this.labels.pop();
  1021. return this.finishNode(node, "ForStatement")
  1022. };
  1023. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  1024. // same from parser's perspective.
  1025. pp$1.parseForIn = function(node, init) {
  1026. var isForIn = this.type === types._in;
  1027. this.next();
  1028. if (
  1029. init.type === "VariableDeclaration" &&
  1030. init.declarations[0].init != null &&
  1031. (
  1032. !isForIn ||
  1033. this.options.ecmaVersion < 8 ||
  1034. this.strict ||
  1035. init.kind !== "var" ||
  1036. init.declarations[0].id.type !== "Identifier"
  1037. )
  1038. ) {
  1039. this.raise(
  1040. init.start,
  1041. ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
  1042. );
  1043. } else if (init.type === "AssignmentPattern") {
  1044. this.raise(init.start, "Invalid left-hand side in for-loop");
  1045. }
  1046. node.left = init;
  1047. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
  1048. this.expect(types.parenR);
  1049. node.body = this.parseStatement("for");
  1050. this.exitScope();
  1051. this.labels.pop();
  1052. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
  1053. };
  1054. // Parse a list of variable declarations.
  1055. pp$1.parseVar = function(node, isFor, kind) {
  1056. node.declarations = [];
  1057. node.kind = kind;
  1058. for (;;) {
  1059. var decl = this.startNode();
  1060. this.parseVarId(decl, kind);
  1061. if (this.eat(types.eq)) {
  1062. decl.init = this.parseMaybeAssign(isFor);
  1063. } else if (kind === "const" && !(this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
  1064. this.unexpected();
  1065. } else if (decl.id.type !== "Identifier" && !(isFor && (this.type === types._in || this.isContextual("of")))) {
  1066. this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
  1067. } else {
  1068. decl.init = null;
  1069. }
  1070. node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
  1071. if (!this.eat(types.comma)) { break }
  1072. }
  1073. return node
  1074. };
  1075. pp$1.parseVarId = function(decl, kind) {
  1076. decl.id = this.parseBindingAtom();
  1077. this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
  1078. };
  1079. var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
  1080. // Parse a function declaration or literal (depending on the
  1081. // `statement & FUNC_STATEMENT`).
  1082. // Remove `allowExpressionBody` for 7.0.0, as it is only called with false
  1083. pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) {
  1084. this.initFunction(node);
  1085. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
  1086. if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT))
  1087. { this.unexpected(); }
  1088. node.generator = this.eat(types.star);
  1089. }
  1090. if (this.options.ecmaVersion >= 8)
  1091. { node.async = !!isAsync; }
  1092. if (statement & FUNC_STATEMENT) {
  1093. node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types.name ? null : this.parseIdent();
  1094. if (node.id && !(statement & FUNC_HANGING_STATEMENT))
  1095. // If it is a regular function declaration in sloppy mode, then it is
  1096. // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
  1097. // mode depends on properties of the current scope (see
  1098. // treatFunctionsAsVar).
  1099. { this.checkLVal(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
  1100. }
  1101. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  1102. this.yieldPos = 0;
  1103. this.awaitPos = 0;
  1104. this.awaitIdentPos = 0;
  1105. this.enterScope(functionFlags(node.async, node.generator));
  1106. if (!(statement & FUNC_STATEMENT))
  1107. { node.id = this.type === types.name ? this.parseIdent() : null; }
  1108. this.parseFunctionParams(node);
  1109. this.parseFunctionBody(node, allowExpressionBody, false);
  1110. this.yieldPos = oldYieldPos;
  1111. this.awaitPos = oldAwaitPos;
  1112. this.awaitIdentPos = oldAwaitIdentPos;
  1113. return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
  1114. };
  1115. pp$1.parseFunctionParams = function(node) {
  1116. this.expect(types.parenL);
  1117. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  1118. this.checkYieldAwaitInDefaultParams();
  1119. };
  1120. // Parse a class declaration or literal (depending on the
  1121. // `isStatement` parameter).
  1122. pp$1.parseClass = function(node, isStatement) {
  1123. this.next();
  1124. // ecma-262 14.6 Class Definitions
  1125. // A class definition is always strict mode code.
  1126. var oldStrict = this.strict;
  1127. this.strict = true;
  1128. this.parseClassId(node, isStatement);
  1129. this.parseClassSuper(node);
  1130. var classBody = this.startNode();
  1131. var hadConstructor = false;
  1132. classBody.body = [];
  1133. this.expect(types.braceL);
  1134. while (!this.eat(types.braceR)) {
  1135. var element = this.parseClassElement(node.superClass !== null);
  1136. if (element) {
  1137. classBody.body.push(element);
  1138. if (element.type === "MethodDefinition" && element.kind === "constructor") {
  1139. if (hadConstructor) { this.raise(element.start, "Duplicate constructor in the same class"); }
  1140. hadConstructor = true;
  1141. }
  1142. }
  1143. }
  1144. node.body = this.finishNode(classBody, "ClassBody");
  1145. this.strict = oldStrict;
  1146. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1147. };
  1148. pp$1.parseClassElement = function(constructorAllowsSuper) {
  1149. var this$1 = this;
  1150. if (this.eat(types.semi)) { return null }
  1151. var method = this.startNode();
  1152. var tryContextual = function (k, noLineBreak) {
  1153. if ( noLineBreak === void 0 ) noLineBreak = false;
  1154. var start = this$1.start, startLoc = this$1.startLoc;
  1155. if (!this$1.eatContextual(k)) { return false }
  1156. if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
  1157. if (method.key) { this$1.unexpected(); }
  1158. method.computed = false;
  1159. method.key = this$1.startNodeAt(start, startLoc);
  1160. method.key.name = k;
  1161. this$1.finishNode(method.key, "Identifier");
  1162. return false
  1163. };
  1164. method.kind = "method";
  1165. method.static = tryContextual("static");
  1166. var isGenerator = this.eat(types.star);
  1167. var isAsync = false;
  1168. if (!isGenerator) {
  1169. if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
  1170. isAsync = true;
  1171. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  1172. } else if (tryContextual("get")) {
  1173. method.kind = "get";
  1174. } else if (tryContextual("set")) {
  1175. method.kind = "set";
  1176. }
  1177. }
  1178. if (!method.key) { this.parsePropertyName(method); }
  1179. var key = method.key;
  1180. var allowsDirectSuper = false;
  1181. if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
  1182. key.type === "Literal" && key.value === "constructor")) {
  1183. if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
  1184. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1185. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1186. method.kind = "constructor";
  1187. allowsDirectSuper = constructorAllowsSuper;
  1188. } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
  1189. this.raise(key.start, "Classes may not have a static property named prototype");
  1190. }
  1191. this.parseClassMethod(method, isGenerator, isAsync, allowsDirectSuper);
  1192. if (method.kind === "get" && method.value.params.length !== 0)
  1193. { this.raiseRecoverable(method.value.start, "getter should have no params"); }
  1194. if (method.kind === "set" && method.value.params.length !== 1)
  1195. { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
  1196. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  1197. { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  1198. return method
  1199. };
  1200. pp$1.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
  1201. method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
  1202. return this.finishNode(method, "MethodDefinition")
  1203. };
  1204. pp$1.parseClassId = function(node, isStatement) {
  1205. if (this.type === types.name) {
  1206. node.id = this.parseIdent();
  1207. if (isStatement)
  1208. { this.checkLVal(node.id, BIND_LEXICAL, false); }
  1209. } else {
  1210. if (isStatement === true)
  1211. { this.unexpected(); }
  1212. node.id = null;
  1213. }
  1214. };
  1215. pp$1.parseClassSuper = function(node) {
  1216. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  1217. };
  1218. // Parses module export declaration.
  1219. pp$1.parseExport = function(node, exports) {
  1220. this.next();
  1221. // export * from '...'
  1222. if (this.eat(types.star)) {
  1223. this.expectContextual("from");
  1224. if (this.type !== types.string) { this.unexpected(); }
  1225. node.source = this.parseExprAtom();
  1226. this.semicolon();
  1227. return this.finishNode(node, "ExportAllDeclaration")
  1228. }
  1229. if (this.eat(types._default)) { // export default ...
  1230. this.checkExport(exports, "default", this.lastTokStart);
  1231. var isAsync;
  1232. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  1233. var fNode = this.startNode();
  1234. this.next();
  1235. if (isAsync) { this.next(); }
  1236. node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
  1237. } else if (this.type === types._class) {
  1238. var cNode = this.startNode();
  1239. node.declaration = this.parseClass(cNode, "nullableID");
  1240. } else {
  1241. node.declaration = this.parseMaybeAssign();
  1242. this.semicolon();
  1243. }
  1244. return this.finishNode(node, "ExportDefaultDeclaration")
  1245. }
  1246. // export var|const|let|function|class ...
  1247. if (this.shouldParseExportStatement()) {
  1248. node.declaration = this.parseStatement(null);
  1249. if (node.declaration.type === "VariableDeclaration")
  1250. { this.checkVariableExport(exports, node.declaration.declarations); }
  1251. else
  1252. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1253. node.specifiers = [];
  1254. node.source = null;
  1255. } else { // export { x, y as z } [from '...']
  1256. node.declaration = null;
  1257. node.specifiers = this.parseExportSpecifiers(exports);
  1258. if (this.eatContextual("from")) {
  1259. if (this.type !== types.string) { this.unexpected(); }
  1260. node.source = this.parseExprAtom();
  1261. } else {
  1262. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1263. // check for keywords used as local names
  1264. var spec = list[i];
  1265. this.checkUnreserved(spec.local);
  1266. // check if export is defined
  1267. this.checkLocalExport(spec.local);
  1268. }
  1269. node.source = null;
  1270. }
  1271. this.semicolon();
  1272. }
  1273. return this.finishNode(node, "ExportNamedDeclaration")
  1274. };
  1275. pp$1.checkExport = function(exports, name, pos) {
  1276. if (!exports) { return }
  1277. if (has(exports, name))
  1278. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1279. exports[name] = true;
  1280. };
  1281. pp$1.checkPatternExport = function(exports, pat) {
  1282. var type = pat.type;
  1283. if (type === "Identifier")
  1284. { this.checkExport(exports, pat.name, pat.start); }
  1285. else if (type === "ObjectPattern")
  1286. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1287. {
  1288. var prop = list[i];
  1289. this.checkPatternExport(exports, prop);
  1290. } }
  1291. else if (type === "ArrayPattern")
  1292. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1293. var elt = list$1[i$1];
  1294. if (elt) { this.checkPatternExport(exports, elt); }
  1295. } }
  1296. else if (type === "Property")
  1297. { this.checkPatternExport(exports, pat.value); }
  1298. else if (type === "AssignmentPattern")
  1299. { this.checkPatternExport(exports, pat.left); }
  1300. else if (type === "RestElement")
  1301. { this.checkPatternExport(exports, pat.argument); }
  1302. else if (type === "ParenthesizedExpression")
  1303. { this.checkPatternExport(exports, pat.expression); }
  1304. };
  1305. pp$1.checkVariableExport = function(exports, decls) {
  1306. if (!exports) { return }
  1307. for (var i = 0, list = decls; i < list.length; i += 1)
  1308. {
  1309. var decl = list[i];
  1310. this.checkPatternExport(exports, decl.id);
  1311. }
  1312. };
  1313. pp$1.shouldParseExportStatement = function() {
  1314. return this.type.keyword === "var" ||
  1315. this.type.keyword === "const" ||
  1316. this.type.keyword === "class" ||
  1317. this.type.keyword === "function" ||
  1318. this.isLet() ||
  1319. this.isAsyncFunction()
  1320. };
  1321. // Parses a comma-separated list of module exports.
  1322. pp$1.parseExportSpecifiers = function(exports) {
  1323. var nodes = [], first = true;
  1324. // export { x, y as z } [from '...']
  1325. this.expect(types.braceL);
  1326. while (!this.eat(types.braceR)) {
  1327. if (!first) {
  1328. this.expect(types.comma);
  1329. if (this.afterTrailingComma(types.braceR)) { break }
  1330. } else { first = false; }
  1331. var node = this.startNode();
  1332. node.local = this.parseIdent(true);
  1333. node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
  1334. this.checkExport(exports, node.exported.name, node.exported.start);
  1335. nodes.push(this.finishNode(node, "ExportSpecifier"));
  1336. }
  1337. return nodes
  1338. };
  1339. // Parses import declaration.
  1340. pp$1.parseImport = function(node) {
  1341. this.next();
  1342. // import '...'
  1343. if (this.type === types.string) {
  1344. node.specifiers = empty;
  1345. node.source = this.parseExprAtom();
  1346. } else {
  1347. node.specifiers = this.parseImportSpecifiers();
  1348. this.expectContextual("from");
  1349. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1350. }
  1351. this.semicolon();
  1352. return this.finishNode(node, "ImportDeclaration")
  1353. };
  1354. // Parses a comma-separated list of module imports.
  1355. pp$1.parseImportSpecifiers = function() {
  1356. var nodes = [], first = true;
  1357. if (this.type === types.name) {
  1358. // import defaultObj, { x, y as z } from '...'
  1359. var node = this.startNode();
  1360. node.local = this.parseIdent();
  1361. this.checkLVal(node.local, BIND_LEXICAL);
  1362. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1363. if (!this.eat(types.comma)) { return nodes }
  1364. }
  1365. if (this.type === types.star) {
  1366. var node$1 = this.startNode();
  1367. this.next();
  1368. this.expectContextual("as");
  1369. node$1.local = this.parseIdent();
  1370. this.checkLVal(node$1.local, BIND_LEXICAL);
  1371. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1372. return nodes
  1373. }
  1374. this.expect(types.braceL);
  1375. while (!this.eat(types.braceR)) {
  1376. if (!first) {
  1377. this.expect(types.comma);
  1378. if (this.afterTrailingComma(types.braceR)) { break }
  1379. } else { first = false; }
  1380. var node$2 = this.startNode();
  1381. node$2.imported = this.parseIdent(true);
  1382. if (this.eatContextual("as")) {
  1383. node$2.local = this.parseIdent();
  1384. } else {
  1385. this.checkUnreserved(node$2.imported);
  1386. node$2.local = node$2.imported;
  1387. }
  1388. this.checkLVal(node$2.local, BIND_LEXICAL);
  1389. nodes.push(this.finishNode(node$2, "ImportSpecifier"));
  1390. }
  1391. return nodes
  1392. };
  1393. // Set `ExpressionStatement#directive` property for directive prologues.
  1394. pp$1.adaptDirectivePrologue = function(statements) {
  1395. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1396. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1397. }
  1398. };
  1399. pp$1.isDirectiveCandidate = function(statement) {
  1400. return (
  1401. statement.type === "ExpressionStatement" &&
  1402. statement.expression.type === "Literal" &&
  1403. typeof statement.expression.value === "string" &&
  1404. // Reject parenthesized strings.
  1405. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1406. )
  1407. };
  1408. var pp$2 = Parser.prototype;
  1409. // Convert existing expression atom to assignable pattern
  1410. // if possible.
  1411. pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1412. if (this.options.ecmaVersion >= 6 && node) {
  1413. switch (node.type) {
  1414. case "Identifier":
  1415. if (this.inAsync && node.name === "await")
  1416. { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
  1417. break
  1418. case "ObjectPattern":
  1419. case "ArrayPattern":
  1420. case "RestElement":
  1421. break
  1422. case "ObjectExpression":
  1423. node.type = "ObjectPattern";
  1424. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1425. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1426. var prop = list[i];
  1427. this.toAssignable(prop, isBinding);
  1428. // Early error:
  1429. // AssignmentRestProperty[Yield, Await] :
  1430. // `...` DestructuringAssignmentTarget[Yield, Await]
  1431. //
  1432. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1433. if (
  1434. prop.type === "RestElement" &&
  1435. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1436. ) {
  1437. this.raise(prop.argument.start, "Unexpected token");
  1438. }
  1439. }
  1440. break
  1441. case "Property":
  1442. // AssignmentProperty has type === "Property"
  1443. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1444. this.toAssignable(node.value, isBinding);
  1445. break
  1446. case "ArrayExpression":
  1447. node.type = "ArrayPattern";
  1448. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1449. this.toAssignableList(node.elements, isBinding);
  1450. break
  1451. case "SpreadElement":
  1452. node.type = "RestElement";
  1453. this.toAssignable(node.argument, isBinding);
  1454. if (node.argument.type === "AssignmentPattern")
  1455. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1456. break
  1457. case "AssignmentExpression":
  1458. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1459. node.type = "AssignmentPattern";
  1460. delete node.operator;
  1461. this.toAssignable(node.left, isBinding);
  1462. // falls through to AssignmentPattern
  1463. case "AssignmentPattern":
  1464. break
  1465. case "ParenthesizedExpression":
  1466. this.toAssignable(node.expression, isBinding, refDestructuringErrors);
  1467. break
  1468. case "MemberExpression":
  1469. if (!isBinding) { break }
  1470. default:
  1471. this.raise(node.start, "Assigning to rvalue");
  1472. }
  1473. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1474. return node
  1475. };
  1476. // Convert list of expression atoms to binding list.
  1477. pp$2.toAssignableList = function(exprList, isBinding) {
  1478. var end = exprList.length;
  1479. for (var i = 0; i < end; i++) {
  1480. var elt = exprList[i];
  1481. if (elt) { this.toAssignable(elt, isBinding); }
  1482. }
  1483. if (end) {
  1484. var last = exprList[end - 1];
  1485. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1486. { this.unexpected(last.argument.start); }
  1487. }
  1488. return exprList
  1489. };
  1490. // Parses spread element.
  1491. pp$2.parseSpread = function(refDestructuringErrors) {
  1492. var node = this.startNode();
  1493. this.next();
  1494. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1495. return this.finishNode(node, "SpreadElement")
  1496. };
  1497. pp$2.parseRestBinding = function() {
  1498. var node = this.startNode();
  1499. this.next();
  1500. // RestElement inside of a function parameter must be an identifier
  1501. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  1502. { this.unexpected(); }
  1503. node.argument = this.parseBindingAtom();
  1504. return this.finishNode(node, "RestElement")
  1505. };
  1506. // Parses lvalue (assignable) atom.
  1507. pp$2.parseBindingAtom = function() {
  1508. if (this.options.ecmaVersion >= 6) {
  1509. switch (this.type) {
  1510. case types.bracketL:
  1511. var node = this.startNode();
  1512. this.next();
  1513. node.elements = this.parseBindingList(types.bracketR, true, true);
  1514. return this.finishNode(node, "ArrayPattern")
  1515. case types.braceL:
  1516. return this.parseObj(true)
  1517. }
  1518. }
  1519. return this.parseIdent()
  1520. };
  1521. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1522. var elts = [], first = true;
  1523. while (!this.eat(close)) {
  1524. if (first) { first = false; }
  1525. else { this.expect(types.comma); }
  1526. if (allowEmpty && this.type === types.comma) {
  1527. elts.push(null);
  1528. } else if (allowTrailingComma && this.afterTrailingComma(close)) {
  1529. break
  1530. } else if (this.type === types.ellipsis) {
  1531. var rest = this.parseRestBinding();
  1532. this.parseBindingListItem(rest);
  1533. elts.push(rest);
  1534. if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
  1535. this.expect(close);
  1536. break
  1537. } else {
  1538. var elem = this.parseMaybeDefault(this.start, this.startLoc);
  1539. this.parseBindingListItem(elem);
  1540. elts.push(elem);
  1541. }
  1542. }
  1543. return elts
  1544. };
  1545. pp$2.parseBindingListItem = function(param) {
  1546. return param
  1547. };
  1548. // Parses assignment pattern around given atom if possible.
  1549. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1550. left = left || this.parseBindingAtom();
  1551. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  1552. var node = this.startNodeAt(startPos, startLoc);
  1553. node.left = left;
  1554. node.right = this.parseMaybeAssign();
  1555. return this.finishNode(node, "AssignmentPattern")
  1556. };
  1557. // Verify that a node is an lval — something that can be assigned
  1558. // to.
  1559. // bindingType can be either:
  1560. // 'var' indicating that the lval creates a 'var' binding
  1561. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  1562. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  1563. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  1564. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1565. switch (expr.type) {
  1566. case "Identifier":
  1567. if (bindingType === BIND_LEXICAL && expr.name === "let")
  1568. { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
  1569. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1570. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1571. if (checkClashes) {
  1572. if (has(checkClashes, expr.name))
  1573. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1574. checkClashes[expr.name] = true;
  1575. }
  1576. if (bindingType !== BIND_NONE && bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
  1577. break
  1578. case "MemberExpression":
  1579. if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  1580. break
  1581. case "ObjectPattern":
  1582. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  1583. {
  1584. var prop = list[i];
  1585. this.checkLVal(prop, bindingType, checkClashes);
  1586. }
  1587. break
  1588. case "Property":
  1589. // AssignmentProperty has type === "Property"
  1590. this.checkLVal(expr.value, bindingType, checkClashes);
  1591. break
  1592. case "ArrayPattern":
  1593. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1594. var elem = list$1[i$1];
  1595. if (elem) { this.checkLVal(elem, bindingType, checkClashes); }
  1596. }
  1597. break
  1598. case "AssignmentPattern":
  1599. this.checkLVal(expr.left, bindingType, checkClashes);
  1600. break
  1601. case "RestElement":
  1602. this.checkLVal(expr.argument, bindingType, checkClashes);
  1603. break
  1604. case "ParenthesizedExpression":
  1605. this.checkLVal(expr.expression, bindingType, checkClashes);
  1606. break
  1607. default:
  1608. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  1609. }
  1610. };
  1611. // A recursive descent parser operates by defining functions for all
  1612. var pp$3 = Parser.prototype;
  1613. // Check if property name clashes with already added.
  1614. // Object/class getters and setters are not allowed to clash —
  1615. // either with each other or with an init property — and in
  1616. // strict mode, init properties are also not allowed to be repeated.
  1617. pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  1618. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  1619. { return }
  1620. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1621. { return }
  1622. var key = prop.key;
  1623. var name;
  1624. switch (key.type) {
  1625. case "Identifier": name = key.name; break
  1626. case "Literal": name = String(key.value); break
  1627. default: return
  1628. }
  1629. var kind = prop.kind;
  1630. if (this.options.ecmaVersion >= 6) {
  1631. if (name === "__proto__" && kind === "init") {
  1632. if (propHash.proto) {
  1633. if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; }
  1634. // Backwards-compat kludge. Can be removed in version 6.0
  1635. else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  1636. }
  1637. propHash.proto = true;
  1638. }
  1639. return
  1640. }
  1641. name = "$" + name;
  1642. var other = propHash[name];
  1643. if (other) {
  1644. var redefinition;
  1645. if (kind === "init") {
  1646. redefinition = this.strict && other.init || other.get || other.set;
  1647. } else {
  1648. redefinition = other.init || other[kind];
  1649. }
  1650. if (redefinition)
  1651. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  1652. } else {
  1653. other = propHash[name] = {
  1654. init: false,
  1655. get: false,
  1656. set: false
  1657. };
  1658. }
  1659. other[kind] = true;
  1660. };
  1661. // ### Expression parsing
  1662. // These nest, from the most general expression type at the top to
  1663. // 'atomic', nondivisible expression types at the bottom. Most of
  1664. // the functions will simply let the function(s) below them parse,
  1665. // and, *if* the syntactic construct they handle is present, wrap
  1666. // the AST node that the inner parser gave them in another node.
  1667. // Parse a full expression. The optional arguments are used to
  1668. // forbid the `in` operator (in for loops initalization expressions)
  1669. // and provide reference for storing '=' operator inside shorthand
  1670. // property assignment in contexts where both object expression
  1671. // and object pattern might appear (so it's possible to raise
  1672. // delayed syntax error at correct position).
  1673. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1674. var startPos = this.start, startLoc = this.startLoc;
  1675. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1676. if (this.type === types.comma) {
  1677. var node = this.startNodeAt(startPos, startLoc);
  1678. node.expressions = [expr];
  1679. while (this.eat(types.comma)) { node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors)); }
  1680. return this.finishNode(node, "SequenceExpression")
  1681. }
  1682. return expr
  1683. };
  1684. // Parse an assignment expression. This includes applications of
  1685. // operators like `+=`.
  1686. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1687. if (this.isContextual("yield")) {
  1688. if (this.inGenerator) { return this.parseYield(noIn) }
  1689. // The tokenizer will assume an expression is allowed after
  1690. // `yield`, but this isn't that kind of yield
  1691. else { this.exprAllowed = false; }
  1692. }
  1693. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldShorthandAssign = -1;
  1694. if (refDestructuringErrors) {
  1695. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  1696. oldTrailingComma = refDestructuringErrors.trailingComma;
  1697. oldShorthandAssign = refDestructuringErrors.shorthandAssign;
  1698. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.shorthandAssign = -1;
  1699. } else {
  1700. refDestructuringErrors = new DestructuringErrors;
  1701. ownDestructuringErrors = true;
  1702. }
  1703. var startPos = this.start, startLoc = this.startLoc;
  1704. if (this.type === types.parenL || this.type === types.name)
  1705. { this.potentialArrowAt = this.start; }
  1706. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1707. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  1708. if (this.type.isAssign) {
  1709. var node = this.startNodeAt(startPos, startLoc);
  1710. node.operator = this.value;
  1711. node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
  1712. if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
  1713. refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
  1714. this.checkLVal(left);
  1715. this.next();
  1716. node.right = this.parseMaybeAssign(noIn);
  1717. return this.finishNode(node, "AssignmentExpression")
  1718. } else {
  1719. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  1720. }
  1721. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  1722. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  1723. if (oldShorthandAssign > -1) { refDestructuringErrors.shorthandAssign = oldShorthandAssign; }
  1724. return left
  1725. };
  1726. // Parse a ternary conditional (`?:`) operator.
  1727. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1728. var startPos = this.start, startLoc = this.startLoc;
  1729. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1730. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1731. if (this.eat(types.question)) {
  1732. var node = this.startNodeAt(startPos, startLoc);
  1733. node.test = expr;
  1734. node.consequent = this.parseMaybeAssign();
  1735. this.expect(types.colon);
  1736. node.alternate = this.parseMaybeAssign(noIn);
  1737. return this.finishNode(node, "ConditionalExpression")
  1738. }
  1739. return expr
  1740. };
  1741. // Start the precedence parser.
  1742. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1743. var startPos = this.start, startLoc = this.startLoc;
  1744. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1745. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1746. return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1747. };
  1748. // Parse binary operators with the operator precedence parsing
  1749. // algorithm. `left` is the left-hand side of the operator.
  1750. // `minPrec` provides context that allows the function to stop and
  1751. // defer further parser to one of its callers when it encounters an
  1752. // operator that has a lower precedence than the set it is parsing.
  1753. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1754. var prec = this.type.binop;
  1755. if (prec != null && (!noIn || this.type !== types._in)) {
  1756. if (prec > minPrec) {
  1757. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  1758. var op = this.value;
  1759. this.next();
  1760. var startPos = this.start, startLoc = this.startLoc;
  1761. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1762. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  1763. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1764. }
  1765. }
  1766. return left
  1767. };
  1768. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1769. var node = this.startNodeAt(startPos, startLoc);
  1770. node.left = left;
  1771. node.operator = op;
  1772. node.right = right;
  1773. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1774. };
  1775. // Parse unary operators, both prefix and postfix.
  1776. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1777. var startPos = this.start, startLoc = this.startLoc, expr;
  1778. if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
  1779. expr = this.parseAwait();
  1780. sawUnary = true;
  1781. } else if (this.type.prefix) {
  1782. var node = this.startNode(), update = this.type === types.incDec;
  1783. node.operator = this.value;
  1784. node.prefix = true;
  1785. this.next();
  1786. node.argument = this.parseMaybeUnary(null, true);
  1787. this.checkExpressionErrors(refDestructuringErrors, true);
  1788. if (update) { this.checkLVal(node.argument); }
  1789. else if (this.strict && node.operator === "delete" &&
  1790. node.argument.type === "Identifier")
  1791. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  1792. else { sawUnary = true; }
  1793. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1794. } else {
  1795. expr = this.parseExprSubscripts(refDestructuringErrors);
  1796. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1797. while (this.type.postfix && !this.canInsertSemicolon()) {
  1798. var node$1 = this.startNodeAt(startPos, startLoc);
  1799. node$1.operator = this.value;
  1800. node$1.prefix = false;
  1801. node$1.argument = expr;
  1802. this.checkLVal(expr);
  1803. this.next();
  1804. expr = this.finishNode(node$1, "UpdateExpression");
  1805. }
  1806. }
  1807. if (!sawUnary && this.eat(types.starstar))
  1808. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  1809. else
  1810. { return expr }
  1811. };
  1812. // Parse call, dot, and `[]`-subscript expressions.
  1813. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1814. var startPos = this.start, startLoc = this.startLoc;
  1815. var expr = this.parseExprAtom(refDestructuringErrors);
  1816. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  1817. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
  1818. var result = this.parseSubscripts(expr, startPos, startLoc);
  1819. if (refDestructuringErrors && result.type === "MemberExpression") {
  1820. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  1821. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  1822. }
  1823. return result
  1824. };
  1825. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1826. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  1827. this.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async";
  1828. while (true) {
  1829. var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow);
  1830. if (element === base || element.type === "ArrowFunctionExpression") { return element }
  1831. base = element;
  1832. }
  1833. };
  1834. pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow) {
  1835. var computed = this.eat(types.bracketL);
  1836. if (computed || this.eat(types.dot)) {
  1837. var node = this.startNodeAt(startPos, startLoc);
  1838. node.object = base;
  1839. node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never");
  1840. node.computed = !!computed;
  1841. if (computed) { this.expect(types.bracketR); }
  1842. base = this.finishNode(node, "MemberExpression");
  1843. } else if (!noCalls && this.eat(types.parenL)) {
  1844. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  1845. this.yieldPos = 0;
  1846. this.awaitPos = 0;
  1847. this.awaitIdentPos = 0;
  1848. var exprList = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8 && base.type !== "Import", false, refDestructuringErrors);
  1849. if (maybeAsyncArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  1850. this.checkPatternErrors(refDestructuringErrors, false);
  1851. this.checkYieldAwaitInDefaultParams();
  1852. if (this.awaitIdentPos > 0)
  1853. { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
  1854. this.yieldPos = oldYieldPos;
  1855. this.awaitPos = oldAwaitPos;
  1856. this.awaitIdentPos = oldAwaitIdentPos;
  1857. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true)
  1858. }
  1859. this.checkExpressionErrors(refDestructuringErrors, true);
  1860. this.yieldPos = oldYieldPos || this.yieldPos;
  1861. this.awaitPos = oldAwaitPos || this.awaitPos;
  1862. this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
  1863. var node$1 = this.startNodeAt(startPos, startLoc);
  1864. node$1.callee = base;
  1865. node$1.arguments = exprList;
  1866. if (node$1.callee.type === "Import") {
  1867. if (node$1.arguments.length !== 1) {
  1868. this.raise(node$1.start, "import() requires exactly one argument");
  1869. }
  1870. var importArg = node$1.arguments[0];
  1871. if (importArg && importArg.type === "SpreadElement") {
  1872. this.raise(importArg.start, "... is not allowed in import()");
  1873. }
  1874. }
  1875. base = this.finishNode(node$1, "CallExpression");
  1876. } else if (this.type === types.backQuote) {
  1877. var node$2 = this.startNodeAt(startPos, startLoc);
  1878. node$2.tag = base;
  1879. node$2.quasi = this.parseTemplate({isTagged: true});
  1880. base = this.finishNode(node$2, "TaggedTemplateExpression");
  1881. }
  1882. return base
  1883. };
  1884. // Parse an atomic expression — either a single token that is an
  1885. // expression, an expression started by a keyword like `function` or
  1886. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1887. // or `{}`.
  1888. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1889. // If a division operator appears in an expression position, the
  1890. // tokenizer got confused, and we force it to read a regexp instead.
  1891. if (this.type === types.slash) { this.readRegexp(); }
  1892. var node, canBeArrow = this.potentialArrowAt === this.start;
  1893. switch (this.type) {
  1894. case types._super:
  1895. if (!this.allowSuper)
  1896. { this.raise(this.start, "'super' keyword outside a method"); }
  1897. node = this.startNode();
  1898. this.next();
  1899. if (this.type === types.parenL && !this.allowDirectSuper)
  1900. { this.raise(node.start, "super() call outside constructor of a subclass"); }
  1901. // The `super` keyword can appear at below:
  1902. // SuperProperty:
  1903. // super [ Expression ]
  1904. // super . IdentifierName
  1905. // SuperCall:
  1906. // super Arguments
  1907. if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
  1908. { this.unexpected(); }
  1909. return this.finishNode(node, "Super")
  1910. case types._this:
  1911. node = this.startNode();
  1912. this.next();
  1913. return this.finishNode(node, "ThisExpression")
  1914. case types.name:
  1915. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  1916. var id = this.parseIdent(false);
  1917. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  1918. { return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true) }
  1919. if (canBeArrow && !this.canInsertSemicolon()) {
  1920. if (this.eat(types.arrow))
  1921. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  1922. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
  1923. id = this.parseIdent(false);
  1924. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  1925. { this.unexpected(); }
  1926. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  1927. }
  1928. }
  1929. return id
  1930. case types.regexp:
  1931. var value = this.value;
  1932. node = this.parseLiteral(value.value);
  1933. node.regex = {pattern: value.pattern, flags: value.flags};
  1934. return node
  1935. case types.num: case types.string:
  1936. return this.parseLiteral(this.value)
  1937. case types._null: case types._true: case types._false:
  1938. node = this.startNode();
  1939. node.value = this.type === types._null ? null : this.type === types._true;
  1940. node.raw = this.type.keyword;
  1941. this.next();
  1942. return this.finishNode(node, "Literal")
  1943. case types.parenL:
  1944. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  1945. if (refDestructuringErrors) {
  1946. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  1947. { refDestructuringErrors.parenthesizedAssign = start; }
  1948. if (refDestructuringErrors.parenthesizedBind < 0)
  1949. { refDestructuringErrors.parenthesizedBind = start; }
  1950. }
  1951. return expr
  1952. case types.bracketL:
  1953. node = this.startNode();
  1954. this.next();
  1955. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  1956. return this.finishNode(node, "ArrayExpression")
  1957. case types.braceL:
  1958. return this.parseObj(false, refDestructuringErrors)
  1959. case types._function:
  1960. node = this.startNode();
  1961. this.next();
  1962. return this.parseFunction(node, 0)
  1963. case types._class:
  1964. return this.parseClass(this.startNode(), false)
  1965. case types._new:
  1966. return this.parseNew()
  1967. case types.backQuote:
  1968. return this.parseTemplate()
  1969. case types._import:
  1970. if (this.options.ecmaVersion > 10) {
  1971. return this.parseDynamicImport()
  1972. } else {
  1973. return this.unexpected()
  1974. }
  1975. default:
  1976. this.unexpected();
  1977. }
  1978. };
  1979. pp$3.parseDynamicImport = function() {
  1980. var node = this.startNode();
  1981. this.next();
  1982. if (this.type !== types.parenL) {
  1983. this.unexpected();
  1984. }
  1985. return this.finishNode(node, "Import")
  1986. };
  1987. pp$3.parseLiteral = function(value) {
  1988. var node = this.startNode();
  1989. node.value = value;
  1990. node.raw = this.input.slice(this.start, this.end);
  1991. if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1); }
  1992. this.next();
  1993. return this.finishNode(node, "Literal")
  1994. };
  1995. pp$3.parseParenExpression = function() {
  1996. this.expect(types.parenL);
  1997. var val = this.parseExpression();
  1998. this.expect(types.parenR);
  1999. return val
  2000. };
  2001. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  2002. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  2003. if (this.options.ecmaVersion >= 6) {
  2004. this.next();
  2005. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  2006. var exprList = [], first = true, lastIsComma = false;
  2007. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  2008. this.yieldPos = 0;
  2009. this.awaitPos = 0;
  2010. // Do not save awaitIdentPos to allow checking awaits nested in parameters
  2011. while (this.type !== types.parenR) {
  2012. first ? first = false : this.expect(types.comma);
  2013. if (allowTrailingComma && this.afterTrailingComma(types.parenR, true)) {
  2014. lastIsComma = true;
  2015. break
  2016. } else if (this.type === types.ellipsis) {
  2017. spreadStart = this.start;
  2018. exprList.push(this.parseParenItem(this.parseRestBinding()));
  2019. if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
  2020. break
  2021. } else {
  2022. exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
  2023. }
  2024. }
  2025. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  2026. this.expect(types.parenR);
  2027. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  2028. this.checkPatternErrors(refDestructuringErrors, false);
  2029. this.checkYieldAwaitInDefaultParams();
  2030. this.yieldPos = oldYieldPos;
  2031. this.awaitPos = oldAwaitPos;
  2032. return this.parseParenArrowList(startPos, startLoc, exprList)
  2033. }
  2034. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  2035. if (spreadStart) { this.unexpected(spreadStart); }
  2036. this.checkExpressionErrors(refDestructuringErrors, true);
  2037. this.yieldPos = oldYieldPos || this.yieldPos;
  2038. this.awaitPos = oldAwaitPos || this.awaitPos;
  2039. if (exprList.length > 1) {
  2040. val = this.startNodeAt(innerStartPos, innerStartLoc);
  2041. val.expressions = exprList;
  2042. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  2043. } else {
  2044. val = exprList[0];
  2045. }
  2046. } else {
  2047. val = this.parseParenExpression();
  2048. }
  2049. if (this.options.preserveParens) {
  2050. var par = this.startNodeAt(startPos, startLoc);
  2051. par.expression = val;
  2052. return this.finishNode(par, "ParenthesizedExpression")
  2053. } else {
  2054. return val
  2055. }
  2056. };
  2057. pp$3.parseParenItem = function(item) {
  2058. return item
  2059. };
  2060. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  2061. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  2062. };
  2063. // New's precedence is slightly tricky. It must allow its argument to
  2064. // be a `[]` or dot subscript expression, but not a call — at least,
  2065. // not without wrapping it in parentheses. Thus, it uses the noCalls
  2066. // argument to parseSubscripts to prevent it from consuming the
  2067. // argument list.
  2068. var empty$1 = [];
  2069. pp$3.parseNew = function() {
  2070. var node = this.startNode();
  2071. var meta = this.parseIdent(true);
  2072. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  2073. node.meta = meta;
  2074. var containsEsc = this.containsEsc;
  2075. node.property = this.parseIdent(true);
  2076. if (node.property.name !== "target" || containsEsc)
  2077. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
  2078. if (!this.inNonArrowFunction())
  2079. { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
  2080. return this.finishNode(node, "MetaProperty")
  2081. }
  2082. var startPos = this.start, startLoc = this.startLoc;
  2083. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  2084. if (this.options.ecmaVersion > 10 && node.callee.type === "Import") {
  2085. this.raise(node.callee.start, "Cannot use new with import(...)");
  2086. }
  2087. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8 && node.callee.type !== "Import", false); }
  2088. else { node.arguments = empty$1; }
  2089. return this.finishNode(node, "NewExpression")
  2090. };
  2091. // Parse template expression.
  2092. pp$3.parseTemplateElement = function(ref) {
  2093. var isTagged = ref.isTagged;
  2094. var elem = this.startNode();
  2095. if (this.type === types.invalidTemplate) {
  2096. if (!isTagged) {
  2097. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2098. }
  2099. elem.value = {
  2100. raw: this.value,
  2101. cooked: null
  2102. };
  2103. } else {
  2104. elem.value = {
  2105. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2106. cooked: this.value
  2107. };
  2108. }
  2109. this.next();
  2110. elem.tail = this.type === types.backQuote;
  2111. return this.finishNode(elem, "TemplateElement")
  2112. };
  2113. pp$3.parseTemplate = function(ref) {
  2114. if ( ref === void 0 ) ref = {};
  2115. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2116. var node = this.startNode();
  2117. this.next();
  2118. node.expressions = [];
  2119. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2120. node.quasis = [curElt];
  2121. while (!curElt.tail) {
  2122. if (this.type === types.eof) { this.raise(this.pos, "Unterminated template literal"); }
  2123. this.expect(types.dollarBraceL);
  2124. node.expressions.push(this.parseExpression());
  2125. this.expect(types.braceR);
  2126. node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
  2127. }
  2128. this.next();
  2129. return this.finishNode(node, "TemplateLiteral")
  2130. };
  2131. pp$3.isAsyncProp = function(prop) {
  2132. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2133. (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) &&
  2134. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2135. };
  2136. // Parse an object literal or binding pattern.
  2137. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  2138. var node = this.startNode(), first = true, propHash = {};
  2139. node.properties = [];
  2140. this.next();
  2141. while (!this.eat(types.braceR)) {
  2142. if (!first) {
  2143. this.expect(types.comma);
  2144. if (this.afterTrailingComma(types.braceR)) { break }
  2145. } else { first = false; }
  2146. var prop = this.parseProperty(isPattern, refDestructuringErrors);
  2147. if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
  2148. node.properties.push(prop);
  2149. }
  2150. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2151. };
  2152. pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
  2153. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2154. if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
  2155. if (isPattern) {
  2156. prop.argument = this.parseIdent(false);
  2157. if (this.type === types.comma) {
  2158. this.raise(this.start, "Comma is not permitted after the rest element");
  2159. }
  2160. return this.finishNode(prop, "RestElement")
  2161. }
  2162. // To disallow parenthesized identifier via `this.toAssignable()`.
  2163. if (this.type === types.parenL && refDestructuringErrors) {
  2164. if (refDestructuringErrors.parenthesizedAssign < 0) {
  2165. refDestructuringErrors.parenthesizedAssign = this.start;
  2166. }
  2167. if (refDestructuringErrors.parenthesizedBind < 0) {
  2168. refDestructuringErrors.parenthesizedBind = this.start;
  2169. }
  2170. }
  2171. // Parse argument.
  2172. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2173. // To disallow trailing comma via `this.toAssignable()`.
  2174. if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2175. refDestructuringErrors.trailingComma = this.start;
  2176. }
  2177. // Finish
  2178. return this.finishNode(prop, "SpreadElement")
  2179. }
  2180. if (this.options.ecmaVersion >= 6) {
  2181. prop.method = false;
  2182. prop.shorthand = false;
  2183. if (isPattern || refDestructuringErrors) {
  2184. startPos = this.start;
  2185. startLoc = this.startLoc;
  2186. }
  2187. if (!isPattern)
  2188. { isGenerator = this.eat(types.star); }
  2189. }
  2190. var containsEsc = this.containsEsc;
  2191. this.parsePropertyName(prop);
  2192. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2193. isAsync = true;
  2194. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  2195. this.parsePropertyName(prop, refDestructuringErrors);
  2196. } else {
  2197. isAsync = false;
  2198. }
  2199. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2200. return this.finishNode(prop, "Property")
  2201. };
  2202. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  2203. if ((isGenerator || isAsync) && this.type === types.colon)
  2204. { this.unexpected(); }
  2205. if (this.eat(types.colon)) {
  2206. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  2207. prop.kind = "init";
  2208. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  2209. if (isPattern) { this.unexpected(); }
  2210. prop.kind = "init";
  2211. prop.method = true;
  2212. prop.value = this.parseMethod(isGenerator, isAsync);
  2213. } else if (!isPattern && !containsEsc &&
  2214. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2215. (prop.key.name === "get" || prop.key.name === "set") &&
  2216. (this.type !== types.comma && this.type !== types.braceR)) {
  2217. if (isGenerator || isAsync) { this.unexpected(); }
  2218. prop.kind = prop.key.name;
  2219. this.parsePropertyName(prop);
  2220. prop.value = this.parseMethod(false);
  2221. var paramCount = prop.kind === "get" ? 0 : 1;
  2222. if (prop.value.params.length !== paramCount) {
  2223. var start = prop.value.start;
  2224. if (prop.kind === "get")
  2225. { this.raiseRecoverable(start, "getter should have no params"); }
  2226. else
  2227. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2228. } else {
  2229. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2230. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2231. }
  2232. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2233. if (isGenerator || isAsync) { this.unexpected(); }
  2234. this.checkUnreserved(prop.key);
  2235. if (prop.key.name === "await" && !this.awaitIdentPos)
  2236. { this.awaitIdentPos = startPos; }
  2237. prop.kind = "init";
  2238. if (isPattern) {
  2239. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2240. } else if (this.type === types.eq && refDestructuringErrors) {
  2241. if (refDestructuringErrors.shorthandAssign < 0)
  2242. { refDestructuringErrors.shorthandAssign = this.start; }
  2243. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2244. } else {
  2245. prop.value = prop.key;
  2246. }
  2247. prop.shorthand = true;
  2248. } else { this.unexpected(); }
  2249. };
  2250. pp$3.parsePropertyName = function(prop) {
  2251. if (this.options.ecmaVersion >= 6) {
  2252. if (this.eat(types.bracketL)) {
  2253. prop.computed = true;
  2254. prop.key = this.parseMaybeAssign();
  2255. this.expect(types.bracketR);
  2256. return prop.key
  2257. } else {
  2258. prop.computed = false;
  2259. }
  2260. }
  2261. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
  2262. };
  2263. // Initialize empty function node.
  2264. pp$3.initFunction = function(node) {
  2265. node.id = null;
  2266. if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
  2267. if (this.options.ecmaVersion >= 8) { node.async = false; }
  2268. };
  2269. // Parse object or class method.
  2270. pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
  2271. var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2272. this.initFunction(node);
  2273. if (this.options.ecmaVersion >= 6)
  2274. { node.generator = isGenerator; }
  2275. if (this.options.ecmaVersion >= 8)
  2276. { node.async = !!isAsync; }
  2277. this.yieldPos = 0;
  2278. this.awaitPos = 0;
  2279. this.awaitIdentPos = 0;
  2280. this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  2281. this.expect(types.parenL);
  2282. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2283. this.checkYieldAwaitInDefaultParams();
  2284. this.parseFunctionBody(node, false, true);
  2285. this.yieldPos = oldYieldPos;
  2286. this.awaitPos = oldAwaitPos;
  2287. this.awaitIdentPos = oldAwaitIdentPos;
  2288. return this.finishNode(node, "FunctionExpression")
  2289. };
  2290. // Parse arrow function expression with given parameters.
  2291. pp$3.parseArrowExpression = function(node, params, isAsync) {
  2292. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2293. this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
  2294. this.initFunction(node);
  2295. if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
  2296. this.yieldPos = 0;
  2297. this.awaitPos = 0;
  2298. this.awaitIdentPos = 0;
  2299. node.params = this.toAssignableList(params, true);
  2300. this.parseFunctionBody(node, true, false);
  2301. this.yieldPos = oldYieldPos;
  2302. this.awaitPos = oldAwaitPos;
  2303. this.awaitIdentPos = oldAwaitIdentPos;
  2304. return this.finishNode(node, "ArrowFunctionExpression")
  2305. };
  2306. // Parse function body and check parameters.
  2307. pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) {
  2308. var isExpression = isArrowFunction && this.type !== types.braceL;
  2309. var oldStrict = this.strict, useStrict = false;
  2310. if (isExpression) {
  2311. node.body = this.parseMaybeAssign();
  2312. node.expression = true;
  2313. this.checkParams(node, false);
  2314. } else {
  2315. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2316. if (!oldStrict || nonSimple) {
  2317. useStrict = this.strictDirective(this.end);
  2318. // If this is a strict mode function, verify that argument names
  2319. // are not repeated, and it does not try to bind the words `eval`
  2320. // or `arguments`.
  2321. if (useStrict && nonSimple)
  2322. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2323. }
  2324. // Start a new scope with regard to labels and the `inFunction`
  2325. // flag (restore them to their old value afterwards).
  2326. var oldLabels = this.labels;
  2327. this.labels = [];
  2328. if (useStrict) { this.strict = true; }
  2329. // Add the params to varDeclaredNames to ensure that an error is thrown
  2330. // if a let/const declaration in the function clashes with one of the params.
  2331. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
  2332. node.body = this.parseBlock(false);
  2333. node.expression = false;
  2334. this.adaptDirectivePrologue(node.body.body);
  2335. this.labels = oldLabels;
  2336. }
  2337. this.exitScope();
  2338. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2339. if (this.strict && node.id) { this.checkLVal(node.id, BIND_OUTSIDE); }
  2340. this.strict = oldStrict;
  2341. };
  2342. pp$3.isSimpleParamList = function(params) {
  2343. for (var i = 0, list = params; i < list.length; i += 1)
  2344. {
  2345. var param = list[i];
  2346. if (param.type !== "Identifier") { return false
  2347. } }
  2348. return true
  2349. };
  2350. // Checks function params for various disallowed patterns such as using "eval"
  2351. // or "arguments" and duplicate parameters.
  2352. pp$3.checkParams = function(node, allowDuplicates) {
  2353. var nameHash = {};
  2354. for (var i = 0, list = node.params; i < list.length; i += 1)
  2355. {
  2356. var param = list[i];
  2357. this.checkLVal(param, BIND_VAR, allowDuplicates ? null : nameHash);
  2358. }
  2359. };
  2360. // Parses a comma-separated list of expressions, and returns them as
  2361. // an array. `close` is the token type that ends the list, and
  2362. // `allowEmpty` can be turned on to allow subsequent commas with
  2363. // nothing in between them to be parsed as `null` (which is needed
  2364. // for array literals).
  2365. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2366. var elts = [], first = true;
  2367. while (!this.eat(close)) {
  2368. if (!first) {
  2369. this.expect(types.comma);
  2370. if (allowTrailingComma && this.afterTrailingComma(close)) { break }
  2371. } else { first = false; }
  2372. var elt = (void 0);
  2373. if (allowEmpty && this.type === types.comma)
  2374. { elt = null; }
  2375. else if (this.type === types.ellipsis) {
  2376. elt = this.parseSpread(refDestructuringErrors);
  2377. if (refDestructuringErrors && this.type === types.comma && refDestructuringErrors.trailingComma < 0)
  2378. { refDestructuringErrors.trailingComma = this.start; }
  2379. } else {
  2380. elt = this.parseMaybeAssign(false, refDestructuringErrors);
  2381. }
  2382. elts.push(elt);
  2383. }
  2384. return elts
  2385. };
  2386. pp$3.checkUnreserved = function(ref) {
  2387. var start = ref.start;
  2388. var end = ref.end;
  2389. var name = ref.name;
  2390. if (this.inGenerator && name === "yield")
  2391. { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
  2392. if (this.inAsync && name === "await")
  2393. { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
  2394. if (this.keywords.test(name))
  2395. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2396. if (this.options.ecmaVersion < 6 &&
  2397. this.input.slice(start, end).indexOf("\\") !== -1) { return }
  2398. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2399. if (re.test(name)) {
  2400. if (!this.inAsync && name === "await")
  2401. { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
  2402. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  2403. }
  2404. };
  2405. // Parse the next token as an identifier. If `liberal` is true (used
  2406. // when parsing properties), it will also convert keywords into
  2407. // identifiers.
  2408. pp$3.parseIdent = function(liberal, isBinding) {
  2409. var node = this.startNode();
  2410. if (this.type === types.name) {
  2411. node.name = this.value;
  2412. } else if (this.type.keyword) {
  2413. node.name = this.type.keyword;
  2414. // To fix https://github.com/acornjs/acorn/issues/575
  2415. // `class` and `function` keywords push new context into this.context.
  2416. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  2417. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  2418. if ((node.name === "class" || node.name === "function") &&
  2419. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  2420. this.context.pop();
  2421. }
  2422. } else {
  2423. this.unexpected();
  2424. }
  2425. this.next();
  2426. this.finishNode(node, "Identifier");
  2427. if (!liberal) {
  2428. this.checkUnreserved(node);
  2429. if (node.name === "await" && !this.awaitIdentPos)
  2430. { this.awaitIdentPos = node.start; }
  2431. }
  2432. return node
  2433. };
  2434. // Parses yield expression inside generator.
  2435. pp$3.parseYield = function(noIn) {
  2436. if (!this.yieldPos) { this.yieldPos = this.start; }
  2437. var node = this.startNode();
  2438. this.next();
  2439. if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
  2440. node.delegate = false;
  2441. node.argument = null;
  2442. } else {
  2443. node.delegate = this.eat(types.star);
  2444. node.argument = this.parseMaybeAssign(noIn);
  2445. }
  2446. return this.finishNode(node, "YieldExpression")
  2447. };
  2448. pp$3.parseAwait = function() {
  2449. if (!this.awaitPos) { this.awaitPos = this.start; }
  2450. var node = this.startNode();
  2451. this.next();
  2452. node.argument = this.parseMaybeUnary(null, true);
  2453. return this.finishNode(node, "AwaitExpression")
  2454. };
  2455. var pp$4 = Parser.prototype;
  2456. // This function is used to raise exceptions on parse errors. It
  2457. // takes an offset integer (into the current `input`) to indicate
  2458. // the location of the error, attaches the position to the end
  2459. // of the error message, and then raises a `SyntaxError` with that
  2460. // message.
  2461. pp$4.raise = function(pos, message) {
  2462. var loc = getLineInfo(this.input, pos);
  2463. message += " (" + loc.line + ":" + loc.column + ")";
  2464. var err = new SyntaxError(message);
  2465. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  2466. throw err
  2467. };
  2468. pp$4.raiseRecoverable = pp$4.raise;
  2469. pp$4.curPosition = function() {
  2470. if (this.options.locations) {
  2471. return new Position(this.curLine, this.pos - this.lineStart)
  2472. }
  2473. };
  2474. var pp$5 = Parser.prototype;
  2475. var Scope = function Scope(flags) {
  2476. this.flags = flags;
  2477. // A list of var-declared names in the current lexical scope
  2478. this.var = [];
  2479. // A list of lexically-declared names in the current lexical scope
  2480. this.lexical = [];
  2481. // A list of lexically-declared FunctionDeclaration names in the current lexical scope
  2482. this.functions = [];
  2483. };
  2484. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  2485. pp$5.enterScope = function(flags) {
  2486. this.scopeStack.push(new Scope(flags));
  2487. };
  2488. pp$5.exitScope = function() {
  2489. this.scopeStack.pop();
  2490. };
  2491. // The spec says:
  2492. // > At the top level of a function, or script, function declarations are
  2493. // > treated like var declarations rather than like lexical declarations.
  2494. pp$5.treatFunctionsAsVarInScope = function(scope) {
  2495. return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
  2496. };
  2497. pp$5.declareName = function(name, bindingType, pos) {
  2498. var redeclared = false;
  2499. if (bindingType === BIND_LEXICAL) {
  2500. var scope = this.currentScope();
  2501. redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
  2502. scope.lexical.push(name);
  2503. if (this.inModule && (scope.flags & SCOPE_TOP))
  2504. { delete this.undefinedExports[name]; }
  2505. } else if (bindingType === BIND_SIMPLE_CATCH) {
  2506. var scope$1 = this.currentScope();
  2507. scope$1.lexical.push(name);
  2508. } else if (bindingType === BIND_FUNCTION) {
  2509. var scope$2 = this.currentScope();
  2510. if (this.treatFunctionsAsVar)
  2511. { redeclared = scope$2.lexical.indexOf(name) > -1; }
  2512. else
  2513. { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
  2514. scope$2.functions.push(name);
  2515. } else {
  2516. for (var i = this.scopeStack.length - 1; i >= 0; --i) {
  2517. var scope$3 = this.scopeStack[i];
  2518. if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
  2519. !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
  2520. redeclared = true;
  2521. break
  2522. }
  2523. scope$3.var.push(name);
  2524. if (this.inModule && (scope$3.flags & SCOPE_TOP))
  2525. { delete this.undefinedExports[name]; }
  2526. if (scope$3.flags & SCOPE_VAR) { break }
  2527. }
  2528. }
  2529. if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
  2530. };
  2531. pp$5.checkLocalExport = function(id) {
  2532. // scope.functions must be empty as Module code is always strict.
  2533. if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
  2534. this.scopeStack[0].var.indexOf(id.name) === -1) {
  2535. this.undefinedExports[id.name] = id;
  2536. }
  2537. };
  2538. pp$5.currentScope = function() {
  2539. return this.scopeStack[this.scopeStack.length - 1]
  2540. };
  2541. pp$5.currentVarScope = function() {
  2542. for (var i = this.scopeStack.length - 1;; i--) {
  2543. var scope = this.scopeStack[i];
  2544. if (scope.flags & SCOPE_VAR) { return scope }
  2545. }
  2546. };
  2547. // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
  2548. pp$5.currentThisScope = function() {
  2549. for (var i = this.scopeStack.length - 1;; i--) {
  2550. var scope = this.scopeStack[i];
  2551. if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
  2552. }
  2553. };
  2554. var Node = function Node(parser, pos, loc) {
  2555. this.type = "";
  2556. this.start = pos;
  2557. this.end = 0;
  2558. if (parser.options.locations)
  2559. { this.loc = new SourceLocation(parser, loc); }
  2560. if (parser.options.directSourceFile)
  2561. { this.sourceFile = parser.options.directSourceFile; }
  2562. if (parser.options.ranges)
  2563. { this.range = [pos, 0]; }
  2564. };
  2565. // Start an AST node, attaching a start offset.
  2566. var pp$6 = Parser.prototype;
  2567. pp$6.startNode = function() {
  2568. return new Node(this, this.start, this.startLoc)
  2569. };
  2570. pp$6.startNodeAt = function(pos, loc) {
  2571. return new Node(this, pos, loc)
  2572. };
  2573. // Finish an AST node, adding `type` and `end` properties.
  2574. function finishNodeAt(node, type, pos, loc) {
  2575. node.type = type;
  2576. node.end = pos;
  2577. if (this.options.locations)
  2578. { node.loc.end = loc; }
  2579. if (this.options.ranges)
  2580. { node.range[1] = pos; }
  2581. return node
  2582. }
  2583. pp$6.finishNode = function(node, type) {
  2584. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  2585. };
  2586. // Finish node at given position
  2587. pp$6.finishNodeAt = function(node, type, pos, loc) {
  2588. return finishNodeAt.call(this, node, type, pos, loc)
  2589. };
  2590. // The algorithm used to determine whether a regexp can appear at a
  2591. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2592. this.token = token;
  2593. this.isExpr = !!isExpr;
  2594. this.preserveSpace = !!preserveSpace;
  2595. this.override = override;
  2596. this.generator = !!generator;
  2597. };
  2598. var types$1 = {
  2599. b_stat: new TokContext("{", false),
  2600. b_expr: new TokContext("{", true),
  2601. b_tmpl: new TokContext("${", false),
  2602. p_stat: new TokContext("(", false),
  2603. p_expr: new TokContext("(", true),
  2604. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2605. f_stat: new TokContext("function", false),
  2606. f_expr: new TokContext("function", true),
  2607. f_expr_gen: new TokContext("function", true, false, null, true),
  2608. f_gen: new TokContext("function", false, false, null, true)
  2609. };
  2610. var pp$7 = Parser.prototype;
  2611. pp$7.initialContext = function() {
  2612. return [types$1.b_stat]
  2613. };
  2614. pp$7.braceIsBlock = function(prevType) {
  2615. var parent = this.curContext();
  2616. if (parent === types$1.f_expr || parent === types$1.f_stat)
  2617. { return true }
  2618. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  2619. { return !parent.isExpr }
  2620. // The check for `tt.name && exprAllowed` detects whether we are
  2621. // after a `yield` or `of` construct. See the `updateContext` for
  2622. // `tt.name`.
  2623. if (prevType === types._return || prevType === types.name && this.exprAllowed)
  2624. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2625. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
  2626. { return true }
  2627. if (prevType === types.braceL)
  2628. { return parent === types$1.b_stat }
  2629. if (prevType === types._var || prevType === types._const || prevType === types.name)
  2630. { return false }
  2631. return !this.exprAllowed
  2632. };
  2633. pp$7.inGeneratorContext = function() {
  2634. for (var i = this.context.length - 1; i >= 1; i--) {
  2635. var context = this.context[i];
  2636. if (context.token === "function")
  2637. { return context.generator }
  2638. }
  2639. return false
  2640. };
  2641. pp$7.updateContext = function(prevType) {
  2642. var update, type = this.type;
  2643. if (type.keyword && prevType === types.dot)
  2644. { this.exprAllowed = false; }
  2645. else if (update = type.updateContext)
  2646. { update.call(this, prevType); }
  2647. else
  2648. { this.exprAllowed = type.beforeExpr; }
  2649. };
  2650. // Token-specific context update code
  2651. types.parenR.updateContext = types.braceR.updateContext = function() {
  2652. if (this.context.length === 1) {
  2653. this.exprAllowed = true;
  2654. return
  2655. }
  2656. var out = this.context.pop();
  2657. if (out === types$1.b_stat && this.curContext().token === "function") {
  2658. out = this.context.pop();
  2659. }
  2660. this.exprAllowed = !out.isExpr;
  2661. };
  2662. types.braceL.updateContext = function(prevType) {
  2663. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  2664. this.exprAllowed = true;
  2665. };
  2666. types.dollarBraceL.updateContext = function() {
  2667. this.context.push(types$1.b_tmpl);
  2668. this.exprAllowed = true;
  2669. };
  2670. types.parenL.updateContext = function(prevType) {
  2671. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  2672. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  2673. this.exprAllowed = true;
  2674. };
  2675. types.incDec.updateContext = function() {
  2676. // tokExprAllowed stays unchanged
  2677. };
  2678. types._function.updateContext = types._class.updateContext = function(prevType) {
  2679. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  2680. !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
  2681. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  2682. { this.context.push(types$1.f_expr); }
  2683. else
  2684. { this.context.push(types$1.f_stat); }
  2685. this.exprAllowed = false;
  2686. };
  2687. types.backQuote.updateContext = function() {
  2688. if (this.curContext() === types$1.q_tmpl)
  2689. { this.context.pop(); }
  2690. else
  2691. { this.context.push(types$1.q_tmpl); }
  2692. this.exprAllowed = false;
  2693. };
  2694. types.star.updateContext = function(prevType) {
  2695. if (prevType === types._function) {
  2696. var index = this.context.length - 1;
  2697. if (this.context[index] === types$1.f_expr)
  2698. { this.context[index] = types$1.f_expr_gen; }
  2699. else
  2700. { this.context[index] = types$1.f_gen; }
  2701. }
  2702. this.exprAllowed = true;
  2703. };
  2704. types.name.updateContext = function(prevType) {
  2705. var allowed = false;
  2706. if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
  2707. if (this.value === "of" && !this.exprAllowed ||
  2708. this.value === "yield" && this.inGeneratorContext())
  2709. { allowed = true; }
  2710. }
  2711. this.exprAllowed = allowed;
  2712. };
  2713. // This file contains Unicode properties extracted from the ECMAScript
  2714. // specification. The lists are extracted like so:
  2715. // $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
  2716. // #table-binary-unicode-properties
  2717. var ecma9BinaryProperties = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS";
  2718. var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
  2719. var ecma11BinaryProperties = ecma10BinaryProperties;
  2720. var unicodeBinaryProperties = {
  2721. 9: ecma9BinaryProperties,
  2722. 10: ecma10BinaryProperties,
  2723. 11: ecma11BinaryProperties
  2724. };
  2725. // #table-unicode-general-category-values
  2726. var unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu";
  2727. // #table-unicode-script-values
  2728. var ecma9ScriptValues = "Adlam Adlm Ahom Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb";
  2729. var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
  2730. var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
  2731. var unicodeScriptValues = {
  2732. 9: ecma9ScriptValues,
  2733. 10: ecma10ScriptValues,
  2734. 11: ecma11ScriptValues
  2735. };
  2736. var data = {};
  2737. function buildUnicodeData(ecmaVersion) {
  2738. var d = data[ecmaVersion] = {
  2739. binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
  2740. nonBinary: {
  2741. General_Category: wordsRegexp(unicodeGeneralCategoryValues),
  2742. Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
  2743. }
  2744. };
  2745. d.nonBinary.Script_Extensions = d.nonBinary.Script;
  2746. d.nonBinary.gc = d.nonBinary.General_Category;
  2747. d.nonBinary.sc = d.nonBinary.Script;
  2748. d.nonBinary.scx = d.nonBinary.Script_Extensions;
  2749. }
  2750. buildUnicodeData(9);
  2751. buildUnicodeData(10);
  2752. buildUnicodeData(11);
  2753. var pp$8 = Parser.prototype;
  2754. var RegExpValidationState = function RegExpValidationState(parser) {
  2755. this.parser = parser;
  2756. this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
  2757. this.unicodeProperties = data[parser.options.ecmaVersion >= 11 ? 11 : parser.options.ecmaVersion];
  2758. this.source = "";
  2759. this.flags = "";
  2760. this.start = 0;
  2761. this.switchU = false;
  2762. this.switchN = false;
  2763. this.pos = 0;
  2764. this.lastIntValue = 0;
  2765. this.lastStringValue = "";
  2766. this.lastAssertionIsQuantifiable = false;
  2767. this.numCapturingParens = 0;
  2768. this.maxBackReference = 0;
  2769. this.groupNames = [];
  2770. this.backReferenceNames = [];
  2771. };
  2772. RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
  2773. var unicode = flags.indexOf("u") !== -1;
  2774. this.start = start | 0;
  2775. this.source = pattern + "";
  2776. this.flags = flags;
  2777. this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
  2778. this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
  2779. };
  2780. RegExpValidationState.prototype.raise = function raise (message) {
  2781. this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
  2782. };
  2783. // If u flag is given, this returns the code point at the index (it combines a surrogate pair).
  2784. // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
  2785. RegExpValidationState.prototype.at = function at (i) {
  2786. var s = this.source;
  2787. var l = s.length;
  2788. if (i >= l) {
  2789. return -1
  2790. }
  2791. var c = s.charCodeAt(i);
  2792. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  2793. return c
  2794. }
  2795. return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00
  2796. };
  2797. RegExpValidationState.prototype.nextIndex = function nextIndex (i) {
  2798. var s = this.source;
  2799. var l = s.length;
  2800. if (i >= l) {
  2801. return l
  2802. }
  2803. var c = s.charCodeAt(i);
  2804. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  2805. return i + 1
  2806. }
  2807. return i + 2
  2808. };
  2809. RegExpValidationState.prototype.current = function current () {
  2810. return this.at(this.pos)
  2811. };
  2812. RegExpValidationState.prototype.lookahead = function lookahead () {
  2813. return this.at(this.nextIndex(this.pos))
  2814. };
  2815. RegExpValidationState.prototype.advance = function advance () {
  2816. this.pos = this.nextIndex(this.pos);
  2817. };
  2818. RegExpValidationState.prototype.eat = function eat (ch) {
  2819. if (this.current() === ch) {
  2820. this.advance();
  2821. return true
  2822. }
  2823. return false
  2824. };
  2825. function codePointToString(ch) {
  2826. if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
  2827. ch -= 0x10000;
  2828. return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
  2829. }
  2830. /**
  2831. * Validate the flags part of a given RegExpLiteral.
  2832. *
  2833. * @param {RegExpValidationState} state The state to validate RegExp.
  2834. * @returns {void}
  2835. */
  2836. pp$8.validateRegExpFlags = function(state) {
  2837. var validFlags = state.validFlags;
  2838. var flags = state.flags;
  2839. for (var i = 0; i < flags.length; i++) {
  2840. var flag = flags.charAt(i);
  2841. if (validFlags.indexOf(flag) === -1) {
  2842. this.raise(state.start, "Invalid regular expression flag");
  2843. }
  2844. if (flags.indexOf(flag, i + 1) > -1) {
  2845. this.raise(state.start, "Duplicate regular expression flag");
  2846. }
  2847. }
  2848. };
  2849. /**
  2850. * Validate the pattern part of a given RegExpLiteral.
  2851. *
  2852. * @param {RegExpValidationState} state The state to validate RegExp.
  2853. * @returns {void}
  2854. */
  2855. pp$8.validateRegExpPattern = function(state) {
  2856. this.regexp_pattern(state);
  2857. // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
  2858. // parsing contains a |GroupName|, reparse with the goal symbol
  2859. // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
  2860. // exception if _P_ did not conform to the grammar, if any elements of _P_
  2861. // were not matched by the parse, or if any Early Error conditions exist.
  2862. if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
  2863. state.switchN = true;
  2864. this.regexp_pattern(state);
  2865. }
  2866. };
  2867. // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
  2868. pp$8.regexp_pattern = function(state) {
  2869. state.pos = 0;
  2870. state.lastIntValue = 0;
  2871. state.lastStringValue = "";
  2872. state.lastAssertionIsQuantifiable = false;
  2873. state.numCapturingParens = 0;
  2874. state.maxBackReference = 0;
  2875. state.groupNames.length = 0;
  2876. state.backReferenceNames.length = 0;
  2877. this.regexp_disjunction(state);
  2878. if (state.pos !== state.source.length) {
  2879. // Make the same messages as V8.
  2880. if (state.eat(0x29 /* ) */)) {
  2881. state.raise("Unmatched ')'");
  2882. }
  2883. if (state.eat(0x5D /* [ */) || state.eat(0x7D /* } */)) {
  2884. state.raise("Lone quantifier brackets");
  2885. }
  2886. }
  2887. if (state.maxBackReference > state.numCapturingParens) {
  2888. state.raise("Invalid escape");
  2889. }
  2890. for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
  2891. var name = list[i];
  2892. if (state.groupNames.indexOf(name) === -1) {
  2893. state.raise("Invalid named capture referenced");
  2894. }
  2895. }
  2896. };
  2897. // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
  2898. pp$8.regexp_disjunction = function(state) {
  2899. this.regexp_alternative(state);
  2900. while (state.eat(0x7C /* | */)) {
  2901. this.regexp_alternative(state);
  2902. }
  2903. // Make the same message as V8.
  2904. if (this.regexp_eatQuantifier(state, true)) {
  2905. state.raise("Nothing to repeat");
  2906. }
  2907. if (state.eat(0x7B /* { */)) {
  2908. state.raise("Lone quantifier brackets");
  2909. }
  2910. };
  2911. // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
  2912. pp$8.regexp_alternative = function(state) {
  2913. while (state.pos < state.source.length && this.regexp_eatTerm(state))
  2914. { }
  2915. };
  2916. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
  2917. pp$8.regexp_eatTerm = function(state) {
  2918. if (this.regexp_eatAssertion(state)) {
  2919. // Handle `QuantifiableAssertion Quantifier` alternative.
  2920. // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
  2921. // is a QuantifiableAssertion.
  2922. if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
  2923. // Make the same message as V8.
  2924. if (state.switchU) {
  2925. state.raise("Invalid quantifier");
  2926. }
  2927. }
  2928. return true
  2929. }
  2930. if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
  2931. this.regexp_eatQuantifier(state);
  2932. return true
  2933. }
  2934. return false
  2935. };
  2936. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
  2937. pp$8.regexp_eatAssertion = function(state) {
  2938. var start = state.pos;
  2939. state.lastAssertionIsQuantifiable = false;
  2940. // ^, $
  2941. if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
  2942. return true
  2943. }
  2944. // \b \B
  2945. if (state.eat(0x5C /* \ */)) {
  2946. if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
  2947. return true
  2948. }
  2949. state.pos = start;
  2950. }
  2951. // Lookahead / Lookbehind
  2952. if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
  2953. var lookbehind = false;
  2954. if (this.options.ecmaVersion >= 9) {
  2955. lookbehind = state.eat(0x3C /* < */);
  2956. }
  2957. if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
  2958. this.regexp_disjunction(state);
  2959. if (!state.eat(0x29 /* ) */)) {
  2960. state.raise("Unterminated group");
  2961. }
  2962. state.lastAssertionIsQuantifiable = !lookbehind;
  2963. return true
  2964. }
  2965. }
  2966. state.pos = start;
  2967. return false
  2968. };
  2969. // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
  2970. pp$8.regexp_eatQuantifier = function(state, noError) {
  2971. if ( noError === void 0 ) noError = false;
  2972. if (this.regexp_eatQuantifierPrefix(state, noError)) {
  2973. state.eat(0x3F /* ? */);
  2974. return true
  2975. }
  2976. return false
  2977. };
  2978. // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
  2979. pp$8.regexp_eatQuantifierPrefix = function(state, noError) {
  2980. return (
  2981. state.eat(0x2A /* * */) ||
  2982. state.eat(0x2B /* + */) ||
  2983. state.eat(0x3F /* ? */) ||
  2984. this.regexp_eatBracedQuantifier(state, noError)
  2985. )
  2986. };
  2987. pp$8.regexp_eatBracedQuantifier = function(state, noError) {
  2988. var start = state.pos;
  2989. if (state.eat(0x7B /* { */)) {
  2990. var min = 0, max = -1;
  2991. if (this.regexp_eatDecimalDigits(state)) {
  2992. min = state.lastIntValue;
  2993. if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
  2994. max = state.lastIntValue;
  2995. }
  2996. if (state.eat(0x7D /* } */)) {
  2997. // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
  2998. if (max !== -1 && max < min && !noError) {
  2999. state.raise("numbers out of order in {} quantifier");
  3000. }
  3001. return true
  3002. }
  3003. }
  3004. if (state.switchU && !noError) {
  3005. state.raise("Incomplete quantifier");
  3006. }
  3007. state.pos = start;
  3008. }
  3009. return false
  3010. };
  3011. // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
  3012. pp$8.regexp_eatAtom = function(state) {
  3013. return (
  3014. this.regexp_eatPatternCharacters(state) ||
  3015. state.eat(0x2E /* . */) ||
  3016. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3017. this.regexp_eatCharacterClass(state) ||
  3018. this.regexp_eatUncapturingGroup(state) ||
  3019. this.regexp_eatCapturingGroup(state)
  3020. )
  3021. };
  3022. pp$8.regexp_eatReverseSolidusAtomEscape = function(state) {
  3023. var start = state.pos;
  3024. if (state.eat(0x5C /* \ */)) {
  3025. if (this.regexp_eatAtomEscape(state)) {
  3026. return true
  3027. }
  3028. state.pos = start;
  3029. }
  3030. return false
  3031. };
  3032. pp$8.regexp_eatUncapturingGroup = function(state) {
  3033. var start = state.pos;
  3034. if (state.eat(0x28 /* ( */)) {
  3035. if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
  3036. this.regexp_disjunction(state);
  3037. if (state.eat(0x29 /* ) */)) {
  3038. return true
  3039. }
  3040. state.raise("Unterminated group");
  3041. }
  3042. state.pos = start;
  3043. }
  3044. return false
  3045. };
  3046. pp$8.regexp_eatCapturingGroup = function(state) {
  3047. if (state.eat(0x28 /* ( */)) {
  3048. if (this.options.ecmaVersion >= 9) {
  3049. this.regexp_groupSpecifier(state);
  3050. } else if (state.current() === 0x3F /* ? */) {
  3051. state.raise("Invalid group");
  3052. }
  3053. this.regexp_disjunction(state);
  3054. if (state.eat(0x29 /* ) */)) {
  3055. state.numCapturingParens += 1;
  3056. return true
  3057. }
  3058. state.raise("Unterminated group");
  3059. }
  3060. return false
  3061. };
  3062. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
  3063. pp$8.regexp_eatExtendedAtom = function(state) {
  3064. return (
  3065. state.eat(0x2E /* . */) ||
  3066. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3067. this.regexp_eatCharacterClass(state) ||
  3068. this.regexp_eatUncapturingGroup(state) ||
  3069. this.regexp_eatCapturingGroup(state) ||
  3070. this.regexp_eatInvalidBracedQuantifier(state) ||
  3071. this.regexp_eatExtendedPatternCharacter(state)
  3072. )
  3073. };
  3074. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
  3075. pp$8.regexp_eatInvalidBracedQuantifier = function(state) {
  3076. if (this.regexp_eatBracedQuantifier(state, true)) {
  3077. state.raise("Nothing to repeat");
  3078. }
  3079. return false
  3080. };
  3081. // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
  3082. pp$8.regexp_eatSyntaxCharacter = function(state) {
  3083. var ch = state.current();
  3084. if (isSyntaxCharacter(ch)) {
  3085. state.lastIntValue = ch;
  3086. state.advance();
  3087. return true
  3088. }
  3089. return false
  3090. };
  3091. function isSyntaxCharacter(ch) {
  3092. return (
  3093. ch === 0x24 /* $ */ ||
  3094. ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
  3095. ch === 0x2E /* . */ ||
  3096. ch === 0x3F /* ? */ ||
  3097. ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
  3098. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  3099. )
  3100. }
  3101. // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
  3102. // But eat eager.
  3103. pp$8.regexp_eatPatternCharacters = function(state) {
  3104. var start = state.pos;
  3105. var ch = 0;
  3106. while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
  3107. state.advance();
  3108. }
  3109. return state.pos !== start
  3110. };
  3111. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
  3112. pp$8.regexp_eatExtendedPatternCharacter = function(state) {
  3113. var ch = state.current();
  3114. if (
  3115. ch !== -1 &&
  3116. ch !== 0x24 /* $ */ &&
  3117. !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
  3118. ch !== 0x2E /* . */ &&
  3119. ch !== 0x3F /* ? */ &&
  3120. ch !== 0x5B /* [ */ &&
  3121. ch !== 0x5E /* ^ */ &&
  3122. ch !== 0x7C /* | */
  3123. ) {
  3124. state.advance();
  3125. return true
  3126. }
  3127. return false
  3128. };
  3129. // GroupSpecifier[U] ::
  3130. // [empty]
  3131. // `?` GroupName[?U]
  3132. pp$8.regexp_groupSpecifier = function(state) {
  3133. if (state.eat(0x3F /* ? */)) {
  3134. if (this.regexp_eatGroupName(state)) {
  3135. if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
  3136. state.raise("Duplicate capture group name");
  3137. }
  3138. state.groupNames.push(state.lastStringValue);
  3139. return
  3140. }
  3141. state.raise("Invalid group");
  3142. }
  3143. };
  3144. // GroupName[U] ::
  3145. // `<` RegExpIdentifierName[?U] `>`
  3146. // Note: this updates `state.lastStringValue` property with the eaten name.
  3147. pp$8.regexp_eatGroupName = function(state) {
  3148. state.lastStringValue = "";
  3149. if (state.eat(0x3C /* < */)) {
  3150. if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
  3151. return true
  3152. }
  3153. state.raise("Invalid capture group name");
  3154. }
  3155. return false
  3156. };
  3157. // RegExpIdentifierName[U] ::
  3158. // RegExpIdentifierStart[?U]
  3159. // RegExpIdentifierName[?U] RegExpIdentifierPart[?U]
  3160. // Note: this updates `state.lastStringValue` property with the eaten name.
  3161. pp$8.regexp_eatRegExpIdentifierName = function(state) {
  3162. state.lastStringValue = "";
  3163. if (this.regexp_eatRegExpIdentifierStart(state)) {
  3164. state.lastStringValue += codePointToString(state.lastIntValue);
  3165. while (this.regexp_eatRegExpIdentifierPart(state)) {
  3166. state.lastStringValue += codePointToString(state.lastIntValue);
  3167. }
  3168. return true
  3169. }
  3170. return false
  3171. };
  3172. // RegExpIdentifierStart[U] ::
  3173. // UnicodeIDStart
  3174. // `$`
  3175. // `_`
  3176. // `\` RegExpUnicodeEscapeSequence[?U]
  3177. pp$8.regexp_eatRegExpIdentifierStart = function(state) {
  3178. var start = state.pos;
  3179. var ch = state.current();
  3180. state.advance();
  3181. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3182. ch = state.lastIntValue;
  3183. }
  3184. if (isRegExpIdentifierStart(ch)) {
  3185. state.lastIntValue = ch;
  3186. return true
  3187. }
  3188. state.pos = start;
  3189. return false
  3190. };
  3191. function isRegExpIdentifierStart(ch) {
  3192. return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
  3193. }
  3194. // RegExpIdentifierPart[U] ::
  3195. // UnicodeIDContinue
  3196. // `$`
  3197. // `_`
  3198. // `\` RegExpUnicodeEscapeSequence[?U]
  3199. // <ZWNJ>
  3200. // <ZWJ>
  3201. pp$8.regexp_eatRegExpIdentifierPart = function(state) {
  3202. var start = state.pos;
  3203. var ch = state.current();
  3204. state.advance();
  3205. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3206. ch = state.lastIntValue;
  3207. }
  3208. if (isRegExpIdentifierPart(ch)) {
  3209. state.lastIntValue = ch;
  3210. return true
  3211. }
  3212. state.pos = start;
  3213. return false
  3214. };
  3215. function isRegExpIdentifierPart(ch) {
  3216. return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
  3217. }
  3218. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
  3219. pp$8.regexp_eatAtomEscape = function(state) {
  3220. if (
  3221. this.regexp_eatBackReference(state) ||
  3222. this.regexp_eatCharacterClassEscape(state) ||
  3223. this.regexp_eatCharacterEscape(state) ||
  3224. (state.switchN && this.regexp_eatKGroupName(state))
  3225. ) {
  3226. return true
  3227. }
  3228. if (state.switchU) {
  3229. // Make the same message as V8.
  3230. if (state.current() === 0x63 /* c */) {
  3231. state.raise("Invalid unicode escape");
  3232. }
  3233. state.raise("Invalid escape");
  3234. }
  3235. return false
  3236. };
  3237. pp$8.regexp_eatBackReference = function(state) {
  3238. var start = state.pos;
  3239. if (this.regexp_eatDecimalEscape(state)) {
  3240. var n = state.lastIntValue;
  3241. if (state.switchU) {
  3242. // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
  3243. if (n > state.maxBackReference) {
  3244. state.maxBackReference = n;
  3245. }
  3246. return true
  3247. }
  3248. if (n <= state.numCapturingParens) {
  3249. return true
  3250. }
  3251. state.pos = start;
  3252. }
  3253. return false
  3254. };
  3255. pp$8.regexp_eatKGroupName = function(state) {
  3256. if (state.eat(0x6B /* k */)) {
  3257. if (this.regexp_eatGroupName(state)) {
  3258. state.backReferenceNames.push(state.lastStringValue);
  3259. return true
  3260. }
  3261. state.raise("Invalid named reference");
  3262. }
  3263. return false
  3264. };
  3265. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
  3266. pp$8.regexp_eatCharacterEscape = function(state) {
  3267. return (
  3268. this.regexp_eatControlEscape(state) ||
  3269. this.regexp_eatCControlLetter(state) ||
  3270. this.regexp_eatZero(state) ||
  3271. this.regexp_eatHexEscapeSequence(state) ||
  3272. this.regexp_eatRegExpUnicodeEscapeSequence(state) ||
  3273. (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
  3274. this.regexp_eatIdentityEscape(state)
  3275. )
  3276. };
  3277. pp$8.regexp_eatCControlLetter = function(state) {
  3278. var start = state.pos;
  3279. if (state.eat(0x63 /* c */)) {
  3280. if (this.regexp_eatControlLetter(state)) {
  3281. return true
  3282. }
  3283. state.pos = start;
  3284. }
  3285. return false
  3286. };
  3287. pp$8.regexp_eatZero = function(state) {
  3288. if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
  3289. state.lastIntValue = 0;
  3290. state.advance();
  3291. return true
  3292. }
  3293. return false
  3294. };
  3295. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
  3296. pp$8.regexp_eatControlEscape = function(state) {
  3297. var ch = state.current();
  3298. if (ch === 0x74 /* t */) {
  3299. state.lastIntValue = 0x09; /* \t */
  3300. state.advance();
  3301. return true
  3302. }
  3303. if (ch === 0x6E /* n */) {
  3304. state.lastIntValue = 0x0A; /* \n */
  3305. state.advance();
  3306. return true
  3307. }
  3308. if (ch === 0x76 /* v */) {
  3309. state.lastIntValue = 0x0B; /* \v */
  3310. state.advance();
  3311. return true
  3312. }
  3313. if (ch === 0x66 /* f */) {
  3314. state.lastIntValue = 0x0C; /* \f */
  3315. state.advance();
  3316. return true
  3317. }
  3318. if (ch === 0x72 /* r */) {
  3319. state.lastIntValue = 0x0D; /* \r */
  3320. state.advance();
  3321. return true
  3322. }
  3323. return false
  3324. };
  3325. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
  3326. pp$8.regexp_eatControlLetter = function(state) {
  3327. var ch = state.current();
  3328. if (isControlLetter(ch)) {
  3329. state.lastIntValue = ch % 0x20;
  3330. state.advance();
  3331. return true
  3332. }
  3333. return false
  3334. };
  3335. function isControlLetter(ch) {
  3336. return (
  3337. (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
  3338. (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
  3339. )
  3340. }
  3341. // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
  3342. pp$8.regexp_eatRegExpUnicodeEscapeSequence = function(state) {
  3343. var start = state.pos;
  3344. if (state.eat(0x75 /* u */)) {
  3345. if (this.regexp_eatFixedHexDigits(state, 4)) {
  3346. var lead = state.lastIntValue;
  3347. if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) {
  3348. var leadSurrogateEnd = state.pos;
  3349. if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
  3350. var trail = state.lastIntValue;
  3351. if (trail >= 0xDC00 && trail <= 0xDFFF) {
  3352. state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3353. return true
  3354. }
  3355. }
  3356. state.pos = leadSurrogateEnd;
  3357. state.lastIntValue = lead;
  3358. }
  3359. return true
  3360. }
  3361. if (
  3362. state.switchU &&
  3363. state.eat(0x7B /* { */) &&
  3364. this.regexp_eatHexDigits(state) &&
  3365. state.eat(0x7D /* } */) &&
  3366. isValidUnicode(state.lastIntValue)
  3367. ) {
  3368. return true
  3369. }
  3370. if (state.switchU) {
  3371. state.raise("Invalid unicode escape");
  3372. }
  3373. state.pos = start;
  3374. }
  3375. return false
  3376. };
  3377. function isValidUnicode(ch) {
  3378. return ch >= 0 && ch <= 0x10FFFF
  3379. }
  3380. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
  3381. pp$8.regexp_eatIdentityEscape = function(state) {
  3382. if (state.switchU) {
  3383. if (this.regexp_eatSyntaxCharacter(state)) {
  3384. return true
  3385. }
  3386. if (state.eat(0x2F /* / */)) {
  3387. state.lastIntValue = 0x2F; /* / */
  3388. return true
  3389. }
  3390. return false
  3391. }
  3392. var ch = state.current();
  3393. if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
  3394. state.lastIntValue = ch;
  3395. state.advance();
  3396. return true
  3397. }
  3398. return false
  3399. };
  3400. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
  3401. pp$8.regexp_eatDecimalEscape = function(state) {
  3402. state.lastIntValue = 0;
  3403. var ch = state.current();
  3404. if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
  3405. do {
  3406. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3407. state.advance();
  3408. } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
  3409. return true
  3410. }
  3411. return false
  3412. };
  3413. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
  3414. pp$8.regexp_eatCharacterClassEscape = function(state) {
  3415. var ch = state.current();
  3416. if (isCharacterClassEscape(ch)) {
  3417. state.lastIntValue = -1;
  3418. state.advance();
  3419. return true
  3420. }
  3421. if (
  3422. state.switchU &&
  3423. this.options.ecmaVersion >= 9 &&
  3424. (ch === 0x50 /* P */ || ch === 0x70 /* p */)
  3425. ) {
  3426. state.lastIntValue = -1;
  3427. state.advance();
  3428. if (
  3429. state.eat(0x7B /* { */) &&
  3430. this.regexp_eatUnicodePropertyValueExpression(state) &&
  3431. state.eat(0x7D /* } */)
  3432. ) {
  3433. return true
  3434. }
  3435. state.raise("Invalid property name");
  3436. }
  3437. return false
  3438. };
  3439. function isCharacterClassEscape(ch) {
  3440. return (
  3441. ch === 0x64 /* d */ ||
  3442. ch === 0x44 /* D */ ||
  3443. ch === 0x73 /* s */ ||
  3444. ch === 0x53 /* S */ ||
  3445. ch === 0x77 /* w */ ||
  3446. ch === 0x57 /* W */
  3447. )
  3448. }
  3449. // UnicodePropertyValueExpression ::
  3450. // UnicodePropertyName `=` UnicodePropertyValue
  3451. // LoneUnicodePropertyNameOrValue
  3452. pp$8.regexp_eatUnicodePropertyValueExpression = function(state) {
  3453. var start = state.pos;
  3454. // UnicodePropertyName `=` UnicodePropertyValue
  3455. if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
  3456. var name = state.lastStringValue;
  3457. if (this.regexp_eatUnicodePropertyValue(state)) {
  3458. var value = state.lastStringValue;
  3459. this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
  3460. return true
  3461. }
  3462. }
  3463. state.pos = start;
  3464. // LoneUnicodePropertyNameOrValue
  3465. if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
  3466. var nameOrValue = state.lastStringValue;
  3467. this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
  3468. return true
  3469. }
  3470. return false
  3471. };
  3472. pp$8.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
  3473. if (!has(state.unicodeProperties.nonBinary, name))
  3474. { state.raise("Invalid property name"); }
  3475. if (!state.unicodeProperties.nonBinary[name].test(value))
  3476. { state.raise("Invalid property value"); }
  3477. };
  3478. pp$8.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
  3479. if (!state.unicodeProperties.binary.test(nameOrValue))
  3480. { state.raise("Invalid property name"); }
  3481. };
  3482. // UnicodePropertyName ::
  3483. // UnicodePropertyNameCharacters
  3484. pp$8.regexp_eatUnicodePropertyName = function(state) {
  3485. var ch = 0;
  3486. state.lastStringValue = "";
  3487. while (isUnicodePropertyNameCharacter(ch = state.current())) {
  3488. state.lastStringValue += codePointToString(ch);
  3489. state.advance();
  3490. }
  3491. return state.lastStringValue !== ""
  3492. };
  3493. function isUnicodePropertyNameCharacter(ch) {
  3494. return isControlLetter(ch) || ch === 0x5F /* _ */
  3495. }
  3496. // UnicodePropertyValue ::
  3497. // UnicodePropertyValueCharacters
  3498. pp$8.regexp_eatUnicodePropertyValue = function(state) {
  3499. var ch = 0;
  3500. state.lastStringValue = "";
  3501. while (isUnicodePropertyValueCharacter(ch = state.current())) {
  3502. state.lastStringValue += codePointToString(ch);
  3503. state.advance();
  3504. }
  3505. return state.lastStringValue !== ""
  3506. };
  3507. function isUnicodePropertyValueCharacter(ch) {
  3508. return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
  3509. }
  3510. // LoneUnicodePropertyNameOrValue ::
  3511. // UnicodePropertyValueCharacters
  3512. pp$8.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
  3513. return this.regexp_eatUnicodePropertyValue(state)
  3514. };
  3515. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
  3516. pp$8.regexp_eatCharacterClass = function(state) {
  3517. if (state.eat(0x5B /* [ */)) {
  3518. state.eat(0x5E /* ^ */);
  3519. this.regexp_classRanges(state);
  3520. if (state.eat(0x5D /* [ */)) {
  3521. return true
  3522. }
  3523. // Unreachable since it threw "unterminated regular expression" error before.
  3524. state.raise("Unterminated character class");
  3525. }
  3526. return false
  3527. };
  3528. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
  3529. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
  3530. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
  3531. pp$8.regexp_classRanges = function(state) {
  3532. while (this.regexp_eatClassAtom(state)) {
  3533. var left = state.lastIntValue;
  3534. if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) {
  3535. var right = state.lastIntValue;
  3536. if (state.switchU && (left === -1 || right === -1)) {
  3537. state.raise("Invalid character class");
  3538. }
  3539. if (left !== -1 && right !== -1 && left > right) {
  3540. state.raise("Range out of order in character class");
  3541. }
  3542. }
  3543. }
  3544. };
  3545. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
  3546. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
  3547. pp$8.regexp_eatClassAtom = function(state) {
  3548. var start = state.pos;
  3549. if (state.eat(0x5C /* \ */)) {
  3550. if (this.regexp_eatClassEscape(state)) {
  3551. return true
  3552. }
  3553. if (state.switchU) {
  3554. // Make the same message as V8.
  3555. var ch$1 = state.current();
  3556. if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
  3557. state.raise("Invalid class escape");
  3558. }
  3559. state.raise("Invalid escape");
  3560. }
  3561. state.pos = start;
  3562. }
  3563. var ch = state.current();
  3564. if (ch !== 0x5D /* [ */) {
  3565. state.lastIntValue = ch;
  3566. state.advance();
  3567. return true
  3568. }
  3569. return false
  3570. };
  3571. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
  3572. pp$8.regexp_eatClassEscape = function(state) {
  3573. var start = state.pos;
  3574. if (state.eat(0x62 /* b */)) {
  3575. state.lastIntValue = 0x08; /* <BS> */
  3576. return true
  3577. }
  3578. if (state.switchU && state.eat(0x2D /* - */)) {
  3579. state.lastIntValue = 0x2D; /* - */
  3580. return true
  3581. }
  3582. if (!state.switchU && state.eat(0x63 /* c */)) {
  3583. if (this.regexp_eatClassControlLetter(state)) {
  3584. return true
  3585. }
  3586. state.pos = start;
  3587. }
  3588. return (
  3589. this.regexp_eatCharacterClassEscape(state) ||
  3590. this.regexp_eatCharacterEscape(state)
  3591. )
  3592. };
  3593. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
  3594. pp$8.regexp_eatClassControlLetter = function(state) {
  3595. var ch = state.current();
  3596. if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
  3597. state.lastIntValue = ch % 0x20;
  3598. state.advance();
  3599. return true
  3600. }
  3601. return false
  3602. };
  3603. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  3604. pp$8.regexp_eatHexEscapeSequence = function(state) {
  3605. var start = state.pos;
  3606. if (state.eat(0x78 /* x */)) {
  3607. if (this.regexp_eatFixedHexDigits(state, 2)) {
  3608. return true
  3609. }
  3610. if (state.switchU) {
  3611. state.raise("Invalid escape");
  3612. }
  3613. state.pos = start;
  3614. }
  3615. return false
  3616. };
  3617. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
  3618. pp$8.regexp_eatDecimalDigits = function(state) {
  3619. var start = state.pos;
  3620. var ch = 0;
  3621. state.lastIntValue = 0;
  3622. while (isDecimalDigit(ch = state.current())) {
  3623. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3624. state.advance();
  3625. }
  3626. return state.pos !== start
  3627. };
  3628. function isDecimalDigit(ch) {
  3629. return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
  3630. }
  3631. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
  3632. pp$8.regexp_eatHexDigits = function(state) {
  3633. var start = state.pos;
  3634. var ch = 0;
  3635. state.lastIntValue = 0;
  3636. while (isHexDigit(ch = state.current())) {
  3637. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  3638. state.advance();
  3639. }
  3640. return state.pos !== start
  3641. };
  3642. function isHexDigit(ch) {
  3643. return (
  3644. (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
  3645. (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
  3646. (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
  3647. )
  3648. }
  3649. function hexToInt(ch) {
  3650. if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
  3651. return 10 + (ch - 0x41 /* A */)
  3652. }
  3653. if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
  3654. return 10 + (ch - 0x61 /* a */)
  3655. }
  3656. return ch - 0x30 /* 0 */
  3657. }
  3658. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
  3659. // Allows only 0-377(octal) i.e. 0-255(decimal).
  3660. pp$8.regexp_eatLegacyOctalEscapeSequence = function(state) {
  3661. if (this.regexp_eatOctalDigit(state)) {
  3662. var n1 = state.lastIntValue;
  3663. if (this.regexp_eatOctalDigit(state)) {
  3664. var n2 = state.lastIntValue;
  3665. if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
  3666. state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
  3667. } else {
  3668. state.lastIntValue = n1 * 8 + n2;
  3669. }
  3670. } else {
  3671. state.lastIntValue = n1;
  3672. }
  3673. return true
  3674. }
  3675. return false
  3676. };
  3677. // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
  3678. pp$8.regexp_eatOctalDigit = function(state) {
  3679. var ch = state.current();
  3680. if (isOctalDigit(ch)) {
  3681. state.lastIntValue = ch - 0x30; /* 0 */
  3682. state.advance();
  3683. return true
  3684. }
  3685. state.lastIntValue = 0;
  3686. return false
  3687. };
  3688. function isOctalDigit(ch) {
  3689. return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
  3690. }
  3691. // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
  3692. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
  3693. // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  3694. pp$8.regexp_eatFixedHexDigits = function(state, length) {
  3695. var start = state.pos;
  3696. state.lastIntValue = 0;
  3697. for (var i = 0; i < length; ++i) {
  3698. var ch = state.current();
  3699. if (!isHexDigit(ch)) {
  3700. state.pos = start;
  3701. return false
  3702. }
  3703. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  3704. state.advance();
  3705. }
  3706. return true
  3707. };
  3708. // Object type used to represent tokens. Note that normally, tokens
  3709. // simply exist as properties on the parser object. This is only
  3710. // used for the onToken callback and the external tokenizer.
  3711. var Token = function Token(p) {
  3712. this.type = p.type;
  3713. this.value = p.value;
  3714. this.start = p.start;
  3715. this.end = p.end;
  3716. if (p.options.locations)
  3717. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  3718. if (p.options.ranges)
  3719. { this.range = [p.start, p.end]; }
  3720. };
  3721. // ## Tokenizer
  3722. var pp$9 = Parser.prototype;
  3723. // Move to the next token
  3724. pp$9.next = function() {
  3725. if (this.options.onToken)
  3726. { this.options.onToken(new Token(this)); }
  3727. this.lastTokEnd = this.end;
  3728. this.lastTokStart = this.start;
  3729. this.lastTokEndLoc = this.endLoc;
  3730. this.lastTokStartLoc = this.startLoc;
  3731. this.nextToken();
  3732. };
  3733. pp$9.getToken = function() {
  3734. this.next();
  3735. return new Token(this)
  3736. };
  3737. // If we're in an ES6 environment, make parsers iterable
  3738. if (typeof Symbol !== "undefined")
  3739. { pp$9[Symbol.iterator] = function() {
  3740. var this$1 = this;
  3741. return {
  3742. next: function () {
  3743. var token = this$1.getToken();
  3744. return {
  3745. done: token.type === types.eof,
  3746. value: token
  3747. }
  3748. }
  3749. }
  3750. }; }
  3751. // Toggle strict mode. Re-reads the next number or string to please
  3752. // pedantic tests (`"use strict"; 010;` should fail).
  3753. pp$9.curContext = function() {
  3754. return this.context[this.context.length - 1]
  3755. };
  3756. // Read a single token, updating the parser object's token-related
  3757. // properties.
  3758. pp$9.nextToken = function() {
  3759. var curContext = this.curContext();
  3760. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  3761. this.start = this.pos;
  3762. if (this.options.locations) { this.startLoc = this.curPosition(); }
  3763. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  3764. if (curContext.override) { return curContext.override(this) }
  3765. else { this.readToken(this.fullCharCodeAtPos()); }
  3766. };
  3767. pp$9.readToken = function(code) {
  3768. // Identifier or keyword. '\uXXXX' sequences are allowed in
  3769. // identifiers, so '\' also dispatches to that.
  3770. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  3771. { return this.readWord() }
  3772. return this.getTokenFromCode(code)
  3773. };
  3774. pp$9.fullCharCodeAtPos = function() {
  3775. var code = this.input.charCodeAt(this.pos);
  3776. if (code <= 0xd7ff || code >= 0xe000) { return code }
  3777. var next = this.input.charCodeAt(this.pos + 1);
  3778. return (code << 10) + next - 0x35fdc00
  3779. };
  3780. pp$9.skipBlockComment = function() {
  3781. var startLoc = this.options.onComment && this.curPosition();
  3782. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  3783. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  3784. this.pos = end + 2;
  3785. if (this.options.locations) {
  3786. lineBreakG.lastIndex = start;
  3787. var match;
  3788. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  3789. ++this.curLine;
  3790. this.lineStart = match.index + match[0].length;
  3791. }
  3792. }
  3793. if (this.options.onComment)
  3794. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  3795. startLoc, this.curPosition()); }
  3796. };
  3797. pp$9.skipLineComment = function(startSkip) {
  3798. var start = this.pos;
  3799. var startLoc = this.options.onComment && this.curPosition();
  3800. var ch = this.input.charCodeAt(this.pos += startSkip);
  3801. while (this.pos < this.input.length && !isNewLine(ch)) {
  3802. ch = this.input.charCodeAt(++this.pos);
  3803. }
  3804. if (this.options.onComment)
  3805. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  3806. startLoc, this.curPosition()); }
  3807. };
  3808. // Called at the start of the parse and after every token. Skips
  3809. // whitespace and comments, and.
  3810. pp$9.skipSpace = function() {
  3811. loop: while (this.pos < this.input.length) {
  3812. var ch = this.input.charCodeAt(this.pos);
  3813. switch (ch) {
  3814. case 32: case 160: // ' '
  3815. ++this.pos;
  3816. break
  3817. case 13:
  3818. if (this.input.charCodeAt(this.pos + 1) === 10) {
  3819. ++this.pos;
  3820. }
  3821. case 10: case 8232: case 8233:
  3822. ++this.pos;
  3823. if (this.options.locations) {
  3824. ++this.curLine;
  3825. this.lineStart = this.pos;
  3826. }
  3827. break
  3828. case 47: // '/'
  3829. switch (this.input.charCodeAt(this.pos + 1)) {
  3830. case 42: // '*'
  3831. this.skipBlockComment();
  3832. break
  3833. case 47:
  3834. this.skipLineComment(2);
  3835. break
  3836. default:
  3837. break loop
  3838. }
  3839. break
  3840. default:
  3841. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  3842. ++this.pos;
  3843. } else {
  3844. break loop
  3845. }
  3846. }
  3847. }
  3848. };
  3849. // Called at the end of every token. Sets `end`, `val`, and
  3850. // maintains `context` and `exprAllowed`, and skips the space after
  3851. // the token, so that the next one's `start` will point at the
  3852. // right position.
  3853. pp$9.finishToken = function(type, val) {
  3854. this.end = this.pos;
  3855. if (this.options.locations) { this.endLoc = this.curPosition(); }
  3856. var prevType = this.type;
  3857. this.type = type;
  3858. this.value = val;
  3859. this.updateContext(prevType);
  3860. };
  3861. // ### Token reading
  3862. // This is the function that is called to fetch the next token. It
  3863. // is somewhat obscure, because it works in character codes rather
  3864. // than characters, and because operator parsing has been inlined
  3865. // into it.
  3866. //
  3867. // All in the name of speed.
  3868. //
  3869. pp$9.readToken_dot = function() {
  3870. var next = this.input.charCodeAt(this.pos + 1);
  3871. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  3872. var next2 = this.input.charCodeAt(this.pos + 2);
  3873. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  3874. this.pos += 3;
  3875. return this.finishToken(types.ellipsis)
  3876. } else {
  3877. ++this.pos;
  3878. return this.finishToken(types.dot)
  3879. }
  3880. };
  3881. pp$9.readToken_slash = function() { // '/'
  3882. var next = this.input.charCodeAt(this.pos + 1);
  3883. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  3884. if (next === 61) { return this.finishOp(types.assign, 2) }
  3885. return this.finishOp(types.slash, 1)
  3886. };
  3887. pp$9.readToken_mult_modulo_exp = function(code) { // '%*'
  3888. var next = this.input.charCodeAt(this.pos + 1);
  3889. var size = 1;
  3890. var tokentype = code === 42 ? types.star : types.modulo;
  3891. // exponentiation operator ** and **=
  3892. if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
  3893. ++size;
  3894. tokentype = types.starstar;
  3895. next = this.input.charCodeAt(this.pos + 2);
  3896. }
  3897. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  3898. return this.finishOp(tokentype, size)
  3899. };
  3900. pp$9.readToken_pipe_amp = function(code) { // '|&'
  3901. var next = this.input.charCodeAt(this.pos + 1);
  3902. if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
  3903. if (next === 61) { return this.finishOp(types.assign, 2) }
  3904. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  3905. };
  3906. pp$9.readToken_caret = function() { // '^'
  3907. var next = this.input.charCodeAt(this.pos + 1);
  3908. if (next === 61) { return this.finishOp(types.assign, 2) }
  3909. return this.finishOp(types.bitwiseXOR, 1)
  3910. };
  3911. pp$9.readToken_plus_min = function(code) { // '+-'
  3912. var next = this.input.charCodeAt(this.pos + 1);
  3913. if (next === code) {
  3914. if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
  3915. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  3916. // A `-->` line comment
  3917. this.skipLineComment(3);
  3918. this.skipSpace();
  3919. return this.nextToken()
  3920. }
  3921. return this.finishOp(types.incDec, 2)
  3922. }
  3923. if (next === 61) { return this.finishOp(types.assign, 2) }
  3924. return this.finishOp(types.plusMin, 1)
  3925. };
  3926. pp$9.readToken_lt_gt = function(code) { // '<>'
  3927. var next = this.input.charCodeAt(this.pos + 1);
  3928. var size = 1;
  3929. if (next === code) {
  3930. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  3931. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  3932. return this.finishOp(types.bitShift, size)
  3933. }
  3934. if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
  3935. this.input.charCodeAt(this.pos + 3) === 45) {
  3936. // `<!--`, an XML-style comment that should be interpreted as a line comment
  3937. this.skipLineComment(4);
  3938. this.skipSpace();
  3939. return this.nextToken()
  3940. }
  3941. if (next === 61) { size = 2; }
  3942. return this.finishOp(types.relational, size)
  3943. };
  3944. pp$9.readToken_eq_excl = function(code) { // '=!'
  3945. var next = this.input.charCodeAt(this.pos + 1);
  3946. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  3947. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  3948. this.pos += 2;
  3949. return this.finishToken(types.arrow)
  3950. }
  3951. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  3952. };
  3953. pp$9.getTokenFromCode = function(code) {
  3954. switch (code) {
  3955. // The interpretation of a dot depends on whether it is followed
  3956. // by a digit or another two dots.
  3957. case 46: // '.'
  3958. return this.readToken_dot()
  3959. // Punctuation tokens.
  3960. case 40: ++this.pos; return this.finishToken(types.parenL)
  3961. case 41: ++this.pos; return this.finishToken(types.parenR)
  3962. case 59: ++this.pos; return this.finishToken(types.semi)
  3963. case 44: ++this.pos; return this.finishToken(types.comma)
  3964. case 91: ++this.pos; return this.finishToken(types.bracketL)
  3965. case 93: ++this.pos; return this.finishToken(types.bracketR)
  3966. case 123: ++this.pos; return this.finishToken(types.braceL)
  3967. case 125: ++this.pos; return this.finishToken(types.braceR)
  3968. case 58: ++this.pos; return this.finishToken(types.colon)
  3969. case 63: ++this.pos; return this.finishToken(types.question)
  3970. case 96: // '`'
  3971. if (this.options.ecmaVersion < 6) { break }
  3972. ++this.pos;
  3973. return this.finishToken(types.backQuote)
  3974. case 48: // '0'
  3975. var next = this.input.charCodeAt(this.pos + 1);
  3976. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  3977. if (this.options.ecmaVersion >= 6) {
  3978. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  3979. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  3980. }
  3981. // Anything else beginning with a digit is an integer, octal
  3982. // number, or float.
  3983. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  3984. return this.readNumber(false)
  3985. // Quotes produce strings.
  3986. case 34: case 39: // '"', "'"
  3987. return this.readString(code)
  3988. // Operators are parsed inline in tiny state machines. '=' (61) is
  3989. // often referred to. `finishOp` simply skips the amount of
  3990. // characters it is given as second argument, and returns a token
  3991. // of the type given by its first argument.
  3992. case 47: // '/'
  3993. return this.readToken_slash()
  3994. case 37: case 42: // '%*'
  3995. return this.readToken_mult_modulo_exp(code)
  3996. case 124: case 38: // '|&'
  3997. return this.readToken_pipe_amp(code)
  3998. case 94: // '^'
  3999. return this.readToken_caret()
  4000. case 43: case 45: // '+-'
  4001. return this.readToken_plus_min(code)
  4002. case 60: case 62: // '<>'
  4003. return this.readToken_lt_gt(code)
  4004. case 61: case 33: // '=!'
  4005. return this.readToken_eq_excl(code)
  4006. case 126: // '~'
  4007. return this.finishOp(types.prefix, 1)
  4008. }
  4009. this.raise(this.pos, "Unexpected character '" + codePointToString$1(code) + "'");
  4010. };
  4011. pp$9.finishOp = function(type, size) {
  4012. var str = this.input.slice(this.pos, this.pos + size);
  4013. this.pos += size;
  4014. return this.finishToken(type, str)
  4015. };
  4016. pp$9.readRegexp = function() {
  4017. var escaped, inClass, start = this.pos;
  4018. for (;;) {
  4019. if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
  4020. var ch = this.input.charAt(this.pos);
  4021. if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
  4022. if (!escaped) {
  4023. if (ch === "[") { inClass = true; }
  4024. else if (ch === "]" && inClass) { inClass = false; }
  4025. else if (ch === "/" && !inClass) { break }
  4026. escaped = ch === "\\";
  4027. } else { escaped = false; }
  4028. ++this.pos;
  4029. }
  4030. var pattern = this.input.slice(start, this.pos);
  4031. ++this.pos;
  4032. var flagsStart = this.pos;
  4033. var flags = this.readWord1();
  4034. if (this.containsEsc) { this.unexpected(flagsStart); }
  4035. // Validate pattern
  4036. var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
  4037. state.reset(start, pattern, flags);
  4038. this.validateRegExpFlags(state);
  4039. this.validateRegExpPattern(state);
  4040. // Create Literal#value property value.
  4041. var value = null;
  4042. try {
  4043. value = new RegExp(pattern, flags);
  4044. } catch (e) {
  4045. // ESTree requires null if it failed to instantiate RegExp object.
  4046. // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
  4047. }
  4048. return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
  4049. };
  4050. // Read an integer in the given radix. Return null if zero digits
  4051. // were read, the integer value otherwise. When `len` is given, this
  4052. // will return `null` unless the integer has exactly `len` digits.
  4053. pp$9.readInt = function(radix, len) {
  4054. var start = this.pos, total = 0;
  4055. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  4056. var code = this.input.charCodeAt(this.pos), val = (void 0);
  4057. if (code >= 97) { val = code - 97 + 10; } // a
  4058. else if (code >= 65) { val = code - 65 + 10; } // A
  4059. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  4060. else { val = Infinity; }
  4061. if (val >= radix) { break }
  4062. ++this.pos;
  4063. total = total * radix + val;
  4064. }
  4065. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  4066. return total
  4067. };
  4068. pp$9.readRadixNumber = function(radix) {
  4069. var start = this.pos;
  4070. this.pos += 2; // 0x
  4071. var val = this.readInt(radix);
  4072. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  4073. if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
  4074. val = typeof BigInt !== "undefined" ? BigInt(this.input.slice(start, this.pos)) : null;
  4075. ++this.pos;
  4076. } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4077. return this.finishToken(types.num, val)
  4078. };
  4079. // Read an integer, octal integer, or floating-point number.
  4080. pp$9.readNumber = function(startsWithDot) {
  4081. var start = this.pos;
  4082. if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4083. var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  4084. if (octal && this.strict) { this.raise(start, "Invalid number"); }
  4085. if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
  4086. var next = this.input.charCodeAt(this.pos);
  4087. if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
  4088. var str$1 = this.input.slice(start, this.pos);
  4089. var val$1 = typeof BigInt !== "undefined" ? BigInt(str$1) : null;
  4090. ++this.pos;
  4091. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4092. return this.finishToken(types.num, val$1)
  4093. }
  4094. if (next === 46 && !octal) { // '.'
  4095. ++this.pos;
  4096. this.readInt(10);
  4097. next = this.input.charCodeAt(this.pos);
  4098. }
  4099. if ((next === 69 || next === 101) && !octal) { // 'eE'
  4100. next = this.input.charCodeAt(++this.pos);
  4101. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  4102. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4103. }
  4104. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4105. var str = this.input.slice(start, this.pos);
  4106. var val = octal ? parseInt(str, 8) : parseFloat(str);
  4107. return this.finishToken(types.num, val)
  4108. };
  4109. // Read a string value, interpreting backslash-escapes.
  4110. pp$9.readCodePoint = function() {
  4111. var ch = this.input.charCodeAt(this.pos), code;
  4112. if (ch === 123) { // '{'
  4113. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  4114. var codePos = ++this.pos;
  4115. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  4116. ++this.pos;
  4117. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  4118. } else {
  4119. code = this.readHexChar(4);
  4120. }
  4121. return code
  4122. };
  4123. function codePointToString$1(code) {
  4124. // UTF-16 Decoding
  4125. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  4126. code -= 0x10000;
  4127. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  4128. }
  4129. pp$9.readString = function(quote) {
  4130. var out = "", chunkStart = ++this.pos;
  4131. for (;;) {
  4132. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
  4133. var ch = this.input.charCodeAt(this.pos);
  4134. if (ch === quote) { break }
  4135. if (ch === 92) { // '\'
  4136. out += this.input.slice(chunkStart, this.pos);
  4137. out += this.readEscapedChar(false);
  4138. chunkStart = this.pos;
  4139. } else {
  4140. if (isNewLine(ch, this.options.ecmaVersion >= 10)) { this.raise(this.start, "Unterminated string constant"); }
  4141. ++this.pos;
  4142. }
  4143. }
  4144. out += this.input.slice(chunkStart, this.pos++);
  4145. return this.finishToken(types.string, out)
  4146. };
  4147. // Reads template string tokens.
  4148. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  4149. pp$9.tryReadTemplateToken = function() {
  4150. this.inTemplateElement = true;
  4151. try {
  4152. this.readTmplToken();
  4153. } catch (err) {
  4154. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  4155. this.readInvalidTemplateToken();
  4156. } else {
  4157. throw err
  4158. }
  4159. }
  4160. this.inTemplateElement = false;
  4161. };
  4162. pp$9.invalidStringToken = function(position, message) {
  4163. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  4164. throw INVALID_TEMPLATE_ESCAPE_ERROR
  4165. } else {
  4166. this.raise(position, message);
  4167. }
  4168. };
  4169. pp$9.readTmplToken = function() {
  4170. var out = "", chunkStart = this.pos;
  4171. for (;;) {
  4172. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
  4173. var ch = this.input.charCodeAt(this.pos);
  4174. if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { // '`', '${'
  4175. if (this.pos === this.start && (this.type === types.template || this.type === types.invalidTemplate)) {
  4176. if (ch === 36) {
  4177. this.pos += 2;
  4178. return this.finishToken(types.dollarBraceL)
  4179. } else {
  4180. ++this.pos;
  4181. return this.finishToken(types.backQuote)
  4182. }
  4183. }
  4184. out += this.input.slice(chunkStart, this.pos);
  4185. return this.finishToken(types.template, out)
  4186. }
  4187. if (ch === 92) { // '\'
  4188. out += this.input.slice(chunkStart, this.pos);
  4189. out += this.readEscapedChar(true);
  4190. chunkStart = this.pos;
  4191. } else if (isNewLine(ch)) {
  4192. out += this.input.slice(chunkStart, this.pos);
  4193. ++this.pos;
  4194. switch (ch) {
  4195. case 13:
  4196. if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
  4197. case 10:
  4198. out += "\n";
  4199. break
  4200. default:
  4201. out += String.fromCharCode(ch);
  4202. break
  4203. }
  4204. if (this.options.locations) {
  4205. ++this.curLine;
  4206. this.lineStart = this.pos;
  4207. }
  4208. chunkStart = this.pos;
  4209. } else {
  4210. ++this.pos;
  4211. }
  4212. }
  4213. };
  4214. // Reads a template token to search for the end, without validating any escape sequences
  4215. pp$9.readInvalidTemplateToken = function() {
  4216. for (; this.pos < this.input.length; this.pos++) {
  4217. switch (this.input[this.pos]) {
  4218. case "\\":
  4219. ++this.pos;
  4220. break
  4221. case "$":
  4222. if (this.input[this.pos + 1] !== "{") {
  4223. break
  4224. }
  4225. // falls through
  4226. case "`":
  4227. return this.finishToken(types.invalidTemplate, this.input.slice(this.start, this.pos))
  4228. // no default
  4229. }
  4230. }
  4231. this.raise(this.start, "Unterminated template");
  4232. };
  4233. // Used to read escaped characters
  4234. pp$9.readEscapedChar = function(inTemplate) {
  4235. var ch = this.input.charCodeAt(++this.pos);
  4236. ++this.pos;
  4237. switch (ch) {
  4238. case 110: return "\n" // 'n' -> '\n'
  4239. case 114: return "\r" // 'r' -> '\r'
  4240. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  4241. case 117: return codePointToString$1(this.readCodePoint()) // 'u'
  4242. case 116: return "\t" // 't' -> '\t'
  4243. case 98: return "\b" // 'b' -> '\b'
  4244. case 118: return "\u000b" // 'v' -> '\u000b'
  4245. case 102: return "\f" // 'f' -> '\f'
  4246. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  4247. case 10: // ' \n'
  4248. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  4249. return ""
  4250. default:
  4251. if (ch >= 48 && ch <= 55) {
  4252. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  4253. var octal = parseInt(octalStr, 8);
  4254. if (octal > 255) {
  4255. octalStr = octalStr.slice(0, -1);
  4256. octal = parseInt(octalStr, 8);
  4257. }
  4258. this.pos += octalStr.length - 1;
  4259. ch = this.input.charCodeAt(this.pos);
  4260. if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
  4261. this.invalidStringToken(
  4262. this.pos - 1 - octalStr.length,
  4263. inTemplate
  4264. ? "Octal literal in template string"
  4265. : "Octal literal in strict mode"
  4266. );
  4267. }
  4268. return String.fromCharCode(octal)
  4269. }
  4270. if (isNewLine(ch)) {
  4271. // Unicode new line characters after \ get removed from output in both
  4272. // template literals and strings
  4273. return ""
  4274. }
  4275. return String.fromCharCode(ch)
  4276. }
  4277. };
  4278. // Used to read character escape sequences ('\x', '\u', '\U').
  4279. pp$9.readHexChar = function(len) {
  4280. var codePos = this.pos;
  4281. var n = this.readInt(16, len);
  4282. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  4283. return n
  4284. };
  4285. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  4286. // to whether the word contained a '\u' escape.
  4287. //
  4288. // Incrementally adds only escaped chars, adding other chunks as-is
  4289. // as a micro-optimization.
  4290. pp$9.readWord1 = function() {
  4291. this.containsEsc = false;
  4292. var word = "", first = true, chunkStart = this.pos;
  4293. var astral = this.options.ecmaVersion >= 6;
  4294. while (this.pos < this.input.length) {
  4295. var ch = this.fullCharCodeAtPos();
  4296. if (isIdentifierChar(ch, astral)) {
  4297. this.pos += ch <= 0xffff ? 1 : 2;
  4298. } else if (ch === 92) { // "\"
  4299. this.containsEsc = true;
  4300. word += this.input.slice(chunkStart, this.pos);
  4301. var escStart = this.pos;
  4302. if (this.input.charCodeAt(++this.pos) !== 117) // "u"
  4303. { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  4304. ++this.pos;
  4305. var esc = this.readCodePoint();
  4306. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  4307. { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
  4308. word += codePointToString$1(esc);
  4309. chunkStart = this.pos;
  4310. } else {
  4311. break
  4312. }
  4313. first = false;
  4314. }
  4315. return word + this.input.slice(chunkStart, this.pos)
  4316. };
  4317. // Read an identifier or keyword token. Will check for reserved
  4318. // words when necessary.
  4319. pp$9.readWord = function() {
  4320. var word = this.readWord1();
  4321. var type = types.name;
  4322. if (this.keywords.test(word)) {
  4323. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
  4324. type = keywords$1[word];
  4325. }
  4326. return this.finishToken(type, word)
  4327. };
  4328. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  4329. var version = "6.3.0";
  4330. // The main exported interface (under `self.acorn` when in the
  4331. // browser) is a `parse` function that takes a code string and
  4332. // returns an abstract syntax tree as specified by [Mozilla parser
  4333. // API][api].
  4334. //
  4335. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4336. function parse(input, options) {
  4337. return Parser.parse(input, options)
  4338. }
  4339. // This function tries to parse a single expression at a given
  4340. // offset in a string. Useful for parsing mixed-language formats
  4341. // that embed JavaScript expressions.
  4342. function parseExpressionAt(input, pos, options) {
  4343. return Parser.parseExpressionAt(input, pos, options)
  4344. }
  4345. // Acorn is organized as a tokenizer and a recursive-descent parser.
  4346. // The `tokenizer` export provides an interface to the tokenizer.
  4347. function tokenizer(input, options) {
  4348. return Parser.tokenizer(input, options)
  4349. }
  4350. exports.Node = Node;
  4351. exports.Parser = Parser;
  4352. exports.Position = Position;
  4353. exports.SourceLocation = SourceLocation;
  4354. exports.TokContext = TokContext;
  4355. exports.Token = Token;
  4356. exports.TokenType = TokenType;
  4357. exports.defaultOptions = defaultOptions;
  4358. exports.getLineInfo = getLineInfo;
  4359. exports.isIdentifierChar = isIdentifierChar;
  4360. exports.isIdentifierStart = isIdentifierStart;
  4361. exports.isNewLine = isNewLine;
  4362. exports.keywordTypes = keywords$1;
  4363. exports.lineBreak = lineBreak;
  4364. exports.lineBreakG = lineBreakG;
  4365. exports.nonASCIIwhitespace = nonASCIIwhitespace;
  4366. exports.parse = parse;
  4367. exports.parseExpressionAt = parseExpressionAt;
  4368. exports.tokContexts = types$1;
  4369. exports.tokTypes = types;
  4370. exports.tokenizer = tokenizer;
  4371. exports.version = version;
  4372. Object.defineProperty(exports, '__esModule', { value: true });
  4373. }));