acorn.js 233 KB

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