acorn.mjs 202 KB

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