index.js 500 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. function _objectWithoutPropertiesLoose(r, e) {
  6. if (null == r) return {};
  7. var t = {};
  8. for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
  9. if (-1 !== e.indexOf(n)) continue;
  10. t[n] = r[n];
  11. }
  12. return t;
  13. }
  14. class Position {
  15. constructor(line, col, index) {
  16. this.line = void 0;
  17. this.column = void 0;
  18. this.index = void 0;
  19. this.line = line;
  20. this.column = col;
  21. this.index = index;
  22. }
  23. }
  24. class SourceLocation {
  25. constructor(start, end) {
  26. this.start = void 0;
  27. this.end = void 0;
  28. this.filename = void 0;
  29. this.identifierName = void 0;
  30. this.start = start;
  31. this.end = end;
  32. }
  33. }
  34. function createPositionWithColumnOffset(position, columnOffset) {
  35. const {
  36. line,
  37. column,
  38. index
  39. } = position;
  40. return new Position(line, column + columnOffset, index + columnOffset);
  41. }
  42. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  43. var ModuleErrors = {
  44. ImportMetaOutsideModule: {
  45. message: `import.meta may appear only with 'sourceType: "module"'`,
  46. code
  47. },
  48. ImportOutsideModule: {
  49. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  50. code
  51. }
  52. };
  53. const NodeDescriptions = {
  54. ArrayPattern: "array destructuring pattern",
  55. AssignmentExpression: "assignment expression",
  56. AssignmentPattern: "assignment expression",
  57. ArrowFunctionExpression: "arrow function expression",
  58. ConditionalExpression: "conditional expression",
  59. CatchClause: "catch clause",
  60. ForOfStatement: "for-of statement",
  61. ForInStatement: "for-in statement",
  62. ForStatement: "for-loop",
  63. FormalParameters: "function parameter list",
  64. Identifier: "identifier",
  65. ImportSpecifier: "import specifier",
  66. ImportDefaultSpecifier: "import default specifier",
  67. ImportNamespaceSpecifier: "import namespace specifier",
  68. ObjectPattern: "object destructuring pattern",
  69. ParenthesizedExpression: "parenthesized expression",
  70. RestElement: "rest element",
  71. UpdateExpression: {
  72. true: "prefix operation",
  73. false: "postfix operation"
  74. },
  75. VariableDeclarator: "variable declaration",
  76. YieldExpression: "yield expression"
  77. };
  78. const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type];
  79. var StandardErrors = {
  80. AccessorIsGenerator: ({
  81. kind
  82. }) => `A ${kind}ter cannot be a generator.`,
  83. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  84. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  85. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  86. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  87. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  88. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  89. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  90. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  91. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  92. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  93. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  94. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  95. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  96. ConstructorIsAsync: "Constructor can't be an async function.",
  97. ConstructorIsGenerator: "Constructor can't be a generator.",
  98. DeclarationMissingInitializer: ({
  99. kind
  100. }) => `Missing initializer in ${kind} declaration.`,
  101. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  102. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  103. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  104. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  105. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  106. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  107. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  108. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  109. DeletePrivateField: "Deleting a private field is not allowed.",
  110. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  111. DuplicateConstructor: "Duplicate constructor in the same class.",
  112. DuplicateDefaultExport: "Only one default export allowed per module.",
  113. DuplicateExport: ({
  114. exportName
  115. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  116. DuplicateProto: "Redefinition of __proto__ property.",
  117. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  118. ElementAfterRest: "Rest element must be last element.",
  119. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  120. ExportBindingIsString: ({
  121. localName,
  122. exportName
  123. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  124. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  125. ForInOfLoopInitializer: ({
  126. type
  127. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  128. ForInUsing: "For-in loop may not start with 'using' declaration.",
  129. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  130. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  131. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  132. IllegalBreakContinue: ({
  133. type
  134. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  135. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  136. IllegalReturn: "'return' outside of function.",
  137. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedImportAssert` parser plugin to suppress this error.",
  138. ImportBindingIsString: ({
  139. importName
  140. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  141. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  142. ImportCallNotNewExpression: "Cannot use new with import(...).",
  143. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  144. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  145. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  146. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  147. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  148. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  149. InvalidCodePoint: "Code point out of bounds.",
  150. InvalidCoverDiscardElement: "'void' must be followed by an expression when not used in a binding position.",
  151. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  152. InvalidDecimal: "Invalid decimal.",
  153. InvalidDigit: ({
  154. radix
  155. }) => `Expected number in radix ${radix}.`,
  156. InvalidEscapeSequence: "Bad character escape sequence.",
  157. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  158. InvalidEscapedReservedWord: ({
  159. reservedWord
  160. }) => `Escape sequence in keyword ${reservedWord}.`,
  161. InvalidIdentifier: ({
  162. identifierName
  163. }) => `Invalid identifier ${identifierName}.`,
  164. InvalidLhs: ({
  165. ancestor
  166. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  167. InvalidLhsBinding: ({
  168. ancestor
  169. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  170. InvalidLhsOptionalChaining: ({
  171. ancestor
  172. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  173. InvalidNumber: "Invalid number.",
  174. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  175. InvalidOrUnexpectedToken: ({
  176. unexpected
  177. }) => `Unexpected character '${unexpected}'.`,
  178. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  179. InvalidPrivateFieldResolution: ({
  180. identifierName
  181. }) => `Private name #${identifierName} is not defined.`,
  182. InvalidPropertyBindingPattern: "Binding member expression.",
  183. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  184. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  185. LabelRedeclaration: ({
  186. labelName
  187. }) => `Label '${labelName}' is already declared.`,
  188. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  189. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  190. MalformedRegExpFlags: "Invalid regular expression flag.",
  191. MissingClassName: "A class name is required.",
  192. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  193. MissingSemicolon: "Missing semicolon.",
  194. MissingPlugin: ({
  195. missingPlugin
  196. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  197. MissingOneOfPlugins: ({
  198. missingPlugin
  199. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  200. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  201. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  202. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  203. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  204. ModuleAttributesWithDuplicateKeys: ({
  205. key
  206. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  207. ModuleExportNameHasLoneSurrogate: ({
  208. surrogateCharCode
  209. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  210. ModuleExportUndefined: ({
  211. localName
  212. }) => `Export '${localName}' is not defined.`,
  213. MultipleDefaultsInSwitch: "Multiple default clauses.",
  214. NewlineAfterThrow: "Illegal newline after throw.",
  215. NoCatchOrFinally: "Missing catch or finally clause.",
  216. NumberIdentifier: "Identifier directly after number.",
  217. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  218. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  219. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  220. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  221. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  222. ParamDupe: "Argument name clash.",
  223. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  224. PatternHasMethod: "Object pattern can't contain methods.",
  225. PrivateInExpectedIn: ({
  226. identifierName
  227. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  228. PrivateNameRedeclaration: ({
  229. identifierName
  230. }) => `Duplicate private name #${identifierName}.`,
  231. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  232. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  233. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  234. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  235. RestTrailingComma: "Unexpected trailing comma after rest element.",
  236. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  237. SloppyFunctionAnnexB: "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement.",
  238. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  239. StaticPrototype: "Classes may not have static property named prototype.",
  240. SuperNotAllowed: "`super()` is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class?",
  241. SuperPrivateField: "Private fields can't be accessed on super.",
  242. TrailingDecorator: "Decorators must be attached to a class element.",
  243. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  244. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  245. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  246. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  247. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  248. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  249. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  250. UnexpectedKeyword: ({
  251. keyword
  252. }) => `Unexpected keyword '${keyword}'.`,
  253. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  254. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  255. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  256. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  257. UnexpectedPrivateField: "Unexpected private name.",
  258. UnexpectedReservedWord: ({
  259. reservedWord
  260. }) => `Unexpected reserved word '${reservedWord}'.`,
  261. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  262. UnexpectedToken: ({
  263. expected,
  264. unexpected
  265. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  266. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  267. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement.",
  268. UnexpectedVoidPattern: "Unexpected void binding.",
  269. UnsupportedBind: "Binding should be performed on object property.",
  270. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  271. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  272. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  273. UnsupportedMetaProperty: ({
  274. target,
  275. onlyValidPropertyName
  276. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  277. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  278. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  279. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  280. UnterminatedComment: "Unterminated comment.",
  281. UnterminatedRegExp: "Unterminated regular expression.",
  282. UnterminatedString: "Unterminated string constant.",
  283. UnterminatedTemplate: "Unterminated template.",
  284. UsingDeclarationExport: "Using declaration cannot be exported.",
  285. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  286. VarRedeclaration: ({
  287. identifierName
  288. }) => `Identifier '${identifierName}' has already been declared.`,
  289. VoidPatternCatchClauseParam: "A void binding can not be the catch clause parameter. Use `try { ... } catch { ... }` if you want to discard the caught error.",
  290. VoidPatternInitializer: "A void binding may not have an initializer.",
  291. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  292. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  293. YieldNotInGeneratorFunction: "'yield' is only allowed within generator functions.",
  294. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  295. };
  296. var StrictModeErrors = {
  297. StrictDelete: "Deleting local variable in strict mode.",
  298. StrictEvalArguments: ({
  299. referenceName
  300. }) => `Assigning to '${referenceName}' in strict mode.`,
  301. StrictEvalArgumentsBinding: ({
  302. bindingName
  303. }) => `Binding '${bindingName}' in strict mode.`,
  304. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  305. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  306. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  307. StrictWith: "'with' in strict mode."
  308. };
  309. var ParseExpressionErrors = {
  310. ParseExpressionEmptyInput: "Unexpected parseExpression() input: The input is empty or contains only comments.",
  311. ParseExpressionExpectsEOF: ({
  312. unexpected
  313. }) => `Unexpected parseExpression() input: The input should contain exactly one expression, but the first expression is followed by the unexpected character \`${String.fromCodePoint(unexpected)}\`.`
  314. };
  315. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  316. var PipelineOperatorErrors = Object.assign({
  317. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  318. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  319. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  320. PipeTopicUnconfiguredToken: ({
  321. token
  322. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  323. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  324. PipeUnparenthesizedBody: ({
  325. type
  326. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  327. type
  328. })}; please wrap it in parentheses.`
  329. }, {
  330. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  331. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  332. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  333. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  334. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  335. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  336. });
  337. const _excluded = ["message"];
  338. function defineHidden(obj, key, value) {
  339. Object.defineProperty(obj, key, {
  340. enumerable: false,
  341. configurable: true,
  342. value
  343. });
  344. }
  345. function toParseErrorConstructor({
  346. toMessage,
  347. code,
  348. reasonCode,
  349. syntaxPlugin
  350. }) {
  351. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  352. const oldReasonCodes = {
  353. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  354. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  355. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  356. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  357. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  358. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  359. };
  360. if (oldReasonCodes[reasonCode]) {
  361. reasonCode = oldReasonCodes[reasonCode];
  362. }
  363. return function constructor(loc, details) {
  364. const error = new SyntaxError();
  365. error.code = code;
  366. error.reasonCode = reasonCode;
  367. error.loc = loc;
  368. error.pos = loc.index;
  369. error.syntaxPlugin = syntaxPlugin;
  370. if (hasMissingPlugin) {
  371. error.missingPlugin = details.missingPlugin;
  372. }
  373. defineHidden(error, "clone", function clone(overrides = {}) {
  374. var _overrides$loc;
  375. const {
  376. line,
  377. column,
  378. index
  379. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  380. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  381. });
  382. defineHidden(error, "details", details);
  383. Object.defineProperty(error, "message", {
  384. configurable: true,
  385. get() {
  386. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  387. this.message = message;
  388. return message;
  389. },
  390. set(value) {
  391. Object.defineProperty(this, "message", {
  392. value,
  393. writable: true
  394. });
  395. }
  396. });
  397. return error;
  398. };
  399. }
  400. function ParseErrorEnum(argument, syntaxPlugin) {
  401. if (Array.isArray(argument)) {
  402. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  403. }
  404. const ParseErrorConstructors = {};
  405. for (const reasonCode of Object.keys(argument)) {
  406. const template = argument[reasonCode];
  407. const _ref = typeof template === "string" ? {
  408. message: () => template
  409. } : typeof template === "function" ? {
  410. message: template
  411. } : template,
  412. {
  413. message
  414. } = _ref,
  415. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  416. const toMessage = typeof message === "string" ? () => message : message;
  417. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  418. code: "BABEL_PARSER_SYNTAX_ERROR",
  419. reasonCode,
  420. toMessage
  421. }, syntaxPlugin ? {
  422. syntaxPlugin
  423. } : {}, rest));
  424. }
  425. return ParseErrorConstructors;
  426. }
  427. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum(ParseExpressionErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  428. function createDefaultOptions() {
  429. return {
  430. sourceType: "script",
  431. sourceFilename: undefined,
  432. startIndex: 0,
  433. startColumn: 0,
  434. startLine: 1,
  435. allowAwaitOutsideFunction: false,
  436. allowReturnOutsideFunction: false,
  437. allowNewTargetOutsideFunction: false,
  438. allowImportExportEverywhere: false,
  439. allowSuperOutsideMethod: false,
  440. allowUndeclaredExports: false,
  441. allowYieldOutsideFunction: false,
  442. plugins: [],
  443. strictMode: undefined,
  444. ranges: false,
  445. tokens: false,
  446. createImportExpressions: false,
  447. createParenthesizedExpressions: false,
  448. errorRecovery: false,
  449. attachComment: true,
  450. annexB: true
  451. };
  452. }
  453. function getOptions(opts) {
  454. const options = createDefaultOptions();
  455. if (opts == null) {
  456. return options;
  457. }
  458. if (opts.annexB != null && opts.annexB !== false) {
  459. throw new Error("The `annexB` option can only be set to `false`.");
  460. }
  461. for (const key of Object.keys(options)) {
  462. if (opts[key] != null) options[key] = opts[key];
  463. }
  464. if (options.startLine === 1) {
  465. if (opts.startIndex == null && options.startColumn > 0) {
  466. options.startIndex = options.startColumn;
  467. } else if (opts.startColumn == null && options.startIndex > 0) {
  468. options.startColumn = options.startIndex;
  469. }
  470. } else if (opts.startColumn == null || opts.startIndex == null) {
  471. if (opts.startIndex != null) {
  472. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  473. }
  474. }
  475. if (options.sourceType === "commonjs") {
  476. if (opts.allowAwaitOutsideFunction != null) {
  477. throw new Error("The `allowAwaitOutsideFunction` option cannot be used with `sourceType: 'commonjs'`.");
  478. }
  479. if (opts.allowReturnOutsideFunction != null) {
  480. throw new Error("`sourceType: 'commonjs'` implies `allowReturnOutsideFunction: true`, please remove the `allowReturnOutsideFunction` option or use `sourceType: 'script'`.");
  481. }
  482. if (opts.allowNewTargetOutsideFunction != null) {
  483. throw new Error("`sourceType: 'commonjs'` implies `allowNewTargetOutsideFunction: true`, please remove the `allowNewTargetOutsideFunction` option or use `sourceType: 'script'`.");
  484. }
  485. }
  486. return options;
  487. }
  488. const {
  489. defineProperty
  490. } = Object;
  491. const toUnenumerable = (object, key) => {
  492. if (object) {
  493. defineProperty(object, key, {
  494. enumerable: false,
  495. value: object[key]
  496. });
  497. }
  498. };
  499. function toESTreeLocation(node) {
  500. toUnenumerable(node.loc.start, "index");
  501. toUnenumerable(node.loc.end, "index");
  502. return node;
  503. }
  504. var estree = superClass => class ESTreeParserMixin extends superClass {
  505. parse() {
  506. const file = toESTreeLocation(super.parse());
  507. if (this.optionFlags & 256) {
  508. file.tokens = file.tokens.map(toESTreeLocation);
  509. }
  510. return file;
  511. }
  512. parseRegExpLiteral({
  513. pattern,
  514. flags
  515. }) {
  516. let regex = null;
  517. try {
  518. regex = new RegExp(pattern, flags);
  519. } catch (_) {}
  520. const node = this.estreeParseLiteral(regex);
  521. node.regex = {
  522. pattern,
  523. flags
  524. };
  525. return node;
  526. }
  527. parseBigIntLiteral(value) {
  528. let bigInt;
  529. try {
  530. bigInt = BigInt(value);
  531. } catch (_unused) {
  532. bigInt = null;
  533. }
  534. const node = this.estreeParseLiteral(bigInt);
  535. node.bigint = String(node.value || value);
  536. return node;
  537. }
  538. parseDecimalLiteral(value) {
  539. const decimal = null;
  540. const node = this.estreeParseLiteral(decimal);
  541. node.decimal = String(node.value || value);
  542. return node;
  543. }
  544. estreeParseLiteral(value) {
  545. return this.parseLiteral(value, "Literal");
  546. }
  547. parseStringLiteral(value) {
  548. return this.estreeParseLiteral(value);
  549. }
  550. parseNumericLiteral(value) {
  551. return this.estreeParseLiteral(value);
  552. }
  553. parseNullLiteral() {
  554. return this.estreeParseLiteral(null);
  555. }
  556. parseBooleanLiteral(value) {
  557. return this.estreeParseLiteral(value);
  558. }
  559. estreeParseChainExpression(node, endLoc) {
  560. const chain = this.startNodeAtNode(node);
  561. chain.expression = node;
  562. return this.finishNodeAt(chain, "ChainExpression", endLoc);
  563. }
  564. directiveToStmt(directive) {
  565. const expression = directive.value;
  566. delete directive.value;
  567. this.castNodeTo(expression, "Literal");
  568. expression.raw = expression.extra.raw;
  569. expression.value = expression.extra.expressionValue;
  570. const stmt = this.castNodeTo(directive, "ExpressionStatement");
  571. stmt.expression = expression;
  572. stmt.directive = expression.extra.rawValue;
  573. delete expression.extra;
  574. return stmt;
  575. }
  576. fillOptionalPropertiesForTSESLint(node) {}
  577. cloneEstreeStringLiteral(node) {
  578. const {
  579. start,
  580. end,
  581. loc,
  582. range,
  583. raw,
  584. value
  585. } = node;
  586. const cloned = Object.create(node.constructor.prototype);
  587. cloned.type = "Literal";
  588. cloned.start = start;
  589. cloned.end = end;
  590. cloned.loc = loc;
  591. cloned.range = range;
  592. cloned.raw = raw;
  593. cloned.value = value;
  594. return cloned;
  595. }
  596. initFunction(node, isAsync) {
  597. super.initFunction(node, isAsync);
  598. node.expression = false;
  599. }
  600. checkDeclaration(node) {
  601. if (node != null && this.isObjectProperty(node)) {
  602. this.checkDeclaration(node.value);
  603. } else {
  604. super.checkDeclaration(node);
  605. }
  606. }
  607. getObjectOrClassMethodParams(method) {
  608. return method.value.params;
  609. }
  610. isValidDirective(stmt) {
  611. var _stmt$expression$extr;
  612. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  613. }
  614. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  615. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  616. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  617. node.body = directiveStatements.concat(node.body);
  618. delete node.directives;
  619. }
  620. parsePrivateName() {
  621. const node = super.parsePrivateName();
  622. if (!this.getPluginOption("estree", "classFeatures")) {
  623. return node;
  624. }
  625. return this.convertPrivateNameToPrivateIdentifier(node);
  626. }
  627. convertPrivateNameToPrivateIdentifier(node) {
  628. const name = super.getPrivateNameSV(node);
  629. delete node.id;
  630. node.name = name;
  631. return this.castNodeTo(node, "PrivateIdentifier");
  632. }
  633. isPrivateName(node) {
  634. if (!this.getPluginOption("estree", "classFeatures")) {
  635. return super.isPrivateName(node);
  636. }
  637. return node.type === "PrivateIdentifier";
  638. }
  639. getPrivateNameSV(node) {
  640. if (!this.getPluginOption("estree", "classFeatures")) {
  641. return super.getPrivateNameSV(node);
  642. }
  643. return node.name;
  644. }
  645. parseLiteral(value, type) {
  646. const node = super.parseLiteral(value, type);
  647. node.raw = node.extra.raw;
  648. delete node.extra;
  649. return node;
  650. }
  651. parseFunctionBody(node, allowExpression, isMethod = false) {
  652. super.parseFunctionBody(node, allowExpression, isMethod);
  653. node.expression = node.body.type !== "BlockStatement";
  654. }
  655. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  656. let funcNode = this.startNode();
  657. funcNode.kind = node.kind;
  658. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  659. delete funcNode.kind;
  660. const {
  661. typeParameters
  662. } = node;
  663. if (typeParameters) {
  664. delete node.typeParameters;
  665. funcNode.typeParameters = typeParameters;
  666. this.resetStartLocationFromNode(funcNode, typeParameters);
  667. }
  668. const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
  669. node.value = valueNode;
  670. if (type === "ClassPrivateMethod") {
  671. node.computed = false;
  672. }
  673. if (type === "ObjectMethod") {
  674. if (node.kind === "method") {
  675. node.kind = "init";
  676. }
  677. node.shorthand = false;
  678. return this.finishNode(node, "Property");
  679. } else {
  680. return this.finishNode(node, "MethodDefinition");
  681. }
  682. }
  683. nameIsConstructor(key) {
  684. if (key.type === "Literal") return key.value === "constructor";
  685. return super.nameIsConstructor(key);
  686. }
  687. parseClassProperty(...args) {
  688. const propertyNode = super.parseClassProperty(...args);
  689. if (!this.getPluginOption("estree", "classFeatures")) {
  690. return propertyNode;
  691. }
  692. this.castNodeTo(propertyNode, "PropertyDefinition");
  693. return propertyNode;
  694. }
  695. parseClassPrivateProperty(...args) {
  696. const propertyNode = super.parseClassPrivateProperty(...args);
  697. if (!this.getPluginOption("estree", "classFeatures")) {
  698. return propertyNode;
  699. }
  700. this.castNodeTo(propertyNode, "PropertyDefinition");
  701. propertyNode.computed = false;
  702. return propertyNode;
  703. }
  704. parseClassAccessorProperty(node) {
  705. const accessorPropertyNode = super.parseClassAccessorProperty(node);
  706. if (!this.getPluginOption("estree", "classFeatures")) {
  707. return accessorPropertyNode;
  708. }
  709. if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
  710. delete accessorPropertyNode.abstract;
  711. this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
  712. } else {
  713. this.castNodeTo(accessorPropertyNode, "AccessorProperty");
  714. }
  715. return accessorPropertyNode;
  716. }
  717. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  718. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  719. if (node) {
  720. node.kind = "init";
  721. this.castNodeTo(node, "Property");
  722. }
  723. return node;
  724. }
  725. finishObjectProperty(node) {
  726. node.kind = "init";
  727. return this.finishNode(node, "Property");
  728. }
  729. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  730. return type === "Property" ? "value" : super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  731. }
  732. isAssignable(node, isBinding) {
  733. if (node != null && this.isObjectProperty(node)) {
  734. return this.isAssignable(node.value, isBinding);
  735. }
  736. return super.isAssignable(node, isBinding);
  737. }
  738. toAssignable(node, isLHS = false) {
  739. if (node != null && this.isObjectProperty(node)) {
  740. const {
  741. key,
  742. value
  743. } = node;
  744. if (this.isPrivateName(key)) {
  745. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  746. }
  747. this.toAssignable(value, isLHS);
  748. } else {
  749. super.toAssignable(node, isLHS);
  750. }
  751. }
  752. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  753. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  754. this.raise(Errors.PatternHasAccessor, prop.key);
  755. } else if (prop.type === "Property" && prop.method) {
  756. this.raise(Errors.PatternHasMethod, prop.key);
  757. } else {
  758. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  759. }
  760. }
  761. finishCallExpression(unfinished, optional) {
  762. const node = super.finishCallExpression(unfinished, optional);
  763. if (node.callee.type === "Import") {
  764. var _ref, _ref2;
  765. this.castNodeTo(node, "ImportExpression");
  766. node.source = node.arguments[0];
  767. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  768. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  769. delete node.arguments;
  770. delete node.callee;
  771. } else if (node.type === "OptionalCallExpression") {
  772. this.castNodeTo(node, "CallExpression");
  773. } else {
  774. node.optional = false;
  775. }
  776. return node;
  777. }
  778. toReferencedArguments(node) {
  779. if (node.type === "ImportExpression") {
  780. return;
  781. }
  782. super.toReferencedArguments(node);
  783. }
  784. parseExport(unfinished, decorators) {
  785. const exportStartLoc = this.state.lastTokStartLoc;
  786. const node = super.parseExport(unfinished, decorators);
  787. switch (node.type) {
  788. case "ExportAllDeclaration":
  789. node.exported = null;
  790. break;
  791. case "ExportNamedDeclaration":
  792. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  793. this.castNodeTo(node, "ExportAllDeclaration");
  794. node.exported = node.specifiers[0].exported;
  795. delete node.specifiers;
  796. }
  797. case "ExportDefaultDeclaration":
  798. {
  799. var _declaration$decorato;
  800. const {
  801. declaration
  802. } = node;
  803. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  804. this.resetStartLocation(node, exportStartLoc);
  805. }
  806. }
  807. break;
  808. }
  809. return node;
  810. }
  811. stopParseSubscript(base, state) {
  812. const node = super.stopParseSubscript(base, state);
  813. if (state.optionalChainMember) {
  814. return this.estreeParseChainExpression(node, base.loc.end);
  815. }
  816. return node;
  817. }
  818. parseMember(base, startLoc, state, computed, optional) {
  819. const node = super.parseMember(base, startLoc, state, computed, optional);
  820. if (node.type === "OptionalMemberExpression") {
  821. this.castNodeTo(node, "MemberExpression");
  822. } else {
  823. node.optional = false;
  824. }
  825. return node;
  826. }
  827. isOptionalMemberExpression(node) {
  828. if (node.type === "ChainExpression") {
  829. return node.expression.type === "MemberExpression";
  830. }
  831. return super.isOptionalMemberExpression(node);
  832. }
  833. hasPropertyAsPrivateName(node) {
  834. if (node.type === "ChainExpression") {
  835. node = node.expression;
  836. }
  837. return super.hasPropertyAsPrivateName(node);
  838. }
  839. isObjectProperty(node) {
  840. return node.type === "Property" && node.kind === "init" && !node.method;
  841. }
  842. isObjectMethod(node) {
  843. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  844. }
  845. castNodeTo(node, type) {
  846. const result = super.castNodeTo(node, type);
  847. this.fillOptionalPropertiesForTSESLint(result);
  848. return result;
  849. }
  850. cloneIdentifier(node) {
  851. const cloned = super.cloneIdentifier(node);
  852. this.fillOptionalPropertiesForTSESLint(cloned);
  853. return cloned;
  854. }
  855. cloneStringLiteral(node) {
  856. if (node.type === "Literal") {
  857. return this.cloneEstreeStringLiteral(node);
  858. }
  859. return super.cloneStringLiteral(node);
  860. }
  861. finishNodeAt(node, type, endLoc) {
  862. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  863. }
  864. finishNode(node, type) {
  865. const result = super.finishNode(node, type);
  866. this.fillOptionalPropertiesForTSESLint(result);
  867. return result;
  868. }
  869. resetStartLocation(node, startLoc) {
  870. super.resetStartLocation(node, startLoc);
  871. toESTreeLocation(node);
  872. }
  873. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  874. super.resetEndLocation(node, endLoc);
  875. toESTreeLocation(node);
  876. }
  877. };
  878. class TokContext {
  879. constructor(token, preserveSpace) {
  880. this.token = void 0;
  881. this.preserveSpace = void 0;
  882. this.token = token;
  883. this.preserveSpace = !!preserveSpace;
  884. }
  885. }
  886. const types = {
  887. brace: new TokContext("{"),
  888. j_oTag: new TokContext("<tag"),
  889. j_cTag: new TokContext("</tag"),
  890. j_expr: new TokContext("<tag>...</tag>", true)
  891. };
  892. types.template = new TokContext("`", true);
  893. const beforeExpr = true;
  894. const startsExpr = true;
  895. const isLoop = true;
  896. const isAssign = true;
  897. const prefix = true;
  898. const postfix = true;
  899. class ExportedTokenType {
  900. constructor(label, conf = {}) {
  901. this.label = void 0;
  902. this.keyword = void 0;
  903. this.beforeExpr = void 0;
  904. this.startsExpr = void 0;
  905. this.rightAssociative = void 0;
  906. this.isLoop = void 0;
  907. this.isAssign = void 0;
  908. this.prefix = void 0;
  909. this.postfix = void 0;
  910. this.binop = void 0;
  911. this.label = label;
  912. this.keyword = conf.keyword;
  913. this.beforeExpr = !!conf.beforeExpr;
  914. this.startsExpr = !!conf.startsExpr;
  915. this.rightAssociative = !!conf.rightAssociative;
  916. this.isLoop = !!conf.isLoop;
  917. this.isAssign = !!conf.isAssign;
  918. this.prefix = !!conf.prefix;
  919. this.postfix = !!conf.postfix;
  920. this.binop = conf.binop != null ? conf.binop : null;
  921. this.updateContext = null;
  922. }
  923. }
  924. const keywords$1 = new Map();
  925. function createKeyword(name, options = {}) {
  926. options.keyword = name;
  927. const token = createToken(name, options);
  928. keywords$1.set(name, token);
  929. return token;
  930. }
  931. function createBinop(name, binop) {
  932. return createToken(name, {
  933. beforeExpr,
  934. binop
  935. });
  936. }
  937. let tokenTypeCounter = -1;
  938. const tokenTypes = [];
  939. const tokenLabels = [];
  940. const tokenBinops = [];
  941. const tokenBeforeExprs = [];
  942. const tokenStartsExprs = [];
  943. const tokenPrefixes = [];
  944. function createToken(name, options = {}) {
  945. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  946. ++tokenTypeCounter;
  947. tokenLabels.push(name);
  948. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  949. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  950. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  951. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  952. tokenTypes.push(new ExportedTokenType(name, options));
  953. return tokenTypeCounter;
  954. }
  955. function createKeywordLike(name, options = {}) {
  956. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  957. ++tokenTypeCounter;
  958. keywords$1.set(name, tokenTypeCounter);
  959. tokenLabels.push(name);
  960. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  961. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  962. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  963. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  964. tokenTypes.push(new ExportedTokenType("name", options));
  965. return tokenTypeCounter;
  966. }
  967. const tt = {
  968. bracketL: createToken("[", {
  969. beforeExpr,
  970. startsExpr
  971. }),
  972. bracketHashL: createToken("#[", {
  973. beforeExpr,
  974. startsExpr
  975. }),
  976. bracketBarL: createToken("[|", {
  977. beforeExpr,
  978. startsExpr
  979. }),
  980. bracketR: createToken("]"),
  981. bracketBarR: createToken("|]"),
  982. braceL: createToken("{", {
  983. beforeExpr,
  984. startsExpr
  985. }),
  986. braceBarL: createToken("{|", {
  987. beforeExpr,
  988. startsExpr
  989. }),
  990. braceHashL: createToken("#{", {
  991. beforeExpr,
  992. startsExpr
  993. }),
  994. braceR: createToken("}"),
  995. braceBarR: createToken("|}"),
  996. parenL: createToken("(", {
  997. beforeExpr,
  998. startsExpr
  999. }),
  1000. parenR: createToken(")"),
  1001. comma: createToken(",", {
  1002. beforeExpr
  1003. }),
  1004. semi: createToken(";", {
  1005. beforeExpr
  1006. }),
  1007. colon: createToken(":", {
  1008. beforeExpr
  1009. }),
  1010. doubleColon: createToken("::", {
  1011. beforeExpr
  1012. }),
  1013. dot: createToken("."),
  1014. question: createToken("?", {
  1015. beforeExpr
  1016. }),
  1017. questionDot: createToken("?."),
  1018. arrow: createToken("=>", {
  1019. beforeExpr
  1020. }),
  1021. template: createToken("template"),
  1022. ellipsis: createToken("...", {
  1023. beforeExpr
  1024. }),
  1025. backQuote: createToken("`", {
  1026. startsExpr
  1027. }),
  1028. dollarBraceL: createToken("${", {
  1029. beforeExpr,
  1030. startsExpr
  1031. }),
  1032. templateTail: createToken("...`", {
  1033. startsExpr
  1034. }),
  1035. templateNonTail: createToken("...${", {
  1036. beforeExpr,
  1037. startsExpr
  1038. }),
  1039. at: createToken("@"),
  1040. hash: createToken("#", {
  1041. startsExpr
  1042. }),
  1043. interpreterDirective: createToken("#!..."),
  1044. eq: createToken("=", {
  1045. beforeExpr,
  1046. isAssign
  1047. }),
  1048. assign: createToken("_=", {
  1049. beforeExpr,
  1050. isAssign
  1051. }),
  1052. slashAssign: createToken("_=", {
  1053. beforeExpr,
  1054. isAssign
  1055. }),
  1056. xorAssign: createToken("_=", {
  1057. beforeExpr,
  1058. isAssign
  1059. }),
  1060. moduloAssign: createToken("_=", {
  1061. beforeExpr,
  1062. isAssign
  1063. }),
  1064. incDec: createToken("++/--", {
  1065. prefix,
  1066. postfix,
  1067. startsExpr
  1068. }),
  1069. bang: createToken("!", {
  1070. beforeExpr,
  1071. prefix,
  1072. startsExpr
  1073. }),
  1074. tilde: createToken("~", {
  1075. beforeExpr,
  1076. prefix,
  1077. startsExpr
  1078. }),
  1079. doubleCaret: createToken("^^", {
  1080. startsExpr
  1081. }),
  1082. doubleAt: createToken("@@", {
  1083. startsExpr
  1084. }),
  1085. pipeline: createBinop("|>", 0),
  1086. nullishCoalescing: createBinop("??", 1),
  1087. logicalOR: createBinop("||", 1),
  1088. logicalAND: createBinop("&&", 2),
  1089. bitwiseOR: createBinop("|", 3),
  1090. bitwiseXOR: createBinop("^", 4),
  1091. bitwiseAND: createBinop("&", 5),
  1092. equality: createBinop("==/!=/===/!==", 6),
  1093. lt: createBinop("</>/<=/>=", 7),
  1094. gt: createBinop("</>/<=/>=", 7),
  1095. relational: createBinop("</>/<=/>=", 7),
  1096. bitShift: createBinop("<</>>/>>>", 8),
  1097. bitShiftL: createBinop("<</>>/>>>", 8),
  1098. bitShiftR: createBinop("<</>>/>>>", 8),
  1099. plusMin: createToken("+/-", {
  1100. beforeExpr,
  1101. binop: 9,
  1102. prefix,
  1103. startsExpr
  1104. }),
  1105. modulo: createToken("%", {
  1106. binop: 10,
  1107. startsExpr
  1108. }),
  1109. star: createToken("*", {
  1110. binop: 10
  1111. }),
  1112. slash: createBinop("/", 10),
  1113. exponent: createToken("**", {
  1114. beforeExpr,
  1115. binop: 11,
  1116. rightAssociative: true
  1117. }),
  1118. _in: createKeyword("in", {
  1119. beforeExpr,
  1120. binop: 7
  1121. }),
  1122. _instanceof: createKeyword("instanceof", {
  1123. beforeExpr,
  1124. binop: 7
  1125. }),
  1126. _break: createKeyword("break"),
  1127. _case: createKeyword("case", {
  1128. beforeExpr
  1129. }),
  1130. _catch: createKeyword("catch"),
  1131. _continue: createKeyword("continue"),
  1132. _debugger: createKeyword("debugger"),
  1133. _default: createKeyword("default", {
  1134. beforeExpr
  1135. }),
  1136. _else: createKeyword("else", {
  1137. beforeExpr
  1138. }),
  1139. _finally: createKeyword("finally"),
  1140. _function: createKeyword("function", {
  1141. startsExpr
  1142. }),
  1143. _if: createKeyword("if"),
  1144. _return: createKeyword("return", {
  1145. beforeExpr
  1146. }),
  1147. _switch: createKeyword("switch"),
  1148. _throw: createKeyword("throw", {
  1149. beforeExpr,
  1150. prefix,
  1151. startsExpr
  1152. }),
  1153. _try: createKeyword("try"),
  1154. _var: createKeyword("var"),
  1155. _const: createKeyword("const"),
  1156. _with: createKeyword("with"),
  1157. _new: createKeyword("new", {
  1158. beforeExpr,
  1159. startsExpr
  1160. }),
  1161. _this: createKeyword("this", {
  1162. startsExpr
  1163. }),
  1164. _super: createKeyword("super", {
  1165. startsExpr
  1166. }),
  1167. _class: createKeyword("class", {
  1168. startsExpr
  1169. }),
  1170. _extends: createKeyword("extends", {
  1171. beforeExpr
  1172. }),
  1173. _export: createKeyword("export"),
  1174. _import: createKeyword("import", {
  1175. startsExpr
  1176. }),
  1177. _null: createKeyword("null", {
  1178. startsExpr
  1179. }),
  1180. _true: createKeyword("true", {
  1181. startsExpr
  1182. }),
  1183. _false: createKeyword("false", {
  1184. startsExpr
  1185. }),
  1186. _typeof: createKeyword("typeof", {
  1187. beforeExpr,
  1188. prefix,
  1189. startsExpr
  1190. }),
  1191. _void: createKeyword("void", {
  1192. beforeExpr,
  1193. prefix,
  1194. startsExpr
  1195. }),
  1196. _delete: createKeyword("delete", {
  1197. beforeExpr,
  1198. prefix,
  1199. startsExpr
  1200. }),
  1201. _do: createKeyword("do", {
  1202. isLoop,
  1203. beforeExpr
  1204. }),
  1205. _for: createKeyword("for", {
  1206. isLoop
  1207. }),
  1208. _while: createKeyword("while", {
  1209. isLoop
  1210. }),
  1211. _as: createKeywordLike("as", {
  1212. startsExpr
  1213. }),
  1214. _assert: createKeywordLike("assert", {
  1215. startsExpr
  1216. }),
  1217. _async: createKeywordLike("async", {
  1218. startsExpr
  1219. }),
  1220. _await: createKeywordLike("await", {
  1221. startsExpr
  1222. }),
  1223. _defer: createKeywordLike("defer", {
  1224. startsExpr
  1225. }),
  1226. _from: createKeywordLike("from", {
  1227. startsExpr
  1228. }),
  1229. _get: createKeywordLike("get", {
  1230. startsExpr
  1231. }),
  1232. _let: createKeywordLike("let", {
  1233. startsExpr
  1234. }),
  1235. _meta: createKeywordLike("meta", {
  1236. startsExpr
  1237. }),
  1238. _of: createKeywordLike("of", {
  1239. startsExpr
  1240. }),
  1241. _sent: createKeywordLike("sent", {
  1242. startsExpr
  1243. }),
  1244. _set: createKeywordLike("set", {
  1245. startsExpr
  1246. }),
  1247. _source: createKeywordLike("source", {
  1248. startsExpr
  1249. }),
  1250. _static: createKeywordLike("static", {
  1251. startsExpr
  1252. }),
  1253. _using: createKeywordLike("using", {
  1254. startsExpr
  1255. }),
  1256. _yield: createKeywordLike("yield", {
  1257. startsExpr
  1258. }),
  1259. _asserts: createKeywordLike("asserts", {
  1260. startsExpr
  1261. }),
  1262. _checks: createKeywordLike("checks", {
  1263. startsExpr
  1264. }),
  1265. _exports: createKeywordLike("exports", {
  1266. startsExpr
  1267. }),
  1268. _global: createKeywordLike("global", {
  1269. startsExpr
  1270. }),
  1271. _implements: createKeywordLike("implements", {
  1272. startsExpr
  1273. }),
  1274. _intrinsic: createKeywordLike("intrinsic", {
  1275. startsExpr
  1276. }),
  1277. _infer: createKeywordLike("infer", {
  1278. startsExpr
  1279. }),
  1280. _is: createKeywordLike("is", {
  1281. startsExpr
  1282. }),
  1283. _mixins: createKeywordLike("mixins", {
  1284. startsExpr
  1285. }),
  1286. _proto: createKeywordLike("proto", {
  1287. startsExpr
  1288. }),
  1289. _require: createKeywordLike("require", {
  1290. startsExpr
  1291. }),
  1292. _satisfies: createKeywordLike("satisfies", {
  1293. startsExpr
  1294. }),
  1295. _keyof: createKeywordLike("keyof", {
  1296. startsExpr
  1297. }),
  1298. _readonly: createKeywordLike("readonly", {
  1299. startsExpr
  1300. }),
  1301. _unique: createKeywordLike("unique", {
  1302. startsExpr
  1303. }),
  1304. _abstract: createKeywordLike("abstract", {
  1305. startsExpr
  1306. }),
  1307. _declare: createKeywordLike("declare", {
  1308. startsExpr
  1309. }),
  1310. _enum: createKeywordLike("enum", {
  1311. startsExpr
  1312. }),
  1313. _module: createKeywordLike("module", {
  1314. startsExpr
  1315. }),
  1316. _namespace: createKeywordLike("namespace", {
  1317. startsExpr
  1318. }),
  1319. _interface: createKeywordLike("interface", {
  1320. startsExpr
  1321. }),
  1322. _type: createKeywordLike("type", {
  1323. startsExpr
  1324. }),
  1325. _opaque: createKeywordLike("opaque", {
  1326. startsExpr
  1327. }),
  1328. name: createToken("name", {
  1329. startsExpr
  1330. }),
  1331. placeholder: createToken("%%", {
  1332. startsExpr
  1333. }),
  1334. string: createToken("string", {
  1335. startsExpr
  1336. }),
  1337. num: createToken("num", {
  1338. startsExpr
  1339. }),
  1340. bigint: createToken("bigint", {
  1341. startsExpr
  1342. }),
  1343. decimal: createToken("decimal", {
  1344. startsExpr
  1345. }),
  1346. regexp: createToken("regexp", {
  1347. startsExpr
  1348. }),
  1349. privateName: createToken("#name", {
  1350. startsExpr
  1351. }),
  1352. eof: createToken("eof"),
  1353. jsxName: createToken("jsxName"),
  1354. jsxText: createToken("jsxText", {
  1355. beforeExpr
  1356. }),
  1357. jsxTagStart: createToken("jsxTagStart", {
  1358. startsExpr
  1359. }),
  1360. jsxTagEnd: createToken("jsxTagEnd")
  1361. };
  1362. function tokenIsIdentifier(token) {
  1363. return token >= 93 && token <= 133;
  1364. }
  1365. function tokenKeywordOrIdentifierIsKeyword(token) {
  1366. return token <= 92;
  1367. }
  1368. function tokenIsKeywordOrIdentifier(token) {
  1369. return token >= 58 && token <= 133;
  1370. }
  1371. function tokenIsLiteralPropertyName(token) {
  1372. return token >= 58 && token <= 137;
  1373. }
  1374. function tokenComesBeforeExpression(token) {
  1375. return tokenBeforeExprs[token];
  1376. }
  1377. function tokenCanStartExpression(token) {
  1378. return tokenStartsExprs[token];
  1379. }
  1380. function tokenIsAssignment(token) {
  1381. return token >= 29 && token <= 33;
  1382. }
  1383. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1384. return token >= 129 && token <= 131;
  1385. }
  1386. function tokenIsLoop(token) {
  1387. return token >= 90 && token <= 92;
  1388. }
  1389. function tokenIsKeyword(token) {
  1390. return token >= 58 && token <= 92;
  1391. }
  1392. function tokenIsOperator(token) {
  1393. return token >= 39 && token <= 59;
  1394. }
  1395. function tokenIsPostfix(token) {
  1396. return token === 34;
  1397. }
  1398. function tokenIsPrefix(token) {
  1399. return tokenPrefixes[token];
  1400. }
  1401. function tokenIsTSTypeOperator(token) {
  1402. return token >= 121 && token <= 123;
  1403. }
  1404. function tokenIsTSDeclarationStart(token) {
  1405. return token >= 124 && token <= 130;
  1406. }
  1407. function tokenLabelName(token) {
  1408. return tokenLabels[token];
  1409. }
  1410. function tokenOperatorPrecedence(token) {
  1411. return tokenBinops[token];
  1412. }
  1413. function tokenIsRightAssociative(token) {
  1414. return token === 57;
  1415. }
  1416. function tokenIsTemplate(token) {
  1417. return token >= 24 && token <= 25;
  1418. }
  1419. function getExportedToken(token) {
  1420. return tokenTypes[token];
  1421. }
  1422. tokenTypes[8].updateContext = context => {
  1423. context.pop();
  1424. };
  1425. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1426. context.push(types.brace);
  1427. };
  1428. tokenTypes[22].updateContext = context => {
  1429. if (context[context.length - 1] === types.template) {
  1430. context.pop();
  1431. } else {
  1432. context.push(types.template);
  1433. }
  1434. };
  1435. tokenTypes[143].updateContext = context => {
  1436. context.push(types.j_expr, types.j_oTag);
  1437. };
  1438. let 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-\u088f\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\u0c5c\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdc-\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7dc\ua7f1-\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";
  1439. let nonASCIIidentifierChars = "\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1add\u1ae0-\u1aeb\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
  1440. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1441. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1442. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1443. const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 7, 25, 39, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 57, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 261, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 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, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489];
  1444. const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 78, 5, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1445. function isInAstralSet(code, set) {
  1446. let pos = 0x10000;
  1447. for (let i = 0, length = set.length; i < length; i += 2) {
  1448. pos += set[i];
  1449. if (pos > code) return false;
  1450. pos += set[i + 1];
  1451. if (pos >= code) return true;
  1452. }
  1453. return false;
  1454. }
  1455. function isIdentifierStart(code) {
  1456. if (code < 65) return code === 36;
  1457. if (code <= 90) return true;
  1458. if (code < 97) return code === 95;
  1459. if (code <= 122) return true;
  1460. if (code <= 0xffff) {
  1461. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1462. }
  1463. return isInAstralSet(code, astralIdentifierStartCodes);
  1464. }
  1465. function isIdentifierChar(code) {
  1466. if (code < 48) return code === 36;
  1467. if (code < 58) return true;
  1468. if (code < 65) return false;
  1469. if (code <= 90) return true;
  1470. if (code < 97) return code === 95;
  1471. if (code <= 122) return true;
  1472. if (code <= 0xffff) {
  1473. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1474. }
  1475. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1476. }
  1477. const reservedWords = {
  1478. keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
  1479. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1480. strictBind: ["eval", "arguments"]
  1481. };
  1482. const keywords = new Set(reservedWords.keyword);
  1483. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1484. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1485. function isReservedWord(word, inModule) {
  1486. return inModule && word === "await" || word === "enum";
  1487. }
  1488. function isStrictReservedWord(word, inModule) {
  1489. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1490. }
  1491. function isStrictBindOnlyReservedWord(word) {
  1492. return reservedWordsStrictBindSet.has(word);
  1493. }
  1494. function isStrictBindReservedWord(word, inModule) {
  1495. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1496. }
  1497. function isKeyword(word) {
  1498. return keywords.has(word);
  1499. }
  1500. function isIteratorStart(current, next, next2) {
  1501. return current === 64 && next === 64 && isIdentifierStart(next2);
  1502. }
  1503. const reservedWordLikeSet = new Set(["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete", "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield", "eval", "arguments", "enum", "await"]);
  1504. function canBeReservedWord(word) {
  1505. return reservedWordLikeSet.has(word);
  1506. }
  1507. class Scope {
  1508. constructor(flags) {
  1509. this.flags = 0;
  1510. this.names = new Map();
  1511. this.firstLexicalName = "";
  1512. this.flags = flags;
  1513. }
  1514. }
  1515. class ScopeHandler {
  1516. constructor(parser, inModule) {
  1517. this.parser = void 0;
  1518. this.scopeStack = [];
  1519. this.inModule = void 0;
  1520. this.undefinedExports = new Map();
  1521. this.parser = parser;
  1522. this.inModule = inModule;
  1523. }
  1524. get inTopLevel() {
  1525. return (this.currentScope().flags & 1) > 0;
  1526. }
  1527. get inFunction() {
  1528. return (this.currentVarScopeFlags() & 2) > 0;
  1529. }
  1530. get allowSuper() {
  1531. return (this.currentThisScopeFlags() & 16) > 0;
  1532. }
  1533. get allowDirectSuper() {
  1534. return (this.currentThisScopeFlags() & 32) > 0;
  1535. }
  1536. get allowNewTarget() {
  1537. return (this.currentThisScopeFlags() & 512) > 0;
  1538. }
  1539. get inClass() {
  1540. return (this.currentThisScopeFlags() & 64) > 0;
  1541. }
  1542. get inClassAndNotInNonArrowFunction() {
  1543. const flags = this.currentThisScopeFlags();
  1544. return (flags & 64) > 0 && (flags & 2) === 0;
  1545. }
  1546. get inStaticBlock() {
  1547. for (let i = this.scopeStack.length - 1;; i--) {
  1548. const {
  1549. flags
  1550. } = this.scopeStack[i];
  1551. if (flags & 128) {
  1552. return true;
  1553. }
  1554. if (flags & (1667 | 64)) {
  1555. return false;
  1556. }
  1557. }
  1558. }
  1559. get inNonArrowFunction() {
  1560. return (this.currentThisScopeFlags() & 2) > 0;
  1561. }
  1562. get inBareCaseStatement() {
  1563. return (this.currentScope().flags & 256) > 0;
  1564. }
  1565. get treatFunctionsAsVar() {
  1566. return this.treatFunctionsAsVarInScope(this.currentScope());
  1567. }
  1568. createScope(flags) {
  1569. return new Scope(flags);
  1570. }
  1571. enter(flags) {
  1572. this.scopeStack.push(this.createScope(flags));
  1573. }
  1574. exit() {
  1575. const scope = this.scopeStack.pop();
  1576. return scope.flags;
  1577. }
  1578. treatFunctionsAsVarInScope(scope) {
  1579. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1580. }
  1581. declareName(name, bindingType, loc) {
  1582. let scope = this.currentScope();
  1583. if (bindingType & 8 || bindingType & 16) {
  1584. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1585. let type = scope.names.get(name) || 0;
  1586. if (bindingType & 16) {
  1587. type = type | 4;
  1588. } else {
  1589. if (!scope.firstLexicalName) {
  1590. scope.firstLexicalName = name;
  1591. }
  1592. type = type | 2;
  1593. }
  1594. scope.names.set(name, type);
  1595. if (bindingType & 8) {
  1596. this.maybeExportDefined(scope, name);
  1597. }
  1598. } else if (bindingType & 4) {
  1599. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1600. scope = this.scopeStack[i];
  1601. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1602. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1603. this.maybeExportDefined(scope, name);
  1604. if (scope.flags & 1667) break;
  1605. }
  1606. }
  1607. if (this.parser.inModule && scope.flags & 1) {
  1608. this.undefinedExports.delete(name);
  1609. }
  1610. }
  1611. maybeExportDefined(scope, name) {
  1612. if (this.parser.inModule && scope.flags & 1) {
  1613. this.undefinedExports.delete(name);
  1614. }
  1615. }
  1616. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1617. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1618. this.parser.raise(Errors.VarRedeclaration, loc, {
  1619. identifierName: name
  1620. });
  1621. }
  1622. }
  1623. isRedeclaredInScope(scope, name, bindingType) {
  1624. if (!(bindingType & 1)) return false;
  1625. if (bindingType & 8) {
  1626. return scope.names.has(name);
  1627. }
  1628. const type = scope.names.get(name) || 0;
  1629. if (bindingType & 16) {
  1630. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1631. }
  1632. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1633. }
  1634. checkLocalExport(id) {
  1635. const {
  1636. name
  1637. } = id;
  1638. const topLevelScope = this.scopeStack[0];
  1639. if (!topLevelScope.names.has(name)) {
  1640. this.undefinedExports.set(name, id.loc.start);
  1641. }
  1642. }
  1643. currentScope() {
  1644. return this.scopeStack[this.scopeStack.length - 1];
  1645. }
  1646. currentVarScopeFlags() {
  1647. for (let i = this.scopeStack.length - 1;; i--) {
  1648. const {
  1649. flags
  1650. } = this.scopeStack[i];
  1651. if (flags & 1667) {
  1652. return flags;
  1653. }
  1654. }
  1655. }
  1656. currentThisScopeFlags() {
  1657. for (let i = this.scopeStack.length - 1;; i--) {
  1658. const {
  1659. flags
  1660. } = this.scopeStack[i];
  1661. if (flags & (1667 | 64) && !(flags & 4)) {
  1662. return flags;
  1663. }
  1664. }
  1665. }
  1666. }
  1667. class FlowScope extends Scope {
  1668. constructor(...args) {
  1669. super(...args);
  1670. this.declareFunctions = new Set();
  1671. }
  1672. }
  1673. class FlowScopeHandler extends ScopeHandler {
  1674. createScope(flags) {
  1675. return new FlowScope(flags);
  1676. }
  1677. declareName(name, bindingType, loc) {
  1678. const scope = this.currentScope();
  1679. if (bindingType & 2048) {
  1680. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1681. this.maybeExportDefined(scope, name);
  1682. scope.declareFunctions.add(name);
  1683. return;
  1684. }
  1685. super.declareName(name, bindingType, loc);
  1686. }
  1687. isRedeclaredInScope(scope, name, bindingType) {
  1688. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1689. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1690. const type = scope.names.get(name);
  1691. return (type & 4) > 0 || (type & 2) > 0;
  1692. }
  1693. return false;
  1694. }
  1695. checkLocalExport(id) {
  1696. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1697. super.checkLocalExport(id);
  1698. }
  1699. }
  1700. }
  1701. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  1702. const FlowErrors = ParseErrorEnum`flow`({
  1703. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  1704. AmbiguousDeclareModuleKind: "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module.",
  1705. AssignReservedType: ({
  1706. reservedType
  1707. }) => `Cannot overwrite reserved type ${reservedType}.`,
  1708. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  1709. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  1710. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  1711. EnumBooleanMemberNotInitialized: ({
  1712. memberName,
  1713. enumName
  1714. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  1715. EnumDuplicateMemberName: ({
  1716. memberName,
  1717. enumName
  1718. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  1719. EnumInconsistentMemberValues: ({
  1720. enumName
  1721. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  1722. EnumInvalidExplicitType: ({
  1723. invalidEnumType,
  1724. enumName
  1725. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1726. EnumInvalidExplicitTypeUnknownSupplied: ({
  1727. enumName
  1728. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1729. EnumInvalidMemberInitializerPrimaryType: ({
  1730. enumName,
  1731. memberName,
  1732. explicitType
  1733. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  1734. EnumInvalidMemberInitializerSymbolType: ({
  1735. enumName,
  1736. memberName
  1737. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  1738. EnumInvalidMemberInitializerUnknownType: ({
  1739. enumName,
  1740. memberName
  1741. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  1742. EnumInvalidMemberName: ({
  1743. enumName,
  1744. memberName,
  1745. suggestion
  1746. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  1747. EnumNumberMemberNotInitialized: ({
  1748. enumName,
  1749. memberName
  1750. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  1751. EnumStringMemberInconsistentlyInitialized: ({
  1752. enumName
  1753. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  1754. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  1755. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  1756. ImportTypeShorthandOnlyInPureImport: "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements.",
  1757. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  1758. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  1759. InexactVariance: "Explicit inexact syntax cannot have variance.",
  1760. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  1761. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  1762. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  1763. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  1764. PatternIsOptional: Object.assign({
  1765. message: "A binding pattern parameter cannot be optional in an implementation signature."
  1766. }, {
  1767. reasonCode: "OptionalBindingPattern"
  1768. }),
  1769. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  1770. SpreadVariance: "Spread properties cannot have variance.",
  1771. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  1772. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  1773. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  1774. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  1775. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  1776. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  1777. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  1778. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  1779. UnexpectedReservedType: ({
  1780. reservedType
  1781. }) => `Unexpected reserved type ${reservedType}.`,
  1782. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  1783. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  1784. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  1785. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  1786. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  1787. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  1788. UnsupportedDeclareExportKind: ({
  1789. unsupportedExportKind,
  1790. suggestion
  1791. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  1792. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  1793. UnterminatedFlowComment: "Unterminated flow-comment."
  1794. });
  1795. function isEsModuleType(bodyElement) {
  1796. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  1797. }
  1798. function hasTypeImportKind(node) {
  1799. return node.importKind === "type" || node.importKind === "typeof";
  1800. }
  1801. const exportSuggestions = {
  1802. const: "declare export var",
  1803. let: "declare export var",
  1804. type: "export type",
  1805. interface: "export interface"
  1806. };
  1807. function partition(list, test) {
  1808. const list1 = [];
  1809. const list2 = [];
  1810. for (let i = 0; i < list.length; i++) {
  1811. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  1812. }
  1813. return [list1, list2];
  1814. }
  1815. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  1816. var flow = superClass => class FlowParserMixin extends superClass {
  1817. constructor(...args) {
  1818. super(...args);
  1819. this.flowPragma = undefined;
  1820. }
  1821. getScopeHandler() {
  1822. return FlowScopeHandler;
  1823. }
  1824. shouldParseTypes() {
  1825. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  1826. }
  1827. finishToken(type, val) {
  1828. if (type !== 134 && type !== 13 && type !== 28) {
  1829. if (this.flowPragma === undefined) {
  1830. this.flowPragma = null;
  1831. }
  1832. }
  1833. super.finishToken(type, val);
  1834. }
  1835. addComment(comment) {
  1836. if (this.flowPragma === undefined) {
  1837. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  1838. if (!matches) ;else if (matches[1] === "flow") {
  1839. this.flowPragma = "flow";
  1840. } else if (matches[1] === "noflow") {
  1841. this.flowPragma = "noflow";
  1842. } else {
  1843. throw new Error("Unexpected flow pragma");
  1844. }
  1845. }
  1846. super.addComment(comment);
  1847. }
  1848. flowParseTypeInitialiser(tok) {
  1849. const oldInType = this.state.inType;
  1850. this.state.inType = true;
  1851. this.expect(tok || 14);
  1852. const type = this.flowParseType();
  1853. this.state.inType = oldInType;
  1854. return type;
  1855. }
  1856. flowParsePredicate() {
  1857. const node = this.startNode();
  1858. const moduloLoc = this.state.startLoc;
  1859. this.next();
  1860. this.expectContextual(110);
  1861. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  1862. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  1863. }
  1864. if (this.eat(10)) {
  1865. node.value = super.parseExpression();
  1866. this.expect(11);
  1867. return this.finishNode(node, "DeclaredPredicate");
  1868. } else {
  1869. return this.finishNode(node, "InferredPredicate");
  1870. }
  1871. }
  1872. flowParseTypeAndPredicateInitialiser() {
  1873. const oldInType = this.state.inType;
  1874. this.state.inType = true;
  1875. this.expect(14);
  1876. let type = null;
  1877. let predicate = null;
  1878. if (this.match(54)) {
  1879. this.state.inType = oldInType;
  1880. predicate = this.flowParsePredicate();
  1881. } else {
  1882. type = this.flowParseType();
  1883. this.state.inType = oldInType;
  1884. if (this.match(54)) {
  1885. predicate = this.flowParsePredicate();
  1886. }
  1887. }
  1888. return [type, predicate];
  1889. }
  1890. flowParseDeclareClass(node) {
  1891. this.next();
  1892. this.flowParseInterfaceish(node, true);
  1893. return this.finishNode(node, "DeclareClass");
  1894. }
  1895. flowParseDeclareFunction(node) {
  1896. this.next();
  1897. const id = node.id = this.parseIdentifier();
  1898. const typeNode = this.startNode();
  1899. const typeContainer = this.startNode();
  1900. if (this.match(47)) {
  1901. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  1902. } else {
  1903. typeNode.typeParameters = null;
  1904. }
  1905. this.expect(10);
  1906. const tmp = this.flowParseFunctionTypeParams();
  1907. typeNode.params = tmp.params;
  1908. typeNode.rest = tmp.rest;
  1909. typeNode.this = tmp._this;
  1910. this.expect(11);
  1911. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  1912. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  1913. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  1914. this.resetEndLocation(id);
  1915. this.semicolon();
  1916. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  1917. return this.finishNode(node, "DeclareFunction");
  1918. }
  1919. flowParseDeclare(node, insideModule) {
  1920. if (this.match(80)) {
  1921. return this.flowParseDeclareClass(node);
  1922. } else if (this.match(68)) {
  1923. return this.flowParseDeclareFunction(node);
  1924. } else if (this.match(74)) {
  1925. return this.flowParseDeclareVariable(node);
  1926. } else if (this.eatContextual(127)) {
  1927. if (this.match(16)) {
  1928. return this.flowParseDeclareModuleExports(node);
  1929. } else {
  1930. if (insideModule) {
  1931. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  1932. }
  1933. return this.flowParseDeclareModule(node);
  1934. }
  1935. } else if (this.isContextual(130)) {
  1936. return this.flowParseDeclareTypeAlias(node);
  1937. } else if (this.isContextual(131)) {
  1938. return this.flowParseDeclareOpaqueType(node);
  1939. } else if (this.isContextual(129)) {
  1940. return this.flowParseDeclareInterface(node);
  1941. } else if (this.match(82)) {
  1942. return this.flowParseDeclareExportDeclaration(node, insideModule);
  1943. }
  1944. throw this.unexpected();
  1945. }
  1946. flowParseDeclareVariable(node) {
  1947. this.next();
  1948. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  1949. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  1950. this.semicolon();
  1951. return this.finishNode(node, "DeclareVariable");
  1952. }
  1953. flowParseDeclareModule(node) {
  1954. this.scope.enter(0);
  1955. if (this.match(134)) {
  1956. node.id = super.parseExprAtom();
  1957. } else {
  1958. node.id = this.parseIdentifier();
  1959. }
  1960. const bodyNode = node.body = this.startNode();
  1961. const body = bodyNode.body = [];
  1962. this.expect(5);
  1963. while (!this.match(8)) {
  1964. const bodyNode = this.startNode();
  1965. if (this.match(83)) {
  1966. this.next();
  1967. if (!this.isContextual(130) && !this.match(87)) {
  1968. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  1969. }
  1970. body.push(super.parseImport(bodyNode));
  1971. } else {
  1972. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  1973. body.push(this.flowParseDeclare(bodyNode, true));
  1974. }
  1975. }
  1976. this.scope.exit();
  1977. this.expect(8);
  1978. this.finishNode(bodyNode, "BlockStatement");
  1979. let kind = null;
  1980. let hasModuleExport = false;
  1981. body.forEach(bodyElement => {
  1982. if (isEsModuleType(bodyElement)) {
  1983. if (kind === "CommonJS") {
  1984. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  1985. }
  1986. kind = "ES";
  1987. } else if (bodyElement.type === "DeclareModuleExports") {
  1988. if (hasModuleExport) {
  1989. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  1990. }
  1991. if (kind === "ES") {
  1992. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  1993. }
  1994. kind = "CommonJS";
  1995. hasModuleExport = true;
  1996. }
  1997. });
  1998. node.kind = kind || "CommonJS";
  1999. return this.finishNode(node, "DeclareModule");
  2000. }
  2001. flowParseDeclareExportDeclaration(node, insideModule) {
  2002. this.expect(82);
  2003. if (this.eat(65)) {
  2004. if (this.match(68) || this.match(80)) {
  2005. node.declaration = this.flowParseDeclare(this.startNode());
  2006. } else {
  2007. node.declaration = this.flowParseType();
  2008. this.semicolon();
  2009. }
  2010. node.default = true;
  2011. return this.finishNode(node, "DeclareExportDeclaration");
  2012. } else {
  2013. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  2014. const label = this.state.value;
  2015. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  2016. unsupportedExportKind: label,
  2017. suggestion: exportSuggestions[label]
  2018. });
  2019. }
  2020. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  2021. node.declaration = this.flowParseDeclare(this.startNode());
  2022. node.default = false;
  2023. return this.finishNode(node, "DeclareExportDeclaration");
  2024. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  2025. node = this.parseExport(node, null);
  2026. if (node.type === "ExportNamedDeclaration") {
  2027. node.default = false;
  2028. delete node.exportKind;
  2029. return this.castNodeTo(node, "DeclareExportDeclaration");
  2030. } else {
  2031. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  2032. }
  2033. }
  2034. }
  2035. throw this.unexpected();
  2036. }
  2037. flowParseDeclareModuleExports(node) {
  2038. this.next();
  2039. this.expectContextual(111);
  2040. node.typeAnnotation = this.flowParseTypeAnnotation();
  2041. this.semicolon();
  2042. return this.finishNode(node, "DeclareModuleExports");
  2043. }
  2044. flowParseDeclareTypeAlias(node) {
  2045. this.next();
  2046. const finished = this.flowParseTypeAlias(node);
  2047. this.castNodeTo(finished, "DeclareTypeAlias");
  2048. return finished;
  2049. }
  2050. flowParseDeclareOpaqueType(node) {
  2051. this.next();
  2052. const finished = this.flowParseOpaqueType(node, true);
  2053. this.castNodeTo(finished, "DeclareOpaqueType");
  2054. return finished;
  2055. }
  2056. flowParseDeclareInterface(node) {
  2057. this.next();
  2058. this.flowParseInterfaceish(node, false);
  2059. return this.finishNode(node, "DeclareInterface");
  2060. }
  2061. flowParseInterfaceish(node, isClass) {
  2062. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  2063. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  2064. if (this.match(47)) {
  2065. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2066. } else {
  2067. node.typeParameters = null;
  2068. }
  2069. node.extends = [];
  2070. if (this.eat(81)) {
  2071. do {
  2072. node.extends.push(this.flowParseInterfaceExtends());
  2073. } while (!isClass && this.eat(12));
  2074. }
  2075. if (isClass) {
  2076. node.implements = [];
  2077. node.mixins = [];
  2078. if (this.eatContextual(117)) {
  2079. do {
  2080. node.mixins.push(this.flowParseInterfaceExtends());
  2081. } while (this.eat(12));
  2082. }
  2083. if (this.eatContextual(113)) {
  2084. do {
  2085. node.implements.push(this.flowParseInterfaceExtends());
  2086. } while (this.eat(12));
  2087. }
  2088. }
  2089. node.body = this.flowParseObjectType({
  2090. allowStatic: isClass,
  2091. allowExact: false,
  2092. allowSpread: false,
  2093. allowProto: isClass,
  2094. allowInexact: false
  2095. });
  2096. }
  2097. flowParseInterfaceExtends() {
  2098. const node = this.startNode();
  2099. node.id = this.flowParseQualifiedTypeIdentifier();
  2100. if (this.match(47)) {
  2101. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2102. } else {
  2103. node.typeParameters = null;
  2104. }
  2105. return this.finishNode(node, "InterfaceExtends");
  2106. }
  2107. flowParseInterface(node) {
  2108. this.flowParseInterfaceish(node, false);
  2109. return this.finishNode(node, "InterfaceDeclaration");
  2110. }
  2111. checkNotUnderscore(word) {
  2112. if (word === "_") {
  2113. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  2114. }
  2115. }
  2116. checkReservedType(word, startLoc, declaration) {
  2117. if (!reservedTypes.has(word)) return;
  2118. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  2119. reservedType: word
  2120. });
  2121. }
  2122. flowParseRestrictedIdentifier(liberal, declaration) {
  2123. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  2124. return this.parseIdentifier(liberal);
  2125. }
  2126. flowParseTypeAlias(node) {
  2127. node.id = this.flowParseRestrictedIdentifier(false, true);
  2128. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2129. if (this.match(47)) {
  2130. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2131. } else {
  2132. node.typeParameters = null;
  2133. }
  2134. node.right = this.flowParseTypeInitialiser(29);
  2135. this.semicolon();
  2136. return this.finishNode(node, "TypeAlias");
  2137. }
  2138. flowParseOpaqueType(node, declare) {
  2139. this.expectContextual(130);
  2140. node.id = this.flowParseRestrictedIdentifier(true, true);
  2141. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2142. if (this.match(47)) {
  2143. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2144. } else {
  2145. node.typeParameters = null;
  2146. }
  2147. node.supertype = null;
  2148. if (this.match(14)) {
  2149. node.supertype = this.flowParseTypeInitialiser(14);
  2150. }
  2151. node.impltype = null;
  2152. if (!declare) {
  2153. node.impltype = this.flowParseTypeInitialiser(29);
  2154. }
  2155. this.semicolon();
  2156. return this.finishNode(node, "OpaqueType");
  2157. }
  2158. flowParseTypeParameter(requireDefault = false) {
  2159. const nodeStartLoc = this.state.startLoc;
  2160. const node = this.startNode();
  2161. const variance = this.flowParseVariance();
  2162. const ident = this.flowParseTypeAnnotatableIdentifier();
  2163. node.name = ident.name;
  2164. node.variance = variance;
  2165. node.bound = ident.typeAnnotation;
  2166. if (this.match(29)) {
  2167. this.eat(29);
  2168. node.default = this.flowParseType();
  2169. } else {
  2170. if (requireDefault) {
  2171. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  2172. }
  2173. }
  2174. return this.finishNode(node, "TypeParameter");
  2175. }
  2176. flowParseTypeParameterDeclaration() {
  2177. const oldInType = this.state.inType;
  2178. const node = this.startNode();
  2179. node.params = [];
  2180. this.state.inType = true;
  2181. if (this.match(47) || this.match(143)) {
  2182. this.next();
  2183. } else {
  2184. this.unexpected();
  2185. }
  2186. let defaultRequired = false;
  2187. do {
  2188. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  2189. node.params.push(typeParameter);
  2190. if (typeParameter.default) {
  2191. defaultRequired = true;
  2192. }
  2193. if (!this.match(48)) {
  2194. this.expect(12);
  2195. }
  2196. } while (!this.match(48));
  2197. this.expect(48);
  2198. this.state.inType = oldInType;
  2199. return this.finishNode(node, "TypeParameterDeclaration");
  2200. }
  2201. flowInTopLevelContext(cb) {
  2202. if (this.curContext() !== types.brace) {
  2203. const oldContext = this.state.context;
  2204. this.state.context = [oldContext[0]];
  2205. try {
  2206. return cb();
  2207. } finally {
  2208. this.state.context = oldContext;
  2209. }
  2210. } else {
  2211. return cb();
  2212. }
  2213. }
  2214. flowParseTypeParameterInstantiationInExpression() {
  2215. if (this.reScan_lt() !== 47) return;
  2216. return this.flowParseTypeParameterInstantiation();
  2217. }
  2218. flowParseTypeParameterInstantiation() {
  2219. const node = this.startNode();
  2220. const oldInType = this.state.inType;
  2221. this.state.inType = true;
  2222. node.params = [];
  2223. this.flowInTopLevelContext(() => {
  2224. this.expect(47);
  2225. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2226. this.state.noAnonFunctionType = false;
  2227. while (!this.match(48)) {
  2228. node.params.push(this.flowParseType());
  2229. if (!this.match(48)) {
  2230. this.expect(12);
  2231. }
  2232. }
  2233. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2234. });
  2235. this.state.inType = oldInType;
  2236. if (!this.state.inType && this.curContext() === types.brace) {
  2237. this.reScan_lt_gt();
  2238. }
  2239. this.expect(48);
  2240. return this.finishNode(node, "TypeParameterInstantiation");
  2241. }
  2242. flowParseTypeParameterInstantiationCallOrNew() {
  2243. if (this.reScan_lt() !== 47) return null;
  2244. const node = this.startNode();
  2245. const oldInType = this.state.inType;
  2246. node.params = [];
  2247. this.state.inType = true;
  2248. this.expect(47);
  2249. while (!this.match(48)) {
  2250. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  2251. if (!this.match(48)) {
  2252. this.expect(12);
  2253. }
  2254. }
  2255. this.expect(48);
  2256. this.state.inType = oldInType;
  2257. return this.finishNode(node, "TypeParameterInstantiation");
  2258. }
  2259. flowParseInterfaceType() {
  2260. const node = this.startNode();
  2261. this.expectContextual(129);
  2262. node.extends = [];
  2263. if (this.eat(81)) {
  2264. do {
  2265. node.extends.push(this.flowParseInterfaceExtends());
  2266. } while (this.eat(12));
  2267. }
  2268. node.body = this.flowParseObjectType({
  2269. allowStatic: false,
  2270. allowExact: false,
  2271. allowSpread: false,
  2272. allowProto: false,
  2273. allowInexact: false
  2274. });
  2275. return this.finishNode(node, "InterfaceTypeAnnotation");
  2276. }
  2277. flowParseObjectPropertyKey() {
  2278. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  2279. }
  2280. flowParseObjectTypeIndexer(node, isStatic, variance) {
  2281. node.static = isStatic;
  2282. if (this.lookahead().type === 14) {
  2283. node.id = this.flowParseObjectPropertyKey();
  2284. node.key = this.flowParseTypeInitialiser();
  2285. } else {
  2286. node.id = null;
  2287. node.key = this.flowParseType();
  2288. }
  2289. this.expect(3);
  2290. node.value = this.flowParseTypeInitialiser();
  2291. node.variance = variance;
  2292. return this.finishNode(node, "ObjectTypeIndexer");
  2293. }
  2294. flowParseObjectTypeInternalSlot(node, isStatic) {
  2295. node.static = isStatic;
  2296. node.id = this.flowParseObjectPropertyKey();
  2297. this.expect(3);
  2298. this.expect(3);
  2299. if (this.match(47) || this.match(10)) {
  2300. node.method = true;
  2301. node.optional = false;
  2302. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2303. } else {
  2304. node.method = false;
  2305. if (this.eat(17)) {
  2306. node.optional = true;
  2307. }
  2308. node.value = this.flowParseTypeInitialiser();
  2309. }
  2310. return this.finishNode(node, "ObjectTypeInternalSlot");
  2311. }
  2312. flowParseObjectTypeMethodish(node) {
  2313. node.params = [];
  2314. node.rest = null;
  2315. node.typeParameters = null;
  2316. node.this = null;
  2317. if (this.match(47)) {
  2318. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2319. }
  2320. this.expect(10);
  2321. if (this.match(78)) {
  2322. node.this = this.flowParseFunctionTypeParam(true);
  2323. node.this.name = null;
  2324. if (!this.match(11)) {
  2325. this.expect(12);
  2326. }
  2327. }
  2328. while (!this.match(11) && !this.match(21)) {
  2329. node.params.push(this.flowParseFunctionTypeParam(false));
  2330. if (!this.match(11)) {
  2331. this.expect(12);
  2332. }
  2333. }
  2334. if (this.eat(21)) {
  2335. node.rest = this.flowParseFunctionTypeParam(false);
  2336. }
  2337. this.expect(11);
  2338. node.returnType = this.flowParseTypeInitialiser();
  2339. return this.finishNode(node, "FunctionTypeAnnotation");
  2340. }
  2341. flowParseObjectTypeCallProperty(node, isStatic) {
  2342. const valueNode = this.startNode();
  2343. node.static = isStatic;
  2344. node.value = this.flowParseObjectTypeMethodish(valueNode);
  2345. return this.finishNode(node, "ObjectTypeCallProperty");
  2346. }
  2347. flowParseObjectType({
  2348. allowStatic,
  2349. allowExact,
  2350. allowSpread,
  2351. allowProto,
  2352. allowInexact
  2353. }) {
  2354. const oldInType = this.state.inType;
  2355. this.state.inType = true;
  2356. const nodeStart = this.startNode();
  2357. nodeStart.callProperties = [];
  2358. nodeStart.properties = [];
  2359. nodeStart.indexers = [];
  2360. nodeStart.internalSlots = [];
  2361. let endDelim;
  2362. let exact;
  2363. let inexact = false;
  2364. if (allowExact && this.match(6)) {
  2365. this.expect(6);
  2366. endDelim = 9;
  2367. exact = true;
  2368. } else {
  2369. this.expect(5);
  2370. endDelim = 8;
  2371. exact = false;
  2372. }
  2373. nodeStart.exact = exact;
  2374. while (!this.match(endDelim)) {
  2375. let isStatic = false;
  2376. let protoStartLoc = null;
  2377. let inexactStartLoc = null;
  2378. const node = this.startNode();
  2379. if (allowProto && this.isContextual(118)) {
  2380. const lookahead = this.lookahead();
  2381. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2382. this.next();
  2383. protoStartLoc = this.state.startLoc;
  2384. allowStatic = false;
  2385. }
  2386. }
  2387. if (allowStatic && this.isContextual(106)) {
  2388. const lookahead = this.lookahead();
  2389. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2390. this.next();
  2391. isStatic = true;
  2392. }
  2393. }
  2394. const variance = this.flowParseVariance();
  2395. if (this.eat(0)) {
  2396. if (protoStartLoc != null) {
  2397. this.unexpected(protoStartLoc);
  2398. }
  2399. if (this.eat(0)) {
  2400. if (variance) {
  2401. this.unexpected(variance.loc.start);
  2402. }
  2403. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  2404. } else {
  2405. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  2406. }
  2407. } else if (this.match(10) || this.match(47)) {
  2408. if (protoStartLoc != null) {
  2409. this.unexpected(protoStartLoc);
  2410. }
  2411. if (variance) {
  2412. this.unexpected(variance.loc.start);
  2413. }
  2414. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  2415. } else {
  2416. let kind = "init";
  2417. if (this.isContextual(99) || this.isContextual(104)) {
  2418. const lookahead = this.lookahead();
  2419. if (tokenIsLiteralPropertyName(lookahead.type)) {
  2420. kind = this.state.value;
  2421. this.next();
  2422. }
  2423. }
  2424. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  2425. if (propOrInexact === null) {
  2426. inexact = true;
  2427. inexactStartLoc = this.state.lastTokStartLoc;
  2428. } else {
  2429. nodeStart.properties.push(propOrInexact);
  2430. }
  2431. }
  2432. this.flowObjectTypeSemicolon();
  2433. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  2434. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  2435. }
  2436. }
  2437. this.expect(endDelim);
  2438. if (allowSpread) {
  2439. nodeStart.inexact = inexact;
  2440. }
  2441. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  2442. this.state.inType = oldInType;
  2443. return out;
  2444. }
  2445. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  2446. if (this.eat(21)) {
  2447. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  2448. if (isInexactToken) {
  2449. if (!allowSpread) {
  2450. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  2451. } else if (!allowInexact) {
  2452. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  2453. }
  2454. if (variance) {
  2455. this.raise(FlowErrors.InexactVariance, variance);
  2456. }
  2457. return null;
  2458. }
  2459. if (!allowSpread) {
  2460. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  2461. }
  2462. if (protoStartLoc != null) {
  2463. this.unexpected(protoStartLoc);
  2464. }
  2465. if (variance) {
  2466. this.raise(FlowErrors.SpreadVariance, variance);
  2467. }
  2468. node.argument = this.flowParseType();
  2469. return this.finishNode(node, "ObjectTypeSpreadProperty");
  2470. } else {
  2471. node.key = this.flowParseObjectPropertyKey();
  2472. node.static = isStatic;
  2473. node.proto = protoStartLoc != null;
  2474. node.kind = kind;
  2475. let optional = false;
  2476. if (this.match(47) || this.match(10)) {
  2477. node.method = true;
  2478. if (protoStartLoc != null) {
  2479. this.unexpected(protoStartLoc);
  2480. }
  2481. if (variance) {
  2482. this.unexpected(variance.loc.start);
  2483. }
  2484. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2485. if (kind === "get" || kind === "set") {
  2486. this.flowCheckGetterSetterParams(node);
  2487. }
  2488. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  2489. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  2490. }
  2491. } else {
  2492. if (kind !== "init") this.unexpected();
  2493. node.method = false;
  2494. if (this.eat(17)) {
  2495. optional = true;
  2496. }
  2497. node.value = this.flowParseTypeInitialiser();
  2498. node.variance = variance;
  2499. }
  2500. node.optional = optional;
  2501. return this.finishNode(node, "ObjectTypeProperty");
  2502. }
  2503. }
  2504. flowCheckGetterSetterParams(property) {
  2505. const paramCount = property.kind === "get" ? 0 : 1;
  2506. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  2507. if (property.value.this) {
  2508. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  2509. }
  2510. if (length !== paramCount) {
  2511. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  2512. }
  2513. if (property.kind === "set" && property.value.rest) {
  2514. this.raise(Errors.BadSetterRestParameter, property);
  2515. }
  2516. }
  2517. flowObjectTypeSemicolon() {
  2518. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  2519. this.unexpected();
  2520. }
  2521. }
  2522. flowParseQualifiedTypeIdentifier(startLoc, id) {
  2523. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  2524. let node = id || this.flowParseRestrictedIdentifier(true);
  2525. while (this.eat(16)) {
  2526. const node2 = this.startNodeAt(startLoc);
  2527. node2.qualification = node;
  2528. node2.id = this.flowParseRestrictedIdentifier(true);
  2529. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  2530. }
  2531. return node;
  2532. }
  2533. flowParseGenericType(startLoc, id) {
  2534. const node = this.startNodeAt(startLoc);
  2535. node.typeParameters = null;
  2536. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  2537. if (this.match(47)) {
  2538. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2539. }
  2540. return this.finishNode(node, "GenericTypeAnnotation");
  2541. }
  2542. flowParseTypeofType() {
  2543. const node = this.startNode();
  2544. this.expect(87);
  2545. node.argument = this.flowParsePrimaryType();
  2546. return this.finishNode(node, "TypeofTypeAnnotation");
  2547. }
  2548. flowParseTupleType() {
  2549. const node = this.startNode();
  2550. node.types = [];
  2551. this.expect(0);
  2552. while (this.state.pos < this.length && !this.match(3)) {
  2553. node.types.push(this.flowParseType());
  2554. if (this.match(3)) break;
  2555. this.expect(12);
  2556. }
  2557. this.expect(3);
  2558. return this.finishNode(node, "TupleTypeAnnotation");
  2559. }
  2560. flowParseFunctionTypeParam(first) {
  2561. let name = null;
  2562. let optional = false;
  2563. let typeAnnotation = null;
  2564. const node = this.startNode();
  2565. const lh = this.lookahead();
  2566. const isThis = this.state.type === 78;
  2567. if (lh.type === 14 || lh.type === 17) {
  2568. if (isThis && !first) {
  2569. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  2570. }
  2571. name = this.parseIdentifier(isThis);
  2572. if (this.eat(17)) {
  2573. optional = true;
  2574. if (isThis) {
  2575. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  2576. }
  2577. }
  2578. typeAnnotation = this.flowParseTypeInitialiser();
  2579. } else {
  2580. typeAnnotation = this.flowParseType();
  2581. }
  2582. node.name = name;
  2583. node.optional = optional;
  2584. node.typeAnnotation = typeAnnotation;
  2585. return this.finishNode(node, "FunctionTypeParam");
  2586. }
  2587. reinterpretTypeAsFunctionTypeParam(type) {
  2588. const node = this.startNodeAt(type.loc.start);
  2589. node.name = null;
  2590. node.optional = false;
  2591. node.typeAnnotation = type;
  2592. return this.finishNode(node, "FunctionTypeParam");
  2593. }
  2594. flowParseFunctionTypeParams(params = []) {
  2595. let rest = null;
  2596. let _this = null;
  2597. if (this.match(78)) {
  2598. _this = this.flowParseFunctionTypeParam(true);
  2599. _this.name = null;
  2600. if (!this.match(11)) {
  2601. this.expect(12);
  2602. }
  2603. }
  2604. while (!this.match(11) && !this.match(21)) {
  2605. params.push(this.flowParseFunctionTypeParam(false));
  2606. if (!this.match(11)) {
  2607. this.expect(12);
  2608. }
  2609. }
  2610. if (this.eat(21)) {
  2611. rest = this.flowParseFunctionTypeParam(false);
  2612. }
  2613. return {
  2614. params,
  2615. rest,
  2616. _this
  2617. };
  2618. }
  2619. flowIdentToTypeAnnotation(startLoc, node, id) {
  2620. switch (id.name) {
  2621. case "any":
  2622. return this.finishNode(node, "AnyTypeAnnotation");
  2623. case "bool":
  2624. case "boolean":
  2625. return this.finishNode(node, "BooleanTypeAnnotation");
  2626. case "mixed":
  2627. return this.finishNode(node, "MixedTypeAnnotation");
  2628. case "empty":
  2629. return this.finishNode(node, "EmptyTypeAnnotation");
  2630. case "number":
  2631. return this.finishNode(node, "NumberTypeAnnotation");
  2632. case "string":
  2633. return this.finishNode(node, "StringTypeAnnotation");
  2634. case "symbol":
  2635. return this.finishNode(node, "SymbolTypeAnnotation");
  2636. default:
  2637. this.checkNotUnderscore(id.name);
  2638. return this.flowParseGenericType(startLoc, id);
  2639. }
  2640. }
  2641. flowParsePrimaryType() {
  2642. const startLoc = this.state.startLoc;
  2643. const node = this.startNode();
  2644. let tmp;
  2645. let type;
  2646. let isGroupedType = false;
  2647. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2648. switch (this.state.type) {
  2649. case 5:
  2650. return this.flowParseObjectType({
  2651. allowStatic: false,
  2652. allowExact: false,
  2653. allowSpread: true,
  2654. allowProto: false,
  2655. allowInexact: true
  2656. });
  2657. case 6:
  2658. return this.flowParseObjectType({
  2659. allowStatic: false,
  2660. allowExact: true,
  2661. allowSpread: true,
  2662. allowProto: false,
  2663. allowInexact: false
  2664. });
  2665. case 0:
  2666. this.state.noAnonFunctionType = false;
  2667. type = this.flowParseTupleType();
  2668. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2669. return type;
  2670. case 47:
  2671. {
  2672. const node = this.startNode();
  2673. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2674. this.expect(10);
  2675. tmp = this.flowParseFunctionTypeParams();
  2676. node.params = tmp.params;
  2677. node.rest = tmp.rest;
  2678. node.this = tmp._this;
  2679. this.expect(11);
  2680. this.expect(19);
  2681. node.returnType = this.flowParseType();
  2682. return this.finishNode(node, "FunctionTypeAnnotation");
  2683. }
  2684. case 10:
  2685. {
  2686. const node = this.startNode();
  2687. this.next();
  2688. if (!this.match(11) && !this.match(21)) {
  2689. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  2690. const token = this.lookahead().type;
  2691. isGroupedType = token !== 17 && token !== 14;
  2692. } else {
  2693. isGroupedType = true;
  2694. }
  2695. }
  2696. if (isGroupedType) {
  2697. this.state.noAnonFunctionType = false;
  2698. type = this.flowParseType();
  2699. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2700. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  2701. this.expect(11);
  2702. return type;
  2703. } else {
  2704. this.eat(12);
  2705. }
  2706. }
  2707. if (type) {
  2708. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  2709. } else {
  2710. tmp = this.flowParseFunctionTypeParams();
  2711. }
  2712. node.params = tmp.params;
  2713. node.rest = tmp.rest;
  2714. node.this = tmp._this;
  2715. this.expect(11);
  2716. this.expect(19);
  2717. node.returnType = this.flowParseType();
  2718. node.typeParameters = null;
  2719. return this.finishNode(node, "FunctionTypeAnnotation");
  2720. }
  2721. case 134:
  2722. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  2723. case 85:
  2724. case 86:
  2725. node.value = this.match(85);
  2726. this.next();
  2727. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  2728. case 53:
  2729. if (this.state.value === "-") {
  2730. this.next();
  2731. if (this.match(135)) {
  2732. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  2733. }
  2734. if (this.match(136)) {
  2735. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  2736. }
  2737. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  2738. }
  2739. throw this.unexpected();
  2740. case 135:
  2741. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  2742. case 136:
  2743. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  2744. case 88:
  2745. this.next();
  2746. return this.finishNode(node, "VoidTypeAnnotation");
  2747. case 84:
  2748. this.next();
  2749. return this.finishNode(node, "NullLiteralTypeAnnotation");
  2750. case 78:
  2751. this.next();
  2752. return this.finishNode(node, "ThisTypeAnnotation");
  2753. case 55:
  2754. this.next();
  2755. return this.finishNode(node, "ExistsTypeAnnotation");
  2756. case 87:
  2757. return this.flowParseTypeofType();
  2758. default:
  2759. if (tokenIsKeyword(this.state.type)) {
  2760. const label = tokenLabelName(this.state.type);
  2761. this.next();
  2762. return super.createIdentifier(node, label);
  2763. } else if (tokenIsIdentifier(this.state.type)) {
  2764. if (this.isContextual(129)) {
  2765. return this.flowParseInterfaceType();
  2766. }
  2767. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  2768. }
  2769. }
  2770. throw this.unexpected();
  2771. }
  2772. flowParsePostfixType() {
  2773. const startLoc = this.state.startLoc;
  2774. let type = this.flowParsePrimaryType();
  2775. let seenOptionalIndexedAccess = false;
  2776. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  2777. const node = this.startNodeAt(startLoc);
  2778. const optional = this.eat(18);
  2779. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  2780. this.expect(0);
  2781. if (!optional && this.match(3)) {
  2782. node.elementType = type;
  2783. this.next();
  2784. type = this.finishNode(node, "ArrayTypeAnnotation");
  2785. } else {
  2786. node.objectType = type;
  2787. node.indexType = this.flowParseType();
  2788. this.expect(3);
  2789. if (seenOptionalIndexedAccess) {
  2790. node.optional = optional;
  2791. type = this.finishNode(node, "OptionalIndexedAccessType");
  2792. } else {
  2793. type = this.finishNode(node, "IndexedAccessType");
  2794. }
  2795. }
  2796. }
  2797. return type;
  2798. }
  2799. flowParsePrefixType() {
  2800. const node = this.startNode();
  2801. if (this.eat(17)) {
  2802. node.typeAnnotation = this.flowParsePrefixType();
  2803. return this.finishNode(node, "NullableTypeAnnotation");
  2804. } else {
  2805. return this.flowParsePostfixType();
  2806. }
  2807. }
  2808. flowParseAnonFunctionWithoutParens() {
  2809. const param = this.flowParsePrefixType();
  2810. if (!this.state.noAnonFunctionType && this.eat(19)) {
  2811. const node = this.startNodeAt(param.loc.start);
  2812. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  2813. node.rest = null;
  2814. node.this = null;
  2815. node.returnType = this.flowParseType();
  2816. node.typeParameters = null;
  2817. return this.finishNode(node, "FunctionTypeAnnotation");
  2818. }
  2819. return param;
  2820. }
  2821. flowParseIntersectionType() {
  2822. const node = this.startNode();
  2823. this.eat(45);
  2824. const type = this.flowParseAnonFunctionWithoutParens();
  2825. node.types = [type];
  2826. while (this.eat(45)) {
  2827. node.types.push(this.flowParseAnonFunctionWithoutParens());
  2828. }
  2829. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  2830. }
  2831. flowParseUnionType() {
  2832. const node = this.startNode();
  2833. this.eat(43);
  2834. const type = this.flowParseIntersectionType();
  2835. node.types = [type];
  2836. while (this.eat(43)) {
  2837. node.types.push(this.flowParseIntersectionType());
  2838. }
  2839. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  2840. }
  2841. flowParseType() {
  2842. const oldInType = this.state.inType;
  2843. this.state.inType = true;
  2844. const type = this.flowParseUnionType();
  2845. this.state.inType = oldInType;
  2846. return type;
  2847. }
  2848. flowParseTypeOrImplicitInstantiation() {
  2849. if (this.state.type === 132 && this.state.value === "_") {
  2850. const startLoc = this.state.startLoc;
  2851. const node = this.parseIdentifier();
  2852. return this.flowParseGenericType(startLoc, node);
  2853. } else {
  2854. return this.flowParseType();
  2855. }
  2856. }
  2857. flowParseTypeAnnotation() {
  2858. const node = this.startNode();
  2859. node.typeAnnotation = this.flowParseTypeInitialiser();
  2860. return this.finishNode(node, "TypeAnnotation");
  2861. }
  2862. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  2863. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  2864. if (this.match(14)) {
  2865. ident.typeAnnotation = this.flowParseTypeAnnotation();
  2866. this.resetEndLocation(ident);
  2867. }
  2868. return ident;
  2869. }
  2870. typeCastToParameter(node) {
  2871. node.expression.typeAnnotation = node.typeAnnotation;
  2872. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  2873. return node.expression;
  2874. }
  2875. flowParseVariance() {
  2876. let variance = null;
  2877. if (this.match(53)) {
  2878. variance = this.startNode();
  2879. if (this.state.value === "+") {
  2880. variance.kind = "plus";
  2881. } else {
  2882. variance.kind = "minus";
  2883. }
  2884. this.next();
  2885. return this.finishNode(variance, "Variance");
  2886. }
  2887. return variance;
  2888. }
  2889. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  2890. if (allowExpressionBody) {
  2891. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  2892. return;
  2893. }
  2894. super.parseFunctionBody(node, false, isMethod);
  2895. }
  2896. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  2897. if (this.match(14)) {
  2898. const typeNode = this.startNode();
  2899. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  2900. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  2901. }
  2902. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  2903. }
  2904. parseStatementLike(flags) {
  2905. if (this.state.strict && this.isContextual(129)) {
  2906. const lookahead = this.lookahead();
  2907. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  2908. const node = this.startNode();
  2909. this.next();
  2910. return this.flowParseInterface(node);
  2911. }
  2912. } else if (this.isContextual(126)) {
  2913. const node = this.startNode();
  2914. this.next();
  2915. return this.flowParseEnumDeclaration(node);
  2916. }
  2917. const stmt = super.parseStatementLike(flags);
  2918. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  2919. this.flowPragma = null;
  2920. }
  2921. return stmt;
  2922. }
  2923. parseExpressionStatement(node, expr, decorators) {
  2924. if (expr.type === "Identifier") {
  2925. if (expr.name === "declare") {
  2926. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  2927. return this.flowParseDeclare(node);
  2928. }
  2929. } else if (tokenIsIdentifier(this.state.type)) {
  2930. if (expr.name === "interface") {
  2931. return this.flowParseInterface(node);
  2932. } else if (expr.name === "type") {
  2933. return this.flowParseTypeAlias(node);
  2934. } else if (expr.name === "opaque") {
  2935. return this.flowParseOpaqueType(node, false);
  2936. }
  2937. }
  2938. }
  2939. return super.parseExpressionStatement(node, expr, decorators);
  2940. }
  2941. shouldParseExportDeclaration() {
  2942. const {
  2943. type
  2944. } = this.state;
  2945. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2946. return !this.state.containsEsc;
  2947. }
  2948. return super.shouldParseExportDeclaration();
  2949. }
  2950. isExportDefaultSpecifier() {
  2951. const {
  2952. type
  2953. } = this.state;
  2954. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2955. return this.state.containsEsc;
  2956. }
  2957. return super.isExportDefaultSpecifier();
  2958. }
  2959. parseExportDefaultExpression() {
  2960. if (this.isContextual(126)) {
  2961. const node = this.startNode();
  2962. this.next();
  2963. return this.flowParseEnumDeclaration(node);
  2964. }
  2965. return super.parseExportDefaultExpression();
  2966. }
  2967. parseConditional(expr, startLoc, refExpressionErrors) {
  2968. if (!this.match(17)) return expr;
  2969. if (this.state.maybeInArrowParameters) {
  2970. const nextCh = this.lookaheadCharCode();
  2971. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  2972. this.setOptionalParametersError(refExpressionErrors);
  2973. return expr;
  2974. }
  2975. }
  2976. this.expect(17);
  2977. const state = this.state.clone();
  2978. const originalNoArrowAt = this.state.noArrowAt;
  2979. const node = this.startNodeAt(startLoc);
  2980. let {
  2981. consequent,
  2982. failed
  2983. } = this.tryParseConditionalConsequent();
  2984. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  2985. if (failed || invalid.length > 0) {
  2986. const noArrowAt = [...originalNoArrowAt];
  2987. if (invalid.length > 0) {
  2988. this.state = state;
  2989. this.state.noArrowAt = noArrowAt;
  2990. for (let i = 0; i < invalid.length; i++) {
  2991. noArrowAt.push(invalid[i].start);
  2992. }
  2993. ({
  2994. consequent,
  2995. failed
  2996. } = this.tryParseConditionalConsequent());
  2997. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  2998. }
  2999. if (failed && valid.length > 1) {
  3000. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  3001. }
  3002. if (failed && valid.length === 1) {
  3003. this.state = state;
  3004. noArrowAt.push(valid[0].start);
  3005. this.state.noArrowAt = noArrowAt;
  3006. ({
  3007. consequent,
  3008. failed
  3009. } = this.tryParseConditionalConsequent());
  3010. }
  3011. }
  3012. this.getArrowLikeExpressions(consequent, true);
  3013. this.state.noArrowAt = originalNoArrowAt;
  3014. this.expect(14);
  3015. node.test = expr;
  3016. node.consequent = consequent;
  3017. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  3018. return this.finishNode(node, "ConditionalExpression");
  3019. }
  3020. tryParseConditionalConsequent() {
  3021. this.state.noArrowParamsConversionAt.push(this.state.start);
  3022. const consequent = this.parseMaybeAssignAllowIn();
  3023. const failed = !this.match(14);
  3024. this.state.noArrowParamsConversionAt.pop();
  3025. return {
  3026. consequent,
  3027. failed
  3028. };
  3029. }
  3030. getArrowLikeExpressions(node, disallowInvalid) {
  3031. const stack = [node];
  3032. const arrows = [];
  3033. while (stack.length !== 0) {
  3034. const node = stack.pop();
  3035. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  3036. if (node.typeParameters || !node.returnType) {
  3037. this.finishArrowValidation(node);
  3038. } else {
  3039. arrows.push(node);
  3040. }
  3041. stack.push(node.body);
  3042. } else if (node.type === "ConditionalExpression") {
  3043. stack.push(node.consequent);
  3044. stack.push(node.alternate);
  3045. }
  3046. }
  3047. if (disallowInvalid) {
  3048. arrows.forEach(node => this.finishArrowValidation(node));
  3049. return [arrows, []];
  3050. }
  3051. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  3052. }
  3053. finishArrowValidation(node) {
  3054. var _node$extra;
  3055. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  3056. this.scope.enter(514 | 4);
  3057. super.checkParams(node, false, true);
  3058. this.scope.exit();
  3059. }
  3060. forwardNoArrowParamsConversionAt(node, parse) {
  3061. let result;
  3062. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3063. this.state.noArrowParamsConversionAt.push(this.state.start);
  3064. result = parse();
  3065. this.state.noArrowParamsConversionAt.pop();
  3066. } else {
  3067. result = parse();
  3068. }
  3069. return result;
  3070. }
  3071. parseParenItem(node, startLoc) {
  3072. const newNode = super.parseParenItem(node, startLoc);
  3073. if (this.eat(17)) {
  3074. newNode.optional = true;
  3075. this.resetEndLocation(node);
  3076. }
  3077. if (this.match(14)) {
  3078. const typeCastNode = this.startNodeAt(startLoc);
  3079. typeCastNode.expression = newNode;
  3080. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  3081. return this.finishNode(typeCastNode, "TypeCastExpression");
  3082. }
  3083. return newNode;
  3084. }
  3085. assertModuleNodeAllowed(node) {
  3086. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  3087. return;
  3088. }
  3089. super.assertModuleNodeAllowed(node);
  3090. }
  3091. parseExportDeclaration(node) {
  3092. if (this.isContextual(130)) {
  3093. node.exportKind = "type";
  3094. const declarationNode = this.startNode();
  3095. this.next();
  3096. if (this.match(5)) {
  3097. node.specifiers = this.parseExportSpecifiers(true);
  3098. super.parseExportFrom(node);
  3099. return null;
  3100. } else {
  3101. return this.flowParseTypeAlias(declarationNode);
  3102. }
  3103. } else if (this.isContextual(131)) {
  3104. node.exportKind = "type";
  3105. const declarationNode = this.startNode();
  3106. this.next();
  3107. return this.flowParseOpaqueType(declarationNode, false);
  3108. } else if (this.isContextual(129)) {
  3109. node.exportKind = "type";
  3110. const declarationNode = this.startNode();
  3111. this.next();
  3112. return this.flowParseInterface(declarationNode);
  3113. } else if (this.isContextual(126)) {
  3114. node.exportKind = "value";
  3115. const declarationNode = this.startNode();
  3116. this.next();
  3117. return this.flowParseEnumDeclaration(declarationNode);
  3118. } else {
  3119. return super.parseExportDeclaration(node);
  3120. }
  3121. }
  3122. eatExportStar(node) {
  3123. if (super.eatExportStar(node)) return true;
  3124. if (this.isContextual(130) && this.lookahead().type === 55) {
  3125. node.exportKind = "type";
  3126. this.next();
  3127. this.next();
  3128. return true;
  3129. }
  3130. return false;
  3131. }
  3132. maybeParseExportNamespaceSpecifier(node) {
  3133. const {
  3134. startLoc
  3135. } = this.state;
  3136. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  3137. if (hasNamespace && node.exportKind === "type") {
  3138. this.unexpected(startLoc);
  3139. }
  3140. return hasNamespace;
  3141. }
  3142. parseClassId(node, isStatement, optionalId) {
  3143. super.parseClassId(node, isStatement, optionalId);
  3144. if (this.match(47)) {
  3145. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3146. }
  3147. }
  3148. parseClassMember(classBody, member, state) {
  3149. const {
  3150. startLoc
  3151. } = this.state;
  3152. if (this.isContextual(125)) {
  3153. if (super.parseClassMemberFromModifier(classBody, member)) {
  3154. return;
  3155. }
  3156. member.declare = true;
  3157. }
  3158. super.parseClassMember(classBody, member, state);
  3159. if (member.declare) {
  3160. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  3161. this.raise(FlowErrors.DeclareClassElement, startLoc);
  3162. } else if (member.value) {
  3163. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  3164. }
  3165. }
  3166. }
  3167. isIterator(word) {
  3168. return word === "iterator" || word === "asyncIterator";
  3169. }
  3170. readIterator() {
  3171. const word = super.readWord1();
  3172. const fullWord = "@@" + word;
  3173. if (!this.isIterator(word) || !this.state.inType) {
  3174. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  3175. identifierName: fullWord
  3176. });
  3177. }
  3178. this.finishToken(132, fullWord);
  3179. }
  3180. getTokenFromCode(code) {
  3181. const next = this.input.charCodeAt(this.state.pos + 1);
  3182. if (code === 123 && next === 124) {
  3183. this.finishOp(6, 2);
  3184. } else if (this.state.inType && (code === 62 || code === 60)) {
  3185. this.finishOp(code === 62 ? 48 : 47, 1);
  3186. } else if (this.state.inType && code === 63) {
  3187. if (next === 46) {
  3188. this.finishOp(18, 2);
  3189. } else {
  3190. this.finishOp(17, 1);
  3191. }
  3192. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  3193. this.state.pos += 2;
  3194. this.readIterator();
  3195. } else {
  3196. super.getTokenFromCode(code);
  3197. }
  3198. }
  3199. isAssignable(node, isBinding) {
  3200. if (node.type === "TypeCastExpression") {
  3201. return this.isAssignable(node.expression, isBinding);
  3202. } else {
  3203. return super.isAssignable(node, isBinding);
  3204. }
  3205. }
  3206. toAssignable(node, isLHS = false) {
  3207. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  3208. node.left = this.typeCastToParameter(node.left);
  3209. }
  3210. super.toAssignable(node, isLHS);
  3211. }
  3212. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  3213. for (let i = 0; i < exprList.length; i++) {
  3214. const expr = exprList[i];
  3215. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  3216. exprList[i] = this.typeCastToParameter(expr);
  3217. }
  3218. }
  3219. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  3220. }
  3221. toReferencedList(exprList, isParenthesizedExpr) {
  3222. for (let i = 0; i < exprList.length; i++) {
  3223. var _expr$extra;
  3224. const expr = exprList[i];
  3225. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  3226. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  3227. }
  3228. }
  3229. return exprList;
  3230. }
  3231. parseArrayLike(close, isTuple, refExpressionErrors) {
  3232. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  3233. if (refExpressionErrors != null && !this.state.maybeInArrowParameters) {
  3234. this.toReferencedList(node.elements);
  3235. }
  3236. return node;
  3237. }
  3238. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  3239. return type === "TypeCastExpression" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  3240. }
  3241. parseClassProperty(node) {
  3242. if (this.match(14)) {
  3243. node.typeAnnotation = this.flowParseTypeAnnotation();
  3244. }
  3245. return super.parseClassProperty(node);
  3246. }
  3247. parseClassPrivateProperty(node) {
  3248. if (this.match(14)) {
  3249. node.typeAnnotation = this.flowParseTypeAnnotation();
  3250. }
  3251. return super.parseClassPrivateProperty(node);
  3252. }
  3253. isClassMethod() {
  3254. return this.match(47) || super.isClassMethod();
  3255. }
  3256. isClassProperty() {
  3257. return this.match(14) || super.isClassProperty();
  3258. }
  3259. isNonstaticConstructor(method) {
  3260. return !this.match(14) && super.isNonstaticConstructor(method);
  3261. }
  3262. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  3263. if (method.variance) {
  3264. this.unexpected(method.variance.loc.start);
  3265. }
  3266. delete method.variance;
  3267. if (this.match(47)) {
  3268. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3269. }
  3270. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  3271. if (method.params && isConstructor) {
  3272. const params = method.params;
  3273. if (params.length > 0 && this.isThisParam(params[0])) {
  3274. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3275. }
  3276. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  3277. const params = method.value.params;
  3278. if (params.length > 0 && this.isThisParam(params[0])) {
  3279. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3280. }
  3281. }
  3282. }
  3283. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  3284. if (method.variance) {
  3285. this.unexpected(method.variance.loc.start);
  3286. }
  3287. delete method.variance;
  3288. if (this.match(47)) {
  3289. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3290. }
  3291. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  3292. }
  3293. parseClassSuper(node) {
  3294. super.parseClassSuper(node);
  3295. if (node.superClass && (this.match(47) || this.match(51))) {
  3296. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  3297. }
  3298. if (this.isContextual(113)) {
  3299. this.next();
  3300. const implemented = node.implements = [];
  3301. do {
  3302. const node = this.startNode();
  3303. node.id = this.flowParseRestrictedIdentifier(true);
  3304. if (this.match(47)) {
  3305. node.typeParameters = this.flowParseTypeParameterInstantiation();
  3306. } else {
  3307. node.typeParameters = null;
  3308. }
  3309. implemented.push(this.finishNode(node, "ClassImplements"));
  3310. } while (this.eat(12));
  3311. }
  3312. }
  3313. checkGetterSetterParams(method) {
  3314. super.checkGetterSetterParams(method);
  3315. const params = this.getObjectOrClassMethodParams(method);
  3316. if (params.length > 0) {
  3317. const param = params[0];
  3318. if (this.isThisParam(param) && method.kind === "get") {
  3319. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  3320. } else if (this.isThisParam(param)) {
  3321. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  3322. }
  3323. }
  3324. }
  3325. parsePropertyNamePrefixOperator(node) {
  3326. node.variance = this.flowParseVariance();
  3327. }
  3328. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  3329. if (prop.variance) {
  3330. this.unexpected(prop.variance.loc.start);
  3331. }
  3332. delete prop.variance;
  3333. let typeParameters;
  3334. if (this.match(47) && !isAccessor) {
  3335. typeParameters = this.flowParseTypeParameterDeclaration();
  3336. if (!this.match(10)) this.unexpected();
  3337. }
  3338. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  3339. if (typeParameters) {
  3340. (result.value || result).typeParameters = typeParameters;
  3341. }
  3342. return result;
  3343. }
  3344. parseFunctionParamType(param) {
  3345. if (this.eat(17)) {
  3346. if (param.type !== "Identifier") {
  3347. this.raise(FlowErrors.PatternIsOptional, param);
  3348. }
  3349. if (this.isThisParam(param)) {
  3350. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  3351. }
  3352. param.optional = true;
  3353. }
  3354. if (this.match(14)) {
  3355. param.typeAnnotation = this.flowParseTypeAnnotation();
  3356. } else if (this.isThisParam(param)) {
  3357. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  3358. }
  3359. if (this.match(29) && this.isThisParam(param)) {
  3360. this.raise(FlowErrors.ThisParamNoDefault, param);
  3361. }
  3362. this.resetEndLocation(param);
  3363. return param;
  3364. }
  3365. parseMaybeDefault(startLoc, left) {
  3366. const node = super.parseMaybeDefault(startLoc, left);
  3367. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  3368. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  3369. }
  3370. return node;
  3371. }
  3372. checkImportReflection(node) {
  3373. super.checkImportReflection(node);
  3374. if (node.module && node.importKind !== "value") {
  3375. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  3376. }
  3377. }
  3378. parseImportSpecifierLocal(node, specifier, type) {
  3379. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  3380. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  3381. }
  3382. isPotentialImportPhase(isExport) {
  3383. if (super.isPotentialImportPhase(isExport)) return true;
  3384. if (this.isContextual(130)) {
  3385. if (!isExport) return true;
  3386. const ch = this.lookaheadCharCode();
  3387. return ch === 123 || ch === 42;
  3388. }
  3389. return !isExport && this.isContextual(87);
  3390. }
  3391. applyImportPhase(node, isExport, phase, loc) {
  3392. super.applyImportPhase(node, isExport, phase, loc);
  3393. if (isExport) {
  3394. if (!phase && this.match(65)) {
  3395. return;
  3396. }
  3397. node.exportKind = phase === "type" ? phase : "value";
  3398. } else {
  3399. if (phase === "type" && this.match(55)) this.unexpected();
  3400. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  3401. }
  3402. }
  3403. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  3404. const firstIdent = specifier.imported;
  3405. let specifierTypeKind = null;
  3406. if (firstIdent.type === "Identifier") {
  3407. if (firstIdent.name === "type") {
  3408. specifierTypeKind = "type";
  3409. } else if (firstIdent.name === "typeof") {
  3410. specifierTypeKind = "typeof";
  3411. }
  3412. }
  3413. let isBinding = false;
  3414. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  3415. const as_ident = this.parseIdentifier(true);
  3416. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  3417. specifier.imported = as_ident;
  3418. specifier.importKind = specifierTypeKind;
  3419. specifier.local = this.cloneIdentifier(as_ident);
  3420. } else {
  3421. specifier.imported = firstIdent;
  3422. specifier.importKind = null;
  3423. specifier.local = this.parseIdentifier();
  3424. }
  3425. } else {
  3426. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  3427. specifier.imported = this.parseIdentifier(true);
  3428. specifier.importKind = specifierTypeKind;
  3429. } else {
  3430. if (importedIsString) {
  3431. throw this.raise(Errors.ImportBindingIsString, specifier, {
  3432. importName: firstIdent.value
  3433. });
  3434. }
  3435. specifier.imported = firstIdent;
  3436. specifier.importKind = null;
  3437. }
  3438. if (this.eatContextual(93)) {
  3439. specifier.local = this.parseIdentifier();
  3440. } else {
  3441. isBinding = true;
  3442. specifier.local = this.cloneIdentifier(specifier.imported);
  3443. }
  3444. }
  3445. const specifierIsTypeImport = hasTypeImportKind(specifier);
  3446. if (isInTypeOnlyImport && specifierIsTypeImport) {
  3447. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  3448. }
  3449. if (isInTypeOnlyImport || specifierIsTypeImport) {
  3450. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  3451. }
  3452. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  3453. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  3454. }
  3455. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  3456. }
  3457. parseBindingAtom() {
  3458. switch (this.state.type) {
  3459. case 78:
  3460. return this.parseIdentifier(true);
  3461. default:
  3462. return super.parseBindingAtom();
  3463. }
  3464. }
  3465. parseFunctionParams(node, isConstructor) {
  3466. const kind = node.kind;
  3467. if (kind !== "get" && kind !== "set" && this.match(47)) {
  3468. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3469. }
  3470. super.parseFunctionParams(node, isConstructor);
  3471. }
  3472. parseVarId(decl, kind) {
  3473. super.parseVarId(decl, kind);
  3474. if (this.match(14)) {
  3475. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  3476. this.resetEndLocation(decl.id);
  3477. }
  3478. }
  3479. parseAsyncArrowFromCallExpression(node, call) {
  3480. if (this.match(14)) {
  3481. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3482. this.state.noAnonFunctionType = true;
  3483. node.returnType = this.flowParseTypeAnnotation();
  3484. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3485. }
  3486. return super.parseAsyncArrowFromCallExpression(node, call);
  3487. }
  3488. shouldParseAsyncArrow() {
  3489. return this.match(14) || super.shouldParseAsyncArrow();
  3490. }
  3491. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  3492. var _jsx;
  3493. let state = null;
  3494. let jsx;
  3495. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  3496. state = this.state.clone();
  3497. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  3498. if (!jsx.error) return jsx.node;
  3499. const {
  3500. context
  3501. } = this.state;
  3502. const currentContext = context[context.length - 1];
  3503. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  3504. context.pop();
  3505. }
  3506. }
  3507. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  3508. var _jsx2, _jsx3;
  3509. state = state || this.state.clone();
  3510. let typeParameters;
  3511. const arrow = this.tryParse(abort => {
  3512. var _arrowExpression$extr;
  3513. typeParameters = this.flowParseTypeParameterDeclaration();
  3514. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  3515. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3516. this.resetStartLocationFromNode(result, typeParameters);
  3517. return result;
  3518. });
  3519. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  3520. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  3521. if (expr.type !== "ArrowFunctionExpression") abort();
  3522. expr.typeParameters = typeParameters;
  3523. this.resetStartLocationFromNode(expr, typeParameters);
  3524. return arrowExpression;
  3525. }, state);
  3526. let arrowExpression = null;
  3527. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  3528. if (!arrow.error && !arrow.aborted) {
  3529. if (arrow.node.async) {
  3530. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  3531. }
  3532. return arrow.node;
  3533. }
  3534. arrowExpression = arrow.node;
  3535. }
  3536. if ((_jsx2 = jsx) != null && _jsx2.node) {
  3537. this.state = jsx.failState;
  3538. return jsx.node;
  3539. }
  3540. if (arrowExpression) {
  3541. this.state = arrow.failState;
  3542. return arrowExpression;
  3543. }
  3544. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  3545. if (arrow.thrown) throw arrow.error;
  3546. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  3547. }
  3548. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3549. }
  3550. parseArrow(node) {
  3551. if (this.match(14)) {
  3552. const result = this.tryParse(() => {
  3553. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3554. this.state.noAnonFunctionType = true;
  3555. const typeNode = this.startNode();
  3556. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  3557. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3558. if (this.canInsertSemicolon()) this.unexpected();
  3559. if (!this.match(19)) this.unexpected();
  3560. return typeNode;
  3561. });
  3562. if (result.thrown) return null;
  3563. if (result.error) this.state = result.failState;
  3564. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  3565. }
  3566. return super.parseArrow(node);
  3567. }
  3568. shouldParseArrow(params) {
  3569. return this.match(14) || super.shouldParseArrow(params);
  3570. }
  3571. setArrowFunctionParameters(node, params) {
  3572. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3573. node.params = params;
  3574. } else {
  3575. super.setArrowFunctionParameters(node, params);
  3576. }
  3577. }
  3578. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  3579. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3580. return;
  3581. }
  3582. for (let i = 0; i < node.params.length; i++) {
  3583. if (this.isThisParam(node.params[i]) && i > 0) {
  3584. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  3585. }
  3586. }
  3587. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  3588. }
  3589. parseParenAndDistinguishExpression(canBeArrow) {
  3590. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  3591. }
  3592. parseSubscripts(base, startLoc, noCalls) {
  3593. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  3594. this.next();
  3595. const node = this.startNodeAt(startLoc);
  3596. node.callee = base;
  3597. node.arguments = super.parseCallExpressionArguments();
  3598. base = this.finishNode(node, "CallExpression");
  3599. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  3600. const state = this.state.clone();
  3601. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  3602. if (!arrow.error && !arrow.aborted) return arrow.node;
  3603. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  3604. if (result.node && !result.error) return result.node;
  3605. if (arrow.node) {
  3606. this.state = arrow.failState;
  3607. return arrow.node;
  3608. }
  3609. if (result.node) {
  3610. this.state = result.failState;
  3611. return result.node;
  3612. }
  3613. throw arrow.error || result.error;
  3614. }
  3615. return super.parseSubscripts(base, startLoc, noCalls);
  3616. }
  3617. parseSubscript(base, startLoc, noCalls, subscriptState) {
  3618. if (this.match(18) && this.isLookaheadToken_lt()) {
  3619. subscriptState.optionalChainMember = true;
  3620. if (noCalls) {
  3621. subscriptState.stop = true;
  3622. return base;
  3623. }
  3624. this.next();
  3625. const node = this.startNodeAt(startLoc);
  3626. node.callee = base;
  3627. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  3628. this.expect(10);
  3629. node.arguments = this.parseCallExpressionArguments();
  3630. node.optional = true;
  3631. return this.finishCallExpression(node, true);
  3632. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  3633. const node = this.startNodeAt(startLoc);
  3634. node.callee = base;
  3635. const result = this.tryParse(() => {
  3636. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  3637. this.expect(10);
  3638. node.arguments = super.parseCallExpressionArguments();
  3639. if (subscriptState.optionalChainMember) {
  3640. node.optional = false;
  3641. }
  3642. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  3643. });
  3644. if (result.node) {
  3645. if (result.error) this.state = result.failState;
  3646. return result.node;
  3647. }
  3648. }
  3649. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  3650. }
  3651. parseNewCallee(node) {
  3652. super.parseNewCallee(node);
  3653. let targs = null;
  3654. if (this.shouldParseTypes() && this.match(47)) {
  3655. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  3656. }
  3657. node.typeArguments = targs;
  3658. }
  3659. parseAsyncArrowWithTypeParameters(startLoc) {
  3660. const node = this.startNodeAt(startLoc);
  3661. this.parseFunctionParams(node, false);
  3662. if (!this.parseArrow(node)) return;
  3663. return super.parseArrowExpression(node, undefined, true);
  3664. }
  3665. readToken_mult_modulo(code) {
  3666. const next = this.input.charCodeAt(this.state.pos + 1);
  3667. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  3668. this.state.hasFlowComment = false;
  3669. this.state.pos += 2;
  3670. this.nextToken();
  3671. return;
  3672. }
  3673. super.readToken_mult_modulo(code);
  3674. }
  3675. readToken_pipe_amp(code) {
  3676. const next = this.input.charCodeAt(this.state.pos + 1);
  3677. if (code === 124 && next === 125) {
  3678. this.finishOp(9, 2);
  3679. return;
  3680. }
  3681. super.readToken_pipe_amp(code);
  3682. }
  3683. parseTopLevel(file, program) {
  3684. const fileNode = super.parseTopLevel(file, program);
  3685. if (this.state.hasFlowComment) {
  3686. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  3687. }
  3688. return fileNode;
  3689. }
  3690. skipBlockComment() {
  3691. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  3692. if (this.state.hasFlowComment) {
  3693. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  3694. }
  3695. this.hasFlowCommentCompletion();
  3696. const commentSkip = this.skipFlowComment();
  3697. if (commentSkip) {
  3698. this.state.pos += commentSkip;
  3699. this.state.hasFlowComment = true;
  3700. }
  3701. return;
  3702. }
  3703. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  3704. }
  3705. skipFlowComment() {
  3706. const {
  3707. pos
  3708. } = this.state;
  3709. let shiftToFirstNonWhiteSpace = 2;
  3710. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  3711. shiftToFirstNonWhiteSpace++;
  3712. }
  3713. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  3714. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  3715. if (ch2 === 58 && ch3 === 58) {
  3716. return shiftToFirstNonWhiteSpace + 2;
  3717. }
  3718. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  3719. return shiftToFirstNonWhiteSpace + 12;
  3720. }
  3721. if (ch2 === 58 && ch3 !== 58) {
  3722. return shiftToFirstNonWhiteSpace;
  3723. }
  3724. return false;
  3725. }
  3726. hasFlowCommentCompletion() {
  3727. const end = this.input.indexOf("*/", this.state.pos);
  3728. if (end === -1) {
  3729. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  3730. }
  3731. }
  3732. flowEnumErrorBooleanMemberNotInitialized(loc, {
  3733. enumName,
  3734. memberName
  3735. }) {
  3736. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  3737. memberName,
  3738. enumName
  3739. });
  3740. }
  3741. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  3742. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  3743. }
  3744. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  3745. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  3746. }
  3747. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  3748. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  3749. }
  3750. flowEnumMemberInit() {
  3751. const startLoc = this.state.startLoc;
  3752. const endOfInit = () => this.match(12) || this.match(8);
  3753. switch (this.state.type) {
  3754. case 135:
  3755. {
  3756. const literal = this.parseNumericLiteral(this.state.value);
  3757. if (endOfInit()) {
  3758. return {
  3759. type: "number",
  3760. loc: literal.loc.start,
  3761. value: literal
  3762. };
  3763. }
  3764. return {
  3765. type: "invalid",
  3766. loc: startLoc
  3767. };
  3768. }
  3769. case 134:
  3770. {
  3771. const literal = this.parseStringLiteral(this.state.value);
  3772. if (endOfInit()) {
  3773. return {
  3774. type: "string",
  3775. loc: literal.loc.start,
  3776. value: literal
  3777. };
  3778. }
  3779. return {
  3780. type: "invalid",
  3781. loc: startLoc
  3782. };
  3783. }
  3784. case 85:
  3785. case 86:
  3786. {
  3787. const literal = this.parseBooleanLiteral(this.match(85));
  3788. if (endOfInit()) {
  3789. return {
  3790. type: "boolean",
  3791. loc: literal.loc.start,
  3792. value: literal
  3793. };
  3794. }
  3795. return {
  3796. type: "invalid",
  3797. loc: startLoc
  3798. };
  3799. }
  3800. default:
  3801. return {
  3802. type: "invalid",
  3803. loc: startLoc
  3804. };
  3805. }
  3806. }
  3807. flowEnumMemberRaw() {
  3808. const loc = this.state.startLoc;
  3809. const id = this.parseIdentifier(true);
  3810. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  3811. type: "none",
  3812. loc
  3813. };
  3814. return {
  3815. id,
  3816. init
  3817. };
  3818. }
  3819. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  3820. const {
  3821. explicitType
  3822. } = context;
  3823. if (explicitType === null) {
  3824. return;
  3825. }
  3826. if (explicitType !== expectedType) {
  3827. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  3828. }
  3829. }
  3830. flowEnumMembers({
  3831. enumName,
  3832. explicitType
  3833. }) {
  3834. const seenNames = new Set();
  3835. const members = {
  3836. booleanMembers: [],
  3837. numberMembers: [],
  3838. stringMembers: [],
  3839. defaultedMembers: []
  3840. };
  3841. let hasUnknownMembers = false;
  3842. while (!this.match(8)) {
  3843. if (this.eat(21)) {
  3844. hasUnknownMembers = true;
  3845. break;
  3846. }
  3847. const memberNode = this.startNode();
  3848. const {
  3849. id,
  3850. init
  3851. } = this.flowEnumMemberRaw();
  3852. const memberName = id.name;
  3853. if (memberName === "") {
  3854. continue;
  3855. }
  3856. if (/^[a-z]/.test(memberName)) {
  3857. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  3858. memberName,
  3859. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  3860. enumName
  3861. });
  3862. }
  3863. if (seenNames.has(memberName)) {
  3864. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  3865. memberName,
  3866. enumName
  3867. });
  3868. }
  3869. seenNames.add(memberName);
  3870. const context = {
  3871. enumName,
  3872. explicitType,
  3873. memberName
  3874. };
  3875. memberNode.id = id;
  3876. switch (init.type) {
  3877. case "boolean":
  3878. {
  3879. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  3880. memberNode.init = init.value;
  3881. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  3882. break;
  3883. }
  3884. case "number":
  3885. {
  3886. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  3887. memberNode.init = init.value;
  3888. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  3889. break;
  3890. }
  3891. case "string":
  3892. {
  3893. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  3894. memberNode.init = init.value;
  3895. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  3896. break;
  3897. }
  3898. case "invalid":
  3899. {
  3900. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  3901. }
  3902. case "none":
  3903. {
  3904. switch (explicitType) {
  3905. case "boolean":
  3906. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  3907. break;
  3908. case "number":
  3909. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  3910. break;
  3911. default:
  3912. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  3913. }
  3914. }
  3915. }
  3916. if (!this.match(8)) {
  3917. this.expect(12);
  3918. }
  3919. }
  3920. return {
  3921. members,
  3922. hasUnknownMembers
  3923. };
  3924. }
  3925. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  3926. enumName
  3927. }) {
  3928. if (initializedMembers.length === 0) {
  3929. return defaultedMembers;
  3930. } else if (defaultedMembers.length === 0) {
  3931. return initializedMembers;
  3932. } else if (defaultedMembers.length > initializedMembers.length) {
  3933. for (const member of initializedMembers) {
  3934. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3935. enumName
  3936. });
  3937. }
  3938. return defaultedMembers;
  3939. } else {
  3940. for (const member of defaultedMembers) {
  3941. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3942. enumName
  3943. });
  3944. }
  3945. return initializedMembers;
  3946. }
  3947. }
  3948. flowEnumParseExplicitType({
  3949. enumName
  3950. }) {
  3951. if (!this.eatContextual(102)) return null;
  3952. if (!tokenIsIdentifier(this.state.type)) {
  3953. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  3954. enumName
  3955. });
  3956. }
  3957. const {
  3958. value
  3959. } = this.state;
  3960. this.next();
  3961. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  3962. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  3963. enumName,
  3964. invalidEnumType: value
  3965. });
  3966. }
  3967. return value;
  3968. }
  3969. flowEnumBody(node, id) {
  3970. const enumName = id.name;
  3971. const nameLoc = id.loc.start;
  3972. const explicitType = this.flowEnumParseExplicitType({
  3973. enumName
  3974. });
  3975. this.expect(5);
  3976. const {
  3977. members,
  3978. hasUnknownMembers
  3979. } = this.flowEnumMembers({
  3980. enumName,
  3981. explicitType
  3982. });
  3983. node.hasUnknownMembers = hasUnknownMembers;
  3984. switch (explicitType) {
  3985. case "boolean":
  3986. node.explicitType = true;
  3987. node.members = members.booleanMembers;
  3988. this.expect(8);
  3989. return this.finishNode(node, "EnumBooleanBody");
  3990. case "number":
  3991. node.explicitType = true;
  3992. node.members = members.numberMembers;
  3993. this.expect(8);
  3994. return this.finishNode(node, "EnumNumberBody");
  3995. case "string":
  3996. node.explicitType = true;
  3997. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  3998. enumName
  3999. });
  4000. this.expect(8);
  4001. return this.finishNode(node, "EnumStringBody");
  4002. case "symbol":
  4003. node.members = members.defaultedMembers;
  4004. this.expect(8);
  4005. return this.finishNode(node, "EnumSymbolBody");
  4006. default:
  4007. {
  4008. const empty = () => {
  4009. node.members = [];
  4010. this.expect(8);
  4011. return this.finishNode(node, "EnumStringBody");
  4012. };
  4013. node.explicitType = false;
  4014. const boolsLen = members.booleanMembers.length;
  4015. const numsLen = members.numberMembers.length;
  4016. const strsLen = members.stringMembers.length;
  4017. const defaultedLen = members.defaultedMembers.length;
  4018. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  4019. return empty();
  4020. } else if (!boolsLen && !numsLen) {
  4021. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4022. enumName
  4023. });
  4024. this.expect(8);
  4025. return this.finishNode(node, "EnumStringBody");
  4026. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  4027. for (const member of members.defaultedMembers) {
  4028. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  4029. enumName,
  4030. memberName: member.id.name
  4031. });
  4032. }
  4033. node.members = members.booleanMembers;
  4034. this.expect(8);
  4035. return this.finishNode(node, "EnumBooleanBody");
  4036. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  4037. for (const member of members.defaultedMembers) {
  4038. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  4039. enumName,
  4040. memberName: member.id.name
  4041. });
  4042. }
  4043. node.members = members.numberMembers;
  4044. this.expect(8);
  4045. return this.finishNode(node, "EnumNumberBody");
  4046. } else {
  4047. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  4048. enumName
  4049. });
  4050. return empty();
  4051. }
  4052. }
  4053. }
  4054. }
  4055. flowParseEnumDeclaration(node) {
  4056. const id = this.parseIdentifier();
  4057. node.id = id;
  4058. node.body = this.flowEnumBody(this.startNode(), id);
  4059. return this.finishNode(node, "EnumDeclaration");
  4060. }
  4061. jsxParseOpeningElementAfterName(node) {
  4062. if (this.shouldParseTypes()) {
  4063. if (this.match(47) || this.match(51)) {
  4064. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  4065. }
  4066. }
  4067. return super.jsxParseOpeningElementAfterName(node);
  4068. }
  4069. isLookaheadToken_lt() {
  4070. const next = this.nextTokenStart();
  4071. if (this.input.charCodeAt(next) === 60) {
  4072. const afterNext = this.input.charCodeAt(next + 1);
  4073. return afterNext !== 60 && afterNext !== 61;
  4074. }
  4075. return false;
  4076. }
  4077. reScan_lt_gt() {
  4078. const {
  4079. type
  4080. } = this.state;
  4081. if (type === 47) {
  4082. this.state.pos -= 1;
  4083. this.readToken_lt();
  4084. } else if (type === 48) {
  4085. this.state.pos -= 1;
  4086. this.readToken_gt();
  4087. }
  4088. }
  4089. reScan_lt() {
  4090. const {
  4091. type
  4092. } = this.state;
  4093. if (type === 51) {
  4094. this.state.pos -= 2;
  4095. this.finishOp(47, 1);
  4096. return 47;
  4097. }
  4098. return type;
  4099. }
  4100. maybeUnwrapTypeCastExpression(node) {
  4101. return node.type === "TypeCastExpression" ? node.expression : node;
  4102. }
  4103. };
  4104. const entities = {
  4105. __proto__: null,
  4106. quot: "\u0022",
  4107. amp: "&",
  4108. apos: "\u0027",
  4109. lt: "<",
  4110. gt: ">",
  4111. nbsp: "\u00A0",
  4112. iexcl: "\u00A1",
  4113. cent: "\u00A2",
  4114. pound: "\u00A3",
  4115. curren: "\u00A4",
  4116. yen: "\u00A5",
  4117. brvbar: "\u00A6",
  4118. sect: "\u00A7",
  4119. uml: "\u00A8",
  4120. copy: "\u00A9",
  4121. ordf: "\u00AA",
  4122. laquo: "\u00AB",
  4123. not: "\u00AC",
  4124. shy: "\u00AD",
  4125. reg: "\u00AE",
  4126. macr: "\u00AF",
  4127. deg: "\u00B0",
  4128. plusmn: "\u00B1",
  4129. sup2: "\u00B2",
  4130. sup3: "\u00B3",
  4131. acute: "\u00B4",
  4132. micro: "\u00B5",
  4133. para: "\u00B6",
  4134. middot: "\u00B7",
  4135. cedil: "\u00B8",
  4136. sup1: "\u00B9",
  4137. ordm: "\u00BA",
  4138. raquo: "\u00BB",
  4139. frac14: "\u00BC",
  4140. frac12: "\u00BD",
  4141. frac34: "\u00BE",
  4142. iquest: "\u00BF",
  4143. Agrave: "\u00C0",
  4144. Aacute: "\u00C1",
  4145. Acirc: "\u00C2",
  4146. Atilde: "\u00C3",
  4147. Auml: "\u00C4",
  4148. Aring: "\u00C5",
  4149. AElig: "\u00C6",
  4150. Ccedil: "\u00C7",
  4151. Egrave: "\u00C8",
  4152. Eacute: "\u00C9",
  4153. Ecirc: "\u00CA",
  4154. Euml: "\u00CB",
  4155. Igrave: "\u00CC",
  4156. Iacute: "\u00CD",
  4157. Icirc: "\u00CE",
  4158. Iuml: "\u00CF",
  4159. ETH: "\u00D0",
  4160. Ntilde: "\u00D1",
  4161. Ograve: "\u00D2",
  4162. Oacute: "\u00D3",
  4163. Ocirc: "\u00D4",
  4164. Otilde: "\u00D5",
  4165. Ouml: "\u00D6",
  4166. times: "\u00D7",
  4167. Oslash: "\u00D8",
  4168. Ugrave: "\u00D9",
  4169. Uacute: "\u00DA",
  4170. Ucirc: "\u00DB",
  4171. Uuml: "\u00DC",
  4172. Yacute: "\u00DD",
  4173. THORN: "\u00DE",
  4174. szlig: "\u00DF",
  4175. agrave: "\u00E0",
  4176. aacute: "\u00E1",
  4177. acirc: "\u00E2",
  4178. atilde: "\u00E3",
  4179. auml: "\u00E4",
  4180. aring: "\u00E5",
  4181. aelig: "\u00E6",
  4182. ccedil: "\u00E7",
  4183. egrave: "\u00E8",
  4184. eacute: "\u00E9",
  4185. ecirc: "\u00EA",
  4186. euml: "\u00EB",
  4187. igrave: "\u00EC",
  4188. iacute: "\u00ED",
  4189. icirc: "\u00EE",
  4190. iuml: "\u00EF",
  4191. eth: "\u00F0",
  4192. ntilde: "\u00F1",
  4193. ograve: "\u00F2",
  4194. oacute: "\u00F3",
  4195. ocirc: "\u00F4",
  4196. otilde: "\u00F5",
  4197. ouml: "\u00F6",
  4198. divide: "\u00F7",
  4199. oslash: "\u00F8",
  4200. ugrave: "\u00F9",
  4201. uacute: "\u00FA",
  4202. ucirc: "\u00FB",
  4203. uuml: "\u00FC",
  4204. yacute: "\u00FD",
  4205. thorn: "\u00FE",
  4206. yuml: "\u00FF",
  4207. OElig: "\u0152",
  4208. oelig: "\u0153",
  4209. Scaron: "\u0160",
  4210. scaron: "\u0161",
  4211. Yuml: "\u0178",
  4212. fnof: "\u0192",
  4213. circ: "\u02C6",
  4214. tilde: "\u02DC",
  4215. Alpha: "\u0391",
  4216. Beta: "\u0392",
  4217. Gamma: "\u0393",
  4218. Delta: "\u0394",
  4219. Epsilon: "\u0395",
  4220. Zeta: "\u0396",
  4221. Eta: "\u0397",
  4222. Theta: "\u0398",
  4223. Iota: "\u0399",
  4224. Kappa: "\u039A",
  4225. Lambda: "\u039B",
  4226. Mu: "\u039C",
  4227. Nu: "\u039D",
  4228. Xi: "\u039E",
  4229. Omicron: "\u039F",
  4230. Pi: "\u03A0",
  4231. Rho: "\u03A1",
  4232. Sigma: "\u03A3",
  4233. Tau: "\u03A4",
  4234. Upsilon: "\u03A5",
  4235. Phi: "\u03A6",
  4236. Chi: "\u03A7",
  4237. Psi: "\u03A8",
  4238. Omega: "\u03A9",
  4239. alpha: "\u03B1",
  4240. beta: "\u03B2",
  4241. gamma: "\u03B3",
  4242. delta: "\u03B4",
  4243. epsilon: "\u03B5",
  4244. zeta: "\u03B6",
  4245. eta: "\u03B7",
  4246. theta: "\u03B8",
  4247. iota: "\u03B9",
  4248. kappa: "\u03BA",
  4249. lambda: "\u03BB",
  4250. mu: "\u03BC",
  4251. nu: "\u03BD",
  4252. xi: "\u03BE",
  4253. omicron: "\u03BF",
  4254. pi: "\u03C0",
  4255. rho: "\u03C1",
  4256. sigmaf: "\u03C2",
  4257. sigma: "\u03C3",
  4258. tau: "\u03C4",
  4259. upsilon: "\u03C5",
  4260. phi: "\u03C6",
  4261. chi: "\u03C7",
  4262. psi: "\u03C8",
  4263. omega: "\u03C9",
  4264. thetasym: "\u03D1",
  4265. upsih: "\u03D2",
  4266. piv: "\u03D6",
  4267. ensp: "\u2002",
  4268. emsp: "\u2003",
  4269. thinsp: "\u2009",
  4270. zwnj: "\u200C",
  4271. zwj: "\u200D",
  4272. lrm: "\u200E",
  4273. rlm: "\u200F",
  4274. ndash: "\u2013",
  4275. mdash: "\u2014",
  4276. lsquo: "\u2018",
  4277. rsquo: "\u2019",
  4278. sbquo: "\u201A",
  4279. ldquo: "\u201C",
  4280. rdquo: "\u201D",
  4281. bdquo: "\u201E",
  4282. dagger: "\u2020",
  4283. Dagger: "\u2021",
  4284. bull: "\u2022",
  4285. hellip: "\u2026",
  4286. permil: "\u2030",
  4287. prime: "\u2032",
  4288. Prime: "\u2033",
  4289. lsaquo: "\u2039",
  4290. rsaquo: "\u203A",
  4291. oline: "\u203E",
  4292. frasl: "\u2044",
  4293. euro: "\u20AC",
  4294. image: "\u2111",
  4295. weierp: "\u2118",
  4296. real: "\u211C",
  4297. trade: "\u2122",
  4298. alefsym: "\u2135",
  4299. larr: "\u2190",
  4300. uarr: "\u2191",
  4301. rarr: "\u2192",
  4302. darr: "\u2193",
  4303. harr: "\u2194",
  4304. crarr: "\u21B5",
  4305. lArr: "\u21D0",
  4306. uArr: "\u21D1",
  4307. rArr: "\u21D2",
  4308. dArr: "\u21D3",
  4309. hArr: "\u21D4",
  4310. forall: "\u2200",
  4311. part: "\u2202",
  4312. exist: "\u2203",
  4313. empty: "\u2205",
  4314. nabla: "\u2207",
  4315. isin: "\u2208",
  4316. notin: "\u2209",
  4317. ni: "\u220B",
  4318. prod: "\u220F",
  4319. sum: "\u2211",
  4320. minus: "\u2212",
  4321. lowast: "\u2217",
  4322. radic: "\u221A",
  4323. prop: "\u221D",
  4324. infin: "\u221E",
  4325. ang: "\u2220",
  4326. and: "\u2227",
  4327. or: "\u2228",
  4328. cap: "\u2229",
  4329. cup: "\u222A",
  4330. int: "\u222B",
  4331. there4: "\u2234",
  4332. sim: "\u223C",
  4333. cong: "\u2245",
  4334. asymp: "\u2248",
  4335. ne: "\u2260",
  4336. equiv: "\u2261",
  4337. le: "\u2264",
  4338. ge: "\u2265",
  4339. sub: "\u2282",
  4340. sup: "\u2283",
  4341. nsub: "\u2284",
  4342. sube: "\u2286",
  4343. supe: "\u2287",
  4344. oplus: "\u2295",
  4345. otimes: "\u2297",
  4346. perp: "\u22A5",
  4347. sdot: "\u22C5",
  4348. lceil: "\u2308",
  4349. rceil: "\u2309",
  4350. lfloor: "\u230A",
  4351. rfloor: "\u230B",
  4352. lang: "\u2329",
  4353. rang: "\u232A",
  4354. loz: "\u25CA",
  4355. spades: "\u2660",
  4356. clubs: "\u2663",
  4357. hearts: "\u2665",
  4358. diams: "\u2666"
  4359. };
  4360. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  4361. const lineBreakG = new RegExp(lineBreak.source, "g");
  4362. function isNewLine(code) {
  4363. switch (code) {
  4364. case 10:
  4365. case 13:
  4366. case 8232:
  4367. case 8233:
  4368. return true;
  4369. default:
  4370. return false;
  4371. }
  4372. }
  4373. function hasNewLine(input, start, end) {
  4374. for (let i = start; i < end; i++) {
  4375. if (isNewLine(input.charCodeAt(i))) {
  4376. return true;
  4377. }
  4378. }
  4379. return false;
  4380. }
  4381. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  4382. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  4383. function isWhitespace(code) {
  4384. switch (code) {
  4385. case 0x0009:
  4386. case 0x000b:
  4387. case 0x000c:
  4388. case 32:
  4389. case 160:
  4390. case 5760:
  4391. case 0x2000:
  4392. case 0x2001:
  4393. case 0x2002:
  4394. case 0x2003:
  4395. case 0x2004:
  4396. case 0x2005:
  4397. case 0x2006:
  4398. case 0x2007:
  4399. case 0x2008:
  4400. case 0x2009:
  4401. case 0x200a:
  4402. case 0x202f:
  4403. case 0x205f:
  4404. case 0x3000:
  4405. case 0xfeff:
  4406. return true;
  4407. default:
  4408. return false;
  4409. }
  4410. }
  4411. const JsxErrors = ParseErrorEnum`jsx`({
  4412. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  4413. MissingClosingTagElement: ({
  4414. openingTagName
  4415. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  4416. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  4417. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  4418. UnexpectedToken: ({
  4419. unexpected,
  4420. HTMLEntity
  4421. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  4422. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  4423. UnterminatedJsxContent: "Unterminated JSX contents.",
  4424. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  4425. });
  4426. function isFragment(object) {
  4427. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  4428. }
  4429. function getQualifiedJSXName(object) {
  4430. if (object.type === "JSXIdentifier") {
  4431. return object.name;
  4432. }
  4433. if (object.type === "JSXNamespacedName") {
  4434. return object.namespace.name + ":" + object.name.name;
  4435. }
  4436. if (object.type === "JSXMemberExpression") {
  4437. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  4438. }
  4439. throw new Error("Node had unexpected type: " + object.type);
  4440. }
  4441. var jsx = superClass => class JSXParserMixin extends superClass {
  4442. jsxReadToken() {
  4443. let out = "";
  4444. let chunkStart = this.state.pos;
  4445. for (;;) {
  4446. if (this.state.pos >= this.length) {
  4447. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  4448. }
  4449. const ch = this.input.charCodeAt(this.state.pos);
  4450. switch (ch) {
  4451. case 60:
  4452. case 123:
  4453. if (this.state.pos === this.state.start) {
  4454. if (ch === 60 && this.state.canStartJSXElement) {
  4455. ++this.state.pos;
  4456. this.finishToken(143);
  4457. } else {
  4458. super.getTokenFromCode(ch);
  4459. }
  4460. return;
  4461. }
  4462. out += this.input.slice(chunkStart, this.state.pos);
  4463. this.finishToken(142, out);
  4464. return;
  4465. case 38:
  4466. out += this.input.slice(chunkStart, this.state.pos);
  4467. out += this.jsxReadEntity();
  4468. chunkStart = this.state.pos;
  4469. break;
  4470. case 62:
  4471. case 125:
  4472. default:
  4473. if (isNewLine(ch)) {
  4474. out += this.input.slice(chunkStart, this.state.pos);
  4475. out += this.jsxReadNewLine(true);
  4476. chunkStart = this.state.pos;
  4477. } else {
  4478. ++this.state.pos;
  4479. }
  4480. }
  4481. }
  4482. }
  4483. jsxReadNewLine(normalizeCRLF) {
  4484. const ch = this.input.charCodeAt(this.state.pos);
  4485. let out;
  4486. ++this.state.pos;
  4487. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  4488. ++this.state.pos;
  4489. out = normalizeCRLF ? "\n" : "\r\n";
  4490. } else {
  4491. out = String.fromCharCode(ch);
  4492. }
  4493. ++this.state.curLine;
  4494. this.state.lineStart = this.state.pos;
  4495. return out;
  4496. }
  4497. jsxReadString(quote) {
  4498. let out = "";
  4499. let chunkStart = ++this.state.pos;
  4500. for (;;) {
  4501. if (this.state.pos >= this.length) {
  4502. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  4503. }
  4504. const ch = this.input.charCodeAt(this.state.pos);
  4505. if (ch === quote) break;
  4506. if (ch === 38) {
  4507. out += this.input.slice(chunkStart, this.state.pos);
  4508. out += this.jsxReadEntity();
  4509. chunkStart = this.state.pos;
  4510. } else if (isNewLine(ch)) {
  4511. out += this.input.slice(chunkStart, this.state.pos);
  4512. out += this.jsxReadNewLine(false);
  4513. chunkStart = this.state.pos;
  4514. } else {
  4515. ++this.state.pos;
  4516. }
  4517. }
  4518. out += this.input.slice(chunkStart, this.state.pos++);
  4519. this.finishToken(134, out);
  4520. }
  4521. jsxReadEntity() {
  4522. const startPos = ++this.state.pos;
  4523. if (this.codePointAtPos(this.state.pos) === 35) {
  4524. ++this.state.pos;
  4525. let radix = 10;
  4526. if (this.codePointAtPos(this.state.pos) === 120) {
  4527. radix = 16;
  4528. ++this.state.pos;
  4529. }
  4530. const codePoint = this.readInt(radix, undefined, false, "bail");
  4531. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  4532. ++this.state.pos;
  4533. return String.fromCodePoint(codePoint);
  4534. }
  4535. } else {
  4536. let count = 0;
  4537. let semi = false;
  4538. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  4539. ++this.state.pos;
  4540. }
  4541. if (semi) {
  4542. const desc = this.input.slice(startPos, this.state.pos);
  4543. const entity = entities[desc];
  4544. ++this.state.pos;
  4545. if (entity) {
  4546. return entity;
  4547. }
  4548. }
  4549. }
  4550. this.state.pos = startPos;
  4551. return "&";
  4552. }
  4553. jsxReadWord() {
  4554. let ch;
  4555. const start = this.state.pos;
  4556. do {
  4557. ch = this.input.charCodeAt(++this.state.pos);
  4558. } while (isIdentifierChar(ch) || ch === 45);
  4559. this.finishToken(141, this.input.slice(start, this.state.pos));
  4560. }
  4561. jsxParseIdentifier() {
  4562. const node = this.startNode();
  4563. if (this.match(141)) {
  4564. node.name = this.state.value;
  4565. } else if (tokenIsKeyword(this.state.type)) {
  4566. node.name = tokenLabelName(this.state.type);
  4567. } else {
  4568. this.unexpected();
  4569. }
  4570. this.next();
  4571. return this.finishNode(node, "JSXIdentifier");
  4572. }
  4573. jsxParseNamespacedName() {
  4574. const startLoc = this.state.startLoc;
  4575. const name = this.jsxParseIdentifier();
  4576. if (!this.eat(14)) return name;
  4577. const node = this.startNodeAt(startLoc);
  4578. node.namespace = name;
  4579. node.name = this.jsxParseIdentifier();
  4580. return this.finishNode(node, "JSXNamespacedName");
  4581. }
  4582. jsxParseElementName() {
  4583. const startLoc = this.state.startLoc;
  4584. let node = this.jsxParseNamespacedName();
  4585. if (node.type === "JSXNamespacedName") {
  4586. return node;
  4587. }
  4588. while (this.eat(16)) {
  4589. const newNode = this.startNodeAt(startLoc);
  4590. newNode.object = node;
  4591. newNode.property = this.jsxParseIdentifier();
  4592. node = this.finishNode(newNode, "JSXMemberExpression");
  4593. }
  4594. return node;
  4595. }
  4596. jsxParseAttributeValue() {
  4597. let node;
  4598. switch (this.state.type) {
  4599. case 5:
  4600. node = this.startNode();
  4601. this.setContext(types.brace);
  4602. this.next();
  4603. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  4604. if (node.expression.type === "JSXEmptyExpression") {
  4605. this.raise(JsxErrors.AttributeIsEmpty, node);
  4606. }
  4607. return node;
  4608. case 143:
  4609. case 134:
  4610. return this.parseExprAtom();
  4611. default:
  4612. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  4613. }
  4614. }
  4615. jsxParseEmptyExpression() {
  4616. const node = this.startNodeAt(this.state.lastTokEndLoc);
  4617. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  4618. }
  4619. jsxParseSpreadChild(node) {
  4620. this.next();
  4621. node.expression = this.parseExpression();
  4622. this.setContext(types.j_expr);
  4623. this.state.canStartJSXElement = true;
  4624. this.expect(8);
  4625. return this.finishNode(node, "JSXSpreadChild");
  4626. }
  4627. jsxParseExpressionContainer(node, previousContext) {
  4628. if (this.match(8)) {
  4629. node.expression = this.jsxParseEmptyExpression();
  4630. } else {
  4631. const expression = this.parseExpression();
  4632. node.expression = expression;
  4633. }
  4634. this.setContext(previousContext);
  4635. this.state.canStartJSXElement = true;
  4636. this.expect(8);
  4637. return this.finishNode(node, "JSXExpressionContainer");
  4638. }
  4639. jsxParseAttribute() {
  4640. const node = this.startNode();
  4641. if (this.match(5)) {
  4642. this.setContext(types.brace);
  4643. this.next();
  4644. this.expect(21);
  4645. node.argument = this.parseMaybeAssignAllowIn();
  4646. this.setContext(types.j_oTag);
  4647. this.state.canStartJSXElement = true;
  4648. this.expect(8);
  4649. return this.finishNode(node, "JSXSpreadAttribute");
  4650. }
  4651. node.name = this.jsxParseNamespacedName();
  4652. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  4653. return this.finishNode(node, "JSXAttribute");
  4654. }
  4655. jsxParseOpeningElementAt(startLoc) {
  4656. const node = this.startNodeAt(startLoc);
  4657. if (this.eat(144)) {
  4658. return this.finishNode(node, "JSXOpeningFragment");
  4659. }
  4660. node.name = this.jsxParseElementName();
  4661. return this.jsxParseOpeningElementAfterName(node);
  4662. }
  4663. jsxParseOpeningElementAfterName(node) {
  4664. const attributes = [];
  4665. while (!this.match(56) && !this.match(144)) {
  4666. attributes.push(this.jsxParseAttribute());
  4667. }
  4668. node.attributes = attributes;
  4669. node.selfClosing = this.eat(56);
  4670. this.expect(144);
  4671. return this.finishNode(node, "JSXOpeningElement");
  4672. }
  4673. jsxParseClosingElementAt(startLoc) {
  4674. const node = this.startNodeAt(startLoc);
  4675. if (this.eat(144)) {
  4676. return this.finishNode(node, "JSXClosingFragment");
  4677. }
  4678. node.name = this.jsxParseElementName();
  4679. this.expect(144);
  4680. return this.finishNode(node, "JSXClosingElement");
  4681. }
  4682. jsxParseElementAt(startLoc) {
  4683. const node = this.startNodeAt(startLoc);
  4684. const children = [];
  4685. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  4686. let closingElement = null;
  4687. if (!openingElement.selfClosing) {
  4688. contents: for (;;) {
  4689. switch (this.state.type) {
  4690. case 143:
  4691. startLoc = this.state.startLoc;
  4692. this.next();
  4693. if (this.eat(56)) {
  4694. closingElement = this.jsxParseClosingElementAt(startLoc);
  4695. break contents;
  4696. }
  4697. children.push(this.jsxParseElementAt(startLoc));
  4698. break;
  4699. case 142:
  4700. children.push(this.parseLiteral(this.state.value, "JSXText"));
  4701. break;
  4702. case 5:
  4703. {
  4704. const node = this.startNode();
  4705. this.setContext(types.brace);
  4706. this.next();
  4707. if (this.match(21)) {
  4708. children.push(this.jsxParseSpreadChild(node));
  4709. } else {
  4710. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  4711. }
  4712. break;
  4713. }
  4714. default:
  4715. this.unexpected();
  4716. }
  4717. }
  4718. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  4719. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  4720. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  4721. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4722. openingTagName: getQualifiedJSXName(openingElement.name)
  4723. });
  4724. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  4725. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  4726. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4727. openingTagName: getQualifiedJSXName(openingElement.name)
  4728. });
  4729. }
  4730. }
  4731. }
  4732. if (isFragment(openingElement)) {
  4733. node.openingFragment = openingElement;
  4734. node.closingFragment = closingElement;
  4735. } else {
  4736. node.openingElement = openingElement;
  4737. node.closingElement = closingElement;
  4738. }
  4739. node.children = children;
  4740. if (this.match(47)) {
  4741. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  4742. }
  4743. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  4744. }
  4745. jsxParseElement() {
  4746. const startLoc = this.state.startLoc;
  4747. this.next();
  4748. return this.jsxParseElementAt(startLoc);
  4749. }
  4750. setContext(newContext) {
  4751. const {
  4752. context
  4753. } = this.state;
  4754. context[context.length - 1] = newContext;
  4755. }
  4756. parseExprAtom(refExpressionErrors) {
  4757. if (this.match(143)) {
  4758. return this.jsxParseElement();
  4759. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  4760. this.replaceToken(143);
  4761. return this.jsxParseElement();
  4762. } else {
  4763. return super.parseExprAtom(refExpressionErrors);
  4764. }
  4765. }
  4766. skipSpace() {
  4767. const curContext = this.curContext();
  4768. if (!curContext.preserveSpace) super.skipSpace();
  4769. }
  4770. getTokenFromCode(code) {
  4771. const context = this.curContext();
  4772. if (context === types.j_expr) {
  4773. this.jsxReadToken();
  4774. return;
  4775. }
  4776. if (context === types.j_oTag || context === types.j_cTag) {
  4777. if (isIdentifierStart(code)) {
  4778. this.jsxReadWord();
  4779. return;
  4780. }
  4781. if (code === 62) {
  4782. ++this.state.pos;
  4783. this.finishToken(144);
  4784. return;
  4785. }
  4786. if ((code === 34 || code === 39) && context === types.j_oTag) {
  4787. this.jsxReadString(code);
  4788. return;
  4789. }
  4790. }
  4791. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  4792. ++this.state.pos;
  4793. this.finishToken(143);
  4794. return;
  4795. }
  4796. super.getTokenFromCode(code);
  4797. }
  4798. updateContext(prevType) {
  4799. const {
  4800. context,
  4801. type
  4802. } = this.state;
  4803. if (type === 56 && prevType === 143) {
  4804. context.splice(-2, 2, types.j_cTag);
  4805. this.state.canStartJSXElement = false;
  4806. } else if (type === 143) {
  4807. context.push(types.j_oTag);
  4808. } else if (type === 144) {
  4809. const out = context[context.length - 1];
  4810. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  4811. context.pop();
  4812. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  4813. } else {
  4814. this.setContext(types.j_expr);
  4815. this.state.canStartJSXElement = true;
  4816. }
  4817. } else {
  4818. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  4819. }
  4820. }
  4821. };
  4822. class TypeScriptScope extends Scope {
  4823. constructor(...args) {
  4824. super(...args);
  4825. this.tsNames = new Map();
  4826. }
  4827. }
  4828. class TypeScriptScopeHandler extends ScopeHandler {
  4829. constructor(...args) {
  4830. super(...args);
  4831. this.importsStack = [];
  4832. }
  4833. createScope(flags) {
  4834. this.importsStack.push(new Set());
  4835. return new TypeScriptScope(flags);
  4836. }
  4837. enter(flags) {
  4838. if (flags === 1024) {
  4839. this.importsStack.push(new Set());
  4840. }
  4841. super.enter(flags);
  4842. }
  4843. exit() {
  4844. const flags = super.exit();
  4845. if (flags === 1024) {
  4846. this.importsStack.pop();
  4847. }
  4848. return flags;
  4849. }
  4850. hasImport(name, allowShadow) {
  4851. const len = this.importsStack.length;
  4852. if (this.importsStack[len - 1].has(name)) {
  4853. return true;
  4854. }
  4855. if (!allowShadow && len > 1) {
  4856. for (let i = 0; i < len - 1; i++) {
  4857. if (this.importsStack[i].has(name)) return true;
  4858. }
  4859. }
  4860. return false;
  4861. }
  4862. declareName(name, bindingType, loc) {
  4863. if (bindingType & 4096) {
  4864. if (this.hasImport(name, true)) {
  4865. this.parser.raise(Errors.VarRedeclaration, loc, {
  4866. identifierName: name
  4867. });
  4868. }
  4869. this.importsStack[this.importsStack.length - 1].add(name);
  4870. return;
  4871. }
  4872. const scope = this.currentScope();
  4873. let type = scope.tsNames.get(name) || 0;
  4874. if (bindingType & 1024) {
  4875. this.maybeExportDefined(scope, name);
  4876. scope.tsNames.set(name, type | 16);
  4877. return;
  4878. }
  4879. super.declareName(name, bindingType, loc);
  4880. if (bindingType & 2) {
  4881. if (!(bindingType & 1)) {
  4882. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4883. this.maybeExportDefined(scope, name);
  4884. }
  4885. type = type | 1;
  4886. }
  4887. if (bindingType & 256) {
  4888. type = type | 2;
  4889. }
  4890. if (bindingType & 512) {
  4891. type = type | 4;
  4892. }
  4893. if (bindingType & 128) {
  4894. type = type | 8;
  4895. }
  4896. if (type) scope.tsNames.set(name, type);
  4897. }
  4898. isRedeclaredInScope(scope, name, bindingType) {
  4899. const type = scope.tsNames.get(name);
  4900. if ((type & 2) > 0) {
  4901. if (bindingType & 256) {
  4902. const isConst = !!(bindingType & 512);
  4903. const wasConst = (type & 4) > 0;
  4904. return isConst !== wasConst;
  4905. }
  4906. return true;
  4907. }
  4908. if (bindingType & 128 && (type & 8) > 0) {
  4909. if (scope.names.get(name) & 2) {
  4910. return !!(bindingType & 1);
  4911. } else {
  4912. return false;
  4913. }
  4914. }
  4915. if (bindingType & 2 && (type & 1) > 0) {
  4916. return true;
  4917. }
  4918. return super.isRedeclaredInScope(scope, name, bindingType);
  4919. }
  4920. checkLocalExport(id) {
  4921. const {
  4922. name
  4923. } = id;
  4924. if (this.hasImport(name)) return;
  4925. const len = this.scopeStack.length;
  4926. for (let i = len - 1; i >= 0; i--) {
  4927. const scope = this.scopeStack[i];
  4928. const type = scope.tsNames.get(name);
  4929. if ((type & 1) > 0 || (type & 16) > 0) {
  4930. return;
  4931. }
  4932. }
  4933. super.checkLocalExport(id);
  4934. }
  4935. }
  4936. class ProductionParameterHandler {
  4937. constructor() {
  4938. this.stacks = [];
  4939. }
  4940. enter(flags) {
  4941. this.stacks.push(flags);
  4942. }
  4943. exit() {
  4944. this.stacks.pop();
  4945. }
  4946. currentFlags() {
  4947. return this.stacks[this.stacks.length - 1];
  4948. }
  4949. get hasAwait() {
  4950. return (this.currentFlags() & 2) > 0;
  4951. }
  4952. get hasYield() {
  4953. return (this.currentFlags() & 1) > 0;
  4954. }
  4955. get hasReturn() {
  4956. return (this.currentFlags() & 4) > 0;
  4957. }
  4958. get hasIn() {
  4959. return (this.currentFlags() & 8) > 0;
  4960. }
  4961. }
  4962. function functionFlags(isAsync, isGenerator) {
  4963. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  4964. }
  4965. class BaseParser {
  4966. constructor() {
  4967. this.sawUnambiguousESM = false;
  4968. this.ambiguousScriptDifferentAst = false;
  4969. }
  4970. sourceToOffsetPos(sourcePos) {
  4971. return sourcePos + this.startIndex;
  4972. }
  4973. offsetToSourcePos(offsetPos) {
  4974. return offsetPos - this.startIndex;
  4975. }
  4976. hasPlugin(pluginConfig) {
  4977. if (typeof pluginConfig === "string") {
  4978. return this.plugins.has(pluginConfig);
  4979. } else {
  4980. const [pluginName, pluginOptions] = pluginConfig;
  4981. if (!this.hasPlugin(pluginName)) {
  4982. return false;
  4983. }
  4984. const actualOptions = this.plugins.get(pluginName);
  4985. for (const key of Object.keys(pluginOptions)) {
  4986. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  4987. return false;
  4988. }
  4989. }
  4990. return true;
  4991. }
  4992. }
  4993. getPluginOption(plugin, name) {
  4994. var _this$plugins$get;
  4995. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  4996. }
  4997. }
  4998. function setTrailingComments(node, comments) {
  4999. if (node.trailingComments === undefined) {
  5000. node.trailingComments = comments;
  5001. } else {
  5002. node.trailingComments.unshift(...comments);
  5003. }
  5004. }
  5005. function setLeadingComments(node, comments) {
  5006. if (node.leadingComments === undefined) {
  5007. node.leadingComments = comments;
  5008. } else {
  5009. node.leadingComments.unshift(...comments);
  5010. }
  5011. }
  5012. function setInnerComments(node, comments) {
  5013. if (node.innerComments === undefined) {
  5014. node.innerComments = comments;
  5015. } else {
  5016. node.innerComments.unshift(...comments);
  5017. }
  5018. }
  5019. function adjustInnerComments(node, elements, commentWS) {
  5020. let lastElement = null;
  5021. let i = elements.length;
  5022. while (lastElement === null && i > 0) {
  5023. lastElement = elements[--i];
  5024. }
  5025. if (lastElement === null || lastElement.start > commentWS.start) {
  5026. setInnerComments(node, commentWS.comments);
  5027. } else {
  5028. setTrailingComments(lastElement, commentWS.comments);
  5029. }
  5030. }
  5031. class CommentsParser extends BaseParser {
  5032. addComment(comment) {
  5033. if (this.filename) comment.loc.filename = this.filename;
  5034. const {
  5035. commentsLen
  5036. } = this.state;
  5037. if (this.comments.length !== commentsLen) {
  5038. this.comments.length = commentsLen;
  5039. }
  5040. this.comments.push(comment);
  5041. this.state.commentsLen++;
  5042. }
  5043. processComment(node) {
  5044. const {
  5045. commentStack
  5046. } = this.state;
  5047. const commentStackLength = commentStack.length;
  5048. if (commentStackLength === 0) return;
  5049. let i = commentStackLength - 1;
  5050. const lastCommentWS = commentStack[i];
  5051. if (lastCommentWS.start === node.end) {
  5052. lastCommentWS.leadingNode = node;
  5053. i--;
  5054. }
  5055. const {
  5056. start: nodeStart
  5057. } = node;
  5058. for (; i >= 0; i--) {
  5059. const commentWS = commentStack[i];
  5060. const commentEnd = commentWS.end;
  5061. if (commentEnd > nodeStart) {
  5062. commentWS.containingNode = node;
  5063. this.finalizeComment(commentWS);
  5064. commentStack.splice(i, 1);
  5065. } else {
  5066. if (commentEnd === nodeStart) {
  5067. commentWS.trailingNode = node;
  5068. }
  5069. break;
  5070. }
  5071. }
  5072. }
  5073. finalizeComment(commentWS) {
  5074. var _node$options;
  5075. const {
  5076. comments
  5077. } = commentWS;
  5078. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  5079. if (commentWS.leadingNode !== null) {
  5080. setTrailingComments(commentWS.leadingNode, comments);
  5081. }
  5082. if (commentWS.trailingNode !== null) {
  5083. setLeadingComments(commentWS.trailingNode, comments);
  5084. }
  5085. } else {
  5086. const node = commentWS.containingNode;
  5087. const commentStart = commentWS.start;
  5088. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  5089. switch (node.type) {
  5090. case "ObjectExpression":
  5091. case "ObjectPattern":
  5092. adjustInnerComments(node, node.properties, commentWS);
  5093. break;
  5094. case "CallExpression":
  5095. case "OptionalCallExpression":
  5096. adjustInnerComments(node, node.arguments, commentWS);
  5097. break;
  5098. case "ImportExpression":
  5099. adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
  5100. break;
  5101. case "FunctionDeclaration":
  5102. case "FunctionExpression":
  5103. case "ArrowFunctionExpression":
  5104. case "ObjectMethod":
  5105. case "ClassMethod":
  5106. case "ClassPrivateMethod":
  5107. adjustInnerComments(node, node.params, commentWS);
  5108. break;
  5109. case "ArrayExpression":
  5110. case "ArrayPattern":
  5111. adjustInnerComments(node, node.elements, commentWS);
  5112. break;
  5113. case "ExportNamedDeclaration":
  5114. case "ImportDeclaration":
  5115. adjustInnerComments(node, node.specifiers, commentWS);
  5116. break;
  5117. case "TSEnumDeclaration":
  5118. adjustInnerComments(node, node.members, commentWS);
  5119. break;
  5120. case "TSEnumBody":
  5121. adjustInnerComments(node, node.members, commentWS);
  5122. break;
  5123. default:
  5124. {
  5125. if (node.type === "RecordExpression") {
  5126. adjustInnerComments(node, node.properties, commentWS);
  5127. break;
  5128. }
  5129. if (node.type === "TupleExpression") {
  5130. adjustInnerComments(node, node.elements, commentWS);
  5131. break;
  5132. }
  5133. setInnerComments(node, comments);
  5134. }
  5135. }
  5136. } else {
  5137. setInnerComments(node, comments);
  5138. }
  5139. }
  5140. }
  5141. finalizeRemainingComments() {
  5142. const {
  5143. commentStack
  5144. } = this.state;
  5145. for (let i = commentStack.length - 1; i >= 0; i--) {
  5146. this.finalizeComment(commentStack[i]);
  5147. }
  5148. this.state.commentStack = [];
  5149. }
  5150. resetPreviousNodeTrailingComments(node) {
  5151. const {
  5152. commentStack
  5153. } = this.state;
  5154. const {
  5155. length
  5156. } = commentStack;
  5157. if (length === 0) return;
  5158. const commentWS = commentStack[length - 1];
  5159. if (commentWS.leadingNode === node) {
  5160. commentWS.leadingNode = null;
  5161. }
  5162. }
  5163. takeSurroundingComments(node, start, end) {
  5164. const {
  5165. commentStack
  5166. } = this.state;
  5167. const commentStackLength = commentStack.length;
  5168. if (commentStackLength === 0) return;
  5169. let i = commentStackLength - 1;
  5170. for (; i >= 0; i--) {
  5171. const commentWS = commentStack[i];
  5172. const commentEnd = commentWS.end;
  5173. const commentStart = commentWS.start;
  5174. if (commentStart === end) {
  5175. commentWS.leadingNode = node;
  5176. } else if (commentEnd === start) {
  5177. commentWS.trailingNode = node;
  5178. } else if (commentEnd < start) {
  5179. break;
  5180. }
  5181. }
  5182. }
  5183. }
  5184. class State {
  5185. constructor() {
  5186. this.flags = 1024;
  5187. this.startIndex = void 0;
  5188. this.curLine = void 0;
  5189. this.lineStart = void 0;
  5190. this.startLoc = void 0;
  5191. this.endLoc = void 0;
  5192. this.errors = [];
  5193. this.potentialArrowAt = -1;
  5194. this.noArrowAt = [];
  5195. this.noArrowParamsConversionAt = [];
  5196. this.topicContext = {
  5197. maxNumOfResolvableTopics: 0,
  5198. maxTopicIndex: null
  5199. };
  5200. this.labels = [];
  5201. this.commentsLen = 0;
  5202. this.commentStack = [];
  5203. this.pos = 0;
  5204. this.type = 140;
  5205. this.value = null;
  5206. this.start = 0;
  5207. this.end = 0;
  5208. this.lastTokEndLoc = null;
  5209. this.lastTokStartLoc = null;
  5210. this.context = [types.brace];
  5211. this.firstInvalidTemplateEscapePos = null;
  5212. this.strictErrors = new Map();
  5213. this.tokensLength = 0;
  5214. }
  5215. get strict() {
  5216. return (this.flags & 1) > 0;
  5217. }
  5218. set strict(v) {
  5219. if (v) this.flags |= 1;else this.flags &= -2;
  5220. }
  5221. init({
  5222. strictMode,
  5223. sourceType,
  5224. startIndex,
  5225. startLine,
  5226. startColumn
  5227. }) {
  5228. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  5229. this.startIndex = startIndex;
  5230. this.curLine = startLine;
  5231. this.lineStart = -startColumn;
  5232. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  5233. }
  5234. get maybeInArrowParameters() {
  5235. return (this.flags & 2) > 0;
  5236. }
  5237. set maybeInArrowParameters(v) {
  5238. if (v) this.flags |= 2;else this.flags &= -3;
  5239. }
  5240. get inType() {
  5241. return (this.flags & 4) > 0;
  5242. }
  5243. set inType(v) {
  5244. if (v) this.flags |= 4;else this.flags &= -5;
  5245. }
  5246. get noAnonFunctionType() {
  5247. return (this.flags & 8) > 0;
  5248. }
  5249. set noAnonFunctionType(v) {
  5250. if (v) this.flags |= 8;else this.flags &= -9;
  5251. }
  5252. get hasFlowComment() {
  5253. return (this.flags & 16) > 0;
  5254. }
  5255. set hasFlowComment(v) {
  5256. if (v) this.flags |= 16;else this.flags &= -17;
  5257. }
  5258. get isAmbientContext() {
  5259. return (this.flags & 32) > 0;
  5260. }
  5261. set isAmbientContext(v) {
  5262. if (v) this.flags |= 32;else this.flags &= -33;
  5263. }
  5264. get inAbstractClass() {
  5265. return (this.flags & 64) > 0;
  5266. }
  5267. set inAbstractClass(v) {
  5268. if (v) this.flags |= 64;else this.flags &= -65;
  5269. }
  5270. get inDisallowConditionalTypesContext() {
  5271. return (this.flags & 128) > 0;
  5272. }
  5273. set inDisallowConditionalTypesContext(v) {
  5274. if (v) this.flags |= 128;else this.flags &= -129;
  5275. }
  5276. get soloAwait() {
  5277. return (this.flags & 256) > 0;
  5278. }
  5279. set soloAwait(v) {
  5280. if (v) this.flags |= 256;else this.flags &= -257;
  5281. }
  5282. get inFSharpPipelineDirectBody() {
  5283. return (this.flags & 512) > 0;
  5284. }
  5285. set inFSharpPipelineDirectBody(v) {
  5286. if (v) this.flags |= 512;else this.flags &= -513;
  5287. }
  5288. get canStartJSXElement() {
  5289. return (this.flags & 1024) > 0;
  5290. }
  5291. set canStartJSXElement(v) {
  5292. if (v) this.flags |= 1024;else this.flags &= -1025;
  5293. }
  5294. get containsEsc() {
  5295. return (this.flags & 2048) > 0;
  5296. }
  5297. set containsEsc(v) {
  5298. if (v) this.flags |= 2048;else this.flags &= -2049;
  5299. }
  5300. get hasTopLevelAwait() {
  5301. return (this.flags & 4096) > 0;
  5302. }
  5303. set hasTopLevelAwait(v) {
  5304. if (v) this.flags |= 4096;else this.flags &= -4097;
  5305. }
  5306. curPosition() {
  5307. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  5308. }
  5309. clone() {
  5310. const state = new State();
  5311. state.flags = this.flags;
  5312. state.startIndex = this.startIndex;
  5313. state.curLine = this.curLine;
  5314. state.lineStart = this.lineStart;
  5315. state.startLoc = this.startLoc;
  5316. state.endLoc = this.endLoc;
  5317. state.errors = this.errors.slice();
  5318. state.potentialArrowAt = this.potentialArrowAt;
  5319. state.noArrowAt = this.noArrowAt.slice();
  5320. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  5321. state.topicContext = this.topicContext;
  5322. state.labels = this.labels.slice();
  5323. state.commentsLen = this.commentsLen;
  5324. state.commentStack = this.commentStack.slice();
  5325. state.pos = this.pos;
  5326. state.type = this.type;
  5327. state.value = this.value;
  5328. state.start = this.start;
  5329. state.end = this.end;
  5330. state.lastTokEndLoc = this.lastTokEndLoc;
  5331. state.lastTokStartLoc = this.lastTokStartLoc;
  5332. state.context = this.context.slice();
  5333. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  5334. state.strictErrors = this.strictErrors;
  5335. state.tokensLength = this.tokensLength;
  5336. return state;
  5337. }
  5338. }
  5339. var _isDigit = function isDigit(code) {
  5340. return code >= 48 && code <= 57;
  5341. };
  5342. const forbiddenNumericSeparatorSiblings = {
  5343. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  5344. hex: new Set([46, 88, 95, 120])
  5345. };
  5346. const isAllowedNumericSeparatorSibling = {
  5347. bin: ch => ch === 48 || ch === 49,
  5348. oct: ch => ch >= 48 && ch <= 55,
  5349. dec: ch => ch >= 48 && ch <= 57,
  5350. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  5351. };
  5352. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  5353. const initialPos = pos;
  5354. const initialLineStart = lineStart;
  5355. const initialCurLine = curLine;
  5356. let out = "";
  5357. let firstInvalidLoc = null;
  5358. let chunkStart = pos;
  5359. const {
  5360. length
  5361. } = input;
  5362. for (;;) {
  5363. if (pos >= length) {
  5364. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5365. out += input.slice(chunkStart, pos);
  5366. break;
  5367. }
  5368. const ch = input.charCodeAt(pos);
  5369. if (isStringEnd(type, ch, input, pos)) {
  5370. out += input.slice(chunkStart, pos);
  5371. break;
  5372. }
  5373. if (ch === 92) {
  5374. out += input.slice(chunkStart, pos);
  5375. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  5376. if (res.ch === null && !firstInvalidLoc) {
  5377. firstInvalidLoc = {
  5378. pos,
  5379. lineStart,
  5380. curLine
  5381. };
  5382. } else {
  5383. out += res.ch;
  5384. }
  5385. ({
  5386. pos,
  5387. lineStart,
  5388. curLine
  5389. } = res);
  5390. chunkStart = pos;
  5391. } else if (ch === 8232 || ch === 8233) {
  5392. ++pos;
  5393. ++curLine;
  5394. lineStart = pos;
  5395. } else if (ch === 10 || ch === 13) {
  5396. if (type === "template") {
  5397. out += input.slice(chunkStart, pos) + "\n";
  5398. ++pos;
  5399. if (ch === 13 && input.charCodeAt(pos) === 10) {
  5400. ++pos;
  5401. }
  5402. ++curLine;
  5403. chunkStart = lineStart = pos;
  5404. } else {
  5405. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5406. }
  5407. } else {
  5408. ++pos;
  5409. }
  5410. }
  5411. return {
  5412. pos,
  5413. str: out,
  5414. firstInvalidLoc,
  5415. lineStart,
  5416. curLine,
  5417. containsInvalid: !!firstInvalidLoc
  5418. };
  5419. }
  5420. function isStringEnd(type, ch, input, pos) {
  5421. if (type === "template") {
  5422. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  5423. }
  5424. return ch === (type === "double" ? 34 : 39);
  5425. }
  5426. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  5427. const throwOnInvalid = !inTemplate;
  5428. pos++;
  5429. const res = ch => ({
  5430. pos,
  5431. ch,
  5432. lineStart,
  5433. curLine
  5434. });
  5435. const ch = input.charCodeAt(pos++);
  5436. switch (ch) {
  5437. case 110:
  5438. return res("\n");
  5439. case 114:
  5440. return res("\r");
  5441. case 120:
  5442. {
  5443. let code;
  5444. ({
  5445. code,
  5446. pos
  5447. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  5448. return res(code === null ? null : String.fromCharCode(code));
  5449. }
  5450. case 117:
  5451. {
  5452. let code;
  5453. ({
  5454. code,
  5455. pos
  5456. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  5457. return res(code === null ? null : String.fromCodePoint(code));
  5458. }
  5459. case 116:
  5460. return res("\t");
  5461. case 98:
  5462. return res("\b");
  5463. case 118:
  5464. return res("\u000b");
  5465. case 102:
  5466. return res("\f");
  5467. case 13:
  5468. if (input.charCodeAt(pos) === 10) {
  5469. ++pos;
  5470. }
  5471. case 10:
  5472. lineStart = pos;
  5473. ++curLine;
  5474. case 8232:
  5475. case 8233:
  5476. return res("");
  5477. case 56:
  5478. case 57:
  5479. if (inTemplate) {
  5480. return res(null);
  5481. } else {
  5482. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  5483. }
  5484. default:
  5485. if (ch >= 48 && ch <= 55) {
  5486. const startPos = pos - 1;
  5487. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  5488. let octalStr = match[0];
  5489. let octal = parseInt(octalStr, 8);
  5490. if (octal > 255) {
  5491. octalStr = octalStr.slice(0, -1);
  5492. octal = parseInt(octalStr, 8);
  5493. }
  5494. pos += octalStr.length - 1;
  5495. const next = input.charCodeAt(pos);
  5496. if (octalStr !== "0" || next === 56 || next === 57) {
  5497. if (inTemplate) {
  5498. return res(null);
  5499. } else {
  5500. errors.strictNumericEscape(startPos, lineStart, curLine);
  5501. }
  5502. }
  5503. return res(String.fromCharCode(octal));
  5504. }
  5505. return res(String.fromCharCode(ch));
  5506. }
  5507. }
  5508. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  5509. const initialPos = pos;
  5510. let n;
  5511. ({
  5512. n,
  5513. pos
  5514. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  5515. if (n === null) {
  5516. if (throwOnInvalid) {
  5517. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  5518. } else {
  5519. pos = initialPos - 1;
  5520. }
  5521. }
  5522. return {
  5523. code: n,
  5524. pos
  5525. };
  5526. }
  5527. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  5528. const start = pos;
  5529. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  5530. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  5531. let invalid = false;
  5532. let total = 0;
  5533. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  5534. const code = input.charCodeAt(pos);
  5535. let val;
  5536. if (code === 95 && allowNumSeparator !== "bail") {
  5537. const prev = input.charCodeAt(pos - 1);
  5538. const next = input.charCodeAt(pos + 1);
  5539. if (!allowNumSeparator) {
  5540. if (bailOnError) return {
  5541. n: null,
  5542. pos
  5543. };
  5544. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  5545. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  5546. if (bailOnError) return {
  5547. n: null,
  5548. pos
  5549. };
  5550. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  5551. }
  5552. ++pos;
  5553. continue;
  5554. }
  5555. if (code >= 97) {
  5556. val = code - 97 + 10;
  5557. } else if (code >= 65) {
  5558. val = code - 65 + 10;
  5559. } else if (_isDigit(code)) {
  5560. val = code - 48;
  5561. } else {
  5562. val = Infinity;
  5563. }
  5564. if (val >= radix) {
  5565. if (val <= 9 && bailOnError) {
  5566. return {
  5567. n: null,
  5568. pos
  5569. };
  5570. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  5571. val = 0;
  5572. } else if (forceLen) {
  5573. val = 0;
  5574. invalid = true;
  5575. } else {
  5576. break;
  5577. }
  5578. }
  5579. ++pos;
  5580. total = total * radix + val;
  5581. }
  5582. if (pos === start || len != null && pos - start !== len || invalid) {
  5583. return {
  5584. n: null,
  5585. pos
  5586. };
  5587. }
  5588. return {
  5589. n: total,
  5590. pos
  5591. };
  5592. }
  5593. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  5594. const ch = input.charCodeAt(pos);
  5595. let code;
  5596. if (ch === 123) {
  5597. ++pos;
  5598. ({
  5599. code,
  5600. pos
  5601. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  5602. ++pos;
  5603. if (code !== null && code > 0x10ffff) {
  5604. if (throwOnInvalid) {
  5605. errors.invalidCodePoint(pos, lineStart, curLine);
  5606. } else {
  5607. return {
  5608. code: null,
  5609. pos
  5610. };
  5611. }
  5612. }
  5613. } else {
  5614. ({
  5615. code,
  5616. pos
  5617. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  5618. }
  5619. return {
  5620. code,
  5621. pos
  5622. };
  5623. }
  5624. function buildPosition(pos, lineStart, curLine) {
  5625. return new Position(curLine, pos - lineStart, pos);
  5626. }
  5627. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  5628. class Token {
  5629. constructor(state) {
  5630. const startIndex = state.startIndex || 0;
  5631. this.type = state.type;
  5632. this.value = state.value;
  5633. this.start = startIndex + state.start;
  5634. this.end = startIndex + state.end;
  5635. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  5636. }
  5637. }
  5638. class Tokenizer extends CommentsParser {
  5639. constructor(options, input) {
  5640. super();
  5641. this.isLookahead = void 0;
  5642. this.tokens = [];
  5643. this.errorHandlers_readInt = {
  5644. invalidDigit: (pos, lineStart, curLine, radix) => {
  5645. if (!(this.optionFlags & 2048)) return false;
  5646. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  5647. radix
  5648. });
  5649. return true;
  5650. },
  5651. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  5652. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  5653. };
  5654. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  5655. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  5656. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  5657. });
  5658. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  5659. strictNumericEscape: (pos, lineStart, curLine) => {
  5660. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  5661. },
  5662. unterminated: (pos, lineStart, curLine) => {
  5663. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  5664. }
  5665. });
  5666. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  5667. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  5668. unterminated: (pos, lineStart, curLine) => {
  5669. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  5670. }
  5671. });
  5672. this.state = new State();
  5673. this.state.init(options);
  5674. this.input = input;
  5675. this.length = input.length;
  5676. this.comments = [];
  5677. this.isLookahead = false;
  5678. }
  5679. pushToken(token) {
  5680. this.tokens.length = this.state.tokensLength;
  5681. this.tokens.push(token);
  5682. ++this.state.tokensLength;
  5683. }
  5684. next() {
  5685. this.checkKeywordEscapes();
  5686. if (this.optionFlags & 256) {
  5687. this.pushToken(new Token(this.state));
  5688. }
  5689. this.state.lastTokEndLoc = this.state.endLoc;
  5690. this.state.lastTokStartLoc = this.state.startLoc;
  5691. this.nextToken();
  5692. }
  5693. eat(type) {
  5694. if (this.match(type)) {
  5695. this.next();
  5696. return true;
  5697. } else {
  5698. return false;
  5699. }
  5700. }
  5701. match(type) {
  5702. return this.state.type === type;
  5703. }
  5704. createLookaheadState(state) {
  5705. return {
  5706. pos: state.pos,
  5707. value: null,
  5708. type: state.type,
  5709. start: state.start,
  5710. end: state.end,
  5711. context: [this.curContext()],
  5712. inType: state.inType,
  5713. startLoc: state.startLoc,
  5714. lastTokEndLoc: state.lastTokEndLoc,
  5715. curLine: state.curLine,
  5716. lineStart: state.lineStart,
  5717. curPosition: state.curPosition
  5718. };
  5719. }
  5720. lookahead() {
  5721. const old = this.state;
  5722. this.state = this.createLookaheadState(old);
  5723. this.isLookahead = true;
  5724. this.nextToken();
  5725. this.isLookahead = false;
  5726. const curr = this.state;
  5727. this.state = old;
  5728. return curr;
  5729. }
  5730. nextTokenStart() {
  5731. return this.nextTokenStartSince(this.state.pos);
  5732. }
  5733. nextTokenStartSince(pos) {
  5734. skipWhiteSpace.lastIndex = pos;
  5735. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  5736. }
  5737. lookaheadCharCode() {
  5738. return this.lookaheadCharCodeSince(this.state.pos);
  5739. }
  5740. lookaheadCharCodeSince(pos) {
  5741. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  5742. }
  5743. nextTokenInLineStart() {
  5744. return this.nextTokenInLineStartSince(this.state.pos);
  5745. }
  5746. nextTokenInLineStartSince(pos) {
  5747. skipWhiteSpaceInLine.lastIndex = pos;
  5748. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  5749. }
  5750. lookaheadInLineCharCode() {
  5751. return this.input.charCodeAt(this.nextTokenInLineStart());
  5752. }
  5753. codePointAtPos(pos) {
  5754. let cp = this.input.charCodeAt(pos);
  5755. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  5756. const trail = this.input.charCodeAt(pos);
  5757. if ((trail & 0xfc00) === 0xdc00) {
  5758. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  5759. }
  5760. }
  5761. return cp;
  5762. }
  5763. setStrict(strict) {
  5764. this.state.strict = strict;
  5765. if (strict) {
  5766. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  5767. this.state.strictErrors.clear();
  5768. }
  5769. }
  5770. curContext() {
  5771. return this.state.context[this.state.context.length - 1];
  5772. }
  5773. nextToken() {
  5774. this.skipSpace();
  5775. this.state.start = this.state.pos;
  5776. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  5777. if (this.state.pos >= this.length) {
  5778. this.finishToken(140);
  5779. return;
  5780. }
  5781. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  5782. }
  5783. skipBlockComment(commentEnd) {
  5784. let startLoc;
  5785. if (!this.isLookahead) startLoc = this.state.curPosition();
  5786. const start = this.state.pos;
  5787. const end = this.input.indexOf(commentEnd, start + 2);
  5788. if (end === -1) {
  5789. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5790. }
  5791. this.state.pos = end + commentEnd.length;
  5792. lineBreakG.lastIndex = start + 2;
  5793. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  5794. ++this.state.curLine;
  5795. this.state.lineStart = lineBreakG.lastIndex;
  5796. }
  5797. if (this.isLookahead) return;
  5798. const comment = {
  5799. type: "CommentBlock",
  5800. value: this.input.slice(start + 2, end),
  5801. start: this.sourceToOffsetPos(start),
  5802. end: this.sourceToOffsetPos(end + commentEnd.length),
  5803. loc: new SourceLocation(startLoc, this.state.curPosition())
  5804. };
  5805. if (this.optionFlags & 256) this.pushToken(comment);
  5806. return comment;
  5807. }
  5808. skipLineComment(startSkip) {
  5809. const start = this.state.pos;
  5810. let startLoc;
  5811. if (!this.isLookahead) startLoc = this.state.curPosition();
  5812. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  5813. if (this.state.pos < this.length) {
  5814. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  5815. ch = this.input.charCodeAt(this.state.pos);
  5816. }
  5817. }
  5818. if (this.isLookahead) return;
  5819. const end = this.state.pos;
  5820. const value = this.input.slice(start + startSkip, end);
  5821. const comment = {
  5822. type: "CommentLine",
  5823. value,
  5824. start: this.sourceToOffsetPos(start),
  5825. end: this.sourceToOffsetPos(end),
  5826. loc: new SourceLocation(startLoc, this.state.curPosition())
  5827. };
  5828. if (this.optionFlags & 256) this.pushToken(comment);
  5829. return comment;
  5830. }
  5831. skipSpace() {
  5832. const spaceStart = this.state.pos;
  5833. const comments = this.optionFlags & 4096 ? [] : null;
  5834. loop: while (this.state.pos < this.length) {
  5835. const ch = this.input.charCodeAt(this.state.pos);
  5836. switch (ch) {
  5837. case 32:
  5838. case 160:
  5839. case 9:
  5840. ++this.state.pos;
  5841. break;
  5842. case 13:
  5843. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  5844. ++this.state.pos;
  5845. }
  5846. case 10:
  5847. case 8232:
  5848. case 8233:
  5849. ++this.state.pos;
  5850. ++this.state.curLine;
  5851. this.state.lineStart = this.state.pos;
  5852. break;
  5853. case 47:
  5854. switch (this.input.charCodeAt(this.state.pos + 1)) {
  5855. case 42:
  5856. {
  5857. const comment = this.skipBlockComment("*/");
  5858. if (comment !== undefined) {
  5859. this.addComment(comment);
  5860. comments == null || comments.push(comment);
  5861. }
  5862. break;
  5863. }
  5864. case 47:
  5865. {
  5866. const comment = this.skipLineComment(2);
  5867. if (comment !== undefined) {
  5868. this.addComment(comment);
  5869. comments == null || comments.push(comment);
  5870. }
  5871. break;
  5872. }
  5873. default:
  5874. break loop;
  5875. }
  5876. break;
  5877. default:
  5878. if (isWhitespace(ch)) {
  5879. ++this.state.pos;
  5880. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  5881. const pos = this.state.pos;
  5882. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  5883. const comment = this.skipLineComment(3);
  5884. if (comment !== undefined) {
  5885. this.addComment(comment);
  5886. comments == null || comments.push(comment);
  5887. }
  5888. } else {
  5889. break loop;
  5890. }
  5891. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  5892. const pos = this.state.pos;
  5893. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  5894. const comment = this.skipLineComment(4);
  5895. if (comment !== undefined) {
  5896. this.addComment(comment);
  5897. comments == null || comments.push(comment);
  5898. }
  5899. } else {
  5900. break loop;
  5901. }
  5902. } else {
  5903. break loop;
  5904. }
  5905. }
  5906. }
  5907. if ((comments == null ? void 0 : comments.length) > 0) {
  5908. const end = this.state.pos;
  5909. const commentWhitespace = {
  5910. start: this.sourceToOffsetPos(spaceStart),
  5911. end: this.sourceToOffsetPos(end),
  5912. comments: comments,
  5913. leadingNode: null,
  5914. trailingNode: null,
  5915. containingNode: null
  5916. };
  5917. this.state.commentStack.push(commentWhitespace);
  5918. }
  5919. }
  5920. finishToken(type, val) {
  5921. this.state.end = this.state.pos;
  5922. this.state.endLoc = this.state.curPosition();
  5923. const prevType = this.state.type;
  5924. this.state.type = type;
  5925. this.state.value = val;
  5926. if (!this.isLookahead) {
  5927. this.updateContext(prevType);
  5928. }
  5929. }
  5930. replaceToken(type) {
  5931. this.state.type = type;
  5932. this.updateContext();
  5933. }
  5934. readToken_numberSign() {
  5935. if (this.state.pos === 0 && this.readToken_interpreter()) {
  5936. return;
  5937. }
  5938. const nextPos = this.state.pos + 1;
  5939. const next = this.codePointAtPos(nextPos);
  5940. if (next >= 48 && next <= 57) {
  5941. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  5942. }
  5943. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  5944. this.expectPlugin("recordAndTuple");
  5945. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  5946. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  5947. }
  5948. this.state.pos += 2;
  5949. if (next === 123) {
  5950. this.finishToken(7);
  5951. } else {
  5952. this.finishToken(1);
  5953. }
  5954. } else if (isIdentifierStart(next)) {
  5955. ++this.state.pos;
  5956. this.finishToken(139, this.readWord1(next));
  5957. } else if (next === 92) {
  5958. ++this.state.pos;
  5959. this.finishToken(139, this.readWord1());
  5960. } else {
  5961. this.finishOp(27, 1);
  5962. }
  5963. }
  5964. readToken_dot() {
  5965. const next = this.input.charCodeAt(this.state.pos + 1);
  5966. if (next >= 48 && next <= 57) {
  5967. this.readNumber(true);
  5968. return;
  5969. }
  5970. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  5971. this.state.pos += 3;
  5972. this.finishToken(21);
  5973. } else {
  5974. ++this.state.pos;
  5975. this.finishToken(16);
  5976. }
  5977. }
  5978. readToken_slash() {
  5979. const next = this.input.charCodeAt(this.state.pos + 1);
  5980. if (next === 61) {
  5981. this.finishOp(31, 2);
  5982. } else {
  5983. this.finishOp(56, 1);
  5984. }
  5985. }
  5986. readToken_interpreter() {
  5987. if (this.state.pos !== 0 || this.length < 2) return false;
  5988. let ch = this.input.charCodeAt(this.state.pos + 1);
  5989. if (ch !== 33) return false;
  5990. const start = this.state.pos;
  5991. this.state.pos += 1;
  5992. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  5993. ch = this.input.charCodeAt(this.state.pos);
  5994. }
  5995. const value = this.input.slice(start + 2, this.state.pos);
  5996. this.finishToken(28, value);
  5997. return true;
  5998. }
  5999. readToken_mult_modulo(code) {
  6000. let type = code === 42 ? 55 : 54;
  6001. let width = 1;
  6002. let next = this.input.charCodeAt(this.state.pos + 1);
  6003. if (code === 42 && next === 42) {
  6004. width++;
  6005. next = this.input.charCodeAt(this.state.pos + 2);
  6006. type = 57;
  6007. }
  6008. if (next === 61 && !this.state.inType) {
  6009. width++;
  6010. type = code === 37 ? 33 : 30;
  6011. }
  6012. this.finishOp(type, width);
  6013. }
  6014. readToken_pipe_amp(code) {
  6015. const next = this.input.charCodeAt(this.state.pos + 1);
  6016. if (next === code) {
  6017. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  6018. this.finishOp(30, 3);
  6019. } else {
  6020. this.finishOp(code === 124 ? 41 : 42, 2);
  6021. }
  6022. return;
  6023. }
  6024. if (code === 124) {
  6025. if (next === 62) {
  6026. this.finishOp(39, 2);
  6027. return;
  6028. }
  6029. if (this.hasPlugin("recordAndTuple") && next === 125) {
  6030. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6031. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6032. }
  6033. this.state.pos += 2;
  6034. this.finishToken(9);
  6035. return;
  6036. }
  6037. if (this.hasPlugin("recordAndTuple") && next === 93) {
  6038. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6039. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6040. }
  6041. this.state.pos += 2;
  6042. this.finishToken(4);
  6043. return;
  6044. }
  6045. }
  6046. if (next === 61) {
  6047. this.finishOp(30, 2);
  6048. return;
  6049. }
  6050. this.finishOp(code === 124 ? 43 : 45, 1);
  6051. }
  6052. readToken_caret() {
  6053. const next = this.input.charCodeAt(this.state.pos + 1);
  6054. if (next === 61 && !this.state.inType) {
  6055. this.finishOp(32, 2);
  6056. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  6057. proposal: "hack",
  6058. topicToken: "^^"
  6059. }])) {
  6060. this.finishOp(37, 2);
  6061. const lookaheadCh = this.input.codePointAt(this.state.pos);
  6062. if (lookaheadCh === 94) {
  6063. this.unexpected();
  6064. }
  6065. } else {
  6066. this.finishOp(44, 1);
  6067. }
  6068. }
  6069. readToken_atSign() {
  6070. const next = this.input.charCodeAt(this.state.pos + 1);
  6071. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  6072. proposal: "hack",
  6073. topicToken: "@@"
  6074. }])) {
  6075. this.finishOp(38, 2);
  6076. } else {
  6077. this.finishOp(26, 1);
  6078. }
  6079. }
  6080. readToken_plus_min(code) {
  6081. const next = this.input.charCodeAt(this.state.pos + 1);
  6082. if (next === code) {
  6083. this.finishOp(34, 2);
  6084. return;
  6085. }
  6086. if (next === 61) {
  6087. this.finishOp(30, 2);
  6088. } else {
  6089. this.finishOp(53, 1);
  6090. }
  6091. }
  6092. readToken_lt() {
  6093. const {
  6094. pos
  6095. } = this.state;
  6096. const next = this.input.charCodeAt(pos + 1);
  6097. if (next === 60) {
  6098. if (this.input.charCodeAt(pos + 2) === 61) {
  6099. this.finishOp(30, 3);
  6100. return;
  6101. }
  6102. this.finishOp(51, 2);
  6103. return;
  6104. }
  6105. if (next === 61) {
  6106. this.finishOp(49, 2);
  6107. return;
  6108. }
  6109. this.finishOp(47, 1);
  6110. }
  6111. readToken_gt() {
  6112. const {
  6113. pos
  6114. } = this.state;
  6115. const next = this.input.charCodeAt(pos + 1);
  6116. if (next === 62) {
  6117. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  6118. if (this.input.charCodeAt(pos + size) === 61) {
  6119. this.finishOp(30, size + 1);
  6120. return;
  6121. }
  6122. this.finishOp(52, size);
  6123. return;
  6124. }
  6125. if (next === 61) {
  6126. this.finishOp(49, 2);
  6127. return;
  6128. }
  6129. this.finishOp(48, 1);
  6130. }
  6131. readToken_eq_excl(code) {
  6132. const next = this.input.charCodeAt(this.state.pos + 1);
  6133. if (next === 61) {
  6134. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  6135. return;
  6136. }
  6137. if (code === 61 && next === 62) {
  6138. this.state.pos += 2;
  6139. this.finishToken(19);
  6140. return;
  6141. }
  6142. this.finishOp(code === 61 ? 29 : 35, 1);
  6143. }
  6144. readToken_question() {
  6145. const next = this.input.charCodeAt(this.state.pos + 1);
  6146. const next2 = this.input.charCodeAt(this.state.pos + 2);
  6147. if (next === 63) {
  6148. if (next2 === 61) {
  6149. this.finishOp(30, 3);
  6150. } else {
  6151. this.finishOp(40, 2);
  6152. }
  6153. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  6154. this.state.pos += 2;
  6155. this.finishToken(18);
  6156. } else {
  6157. ++this.state.pos;
  6158. this.finishToken(17);
  6159. }
  6160. }
  6161. getTokenFromCode(code) {
  6162. switch (code) {
  6163. case 46:
  6164. this.readToken_dot();
  6165. return;
  6166. case 40:
  6167. ++this.state.pos;
  6168. this.finishToken(10);
  6169. return;
  6170. case 41:
  6171. ++this.state.pos;
  6172. this.finishToken(11);
  6173. return;
  6174. case 59:
  6175. ++this.state.pos;
  6176. this.finishToken(13);
  6177. return;
  6178. case 44:
  6179. ++this.state.pos;
  6180. this.finishToken(12);
  6181. return;
  6182. case 91:
  6183. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6184. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6185. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6186. }
  6187. this.state.pos += 2;
  6188. this.finishToken(2);
  6189. } else {
  6190. ++this.state.pos;
  6191. this.finishToken(0);
  6192. }
  6193. return;
  6194. case 93:
  6195. ++this.state.pos;
  6196. this.finishToken(3);
  6197. return;
  6198. case 123:
  6199. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6200. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6201. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6202. }
  6203. this.state.pos += 2;
  6204. this.finishToken(6);
  6205. } else {
  6206. ++this.state.pos;
  6207. this.finishToken(5);
  6208. }
  6209. return;
  6210. case 125:
  6211. ++this.state.pos;
  6212. this.finishToken(8);
  6213. return;
  6214. case 58:
  6215. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  6216. this.finishOp(15, 2);
  6217. } else {
  6218. ++this.state.pos;
  6219. this.finishToken(14);
  6220. }
  6221. return;
  6222. case 63:
  6223. this.readToken_question();
  6224. return;
  6225. case 96:
  6226. this.readTemplateToken();
  6227. return;
  6228. case 48:
  6229. {
  6230. const next = this.input.charCodeAt(this.state.pos + 1);
  6231. if (next === 120 || next === 88) {
  6232. this.readRadixNumber(16);
  6233. return;
  6234. }
  6235. if (next === 111 || next === 79) {
  6236. this.readRadixNumber(8);
  6237. return;
  6238. }
  6239. if (next === 98 || next === 66) {
  6240. this.readRadixNumber(2);
  6241. return;
  6242. }
  6243. }
  6244. case 49:
  6245. case 50:
  6246. case 51:
  6247. case 52:
  6248. case 53:
  6249. case 54:
  6250. case 55:
  6251. case 56:
  6252. case 57:
  6253. this.readNumber(false);
  6254. return;
  6255. case 34:
  6256. case 39:
  6257. this.readString(code);
  6258. return;
  6259. case 47:
  6260. this.readToken_slash();
  6261. return;
  6262. case 37:
  6263. case 42:
  6264. this.readToken_mult_modulo(code);
  6265. return;
  6266. case 124:
  6267. case 38:
  6268. this.readToken_pipe_amp(code);
  6269. return;
  6270. case 94:
  6271. this.readToken_caret();
  6272. return;
  6273. case 43:
  6274. case 45:
  6275. this.readToken_plus_min(code);
  6276. return;
  6277. case 60:
  6278. this.readToken_lt();
  6279. return;
  6280. case 62:
  6281. this.readToken_gt();
  6282. return;
  6283. case 61:
  6284. case 33:
  6285. this.readToken_eq_excl(code);
  6286. return;
  6287. case 126:
  6288. this.finishOp(36, 1);
  6289. return;
  6290. case 64:
  6291. this.readToken_atSign();
  6292. return;
  6293. case 35:
  6294. this.readToken_numberSign();
  6295. return;
  6296. case 92:
  6297. this.readWord();
  6298. return;
  6299. default:
  6300. if (isIdentifierStart(code)) {
  6301. this.readWord(code);
  6302. return;
  6303. }
  6304. }
  6305. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  6306. unexpected: String.fromCodePoint(code)
  6307. });
  6308. }
  6309. finishOp(type, size) {
  6310. const str = this.input.slice(this.state.pos, this.state.pos + size);
  6311. this.state.pos += size;
  6312. this.finishToken(type, str);
  6313. }
  6314. readRegexp() {
  6315. const startLoc = this.state.startLoc;
  6316. const start = this.state.start + 1;
  6317. let escaped, inClass;
  6318. let {
  6319. pos
  6320. } = this.state;
  6321. for (;; ++pos) {
  6322. if (pos >= this.length) {
  6323. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6324. }
  6325. const ch = this.input.charCodeAt(pos);
  6326. if (isNewLine(ch)) {
  6327. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6328. }
  6329. if (escaped) {
  6330. escaped = false;
  6331. } else {
  6332. if (ch === 91) {
  6333. inClass = true;
  6334. } else if (ch === 93 && inClass) {
  6335. inClass = false;
  6336. } else if (ch === 47 && !inClass) {
  6337. break;
  6338. }
  6339. escaped = ch === 92;
  6340. }
  6341. }
  6342. const content = this.input.slice(start, pos);
  6343. ++pos;
  6344. let mods = "";
  6345. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  6346. while (pos < this.length) {
  6347. const cp = this.codePointAtPos(pos);
  6348. const char = String.fromCharCode(cp);
  6349. if (VALID_REGEX_FLAGS.has(cp)) {
  6350. if (cp === 118) {
  6351. if (mods.includes("u")) {
  6352. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6353. }
  6354. } else if (cp === 117) {
  6355. if (mods.includes("v")) {
  6356. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6357. }
  6358. }
  6359. if (mods.includes(char)) {
  6360. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  6361. }
  6362. } else if (isIdentifierChar(cp) || cp === 92) {
  6363. this.raise(Errors.MalformedRegExpFlags, nextPos());
  6364. } else {
  6365. break;
  6366. }
  6367. ++pos;
  6368. mods += char;
  6369. }
  6370. this.state.pos = pos;
  6371. this.finishToken(138, {
  6372. pattern: content,
  6373. flags: mods
  6374. });
  6375. }
  6376. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  6377. const {
  6378. n,
  6379. pos
  6380. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  6381. this.state.pos = pos;
  6382. return n;
  6383. }
  6384. readRadixNumber(radix) {
  6385. const start = this.state.pos;
  6386. const startLoc = this.state.curPosition();
  6387. let isBigInt = false;
  6388. this.state.pos += 2;
  6389. const val = this.readInt(radix);
  6390. if (val == null) {
  6391. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  6392. radix
  6393. });
  6394. }
  6395. const next = this.input.charCodeAt(this.state.pos);
  6396. if (next === 110) {
  6397. ++this.state.pos;
  6398. isBigInt = true;
  6399. } else if (next === 109) {
  6400. throw this.raise(Errors.InvalidDecimal, startLoc);
  6401. }
  6402. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6403. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6404. }
  6405. if (isBigInt) {
  6406. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  6407. this.finishToken(136, str);
  6408. return;
  6409. }
  6410. this.finishToken(135, val);
  6411. }
  6412. readNumber(startsWithDot) {
  6413. const start = this.state.pos;
  6414. const startLoc = this.state.curPosition();
  6415. let isFloat = false;
  6416. let isBigInt = false;
  6417. let hasExponent = false;
  6418. let isOctal = false;
  6419. if (!startsWithDot && this.readInt(10) === null) {
  6420. this.raise(Errors.InvalidNumber, this.state.curPosition());
  6421. }
  6422. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  6423. if (hasLeadingZero) {
  6424. const integer = this.input.slice(start, this.state.pos);
  6425. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  6426. if (!this.state.strict) {
  6427. const underscorePos = integer.indexOf("_");
  6428. if (underscorePos > 0) {
  6429. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  6430. }
  6431. }
  6432. isOctal = hasLeadingZero && !/[89]/.test(integer);
  6433. }
  6434. let next = this.input.charCodeAt(this.state.pos);
  6435. if (next === 46 && !isOctal) {
  6436. ++this.state.pos;
  6437. this.readInt(10);
  6438. isFloat = true;
  6439. next = this.input.charCodeAt(this.state.pos);
  6440. }
  6441. if ((next === 69 || next === 101) && !isOctal) {
  6442. next = this.input.charCodeAt(++this.state.pos);
  6443. if (next === 43 || next === 45) {
  6444. ++this.state.pos;
  6445. }
  6446. if (this.readInt(10) === null) {
  6447. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  6448. }
  6449. isFloat = true;
  6450. hasExponent = true;
  6451. next = this.input.charCodeAt(this.state.pos);
  6452. }
  6453. if (next === 110) {
  6454. if (isFloat || hasLeadingZero) {
  6455. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  6456. }
  6457. ++this.state.pos;
  6458. isBigInt = true;
  6459. }
  6460. if (next === 109) {
  6461. this.expectPlugin("decimal", this.state.curPosition());
  6462. if (hasExponent || hasLeadingZero) {
  6463. this.raise(Errors.InvalidDecimal, startLoc);
  6464. }
  6465. ++this.state.pos;
  6466. var isDecimal = true;
  6467. }
  6468. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6469. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6470. }
  6471. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  6472. if (isBigInt) {
  6473. this.finishToken(136, str);
  6474. return;
  6475. }
  6476. if (isDecimal) {
  6477. this.finishToken(137, str);
  6478. return;
  6479. }
  6480. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  6481. this.finishToken(135, val);
  6482. }
  6483. readCodePoint(throwOnInvalid) {
  6484. const {
  6485. code,
  6486. pos
  6487. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  6488. this.state.pos = pos;
  6489. return code;
  6490. }
  6491. readString(quote) {
  6492. const {
  6493. str,
  6494. pos,
  6495. curLine,
  6496. lineStart
  6497. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  6498. this.state.pos = pos + 1;
  6499. this.state.lineStart = lineStart;
  6500. this.state.curLine = curLine;
  6501. this.finishToken(134, str);
  6502. }
  6503. readTemplateContinuation() {
  6504. if (!this.match(8)) {
  6505. this.unexpected(null, 8);
  6506. }
  6507. this.state.pos--;
  6508. this.readTemplateToken();
  6509. }
  6510. readTemplateToken() {
  6511. const opening = this.input[this.state.pos];
  6512. const {
  6513. str,
  6514. firstInvalidLoc,
  6515. pos,
  6516. curLine,
  6517. lineStart
  6518. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  6519. this.state.pos = pos + 1;
  6520. this.state.lineStart = lineStart;
  6521. this.state.curLine = curLine;
  6522. if (firstInvalidLoc) {
  6523. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  6524. }
  6525. if (this.input.codePointAt(pos) === 96) {
  6526. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  6527. } else {
  6528. this.state.pos++;
  6529. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  6530. }
  6531. }
  6532. recordStrictModeErrors(toParseError, at) {
  6533. const index = at.index;
  6534. if (this.state.strict && !this.state.strictErrors.has(index)) {
  6535. this.raise(toParseError, at);
  6536. } else {
  6537. this.state.strictErrors.set(index, [toParseError, at]);
  6538. }
  6539. }
  6540. readWord1(firstCode) {
  6541. this.state.containsEsc = false;
  6542. let word = "";
  6543. const start = this.state.pos;
  6544. let chunkStart = this.state.pos;
  6545. if (firstCode !== undefined) {
  6546. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  6547. }
  6548. while (this.state.pos < this.length) {
  6549. const ch = this.codePointAtPos(this.state.pos);
  6550. if (isIdentifierChar(ch)) {
  6551. this.state.pos += ch <= 0xffff ? 1 : 2;
  6552. } else if (ch === 92) {
  6553. this.state.containsEsc = true;
  6554. word += this.input.slice(chunkStart, this.state.pos);
  6555. const escStart = this.state.curPosition();
  6556. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  6557. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  6558. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  6559. chunkStart = this.state.pos - 1;
  6560. continue;
  6561. }
  6562. ++this.state.pos;
  6563. const esc = this.readCodePoint(true);
  6564. if (esc !== null) {
  6565. if (!identifierCheck(esc)) {
  6566. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  6567. }
  6568. word += String.fromCodePoint(esc);
  6569. }
  6570. chunkStart = this.state.pos;
  6571. } else {
  6572. break;
  6573. }
  6574. }
  6575. return word + this.input.slice(chunkStart, this.state.pos);
  6576. }
  6577. readWord(firstCode) {
  6578. const word = this.readWord1(firstCode);
  6579. const type = keywords$1.get(word);
  6580. if (type !== undefined) {
  6581. this.finishToken(type, tokenLabelName(type));
  6582. } else {
  6583. this.finishToken(132, word);
  6584. }
  6585. }
  6586. checkKeywordEscapes() {
  6587. const {
  6588. type
  6589. } = this.state;
  6590. if (tokenIsKeyword(type) && this.state.containsEsc) {
  6591. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  6592. reservedWord: tokenLabelName(type)
  6593. });
  6594. }
  6595. }
  6596. raise(toParseError, at, details = {}) {
  6597. const loc = at instanceof Position ? at : at.loc.start;
  6598. const error = toParseError(loc, details);
  6599. if (!(this.optionFlags & 2048)) throw error;
  6600. if (!this.isLookahead) this.state.errors.push(error);
  6601. return error;
  6602. }
  6603. raiseOverwrite(toParseError, at, details = {}) {
  6604. const loc = at instanceof Position ? at : at.loc.start;
  6605. const pos = loc.index;
  6606. const errors = this.state.errors;
  6607. for (let i = errors.length - 1; i >= 0; i--) {
  6608. const error = errors[i];
  6609. if (error.loc.index === pos) {
  6610. return errors[i] = toParseError(loc, details);
  6611. }
  6612. if (error.loc.index < pos) break;
  6613. }
  6614. return this.raise(toParseError, at, details);
  6615. }
  6616. updateContext(prevType) {}
  6617. unexpected(loc, type) {
  6618. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  6619. expected: type ? tokenLabelName(type) : null
  6620. });
  6621. }
  6622. expectPlugin(pluginName, loc) {
  6623. if (this.hasPlugin(pluginName)) {
  6624. return true;
  6625. }
  6626. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  6627. missingPlugin: [pluginName]
  6628. });
  6629. }
  6630. expectOnePlugin(pluginNames) {
  6631. if (!pluginNames.some(name => this.hasPlugin(name))) {
  6632. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  6633. missingPlugin: pluginNames
  6634. });
  6635. }
  6636. }
  6637. errorBuilder(error) {
  6638. return (pos, lineStart, curLine) => {
  6639. this.raise(error, buildPosition(pos, lineStart, curLine));
  6640. };
  6641. }
  6642. }
  6643. class ClassScope {
  6644. constructor() {
  6645. this.privateNames = new Set();
  6646. this.loneAccessors = new Map();
  6647. this.undefinedPrivateNames = new Map();
  6648. }
  6649. }
  6650. class ClassScopeHandler {
  6651. constructor(parser) {
  6652. this.parser = void 0;
  6653. this.stack = [];
  6654. this.undefinedPrivateNames = new Map();
  6655. this.parser = parser;
  6656. }
  6657. current() {
  6658. return this.stack[this.stack.length - 1];
  6659. }
  6660. enter() {
  6661. this.stack.push(new ClassScope());
  6662. }
  6663. exit() {
  6664. const oldClassScope = this.stack.pop();
  6665. const current = this.current();
  6666. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  6667. if (current) {
  6668. if (!current.undefinedPrivateNames.has(name)) {
  6669. current.undefinedPrivateNames.set(name, loc);
  6670. }
  6671. } else {
  6672. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6673. identifierName: name
  6674. });
  6675. }
  6676. }
  6677. }
  6678. declarePrivateName(name, elementType, loc) {
  6679. const {
  6680. privateNames,
  6681. loneAccessors,
  6682. undefinedPrivateNames
  6683. } = this.current();
  6684. let redefined = privateNames.has(name);
  6685. if (elementType & 3) {
  6686. const accessor = redefined && loneAccessors.get(name);
  6687. if (accessor) {
  6688. const oldStatic = accessor & 4;
  6689. const newStatic = elementType & 4;
  6690. const oldKind = accessor & 3;
  6691. const newKind = elementType & 3;
  6692. redefined = oldKind === newKind || oldStatic !== newStatic;
  6693. if (!redefined) loneAccessors.delete(name);
  6694. } else if (!redefined) {
  6695. loneAccessors.set(name, elementType);
  6696. }
  6697. }
  6698. if (redefined) {
  6699. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  6700. identifierName: name
  6701. });
  6702. }
  6703. privateNames.add(name);
  6704. undefinedPrivateNames.delete(name);
  6705. }
  6706. usePrivateName(name, loc) {
  6707. let classScope;
  6708. for (classScope of this.stack) {
  6709. if (classScope.privateNames.has(name)) return;
  6710. }
  6711. if (classScope) {
  6712. classScope.undefinedPrivateNames.set(name, loc);
  6713. } else {
  6714. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6715. identifierName: name
  6716. });
  6717. }
  6718. }
  6719. }
  6720. class ExpressionScope {
  6721. constructor(type = 0) {
  6722. this.type = type;
  6723. }
  6724. canBeArrowParameterDeclaration() {
  6725. return this.type === 2 || this.type === 1;
  6726. }
  6727. isCertainlyParameterDeclaration() {
  6728. return this.type === 3;
  6729. }
  6730. }
  6731. class ArrowHeadParsingScope extends ExpressionScope {
  6732. constructor(type) {
  6733. super(type);
  6734. this.declarationErrors = new Map();
  6735. }
  6736. recordDeclarationError(ParsingErrorClass, at) {
  6737. const index = at.index;
  6738. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  6739. }
  6740. clearDeclarationError(index) {
  6741. this.declarationErrors.delete(index);
  6742. }
  6743. iterateErrors(iterator) {
  6744. this.declarationErrors.forEach(iterator);
  6745. }
  6746. }
  6747. class ExpressionScopeHandler {
  6748. constructor(parser) {
  6749. this.parser = void 0;
  6750. this.stack = [new ExpressionScope()];
  6751. this.parser = parser;
  6752. }
  6753. enter(scope) {
  6754. this.stack.push(scope);
  6755. }
  6756. exit() {
  6757. this.stack.pop();
  6758. }
  6759. recordParameterInitializerError(toParseError, node) {
  6760. const origin = node.loc.start;
  6761. const {
  6762. stack
  6763. } = this;
  6764. let i = stack.length - 1;
  6765. let scope = stack[i];
  6766. while (!scope.isCertainlyParameterDeclaration()) {
  6767. if (scope.canBeArrowParameterDeclaration()) {
  6768. scope.recordDeclarationError(toParseError, origin);
  6769. } else {
  6770. return;
  6771. }
  6772. scope = stack[--i];
  6773. }
  6774. this.parser.raise(toParseError, origin);
  6775. }
  6776. recordArrowParameterBindingError(error, node) {
  6777. const {
  6778. stack
  6779. } = this;
  6780. const scope = stack[stack.length - 1];
  6781. const origin = node.loc.start;
  6782. if (scope.isCertainlyParameterDeclaration()) {
  6783. this.parser.raise(error, origin);
  6784. } else if (scope.canBeArrowParameterDeclaration()) {
  6785. scope.recordDeclarationError(error, origin);
  6786. } else {
  6787. return;
  6788. }
  6789. }
  6790. recordAsyncArrowParametersError(at) {
  6791. const {
  6792. stack
  6793. } = this;
  6794. let i = stack.length - 1;
  6795. let scope = stack[i];
  6796. while (scope.canBeArrowParameterDeclaration()) {
  6797. if (scope.type === 2) {
  6798. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  6799. }
  6800. scope = stack[--i];
  6801. }
  6802. }
  6803. validateAsPattern() {
  6804. const {
  6805. stack
  6806. } = this;
  6807. const currentScope = stack[stack.length - 1];
  6808. if (!currentScope.canBeArrowParameterDeclaration()) return;
  6809. currentScope.iterateErrors(([toParseError, loc]) => {
  6810. this.parser.raise(toParseError, loc);
  6811. let i = stack.length - 2;
  6812. let scope = stack[i];
  6813. while (scope.canBeArrowParameterDeclaration()) {
  6814. scope.clearDeclarationError(loc.index);
  6815. scope = stack[--i];
  6816. }
  6817. });
  6818. }
  6819. }
  6820. function newParameterDeclarationScope() {
  6821. return new ExpressionScope(3);
  6822. }
  6823. function newArrowHeadScope() {
  6824. return new ArrowHeadParsingScope(1);
  6825. }
  6826. function newAsyncArrowScope() {
  6827. return new ArrowHeadParsingScope(2);
  6828. }
  6829. function newExpressionScope() {
  6830. return new ExpressionScope();
  6831. }
  6832. class UtilParser extends Tokenizer {
  6833. addExtra(node, key, value, enumerable = true) {
  6834. if (!node) return;
  6835. let {
  6836. extra
  6837. } = node;
  6838. if (extra == null) {
  6839. extra = {};
  6840. node.extra = extra;
  6841. }
  6842. if (enumerable) {
  6843. extra[key] = value;
  6844. } else {
  6845. Object.defineProperty(extra, key, {
  6846. enumerable,
  6847. value
  6848. });
  6849. }
  6850. }
  6851. isContextual(token) {
  6852. return this.state.type === token && !this.state.containsEsc;
  6853. }
  6854. isUnparsedContextual(nameStart, name) {
  6855. if (this.input.startsWith(name, nameStart)) {
  6856. const nextCh = this.input.charCodeAt(nameStart + name.length);
  6857. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  6858. }
  6859. return false;
  6860. }
  6861. isLookaheadContextual(name) {
  6862. const next = this.nextTokenStart();
  6863. return this.isUnparsedContextual(next, name);
  6864. }
  6865. eatContextual(token) {
  6866. if (this.isContextual(token)) {
  6867. this.next();
  6868. return true;
  6869. }
  6870. return false;
  6871. }
  6872. expectContextual(token, toParseError) {
  6873. if (!this.eatContextual(token)) {
  6874. if (toParseError != null) {
  6875. throw this.raise(toParseError, this.state.startLoc);
  6876. }
  6877. this.unexpected(null, token);
  6878. }
  6879. }
  6880. canInsertSemicolon() {
  6881. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  6882. }
  6883. hasPrecedingLineBreak() {
  6884. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  6885. }
  6886. hasFollowingLineBreak() {
  6887. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  6888. }
  6889. isLineTerminator() {
  6890. return this.eat(13) || this.canInsertSemicolon();
  6891. }
  6892. semicolon(allowAsi = true) {
  6893. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  6894. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  6895. }
  6896. expect(type, loc) {
  6897. if (!this.eat(type)) {
  6898. this.unexpected(loc, type);
  6899. }
  6900. }
  6901. tryParse(fn, oldState = this.state.clone()) {
  6902. const abortSignal = {
  6903. node: null
  6904. };
  6905. try {
  6906. const node = fn((node = null) => {
  6907. abortSignal.node = node;
  6908. throw abortSignal;
  6909. });
  6910. if (this.state.errors.length > oldState.errors.length) {
  6911. const failState = this.state;
  6912. this.state = oldState;
  6913. this.state.tokensLength = failState.tokensLength;
  6914. return {
  6915. node,
  6916. error: failState.errors[oldState.errors.length],
  6917. thrown: false,
  6918. aborted: false,
  6919. failState
  6920. };
  6921. }
  6922. return {
  6923. node: node,
  6924. error: null,
  6925. thrown: false,
  6926. aborted: false,
  6927. failState: null
  6928. };
  6929. } catch (error) {
  6930. const failState = this.state;
  6931. this.state = oldState;
  6932. if (error instanceof SyntaxError) {
  6933. return {
  6934. node: null,
  6935. error,
  6936. thrown: true,
  6937. aborted: false,
  6938. failState
  6939. };
  6940. }
  6941. if (error === abortSignal) {
  6942. return {
  6943. node: abortSignal.node,
  6944. error: null,
  6945. thrown: false,
  6946. aborted: true,
  6947. failState
  6948. };
  6949. }
  6950. throw error;
  6951. }
  6952. }
  6953. checkExpressionErrors(refExpressionErrors, andThrow) {
  6954. if (!refExpressionErrors) return false;
  6955. const {
  6956. shorthandAssignLoc,
  6957. doubleProtoLoc,
  6958. privateKeyLoc,
  6959. optionalParametersLoc,
  6960. voidPatternLoc
  6961. } = refExpressionErrors;
  6962. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
  6963. if (!andThrow) {
  6964. return hasErrors;
  6965. }
  6966. if (shorthandAssignLoc != null) {
  6967. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  6968. }
  6969. if (doubleProtoLoc != null) {
  6970. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  6971. }
  6972. if (privateKeyLoc != null) {
  6973. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  6974. }
  6975. if (optionalParametersLoc != null) {
  6976. this.unexpected(optionalParametersLoc);
  6977. }
  6978. if (voidPatternLoc != null) {
  6979. this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
  6980. }
  6981. }
  6982. isLiteralPropertyName() {
  6983. return tokenIsLiteralPropertyName(this.state.type);
  6984. }
  6985. isPrivateName(node) {
  6986. return node.type === "PrivateName";
  6987. }
  6988. getPrivateNameSV(node) {
  6989. return node.id.name;
  6990. }
  6991. hasPropertyAsPrivateName(node) {
  6992. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  6993. }
  6994. isObjectProperty(node) {
  6995. return node.type === "ObjectProperty";
  6996. }
  6997. isObjectMethod(node) {
  6998. return node.type === "ObjectMethod";
  6999. }
  7000. initializeScopes(inModule = this.options.sourceType === "module") {
  7001. const oldLabels = this.state.labels;
  7002. this.state.labels = [];
  7003. const oldExportedIdentifiers = this.exportedIdentifiers;
  7004. this.exportedIdentifiers = new Set();
  7005. const oldInModule = this.inModule;
  7006. this.inModule = inModule;
  7007. const oldScope = this.scope;
  7008. const ScopeHandler = this.getScopeHandler();
  7009. this.scope = new ScopeHandler(this, inModule);
  7010. const oldProdParam = this.prodParam;
  7011. this.prodParam = new ProductionParameterHandler();
  7012. const oldClassScope = this.classScope;
  7013. this.classScope = new ClassScopeHandler(this);
  7014. const oldExpressionScope = this.expressionScope;
  7015. this.expressionScope = new ExpressionScopeHandler(this);
  7016. return () => {
  7017. this.state.labels = oldLabels;
  7018. this.exportedIdentifiers = oldExportedIdentifiers;
  7019. this.inModule = oldInModule;
  7020. this.scope = oldScope;
  7021. this.prodParam = oldProdParam;
  7022. this.classScope = oldClassScope;
  7023. this.expressionScope = oldExpressionScope;
  7024. };
  7025. }
  7026. enterInitialScopes() {
  7027. let paramFlags = 0;
  7028. if (this.inModule || this.optionFlags & 1) {
  7029. paramFlags |= 2;
  7030. }
  7031. if (this.optionFlags & 32) {
  7032. paramFlags |= 1;
  7033. }
  7034. const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
  7035. if (isCommonJS || this.optionFlags & 2) {
  7036. paramFlags |= 4;
  7037. }
  7038. this.prodParam.enter(paramFlags);
  7039. let scopeFlags = isCommonJS ? 514 : 1;
  7040. if (this.optionFlags & 4) {
  7041. scopeFlags |= 512;
  7042. }
  7043. this.scope.enter(scopeFlags);
  7044. }
  7045. checkDestructuringPrivate(refExpressionErrors) {
  7046. const {
  7047. privateKeyLoc
  7048. } = refExpressionErrors;
  7049. if (privateKeyLoc !== null) {
  7050. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  7051. }
  7052. }
  7053. }
  7054. class ExpressionErrors {
  7055. constructor() {
  7056. this.shorthandAssignLoc = null;
  7057. this.doubleProtoLoc = null;
  7058. this.privateKeyLoc = null;
  7059. this.optionalParametersLoc = null;
  7060. this.voidPatternLoc = null;
  7061. }
  7062. }
  7063. class Node {
  7064. constructor(parser, pos, loc) {
  7065. this.type = "";
  7066. this.start = pos;
  7067. this.end = 0;
  7068. this.loc = new SourceLocation(loc);
  7069. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  7070. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  7071. }
  7072. }
  7073. const NodePrototype = Node.prototype;
  7074. NodePrototype.__clone = function () {
  7075. const newNode = new Node(undefined, this.start, this.loc.start);
  7076. const keys = Object.keys(this);
  7077. for (let i = 0, length = keys.length; i < length; i++) {
  7078. const key = keys[i];
  7079. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  7080. newNode[key] = this[key];
  7081. }
  7082. }
  7083. return newNode;
  7084. };
  7085. class NodeUtils extends UtilParser {
  7086. startNode() {
  7087. const loc = this.state.startLoc;
  7088. return new Node(this, loc.index, loc);
  7089. }
  7090. startNodeAt(loc) {
  7091. return new Node(this, loc.index, loc);
  7092. }
  7093. startNodeAtNode(type) {
  7094. return this.startNodeAt(type.loc.start);
  7095. }
  7096. finishNode(node, type) {
  7097. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  7098. }
  7099. finishNodeAt(node, type, endLoc) {
  7100. node.type = type;
  7101. node.end = endLoc.index;
  7102. node.loc.end = endLoc;
  7103. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7104. if (this.optionFlags & 4096) {
  7105. this.processComment(node);
  7106. }
  7107. return node;
  7108. }
  7109. resetStartLocation(node, startLoc) {
  7110. node.start = startLoc.index;
  7111. node.loc.start = startLoc;
  7112. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  7113. }
  7114. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  7115. node.end = endLoc.index;
  7116. node.loc.end = endLoc;
  7117. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7118. }
  7119. resetStartLocationFromNode(node, locationNode) {
  7120. this.resetStartLocation(node, locationNode.loc.start);
  7121. }
  7122. castNodeTo(node, type) {
  7123. node.type = type;
  7124. return node;
  7125. }
  7126. cloneIdentifier(node) {
  7127. const {
  7128. type,
  7129. start,
  7130. end,
  7131. loc,
  7132. range,
  7133. name
  7134. } = node;
  7135. const cloned = Object.create(NodePrototype);
  7136. cloned.type = type;
  7137. cloned.start = start;
  7138. cloned.end = end;
  7139. cloned.loc = loc;
  7140. cloned.range = range;
  7141. cloned.name = name;
  7142. if (node.extra) cloned.extra = node.extra;
  7143. return cloned;
  7144. }
  7145. cloneStringLiteral(node) {
  7146. const {
  7147. type,
  7148. start,
  7149. end,
  7150. loc,
  7151. range,
  7152. extra
  7153. } = node;
  7154. const cloned = Object.create(NodePrototype);
  7155. cloned.type = type;
  7156. cloned.start = start;
  7157. cloned.end = end;
  7158. cloned.loc = loc;
  7159. cloned.range = range;
  7160. cloned.extra = extra;
  7161. cloned.value = node.value;
  7162. return cloned;
  7163. }
  7164. }
  7165. const unwrapParenthesizedExpression = node => {
  7166. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7167. };
  7168. class LValParser extends NodeUtils {
  7169. toAssignable(node, isLHS = false) {
  7170. var _node$extra, _node$extra3;
  7171. let parenthesized = undefined;
  7172. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7173. parenthesized = unwrapParenthesizedExpression(node);
  7174. if (isLHS) {
  7175. if (parenthesized.type === "Identifier") {
  7176. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7177. } else if (parenthesized.type !== "CallExpression" && parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7178. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7179. }
  7180. } else {
  7181. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7182. }
  7183. }
  7184. switch (node.type) {
  7185. case "Identifier":
  7186. case "ObjectPattern":
  7187. case "ArrayPattern":
  7188. case "AssignmentPattern":
  7189. case "RestElement":
  7190. case "VoidPattern":
  7191. break;
  7192. case "ObjectExpression":
  7193. this.castNodeTo(node, "ObjectPattern");
  7194. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7195. var _node$extra2;
  7196. const prop = node.properties[i];
  7197. const isLast = i === last;
  7198. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7199. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7200. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7201. }
  7202. }
  7203. break;
  7204. case "ObjectProperty":
  7205. {
  7206. const {
  7207. key,
  7208. value
  7209. } = node;
  7210. if (this.isPrivateName(key)) {
  7211. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7212. }
  7213. this.toAssignable(value, isLHS);
  7214. break;
  7215. }
  7216. case "SpreadElement":
  7217. {
  7218. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7219. }
  7220. case "ArrayExpression":
  7221. this.castNodeTo(node, "ArrayPattern");
  7222. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7223. break;
  7224. case "AssignmentExpression":
  7225. if (node.operator !== "=") {
  7226. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7227. }
  7228. this.castNodeTo(node, "AssignmentPattern");
  7229. delete node.operator;
  7230. if (node.left.type === "VoidPattern") {
  7231. this.raise(Errors.VoidPatternInitializer, node.left);
  7232. }
  7233. this.toAssignable(node.left, isLHS);
  7234. break;
  7235. case "ParenthesizedExpression":
  7236. this.toAssignable(parenthesized, isLHS);
  7237. break;
  7238. }
  7239. }
  7240. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7241. if (prop.type === "ObjectMethod") {
  7242. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7243. } else if (prop.type === "SpreadElement") {
  7244. this.castNodeTo(prop, "RestElement");
  7245. const arg = prop.argument;
  7246. this.checkToRestConversion(arg, false);
  7247. this.toAssignable(arg, isLHS);
  7248. if (!isLast) {
  7249. this.raise(Errors.RestTrailingComma, prop);
  7250. }
  7251. } else {
  7252. this.toAssignable(prop, isLHS);
  7253. }
  7254. }
  7255. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7256. const end = exprList.length - 1;
  7257. for (let i = 0; i <= end; i++) {
  7258. const elt = exprList[i];
  7259. if (!elt) continue;
  7260. this.toAssignableListItem(exprList, i, isLHS);
  7261. if (elt.type === "RestElement") {
  7262. if (i < end) {
  7263. this.raise(Errors.RestTrailingComma, elt);
  7264. } else if (trailingCommaLoc) {
  7265. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7266. }
  7267. }
  7268. }
  7269. }
  7270. toAssignableListItem(exprList, index, isLHS) {
  7271. const node = exprList[index];
  7272. if (node.type === "SpreadElement") {
  7273. this.castNodeTo(node, "RestElement");
  7274. const arg = node.argument;
  7275. this.checkToRestConversion(arg, true);
  7276. this.toAssignable(arg, isLHS);
  7277. } else {
  7278. this.toAssignable(node, isLHS);
  7279. }
  7280. }
  7281. isAssignable(node, isBinding) {
  7282. switch (node.type) {
  7283. case "Identifier":
  7284. case "ObjectPattern":
  7285. case "ArrayPattern":
  7286. case "AssignmentPattern":
  7287. case "RestElement":
  7288. case "VoidPattern":
  7289. return true;
  7290. case "ObjectExpression":
  7291. {
  7292. const last = node.properties.length - 1;
  7293. return node.properties.every((prop, i) => {
  7294. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7295. });
  7296. }
  7297. case "ObjectProperty":
  7298. return this.isAssignable(node.value);
  7299. case "SpreadElement":
  7300. return this.isAssignable(node.argument);
  7301. case "ArrayExpression":
  7302. return node.elements.every(element => element === null || this.isAssignable(element));
  7303. case "AssignmentExpression":
  7304. return node.operator === "=";
  7305. case "ParenthesizedExpression":
  7306. return this.isAssignable(node.expression);
  7307. case "MemberExpression":
  7308. case "OptionalMemberExpression":
  7309. return !isBinding;
  7310. default:
  7311. return false;
  7312. }
  7313. }
  7314. toReferencedList(exprList, isParenthesizedExpr) {
  7315. return exprList;
  7316. }
  7317. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7318. this.toReferencedList(exprList, isParenthesizedExpr);
  7319. for (const expr of exprList) {
  7320. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7321. this.toReferencedListDeep(expr.elements);
  7322. }
  7323. }
  7324. }
  7325. parseSpread(refExpressionErrors) {
  7326. const node = this.startNode();
  7327. this.next();
  7328. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7329. return this.finishNode(node, "SpreadElement");
  7330. }
  7331. parseRestBinding() {
  7332. const node = this.startNode();
  7333. this.next();
  7334. const argument = this.parseBindingAtom();
  7335. if (argument.type === "VoidPattern") {
  7336. this.raise(Errors.UnexpectedVoidPattern, argument);
  7337. }
  7338. node.argument = argument;
  7339. return this.finishNode(node, "RestElement");
  7340. }
  7341. parseBindingAtom() {
  7342. switch (this.state.type) {
  7343. case 0:
  7344. {
  7345. const node = this.startNode();
  7346. this.next();
  7347. node.elements = this.parseBindingList(3, 93, 1);
  7348. return this.finishNode(node, "ArrayPattern");
  7349. }
  7350. case 5:
  7351. return this.parseObjectLike(8, true);
  7352. case 88:
  7353. return this.parseVoidPattern(null);
  7354. }
  7355. return this.parseIdentifier();
  7356. }
  7357. parseBindingList(close, closeCharCode, flags) {
  7358. const allowEmpty = flags & 1;
  7359. const elts = [];
  7360. let first = true;
  7361. while (!this.eat(close)) {
  7362. if (first) {
  7363. first = false;
  7364. } else {
  7365. this.expect(12);
  7366. }
  7367. if (allowEmpty && this.match(12)) {
  7368. elts.push(null);
  7369. } else if (this.eat(close)) {
  7370. break;
  7371. } else if (this.match(21)) {
  7372. let rest = this.parseRestBinding();
  7373. if (this.hasPlugin("flow") || flags & 2) {
  7374. rest = this.parseFunctionParamType(rest);
  7375. }
  7376. elts.push(rest);
  7377. if (!this.checkCommaAfterRest(closeCharCode)) {
  7378. this.expect(close);
  7379. break;
  7380. }
  7381. } else {
  7382. const decorators = [];
  7383. if (flags & 2) {
  7384. if (this.match(26) && this.hasPlugin("decorators")) {
  7385. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7386. }
  7387. while (this.match(26)) {
  7388. decorators.push(this.parseDecorator());
  7389. }
  7390. }
  7391. elts.push(this.parseBindingElement(flags, decorators));
  7392. }
  7393. }
  7394. return elts;
  7395. }
  7396. parseBindingRestProperty(prop) {
  7397. this.next();
  7398. if (this.hasPlugin("discardBinding") && this.match(88)) {
  7399. prop.argument = this.parseVoidPattern(null);
  7400. this.raise(Errors.UnexpectedVoidPattern, prop.argument);
  7401. } else {
  7402. prop.argument = this.parseIdentifier();
  7403. }
  7404. this.checkCommaAfterRest(125);
  7405. return this.finishNode(prop, "RestElement");
  7406. }
  7407. parseBindingProperty() {
  7408. const {
  7409. type,
  7410. startLoc
  7411. } = this.state;
  7412. if (type === 21) {
  7413. return this.parseBindingRestProperty(this.startNode());
  7414. }
  7415. const prop = this.startNode();
  7416. if (type === 139) {
  7417. this.expectPlugin("destructuringPrivate", startLoc);
  7418. this.classScope.usePrivateName(this.state.value, startLoc);
  7419. prop.key = this.parsePrivateName();
  7420. } else {
  7421. this.parsePropertyName(prop);
  7422. }
  7423. prop.method = false;
  7424. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7425. }
  7426. parseBindingElement(flags, decorators) {
  7427. const left = this.parseMaybeDefault();
  7428. if (this.hasPlugin("flow") || flags & 2) {
  7429. this.parseFunctionParamType(left);
  7430. }
  7431. if (decorators.length) {
  7432. left.decorators = decorators;
  7433. this.resetStartLocationFromNode(left, decorators[0]);
  7434. }
  7435. const elt = this.parseMaybeDefault(left.loc.start, left);
  7436. return elt;
  7437. }
  7438. parseFunctionParamType(param) {
  7439. return param;
  7440. }
  7441. parseMaybeDefault(startLoc, left) {
  7442. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  7443. left = left != null ? left : this.parseBindingAtom();
  7444. if (!this.eat(29)) return left;
  7445. const node = this.startNodeAt(startLoc);
  7446. if (left.type === "VoidPattern") {
  7447. this.raise(Errors.VoidPatternInitializer, left);
  7448. }
  7449. node.left = left;
  7450. node.right = this.parseMaybeAssignAllowIn();
  7451. return this.finishNode(node, "AssignmentPattern");
  7452. }
  7453. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  7454. switch (type) {
  7455. case "AssignmentPattern":
  7456. return "left";
  7457. case "RestElement":
  7458. return "argument";
  7459. case "ObjectProperty":
  7460. return "value";
  7461. case "ParenthesizedExpression":
  7462. return "expression";
  7463. case "ArrayPattern":
  7464. return "elements";
  7465. case "ObjectPattern":
  7466. return "properties";
  7467. case "VoidPattern":
  7468. return true;
  7469. case "CallExpression":
  7470. if (!disallowCallExpression && !this.state.strict && this.optionFlags & 8192) {
  7471. return true;
  7472. }
  7473. }
  7474. return false;
  7475. }
  7476. isOptionalMemberExpression(expression) {
  7477. return expression.type === "OptionalMemberExpression";
  7478. }
  7479. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false, disallowCallExpression = false) {
  7480. var _expression$extra;
  7481. const type = expression.type;
  7482. if (this.isObjectMethod(expression)) return;
  7483. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7484. if (isOptionalMemberExpression || type === "MemberExpression") {
  7485. if (isOptionalMemberExpression) {
  7486. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7487. if (ancestor.type !== "AssignmentExpression") {
  7488. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7489. ancestor
  7490. });
  7491. }
  7492. }
  7493. if (binding !== 64) {
  7494. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7495. }
  7496. return;
  7497. }
  7498. if (type === "Identifier") {
  7499. this.checkIdentifier(expression, binding, strictModeChanged);
  7500. const {
  7501. name
  7502. } = expression;
  7503. if (checkClashes) {
  7504. if (checkClashes.has(name)) {
  7505. this.raise(Errors.ParamDupe, expression);
  7506. } else {
  7507. checkClashes.add(name);
  7508. }
  7509. }
  7510. return;
  7511. } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
  7512. this.raise(Errors.VoidPatternCatchClauseParam, expression);
  7513. }
  7514. const unwrappedExpression = unwrapParenthesizedExpression(expression);
  7515. disallowCallExpression || (disallowCallExpression = unwrappedExpression.type === "CallExpression" && (unwrappedExpression.callee.type === "Import" || unwrappedExpression.callee.type === "Super"));
  7516. const validity = this.isValidLVal(type, disallowCallExpression, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7517. if (validity === true) return;
  7518. if (validity === false) {
  7519. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7520. this.raise(ParseErrorClass, expression, {
  7521. ancestor
  7522. });
  7523. return;
  7524. }
  7525. let key, isParenthesizedExpression;
  7526. if (typeof validity === "string") {
  7527. key = validity;
  7528. isParenthesizedExpression = type === "ParenthesizedExpression";
  7529. } else {
  7530. [key, isParenthesizedExpression] = validity;
  7531. }
  7532. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7533. type
  7534. } : ancestor;
  7535. const val = expression[key];
  7536. if (Array.isArray(val)) {
  7537. for (const child of val) {
  7538. if (child) {
  7539. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, true);
  7540. }
  7541. }
  7542. } else if (val) {
  7543. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, disallowCallExpression);
  7544. }
  7545. }
  7546. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7547. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7548. if (bindingType === 64) {
  7549. this.raise(Errors.StrictEvalArguments, at, {
  7550. referenceName: at.name
  7551. });
  7552. } else {
  7553. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  7554. bindingName: at.name
  7555. });
  7556. }
  7557. }
  7558. if (bindingType & 8192 && at.name === "let") {
  7559. this.raise(Errors.LetInLexicalBinding, at);
  7560. }
  7561. if (!(bindingType & 64)) {
  7562. this.declareNameFromIdentifier(at, bindingType);
  7563. }
  7564. }
  7565. declareNameFromIdentifier(identifier, binding) {
  7566. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7567. }
  7568. checkToRestConversion(node, allowPattern) {
  7569. switch (node.type) {
  7570. case "ParenthesizedExpression":
  7571. this.checkToRestConversion(node.expression, allowPattern);
  7572. break;
  7573. case "Identifier":
  7574. case "MemberExpression":
  7575. break;
  7576. case "ArrayExpression":
  7577. case "ObjectExpression":
  7578. if (allowPattern) break;
  7579. default:
  7580. this.raise(Errors.InvalidRestAssignmentPattern, node);
  7581. }
  7582. }
  7583. checkCommaAfterRest(close) {
  7584. if (!this.match(12)) {
  7585. return false;
  7586. }
  7587. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  7588. return true;
  7589. }
  7590. }
  7591. const keywordAndTSRelationalOperator = /in(?:stanceof)?|as|satisfies/y;
  7592. function nonNull(x) {
  7593. if (x == null) {
  7594. throw new Error(`Unexpected ${x} value.`);
  7595. }
  7596. return x;
  7597. }
  7598. function assert(x) {
  7599. if (!x) {
  7600. throw new Error("Assert fail");
  7601. }
  7602. }
  7603. const TSErrors = ParseErrorEnum`typescript`({
  7604. AbstractMethodHasImplementation: ({
  7605. methodName
  7606. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7607. AbstractPropertyHasInitializer: ({
  7608. propertyName
  7609. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7610. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7611. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7612. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7613. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7614. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7615. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7616. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7617. DeclareAccessor: ({
  7618. kind
  7619. }) => `'declare' is not allowed in ${kind}ters.`,
  7620. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7621. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7622. DuplicateAccessibilityModifier: ({
  7623. modifier
  7624. }) => `Accessibility modifier already seen: '${modifier}'.`,
  7625. DuplicateModifier: ({
  7626. modifier
  7627. }) => `Duplicate modifier: '${modifier}'.`,
  7628. EmptyHeritageClauseType: ({
  7629. token
  7630. }) => `'${token}' list cannot be empty.`,
  7631. EmptyTypeArguments: "Type argument list cannot be empty.",
  7632. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7633. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7634. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7635. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7636. IncompatibleModifiers: ({
  7637. modifiers
  7638. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7639. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7640. IndexSignatureHasAccessibility: ({
  7641. modifier
  7642. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7643. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7644. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7645. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7646. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7647. InvalidHeritageClauseType: ({
  7648. token
  7649. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  7650. InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
  7651. InvalidModifierOnTypeMember: ({
  7652. modifier
  7653. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7654. InvalidModifierOnTypeParameter: ({
  7655. modifier
  7656. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7657. InvalidModifierOnTypeParameterPositions: ({
  7658. modifier
  7659. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7660. InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
  7661. InvalidModifiersOrder: ({
  7662. orderedModifiers
  7663. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7664. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7665. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7666. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7667. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7668. NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7669. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7670. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7671. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7672. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7673. PrivateElementHasAccessibility: ({
  7674. modifier
  7675. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7676. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7677. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7678. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7679. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7680. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7681. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7682. SingleTypeParameterWithoutTrailingComma: ({
  7683. typeParameterName
  7684. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7685. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7686. TupleOptionalAfterType: "A labeled tuple optional element must be declared using a question mark after the name and before the colon (`name?: type`), rather than after the type (`name: type?`).",
  7687. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7688. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7689. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7690. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7691. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7692. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7693. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7694. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7695. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7696. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7697. UnsupportedSignatureParameterKind: ({
  7698. type
  7699. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
  7700. UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
  7701. });
  7702. function keywordTypeFromName(value) {
  7703. switch (value) {
  7704. case "any":
  7705. return "TSAnyKeyword";
  7706. case "boolean":
  7707. return "TSBooleanKeyword";
  7708. case "bigint":
  7709. return "TSBigIntKeyword";
  7710. case "never":
  7711. return "TSNeverKeyword";
  7712. case "number":
  7713. return "TSNumberKeyword";
  7714. case "object":
  7715. return "TSObjectKeyword";
  7716. case "string":
  7717. return "TSStringKeyword";
  7718. case "symbol":
  7719. return "TSSymbolKeyword";
  7720. case "undefined":
  7721. return "TSUndefinedKeyword";
  7722. case "unknown":
  7723. return "TSUnknownKeyword";
  7724. default:
  7725. return undefined;
  7726. }
  7727. }
  7728. function tsIsAccessModifier(modifier) {
  7729. return modifier === "private" || modifier === "public" || modifier === "protected";
  7730. }
  7731. function tsIsVarianceAnnotations(modifier) {
  7732. return modifier === "in" || modifier === "out";
  7733. }
  7734. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7735. constructor(...args) {
  7736. super(...args);
  7737. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7738. allowedModifiers: ["in", "out"],
  7739. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7740. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7741. });
  7742. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7743. allowedModifiers: ["const"],
  7744. disallowedModifiers: ["in", "out"],
  7745. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7746. });
  7747. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7748. allowedModifiers: ["in", "out", "const"],
  7749. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7750. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7751. });
  7752. }
  7753. getScopeHandler() {
  7754. return TypeScriptScopeHandler;
  7755. }
  7756. tsIsIdentifier() {
  7757. return tokenIsIdentifier(this.state.type);
  7758. }
  7759. tsTokenCanFollowModifier() {
  7760. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  7761. }
  7762. tsNextTokenOnSameLineAndCanFollowModifier() {
  7763. this.next();
  7764. if (this.hasPrecedingLineBreak()) {
  7765. return false;
  7766. }
  7767. return this.tsTokenCanFollowModifier();
  7768. }
  7769. tsNextTokenCanFollowModifier() {
  7770. if (this.match(106)) {
  7771. this.next();
  7772. return this.tsTokenCanFollowModifier();
  7773. }
  7774. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  7775. }
  7776. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
  7777. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7778. return undefined;
  7779. }
  7780. const modifier = this.state.value;
  7781. if (allowedModifiers.includes(modifier)) {
  7782. if (hasSeenStaticModifier && this.match(106)) {
  7783. return undefined;
  7784. }
  7785. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7786. return undefined;
  7787. }
  7788. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7789. return modifier;
  7790. }
  7791. }
  7792. return undefined;
  7793. }
  7794. tsParseModifiers({
  7795. allowedModifiers,
  7796. disallowedModifiers,
  7797. stopOnStartOfClassStaticBlock,
  7798. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7799. }, modified) {
  7800. const enforceOrder = (loc, modifier, before, after) => {
  7801. if (modifier === before && modified[after]) {
  7802. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7803. orderedModifiers: [before, after]
  7804. });
  7805. }
  7806. };
  7807. const incompatible = (loc, modifier, mod1, mod2) => {
  7808. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7809. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7810. modifiers: [mod1, mod2]
  7811. });
  7812. }
  7813. };
  7814. for (;;) {
  7815. const {
  7816. startLoc
  7817. } = this.state;
  7818. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
  7819. if (!modifier) break;
  7820. if (tsIsAccessModifier(modifier)) {
  7821. if (modified.accessibility) {
  7822. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7823. modifier
  7824. });
  7825. } else {
  7826. enforceOrder(startLoc, modifier, modifier, "override");
  7827. enforceOrder(startLoc, modifier, modifier, "static");
  7828. enforceOrder(startLoc, modifier, modifier, "readonly");
  7829. modified.accessibility = modifier;
  7830. }
  7831. } else if (tsIsVarianceAnnotations(modifier)) {
  7832. if (modified[modifier]) {
  7833. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7834. modifier
  7835. });
  7836. }
  7837. modified[modifier] = true;
  7838. enforceOrder(startLoc, modifier, "in", "out");
  7839. } else {
  7840. if (hasOwnProperty.call(modified, modifier)) {
  7841. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7842. modifier
  7843. });
  7844. } else {
  7845. enforceOrder(startLoc, modifier, "static", "readonly");
  7846. enforceOrder(startLoc, modifier, "static", "override");
  7847. enforceOrder(startLoc, modifier, "override", "readonly");
  7848. enforceOrder(startLoc, modifier, "abstract", "override");
  7849. incompatible(startLoc, modifier, "declare", "override");
  7850. incompatible(startLoc, modifier, "static", "abstract");
  7851. }
  7852. modified[modifier] = true;
  7853. }
  7854. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7855. this.raise(errorTemplate, startLoc, {
  7856. modifier
  7857. });
  7858. }
  7859. }
  7860. }
  7861. tsIsListTerminator(kind) {
  7862. switch (kind) {
  7863. case "EnumMembers":
  7864. case "TypeMembers":
  7865. return this.match(8);
  7866. case "HeritageClauseElement":
  7867. return this.match(5);
  7868. case "TupleElementTypes":
  7869. return this.match(3);
  7870. case "TypeParametersOrArguments":
  7871. return this.match(48);
  7872. }
  7873. }
  7874. tsParseList(kind, parseElement) {
  7875. const result = [];
  7876. while (!this.tsIsListTerminator(kind)) {
  7877. result.push(parseElement());
  7878. }
  7879. return result;
  7880. }
  7881. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7882. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7883. }
  7884. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7885. const result = [];
  7886. let trailingCommaPos = -1;
  7887. for (;;) {
  7888. if (this.tsIsListTerminator(kind)) {
  7889. break;
  7890. }
  7891. trailingCommaPos = -1;
  7892. const element = parseElement();
  7893. if (element == null) {
  7894. return undefined;
  7895. }
  7896. result.push(element);
  7897. if (this.eat(12)) {
  7898. trailingCommaPos = this.state.lastTokStartLoc.index;
  7899. continue;
  7900. }
  7901. if (this.tsIsListTerminator(kind)) {
  7902. break;
  7903. }
  7904. if (expectSuccess) {
  7905. this.expect(12);
  7906. }
  7907. return undefined;
  7908. }
  7909. if (refTrailingCommaPos) {
  7910. refTrailingCommaPos.value = trailingCommaPos;
  7911. }
  7912. return result;
  7913. }
  7914. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7915. if (!skipFirstToken) {
  7916. if (bracket) {
  7917. this.expect(0);
  7918. } else {
  7919. this.expect(47);
  7920. }
  7921. }
  7922. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7923. if (bracket) {
  7924. this.expect(3);
  7925. } else {
  7926. this.expect(48);
  7927. }
  7928. return result;
  7929. }
  7930. tsParseImportType() {
  7931. const node = this.startNode();
  7932. this.expect(83);
  7933. this.expect(10);
  7934. if (!this.match(134)) {
  7935. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7936. node.argument = super.parseExprAtom();
  7937. } else {
  7938. node.argument = this.parseStringLiteral(this.state.value);
  7939. }
  7940. if (this.eat(12)) {
  7941. node.options = this.tsParseImportTypeOptions();
  7942. } else {
  7943. node.options = null;
  7944. }
  7945. this.expect(11);
  7946. if (this.eat(16)) {
  7947. node.qualifier = this.tsParseEntityName(1 | 2);
  7948. }
  7949. if (this.match(47)) {
  7950. node.typeParameters = this.tsParseTypeArguments();
  7951. }
  7952. return this.finishNode(node, "TSImportType");
  7953. }
  7954. tsParseImportTypeOptions() {
  7955. const node = this.startNode();
  7956. this.expect(5);
  7957. const withProperty = this.startNode();
  7958. if (this.isContextual(76)) {
  7959. withProperty.method = false;
  7960. withProperty.key = this.parseIdentifier(true);
  7961. withProperty.computed = false;
  7962. withProperty.shorthand = false;
  7963. } else {
  7964. this.unexpected(null, 76);
  7965. }
  7966. this.expect(14);
  7967. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  7968. node.properties = [this.finishObjectProperty(withProperty)];
  7969. this.eat(12);
  7970. this.expect(8);
  7971. return this.finishNode(node, "ObjectExpression");
  7972. }
  7973. tsParseImportTypeWithPropertyValue() {
  7974. const node = this.startNode();
  7975. const properties = [];
  7976. this.expect(5);
  7977. while (!this.match(8)) {
  7978. const type = this.state.type;
  7979. if (tokenIsIdentifier(type) || type === 134) {
  7980. properties.push(super.parsePropertyDefinition(null));
  7981. } else {
  7982. this.unexpected();
  7983. }
  7984. this.eat(12);
  7985. }
  7986. node.properties = properties;
  7987. this.next();
  7988. return this.finishNode(node, "ObjectExpression");
  7989. }
  7990. tsParseEntityName(flags) {
  7991. let entity;
  7992. if (flags & 1 && this.match(78)) {
  7993. if (flags & 2) {
  7994. entity = this.parseIdentifier(true);
  7995. } else {
  7996. const node = this.startNode();
  7997. this.next();
  7998. entity = this.finishNode(node, "ThisExpression");
  7999. }
  8000. } else {
  8001. entity = this.parseIdentifier(!!(flags & 1));
  8002. }
  8003. while (this.eat(16)) {
  8004. const node = this.startNodeAtNode(entity);
  8005. node.left = entity;
  8006. node.right = this.parseIdentifier(!!(flags & 1));
  8007. entity = this.finishNode(node, "TSQualifiedName");
  8008. }
  8009. return entity;
  8010. }
  8011. tsParseTypeReference() {
  8012. const node = this.startNode();
  8013. node.typeName = this.tsParseEntityName(1);
  8014. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8015. node.typeParameters = this.tsParseTypeArguments();
  8016. }
  8017. return this.finishNode(node, "TSTypeReference");
  8018. }
  8019. tsParseThisTypePredicate(lhs) {
  8020. this.next();
  8021. const node = this.startNodeAtNode(lhs);
  8022. node.parameterName = lhs;
  8023. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  8024. node.asserts = false;
  8025. return this.finishNode(node, "TSTypePredicate");
  8026. }
  8027. tsParseThisTypeNode() {
  8028. const node = this.startNode();
  8029. this.next();
  8030. return this.finishNode(node, "TSThisType");
  8031. }
  8032. tsParseTypeQuery() {
  8033. const node = this.startNode();
  8034. this.expect(87);
  8035. if (this.match(83)) {
  8036. node.exprName = this.tsParseImportType();
  8037. } else {
  8038. node.exprName = this.tsParseEntityName(1 | 2);
  8039. }
  8040. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8041. node.typeParameters = this.tsParseTypeArguments();
  8042. }
  8043. return this.finishNode(node, "TSTypeQuery");
  8044. }
  8045. tsParseTypeParameter(parseModifiers) {
  8046. const node = this.startNode();
  8047. parseModifiers(node);
  8048. node.name = this.tsParseTypeParameterName();
  8049. node.constraint = this.tsEatThenParseType(81);
  8050. node.default = this.tsEatThenParseType(29);
  8051. return this.finishNode(node, "TSTypeParameter");
  8052. }
  8053. tsTryParseTypeParameters(parseModifiers) {
  8054. if (this.match(47)) {
  8055. return this.tsParseTypeParameters(parseModifiers);
  8056. }
  8057. }
  8058. tsParseTypeParameters(parseModifiers) {
  8059. const node = this.startNode();
  8060. if (this.match(47) || this.match(143)) {
  8061. this.next();
  8062. } else {
  8063. this.unexpected();
  8064. }
  8065. const refTrailingCommaPos = {
  8066. value: -1
  8067. };
  8068. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  8069. if (node.params.length === 0) {
  8070. this.raise(TSErrors.EmptyTypeParameters, node);
  8071. }
  8072. if (refTrailingCommaPos.value !== -1) {
  8073. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  8074. }
  8075. return this.finishNode(node, "TSTypeParameterDeclaration");
  8076. }
  8077. tsFillSignature(returnToken, signature) {
  8078. const returnTokenRequired = returnToken === 19;
  8079. const paramsKey = "parameters";
  8080. const returnTypeKey = "typeAnnotation";
  8081. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  8082. this.expect(10);
  8083. signature[paramsKey] = this.tsParseBindingListForSignature();
  8084. if (returnTokenRequired) {
  8085. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8086. } else if (this.match(returnToken)) {
  8087. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8088. }
  8089. }
  8090. tsParseBindingListForSignature() {
  8091. const list = super.parseBindingList(11, 41, 2);
  8092. for (const pattern of list) {
  8093. const {
  8094. type
  8095. } = pattern;
  8096. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  8097. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  8098. type
  8099. });
  8100. }
  8101. }
  8102. return list;
  8103. }
  8104. tsParseTypeMemberSemicolon() {
  8105. if (!this.eat(12) && !this.isLineTerminator()) {
  8106. this.expect(13);
  8107. }
  8108. }
  8109. tsParseSignatureMember(kind, node) {
  8110. this.tsFillSignature(14, node);
  8111. this.tsParseTypeMemberSemicolon();
  8112. return this.finishNode(node, kind);
  8113. }
  8114. tsIsUnambiguouslyIndexSignature() {
  8115. this.next();
  8116. if (tokenIsIdentifier(this.state.type)) {
  8117. this.next();
  8118. return this.match(14);
  8119. }
  8120. return false;
  8121. }
  8122. tsTryParseIndexSignature(node) {
  8123. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8124. return;
  8125. }
  8126. this.expect(0);
  8127. const id = this.parseIdentifier();
  8128. id.typeAnnotation = this.tsParseTypeAnnotation();
  8129. this.resetEndLocation(id);
  8130. this.expect(3);
  8131. node.parameters = [id];
  8132. const type = this.tsTryParseTypeAnnotation();
  8133. if (type) node.typeAnnotation = type;
  8134. this.tsParseTypeMemberSemicolon();
  8135. return this.finishNode(node, "TSIndexSignature");
  8136. }
  8137. tsParsePropertyOrMethodSignature(node, readonly) {
  8138. if (this.eat(17)) node.optional = true;
  8139. if (this.match(10) || this.match(47)) {
  8140. if (readonly) {
  8141. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  8142. }
  8143. const method = node;
  8144. if (method.kind && this.match(47)) {
  8145. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  8146. }
  8147. this.tsFillSignature(14, method);
  8148. this.tsParseTypeMemberSemicolon();
  8149. const paramsKey = "parameters";
  8150. const returnTypeKey = "typeAnnotation";
  8151. if (method.kind === "get") {
  8152. if (method[paramsKey].length > 0) {
  8153. this.raise(Errors.BadGetterArity, this.state.curPosition());
  8154. if (this.isThisParam(method[paramsKey][0])) {
  8155. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8156. }
  8157. }
  8158. } else if (method.kind === "set") {
  8159. if (method[paramsKey].length !== 1) {
  8160. this.raise(Errors.BadSetterArity, this.state.curPosition());
  8161. } else {
  8162. const firstParameter = method[paramsKey][0];
  8163. if (this.isThisParam(firstParameter)) {
  8164. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8165. }
  8166. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8167. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  8168. }
  8169. if (firstParameter.type === "RestElement") {
  8170. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  8171. }
  8172. }
  8173. if (method[returnTypeKey]) {
  8174. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  8175. }
  8176. } else {
  8177. method.kind = "method";
  8178. }
  8179. return this.finishNode(method, "TSMethodSignature");
  8180. } else {
  8181. const property = node;
  8182. if (readonly) property.readonly = true;
  8183. const type = this.tsTryParseTypeAnnotation();
  8184. if (type) property.typeAnnotation = type;
  8185. this.tsParseTypeMemberSemicolon();
  8186. return this.finishNode(property, "TSPropertySignature");
  8187. }
  8188. }
  8189. tsParseTypeMember() {
  8190. const node = this.startNode();
  8191. if (this.match(10) || this.match(47)) {
  8192. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8193. }
  8194. if (this.match(77)) {
  8195. const id = this.startNode();
  8196. this.next();
  8197. if (this.match(10) || this.match(47)) {
  8198. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8199. } else {
  8200. node.key = this.createIdentifier(id, "new");
  8201. return this.tsParsePropertyOrMethodSignature(node, false);
  8202. }
  8203. }
  8204. this.tsParseModifiers({
  8205. allowedModifiers: ["readonly"],
  8206. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8207. }, node);
  8208. const idx = this.tsTryParseIndexSignature(node);
  8209. if (idx) {
  8210. return idx;
  8211. }
  8212. super.parsePropertyName(node);
  8213. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8214. node.kind = node.key.name;
  8215. super.parsePropertyName(node);
  8216. if (!this.match(10) && !this.match(47)) {
  8217. this.unexpected(null, 10);
  8218. }
  8219. }
  8220. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8221. }
  8222. tsParseTypeLiteral() {
  8223. const node = this.startNode();
  8224. node.members = this.tsParseObjectTypeMembers();
  8225. return this.finishNode(node, "TSTypeLiteral");
  8226. }
  8227. tsParseObjectTypeMembers() {
  8228. this.expect(5);
  8229. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8230. this.expect(8);
  8231. return members;
  8232. }
  8233. tsIsStartOfMappedType() {
  8234. this.next();
  8235. if (this.eat(53)) {
  8236. return this.isContextual(122);
  8237. }
  8238. if (this.isContextual(122)) {
  8239. this.next();
  8240. }
  8241. if (!this.match(0)) {
  8242. return false;
  8243. }
  8244. this.next();
  8245. if (!this.tsIsIdentifier()) {
  8246. return false;
  8247. }
  8248. this.next();
  8249. return this.match(58);
  8250. }
  8251. tsParseMappedType() {
  8252. const node = this.startNode();
  8253. this.expect(5);
  8254. if (this.match(53)) {
  8255. node.readonly = this.state.value;
  8256. this.next();
  8257. this.expectContextual(122);
  8258. } else if (this.eatContextual(122)) {
  8259. node.readonly = true;
  8260. }
  8261. this.expect(0);
  8262. const typeParameter = this.startNode();
  8263. typeParameter.name = this.tsParseTypeParameterName();
  8264. typeParameter.constraint = this.tsExpectThenParseType(58);
  8265. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8266. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8267. this.expect(3);
  8268. if (this.match(53)) {
  8269. node.optional = this.state.value;
  8270. this.next();
  8271. this.expect(17);
  8272. } else if (this.eat(17)) {
  8273. node.optional = true;
  8274. }
  8275. node.typeAnnotation = this.tsTryParseType();
  8276. this.semicolon();
  8277. this.expect(8);
  8278. return this.finishNode(node, "TSMappedType");
  8279. }
  8280. tsParseTupleType() {
  8281. const node = this.startNode();
  8282. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8283. let seenOptionalElement = false;
  8284. node.elementTypes.forEach(elementNode => {
  8285. const {
  8286. type
  8287. } = elementNode;
  8288. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8289. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8290. }
  8291. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8292. });
  8293. return this.finishNode(node, "TSTupleType");
  8294. }
  8295. tsParseTupleElementType() {
  8296. const restStartLoc = this.state.startLoc;
  8297. const rest = this.eat(21);
  8298. const {
  8299. startLoc
  8300. } = this.state;
  8301. let labeled;
  8302. let label;
  8303. let optional;
  8304. let type;
  8305. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8306. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8307. if (chAfterWord === 58) {
  8308. labeled = true;
  8309. optional = false;
  8310. label = this.parseIdentifier(true);
  8311. this.expect(14);
  8312. type = this.tsParseType();
  8313. } else if (chAfterWord === 63) {
  8314. optional = true;
  8315. const wordName = this.state.value;
  8316. const typeOrLabel = this.tsParseNonArrayType();
  8317. if (this.lookaheadCharCode() === 58) {
  8318. labeled = true;
  8319. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8320. this.expect(17);
  8321. this.expect(14);
  8322. type = this.tsParseType();
  8323. } else {
  8324. labeled = false;
  8325. type = typeOrLabel;
  8326. this.expect(17);
  8327. }
  8328. } else {
  8329. type = this.tsParseType();
  8330. optional = this.eat(17);
  8331. labeled = this.eat(14);
  8332. }
  8333. if (labeled) {
  8334. let labeledNode;
  8335. if (label) {
  8336. labeledNode = this.startNodeAt(startLoc);
  8337. labeledNode.optional = optional;
  8338. labeledNode.label = label;
  8339. labeledNode.elementType = type;
  8340. if (this.eat(17)) {
  8341. labeledNode.optional = true;
  8342. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8343. }
  8344. } else {
  8345. labeledNode = this.startNodeAt(startLoc);
  8346. labeledNode.optional = optional;
  8347. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8348. labeledNode.label = type;
  8349. labeledNode.elementType = this.tsParseType();
  8350. }
  8351. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8352. } else if (optional) {
  8353. const optionalTypeNode = this.startNodeAt(startLoc);
  8354. optionalTypeNode.typeAnnotation = type;
  8355. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8356. }
  8357. if (rest) {
  8358. const restNode = this.startNodeAt(restStartLoc);
  8359. restNode.typeAnnotation = type;
  8360. type = this.finishNode(restNode, "TSRestType");
  8361. }
  8362. return type;
  8363. }
  8364. tsParseParenthesizedType() {
  8365. const node = this.startNode();
  8366. this.expect(10);
  8367. node.typeAnnotation = this.tsParseType();
  8368. this.expect(11);
  8369. return this.finishNode(node, "TSParenthesizedType");
  8370. }
  8371. tsParseFunctionOrConstructorType(type, abstract) {
  8372. const node = this.startNode();
  8373. if (type === "TSConstructorType") {
  8374. node.abstract = !!abstract;
  8375. if (abstract) this.next();
  8376. this.next();
  8377. }
  8378. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8379. return this.finishNode(node, type);
  8380. }
  8381. tsParseLiteralTypeNode() {
  8382. const node = this.startNode();
  8383. switch (this.state.type) {
  8384. case 135:
  8385. case 136:
  8386. case 134:
  8387. case 85:
  8388. case 86:
  8389. node.literal = super.parseExprAtom();
  8390. break;
  8391. default:
  8392. this.unexpected();
  8393. }
  8394. return this.finishNode(node, "TSLiteralType");
  8395. }
  8396. tsParseTemplateLiteralType() {
  8397. const node = this.startNode();
  8398. node.literal = super.parseTemplate(false);
  8399. return this.finishNode(node, "TSLiteralType");
  8400. }
  8401. parseTemplateSubstitution() {
  8402. if (this.state.inType) return this.tsParseType();
  8403. return super.parseTemplateSubstitution();
  8404. }
  8405. tsParseThisTypeOrThisTypePredicate() {
  8406. const thisKeyword = this.tsParseThisTypeNode();
  8407. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8408. return this.tsParseThisTypePredicate(thisKeyword);
  8409. } else {
  8410. return thisKeyword;
  8411. }
  8412. }
  8413. tsParseNonArrayType() {
  8414. switch (this.state.type) {
  8415. case 134:
  8416. case 135:
  8417. case 136:
  8418. case 85:
  8419. case 86:
  8420. return this.tsParseLiteralTypeNode();
  8421. case 53:
  8422. if (this.state.value === "-") {
  8423. const node = this.startNode();
  8424. const nextToken = this.lookahead();
  8425. if (nextToken.type !== 135 && nextToken.type !== 136) {
  8426. this.unexpected();
  8427. }
  8428. node.literal = this.parseMaybeUnary();
  8429. return this.finishNode(node, "TSLiteralType");
  8430. }
  8431. break;
  8432. case 78:
  8433. return this.tsParseThisTypeOrThisTypePredicate();
  8434. case 87:
  8435. return this.tsParseTypeQuery();
  8436. case 83:
  8437. return this.tsParseImportType();
  8438. case 5:
  8439. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8440. case 0:
  8441. return this.tsParseTupleType();
  8442. case 10:
  8443. return this.tsParseParenthesizedType();
  8444. case 25:
  8445. case 24:
  8446. return this.tsParseTemplateLiteralType();
  8447. default:
  8448. {
  8449. const {
  8450. type
  8451. } = this.state;
  8452. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8453. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8454. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8455. const node = this.startNode();
  8456. this.next();
  8457. return this.finishNode(node, nodeType);
  8458. }
  8459. return this.tsParseTypeReference();
  8460. }
  8461. }
  8462. }
  8463. throw this.unexpected();
  8464. }
  8465. tsParseArrayTypeOrHigher() {
  8466. const {
  8467. startLoc
  8468. } = this.state;
  8469. let type = this.tsParseNonArrayType();
  8470. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8471. if (this.match(3)) {
  8472. const node = this.startNodeAt(startLoc);
  8473. node.elementType = type;
  8474. this.expect(3);
  8475. type = this.finishNode(node, "TSArrayType");
  8476. } else {
  8477. const node = this.startNodeAt(startLoc);
  8478. node.objectType = type;
  8479. node.indexType = this.tsParseType();
  8480. this.expect(3);
  8481. type = this.finishNode(node, "TSIndexedAccessType");
  8482. }
  8483. }
  8484. return type;
  8485. }
  8486. tsParseTypeOperator() {
  8487. const node = this.startNode();
  8488. const operator = this.state.value;
  8489. this.next();
  8490. node.operator = operator;
  8491. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8492. if (operator === "readonly") {
  8493. this.tsCheckTypeAnnotationForReadOnly(node);
  8494. }
  8495. return this.finishNode(node, "TSTypeOperator");
  8496. }
  8497. tsCheckTypeAnnotationForReadOnly(node) {
  8498. switch (node.typeAnnotation.type) {
  8499. case "TSTupleType":
  8500. case "TSArrayType":
  8501. return;
  8502. default:
  8503. this.raise(TSErrors.UnexpectedReadonly, node);
  8504. }
  8505. }
  8506. tsParseInferType() {
  8507. const node = this.startNode();
  8508. this.expectContextual(115);
  8509. const typeParameter = this.startNode();
  8510. typeParameter.name = this.tsParseTypeParameterName();
  8511. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8512. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8513. return this.finishNode(node, "TSInferType");
  8514. }
  8515. tsParseConstraintForInferType() {
  8516. if (this.eat(81)) {
  8517. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8518. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8519. return constraint;
  8520. }
  8521. }
  8522. }
  8523. tsParseTypeOperatorOrHigher() {
  8524. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8525. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8526. }
  8527. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8528. const node = this.startNode();
  8529. const hasLeadingOperator = this.eat(operator);
  8530. const types = [];
  8531. do {
  8532. types.push(parseConstituentType());
  8533. } while (this.eat(operator));
  8534. if (types.length === 1 && !hasLeadingOperator) {
  8535. return types[0];
  8536. }
  8537. node.types = types;
  8538. return this.finishNode(node, kind);
  8539. }
  8540. tsParseIntersectionTypeOrHigher() {
  8541. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8542. }
  8543. tsParseUnionTypeOrHigher() {
  8544. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8545. }
  8546. tsIsStartOfFunctionType() {
  8547. if (this.match(47)) {
  8548. return true;
  8549. }
  8550. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8551. }
  8552. tsSkipParameterStart() {
  8553. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8554. this.next();
  8555. return true;
  8556. }
  8557. if (this.match(5)) {
  8558. const {
  8559. errors
  8560. } = this.state;
  8561. const previousErrorCount = errors.length;
  8562. try {
  8563. this.parseObjectLike(8, true);
  8564. return errors.length === previousErrorCount;
  8565. } catch (_unused) {
  8566. return false;
  8567. }
  8568. }
  8569. if (this.match(0)) {
  8570. this.next();
  8571. const {
  8572. errors
  8573. } = this.state;
  8574. const previousErrorCount = errors.length;
  8575. try {
  8576. super.parseBindingList(3, 93, 1);
  8577. return errors.length === previousErrorCount;
  8578. } catch (_unused2) {
  8579. return false;
  8580. }
  8581. }
  8582. return false;
  8583. }
  8584. tsIsUnambiguouslyStartOfFunctionType() {
  8585. this.next();
  8586. if (this.match(11) || this.match(21)) {
  8587. return true;
  8588. }
  8589. if (this.tsSkipParameterStart()) {
  8590. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8591. return true;
  8592. }
  8593. if (this.match(11)) {
  8594. this.next();
  8595. if (this.match(19)) {
  8596. return true;
  8597. }
  8598. }
  8599. }
  8600. return false;
  8601. }
  8602. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8603. return this.tsInType(() => {
  8604. const t = this.startNode();
  8605. this.expect(returnToken);
  8606. const node = this.startNode();
  8607. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8608. if (asserts && this.match(78)) {
  8609. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8610. if (thisTypePredicate.type === "TSThisType") {
  8611. node.parameterName = thisTypePredicate;
  8612. node.asserts = true;
  8613. node.typeAnnotation = null;
  8614. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8615. } else {
  8616. this.resetStartLocationFromNode(thisTypePredicate, node);
  8617. thisTypePredicate.asserts = true;
  8618. }
  8619. t.typeAnnotation = thisTypePredicate;
  8620. return this.finishNode(t, "TSTypeAnnotation");
  8621. }
  8622. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8623. if (!typePredicateVariable) {
  8624. if (!asserts) {
  8625. return this.tsParseTypeAnnotation(false, t);
  8626. }
  8627. node.parameterName = this.parseIdentifier();
  8628. node.asserts = asserts;
  8629. node.typeAnnotation = null;
  8630. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8631. return this.finishNode(t, "TSTypeAnnotation");
  8632. }
  8633. const type = this.tsParseTypeAnnotation(false);
  8634. node.parameterName = typePredicateVariable;
  8635. node.typeAnnotation = type;
  8636. node.asserts = asserts;
  8637. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8638. return this.finishNode(t, "TSTypeAnnotation");
  8639. });
  8640. }
  8641. tsTryParseTypeOrTypePredicateAnnotation() {
  8642. if (this.match(14)) {
  8643. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8644. }
  8645. }
  8646. tsTryParseTypeAnnotation() {
  8647. if (this.match(14)) {
  8648. return this.tsParseTypeAnnotation();
  8649. }
  8650. }
  8651. tsTryParseType() {
  8652. return this.tsEatThenParseType(14);
  8653. }
  8654. tsParseTypePredicatePrefix() {
  8655. const id = this.parseIdentifier();
  8656. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8657. this.next();
  8658. return id;
  8659. }
  8660. }
  8661. tsParseTypePredicateAsserts() {
  8662. if (this.state.type !== 109) {
  8663. return false;
  8664. }
  8665. const containsEsc = this.state.containsEsc;
  8666. this.next();
  8667. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8668. return false;
  8669. }
  8670. if (containsEsc) {
  8671. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8672. reservedWord: "asserts"
  8673. });
  8674. }
  8675. return true;
  8676. }
  8677. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8678. this.tsInType(() => {
  8679. if (eatColon) this.expect(14);
  8680. t.typeAnnotation = this.tsParseType();
  8681. });
  8682. return this.finishNode(t, "TSTypeAnnotation");
  8683. }
  8684. tsParseType() {
  8685. assert(this.state.inType);
  8686. const type = this.tsParseNonConditionalType();
  8687. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8688. return type;
  8689. }
  8690. const node = this.startNodeAtNode(type);
  8691. node.checkType = type;
  8692. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8693. this.expect(17);
  8694. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8695. this.expect(14);
  8696. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8697. return this.finishNode(node, "TSConditionalType");
  8698. }
  8699. isAbstractConstructorSignature() {
  8700. return this.isContextual(124) && this.isLookaheadContextual("new");
  8701. }
  8702. tsParseNonConditionalType() {
  8703. if (this.tsIsStartOfFunctionType()) {
  8704. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8705. }
  8706. if (this.match(77)) {
  8707. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8708. } else if (this.isAbstractConstructorSignature()) {
  8709. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8710. }
  8711. return this.tsParseUnionTypeOrHigher();
  8712. }
  8713. tsParseTypeAssertion() {
  8714. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8715. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8716. }
  8717. const node = this.startNode();
  8718. node.typeAnnotation = this.tsInType(() => {
  8719. this.next();
  8720. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8721. });
  8722. this.expect(48);
  8723. node.expression = this.parseMaybeUnary();
  8724. return this.finishNode(node, "TSTypeAssertion");
  8725. }
  8726. tsParseHeritageClause(token) {
  8727. const originalStartLoc = this.state.startLoc;
  8728. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8729. const node = this.startNode();
  8730. node.expression = this.tsParseEntityName(1 | 2);
  8731. if (this.match(47)) {
  8732. node.typeParameters = this.tsParseTypeArguments();
  8733. }
  8734. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8735. });
  8736. if (!delimitedList.length) {
  8737. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8738. token
  8739. });
  8740. }
  8741. return delimitedList;
  8742. }
  8743. tsParseInterfaceDeclaration(node, properties = {}) {
  8744. if (this.hasFollowingLineBreak()) return null;
  8745. this.expectContextual(129);
  8746. if (properties.declare) node.declare = true;
  8747. if (tokenIsIdentifier(this.state.type)) {
  8748. node.id = this.parseIdentifier();
  8749. this.checkIdentifier(node.id, 130);
  8750. } else {
  8751. node.id = null;
  8752. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8753. }
  8754. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8755. if (this.eat(81)) {
  8756. node.extends = this.tsParseHeritageClause("extends");
  8757. }
  8758. const body = this.startNode();
  8759. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8760. node.body = this.finishNode(body, "TSInterfaceBody");
  8761. return this.finishNode(node, "TSInterfaceDeclaration");
  8762. }
  8763. tsParseTypeAliasDeclaration(node) {
  8764. node.id = this.parseIdentifier();
  8765. this.checkIdentifier(node.id, 2);
  8766. node.typeAnnotation = this.tsInType(() => {
  8767. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8768. this.expect(29);
  8769. if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
  8770. const node = this.startNode();
  8771. this.next();
  8772. return this.finishNode(node, "TSIntrinsicKeyword");
  8773. }
  8774. return this.tsParseType();
  8775. });
  8776. this.semicolon();
  8777. return this.finishNode(node, "TSTypeAliasDeclaration");
  8778. }
  8779. tsInTopLevelContext(cb) {
  8780. if (this.curContext() !== types.brace) {
  8781. const oldContext = this.state.context;
  8782. this.state.context = [oldContext[0]];
  8783. try {
  8784. return cb();
  8785. } finally {
  8786. this.state.context = oldContext;
  8787. }
  8788. } else {
  8789. return cb();
  8790. }
  8791. }
  8792. tsInType(cb) {
  8793. const oldInType = this.state.inType;
  8794. this.state.inType = true;
  8795. try {
  8796. return cb();
  8797. } finally {
  8798. this.state.inType = oldInType;
  8799. }
  8800. }
  8801. tsInDisallowConditionalTypesContext(cb) {
  8802. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8803. this.state.inDisallowConditionalTypesContext = true;
  8804. try {
  8805. return cb();
  8806. } finally {
  8807. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8808. }
  8809. }
  8810. tsInAllowConditionalTypesContext(cb) {
  8811. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8812. this.state.inDisallowConditionalTypesContext = false;
  8813. try {
  8814. return cb();
  8815. } finally {
  8816. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8817. }
  8818. }
  8819. tsEatThenParseType(token) {
  8820. if (this.match(token)) {
  8821. return this.tsNextThenParseType();
  8822. }
  8823. }
  8824. tsExpectThenParseType(token) {
  8825. return this.tsInType(() => {
  8826. this.expect(token);
  8827. return this.tsParseType();
  8828. });
  8829. }
  8830. tsNextThenParseType() {
  8831. return this.tsInType(() => {
  8832. this.next();
  8833. return this.tsParseType();
  8834. });
  8835. }
  8836. tsParseEnumMember() {
  8837. const node = this.startNode();
  8838. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8839. if (this.eat(29)) {
  8840. node.initializer = super.parseMaybeAssignAllowIn();
  8841. }
  8842. return this.finishNode(node, "TSEnumMember");
  8843. }
  8844. tsParseEnumDeclaration(node, properties = {}) {
  8845. if (properties.const) node.const = true;
  8846. if (properties.declare) node.declare = true;
  8847. this.expectContextual(126);
  8848. node.id = this.parseIdentifier();
  8849. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8850. this.expect(5);
  8851. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8852. this.expect(8);
  8853. return this.finishNode(node, "TSEnumDeclaration");
  8854. }
  8855. tsParseEnumBody() {
  8856. const node = this.startNode();
  8857. this.expect(5);
  8858. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8859. this.expect(8);
  8860. return this.finishNode(node, "TSEnumBody");
  8861. }
  8862. tsParseModuleBlock() {
  8863. const node = this.startNode();
  8864. this.scope.enter(0);
  8865. this.expect(5);
  8866. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8867. this.scope.exit();
  8868. return this.finishNode(node, "TSModuleBlock");
  8869. }
  8870. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8871. node.id = this.parseIdentifier();
  8872. if (!nested) {
  8873. this.checkIdentifier(node.id, 1024);
  8874. }
  8875. if (this.eat(16)) {
  8876. const inner = this.startNode();
  8877. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8878. node.body = inner;
  8879. } else {
  8880. this.scope.enter(1024);
  8881. this.prodParam.enter(0);
  8882. node.body = this.tsParseModuleBlock();
  8883. this.prodParam.exit();
  8884. this.scope.exit();
  8885. }
  8886. return this.finishNode(node, "TSModuleDeclaration");
  8887. }
  8888. tsParseAmbientExternalModuleDeclaration(node) {
  8889. if (this.isContextual(112)) {
  8890. node.kind = "global";
  8891. node.global = true;
  8892. node.id = this.parseIdentifier();
  8893. } else if (this.match(134)) {
  8894. node.kind = "module";
  8895. node.id = super.parseStringLiteral(this.state.value);
  8896. } else {
  8897. this.unexpected();
  8898. }
  8899. if (this.match(5)) {
  8900. this.scope.enter(1024);
  8901. this.prodParam.enter(0);
  8902. node.body = this.tsParseModuleBlock();
  8903. this.prodParam.exit();
  8904. this.scope.exit();
  8905. } else {
  8906. this.semicolon();
  8907. }
  8908. return this.finishNode(node, "TSModuleDeclaration");
  8909. }
  8910. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8911. node.isExport = isExport || false;
  8912. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8913. this.checkIdentifier(node.id, 4096);
  8914. this.expect(29);
  8915. const moduleReference = this.tsParseModuleReference();
  8916. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8917. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8918. }
  8919. node.moduleReference = moduleReference;
  8920. this.semicolon();
  8921. return this.finishNode(node, "TSImportEqualsDeclaration");
  8922. }
  8923. tsIsExternalModuleReference() {
  8924. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8925. }
  8926. tsParseModuleReference() {
  8927. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  8928. }
  8929. tsParseExternalModuleReference() {
  8930. const node = this.startNode();
  8931. this.expectContextual(119);
  8932. this.expect(10);
  8933. if (!this.match(134)) {
  8934. this.unexpected();
  8935. }
  8936. node.expression = super.parseExprAtom();
  8937. this.expect(11);
  8938. this.sawUnambiguousESM = true;
  8939. return this.finishNode(node, "TSExternalModuleReference");
  8940. }
  8941. tsLookAhead(f) {
  8942. const state = this.state.clone();
  8943. const res = f();
  8944. this.state = state;
  8945. return res;
  8946. }
  8947. tsTryParseAndCatch(f) {
  8948. const result = this.tryParse(abort => f() || abort());
  8949. if (result.aborted || !result.node) return;
  8950. if (result.error) this.state = result.failState;
  8951. return result.node;
  8952. }
  8953. tsTryParse(f) {
  8954. const state = this.state.clone();
  8955. const result = f();
  8956. if (result !== undefined && result !== false) {
  8957. return result;
  8958. }
  8959. this.state = state;
  8960. }
  8961. tsTryParseDeclare(node) {
  8962. if (this.isLineTerminator()) {
  8963. return;
  8964. }
  8965. const startType = this.state.type;
  8966. return this.tsInAmbientContext(() => {
  8967. switch (startType) {
  8968. case 68:
  8969. node.declare = true;
  8970. return super.parseFunctionStatement(node, false, false);
  8971. case 80:
  8972. node.declare = true;
  8973. return this.parseClass(node, true, false);
  8974. case 126:
  8975. return this.tsParseEnumDeclaration(node, {
  8976. declare: true
  8977. });
  8978. case 112:
  8979. return this.tsParseAmbientExternalModuleDeclaration(node);
  8980. case 100:
  8981. if (this.state.containsEsc) {
  8982. return;
  8983. }
  8984. case 75:
  8985. case 74:
  8986. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8987. node.declare = true;
  8988. return this.parseVarStatement(node, this.state.value, true);
  8989. }
  8990. this.expect(75);
  8991. return this.tsParseEnumDeclaration(node, {
  8992. const: true,
  8993. declare: true
  8994. });
  8995. case 107:
  8996. if (this.isUsing()) {
  8997. this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
  8998. node.declare = true;
  8999. return this.parseVarStatement(node, "using", true);
  9000. }
  9001. break;
  9002. case 96:
  9003. if (this.isAwaitUsing()) {
  9004. this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
  9005. node.declare = true;
  9006. this.next();
  9007. return this.parseVarStatement(node, "await using", true);
  9008. }
  9009. break;
  9010. case 129:
  9011. {
  9012. const result = this.tsParseInterfaceDeclaration(node, {
  9013. declare: true
  9014. });
  9015. if (result) return result;
  9016. }
  9017. default:
  9018. if (tokenIsIdentifier(startType)) {
  9019. return this.tsParseDeclaration(node, this.state.type, true, null);
  9020. }
  9021. }
  9022. });
  9023. }
  9024. tsTryParseExportDeclaration() {
  9025. return this.tsParseDeclaration(this.startNode(), this.state.type, true, null);
  9026. }
  9027. tsParseDeclaration(node, type, next, decorators) {
  9028. switch (type) {
  9029. case 124:
  9030. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  9031. return this.tsParseAbstractDeclaration(node, decorators);
  9032. }
  9033. break;
  9034. case 127:
  9035. if (this.tsCheckLineTerminator(next)) {
  9036. if (this.match(134)) {
  9037. return this.tsParseAmbientExternalModuleDeclaration(node);
  9038. } else if (tokenIsIdentifier(this.state.type)) {
  9039. node.kind = "module";
  9040. return this.tsParseModuleOrNamespaceDeclaration(node);
  9041. }
  9042. }
  9043. break;
  9044. case 128:
  9045. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9046. node.kind = "namespace";
  9047. return this.tsParseModuleOrNamespaceDeclaration(node);
  9048. }
  9049. break;
  9050. case 130:
  9051. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9052. return this.tsParseTypeAliasDeclaration(node);
  9053. }
  9054. break;
  9055. }
  9056. }
  9057. tsCheckLineTerminator(next) {
  9058. if (next) {
  9059. if (this.hasFollowingLineBreak()) return false;
  9060. this.next();
  9061. return true;
  9062. }
  9063. return !this.isLineTerminator();
  9064. }
  9065. tsTryParseGenericAsyncArrowFunction(startLoc) {
  9066. if (!this.match(47)) return;
  9067. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9068. this.state.maybeInArrowParameters = true;
  9069. const res = this.tsTryParseAndCatch(() => {
  9070. const node = this.startNodeAt(startLoc);
  9071. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9072. super.parseFunctionParams(node);
  9073. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9074. this.expect(19);
  9075. return node;
  9076. });
  9077. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9078. if (!res) return;
  9079. return super.parseArrowExpression(res, null, true);
  9080. }
  9081. tsParseTypeArgumentsInExpression() {
  9082. if (this.reScan_lt() !== 47) return;
  9083. return this.tsParseTypeArguments();
  9084. }
  9085. tsParseTypeArguments() {
  9086. const node = this.startNode();
  9087. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  9088. this.expect(47);
  9089. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9090. }));
  9091. if (node.params.length === 0) {
  9092. this.raise(TSErrors.EmptyTypeArguments, node);
  9093. } else if (!this.state.inType && this.curContext() === types.brace) {
  9094. this.reScan_lt_gt();
  9095. }
  9096. this.expect(48);
  9097. return this.finishNode(node, "TSTypeParameterInstantiation");
  9098. }
  9099. tsIsDeclarationStart() {
  9100. return tokenIsTSDeclarationStart(this.state.type);
  9101. }
  9102. isExportDefaultSpecifier() {
  9103. if (this.tsIsDeclarationStart()) return false;
  9104. return super.isExportDefaultSpecifier();
  9105. }
  9106. parseBindingElement(flags, decorators) {
  9107. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  9108. const modified = {};
  9109. this.tsParseModifiers({
  9110. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9111. }, modified);
  9112. const accessibility = modified.accessibility;
  9113. const override = modified.override;
  9114. const readonly = modified.readonly;
  9115. if (!(flags & 4) && (accessibility || readonly || override)) {
  9116. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  9117. }
  9118. const left = this.parseMaybeDefault();
  9119. if (flags & 2) {
  9120. this.parseFunctionParamType(left);
  9121. }
  9122. const elt = this.parseMaybeDefault(left.loc.start, left);
  9123. if (accessibility || readonly || override) {
  9124. const pp = this.startNodeAt(startLoc);
  9125. if (decorators.length) {
  9126. pp.decorators = decorators;
  9127. }
  9128. if (accessibility) pp.accessibility = accessibility;
  9129. if (readonly) pp.readonly = readonly;
  9130. if (override) pp.override = override;
  9131. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9132. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  9133. }
  9134. pp.parameter = elt;
  9135. return this.finishNode(pp, "TSParameterProperty");
  9136. }
  9137. if (decorators.length) {
  9138. left.decorators = decorators;
  9139. }
  9140. return elt;
  9141. }
  9142. isSimpleParameter(node) {
  9143. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9144. }
  9145. tsDisallowOptionalPattern(node) {
  9146. for (const param of node.params) {
  9147. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9148. this.raise(TSErrors.PatternIsOptional, param);
  9149. }
  9150. }
  9151. }
  9152. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9153. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9154. this.tsDisallowOptionalPattern(node);
  9155. }
  9156. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9157. if (this.match(14)) {
  9158. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9159. }
  9160. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9161. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9162. return this.finishNode(node, bodilessType);
  9163. }
  9164. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9165. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  9166. if (node.declare) {
  9167. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9168. }
  9169. }
  9170. this.tsDisallowOptionalPattern(node);
  9171. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9172. }
  9173. registerFunctionStatementId(node) {
  9174. if (!node.body && node.id) {
  9175. this.checkIdentifier(node.id, 1024);
  9176. } else {
  9177. super.registerFunctionStatementId(node);
  9178. }
  9179. }
  9180. tsCheckForInvalidTypeCasts(items) {
  9181. items.forEach(node => {
  9182. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9183. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  9184. }
  9185. });
  9186. }
  9187. toReferencedList(exprList, isInParens) {
  9188. this.tsCheckForInvalidTypeCasts(exprList);
  9189. return exprList;
  9190. }
  9191. parseArrayLike(close, isTuple, refExpressionErrors) {
  9192. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  9193. if (node.type === "ArrayExpression") {
  9194. this.tsCheckForInvalidTypeCasts(node.elements);
  9195. }
  9196. return node;
  9197. }
  9198. parseSubscript(base, startLoc, noCalls, state) {
  9199. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9200. this.state.canStartJSXElement = false;
  9201. this.next();
  9202. const nonNullExpression = this.startNodeAt(startLoc);
  9203. nonNullExpression.expression = base;
  9204. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9205. }
  9206. let isOptionalCall = false;
  9207. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9208. if (noCalls) {
  9209. state.stop = true;
  9210. return base;
  9211. }
  9212. state.optionalChainMember = isOptionalCall = true;
  9213. this.next();
  9214. }
  9215. if (this.match(47) || this.match(51)) {
  9216. let missingParenErrorLoc;
  9217. const result = this.tsTryParseAndCatch(() => {
  9218. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9219. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9220. if (asyncArrowFn) {
  9221. state.stop = true;
  9222. return asyncArrowFn;
  9223. }
  9224. }
  9225. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9226. if (!typeArguments) return;
  9227. if (isOptionalCall && !this.match(10)) {
  9228. missingParenErrorLoc = this.state.curPosition();
  9229. return;
  9230. }
  9231. if (tokenIsTemplate(this.state.type)) {
  9232. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9233. result.typeParameters = typeArguments;
  9234. return result;
  9235. }
  9236. if (!noCalls && this.eat(10)) {
  9237. const node = this.startNodeAt(startLoc);
  9238. node.callee = base;
  9239. node.arguments = this.parseCallExpressionArguments();
  9240. this.tsCheckForInvalidTypeCasts(node.arguments);
  9241. node.typeParameters = typeArguments;
  9242. if (state.optionalChainMember) {
  9243. node.optional = isOptionalCall;
  9244. }
  9245. return this.finishCallExpression(node, state.optionalChainMember);
  9246. }
  9247. const tokenType = this.state.type;
  9248. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenType !== 93 && tokenType !== 120 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9249. return;
  9250. }
  9251. const node = this.startNodeAt(startLoc);
  9252. node.expression = base;
  9253. node.typeParameters = typeArguments;
  9254. return this.finishNode(node, "TSInstantiationExpression");
  9255. });
  9256. if (missingParenErrorLoc) {
  9257. this.unexpected(missingParenErrorLoc, 10);
  9258. }
  9259. if (result) {
  9260. if (result.type === "TSInstantiationExpression") {
  9261. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  9262. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  9263. }
  9264. if (!this.match(16) && !this.match(18)) {
  9265. result.expression = super.stopParseSubscript(base, state);
  9266. }
  9267. }
  9268. return result;
  9269. }
  9270. }
  9271. return super.parseSubscript(base, startLoc, noCalls, state);
  9272. }
  9273. parseNewCallee(node) {
  9274. var _callee$extra;
  9275. super.parseNewCallee(node);
  9276. const {
  9277. callee
  9278. } = node;
  9279. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9280. node.typeParameters = callee.typeParameters;
  9281. node.callee = callee.expression;
  9282. }
  9283. }
  9284. parseExprOp(left, leftStartLoc, minPrec) {
  9285. let isSatisfies;
  9286. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9287. const node = this.startNodeAt(leftStartLoc);
  9288. node.expression = left;
  9289. node.typeAnnotation = this.tsInType(() => {
  9290. this.next();
  9291. if (this.match(75)) {
  9292. if (isSatisfies) {
  9293. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9294. keyword: "const"
  9295. });
  9296. }
  9297. return this.tsParseTypeReference();
  9298. }
  9299. return this.tsParseType();
  9300. });
  9301. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9302. this.reScan_lt_gt();
  9303. return this.parseExprOp(node, leftStartLoc, minPrec);
  9304. }
  9305. return super.parseExprOp(left, leftStartLoc, minPrec);
  9306. }
  9307. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9308. if (!this.state.isAmbientContext) {
  9309. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9310. }
  9311. }
  9312. checkImportReflection(node) {
  9313. super.checkImportReflection(node);
  9314. if (node.module && node.importKind !== "value") {
  9315. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9316. }
  9317. }
  9318. checkDuplicateExports() {}
  9319. isPotentialImportPhase(isExport) {
  9320. if (super.isPotentialImportPhase(isExport)) return true;
  9321. if (this.isContextual(130)) {
  9322. const ch = this.lookaheadCharCode();
  9323. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9324. }
  9325. return !isExport && this.isContextual(87);
  9326. }
  9327. applyImportPhase(node, isExport, phase, loc) {
  9328. super.applyImportPhase(node, isExport, phase, loc);
  9329. if (isExport) {
  9330. node.exportKind = phase === "type" ? "type" : "value";
  9331. } else {
  9332. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9333. }
  9334. }
  9335. parseImport(node) {
  9336. if (this.match(134)) {
  9337. node.importKind = "value";
  9338. return super.parseImport(node);
  9339. }
  9340. let importNode;
  9341. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9342. node.importKind = "value";
  9343. return this.tsParseImportEqualsDeclaration(node);
  9344. } else if (this.isContextual(130)) {
  9345. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9346. if (this.lookaheadCharCode() === 61) {
  9347. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9348. } else {
  9349. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9350. }
  9351. } else {
  9352. importNode = super.parseImport(node);
  9353. }
  9354. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9355. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9356. }
  9357. return importNode;
  9358. }
  9359. parseExport(node, decorators) {
  9360. if (this.match(83)) {
  9361. const nodeImportEquals = node;
  9362. this.next();
  9363. let maybeDefaultIdentifier = null;
  9364. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9365. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9366. } else {
  9367. nodeImportEquals.importKind = "value";
  9368. }
  9369. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9370. return declaration;
  9371. } else if (this.eat(29)) {
  9372. const assign = node;
  9373. assign.expression = super.parseExpression();
  9374. this.semicolon();
  9375. this.sawUnambiguousESM = true;
  9376. return this.finishNode(assign, "TSExportAssignment");
  9377. } else if (this.eatContextual(93)) {
  9378. const decl = node;
  9379. this.expectContextual(128);
  9380. decl.id = this.parseIdentifier();
  9381. this.semicolon();
  9382. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9383. } else {
  9384. return super.parseExport(node, decorators);
  9385. }
  9386. }
  9387. isAbstractClass() {
  9388. return this.isContextual(124) && this.isLookaheadContextual("class");
  9389. }
  9390. parseExportDefaultExpression() {
  9391. if (this.isAbstractClass()) {
  9392. const cls = this.startNode();
  9393. this.next();
  9394. cls.abstract = true;
  9395. return this.parseClass(cls, true, true);
  9396. }
  9397. if (this.match(129)) {
  9398. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9399. if (result) return result;
  9400. }
  9401. return super.parseExportDefaultExpression();
  9402. }
  9403. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9404. const {
  9405. isAmbientContext
  9406. } = this.state;
  9407. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9408. if (!isAmbientContext) return declaration;
  9409. if (!node.declare && (kind === "using" || kind === "await using")) {
  9410. this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
  9411. return declaration;
  9412. }
  9413. for (const {
  9414. id,
  9415. init
  9416. } of declaration.declarations) {
  9417. if (!init) continue;
  9418. if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
  9419. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9420. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9421. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9422. }
  9423. }
  9424. return declaration;
  9425. }
  9426. parseStatementContent(flags, decorators) {
  9427. if (!this.state.containsEsc) {
  9428. switch (this.state.type) {
  9429. case 75:
  9430. {
  9431. if (this.isLookaheadContextual("enum")) {
  9432. const node = this.startNode();
  9433. this.expect(75);
  9434. return this.tsParseEnumDeclaration(node, {
  9435. const: true
  9436. });
  9437. }
  9438. break;
  9439. }
  9440. case 124:
  9441. case 125:
  9442. {
  9443. if (this.nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine()) {
  9444. const token = this.state.type;
  9445. const node = this.startNode();
  9446. this.next();
  9447. const declaration = token === 125 ? this.tsTryParseDeclare(node) : this.tsParseAbstractDeclaration(node, decorators);
  9448. if (declaration) {
  9449. if (token === 125) {
  9450. declaration.declare = true;
  9451. }
  9452. return declaration;
  9453. } else {
  9454. node.expression = this.createIdentifier(this.startNodeAt(node.loc.start), token === 125 ? "declare" : "abstract");
  9455. this.semicolon(false);
  9456. return this.finishNode(node, "ExpressionStatement");
  9457. }
  9458. }
  9459. break;
  9460. }
  9461. case 126:
  9462. return this.tsParseEnumDeclaration(this.startNode());
  9463. case 112:
  9464. {
  9465. const nextCh = this.lookaheadCharCode();
  9466. if (nextCh === 123) {
  9467. const node = this.startNode();
  9468. return this.tsParseAmbientExternalModuleDeclaration(node);
  9469. }
  9470. break;
  9471. }
  9472. case 129:
  9473. {
  9474. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9475. if (result) return result;
  9476. break;
  9477. }
  9478. case 127:
  9479. {
  9480. if (this.nextTokenIsIdentifierOrStringLiteralOnSameLine()) {
  9481. const node = this.startNode();
  9482. this.next();
  9483. return this.tsParseDeclaration(node, 127, false, decorators);
  9484. }
  9485. break;
  9486. }
  9487. case 128:
  9488. {
  9489. if (this.nextTokenIsIdentifierOnSameLine()) {
  9490. const node = this.startNode();
  9491. this.next();
  9492. return this.tsParseDeclaration(node, 128, false, decorators);
  9493. }
  9494. break;
  9495. }
  9496. case 130:
  9497. {
  9498. if (this.nextTokenIsIdentifierOnSameLine()) {
  9499. const node = this.startNode();
  9500. this.next();
  9501. return this.tsParseTypeAliasDeclaration(node);
  9502. }
  9503. break;
  9504. }
  9505. }
  9506. }
  9507. return super.parseStatementContent(flags, decorators);
  9508. }
  9509. parseAccessModifier() {
  9510. return this.tsParseModifier(["public", "protected", "private"]);
  9511. }
  9512. tsHasSomeModifiers(member, modifiers) {
  9513. return modifiers.some(modifier => {
  9514. if (tsIsAccessModifier(modifier)) {
  9515. return member.accessibility === modifier;
  9516. }
  9517. return !!member[modifier];
  9518. });
  9519. }
  9520. tsIsStartOfStaticBlocks() {
  9521. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9522. }
  9523. parseClassMember(classBody, member, state) {
  9524. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9525. this.tsParseModifiers({
  9526. allowedModifiers: modifiers,
  9527. disallowedModifiers: ["in", "out"],
  9528. stopOnStartOfClassStaticBlock: true,
  9529. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9530. }, member);
  9531. const callParseClassMemberWithIsStatic = () => {
  9532. if (this.tsIsStartOfStaticBlocks()) {
  9533. this.next();
  9534. this.next();
  9535. if (this.tsHasSomeModifiers(member, modifiers)) {
  9536. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9537. }
  9538. super.parseClassStaticBlock(classBody, member);
  9539. } else {
  9540. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9541. }
  9542. };
  9543. if (member.declare) {
  9544. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9545. } else {
  9546. callParseClassMemberWithIsStatic();
  9547. }
  9548. }
  9549. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9550. const idx = this.tsTryParseIndexSignature(member);
  9551. if (idx) {
  9552. classBody.body.push(idx);
  9553. if (member.abstract) {
  9554. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9555. }
  9556. if (member.accessibility) {
  9557. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9558. modifier: member.accessibility
  9559. });
  9560. }
  9561. if (member.declare) {
  9562. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9563. }
  9564. if (member.override) {
  9565. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9566. }
  9567. return;
  9568. }
  9569. if (!this.state.inAbstractClass && member.abstract) {
  9570. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9571. }
  9572. if (member.override) {
  9573. if (!state.hadSuperClass) {
  9574. this.raise(TSErrors.OverrideNotInSubClass, member);
  9575. }
  9576. }
  9577. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9578. }
  9579. parsePostMemberNameModifiers(methodOrProp) {
  9580. const optional = this.eat(17);
  9581. if (optional) methodOrProp.optional = true;
  9582. if (methodOrProp.readonly && this.match(10)) {
  9583. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9584. }
  9585. if (methodOrProp.declare && this.match(10)) {
  9586. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9587. }
  9588. }
  9589. shouldParseExportDeclaration() {
  9590. if (this.tsIsDeclarationStart()) return true;
  9591. return super.shouldParseExportDeclaration();
  9592. }
  9593. parseConditional(expr, startLoc, refExpressionErrors) {
  9594. if (!this.match(17)) return expr;
  9595. if (this.state.maybeInArrowParameters) {
  9596. const nextCh = this.lookaheadCharCode();
  9597. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  9598. this.setOptionalParametersError(refExpressionErrors);
  9599. return expr;
  9600. }
  9601. }
  9602. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9603. }
  9604. parseParenItem(node, startLoc) {
  9605. const newNode = super.parseParenItem(node, startLoc);
  9606. if (this.eat(17)) {
  9607. newNode.optional = true;
  9608. this.resetEndLocation(node);
  9609. }
  9610. if (this.match(14)) {
  9611. const typeCastNode = this.startNodeAt(startLoc);
  9612. typeCastNode.expression = node;
  9613. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9614. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9615. }
  9616. return node;
  9617. }
  9618. parseExportDeclaration(node) {
  9619. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9620. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9621. }
  9622. const startLoc = this.state.startLoc;
  9623. const isDeclare = this.eatContextual(125);
  9624. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9625. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9626. }
  9627. const isIdentifier = tokenIsIdentifier(this.state.type);
  9628. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9629. if (!declaration) return null;
  9630. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9631. node.exportKind = "type";
  9632. }
  9633. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  9634. this.resetStartLocation(declaration, startLoc);
  9635. declaration.declare = true;
  9636. }
  9637. return declaration;
  9638. }
  9639. parseClassId(node, isStatement, optionalId, bindingType) {
  9640. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9641. return;
  9642. }
  9643. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9644. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9645. if (typeParameters) node.typeParameters = typeParameters;
  9646. }
  9647. parseClassPropertyAnnotation(node) {
  9648. if (!node.optional) {
  9649. if (this.eat(35)) {
  9650. node.definite = true;
  9651. } else if (this.eat(17)) {
  9652. node.optional = true;
  9653. }
  9654. }
  9655. const type = this.tsTryParseTypeAnnotation();
  9656. if (type) node.typeAnnotation = type;
  9657. }
  9658. parseClassProperty(node) {
  9659. this.parseClassPropertyAnnotation(node);
  9660. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9661. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9662. }
  9663. if (node.abstract && this.match(29)) {
  9664. const {
  9665. key
  9666. } = node;
  9667. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9668. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9669. });
  9670. }
  9671. return super.parseClassProperty(node);
  9672. }
  9673. parseClassPrivateProperty(node) {
  9674. if (node.abstract) {
  9675. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9676. }
  9677. if (node.accessibility) {
  9678. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9679. modifier: node.accessibility
  9680. });
  9681. }
  9682. this.parseClassPropertyAnnotation(node);
  9683. return super.parseClassPrivateProperty(node);
  9684. }
  9685. parseClassAccessorProperty(node) {
  9686. this.parseClassPropertyAnnotation(node);
  9687. if (node.optional) {
  9688. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9689. }
  9690. return super.parseClassAccessorProperty(node);
  9691. }
  9692. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9693. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9694. if (typeParameters && isConstructor) {
  9695. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9696. }
  9697. const {
  9698. declare = false,
  9699. kind
  9700. } = method;
  9701. if (declare && (kind === "get" || kind === "set")) {
  9702. this.raise(TSErrors.DeclareAccessor, method, {
  9703. kind
  9704. });
  9705. }
  9706. if (typeParameters) method.typeParameters = typeParameters;
  9707. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9708. }
  9709. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9710. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9711. if (typeParameters) method.typeParameters = typeParameters;
  9712. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9713. }
  9714. declareClassPrivateMethodInScope(node, kind) {
  9715. if (node.type === "TSDeclareMethod") return;
  9716. if (node.type === "MethodDefinition" && node.value.body == null) {
  9717. return;
  9718. }
  9719. super.declareClassPrivateMethodInScope(node, kind);
  9720. }
  9721. parseClassSuper(node) {
  9722. super.parseClassSuper(node);
  9723. if (node.superClass) {
  9724. if (node.superClass.type === "TSInstantiationExpression") {
  9725. const tsInstantiationExpression = node.superClass;
  9726. const superClass = tsInstantiationExpression.expression;
  9727. this.takeSurroundingComments(superClass, superClass.start, superClass.end);
  9728. const superTypeArguments = tsInstantiationExpression.typeParameters;
  9729. this.takeSurroundingComments(superTypeArguments, superTypeArguments.start, superTypeArguments.end);
  9730. node.superClass = superClass;
  9731. node.superTypeParameters = superTypeArguments;
  9732. } else if (this.match(47) || this.match(51)) {
  9733. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9734. }
  9735. }
  9736. if (this.eatContextual(113)) {
  9737. node.implements = this.tsParseHeritageClause("implements");
  9738. }
  9739. }
  9740. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9741. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9742. if (typeParameters) prop.typeParameters = typeParameters;
  9743. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9744. }
  9745. parseFunctionParams(node, isConstructor) {
  9746. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9747. if (typeParameters) node.typeParameters = typeParameters;
  9748. super.parseFunctionParams(node, isConstructor);
  9749. }
  9750. parseVarId(decl, kind) {
  9751. super.parseVarId(decl, kind);
  9752. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9753. decl.definite = true;
  9754. }
  9755. const type = this.tsTryParseTypeAnnotation();
  9756. if (type) {
  9757. decl.id.typeAnnotation = type;
  9758. this.resetEndLocation(decl.id);
  9759. }
  9760. }
  9761. parseAsyncArrowFromCallExpression(node, call) {
  9762. if (this.match(14)) {
  9763. node.returnType = this.tsParseTypeAnnotation();
  9764. }
  9765. return super.parseAsyncArrowFromCallExpression(node, call);
  9766. }
  9767. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9768. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9769. let state;
  9770. let jsx;
  9771. let typeCast;
  9772. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  9773. state = this.state.clone();
  9774. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9775. if (!jsx.error) return jsx.node;
  9776. const {
  9777. context
  9778. } = this.state;
  9779. const currentContext = context[context.length - 1];
  9780. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9781. context.pop();
  9782. }
  9783. }
  9784. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9785. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9786. }
  9787. if (!state || state === this.state) state = this.state.clone();
  9788. let typeParameters;
  9789. const arrow = this.tryParse(abort => {
  9790. var _expr$extra, _typeParameters;
  9791. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9792. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9793. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9794. abort();
  9795. }
  9796. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9797. this.resetStartLocationFromNode(expr, typeParameters);
  9798. }
  9799. expr.typeParameters = typeParameters;
  9800. return expr;
  9801. }, state);
  9802. if (!arrow.error && !arrow.aborted) {
  9803. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9804. return arrow.node;
  9805. }
  9806. if (!jsx) {
  9807. assert(!this.hasPlugin("jsx"));
  9808. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9809. if (!typeCast.error) return typeCast.node;
  9810. }
  9811. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9812. this.state = jsx.failState;
  9813. return jsx.node;
  9814. }
  9815. if (arrow.node) {
  9816. this.state = arrow.failState;
  9817. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9818. return arrow.node;
  9819. }
  9820. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9821. this.state = typeCast.failState;
  9822. return typeCast.node;
  9823. }
  9824. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9825. }
  9826. reportReservedArrowTypeParam(node) {
  9827. var _node$extra2;
  9828. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9829. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9830. }
  9831. }
  9832. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9833. if (!this.hasPlugin("jsx") && this.match(47)) {
  9834. return this.tsParseTypeAssertion();
  9835. }
  9836. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9837. }
  9838. parseArrow(node) {
  9839. if (this.match(14)) {
  9840. const result = this.tryParse(abort => {
  9841. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9842. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9843. return returnType;
  9844. });
  9845. if (result.aborted) return;
  9846. if (!result.thrown) {
  9847. if (result.error) this.state = result.failState;
  9848. node.returnType = result.node;
  9849. }
  9850. }
  9851. return super.parseArrow(node);
  9852. }
  9853. parseFunctionParamType(param) {
  9854. if (this.eat(17)) {
  9855. param.optional = true;
  9856. }
  9857. const type = this.tsTryParseTypeAnnotation();
  9858. if (type) param.typeAnnotation = type;
  9859. this.resetEndLocation(param);
  9860. return param;
  9861. }
  9862. isAssignable(node, isBinding) {
  9863. switch (node.type) {
  9864. case "TSTypeCastExpression":
  9865. return this.isAssignable(node.expression, isBinding);
  9866. case "TSParameterProperty":
  9867. return true;
  9868. default:
  9869. return super.isAssignable(node, isBinding);
  9870. }
  9871. }
  9872. toAssignable(node, isLHS = false) {
  9873. switch (node.type) {
  9874. case "ParenthesizedExpression":
  9875. this.toAssignableParenthesizedExpression(node, isLHS);
  9876. break;
  9877. case "TSAsExpression":
  9878. case "TSSatisfiesExpression":
  9879. case "TSNonNullExpression":
  9880. case "TSTypeAssertion":
  9881. if (isLHS) {
  9882. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9883. } else {
  9884. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9885. }
  9886. this.toAssignable(node.expression, isLHS);
  9887. break;
  9888. case "AssignmentExpression":
  9889. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9890. node.left = this.typeCastToParameter(node.left);
  9891. }
  9892. default:
  9893. super.toAssignable(node, isLHS);
  9894. }
  9895. }
  9896. toAssignableParenthesizedExpression(node, isLHS) {
  9897. switch (node.expression.type) {
  9898. case "TSAsExpression":
  9899. case "TSSatisfiesExpression":
  9900. case "TSNonNullExpression":
  9901. case "TSTypeAssertion":
  9902. case "ParenthesizedExpression":
  9903. this.toAssignable(node.expression, isLHS);
  9904. break;
  9905. default:
  9906. super.toAssignable(node, isLHS);
  9907. }
  9908. }
  9909. checkToRestConversion(node, allowPattern) {
  9910. switch (node.type) {
  9911. case "TSAsExpression":
  9912. case "TSSatisfiesExpression":
  9913. case "TSTypeAssertion":
  9914. case "TSNonNullExpression":
  9915. this.checkToRestConversion(node.expression, false);
  9916. break;
  9917. default:
  9918. super.checkToRestConversion(node, allowPattern);
  9919. }
  9920. }
  9921. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  9922. switch (type) {
  9923. case "TSTypeCastExpression":
  9924. return true;
  9925. case "TSParameterProperty":
  9926. return "parameter";
  9927. case "TSNonNullExpression":
  9928. return "expression";
  9929. case "TSAsExpression":
  9930. case "TSSatisfiesExpression":
  9931. case "TSTypeAssertion":
  9932. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  9933. default:
  9934. return super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  9935. }
  9936. }
  9937. parseBindingAtom() {
  9938. if (this.state.type === 78) {
  9939. return this.parseIdentifier(true);
  9940. }
  9941. return super.parseBindingAtom();
  9942. }
  9943. parseMaybeDecoratorArguments(expr, startLoc) {
  9944. if (this.match(47) || this.match(51)) {
  9945. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9946. if (this.match(10)) {
  9947. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  9948. call.typeParameters = typeArguments;
  9949. return call;
  9950. }
  9951. this.unexpected(null, 10);
  9952. }
  9953. return super.parseMaybeDecoratorArguments(expr, startLoc);
  9954. }
  9955. checkCommaAfterRest(close) {
  9956. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9957. this.next();
  9958. return false;
  9959. }
  9960. return super.checkCommaAfterRest(close);
  9961. }
  9962. isClassMethod() {
  9963. return this.match(47) || super.isClassMethod();
  9964. }
  9965. isClassProperty() {
  9966. return this.match(35) || this.match(14) || super.isClassProperty();
  9967. }
  9968. parseMaybeDefault(startLoc, left) {
  9969. const node = super.parseMaybeDefault(startLoc, left);
  9970. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9971. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  9972. }
  9973. return node;
  9974. }
  9975. getTokenFromCode(code) {
  9976. if (this.state.inType) {
  9977. if (code === 62) {
  9978. this.finishOp(48, 1);
  9979. return;
  9980. }
  9981. if (code === 60) {
  9982. this.finishOp(47, 1);
  9983. return;
  9984. }
  9985. }
  9986. super.getTokenFromCode(code);
  9987. }
  9988. reScan_lt_gt() {
  9989. const {
  9990. type
  9991. } = this.state;
  9992. if (type === 47) {
  9993. this.state.pos -= 1;
  9994. this.readToken_lt();
  9995. } else if (type === 48) {
  9996. this.state.pos -= 1;
  9997. this.readToken_gt();
  9998. }
  9999. }
  10000. reScan_lt() {
  10001. const {
  10002. type
  10003. } = this.state;
  10004. if (type === 51) {
  10005. this.state.pos -= 2;
  10006. this.finishOp(47, 1);
  10007. return 47;
  10008. }
  10009. return type;
  10010. }
  10011. toAssignableListItem(exprList, index, isLHS) {
  10012. const node = exprList[index];
  10013. if (node.type === "TSTypeCastExpression") {
  10014. exprList[index] = this.typeCastToParameter(node);
  10015. }
  10016. super.toAssignableListItem(exprList, index, isLHS);
  10017. }
  10018. typeCastToParameter(node) {
  10019. node.expression.typeAnnotation = node.typeAnnotation;
  10020. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  10021. return node.expression;
  10022. }
  10023. shouldParseArrow(params) {
  10024. if (this.match(14)) {
  10025. return params.every(expr => this.isAssignable(expr, true));
  10026. }
  10027. return super.shouldParseArrow(params);
  10028. }
  10029. shouldParseAsyncArrow() {
  10030. return this.match(14) || super.shouldParseAsyncArrow();
  10031. }
  10032. canHaveLeadingDecorator() {
  10033. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  10034. }
  10035. jsxParseOpeningElementAfterName(node) {
  10036. if (this.match(47) || this.match(51)) {
  10037. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  10038. if (typeArguments) {
  10039. node.typeParameters = typeArguments;
  10040. }
  10041. }
  10042. return super.jsxParseOpeningElementAfterName(node);
  10043. }
  10044. getGetterSetterExpectedParamCount(method) {
  10045. const baseCount = super.getGetterSetterExpectedParamCount(method);
  10046. const params = this.getObjectOrClassMethodParams(method);
  10047. const firstParam = params[0];
  10048. const hasContextParam = firstParam && this.isThisParam(firstParam);
  10049. return hasContextParam ? baseCount + 1 : baseCount;
  10050. }
  10051. parseCatchClauseParam() {
  10052. const param = super.parseCatchClauseParam();
  10053. const type = this.tsTryParseTypeAnnotation();
  10054. if (type) {
  10055. param.typeAnnotation = type;
  10056. this.resetEndLocation(param);
  10057. }
  10058. return param;
  10059. }
  10060. tsInAmbientContext(cb) {
  10061. const {
  10062. isAmbientContext: oldIsAmbientContext,
  10063. strict: oldStrict
  10064. } = this.state;
  10065. this.state.isAmbientContext = true;
  10066. this.state.strict = false;
  10067. try {
  10068. return cb();
  10069. } finally {
  10070. this.state.isAmbientContext = oldIsAmbientContext;
  10071. this.state.strict = oldStrict;
  10072. }
  10073. }
  10074. parseClass(node, isStatement, optionalId) {
  10075. const oldInAbstractClass = this.state.inAbstractClass;
  10076. this.state.inAbstractClass = !!node.abstract;
  10077. try {
  10078. return super.parseClass(node, isStatement, optionalId);
  10079. } finally {
  10080. this.state.inAbstractClass = oldInAbstractClass;
  10081. }
  10082. }
  10083. tsParseAbstractDeclaration(node, decorators) {
  10084. if (this.match(80)) {
  10085. node.abstract = true;
  10086. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  10087. } else if (this.isContextual(129)) {
  10088. if (!this.hasFollowingLineBreak()) {
  10089. node.abstract = true;
  10090. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
  10091. return this.tsParseInterfaceDeclaration(node);
  10092. } else {
  10093. return null;
  10094. }
  10095. }
  10096. throw this.unexpected(null, 80);
  10097. }
  10098. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  10099. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  10100. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  10101. const hasEstreePlugin = this.hasPlugin("estree");
  10102. const methodFn = hasEstreePlugin ? method.value : method;
  10103. if (methodFn.body) {
  10104. const {
  10105. key
  10106. } = method;
  10107. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  10108. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  10109. });
  10110. }
  10111. }
  10112. return method;
  10113. }
  10114. tsParseTypeParameterName() {
  10115. const typeName = this.parseIdentifier();
  10116. return typeName.name;
  10117. }
  10118. shouldParseAsAmbientContext() {
  10119. return !!this.getPluginOption("typescript", "dts");
  10120. }
  10121. parse() {
  10122. if (this.shouldParseAsAmbientContext()) {
  10123. this.state.isAmbientContext = true;
  10124. }
  10125. return super.parse();
  10126. }
  10127. getExpression() {
  10128. if (this.shouldParseAsAmbientContext()) {
  10129. this.state.isAmbientContext = true;
  10130. }
  10131. return super.getExpression();
  10132. }
  10133. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10134. if (!isString && isMaybeTypeOnly) {
  10135. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10136. return this.finishNode(node, "ExportSpecifier");
  10137. }
  10138. node.exportKind = "value";
  10139. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10140. }
  10141. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10142. if (!importedIsString && isMaybeTypeOnly) {
  10143. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10144. return this.finishNode(specifier, "ImportSpecifier");
  10145. }
  10146. specifier.importKind = "value";
  10147. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  10148. }
  10149. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10150. const leftOfAsKey = isImport ? "imported" : "local";
  10151. const rightOfAsKey = isImport ? "local" : "exported";
  10152. let leftOfAs = node[leftOfAsKey];
  10153. let rightOfAs;
  10154. let hasTypeSpecifier = false;
  10155. let canParseAsKeyword = true;
  10156. const loc = leftOfAs.loc.start;
  10157. if (this.isContextual(93)) {
  10158. const firstAs = this.parseIdentifier();
  10159. if (this.isContextual(93)) {
  10160. const secondAs = this.parseIdentifier();
  10161. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10162. hasTypeSpecifier = true;
  10163. leftOfAs = firstAs;
  10164. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10165. canParseAsKeyword = false;
  10166. } else {
  10167. rightOfAs = secondAs;
  10168. canParseAsKeyword = false;
  10169. }
  10170. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10171. canParseAsKeyword = false;
  10172. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10173. } else {
  10174. hasTypeSpecifier = true;
  10175. leftOfAs = firstAs;
  10176. }
  10177. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10178. hasTypeSpecifier = true;
  10179. if (isImport) {
  10180. leftOfAs = this.parseIdentifier(true);
  10181. if (!this.isContextual(93)) {
  10182. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10183. }
  10184. } else {
  10185. leftOfAs = this.parseModuleExportName();
  10186. }
  10187. }
  10188. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10189. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  10190. }
  10191. node[leftOfAsKey] = leftOfAs;
  10192. node[rightOfAsKey] = rightOfAs;
  10193. const kindKey = isImport ? "importKind" : "exportKind";
  10194. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10195. if (canParseAsKeyword && this.eatContextual(93)) {
  10196. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10197. }
  10198. if (!node[rightOfAsKey]) {
  10199. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  10200. }
  10201. if (isImport) {
  10202. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10203. }
  10204. }
  10205. fillOptionalPropertiesForTSESLint(node) {
  10206. var _node$directive, _node$decorators, _node$optional, _node$typeAnnotation, _node$accessibility, _node$decorators2, _node$override, _node$readonly, _node$static, _node$declare, _node$returnType, _node$typeParameters, _node$optional2, _node$optional3, _node$accessibility2, _node$readonly2, _node$static2, _node$declare2, _node$definite, _node$readonly3, _node$typeAnnotation2, _node$accessibility3, _node$decorators3, _node$override2, _node$optional4, _node$id, _node$abstract, _node$declare3, _node$decorators4, _node$implements, _node$superTypeArgume, _node$typeParameters2, _node$declare4, _node$definite2, _node$const, _node$declare5, _node$computed, _node$qualifier, _node$options, _node$declare6, _node$extends, _node$optional5, _node$readonly4, _node$declare7, _node$global, _node$const2, _node$in, _node$out;
  10207. switch (node.type) {
  10208. case "ExpressionStatement":
  10209. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  10210. return;
  10211. case "RestElement":
  10212. node.value = undefined;
  10213. case "Identifier":
  10214. case "ArrayPattern":
  10215. case "AssignmentPattern":
  10216. case "ObjectPattern":
  10217. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  10218. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  10219. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  10220. return;
  10221. case "TSParameterProperty":
  10222. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  10223. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  10224. (_node$override = node.override) != null ? _node$override : node.override = false;
  10225. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  10226. (_node$static = node.static) != null ? _node$static : node.static = false;
  10227. return;
  10228. case "TSEmptyBodyFunctionExpression":
  10229. node.body = null;
  10230. case "TSDeclareFunction":
  10231. case "FunctionDeclaration":
  10232. case "FunctionExpression":
  10233. case "ClassMethod":
  10234. case "ClassPrivateMethod":
  10235. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  10236. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  10237. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  10238. return;
  10239. case "Property":
  10240. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  10241. return;
  10242. case "TSMethodSignature":
  10243. case "TSPropertySignature":
  10244. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  10245. case "TSIndexSignature":
  10246. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  10247. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  10248. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  10249. return;
  10250. case "TSAbstractPropertyDefinition":
  10251. case "PropertyDefinition":
  10252. case "TSAbstractAccessorProperty":
  10253. case "AccessorProperty":
  10254. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  10255. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  10256. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  10257. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  10258. case "TSAbstractMethodDefinition":
  10259. case "MethodDefinition":
  10260. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  10261. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  10262. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  10263. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  10264. return;
  10265. case "ClassExpression":
  10266. (_node$id = node.id) != null ? _node$id : node.id = null;
  10267. case "ClassDeclaration":
  10268. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  10269. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  10270. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  10271. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  10272. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  10273. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  10274. return;
  10275. case "TSTypeAliasDeclaration":
  10276. case "VariableDeclaration":
  10277. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  10278. return;
  10279. case "VariableDeclarator":
  10280. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  10281. return;
  10282. case "TSEnumDeclaration":
  10283. (_node$const = node.const) != null ? _node$const : node.const = false;
  10284. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  10285. return;
  10286. case "TSEnumMember":
  10287. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  10288. return;
  10289. case "TSImportType":
  10290. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  10291. (_node$options = node.options) != null ? _node$options : node.options = null;
  10292. return;
  10293. case "TSInterfaceDeclaration":
  10294. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  10295. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  10296. return;
  10297. case "TSMappedType":
  10298. (_node$optional5 = node.optional) != null ? _node$optional5 : node.optional = false;
  10299. (_node$readonly4 = node.readonly) != null ? _node$readonly4 : node.readonly = undefined;
  10300. return;
  10301. case "TSModuleDeclaration":
  10302. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  10303. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  10304. return;
  10305. case "TSTypeParameter":
  10306. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  10307. (_node$in = node.in) != null ? _node$in : node.in = false;
  10308. (_node$out = node.out) != null ? _node$out : node.out = false;
  10309. return;
  10310. }
  10311. }
  10312. chStartsBindingIdentifierAndNotRelationalOperator(ch, pos) {
  10313. if (isIdentifierStart(ch)) {
  10314. keywordAndTSRelationalOperator.lastIndex = pos;
  10315. if (keywordAndTSRelationalOperator.test(this.input)) {
  10316. const endCh = this.codePointAtPos(keywordAndTSRelationalOperator.lastIndex);
  10317. if (!isIdentifierChar(endCh) && endCh !== 92) {
  10318. return false;
  10319. }
  10320. }
  10321. return true;
  10322. } else if (ch === 92) {
  10323. return true;
  10324. } else {
  10325. return false;
  10326. }
  10327. }
  10328. nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine() {
  10329. const next = this.nextTokenInLineStart();
  10330. const nextCh = this.codePointAtPos(next);
  10331. return this.chStartsBindingIdentifierAndNotRelationalOperator(nextCh, next);
  10332. }
  10333. nextTokenIsIdentifierOrStringLiteralOnSameLine() {
  10334. const next = this.nextTokenInLineStart();
  10335. const nextCh = this.codePointAtPos(next);
  10336. return this.chStartsBindingIdentifier(nextCh, next) || nextCh === 34 || nextCh === 39;
  10337. }
  10338. };
  10339. function isPossiblyLiteralEnum(expression) {
  10340. if (expression.type !== "MemberExpression") return false;
  10341. const {
  10342. computed,
  10343. property
  10344. } = expression;
  10345. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10346. return false;
  10347. }
  10348. return isUncomputedMemberExpressionChain(expression.object);
  10349. }
  10350. function isValidAmbientConstInitializer(expression, estree) {
  10351. var _expression$extra;
  10352. const {
  10353. type
  10354. } = expression;
  10355. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10356. return false;
  10357. }
  10358. if (estree) {
  10359. if (type === "Literal") {
  10360. const {
  10361. value
  10362. } = expression;
  10363. if (typeof value === "string" || typeof value === "boolean") {
  10364. return true;
  10365. }
  10366. }
  10367. } else {
  10368. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10369. return true;
  10370. }
  10371. }
  10372. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10373. return true;
  10374. }
  10375. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10376. return true;
  10377. }
  10378. if (isPossiblyLiteralEnum(expression)) {
  10379. return true;
  10380. }
  10381. return false;
  10382. }
  10383. function isNumber(expression, estree) {
  10384. if (estree) {
  10385. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10386. }
  10387. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10388. }
  10389. function isNegativeNumber(expression, estree) {
  10390. if (expression.type === "UnaryExpression") {
  10391. const {
  10392. operator,
  10393. argument
  10394. } = expression;
  10395. if (operator === "-" && isNumber(argument, estree)) {
  10396. return true;
  10397. }
  10398. }
  10399. return false;
  10400. }
  10401. function isUncomputedMemberExpressionChain(expression) {
  10402. if (expression.type === "Identifier") return true;
  10403. if (expression.type !== "MemberExpression" || expression.computed) {
  10404. return false;
  10405. }
  10406. return isUncomputedMemberExpressionChain(expression.object);
  10407. }
  10408. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10409. ClassNameIsRequired: "A class name is required.",
  10410. UnexpectedSpace: "Unexpected space in placeholder."
  10411. });
  10412. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10413. parsePlaceholder(expectedNode) {
  10414. if (this.match(133)) {
  10415. const node = this.startNode();
  10416. this.next();
  10417. this.assertNoSpace();
  10418. node.name = super.parseIdentifier(true);
  10419. this.assertNoSpace();
  10420. this.expect(133);
  10421. return this.finishPlaceholder(node, expectedNode);
  10422. }
  10423. }
  10424. finishPlaceholder(node, expectedNode) {
  10425. let placeholder = node;
  10426. if (!placeholder.expectedNode || !placeholder.type) {
  10427. placeholder = this.finishNode(placeholder, "Placeholder");
  10428. }
  10429. placeholder.expectedNode = expectedNode;
  10430. return placeholder;
  10431. }
  10432. getTokenFromCode(code) {
  10433. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10434. this.finishOp(133, 2);
  10435. } else {
  10436. super.getTokenFromCode(code);
  10437. }
  10438. }
  10439. parseExprAtom(refExpressionErrors) {
  10440. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10441. }
  10442. parseIdentifier(liberal) {
  10443. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10444. }
  10445. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10446. if (word !== undefined) {
  10447. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10448. }
  10449. }
  10450. cloneIdentifier(node) {
  10451. const cloned = super.cloneIdentifier(node);
  10452. if (cloned.type === "Placeholder") {
  10453. cloned.expectedNode = node.expectedNode;
  10454. }
  10455. return cloned;
  10456. }
  10457. cloneStringLiteral(node) {
  10458. if (node.type === "Placeholder") {
  10459. return this.cloneIdentifier(node);
  10460. }
  10461. return super.cloneStringLiteral(node);
  10462. }
  10463. parseBindingAtom() {
  10464. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10465. }
  10466. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  10467. return type === "Placeholder" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  10468. }
  10469. toAssignable(node, isLHS) {
  10470. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10471. node.expectedNode = "Pattern";
  10472. } else {
  10473. super.toAssignable(node, isLHS);
  10474. }
  10475. }
  10476. chStartsBindingIdentifier(ch, pos) {
  10477. if (super.chStartsBindingIdentifier(ch, pos)) {
  10478. return true;
  10479. }
  10480. const next = this.nextTokenStart();
  10481. if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
  10482. return true;
  10483. }
  10484. return false;
  10485. }
  10486. verifyBreakContinue(node, isBreak) {
  10487. var _node$label;
  10488. if (((_node$label = node.label) == null ? void 0 : _node$label.type) === "Placeholder") return;
  10489. super.verifyBreakContinue(node, isBreak);
  10490. }
  10491. parseExpressionStatement(node, expr) {
  10492. var _expr$extra;
  10493. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10494. return super.parseExpressionStatement(node, expr);
  10495. }
  10496. if (this.match(14)) {
  10497. const stmt = node;
  10498. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10499. this.next();
  10500. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10501. return this.finishNode(stmt, "LabeledStatement");
  10502. }
  10503. this.semicolon();
  10504. const stmtPlaceholder = node;
  10505. stmtPlaceholder.name = expr.name;
  10506. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  10507. }
  10508. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10509. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10510. }
  10511. parseFunctionId(requireId) {
  10512. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10513. }
  10514. parseClass(node, isStatement, optionalId) {
  10515. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10516. this.next();
  10517. const oldStrict = this.state.strict;
  10518. const placeholder = this.parsePlaceholder("Identifier");
  10519. if (placeholder) {
  10520. if (this.match(81) || this.match(133) || this.match(5)) {
  10521. node.id = placeholder;
  10522. } else if (optionalId || !isStatement) {
  10523. node.id = null;
  10524. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10525. return this.finishNode(node, type);
  10526. } else {
  10527. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10528. }
  10529. } else {
  10530. this.parseClassId(node, isStatement, optionalId);
  10531. }
  10532. super.parseClassSuper(node);
  10533. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10534. return this.finishNode(node, type);
  10535. }
  10536. parseExport(node, decorators) {
  10537. const placeholder = this.parsePlaceholder("Identifier");
  10538. if (!placeholder) return super.parseExport(node, decorators);
  10539. const node2 = node;
  10540. if (!this.isContextual(98) && !this.match(12)) {
  10541. node2.specifiers = [];
  10542. node2.source = null;
  10543. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10544. return this.finishNode(node2, "ExportNamedDeclaration");
  10545. }
  10546. this.expectPlugin("exportDefaultFrom");
  10547. const specifier = this.startNode();
  10548. specifier.exported = placeholder;
  10549. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10550. return super.parseExport(node2, decorators);
  10551. }
  10552. isExportDefaultSpecifier() {
  10553. if (this.match(65)) {
  10554. const next = this.nextTokenStart();
  10555. if (this.isUnparsedContextual(next, "from")) {
  10556. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  10557. return true;
  10558. }
  10559. }
  10560. }
  10561. return super.isExportDefaultSpecifier();
  10562. }
  10563. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10564. var _specifiers;
  10565. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10566. return true;
  10567. }
  10568. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10569. }
  10570. checkExport(node) {
  10571. const {
  10572. specifiers
  10573. } = node;
  10574. if (specifiers != null && specifiers.length) {
  10575. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10576. }
  10577. super.checkExport(node);
  10578. node.specifiers = specifiers;
  10579. }
  10580. parseImport(node) {
  10581. const placeholder = this.parsePlaceholder("Identifier");
  10582. if (!placeholder) return super.parseImport(node);
  10583. node.specifiers = [];
  10584. if (!this.isContextual(98) && !this.match(12)) {
  10585. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10586. this.semicolon();
  10587. return this.finishNode(node, "ImportDeclaration");
  10588. }
  10589. const specifier = this.startNodeAtNode(placeholder);
  10590. specifier.local = placeholder;
  10591. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10592. if (this.eat(12)) {
  10593. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10594. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10595. }
  10596. this.expectContextual(98);
  10597. node.source = this.parseImportSource();
  10598. this.semicolon();
  10599. return this.finishNode(node, "ImportDeclaration");
  10600. }
  10601. parseImportSource() {
  10602. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10603. }
  10604. assertNoSpace() {
  10605. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  10606. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10607. }
  10608. }
  10609. };
  10610. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10611. parseV8Intrinsic() {
  10612. if (this.match(54)) {
  10613. const v8IntrinsicStartLoc = this.state.startLoc;
  10614. const node = this.startNode();
  10615. this.next();
  10616. if (tokenIsIdentifier(this.state.type)) {
  10617. const name = this.parseIdentifierName();
  10618. const identifier = this.createIdentifier(node, name);
  10619. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  10620. if (this.match(10)) {
  10621. return identifier;
  10622. }
  10623. }
  10624. this.unexpected(v8IntrinsicStartLoc);
  10625. }
  10626. }
  10627. parseExprAtom(refExpressionErrors) {
  10628. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10629. }
  10630. };
  10631. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10632. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10633. function validatePlugins(pluginsMap) {
  10634. if (pluginsMap.has("decorators")) {
  10635. if (pluginsMap.has("decorators-legacy")) {
  10636. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10637. }
  10638. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  10639. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10640. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10641. }
  10642. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  10643. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10644. throw new Error("'allowCallParenthesized' must be a boolean.");
  10645. }
  10646. }
  10647. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  10648. throw new Error("Cannot combine flow and typescript plugins.");
  10649. }
  10650. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  10651. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10652. }
  10653. if (pluginsMap.has("pipelineOperator")) {
  10654. var _pluginsMap$get2;
  10655. const proposal = pluginsMap.get("pipelineOperator").proposal;
  10656. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10657. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10658. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10659. }
  10660. if (proposal === "hack") {
  10661. var _pluginsMap$get;
  10662. if (pluginsMap.has("placeholders")) {
  10663. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10664. }
  10665. if (pluginsMap.has("v8intrinsic")) {
  10666. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10667. }
  10668. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  10669. if (!TOPIC_TOKENS.includes(topicToken)) {
  10670. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10671. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10672. }
  10673. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  10674. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10675. }
  10676. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  10677. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10678. }
  10679. }
  10680. if (pluginsMap.has("moduleAttributes")) {
  10681. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  10682. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  10683. }
  10684. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  10685. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10686. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10687. }
  10688. }
  10689. if (pluginsMap.has("importAssertions")) {
  10690. if (pluginsMap.has("deprecatedImportAssert")) {
  10691. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  10692. }
  10693. }
  10694. if (pluginsMap.has("deprecatedImportAssert")) ;else if (pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  10695. pluginsMap.set("deprecatedImportAssert", {});
  10696. }
  10697. if (pluginsMap.has("recordAndTuple")) {
  10698. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  10699. if (syntaxType != null) {
  10700. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10701. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  10702. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10703. }
  10704. }
  10705. }
  10706. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  10707. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10708. error.missingPlugins = "doExpressions";
  10709. throw error;
  10710. }
  10711. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  10712. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10713. }
  10714. if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
  10715. throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
  10716. }
  10717. }
  10718. const mixinPlugins = {
  10719. estree,
  10720. jsx,
  10721. flow,
  10722. typescript,
  10723. v8intrinsic,
  10724. placeholders
  10725. };
  10726. const mixinPluginNames = Object.keys(mixinPlugins);
  10727. class ExpressionParser extends LValParser {
  10728. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  10729. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10730. return sawProto;
  10731. }
  10732. const key = prop.key;
  10733. const name = key.type === "Identifier" ? key.name : key.value;
  10734. if (name === "__proto__") {
  10735. if (isRecord) {
  10736. this.raise(Errors.RecordNoProto, key);
  10737. return true;
  10738. }
  10739. if (sawProto) {
  10740. if (refExpressionErrors) {
  10741. if (refExpressionErrors.doubleProtoLoc === null) {
  10742. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10743. }
  10744. } else {
  10745. this.raise(Errors.DuplicateProto, key);
  10746. }
  10747. }
  10748. return true;
  10749. }
  10750. return sawProto;
  10751. }
  10752. shouldExitDescending(expr, potentialArrowAt) {
  10753. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  10754. }
  10755. getExpression() {
  10756. this.enterInitialScopes();
  10757. this.nextToken();
  10758. if (this.match(140)) {
  10759. throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
  10760. }
  10761. const expr = this.parseExpression();
  10762. if (!this.match(140)) {
  10763. throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
  10764. unexpected: this.input.codePointAt(this.state.start)
  10765. });
  10766. }
  10767. this.finalizeRemainingComments();
  10768. expr.comments = this.comments;
  10769. expr.errors = this.state.errors;
  10770. if (this.optionFlags & 256) {
  10771. expr.tokens = this.tokens;
  10772. }
  10773. return expr;
  10774. }
  10775. parseExpression(disallowIn, refExpressionErrors) {
  10776. if (disallowIn) {
  10777. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10778. }
  10779. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10780. }
  10781. parseExpressionBase(refExpressionErrors) {
  10782. const startLoc = this.state.startLoc;
  10783. const expr = this.parseMaybeAssign(refExpressionErrors);
  10784. if (this.match(12)) {
  10785. const node = this.startNodeAt(startLoc);
  10786. node.expressions = [expr];
  10787. while (this.eat(12)) {
  10788. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10789. }
  10790. this.toReferencedList(node.expressions);
  10791. return this.finishNode(node, "SequenceExpression");
  10792. }
  10793. return expr;
  10794. }
  10795. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10796. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10797. }
  10798. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10799. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10800. }
  10801. setOptionalParametersError(refExpressionErrors) {
  10802. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  10803. }
  10804. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10805. const startLoc = this.state.startLoc;
  10806. const isYield = this.isContextual(108);
  10807. if (isYield) {
  10808. if (this.prodParam.hasYield) {
  10809. this.next();
  10810. let left = this.parseYield(startLoc);
  10811. if (afterLeftParse) {
  10812. left = afterLeftParse.call(this, left, startLoc);
  10813. }
  10814. return left;
  10815. }
  10816. }
  10817. let ownExpressionErrors;
  10818. if (refExpressionErrors) {
  10819. ownExpressionErrors = false;
  10820. } else {
  10821. refExpressionErrors = new ExpressionErrors();
  10822. ownExpressionErrors = true;
  10823. }
  10824. const {
  10825. type
  10826. } = this.state;
  10827. if (type === 10 || tokenIsIdentifier(type)) {
  10828. this.state.potentialArrowAt = this.state.start;
  10829. }
  10830. let left = this.parseMaybeConditional(refExpressionErrors);
  10831. if (afterLeftParse) {
  10832. left = afterLeftParse.call(this, left, startLoc);
  10833. }
  10834. if (tokenIsAssignment(this.state.type)) {
  10835. const node = this.startNodeAt(startLoc);
  10836. const operator = this.state.value;
  10837. node.operator = operator;
  10838. if (this.match(29)) {
  10839. this.toAssignable(left, true);
  10840. node.left = left;
  10841. const startIndex = startLoc.index;
  10842. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10843. refExpressionErrors.doubleProtoLoc = null;
  10844. }
  10845. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10846. refExpressionErrors.shorthandAssignLoc = null;
  10847. }
  10848. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10849. this.checkDestructuringPrivate(refExpressionErrors);
  10850. refExpressionErrors.privateKeyLoc = null;
  10851. }
  10852. if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
  10853. refExpressionErrors.voidPatternLoc = null;
  10854. }
  10855. } else {
  10856. node.left = left;
  10857. }
  10858. this.next();
  10859. node.right = this.parseMaybeAssign();
  10860. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"), undefined, undefined, undefined, undefined, operator === "||=" || operator === "&&=" || operator === "??=");
  10861. return node;
  10862. } else if (ownExpressionErrors) {
  10863. this.checkExpressionErrors(refExpressionErrors, true);
  10864. }
  10865. if (isYield) {
  10866. const {
  10867. type
  10868. } = this.state;
  10869. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10870. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  10871. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  10872. return this.parseYield(startLoc);
  10873. }
  10874. }
  10875. return left;
  10876. }
  10877. parseMaybeConditional(refExpressionErrors) {
  10878. const startLoc = this.state.startLoc;
  10879. const potentialArrowAt = this.state.potentialArrowAt;
  10880. const expr = this.parseExprOps(refExpressionErrors);
  10881. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10882. return expr;
  10883. }
  10884. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10885. }
  10886. parseConditional(expr, startLoc, refExpressionErrors) {
  10887. if (this.eat(17)) {
  10888. const node = this.startNodeAt(startLoc);
  10889. node.test = expr;
  10890. node.consequent = this.parseMaybeAssignAllowIn();
  10891. this.expect(14);
  10892. node.alternate = this.parseMaybeAssign();
  10893. return this.finishNode(node, "ConditionalExpression");
  10894. }
  10895. return expr;
  10896. }
  10897. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10898. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10899. }
  10900. parseExprOps(refExpressionErrors) {
  10901. const startLoc = this.state.startLoc;
  10902. const potentialArrowAt = this.state.potentialArrowAt;
  10903. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10904. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10905. return expr;
  10906. }
  10907. return this.parseExprOp(expr, startLoc, -1);
  10908. }
  10909. parseExprOp(left, leftStartLoc, minPrec) {
  10910. if (this.isPrivateName(left)) {
  10911. const value = this.getPrivateNameSV(left);
  10912. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10913. this.raise(Errors.PrivateInExpectedIn, left, {
  10914. identifierName: value
  10915. });
  10916. }
  10917. this.classScope.usePrivateName(value, left.loc.start);
  10918. }
  10919. const op = this.state.type;
  10920. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10921. let prec = tokenOperatorPrecedence(op);
  10922. if (prec > minPrec) {
  10923. if (op === 39) {
  10924. this.expectPlugin("pipelineOperator");
  10925. if (this.state.inFSharpPipelineDirectBody) {
  10926. return left;
  10927. }
  10928. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10929. }
  10930. const node = this.startNodeAt(leftStartLoc);
  10931. node.left = left;
  10932. node.operator = this.state.value;
  10933. const logical = op === 41 || op === 42;
  10934. const coalesce = op === 40;
  10935. if (coalesce) {
  10936. prec = tokenOperatorPrecedence(42);
  10937. }
  10938. this.next();
  10939. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10940. proposal: "minimal"
  10941. }])) {
  10942. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10943. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  10944. }
  10945. }
  10946. node.right = this.parseExprOpRightExpr(op, prec);
  10947. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10948. const nextOp = this.state.type;
  10949. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10950. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  10951. }
  10952. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10953. }
  10954. }
  10955. return left;
  10956. }
  10957. parseExprOpRightExpr(op, prec) {
  10958. const startLoc = this.state.startLoc;
  10959. switch (op) {
  10960. case 39:
  10961. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10962. case "hack":
  10963. return this.withTopicBindingContext(() => {
  10964. return this.parseHackPipeBody();
  10965. });
  10966. case "fsharp":
  10967. return this.withSoloAwaitPermittingContext(() => {
  10968. return this.parseFSharpPipelineBody(prec);
  10969. });
  10970. }
  10971. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  10972. return this.withTopicBindingContext(() => {
  10973. if (this.prodParam.hasYield && this.isContextual(108)) {
  10974. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  10975. }
  10976. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10977. });
  10978. }
  10979. default:
  10980. return this.parseExprOpBaseRightExpr(op, prec);
  10981. }
  10982. }
  10983. parseExprOpBaseRightExpr(op, prec) {
  10984. const startLoc = this.state.startLoc;
  10985. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10986. }
  10987. parseHackPipeBody() {
  10988. var _body$extra;
  10989. const {
  10990. startLoc
  10991. } = this.state;
  10992. const body = this.parseMaybeAssign();
  10993. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10994. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10995. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  10996. type: body.type
  10997. });
  10998. }
  10999. if (!this.topicReferenceWasUsedInCurrentContext()) {
  11000. this.raise(Errors.PipeTopicUnused, startLoc);
  11001. }
  11002. return body;
  11003. }
  11004. checkExponentialAfterUnary(node) {
  11005. if (this.match(57)) {
  11006. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  11007. }
  11008. }
  11009. parseMaybeUnary(refExpressionErrors, sawUnary) {
  11010. const startLoc = this.state.startLoc;
  11011. const isAwait = this.isContextual(96);
  11012. if (isAwait && this.recordAwaitIfAllowed()) {
  11013. this.next();
  11014. const expr = this.parseAwait(startLoc);
  11015. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  11016. return expr;
  11017. }
  11018. const update = this.match(34);
  11019. const node = this.startNode();
  11020. if (tokenIsPrefix(this.state.type)) {
  11021. node.operator = this.state.value;
  11022. node.prefix = true;
  11023. if (this.match(72)) {
  11024. this.expectPlugin("throwExpressions");
  11025. }
  11026. const isDelete = this.match(89);
  11027. this.next();
  11028. node.argument = this.parseMaybeUnary(null, true);
  11029. this.checkExpressionErrors(refExpressionErrors, true);
  11030. if (this.state.strict && isDelete) {
  11031. const arg = node.argument;
  11032. if (arg.type === "Identifier") {
  11033. this.raise(Errors.StrictDelete, node);
  11034. } else if (this.hasPropertyAsPrivateName(arg)) {
  11035. this.raise(Errors.DeletePrivateField, node);
  11036. }
  11037. }
  11038. if (!update) {
  11039. if (!sawUnary) {
  11040. this.checkExponentialAfterUnary(node);
  11041. }
  11042. return this.finishNode(node, "UnaryExpression");
  11043. }
  11044. }
  11045. const expr = this.parseUpdate(node, update, refExpressionErrors);
  11046. if (isAwait) {
  11047. const {
  11048. type
  11049. } = this.state;
  11050. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  11051. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  11052. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  11053. return this.parseAwait(startLoc);
  11054. }
  11055. }
  11056. return expr;
  11057. }
  11058. parseUpdate(node, update, refExpressionErrors) {
  11059. if (update) {
  11060. const updateExpressionNode = node;
  11061. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  11062. return node;
  11063. }
  11064. const startLoc = this.state.startLoc;
  11065. let expr = this.parseExprSubscripts(refExpressionErrors);
  11066. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  11067. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  11068. const node = this.startNodeAt(startLoc);
  11069. node.operator = this.state.value;
  11070. node.prefix = false;
  11071. node.argument = expr;
  11072. this.next();
  11073. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  11074. }
  11075. return expr;
  11076. }
  11077. parseExprSubscripts(refExpressionErrors) {
  11078. const startLoc = this.state.startLoc;
  11079. const potentialArrowAt = this.state.potentialArrowAt;
  11080. const expr = this.parseExprAtom(refExpressionErrors);
  11081. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11082. return expr;
  11083. }
  11084. return this.parseSubscripts(expr, startLoc);
  11085. }
  11086. parseSubscripts(base, startLoc, noCalls) {
  11087. const state = {
  11088. optionalChainMember: false,
  11089. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  11090. stop: false
  11091. };
  11092. do {
  11093. base = this.parseSubscript(base, startLoc, noCalls, state);
  11094. state.maybeAsyncArrow = false;
  11095. } while (!state.stop);
  11096. return base;
  11097. }
  11098. parseSubscript(base, startLoc, noCalls, state) {
  11099. const {
  11100. type
  11101. } = this.state;
  11102. if (!noCalls && type === 15) {
  11103. return this.parseBind(base, startLoc, noCalls, state);
  11104. } else if (tokenIsTemplate(type)) {
  11105. return this.parseTaggedTemplateExpression(base, startLoc, state);
  11106. }
  11107. let optional = false;
  11108. if (type === 18) {
  11109. if (noCalls) {
  11110. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  11111. if (this.lookaheadCharCode() === 40) {
  11112. return this.stopParseSubscript(base, state);
  11113. }
  11114. }
  11115. state.optionalChainMember = optional = true;
  11116. this.next();
  11117. }
  11118. if (!noCalls && this.match(10)) {
  11119. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  11120. } else {
  11121. const computed = this.eat(0);
  11122. if (computed || optional || this.eat(16)) {
  11123. return this.parseMember(base, startLoc, state, computed, optional);
  11124. } else {
  11125. return this.stopParseSubscript(base, state);
  11126. }
  11127. }
  11128. }
  11129. stopParseSubscript(base, state) {
  11130. state.stop = true;
  11131. return base;
  11132. }
  11133. parseMember(base, startLoc, state, computed, optional) {
  11134. const node = this.startNodeAt(startLoc);
  11135. node.object = base;
  11136. node.computed = computed;
  11137. if (computed) {
  11138. node.property = this.parseExpression();
  11139. this.expect(3);
  11140. } else if (this.match(139)) {
  11141. if (base.type === "Super") {
  11142. this.raise(Errors.SuperPrivateField, startLoc);
  11143. }
  11144. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  11145. node.property = this.parsePrivateName();
  11146. } else {
  11147. node.property = this.parseIdentifier(true);
  11148. }
  11149. if (state.optionalChainMember) {
  11150. node.optional = optional;
  11151. return this.finishNode(node, "OptionalMemberExpression");
  11152. } else {
  11153. return this.finishNode(node, "MemberExpression");
  11154. }
  11155. }
  11156. parseBind(base, startLoc, noCalls, state) {
  11157. const node = this.startNodeAt(startLoc);
  11158. node.object = base;
  11159. this.next();
  11160. node.callee = this.parseNoCallExpr();
  11161. state.stop = true;
  11162. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  11163. }
  11164. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  11165. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11166. let refExpressionErrors = null;
  11167. this.state.maybeInArrowParameters = true;
  11168. this.next();
  11169. const node = this.startNodeAt(startLoc);
  11170. node.callee = base;
  11171. const {
  11172. maybeAsyncArrow,
  11173. optionalChainMember
  11174. } = state;
  11175. if (maybeAsyncArrow) {
  11176. this.expressionScope.enter(newAsyncArrowScope());
  11177. refExpressionErrors = new ExpressionErrors();
  11178. }
  11179. if (optionalChainMember) {
  11180. node.optional = optional;
  11181. }
  11182. if (optional) {
  11183. node.arguments = this.parseCallExpressionArguments();
  11184. } else {
  11185. node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
  11186. }
  11187. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  11188. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  11189. state.stop = true;
  11190. this.checkDestructuringPrivate(refExpressionErrors);
  11191. this.expressionScope.validateAsPattern();
  11192. this.expressionScope.exit();
  11193. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  11194. } else {
  11195. if (maybeAsyncArrow) {
  11196. this.checkExpressionErrors(refExpressionErrors, true);
  11197. this.expressionScope.exit();
  11198. }
  11199. this.toReferencedArguments(finishedNode);
  11200. }
  11201. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11202. return finishedNode;
  11203. }
  11204. toReferencedArguments(node, isParenthesizedExpr) {
  11205. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11206. }
  11207. parseTaggedTemplateExpression(base, startLoc, state) {
  11208. const node = this.startNodeAt(startLoc);
  11209. node.tag = base;
  11210. node.quasi = this.parseTemplate(true);
  11211. if (state.optionalChainMember) {
  11212. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  11213. }
  11214. return this.finishNode(node, "TaggedTemplateExpression");
  11215. }
  11216. atPossibleAsyncArrow(base) {
  11217. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && this.offsetToSourcePos(base.start) === this.state.potentialArrowAt;
  11218. }
  11219. finishCallExpression(node, optional) {
  11220. if (node.callee.type === "Import") {
  11221. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11222. this.raise(Errors.ImportCallArity, node);
  11223. } else {
  11224. for (const arg of node.arguments) {
  11225. if (arg.type === "SpreadElement") {
  11226. this.raise(Errors.ImportCallSpreadArgument, arg);
  11227. }
  11228. }
  11229. }
  11230. }
  11231. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11232. }
  11233. parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11234. const elts = [];
  11235. let first = true;
  11236. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11237. this.state.inFSharpPipelineDirectBody = false;
  11238. while (!this.eat(11)) {
  11239. if (first) {
  11240. first = false;
  11241. } else {
  11242. this.expect(12);
  11243. if (this.match(11)) {
  11244. if (nodeForExtra) {
  11245. this.addTrailingCommaExtraToNode(nodeForExtra);
  11246. }
  11247. this.next();
  11248. break;
  11249. }
  11250. }
  11251. elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
  11252. }
  11253. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11254. return elts;
  11255. }
  11256. shouldParseAsyncArrow() {
  11257. return this.match(19) && !this.canInsertSemicolon();
  11258. }
  11259. parseAsyncArrowFromCallExpression(node, call) {
  11260. var _call$extra;
  11261. this.resetPreviousNodeTrailingComments(call);
  11262. this.expect(19);
  11263. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11264. if (call.innerComments) {
  11265. setInnerComments(node, call.innerComments);
  11266. }
  11267. if (call.callee.trailingComments) {
  11268. setInnerComments(node, call.callee.trailingComments);
  11269. }
  11270. return node;
  11271. }
  11272. parseNoCallExpr() {
  11273. const startLoc = this.state.startLoc;
  11274. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11275. }
  11276. parseExprAtom(refExpressionErrors) {
  11277. let node;
  11278. let decorators = null;
  11279. const {
  11280. type
  11281. } = this.state;
  11282. switch (type) {
  11283. case 79:
  11284. return this.parseSuper();
  11285. case 83:
  11286. node = this.startNode();
  11287. this.next();
  11288. if (this.match(16)) {
  11289. return this.parseImportMetaPropertyOrPhaseCall(node);
  11290. }
  11291. if (this.match(10)) {
  11292. if (this.optionFlags & 512) {
  11293. return this.parseImportCall(node);
  11294. } else {
  11295. return this.finishNode(node, "Import");
  11296. }
  11297. } else {
  11298. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  11299. return this.finishNode(node, "Import");
  11300. }
  11301. case 78:
  11302. node = this.startNode();
  11303. this.next();
  11304. return this.finishNode(node, "ThisExpression");
  11305. case 90:
  11306. {
  11307. return this.parseDo(this.startNode(), false);
  11308. }
  11309. case 56:
  11310. case 31:
  11311. {
  11312. this.readRegexp();
  11313. return this.parseRegExpLiteral(this.state.value);
  11314. }
  11315. case 135:
  11316. return this.parseNumericLiteral(this.state.value);
  11317. case 136:
  11318. return this.parseBigIntLiteral(this.state.value);
  11319. case 134:
  11320. return this.parseStringLiteral(this.state.value);
  11321. case 84:
  11322. return this.parseNullLiteral();
  11323. case 85:
  11324. return this.parseBooleanLiteral(true);
  11325. case 86:
  11326. return this.parseBooleanLiteral(false);
  11327. case 10:
  11328. {
  11329. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11330. return this.parseParenAndDistinguishExpression(canBeArrow);
  11331. }
  11332. case 0:
  11333. {
  11334. return this.parseArrayLike(3, false, refExpressionErrors);
  11335. }
  11336. case 5:
  11337. {
  11338. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11339. }
  11340. case 68:
  11341. return this.parseFunctionOrFunctionSent();
  11342. case 26:
  11343. decorators = this.parseDecorators();
  11344. case 80:
  11345. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11346. case 77:
  11347. return this.parseNewOrNewTarget();
  11348. case 25:
  11349. case 24:
  11350. return this.parseTemplate(false);
  11351. case 15:
  11352. {
  11353. node = this.startNode();
  11354. this.next();
  11355. node.object = null;
  11356. const callee = node.callee = this.parseNoCallExpr();
  11357. if (callee.type === "MemberExpression") {
  11358. return this.finishNode(node, "BindExpression");
  11359. } else {
  11360. throw this.raise(Errors.UnsupportedBind, callee);
  11361. }
  11362. }
  11363. case 139:
  11364. {
  11365. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  11366. identifierName: this.state.value
  11367. });
  11368. return this.parsePrivateName();
  11369. }
  11370. case 33:
  11371. {
  11372. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11373. }
  11374. case 32:
  11375. {
  11376. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11377. }
  11378. case 37:
  11379. case 38:
  11380. {
  11381. return this.parseTopicReference("hack");
  11382. }
  11383. case 44:
  11384. case 54:
  11385. case 27:
  11386. {
  11387. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11388. if (pipeProposal) {
  11389. return this.parseTopicReference(pipeProposal);
  11390. }
  11391. throw this.unexpected();
  11392. }
  11393. case 47:
  11394. {
  11395. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11396. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11397. throw this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11398. }
  11399. throw this.unexpected();
  11400. }
  11401. default:
  11402. if (type === 137) {
  11403. return this.parseDecimalLiteral(this.state.value);
  11404. } else if (type === 2 || type === 1) {
  11405. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, true);
  11406. } else if (type === 6 || type === 7) {
  11407. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11408. }
  11409. if (tokenIsIdentifier(type)) {
  11410. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11411. return this.parseModuleExpression();
  11412. }
  11413. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11414. const containsEsc = this.state.containsEsc;
  11415. const id = this.parseIdentifier();
  11416. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11417. const {
  11418. type
  11419. } = this.state;
  11420. if (type === 68) {
  11421. this.resetPreviousNodeTrailingComments(id);
  11422. this.next();
  11423. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11424. } else if (tokenIsIdentifier(type)) {
  11425. if (this.lookaheadCharCode() === 61) {
  11426. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11427. } else {
  11428. return id;
  11429. }
  11430. } else if (type === 90) {
  11431. this.resetPreviousNodeTrailingComments(id);
  11432. return this.parseDo(this.startNodeAtNode(id), true);
  11433. }
  11434. }
  11435. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11436. this.next();
  11437. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11438. }
  11439. return id;
  11440. } else {
  11441. throw this.unexpected();
  11442. }
  11443. }
  11444. }
  11445. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11446. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11447. if (pipeProposal) {
  11448. this.state.type = topicTokenType;
  11449. this.state.value = topicTokenValue;
  11450. this.state.pos--;
  11451. this.state.end--;
  11452. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11453. return this.parseTopicReference(pipeProposal);
  11454. }
  11455. throw this.unexpected();
  11456. }
  11457. parseTopicReference(pipeProposal) {
  11458. const node = this.startNode();
  11459. const startLoc = this.state.startLoc;
  11460. const tokenType = this.state.type;
  11461. this.next();
  11462. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11463. }
  11464. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11465. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11466. if (pipeProposal === "hack") {
  11467. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11468. this.raise(Errors.PipeTopicUnbound, startLoc);
  11469. }
  11470. this.registerTopicReference();
  11471. return this.finishNode(node, "TopicReference");
  11472. } else {
  11473. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11474. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  11475. }
  11476. this.registerTopicReference();
  11477. return this.finishNode(node, "PipelinePrimaryTopicReference");
  11478. }
  11479. } else {
  11480. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11481. token: tokenLabelName(tokenType)
  11482. });
  11483. }
  11484. }
  11485. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11486. switch (pipeProposal) {
  11487. case "hack":
  11488. {
  11489. return this.hasPlugin(["pipelineOperator", {
  11490. topicToken: tokenLabelName(tokenType)
  11491. }]);
  11492. }
  11493. case "smart":
  11494. return tokenType === 27;
  11495. default:
  11496. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11497. }
  11498. }
  11499. parseAsyncArrowUnaryFunction(node) {
  11500. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11501. const params = [this.parseIdentifier()];
  11502. this.prodParam.exit();
  11503. if (this.hasPrecedingLineBreak()) {
  11504. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11505. }
  11506. this.expect(19);
  11507. return this.parseArrowExpression(node, params, true);
  11508. }
  11509. parseDo(node, isAsync) {
  11510. this.expectPlugin("doExpressions");
  11511. if (isAsync) {
  11512. this.expectPlugin("asyncDoExpressions");
  11513. }
  11514. node.async = isAsync;
  11515. this.next();
  11516. const oldLabels = this.state.labels;
  11517. this.state.labels = [];
  11518. if (isAsync) {
  11519. this.prodParam.enter(2);
  11520. node.body = this.parseBlock();
  11521. this.prodParam.exit();
  11522. } else {
  11523. node.body = this.parseBlock();
  11524. }
  11525. this.state.labels = oldLabels;
  11526. return this.finishNode(node, "DoExpression");
  11527. }
  11528. parseSuper() {
  11529. const node = this.startNode();
  11530. this.next();
  11531. if (this.match(10) && !this.scope.allowDirectSuper) {
  11532. if (!(this.optionFlags & 16)) {
  11533. this.raise(Errors.SuperNotAllowed, node);
  11534. }
  11535. } else if (!this.scope.allowSuper) {
  11536. if (!(this.optionFlags & 16)) {
  11537. this.raise(Errors.UnexpectedSuper, node);
  11538. }
  11539. }
  11540. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11541. this.raise(Errors.UnsupportedSuper, node);
  11542. }
  11543. return this.finishNode(node, "Super");
  11544. }
  11545. parsePrivateName() {
  11546. const node = this.startNode();
  11547. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11548. const name = this.state.value;
  11549. this.next();
  11550. node.id = this.createIdentifier(id, name);
  11551. return this.finishNode(node, "PrivateName");
  11552. }
  11553. parseFunctionOrFunctionSent() {
  11554. const node = this.startNode();
  11555. this.next();
  11556. if (this.prodParam.hasYield && this.match(16)) {
  11557. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11558. this.next();
  11559. if (this.match(103)) {
  11560. this.expectPlugin("functionSent");
  11561. } else if (!this.hasPlugin("functionSent")) {
  11562. this.unexpected();
  11563. }
  11564. return this.parseMetaProperty(node, meta, "sent");
  11565. }
  11566. return this.parseFunction(node);
  11567. }
  11568. parseMetaProperty(node, meta, propertyName) {
  11569. node.meta = meta;
  11570. const containsEsc = this.state.containsEsc;
  11571. node.property = this.parseIdentifier(true);
  11572. if (node.property.name !== propertyName || containsEsc) {
  11573. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11574. target: meta.name,
  11575. onlyValidPropertyName: propertyName
  11576. });
  11577. }
  11578. return this.finishNode(node, "MetaProperty");
  11579. }
  11580. parseImportMetaPropertyOrPhaseCall(node) {
  11581. this.next();
  11582. if (this.isContextual(105) || this.isContextual(97)) {
  11583. const isSource = this.isContextual(105);
  11584. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11585. this.next();
  11586. node.phase = isSource ? "source" : "defer";
  11587. return this.parseImportCall(node);
  11588. } else {
  11589. const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
  11590. if (this.isContextual(101)) {
  11591. if (!this.inModule) {
  11592. this.raise(Errors.ImportMetaOutsideModule, id);
  11593. }
  11594. this.sawUnambiguousESM = true;
  11595. }
  11596. return this.parseMetaProperty(node, id, "meta");
  11597. }
  11598. }
  11599. parseLiteralAtNode(value, type, node) {
  11600. this.addExtra(node, "rawValue", value);
  11601. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11602. node.value = value;
  11603. this.next();
  11604. return this.finishNode(node, type);
  11605. }
  11606. parseLiteral(value, type) {
  11607. const node = this.startNode();
  11608. return this.parseLiteralAtNode(value, type, node);
  11609. }
  11610. parseStringLiteral(value) {
  11611. return this.parseLiteral(value, "StringLiteral");
  11612. }
  11613. parseNumericLiteral(value) {
  11614. return this.parseLiteral(value, "NumericLiteral");
  11615. }
  11616. parseBigIntLiteral(value) {
  11617. return this.parseLiteral(value, "BigIntLiteral");
  11618. }
  11619. parseDecimalLiteral(value) {
  11620. return this.parseLiteral(value, "DecimalLiteral");
  11621. }
  11622. parseRegExpLiteral(value) {
  11623. const node = this.startNode();
  11624. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11625. node.pattern = value.pattern;
  11626. node.flags = value.flags;
  11627. this.next();
  11628. return this.finishNode(node, "RegExpLiteral");
  11629. }
  11630. parseBooleanLiteral(value) {
  11631. const node = this.startNode();
  11632. node.value = value;
  11633. this.next();
  11634. return this.finishNode(node, "BooleanLiteral");
  11635. }
  11636. parseNullLiteral() {
  11637. const node = this.startNode();
  11638. this.next();
  11639. return this.finishNode(node, "NullLiteral");
  11640. }
  11641. parseParenAndDistinguishExpression(canBeArrow) {
  11642. const startLoc = this.state.startLoc;
  11643. let val;
  11644. this.next();
  11645. this.expressionScope.enter(newArrowHeadScope());
  11646. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11647. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11648. this.state.maybeInArrowParameters = true;
  11649. this.state.inFSharpPipelineDirectBody = false;
  11650. const innerStartLoc = this.state.startLoc;
  11651. const exprList = [];
  11652. const refExpressionErrors = new ExpressionErrors();
  11653. let first = true;
  11654. let spreadStartLoc;
  11655. let optionalCommaStartLoc;
  11656. while (!this.match(11)) {
  11657. if (first) {
  11658. first = false;
  11659. } else {
  11660. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11661. if (this.match(11)) {
  11662. optionalCommaStartLoc = this.state.startLoc;
  11663. break;
  11664. }
  11665. }
  11666. if (this.match(21)) {
  11667. const spreadNodeStartLoc = this.state.startLoc;
  11668. spreadStartLoc = this.state.startLoc;
  11669. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11670. if (!this.checkCommaAfterRest(41)) {
  11671. break;
  11672. }
  11673. } else {
  11674. exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
  11675. }
  11676. }
  11677. const innerEndLoc = this.state.lastTokEndLoc;
  11678. this.expect(11);
  11679. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11680. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11681. let arrowNode = this.startNodeAt(startLoc);
  11682. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11683. this.checkDestructuringPrivate(refExpressionErrors);
  11684. this.expressionScope.validateAsPattern();
  11685. this.expressionScope.exit();
  11686. this.parseArrowExpression(arrowNode, exprList, false);
  11687. return arrowNode;
  11688. }
  11689. this.expressionScope.exit();
  11690. if (!exprList.length) {
  11691. this.unexpected(this.state.lastTokStartLoc);
  11692. }
  11693. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11694. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11695. this.checkExpressionErrors(refExpressionErrors, true);
  11696. this.toReferencedListDeep(exprList, true);
  11697. if (exprList.length > 1) {
  11698. val = this.startNodeAt(innerStartLoc);
  11699. val.expressions = exprList;
  11700. this.finishNode(val, "SequenceExpression");
  11701. this.resetEndLocation(val, innerEndLoc);
  11702. } else {
  11703. val = exprList[0];
  11704. }
  11705. return this.wrapParenthesis(startLoc, val);
  11706. }
  11707. wrapParenthesis(startLoc, expression) {
  11708. if (!(this.optionFlags & 1024)) {
  11709. this.addExtra(expression, "parenthesized", true);
  11710. this.addExtra(expression, "parenStart", startLoc.index);
  11711. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11712. return expression;
  11713. }
  11714. const parenExpression = this.startNodeAt(startLoc);
  11715. parenExpression.expression = expression;
  11716. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11717. }
  11718. shouldParseArrow(params) {
  11719. return !this.canInsertSemicolon();
  11720. }
  11721. parseArrow(node) {
  11722. if (this.eat(19)) {
  11723. return node;
  11724. }
  11725. }
  11726. parseParenItem(node, startLoc) {
  11727. return node;
  11728. }
  11729. parseNewOrNewTarget() {
  11730. const node = this.startNode();
  11731. this.next();
  11732. if (this.match(16)) {
  11733. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11734. this.next();
  11735. const metaProp = this.parseMetaProperty(node, meta, "target");
  11736. if (!this.scope.allowNewTarget) {
  11737. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11738. }
  11739. return metaProp;
  11740. }
  11741. return this.parseNew(node);
  11742. }
  11743. parseNew(node) {
  11744. this.parseNewCallee(node);
  11745. if (this.eat(10)) {
  11746. const args = this.parseExprList(11);
  11747. this.toReferencedList(args);
  11748. node.arguments = args;
  11749. } else {
  11750. node.arguments = [];
  11751. }
  11752. return this.finishNode(node, "NewExpression");
  11753. }
  11754. parseNewCallee(node) {
  11755. const isImport = this.match(83);
  11756. const callee = this.parseNoCallExpr();
  11757. node.callee = callee;
  11758. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11759. this.raise(Errors.ImportCallNotNewExpression, callee);
  11760. }
  11761. }
  11762. parseTemplateElement(isTagged) {
  11763. const {
  11764. start,
  11765. startLoc,
  11766. end,
  11767. value
  11768. } = this.state;
  11769. const elemStart = start + 1;
  11770. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11771. if (value === null) {
  11772. if (!isTagged) {
  11773. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11774. }
  11775. }
  11776. const isTail = this.match(24);
  11777. const endOffset = isTail ? -1 : -2;
  11778. const elemEnd = end + endOffset;
  11779. elem.value = {
  11780. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11781. cooked: value === null ? null : value.slice(1, endOffset)
  11782. };
  11783. elem.tail = isTail;
  11784. this.next();
  11785. const finishedNode = this.finishNode(elem, "TemplateElement");
  11786. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11787. return finishedNode;
  11788. }
  11789. parseTemplate(isTagged) {
  11790. const node = this.startNode();
  11791. let curElt = this.parseTemplateElement(isTagged);
  11792. const quasis = [curElt];
  11793. const substitutions = [];
  11794. while (!curElt.tail) {
  11795. substitutions.push(this.parseTemplateSubstitution());
  11796. this.readTemplateContinuation();
  11797. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11798. }
  11799. node.expressions = substitutions;
  11800. node.quasis = quasis;
  11801. return this.finishNode(node, "TemplateLiteral");
  11802. }
  11803. parseTemplateSubstitution() {
  11804. return this.parseExpression();
  11805. }
  11806. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11807. if (isRecord) {
  11808. this.expectPlugin("recordAndTuple");
  11809. }
  11810. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11811. this.state.inFSharpPipelineDirectBody = false;
  11812. let sawProto = false;
  11813. let first = true;
  11814. const node = this.startNode();
  11815. node.properties = [];
  11816. this.next();
  11817. while (!this.match(close)) {
  11818. if (first) {
  11819. first = false;
  11820. } else {
  11821. this.expect(12);
  11822. if (this.match(close)) {
  11823. this.addTrailingCommaExtraToNode(node);
  11824. break;
  11825. }
  11826. }
  11827. let prop;
  11828. if (isPattern) {
  11829. prop = this.parseBindingProperty();
  11830. } else {
  11831. prop = this.parsePropertyDefinition(refExpressionErrors);
  11832. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  11833. }
  11834. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11835. this.raise(Errors.InvalidRecordProperty, prop);
  11836. }
  11837. if (prop.shorthand) {
  11838. this.addExtra(prop, "shorthand", true);
  11839. }
  11840. node.properties.push(prop);
  11841. }
  11842. this.next();
  11843. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11844. let type = "ObjectExpression";
  11845. if (isPattern) {
  11846. type = "ObjectPattern";
  11847. } else if (isRecord) {
  11848. type = "RecordExpression";
  11849. }
  11850. return this.finishNode(node, type);
  11851. }
  11852. addTrailingCommaExtraToNode(node) {
  11853. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11854. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11855. }
  11856. maybeAsyncOrAccessorProp(prop) {
  11857. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11858. }
  11859. parsePropertyDefinition(refExpressionErrors) {
  11860. let decorators = [];
  11861. if (this.match(26)) {
  11862. if (this.hasPlugin("decorators")) {
  11863. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11864. }
  11865. while (this.match(26)) {
  11866. decorators.push(this.parseDecorator());
  11867. }
  11868. }
  11869. const prop = this.startNode();
  11870. let isAsync = false;
  11871. let isAccessor = false;
  11872. let startLoc;
  11873. if (this.match(21)) {
  11874. if (decorators.length) this.unexpected();
  11875. return this.parseSpread();
  11876. }
  11877. if (decorators.length) {
  11878. prop.decorators = decorators;
  11879. decorators = [];
  11880. }
  11881. prop.method = false;
  11882. if (refExpressionErrors) {
  11883. startLoc = this.state.startLoc;
  11884. }
  11885. let isGenerator = this.eat(55);
  11886. this.parsePropertyNamePrefixOperator(prop);
  11887. const containsEsc = this.state.containsEsc;
  11888. this.parsePropertyName(prop, refExpressionErrors);
  11889. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11890. const {
  11891. key
  11892. } = prop;
  11893. const keyName = key.name;
  11894. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11895. isAsync = true;
  11896. this.resetPreviousNodeTrailingComments(key);
  11897. isGenerator = this.eat(55);
  11898. this.parsePropertyName(prop);
  11899. }
  11900. if (keyName === "get" || keyName === "set") {
  11901. isAccessor = true;
  11902. this.resetPreviousNodeTrailingComments(key);
  11903. prop.kind = keyName;
  11904. if (this.match(55)) {
  11905. isGenerator = true;
  11906. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11907. kind: keyName
  11908. });
  11909. this.next();
  11910. }
  11911. this.parsePropertyName(prop);
  11912. }
  11913. }
  11914. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11915. }
  11916. getGetterSetterExpectedParamCount(method) {
  11917. return method.kind === "get" ? 0 : 1;
  11918. }
  11919. getObjectOrClassMethodParams(method) {
  11920. return method.params;
  11921. }
  11922. checkGetterSetterParams(method) {
  11923. var _params;
  11924. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11925. const params = this.getObjectOrClassMethodParams(method);
  11926. if (params.length !== paramCount) {
  11927. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  11928. }
  11929. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11930. this.raise(Errors.BadSetterRestParameter, method);
  11931. }
  11932. }
  11933. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11934. if (isAccessor) {
  11935. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11936. this.checkGetterSetterParams(finishedProp);
  11937. return finishedProp;
  11938. }
  11939. if (isAsync || isGenerator || this.match(10)) {
  11940. if (isPattern) this.unexpected();
  11941. prop.kind = "method";
  11942. prop.method = true;
  11943. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11944. }
  11945. }
  11946. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11947. prop.shorthand = false;
  11948. if (this.eat(14)) {
  11949. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
  11950. return this.finishObjectProperty(prop);
  11951. }
  11952. if (!prop.computed && prop.key.type === "Identifier") {
  11953. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11954. if (isPattern) {
  11955. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  11956. } else if (this.match(29)) {
  11957. const shorthandAssignLoc = this.state.startLoc;
  11958. if (refExpressionErrors != null) {
  11959. if (refExpressionErrors.shorthandAssignLoc === null) {
  11960. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11961. }
  11962. } else {
  11963. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11964. }
  11965. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  11966. } else {
  11967. prop.value = this.cloneIdentifier(prop.key);
  11968. }
  11969. prop.shorthand = true;
  11970. return this.finishObjectProperty(prop);
  11971. }
  11972. }
  11973. finishObjectProperty(node) {
  11974. return this.finishNode(node, "ObjectProperty");
  11975. }
  11976. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11977. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11978. if (!node) this.unexpected();
  11979. return node;
  11980. }
  11981. parsePropertyName(prop, refExpressionErrors) {
  11982. if (this.eat(0)) {
  11983. prop.computed = true;
  11984. prop.key = this.parseMaybeAssignAllowIn();
  11985. this.expect(3);
  11986. } else {
  11987. const {
  11988. type,
  11989. value
  11990. } = this.state;
  11991. let key;
  11992. if (tokenIsKeywordOrIdentifier(type)) {
  11993. key = this.parseIdentifier(true);
  11994. } else {
  11995. switch (type) {
  11996. case 135:
  11997. key = this.parseNumericLiteral(value);
  11998. break;
  11999. case 134:
  12000. key = this.parseStringLiteral(value);
  12001. break;
  12002. case 136:
  12003. key = this.parseBigIntLiteral(value);
  12004. break;
  12005. case 139:
  12006. {
  12007. const privateKeyLoc = this.state.startLoc;
  12008. if (refExpressionErrors != null) {
  12009. if (refExpressionErrors.privateKeyLoc === null) {
  12010. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  12011. }
  12012. } else {
  12013. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  12014. }
  12015. key = this.parsePrivateName();
  12016. break;
  12017. }
  12018. default:
  12019. if (type === 137) {
  12020. key = this.parseDecimalLiteral(value);
  12021. break;
  12022. }
  12023. this.unexpected();
  12024. }
  12025. }
  12026. prop.key = key;
  12027. if (type !== 139) {
  12028. prop.computed = false;
  12029. }
  12030. }
  12031. }
  12032. initFunction(node, isAsync) {
  12033. node.id = null;
  12034. node.generator = false;
  12035. node.async = isAsync;
  12036. }
  12037. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  12038. this.initFunction(node, isAsync);
  12039. node.generator = isGenerator;
  12040. this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
  12041. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12042. this.parseFunctionParams(node, isConstructor);
  12043. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  12044. this.prodParam.exit();
  12045. this.scope.exit();
  12046. return finishedNode;
  12047. }
  12048. parseArrayLike(close, isTuple, refExpressionErrors) {
  12049. if (isTuple) {
  12050. this.expectPlugin("recordAndTuple");
  12051. }
  12052. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12053. this.state.inFSharpPipelineDirectBody = false;
  12054. const node = this.startNode();
  12055. this.next();
  12056. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  12057. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12058. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  12059. }
  12060. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  12061. this.scope.enter(514 | 4);
  12062. let flags = functionFlags(isAsync, false);
  12063. if (!this.match(5) && this.prodParam.hasIn) {
  12064. flags |= 8;
  12065. }
  12066. this.prodParam.enter(flags);
  12067. this.initFunction(node, isAsync);
  12068. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12069. if (params) {
  12070. this.state.maybeInArrowParameters = true;
  12071. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  12072. }
  12073. this.state.maybeInArrowParameters = false;
  12074. this.parseFunctionBody(node, true);
  12075. this.prodParam.exit();
  12076. this.scope.exit();
  12077. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12078. return this.finishNode(node, "ArrowFunctionExpression");
  12079. }
  12080. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  12081. this.toAssignableList(params, trailingCommaLoc, false);
  12082. node.params = params;
  12083. }
  12084. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  12085. this.parseFunctionBody(node, false, isMethod);
  12086. return this.finishNode(node, type);
  12087. }
  12088. parseFunctionBody(node, allowExpression, isMethod = false) {
  12089. const isExpression = allowExpression && !this.match(5);
  12090. this.expressionScope.enter(newExpressionScope());
  12091. if (isExpression) {
  12092. node.body = this.parseMaybeAssign();
  12093. this.checkParams(node, false, allowExpression, false);
  12094. } else {
  12095. const oldStrict = this.state.strict;
  12096. const oldLabels = this.state.labels;
  12097. this.state.labels = [];
  12098. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  12099. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  12100. const nonSimple = !this.isSimpleParamList(node.params);
  12101. if (hasStrictModeDirective && nonSimple) {
  12102. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  12103. }
  12104. const strictModeChanged = !oldStrict && this.state.strict;
  12105. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  12106. if (this.state.strict && node.id) {
  12107. this.checkIdentifier(node.id, 65, strictModeChanged);
  12108. }
  12109. });
  12110. this.prodParam.exit();
  12111. this.state.labels = oldLabels;
  12112. }
  12113. this.expressionScope.exit();
  12114. }
  12115. isSimpleParameter(node) {
  12116. return node.type === "Identifier";
  12117. }
  12118. isSimpleParamList(params) {
  12119. for (let i = 0, len = params.length; i < len; i++) {
  12120. if (!this.isSimpleParameter(params[i])) return false;
  12121. }
  12122. return true;
  12123. }
  12124. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  12125. const checkClashes = !allowDuplicates && new Set();
  12126. const formalParameters = {
  12127. type: "FormalParameters"
  12128. };
  12129. for (const param of node.params) {
  12130. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  12131. }
  12132. }
  12133. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  12134. const elts = [];
  12135. let first = true;
  12136. while (!this.eat(close)) {
  12137. if (first) {
  12138. first = false;
  12139. } else {
  12140. this.expect(12);
  12141. if (this.match(close)) {
  12142. if (nodeForExtra) {
  12143. this.addTrailingCommaExtraToNode(nodeForExtra);
  12144. }
  12145. this.next();
  12146. break;
  12147. }
  12148. }
  12149. elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
  12150. }
  12151. return elts;
  12152. }
  12153. parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
  12154. let elt;
  12155. if (this.match(12)) {
  12156. if (!allowEmpty) {
  12157. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  12158. unexpected: ","
  12159. });
  12160. }
  12161. elt = null;
  12162. } else if (this.match(21)) {
  12163. const spreadNodeStartLoc = this.state.startLoc;
  12164. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12165. } else if (this.match(17)) {
  12166. this.expectPlugin("partialApplication");
  12167. if (!allowPlaceholder) {
  12168. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  12169. }
  12170. const node = this.startNode();
  12171. this.next();
  12172. elt = this.finishNode(node, "ArgumentPlaceholder");
  12173. } else {
  12174. elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
  12175. }
  12176. return elt;
  12177. }
  12178. parseIdentifier(liberal) {
  12179. const node = this.startNode();
  12180. const name = this.parseIdentifierName(liberal);
  12181. return this.createIdentifier(node, name);
  12182. }
  12183. createIdentifier(node, name) {
  12184. node.name = name;
  12185. node.loc.identifierName = name;
  12186. return this.finishNode(node, "Identifier");
  12187. }
  12188. createIdentifierAt(node, name, endLoc) {
  12189. node.name = name;
  12190. node.loc.identifierName = name;
  12191. return this.finishNodeAt(node, "Identifier", endLoc);
  12192. }
  12193. parseIdentifierName(liberal) {
  12194. let name;
  12195. const {
  12196. startLoc,
  12197. type
  12198. } = this.state;
  12199. if (tokenIsKeywordOrIdentifier(type)) {
  12200. name = this.state.value;
  12201. } else {
  12202. this.unexpected();
  12203. }
  12204. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12205. if (liberal) {
  12206. if (tokenIsKeyword) {
  12207. this.replaceToken(132);
  12208. }
  12209. } else {
  12210. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12211. }
  12212. this.next();
  12213. return name;
  12214. }
  12215. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12216. if (word.length > 10) {
  12217. return;
  12218. }
  12219. if (!canBeReservedWord(word)) {
  12220. return;
  12221. }
  12222. if (checkKeywords && isKeyword(word)) {
  12223. this.raise(Errors.UnexpectedKeyword, startLoc, {
  12224. keyword: word
  12225. });
  12226. return;
  12227. }
  12228. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12229. if (reservedTest(word, this.inModule)) {
  12230. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  12231. reservedWord: word
  12232. });
  12233. return;
  12234. } else if (word === "yield") {
  12235. if (this.prodParam.hasYield) {
  12236. this.raise(Errors.YieldBindingIdentifier, startLoc);
  12237. return;
  12238. }
  12239. } else if (word === "await") {
  12240. if (this.prodParam.hasAwait) {
  12241. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  12242. return;
  12243. }
  12244. if (this.scope.inStaticBlock) {
  12245. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  12246. return;
  12247. }
  12248. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  12249. } else if (word === "arguments") {
  12250. if (this.scope.inClassAndNotInNonArrowFunction) {
  12251. this.raise(Errors.ArgumentsInClass, startLoc);
  12252. return;
  12253. }
  12254. }
  12255. }
  12256. recordAwaitIfAllowed() {
  12257. const isAwaitAllowed = this.prodParam.hasAwait;
  12258. if (isAwaitAllowed && !this.scope.inFunction) {
  12259. this.state.hasTopLevelAwait = true;
  12260. }
  12261. return isAwaitAllowed;
  12262. }
  12263. parseAwait(startLoc) {
  12264. const node = this.startNodeAt(startLoc);
  12265. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  12266. if (this.eat(55)) {
  12267. this.raise(Errors.ObsoleteAwaitStar, node);
  12268. }
  12269. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  12270. if (this.isAmbiguousPrefixOrIdentifier()) {
  12271. this.ambiguousScriptDifferentAst = true;
  12272. } else {
  12273. this.sawUnambiguousESM = true;
  12274. }
  12275. }
  12276. if (!this.state.soloAwait) {
  12277. node.argument = this.parseMaybeUnary(null, true);
  12278. }
  12279. return this.finishNode(node, "AwaitExpression");
  12280. }
  12281. isAmbiguousPrefixOrIdentifier() {
  12282. if (this.hasPrecedingLineBreak()) return true;
  12283. const {
  12284. type
  12285. } = this.state;
  12286. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12287. }
  12288. parseYield(startLoc) {
  12289. const node = this.startNodeAt(startLoc);
  12290. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  12291. let delegating = false;
  12292. let argument = null;
  12293. if (!this.hasPrecedingLineBreak()) {
  12294. delegating = this.eat(55);
  12295. switch (this.state.type) {
  12296. case 13:
  12297. case 140:
  12298. case 8:
  12299. case 11:
  12300. case 3:
  12301. case 9:
  12302. case 14:
  12303. case 12:
  12304. if (!delegating) break;
  12305. default:
  12306. argument = this.parseMaybeAssign();
  12307. }
  12308. }
  12309. node.delegate = delegating;
  12310. node.argument = argument;
  12311. return this.finishNode(node, "YieldExpression");
  12312. }
  12313. parseImportCall(node) {
  12314. this.next();
  12315. node.source = this.parseMaybeAssignAllowIn();
  12316. node.options = null;
  12317. if (this.eat(12)) {
  12318. if (!this.match(11)) {
  12319. node.options = this.parseMaybeAssignAllowIn();
  12320. if (this.eat(12)) {
  12321. this.addTrailingCommaExtraToNode(node.options);
  12322. if (!this.match(11)) {
  12323. do {
  12324. this.parseMaybeAssignAllowIn();
  12325. } while (this.eat(12) && !this.match(11));
  12326. this.raise(Errors.ImportCallArity, node);
  12327. }
  12328. }
  12329. } else {
  12330. this.addTrailingCommaExtraToNode(node.source);
  12331. }
  12332. }
  12333. this.expect(11);
  12334. return this.finishNode(node, "ImportExpression");
  12335. }
  12336. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12337. if (this.hasPlugin(["pipelineOperator", {
  12338. proposal: "smart"
  12339. }])) {
  12340. if (left.type === "SequenceExpression") {
  12341. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  12342. }
  12343. }
  12344. }
  12345. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12346. if (this.isSimpleReference(childExpr)) {
  12347. const bodyNode = this.startNodeAt(startLoc);
  12348. bodyNode.callee = childExpr;
  12349. return this.finishNode(bodyNode, "PipelineBareFunction");
  12350. } else {
  12351. const bodyNode = this.startNodeAt(startLoc);
  12352. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12353. bodyNode.expression = childExpr;
  12354. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12355. }
  12356. }
  12357. isSimpleReference(expression) {
  12358. switch (expression.type) {
  12359. case "MemberExpression":
  12360. return !expression.computed && this.isSimpleReference(expression.object);
  12361. case "Identifier":
  12362. return true;
  12363. default:
  12364. return false;
  12365. }
  12366. }
  12367. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12368. if (this.match(19)) {
  12369. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  12370. }
  12371. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12372. this.raise(Errors.PipelineTopicUnused, startLoc);
  12373. }
  12374. }
  12375. withTopicBindingContext(callback) {
  12376. const outerContextTopicState = this.state.topicContext;
  12377. this.state.topicContext = {
  12378. maxNumOfResolvableTopics: 1,
  12379. maxTopicIndex: null
  12380. };
  12381. try {
  12382. return callback();
  12383. } finally {
  12384. this.state.topicContext = outerContextTopicState;
  12385. }
  12386. }
  12387. withSmartMixTopicForbiddingContext(callback) {
  12388. if (this.hasPlugin(["pipelineOperator", {
  12389. proposal: "smart"
  12390. }])) {
  12391. const outerContextTopicState = this.state.topicContext;
  12392. this.state.topicContext = {
  12393. maxNumOfResolvableTopics: 0,
  12394. maxTopicIndex: null
  12395. };
  12396. try {
  12397. return callback();
  12398. } finally {
  12399. this.state.topicContext = outerContextTopicState;
  12400. }
  12401. } else {
  12402. return callback();
  12403. }
  12404. }
  12405. withSoloAwaitPermittingContext(callback) {
  12406. const outerContextSoloAwaitState = this.state.soloAwait;
  12407. this.state.soloAwait = true;
  12408. try {
  12409. return callback();
  12410. } finally {
  12411. this.state.soloAwait = outerContextSoloAwaitState;
  12412. }
  12413. }
  12414. allowInAnd(callback) {
  12415. const flags = this.prodParam.currentFlags();
  12416. const prodParamToSet = 8 & ~flags;
  12417. if (prodParamToSet) {
  12418. this.prodParam.enter(flags | 8);
  12419. try {
  12420. return callback();
  12421. } finally {
  12422. this.prodParam.exit();
  12423. }
  12424. }
  12425. return callback();
  12426. }
  12427. disallowInAnd(callback) {
  12428. const flags = this.prodParam.currentFlags();
  12429. const prodParamToClear = 8 & flags;
  12430. if (prodParamToClear) {
  12431. this.prodParam.enter(flags & ~8);
  12432. try {
  12433. return callback();
  12434. } finally {
  12435. this.prodParam.exit();
  12436. }
  12437. }
  12438. return callback();
  12439. }
  12440. registerTopicReference() {
  12441. this.state.topicContext.maxTopicIndex = 0;
  12442. }
  12443. topicReferenceIsAllowedInCurrentContext() {
  12444. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12445. }
  12446. topicReferenceWasUsedInCurrentContext() {
  12447. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12448. }
  12449. parseFSharpPipelineBody(prec) {
  12450. const startLoc = this.state.startLoc;
  12451. this.state.potentialArrowAt = this.state.start;
  12452. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12453. this.state.inFSharpPipelineDirectBody = true;
  12454. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12455. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12456. return ret;
  12457. }
  12458. parseModuleExpression() {
  12459. this.expectPlugin("moduleBlocks");
  12460. const node = this.startNode();
  12461. this.next();
  12462. if (!this.match(5)) {
  12463. this.unexpected(null, 5);
  12464. }
  12465. const program = this.startNodeAt(this.state.endLoc);
  12466. this.next();
  12467. const revertScopes = this.initializeScopes(true);
  12468. this.enterInitialScopes();
  12469. try {
  12470. node.body = this.parseProgram(program, 8, "module");
  12471. } finally {
  12472. revertScopes();
  12473. }
  12474. return this.finishNode(node, "ModuleExpression");
  12475. }
  12476. parseVoidPattern(refExpressionErrors) {
  12477. this.expectPlugin("discardBinding");
  12478. const node = this.startNode();
  12479. if (refExpressionErrors != null) {
  12480. refExpressionErrors.voidPatternLoc = this.state.startLoc;
  12481. }
  12482. this.next();
  12483. return this.finishNode(node, "VoidPattern");
  12484. }
  12485. parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
  12486. if (refExpressionErrors != null && this.match(88)) {
  12487. const nextCode = this.lookaheadCharCode();
  12488. if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
  12489. return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
  12490. }
  12491. }
  12492. return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
  12493. }
  12494. parsePropertyNamePrefixOperator(prop) {}
  12495. }
  12496. const loopLabel = {
  12497. kind: 1
  12498. },
  12499. switchLabel = {
  12500. kind: 2
  12501. };
  12502. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12503. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12504. function babel7CompatTokens(tokens, input, startIndex) {
  12505. for (let i = 0; i < tokens.length; i++) {
  12506. const token = tokens[i];
  12507. const {
  12508. type
  12509. } = token;
  12510. if (typeof type === "number") {
  12511. if (type === 139) {
  12512. const {
  12513. loc,
  12514. start,
  12515. value,
  12516. end
  12517. } = token;
  12518. const hashEndPos = start + 1;
  12519. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12520. tokens.splice(i, 1, new Token({
  12521. type: getExportedToken(27),
  12522. value: "#",
  12523. start: start,
  12524. end: hashEndPos,
  12525. startLoc: loc.start,
  12526. endLoc: hashEndLoc
  12527. }), new Token({
  12528. type: getExportedToken(132),
  12529. value: value,
  12530. start: hashEndPos,
  12531. end: end,
  12532. startLoc: hashEndLoc,
  12533. endLoc: loc.end
  12534. }));
  12535. i++;
  12536. continue;
  12537. }
  12538. if (tokenIsTemplate(type)) {
  12539. const {
  12540. loc,
  12541. start,
  12542. value,
  12543. end
  12544. } = token;
  12545. const backquoteEnd = start + 1;
  12546. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12547. let startToken;
  12548. if (input.charCodeAt(start - startIndex) === 96) {
  12549. startToken = new Token({
  12550. type: getExportedToken(22),
  12551. value: "`",
  12552. start: start,
  12553. end: backquoteEnd,
  12554. startLoc: loc.start,
  12555. endLoc: backquoteEndLoc
  12556. });
  12557. } else {
  12558. startToken = new Token({
  12559. type: getExportedToken(8),
  12560. value: "}",
  12561. start: start,
  12562. end: backquoteEnd,
  12563. startLoc: loc.start,
  12564. endLoc: backquoteEndLoc
  12565. });
  12566. }
  12567. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12568. if (type === 24) {
  12569. templateElementEnd = end - 1;
  12570. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12571. templateValue = value === null ? null : value.slice(1, -1);
  12572. endToken = new Token({
  12573. type: getExportedToken(22),
  12574. value: "`",
  12575. start: templateElementEnd,
  12576. end: end,
  12577. startLoc: templateElementEndLoc,
  12578. endLoc: loc.end
  12579. });
  12580. } else {
  12581. templateElementEnd = end - 2;
  12582. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12583. templateValue = value === null ? null : value.slice(1, -2);
  12584. endToken = new Token({
  12585. type: getExportedToken(23),
  12586. value: "${",
  12587. start: templateElementEnd,
  12588. end: end,
  12589. startLoc: templateElementEndLoc,
  12590. endLoc: loc.end
  12591. });
  12592. }
  12593. tokens.splice(i, 1, startToken, new Token({
  12594. type: getExportedToken(20),
  12595. value: templateValue,
  12596. start: backquoteEnd,
  12597. end: templateElementEnd,
  12598. startLoc: backquoteEndLoc,
  12599. endLoc: templateElementEndLoc
  12600. }), endToken);
  12601. i += 2;
  12602. continue;
  12603. }
  12604. token.type = getExportedToken(type);
  12605. }
  12606. }
  12607. return tokens;
  12608. }
  12609. class StatementParser extends ExpressionParser {
  12610. parseTopLevel(file, program) {
  12611. file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
  12612. file.comments = this.comments;
  12613. if (this.optionFlags & 256) {
  12614. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  12615. }
  12616. return this.finishNode(file, "File");
  12617. }
  12618. parseProgram(program, end, sourceType) {
  12619. program.sourceType = sourceType;
  12620. program.interpreter = this.parseInterpreterDirective();
  12621. this.parseBlockBody(program, true, true, end);
  12622. if (this.inModule) {
  12623. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  12624. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12625. this.raise(Errors.ModuleExportUndefined, at, {
  12626. localName
  12627. });
  12628. }
  12629. }
  12630. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  12631. }
  12632. let finishedProgram;
  12633. if (end === 140) {
  12634. finishedProgram = this.finishNode(program, "Program");
  12635. } else {
  12636. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12637. }
  12638. return finishedProgram;
  12639. }
  12640. stmtToDirective(stmt) {
  12641. const directive = this.castNodeTo(stmt, "Directive");
  12642. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  12643. const expressionValue = directiveLiteral.value;
  12644. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  12645. const val = directiveLiteral.value = raw.slice(1, -1);
  12646. this.addExtra(directiveLiteral, "raw", raw);
  12647. this.addExtra(directiveLiteral, "rawValue", val);
  12648. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12649. directive.value = directiveLiteral;
  12650. delete stmt.expression;
  12651. return directive;
  12652. }
  12653. parseInterpreterDirective() {
  12654. if (!this.match(28)) {
  12655. return null;
  12656. }
  12657. const node = this.startNode();
  12658. node.value = this.state.value;
  12659. this.next();
  12660. return this.finishNode(node, "InterpreterDirective");
  12661. }
  12662. isLet() {
  12663. if (!this.isContextual(100)) {
  12664. return false;
  12665. }
  12666. return this.hasFollowingBindingAtom();
  12667. }
  12668. isUsing() {
  12669. if (!this.isContextual(107)) {
  12670. return false;
  12671. }
  12672. return this.nextTokenIsIdentifierOnSameLine();
  12673. }
  12674. isForUsing() {
  12675. if (!this.isContextual(107)) {
  12676. return false;
  12677. }
  12678. const next = this.nextTokenInLineStart();
  12679. const nextCh = this.codePointAtPos(next);
  12680. if (this.isUnparsedContextual(next, "of")) {
  12681. const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
  12682. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  12683. return false;
  12684. }
  12685. }
  12686. if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
  12687. return true;
  12688. }
  12689. return false;
  12690. }
  12691. nextTokenIsIdentifierOnSameLine() {
  12692. const next = this.nextTokenInLineStart();
  12693. const nextCh = this.codePointAtPos(next);
  12694. return this.chStartsBindingIdentifier(nextCh, next);
  12695. }
  12696. isAwaitUsing() {
  12697. if (!this.isContextual(96)) {
  12698. return false;
  12699. }
  12700. let next = this.nextTokenInLineStart();
  12701. if (this.isUnparsedContextual(next, "using")) {
  12702. next = this.nextTokenInLineStartSince(next + 5);
  12703. const nextCh = this.codePointAtPos(next);
  12704. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12705. return true;
  12706. }
  12707. }
  12708. return false;
  12709. }
  12710. chStartsBindingIdentifier(ch, pos) {
  12711. if (isIdentifierStart(ch)) {
  12712. keywordRelationalOperator.lastIndex = pos;
  12713. if (keywordRelationalOperator.test(this.input)) {
  12714. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12715. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12716. return false;
  12717. }
  12718. }
  12719. return true;
  12720. } else if (ch === 92) {
  12721. return true;
  12722. } else {
  12723. return false;
  12724. }
  12725. }
  12726. chStartsBindingPattern(ch) {
  12727. return ch === 91 || ch === 123;
  12728. }
  12729. hasFollowingBindingAtom() {
  12730. const next = this.nextTokenStart();
  12731. const nextCh = this.codePointAtPos(next);
  12732. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12733. }
  12734. hasInLineFollowingBindingIdentifierOrBrace() {
  12735. const next = this.nextTokenInLineStart();
  12736. const nextCh = this.codePointAtPos(next);
  12737. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  12738. }
  12739. allowsUsing() {
  12740. return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
  12741. }
  12742. parseModuleItem() {
  12743. return this.parseStatementLike(1 | 2 | 4 | 8);
  12744. }
  12745. parseStatementListItem() {
  12746. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12747. }
  12748. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12749. let flags = 0;
  12750. if (this.options.annexB && !this.state.strict) {
  12751. flags |= 4;
  12752. if (allowLabeledFunction) {
  12753. flags |= 8;
  12754. }
  12755. }
  12756. return this.parseStatementLike(flags);
  12757. }
  12758. parseStatement() {
  12759. return this.parseStatementLike(0);
  12760. }
  12761. parseStatementLike(flags) {
  12762. let decorators = null;
  12763. if (this.match(26)) {
  12764. decorators = this.parseDecorators(true);
  12765. }
  12766. return this.parseStatementContent(flags, decorators);
  12767. }
  12768. parseStatementContent(flags, decorators) {
  12769. const startType = this.state.type;
  12770. const node = this.startNode();
  12771. const allowDeclaration = !!(flags & 2);
  12772. const allowFunctionDeclaration = !!(flags & 4);
  12773. const topLevel = flags & 1;
  12774. switch (startType) {
  12775. case 60:
  12776. return this.parseBreakContinueStatement(node, true);
  12777. case 63:
  12778. return this.parseBreakContinueStatement(node, false);
  12779. case 64:
  12780. return this.parseDebuggerStatement(node);
  12781. case 90:
  12782. return this.parseDoWhileStatement(node);
  12783. case 91:
  12784. return this.parseForStatement(node);
  12785. case 68:
  12786. if (this.lookaheadCharCode() === 46) break;
  12787. if (!allowFunctionDeclaration) {
  12788. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12789. }
  12790. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12791. case 80:
  12792. if (!allowDeclaration) this.unexpected();
  12793. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12794. case 69:
  12795. return this.parseIfStatement(node);
  12796. case 70:
  12797. return this.parseReturnStatement(node);
  12798. case 71:
  12799. return this.parseSwitchStatement(node);
  12800. case 72:
  12801. return this.parseThrowStatement(node);
  12802. case 73:
  12803. return this.parseTryStatement(node);
  12804. case 96:
  12805. if (this.isAwaitUsing()) {
  12806. if (!this.allowsUsing()) {
  12807. this.raise(Errors.UnexpectedUsingDeclaration, node);
  12808. } else if (!allowDeclaration) {
  12809. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12810. } else if (!this.recordAwaitIfAllowed()) {
  12811. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12812. }
  12813. this.next();
  12814. return this.parseVarStatement(node, "await using");
  12815. }
  12816. break;
  12817. case 107:
  12818. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  12819. break;
  12820. }
  12821. if (!this.allowsUsing()) {
  12822. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12823. } else if (!allowDeclaration) {
  12824. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12825. }
  12826. return this.parseVarStatement(node, "using");
  12827. case 100:
  12828. {
  12829. if (this.state.containsEsc) {
  12830. break;
  12831. }
  12832. const next = this.nextTokenStart();
  12833. const nextCh = this.codePointAtPos(next);
  12834. if (nextCh !== 91) {
  12835. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12836. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12837. break;
  12838. }
  12839. }
  12840. }
  12841. case 75:
  12842. {
  12843. if (!allowDeclaration) {
  12844. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12845. }
  12846. }
  12847. case 74:
  12848. {
  12849. const kind = this.state.value;
  12850. return this.parseVarStatement(node, kind);
  12851. }
  12852. case 92:
  12853. return this.parseWhileStatement(node);
  12854. case 76:
  12855. return this.parseWithStatement(node);
  12856. case 5:
  12857. return this.parseBlock();
  12858. case 13:
  12859. return this.parseEmptyStatement(node);
  12860. case 83:
  12861. {
  12862. const nextTokenCharCode = this.lookaheadCharCode();
  12863. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12864. break;
  12865. }
  12866. }
  12867. case 82:
  12868. {
  12869. if (!(this.optionFlags & 8) && !topLevel) {
  12870. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12871. }
  12872. this.next();
  12873. let result;
  12874. if (startType === 83) {
  12875. result = this.parseImport(node);
  12876. } else {
  12877. result = this.parseExport(node, decorators);
  12878. }
  12879. this.assertModuleNodeAllowed(result);
  12880. return result;
  12881. }
  12882. default:
  12883. {
  12884. if (this.isAsyncFunction()) {
  12885. if (!allowDeclaration) {
  12886. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12887. }
  12888. this.next();
  12889. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12890. }
  12891. }
  12892. }
  12893. const maybeName = this.state.value;
  12894. const expr = this.parseExpression();
  12895. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  12896. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12897. } else {
  12898. return this.parseExpressionStatement(node, expr, decorators);
  12899. }
  12900. }
  12901. assertModuleNodeAllowed(node) {
  12902. if (!(this.optionFlags & 8) && !this.inModule) {
  12903. this.raise(Errors.ImportOutsideModule, node);
  12904. }
  12905. }
  12906. decoratorsEnabledBeforeExport() {
  12907. if (this.hasPlugin("decorators-legacy")) return true;
  12908. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12909. }
  12910. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12911. if (maybeDecorators) {
  12912. var _classNode$decorators;
  12913. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  12914. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12915. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12916. }
  12917. classNode.decorators.unshift(...maybeDecorators);
  12918. } else {
  12919. classNode.decorators = maybeDecorators;
  12920. }
  12921. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12922. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12923. }
  12924. return classNode;
  12925. }
  12926. canHaveLeadingDecorator() {
  12927. return this.match(80);
  12928. }
  12929. parseDecorators(allowExport) {
  12930. const decorators = [];
  12931. do {
  12932. decorators.push(this.parseDecorator());
  12933. } while (this.match(26));
  12934. if (this.match(82)) {
  12935. if (!allowExport) {
  12936. this.unexpected();
  12937. }
  12938. if (!this.decoratorsEnabledBeforeExport()) {
  12939. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  12940. }
  12941. } else if (!this.canHaveLeadingDecorator()) {
  12942. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  12943. }
  12944. return decorators;
  12945. }
  12946. parseDecorator() {
  12947. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12948. const node = this.startNode();
  12949. this.next();
  12950. if (this.hasPlugin("decorators")) {
  12951. const startLoc = this.state.startLoc;
  12952. let expr;
  12953. if (this.match(10)) {
  12954. const startLoc = this.state.startLoc;
  12955. this.next();
  12956. expr = this.parseExpression();
  12957. this.expect(11);
  12958. expr = this.wrapParenthesis(startLoc, expr);
  12959. const paramsStartLoc = this.state.startLoc;
  12960. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12961. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12962. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  12963. }
  12964. } else {
  12965. expr = this.parseIdentifier(false);
  12966. while (this.eat(16)) {
  12967. const node = this.startNodeAt(startLoc);
  12968. node.object = expr;
  12969. if (this.match(139)) {
  12970. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12971. node.property = this.parsePrivateName();
  12972. } else {
  12973. node.property = this.parseIdentifier(true);
  12974. }
  12975. node.computed = false;
  12976. expr = this.finishNode(node, "MemberExpression");
  12977. }
  12978. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12979. }
  12980. } else {
  12981. node.expression = this.parseExprSubscripts();
  12982. }
  12983. return this.finishNode(node, "Decorator");
  12984. }
  12985. parseMaybeDecoratorArguments(expr, startLoc) {
  12986. if (this.eat(10)) {
  12987. const node = this.startNodeAt(startLoc);
  12988. node.callee = expr;
  12989. node.arguments = this.parseCallExpressionArguments();
  12990. this.toReferencedList(node.arguments);
  12991. return this.finishNode(node, "CallExpression");
  12992. }
  12993. return expr;
  12994. }
  12995. parseBreakContinueStatement(node, isBreak) {
  12996. this.next();
  12997. if (this.isLineTerminator()) {
  12998. node.label = null;
  12999. } else {
  13000. node.label = this.parseIdentifier();
  13001. this.semicolon();
  13002. }
  13003. this.verifyBreakContinue(node, isBreak);
  13004. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  13005. }
  13006. verifyBreakContinue(node, isBreak) {
  13007. let i;
  13008. for (i = 0; i < this.state.labels.length; ++i) {
  13009. const lab = this.state.labels[i];
  13010. if (node.label == null || lab.name === node.label.name) {
  13011. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  13012. break;
  13013. }
  13014. if (node.label && isBreak) break;
  13015. }
  13016. }
  13017. if (i === this.state.labels.length) {
  13018. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  13019. this.raise(Errors.IllegalBreakContinue, node, {
  13020. type
  13021. });
  13022. }
  13023. }
  13024. parseDebuggerStatement(node) {
  13025. this.next();
  13026. this.semicolon();
  13027. return this.finishNode(node, "DebuggerStatement");
  13028. }
  13029. parseHeaderExpression() {
  13030. this.expect(10);
  13031. const val = this.parseExpression();
  13032. this.expect(11);
  13033. return val;
  13034. }
  13035. parseDoWhileStatement(node) {
  13036. this.next();
  13037. this.state.labels.push(loopLabel);
  13038. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13039. this.state.labels.pop();
  13040. this.expect(92);
  13041. node.test = this.parseHeaderExpression();
  13042. this.eat(13);
  13043. return this.finishNode(node, "DoWhileStatement");
  13044. }
  13045. parseForStatement(node) {
  13046. this.next();
  13047. this.state.labels.push(loopLabel);
  13048. let awaitAt = null;
  13049. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  13050. awaitAt = this.state.startLoc;
  13051. this.next();
  13052. }
  13053. this.scope.enter(0);
  13054. this.expect(10);
  13055. if (this.match(13)) {
  13056. if (awaitAt !== null) {
  13057. this.unexpected(awaitAt);
  13058. }
  13059. return this.parseFor(node, null);
  13060. }
  13061. const startsWithLet = this.isContextual(100);
  13062. {
  13063. const startsWithAwaitUsing = this.isAwaitUsing();
  13064. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
  13065. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  13066. if (this.match(74) || this.match(75) || isLetOrUsing) {
  13067. const initNode = this.startNode();
  13068. let kind;
  13069. if (startsWithAwaitUsing) {
  13070. kind = "await using";
  13071. if (!this.recordAwaitIfAllowed()) {
  13072. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  13073. }
  13074. this.next();
  13075. } else {
  13076. kind = this.state.value;
  13077. }
  13078. this.next();
  13079. this.parseVar(initNode, true, kind);
  13080. const init = this.finishNode(initNode, "VariableDeclaration");
  13081. const isForIn = this.match(58);
  13082. if (isForIn && starsWithUsingDeclaration) {
  13083. this.raise(Errors.ForInUsing, init);
  13084. }
  13085. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  13086. return this.parseForIn(node, init, awaitAt);
  13087. }
  13088. if (awaitAt !== null) {
  13089. this.unexpected(awaitAt);
  13090. }
  13091. return this.parseFor(node, init);
  13092. }
  13093. }
  13094. const startsWithAsync = this.isContextual(95);
  13095. const refExpressionErrors = new ExpressionErrors();
  13096. const init = this.parseExpression(true, refExpressionErrors);
  13097. const isForOf = this.isContextual(102);
  13098. if (isForOf) {
  13099. if (startsWithLet) {
  13100. this.raise(Errors.ForOfLet, init);
  13101. }
  13102. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  13103. this.raise(Errors.ForOfAsync, init);
  13104. }
  13105. }
  13106. if (isForOf || this.match(58)) {
  13107. this.checkDestructuringPrivate(refExpressionErrors);
  13108. this.toAssignable(init, true);
  13109. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  13110. this.checkLVal(init, {
  13111. type
  13112. });
  13113. return this.parseForIn(node, init, awaitAt);
  13114. } else {
  13115. this.checkExpressionErrors(refExpressionErrors, true);
  13116. }
  13117. if (awaitAt !== null) {
  13118. this.unexpected(awaitAt);
  13119. }
  13120. return this.parseFor(node, init);
  13121. }
  13122. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  13123. this.next();
  13124. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  13125. }
  13126. parseIfStatement(node) {
  13127. this.next();
  13128. node.test = this.parseHeaderExpression();
  13129. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  13130. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  13131. return this.finishNode(node, "IfStatement");
  13132. }
  13133. parseReturnStatement(node) {
  13134. if (!this.prodParam.hasReturn) {
  13135. this.raise(Errors.IllegalReturn, this.state.startLoc);
  13136. }
  13137. this.next();
  13138. if (this.isLineTerminator()) {
  13139. node.argument = null;
  13140. } else {
  13141. node.argument = this.parseExpression();
  13142. this.semicolon();
  13143. }
  13144. return this.finishNode(node, "ReturnStatement");
  13145. }
  13146. parseSwitchStatement(node) {
  13147. this.next();
  13148. node.discriminant = this.parseHeaderExpression();
  13149. const cases = node.cases = [];
  13150. this.expect(5);
  13151. this.state.labels.push(switchLabel);
  13152. this.scope.enter(256);
  13153. let cur;
  13154. for (let sawDefault; !this.match(8);) {
  13155. if (this.match(61) || this.match(65)) {
  13156. const isCase = this.match(61);
  13157. if (cur) this.finishNode(cur, "SwitchCase");
  13158. cases.push(cur = this.startNode());
  13159. cur.consequent = [];
  13160. this.next();
  13161. if (isCase) {
  13162. cur.test = this.parseExpression();
  13163. } else {
  13164. if (sawDefault) {
  13165. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  13166. }
  13167. sawDefault = true;
  13168. cur.test = null;
  13169. }
  13170. this.expect(14);
  13171. } else {
  13172. if (cur) {
  13173. cur.consequent.push(this.parseStatementListItem());
  13174. } else {
  13175. this.unexpected();
  13176. }
  13177. }
  13178. }
  13179. this.scope.exit();
  13180. if (cur) this.finishNode(cur, "SwitchCase");
  13181. this.next();
  13182. this.state.labels.pop();
  13183. return this.finishNode(node, "SwitchStatement");
  13184. }
  13185. parseThrowStatement(node) {
  13186. this.next();
  13187. if (this.hasPrecedingLineBreak()) {
  13188. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  13189. }
  13190. node.argument = this.parseExpression();
  13191. this.semicolon();
  13192. return this.finishNode(node, "ThrowStatement");
  13193. }
  13194. parseCatchClauseParam() {
  13195. const param = this.parseBindingAtom();
  13196. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13197. this.checkLVal(param, {
  13198. type: "CatchClause"
  13199. }, 9);
  13200. return param;
  13201. }
  13202. parseTryStatement(node) {
  13203. this.next();
  13204. node.block = this.parseBlock();
  13205. node.handler = null;
  13206. if (this.match(62)) {
  13207. const clause = this.startNode();
  13208. this.next();
  13209. if (this.match(10)) {
  13210. this.expect(10);
  13211. clause.param = this.parseCatchClauseParam();
  13212. this.expect(11);
  13213. } else {
  13214. clause.param = null;
  13215. this.scope.enter(0);
  13216. }
  13217. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13218. this.scope.exit();
  13219. node.handler = this.finishNode(clause, "CatchClause");
  13220. }
  13221. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13222. if (!node.handler && !node.finalizer) {
  13223. this.raise(Errors.NoCatchOrFinally, node);
  13224. }
  13225. return this.finishNode(node, "TryStatement");
  13226. }
  13227. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13228. this.next();
  13229. this.parseVar(node, false, kind, allowMissingInitializer);
  13230. this.semicolon();
  13231. return this.finishNode(node, "VariableDeclaration");
  13232. }
  13233. parseWhileStatement(node) {
  13234. this.next();
  13235. node.test = this.parseHeaderExpression();
  13236. this.state.labels.push(loopLabel);
  13237. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13238. this.state.labels.pop();
  13239. return this.finishNode(node, "WhileStatement");
  13240. }
  13241. parseWithStatement(node) {
  13242. if (this.state.strict) {
  13243. this.raise(Errors.StrictWith, this.state.startLoc);
  13244. }
  13245. this.next();
  13246. node.object = this.parseHeaderExpression();
  13247. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13248. return this.finishNode(node, "WithStatement");
  13249. }
  13250. parseEmptyStatement(node) {
  13251. this.next();
  13252. return this.finishNode(node, "EmptyStatement");
  13253. }
  13254. parseLabeledStatement(node, maybeName, expr, flags) {
  13255. for (const label of this.state.labels) {
  13256. if (label.name === maybeName) {
  13257. this.raise(Errors.LabelRedeclaration, expr, {
  13258. labelName: maybeName
  13259. });
  13260. }
  13261. }
  13262. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  13263. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13264. const label = this.state.labels[i];
  13265. if (label.statementStart === node.start) {
  13266. label.statementStart = this.sourceToOffsetPos(this.state.start);
  13267. label.kind = kind;
  13268. } else {
  13269. break;
  13270. }
  13271. }
  13272. this.state.labels.push({
  13273. name: maybeName,
  13274. kind: kind,
  13275. statementStart: this.sourceToOffsetPos(this.state.start)
  13276. });
  13277. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13278. this.state.labels.pop();
  13279. node.label = expr;
  13280. return this.finishNode(node, "LabeledStatement");
  13281. }
  13282. parseExpressionStatement(node, expr, decorators) {
  13283. node.expression = expr;
  13284. this.semicolon();
  13285. return this.finishNode(node, "ExpressionStatement");
  13286. }
  13287. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13288. const node = this.startNode();
  13289. if (allowDirectives) {
  13290. this.state.strictErrors.clear();
  13291. }
  13292. this.expect(5);
  13293. if (createNewLexicalScope) {
  13294. this.scope.enter(0);
  13295. }
  13296. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13297. if (createNewLexicalScope) {
  13298. this.scope.exit();
  13299. }
  13300. return this.finishNode(node, "BlockStatement");
  13301. }
  13302. isValidDirective(stmt) {
  13303. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13304. }
  13305. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13306. const body = node.body = [];
  13307. const directives = node.directives = [];
  13308. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13309. }
  13310. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13311. const oldStrict = this.state.strict;
  13312. let hasStrictModeDirective = false;
  13313. let parsedNonDirective = false;
  13314. while (!this.match(end)) {
  13315. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13316. if (directives && !parsedNonDirective) {
  13317. if (this.isValidDirective(stmt)) {
  13318. const directive = this.stmtToDirective(stmt);
  13319. directives.push(directive);
  13320. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13321. hasStrictModeDirective = true;
  13322. this.setStrict(true);
  13323. }
  13324. continue;
  13325. }
  13326. parsedNonDirective = true;
  13327. this.state.strictErrors.clear();
  13328. }
  13329. body.push(stmt);
  13330. }
  13331. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  13332. if (!oldStrict) {
  13333. this.setStrict(false);
  13334. }
  13335. this.next();
  13336. }
  13337. parseFor(node, init) {
  13338. node.init = init;
  13339. this.semicolon(false);
  13340. node.test = this.match(13) ? null : this.parseExpression();
  13341. this.semicolon(false);
  13342. node.update = this.match(11) ? null : this.parseExpression();
  13343. this.expect(11);
  13344. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13345. this.scope.exit();
  13346. this.state.labels.pop();
  13347. return this.finishNode(node, "ForStatement");
  13348. }
  13349. parseForIn(node, init, awaitAt) {
  13350. const isForIn = this.match(58);
  13351. this.next();
  13352. if (isForIn) {
  13353. if (awaitAt !== null) this.unexpected(awaitAt);
  13354. } else {
  13355. node.await = awaitAt !== null;
  13356. }
  13357. if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || !this.options.annexB || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) {
  13358. this.raise(Errors.ForInOfLoopInitializer, init, {
  13359. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13360. });
  13361. }
  13362. if (init.type === "AssignmentPattern") {
  13363. this.raise(Errors.InvalidLhs, init, {
  13364. ancestor: {
  13365. type: "ForStatement"
  13366. }
  13367. });
  13368. }
  13369. node.left = init;
  13370. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13371. this.expect(11);
  13372. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13373. this.scope.exit();
  13374. this.state.labels.pop();
  13375. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13376. }
  13377. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13378. const declarations = node.declarations = [];
  13379. node.kind = kind;
  13380. for (;;) {
  13381. const decl = this.startNode();
  13382. this.parseVarId(decl, kind);
  13383. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13384. if (decl.init === null && !allowMissingInitializer) {
  13385. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13386. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13387. kind: "destructuring"
  13388. });
  13389. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  13390. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13391. kind
  13392. });
  13393. }
  13394. }
  13395. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13396. if (!this.eat(12)) break;
  13397. }
  13398. return node;
  13399. }
  13400. parseVarId(decl, kind) {
  13401. const id = this.parseBindingAtom();
  13402. if (kind === "using" || kind === "await using") {
  13403. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  13404. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  13405. }
  13406. } else {
  13407. if (id.type === "VoidPattern") {
  13408. this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
  13409. }
  13410. }
  13411. this.checkLVal(id, {
  13412. type: "VariableDeclarator"
  13413. }, kind === "var" ? 5 : 8201);
  13414. decl.id = id;
  13415. }
  13416. parseAsyncFunctionExpression(node) {
  13417. return this.parseFunction(node, 8);
  13418. }
  13419. parseFunction(node, flags = 0) {
  13420. const hangingDeclaration = flags & 2;
  13421. const isDeclaration = !!(flags & 1);
  13422. const requireId = isDeclaration && !(flags & 4);
  13423. const isAsync = !!(flags & 8);
  13424. this.initFunction(node, isAsync);
  13425. if (this.match(55)) {
  13426. if (hangingDeclaration) {
  13427. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  13428. }
  13429. this.next();
  13430. node.generator = true;
  13431. }
  13432. if (isDeclaration) {
  13433. node.id = this.parseFunctionId(requireId);
  13434. }
  13435. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13436. this.state.maybeInArrowParameters = false;
  13437. this.scope.enter(514);
  13438. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13439. if (!isDeclaration) {
  13440. node.id = this.parseFunctionId();
  13441. }
  13442. this.parseFunctionParams(node, false);
  13443. this.withSmartMixTopicForbiddingContext(() => {
  13444. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13445. });
  13446. this.prodParam.exit();
  13447. this.scope.exit();
  13448. if (isDeclaration && !hangingDeclaration) {
  13449. this.registerFunctionStatementId(node);
  13450. }
  13451. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13452. return node;
  13453. }
  13454. parseFunctionId(requireId) {
  13455. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13456. }
  13457. parseFunctionParams(node, isConstructor) {
  13458. this.expect(10);
  13459. this.expressionScope.enter(newParameterDeclarationScope());
  13460. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13461. this.expressionScope.exit();
  13462. }
  13463. registerFunctionStatementId(node) {
  13464. if (!node.id) return;
  13465. this.scope.declareName(node.id.name, !this.options.annexB || this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? 5 : 8201 : 17, node.id.loc.start);
  13466. }
  13467. parseClass(node, isStatement, optionalId) {
  13468. this.next();
  13469. const oldStrict = this.state.strict;
  13470. this.state.strict = true;
  13471. this.parseClassId(node, isStatement, optionalId);
  13472. this.parseClassSuper(node);
  13473. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13474. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13475. }
  13476. isClassProperty() {
  13477. return this.match(29) || this.match(13) || this.match(8);
  13478. }
  13479. isClassMethod() {
  13480. return this.match(10);
  13481. }
  13482. nameIsConstructor(key) {
  13483. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  13484. }
  13485. isNonstaticConstructor(method) {
  13486. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  13487. }
  13488. parseClassBody(hadSuperClass, oldStrict) {
  13489. this.classScope.enter();
  13490. const state = {
  13491. hadConstructor: false,
  13492. hadSuperClass
  13493. };
  13494. let decorators = [];
  13495. const classBody = this.startNode();
  13496. classBody.body = [];
  13497. this.expect(5);
  13498. this.withSmartMixTopicForbiddingContext(() => {
  13499. while (!this.match(8)) {
  13500. if (this.eat(13)) {
  13501. if (decorators.length > 0) {
  13502. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  13503. }
  13504. continue;
  13505. }
  13506. if (this.match(26)) {
  13507. decorators.push(this.parseDecorator());
  13508. continue;
  13509. }
  13510. const member = this.startNode();
  13511. if (decorators.length) {
  13512. member.decorators = decorators;
  13513. this.resetStartLocationFromNode(member, decorators[0]);
  13514. decorators = [];
  13515. }
  13516. this.parseClassMember(classBody, member, state);
  13517. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13518. this.raise(Errors.DecoratorConstructor, member);
  13519. }
  13520. }
  13521. });
  13522. this.state.strict = oldStrict;
  13523. this.next();
  13524. if (decorators.length) {
  13525. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13526. }
  13527. this.classScope.exit();
  13528. return this.finishNode(classBody, "ClassBody");
  13529. }
  13530. parseClassMemberFromModifier(classBody, member) {
  13531. const key = this.parseIdentifier(true);
  13532. if (this.isClassMethod()) {
  13533. const method = member;
  13534. method.kind = "method";
  13535. method.computed = false;
  13536. method.key = key;
  13537. method.static = false;
  13538. this.pushClassMethod(classBody, method, false, false, false, false);
  13539. return true;
  13540. } else if (this.isClassProperty()) {
  13541. const prop = member;
  13542. prop.computed = false;
  13543. prop.key = key;
  13544. prop.static = false;
  13545. classBody.body.push(this.parseClassProperty(prop));
  13546. return true;
  13547. }
  13548. this.resetPreviousNodeTrailingComments(key);
  13549. return false;
  13550. }
  13551. parseClassMember(classBody, member, state) {
  13552. const isStatic = this.isContextual(106);
  13553. if (isStatic) {
  13554. if (this.parseClassMemberFromModifier(classBody, member)) {
  13555. return;
  13556. }
  13557. if (this.eat(5)) {
  13558. this.parseClassStaticBlock(classBody, member);
  13559. return;
  13560. }
  13561. }
  13562. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13563. }
  13564. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13565. const publicMethod = member;
  13566. const privateMethod = member;
  13567. const publicProp = member;
  13568. const privateProp = member;
  13569. const accessorProp = member;
  13570. const method = publicMethod;
  13571. const publicMember = publicMethod;
  13572. member.static = isStatic;
  13573. this.parsePropertyNamePrefixOperator(member);
  13574. if (this.eat(55)) {
  13575. method.kind = "method";
  13576. const isPrivateName = this.match(139);
  13577. this.parseClassElementName(method);
  13578. this.parsePostMemberNameModifiers(method);
  13579. if (isPrivateName) {
  13580. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13581. return;
  13582. }
  13583. if (this.isNonstaticConstructor(publicMethod)) {
  13584. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13585. }
  13586. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13587. return;
  13588. }
  13589. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13590. const key = this.parseClassElementName(member);
  13591. const maybeContextualKw = isContextual ? key.name : null;
  13592. const isPrivate = this.isPrivateName(key);
  13593. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13594. this.parsePostMemberNameModifiers(publicMember);
  13595. if (this.isClassMethod()) {
  13596. method.kind = "method";
  13597. if (isPrivate) {
  13598. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13599. return;
  13600. }
  13601. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13602. let allowsDirectSuper = false;
  13603. if (isConstructor) {
  13604. publicMethod.kind = "constructor";
  13605. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13606. this.raise(Errors.DuplicateConstructor, key);
  13607. }
  13608. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13609. this.raise(Errors.OverrideOnConstructor, key);
  13610. }
  13611. state.hadConstructor = true;
  13612. allowsDirectSuper = state.hadSuperClass;
  13613. }
  13614. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13615. } else if (this.isClassProperty()) {
  13616. if (isPrivate) {
  13617. this.pushClassPrivateProperty(classBody, privateProp);
  13618. } else {
  13619. this.pushClassProperty(classBody, publicProp);
  13620. }
  13621. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13622. this.resetPreviousNodeTrailingComments(key);
  13623. const isGenerator = this.eat(55);
  13624. if (publicMember.optional) {
  13625. this.unexpected(maybeQuestionTokenStartLoc);
  13626. }
  13627. method.kind = "method";
  13628. const isPrivate = this.match(139);
  13629. this.parseClassElementName(method);
  13630. this.parsePostMemberNameModifiers(publicMember);
  13631. if (isPrivate) {
  13632. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13633. } else {
  13634. if (this.isNonstaticConstructor(publicMethod)) {
  13635. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13636. }
  13637. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13638. }
  13639. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13640. this.resetPreviousNodeTrailingComments(key);
  13641. method.kind = maybeContextualKw;
  13642. const isPrivate = this.match(139);
  13643. this.parseClassElementName(publicMethod);
  13644. if (isPrivate) {
  13645. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13646. } else {
  13647. if (this.isNonstaticConstructor(publicMethod)) {
  13648. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13649. }
  13650. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13651. }
  13652. this.checkGetterSetterParams(publicMethod);
  13653. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13654. this.expectPlugin("decoratorAutoAccessors");
  13655. this.resetPreviousNodeTrailingComments(key);
  13656. const isPrivate = this.match(139);
  13657. this.parseClassElementName(publicProp);
  13658. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13659. } else if (this.isLineTerminator()) {
  13660. if (isPrivate) {
  13661. this.pushClassPrivateProperty(classBody, privateProp);
  13662. } else {
  13663. this.pushClassProperty(classBody, publicProp);
  13664. }
  13665. } else {
  13666. this.unexpected();
  13667. }
  13668. }
  13669. parseClassElementName(member) {
  13670. const {
  13671. type,
  13672. value
  13673. } = this.state;
  13674. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  13675. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13676. }
  13677. if (type === 139) {
  13678. if (value === "constructor") {
  13679. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13680. }
  13681. const key = this.parsePrivateName();
  13682. member.key = key;
  13683. return key;
  13684. }
  13685. this.parsePropertyName(member);
  13686. return member.key;
  13687. }
  13688. parseClassStaticBlock(classBody, member) {
  13689. var _member$decorators;
  13690. this.scope.enter(576 | 128 | 16);
  13691. const oldLabels = this.state.labels;
  13692. this.state.labels = [];
  13693. this.prodParam.enter(0);
  13694. const body = member.body = [];
  13695. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13696. this.prodParam.exit();
  13697. this.scope.exit();
  13698. this.state.labels = oldLabels;
  13699. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13700. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13701. this.raise(Errors.DecoratorStaticBlock, member);
  13702. }
  13703. }
  13704. pushClassProperty(classBody, prop) {
  13705. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13706. this.raise(Errors.ConstructorClassField, prop.key);
  13707. }
  13708. classBody.body.push(this.parseClassProperty(prop));
  13709. }
  13710. pushClassPrivateProperty(classBody, prop) {
  13711. const node = this.parseClassPrivateProperty(prop);
  13712. classBody.body.push(node);
  13713. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13714. }
  13715. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13716. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13717. this.raise(Errors.ConstructorClassField, prop.key);
  13718. }
  13719. const node = this.parseClassAccessorProperty(prop);
  13720. classBody.body.push(node);
  13721. if (isPrivate) {
  13722. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13723. }
  13724. }
  13725. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13726. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13727. }
  13728. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13729. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13730. classBody.body.push(node);
  13731. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13732. this.declareClassPrivateMethodInScope(node, kind);
  13733. }
  13734. declareClassPrivateMethodInScope(node, kind) {
  13735. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13736. }
  13737. parsePostMemberNameModifiers(methodOrProp) {}
  13738. parseClassPrivateProperty(node) {
  13739. this.parseInitializer(node);
  13740. this.semicolon();
  13741. return this.finishNode(node, "ClassPrivateProperty");
  13742. }
  13743. parseClassProperty(node) {
  13744. this.parseInitializer(node);
  13745. this.semicolon();
  13746. return this.finishNode(node, "ClassProperty");
  13747. }
  13748. parseClassAccessorProperty(node) {
  13749. this.parseInitializer(node);
  13750. this.semicolon();
  13751. return this.finishNode(node, "ClassAccessorProperty");
  13752. }
  13753. parseInitializer(node) {
  13754. this.scope.enter(576 | 16);
  13755. this.expressionScope.enter(newExpressionScope());
  13756. this.prodParam.enter(0);
  13757. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13758. this.expressionScope.exit();
  13759. this.prodParam.exit();
  13760. this.scope.exit();
  13761. }
  13762. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13763. if (tokenIsIdentifier(this.state.type)) {
  13764. node.id = this.parseIdentifier();
  13765. if (isStatement) {
  13766. this.declareNameFromIdentifier(node.id, bindingType);
  13767. }
  13768. } else {
  13769. if (optionalId || !isStatement) {
  13770. node.id = null;
  13771. } else {
  13772. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13773. }
  13774. }
  13775. }
  13776. parseClassSuper(node) {
  13777. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13778. }
  13779. parseExport(node, decorators) {
  13780. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13781. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13782. const parseAfterDefault = !hasDefault || this.eat(12);
  13783. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13784. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13785. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13786. const isFromRequired = hasDefault || hasStar;
  13787. if (hasStar && !hasNamespace) {
  13788. if (hasDefault) this.unexpected();
  13789. if (decorators) {
  13790. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13791. }
  13792. this.parseExportFrom(node, true);
  13793. this.sawUnambiguousESM = true;
  13794. return this.finishNode(node, "ExportAllDeclaration");
  13795. }
  13796. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13797. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13798. this.unexpected(null, 5);
  13799. }
  13800. if (hasNamespace && parseAfterNamespace) {
  13801. this.unexpected(null, 98);
  13802. }
  13803. let hasDeclaration;
  13804. if (isFromRequired || hasSpecifiers) {
  13805. hasDeclaration = false;
  13806. if (decorators) {
  13807. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13808. }
  13809. this.parseExportFrom(node, isFromRequired);
  13810. } else {
  13811. hasDeclaration = this.maybeParseExportDeclaration(node);
  13812. }
  13813. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13814. var _node2$declaration;
  13815. const node2 = node;
  13816. this.checkExport(node2, true, false, !!node2.source);
  13817. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13818. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13819. } else if (decorators) {
  13820. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13821. }
  13822. this.sawUnambiguousESM = true;
  13823. return this.finishNode(node2, "ExportNamedDeclaration");
  13824. }
  13825. if (this.eat(65)) {
  13826. const node2 = node;
  13827. const decl = this.parseExportDefaultExpression();
  13828. node2.declaration = decl;
  13829. if (decl.type === "ClassDeclaration") {
  13830. this.maybeTakeDecorators(decorators, decl, node2);
  13831. } else if (decorators) {
  13832. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13833. }
  13834. this.checkExport(node2, true, true);
  13835. this.sawUnambiguousESM = true;
  13836. return this.finishNode(node2, "ExportDefaultDeclaration");
  13837. }
  13838. throw this.unexpected(null, 5);
  13839. }
  13840. eatExportStar(node) {
  13841. return this.eat(55);
  13842. }
  13843. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13844. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13845. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13846. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13847. const specifier = this.startNodeAtNode(id);
  13848. specifier.exported = id;
  13849. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13850. return true;
  13851. }
  13852. return false;
  13853. }
  13854. maybeParseExportNamespaceSpecifier(node) {
  13855. if (this.isContextual(93)) {
  13856. var _ref, _ref$specifiers;
  13857. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13858. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13859. this.next();
  13860. specifier.exported = this.parseModuleExportName();
  13861. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13862. return true;
  13863. }
  13864. return false;
  13865. }
  13866. maybeParseExportNamedSpecifiers(node) {
  13867. if (this.match(5)) {
  13868. const node2 = node;
  13869. if (!node2.specifiers) node2.specifiers = [];
  13870. const isTypeExport = node2.exportKind === "type";
  13871. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13872. node2.source = null;
  13873. if (this.hasPlugin("importAssertions")) {
  13874. node2.assertions = [];
  13875. } else {
  13876. node2.attributes = [];
  13877. }
  13878. node2.declaration = null;
  13879. return true;
  13880. }
  13881. return false;
  13882. }
  13883. maybeParseExportDeclaration(node) {
  13884. if (this.shouldParseExportDeclaration()) {
  13885. node.specifiers = [];
  13886. node.source = null;
  13887. if (this.hasPlugin("importAssertions")) {
  13888. node.assertions = [];
  13889. } else {
  13890. node.attributes = [];
  13891. }
  13892. node.declaration = this.parseExportDeclaration(node);
  13893. return true;
  13894. }
  13895. return false;
  13896. }
  13897. isAsyncFunction() {
  13898. if (!this.isContextual(95)) return false;
  13899. const next = this.nextTokenInLineStart();
  13900. return this.isUnparsedContextual(next, "function");
  13901. }
  13902. parseExportDefaultExpression() {
  13903. const expr = this.startNode();
  13904. if (this.match(68)) {
  13905. this.next();
  13906. return this.parseFunction(expr, 1 | 4);
  13907. } else if (this.isAsyncFunction()) {
  13908. this.next();
  13909. this.next();
  13910. return this.parseFunction(expr, 1 | 4 | 8);
  13911. }
  13912. if (this.match(80)) {
  13913. return this.parseClass(expr, true, true);
  13914. }
  13915. if (this.match(26)) {
  13916. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13917. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13918. }
  13919. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13920. }
  13921. if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
  13922. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13923. }
  13924. const res = this.parseMaybeAssignAllowIn();
  13925. this.semicolon();
  13926. return res;
  13927. }
  13928. parseExportDeclaration(node) {
  13929. if (this.match(80)) {
  13930. const node = this.parseClass(this.startNode(), true, false);
  13931. return node;
  13932. }
  13933. return this.parseStatementListItem();
  13934. }
  13935. isExportDefaultSpecifier() {
  13936. const {
  13937. type
  13938. } = this.state;
  13939. if (tokenIsIdentifier(type)) {
  13940. if (type === 95 && !this.state.containsEsc || type === 100) {
  13941. return false;
  13942. }
  13943. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13944. const next = this.nextTokenStart();
  13945. const nextChar = this.input.charCodeAt(next);
  13946. if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
  13947. this.expectOnePlugin(["flow", "typescript"]);
  13948. return false;
  13949. }
  13950. }
  13951. } else if (!this.match(65)) {
  13952. return false;
  13953. }
  13954. const next = this.nextTokenStart();
  13955. const hasFrom = this.isUnparsedContextual(next, "from");
  13956. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13957. return true;
  13958. }
  13959. if (this.match(65) && hasFrom) {
  13960. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13961. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13962. }
  13963. return false;
  13964. }
  13965. parseExportFrom(node, expect) {
  13966. if (this.eatContextual(98)) {
  13967. node.source = this.parseImportSource();
  13968. this.checkExport(node);
  13969. this.maybeParseImportAttributes(node);
  13970. this.checkJSONModuleImport(node);
  13971. } else if (expect) {
  13972. this.unexpected();
  13973. }
  13974. this.semicolon();
  13975. }
  13976. shouldParseExportDeclaration() {
  13977. const {
  13978. type
  13979. } = this.state;
  13980. if (type === 26) {
  13981. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13982. if (this.hasPlugin("decorators")) {
  13983. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13984. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13985. }
  13986. return true;
  13987. }
  13988. }
  13989. if (this.isUsing()) {
  13990. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13991. return true;
  13992. }
  13993. if (this.isAwaitUsing()) {
  13994. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13995. return true;
  13996. }
  13997. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13998. }
  13999. checkExport(node, checkNames, isDefault, isFrom) {
  14000. if (checkNames) {
  14001. var _node$specifiers;
  14002. if (isDefault) {
  14003. this.checkDuplicateExports(node, "default");
  14004. if (this.hasPlugin("exportDefaultFrom")) {
  14005. var _declaration$extra;
  14006. const declaration = node.declaration;
  14007. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  14008. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  14009. }
  14010. }
  14011. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  14012. for (const specifier of node.specifiers) {
  14013. const {
  14014. exported
  14015. } = specifier;
  14016. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  14017. this.checkDuplicateExports(specifier, exportName);
  14018. if (!isFrom && specifier.local) {
  14019. const {
  14020. local
  14021. } = specifier;
  14022. if (local.type !== "Identifier") {
  14023. this.raise(Errors.ExportBindingIsString, specifier, {
  14024. localName: local.value,
  14025. exportName
  14026. });
  14027. } else {
  14028. this.checkReservedWord(local.name, local.loc.start, true, false);
  14029. this.scope.checkLocalExport(local);
  14030. }
  14031. }
  14032. }
  14033. } else if (node.declaration) {
  14034. const decl = node.declaration;
  14035. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  14036. const {
  14037. id
  14038. } = decl;
  14039. if (!id) throw new Error("Assertion failure");
  14040. this.checkDuplicateExports(node, id.name);
  14041. } else if (decl.type === "VariableDeclaration") {
  14042. for (const declaration of decl.declarations) {
  14043. this.checkDeclaration(declaration.id);
  14044. }
  14045. }
  14046. }
  14047. }
  14048. }
  14049. checkDeclaration(node) {
  14050. if (node.type === "Identifier") {
  14051. this.checkDuplicateExports(node, node.name);
  14052. } else if (node.type === "ObjectPattern") {
  14053. for (const prop of node.properties) {
  14054. this.checkDeclaration(prop);
  14055. }
  14056. } else if (node.type === "ArrayPattern") {
  14057. for (const elem of node.elements) {
  14058. if (elem) {
  14059. this.checkDeclaration(elem);
  14060. }
  14061. }
  14062. } else if (node.type === "ObjectProperty") {
  14063. this.checkDeclaration(node.value);
  14064. } else if (node.type === "RestElement") {
  14065. this.checkDeclaration(node.argument);
  14066. } else if (node.type === "AssignmentPattern") {
  14067. this.checkDeclaration(node.left);
  14068. }
  14069. }
  14070. checkDuplicateExports(node, exportName) {
  14071. if (this.exportedIdentifiers.has(exportName)) {
  14072. if (exportName === "default") {
  14073. this.raise(Errors.DuplicateDefaultExport, node);
  14074. } else {
  14075. this.raise(Errors.DuplicateExport, node, {
  14076. exportName
  14077. });
  14078. }
  14079. }
  14080. this.exportedIdentifiers.add(exportName);
  14081. }
  14082. parseExportSpecifiers(isInTypeExport) {
  14083. const nodes = [];
  14084. let first = true;
  14085. this.expect(5);
  14086. while (!this.eat(8)) {
  14087. if (first) {
  14088. first = false;
  14089. } else {
  14090. this.expect(12);
  14091. if (this.eat(8)) break;
  14092. }
  14093. const isMaybeTypeOnly = this.isContextual(130);
  14094. const isString = this.match(134);
  14095. const node = this.startNode();
  14096. node.local = this.parseModuleExportName();
  14097. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  14098. }
  14099. return nodes;
  14100. }
  14101. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14102. if (this.eatContextual(93)) {
  14103. node.exported = this.parseModuleExportName();
  14104. } else if (isString) {
  14105. node.exported = this.cloneStringLiteral(node.local);
  14106. } else if (!node.exported) {
  14107. node.exported = this.cloneIdentifier(node.local);
  14108. }
  14109. return this.finishNode(node, "ExportSpecifier");
  14110. }
  14111. parseModuleExportName() {
  14112. if (this.match(134)) {
  14113. const result = this.parseStringLiteral(this.state.value);
  14114. const surrogate = loneSurrogate.exec(result.value);
  14115. if (surrogate) {
  14116. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  14117. surrogateCharCode: surrogate[0].charCodeAt(0)
  14118. });
  14119. }
  14120. return result;
  14121. }
  14122. return this.parseIdentifier(true);
  14123. }
  14124. isJSONModuleImport(node) {
  14125. if (node.assertions != null) {
  14126. return node.assertions.some(({
  14127. key,
  14128. value
  14129. }) => {
  14130. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14131. });
  14132. }
  14133. return false;
  14134. }
  14135. checkImportReflection(node) {
  14136. const {
  14137. specifiers
  14138. } = node;
  14139. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  14140. if (node.phase === "source") {
  14141. if (singleBindingType !== "ImportDefaultSpecifier") {
  14142. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  14143. }
  14144. } else if (node.phase === "defer") {
  14145. if (singleBindingType !== "ImportNamespaceSpecifier") {
  14146. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  14147. }
  14148. } else if (node.module) {
  14149. var _node$assertions;
  14150. if (singleBindingType !== "ImportDefaultSpecifier") {
  14151. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  14152. }
  14153. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14154. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  14155. }
  14156. }
  14157. }
  14158. checkJSONModuleImport(node) {
  14159. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14160. const {
  14161. specifiers
  14162. } = node;
  14163. if (specifiers != null) {
  14164. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14165. let imported;
  14166. if (specifier.type === "ExportSpecifier") {
  14167. imported = specifier.local;
  14168. } else if (specifier.type === "ImportSpecifier") {
  14169. imported = specifier.imported;
  14170. }
  14171. if (imported !== undefined) {
  14172. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14173. }
  14174. });
  14175. if (nonDefaultNamedSpecifier !== undefined) {
  14176. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  14177. }
  14178. }
  14179. }
  14180. }
  14181. isPotentialImportPhase(isExport) {
  14182. if (isExport) return false;
  14183. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  14184. }
  14185. applyImportPhase(node, isExport, phase, loc) {
  14186. if (isExport) {
  14187. return;
  14188. }
  14189. if (phase === "module") {
  14190. this.expectPlugin("importReflection", loc);
  14191. node.module = true;
  14192. } else if (this.hasPlugin("importReflection")) {
  14193. node.module = false;
  14194. }
  14195. if (phase === "source") {
  14196. this.expectPlugin("sourcePhaseImports", loc);
  14197. node.phase = "source";
  14198. } else if (phase === "defer") {
  14199. this.expectPlugin("deferredImportEvaluation", loc);
  14200. node.phase = "defer";
  14201. } else if (this.hasPlugin("sourcePhaseImports")) {
  14202. node.phase = null;
  14203. }
  14204. }
  14205. parseMaybeImportPhase(node, isExport) {
  14206. if (!this.isPotentialImportPhase(isExport)) {
  14207. this.applyImportPhase(node, isExport, null);
  14208. return null;
  14209. }
  14210. const phaseIdentifier = this.startNode();
  14211. const phaseIdentifierName = this.parseIdentifierName(true);
  14212. const {
  14213. type
  14214. } = this.state;
  14215. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14216. if (isImportPhase) {
  14217. this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
  14218. return null;
  14219. } else {
  14220. this.applyImportPhase(node, isExport, null);
  14221. return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
  14222. }
  14223. }
  14224. isPrecedingIdImportPhase(phase) {
  14225. const {
  14226. type
  14227. } = this.state;
  14228. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14229. }
  14230. parseImport(node) {
  14231. if (this.match(134)) {
  14232. return this.parseImportSourceAndAttributes(node);
  14233. }
  14234. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14235. }
  14236. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14237. node.specifiers = [];
  14238. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14239. const parseNext = !hasDefault || this.eat(12);
  14240. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14241. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14242. this.expectContextual(98);
  14243. return this.parseImportSourceAndAttributes(node);
  14244. }
  14245. parseImportSourceAndAttributes(node) {
  14246. var _node$specifiers2;
  14247. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14248. node.source = this.parseImportSource();
  14249. this.maybeParseImportAttributes(node);
  14250. this.checkImportReflection(node);
  14251. this.checkJSONModuleImport(node);
  14252. this.semicolon();
  14253. this.sawUnambiguousESM = true;
  14254. return this.finishNode(node, "ImportDeclaration");
  14255. }
  14256. parseImportSource() {
  14257. if (!this.match(134)) this.unexpected();
  14258. return this.parseExprAtom();
  14259. }
  14260. parseImportSpecifierLocal(node, specifier, type) {
  14261. specifier.local = this.parseIdentifier();
  14262. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14263. }
  14264. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14265. this.checkLVal(specifier.local, {
  14266. type
  14267. }, bindingType);
  14268. return this.finishNode(specifier, type);
  14269. }
  14270. parseImportAttributes() {
  14271. this.expect(5);
  14272. const attrs = [];
  14273. const attrNames = new Set();
  14274. do {
  14275. if (this.match(8)) {
  14276. break;
  14277. }
  14278. const node = this.startNode();
  14279. const keyName = this.state.value;
  14280. if (attrNames.has(keyName)) {
  14281. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  14282. key: keyName
  14283. });
  14284. }
  14285. attrNames.add(keyName);
  14286. if (this.match(134)) {
  14287. node.key = this.parseStringLiteral(keyName);
  14288. } else {
  14289. node.key = this.parseIdentifier(true);
  14290. }
  14291. this.expect(14);
  14292. if (!this.match(134)) {
  14293. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14294. }
  14295. node.value = this.parseStringLiteral(this.state.value);
  14296. attrs.push(this.finishNode(node, "ImportAttribute"));
  14297. } while (this.eat(12));
  14298. this.expect(8);
  14299. return attrs;
  14300. }
  14301. parseModuleAttributes() {
  14302. const attrs = [];
  14303. const attributes = new Set();
  14304. do {
  14305. const node = this.startNode();
  14306. node.key = this.parseIdentifier(true);
  14307. if (node.key.name !== "type") {
  14308. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  14309. }
  14310. if (attributes.has(node.key.name)) {
  14311. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  14312. key: node.key.name
  14313. });
  14314. }
  14315. attributes.add(node.key.name);
  14316. this.expect(14);
  14317. if (!this.match(134)) {
  14318. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14319. }
  14320. node.value = this.parseStringLiteral(this.state.value);
  14321. attrs.push(this.finishNode(node, "ImportAttribute"));
  14322. } while (this.eat(12));
  14323. return attrs;
  14324. }
  14325. maybeParseImportAttributes(node) {
  14326. let attributes;
  14327. var useWith = false;
  14328. if (this.match(76)) {
  14329. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14330. return;
  14331. }
  14332. this.next();
  14333. if (this.hasPlugin("moduleAttributes")) {
  14334. attributes = this.parseModuleAttributes();
  14335. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  14336. } else {
  14337. attributes = this.parseImportAttributes();
  14338. }
  14339. useWith = true;
  14340. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14341. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  14342. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  14343. }
  14344. if (!this.hasPlugin("importAssertions")) {
  14345. this.addExtra(node, "deprecatedAssertSyntax", true);
  14346. }
  14347. this.next();
  14348. attributes = this.parseImportAttributes();
  14349. } else {
  14350. attributes = [];
  14351. }
  14352. if (!useWith && this.hasPlugin("importAssertions")) {
  14353. node.assertions = attributes;
  14354. } else {
  14355. node.attributes = attributes;
  14356. }
  14357. }
  14358. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14359. if (maybeDefaultIdentifier) {
  14360. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14361. specifier.local = maybeDefaultIdentifier;
  14362. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14363. return true;
  14364. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14365. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14366. return true;
  14367. }
  14368. return false;
  14369. }
  14370. maybeParseStarImportSpecifier(node) {
  14371. if (this.match(55)) {
  14372. const specifier = this.startNode();
  14373. this.next();
  14374. this.expectContextual(93);
  14375. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14376. return true;
  14377. }
  14378. return false;
  14379. }
  14380. parseNamedImportSpecifiers(node) {
  14381. let first = true;
  14382. this.expect(5);
  14383. while (!this.eat(8)) {
  14384. if (first) {
  14385. first = false;
  14386. } else {
  14387. if (this.eat(14)) {
  14388. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  14389. }
  14390. this.expect(12);
  14391. if (this.eat(8)) break;
  14392. }
  14393. const specifier = this.startNode();
  14394. const importedIsString = this.match(134);
  14395. const isMaybeTypeOnly = this.isContextual(130);
  14396. specifier.imported = this.parseModuleExportName();
  14397. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14398. node.specifiers.push(importSpecifier);
  14399. }
  14400. }
  14401. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14402. if (this.eatContextual(93)) {
  14403. specifier.local = this.parseIdentifier();
  14404. } else {
  14405. const {
  14406. imported
  14407. } = specifier;
  14408. if (importedIsString) {
  14409. throw this.raise(Errors.ImportBindingIsString, specifier, {
  14410. importName: imported.value
  14411. });
  14412. }
  14413. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14414. if (!specifier.local) {
  14415. specifier.local = this.cloneIdentifier(imported);
  14416. }
  14417. }
  14418. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14419. }
  14420. isThisParam(param) {
  14421. return param.type === "Identifier" && param.name === "this";
  14422. }
  14423. }
  14424. class Parser extends StatementParser {
  14425. constructor(options, input, pluginsMap) {
  14426. const normalizedOptions = getOptions(options);
  14427. super(normalizedOptions, input);
  14428. this.options = normalizedOptions;
  14429. this.initializeScopes();
  14430. this.plugins = pluginsMap;
  14431. this.filename = normalizedOptions.sourceFilename;
  14432. this.startIndex = normalizedOptions.startIndex;
  14433. let optionFlags = 0;
  14434. if (normalizedOptions.allowAwaitOutsideFunction) {
  14435. optionFlags |= 1;
  14436. }
  14437. if (normalizedOptions.allowReturnOutsideFunction) {
  14438. optionFlags |= 2;
  14439. }
  14440. if (normalizedOptions.allowImportExportEverywhere) {
  14441. optionFlags |= 8;
  14442. }
  14443. if (normalizedOptions.allowSuperOutsideMethod) {
  14444. optionFlags |= 16;
  14445. }
  14446. if (normalizedOptions.allowUndeclaredExports) {
  14447. optionFlags |= 64;
  14448. }
  14449. if (normalizedOptions.allowNewTargetOutsideFunction) {
  14450. optionFlags |= 4;
  14451. }
  14452. if (normalizedOptions.allowYieldOutsideFunction) {
  14453. optionFlags |= 32;
  14454. }
  14455. if (normalizedOptions.ranges) {
  14456. optionFlags |= 128;
  14457. }
  14458. if (normalizedOptions.tokens) {
  14459. optionFlags |= 256;
  14460. }
  14461. if (normalizedOptions.createImportExpressions) {
  14462. optionFlags |= 512;
  14463. }
  14464. if (normalizedOptions.createParenthesizedExpressions) {
  14465. optionFlags |= 1024;
  14466. }
  14467. if (normalizedOptions.errorRecovery) {
  14468. optionFlags |= 2048;
  14469. }
  14470. if (normalizedOptions.attachComment) {
  14471. optionFlags |= 4096;
  14472. }
  14473. if (normalizedOptions.annexB) {
  14474. optionFlags |= 8192;
  14475. }
  14476. this.optionFlags = optionFlags;
  14477. }
  14478. getScopeHandler() {
  14479. return ScopeHandler;
  14480. }
  14481. parse() {
  14482. this.enterInitialScopes();
  14483. const file = this.startNode();
  14484. const program = this.startNode();
  14485. this.nextToken();
  14486. file.errors = null;
  14487. const result = this.parseTopLevel(file, program);
  14488. result.errors = this.state.errors;
  14489. result.comments.length = this.state.commentsLen;
  14490. return result;
  14491. }
  14492. }
  14493. function parse(input, options) {
  14494. var _options;
  14495. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14496. options = Object.assign({}, options);
  14497. try {
  14498. options.sourceType = "module";
  14499. const parser = getParser(options, input);
  14500. const ast = parser.parse();
  14501. if (parser.sawUnambiguousESM) {
  14502. return ast;
  14503. }
  14504. if (parser.ambiguousScriptDifferentAst) {
  14505. try {
  14506. options.sourceType = "script";
  14507. return getParser(options, input).parse();
  14508. } catch (_unused) {}
  14509. } else {
  14510. ast.program.sourceType = "script";
  14511. }
  14512. return ast;
  14513. } catch (moduleError) {
  14514. try {
  14515. options.sourceType = "script";
  14516. return getParser(options, input).parse();
  14517. } catch (_unused2) {}
  14518. throw moduleError;
  14519. }
  14520. } else {
  14521. return getParser(options, input).parse();
  14522. }
  14523. }
  14524. function parseExpression(input, options) {
  14525. const parser = getParser(options, input);
  14526. if (parser.options.strictMode) {
  14527. parser.state.strict = true;
  14528. }
  14529. return parser.getExpression();
  14530. }
  14531. function generateExportedTokenTypes(internalTokenTypes) {
  14532. const tokenTypes = {};
  14533. for (const typeName of Object.keys(internalTokenTypes)) {
  14534. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14535. }
  14536. return tokenTypes;
  14537. }
  14538. const tokTypes = generateExportedTokenTypes(tt);
  14539. function getParser(options, input) {
  14540. let cls = Parser;
  14541. const pluginsMap = new Map();
  14542. if (options != null && options.plugins) {
  14543. for (const plugin of options.plugins) {
  14544. let name, opts;
  14545. if (typeof plugin === "string") {
  14546. name = plugin;
  14547. } else {
  14548. [name, opts] = plugin;
  14549. }
  14550. if (!pluginsMap.has(name)) {
  14551. pluginsMap.set(name, opts || {});
  14552. }
  14553. }
  14554. validatePlugins(pluginsMap);
  14555. cls = getParserClass(pluginsMap);
  14556. }
  14557. return new cls(options, input, pluginsMap);
  14558. }
  14559. const parserClassCache = new Map();
  14560. function getParserClass(pluginsMap) {
  14561. const pluginList = [];
  14562. for (const name of mixinPluginNames) {
  14563. if (pluginsMap.has(name)) {
  14564. pluginList.push(name);
  14565. }
  14566. }
  14567. const key = pluginList.join("|");
  14568. let cls = parserClassCache.get(key);
  14569. if (!cls) {
  14570. cls = Parser;
  14571. for (const plugin of pluginList) {
  14572. cls = mixinPlugins[plugin](cls);
  14573. }
  14574. parserClassCache.set(key, cls);
  14575. }
  14576. return cls;
  14577. }
  14578. exports.parse = parse;
  14579. exports.parseExpression = parseExpression;
  14580. exports.tokTypes = tokTypes;
  14581. //# sourceMappingURL=index.js.map