acorn.js 213 KB

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