acorn.mjs 214 KB

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