acorn.mjs 217 KB

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