index.js 480 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214
  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 (e.includes(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. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  91. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  92. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  93. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  94. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  95. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  96. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  97. ConstructorIsAsync: "Constructor can't be an async function.",
  98. ConstructorIsGenerator: "Constructor can't be a generator.",
  99. DeclarationMissingInitializer: ({
  100. kind
  101. }) => `Missing initializer in ${kind} declaration.`,
  102. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  103. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  104. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  105. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  106. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  107. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  108. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  109. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  110. DeletePrivateField: "Deleting a private field is not allowed.",
  111. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  112. DuplicateConstructor: "Duplicate constructor in the same class.",
  113. DuplicateDefaultExport: "Only one default export allowed per module.",
  114. DuplicateExport: ({
  115. exportName
  116. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  117. DuplicateProto: "Redefinition of __proto__ property.",
  118. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  119. DynamicImportPhaseRequiresImportExpressions: ({
  120. phase
  121. }) => `'import.${phase}(...)' can only be parsed when using the 'createImportExpressions' option.`,
  122. ElementAfterRest: "Rest element must be last element.",
  123. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  124. ExportBindingIsString: ({
  125. localName,
  126. exportName
  127. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  128. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  129. ForInOfLoopInitializer: ({
  130. type
  131. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  132. ForInUsing: "For-in loop may not start with 'using' declaration.",
  133. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  134. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  135. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  136. IllegalBreakContinue: ({
  137. type
  138. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  139. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  140. IllegalReturn: "'return' outside of function.",
  141. 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.",
  142. ImportBindingIsString: ({
  143. importName
  144. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  145. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  146. ImportCallNotNewExpression: "Cannot use new with import(...).",
  147. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  148. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  149. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  150. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  151. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  152. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  153. InvalidCodePoint: "Code point out of bounds.",
  154. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  155. InvalidDecimal: "Invalid decimal.",
  156. InvalidDigit: ({
  157. radix
  158. }) => `Expected number in radix ${radix}.`,
  159. InvalidEscapeSequence: "Bad character escape sequence.",
  160. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  161. InvalidEscapedReservedWord: ({
  162. reservedWord
  163. }) => `Escape sequence in keyword ${reservedWord}.`,
  164. InvalidIdentifier: ({
  165. identifierName
  166. }) => `Invalid identifier ${identifierName}.`,
  167. InvalidLhs: ({
  168. ancestor
  169. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  170. InvalidLhsBinding: ({
  171. ancestor
  172. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  173. InvalidLhsOptionalChaining: ({
  174. ancestor
  175. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  176. InvalidNumber: "Invalid number.",
  177. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  178. InvalidOrUnexpectedToken: ({
  179. unexpected
  180. }) => `Unexpected character '${unexpected}'.`,
  181. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  182. InvalidPrivateFieldResolution: ({
  183. identifierName
  184. }) => `Private name #${identifierName} is not defined.`,
  185. InvalidPropertyBindingPattern: "Binding member expression.",
  186. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  187. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  188. LabelRedeclaration: ({
  189. labelName
  190. }) => `Label '${labelName}' is already declared.`,
  191. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  192. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  193. MalformedRegExpFlags: "Invalid regular expression flag.",
  194. MissingClassName: "A class name is required.",
  195. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  196. MissingSemicolon: "Missing semicolon.",
  197. MissingPlugin: ({
  198. missingPlugin
  199. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  200. MissingOneOfPlugins: ({
  201. missingPlugin
  202. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  203. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  204. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  205. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  206. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  207. ModuleAttributesWithDuplicateKeys: ({
  208. key
  209. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  210. ModuleExportNameHasLoneSurrogate: ({
  211. surrogateCharCode
  212. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  213. ModuleExportUndefined: ({
  214. localName
  215. }) => `Export '${localName}' is not defined.`,
  216. MultipleDefaultsInSwitch: "Multiple default clauses.",
  217. NewlineAfterThrow: "Illegal newline after throw.",
  218. NoCatchOrFinally: "Missing catch or finally clause.",
  219. NumberIdentifier: "Identifier directly after number.",
  220. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  221. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  222. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  223. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  224. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  225. ParamDupe: "Argument name clash.",
  226. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  227. PatternHasMethod: "Object pattern can't contain methods.",
  228. PrivateInExpectedIn: ({
  229. identifierName
  230. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  231. PrivateNameRedeclaration: ({
  232. identifierName
  233. }) => `Duplicate private name #${identifierName}.`,
  234. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  235. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  236. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  237. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  238. RestTrailingComma: "Unexpected trailing comma after rest element.",
  239. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  240. 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.",
  241. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  242. StaticPrototype: "Classes may not have static property named prototype.",
  243. 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?",
  244. SuperPrivateField: "Private fields can't be accessed on super.",
  245. TrailingDecorator: "Decorators must be attached to a class element.",
  246. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  247. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  248. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  249. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  250. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  251. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  252. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  253. UnexpectedKeyword: ({
  254. keyword
  255. }) => `Unexpected keyword '${keyword}'.`,
  256. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  257. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  258. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  259. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  260. UnexpectedPrivateField: "Unexpected private name.",
  261. UnexpectedReservedWord: ({
  262. reservedWord
  263. }) => `Unexpected reserved word '${reservedWord}'.`,
  264. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  265. UnexpectedToken: ({
  266. expected,
  267. unexpected
  268. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  269. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  270. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  271. UnsupportedBind: "Binding should be performed on object property.",
  272. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  273. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  274. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  275. UnsupportedMetaProperty: ({
  276. target,
  277. onlyValidPropertyName
  278. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  279. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  280. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  281. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  282. UnterminatedComment: "Unterminated comment.",
  283. UnterminatedRegExp: "Unterminated regular expression.",
  284. UnterminatedString: "Unterminated string constant.",
  285. UnterminatedTemplate: "Unterminated template.",
  286. UsingDeclarationExport: "Using declaration cannot be exported.",
  287. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  288. VarRedeclaration: ({
  289. identifierName
  290. }) => `Identifier '${identifierName}' has already been declared.`,
  291. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  292. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  293. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  294. };
  295. var StrictModeErrors = {
  296. StrictDelete: "Deleting local variable in strict mode.",
  297. StrictEvalArguments: ({
  298. referenceName
  299. }) => `Assigning to '${referenceName}' in strict mode.`,
  300. StrictEvalArgumentsBinding: ({
  301. bindingName
  302. }) => `Binding '${bindingName}' in strict mode.`,
  303. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  304. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  305. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  306. StrictWith: "'with' in strict mode."
  307. };
  308. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  309. var PipelineOperatorErrors = Object.assign({
  310. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  311. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  312. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  313. PipeTopicUnconfiguredToken: ({
  314. token
  315. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  316. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  317. PipeUnparenthesizedBody: ({
  318. type
  319. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  320. type
  321. })}; please wrap it in parentheses.`
  322. }, {
  323. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  324. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  325. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  326. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  327. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  328. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  329. });
  330. const _excluded = ["message"];
  331. function defineHidden(obj, key, value) {
  332. Object.defineProperty(obj, key, {
  333. enumerable: false,
  334. configurable: true,
  335. value
  336. });
  337. }
  338. function toParseErrorConstructor({
  339. toMessage,
  340. code,
  341. reasonCode,
  342. syntaxPlugin
  343. }) {
  344. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  345. {
  346. const oldReasonCodes = {
  347. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  348. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  349. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  350. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  351. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  352. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  353. };
  354. if (oldReasonCodes[reasonCode]) {
  355. reasonCode = oldReasonCodes[reasonCode];
  356. }
  357. }
  358. return function constructor(loc, details) {
  359. const error = new SyntaxError();
  360. error.code = code;
  361. error.reasonCode = reasonCode;
  362. error.loc = loc;
  363. error.pos = loc.index;
  364. error.syntaxPlugin = syntaxPlugin;
  365. if (hasMissingPlugin) {
  366. error.missingPlugin = details.missingPlugin;
  367. }
  368. defineHidden(error, "clone", function clone(overrides = {}) {
  369. var _overrides$loc;
  370. const {
  371. line,
  372. column,
  373. index
  374. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  375. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  376. });
  377. defineHidden(error, "details", details);
  378. Object.defineProperty(error, "message", {
  379. configurable: true,
  380. get() {
  381. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  382. this.message = message;
  383. return message;
  384. },
  385. set(value) {
  386. Object.defineProperty(this, "message", {
  387. value,
  388. writable: true
  389. });
  390. }
  391. });
  392. return error;
  393. };
  394. }
  395. function ParseErrorEnum(argument, syntaxPlugin) {
  396. if (Array.isArray(argument)) {
  397. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  398. }
  399. const ParseErrorConstructors = {};
  400. for (const reasonCode of Object.keys(argument)) {
  401. const template = argument[reasonCode];
  402. const _ref = typeof template === "string" ? {
  403. message: () => template
  404. } : typeof template === "function" ? {
  405. message: template
  406. } : template,
  407. {
  408. message
  409. } = _ref,
  410. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  411. const toMessage = typeof message === "string" ? () => message : message;
  412. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  413. code: "BABEL_PARSER_SYNTAX_ERROR",
  414. reasonCode,
  415. toMessage
  416. }, syntaxPlugin ? {
  417. syntaxPlugin
  418. } : {}, rest));
  419. }
  420. return ParseErrorConstructors;
  421. }
  422. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  423. function createDefaultOptions() {
  424. return {
  425. sourceType: "script",
  426. sourceFilename: undefined,
  427. startIndex: 0,
  428. startColumn: 0,
  429. startLine: 1,
  430. allowAwaitOutsideFunction: false,
  431. allowReturnOutsideFunction: false,
  432. allowNewTargetOutsideFunction: false,
  433. allowImportExportEverywhere: false,
  434. allowSuperOutsideMethod: false,
  435. allowUndeclaredExports: false,
  436. plugins: [],
  437. strictMode: null,
  438. ranges: false,
  439. tokens: false,
  440. createImportExpressions: false,
  441. createParenthesizedExpressions: false,
  442. errorRecovery: false,
  443. attachComment: true,
  444. annexB: true
  445. };
  446. }
  447. function getOptions(opts) {
  448. const options = createDefaultOptions();
  449. if (opts == null) {
  450. return options;
  451. }
  452. if (opts.annexB != null && opts.annexB !== false) {
  453. throw new Error("The `annexB` option can only be set to `false`.");
  454. }
  455. for (const key of Object.keys(options)) {
  456. if (opts[key] != null) options[key] = opts[key];
  457. }
  458. if (options.startLine === 1) {
  459. if (opts.startIndex == null && options.startColumn > 0) {
  460. options.startIndex = options.startColumn;
  461. } else if (opts.startColumn == null && options.startIndex > 0) {
  462. options.startColumn = options.startIndex;
  463. }
  464. } else if (opts.startColumn == null || opts.startIndex == null) {
  465. if (opts.startIndex != null) {
  466. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  467. }
  468. }
  469. return options;
  470. }
  471. const {
  472. defineProperty
  473. } = Object;
  474. const toUnenumerable = (object, key) => {
  475. if (object) {
  476. defineProperty(object, key, {
  477. enumerable: false,
  478. value: object[key]
  479. });
  480. }
  481. };
  482. function toESTreeLocation(node) {
  483. toUnenumerable(node.loc.start, "index");
  484. toUnenumerable(node.loc.end, "index");
  485. return node;
  486. }
  487. var estree = superClass => class ESTreeParserMixin extends superClass {
  488. parse() {
  489. const file = toESTreeLocation(super.parse());
  490. if (this.optionFlags & 128) {
  491. file.tokens = file.tokens.map(toESTreeLocation);
  492. }
  493. return file;
  494. }
  495. parseRegExpLiteral({
  496. pattern,
  497. flags
  498. }) {
  499. let regex = null;
  500. try {
  501. regex = new RegExp(pattern, flags);
  502. } catch (_) {}
  503. const node = this.estreeParseLiteral(regex);
  504. node.regex = {
  505. pattern,
  506. flags
  507. };
  508. return node;
  509. }
  510. parseBigIntLiteral(value) {
  511. let bigInt;
  512. try {
  513. bigInt = BigInt(value);
  514. } catch (_unused) {
  515. bigInt = null;
  516. }
  517. const node = this.estreeParseLiteral(bigInt);
  518. node.bigint = String(node.value || value);
  519. return node;
  520. }
  521. parseDecimalLiteral(value) {
  522. const decimal = null;
  523. const node = this.estreeParseLiteral(decimal);
  524. node.decimal = String(node.value || value);
  525. return node;
  526. }
  527. estreeParseLiteral(value) {
  528. return this.parseLiteral(value, "Literal");
  529. }
  530. parseStringLiteral(value) {
  531. return this.estreeParseLiteral(value);
  532. }
  533. parseNumericLiteral(value) {
  534. return this.estreeParseLiteral(value);
  535. }
  536. parseNullLiteral() {
  537. return this.estreeParseLiteral(null);
  538. }
  539. parseBooleanLiteral(value) {
  540. return this.estreeParseLiteral(value);
  541. }
  542. directiveToStmt(directive) {
  543. const expression = directive.value;
  544. delete directive.value;
  545. expression.type = "Literal";
  546. expression.raw = expression.extra.raw;
  547. expression.value = expression.extra.expressionValue;
  548. const stmt = directive;
  549. stmt.type = "ExpressionStatement";
  550. stmt.expression = expression;
  551. stmt.directive = expression.extra.rawValue;
  552. delete expression.extra;
  553. return stmt;
  554. }
  555. initFunction(node, isAsync) {
  556. super.initFunction(node, isAsync);
  557. node.expression = false;
  558. }
  559. checkDeclaration(node) {
  560. if (node != null && this.isObjectProperty(node)) {
  561. this.checkDeclaration(node.value);
  562. } else {
  563. super.checkDeclaration(node);
  564. }
  565. }
  566. getObjectOrClassMethodParams(method) {
  567. return method.value.params;
  568. }
  569. isValidDirective(stmt) {
  570. var _stmt$expression$extr;
  571. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  572. }
  573. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  574. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  575. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  576. node.body = directiveStatements.concat(node.body);
  577. delete node.directives;
  578. }
  579. parsePrivateName() {
  580. const node = super.parsePrivateName();
  581. {
  582. if (!this.getPluginOption("estree", "classFeatures")) {
  583. return node;
  584. }
  585. }
  586. return this.convertPrivateNameToPrivateIdentifier(node);
  587. }
  588. convertPrivateNameToPrivateIdentifier(node) {
  589. const name = super.getPrivateNameSV(node);
  590. node = node;
  591. delete node.id;
  592. node.name = name;
  593. node.type = "PrivateIdentifier";
  594. return node;
  595. }
  596. isPrivateName(node) {
  597. {
  598. if (!this.getPluginOption("estree", "classFeatures")) {
  599. return super.isPrivateName(node);
  600. }
  601. }
  602. return node.type === "PrivateIdentifier";
  603. }
  604. getPrivateNameSV(node) {
  605. {
  606. if (!this.getPluginOption("estree", "classFeatures")) {
  607. return super.getPrivateNameSV(node);
  608. }
  609. }
  610. return node.name;
  611. }
  612. parseLiteral(value, type) {
  613. const node = super.parseLiteral(value, type);
  614. node.raw = node.extra.raw;
  615. delete node.extra;
  616. return node;
  617. }
  618. parseFunctionBody(node, allowExpression, isMethod = false) {
  619. super.parseFunctionBody(node, allowExpression, isMethod);
  620. node.expression = node.body.type !== "BlockStatement";
  621. }
  622. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  623. let funcNode = this.startNode();
  624. funcNode.kind = node.kind;
  625. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  626. funcNode.type = "FunctionExpression";
  627. delete funcNode.kind;
  628. node.value = funcNode;
  629. const {
  630. typeParameters
  631. } = node;
  632. if (typeParameters) {
  633. delete node.typeParameters;
  634. funcNode.typeParameters = typeParameters;
  635. this.resetStartLocationFromNode(funcNode, typeParameters);
  636. }
  637. if (type === "ClassPrivateMethod") {
  638. node.computed = false;
  639. }
  640. return this.finishNode(node, "MethodDefinition");
  641. }
  642. nameIsConstructor(key) {
  643. if (key.type === "Literal") return key.value === "constructor";
  644. return super.nameIsConstructor(key);
  645. }
  646. parseClassProperty(...args) {
  647. const propertyNode = super.parseClassProperty(...args);
  648. {
  649. if (!this.getPluginOption("estree", "classFeatures")) {
  650. return propertyNode;
  651. }
  652. }
  653. {
  654. propertyNode.type = "PropertyDefinition";
  655. }
  656. return propertyNode;
  657. }
  658. parseClassPrivateProperty(...args) {
  659. const propertyNode = super.parseClassPrivateProperty(...args);
  660. {
  661. if (!this.getPluginOption("estree", "classFeatures")) {
  662. return propertyNode;
  663. }
  664. }
  665. {
  666. propertyNode.type = "PropertyDefinition";
  667. }
  668. propertyNode.computed = false;
  669. return propertyNode;
  670. }
  671. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  672. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  673. if (node) {
  674. node.type = "Property";
  675. if (node.kind === "method") {
  676. node.kind = "init";
  677. }
  678. node.shorthand = false;
  679. }
  680. return node;
  681. }
  682. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  683. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  684. if (node) {
  685. node.kind = "init";
  686. node.type = "Property";
  687. }
  688. return node;
  689. }
  690. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  691. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  692. }
  693. isAssignable(node, isBinding) {
  694. if (node != null && this.isObjectProperty(node)) {
  695. return this.isAssignable(node.value, isBinding);
  696. }
  697. return super.isAssignable(node, isBinding);
  698. }
  699. toAssignable(node, isLHS = false) {
  700. if (node != null && this.isObjectProperty(node)) {
  701. const {
  702. key,
  703. value
  704. } = node;
  705. if (this.isPrivateName(key)) {
  706. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  707. }
  708. this.toAssignable(value, isLHS);
  709. } else {
  710. super.toAssignable(node, isLHS);
  711. }
  712. }
  713. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  714. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  715. this.raise(Errors.PatternHasAccessor, prop.key);
  716. } else if (prop.type === "Property" && prop.method) {
  717. this.raise(Errors.PatternHasMethod, prop.key);
  718. } else {
  719. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  720. }
  721. }
  722. finishCallExpression(unfinished, optional) {
  723. const node = super.finishCallExpression(unfinished, optional);
  724. if (node.callee.type === "Import") {
  725. var _ref, _ref2;
  726. node.type = "ImportExpression";
  727. node.source = node.arguments[0];
  728. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  729. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  730. delete node.arguments;
  731. delete node.callee;
  732. }
  733. return node;
  734. }
  735. toReferencedArguments(node) {
  736. if (node.type === "ImportExpression") {
  737. return;
  738. }
  739. super.toReferencedArguments(node);
  740. }
  741. parseExport(unfinished, decorators) {
  742. const exportStartLoc = this.state.lastTokStartLoc;
  743. const node = super.parseExport(unfinished, decorators);
  744. switch (node.type) {
  745. case "ExportAllDeclaration":
  746. node.exported = null;
  747. break;
  748. case "ExportNamedDeclaration":
  749. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  750. node.type = "ExportAllDeclaration";
  751. node.exported = node.specifiers[0].exported;
  752. delete node.specifiers;
  753. }
  754. case "ExportDefaultDeclaration":
  755. {
  756. var _declaration$decorato;
  757. const {
  758. declaration
  759. } = node;
  760. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  761. this.resetStartLocation(node, exportStartLoc);
  762. }
  763. }
  764. break;
  765. }
  766. return node;
  767. }
  768. parseSubscript(base, startLoc, noCalls, state) {
  769. const node = super.parseSubscript(base, startLoc, noCalls, state);
  770. if (state.optionalChainMember) {
  771. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  772. node.type = node.type.substring(8);
  773. }
  774. if (state.stop) {
  775. const chain = this.startNodeAtNode(node);
  776. chain.expression = node;
  777. return this.finishNode(chain, "ChainExpression");
  778. }
  779. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  780. node.optional = false;
  781. }
  782. return node;
  783. }
  784. isOptionalMemberExpression(node) {
  785. if (node.type === "ChainExpression") {
  786. return node.expression.type === "MemberExpression";
  787. }
  788. return super.isOptionalMemberExpression(node);
  789. }
  790. hasPropertyAsPrivateName(node) {
  791. if (node.type === "ChainExpression") {
  792. node = node.expression;
  793. }
  794. return super.hasPropertyAsPrivateName(node);
  795. }
  796. isObjectProperty(node) {
  797. return node.type === "Property" && node.kind === "init" && !node.method;
  798. }
  799. isObjectMethod(node) {
  800. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  801. }
  802. finishNodeAt(node, type, endLoc) {
  803. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  804. }
  805. resetStartLocation(node, startLoc) {
  806. super.resetStartLocation(node, startLoc);
  807. toESTreeLocation(node);
  808. }
  809. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  810. super.resetEndLocation(node, endLoc);
  811. toESTreeLocation(node);
  812. }
  813. };
  814. class TokContext {
  815. constructor(token, preserveSpace) {
  816. this.token = void 0;
  817. this.preserveSpace = void 0;
  818. this.token = token;
  819. this.preserveSpace = !!preserveSpace;
  820. }
  821. }
  822. const types = {
  823. brace: new TokContext("{"),
  824. j_oTag: new TokContext("<tag"),
  825. j_cTag: new TokContext("</tag"),
  826. j_expr: new TokContext("<tag>...</tag>", true)
  827. };
  828. {
  829. types.template = new TokContext("`", true);
  830. }
  831. const beforeExpr = true;
  832. const startsExpr = true;
  833. const isLoop = true;
  834. const isAssign = true;
  835. const prefix = true;
  836. const postfix = true;
  837. class ExportedTokenType {
  838. constructor(label, conf = {}) {
  839. this.label = void 0;
  840. this.keyword = void 0;
  841. this.beforeExpr = void 0;
  842. this.startsExpr = void 0;
  843. this.rightAssociative = void 0;
  844. this.isLoop = void 0;
  845. this.isAssign = void 0;
  846. this.prefix = void 0;
  847. this.postfix = void 0;
  848. this.binop = void 0;
  849. this.label = label;
  850. this.keyword = conf.keyword;
  851. this.beforeExpr = !!conf.beforeExpr;
  852. this.startsExpr = !!conf.startsExpr;
  853. this.rightAssociative = !!conf.rightAssociative;
  854. this.isLoop = !!conf.isLoop;
  855. this.isAssign = !!conf.isAssign;
  856. this.prefix = !!conf.prefix;
  857. this.postfix = !!conf.postfix;
  858. this.binop = conf.binop != null ? conf.binop : null;
  859. {
  860. this.updateContext = null;
  861. }
  862. }
  863. }
  864. const keywords$1 = new Map();
  865. function createKeyword(name, options = {}) {
  866. options.keyword = name;
  867. const token = createToken(name, options);
  868. keywords$1.set(name, token);
  869. return token;
  870. }
  871. function createBinop(name, binop) {
  872. return createToken(name, {
  873. beforeExpr,
  874. binop
  875. });
  876. }
  877. let tokenTypeCounter = -1;
  878. const tokenTypes = [];
  879. const tokenLabels = [];
  880. const tokenBinops = [];
  881. const tokenBeforeExprs = [];
  882. const tokenStartsExprs = [];
  883. const tokenPrefixes = [];
  884. function createToken(name, options = {}) {
  885. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  886. ++tokenTypeCounter;
  887. tokenLabels.push(name);
  888. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  889. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  890. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  891. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  892. tokenTypes.push(new ExportedTokenType(name, options));
  893. return tokenTypeCounter;
  894. }
  895. function createKeywordLike(name, options = {}) {
  896. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  897. ++tokenTypeCounter;
  898. keywords$1.set(name, tokenTypeCounter);
  899. tokenLabels.push(name);
  900. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  901. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  902. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  903. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  904. tokenTypes.push(new ExportedTokenType("name", options));
  905. return tokenTypeCounter;
  906. }
  907. const tt = {
  908. bracketL: createToken("[", {
  909. beforeExpr,
  910. startsExpr
  911. }),
  912. bracketHashL: createToken("#[", {
  913. beforeExpr,
  914. startsExpr
  915. }),
  916. bracketBarL: createToken("[|", {
  917. beforeExpr,
  918. startsExpr
  919. }),
  920. bracketR: createToken("]"),
  921. bracketBarR: createToken("|]"),
  922. braceL: createToken("{", {
  923. beforeExpr,
  924. startsExpr
  925. }),
  926. braceBarL: createToken("{|", {
  927. beforeExpr,
  928. startsExpr
  929. }),
  930. braceHashL: createToken("#{", {
  931. beforeExpr,
  932. startsExpr
  933. }),
  934. braceR: createToken("}"),
  935. braceBarR: createToken("|}"),
  936. parenL: createToken("(", {
  937. beforeExpr,
  938. startsExpr
  939. }),
  940. parenR: createToken(")"),
  941. comma: createToken(",", {
  942. beforeExpr
  943. }),
  944. semi: createToken(";", {
  945. beforeExpr
  946. }),
  947. colon: createToken(":", {
  948. beforeExpr
  949. }),
  950. doubleColon: createToken("::", {
  951. beforeExpr
  952. }),
  953. dot: createToken("."),
  954. question: createToken("?", {
  955. beforeExpr
  956. }),
  957. questionDot: createToken("?."),
  958. arrow: createToken("=>", {
  959. beforeExpr
  960. }),
  961. template: createToken("template"),
  962. ellipsis: createToken("...", {
  963. beforeExpr
  964. }),
  965. backQuote: createToken("`", {
  966. startsExpr
  967. }),
  968. dollarBraceL: createToken("${", {
  969. beforeExpr,
  970. startsExpr
  971. }),
  972. templateTail: createToken("...`", {
  973. startsExpr
  974. }),
  975. templateNonTail: createToken("...${", {
  976. beforeExpr,
  977. startsExpr
  978. }),
  979. at: createToken("@"),
  980. hash: createToken("#", {
  981. startsExpr
  982. }),
  983. interpreterDirective: createToken("#!..."),
  984. eq: createToken("=", {
  985. beforeExpr,
  986. isAssign
  987. }),
  988. assign: createToken("_=", {
  989. beforeExpr,
  990. isAssign
  991. }),
  992. slashAssign: createToken("_=", {
  993. beforeExpr,
  994. isAssign
  995. }),
  996. xorAssign: createToken("_=", {
  997. beforeExpr,
  998. isAssign
  999. }),
  1000. moduloAssign: createToken("_=", {
  1001. beforeExpr,
  1002. isAssign
  1003. }),
  1004. incDec: createToken("++/--", {
  1005. prefix,
  1006. postfix,
  1007. startsExpr
  1008. }),
  1009. bang: createToken("!", {
  1010. beforeExpr,
  1011. prefix,
  1012. startsExpr
  1013. }),
  1014. tilde: createToken("~", {
  1015. beforeExpr,
  1016. prefix,
  1017. startsExpr
  1018. }),
  1019. doubleCaret: createToken("^^", {
  1020. startsExpr
  1021. }),
  1022. doubleAt: createToken("@@", {
  1023. startsExpr
  1024. }),
  1025. pipeline: createBinop("|>", 0),
  1026. nullishCoalescing: createBinop("??", 1),
  1027. logicalOR: createBinop("||", 1),
  1028. logicalAND: createBinop("&&", 2),
  1029. bitwiseOR: createBinop("|", 3),
  1030. bitwiseXOR: createBinop("^", 4),
  1031. bitwiseAND: createBinop("&", 5),
  1032. equality: createBinop("==/!=/===/!==", 6),
  1033. lt: createBinop("</>/<=/>=", 7),
  1034. gt: createBinop("</>/<=/>=", 7),
  1035. relational: createBinop("</>/<=/>=", 7),
  1036. bitShift: createBinop("<</>>/>>>", 8),
  1037. bitShiftL: createBinop("<</>>/>>>", 8),
  1038. bitShiftR: createBinop("<</>>/>>>", 8),
  1039. plusMin: createToken("+/-", {
  1040. beforeExpr,
  1041. binop: 9,
  1042. prefix,
  1043. startsExpr
  1044. }),
  1045. modulo: createToken("%", {
  1046. binop: 10,
  1047. startsExpr
  1048. }),
  1049. star: createToken("*", {
  1050. binop: 10
  1051. }),
  1052. slash: createBinop("/", 10),
  1053. exponent: createToken("**", {
  1054. beforeExpr,
  1055. binop: 11,
  1056. rightAssociative: true
  1057. }),
  1058. _in: createKeyword("in", {
  1059. beforeExpr,
  1060. binop: 7
  1061. }),
  1062. _instanceof: createKeyword("instanceof", {
  1063. beforeExpr,
  1064. binop: 7
  1065. }),
  1066. _break: createKeyword("break"),
  1067. _case: createKeyword("case", {
  1068. beforeExpr
  1069. }),
  1070. _catch: createKeyword("catch"),
  1071. _continue: createKeyword("continue"),
  1072. _debugger: createKeyword("debugger"),
  1073. _default: createKeyword("default", {
  1074. beforeExpr
  1075. }),
  1076. _else: createKeyword("else", {
  1077. beforeExpr
  1078. }),
  1079. _finally: createKeyword("finally"),
  1080. _function: createKeyword("function", {
  1081. startsExpr
  1082. }),
  1083. _if: createKeyword("if"),
  1084. _return: createKeyword("return", {
  1085. beforeExpr
  1086. }),
  1087. _switch: createKeyword("switch"),
  1088. _throw: createKeyword("throw", {
  1089. beforeExpr,
  1090. prefix,
  1091. startsExpr
  1092. }),
  1093. _try: createKeyword("try"),
  1094. _var: createKeyword("var"),
  1095. _const: createKeyword("const"),
  1096. _with: createKeyword("with"),
  1097. _new: createKeyword("new", {
  1098. beforeExpr,
  1099. startsExpr
  1100. }),
  1101. _this: createKeyword("this", {
  1102. startsExpr
  1103. }),
  1104. _super: createKeyword("super", {
  1105. startsExpr
  1106. }),
  1107. _class: createKeyword("class", {
  1108. startsExpr
  1109. }),
  1110. _extends: createKeyword("extends", {
  1111. beforeExpr
  1112. }),
  1113. _export: createKeyword("export"),
  1114. _import: createKeyword("import", {
  1115. startsExpr
  1116. }),
  1117. _null: createKeyword("null", {
  1118. startsExpr
  1119. }),
  1120. _true: createKeyword("true", {
  1121. startsExpr
  1122. }),
  1123. _false: createKeyword("false", {
  1124. startsExpr
  1125. }),
  1126. _typeof: createKeyword("typeof", {
  1127. beforeExpr,
  1128. prefix,
  1129. startsExpr
  1130. }),
  1131. _void: createKeyword("void", {
  1132. beforeExpr,
  1133. prefix,
  1134. startsExpr
  1135. }),
  1136. _delete: createKeyword("delete", {
  1137. beforeExpr,
  1138. prefix,
  1139. startsExpr
  1140. }),
  1141. _do: createKeyword("do", {
  1142. isLoop,
  1143. beforeExpr
  1144. }),
  1145. _for: createKeyword("for", {
  1146. isLoop
  1147. }),
  1148. _while: createKeyword("while", {
  1149. isLoop
  1150. }),
  1151. _as: createKeywordLike("as", {
  1152. startsExpr
  1153. }),
  1154. _assert: createKeywordLike("assert", {
  1155. startsExpr
  1156. }),
  1157. _async: createKeywordLike("async", {
  1158. startsExpr
  1159. }),
  1160. _await: createKeywordLike("await", {
  1161. startsExpr
  1162. }),
  1163. _defer: createKeywordLike("defer", {
  1164. startsExpr
  1165. }),
  1166. _from: createKeywordLike("from", {
  1167. startsExpr
  1168. }),
  1169. _get: createKeywordLike("get", {
  1170. startsExpr
  1171. }),
  1172. _let: createKeywordLike("let", {
  1173. startsExpr
  1174. }),
  1175. _meta: createKeywordLike("meta", {
  1176. startsExpr
  1177. }),
  1178. _of: createKeywordLike("of", {
  1179. startsExpr
  1180. }),
  1181. _sent: createKeywordLike("sent", {
  1182. startsExpr
  1183. }),
  1184. _set: createKeywordLike("set", {
  1185. startsExpr
  1186. }),
  1187. _source: createKeywordLike("source", {
  1188. startsExpr
  1189. }),
  1190. _static: createKeywordLike("static", {
  1191. startsExpr
  1192. }),
  1193. _using: createKeywordLike("using", {
  1194. startsExpr
  1195. }),
  1196. _yield: createKeywordLike("yield", {
  1197. startsExpr
  1198. }),
  1199. _asserts: createKeywordLike("asserts", {
  1200. startsExpr
  1201. }),
  1202. _checks: createKeywordLike("checks", {
  1203. startsExpr
  1204. }),
  1205. _exports: createKeywordLike("exports", {
  1206. startsExpr
  1207. }),
  1208. _global: createKeywordLike("global", {
  1209. startsExpr
  1210. }),
  1211. _implements: createKeywordLike("implements", {
  1212. startsExpr
  1213. }),
  1214. _intrinsic: createKeywordLike("intrinsic", {
  1215. startsExpr
  1216. }),
  1217. _infer: createKeywordLike("infer", {
  1218. startsExpr
  1219. }),
  1220. _is: createKeywordLike("is", {
  1221. startsExpr
  1222. }),
  1223. _mixins: createKeywordLike("mixins", {
  1224. startsExpr
  1225. }),
  1226. _proto: createKeywordLike("proto", {
  1227. startsExpr
  1228. }),
  1229. _require: createKeywordLike("require", {
  1230. startsExpr
  1231. }),
  1232. _satisfies: createKeywordLike("satisfies", {
  1233. startsExpr
  1234. }),
  1235. _keyof: createKeywordLike("keyof", {
  1236. startsExpr
  1237. }),
  1238. _readonly: createKeywordLike("readonly", {
  1239. startsExpr
  1240. }),
  1241. _unique: createKeywordLike("unique", {
  1242. startsExpr
  1243. }),
  1244. _abstract: createKeywordLike("abstract", {
  1245. startsExpr
  1246. }),
  1247. _declare: createKeywordLike("declare", {
  1248. startsExpr
  1249. }),
  1250. _enum: createKeywordLike("enum", {
  1251. startsExpr
  1252. }),
  1253. _module: createKeywordLike("module", {
  1254. startsExpr
  1255. }),
  1256. _namespace: createKeywordLike("namespace", {
  1257. startsExpr
  1258. }),
  1259. _interface: createKeywordLike("interface", {
  1260. startsExpr
  1261. }),
  1262. _type: createKeywordLike("type", {
  1263. startsExpr
  1264. }),
  1265. _opaque: createKeywordLike("opaque", {
  1266. startsExpr
  1267. }),
  1268. name: createToken("name", {
  1269. startsExpr
  1270. }),
  1271. placeholder: createToken("%%", {
  1272. startsExpr: true
  1273. }),
  1274. string: createToken("string", {
  1275. startsExpr
  1276. }),
  1277. num: createToken("num", {
  1278. startsExpr
  1279. }),
  1280. bigint: createToken("bigint", {
  1281. startsExpr
  1282. }),
  1283. decimal: createToken("decimal", {
  1284. startsExpr
  1285. }),
  1286. regexp: createToken("regexp", {
  1287. startsExpr
  1288. }),
  1289. privateName: createToken("#name", {
  1290. startsExpr
  1291. }),
  1292. eof: createToken("eof"),
  1293. jsxName: createToken("jsxName"),
  1294. jsxText: createToken("jsxText", {
  1295. beforeExpr: true
  1296. }),
  1297. jsxTagStart: createToken("jsxTagStart", {
  1298. startsExpr: true
  1299. }),
  1300. jsxTagEnd: createToken("jsxTagEnd")
  1301. };
  1302. function tokenIsIdentifier(token) {
  1303. return token >= 93 && token <= 133;
  1304. }
  1305. function tokenKeywordOrIdentifierIsKeyword(token) {
  1306. return token <= 92;
  1307. }
  1308. function tokenIsKeywordOrIdentifier(token) {
  1309. return token >= 58 && token <= 133;
  1310. }
  1311. function tokenIsLiteralPropertyName(token) {
  1312. return token >= 58 && token <= 137;
  1313. }
  1314. function tokenComesBeforeExpression(token) {
  1315. return tokenBeforeExprs[token];
  1316. }
  1317. function tokenCanStartExpression(token) {
  1318. return tokenStartsExprs[token];
  1319. }
  1320. function tokenIsAssignment(token) {
  1321. return token >= 29 && token <= 33;
  1322. }
  1323. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1324. return token >= 129 && token <= 131;
  1325. }
  1326. function tokenIsLoop(token) {
  1327. return token >= 90 && token <= 92;
  1328. }
  1329. function tokenIsKeyword(token) {
  1330. return token >= 58 && token <= 92;
  1331. }
  1332. function tokenIsOperator(token) {
  1333. return token >= 39 && token <= 59;
  1334. }
  1335. function tokenIsPostfix(token) {
  1336. return token === 34;
  1337. }
  1338. function tokenIsPrefix(token) {
  1339. return tokenPrefixes[token];
  1340. }
  1341. function tokenIsTSTypeOperator(token) {
  1342. return token >= 121 && token <= 123;
  1343. }
  1344. function tokenIsTSDeclarationStart(token) {
  1345. return token >= 124 && token <= 130;
  1346. }
  1347. function tokenLabelName(token) {
  1348. return tokenLabels[token];
  1349. }
  1350. function tokenOperatorPrecedence(token) {
  1351. return tokenBinops[token];
  1352. }
  1353. function tokenIsRightAssociative(token) {
  1354. return token === 57;
  1355. }
  1356. function tokenIsTemplate(token) {
  1357. return token >= 24 && token <= 25;
  1358. }
  1359. function getExportedToken(token) {
  1360. return tokenTypes[token];
  1361. }
  1362. {
  1363. tokenTypes[8].updateContext = context => {
  1364. context.pop();
  1365. };
  1366. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1367. context.push(types.brace);
  1368. };
  1369. tokenTypes[22].updateContext = context => {
  1370. if (context[context.length - 1] === types.template) {
  1371. context.pop();
  1372. } else {
  1373. context.push(types.template);
  1374. }
  1375. };
  1376. tokenTypes[143].updateContext = context => {
  1377. context.push(types.j_expr, types.j_oTag);
  1378. };
  1379. }
  1380. 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-\u088e\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7cd\ua7d0\ua7d1\ua7d3\ua7d5-\ua7dc\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  1381. 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-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
  1382. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1383. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1384. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1385. 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, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
  1386. 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, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1387. function isInAstralSet(code, set) {
  1388. let pos = 0x10000;
  1389. for (let i = 0, length = set.length; i < length; i += 2) {
  1390. pos += set[i];
  1391. if (pos > code) return false;
  1392. pos += set[i + 1];
  1393. if (pos >= code) return true;
  1394. }
  1395. return false;
  1396. }
  1397. function isIdentifierStart(code) {
  1398. if (code < 65) return code === 36;
  1399. if (code <= 90) return true;
  1400. if (code < 97) return code === 95;
  1401. if (code <= 122) return true;
  1402. if (code <= 0xffff) {
  1403. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1404. }
  1405. return isInAstralSet(code, astralIdentifierStartCodes);
  1406. }
  1407. function isIdentifierChar(code) {
  1408. if (code < 48) return code === 36;
  1409. if (code < 58) return true;
  1410. if (code < 65) return false;
  1411. if (code <= 90) return true;
  1412. if (code < 97) return code === 95;
  1413. if (code <= 122) return true;
  1414. if (code <= 0xffff) {
  1415. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1416. }
  1417. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1418. }
  1419. const reservedWords = {
  1420. 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"],
  1421. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1422. strictBind: ["eval", "arguments"]
  1423. };
  1424. const keywords = new Set(reservedWords.keyword);
  1425. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1426. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1427. function isReservedWord(word, inModule) {
  1428. return inModule && word === "await" || word === "enum";
  1429. }
  1430. function isStrictReservedWord(word, inModule) {
  1431. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1432. }
  1433. function isStrictBindOnlyReservedWord(word) {
  1434. return reservedWordsStrictBindSet.has(word);
  1435. }
  1436. function isStrictBindReservedWord(word, inModule) {
  1437. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1438. }
  1439. function isKeyword(word) {
  1440. return keywords.has(word);
  1441. }
  1442. function isIteratorStart(current, next, next2) {
  1443. return current === 64 && next === 64 && isIdentifierStart(next2);
  1444. }
  1445. 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"]);
  1446. function canBeReservedWord(word) {
  1447. return reservedWordLikeSet.has(word);
  1448. }
  1449. class Scope {
  1450. constructor(flags) {
  1451. this.flags = 0;
  1452. this.names = new Map();
  1453. this.firstLexicalName = "";
  1454. this.flags = flags;
  1455. }
  1456. }
  1457. class ScopeHandler {
  1458. constructor(parser, inModule) {
  1459. this.parser = void 0;
  1460. this.scopeStack = [];
  1461. this.inModule = void 0;
  1462. this.undefinedExports = new Map();
  1463. this.parser = parser;
  1464. this.inModule = inModule;
  1465. }
  1466. get inTopLevel() {
  1467. return (this.currentScope().flags & 1) > 0;
  1468. }
  1469. get inFunction() {
  1470. return (this.currentVarScopeFlags() & 2) > 0;
  1471. }
  1472. get allowSuper() {
  1473. return (this.currentThisScopeFlags() & 16) > 0;
  1474. }
  1475. get allowDirectSuper() {
  1476. return (this.currentThisScopeFlags() & 32) > 0;
  1477. }
  1478. get inClass() {
  1479. return (this.currentThisScopeFlags() & 64) > 0;
  1480. }
  1481. get inClassAndNotInNonArrowFunction() {
  1482. const flags = this.currentThisScopeFlags();
  1483. return (flags & 64) > 0 && (flags & 2) === 0;
  1484. }
  1485. get inStaticBlock() {
  1486. for (let i = this.scopeStack.length - 1;; i--) {
  1487. const {
  1488. flags
  1489. } = this.scopeStack[i];
  1490. if (flags & 128) {
  1491. return true;
  1492. }
  1493. if (flags & (387 | 64)) {
  1494. return false;
  1495. }
  1496. }
  1497. }
  1498. get inNonArrowFunction() {
  1499. return (this.currentThisScopeFlags() & 2) > 0;
  1500. }
  1501. get treatFunctionsAsVar() {
  1502. return this.treatFunctionsAsVarInScope(this.currentScope());
  1503. }
  1504. createScope(flags) {
  1505. return new Scope(flags);
  1506. }
  1507. enter(flags) {
  1508. this.scopeStack.push(this.createScope(flags));
  1509. }
  1510. exit() {
  1511. const scope = this.scopeStack.pop();
  1512. return scope.flags;
  1513. }
  1514. treatFunctionsAsVarInScope(scope) {
  1515. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1516. }
  1517. declareName(name, bindingType, loc) {
  1518. let scope = this.currentScope();
  1519. if (bindingType & 8 || bindingType & 16) {
  1520. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1521. let type = scope.names.get(name) || 0;
  1522. if (bindingType & 16) {
  1523. type = type | 4;
  1524. } else {
  1525. if (!scope.firstLexicalName) {
  1526. scope.firstLexicalName = name;
  1527. }
  1528. type = type | 2;
  1529. }
  1530. scope.names.set(name, type);
  1531. if (bindingType & 8) {
  1532. this.maybeExportDefined(scope, name);
  1533. }
  1534. } else if (bindingType & 4) {
  1535. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1536. scope = this.scopeStack[i];
  1537. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1538. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1539. this.maybeExportDefined(scope, name);
  1540. if (scope.flags & 387) break;
  1541. }
  1542. }
  1543. if (this.parser.inModule && scope.flags & 1) {
  1544. this.undefinedExports.delete(name);
  1545. }
  1546. }
  1547. maybeExportDefined(scope, name) {
  1548. if (this.parser.inModule && scope.flags & 1) {
  1549. this.undefinedExports.delete(name);
  1550. }
  1551. }
  1552. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1553. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1554. this.parser.raise(Errors.VarRedeclaration, loc, {
  1555. identifierName: name
  1556. });
  1557. }
  1558. }
  1559. isRedeclaredInScope(scope, name, bindingType) {
  1560. if (!(bindingType & 1)) return false;
  1561. if (bindingType & 8) {
  1562. return scope.names.has(name);
  1563. }
  1564. const type = scope.names.get(name);
  1565. if (bindingType & 16) {
  1566. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1567. }
  1568. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1569. }
  1570. checkLocalExport(id) {
  1571. const {
  1572. name
  1573. } = id;
  1574. const topLevelScope = this.scopeStack[0];
  1575. if (!topLevelScope.names.has(name)) {
  1576. this.undefinedExports.set(name, id.loc.start);
  1577. }
  1578. }
  1579. currentScope() {
  1580. return this.scopeStack[this.scopeStack.length - 1];
  1581. }
  1582. currentVarScopeFlags() {
  1583. for (let i = this.scopeStack.length - 1;; i--) {
  1584. const {
  1585. flags
  1586. } = this.scopeStack[i];
  1587. if (flags & 387) {
  1588. return flags;
  1589. }
  1590. }
  1591. }
  1592. currentThisScopeFlags() {
  1593. for (let i = this.scopeStack.length - 1;; i--) {
  1594. const {
  1595. flags
  1596. } = this.scopeStack[i];
  1597. if (flags & (387 | 64) && !(flags & 4)) {
  1598. return flags;
  1599. }
  1600. }
  1601. }
  1602. }
  1603. class FlowScope extends Scope {
  1604. constructor(...args) {
  1605. super(...args);
  1606. this.declareFunctions = new Set();
  1607. }
  1608. }
  1609. class FlowScopeHandler extends ScopeHandler {
  1610. createScope(flags) {
  1611. return new FlowScope(flags);
  1612. }
  1613. declareName(name, bindingType, loc) {
  1614. const scope = this.currentScope();
  1615. if (bindingType & 2048) {
  1616. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1617. this.maybeExportDefined(scope, name);
  1618. scope.declareFunctions.add(name);
  1619. return;
  1620. }
  1621. super.declareName(name, bindingType, loc);
  1622. }
  1623. isRedeclaredInScope(scope, name, bindingType) {
  1624. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1625. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1626. const type = scope.names.get(name);
  1627. return (type & 4) > 0 || (type & 2) > 0;
  1628. }
  1629. return false;
  1630. }
  1631. checkLocalExport(id) {
  1632. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1633. super.checkLocalExport(id);
  1634. }
  1635. }
  1636. }
  1637. class BaseParser {
  1638. constructor() {
  1639. this.sawUnambiguousESM = false;
  1640. this.ambiguousScriptDifferentAst = false;
  1641. }
  1642. sourceToOffsetPos(sourcePos) {
  1643. return sourcePos + this.startIndex;
  1644. }
  1645. offsetToSourcePos(offsetPos) {
  1646. return offsetPos - this.startIndex;
  1647. }
  1648. hasPlugin(pluginConfig) {
  1649. if (typeof pluginConfig === "string") {
  1650. return this.plugins.has(pluginConfig);
  1651. } else {
  1652. const [pluginName, pluginOptions] = pluginConfig;
  1653. if (!this.hasPlugin(pluginName)) {
  1654. return false;
  1655. }
  1656. const actualOptions = this.plugins.get(pluginName);
  1657. for (const key of Object.keys(pluginOptions)) {
  1658. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1659. return false;
  1660. }
  1661. }
  1662. return true;
  1663. }
  1664. }
  1665. getPluginOption(plugin, name) {
  1666. var _this$plugins$get;
  1667. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1668. }
  1669. }
  1670. function setTrailingComments(node, comments) {
  1671. if (node.trailingComments === undefined) {
  1672. node.trailingComments = comments;
  1673. } else {
  1674. node.trailingComments.unshift(...comments);
  1675. }
  1676. }
  1677. function setLeadingComments(node, comments) {
  1678. if (node.leadingComments === undefined) {
  1679. node.leadingComments = comments;
  1680. } else {
  1681. node.leadingComments.unshift(...comments);
  1682. }
  1683. }
  1684. function setInnerComments(node, comments) {
  1685. if (node.innerComments === undefined) {
  1686. node.innerComments = comments;
  1687. } else {
  1688. node.innerComments.unshift(...comments);
  1689. }
  1690. }
  1691. function adjustInnerComments(node, elements, commentWS) {
  1692. let lastElement = null;
  1693. let i = elements.length;
  1694. while (lastElement === null && i > 0) {
  1695. lastElement = elements[--i];
  1696. }
  1697. if (lastElement === null || lastElement.start > commentWS.start) {
  1698. setInnerComments(node, commentWS.comments);
  1699. } else {
  1700. setTrailingComments(lastElement, commentWS.comments);
  1701. }
  1702. }
  1703. class CommentsParser extends BaseParser {
  1704. addComment(comment) {
  1705. if (this.filename) comment.loc.filename = this.filename;
  1706. const {
  1707. commentsLen
  1708. } = this.state;
  1709. if (this.comments.length !== commentsLen) {
  1710. this.comments.length = commentsLen;
  1711. }
  1712. this.comments.push(comment);
  1713. this.state.commentsLen++;
  1714. }
  1715. processComment(node) {
  1716. const {
  1717. commentStack
  1718. } = this.state;
  1719. const commentStackLength = commentStack.length;
  1720. if (commentStackLength === 0) return;
  1721. let i = commentStackLength - 1;
  1722. const lastCommentWS = commentStack[i];
  1723. if (lastCommentWS.start === node.end) {
  1724. lastCommentWS.leadingNode = node;
  1725. i--;
  1726. }
  1727. const {
  1728. start: nodeStart
  1729. } = node;
  1730. for (; i >= 0; i--) {
  1731. const commentWS = commentStack[i];
  1732. const commentEnd = commentWS.end;
  1733. if (commentEnd > nodeStart) {
  1734. commentWS.containingNode = node;
  1735. this.finalizeComment(commentWS);
  1736. commentStack.splice(i, 1);
  1737. } else {
  1738. if (commentEnd === nodeStart) {
  1739. commentWS.trailingNode = node;
  1740. }
  1741. break;
  1742. }
  1743. }
  1744. }
  1745. finalizeComment(commentWS) {
  1746. const {
  1747. comments
  1748. } = commentWS;
  1749. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1750. if (commentWS.leadingNode !== null) {
  1751. setTrailingComments(commentWS.leadingNode, comments);
  1752. }
  1753. if (commentWS.trailingNode !== null) {
  1754. setLeadingComments(commentWS.trailingNode, comments);
  1755. }
  1756. } else {
  1757. const {
  1758. containingNode: node,
  1759. start: commentStart
  1760. } = commentWS;
  1761. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  1762. switch (node.type) {
  1763. case "ObjectExpression":
  1764. case "ObjectPattern":
  1765. case "RecordExpression":
  1766. adjustInnerComments(node, node.properties, commentWS);
  1767. break;
  1768. case "CallExpression":
  1769. case "OptionalCallExpression":
  1770. adjustInnerComments(node, node.arguments, commentWS);
  1771. break;
  1772. case "FunctionDeclaration":
  1773. case "FunctionExpression":
  1774. case "ArrowFunctionExpression":
  1775. case "ObjectMethod":
  1776. case "ClassMethod":
  1777. case "ClassPrivateMethod":
  1778. adjustInnerComments(node, node.params, commentWS);
  1779. break;
  1780. case "ArrayExpression":
  1781. case "ArrayPattern":
  1782. case "TupleExpression":
  1783. adjustInnerComments(node, node.elements, commentWS);
  1784. break;
  1785. case "ExportNamedDeclaration":
  1786. case "ImportDeclaration":
  1787. adjustInnerComments(node, node.specifiers, commentWS);
  1788. break;
  1789. case "TSEnumDeclaration":
  1790. {
  1791. adjustInnerComments(node, node.members, commentWS);
  1792. }
  1793. break;
  1794. case "TSEnumBody":
  1795. adjustInnerComments(node, node.members, commentWS);
  1796. break;
  1797. default:
  1798. {
  1799. setInnerComments(node, comments);
  1800. }
  1801. }
  1802. } else {
  1803. setInnerComments(node, comments);
  1804. }
  1805. }
  1806. }
  1807. finalizeRemainingComments() {
  1808. const {
  1809. commentStack
  1810. } = this.state;
  1811. for (let i = commentStack.length - 1; i >= 0; i--) {
  1812. this.finalizeComment(commentStack[i]);
  1813. }
  1814. this.state.commentStack = [];
  1815. }
  1816. resetPreviousNodeTrailingComments(node) {
  1817. const {
  1818. commentStack
  1819. } = this.state;
  1820. const {
  1821. length
  1822. } = commentStack;
  1823. if (length === 0) return;
  1824. const commentWS = commentStack[length - 1];
  1825. if (commentWS.leadingNode === node) {
  1826. commentWS.leadingNode = null;
  1827. }
  1828. }
  1829. resetPreviousIdentifierLeadingComments(node) {
  1830. const {
  1831. commentStack
  1832. } = this.state;
  1833. const {
  1834. length
  1835. } = commentStack;
  1836. if (length === 0) return;
  1837. if (commentStack[length - 1].trailingNode === node) {
  1838. commentStack[length - 1].trailingNode = null;
  1839. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  1840. commentStack[length - 2].trailingNode = null;
  1841. }
  1842. }
  1843. takeSurroundingComments(node, start, end) {
  1844. const {
  1845. commentStack
  1846. } = this.state;
  1847. const commentStackLength = commentStack.length;
  1848. if (commentStackLength === 0) return;
  1849. let i = commentStackLength - 1;
  1850. for (; i >= 0; i--) {
  1851. const commentWS = commentStack[i];
  1852. const commentEnd = commentWS.end;
  1853. const commentStart = commentWS.start;
  1854. if (commentStart === end) {
  1855. commentWS.leadingNode = node;
  1856. } else if (commentEnd === start) {
  1857. commentWS.trailingNode = node;
  1858. } else if (commentEnd < start) {
  1859. break;
  1860. }
  1861. }
  1862. }
  1863. }
  1864. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  1865. const lineBreakG = new RegExp(lineBreak.source, "g");
  1866. function isNewLine(code) {
  1867. switch (code) {
  1868. case 10:
  1869. case 13:
  1870. case 8232:
  1871. case 8233:
  1872. return true;
  1873. default:
  1874. return false;
  1875. }
  1876. }
  1877. function hasNewLine(input, start, end) {
  1878. for (let i = start; i < end; i++) {
  1879. if (isNewLine(input.charCodeAt(i))) {
  1880. return true;
  1881. }
  1882. }
  1883. return false;
  1884. }
  1885. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1886. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1887. function isWhitespace(code) {
  1888. switch (code) {
  1889. case 0x0009:
  1890. case 0x000b:
  1891. case 0x000c:
  1892. case 32:
  1893. case 160:
  1894. case 5760:
  1895. case 0x2000:
  1896. case 0x2001:
  1897. case 0x2002:
  1898. case 0x2003:
  1899. case 0x2004:
  1900. case 0x2005:
  1901. case 0x2006:
  1902. case 0x2007:
  1903. case 0x2008:
  1904. case 0x2009:
  1905. case 0x200a:
  1906. case 0x202f:
  1907. case 0x205f:
  1908. case 0x3000:
  1909. case 0xfeff:
  1910. return true;
  1911. default:
  1912. return false;
  1913. }
  1914. }
  1915. class State {
  1916. constructor() {
  1917. this.flags = 1024;
  1918. this.startIndex = void 0;
  1919. this.curLine = void 0;
  1920. this.lineStart = void 0;
  1921. this.startLoc = void 0;
  1922. this.endLoc = void 0;
  1923. this.errors = [];
  1924. this.potentialArrowAt = -1;
  1925. this.noArrowAt = [];
  1926. this.noArrowParamsConversionAt = [];
  1927. this.topicContext = {
  1928. maxNumOfResolvableTopics: 0,
  1929. maxTopicIndex: null
  1930. };
  1931. this.labels = [];
  1932. this.commentsLen = 0;
  1933. this.commentStack = [];
  1934. this.pos = 0;
  1935. this.type = 140;
  1936. this.value = null;
  1937. this.start = 0;
  1938. this.end = 0;
  1939. this.lastTokEndLoc = null;
  1940. this.lastTokStartLoc = null;
  1941. this.context = [types.brace];
  1942. this.firstInvalidTemplateEscapePos = null;
  1943. this.strictErrors = new Map();
  1944. this.tokensLength = 0;
  1945. }
  1946. get strict() {
  1947. return (this.flags & 1) > 0;
  1948. }
  1949. set strict(v) {
  1950. if (v) this.flags |= 1;else this.flags &= -2;
  1951. }
  1952. init({
  1953. strictMode,
  1954. sourceType,
  1955. startIndex,
  1956. startLine,
  1957. startColumn
  1958. }) {
  1959. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1960. this.startIndex = startIndex;
  1961. this.curLine = startLine;
  1962. this.lineStart = -startColumn;
  1963. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  1964. }
  1965. get maybeInArrowParameters() {
  1966. return (this.flags & 2) > 0;
  1967. }
  1968. set maybeInArrowParameters(v) {
  1969. if (v) this.flags |= 2;else this.flags &= -3;
  1970. }
  1971. get inType() {
  1972. return (this.flags & 4) > 0;
  1973. }
  1974. set inType(v) {
  1975. if (v) this.flags |= 4;else this.flags &= -5;
  1976. }
  1977. get noAnonFunctionType() {
  1978. return (this.flags & 8) > 0;
  1979. }
  1980. set noAnonFunctionType(v) {
  1981. if (v) this.flags |= 8;else this.flags &= -9;
  1982. }
  1983. get hasFlowComment() {
  1984. return (this.flags & 16) > 0;
  1985. }
  1986. set hasFlowComment(v) {
  1987. if (v) this.flags |= 16;else this.flags &= -17;
  1988. }
  1989. get isAmbientContext() {
  1990. return (this.flags & 32) > 0;
  1991. }
  1992. set isAmbientContext(v) {
  1993. if (v) this.flags |= 32;else this.flags &= -33;
  1994. }
  1995. get inAbstractClass() {
  1996. return (this.flags & 64) > 0;
  1997. }
  1998. set inAbstractClass(v) {
  1999. if (v) this.flags |= 64;else this.flags &= -65;
  2000. }
  2001. get inDisallowConditionalTypesContext() {
  2002. return (this.flags & 128) > 0;
  2003. }
  2004. set inDisallowConditionalTypesContext(v) {
  2005. if (v) this.flags |= 128;else this.flags &= -129;
  2006. }
  2007. get soloAwait() {
  2008. return (this.flags & 256) > 0;
  2009. }
  2010. set soloAwait(v) {
  2011. if (v) this.flags |= 256;else this.flags &= -257;
  2012. }
  2013. get inFSharpPipelineDirectBody() {
  2014. return (this.flags & 512) > 0;
  2015. }
  2016. set inFSharpPipelineDirectBody(v) {
  2017. if (v) this.flags |= 512;else this.flags &= -513;
  2018. }
  2019. get canStartJSXElement() {
  2020. return (this.flags & 1024) > 0;
  2021. }
  2022. set canStartJSXElement(v) {
  2023. if (v) this.flags |= 1024;else this.flags &= -1025;
  2024. }
  2025. get containsEsc() {
  2026. return (this.flags & 2048) > 0;
  2027. }
  2028. set containsEsc(v) {
  2029. if (v) this.flags |= 2048;else this.flags &= -2049;
  2030. }
  2031. get hasTopLevelAwait() {
  2032. return (this.flags & 4096) > 0;
  2033. }
  2034. set hasTopLevelAwait(v) {
  2035. if (v) this.flags |= 4096;else this.flags &= -4097;
  2036. }
  2037. curPosition() {
  2038. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  2039. }
  2040. clone() {
  2041. const state = new State();
  2042. state.flags = this.flags;
  2043. state.startIndex = this.startIndex;
  2044. state.curLine = this.curLine;
  2045. state.lineStart = this.lineStart;
  2046. state.startLoc = this.startLoc;
  2047. state.endLoc = this.endLoc;
  2048. state.errors = this.errors.slice();
  2049. state.potentialArrowAt = this.potentialArrowAt;
  2050. state.noArrowAt = this.noArrowAt.slice();
  2051. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  2052. state.topicContext = this.topicContext;
  2053. state.labels = this.labels.slice();
  2054. state.commentsLen = this.commentsLen;
  2055. state.commentStack = this.commentStack.slice();
  2056. state.pos = this.pos;
  2057. state.type = this.type;
  2058. state.value = this.value;
  2059. state.start = this.start;
  2060. state.end = this.end;
  2061. state.lastTokEndLoc = this.lastTokEndLoc;
  2062. state.lastTokStartLoc = this.lastTokStartLoc;
  2063. state.context = this.context.slice();
  2064. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  2065. state.strictErrors = this.strictErrors;
  2066. state.tokensLength = this.tokensLength;
  2067. return state;
  2068. }
  2069. }
  2070. var _isDigit = function isDigit(code) {
  2071. return code >= 48 && code <= 57;
  2072. };
  2073. const forbiddenNumericSeparatorSiblings = {
  2074. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  2075. hex: new Set([46, 88, 95, 120])
  2076. };
  2077. const isAllowedNumericSeparatorSibling = {
  2078. bin: ch => ch === 48 || ch === 49,
  2079. oct: ch => ch >= 48 && ch <= 55,
  2080. dec: ch => ch >= 48 && ch <= 57,
  2081. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  2082. };
  2083. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  2084. const initialPos = pos;
  2085. const initialLineStart = lineStart;
  2086. const initialCurLine = curLine;
  2087. let out = "";
  2088. let firstInvalidLoc = null;
  2089. let chunkStart = pos;
  2090. const {
  2091. length
  2092. } = input;
  2093. for (;;) {
  2094. if (pos >= length) {
  2095. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2096. out += input.slice(chunkStart, pos);
  2097. break;
  2098. }
  2099. const ch = input.charCodeAt(pos);
  2100. if (isStringEnd(type, ch, input, pos)) {
  2101. out += input.slice(chunkStart, pos);
  2102. break;
  2103. }
  2104. if (ch === 92) {
  2105. out += input.slice(chunkStart, pos);
  2106. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  2107. if (res.ch === null && !firstInvalidLoc) {
  2108. firstInvalidLoc = {
  2109. pos,
  2110. lineStart,
  2111. curLine
  2112. };
  2113. } else {
  2114. out += res.ch;
  2115. }
  2116. ({
  2117. pos,
  2118. lineStart,
  2119. curLine
  2120. } = res);
  2121. chunkStart = pos;
  2122. } else if (ch === 8232 || ch === 8233) {
  2123. ++pos;
  2124. ++curLine;
  2125. lineStart = pos;
  2126. } else if (ch === 10 || ch === 13) {
  2127. if (type === "template") {
  2128. out += input.slice(chunkStart, pos) + "\n";
  2129. ++pos;
  2130. if (ch === 13 && input.charCodeAt(pos) === 10) {
  2131. ++pos;
  2132. }
  2133. ++curLine;
  2134. chunkStart = lineStart = pos;
  2135. } else {
  2136. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2137. }
  2138. } else {
  2139. ++pos;
  2140. }
  2141. }
  2142. return {
  2143. pos,
  2144. str: out,
  2145. firstInvalidLoc,
  2146. lineStart,
  2147. curLine,
  2148. containsInvalid: !!firstInvalidLoc
  2149. };
  2150. }
  2151. function isStringEnd(type, ch, input, pos) {
  2152. if (type === "template") {
  2153. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2154. }
  2155. return ch === (type === "double" ? 34 : 39);
  2156. }
  2157. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2158. const throwOnInvalid = !inTemplate;
  2159. pos++;
  2160. const res = ch => ({
  2161. pos,
  2162. ch,
  2163. lineStart,
  2164. curLine
  2165. });
  2166. const ch = input.charCodeAt(pos++);
  2167. switch (ch) {
  2168. case 110:
  2169. return res("\n");
  2170. case 114:
  2171. return res("\r");
  2172. case 120:
  2173. {
  2174. let code;
  2175. ({
  2176. code,
  2177. pos
  2178. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2179. return res(code === null ? null : String.fromCharCode(code));
  2180. }
  2181. case 117:
  2182. {
  2183. let code;
  2184. ({
  2185. code,
  2186. pos
  2187. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2188. return res(code === null ? null : String.fromCodePoint(code));
  2189. }
  2190. case 116:
  2191. return res("\t");
  2192. case 98:
  2193. return res("\b");
  2194. case 118:
  2195. return res("\u000b");
  2196. case 102:
  2197. return res("\f");
  2198. case 13:
  2199. if (input.charCodeAt(pos) === 10) {
  2200. ++pos;
  2201. }
  2202. case 10:
  2203. lineStart = pos;
  2204. ++curLine;
  2205. case 8232:
  2206. case 8233:
  2207. return res("");
  2208. case 56:
  2209. case 57:
  2210. if (inTemplate) {
  2211. return res(null);
  2212. } else {
  2213. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2214. }
  2215. default:
  2216. if (ch >= 48 && ch <= 55) {
  2217. const startPos = pos - 1;
  2218. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  2219. let octalStr = match[0];
  2220. let octal = parseInt(octalStr, 8);
  2221. if (octal > 255) {
  2222. octalStr = octalStr.slice(0, -1);
  2223. octal = parseInt(octalStr, 8);
  2224. }
  2225. pos += octalStr.length - 1;
  2226. const next = input.charCodeAt(pos);
  2227. if (octalStr !== "0" || next === 56 || next === 57) {
  2228. if (inTemplate) {
  2229. return res(null);
  2230. } else {
  2231. errors.strictNumericEscape(startPos, lineStart, curLine);
  2232. }
  2233. }
  2234. return res(String.fromCharCode(octal));
  2235. }
  2236. return res(String.fromCharCode(ch));
  2237. }
  2238. }
  2239. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2240. const initialPos = pos;
  2241. let n;
  2242. ({
  2243. n,
  2244. pos
  2245. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2246. if (n === null) {
  2247. if (throwOnInvalid) {
  2248. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2249. } else {
  2250. pos = initialPos - 1;
  2251. }
  2252. }
  2253. return {
  2254. code: n,
  2255. pos
  2256. };
  2257. }
  2258. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2259. const start = pos;
  2260. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2261. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2262. let invalid = false;
  2263. let total = 0;
  2264. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2265. const code = input.charCodeAt(pos);
  2266. let val;
  2267. if (code === 95 && allowNumSeparator !== "bail") {
  2268. const prev = input.charCodeAt(pos - 1);
  2269. const next = input.charCodeAt(pos + 1);
  2270. if (!allowNumSeparator) {
  2271. if (bailOnError) return {
  2272. n: null,
  2273. pos
  2274. };
  2275. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2276. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2277. if (bailOnError) return {
  2278. n: null,
  2279. pos
  2280. };
  2281. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2282. }
  2283. ++pos;
  2284. continue;
  2285. }
  2286. if (code >= 97) {
  2287. val = code - 97 + 10;
  2288. } else if (code >= 65) {
  2289. val = code - 65 + 10;
  2290. } else if (_isDigit(code)) {
  2291. val = code - 48;
  2292. } else {
  2293. val = Infinity;
  2294. }
  2295. if (val >= radix) {
  2296. if (val <= 9 && bailOnError) {
  2297. return {
  2298. n: null,
  2299. pos
  2300. };
  2301. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2302. val = 0;
  2303. } else if (forceLen) {
  2304. val = 0;
  2305. invalid = true;
  2306. } else {
  2307. break;
  2308. }
  2309. }
  2310. ++pos;
  2311. total = total * radix + val;
  2312. }
  2313. if (pos === start || len != null && pos - start !== len || invalid) {
  2314. return {
  2315. n: null,
  2316. pos
  2317. };
  2318. }
  2319. return {
  2320. n: total,
  2321. pos
  2322. };
  2323. }
  2324. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2325. const ch = input.charCodeAt(pos);
  2326. let code;
  2327. if (ch === 123) {
  2328. ++pos;
  2329. ({
  2330. code,
  2331. pos
  2332. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2333. ++pos;
  2334. if (code !== null && code > 0x10ffff) {
  2335. if (throwOnInvalid) {
  2336. errors.invalidCodePoint(pos, lineStart, curLine);
  2337. } else {
  2338. return {
  2339. code: null,
  2340. pos
  2341. };
  2342. }
  2343. }
  2344. } else {
  2345. ({
  2346. code,
  2347. pos
  2348. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2349. }
  2350. return {
  2351. code,
  2352. pos
  2353. };
  2354. }
  2355. function buildPosition(pos, lineStart, curLine) {
  2356. return new Position(curLine, pos - lineStart, pos);
  2357. }
  2358. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2359. class Token {
  2360. constructor(state) {
  2361. const startIndex = state.startIndex || 0;
  2362. this.type = state.type;
  2363. this.value = state.value;
  2364. this.start = startIndex + state.start;
  2365. this.end = startIndex + state.end;
  2366. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2367. }
  2368. }
  2369. class Tokenizer extends CommentsParser {
  2370. constructor(options, input) {
  2371. super();
  2372. this.isLookahead = void 0;
  2373. this.tokens = [];
  2374. this.errorHandlers_readInt = {
  2375. invalidDigit: (pos, lineStart, curLine, radix) => {
  2376. if (!(this.optionFlags & 1024)) return false;
  2377. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  2378. radix
  2379. });
  2380. return true;
  2381. },
  2382. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2383. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2384. };
  2385. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2386. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2387. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2388. });
  2389. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2390. strictNumericEscape: (pos, lineStart, curLine) => {
  2391. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  2392. },
  2393. unterminated: (pos, lineStart, curLine) => {
  2394. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  2395. }
  2396. });
  2397. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2398. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2399. unterminated: (pos, lineStart, curLine) => {
  2400. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  2401. }
  2402. });
  2403. this.state = new State();
  2404. this.state.init(options);
  2405. this.input = input;
  2406. this.length = input.length;
  2407. this.comments = [];
  2408. this.isLookahead = false;
  2409. }
  2410. pushToken(token) {
  2411. this.tokens.length = this.state.tokensLength;
  2412. this.tokens.push(token);
  2413. ++this.state.tokensLength;
  2414. }
  2415. next() {
  2416. this.checkKeywordEscapes();
  2417. if (this.optionFlags & 128) {
  2418. this.pushToken(new Token(this.state));
  2419. }
  2420. this.state.lastTokEndLoc = this.state.endLoc;
  2421. this.state.lastTokStartLoc = this.state.startLoc;
  2422. this.nextToken();
  2423. }
  2424. eat(type) {
  2425. if (this.match(type)) {
  2426. this.next();
  2427. return true;
  2428. } else {
  2429. return false;
  2430. }
  2431. }
  2432. match(type) {
  2433. return this.state.type === type;
  2434. }
  2435. createLookaheadState(state) {
  2436. return {
  2437. pos: state.pos,
  2438. value: null,
  2439. type: state.type,
  2440. start: state.start,
  2441. end: state.end,
  2442. context: [this.curContext()],
  2443. inType: state.inType,
  2444. startLoc: state.startLoc,
  2445. lastTokEndLoc: state.lastTokEndLoc,
  2446. curLine: state.curLine,
  2447. lineStart: state.lineStart,
  2448. curPosition: state.curPosition
  2449. };
  2450. }
  2451. lookahead() {
  2452. const old = this.state;
  2453. this.state = this.createLookaheadState(old);
  2454. this.isLookahead = true;
  2455. this.nextToken();
  2456. this.isLookahead = false;
  2457. const curr = this.state;
  2458. this.state = old;
  2459. return curr;
  2460. }
  2461. nextTokenStart() {
  2462. return this.nextTokenStartSince(this.state.pos);
  2463. }
  2464. nextTokenStartSince(pos) {
  2465. skipWhiteSpace.lastIndex = pos;
  2466. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2467. }
  2468. lookaheadCharCode() {
  2469. return this.input.charCodeAt(this.nextTokenStart());
  2470. }
  2471. nextTokenInLineStart() {
  2472. return this.nextTokenInLineStartSince(this.state.pos);
  2473. }
  2474. nextTokenInLineStartSince(pos) {
  2475. skipWhiteSpaceInLine.lastIndex = pos;
  2476. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2477. }
  2478. lookaheadInLineCharCode() {
  2479. return this.input.charCodeAt(this.nextTokenInLineStart());
  2480. }
  2481. codePointAtPos(pos) {
  2482. let cp = this.input.charCodeAt(pos);
  2483. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2484. const trail = this.input.charCodeAt(pos);
  2485. if ((trail & 0xfc00) === 0xdc00) {
  2486. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2487. }
  2488. }
  2489. return cp;
  2490. }
  2491. setStrict(strict) {
  2492. this.state.strict = strict;
  2493. if (strict) {
  2494. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  2495. this.state.strictErrors.clear();
  2496. }
  2497. }
  2498. curContext() {
  2499. return this.state.context[this.state.context.length - 1];
  2500. }
  2501. nextToken() {
  2502. this.skipSpace();
  2503. this.state.start = this.state.pos;
  2504. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2505. if (this.state.pos >= this.length) {
  2506. this.finishToken(140);
  2507. return;
  2508. }
  2509. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2510. }
  2511. skipBlockComment(commentEnd) {
  2512. let startLoc;
  2513. if (!this.isLookahead) startLoc = this.state.curPosition();
  2514. const start = this.state.pos;
  2515. const end = this.input.indexOf(commentEnd, start + 2);
  2516. if (end === -1) {
  2517. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  2518. }
  2519. this.state.pos = end + commentEnd.length;
  2520. lineBreakG.lastIndex = start + 2;
  2521. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2522. ++this.state.curLine;
  2523. this.state.lineStart = lineBreakG.lastIndex;
  2524. }
  2525. if (this.isLookahead) return;
  2526. const comment = {
  2527. type: "CommentBlock",
  2528. value: this.input.slice(start + 2, end),
  2529. start: this.sourceToOffsetPos(start),
  2530. end: this.sourceToOffsetPos(end + commentEnd.length),
  2531. loc: new SourceLocation(startLoc, this.state.curPosition())
  2532. };
  2533. if (this.optionFlags & 128) this.pushToken(comment);
  2534. return comment;
  2535. }
  2536. skipLineComment(startSkip) {
  2537. const start = this.state.pos;
  2538. let startLoc;
  2539. if (!this.isLookahead) startLoc = this.state.curPosition();
  2540. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2541. if (this.state.pos < this.length) {
  2542. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2543. ch = this.input.charCodeAt(this.state.pos);
  2544. }
  2545. }
  2546. if (this.isLookahead) return;
  2547. const end = this.state.pos;
  2548. const value = this.input.slice(start + startSkip, end);
  2549. const comment = {
  2550. type: "CommentLine",
  2551. value,
  2552. start: this.sourceToOffsetPos(start),
  2553. end: this.sourceToOffsetPos(end),
  2554. loc: new SourceLocation(startLoc, this.state.curPosition())
  2555. };
  2556. if (this.optionFlags & 128) this.pushToken(comment);
  2557. return comment;
  2558. }
  2559. skipSpace() {
  2560. const spaceStart = this.state.pos;
  2561. const comments = this.optionFlags & 2048 ? [] : null;
  2562. loop: while (this.state.pos < this.length) {
  2563. const ch = this.input.charCodeAt(this.state.pos);
  2564. switch (ch) {
  2565. case 32:
  2566. case 160:
  2567. case 9:
  2568. ++this.state.pos;
  2569. break;
  2570. case 13:
  2571. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2572. ++this.state.pos;
  2573. }
  2574. case 10:
  2575. case 8232:
  2576. case 8233:
  2577. ++this.state.pos;
  2578. ++this.state.curLine;
  2579. this.state.lineStart = this.state.pos;
  2580. break;
  2581. case 47:
  2582. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2583. case 42:
  2584. {
  2585. const comment = this.skipBlockComment("*/");
  2586. if (comment !== undefined) {
  2587. this.addComment(comment);
  2588. comments == null || comments.push(comment);
  2589. }
  2590. break;
  2591. }
  2592. case 47:
  2593. {
  2594. const comment = this.skipLineComment(2);
  2595. if (comment !== undefined) {
  2596. this.addComment(comment);
  2597. comments == null || comments.push(comment);
  2598. }
  2599. break;
  2600. }
  2601. default:
  2602. break loop;
  2603. }
  2604. break;
  2605. default:
  2606. if (isWhitespace(ch)) {
  2607. ++this.state.pos;
  2608. } else if (ch === 45 && !this.inModule && this.optionFlags & 4096) {
  2609. const pos = this.state.pos;
  2610. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2611. const comment = this.skipLineComment(3);
  2612. if (comment !== undefined) {
  2613. this.addComment(comment);
  2614. comments == null || comments.push(comment);
  2615. }
  2616. } else {
  2617. break loop;
  2618. }
  2619. } else if (ch === 60 && !this.inModule && this.optionFlags & 4096) {
  2620. const pos = this.state.pos;
  2621. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2622. const comment = this.skipLineComment(4);
  2623. if (comment !== undefined) {
  2624. this.addComment(comment);
  2625. comments == null || comments.push(comment);
  2626. }
  2627. } else {
  2628. break loop;
  2629. }
  2630. } else {
  2631. break loop;
  2632. }
  2633. }
  2634. }
  2635. if ((comments == null ? void 0 : comments.length) > 0) {
  2636. const end = this.state.pos;
  2637. const commentWhitespace = {
  2638. start: this.sourceToOffsetPos(spaceStart),
  2639. end: this.sourceToOffsetPos(end),
  2640. comments,
  2641. leadingNode: null,
  2642. trailingNode: null,
  2643. containingNode: null
  2644. };
  2645. this.state.commentStack.push(commentWhitespace);
  2646. }
  2647. }
  2648. finishToken(type, val) {
  2649. this.state.end = this.state.pos;
  2650. this.state.endLoc = this.state.curPosition();
  2651. const prevType = this.state.type;
  2652. this.state.type = type;
  2653. this.state.value = val;
  2654. if (!this.isLookahead) {
  2655. this.updateContext(prevType);
  2656. }
  2657. }
  2658. replaceToken(type) {
  2659. this.state.type = type;
  2660. this.updateContext();
  2661. }
  2662. readToken_numberSign() {
  2663. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2664. return;
  2665. }
  2666. const nextPos = this.state.pos + 1;
  2667. const next = this.codePointAtPos(nextPos);
  2668. if (next >= 48 && next <= 57) {
  2669. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  2670. }
  2671. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2672. this.expectPlugin("recordAndTuple");
  2673. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2674. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  2675. }
  2676. this.state.pos += 2;
  2677. if (next === 123) {
  2678. this.finishToken(7);
  2679. } else {
  2680. this.finishToken(1);
  2681. }
  2682. } else if (isIdentifierStart(next)) {
  2683. ++this.state.pos;
  2684. this.finishToken(139, this.readWord1(next));
  2685. } else if (next === 92) {
  2686. ++this.state.pos;
  2687. this.finishToken(139, this.readWord1());
  2688. } else {
  2689. this.finishOp(27, 1);
  2690. }
  2691. }
  2692. readToken_dot() {
  2693. const next = this.input.charCodeAt(this.state.pos + 1);
  2694. if (next >= 48 && next <= 57) {
  2695. this.readNumber(true);
  2696. return;
  2697. }
  2698. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2699. this.state.pos += 3;
  2700. this.finishToken(21);
  2701. } else {
  2702. ++this.state.pos;
  2703. this.finishToken(16);
  2704. }
  2705. }
  2706. readToken_slash() {
  2707. const next = this.input.charCodeAt(this.state.pos + 1);
  2708. if (next === 61) {
  2709. this.finishOp(31, 2);
  2710. } else {
  2711. this.finishOp(56, 1);
  2712. }
  2713. }
  2714. readToken_interpreter() {
  2715. if (this.state.pos !== 0 || this.length < 2) return false;
  2716. let ch = this.input.charCodeAt(this.state.pos + 1);
  2717. if (ch !== 33) return false;
  2718. const start = this.state.pos;
  2719. this.state.pos += 1;
  2720. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2721. ch = this.input.charCodeAt(this.state.pos);
  2722. }
  2723. const value = this.input.slice(start + 2, this.state.pos);
  2724. this.finishToken(28, value);
  2725. return true;
  2726. }
  2727. readToken_mult_modulo(code) {
  2728. let type = code === 42 ? 55 : 54;
  2729. let width = 1;
  2730. let next = this.input.charCodeAt(this.state.pos + 1);
  2731. if (code === 42 && next === 42) {
  2732. width++;
  2733. next = this.input.charCodeAt(this.state.pos + 2);
  2734. type = 57;
  2735. }
  2736. if (next === 61 && !this.state.inType) {
  2737. width++;
  2738. type = code === 37 ? 33 : 30;
  2739. }
  2740. this.finishOp(type, width);
  2741. }
  2742. readToken_pipe_amp(code) {
  2743. const next = this.input.charCodeAt(this.state.pos + 1);
  2744. if (next === code) {
  2745. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2746. this.finishOp(30, 3);
  2747. } else {
  2748. this.finishOp(code === 124 ? 41 : 42, 2);
  2749. }
  2750. return;
  2751. }
  2752. if (code === 124) {
  2753. if (next === 62) {
  2754. this.finishOp(39, 2);
  2755. return;
  2756. }
  2757. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2758. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2759. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2760. }
  2761. this.state.pos += 2;
  2762. this.finishToken(9);
  2763. return;
  2764. }
  2765. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2766. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2767. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2768. }
  2769. this.state.pos += 2;
  2770. this.finishToken(4);
  2771. return;
  2772. }
  2773. }
  2774. if (next === 61) {
  2775. this.finishOp(30, 2);
  2776. return;
  2777. }
  2778. this.finishOp(code === 124 ? 43 : 45, 1);
  2779. }
  2780. readToken_caret() {
  2781. const next = this.input.charCodeAt(this.state.pos + 1);
  2782. if (next === 61 && !this.state.inType) {
  2783. this.finishOp(32, 2);
  2784. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2785. proposal: "hack",
  2786. topicToken: "^^"
  2787. }])) {
  2788. this.finishOp(37, 2);
  2789. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2790. if (lookaheadCh === 94) {
  2791. this.unexpected();
  2792. }
  2793. } else {
  2794. this.finishOp(44, 1);
  2795. }
  2796. }
  2797. readToken_atSign() {
  2798. const next = this.input.charCodeAt(this.state.pos + 1);
  2799. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2800. proposal: "hack",
  2801. topicToken: "@@"
  2802. }])) {
  2803. this.finishOp(38, 2);
  2804. } else {
  2805. this.finishOp(26, 1);
  2806. }
  2807. }
  2808. readToken_plus_min(code) {
  2809. const next = this.input.charCodeAt(this.state.pos + 1);
  2810. if (next === code) {
  2811. this.finishOp(34, 2);
  2812. return;
  2813. }
  2814. if (next === 61) {
  2815. this.finishOp(30, 2);
  2816. } else {
  2817. this.finishOp(53, 1);
  2818. }
  2819. }
  2820. readToken_lt() {
  2821. const {
  2822. pos
  2823. } = this.state;
  2824. const next = this.input.charCodeAt(pos + 1);
  2825. if (next === 60) {
  2826. if (this.input.charCodeAt(pos + 2) === 61) {
  2827. this.finishOp(30, 3);
  2828. return;
  2829. }
  2830. this.finishOp(51, 2);
  2831. return;
  2832. }
  2833. if (next === 61) {
  2834. this.finishOp(49, 2);
  2835. return;
  2836. }
  2837. this.finishOp(47, 1);
  2838. }
  2839. readToken_gt() {
  2840. const {
  2841. pos
  2842. } = this.state;
  2843. const next = this.input.charCodeAt(pos + 1);
  2844. if (next === 62) {
  2845. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2846. if (this.input.charCodeAt(pos + size) === 61) {
  2847. this.finishOp(30, size + 1);
  2848. return;
  2849. }
  2850. this.finishOp(52, size);
  2851. return;
  2852. }
  2853. if (next === 61) {
  2854. this.finishOp(49, 2);
  2855. return;
  2856. }
  2857. this.finishOp(48, 1);
  2858. }
  2859. readToken_eq_excl(code) {
  2860. const next = this.input.charCodeAt(this.state.pos + 1);
  2861. if (next === 61) {
  2862. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2863. return;
  2864. }
  2865. if (code === 61 && next === 62) {
  2866. this.state.pos += 2;
  2867. this.finishToken(19);
  2868. return;
  2869. }
  2870. this.finishOp(code === 61 ? 29 : 35, 1);
  2871. }
  2872. readToken_question() {
  2873. const next = this.input.charCodeAt(this.state.pos + 1);
  2874. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2875. if (next === 63) {
  2876. if (next2 === 61) {
  2877. this.finishOp(30, 3);
  2878. } else {
  2879. this.finishOp(40, 2);
  2880. }
  2881. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2882. this.state.pos += 2;
  2883. this.finishToken(18);
  2884. } else {
  2885. ++this.state.pos;
  2886. this.finishToken(17);
  2887. }
  2888. }
  2889. getTokenFromCode(code) {
  2890. switch (code) {
  2891. case 46:
  2892. this.readToken_dot();
  2893. return;
  2894. case 40:
  2895. ++this.state.pos;
  2896. this.finishToken(10);
  2897. return;
  2898. case 41:
  2899. ++this.state.pos;
  2900. this.finishToken(11);
  2901. return;
  2902. case 59:
  2903. ++this.state.pos;
  2904. this.finishToken(13);
  2905. return;
  2906. case 44:
  2907. ++this.state.pos;
  2908. this.finishToken(12);
  2909. return;
  2910. case 91:
  2911. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2912. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2913. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2914. }
  2915. this.state.pos += 2;
  2916. this.finishToken(2);
  2917. } else {
  2918. ++this.state.pos;
  2919. this.finishToken(0);
  2920. }
  2921. return;
  2922. case 93:
  2923. ++this.state.pos;
  2924. this.finishToken(3);
  2925. return;
  2926. case 123:
  2927. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2928. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2929. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2930. }
  2931. this.state.pos += 2;
  2932. this.finishToken(6);
  2933. } else {
  2934. ++this.state.pos;
  2935. this.finishToken(5);
  2936. }
  2937. return;
  2938. case 125:
  2939. ++this.state.pos;
  2940. this.finishToken(8);
  2941. return;
  2942. case 58:
  2943. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2944. this.finishOp(15, 2);
  2945. } else {
  2946. ++this.state.pos;
  2947. this.finishToken(14);
  2948. }
  2949. return;
  2950. case 63:
  2951. this.readToken_question();
  2952. return;
  2953. case 96:
  2954. this.readTemplateToken();
  2955. return;
  2956. case 48:
  2957. {
  2958. const next = this.input.charCodeAt(this.state.pos + 1);
  2959. if (next === 120 || next === 88) {
  2960. this.readRadixNumber(16);
  2961. return;
  2962. }
  2963. if (next === 111 || next === 79) {
  2964. this.readRadixNumber(8);
  2965. return;
  2966. }
  2967. if (next === 98 || next === 66) {
  2968. this.readRadixNumber(2);
  2969. return;
  2970. }
  2971. }
  2972. case 49:
  2973. case 50:
  2974. case 51:
  2975. case 52:
  2976. case 53:
  2977. case 54:
  2978. case 55:
  2979. case 56:
  2980. case 57:
  2981. this.readNumber(false);
  2982. return;
  2983. case 34:
  2984. case 39:
  2985. this.readString(code);
  2986. return;
  2987. case 47:
  2988. this.readToken_slash();
  2989. return;
  2990. case 37:
  2991. case 42:
  2992. this.readToken_mult_modulo(code);
  2993. return;
  2994. case 124:
  2995. case 38:
  2996. this.readToken_pipe_amp(code);
  2997. return;
  2998. case 94:
  2999. this.readToken_caret();
  3000. return;
  3001. case 43:
  3002. case 45:
  3003. this.readToken_plus_min(code);
  3004. return;
  3005. case 60:
  3006. this.readToken_lt();
  3007. return;
  3008. case 62:
  3009. this.readToken_gt();
  3010. return;
  3011. case 61:
  3012. case 33:
  3013. this.readToken_eq_excl(code);
  3014. return;
  3015. case 126:
  3016. this.finishOp(36, 1);
  3017. return;
  3018. case 64:
  3019. this.readToken_atSign();
  3020. return;
  3021. case 35:
  3022. this.readToken_numberSign();
  3023. return;
  3024. case 92:
  3025. this.readWord();
  3026. return;
  3027. default:
  3028. if (isIdentifierStart(code)) {
  3029. this.readWord(code);
  3030. return;
  3031. }
  3032. }
  3033. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  3034. unexpected: String.fromCodePoint(code)
  3035. });
  3036. }
  3037. finishOp(type, size) {
  3038. const str = this.input.slice(this.state.pos, this.state.pos + size);
  3039. this.state.pos += size;
  3040. this.finishToken(type, str);
  3041. }
  3042. readRegexp() {
  3043. const startLoc = this.state.startLoc;
  3044. const start = this.state.start + 1;
  3045. let escaped, inClass;
  3046. let {
  3047. pos
  3048. } = this.state;
  3049. for (;; ++pos) {
  3050. if (pos >= this.length) {
  3051. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  3052. }
  3053. const ch = this.input.charCodeAt(pos);
  3054. if (isNewLine(ch)) {
  3055. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  3056. }
  3057. if (escaped) {
  3058. escaped = false;
  3059. } else {
  3060. if (ch === 91) {
  3061. inClass = true;
  3062. } else if (ch === 93 && inClass) {
  3063. inClass = false;
  3064. } else if (ch === 47 && !inClass) {
  3065. break;
  3066. }
  3067. escaped = ch === 92;
  3068. }
  3069. }
  3070. const content = this.input.slice(start, pos);
  3071. ++pos;
  3072. let mods = "";
  3073. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  3074. while (pos < this.length) {
  3075. const cp = this.codePointAtPos(pos);
  3076. const char = String.fromCharCode(cp);
  3077. if (VALID_REGEX_FLAGS.has(cp)) {
  3078. if (cp === 118) {
  3079. if (mods.includes("u")) {
  3080. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3081. }
  3082. } else if (cp === 117) {
  3083. if (mods.includes("v")) {
  3084. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3085. }
  3086. }
  3087. if (mods.includes(char)) {
  3088. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  3089. }
  3090. } else if (isIdentifierChar(cp) || cp === 92) {
  3091. this.raise(Errors.MalformedRegExpFlags, nextPos());
  3092. } else {
  3093. break;
  3094. }
  3095. ++pos;
  3096. mods += char;
  3097. }
  3098. this.state.pos = pos;
  3099. this.finishToken(138, {
  3100. pattern: content,
  3101. flags: mods
  3102. });
  3103. }
  3104. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  3105. const {
  3106. n,
  3107. pos
  3108. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  3109. this.state.pos = pos;
  3110. return n;
  3111. }
  3112. readRadixNumber(radix) {
  3113. const start = this.state.pos;
  3114. const startLoc = this.state.curPosition();
  3115. let isBigInt = false;
  3116. this.state.pos += 2;
  3117. const val = this.readInt(radix);
  3118. if (val == null) {
  3119. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  3120. radix
  3121. });
  3122. }
  3123. const next = this.input.charCodeAt(this.state.pos);
  3124. if (next === 110) {
  3125. ++this.state.pos;
  3126. isBigInt = true;
  3127. } else if (next === 109) {
  3128. throw this.raise(Errors.InvalidDecimal, startLoc);
  3129. }
  3130. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3131. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3132. }
  3133. if (isBigInt) {
  3134. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  3135. this.finishToken(136, str);
  3136. return;
  3137. }
  3138. this.finishToken(135, val);
  3139. }
  3140. readNumber(startsWithDot) {
  3141. const start = this.state.pos;
  3142. const startLoc = this.state.curPosition();
  3143. let isFloat = false;
  3144. let isBigInt = false;
  3145. let hasExponent = false;
  3146. let isOctal = false;
  3147. if (!startsWithDot && this.readInt(10) === null) {
  3148. this.raise(Errors.InvalidNumber, this.state.curPosition());
  3149. }
  3150. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3151. if (hasLeadingZero) {
  3152. const integer = this.input.slice(start, this.state.pos);
  3153. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  3154. if (!this.state.strict) {
  3155. const underscorePos = integer.indexOf("_");
  3156. if (underscorePos > 0) {
  3157. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  3158. }
  3159. }
  3160. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3161. }
  3162. let next = this.input.charCodeAt(this.state.pos);
  3163. if (next === 46 && !isOctal) {
  3164. ++this.state.pos;
  3165. this.readInt(10);
  3166. isFloat = true;
  3167. next = this.input.charCodeAt(this.state.pos);
  3168. }
  3169. if ((next === 69 || next === 101) && !isOctal) {
  3170. next = this.input.charCodeAt(++this.state.pos);
  3171. if (next === 43 || next === 45) {
  3172. ++this.state.pos;
  3173. }
  3174. if (this.readInt(10) === null) {
  3175. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  3176. }
  3177. isFloat = true;
  3178. hasExponent = true;
  3179. next = this.input.charCodeAt(this.state.pos);
  3180. }
  3181. if (next === 110) {
  3182. if (isFloat || hasLeadingZero) {
  3183. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  3184. }
  3185. ++this.state.pos;
  3186. isBigInt = true;
  3187. }
  3188. if (next === 109) {
  3189. this.expectPlugin("decimal", this.state.curPosition());
  3190. if (hasExponent || hasLeadingZero) {
  3191. this.raise(Errors.InvalidDecimal, startLoc);
  3192. }
  3193. ++this.state.pos;
  3194. var isDecimal = true;
  3195. }
  3196. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3197. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3198. }
  3199. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3200. if (isBigInt) {
  3201. this.finishToken(136, str);
  3202. return;
  3203. }
  3204. if (isDecimal) {
  3205. this.finishToken(137, str);
  3206. return;
  3207. }
  3208. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3209. this.finishToken(135, val);
  3210. }
  3211. readCodePoint(throwOnInvalid) {
  3212. const {
  3213. code,
  3214. pos
  3215. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3216. this.state.pos = pos;
  3217. return code;
  3218. }
  3219. readString(quote) {
  3220. const {
  3221. str,
  3222. pos,
  3223. curLine,
  3224. lineStart
  3225. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3226. this.state.pos = pos + 1;
  3227. this.state.lineStart = lineStart;
  3228. this.state.curLine = curLine;
  3229. this.finishToken(134, str);
  3230. }
  3231. readTemplateContinuation() {
  3232. if (!this.match(8)) {
  3233. this.unexpected(null, 8);
  3234. }
  3235. this.state.pos--;
  3236. this.readTemplateToken();
  3237. }
  3238. readTemplateToken() {
  3239. const opening = this.input[this.state.pos];
  3240. const {
  3241. str,
  3242. firstInvalidLoc,
  3243. pos,
  3244. curLine,
  3245. lineStart
  3246. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3247. this.state.pos = pos + 1;
  3248. this.state.lineStart = lineStart;
  3249. this.state.curLine = curLine;
  3250. if (firstInvalidLoc) {
  3251. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  3252. }
  3253. if (this.input.codePointAt(pos) === 96) {
  3254. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3255. } else {
  3256. this.state.pos++;
  3257. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3258. }
  3259. }
  3260. recordStrictModeErrors(toParseError, at) {
  3261. const index = at.index;
  3262. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3263. this.raise(toParseError, at);
  3264. } else {
  3265. this.state.strictErrors.set(index, [toParseError, at]);
  3266. }
  3267. }
  3268. readWord1(firstCode) {
  3269. this.state.containsEsc = false;
  3270. let word = "";
  3271. const start = this.state.pos;
  3272. let chunkStart = this.state.pos;
  3273. if (firstCode !== undefined) {
  3274. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3275. }
  3276. while (this.state.pos < this.length) {
  3277. const ch = this.codePointAtPos(this.state.pos);
  3278. if (isIdentifierChar(ch)) {
  3279. this.state.pos += ch <= 0xffff ? 1 : 2;
  3280. } else if (ch === 92) {
  3281. this.state.containsEsc = true;
  3282. word += this.input.slice(chunkStart, this.state.pos);
  3283. const escStart = this.state.curPosition();
  3284. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3285. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3286. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  3287. chunkStart = this.state.pos - 1;
  3288. continue;
  3289. }
  3290. ++this.state.pos;
  3291. const esc = this.readCodePoint(true);
  3292. if (esc !== null) {
  3293. if (!identifierCheck(esc)) {
  3294. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  3295. }
  3296. word += String.fromCodePoint(esc);
  3297. }
  3298. chunkStart = this.state.pos;
  3299. } else {
  3300. break;
  3301. }
  3302. }
  3303. return word + this.input.slice(chunkStart, this.state.pos);
  3304. }
  3305. readWord(firstCode) {
  3306. const word = this.readWord1(firstCode);
  3307. const type = keywords$1.get(word);
  3308. if (type !== undefined) {
  3309. this.finishToken(type, tokenLabelName(type));
  3310. } else {
  3311. this.finishToken(132, word);
  3312. }
  3313. }
  3314. checkKeywordEscapes() {
  3315. const {
  3316. type
  3317. } = this.state;
  3318. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3319. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  3320. reservedWord: tokenLabelName(type)
  3321. });
  3322. }
  3323. }
  3324. raise(toParseError, at, details = {}) {
  3325. const loc = at instanceof Position ? at : at.loc.start;
  3326. const error = toParseError(loc, details);
  3327. if (!(this.optionFlags & 1024)) throw error;
  3328. if (!this.isLookahead) this.state.errors.push(error);
  3329. return error;
  3330. }
  3331. raiseOverwrite(toParseError, at, details = {}) {
  3332. const loc = at instanceof Position ? at : at.loc.start;
  3333. const pos = loc.index;
  3334. const errors = this.state.errors;
  3335. for (let i = errors.length - 1; i >= 0; i--) {
  3336. const error = errors[i];
  3337. if (error.loc.index === pos) {
  3338. return errors[i] = toParseError(loc, details);
  3339. }
  3340. if (error.loc.index < pos) break;
  3341. }
  3342. return this.raise(toParseError, at, details);
  3343. }
  3344. updateContext(prevType) {}
  3345. unexpected(loc, type) {
  3346. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  3347. expected: type ? tokenLabelName(type) : null
  3348. });
  3349. }
  3350. expectPlugin(pluginName, loc) {
  3351. if (this.hasPlugin(pluginName)) {
  3352. return true;
  3353. }
  3354. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  3355. missingPlugin: [pluginName]
  3356. });
  3357. }
  3358. expectOnePlugin(pluginNames) {
  3359. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3360. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  3361. missingPlugin: pluginNames
  3362. });
  3363. }
  3364. }
  3365. errorBuilder(error) {
  3366. return (pos, lineStart, curLine) => {
  3367. this.raise(error, buildPosition(pos, lineStart, curLine));
  3368. };
  3369. }
  3370. }
  3371. class ClassScope {
  3372. constructor() {
  3373. this.privateNames = new Set();
  3374. this.loneAccessors = new Map();
  3375. this.undefinedPrivateNames = new Map();
  3376. }
  3377. }
  3378. class ClassScopeHandler {
  3379. constructor(parser) {
  3380. this.parser = void 0;
  3381. this.stack = [];
  3382. this.undefinedPrivateNames = new Map();
  3383. this.parser = parser;
  3384. }
  3385. current() {
  3386. return this.stack[this.stack.length - 1];
  3387. }
  3388. enter() {
  3389. this.stack.push(new ClassScope());
  3390. }
  3391. exit() {
  3392. const oldClassScope = this.stack.pop();
  3393. const current = this.current();
  3394. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3395. if (current) {
  3396. if (!current.undefinedPrivateNames.has(name)) {
  3397. current.undefinedPrivateNames.set(name, loc);
  3398. }
  3399. } else {
  3400. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3401. identifierName: name
  3402. });
  3403. }
  3404. }
  3405. }
  3406. declarePrivateName(name, elementType, loc) {
  3407. const {
  3408. privateNames,
  3409. loneAccessors,
  3410. undefinedPrivateNames
  3411. } = this.current();
  3412. let redefined = privateNames.has(name);
  3413. if (elementType & 3) {
  3414. const accessor = redefined && loneAccessors.get(name);
  3415. if (accessor) {
  3416. const oldStatic = accessor & 4;
  3417. const newStatic = elementType & 4;
  3418. const oldKind = accessor & 3;
  3419. const newKind = elementType & 3;
  3420. redefined = oldKind === newKind || oldStatic !== newStatic;
  3421. if (!redefined) loneAccessors.delete(name);
  3422. } else if (!redefined) {
  3423. loneAccessors.set(name, elementType);
  3424. }
  3425. }
  3426. if (redefined) {
  3427. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  3428. identifierName: name
  3429. });
  3430. }
  3431. privateNames.add(name);
  3432. undefinedPrivateNames.delete(name);
  3433. }
  3434. usePrivateName(name, loc) {
  3435. let classScope;
  3436. for (classScope of this.stack) {
  3437. if (classScope.privateNames.has(name)) return;
  3438. }
  3439. if (classScope) {
  3440. classScope.undefinedPrivateNames.set(name, loc);
  3441. } else {
  3442. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3443. identifierName: name
  3444. });
  3445. }
  3446. }
  3447. }
  3448. class ExpressionScope {
  3449. constructor(type = 0) {
  3450. this.type = type;
  3451. }
  3452. canBeArrowParameterDeclaration() {
  3453. return this.type === 2 || this.type === 1;
  3454. }
  3455. isCertainlyParameterDeclaration() {
  3456. return this.type === 3;
  3457. }
  3458. }
  3459. class ArrowHeadParsingScope extends ExpressionScope {
  3460. constructor(type) {
  3461. super(type);
  3462. this.declarationErrors = new Map();
  3463. }
  3464. recordDeclarationError(ParsingErrorClass, at) {
  3465. const index = at.index;
  3466. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3467. }
  3468. clearDeclarationError(index) {
  3469. this.declarationErrors.delete(index);
  3470. }
  3471. iterateErrors(iterator) {
  3472. this.declarationErrors.forEach(iterator);
  3473. }
  3474. }
  3475. class ExpressionScopeHandler {
  3476. constructor(parser) {
  3477. this.parser = void 0;
  3478. this.stack = [new ExpressionScope()];
  3479. this.parser = parser;
  3480. }
  3481. enter(scope) {
  3482. this.stack.push(scope);
  3483. }
  3484. exit() {
  3485. this.stack.pop();
  3486. }
  3487. recordParameterInitializerError(toParseError, node) {
  3488. const origin = node.loc.start;
  3489. const {
  3490. stack
  3491. } = this;
  3492. let i = stack.length - 1;
  3493. let scope = stack[i];
  3494. while (!scope.isCertainlyParameterDeclaration()) {
  3495. if (scope.canBeArrowParameterDeclaration()) {
  3496. scope.recordDeclarationError(toParseError, origin);
  3497. } else {
  3498. return;
  3499. }
  3500. scope = stack[--i];
  3501. }
  3502. this.parser.raise(toParseError, origin);
  3503. }
  3504. recordArrowParameterBindingError(error, node) {
  3505. const {
  3506. stack
  3507. } = this;
  3508. const scope = stack[stack.length - 1];
  3509. const origin = node.loc.start;
  3510. if (scope.isCertainlyParameterDeclaration()) {
  3511. this.parser.raise(error, origin);
  3512. } else if (scope.canBeArrowParameterDeclaration()) {
  3513. scope.recordDeclarationError(error, origin);
  3514. } else {
  3515. return;
  3516. }
  3517. }
  3518. recordAsyncArrowParametersError(at) {
  3519. const {
  3520. stack
  3521. } = this;
  3522. let i = stack.length - 1;
  3523. let scope = stack[i];
  3524. while (scope.canBeArrowParameterDeclaration()) {
  3525. if (scope.type === 2) {
  3526. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  3527. }
  3528. scope = stack[--i];
  3529. }
  3530. }
  3531. validateAsPattern() {
  3532. const {
  3533. stack
  3534. } = this;
  3535. const currentScope = stack[stack.length - 1];
  3536. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3537. currentScope.iterateErrors(([toParseError, loc]) => {
  3538. this.parser.raise(toParseError, loc);
  3539. let i = stack.length - 2;
  3540. let scope = stack[i];
  3541. while (scope.canBeArrowParameterDeclaration()) {
  3542. scope.clearDeclarationError(loc.index);
  3543. scope = stack[--i];
  3544. }
  3545. });
  3546. }
  3547. }
  3548. function newParameterDeclarationScope() {
  3549. return new ExpressionScope(3);
  3550. }
  3551. function newArrowHeadScope() {
  3552. return new ArrowHeadParsingScope(1);
  3553. }
  3554. function newAsyncArrowScope() {
  3555. return new ArrowHeadParsingScope(2);
  3556. }
  3557. function newExpressionScope() {
  3558. return new ExpressionScope();
  3559. }
  3560. class ProductionParameterHandler {
  3561. constructor() {
  3562. this.stacks = [];
  3563. }
  3564. enter(flags) {
  3565. this.stacks.push(flags);
  3566. }
  3567. exit() {
  3568. this.stacks.pop();
  3569. }
  3570. currentFlags() {
  3571. return this.stacks[this.stacks.length - 1];
  3572. }
  3573. get hasAwait() {
  3574. return (this.currentFlags() & 2) > 0;
  3575. }
  3576. get hasYield() {
  3577. return (this.currentFlags() & 1) > 0;
  3578. }
  3579. get hasReturn() {
  3580. return (this.currentFlags() & 4) > 0;
  3581. }
  3582. get hasIn() {
  3583. return (this.currentFlags() & 8) > 0;
  3584. }
  3585. }
  3586. function functionFlags(isAsync, isGenerator) {
  3587. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  3588. }
  3589. class UtilParser extends Tokenizer {
  3590. addExtra(node, key, value, enumerable = true) {
  3591. if (!node) return;
  3592. let {
  3593. extra
  3594. } = node;
  3595. if (extra == null) {
  3596. extra = {};
  3597. node.extra = extra;
  3598. }
  3599. if (enumerable) {
  3600. extra[key] = value;
  3601. } else {
  3602. Object.defineProperty(extra, key, {
  3603. enumerable,
  3604. value
  3605. });
  3606. }
  3607. }
  3608. isContextual(token) {
  3609. return this.state.type === token && !this.state.containsEsc;
  3610. }
  3611. isUnparsedContextual(nameStart, name) {
  3612. const nameEnd = nameStart + name.length;
  3613. if (this.input.slice(nameStart, nameEnd) === name) {
  3614. const nextCh = this.input.charCodeAt(nameEnd);
  3615. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3616. }
  3617. return false;
  3618. }
  3619. isLookaheadContextual(name) {
  3620. const next = this.nextTokenStart();
  3621. return this.isUnparsedContextual(next, name);
  3622. }
  3623. eatContextual(token) {
  3624. if (this.isContextual(token)) {
  3625. this.next();
  3626. return true;
  3627. }
  3628. return false;
  3629. }
  3630. expectContextual(token, toParseError) {
  3631. if (!this.eatContextual(token)) {
  3632. if (toParseError != null) {
  3633. throw this.raise(toParseError, this.state.startLoc);
  3634. }
  3635. this.unexpected(null, token);
  3636. }
  3637. }
  3638. canInsertSemicolon() {
  3639. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  3640. }
  3641. hasPrecedingLineBreak() {
  3642. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  3643. }
  3644. hasFollowingLineBreak() {
  3645. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  3646. }
  3647. isLineTerminator() {
  3648. return this.eat(13) || this.canInsertSemicolon();
  3649. }
  3650. semicolon(allowAsi = true) {
  3651. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3652. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  3653. }
  3654. expect(type, loc) {
  3655. if (!this.eat(type)) {
  3656. this.unexpected(loc, type);
  3657. }
  3658. }
  3659. tryParse(fn, oldState = this.state.clone()) {
  3660. const abortSignal = {
  3661. node: null
  3662. };
  3663. try {
  3664. const node = fn((node = null) => {
  3665. abortSignal.node = node;
  3666. throw abortSignal;
  3667. });
  3668. if (this.state.errors.length > oldState.errors.length) {
  3669. const failState = this.state;
  3670. this.state = oldState;
  3671. this.state.tokensLength = failState.tokensLength;
  3672. return {
  3673. node,
  3674. error: failState.errors[oldState.errors.length],
  3675. thrown: false,
  3676. aborted: false,
  3677. failState
  3678. };
  3679. }
  3680. return {
  3681. node,
  3682. error: null,
  3683. thrown: false,
  3684. aborted: false,
  3685. failState: null
  3686. };
  3687. } catch (error) {
  3688. const failState = this.state;
  3689. this.state = oldState;
  3690. if (error instanceof SyntaxError) {
  3691. return {
  3692. node: null,
  3693. error,
  3694. thrown: true,
  3695. aborted: false,
  3696. failState
  3697. };
  3698. }
  3699. if (error === abortSignal) {
  3700. return {
  3701. node: abortSignal.node,
  3702. error: null,
  3703. thrown: false,
  3704. aborted: true,
  3705. failState
  3706. };
  3707. }
  3708. throw error;
  3709. }
  3710. }
  3711. checkExpressionErrors(refExpressionErrors, andThrow) {
  3712. if (!refExpressionErrors) return false;
  3713. const {
  3714. shorthandAssignLoc,
  3715. doubleProtoLoc,
  3716. privateKeyLoc,
  3717. optionalParametersLoc
  3718. } = refExpressionErrors;
  3719. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3720. if (!andThrow) {
  3721. return hasErrors;
  3722. }
  3723. if (shorthandAssignLoc != null) {
  3724. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  3725. }
  3726. if (doubleProtoLoc != null) {
  3727. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  3728. }
  3729. if (privateKeyLoc != null) {
  3730. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  3731. }
  3732. if (optionalParametersLoc != null) {
  3733. this.unexpected(optionalParametersLoc);
  3734. }
  3735. }
  3736. isLiteralPropertyName() {
  3737. return tokenIsLiteralPropertyName(this.state.type);
  3738. }
  3739. isPrivateName(node) {
  3740. return node.type === "PrivateName";
  3741. }
  3742. getPrivateNameSV(node) {
  3743. return node.id.name;
  3744. }
  3745. hasPropertyAsPrivateName(node) {
  3746. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3747. }
  3748. isObjectProperty(node) {
  3749. return node.type === "ObjectProperty";
  3750. }
  3751. isObjectMethod(node) {
  3752. return node.type === "ObjectMethod";
  3753. }
  3754. initializeScopes(inModule = this.options.sourceType === "module") {
  3755. const oldLabels = this.state.labels;
  3756. this.state.labels = [];
  3757. const oldExportedIdentifiers = this.exportedIdentifiers;
  3758. this.exportedIdentifiers = new Set();
  3759. const oldInModule = this.inModule;
  3760. this.inModule = inModule;
  3761. const oldScope = this.scope;
  3762. const ScopeHandler = this.getScopeHandler();
  3763. this.scope = new ScopeHandler(this, inModule);
  3764. const oldProdParam = this.prodParam;
  3765. this.prodParam = new ProductionParameterHandler();
  3766. const oldClassScope = this.classScope;
  3767. this.classScope = new ClassScopeHandler(this);
  3768. const oldExpressionScope = this.expressionScope;
  3769. this.expressionScope = new ExpressionScopeHandler(this);
  3770. return () => {
  3771. this.state.labels = oldLabels;
  3772. this.exportedIdentifiers = oldExportedIdentifiers;
  3773. this.inModule = oldInModule;
  3774. this.scope = oldScope;
  3775. this.prodParam = oldProdParam;
  3776. this.classScope = oldClassScope;
  3777. this.expressionScope = oldExpressionScope;
  3778. };
  3779. }
  3780. enterInitialScopes() {
  3781. let paramFlags = 0;
  3782. if (this.inModule) {
  3783. paramFlags |= 2;
  3784. }
  3785. this.scope.enter(1);
  3786. this.prodParam.enter(paramFlags);
  3787. }
  3788. checkDestructuringPrivate(refExpressionErrors) {
  3789. const {
  3790. privateKeyLoc
  3791. } = refExpressionErrors;
  3792. if (privateKeyLoc !== null) {
  3793. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3794. }
  3795. }
  3796. }
  3797. class ExpressionErrors {
  3798. constructor() {
  3799. this.shorthandAssignLoc = null;
  3800. this.doubleProtoLoc = null;
  3801. this.privateKeyLoc = null;
  3802. this.optionalParametersLoc = null;
  3803. }
  3804. }
  3805. class Node {
  3806. constructor(parser, pos, loc) {
  3807. this.type = "";
  3808. this.start = pos;
  3809. this.end = 0;
  3810. this.loc = new SourceLocation(loc);
  3811. if ((parser == null ? void 0 : parser.optionFlags) & 64) this.range = [pos, 0];
  3812. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3813. }
  3814. }
  3815. const NodePrototype = Node.prototype;
  3816. {
  3817. NodePrototype.__clone = function () {
  3818. const newNode = new Node(undefined, this.start, this.loc.start);
  3819. const keys = Object.keys(this);
  3820. for (let i = 0, length = keys.length; i < length; i++) {
  3821. const key = keys[i];
  3822. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3823. newNode[key] = this[key];
  3824. }
  3825. }
  3826. return newNode;
  3827. };
  3828. }
  3829. function clonePlaceholder(node) {
  3830. return cloneIdentifier(node);
  3831. }
  3832. function cloneIdentifier(node) {
  3833. const {
  3834. type,
  3835. start,
  3836. end,
  3837. loc,
  3838. range,
  3839. extra,
  3840. name
  3841. } = node;
  3842. const cloned = Object.create(NodePrototype);
  3843. cloned.type = type;
  3844. cloned.start = start;
  3845. cloned.end = end;
  3846. cloned.loc = loc;
  3847. cloned.range = range;
  3848. cloned.extra = extra;
  3849. cloned.name = name;
  3850. if (type === "Placeholder") {
  3851. cloned.expectedNode = node.expectedNode;
  3852. }
  3853. return cloned;
  3854. }
  3855. function cloneStringLiteral(node) {
  3856. const {
  3857. type,
  3858. start,
  3859. end,
  3860. loc,
  3861. range,
  3862. extra
  3863. } = node;
  3864. if (type === "Placeholder") {
  3865. return clonePlaceholder(node);
  3866. }
  3867. const cloned = Object.create(NodePrototype);
  3868. cloned.type = type;
  3869. cloned.start = start;
  3870. cloned.end = end;
  3871. cloned.loc = loc;
  3872. cloned.range = range;
  3873. if (node.raw !== undefined) {
  3874. cloned.raw = node.raw;
  3875. } else {
  3876. cloned.extra = extra;
  3877. }
  3878. cloned.value = node.value;
  3879. return cloned;
  3880. }
  3881. class NodeUtils extends UtilParser {
  3882. startNode() {
  3883. const loc = this.state.startLoc;
  3884. return new Node(this, loc.index, loc);
  3885. }
  3886. startNodeAt(loc) {
  3887. return new Node(this, loc.index, loc);
  3888. }
  3889. startNodeAtNode(type) {
  3890. return this.startNodeAt(type.loc.start);
  3891. }
  3892. finishNode(node, type) {
  3893. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3894. }
  3895. finishNodeAt(node, type, endLoc) {
  3896. node.type = type;
  3897. node.end = endLoc.index;
  3898. node.loc.end = endLoc;
  3899. if (this.optionFlags & 64) node.range[1] = endLoc.index;
  3900. if (this.optionFlags & 2048) {
  3901. this.processComment(node);
  3902. }
  3903. return node;
  3904. }
  3905. resetStartLocation(node, startLoc) {
  3906. node.start = startLoc.index;
  3907. node.loc.start = startLoc;
  3908. if (this.optionFlags & 64) node.range[0] = startLoc.index;
  3909. }
  3910. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3911. node.end = endLoc.index;
  3912. node.loc.end = endLoc;
  3913. if (this.optionFlags & 64) node.range[1] = endLoc.index;
  3914. }
  3915. resetStartLocationFromNode(node, locationNode) {
  3916. this.resetStartLocation(node, locationNode.loc.start);
  3917. }
  3918. }
  3919. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3920. const FlowErrors = ParseErrorEnum`flow`({
  3921. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3922. 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.",
  3923. AssignReservedType: ({
  3924. reservedType
  3925. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3926. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3927. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3928. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3929. EnumBooleanMemberNotInitialized: ({
  3930. memberName,
  3931. enumName
  3932. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3933. EnumDuplicateMemberName: ({
  3934. memberName,
  3935. enumName
  3936. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3937. EnumInconsistentMemberValues: ({
  3938. enumName
  3939. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3940. EnumInvalidExplicitType: ({
  3941. invalidEnumType,
  3942. enumName
  3943. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3944. EnumInvalidExplicitTypeUnknownSupplied: ({
  3945. enumName
  3946. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3947. EnumInvalidMemberInitializerPrimaryType: ({
  3948. enumName,
  3949. memberName,
  3950. explicitType
  3951. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3952. EnumInvalidMemberInitializerSymbolType: ({
  3953. enumName,
  3954. memberName
  3955. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3956. EnumInvalidMemberInitializerUnknownType: ({
  3957. enumName,
  3958. memberName
  3959. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3960. EnumInvalidMemberName: ({
  3961. enumName,
  3962. memberName,
  3963. suggestion
  3964. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3965. EnumNumberMemberNotInitialized: ({
  3966. enumName,
  3967. memberName
  3968. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3969. EnumStringMemberInconsistentlyInitialized: ({
  3970. enumName
  3971. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3972. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3973. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3974. 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.",
  3975. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3976. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3977. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3978. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3979. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3980. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3981. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3982. PatternIsOptional: Object.assign({
  3983. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3984. }, {
  3985. reasonCode: "OptionalBindingPattern"
  3986. }),
  3987. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3988. SpreadVariance: "Spread properties cannot have variance.",
  3989. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3990. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3991. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3992. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3993. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3994. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3995. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3996. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3997. UnexpectedReservedType: ({
  3998. reservedType
  3999. }) => `Unexpected reserved type ${reservedType}.`,
  4000. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  4001. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  4002. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  4003. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  4004. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  4005. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  4006. UnsupportedDeclareExportKind: ({
  4007. unsupportedExportKind,
  4008. suggestion
  4009. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  4010. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  4011. UnterminatedFlowComment: "Unterminated flow-comment."
  4012. });
  4013. function isEsModuleType(bodyElement) {
  4014. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  4015. }
  4016. function hasTypeImportKind(node) {
  4017. return node.importKind === "type" || node.importKind === "typeof";
  4018. }
  4019. const exportSuggestions = {
  4020. const: "declare export var",
  4021. let: "declare export var",
  4022. type: "export type",
  4023. interface: "export interface"
  4024. };
  4025. function partition(list, test) {
  4026. const list1 = [];
  4027. const list2 = [];
  4028. for (let i = 0; i < list.length; i++) {
  4029. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  4030. }
  4031. return [list1, list2];
  4032. }
  4033. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  4034. var flow = superClass => class FlowParserMixin extends superClass {
  4035. constructor(...args) {
  4036. super(...args);
  4037. this.flowPragma = undefined;
  4038. }
  4039. getScopeHandler() {
  4040. return FlowScopeHandler;
  4041. }
  4042. shouldParseTypes() {
  4043. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  4044. }
  4045. finishToken(type, val) {
  4046. if (type !== 134 && type !== 13 && type !== 28) {
  4047. if (this.flowPragma === undefined) {
  4048. this.flowPragma = null;
  4049. }
  4050. }
  4051. super.finishToken(type, val);
  4052. }
  4053. addComment(comment) {
  4054. if (this.flowPragma === undefined) {
  4055. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4056. if (!matches) ;else if (matches[1] === "flow") {
  4057. this.flowPragma = "flow";
  4058. } else if (matches[1] === "noflow") {
  4059. this.flowPragma = "noflow";
  4060. } else {
  4061. throw new Error("Unexpected flow pragma");
  4062. }
  4063. }
  4064. super.addComment(comment);
  4065. }
  4066. flowParseTypeInitialiser(tok) {
  4067. const oldInType = this.state.inType;
  4068. this.state.inType = true;
  4069. this.expect(tok || 14);
  4070. const type = this.flowParseType();
  4071. this.state.inType = oldInType;
  4072. return type;
  4073. }
  4074. flowParsePredicate() {
  4075. const node = this.startNode();
  4076. const moduloLoc = this.state.startLoc;
  4077. this.next();
  4078. this.expectContextual(110);
  4079. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  4080. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  4081. }
  4082. if (this.eat(10)) {
  4083. node.value = super.parseExpression();
  4084. this.expect(11);
  4085. return this.finishNode(node, "DeclaredPredicate");
  4086. } else {
  4087. return this.finishNode(node, "InferredPredicate");
  4088. }
  4089. }
  4090. flowParseTypeAndPredicateInitialiser() {
  4091. const oldInType = this.state.inType;
  4092. this.state.inType = true;
  4093. this.expect(14);
  4094. let type = null;
  4095. let predicate = null;
  4096. if (this.match(54)) {
  4097. this.state.inType = oldInType;
  4098. predicate = this.flowParsePredicate();
  4099. } else {
  4100. type = this.flowParseType();
  4101. this.state.inType = oldInType;
  4102. if (this.match(54)) {
  4103. predicate = this.flowParsePredicate();
  4104. }
  4105. }
  4106. return [type, predicate];
  4107. }
  4108. flowParseDeclareClass(node) {
  4109. this.next();
  4110. this.flowParseInterfaceish(node, true);
  4111. return this.finishNode(node, "DeclareClass");
  4112. }
  4113. flowParseDeclareFunction(node) {
  4114. this.next();
  4115. const id = node.id = this.parseIdentifier();
  4116. const typeNode = this.startNode();
  4117. const typeContainer = this.startNode();
  4118. if (this.match(47)) {
  4119. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4120. } else {
  4121. typeNode.typeParameters = null;
  4122. }
  4123. this.expect(10);
  4124. const tmp = this.flowParseFunctionTypeParams();
  4125. typeNode.params = tmp.params;
  4126. typeNode.rest = tmp.rest;
  4127. typeNode.this = tmp._this;
  4128. this.expect(11);
  4129. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4130. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4131. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4132. this.resetEndLocation(id);
  4133. this.semicolon();
  4134. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4135. return this.finishNode(node, "DeclareFunction");
  4136. }
  4137. flowParseDeclare(node, insideModule) {
  4138. if (this.match(80)) {
  4139. return this.flowParseDeclareClass(node);
  4140. } else if (this.match(68)) {
  4141. return this.flowParseDeclareFunction(node);
  4142. } else if (this.match(74)) {
  4143. return this.flowParseDeclareVariable(node);
  4144. } else if (this.eatContextual(127)) {
  4145. if (this.match(16)) {
  4146. return this.flowParseDeclareModuleExports(node);
  4147. } else {
  4148. if (insideModule) {
  4149. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  4150. }
  4151. return this.flowParseDeclareModule(node);
  4152. }
  4153. } else if (this.isContextual(130)) {
  4154. return this.flowParseDeclareTypeAlias(node);
  4155. } else if (this.isContextual(131)) {
  4156. return this.flowParseDeclareOpaqueType(node);
  4157. } else if (this.isContextual(129)) {
  4158. return this.flowParseDeclareInterface(node);
  4159. } else if (this.match(82)) {
  4160. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4161. } else {
  4162. this.unexpected();
  4163. }
  4164. }
  4165. flowParseDeclareVariable(node) {
  4166. this.next();
  4167. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4168. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4169. this.semicolon();
  4170. return this.finishNode(node, "DeclareVariable");
  4171. }
  4172. flowParseDeclareModule(node) {
  4173. this.scope.enter(0);
  4174. if (this.match(134)) {
  4175. node.id = super.parseExprAtom();
  4176. } else {
  4177. node.id = this.parseIdentifier();
  4178. }
  4179. const bodyNode = node.body = this.startNode();
  4180. const body = bodyNode.body = [];
  4181. this.expect(5);
  4182. while (!this.match(8)) {
  4183. let bodyNode = this.startNode();
  4184. if (this.match(83)) {
  4185. this.next();
  4186. if (!this.isContextual(130) && !this.match(87)) {
  4187. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  4188. }
  4189. super.parseImport(bodyNode);
  4190. } else {
  4191. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4192. bodyNode = this.flowParseDeclare(bodyNode, true);
  4193. }
  4194. body.push(bodyNode);
  4195. }
  4196. this.scope.exit();
  4197. this.expect(8);
  4198. this.finishNode(bodyNode, "BlockStatement");
  4199. let kind = null;
  4200. let hasModuleExport = false;
  4201. body.forEach(bodyElement => {
  4202. if (isEsModuleType(bodyElement)) {
  4203. if (kind === "CommonJS") {
  4204. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4205. }
  4206. kind = "ES";
  4207. } else if (bodyElement.type === "DeclareModuleExports") {
  4208. if (hasModuleExport) {
  4209. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  4210. }
  4211. if (kind === "ES") {
  4212. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4213. }
  4214. kind = "CommonJS";
  4215. hasModuleExport = true;
  4216. }
  4217. });
  4218. node.kind = kind || "CommonJS";
  4219. return this.finishNode(node, "DeclareModule");
  4220. }
  4221. flowParseDeclareExportDeclaration(node, insideModule) {
  4222. this.expect(82);
  4223. if (this.eat(65)) {
  4224. if (this.match(68) || this.match(80)) {
  4225. node.declaration = this.flowParseDeclare(this.startNode());
  4226. } else {
  4227. node.declaration = this.flowParseType();
  4228. this.semicolon();
  4229. }
  4230. node.default = true;
  4231. return this.finishNode(node, "DeclareExportDeclaration");
  4232. } else {
  4233. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4234. const label = this.state.value;
  4235. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  4236. unsupportedExportKind: label,
  4237. suggestion: exportSuggestions[label]
  4238. });
  4239. }
  4240. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4241. node.declaration = this.flowParseDeclare(this.startNode());
  4242. node.default = false;
  4243. return this.finishNode(node, "DeclareExportDeclaration");
  4244. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4245. node = this.parseExport(node, null);
  4246. if (node.type === "ExportNamedDeclaration") {
  4247. node.type = "ExportDeclaration";
  4248. node.default = false;
  4249. delete node.exportKind;
  4250. }
  4251. node.type = "Declare" + node.type;
  4252. return node;
  4253. }
  4254. }
  4255. this.unexpected();
  4256. }
  4257. flowParseDeclareModuleExports(node) {
  4258. this.next();
  4259. this.expectContextual(111);
  4260. node.typeAnnotation = this.flowParseTypeAnnotation();
  4261. this.semicolon();
  4262. return this.finishNode(node, "DeclareModuleExports");
  4263. }
  4264. flowParseDeclareTypeAlias(node) {
  4265. this.next();
  4266. const finished = this.flowParseTypeAlias(node);
  4267. finished.type = "DeclareTypeAlias";
  4268. return finished;
  4269. }
  4270. flowParseDeclareOpaqueType(node) {
  4271. this.next();
  4272. const finished = this.flowParseOpaqueType(node, true);
  4273. finished.type = "DeclareOpaqueType";
  4274. return finished;
  4275. }
  4276. flowParseDeclareInterface(node) {
  4277. this.next();
  4278. this.flowParseInterfaceish(node, false);
  4279. return this.finishNode(node, "DeclareInterface");
  4280. }
  4281. flowParseInterfaceish(node, isClass) {
  4282. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4283. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4284. if (this.match(47)) {
  4285. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4286. } else {
  4287. node.typeParameters = null;
  4288. }
  4289. node.extends = [];
  4290. if (this.eat(81)) {
  4291. do {
  4292. node.extends.push(this.flowParseInterfaceExtends());
  4293. } while (!isClass && this.eat(12));
  4294. }
  4295. if (isClass) {
  4296. node.implements = [];
  4297. node.mixins = [];
  4298. if (this.eatContextual(117)) {
  4299. do {
  4300. node.mixins.push(this.flowParseInterfaceExtends());
  4301. } while (this.eat(12));
  4302. }
  4303. if (this.eatContextual(113)) {
  4304. do {
  4305. node.implements.push(this.flowParseInterfaceExtends());
  4306. } while (this.eat(12));
  4307. }
  4308. }
  4309. node.body = this.flowParseObjectType({
  4310. allowStatic: isClass,
  4311. allowExact: false,
  4312. allowSpread: false,
  4313. allowProto: isClass,
  4314. allowInexact: false
  4315. });
  4316. }
  4317. flowParseInterfaceExtends() {
  4318. const node = this.startNode();
  4319. node.id = this.flowParseQualifiedTypeIdentifier();
  4320. if (this.match(47)) {
  4321. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4322. } else {
  4323. node.typeParameters = null;
  4324. }
  4325. return this.finishNode(node, "InterfaceExtends");
  4326. }
  4327. flowParseInterface(node) {
  4328. this.flowParseInterfaceish(node, false);
  4329. return this.finishNode(node, "InterfaceDeclaration");
  4330. }
  4331. checkNotUnderscore(word) {
  4332. if (word === "_") {
  4333. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  4334. }
  4335. }
  4336. checkReservedType(word, startLoc, declaration) {
  4337. if (!reservedTypes.has(word)) return;
  4338. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  4339. reservedType: word
  4340. });
  4341. }
  4342. flowParseRestrictedIdentifier(liberal, declaration) {
  4343. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4344. return this.parseIdentifier(liberal);
  4345. }
  4346. flowParseTypeAlias(node) {
  4347. node.id = this.flowParseRestrictedIdentifier(false, true);
  4348. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4349. if (this.match(47)) {
  4350. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4351. } else {
  4352. node.typeParameters = null;
  4353. }
  4354. node.right = this.flowParseTypeInitialiser(29);
  4355. this.semicolon();
  4356. return this.finishNode(node, "TypeAlias");
  4357. }
  4358. flowParseOpaqueType(node, declare) {
  4359. this.expectContextual(130);
  4360. node.id = this.flowParseRestrictedIdentifier(true, true);
  4361. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4362. if (this.match(47)) {
  4363. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4364. } else {
  4365. node.typeParameters = null;
  4366. }
  4367. node.supertype = null;
  4368. if (this.match(14)) {
  4369. node.supertype = this.flowParseTypeInitialiser(14);
  4370. }
  4371. node.impltype = null;
  4372. if (!declare) {
  4373. node.impltype = this.flowParseTypeInitialiser(29);
  4374. }
  4375. this.semicolon();
  4376. return this.finishNode(node, "OpaqueType");
  4377. }
  4378. flowParseTypeParameter(requireDefault = false) {
  4379. const nodeStartLoc = this.state.startLoc;
  4380. const node = this.startNode();
  4381. const variance = this.flowParseVariance();
  4382. const ident = this.flowParseTypeAnnotatableIdentifier();
  4383. node.name = ident.name;
  4384. node.variance = variance;
  4385. node.bound = ident.typeAnnotation;
  4386. if (this.match(29)) {
  4387. this.eat(29);
  4388. node.default = this.flowParseType();
  4389. } else {
  4390. if (requireDefault) {
  4391. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  4392. }
  4393. }
  4394. return this.finishNode(node, "TypeParameter");
  4395. }
  4396. flowParseTypeParameterDeclaration() {
  4397. const oldInType = this.state.inType;
  4398. const node = this.startNode();
  4399. node.params = [];
  4400. this.state.inType = true;
  4401. if (this.match(47) || this.match(143)) {
  4402. this.next();
  4403. } else {
  4404. this.unexpected();
  4405. }
  4406. let defaultRequired = false;
  4407. do {
  4408. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4409. node.params.push(typeParameter);
  4410. if (typeParameter.default) {
  4411. defaultRequired = true;
  4412. }
  4413. if (!this.match(48)) {
  4414. this.expect(12);
  4415. }
  4416. } while (!this.match(48));
  4417. this.expect(48);
  4418. this.state.inType = oldInType;
  4419. return this.finishNode(node, "TypeParameterDeclaration");
  4420. }
  4421. flowInTopLevelContext(cb) {
  4422. if (this.curContext() !== types.brace) {
  4423. const oldContext = this.state.context;
  4424. this.state.context = [oldContext[0]];
  4425. try {
  4426. return cb();
  4427. } finally {
  4428. this.state.context = oldContext;
  4429. }
  4430. } else {
  4431. return cb();
  4432. }
  4433. }
  4434. flowParseTypeParameterInstantiationInExpression() {
  4435. if (this.reScan_lt() !== 47) return;
  4436. return this.flowParseTypeParameterInstantiation();
  4437. }
  4438. flowParseTypeParameterInstantiation() {
  4439. const node = this.startNode();
  4440. const oldInType = this.state.inType;
  4441. this.state.inType = true;
  4442. node.params = [];
  4443. this.flowInTopLevelContext(() => {
  4444. this.expect(47);
  4445. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4446. this.state.noAnonFunctionType = false;
  4447. while (!this.match(48)) {
  4448. node.params.push(this.flowParseType());
  4449. if (!this.match(48)) {
  4450. this.expect(12);
  4451. }
  4452. }
  4453. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4454. });
  4455. this.state.inType = oldInType;
  4456. if (!this.state.inType && this.curContext() === types.brace) {
  4457. this.reScan_lt_gt();
  4458. }
  4459. this.expect(48);
  4460. return this.finishNode(node, "TypeParameterInstantiation");
  4461. }
  4462. flowParseTypeParameterInstantiationCallOrNew() {
  4463. if (this.reScan_lt() !== 47) return;
  4464. const node = this.startNode();
  4465. const oldInType = this.state.inType;
  4466. node.params = [];
  4467. this.state.inType = true;
  4468. this.expect(47);
  4469. while (!this.match(48)) {
  4470. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4471. if (!this.match(48)) {
  4472. this.expect(12);
  4473. }
  4474. }
  4475. this.expect(48);
  4476. this.state.inType = oldInType;
  4477. return this.finishNode(node, "TypeParameterInstantiation");
  4478. }
  4479. flowParseInterfaceType() {
  4480. const node = this.startNode();
  4481. this.expectContextual(129);
  4482. node.extends = [];
  4483. if (this.eat(81)) {
  4484. do {
  4485. node.extends.push(this.flowParseInterfaceExtends());
  4486. } while (this.eat(12));
  4487. }
  4488. node.body = this.flowParseObjectType({
  4489. allowStatic: false,
  4490. allowExact: false,
  4491. allowSpread: false,
  4492. allowProto: false,
  4493. allowInexact: false
  4494. });
  4495. return this.finishNode(node, "InterfaceTypeAnnotation");
  4496. }
  4497. flowParseObjectPropertyKey() {
  4498. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  4499. }
  4500. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4501. node.static = isStatic;
  4502. if (this.lookahead().type === 14) {
  4503. node.id = this.flowParseObjectPropertyKey();
  4504. node.key = this.flowParseTypeInitialiser();
  4505. } else {
  4506. node.id = null;
  4507. node.key = this.flowParseType();
  4508. }
  4509. this.expect(3);
  4510. node.value = this.flowParseTypeInitialiser();
  4511. node.variance = variance;
  4512. return this.finishNode(node, "ObjectTypeIndexer");
  4513. }
  4514. flowParseObjectTypeInternalSlot(node, isStatic) {
  4515. node.static = isStatic;
  4516. node.id = this.flowParseObjectPropertyKey();
  4517. this.expect(3);
  4518. this.expect(3);
  4519. if (this.match(47) || this.match(10)) {
  4520. node.method = true;
  4521. node.optional = false;
  4522. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4523. } else {
  4524. node.method = false;
  4525. if (this.eat(17)) {
  4526. node.optional = true;
  4527. }
  4528. node.value = this.flowParseTypeInitialiser();
  4529. }
  4530. return this.finishNode(node, "ObjectTypeInternalSlot");
  4531. }
  4532. flowParseObjectTypeMethodish(node) {
  4533. node.params = [];
  4534. node.rest = null;
  4535. node.typeParameters = null;
  4536. node.this = null;
  4537. if (this.match(47)) {
  4538. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4539. }
  4540. this.expect(10);
  4541. if (this.match(78)) {
  4542. node.this = this.flowParseFunctionTypeParam(true);
  4543. node.this.name = null;
  4544. if (!this.match(11)) {
  4545. this.expect(12);
  4546. }
  4547. }
  4548. while (!this.match(11) && !this.match(21)) {
  4549. node.params.push(this.flowParseFunctionTypeParam(false));
  4550. if (!this.match(11)) {
  4551. this.expect(12);
  4552. }
  4553. }
  4554. if (this.eat(21)) {
  4555. node.rest = this.flowParseFunctionTypeParam(false);
  4556. }
  4557. this.expect(11);
  4558. node.returnType = this.flowParseTypeInitialiser();
  4559. return this.finishNode(node, "FunctionTypeAnnotation");
  4560. }
  4561. flowParseObjectTypeCallProperty(node, isStatic) {
  4562. const valueNode = this.startNode();
  4563. node.static = isStatic;
  4564. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4565. return this.finishNode(node, "ObjectTypeCallProperty");
  4566. }
  4567. flowParseObjectType({
  4568. allowStatic,
  4569. allowExact,
  4570. allowSpread,
  4571. allowProto,
  4572. allowInexact
  4573. }) {
  4574. const oldInType = this.state.inType;
  4575. this.state.inType = true;
  4576. const nodeStart = this.startNode();
  4577. nodeStart.callProperties = [];
  4578. nodeStart.properties = [];
  4579. nodeStart.indexers = [];
  4580. nodeStart.internalSlots = [];
  4581. let endDelim;
  4582. let exact;
  4583. let inexact = false;
  4584. if (allowExact && this.match(6)) {
  4585. this.expect(6);
  4586. endDelim = 9;
  4587. exact = true;
  4588. } else {
  4589. this.expect(5);
  4590. endDelim = 8;
  4591. exact = false;
  4592. }
  4593. nodeStart.exact = exact;
  4594. while (!this.match(endDelim)) {
  4595. let isStatic = false;
  4596. let protoStartLoc = null;
  4597. let inexactStartLoc = null;
  4598. const node = this.startNode();
  4599. if (allowProto && this.isContextual(118)) {
  4600. const lookahead = this.lookahead();
  4601. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4602. this.next();
  4603. protoStartLoc = this.state.startLoc;
  4604. allowStatic = false;
  4605. }
  4606. }
  4607. if (allowStatic && this.isContextual(106)) {
  4608. const lookahead = this.lookahead();
  4609. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4610. this.next();
  4611. isStatic = true;
  4612. }
  4613. }
  4614. const variance = this.flowParseVariance();
  4615. if (this.eat(0)) {
  4616. if (protoStartLoc != null) {
  4617. this.unexpected(protoStartLoc);
  4618. }
  4619. if (this.eat(0)) {
  4620. if (variance) {
  4621. this.unexpected(variance.loc.start);
  4622. }
  4623. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4624. } else {
  4625. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4626. }
  4627. } else if (this.match(10) || this.match(47)) {
  4628. if (protoStartLoc != null) {
  4629. this.unexpected(protoStartLoc);
  4630. }
  4631. if (variance) {
  4632. this.unexpected(variance.loc.start);
  4633. }
  4634. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4635. } else {
  4636. let kind = "init";
  4637. if (this.isContextual(99) || this.isContextual(104)) {
  4638. const lookahead = this.lookahead();
  4639. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4640. kind = this.state.value;
  4641. this.next();
  4642. }
  4643. }
  4644. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4645. if (propOrInexact === null) {
  4646. inexact = true;
  4647. inexactStartLoc = this.state.lastTokStartLoc;
  4648. } else {
  4649. nodeStart.properties.push(propOrInexact);
  4650. }
  4651. }
  4652. this.flowObjectTypeSemicolon();
  4653. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4654. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  4655. }
  4656. }
  4657. this.expect(endDelim);
  4658. if (allowSpread) {
  4659. nodeStart.inexact = inexact;
  4660. }
  4661. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4662. this.state.inType = oldInType;
  4663. return out;
  4664. }
  4665. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4666. if (this.eat(21)) {
  4667. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4668. if (isInexactToken) {
  4669. if (!allowSpread) {
  4670. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  4671. } else if (!allowInexact) {
  4672. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  4673. }
  4674. if (variance) {
  4675. this.raise(FlowErrors.InexactVariance, variance);
  4676. }
  4677. return null;
  4678. }
  4679. if (!allowSpread) {
  4680. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  4681. }
  4682. if (protoStartLoc != null) {
  4683. this.unexpected(protoStartLoc);
  4684. }
  4685. if (variance) {
  4686. this.raise(FlowErrors.SpreadVariance, variance);
  4687. }
  4688. node.argument = this.flowParseType();
  4689. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4690. } else {
  4691. node.key = this.flowParseObjectPropertyKey();
  4692. node.static = isStatic;
  4693. node.proto = protoStartLoc != null;
  4694. node.kind = kind;
  4695. let optional = false;
  4696. if (this.match(47) || this.match(10)) {
  4697. node.method = true;
  4698. if (protoStartLoc != null) {
  4699. this.unexpected(protoStartLoc);
  4700. }
  4701. if (variance) {
  4702. this.unexpected(variance.loc.start);
  4703. }
  4704. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4705. if (kind === "get" || kind === "set") {
  4706. this.flowCheckGetterSetterParams(node);
  4707. }
  4708. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4709. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  4710. }
  4711. } else {
  4712. if (kind !== "init") this.unexpected();
  4713. node.method = false;
  4714. if (this.eat(17)) {
  4715. optional = true;
  4716. }
  4717. node.value = this.flowParseTypeInitialiser();
  4718. node.variance = variance;
  4719. }
  4720. node.optional = optional;
  4721. return this.finishNode(node, "ObjectTypeProperty");
  4722. }
  4723. }
  4724. flowCheckGetterSetterParams(property) {
  4725. const paramCount = property.kind === "get" ? 0 : 1;
  4726. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4727. if (property.value.this) {
  4728. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  4729. }
  4730. if (length !== paramCount) {
  4731. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  4732. }
  4733. if (property.kind === "set" && property.value.rest) {
  4734. this.raise(Errors.BadSetterRestParameter, property);
  4735. }
  4736. }
  4737. flowObjectTypeSemicolon() {
  4738. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4739. this.unexpected();
  4740. }
  4741. }
  4742. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4743. var _startLoc;
  4744. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4745. let node = id || this.flowParseRestrictedIdentifier(true);
  4746. while (this.eat(16)) {
  4747. const node2 = this.startNodeAt(startLoc);
  4748. node2.qualification = node;
  4749. node2.id = this.flowParseRestrictedIdentifier(true);
  4750. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4751. }
  4752. return node;
  4753. }
  4754. flowParseGenericType(startLoc, id) {
  4755. const node = this.startNodeAt(startLoc);
  4756. node.typeParameters = null;
  4757. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4758. if (this.match(47)) {
  4759. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4760. }
  4761. return this.finishNode(node, "GenericTypeAnnotation");
  4762. }
  4763. flowParseTypeofType() {
  4764. const node = this.startNode();
  4765. this.expect(87);
  4766. node.argument = this.flowParsePrimaryType();
  4767. return this.finishNode(node, "TypeofTypeAnnotation");
  4768. }
  4769. flowParseTupleType() {
  4770. const node = this.startNode();
  4771. node.types = [];
  4772. this.expect(0);
  4773. while (this.state.pos < this.length && !this.match(3)) {
  4774. node.types.push(this.flowParseType());
  4775. if (this.match(3)) break;
  4776. this.expect(12);
  4777. }
  4778. this.expect(3);
  4779. return this.finishNode(node, "TupleTypeAnnotation");
  4780. }
  4781. flowParseFunctionTypeParam(first) {
  4782. let name = null;
  4783. let optional = false;
  4784. let typeAnnotation = null;
  4785. const node = this.startNode();
  4786. const lh = this.lookahead();
  4787. const isThis = this.state.type === 78;
  4788. if (lh.type === 14 || lh.type === 17) {
  4789. if (isThis && !first) {
  4790. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  4791. }
  4792. name = this.parseIdentifier(isThis);
  4793. if (this.eat(17)) {
  4794. optional = true;
  4795. if (isThis) {
  4796. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  4797. }
  4798. }
  4799. typeAnnotation = this.flowParseTypeInitialiser();
  4800. } else {
  4801. typeAnnotation = this.flowParseType();
  4802. }
  4803. node.name = name;
  4804. node.optional = optional;
  4805. node.typeAnnotation = typeAnnotation;
  4806. return this.finishNode(node, "FunctionTypeParam");
  4807. }
  4808. reinterpretTypeAsFunctionTypeParam(type) {
  4809. const node = this.startNodeAt(type.loc.start);
  4810. node.name = null;
  4811. node.optional = false;
  4812. node.typeAnnotation = type;
  4813. return this.finishNode(node, "FunctionTypeParam");
  4814. }
  4815. flowParseFunctionTypeParams(params = []) {
  4816. let rest = null;
  4817. let _this = null;
  4818. if (this.match(78)) {
  4819. _this = this.flowParseFunctionTypeParam(true);
  4820. _this.name = null;
  4821. if (!this.match(11)) {
  4822. this.expect(12);
  4823. }
  4824. }
  4825. while (!this.match(11) && !this.match(21)) {
  4826. params.push(this.flowParseFunctionTypeParam(false));
  4827. if (!this.match(11)) {
  4828. this.expect(12);
  4829. }
  4830. }
  4831. if (this.eat(21)) {
  4832. rest = this.flowParseFunctionTypeParam(false);
  4833. }
  4834. return {
  4835. params,
  4836. rest,
  4837. _this
  4838. };
  4839. }
  4840. flowIdentToTypeAnnotation(startLoc, node, id) {
  4841. switch (id.name) {
  4842. case "any":
  4843. return this.finishNode(node, "AnyTypeAnnotation");
  4844. case "bool":
  4845. case "boolean":
  4846. return this.finishNode(node, "BooleanTypeAnnotation");
  4847. case "mixed":
  4848. return this.finishNode(node, "MixedTypeAnnotation");
  4849. case "empty":
  4850. return this.finishNode(node, "EmptyTypeAnnotation");
  4851. case "number":
  4852. return this.finishNode(node, "NumberTypeAnnotation");
  4853. case "string":
  4854. return this.finishNode(node, "StringTypeAnnotation");
  4855. case "symbol":
  4856. return this.finishNode(node, "SymbolTypeAnnotation");
  4857. default:
  4858. this.checkNotUnderscore(id.name);
  4859. return this.flowParseGenericType(startLoc, id);
  4860. }
  4861. }
  4862. flowParsePrimaryType() {
  4863. const startLoc = this.state.startLoc;
  4864. const node = this.startNode();
  4865. let tmp;
  4866. let type;
  4867. let isGroupedType = false;
  4868. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4869. switch (this.state.type) {
  4870. case 5:
  4871. return this.flowParseObjectType({
  4872. allowStatic: false,
  4873. allowExact: false,
  4874. allowSpread: true,
  4875. allowProto: false,
  4876. allowInexact: true
  4877. });
  4878. case 6:
  4879. return this.flowParseObjectType({
  4880. allowStatic: false,
  4881. allowExact: true,
  4882. allowSpread: true,
  4883. allowProto: false,
  4884. allowInexact: false
  4885. });
  4886. case 0:
  4887. this.state.noAnonFunctionType = false;
  4888. type = this.flowParseTupleType();
  4889. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4890. return type;
  4891. case 47:
  4892. {
  4893. const node = this.startNode();
  4894. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4895. this.expect(10);
  4896. tmp = this.flowParseFunctionTypeParams();
  4897. node.params = tmp.params;
  4898. node.rest = tmp.rest;
  4899. node.this = tmp._this;
  4900. this.expect(11);
  4901. this.expect(19);
  4902. node.returnType = this.flowParseType();
  4903. return this.finishNode(node, "FunctionTypeAnnotation");
  4904. }
  4905. case 10:
  4906. {
  4907. const node = this.startNode();
  4908. this.next();
  4909. if (!this.match(11) && !this.match(21)) {
  4910. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4911. const token = this.lookahead().type;
  4912. isGroupedType = token !== 17 && token !== 14;
  4913. } else {
  4914. isGroupedType = true;
  4915. }
  4916. }
  4917. if (isGroupedType) {
  4918. this.state.noAnonFunctionType = false;
  4919. type = this.flowParseType();
  4920. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4921. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4922. this.expect(11);
  4923. return type;
  4924. } else {
  4925. this.eat(12);
  4926. }
  4927. }
  4928. if (type) {
  4929. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4930. } else {
  4931. tmp = this.flowParseFunctionTypeParams();
  4932. }
  4933. node.params = tmp.params;
  4934. node.rest = tmp.rest;
  4935. node.this = tmp._this;
  4936. this.expect(11);
  4937. this.expect(19);
  4938. node.returnType = this.flowParseType();
  4939. node.typeParameters = null;
  4940. return this.finishNode(node, "FunctionTypeAnnotation");
  4941. }
  4942. case 134:
  4943. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4944. case 85:
  4945. case 86:
  4946. node.value = this.match(85);
  4947. this.next();
  4948. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4949. case 53:
  4950. if (this.state.value === "-") {
  4951. this.next();
  4952. if (this.match(135)) {
  4953. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4954. }
  4955. if (this.match(136)) {
  4956. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4957. }
  4958. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  4959. }
  4960. this.unexpected();
  4961. return;
  4962. case 135:
  4963. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4964. case 136:
  4965. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4966. case 88:
  4967. this.next();
  4968. return this.finishNode(node, "VoidTypeAnnotation");
  4969. case 84:
  4970. this.next();
  4971. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4972. case 78:
  4973. this.next();
  4974. return this.finishNode(node, "ThisTypeAnnotation");
  4975. case 55:
  4976. this.next();
  4977. return this.finishNode(node, "ExistsTypeAnnotation");
  4978. case 87:
  4979. return this.flowParseTypeofType();
  4980. default:
  4981. if (tokenIsKeyword(this.state.type)) {
  4982. const label = tokenLabelName(this.state.type);
  4983. this.next();
  4984. return super.createIdentifier(node, label);
  4985. } else if (tokenIsIdentifier(this.state.type)) {
  4986. if (this.isContextual(129)) {
  4987. return this.flowParseInterfaceType();
  4988. }
  4989. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4990. }
  4991. }
  4992. this.unexpected();
  4993. }
  4994. flowParsePostfixType() {
  4995. const startLoc = this.state.startLoc;
  4996. let type = this.flowParsePrimaryType();
  4997. let seenOptionalIndexedAccess = false;
  4998. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4999. const node = this.startNodeAt(startLoc);
  5000. const optional = this.eat(18);
  5001. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  5002. this.expect(0);
  5003. if (!optional && this.match(3)) {
  5004. node.elementType = type;
  5005. this.next();
  5006. type = this.finishNode(node, "ArrayTypeAnnotation");
  5007. } else {
  5008. node.objectType = type;
  5009. node.indexType = this.flowParseType();
  5010. this.expect(3);
  5011. if (seenOptionalIndexedAccess) {
  5012. node.optional = optional;
  5013. type = this.finishNode(node, "OptionalIndexedAccessType");
  5014. } else {
  5015. type = this.finishNode(node, "IndexedAccessType");
  5016. }
  5017. }
  5018. }
  5019. return type;
  5020. }
  5021. flowParsePrefixType() {
  5022. const node = this.startNode();
  5023. if (this.eat(17)) {
  5024. node.typeAnnotation = this.flowParsePrefixType();
  5025. return this.finishNode(node, "NullableTypeAnnotation");
  5026. } else {
  5027. return this.flowParsePostfixType();
  5028. }
  5029. }
  5030. flowParseAnonFunctionWithoutParens() {
  5031. const param = this.flowParsePrefixType();
  5032. if (!this.state.noAnonFunctionType && this.eat(19)) {
  5033. const node = this.startNodeAt(param.loc.start);
  5034. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  5035. node.rest = null;
  5036. node.this = null;
  5037. node.returnType = this.flowParseType();
  5038. node.typeParameters = null;
  5039. return this.finishNode(node, "FunctionTypeAnnotation");
  5040. }
  5041. return param;
  5042. }
  5043. flowParseIntersectionType() {
  5044. const node = this.startNode();
  5045. this.eat(45);
  5046. const type = this.flowParseAnonFunctionWithoutParens();
  5047. node.types = [type];
  5048. while (this.eat(45)) {
  5049. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5050. }
  5051. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5052. }
  5053. flowParseUnionType() {
  5054. const node = this.startNode();
  5055. this.eat(43);
  5056. const type = this.flowParseIntersectionType();
  5057. node.types = [type];
  5058. while (this.eat(43)) {
  5059. node.types.push(this.flowParseIntersectionType());
  5060. }
  5061. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5062. }
  5063. flowParseType() {
  5064. const oldInType = this.state.inType;
  5065. this.state.inType = true;
  5066. const type = this.flowParseUnionType();
  5067. this.state.inType = oldInType;
  5068. return type;
  5069. }
  5070. flowParseTypeOrImplicitInstantiation() {
  5071. if (this.state.type === 132 && this.state.value === "_") {
  5072. const startLoc = this.state.startLoc;
  5073. const node = this.parseIdentifier();
  5074. return this.flowParseGenericType(startLoc, node);
  5075. } else {
  5076. return this.flowParseType();
  5077. }
  5078. }
  5079. flowParseTypeAnnotation() {
  5080. const node = this.startNode();
  5081. node.typeAnnotation = this.flowParseTypeInitialiser();
  5082. return this.finishNode(node, "TypeAnnotation");
  5083. }
  5084. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5085. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5086. if (this.match(14)) {
  5087. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5088. this.resetEndLocation(ident);
  5089. }
  5090. return ident;
  5091. }
  5092. typeCastToParameter(node) {
  5093. node.expression.typeAnnotation = node.typeAnnotation;
  5094. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5095. return node.expression;
  5096. }
  5097. flowParseVariance() {
  5098. let variance = null;
  5099. if (this.match(53)) {
  5100. variance = this.startNode();
  5101. if (this.state.value === "+") {
  5102. variance.kind = "plus";
  5103. } else {
  5104. variance.kind = "minus";
  5105. }
  5106. this.next();
  5107. return this.finishNode(variance, "Variance");
  5108. }
  5109. return variance;
  5110. }
  5111. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5112. if (allowExpressionBody) {
  5113. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5114. return;
  5115. }
  5116. super.parseFunctionBody(node, false, isMethod);
  5117. }
  5118. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5119. if (this.match(14)) {
  5120. const typeNode = this.startNode();
  5121. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5122. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5123. }
  5124. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5125. }
  5126. parseStatementLike(flags) {
  5127. if (this.state.strict && this.isContextual(129)) {
  5128. const lookahead = this.lookahead();
  5129. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5130. const node = this.startNode();
  5131. this.next();
  5132. return this.flowParseInterface(node);
  5133. }
  5134. } else if (this.isContextual(126)) {
  5135. const node = this.startNode();
  5136. this.next();
  5137. return this.flowParseEnumDeclaration(node);
  5138. }
  5139. const stmt = super.parseStatementLike(flags);
  5140. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5141. this.flowPragma = null;
  5142. }
  5143. return stmt;
  5144. }
  5145. parseExpressionStatement(node, expr, decorators) {
  5146. if (expr.type === "Identifier") {
  5147. if (expr.name === "declare") {
  5148. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5149. return this.flowParseDeclare(node);
  5150. }
  5151. } else if (tokenIsIdentifier(this.state.type)) {
  5152. if (expr.name === "interface") {
  5153. return this.flowParseInterface(node);
  5154. } else if (expr.name === "type") {
  5155. return this.flowParseTypeAlias(node);
  5156. } else if (expr.name === "opaque") {
  5157. return this.flowParseOpaqueType(node, false);
  5158. }
  5159. }
  5160. }
  5161. return super.parseExpressionStatement(node, expr, decorators);
  5162. }
  5163. shouldParseExportDeclaration() {
  5164. const {
  5165. type
  5166. } = this.state;
  5167. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5168. return !this.state.containsEsc;
  5169. }
  5170. return super.shouldParseExportDeclaration();
  5171. }
  5172. isExportDefaultSpecifier() {
  5173. const {
  5174. type
  5175. } = this.state;
  5176. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5177. return this.state.containsEsc;
  5178. }
  5179. return super.isExportDefaultSpecifier();
  5180. }
  5181. parseExportDefaultExpression() {
  5182. if (this.isContextual(126)) {
  5183. const node = this.startNode();
  5184. this.next();
  5185. return this.flowParseEnumDeclaration(node);
  5186. }
  5187. return super.parseExportDefaultExpression();
  5188. }
  5189. parseConditional(expr, startLoc, refExpressionErrors) {
  5190. if (!this.match(17)) return expr;
  5191. if (this.state.maybeInArrowParameters) {
  5192. const nextCh = this.lookaheadCharCode();
  5193. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5194. this.setOptionalParametersError(refExpressionErrors);
  5195. return expr;
  5196. }
  5197. }
  5198. this.expect(17);
  5199. const state = this.state.clone();
  5200. const originalNoArrowAt = this.state.noArrowAt;
  5201. const node = this.startNodeAt(startLoc);
  5202. let {
  5203. consequent,
  5204. failed
  5205. } = this.tryParseConditionalConsequent();
  5206. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5207. if (failed || invalid.length > 0) {
  5208. const noArrowAt = [...originalNoArrowAt];
  5209. if (invalid.length > 0) {
  5210. this.state = state;
  5211. this.state.noArrowAt = noArrowAt;
  5212. for (let i = 0; i < invalid.length; i++) {
  5213. noArrowAt.push(invalid[i].start);
  5214. }
  5215. ({
  5216. consequent,
  5217. failed
  5218. } = this.tryParseConditionalConsequent());
  5219. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5220. }
  5221. if (failed && valid.length > 1) {
  5222. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  5223. }
  5224. if (failed && valid.length === 1) {
  5225. this.state = state;
  5226. noArrowAt.push(valid[0].start);
  5227. this.state.noArrowAt = noArrowAt;
  5228. ({
  5229. consequent,
  5230. failed
  5231. } = this.tryParseConditionalConsequent());
  5232. }
  5233. }
  5234. this.getArrowLikeExpressions(consequent, true);
  5235. this.state.noArrowAt = originalNoArrowAt;
  5236. this.expect(14);
  5237. node.test = expr;
  5238. node.consequent = consequent;
  5239. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5240. return this.finishNode(node, "ConditionalExpression");
  5241. }
  5242. tryParseConditionalConsequent() {
  5243. this.state.noArrowParamsConversionAt.push(this.state.start);
  5244. const consequent = this.parseMaybeAssignAllowIn();
  5245. const failed = !this.match(14);
  5246. this.state.noArrowParamsConversionAt.pop();
  5247. return {
  5248. consequent,
  5249. failed
  5250. };
  5251. }
  5252. getArrowLikeExpressions(node, disallowInvalid) {
  5253. const stack = [node];
  5254. const arrows = [];
  5255. while (stack.length !== 0) {
  5256. const node = stack.pop();
  5257. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  5258. if (node.typeParameters || !node.returnType) {
  5259. this.finishArrowValidation(node);
  5260. } else {
  5261. arrows.push(node);
  5262. }
  5263. stack.push(node.body);
  5264. } else if (node.type === "ConditionalExpression") {
  5265. stack.push(node.consequent);
  5266. stack.push(node.alternate);
  5267. }
  5268. }
  5269. if (disallowInvalid) {
  5270. arrows.forEach(node => this.finishArrowValidation(node));
  5271. return [arrows, []];
  5272. }
  5273. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5274. }
  5275. finishArrowValidation(node) {
  5276. var _node$extra;
  5277. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5278. this.scope.enter(2 | 4);
  5279. super.checkParams(node, false, true);
  5280. this.scope.exit();
  5281. }
  5282. forwardNoArrowParamsConversionAt(node, parse) {
  5283. let result;
  5284. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5285. this.state.noArrowParamsConversionAt.push(this.state.start);
  5286. result = parse();
  5287. this.state.noArrowParamsConversionAt.pop();
  5288. } else {
  5289. result = parse();
  5290. }
  5291. return result;
  5292. }
  5293. parseParenItem(node, startLoc) {
  5294. const newNode = super.parseParenItem(node, startLoc);
  5295. if (this.eat(17)) {
  5296. newNode.optional = true;
  5297. this.resetEndLocation(node);
  5298. }
  5299. if (this.match(14)) {
  5300. const typeCastNode = this.startNodeAt(startLoc);
  5301. typeCastNode.expression = newNode;
  5302. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5303. return this.finishNode(typeCastNode, "TypeCastExpression");
  5304. }
  5305. return newNode;
  5306. }
  5307. assertModuleNodeAllowed(node) {
  5308. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5309. return;
  5310. }
  5311. super.assertModuleNodeAllowed(node);
  5312. }
  5313. parseExportDeclaration(node) {
  5314. if (this.isContextual(130)) {
  5315. node.exportKind = "type";
  5316. const declarationNode = this.startNode();
  5317. this.next();
  5318. if (this.match(5)) {
  5319. node.specifiers = this.parseExportSpecifiers(true);
  5320. super.parseExportFrom(node);
  5321. return null;
  5322. } else {
  5323. return this.flowParseTypeAlias(declarationNode);
  5324. }
  5325. } else if (this.isContextual(131)) {
  5326. node.exportKind = "type";
  5327. const declarationNode = this.startNode();
  5328. this.next();
  5329. return this.flowParseOpaqueType(declarationNode, false);
  5330. } else if (this.isContextual(129)) {
  5331. node.exportKind = "type";
  5332. const declarationNode = this.startNode();
  5333. this.next();
  5334. return this.flowParseInterface(declarationNode);
  5335. } else if (this.isContextual(126)) {
  5336. node.exportKind = "value";
  5337. const declarationNode = this.startNode();
  5338. this.next();
  5339. return this.flowParseEnumDeclaration(declarationNode);
  5340. } else {
  5341. return super.parseExportDeclaration(node);
  5342. }
  5343. }
  5344. eatExportStar(node) {
  5345. if (super.eatExportStar(node)) return true;
  5346. if (this.isContextual(130) && this.lookahead().type === 55) {
  5347. node.exportKind = "type";
  5348. this.next();
  5349. this.next();
  5350. return true;
  5351. }
  5352. return false;
  5353. }
  5354. maybeParseExportNamespaceSpecifier(node) {
  5355. const {
  5356. startLoc
  5357. } = this.state;
  5358. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5359. if (hasNamespace && node.exportKind === "type") {
  5360. this.unexpected(startLoc);
  5361. }
  5362. return hasNamespace;
  5363. }
  5364. parseClassId(node, isStatement, optionalId) {
  5365. super.parseClassId(node, isStatement, optionalId);
  5366. if (this.match(47)) {
  5367. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5368. }
  5369. }
  5370. parseClassMember(classBody, member, state) {
  5371. const {
  5372. startLoc
  5373. } = this.state;
  5374. if (this.isContextual(125)) {
  5375. if (super.parseClassMemberFromModifier(classBody, member)) {
  5376. return;
  5377. }
  5378. member.declare = true;
  5379. }
  5380. super.parseClassMember(classBody, member, state);
  5381. if (member.declare) {
  5382. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5383. this.raise(FlowErrors.DeclareClassElement, startLoc);
  5384. } else if (member.value) {
  5385. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  5386. }
  5387. }
  5388. }
  5389. isIterator(word) {
  5390. return word === "iterator" || word === "asyncIterator";
  5391. }
  5392. readIterator() {
  5393. const word = super.readWord1();
  5394. const fullWord = "@@" + word;
  5395. if (!this.isIterator(word) || !this.state.inType) {
  5396. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  5397. identifierName: fullWord
  5398. });
  5399. }
  5400. this.finishToken(132, fullWord);
  5401. }
  5402. getTokenFromCode(code) {
  5403. const next = this.input.charCodeAt(this.state.pos + 1);
  5404. if (code === 123 && next === 124) {
  5405. this.finishOp(6, 2);
  5406. } else if (this.state.inType && (code === 62 || code === 60)) {
  5407. this.finishOp(code === 62 ? 48 : 47, 1);
  5408. } else if (this.state.inType && code === 63) {
  5409. if (next === 46) {
  5410. this.finishOp(18, 2);
  5411. } else {
  5412. this.finishOp(17, 1);
  5413. }
  5414. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5415. this.state.pos += 2;
  5416. this.readIterator();
  5417. } else {
  5418. super.getTokenFromCode(code);
  5419. }
  5420. }
  5421. isAssignable(node, isBinding) {
  5422. if (node.type === "TypeCastExpression") {
  5423. return this.isAssignable(node.expression, isBinding);
  5424. } else {
  5425. return super.isAssignable(node, isBinding);
  5426. }
  5427. }
  5428. toAssignable(node, isLHS = false) {
  5429. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5430. node.left = this.typeCastToParameter(node.left);
  5431. }
  5432. super.toAssignable(node, isLHS);
  5433. }
  5434. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5435. for (let i = 0; i < exprList.length; i++) {
  5436. const expr = exprList[i];
  5437. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5438. exprList[i] = this.typeCastToParameter(expr);
  5439. }
  5440. }
  5441. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5442. }
  5443. toReferencedList(exprList, isParenthesizedExpr) {
  5444. for (let i = 0; i < exprList.length; i++) {
  5445. var _expr$extra;
  5446. const expr = exprList[i];
  5447. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5448. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  5449. }
  5450. }
  5451. return exprList;
  5452. }
  5453. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5454. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5455. if (canBePattern && !this.state.maybeInArrowParameters) {
  5456. this.toReferencedList(node.elements);
  5457. }
  5458. return node;
  5459. }
  5460. isValidLVal(type, isParenthesized, binding) {
  5461. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5462. }
  5463. parseClassProperty(node) {
  5464. if (this.match(14)) {
  5465. node.typeAnnotation = this.flowParseTypeAnnotation();
  5466. }
  5467. return super.parseClassProperty(node);
  5468. }
  5469. parseClassPrivateProperty(node) {
  5470. if (this.match(14)) {
  5471. node.typeAnnotation = this.flowParseTypeAnnotation();
  5472. }
  5473. return super.parseClassPrivateProperty(node);
  5474. }
  5475. isClassMethod() {
  5476. return this.match(47) || super.isClassMethod();
  5477. }
  5478. isClassProperty() {
  5479. return this.match(14) || super.isClassProperty();
  5480. }
  5481. isNonstaticConstructor(method) {
  5482. return !this.match(14) && super.isNonstaticConstructor(method);
  5483. }
  5484. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5485. if (method.variance) {
  5486. this.unexpected(method.variance.loc.start);
  5487. }
  5488. delete method.variance;
  5489. if (this.match(47)) {
  5490. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5491. }
  5492. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5493. if (method.params && isConstructor) {
  5494. const params = method.params;
  5495. if (params.length > 0 && this.isThisParam(params[0])) {
  5496. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5497. }
  5498. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5499. const params = method.value.params;
  5500. if (params.length > 0 && this.isThisParam(params[0])) {
  5501. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5502. }
  5503. }
  5504. }
  5505. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5506. if (method.variance) {
  5507. this.unexpected(method.variance.loc.start);
  5508. }
  5509. delete method.variance;
  5510. if (this.match(47)) {
  5511. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5512. }
  5513. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5514. }
  5515. parseClassSuper(node) {
  5516. super.parseClassSuper(node);
  5517. if (node.superClass && (this.match(47) || this.match(51))) {
  5518. {
  5519. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  5520. }
  5521. }
  5522. if (this.isContextual(113)) {
  5523. this.next();
  5524. const implemented = node.implements = [];
  5525. do {
  5526. const node = this.startNode();
  5527. node.id = this.flowParseRestrictedIdentifier(true);
  5528. if (this.match(47)) {
  5529. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5530. } else {
  5531. node.typeParameters = null;
  5532. }
  5533. implemented.push(this.finishNode(node, "ClassImplements"));
  5534. } while (this.eat(12));
  5535. }
  5536. }
  5537. checkGetterSetterParams(method) {
  5538. super.checkGetterSetterParams(method);
  5539. const params = this.getObjectOrClassMethodParams(method);
  5540. if (params.length > 0) {
  5541. const param = params[0];
  5542. if (this.isThisParam(param) && method.kind === "get") {
  5543. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  5544. } else if (this.isThisParam(param)) {
  5545. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  5546. }
  5547. }
  5548. }
  5549. parsePropertyNamePrefixOperator(node) {
  5550. node.variance = this.flowParseVariance();
  5551. }
  5552. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5553. if (prop.variance) {
  5554. this.unexpected(prop.variance.loc.start);
  5555. }
  5556. delete prop.variance;
  5557. let typeParameters;
  5558. if (this.match(47) && !isAccessor) {
  5559. typeParameters = this.flowParseTypeParameterDeclaration();
  5560. if (!this.match(10)) this.unexpected();
  5561. }
  5562. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5563. if (typeParameters) {
  5564. (result.value || result).typeParameters = typeParameters;
  5565. }
  5566. return result;
  5567. }
  5568. parseFunctionParamType(param) {
  5569. if (this.eat(17)) {
  5570. if (param.type !== "Identifier") {
  5571. this.raise(FlowErrors.PatternIsOptional, param);
  5572. }
  5573. if (this.isThisParam(param)) {
  5574. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  5575. }
  5576. param.optional = true;
  5577. }
  5578. if (this.match(14)) {
  5579. param.typeAnnotation = this.flowParseTypeAnnotation();
  5580. } else if (this.isThisParam(param)) {
  5581. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  5582. }
  5583. if (this.match(29) && this.isThisParam(param)) {
  5584. this.raise(FlowErrors.ThisParamNoDefault, param);
  5585. }
  5586. this.resetEndLocation(param);
  5587. return param;
  5588. }
  5589. parseMaybeDefault(startLoc, left) {
  5590. const node = super.parseMaybeDefault(startLoc, left);
  5591. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5592. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  5593. }
  5594. return node;
  5595. }
  5596. checkImportReflection(node) {
  5597. super.checkImportReflection(node);
  5598. if (node.module && node.importKind !== "value") {
  5599. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  5600. }
  5601. }
  5602. parseImportSpecifierLocal(node, specifier, type) {
  5603. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5604. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5605. }
  5606. isPotentialImportPhase(isExport) {
  5607. if (super.isPotentialImportPhase(isExport)) return true;
  5608. if (this.isContextual(130)) {
  5609. if (!isExport) return true;
  5610. const ch = this.lookaheadCharCode();
  5611. return ch === 123 || ch === 42;
  5612. }
  5613. return !isExport && this.isContextual(87);
  5614. }
  5615. applyImportPhase(node, isExport, phase, loc) {
  5616. super.applyImportPhase(node, isExport, phase, loc);
  5617. if (isExport) {
  5618. if (!phase && this.match(65)) {
  5619. return;
  5620. }
  5621. node.exportKind = phase === "type" ? phase : "value";
  5622. } else {
  5623. if (phase === "type" && this.match(55)) this.unexpected();
  5624. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5625. }
  5626. }
  5627. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5628. const firstIdent = specifier.imported;
  5629. let specifierTypeKind = null;
  5630. if (firstIdent.type === "Identifier") {
  5631. if (firstIdent.name === "type") {
  5632. specifierTypeKind = "type";
  5633. } else if (firstIdent.name === "typeof") {
  5634. specifierTypeKind = "typeof";
  5635. }
  5636. }
  5637. let isBinding = false;
  5638. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5639. const as_ident = this.parseIdentifier(true);
  5640. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5641. specifier.imported = as_ident;
  5642. specifier.importKind = specifierTypeKind;
  5643. specifier.local = cloneIdentifier(as_ident);
  5644. } else {
  5645. specifier.imported = firstIdent;
  5646. specifier.importKind = null;
  5647. specifier.local = this.parseIdentifier();
  5648. }
  5649. } else {
  5650. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5651. specifier.imported = this.parseIdentifier(true);
  5652. specifier.importKind = specifierTypeKind;
  5653. } else {
  5654. if (importedIsString) {
  5655. throw this.raise(Errors.ImportBindingIsString, specifier, {
  5656. importName: firstIdent.value
  5657. });
  5658. }
  5659. specifier.imported = firstIdent;
  5660. specifier.importKind = null;
  5661. }
  5662. if (this.eatContextual(93)) {
  5663. specifier.local = this.parseIdentifier();
  5664. } else {
  5665. isBinding = true;
  5666. specifier.local = cloneIdentifier(specifier.imported);
  5667. }
  5668. }
  5669. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5670. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5671. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  5672. }
  5673. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5674. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5675. }
  5676. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5677. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5678. }
  5679. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5680. }
  5681. parseBindingAtom() {
  5682. switch (this.state.type) {
  5683. case 78:
  5684. return this.parseIdentifier(true);
  5685. default:
  5686. return super.parseBindingAtom();
  5687. }
  5688. }
  5689. parseFunctionParams(node, isConstructor) {
  5690. const kind = node.kind;
  5691. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5692. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5693. }
  5694. super.parseFunctionParams(node, isConstructor);
  5695. }
  5696. parseVarId(decl, kind) {
  5697. super.parseVarId(decl, kind);
  5698. if (this.match(14)) {
  5699. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5700. this.resetEndLocation(decl.id);
  5701. }
  5702. }
  5703. parseAsyncArrowFromCallExpression(node, call) {
  5704. if (this.match(14)) {
  5705. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5706. this.state.noAnonFunctionType = true;
  5707. node.returnType = this.flowParseTypeAnnotation();
  5708. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5709. }
  5710. return super.parseAsyncArrowFromCallExpression(node, call);
  5711. }
  5712. shouldParseAsyncArrow() {
  5713. return this.match(14) || super.shouldParseAsyncArrow();
  5714. }
  5715. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5716. var _jsx;
  5717. let state = null;
  5718. let jsx;
  5719. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  5720. state = this.state.clone();
  5721. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5722. if (!jsx.error) return jsx.node;
  5723. const {
  5724. context
  5725. } = this.state;
  5726. const currentContext = context[context.length - 1];
  5727. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5728. context.pop();
  5729. }
  5730. }
  5731. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5732. var _jsx2, _jsx3;
  5733. state = state || this.state.clone();
  5734. let typeParameters;
  5735. const arrow = this.tryParse(abort => {
  5736. var _arrowExpression$extr;
  5737. typeParameters = this.flowParseTypeParameterDeclaration();
  5738. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5739. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5740. this.resetStartLocationFromNode(result, typeParameters);
  5741. return result;
  5742. });
  5743. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5744. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5745. if (expr.type !== "ArrowFunctionExpression") abort();
  5746. expr.typeParameters = typeParameters;
  5747. this.resetStartLocationFromNode(expr, typeParameters);
  5748. return arrowExpression;
  5749. }, state);
  5750. let arrowExpression = null;
  5751. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5752. if (!arrow.error && !arrow.aborted) {
  5753. if (arrow.node.async) {
  5754. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  5755. }
  5756. return arrow.node;
  5757. }
  5758. arrowExpression = arrow.node;
  5759. }
  5760. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5761. this.state = jsx.failState;
  5762. return jsx.node;
  5763. }
  5764. if (arrowExpression) {
  5765. this.state = arrow.failState;
  5766. return arrowExpression;
  5767. }
  5768. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5769. if (arrow.thrown) throw arrow.error;
  5770. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  5771. }
  5772. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5773. }
  5774. parseArrow(node) {
  5775. if (this.match(14)) {
  5776. const result = this.tryParse(() => {
  5777. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5778. this.state.noAnonFunctionType = true;
  5779. const typeNode = this.startNode();
  5780. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5781. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5782. if (this.canInsertSemicolon()) this.unexpected();
  5783. if (!this.match(19)) this.unexpected();
  5784. return typeNode;
  5785. });
  5786. if (result.thrown) return null;
  5787. if (result.error) this.state = result.failState;
  5788. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5789. }
  5790. return super.parseArrow(node);
  5791. }
  5792. shouldParseArrow(params) {
  5793. return this.match(14) || super.shouldParseArrow(params);
  5794. }
  5795. setArrowFunctionParameters(node, params) {
  5796. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5797. node.params = params;
  5798. } else {
  5799. super.setArrowFunctionParameters(node, params);
  5800. }
  5801. }
  5802. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5803. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5804. return;
  5805. }
  5806. for (let i = 0; i < node.params.length; i++) {
  5807. if (this.isThisParam(node.params[i]) && i > 0) {
  5808. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  5809. }
  5810. }
  5811. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5812. }
  5813. parseParenAndDistinguishExpression(canBeArrow) {
  5814. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  5815. }
  5816. parseSubscripts(base, startLoc, noCalls) {
  5817. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  5818. this.next();
  5819. const node = this.startNodeAt(startLoc);
  5820. node.callee = base;
  5821. node.arguments = super.parseCallExpressionArguments(11);
  5822. base = this.finishNode(node, "CallExpression");
  5823. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5824. const state = this.state.clone();
  5825. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5826. if (!arrow.error && !arrow.aborted) return arrow.node;
  5827. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5828. if (result.node && !result.error) return result.node;
  5829. if (arrow.node) {
  5830. this.state = arrow.failState;
  5831. return arrow.node;
  5832. }
  5833. if (result.node) {
  5834. this.state = result.failState;
  5835. return result.node;
  5836. }
  5837. throw arrow.error || result.error;
  5838. }
  5839. return super.parseSubscripts(base, startLoc, noCalls);
  5840. }
  5841. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5842. if (this.match(18) && this.isLookaheadToken_lt()) {
  5843. subscriptState.optionalChainMember = true;
  5844. if (noCalls) {
  5845. subscriptState.stop = true;
  5846. return base;
  5847. }
  5848. this.next();
  5849. const node = this.startNodeAt(startLoc);
  5850. node.callee = base;
  5851. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  5852. this.expect(10);
  5853. node.arguments = this.parseCallExpressionArguments(11);
  5854. node.optional = true;
  5855. return this.finishCallExpression(node, true);
  5856. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  5857. const node = this.startNodeAt(startLoc);
  5858. node.callee = base;
  5859. const result = this.tryParse(() => {
  5860. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5861. this.expect(10);
  5862. node.arguments = super.parseCallExpressionArguments(11);
  5863. if (subscriptState.optionalChainMember) {
  5864. node.optional = false;
  5865. }
  5866. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5867. });
  5868. if (result.node) {
  5869. if (result.error) this.state = result.failState;
  5870. return result.node;
  5871. }
  5872. }
  5873. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5874. }
  5875. parseNewCallee(node) {
  5876. super.parseNewCallee(node);
  5877. let targs = null;
  5878. if (this.shouldParseTypes() && this.match(47)) {
  5879. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5880. }
  5881. node.typeArguments = targs;
  5882. }
  5883. parseAsyncArrowWithTypeParameters(startLoc) {
  5884. const node = this.startNodeAt(startLoc);
  5885. this.parseFunctionParams(node, false);
  5886. if (!this.parseArrow(node)) return;
  5887. return super.parseArrowExpression(node, undefined, true);
  5888. }
  5889. readToken_mult_modulo(code) {
  5890. const next = this.input.charCodeAt(this.state.pos + 1);
  5891. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5892. this.state.hasFlowComment = false;
  5893. this.state.pos += 2;
  5894. this.nextToken();
  5895. return;
  5896. }
  5897. super.readToken_mult_modulo(code);
  5898. }
  5899. readToken_pipe_amp(code) {
  5900. const next = this.input.charCodeAt(this.state.pos + 1);
  5901. if (code === 124 && next === 125) {
  5902. this.finishOp(9, 2);
  5903. return;
  5904. }
  5905. super.readToken_pipe_amp(code);
  5906. }
  5907. parseTopLevel(file, program) {
  5908. const fileNode = super.parseTopLevel(file, program);
  5909. if (this.state.hasFlowComment) {
  5910. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  5911. }
  5912. return fileNode;
  5913. }
  5914. skipBlockComment() {
  5915. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5916. if (this.state.hasFlowComment) {
  5917. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  5918. }
  5919. this.hasFlowCommentCompletion();
  5920. const commentSkip = this.skipFlowComment();
  5921. if (commentSkip) {
  5922. this.state.pos += commentSkip;
  5923. this.state.hasFlowComment = true;
  5924. }
  5925. return;
  5926. }
  5927. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5928. }
  5929. skipFlowComment() {
  5930. const {
  5931. pos
  5932. } = this.state;
  5933. let shiftToFirstNonWhiteSpace = 2;
  5934. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5935. shiftToFirstNonWhiteSpace++;
  5936. }
  5937. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5938. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5939. if (ch2 === 58 && ch3 === 58) {
  5940. return shiftToFirstNonWhiteSpace + 2;
  5941. }
  5942. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5943. return shiftToFirstNonWhiteSpace + 12;
  5944. }
  5945. if (ch2 === 58 && ch3 !== 58) {
  5946. return shiftToFirstNonWhiteSpace;
  5947. }
  5948. return false;
  5949. }
  5950. hasFlowCommentCompletion() {
  5951. const end = this.input.indexOf("*/", this.state.pos);
  5952. if (end === -1) {
  5953. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5954. }
  5955. }
  5956. flowEnumErrorBooleanMemberNotInitialized(loc, {
  5957. enumName,
  5958. memberName
  5959. }) {
  5960. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  5961. memberName,
  5962. enumName
  5963. });
  5964. }
  5965. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  5966. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  5967. }
  5968. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  5969. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  5970. }
  5971. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  5972. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  5973. }
  5974. flowEnumMemberInit() {
  5975. const startLoc = this.state.startLoc;
  5976. const endOfInit = () => this.match(12) || this.match(8);
  5977. switch (this.state.type) {
  5978. case 135:
  5979. {
  5980. const literal = this.parseNumericLiteral(this.state.value);
  5981. if (endOfInit()) {
  5982. return {
  5983. type: "number",
  5984. loc: literal.loc.start,
  5985. value: literal
  5986. };
  5987. }
  5988. return {
  5989. type: "invalid",
  5990. loc: startLoc
  5991. };
  5992. }
  5993. case 134:
  5994. {
  5995. const literal = this.parseStringLiteral(this.state.value);
  5996. if (endOfInit()) {
  5997. return {
  5998. type: "string",
  5999. loc: literal.loc.start,
  6000. value: literal
  6001. };
  6002. }
  6003. return {
  6004. type: "invalid",
  6005. loc: startLoc
  6006. };
  6007. }
  6008. case 85:
  6009. case 86:
  6010. {
  6011. const literal = this.parseBooleanLiteral(this.match(85));
  6012. if (endOfInit()) {
  6013. return {
  6014. type: "boolean",
  6015. loc: literal.loc.start,
  6016. value: literal
  6017. };
  6018. }
  6019. return {
  6020. type: "invalid",
  6021. loc: startLoc
  6022. };
  6023. }
  6024. default:
  6025. return {
  6026. type: "invalid",
  6027. loc: startLoc
  6028. };
  6029. }
  6030. }
  6031. flowEnumMemberRaw() {
  6032. const loc = this.state.startLoc;
  6033. const id = this.parseIdentifier(true);
  6034. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6035. type: "none",
  6036. loc
  6037. };
  6038. return {
  6039. id,
  6040. init
  6041. };
  6042. }
  6043. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6044. const {
  6045. explicitType
  6046. } = context;
  6047. if (explicitType === null) {
  6048. return;
  6049. }
  6050. if (explicitType !== expectedType) {
  6051. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6052. }
  6053. }
  6054. flowEnumMembers({
  6055. enumName,
  6056. explicitType
  6057. }) {
  6058. const seenNames = new Set();
  6059. const members = {
  6060. booleanMembers: [],
  6061. numberMembers: [],
  6062. stringMembers: [],
  6063. defaultedMembers: []
  6064. };
  6065. let hasUnknownMembers = false;
  6066. while (!this.match(8)) {
  6067. if (this.eat(21)) {
  6068. hasUnknownMembers = true;
  6069. break;
  6070. }
  6071. const memberNode = this.startNode();
  6072. const {
  6073. id,
  6074. init
  6075. } = this.flowEnumMemberRaw();
  6076. const memberName = id.name;
  6077. if (memberName === "") {
  6078. continue;
  6079. }
  6080. if (/^[a-z]/.test(memberName)) {
  6081. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  6082. memberName,
  6083. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6084. enumName
  6085. });
  6086. }
  6087. if (seenNames.has(memberName)) {
  6088. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  6089. memberName,
  6090. enumName
  6091. });
  6092. }
  6093. seenNames.add(memberName);
  6094. const context = {
  6095. enumName,
  6096. explicitType,
  6097. memberName
  6098. };
  6099. memberNode.id = id;
  6100. switch (init.type) {
  6101. case "boolean":
  6102. {
  6103. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6104. memberNode.init = init.value;
  6105. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6106. break;
  6107. }
  6108. case "number":
  6109. {
  6110. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6111. memberNode.init = init.value;
  6112. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6113. break;
  6114. }
  6115. case "string":
  6116. {
  6117. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6118. memberNode.init = init.value;
  6119. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6120. break;
  6121. }
  6122. case "invalid":
  6123. {
  6124. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6125. }
  6126. case "none":
  6127. {
  6128. switch (explicitType) {
  6129. case "boolean":
  6130. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6131. break;
  6132. case "number":
  6133. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6134. break;
  6135. default:
  6136. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6137. }
  6138. }
  6139. }
  6140. if (!this.match(8)) {
  6141. this.expect(12);
  6142. }
  6143. }
  6144. return {
  6145. members,
  6146. hasUnknownMembers
  6147. };
  6148. }
  6149. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6150. enumName
  6151. }) {
  6152. if (initializedMembers.length === 0) {
  6153. return defaultedMembers;
  6154. } else if (defaultedMembers.length === 0) {
  6155. return initializedMembers;
  6156. } else if (defaultedMembers.length > initializedMembers.length) {
  6157. for (const member of initializedMembers) {
  6158. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6159. enumName
  6160. });
  6161. }
  6162. return defaultedMembers;
  6163. } else {
  6164. for (const member of defaultedMembers) {
  6165. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6166. enumName
  6167. });
  6168. }
  6169. return initializedMembers;
  6170. }
  6171. }
  6172. flowEnumParseExplicitType({
  6173. enumName
  6174. }) {
  6175. if (!this.eatContextual(102)) return null;
  6176. if (!tokenIsIdentifier(this.state.type)) {
  6177. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  6178. enumName
  6179. });
  6180. }
  6181. const {
  6182. value
  6183. } = this.state;
  6184. this.next();
  6185. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6186. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  6187. enumName,
  6188. invalidEnumType: value
  6189. });
  6190. }
  6191. return value;
  6192. }
  6193. flowEnumBody(node, id) {
  6194. const enumName = id.name;
  6195. const nameLoc = id.loc.start;
  6196. const explicitType = this.flowEnumParseExplicitType({
  6197. enumName
  6198. });
  6199. this.expect(5);
  6200. const {
  6201. members,
  6202. hasUnknownMembers
  6203. } = this.flowEnumMembers({
  6204. enumName,
  6205. explicitType
  6206. });
  6207. node.hasUnknownMembers = hasUnknownMembers;
  6208. switch (explicitType) {
  6209. case "boolean":
  6210. node.explicitType = true;
  6211. node.members = members.booleanMembers;
  6212. this.expect(8);
  6213. return this.finishNode(node, "EnumBooleanBody");
  6214. case "number":
  6215. node.explicitType = true;
  6216. node.members = members.numberMembers;
  6217. this.expect(8);
  6218. return this.finishNode(node, "EnumNumberBody");
  6219. case "string":
  6220. node.explicitType = true;
  6221. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6222. enumName
  6223. });
  6224. this.expect(8);
  6225. return this.finishNode(node, "EnumStringBody");
  6226. case "symbol":
  6227. node.members = members.defaultedMembers;
  6228. this.expect(8);
  6229. return this.finishNode(node, "EnumSymbolBody");
  6230. default:
  6231. {
  6232. const empty = () => {
  6233. node.members = [];
  6234. this.expect(8);
  6235. return this.finishNode(node, "EnumStringBody");
  6236. };
  6237. node.explicitType = false;
  6238. const boolsLen = members.booleanMembers.length;
  6239. const numsLen = members.numberMembers.length;
  6240. const strsLen = members.stringMembers.length;
  6241. const defaultedLen = members.defaultedMembers.length;
  6242. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6243. return empty();
  6244. } else if (!boolsLen && !numsLen) {
  6245. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6246. enumName
  6247. });
  6248. this.expect(8);
  6249. return this.finishNode(node, "EnumStringBody");
  6250. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6251. for (const member of members.defaultedMembers) {
  6252. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6253. enumName,
  6254. memberName: member.id.name
  6255. });
  6256. }
  6257. node.members = members.booleanMembers;
  6258. this.expect(8);
  6259. return this.finishNode(node, "EnumBooleanBody");
  6260. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6261. for (const member of members.defaultedMembers) {
  6262. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6263. enumName,
  6264. memberName: member.id.name
  6265. });
  6266. }
  6267. node.members = members.numberMembers;
  6268. this.expect(8);
  6269. return this.finishNode(node, "EnumNumberBody");
  6270. } else {
  6271. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  6272. enumName
  6273. });
  6274. return empty();
  6275. }
  6276. }
  6277. }
  6278. }
  6279. flowParseEnumDeclaration(node) {
  6280. const id = this.parseIdentifier();
  6281. node.id = id;
  6282. node.body = this.flowEnumBody(this.startNode(), id);
  6283. return this.finishNode(node, "EnumDeclaration");
  6284. }
  6285. jsxParseOpeningElementAfterName(node) {
  6286. if (this.shouldParseTypes()) {
  6287. if (this.match(47) || this.match(51)) {
  6288. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  6289. }
  6290. }
  6291. return super.jsxParseOpeningElementAfterName(node);
  6292. }
  6293. isLookaheadToken_lt() {
  6294. const next = this.nextTokenStart();
  6295. if (this.input.charCodeAt(next) === 60) {
  6296. const afterNext = this.input.charCodeAt(next + 1);
  6297. return afterNext !== 60 && afterNext !== 61;
  6298. }
  6299. return false;
  6300. }
  6301. reScan_lt_gt() {
  6302. const {
  6303. type
  6304. } = this.state;
  6305. if (type === 47) {
  6306. this.state.pos -= 1;
  6307. this.readToken_lt();
  6308. } else if (type === 48) {
  6309. this.state.pos -= 1;
  6310. this.readToken_gt();
  6311. }
  6312. }
  6313. reScan_lt() {
  6314. const {
  6315. type
  6316. } = this.state;
  6317. if (type === 51) {
  6318. this.state.pos -= 2;
  6319. this.finishOp(47, 1);
  6320. return 47;
  6321. }
  6322. return type;
  6323. }
  6324. maybeUnwrapTypeCastExpression(node) {
  6325. return node.type === "TypeCastExpression" ? node.expression : node;
  6326. }
  6327. };
  6328. const entities = {
  6329. __proto__: null,
  6330. quot: "\u0022",
  6331. amp: "&",
  6332. apos: "\u0027",
  6333. lt: "<",
  6334. gt: ">",
  6335. nbsp: "\u00A0",
  6336. iexcl: "\u00A1",
  6337. cent: "\u00A2",
  6338. pound: "\u00A3",
  6339. curren: "\u00A4",
  6340. yen: "\u00A5",
  6341. brvbar: "\u00A6",
  6342. sect: "\u00A7",
  6343. uml: "\u00A8",
  6344. copy: "\u00A9",
  6345. ordf: "\u00AA",
  6346. laquo: "\u00AB",
  6347. not: "\u00AC",
  6348. shy: "\u00AD",
  6349. reg: "\u00AE",
  6350. macr: "\u00AF",
  6351. deg: "\u00B0",
  6352. plusmn: "\u00B1",
  6353. sup2: "\u00B2",
  6354. sup3: "\u00B3",
  6355. acute: "\u00B4",
  6356. micro: "\u00B5",
  6357. para: "\u00B6",
  6358. middot: "\u00B7",
  6359. cedil: "\u00B8",
  6360. sup1: "\u00B9",
  6361. ordm: "\u00BA",
  6362. raquo: "\u00BB",
  6363. frac14: "\u00BC",
  6364. frac12: "\u00BD",
  6365. frac34: "\u00BE",
  6366. iquest: "\u00BF",
  6367. Agrave: "\u00C0",
  6368. Aacute: "\u00C1",
  6369. Acirc: "\u00C2",
  6370. Atilde: "\u00C3",
  6371. Auml: "\u00C4",
  6372. Aring: "\u00C5",
  6373. AElig: "\u00C6",
  6374. Ccedil: "\u00C7",
  6375. Egrave: "\u00C8",
  6376. Eacute: "\u00C9",
  6377. Ecirc: "\u00CA",
  6378. Euml: "\u00CB",
  6379. Igrave: "\u00CC",
  6380. Iacute: "\u00CD",
  6381. Icirc: "\u00CE",
  6382. Iuml: "\u00CF",
  6383. ETH: "\u00D0",
  6384. Ntilde: "\u00D1",
  6385. Ograve: "\u00D2",
  6386. Oacute: "\u00D3",
  6387. Ocirc: "\u00D4",
  6388. Otilde: "\u00D5",
  6389. Ouml: "\u00D6",
  6390. times: "\u00D7",
  6391. Oslash: "\u00D8",
  6392. Ugrave: "\u00D9",
  6393. Uacute: "\u00DA",
  6394. Ucirc: "\u00DB",
  6395. Uuml: "\u00DC",
  6396. Yacute: "\u00DD",
  6397. THORN: "\u00DE",
  6398. szlig: "\u00DF",
  6399. agrave: "\u00E0",
  6400. aacute: "\u00E1",
  6401. acirc: "\u00E2",
  6402. atilde: "\u00E3",
  6403. auml: "\u00E4",
  6404. aring: "\u00E5",
  6405. aelig: "\u00E6",
  6406. ccedil: "\u00E7",
  6407. egrave: "\u00E8",
  6408. eacute: "\u00E9",
  6409. ecirc: "\u00EA",
  6410. euml: "\u00EB",
  6411. igrave: "\u00EC",
  6412. iacute: "\u00ED",
  6413. icirc: "\u00EE",
  6414. iuml: "\u00EF",
  6415. eth: "\u00F0",
  6416. ntilde: "\u00F1",
  6417. ograve: "\u00F2",
  6418. oacute: "\u00F3",
  6419. ocirc: "\u00F4",
  6420. otilde: "\u00F5",
  6421. ouml: "\u00F6",
  6422. divide: "\u00F7",
  6423. oslash: "\u00F8",
  6424. ugrave: "\u00F9",
  6425. uacute: "\u00FA",
  6426. ucirc: "\u00FB",
  6427. uuml: "\u00FC",
  6428. yacute: "\u00FD",
  6429. thorn: "\u00FE",
  6430. yuml: "\u00FF",
  6431. OElig: "\u0152",
  6432. oelig: "\u0153",
  6433. Scaron: "\u0160",
  6434. scaron: "\u0161",
  6435. Yuml: "\u0178",
  6436. fnof: "\u0192",
  6437. circ: "\u02C6",
  6438. tilde: "\u02DC",
  6439. Alpha: "\u0391",
  6440. Beta: "\u0392",
  6441. Gamma: "\u0393",
  6442. Delta: "\u0394",
  6443. Epsilon: "\u0395",
  6444. Zeta: "\u0396",
  6445. Eta: "\u0397",
  6446. Theta: "\u0398",
  6447. Iota: "\u0399",
  6448. Kappa: "\u039A",
  6449. Lambda: "\u039B",
  6450. Mu: "\u039C",
  6451. Nu: "\u039D",
  6452. Xi: "\u039E",
  6453. Omicron: "\u039F",
  6454. Pi: "\u03A0",
  6455. Rho: "\u03A1",
  6456. Sigma: "\u03A3",
  6457. Tau: "\u03A4",
  6458. Upsilon: "\u03A5",
  6459. Phi: "\u03A6",
  6460. Chi: "\u03A7",
  6461. Psi: "\u03A8",
  6462. Omega: "\u03A9",
  6463. alpha: "\u03B1",
  6464. beta: "\u03B2",
  6465. gamma: "\u03B3",
  6466. delta: "\u03B4",
  6467. epsilon: "\u03B5",
  6468. zeta: "\u03B6",
  6469. eta: "\u03B7",
  6470. theta: "\u03B8",
  6471. iota: "\u03B9",
  6472. kappa: "\u03BA",
  6473. lambda: "\u03BB",
  6474. mu: "\u03BC",
  6475. nu: "\u03BD",
  6476. xi: "\u03BE",
  6477. omicron: "\u03BF",
  6478. pi: "\u03C0",
  6479. rho: "\u03C1",
  6480. sigmaf: "\u03C2",
  6481. sigma: "\u03C3",
  6482. tau: "\u03C4",
  6483. upsilon: "\u03C5",
  6484. phi: "\u03C6",
  6485. chi: "\u03C7",
  6486. psi: "\u03C8",
  6487. omega: "\u03C9",
  6488. thetasym: "\u03D1",
  6489. upsih: "\u03D2",
  6490. piv: "\u03D6",
  6491. ensp: "\u2002",
  6492. emsp: "\u2003",
  6493. thinsp: "\u2009",
  6494. zwnj: "\u200C",
  6495. zwj: "\u200D",
  6496. lrm: "\u200E",
  6497. rlm: "\u200F",
  6498. ndash: "\u2013",
  6499. mdash: "\u2014",
  6500. lsquo: "\u2018",
  6501. rsquo: "\u2019",
  6502. sbquo: "\u201A",
  6503. ldquo: "\u201C",
  6504. rdquo: "\u201D",
  6505. bdquo: "\u201E",
  6506. dagger: "\u2020",
  6507. Dagger: "\u2021",
  6508. bull: "\u2022",
  6509. hellip: "\u2026",
  6510. permil: "\u2030",
  6511. prime: "\u2032",
  6512. Prime: "\u2033",
  6513. lsaquo: "\u2039",
  6514. rsaquo: "\u203A",
  6515. oline: "\u203E",
  6516. frasl: "\u2044",
  6517. euro: "\u20AC",
  6518. image: "\u2111",
  6519. weierp: "\u2118",
  6520. real: "\u211C",
  6521. trade: "\u2122",
  6522. alefsym: "\u2135",
  6523. larr: "\u2190",
  6524. uarr: "\u2191",
  6525. rarr: "\u2192",
  6526. darr: "\u2193",
  6527. harr: "\u2194",
  6528. crarr: "\u21B5",
  6529. lArr: "\u21D0",
  6530. uArr: "\u21D1",
  6531. rArr: "\u21D2",
  6532. dArr: "\u21D3",
  6533. hArr: "\u21D4",
  6534. forall: "\u2200",
  6535. part: "\u2202",
  6536. exist: "\u2203",
  6537. empty: "\u2205",
  6538. nabla: "\u2207",
  6539. isin: "\u2208",
  6540. notin: "\u2209",
  6541. ni: "\u220B",
  6542. prod: "\u220F",
  6543. sum: "\u2211",
  6544. minus: "\u2212",
  6545. lowast: "\u2217",
  6546. radic: "\u221A",
  6547. prop: "\u221D",
  6548. infin: "\u221E",
  6549. ang: "\u2220",
  6550. and: "\u2227",
  6551. or: "\u2228",
  6552. cap: "\u2229",
  6553. cup: "\u222A",
  6554. int: "\u222B",
  6555. there4: "\u2234",
  6556. sim: "\u223C",
  6557. cong: "\u2245",
  6558. asymp: "\u2248",
  6559. ne: "\u2260",
  6560. equiv: "\u2261",
  6561. le: "\u2264",
  6562. ge: "\u2265",
  6563. sub: "\u2282",
  6564. sup: "\u2283",
  6565. nsub: "\u2284",
  6566. sube: "\u2286",
  6567. supe: "\u2287",
  6568. oplus: "\u2295",
  6569. otimes: "\u2297",
  6570. perp: "\u22A5",
  6571. sdot: "\u22C5",
  6572. lceil: "\u2308",
  6573. rceil: "\u2309",
  6574. lfloor: "\u230A",
  6575. rfloor: "\u230B",
  6576. lang: "\u2329",
  6577. rang: "\u232A",
  6578. loz: "\u25CA",
  6579. spades: "\u2660",
  6580. clubs: "\u2663",
  6581. hearts: "\u2665",
  6582. diams: "\u2666"
  6583. };
  6584. const JsxErrors = ParseErrorEnum`jsx`({
  6585. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6586. MissingClosingTagElement: ({
  6587. openingTagName
  6588. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6589. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6590. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6591. UnexpectedToken: ({
  6592. unexpected,
  6593. HTMLEntity
  6594. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6595. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6596. UnterminatedJsxContent: "Unterminated JSX contents.",
  6597. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6598. });
  6599. function isFragment(object) {
  6600. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6601. }
  6602. function getQualifiedJSXName(object) {
  6603. if (object.type === "JSXIdentifier") {
  6604. return object.name;
  6605. }
  6606. if (object.type === "JSXNamespacedName") {
  6607. return object.namespace.name + ":" + object.name.name;
  6608. }
  6609. if (object.type === "JSXMemberExpression") {
  6610. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6611. }
  6612. throw new Error("Node had unexpected type: " + object.type);
  6613. }
  6614. var jsx = superClass => class JSXParserMixin extends superClass {
  6615. jsxReadToken() {
  6616. let out = "";
  6617. let chunkStart = this.state.pos;
  6618. for (;;) {
  6619. if (this.state.pos >= this.length) {
  6620. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  6621. }
  6622. const ch = this.input.charCodeAt(this.state.pos);
  6623. switch (ch) {
  6624. case 60:
  6625. case 123:
  6626. if (this.state.pos === this.state.start) {
  6627. if (ch === 60 && this.state.canStartJSXElement) {
  6628. ++this.state.pos;
  6629. this.finishToken(143);
  6630. } else {
  6631. super.getTokenFromCode(ch);
  6632. }
  6633. return;
  6634. }
  6635. out += this.input.slice(chunkStart, this.state.pos);
  6636. this.finishToken(142, out);
  6637. return;
  6638. case 38:
  6639. out += this.input.slice(chunkStart, this.state.pos);
  6640. out += this.jsxReadEntity();
  6641. chunkStart = this.state.pos;
  6642. break;
  6643. case 62:
  6644. case 125:
  6645. default:
  6646. if (isNewLine(ch)) {
  6647. out += this.input.slice(chunkStart, this.state.pos);
  6648. out += this.jsxReadNewLine(true);
  6649. chunkStart = this.state.pos;
  6650. } else {
  6651. ++this.state.pos;
  6652. }
  6653. }
  6654. }
  6655. }
  6656. jsxReadNewLine(normalizeCRLF) {
  6657. const ch = this.input.charCodeAt(this.state.pos);
  6658. let out;
  6659. ++this.state.pos;
  6660. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6661. ++this.state.pos;
  6662. out = normalizeCRLF ? "\n" : "\r\n";
  6663. } else {
  6664. out = String.fromCharCode(ch);
  6665. }
  6666. ++this.state.curLine;
  6667. this.state.lineStart = this.state.pos;
  6668. return out;
  6669. }
  6670. jsxReadString(quote) {
  6671. let out = "";
  6672. let chunkStart = ++this.state.pos;
  6673. for (;;) {
  6674. if (this.state.pos >= this.length) {
  6675. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  6676. }
  6677. const ch = this.input.charCodeAt(this.state.pos);
  6678. if (ch === quote) break;
  6679. if (ch === 38) {
  6680. out += this.input.slice(chunkStart, this.state.pos);
  6681. out += this.jsxReadEntity();
  6682. chunkStart = this.state.pos;
  6683. } else if (isNewLine(ch)) {
  6684. out += this.input.slice(chunkStart, this.state.pos);
  6685. out += this.jsxReadNewLine(false);
  6686. chunkStart = this.state.pos;
  6687. } else {
  6688. ++this.state.pos;
  6689. }
  6690. }
  6691. out += this.input.slice(chunkStart, this.state.pos++);
  6692. this.finishToken(134, out);
  6693. }
  6694. jsxReadEntity() {
  6695. const startPos = ++this.state.pos;
  6696. if (this.codePointAtPos(this.state.pos) === 35) {
  6697. ++this.state.pos;
  6698. let radix = 10;
  6699. if (this.codePointAtPos(this.state.pos) === 120) {
  6700. radix = 16;
  6701. ++this.state.pos;
  6702. }
  6703. const codePoint = this.readInt(radix, undefined, false, "bail");
  6704. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6705. ++this.state.pos;
  6706. return String.fromCodePoint(codePoint);
  6707. }
  6708. } else {
  6709. let count = 0;
  6710. let semi = false;
  6711. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  6712. ++this.state.pos;
  6713. }
  6714. if (semi) {
  6715. const desc = this.input.slice(startPos, this.state.pos);
  6716. const entity = entities[desc];
  6717. ++this.state.pos;
  6718. if (entity) {
  6719. return entity;
  6720. }
  6721. }
  6722. }
  6723. this.state.pos = startPos;
  6724. return "&";
  6725. }
  6726. jsxReadWord() {
  6727. let ch;
  6728. const start = this.state.pos;
  6729. do {
  6730. ch = this.input.charCodeAt(++this.state.pos);
  6731. } while (isIdentifierChar(ch) || ch === 45);
  6732. this.finishToken(141, this.input.slice(start, this.state.pos));
  6733. }
  6734. jsxParseIdentifier() {
  6735. const node = this.startNode();
  6736. if (this.match(141)) {
  6737. node.name = this.state.value;
  6738. } else if (tokenIsKeyword(this.state.type)) {
  6739. node.name = tokenLabelName(this.state.type);
  6740. } else {
  6741. this.unexpected();
  6742. }
  6743. this.next();
  6744. return this.finishNode(node, "JSXIdentifier");
  6745. }
  6746. jsxParseNamespacedName() {
  6747. const startLoc = this.state.startLoc;
  6748. const name = this.jsxParseIdentifier();
  6749. if (!this.eat(14)) return name;
  6750. const node = this.startNodeAt(startLoc);
  6751. node.namespace = name;
  6752. node.name = this.jsxParseIdentifier();
  6753. return this.finishNode(node, "JSXNamespacedName");
  6754. }
  6755. jsxParseElementName() {
  6756. const startLoc = this.state.startLoc;
  6757. let node = this.jsxParseNamespacedName();
  6758. if (node.type === "JSXNamespacedName") {
  6759. return node;
  6760. }
  6761. while (this.eat(16)) {
  6762. const newNode = this.startNodeAt(startLoc);
  6763. newNode.object = node;
  6764. newNode.property = this.jsxParseIdentifier();
  6765. node = this.finishNode(newNode, "JSXMemberExpression");
  6766. }
  6767. return node;
  6768. }
  6769. jsxParseAttributeValue() {
  6770. let node;
  6771. switch (this.state.type) {
  6772. case 5:
  6773. node = this.startNode();
  6774. this.setContext(types.brace);
  6775. this.next();
  6776. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6777. if (node.expression.type === "JSXEmptyExpression") {
  6778. this.raise(JsxErrors.AttributeIsEmpty, node);
  6779. }
  6780. return node;
  6781. case 143:
  6782. case 134:
  6783. return this.parseExprAtom();
  6784. default:
  6785. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  6786. }
  6787. }
  6788. jsxParseEmptyExpression() {
  6789. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6790. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6791. }
  6792. jsxParseSpreadChild(node) {
  6793. this.next();
  6794. node.expression = this.parseExpression();
  6795. this.setContext(types.j_expr);
  6796. this.state.canStartJSXElement = true;
  6797. this.expect(8);
  6798. return this.finishNode(node, "JSXSpreadChild");
  6799. }
  6800. jsxParseExpressionContainer(node, previousContext) {
  6801. if (this.match(8)) {
  6802. node.expression = this.jsxParseEmptyExpression();
  6803. } else {
  6804. const expression = this.parseExpression();
  6805. node.expression = expression;
  6806. }
  6807. this.setContext(previousContext);
  6808. this.state.canStartJSXElement = true;
  6809. this.expect(8);
  6810. return this.finishNode(node, "JSXExpressionContainer");
  6811. }
  6812. jsxParseAttribute() {
  6813. const node = this.startNode();
  6814. if (this.match(5)) {
  6815. this.setContext(types.brace);
  6816. this.next();
  6817. this.expect(21);
  6818. node.argument = this.parseMaybeAssignAllowIn();
  6819. this.setContext(types.j_oTag);
  6820. this.state.canStartJSXElement = true;
  6821. this.expect(8);
  6822. return this.finishNode(node, "JSXSpreadAttribute");
  6823. }
  6824. node.name = this.jsxParseNamespacedName();
  6825. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6826. return this.finishNode(node, "JSXAttribute");
  6827. }
  6828. jsxParseOpeningElementAt(startLoc) {
  6829. const node = this.startNodeAt(startLoc);
  6830. if (this.eat(144)) {
  6831. return this.finishNode(node, "JSXOpeningFragment");
  6832. }
  6833. node.name = this.jsxParseElementName();
  6834. return this.jsxParseOpeningElementAfterName(node);
  6835. }
  6836. jsxParseOpeningElementAfterName(node) {
  6837. const attributes = [];
  6838. while (!this.match(56) && !this.match(144)) {
  6839. attributes.push(this.jsxParseAttribute());
  6840. }
  6841. node.attributes = attributes;
  6842. node.selfClosing = this.eat(56);
  6843. this.expect(144);
  6844. return this.finishNode(node, "JSXOpeningElement");
  6845. }
  6846. jsxParseClosingElementAt(startLoc) {
  6847. const node = this.startNodeAt(startLoc);
  6848. if (this.eat(144)) {
  6849. return this.finishNode(node, "JSXClosingFragment");
  6850. }
  6851. node.name = this.jsxParseElementName();
  6852. this.expect(144);
  6853. return this.finishNode(node, "JSXClosingElement");
  6854. }
  6855. jsxParseElementAt(startLoc) {
  6856. const node = this.startNodeAt(startLoc);
  6857. const children = [];
  6858. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6859. let closingElement = null;
  6860. if (!openingElement.selfClosing) {
  6861. contents: for (;;) {
  6862. switch (this.state.type) {
  6863. case 143:
  6864. startLoc = this.state.startLoc;
  6865. this.next();
  6866. if (this.eat(56)) {
  6867. closingElement = this.jsxParseClosingElementAt(startLoc);
  6868. break contents;
  6869. }
  6870. children.push(this.jsxParseElementAt(startLoc));
  6871. break;
  6872. case 142:
  6873. children.push(this.parseLiteral(this.state.value, "JSXText"));
  6874. break;
  6875. case 5:
  6876. {
  6877. const node = this.startNode();
  6878. this.setContext(types.brace);
  6879. this.next();
  6880. if (this.match(21)) {
  6881. children.push(this.jsxParseSpreadChild(node));
  6882. } else {
  6883. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6884. }
  6885. break;
  6886. }
  6887. default:
  6888. this.unexpected();
  6889. }
  6890. }
  6891. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6892. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  6893. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6894. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  6895. openingTagName: getQualifiedJSXName(openingElement.name)
  6896. });
  6897. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6898. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6899. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  6900. openingTagName: getQualifiedJSXName(openingElement.name)
  6901. });
  6902. }
  6903. }
  6904. }
  6905. if (isFragment(openingElement)) {
  6906. node.openingFragment = openingElement;
  6907. node.closingFragment = closingElement;
  6908. } else {
  6909. node.openingElement = openingElement;
  6910. node.closingElement = closingElement;
  6911. }
  6912. node.children = children;
  6913. if (this.match(47)) {
  6914. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  6915. }
  6916. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6917. }
  6918. jsxParseElement() {
  6919. const startLoc = this.state.startLoc;
  6920. this.next();
  6921. return this.jsxParseElementAt(startLoc);
  6922. }
  6923. setContext(newContext) {
  6924. const {
  6925. context
  6926. } = this.state;
  6927. context[context.length - 1] = newContext;
  6928. }
  6929. parseExprAtom(refExpressionErrors) {
  6930. if (this.match(143)) {
  6931. return this.jsxParseElement();
  6932. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  6933. this.replaceToken(143);
  6934. return this.jsxParseElement();
  6935. } else {
  6936. return super.parseExprAtom(refExpressionErrors);
  6937. }
  6938. }
  6939. skipSpace() {
  6940. const curContext = this.curContext();
  6941. if (!curContext.preserveSpace) super.skipSpace();
  6942. }
  6943. getTokenFromCode(code) {
  6944. const context = this.curContext();
  6945. if (context === types.j_expr) {
  6946. this.jsxReadToken();
  6947. return;
  6948. }
  6949. if (context === types.j_oTag || context === types.j_cTag) {
  6950. if (isIdentifierStart(code)) {
  6951. this.jsxReadWord();
  6952. return;
  6953. }
  6954. if (code === 62) {
  6955. ++this.state.pos;
  6956. this.finishToken(144);
  6957. return;
  6958. }
  6959. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6960. this.jsxReadString(code);
  6961. return;
  6962. }
  6963. }
  6964. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  6965. ++this.state.pos;
  6966. this.finishToken(143);
  6967. return;
  6968. }
  6969. super.getTokenFromCode(code);
  6970. }
  6971. updateContext(prevType) {
  6972. const {
  6973. context,
  6974. type
  6975. } = this.state;
  6976. if (type === 56 && prevType === 143) {
  6977. context.splice(-2, 2, types.j_cTag);
  6978. this.state.canStartJSXElement = false;
  6979. } else if (type === 143) {
  6980. context.push(types.j_oTag);
  6981. } else if (type === 144) {
  6982. const out = context[context.length - 1];
  6983. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  6984. context.pop();
  6985. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  6986. } else {
  6987. this.setContext(types.j_expr);
  6988. this.state.canStartJSXElement = true;
  6989. }
  6990. } else {
  6991. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  6992. }
  6993. }
  6994. };
  6995. class TypeScriptScope extends Scope {
  6996. constructor(...args) {
  6997. super(...args);
  6998. this.tsNames = new Map();
  6999. }
  7000. }
  7001. class TypeScriptScopeHandler extends ScopeHandler {
  7002. constructor(...args) {
  7003. super(...args);
  7004. this.importsStack = [];
  7005. }
  7006. createScope(flags) {
  7007. this.importsStack.push(new Set());
  7008. return new TypeScriptScope(flags);
  7009. }
  7010. enter(flags) {
  7011. if (flags === 256) {
  7012. this.importsStack.push(new Set());
  7013. }
  7014. super.enter(flags);
  7015. }
  7016. exit() {
  7017. const flags = super.exit();
  7018. if (flags === 256) {
  7019. this.importsStack.pop();
  7020. }
  7021. return flags;
  7022. }
  7023. hasImport(name, allowShadow) {
  7024. const len = this.importsStack.length;
  7025. if (this.importsStack[len - 1].has(name)) {
  7026. return true;
  7027. }
  7028. if (!allowShadow && len > 1) {
  7029. for (let i = 0; i < len - 1; i++) {
  7030. if (this.importsStack[i].has(name)) return true;
  7031. }
  7032. }
  7033. return false;
  7034. }
  7035. declareName(name, bindingType, loc) {
  7036. if (bindingType & 4096) {
  7037. if (this.hasImport(name, true)) {
  7038. this.parser.raise(Errors.VarRedeclaration, loc, {
  7039. identifierName: name
  7040. });
  7041. }
  7042. this.importsStack[this.importsStack.length - 1].add(name);
  7043. return;
  7044. }
  7045. const scope = this.currentScope();
  7046. let type = scope.tsNames.get(name) || 0;
  7047. if (bindingType & 1024) {
  7048. this.maybeExportDefined(scope, name);
  7049. scope.tsNames.set(name, type | 16);
  7050. return;
  7051. }
  7052. super.declareName(name, bindingType, loc);
  7053. if (bindingType & 2) {
  7054. if (!(bindingType & 1)) {
  7055. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7056. this.maybeExportDefined(scope, name);
  7057. }
  7058. type = type | 1;
  7059. }
  7060. if (bindingType & 256) {
  7061. type = type | 2;
  7062. }
  7063. if (bindingType & 512) {
  7064. type = type | 4;
  7065. }
  7066. if (bindingType & 128) {
  7067. type = type | 8;
  7068. }
  7069. if (type) scope.tsNames.set(name, type);
  7070. }
  7071. isRedeclaredInScope(scope, name, bindingType) {
  7072. const type = scope.tsNames.get(name);
  7073. if ((type & 2) > 0) {
  7074. if (bindingType & 256) {
  7075. const isConst = !!(bindingType & 512);
  7076. const wasConst = (type & 4) > 0;
  7077. return isConst !== wasConst;
  7078. }
  7079. return true;
  7080. }
  7081. if (bindingType & 128 && (type & 8) > 0) {
  7082. if (scope.names.get(name) & 2) {
  7083. return !!(bindingType & 1);
  7084. } else {
  7085. return false;
  7086. }
  7087. }
  7088. if (bindingType & 2 && (type & 1) > 0) {
  7089. return true;
  7090. }
  7091. return super.isRedeclaredInScope(scope, name, bindingType);
  7092. }
  7093. checkLocalExport(id) {
  7094. const {
  7095. name
  7096. } = id;
  7097. if (this.hasImport(name)) return;
  7098. const len = this.scopeStack.length;
  7099. for (let i = len - 1; i >= 0; i--) {
  7100. const scope = this.scopeStack[i];
  7101. const type = scope.tsNames.get(name);
  7102. if ((type & 1) > 0 || (type & 16) > 0) {
  7103. return;
  7104. }
  7105. }
  7106. super.checkLocalExport(id);
  7107. }
  7108. }
  7109. const unwrapParenthesizedExpression = node => {
  7110. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7111. };
  7112. class LValParser extends NodeUtils {
  7113. toAssignable(node, isLHS = false) {
  7114. var _node$extra, _node$extra3;
  7115. let parenthesized = undefined;
  7116. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7117. parenthesized = unwrapParenthesizedExpression(node);
  7118. if (isLHS) {
  7119. if (parenthesized.type === "Identifier") {
  7120. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7121. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7122. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7123. }
  7124. } else {
  7125. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7126. }
  7127. }
  7128. switch (node.type) {
  7129. case "Identifier":
  7130. case "ObjectPattern":
  7131. case "ArrayPattern":
  7132. case "AssignmentPattern":
  7133. case "RestElement":
  7134. break;
  7135. case "ObjectExpression":
  7136. node.type = "ObjectPattern";
  7137. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7138. var _node$extra2;
  7139. const prop = node.properties[i];
  7140. const isLast = i === last;
  7141. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7142. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7143. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7144. }
  7145. }
  7146. break;
  7147. case "ObjectProperty":
  7148. {
  7149. const {
  7150. key,
  7151. value
  7152. } = node;
  7153. if (this.isPrivateName(key)) {
  7154. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7155. }
  7156. this.toAssignable(value, isLHS);
  7157. break;
  7158. }
  7159. case "SpreadElement":
  7160. {
  7161. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7162. }
  7163. case "ArrayExpression":
  7164. node.type = "ArrayPattern";
  7165. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7166. break;
  7167. case "AssignmentExpression":
  7168. if (node.operator !== "=") {
  7169. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7170. }
  7171. node.type = "AssignmentPattern";
  7172. delete node.operator;
  7173. this.toAssignable(node.left, isLHS);
  7174. break;
  7175. case "ParenthesizedExpression":
  7176. this.toAssignable(parenthesized, isLHS);
  7177. break;
  7178. }
  7179. }
  7180. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7181. if (prop.type === "ObjectMethod") {
  7182. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7183. } else if (prop.type === "SpreadElement") {
  7184. prop.type = "RestElement";
  7185. const arg = prop.argument;
  7186. this.checkToRestConversion(arg, false);
  7187. this.toAssignable(arg, isLHS);
  7188. if (!isLast) {
  7189. this.raise(Errors.RestTrailingComma, prop);
  7190. }
  7191. } else {
  7192. this.toAssignable(prop, isLHS);
  7193. }
  7194. }
  7195. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7196. const end = exprList.length - 1;
  7197. for (let i = 0; i <= end; i++) {
  7198. const elt = exprList[i];
  7199. if (!elt) continue;
  7200. if (elt.type === "SpreadElement") {
  7201. elt.type = "RestElement";
  7202. const arg = elt.argument;
  7203. this.checkToRestConversion(arg, true);
  7204. this.toAssignable(arg, isLHS);
  7205. } else {
  7206. this.toAssignable(elt, isLHS);
  7207. }
  7208. if (elt.type === "RestElement") {
  7209. if (i < end) {
  7210. this.raise(Errors.RestTrailingComma, elt);
  7211. } else if (trailingCommaLoc) {
  7212. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7213. }
  7214. }
  7215. }
  7216. }
  7217. isAssignable(node, isBinding) {
  7218. switch (node.type) {
  7219. case "Identifier":
  7220. case "ObjectPattern":
  7221. case "ArrayPattern":
  7222. case "AssignmentPattern":
  7223. case "RestElement":
  7224. return true;
  7225. case "ObjectExpression":
  7226. {
  7227. const last = node.properties.length - 1;
  7228. return node.properties.every((prop, i) => {
  7229. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7230. });
  7231. }
  7232. case "ObjectProperty":
  7233. return this.isAssignable(node.value);
  7234. case "SpreadElement":
  7235. return this.isAssignable(node.argument);
  7236. case "ArrayExpression":
  7237. return node.elements.every(element => element === null || this.isAssignable(element));
  7238. case "AssignmentExpression":
  7239. return node.operator === "=";
  7240. case "ParenthesizedExpression":
  7241. return this.isAssignable(node.expression);
  7242. case "MemberExpression":
  7243. case "OptionalMemberExpression":
  7244. return !isBinding;
  7245. default:
  7246. return false;
  7247. }
  7248. }
  7249. toReferencedList(exprList, isParenthesizedExpr) {
  7250. return exprList;
  7251. }
  7252. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7253. this.toReferencedList(exprList, isParenthesizedExpr);
  7254. for (const expr of exprList) {
  7255. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7256. this.toReferencedListDeep(expr.elements);
  7257. }
  7258. }
  7259. }
  7260. parseSpread(refExpressionErrors) {
  7261. const node = this.startNode();
  7262. this.next();
  7263. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7264. return this.finishNode(node, "SpreadElement");
  7265. }
  7266. parseRestBinding() {
  7267. const node = this.startNode();
  7268. this.next();
  7269. node.argument = this.parseBindingAtom();
  7270. return this.finishNode(node, "RestElement");
  7271. }
  7272. parseBindingAtom() {
  7273. switch (this.state.type) {
  7274. case 0:
  7275. {
  7276. const node = this.startNode();
  7277. this.next();
  7278. node.elements = this.parseBindingList(3, 93, 1);
  7279. return this.finishNode(node, "ArrayPattern");
  7280. }
  7281. case 5:
  7282. return this.parseObjectLike(8, true);
  7283. }
  7284. return this.parseIdentifier();
  7285. }
  7286. parseBindingList(close, closeCharCode, flags) {
  7287. const allowEmpty = flags & 1;
  7288. const elts = [];
  7289. let first = true;
  7290. while (!this.eat(close)) {
  7291. if (first) {
  7292. first = false;
  7293. } else {
  7294. this.expect(12);
  7295. }
  7296. if (allowEmpty && this.match(12)) {
  7297. elts.push(null);
  7298. } else if (this.eat(close)) {
  7299. break;
  7300. } else if (this.match(21)) {
  7301. let rest = this.parseRestBinding();
  7302. if (this.hasPlugin("flow") || flags & 2) {
  7303. rest = this.parseFunctionParamType(rest);
  7304. }
  7305. elts.push(rest);
  7306. if (!this.checkCommaAfterRest(closeCharCode)) {
  7307. this.expect(close);
  7308. break;
  7309. }
  7310. } else {
  7311. const decorators = [];
  7312. if (this.match(26) && this.hasPlugin("decorators")) {
  7313. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7314. }
  7315. while (this.match(26)) {
  7316. decorators.push(this.parseDecorator());
  7317. }
  7318. elts.push(this.parseAssignableListItem(flags, decorators));
  7319. }
  7320. }
  7321. return elts;
  7322. }
  7323. parseBindingRestProperty(prop) {
  7324. this.next();
  7325. prop.argument = this.parseIdentifier();
  7326. this.checkCommaAfterRest(125);
  7327. return this.finishNode(prop, "RestElement");
  7328. }
  7329. parseBindingProperty() {
  7330. const {
  7331. type,
  7332. startLoc
  7333. } = this.state;
  7334. if (type === 21) {
  7335. return this.parseBindingRestProperty(this.startNode());
  7336. }
  7337. const prop = this.startNode();
  7338. if (type === 139) {
  7339. this.expectPlugin("destructuringPrivate", startLoc);
  7340. this.classScope.usePrivateName(this.state.value, startLoc);
  7341. prop.key = this.parsePrivateName();
  7342. } else {
  7343. this.parsePropertyName(prop);
  7344. }
  7345. prop.method = false;
  7346. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7347. }
  7348. parseAssignableListItem(flags, decorators) {
  7349. const left = this.parseMaybeDefault();
  7350. if (this.hasPlugin("flow") || flags & 2) {
  7351. this.parseFunctionParamType(left);
  7352. }
  7353. const elt = this.parseMaybeDefault(left.loc.start, left);
  7354. if (decorators.length) {
  7355. left.decorators = decorators;
  7356. }
  7357. return elt;
  7358. }
  7359. parseFunctionParamType(param) {
  7360. return param;
  7361. }
  7362. parseMaybeDefault(startLoc, left) {
  7363. var _startLoc, _left;
  7364. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  7365. left = (_left = left) != null ? _left : this.parseBindingAtom();
  7366. if (!this.eat(29)) return left;
  7367. const node = this.startNodeAt(startLoc);
  7368. node.left = left;
  7369. node.right = this.parseMaybeAssignAllowIn();
  7370. return this.finishNode(node, "AssignmentPattern");
  7371. }
  7372. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7373. switch (type) {
  7374. case "AssignmentPattern":
  7375. return "left";
  7376. case "RestElement":
  7377. return "argument";
  7378. case "ObjectProperty":
  7379. return "value";
  7380. case "ParenthesizedExpression":
  7381. return "expression";
  7382. case "ArrayPattern":
  7383. return "elements";
  7384. case "ObjectPattern":
  7385. return "properties";
  7386. }
  7387. return false;
  7388. }
  7389. isOptionalMemberExpression(expression) {
  7390. return expression.type === "OptionalMemberExpression";
  7391. }
  7392. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false) {
  7393. var _expression$extra;
  7394. const type = expression.type;
  7395. if (this.isObjectMethod(expression)) return;
  7396. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7397. if (isOptionalMemberExpression || type === "MemberExpression") {
  7398. if (isOptionalMemberExpression) {
  7399. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7400. if (ancestor.type !== "AssignmentExpression") {
  7401. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7402. ancestor
  7403. });
  7404. }
  7405. }
  7406. if (binding !== 64) {
  7407. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7408. }
  7409. return;
  7410. }
  7411. if (type === "Identifier") {
  7412. this.checkIdentifier(expression, binding, strictModeChanged);
  7413. const {
  7414. name
  7415. } = expression;
  7416. if (checkClashes) {
  7417. if (checkClashes.has(name)) {
  7418. this.raise(Errors.ParamDupe, expression);
  7419. } else {
  7420. checkClashes.add(name);
  7421. }
  7422. }
  7423. return;
  7424. }
  7425. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7426. if (validity === true) return;
  7427. if (validity === false) {
  7428. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7429. this.raise(ParseErrorClass, expression, {
  7430. ancestor
  7431. });
  7432. return;
  7433. }
  7434. let key, isParenthesizedExpression;
  7435. if (typeof validity === "string") {
  7436. key = validity;
  7437. isParenthesizedExpression = type === "ParenthesizedExpression";
  7438. } else {
  7439. [key, isParenthesizedExpression] = validity;
  7440. }
  7441. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7442. type
  7443. } : ancestor;
  7444. const val = expression[key];
  7445. if (Array.isArray(val)) {
  7446. for (const child of val) {
  7447. if (child) {
  7448. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  7449. }
  7450. }
  7451. } else if (val) {
  7452. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  7453. }
  7454. }
  7455. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7456. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7457. if (bindingType === 64) {
  7458. this.raise(Errors.StrictEvalArguments, at, {
  7459. referenceName: at.name
  7460. });
  7461. } else {
  7462. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  7463. bindingName: at.name
  7464. });
  7465. }
  7466. }
  7467. if (bindingType & 8192 && at.name === "let") {
  7468. this.raise(Errors.LetInLexicalBinding, at);
  7469. }
  7470. if (!(bindingType & 64)) {
  7471. this.declareNameFromIdentifier(at, bindingType);
  7472. }
  7473. }
  7474. declareNameFromIdentifier(identifier, binding) {
  7475. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7476. }
  7477. checkToRestConversion(node, allowPattern) {
  7478. switch (node.type) {
  7479. case "ParenthesizedExpression":
  7480. this.checkToRestConversion(node.expression, allowPattern);
  7481. break;
  7482. case "Identifier":
  7483. case "MemberExpression":
  7484. break;
  7485. case "ArrayExpression":
  7486. case "ObjectExpression":
  7487. if (allowPattern) break;
  7488. default:
  7489. this.raise(Errors.InvalidRestAssignmentPattern, node);
  7490. }
  7491. }
  7492. checkCommaAfterRest(close) {
  7493. if (!this.match(12)) {
  7494. return false;
  7495. }
  7496. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  7497. return true;
  7498. }
  7499. }
  7500. function nonNull(x) {
  7501. if (x == null) {
  7502. throw new Error(`Unexpected ${x} value.`);
  7503. }
  7504. return x;
  7505. }
  7506. function assert(x) {
  7507. if (!x) {
  7508. throw new Error("Assert fail");
  7509. }
  7510. }
  7511. const TSErrors = ParseErrorEnum`typescript`({
  7512. AbstractMethodHasImplementation: ({
  7513. methodName
  7514. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7515. AbstractPropertyHasInitializer: ({
  7516. propertyName
  7517. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7518. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7519. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7520. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7521. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7522. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7523. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7524. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7525. DeclareAccessor: ({
  7526. kind
  7527. }) => `'declare' is not allowed in ${kind}ters.`,
  7528. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7529. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7530. DuplicateAccessibilityModifier: ({
  7531. modifier
  7532. }) => `Accessibility modifier already seen.`,
  7533. DuplicateModifier: ({
  7534. modifier
  7535. }) => `Duplicate modifier: '${modifier}'.`,
  7536. EmptyHeritageClauseType: ({
  7537. token
  7538. }) => `'${token}' list cannot be empty.`,
  7539. EmptyTypeArguments: "Type argument list cannot be empty.",
  7540. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7541. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7542. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7543. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7544. IncompatibleModifiers: ({
  7545. modifiers
  7546. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7547. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7548. IndexSignatureHasAccessibility: ({
  7549. modifier
  7550. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7551. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7552. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7553. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7554. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7555. InvalidModifierOnTypeMember: ({
  7556. modifier
  7557. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7558. InvalidModifierOnTypeParameter: ({
  7559. modifier
  7560. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7561. InvalidModifierOnTypeParameterPositions: ({
  7562. modifier
  7563. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7564. InvalidModifiersOrder: ({
  7565. orderedModifiers
  7566. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7567. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7568. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7569. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7570. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7571. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7572. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7573. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7574. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7575. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7576. PrivateElementHasAccessibility: ({
  7577. modifier
  7578. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7579. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7580. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7581. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7582. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7583. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7584. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7585. SingleTypeParameterWithoutTrailingComma: ({
  7586. typeParameterName
  7587. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7588. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7589. 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?`).",
  7590. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7591. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7592. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7593. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7594. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7595. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7596. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7597. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7598. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7599. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7600. UnsupportedSignatureParameterKind: ({
  7601. type
  7602. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7603. });
  7604. function keywordTypeFromName(value) {
  7605. switch (value) {
  7606. case "any":
  7607. return "TSAnyKeyword";
  7608. case "boolean":
  7609. return "TSBooleanKeyword";
  7610. case "bigint":
  7611. return "TSBigIntKeyword";
  7612. case "never":
  7613. return "TSNeverKeyword";
  7614. case "number":
  7615. return "TSNumberKeyword";
  7616. case "object":
  7617. return "TSObjectKeyword";
  7618. case "string":
  7619. return "TSStringKeyword";
  7620. case "symbol":
  7621. return "TSSymbolKeyword";
  7622. case "undefined":
  7623. return "TSUndefinedKeyword";
  7624. case "unknown":
  7625. return "TSUnknownKeyword";
  7626. default:
  7627. return undefined;
  7628. }
  7629. }
  7630. function tsIsAccessModifier(modifier) {
  7631. return modifier === "private" || modifier === "public" || modifier === "protected";
  7632. }
  7633. function tsIsVarianceAnnotations(modifier) {
  7634. return modifier === "in" || modifier === "out";
  7635. }
  7636. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7637. constructor(...args) {
  7638. super(...args);
  7639. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7640. allowedModifiers: ["in", "out"],
  7641. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7642. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7643. });
  7644. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7645. allowedModifiers: ["const"],
  7646. disallowedModifiers: ["in", "out"],
  7647. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7648. });
  7649. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7650. allowedModifiers: ["in", "out", "const"],
  7651. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7652. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7653. });
  7654. }
  7655. getScopeHandler() {
  7656. return TypeScriptScopeHandler;
  7657. }
  7658. tsIsIdentifier() {
  7659. return tokenIsIdentifier(this.state.type);
  7660. }
  7661. tsTokenCanFollowModifier() {
  7662. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  7663. }
  7664. tsNextTokenOnSameLineAndCanFollowModifier() {
  7665. this.next();
  7666. if (this.hasPrecedingLineBreak()) {
  7667. return false;
  7668. }
  7669. return this.tsTokenCanFollowModifier();
  7670. }
  7671. tsNextTokenCanFollowModifier() {
  7672. if (this.match(106)) {
  7673. this.next();
  7674. return this.tsTokenCanFollowModifier();
  7675. }
  7676. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  7677. }
  7678. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7679. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7680. return undefined;
  7681. }
  7682. const modifier = this.state.value;
  7683. if (allowedModifiers.includes(modifier)) {
  7684. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7685. return undefined;
  7686. }
  7687. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7688. return modifier;
  7689. }
  7690. }
  7691. return undefined;
  7692. }
  7693. tsParseModifiers({
  7694. allowedModifiers,
  7695. disallowedModifiers,
  7696. stopOnStartOfClassStaticBlock,
  7697. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7698. }, modified) {
  7699. const enforceOrder = (loc, modifier, before, after) => {
  7700. if (modifier === before && modified[after]) {
  7701. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7702. orderedModifiers: [before, after]
  7703. });
  7704. }
  7705. };
  7706. const incompatible = (loc, modifier, mod1, mod2) => {
  7707. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7708. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7709. modifiers: [mod1, mod2]
  7710. });
  7711. }
  7712. };
  7713. for (;;) {
  7714. const {
  7715. startLoc
  7716. } = this.state;
  7717. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7718. if (!modifier) break;
  7719. if (tsIsAccessModifier(modifier)) {
  7720. if (modified.accessibility) {
  7721. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7722. modifier
  7723. });
  7724. } else {
  7725. enforceOrder(startLoc, modifier, modifier, "override");
  7726. enforceOrder(startLoc, modifier, modifier, "static");
  7727. enforceOrder(startLoc, modifier, modifier, "readonly");
  7728. modified.accessibility = modifier;
  7729. }
  7730. } else if (tsIsVarianceAnnotations(modifier)) {
  7731. if (modified[modifier]) {
  7732. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7733. modifier
  7734. });
  7735. }
  7736. modified[modifier] = true;
  7737. enforceOrder(startLoc, modifier, "in", "out");
  7738. } else {
  7739. if (hasOwnProperty.call(modified, modifier)) {
  7740. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7741. modifier
  7742. });
  7743. } else {
  7744. enforceOrder(startLoc, modifier, "static", "readonly");
  7745. enforceOrder(startLoc, modifier, "static", "override");
  7746. enforceOrder(startLoc, modifier, "override", "readonly");
  7747. enforceOrder(startLoc, modifier, "abstract", "override");
  7748. incompatible(startLoc, modifier, "declare", "override");
  7749. incompatible(startLoc, modifier, "static", "abstract");
  7750. }
  7751. modified[modifier] = true;
  7752. }
  7753. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7754. this.raise(errorTemplate, startLoc, {
  7755. modifier
  7756. });
  7757. }
  7758. }
  7759. }
  7760. tsIsListTerminator(kind) {
  7761. switch (kind) {
  7762. case "EnumMembers":
  7763. case "TypeMembers":
  7764. return this.match(8);
  7765. case "HeritageClauseElement":
  7766. return this.match(5);
  7767. case "TupleElementTypes":
  7768. return this.match(3);
  7769. case "TypeParametersOrArguments":
  7770. return this.match(48);
  7771. }
  7772. }
  7773. tsParseList(kind, parseElement) {
  7774. const result = [];
  7775. while (!this.tsIsListTerminator(kind)) {
  7776. result.push(parseElement());
  7777. }
  7778. return result;
  7779. }
  7780. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7781. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7782. }
  7783. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7784. const result = [];
  7785. let trailingCommaPos = -1;
  7786. for (;;) {
  7787. if (this.tsIsListTerminator(kind)) {
  7788. break;
  7789. }
  7790. trailingCommaPos = -1;
  7791. const element = parseElement();
  7792. if (element == null) {
  7793. return undefined;
  7794. }
  7795. result.push(element);
  7796. if (this.eat(12)) {
  7797. trailingCommaPos = this.state.lastTokStartLoc.index;
  7798. continue;
  7799. }
  7800. if (this.tsIsListTerminator(kind)) {
  7801. break;
  7802. }
  7803. if (expectSuccess) {
  7804. this.expect(12);
  7805. }
  7806. return undefined;
  7807. }
  7808. if (refTrailingCommaPos) {
  7809. refTrailingCommaPos.value = trailingCommaPos;
  7810. }
  7811. return result;
  7812. }
  7813. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7814. if (!skipFirstToken) {
  7815. if (bracket) {
  7816. this.expect(0);
  7817. } else {
  7818. this.expect(47);
  7819. }
  7820. }
  7821. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7822. if (bracket) {
  7823. this.expect(3);
  7824. } else {
  7825. this.expect(48);
  7826. }
  7827. return result;
  7828. }
  7829. tsParseImportType() {
  7830. const node = this.startNode();
  7831. this.expect(83);
  7832. this.expect(10);
  7833. if (!this.match(134)) {
  7834. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7835. {
  7836. node.argument = super.parseExprAtom();
  7837. }
  7838. } else {
  7839. {
  7840. node.argument = this.parseStringLiteral(this.state.value);
  7841. }
  7842. }
  7843. if (this.eat(12) && !this.match(11)) {
  7844. node.options = super.parseMaybeAssignAllowIn();
  7845. this.eat(12);
  7846. } else {
  7847. node.options = null;
  7848. }
  7849. this.expect(11);
  7850. if (this.eat(16)) {
  7851. node.qualifier = this.tsParseEntityName(1 | 2);
  7852. }
  7853. if (this.match(47)) {
  7854. {
  7855. node.typeParameters = this.tsParseTypeArguments();
  7856. }
  7857. }
  7858. return this.finishNode(node, "TSImportType");
  7859. }
  7860. tsParseEntityName(flags) {
  7861. let entity;
  7862. if (flags & 1 && this.match(78)) {
  7863. if (flags & 2) {
  7864. entity = this.parseIdentifier(true);
  7865. } else {
  7866. const node = this.startNode();
  7867. this.next();
  7868. entity = this.finishNode(node, "ThisExpression");
  7869. }
  7870. } else {
  7871. entity = this.parseIdentifier(!!(flags & 1));
  7872. }
  7873. while (this.eat(16)) {
  7874. const node = this.startNodeAtNode(entity);
  7875. node.left = entity;
  7876. node.right = this.parseIdentifier(!!(flags & 1));
  7877. entity = this.finishNode(node, "TSQualifiedName");
  7878. }
  7879. return entity;
  7880. }
  7881. tsParseTypeReference() {
  7882. const node = this.startNode();
  7883. node.typeName = this.tsParseEntityName(1);
  7884. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7885. {
  7886. node.typeParameters = this.tsParseTypeArguments();
  7887. }
  7888. }
  7889. return this.finishNode(node, "TSTypeReference");
  7890. }
  7891. tsParseThisTypePredicate(lhs) {
  7892. this.next();
  7893. const node = this.startNodeAtNode(lhs);
  7894. node.parameterName = lhs;
  7895. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7896. node.asserts = false;
  7897. return this.finishNode(node, "TSTypePredicate");
  7898. }
  7899. tsParseThisTypeNode() {
  7900. const node = this.startNode();
  7901. this.next();
  7902. return this.finishNode(node, "TSThisType");
  7903. }
  7904. tsParseTypeQuery() {
  7905. const node = this.startNode();
  7906. this.expect(87);
  7907. if (this.match(83)) {
  7908. node.exprName = this.tsParseImportType();
  7909. } else {
  7910. {
  7911. node.exprName = this.tsParseEntityName(1 | 2);
  7912. }
  7913. }
  7914. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7915. {
  7916. node.typeParameters = this.tsParseTypeArguments();
  7917. }
  7918. }
  7919. return this.finishNode(node, "TSTypeQuery");
  7920. }
  7921. tsParseTypeParameter(parseModifiers) {
  7922. const node = this.startNode();
  7923. parseModifiers(node);
  7924. node.name = this.tsParseTypeParameterName();
  7925. node.constraint = this.tsEatThenParseType(81);
  7926. node.default = this.tsEatThenParseType(29);
  7927. return this.finishNode(node, "TSTypeParameter");
  7928. }
  7929. tsTryParseTypeParameters(parseModifiers) {
  7930. if (this.match(47)) {
  7931. return this.tsParseTypeParameters(parseModifiers);
  7932. }
  7933. }
  7934. tsParseTypeParameters(parseModifiers) {
  7935. const node = this.startNode();
  7936. if (this.match(47) || this.match(143)) {
  7937. this.next();
  7938. } else {
  7939. this.unexpected();
  7940. }
  7941. const refTrailingCommaPos = {
  7942. value: -1
  7943. };
  7944. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7945. if (node.params.length === 0) {
  7946. this.raise(TSErrors.EmptyTypeParameters, node);
  7947. }
  7948. if (refTrailingCommaPos.value !== -1) {
  7949. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7950. }
  7951. return this.finishNode(node, "TSTypeParameterDeclaration");
  7952. }
  7953. tsFillSignature(returnToken, signature) {
  7954. const returnTokenRequired = returnToken === 19;
  7955. const paramsKey = "parameters";
  7956. const returnTypeKey = "typeAnnotation";
  7957. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  7958. this.expect(10);
  7959. signature[paramsKey] = this.tsParseBindingListForSignature();
  7960. if (returnTokenRequired) {
  7961. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7962. } else if (this.match(returnToken)) {
  7963. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7964. }
  7965. }
  7966. tsParseBindingListForSignature() {
  7967. const list = super.parseBindingList(11, 41, 2);
  7968. for (const pattern of list) {
  7969. const {
  7970. type
  7971. } = pattern;
  7972. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  7973. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  7974. type
  7975. });
  7976. }
  7977. }
  7978. return list;
  7979. }
  7980. tsParseTypeMemberSemicolon() {
  7981. if (!this.eat(12) && !this.isLineTerminator()) {
  7982. this.expect(13);
  7983. }
  7984. }
  7985. tsParseSignatureMember(kind, node) {
  7986. this.tsFillSignature(14, node);
  7987. this.tsParseTypeMemberSemicolon();
  7988. return this.finishNode(node, kind);
  7989. }
  7990. tsIsUnambiguouslyIndexSignature() {
  7991. this.next();
  7992. if (tokenIsIdentifier(this.state.type)) {
  7993. this.next();
  7994. return this.match(14);
  7995. }
  7996. return false;
  7997. }
  7998. tsTryParseIndexSignature(node) {
  7999. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8000. return;
  8001. }
  8002. this.expect(0);
  8003. const id = this.parseIdentifier();
  8004. id.typeAnnotation = this.tsParseTypeAnnotation();
  8005. this.resetEndLocation(id);
  8006. this.expect(3);
  8007. node.parameters = [id];
  8008. const type = this.tsTryParseTypeAnnotation();
  8009. if (type) node.typeAnnotation = type;
  8010. this.tsParseTypeMemberSemicolon();
  8011. return this.finishNode(node, "TSIndexSignature");
  8012. }
  8013. tsParsePropertyOrMethodSignature(node, readonly) {
  8014. if (this.eat(17)) node.optional = true;
  8015. const nodeAny = node;
  8016. if (this.match(10) || this.match(47)) {
  8017. if (readonly) {
  8018. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  8019. }
  8020. const method = nodeAny;
  8021. if (method.kind && this.match(47)) {
  8022. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  8023. }
  8024. this.tsFillSignature(14, method);
  8025. this.tsParseTypeMemberSemicolon();
  8026. const paramsKey = "parameters";
  8027. const returnTypeKey = "typeAnnotation";
  8028. if (method.kind === "get") {
  8029. if (method[paramsKey].length > 0) {
  8030. this.raise(Errors.BadGetterArity, this.state.curPosition());
  8031. if (this.isThisParam(method[paramsKey][0])) {
  8032. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8033. }
  8034. }
  8035. } else if (method.kind === "set") {
  8036. if (method[paramsKey].length !== 1) {
  8037. this.raise(Errors.BadSetterArity, this.state.curPosition());
  8038. } else {
  8039. const firstParameter = method[paramsKey][0];
  8040. if (this.isThisParam(firstParameter)) {
  8041. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8042. }
  8043. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8044. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  8045. }
  8046. if (firstParameter.type === "RestElement") {
  8047. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  8048. }
  8049. }
  8050. if (method[returnTypeKey]) {
  8051. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  8052. }
  8053. } else {
  8054. method.kind = "method";
  8055. }
  8056. return this.finishNode(method, "TSMethodSignature");
  8057. } else {
  8058. const property = nodeAny;
  8059. if (readonly) property.readonly = true;
  8060. const type = this.tsTryParseTypeAnnotation();
  8061. if (type) property.typeAnnotation = type;
  8062. this.tsParseTypeMemberSemicolon();
  8063. return this.finishNode(property, "TSPropertySignature");
  8064. }
  8065. }
  8066. tsParseTypeMember() {
  8067. const node = this.startNode();
  8068. if (this.match(10) || this.match(47)) {
  8069. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8070. }
  8071. if (this.match(77)) {
  8072. const id = this.startNode();
  8073. this.next();
  8074. if (this.match(10) || this.match(47)) {
  8075. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8076. } else {
  8077. node.key = this.createIdentifier(id, "new");
  8078. return this.tsParsePropertyOrMethodSignature(node, false);
  8079. }
  8080. }
  8081. this.tsParseModifiers({
  8082. allowedModifiers: ["readonly"],
  8083. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8084. }, node);
  8085. const idx = this.tsTryParseIndexSignature(node);
  8086. if (idx) {
  8087. return idx;
  8088. }
  8089. super.parsePropertyName(node);
  8090. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8091. node.kind = node.key.name;
  8092. super.parsePropertyName(node);
  8093. }
  8094. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8095. }
  8096. tsParseTypeLiteral() {
  8097. const node = this.startNode();
  8098. node.members = this.tsParseObjectTypeMembers();
  8099. return this.finishNode(node, "TSTypeLiteral");
  8100. }
  8101. tsParseObjectTypeMembers() {
  8102. this.expect(5);
  8103. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8104. this.expect(8);
  8105. return members;
  8106. }
  8107. tsIsStartOfMappedType() {
  8108. this.next();
  8109. if (this.eat(53)) {
  8110. return this.isContextual(122);
  8111. }
  8112. if (this.isContextual(122)) {
  8113. this.next();
  8114. }
  8115. if (!this.match(0)) {
  8116. return false;
  8117. }
  8118. this.next();
  8119. if (!this.tsIsIdentifier()) {
  8120. return false;
  8121. }
  8122. this.next();
  8123. return this.match(58);
  8124. }
  8125. tsParseMappedType() {
  8126. const node = this.startNode();
  8127. this.expect(5);
  8128. if (this.match(53)) {
  8129. node.readonly = this.state.value;
  8130. this.next();
  8131. this.expectContextual(122);
  8132. } else if (this.eatContextual(122)) {
  8133. node.readonly = true;
  8134. }
  8135. this.expect(0);
  8136. {
  8137. const typeParameter = this.startNode();
  8138. typeParameter.name = this.tsParseTypeParameterName();
  8139. typeParameter.constraint = this.tsExpectThenParseType(58);
  8140. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8141. }
  8142. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8143. this.expect(3);
  8144. if (this.match(53)) {
  8145. node.optional = this.state.value;
  8146. this.next();
  8147. this.expect(17);
  8148. } else if (this.eat(17)) {
  8149. node.optional = true;
  8150. }
  8151. node.typeAnnotation = this.tsTryParseType();
  8152. this.semicolon();
  8153. this.expect(8);
  8154. return this.finishNode(node, "TSMappedType");
  8155. }
  8156. tsParseTupleType() {
  8157. const node = this.startNode();
  8158. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8159. let seenOptionalElement = false;
  8160. node.elementTypes.forEach(elementNode => {
  8161. const {
  8162. type
  8163. } = elementNode;
  8164. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8165. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8166. }
  8167. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8168. });
  8169. return this.finishNode(node, "TSTupleType");
  8170. }
  8171. tsParseTupleElementType() {
  8172. const restStartLoc = this.state.startLoc;
  8173. const rest = this.eat(21);
  8174. const {
  8175. startLoc
  8176. } = this.state;
  8177. let labeled;
  8178. let label;
  8179. let optional;
  8180. let type;
  8181. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8182. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8183. if (chAfterWord === 58) {
  8184. labeled = true;
  8185. optional = false;
  8186. label = this.parseIdentifier(true);
  8187. this.expect(14);
  8188. type = this.tsParseType();
  8189. } else if (chAfterWord === 63) {
  8190. optional = true;
  8191. const wordName = this.state.value;
  8192. const typeOrLabel = this.tsParseNonArrayType();
  8193. if (this.lookaheadCharCode() === 58) {
  8194. labeled = true;
  8195. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8196. this.expect(17);
  8197. this.expect(14);
  8198. type = this.tsParseType();
  8199. } else {
  8200. labeled = false;
  8201. type = typeOrLabel;
  8202. this.expect(17);
  8203. }
  8204. } else {
  8205. type = this.tsParseType();
  8206. optional = this.eat(17);
  8207. labeled = this.eat(14);
  8208. }
  8209. if (labeled) {
  8210. let labeledNode;
  8211. if (label) {
  8212. labeledNode = this.startNodeAt(startLoc);
  8213. labeledNode.optional = optional;
  8214. labeledNode.label = label;
  8215. labeledNode.elementType = type;
  8216. if (this.eat(17)) {
  8217. labeledNode.optional = true;
  8218. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8219. }
  8220. } else {
  8221. labeledNode = this.startNodeAt(startLoc);
  8222. labeledNode.optional = optional;
  8223. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8224. labeledNode.label = type;
  8225. labeledNode.elementType = this.tsParseType();
  8226. }
  8227. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8228. } else if (optional) {
  8229. const optionalTypeNode = this.startNodeAt(startLoc);
  8230. optionalTypeNode.typeAnnotation = type;
  8231. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8232. }
  8233. if (rest) {
  8234. const restNode = this.startNodeAt(restStartLoc);
  8235. restNode.typeAnnotation = type;
  8236. type = this.finishNode(restNode, "TSRestType");
  8237. }
  8238. return type;
  8239. }
  8240. tsParseParenthesizedType() {
  8241. const node = this.startNode();
  8242. this.expect(10);
  8243. node.typeAnnotation = this.tsParseType();
  8244. this.expect(11);
  8245. return this.finishNode(node, "TSParenthesizedType");
  8246. }
  8247. tsParseFunctionOrConstructorType(type, abstract) {
  8248. const node = this.startNode();
  8249. if (type === "TSConstructorType") {
  8250. node.abstract = !!abstract;
  8251. if (abstract) this.next();
  8252. this.next();
  8253. }
  8254. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8255. return this.finishNode(node, type);
  8256. }
  8257. tsParseLiteralTypeNode() {
  8258. const node = this.startNode();
  8259. switch (this.state.type) {
  8260. case 135:
  8261. case 136:
  8262. case 134:
  8263. case 85:
  8264. case 86:
  8265. node.literal = super.parseExprAtom();
  8266. break;
  8267. default:
  8268. this.unexpected();
  8269. }
  8270. return this.finishNode(node, "TSLiteralType");
  8271. }
  8272. tsParseTemplateLiteralType() {
  8273. {
  8274. const node = this.startNode();
  8275. node.literal = super.parseTemplate(false);
  8276. return this.finishNode(node, "TSLiteralType");
  8277. }
  8278. }
  8279. parseTemplateSubstitution() {
  8280. if (this.state.inType) return this.tsParseType();
  8281. return super.parseTemplateSubstitution();
  8282. }
  8283. tsParseThisTypeOrThisTypePredicate() {
  8284. const thisKeyword = this.tsParseThisTypeNode();
  8285. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8286. return this.tsParseThisTypePredicate(thisKeyword);
  8287. } else {
  8288. return thisKeyword;
  8289. }
  8290. }
  8291. tsParseNonArrayType() {
  8292. switch (this.state.type) {
  8293. case 134:
  8294. case 135:
  8295. case 136:
  8296. case 85:
  8297. case 86:
  8298. return this.tsParseLiteralTypeNode();
  8299. case 53:
  8300. if (this.state.value === "-") {
  8301. const node = this.startNode();
  8302. const nextToken = this.lookahead();
  8303. if (nextToken.type !== 135 && nextToken.type !== 136) {
  8304. this.unexpected();
  8305. }
  8306. node.literal = this.parseMaybeUnary();
  8307. return this.finishNode(node, "TSLiteralType");
  8308. }
  8309. break;
  8310. case 78:
  8311. return this.tsParseThisTypeOrThisTypePredicate();
  8312. case 87:
  8313. return this.tsParseTypeQuery();
  8314. case 83:
  8315. return this.tsParseImportType();
  8316. case 5:
  8317. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8318. case 0:
  8319. return this.tsParseTupleType();
  8320. case 10:
  8321. return this.tsParseParenthesizedType();
  8322. case 25:
  8323. case 24:
  8324. return this.tsParseTemplateLiteralType();
  8325. default:
  8326. {
  8327. const {
  8328. type
  8329. } = this.state;
  8330. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8331. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8332. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8333. const node = this.startNode();
  8334. this.next();
  8335. return this.finishNode(node, nodeType);
  8336. }
  8337. return this.tsParseTypeReference();
  8338. }
  8339. }
  8340. }
  8341. this.unexpected();
  8342. }
  8343. tsParseArrayTypeOrHigher() {
  8344. const {
  8345. startLoc
  8346. } = this.state;
  8347. let type = this.tsParseNonArrayType();
  8348. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8349. if (this.match(3)) {
  8350. const node = this.startNodeAt(startLoc);
  8351. node.elementType = type;
  8352. this.expect(3);
  8353. type = this.finishNode(node, "TSArrayType");
  8354. } else {
  8355. const node = this.startNodeAt(startLoc);
  8356. node.objectType = type;
  8357. node.indexType = this.tsParseType();
  8358. this.expect(3);
  8359. type = this.finishNode(node, "TSIndexedAccessType");
  8360. }
  8361. }
  8362. return type;
  8363. }
  8364. tsParseTypeOperator() {
  8365. const node = this.startNode();
  8366. const operator = this.state.value;
  8367. this.next();
  8368. node.operator = operator;
  8369. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8370. if (operator === "readonly") {
  8371. this.tsCheckTypeAnnotationForReadOnly(node);
  8372. }
  8373. return this.finishNode(node, "TSTypeOperator");
  8374. }
  8375. tsCheckTypeAnnotationForReadOnly(node) {
  8376. switch (node.typeAnnotation.type) {
  8377. case "TSTupleType":
  8378. case "TSArrayType":
  8379. return;
  8380. default:
  8381. this.raise(TSErrors.UnexpectedReadonly, node);
  8382. }
  8383. }
  8384. tsParseInferType() {
  8385. const node = this.startNode();
  8386. this.expectContextual(115);
  8387. const typeParameter = this.startNode();
  8388. typeParameter.name = this.tsParseTypeParameterName();
  8389. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8390. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8391. return this.finishNode(node, "TSInferType");
  8392. }
  8393. tsParseConstraintForInferType() {
  8394. if (this.eat(81)) {
  8395. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8396. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8397. return constraint;
  8398. }
  8399. }
  8400. }
  8401. tsParseTypeOperatorOrHigher() {
  8402. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8403. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8404. }
  8405. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8406. const node = this.startNode();
  8407. const hasLeadingOperator = this.eat(operator);
  8408. const types = [];
  8409. do {
  8410. types.push(parseConstituentType());
  8411. } while (this.eat(operator));
  8412. if (types.length === 1 && !hasLeadingOperator) {
  8413. return types[0];
  8414. }
  8415. node.types = types;
  8416. return this.finishNode(node, kind);
  8417. }
  8418. tsParseIntersectionTypeOrHigher() {
  8419. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8420. }
  8421. tsParseUnionTypeOrHigher() {
  8422. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8423. }
  8424. tsIsStartOfFunctionType() {
  8425. if (this.match(47)) {
  8426. return true;
  8427. }
  8428. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8429. }
  8430. tsSkipParameterStart() {
  8431. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8432. this.next();
  8433. return true;
  8434. }
  8435. if (this.match(5)) {
  8436. const {
  8437. errors
  8438. } = this.state;
  8439. const previousErrorCount = errors.length;
  8440. try {
  8441. this.parseObjectLike(8, true);
  8442. return errors.length === previousErrorCount;
  8443. } catch (_unused) {
  8444. return false;
  8445. }
  8446. }
  8447. if (this.match(0)) {
  8448. this.next();
  8449. const {
  8450. errors
  8451. } = this.state;
  8452. const previousErrorCount = errors.length;
  8453. try {
  8454. super.parseBindingList(3, 93, 1);
  8455. return errors.length === previousErrorCount;
  8456. } catch (_unused2) {
  8457. return false;
  8458. }
  8459. }
  8460. return false;
  8461. }
  8462. tsIsUnambiguouslyStartOfFunctionType() {
  8463. this.next();
  8464. if (this.match(11) || this.match(21)) {
  8465. return true;
  8466. }
  8467. if (this.tsSkipParameterStart()) {
  8468. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8469. return true;
  8470. }
  8471. if (this.match(11)) {
  8472. this.next();
  8473. if (this.match(19)) {
  8474. return true;
  8475. }
  8476. }
  8477. }
  8478. return false;
  8479. }
  8480. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8481. return this.tsInType(() => {
  8482. const t = this.startNode();
  8483. this.expect(returnToken);
  8484. const node = this.startNode();
  8485. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8486. if (asserts && this.match(78)) {
  8487. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8488. if (thisTypePredicate.type === "TSThisType") {
  8489. node.parameterName = thisTypePredicate;
  8490. node.asserts = true;
  8491. node.typeAnnotation = null;
  8492. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8493. } else {
  8494. this.resetStartLocationFromNode(thisTypePredicate, node);
  8495. thisTypePredicate.asserts = true;
  8496. }
  8497. t.typeAnnotation = thisTypePredicate;
  8498. return this.finishNode(t, "TSTypeAnnotation");
  8499. }
  8500. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8501. if (!typePredicateVariable) {
  8502. if (!asserts) {
  8503. return this.tsParseTypeAnnotation(false, t);
  8504. }
  8505. node.parameterName = this.parseIdentifier();
  8506. node.asserts = asserts;
  8507. node.typeAnnotation = null;
  8508. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8509. return this.finishNode(t, "TSTypeAnnotation");
  8510. }
  8511. const type = this.tsParseTypeAnnotation(false);
  8512. node.parameterName = typePredicateVariable;
  8513. node.typeAnnotation = type;
  8514. node.asserts = asserts;
  8515. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8516. return this.finishNode(t, "TSTypeAnnotation");
  8517. });
  8518. }
  8519. tsTryParseTypeOrTypePredicateAnnotation() {
  8520. if (this.match(14)) {
  8521. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8522. }
  8523. }
  8524. tsTryParseTypeAnnotation() {
  8525. if (this.match(14)) {
  8526. return this.tsParseTypeAnnotation();
  8527. }
  8528. }
  8529. tsTryParseType() {
  8530. return this.tsEatThenParseType(14);
  8531. }
  8532. tsParseTypePredicatePrefix() {
  8533. const id = this.parseIdentifier();
  8534. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8535. this.next();
  8536. return id;
  8537. }
  8538. }
  8539. tsParseTypePredicateAsserts() {
  8540. if (this.state.type !== 109) {
  8541. return false;
  8542. }
  8543. const containsEsc = this.state.containsEsc;
  8544. this.next();
  8545. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8546. return false;
  8547. }
  8548. if (containsEsc) {
  8549. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8550. reservedWord: "asserts"
  8551. });
  8552. }
  8553. return true;
  8554. }
  8555. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8556. this.tsInType(() => {
  8557. if (eatColon) this.expect(14);
  8558. t.typeAnnotation = this.tsParseType();
  8559. });
  8560. return this.finishNode(t, "TSTypeAnnotation");
  8561. }
  8562. tsParseType() {
  8563. assert(this.state.inType);
  8564. const type = this.tsParseNonConditionalType();
  8565. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8566. return type;
  8567. }
  8568. const node = this.startNodeAtNode(type);
  8569. node.checkType = type;
  8570. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8571. this.expect(17);
  8572. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8573. this.expect(14);
  8574. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8575. return this.finishNode(node, "TSConditionalType");
  8576. }
  8577. isAbstractConstructorSignature() {
  8578. return this.isContextual(124) && this.lookahead().type === 77;
  8579. }
  8580. tsParseNonConditionalType() {
  8581. if (this.tsIsStartOfFunctionType()) {
  8582. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8583. }
  8584. if (this.match(77)) {
  8585. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8586. } else if (this.isAbstractConstructorSignature()) {
  8587. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8588. }
  8589. return this.tsParseUnionTypeOrHigher();
  8590. }
  8591. tsParseTypeAssertion() {
  8592. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8593. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8594. }
  8595. const node = this.startNode();
  8596. node.typeAnnotation = this.tsInType(() => {
  8597. this.next();
  8598. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8599. });
  8600. this.expect(48);
  8601. node.expression = this.parseMaybeUnary();
  8602. return this.finishNode(node, "TSTypeAssertion");
  8603. }
  8604. tsParseHeritageClause(token) {
  8605. const originalStartLoc = this.state.startLoc;
  8606. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8607. const node = this.startNode();
  8608. {
  8609. node.expression = this.tsParseEntityName(1 | 2);
  8610. if (this.match(47)) {
  8611. node.typeParameters = this.tsParseTypeArguments();
  8612. }
  8613. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8614. }
  8615. });
  8616. if (!delimitedList.length) {
  8617. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8618. token
  8619. });
  8620. }
  8621. return delimitedList;
  8622. }
  8623. tsParseInterfaceDeclaration(node, properties = {}) {
  8624. if (this.hasFollowingLineBreak()) return null;
  8625. this.expectContextual(129);
  8626. if (properties.declare) node.declare = true;
  8627. if (tokenIsIdentifier(this.state.type)) {
  8628. node.id = this.parseIdentifier();
  8629. this.checkIdentifier(node.id, 130);
  8630. } else {
  8631. node.id = null;
  8632. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8633. }
  8634. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8635. if (this.eat(81)) {
  8636. node.extends = this.tsParseHeritageClause("extends");
  8637. }
  8638. const body = this.startNode();
  8639. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8640. node.body = this.finishNode(body, "TSInterfaceBody");
  8641. return this.finishNode(node, "TSInterfaceDeclaration");
  8642. }
  8643. tsParseTypeAliasDeclaration(node) {
  8644. node.id = this.parseIdentifier();
  8645. this.checkIdentifier(node.id, 2);
  8646. node.typeAnnotation = this.tsInType(() => {
  8647. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8648. this.expect(29);
  8649. if (this.isContextual(114) && this.lookahead().type !== 16) {
  8650. const node = this.startNode();
  8651. this.next();
  8652. return this.finishNode(node, "TSIntrinsicKeyword");
  8653. }
  8654. return this.tsParseType();
  8655. });
  8656. this.semicolon();
  8657. return this.finishNode(node, "TSTypeAliasDeclaration");
  8658. }
  8659. tsInTopLevelContext(cb) {
  8660. if (this.curContext() !== types.brace) {
  8661. const oldContext = this.state.context;
  8662. this.state.context = [oldContext[0]];
  8663. try {
  8664. return cb();
  8665. } finally {
  8666. this.state.context = oldContext;
  8667. }
  8668. } else {
  8669. return cb();
  8670. }
  8671. }
  8672. tsInType(cb) {
  8673. const oldInType = this.state.inType;
  8674. this.state.inType = true;
  8675. try {
  8676. return cb();
  8677. } finally {
  8678. this.state.inType = oldInType;
  8679. }
  8680. }
  8681. tsInDisallowConditionalTypesContext(cb) {
  8682. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8683. this.state.inDisallowConditionalTypesContext = true;
  8684. try {
  8685. return cb();
  8686. } finally {
  8687. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8688. }
  8689. }
  8690. tsInAllowConditionalTypesContext(cb) {
  8691. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8692. this.state.inDisallowConditionalTypesContext = false;
  8693. try {
  8694. return cb();
  8695. } finally {
  8696. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8697. }
  8698. }
  8699. tsEatThenParseType(token) {
  8700. if (this.match(token)) {
  8701. return this.tsNextThenParseType();
  8702. }
  8703. }
  8704. tsExpectThenParseType(token) {
  8705. return this.tsInType(() => {
  8706. this.expect(token);
  8707. return this.tsParseType();
  8708. });
  8709. }
  8710. tsNextThenParseType() {
  8711. return this.tsInType(() => {
  8712. this.next();
  8713. return this.tsParseType();
  8714. });
  8715. }
  8716. tsParseEnumMember() {
  8717. const node = this.startNode();
  8718. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8719. if (this.eat(29)) {
  8720. node.initializer = super.parseMaybeAssignAllowIn();
  8721. }
  8722. return this.finishNode(node, "TSEnumMember");
  8723. }
  8724. tsParseEnumDeclaration(node, properties = {}) {
  8725. if (properties.const) node.const = true;
  8726. if (properties.declare) node.declare = true;
  8727. this.expectContextual(126);
  8728. node.id = this.parseIdentifier();
  8729. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8730. {
  8731. this.expect(5);
  8732. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8733. this.expect(8);
  8734. }
  8735. return this.finishNode(node, "TSEnumDeclaration");
  8736. }
  8737. tsParseEnumBody() {
  8738. const node = this.startNode();
  8739. this.expect(5);
  8740. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8741. this.expect(8);
  8742. return this.finishNode(node, "TSEnumBody");
  8743. }
  8744. tsParseModuleBlock() {
  8745. const node = this.startNode();
  8746. this.scope.enter(0);
  8747. this.expect(5);
  8748. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8749. this.scope.exit();
  8750. return this.finishNode(node, "TSModuleBlock");
  8751. }
  8752. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8753. node.id = this.parseIdentifier();
  8754. if (!nested) {
  8755. this.checkIdentifier(node.id, 1024);
  8756. }
  8757. if (this.eat(16)) {
  8758. const inner = this.startNode();
  8759. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8760. node.body = inner;
  8761. } else {
  8762. this.scope.enter(256);
  8763. this.prodParam.enter(0);
  8764. node.body = this.tsParseModuleBlock();
  8765. this.prodParam.exit();
  8766. this.scope.exit();
  8767. }
  8768. return this.finishNode(node, "TSModuleDeclaration");
  8769. }
  8770. tsParseAmbientExternalModuleDeclaration(node) {
  8771. if (this.isContextual(112)) {
  8772. node.kind = "global";
  8773. {
  8774. node.global = true;
  8775. }
  8776. node.id = this.parseIdentifier();
  8777. } else if (this.match(134)) {
  8778. node.kind = "module";
  8779. node.id = super.parseStringLiteral(this.state.value);
  8780. } else {
  8781. this.unexpected();
  8782. }
  8783. if (this.match(5)) {
  8784. this.scope.enter(256);
  8785. this.prodParam.enter(0);
  8786. node.body = this.tsParseModuleBlock();
  8787. this.prodParam.exit();
  8788. this.scope.exit();
  8789. } else {
  8790. this.semicolon();
  8791. }
  8792. return this.finishNode(node, "TSModuleDeclaration");
  8793. }
  8794. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8795. {
  8796. node.isExport = isExport || false;
  8797. }
  8798. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8799. this.checkIdentifier(node.id, 4096);
  8800. this.expect(29);
  8801. const moduleReference = this.tsParseModuleReference();
  8802. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8803. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8804. }
  8805. node.moduleReference = moduleReference;
  8806. this.semicolon();
  8807. return this.finishNode(node, "TSImportEqualsDeclaration");
  8808. }
  8809. tsIsExternalModuleReference() {
  8810. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8811. }
  8812. tsParseModuleReference() {
  8813. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  8814. }
  8815. tsParseExternalModuleReference() {
  8816. const node = this.startNode();
  8817. this.expectContextual(119);
  8818. this.expect(10);
  8819. if (!this.match(134)) {
  8820. this.unexpected();
  8821. }
  8822. node.expression = super.parseExprAtom();
  8823. this.expect(11);
  8824. this.sawUnambiguousESM = true;
  8825. return this.finishNode(node, "TSExternalModuleReference");
  8826. }
  8827. tsLookAhead(f) {
  8828. const state = this.state.clone();
  8829. const res = f();
  8830. this.state = state;
  8831. return res;
  8832. }
  8833. tsTryParseAndCatch(f) {
  8834. const result = this.tryParse(abort => f() || abort());
  8835. if (result.aborted || !result.node) return;
  8836. if (result.error) this.state = result.failState;
  8837. return result.node;
  8838. }
  8839. tsTryParse(f) {
  8840. const state = this.state.clone();
  8841. const result = f();
  8842. if (result !== undefined && result !== false) {
  8843. return result;
  8844. }
  8845. this.state = state;
  8846. }
  8847. tsTryParseDeclare(nany) {
  8848. if (this.isLineTerminator()) {
  8849. return;
  8850. }
  8851. let startType = this.state.type;
  8852. let kind;
  8853. if (this.isContextual(100)) {
  8854. startType = 74;
  8855. kind = "let";
  8856. }
  8857. return this.tsInAmbientContext(() => {
  8858. switch (startType) {
  8859. case 68:
  8860. nany.declare = true;
  8861. return super.parseFunctionStatement(nany, false, false);
  8862. case 80:
  8863. nany.declare = true;
  8864. return this.parseClass(nany, true, false);
  8865. case 126:
  8866. return this.tsParseEnumDeclaration(nany, {
  8867. declare: true
  8868. });
  8869. case 112:
  8870. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8871. case 75:
  8872. case 74:
  8873. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8874. nany.declare = true;
  8875. return this.parseVarStatement(nany, kind || this.state.value, true);
  8876. }
  8877. this.expect(75);
  8878. return this.tsParseEnumDeclaration(nany, {
  8879. const: true,
  8880. declare: true
  8881. });
  8882. case 129:
  8883. {
  8884. const result = this.tsParseInterfaceDeclaration(nany, {
  8885. declare: true
  8886. });
  8887. if (result) return result;
  8888. }
  8889. default:
  8890. if (tokenIsIdentifier(startType)) {
  8891. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8892. }
  8893. }
  8894. });
  8895. }
  8896. tsTryParseExportDeclaration() {
  8897. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  8898. }
  8899. tsParseExpressionStatement(node, expr, decorators) {
  8900. switch (expr.name) {
  8901. case "declare":
  8902. {
  8903. const declaration = this.tsTryParseDeclare(node);
  8904. if (declaration) {
  8905. declaration.declare = true;
  8906. }
  8907. return declaration;
  8908. }
  8909. case "global":
  8910. if (this.match(5)) {
  8911. this.scope.enter(256);
  8912. this.prodParam.enter(0);
  8913. const mod = node;
  8914. mod.kind = "global";
  8915. {
  8916. node.global = true;
  8917. }
  8918. mod.id = expr;
  8919. mod.body = this.tsParseModuleBlock();
  8920. this.scope.exit();
  8921. this.prodParam.exit();
  8922. return this.finishNode(mod, "TSModuleDeclaration");
  8923. }
  8924. break;
  8925. default:
  8926. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8927. }
  8928. }
  8929. tsParseDeclaration(node, value, next, decorators) {
  8930. switch (value) {
  8931. case "abstract":
  8932. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8933. return this.tsParseAbstractDeclaration(node, decorators);
  8934. }
  8935. break;
  8936. case "module":
  8937. if (this.tsCheckLineTerminator(next)) {
  8938. if (this.match(134)) {
  8939. return this.tsParseAmbientExternalModuleDeclaration(node);
  8940. } else if (tokenIsIdentifier(this.state.type)) {
  8941. node.kind = "module";
  8942. return this.tsParseModuleOrNamespaceDeclaration(node);
  8943. }
  8944. }
  8945. break;
  8946. case "namespace":
  8947. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8948. node.kind = "namespace";
  8949. return this.tsParseModuleOrNamespaceDeclaration(node);
  8950. }
  8951. break;
  8952. case "type":
  8953. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8954. return this.tsParseTypeAliasDeclaration(node);
  8955. }
  8956. break;
  8957. }
  8958. }
  8959. tsCheckLineTerminator(next) {
  8960. if (next) {
  8961. if (this.hasFollowingLineBreak()) return false;
  8962. this.next();
  8963. return true;
  8964. }
  8965. return !this.isLineTerminator();
  8966. }
  8967. tsTryParseGenericAsyncArrowFunction(startLoc) {
  8968. if (!this.match(47)) return;
  8969. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8970. this.state.maybeInArrowParameters = true;
  8971. const res = this.tsTryParseAndCatch(() => {
  8972. const node = this.startNodeAt(startLoc);
  8973. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  8974. super.parseFunctionParams(node);
  8975. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  8976. this.expect(19);
  8977. return node;
  8978. });
  8979. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  8980. if (!res) return;
  8981. return super.parseArrowExpression(res, null, true);
  8982. }
  8983. tsParseTypeArgumentsInExpression() {
  8984. if (this.reScan_lt() !== 47) return;
  8985. return this.tsParseTypeArguments();
  8986. }
  8987. tsParseTypeArguments() {
  8988. const node = this.startNode();
  8989. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  8990. this.expect(47);
  8991. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  8992. }));
  8993. if (node.params.length === 0) {
  8994. this.raise(TSErrors.EmptyTypeArguments, node);
  8995. } else if (!this.state.inType && this.curContext() === types.brace) {
  8996. this.reScan_lt_gt();
  8997. }
  8998. this.expect(48);
  8999. return this.finishNode(node, "TSTypeParameterInstantiation");
  9000. }
  9001. tsIsDeclarationStart() {
  9002. return tokenIsTSDeclarationStart(this.state.type);
  9003. }
  9004. isExportDefaultSpecifier() {
  9005. if (this.tsIsDeclarationStart()) return false;
  9006. return super.isExportDefaultSpecifier();
  9007. }
  9008. parseAssignableListItem(flags, decorators) {
  9009. const startLoc = this.state.startLoc;
  9010. const modified = {};
  9011. this.tsParseModifiers({
  9012. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9013. }, modified);
  9014. const accessibility = modified.accessibility;
  9015. const override = modified.override;
  9016. const readonly = modified.readonly;
  9017. if (!(flags & 4) && (accessibility || readonly || override)) {
  9018. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  9019. }
  9020. const left = this.parseMaybeDefault();
  9021. if (flags & 2) {
  9022. this.parseFunctionParamType(left);
  9023. }
  9024. const elt = this.parseMaybeDefault(left.loc.start, left);
  9025. if (accessibility || readonly || override) {
  9026. const pp = this.startNodeAt(startLoc);
  9027. if (decorators.length) {
  9028. pp.decorators = decorators;
  9029. }
  9030. if (accessibility) pp.accessibility = accessibility;
  9031. if (readonly) pp.readonly = readonly;
  9032. if (override) pp.override = override;
  9033. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9034. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  9035. }
  9036. pp.parameter = elt;
  9037. return this.finishNode(pp, "TSParameterProperty");
  9038. }
  9039. if (decorators.length) {
  9040. left.decorators = decorators;
  9041. }
  9042. return elt;
  9043. }
  9044. isSimpleParameter(node) {
  9045. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9046. }
  9047. tsDisallowOptionalPattern(node) {
  9048. for (const param of node.params) {
  9049. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9050. this.raise(TSErrors.PatternIsOptional, param);
  9051. }
  9052. }
  9053. }
  9054. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9055. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9056. this.tsDisallowOptionalPattern(node);
  9057. }
  9058. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9059. if (this.match(14)) {
  9060. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9061. }
  9062. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9063. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9064. return this.finishNode(node, bodilessType);
  9065. }
  9066. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9067. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  9068. if (node.declare) {
  9069. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9070. }
  9071. }
  9072. this.tsDisallowOptionalPattern(node);
  9073. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9074. }
  9075. registerFunctionStatementId(node) {
  9076. if (!node.body && node.id) {
  9077. this.checkIdentifier(node.id, 1024);
  9078. } else {
  9079. super.registerFunctionStatementId(node);
  9080. }
  9081. }
  9082. tsCheckForInvalidTypeCasts(items) {
  9083. items.forEach(node => {
  9084. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9085. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  9086. }
  9087. });
  9088. }
  9089. toReferencedList(exprList, isInParens) {
  9090. this.tsCheckForInvalidTypeCasts(exprList);
  9091. return exprList;
  9092. }
  9093. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9094. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9095. if (node.type === "ArrayExpression") {
  9096. this.tsCheckForInvalidTypeCasts(node.elements);
  9097. }
  9098. return node;
  9099. }
  9100. parseSubscript(base, startLoc, noCalls, state) {
  9101. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9102. this.state.canStartJSXElement = false;
  9103. this.next();
  9104. const nonNullExpression = this.startNodeAt(startLoc);
  9105. nonNullExpression.expression = base;
  9106. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9107. }
  9108. let isOptionalCall = false;
  9109. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9110. if (noCalls) {
  9111. state.stop = true;
  9112. return base;
  9113. }
  9114. state.optionalChainMember = isOptionalCall = true;
  9115. this.next();
  9116. }
  9117. if (this.match(47) || this.match(51)) {
  9118. let missingParenErrorLoc;
  9119. const result = this.tsTryParseAndCatch(() => {
  9120. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9121. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9122. if (asyncArrowFn) {
  9123. return asyncArrowFn;
  9124. }
  9125. }
  9126. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9127. if (!typeArguments) return;
  9128. if (isOptionalCall && !this.match(10)) {
  9129. missingParenErrorLoc = this.state.curPosition();
  9130. return;
  9131. }
  9132. if (tokenIsTemplate(this.state.type)) {
  9133. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9134. {
  9135. result.typeParameters = typeArguments;
  9136. }
  9137. return result;
  9138. }
  9139. if (!noCalls && this.eat(10)) {
  9140. const node = this.startNodeAt(startLoc);
  9141. node.callee = base;
  9142. node.arguments = this.parseCallExpressionArguments(11);
  9143. this.tsCheckForInvalidTypeCasts(node.arguments);
  9144. {
  9145. node.typeParameters = typeArguments;
  9146. }
  9147. if (state.optionalChainMember) {
  9148. node.optional = isOptionalCall;
  9149. }
  9150. return this.finishCallExpression(node, state.optionalChainMember);
  9151. }
  9152. const tokenType = this.state.type;
  9153. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9154. return;
  9155. }
  9156. const node = this.startNodeAt(startLoc);
  9157. node.expression = base;
  9158. {
  9159. node.typeParameters = typeArguments;
  9160. }
  9161. return this.finishNode(node, "TSInstantiationExpression");
  9162. });
  9163. if (missingParenErrorLoc) {
  9164. this.unexpected(missingParenErrorLoc, 10);
  9165. }
  9166. if (result) {
  9167. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  9168. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  9169. }
  9170. return result;
  9171. }
  9172. }
  9173. return super.parseSubscript(base, startLoc, noCalls, state);
  9174. }
  9175. parseNewCallee(node) {
  9176. var _callee$extra;
  9177. super.parseNewCallee(node);
  9178. const {
  9179. callee
  9180. } = node;
  9181. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9182. {
  9183. node.typeParameters = callee.typeParameters;
  9184. }
  9185. node.callee = callee.expression;
  9186. }
  9187. }
  9188. parseExprOp(left, leftStartLoc, minPrec) {
  9189. let isSatisfies;
  9190. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9191. const node = this.startNodeAt(leftStartLoc);
  9192. node.expression = left;
  9193. node.typeAnnotation = this.tsInType(() => {
  9194. this.next();
  9195. if (this.match(75)) {
  9196. if (isSatisfies) {
  9197. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9198. keyword: "const"
  9199. });
  9200. }
  9201. return this.tsParseTypeReference();
  9202. }
  9203. return this.tsParseType();
  9204. });
  9205. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9206. this.reScan_lt_gt();
  9207. return this.parseExprOp(node, leftStartLoc, minPrec);
  9208. }
  9209. return super.parseExprOp(left, leftStartLoc, minPrec);
  9210. }
  9211. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9212. if (!this.state.isAmbientContext) {
  9213. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9214. }
  9215. }
  9216. checkImportReflection(node) {
  9217. super.checkImportReflection(node);
  9218. if (node.module && node.importKind !== "value") {
  9219. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9220. }
  9221. }
  9222. checkDuplicateExports() {}
  9223. isPotentialImportPhase(isExport) {
  9224. if (super.isPotentialImportPhase(isExport)) return true;
  9225. if (this.isContextual(130)) {
  9226. const ch = this.lookaheadCharCode();
  9227. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9228. }
  9229. return !isExport && this.isContextual(87);
  9230. }
  9231. applyImportPhase(node, isExport, phase, loc) {
  9232. super.applyImportPhase(node, isExport, phase, loc);
  9233. if (isExport) {
  9234. node.exportKind = phase === "type" ? "type" : "value";
  9235. } else {
  9236. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9237. }
  9238. }
  9239. parseImport(node) {
  9240. if (this.match(134)) {
  9241. node.importKind = "value";
  9242. return super.parseImport(node);
  9243. }
  9244. let importNode;
  9245. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9246. node.importKind = "value";
  9247. return this.tsParseImportEqualsDeclaration(node);
  9248. } else if (this.isContextual(130)) {
  9249. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9250. if (this.lookaheadCharCode() === 61) {
  9251. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9252. } else {
  9253. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9254. }
  9255. } else {
  9256. importNode = super.parseImport(node);
  9257. }
  9258. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9259. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9260. }
  9261. return importNode;
  9262. }
  9263. parseExport(node, decorators) {
  9264. if (this.match(83)) {
  9265. const nodeImportEquals = node;
  9266. this.next();
  9267. let maybeDefaultIdentifier = null;
  9268. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9269. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9270. } else {
  9271. nodeImportEquals.importKind = "value";
  9272. }
  9273. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9274. {
  9275. return declaration;
  9276. }
  9277. } else if (this.eat(29)) {
  9278. const assign = node;
  9279. assign.expression = super.parseExpression();
  9280. this.semicolon();
  9281. this.sawUnambiguousESM = true;
  9282. return this.finishNode(assign, "TSExportAssignment");
  9283. } else if (this.eatContextual(93)) {
  9284. const decl = node;
  9285. this.expectContextual(128);
  9286. decl.id = this.parseIdentifier();
  9287. this.semicolon();
  9288. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9289. } else {
  9290. return super.parseExport(node, decorators);
  9291. }
  9292. }
  9293. isAbstractClass() {
  9294. return this.isContextual(124) && this.lookahead().type === 80;
  9295. }
  9296. parseExportDefaultExpression() {
  9297. if (this.isAbstractClass()) {
  9298. const cls = this.startNode();
  9299. this.next();
  9300. cls.abstract = true;
  9301. return this.parseClass(cls, true, true);
  9302. }
  9303. if (this.match(129)) {
  9304. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9305. if (result) return result;
  9306. }
  9307. return super.parseExportDefaultExpression();
  9308. }
  9309. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9310. const {
  9311. isAmbientContext
  9312. } = this.state;
  9313. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9314. if (!isAmbientContext) return declaration;
  9315. for (const {
  9316. id,
  9317. init
  9318. } of declaration.declarations) {
  9319. if (!init) continue;
  9320. if (kind !== "const" || !!id.typeAnnotation) {
  9321. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9322. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9323. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9324. }
  9325. }
  9326. return declaration;
  9327. }
  9328. parseStatementContent(flags, decorators) {
  9329. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9330. const node = this.startNode();
  9331. this.expect(75);
  9332. return this.tsParseEnumDeclaration(node, {
  9333. const: true
  9334. });
  9335. }
  9336. if (this.isContextual(126)) {
  9337. return this.tsParseEnumDeclaration(this.startNode());
  9338. }
  9339. if (this.isContextual(129)) {
  9340. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9341. if (result) return result;
  9342. }
  9343. return super.parseStatementContent(flags, decorators);
  9344. }
  9345. parseAccessModifier() {
  9346. return this.tsParseModifier(["public", "protected", "private"]);
  9347. }
  9348. tsHasSomeModifiers(member, modifiers) {
  9349. return modifiers.some(modifier => {
  9350. if (tsIsAccessModifier(modifier)) {
  9351. return member.accessibility === modifier;
  9352. }
  9353. return !!member[modifier];
  9354. });
  9355. }
  9356. tsIsStartOfStaticBlocks() {
  9357. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9358. }
  9359. parseClassMember(classBody, member, state) {
  9360. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9361. this.tsParseModifiers({
  9362. allowedModifiers: modifiers,
  9363. disallowedModifiers: ["in", "out"],
  9364. stopOnStartOfClassStaticBlock: true,
  9365. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9366. }, member);
  9367. const callParseClassMemberWithIsStatic = () => {
  9368. if (this.tsIsStartOfStaticBlocks()) {
  9369. this.next();
  9370. this.next();
  9371. if (this.tsHasSomeModifiers(member, modifiers)) {
  9372. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9373. }
  9374. super.parseClassStaticBlock(classBody, member);
  9375. } else {
  9376. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9377. }
  9378. };
  9379. if (member.declare) {
  9380. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9381. } else {
  9382. callParseClassMemberWithIsStatic();
  9383. }
  9384. }
  9385. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9386. const idx = this.tsTryParseIndexSignature(member);
  9387. if (idx) {
  9388. classBody.body.push(idx);
  9389. if (member.abstract) {
  9390. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9391. }
  9392. if (member.accessibility) {
  9393. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9394. modifier: member.accessibility
  9395. });
  9396. }
  9397. if (member.declare) {
  9398. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9399. }
  9400. if (member.override) {
  9401. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9402. }
  9403. return;
  9404. }
  9405. if (!this.state.inAbstractClass && member.abstract) {
  9406. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9407. }
  9408. if (member.override) {
  9409. if (!state.hadSuperClass) {
  9410. this.raise(TSErrors.OverrideNotInSubClass, member);
  9411. }
  9412. }
  9413. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9414. }
  9415. parsePostMemberNameModifiers(methodOrProp) {
  9416. const optional = this.eat(17);
  9417. if (optional) methodOrProp.optional = true;
  9418. if (methodOrProp.readonly && this.match(10)) {
  9419. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9420. }
  9421. if (methodOrProp.declare && this.match(10)) {
  9422. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9423. }
  9424. }
  9425. parseExpressionStatement(node, expr, decorators) {
  9426. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9427. return decl || super.parseExpressionStatement(node, expr, decorators);
  9428. }
  9429. shouldParseExportDeclaration() {
  9430. if (this.tsIsDeclarationStart()) return true;
  9431. return super.shouldParseExportDeclaration();
  9432. }
  9433. parseConditional(expr, startLoc, refExpressionErrors) {
  9434. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9435. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9436. }
  9437. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9438. if (!result.node) {
  9439. if (result.error) {
  9440. super.setOptionalParametersError(refExpressionErrors, result.error);
  9441. }
  9442. return expr;
  9443. }
  9444. if (result.error) this.state = result.failState;
  9445. return result.node;
  9446. }
  9447. parseParenItem(node, startLoc) {
  9448. const newNode = super.parseParenItem(node, startLoc);
  9449. if (this.eat(17)) {
  9450. newNode.optional = true;
  9451. this.resetEndLocation(node);
  9452. }
  9453. if (this.match(14)) {
  9454. const typeCastNode = this.startNodeAt(startLoc);
  9455. typeCastNode.expression = node;
  9456. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9457. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9458. }
  9459. return node;
  9460. }
  9461. parseExportDeclaration(node) {
  9462. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9463. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9464. }
  9465. const startLoc = this.state.startLoc;
  9466. const isDeclare = this.eatContextual(125);
  9467. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9468. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9469. }
  9470. const isIdentifier = tokenIsIdentifier(this.state.type);
  9471. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9472. if (!declaration) return null;
  9473. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9474. node.exportKind = "type";
  9475. }
  9476. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  9477. this.resetStartLocation(declaration, startLoc);
  9478. declaration.declare = true;
  9479. }
  9480. return declaration;
  9481. }
  9482. parseClassId(node, isStatement, optionalId, bindingType) {
  9483. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9484. return;
  9485. }
  9486. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9487. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9488. if (typeParameters) node.typeParameters = typeParameters;
  9489. }
  9490. parseClassPropertyAnnotation(node) {
  9491. if (!node.optional) {
  9492. if (this.eat(35)) {
  9493. node.definite = true;
  9494. } else if (this.eat(17)) {
  9495. node.optional = true;
  9496. }
  9497. }
  9498. const type = this.tsTryParseTypeAnnotation();
  9499. if (type) node.typeAnnotation = type;
  9500. }
  9501. parseClassProperty(node) {
  9502. this.parseClassPropertyAnnotation(node);
  9503. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9504. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9505. }
  9506. if (node.abstract && this.match(29)) {
  9507. const {
  9508. key
  9509. } = node;
  9510. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9511. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9512. });
  9513. }
  9514. return super.parseClassProperty(node);
  9515. }
  9516. parseClassPrivateProperty(node) {
  9517. if (node.abstract) {
  9518. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9519. }
  9520. if (node.accessibility) {
  9521. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9522. modifier: node.accessibility
  9523. });
  9524. }
  9525. this.parseClassPropertyAnnotation(node);
  9526. return super.parseClassPrivateProperty(node);
  9527. }
  9528. parseClassAccessorProperty(node) {
  9529. this.parseClassPropertyAnnotation(node);
  9530. if (node.optional) {
  9531. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9532. }
  9533. return super.parseClassAccessorProperty(node);
  9534. }
  9535. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9536. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9537. if (typeParameters && isConstructor) {
  9538. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9539. }
  9540. const {
  9541. declare = false,
  9542. kind
  9543. } = method;
  9544. if (declare && (kind === "get" || kind === "set")) {
  9545. this.raise(TSErrors.DeclareAccessor, method, {
  9546. kind
  9547. });
  9548. }
  9549. if (typeParameters) method.typeParameters = typeParameters;
  9550. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9551. }
  9552. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9553. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9554. if (typeParameters) method.typeParameters = typeParameters;
  9555. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9556. }
  9557. declareClassPrivateMethodInScope(node, kind) {
  9558. if (node.type === "TSDeclareMethod") return;
  9559. if (node.type === "MethodDefinition" && !hasOwnProperty.call(node.value, "body")) {
  9560. return;
  9561. }
  9562. super.declareClassPrivateMethodInScope(node, kind);
  9563. }
  9564. parseClassSuper(node) {
  9565. super.parseClassSuper(node);
  9566. if (node.superClass && (this.match(47) || this.match(51))) {
  9567. {
  9568. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9569. }
  9570. }
  9571. if (this.eatContextual(113)) {
  9572. node.implements = this.tsParseHeritageClause("implements");
  9573. }
  9574. }
  9575. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9576. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9577. if (typeParameters) prop.typeParameters = typeParameters;
  9578. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9579. }
  9580. parseFunctionParams(node, isConstructor) {
  9581. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9582. if (typeParameters) node.typeParameters = typeParameters;
  9583. super.parseFunctionParams(node, isConstructor);
  9584. }
  9585. parseVarId(decl, kind) {
  9586. super.parseVarId(decl, kind);
  9587. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9588. decl.definite = true;
  9589. }
  9590. const type = this.tsTryParseTypeAnnotation();
  9591. if (type) {
  9592. decl.id.typeAnnotation = type;
  9593. this.resetEndLocation(decl.id);
  9594. }
  9595. }
  9596. parseAsyncArrowFromCallExpression(node, call) {
  9597. if (this.match(14)) {
  9598. node.returnType = this.tsParseTypeAnnotation();
  9599. }
  9600. return super.parseAsyncArrowFromCallExpression(node, call);
  9601. }
  9602. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9603. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9604. let state;
  9605. let jsx;
  9606. let typeCast;
  9607. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  9608. state = this.state.clone();
  9609. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9610. if (!jsx.error) return jsx.node;
  9611. const {
  9612. context
  9613. } = this.state;
  9614. const currentContext = context[context.length - 1];
  9615. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9616. context.pop();
  9617. }
  9618. }
  9619. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9620. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9621. }
  9622. if (!state || state === this.state) state = this.state.clone();
  9623. let typeParameters;
  9624. const arrow = this.tryParse(abort => {
  9625. var _expr$extra, _typeParameters;
  9626. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9627. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9628. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9629. abort();
  9630. }
  9631. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9632. this.resetStartLocationFromNode(expr, typeParameters);
  9633. }
  9634. expr.typeParameters = typeParameters;
  9635. return expr;
  9636. }, state);
  9637. if (!arrow.error && !arrow.aborted) {
  9638. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9639. return arrow.node;
  9640. }
  9641. if (!jsx) {
  9642. assert(!this.hasPlugin("jsx"));
  9643. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9644. if (!typeCast.error) return typeCast.node;
  9645. }
  9646. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9647. this.state = jsx.failState;
  9648. return jsx.node;
  9649. }
  9650. if (arrow.node) {
  9651. this.state = arrow.failState;
  9652. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9653. return arrow.node;
  9654. }
  9655. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9656. this.state = typeCast.failState;
  9657. return typeCast.node;
  9658. }
  9659. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9660. }
  9661. reportReservedArrowTypeParam(node) {
  9662. var _node$extra;
  9663. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9664. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9665. }
  9666. }
  9667. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9668. if (!this.hasPlugin("jsx") && this.match(47)) {
  9669. return this.tsParseTypeAssertion();
  9670. }
  9671. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9672. }
  9673. parseArrow(node) {
  9674. if (this.match(14)) {
  9675. const result = this.tryParse(abort => {
  9676. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9677. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9678. return returnType;
  9679. });
  9680. if (result.aborted) return;
  9681. if (!result.thrown) {
  9682. if (result.error) this.state = result.failState;
  9683. node.returnType = result.node;
  9684. }
  9685. }
  9686. return super.parseArrow(node);
  9687. }
  9688. parseFunctionParamType(param) {
  9689. if (this.eat(17)) {
  9690. param.optional = true;
  9691. }
  9692. const type = this.tsTryParseTypeAnnotation();
  9693. if (type) param.typeAnnotation = type;
  9694. this.resetEndLocation(param);
  9695. return param;
  9696. }
  9697. isAssignable(node, isBinding) {
  9698. switch (node.type) {
  9699. case "TSTypeCastExpression":
  9700. return this.isAssignable(node.expression, isBinding);
  9701. case "TSParameterProperty":
  9702. return true;
  9703. default:
  9704. return super.isAssignable(node, isBinding);
  9705. }
  9706. }
  9707. toAssignable(node, isLHS = false) {
  9708. switch (node.type) {
  9709. case "ParenthesizedExpression":
  9710. this.toAssignableParenthesizedExpression(node, isLHS);
  9711. break;
  9712. case "TSAsExpression":
  9713. case "TSSatisfiesExpression":
  9714. case "TSNonNullExpression":
  9715. case "TSTypeAssertion":
  9716. if (isLHS) {
  9717. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9718. } else {
  9719. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9720. }
  9721. this.toAssignable(node.expression, isLHS);
  9722. break;
  9723. case "AssignmentExpression":
  9724. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9725. node.left = this.typeCastToParameter(node.left);
  9726. }
  9727. default:
  9728. super.toAssignable(node, isLHS);
  9729. }
  9730. }
  9731. toAssignableParenthesizedExpression(node, isLHS) {
  9732. switch (node.expression.type) {
  9733. case "TSAsExpression":
  9734. case "TSSatisfiesExpression":
  9735. case "TSNonNullExpression":
  9736. case "TSTypeAssertion":
  9737. case "ParenthesizedExpression":
  9738. this.toAssignable(node.expression, isLHS);
  9739. break;
  9740. default:
  9741. super.toAssignable(node, isLHS);
  9742. }
  9743. }
  9744. checkToRestConversion(node, allowPattern) {
  9745. switch (node.type) {
  9746. case "TSAsExpression":
  9747. case "TSSatisfiesExpression":
  9748. case "TSTypeAssertion":
  9749. case "TSNonNullExpression":
  9750. this.checkToRestConversion(node.expression, false);
  9751. break;
  9752. default:
  9753. super.checkToRestConversion(node, allowPattern);
  9754. }
  9755. }
  9756. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9757. switch (type) {
  9758. case "TSTypeCastExpression":
  9759. return true;
  9760. case "TSParameterProperty":
  9761. return "parameter";
  9762. case "TSNonNullExpression":
  9763. case "TSInstantiationExpression":
  9764. return "expression";
  9765. case "TSAsExpression":
  9766. case "TSSatisfiesExpression":
  9767. case "TSTypeAssertion":
  9768. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  9769. default:
  9770. return super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9771. }
  9772. }
  9773. parseBindingAtom() {
  9774. if (this.state.type === 78) {
  9775. return this.parseIdentifier(true);
  9776. }
  9777. return super.parseBindingAtom();
  9778. }
  9779. parseMaybeDecoratorArguments(expr, startLoc) {
  9780. if (this.match(47) || this.match(51)) {
  9781. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9782. if (this.match(10)) {
  9783. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  9784. {
  9785. call.typeParameters = typeArguments;
  9786. }
  9787. return call;
  9788. }
  9789. this.unexpected(null, 10);
  9790. }
  9791. return super.parseMaybeDecoratorArguments(expr, startLoc);
  9792. }
  9793. checkCommaAfterRest(close) {
  9794. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9795. this.next();
  9796. return false;
  9797. }
  9798. return super.checkCommaAfterRest(close);
  9799. }
  9800. isClassMethod() {
  9801. return this.match(47) || super.isClassMethod();
  9802. }
  9803. isClassProperty() {
  9804. return this.match(35) || this.match(14) || super.isClassProperty();
  9805. }
  9806. parseMaybeDefault(startLoc, left) {
  9807. const node = super.parseMaybeDefault(startLoc, left);
  9808. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9809. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  9810. }
  9811. return node;
  9812. }
  9813. getTokenFromCode(code) {
  9814. if (this.state.inType) {
  9815. if (code === 62) {
  9816. this.finishOp(48, 1);
  9817. return;
  9818. }
  9819. if (code === 60) {
  9820. this.finishOp(47, 1);
  9821. return;
  9822. }
  9823. }
  9824. super.getTokenFromCode(code);
  9825. }
  9826. reScan_lt_gt() {
  9827. const {
  9828. type
  9829. } = this.state;
  9830. if (type === 47) {
  9831. this.state.pos -= 1;
  9832. this.readToken_lt();
  9833. } else if (type === 48) {
  9834. this.state.pos -= 1;
  9835. this.readToken_gt();
  9836. }
  9837. }
  9838. reScan_lt() {
  9839. const {
  9840. type
  9841. } = this.state;
  9842. if (type === 51) {
  9843. this.state.pos -= 2;
  9844. this.finishOp(47, 1);
  9845. return 47;
  9846. }
  9847. return type;
  9848. }
  9849. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9850. for (let i = 0; i < exprList.length; i++) {
  9851. const expr = exprList[i];
  9852. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9853. exprList[i] = this.typeCastToParameter(expr);
  9854. }
  9855. }
  9856. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9857. }
  9858. typeCastToParameter(node) {
  9859. node.expression.typeAnnotation = node.typeAnnotation;
  9860. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9861. return node.expression;
  9862. }
  9863. shouldParseArrow(params) {
  9864. if (this.match(14)) {
  9865. return params.every(expr => this.isAssignable(expr, true));
  9866. }
  9867. return super.shouldParseArrow(params);
  9868. }
  9869. shouldParseAsyncArrow() {
  9870. return this.match(14) || super.shouldParseAsyncArrow();
  9871. }
  9872. canHaveLeadingDecorator() {
  9873. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9874. }
  9875. jsxParseOpeningElementAfterName(node) {
  9876. if (this.match(47) || this.match(51)) {
  9877. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9878. if (typeArguments) {
  9879. {
  9880. node.typeParameters = typeArguments;
  9881. }
  9882. }
  9883. }
  9884. return super.jsxParseOpeningElementAfterName(node);
  9885. }
  9886. getGetterSetterExpectedParamCount(method) {
  9887. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9888. const params = this.getObjectOrClassMethodParams(method);
  9889. const firstParam = params[0];
  9890. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9891. return hasContextParam ? baseCount + 1 : baseCount;
  9892. }
  9893. parseCatchClauseParam() {
  9894. const param = super.parseCatchClauseParam();
  9895. const type = this.tsTryParseTypeAnnotation();
  9896. if (type) {
  9897. param.typeAnnotation = type;
  9898. this.resetEndLocation(param);
  9899. }
  9900. return param;
  9901. }
  9902. tsInAmbientContext(cb) {
  9903. const {
  9904. isAmbientContext: oldIsAmbientContext,
  9905. strict: oldStrict
  9906. } = this.state;
  9907. this.state.isAmbientContext = true;
  9908. this.state.strict = false;
  9909. try {
  9910. return cb();
  9911. } finally {
  9912. this.state.isAmbientContext = oldIsAmbientContext;
  9913. this.state.strict = oldStrict;
  9914. }
  9915. }
  9916. parseClass(node, isStatement, optionalId) {
  9917. const oldInAbstractClass = this.state.inAbstractClass;
  9918. this.state.inAbstractClass = !!node.abstract;
  9919. try {
  9920. return super.parseClass(node, isStatement, optionalId);
  9921. } finally {
  9922. this.state.inAbstractClass = oldInAbstractClass;
  9923. }
  9924. }
  9925. tsParseAbstractDeclaration(node, decorators) {
  9926. if (this.match(80)) {
  9927. node.abstract = true;
  9928. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  9929. } else if (this.isContextual(129)) {
  9930. if (!this.hasFollowingLineBreak()) {
  9931. node.abstract = true;
  9932. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, node);
  9933. return this.tsParseInterfaceDeclaration(node);
  9934. }
  9935. } else {
  9936. this.unexpected(null, 80);
  9937. }
  9938. }
  9939. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  9940. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  9941. if (method.abstract) {
  9942. const hasEstreePlugin = this.hasPlugin("estree");
  9943. const methodFn = hasEstreePlugin ? method.value : method;
  9944. if (methodFn.body) {
  9945. const {
  9946. key
  9947. } = method;
  9948. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  9949. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9950. });
  9951. }
  9952. }
  9953. return method;
  9954. }
  9955. tsParseTypeParameterName() {
  9956. const typeName = this.parseIdentifier();
  9957. return typeName.name;
  9958. }
  9959. shouldParseAsAmbientContext() {
  9960. return !!this.getPluginOption("typescript", "dts");
  9961. }
  9962. parse() {
  9963. if (this.shouldParseAsAmbientContext()) {
  9964. this.state.isAmbientContext = true;
  9965. }
  9966. return super.parse();
  9967. }
  9968. getExpression() {
  9969. if (this.shouldParseAsAmbientContext()) {
  9970. this.state.isAmbientContext = true;
  9971. }
  9972. return super.getExpression();
  9973. }
  9974. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  9975. if (!isString && isMaybeTypeOnly) {
  9976. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  9977. return this.finishNode(node, "ExportSpecifier");
  9978. }
  9979. node.exportKind = "value";
  9980. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  9981. }
  9982. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  9983. if (!importedIsString && isMaybeTypeOnly) {
  9984. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  9985. return this.finishNode(specifier, "ImportSpecifier");
  9986. }
  9987. specifier.importKind = "value";
  9988. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  9989. }
  9990. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  9991. const leftOfAsKey = isImport ? "imported" : "local";
  9992. const rightOfAsKey = isImport ? "local" : "exported";
  9993. let leftOfAs = node[leftOfAsKey];
  9994. let rightOfAs;
  9995. let hasTypeSpecifier = false;
  9996. let canParseAsKeyword = true;
  9997. const loc = leftOfAs.loc.start;
  9998. if (this.isContextual(93)) {
  9999. const firstAs = this.parseIdentifier();
  10000. if (this.isContextual(93)) {
  10001. const secondAs = this.parseIdentifier();
  10002. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10003. hasTypeSpecifier = true;
  10004. leftOfAs = firstAs;
  10005. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10006. canParseAsKeyword = false;
  10007. } else {
  10008. rightOfAs = secondAs;
  10009. canParseAsKeyword = false;
  10010. }
  10011. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10012. canParseAsKeyword = false;
  10013. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10014. } else {
  10015. hasTypeSpecifier = true;
  10016. leftOfAs = firstAs;
  10017. }
  10018. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10019. hasTypeSpecifier = true;
  10020. if (isImport) {
  10021. leftOfAs = this.parseIdentifier(true);
  10022. if (!this.isContextual(93)) {
  10023. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10024. }
  10025. } else {
  10026. leftOfAs = this.parseModuleExportName();
  10027. }
  10028. }
  10029. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10030. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  10031. }
  10032. node[leftOfAsKey] = leftOfAs;
  10033. node[rightOfAsKey] = rightOfAs;
  10034. const kindKey = isImport ? "importKind" : "exportKind";
  10035. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10036. if (canParseAsKeyword && this.eatContextual(93)) {
  10037. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10038. }
  10039. if (!node[rightOfAsKey]) {
  10040. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  10041. }
  10042. if (isImport) {
  10043. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10044. }
  10045. }
  10046. };
  10047. function isPossiblyLiteralEnum(expression) {
  10048. if (expression.type !== "MemberExpression") return false;
  10049. const {
  10050. computed,
  10051. property
  10052. } = expression;
  10053. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10054. return false;
  10055. }
  10056. return isUncomputedMemberExpressionChain(expression.object);
  10057. }
  10058. function isValidAmbientConstInitializer(expression, estree) {
  10059. var _expression$extra;
  10060. const {
  10061. type
  10062. } = expression;
  10063. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10064. return false;
  10065. }
  10066. if (estree) {
  10067. if (type === "Literal") {
  10068. const {
  10069. value
  10070. } = expression;
  10071. if (typeof value === "string" || typeof value === "boolean") {
  10072. return true;
  10073. }
  10074. }
  10075. } else {
  10076. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10077. return true;
  10078. }
  10079. }
  10080. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10081. return true;
  10082. }
  10083. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10084. return true;
  10085. }
  10086. if (isPossiblyLiteralEnum(expression)) {
  10087. return true;
  10088. }
  10089. return false;
  10090. }
  10091. function isNumber(expression, estree) {
  10092. if (estree) {
  10093. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10094. }
  10095. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10096. }
  10097. function isNegativeNumber(expression, estree) {
  10098. if (expression.type === "UnaryExpression") {
  10099. const {
  10100. operator,
  10101. argument
  10102. } = expression;
  10103. if (operator === "-" && isNumber(argument, estree)) {
  10104. return true;
  10105. }
  10106. }
  10107. return false;
  10108. }
  10109. function isUncomputedMemberExpressionChain(expression) {
  10110. if (expression.type === "Identifier") return true;
  10111. if (expression.type !== "MemberExpression" || expression.computed) {
  10112. return false;
  10113. }
  10114. return isUncomputedMemberExpressionChain(expression.object);
  10115. }
  10116. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10117. ClassNameIsRequired: "A class name is required.",
  10118. UnexpectedSpace: "Unexpected space in placeholder."
  10119. });
  10120. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10121. parsePlaceholder(expectedNode) {
  10122. if (this.match(133)) {
  10123. const node = this.startNode();
  10124. this.next();
  10125. this.assertNoSpace();
  10126. node.name = super.parseIdentifier(true);
  10127. this.assertNoSpace();
  10128. this.expect(133);
  10129. return this.finishPlaceholder(node, expectedNode);
  10130. }
  10131. }
  10132. finishPlaceholder(node, expectedNode) {
  10133. let placeholder = node;
  10134. if (!placeholder.expectedNode || !placeholder.type) {
  10135. placeholder = this.finishNode(placeholder, "Placeholder");
  10136. }
  10137. placeholder.expectedNode = expectedNode;
  10138. return placeholder;
  10139. }
  10140. getTokenFromCode(code) {
  10141. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10142. this.finishOp(133, 2);
  10143. } else {
  10144. super.getTokenFromCode(code);
  10145. }
  10146. }
  10147. parseExprAtom(refExpressionErrors) {
  10148. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10149. }
  10150. parseIdentifier(liberal) {
  10151. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10152. }
  10153. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10154. if (word !== undefined) {
  10155. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10156. }
  10157. }
  10158. parseBindingAtom() {
  10159. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10160. }
  10161. isValidLVal(type, isParenthesized, binding) {
  10162. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10163. }
  10164. toAssignable(node, isLHS) {
  10165. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10166. node.expectedNode = "Pattern";
  10167. } else {
  10168. super.toAssignable(node, isLHS);
  10169. }
  10170. }
  10171. chStartsBindingIdentifier(ch, pos) {
  10172. if (super.chStartsBindingIdentifier(ch, pos)) {
  10173. return true;
  10174. }
  10175. const nextToken = this.lookahead();
  10176. if (nextToken.type === 133) {
  10177. return true;
  10178. }
  10179. return false;
  10180. }
  10181. verifyBreakContinue(node, isBreak) {
  10182. if (node.label && node.label.type === "Placeholder") return;
  10183. super.verifyBreakContinue(node, isBreak);
  10184. }
  10185. parseExpressionStatement(node, expr) {
  10186. var _expr$extra;
  10187. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10188. return super.parseExpressionStatement(node, expr);
  10189. }
  10190. if (this.match(14)) {
  10191. const stmt = node;
  10192. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10193. this.next();
  10194. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10195. return this.finishNode(stmt, "LabeledStatement");
  10196. }
  10197. this.semicolon();
  10198. const stmtPlaceholder = node;
  10199. stmtPlaceholder.name = expr.name;
  10200. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  10201. }
  10202. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10203. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10204. }
  10205. parseFunctionId(requireId) {
  10206. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10207. }
  10208. parseClass(node, isStatement, optionalId) {
  10209. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10210. this.next();
  10211. const oldStrict = this.state.strict;
  10212. const placeholder = this.parsePlaceholder("Identifier");
  10213. if (placeholder) {
  10214. if (this.match(81) || this.match(133) || this.match(5)) {
  10215. node.id = placeholder;
  10216. } else if (optionalId || !isStatement) {
  10217. node.id = null;
  10218. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10219. return this.finishNode(node, type);
  10220. } else {
  10221. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10222. }
  10223. } else {
  10224. this.parseClassId(node, isStatement, optionalId);
  10225. }
  10226. super.parseClassSuper(node);
  10227. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10228. return this.finishNode(node, type);
  10229. }
  10230. parseExport(node, decorators) {
  10231. const placeholder = this.parsePlaceholder("Identifier");
  10232. if (!placeholder) return super.parseExport(node, decorators);
  10233. const node2 = node;
  10234. if (!this.isContextual(98) && !this.match(12)) {
  10235. node2.specifiers = [];
  10236. node2.source = null;
  10237. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10238. return this.finishNode(node2, "ExportNamedDeclaration");
  10239. }
  10240. this.expectPlugin("exportDefaultFrom");
  10241. const specifier = this.startNode();
  10242. specifier.exported = placeholder;
  10243. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10244. return super.parseExport(node2, decorators);
  10245. }
  10246. isExportDefaultSpecifier() {
  10247. if (this.match(65)) {
  10248. const next = this.nextTokenStart();
  10249. if (this.isUnparsedContextual(next, "from")) {
  10250. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  10251. return true;
  10252. }
  10253. }
  10254. }
  10255. return super.isExportDefaultSpecifier();
  10256. }
  10257. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10258. var _specifiers;
  10259. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10260. return true;
  10261. }
  10262. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10263. }
  10264. checkExport(node) {
  10265. const {
  10266. specifiers
  10267. } = node;
  10268. if (specifiers != null && specifiers.length) {
  10269. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10270. }
  10271. super.checkExport(node);
  10272. node.specifiers = specifiers;
  10273. }
  10274. parseImport(node) {
  10275. const placeholder = this.parsePlaceholder("Identifier");
  10276. if (!placeholder) return super.parseImport(node);
  10277. node.specifiers = [];
  10278. if (!this.isContextual(98) && !this.match(12)) {
  10279. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10280. this.semicolon();
  10281. return this.finishNode(node, "ImportDeclaration");
  10282. }
  10283. const specifier = this.startNodeAtNode(placeholder);
  10284. specifier.local = placeholder;
  10285. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10286. if (this.eat(12)) {
  10287. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10288. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10289. }
  10290. this.expectContextual(98);
  10291. node.source = this.parseImportSource();
  10292. this.semicolon();
  10293. return this.finishNode(node, "ImportDeclaration");
  10294. }
  10295. parseImportSource() {
  10296. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10297. }
  10298. assertNoSpace() {
  10299. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  10300. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10301. }
  10302. }
  10303. };
  10304. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10305. parseV8Intrinsic() {
  10306. if (this.match(54)) {
  10307. const v8IntrinsicStartLoc = this.state.startLoc;
  10308. const node = this.startNode();
  10309. this.next();
  10310. if (tokenIsIdentifier(this.state.type)) {
  10311. const name = this.parseIdentifierName();
  10312. const identifier = this.createIdentifier(node, name);
  10313. identifier.type = "V8IntrinsicIdentifier";
  10314. if (this.match(10)) {
  10315. return identifier;
  10316. }
  10317. }
  10318. this.unexpected(v8IntrinsicStartLoc);
  10319. }
  10320. }
  10321. parseExprAtom(refExpressionErrors) {
  10322. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10323. }
  10324. };
  10325. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10326. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10327. function validatePlugins(pluginsMap) {
  10328. if (pluginsMap.has("decorators")) {
  10329. if (pluginsMap.has("decorators-legacy")) {
  10330. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10331. }
  10332. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  10333. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10334. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10335. }
  10336. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  10337. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10338. throw new Error("'allowCallParenthesized' must be a boolean.");
  10339. }
  10340. }
  10341. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  10342. throw new Error("Cannot combine flow and typescript plugins.");
  10343. }
  10344. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  10345. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10346. }
  10347. if (pluginsMap.has("pipelineOperator")) {
  10348. var _pluginsMap$get;
  10349. const proposal = pluginsMap.get("pipelineOperator").proposal;
  10350. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10351. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10352. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10353. }
  10354. const tupleSyntaxIsHash = ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash";
  10355. if (proposal === "hack") {
  10356. if (pluginsMap.has("placeholders")) {
  10357. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10358. }
  10359. if (pluginsMap.has("v8intrinsic")) {
  10360. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10361. }
  10362. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  10363. if (!TOPIC_TOKENS.includes(topicToken)) {
  10364. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10365. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10366. }
  10367. if (topicToken === "#" && tupleSyntaxIsHash) {
  10368. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10369. }
  10370. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  10371. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10372. }
  10373. }
  10374. if (pluginsMap.has("moduleAttributes")) {
  10375. {
  10376. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  10377. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  10378. }
  10379. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  10380. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10381. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10382. }
  10383. }
  10384. }
  10385. if (pluginsMap.has("importAssertions")) {
  10386. if (pluginsMap.has("deprecatedImportAssert")) {
  10387. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  10388. }
  10389. }
  10390. if (!pluginsMap.has("deprecatedImportAssert") && pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  10391. {
  10392. pluginsMap.set("deprecatedImportAssert", {});
  10393. }
  10394. }
  10395. if (pluginsMap.has("recordAndTuple")) {
  10396. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  10397. if (syntaxType != null) {
  10398. {
  10399. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10400. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  10401. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10402. }
  10403. }
  10404. }
  10405. }
  10406. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  10407. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10408. error.missingPlugins = "doExpressions";
  10409. throw error;
  10410. }
  10411. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  10412. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10413. }
  10414. }
  10415. const mixinPlugins = {
  10416. estree,
  10417. jsx,
  10418. flow,
  10419. typescript,
  10420. v8intrinsic,
  10421. placeholders
  10422. };
  10423. const mixinPluginNames = Object.keys(mixinPlugins);
  10424. class ExpressionParser extends LValParser {
  10425. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10426. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10427. return;
  10428. }
  10429. const key = prop.key;
  10430. const name = key.type === "Identifier" ? key.name : key.value;
  10431. if (name === "__proto__") {
  10432. if (isRecord) {
  10433. this.raise(Errors.RecordNoProto, key);
  10434. return;
  10435. }
  10436. if (protoRef.used) {
  10437. if (refExpressionErrors) {
  10438. if (refExpressionErrors.doubleProtoLoc === null) {
  10439. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10440. }
  10441. } else {
  10442. this.raise(Errors.DuplicateProto, key);
  10443. }
  10444. }
  10445. protoRef.used = true;
  10446. }
  10447. }
  10448. shouldExitDescending(expr, potentialArrowAt) {
  10449. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  10450. }
  10451. getExpression() {
  10452. this.enterInitialScopes();
  10453. this.nextToken();
  10454. const expr = this.parseExpression();
  10455. if (!this.match(140)) {
  10456. this.unexpected();
  10457. }
  10458. this.finalizeRemainingComments();
  10459. expr.comments = this.comments;
  10460. expr.errors = this.state.errors;
  10461. if (this.optionFlags & 128) {
  10462. expr.tokens = this.tokens;
  10463. }
  10464. return expr;
  10465. }
  10466. parseExpression(disallowIn, refExpressionErrors) {
  10467. if (disallowIn) {
  10468. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10469. }
  10470. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10471. }
  10472. parseExpressionBase(refExpressionErrors) {
  10473. const startLoc = this.state.startLoc;
  10474. const expr = this.parseMaybeAssign(refExpressionErrors);
  10475. if (this.match(12)) {
  10476. const node = this.startNodeAt(startLoc);
  10477. node.expressions = [expr];
  10478. while (this.eat(12)) {
  10479. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10480. }
  10481. this.toReferencedList(node.expressions);
  10482. return this.finishNode(node, "SequenceExpression");
  10483. }
  10484. return expr;
  10485. }
  10486. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10487. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10488. }
  10489. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10490. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10491. }
  10492. setOptionalParametersError(refExpressionErrors, resultError) {
  10493. var _resultError$loc;
  10494. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10495. }
  10496. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10497. const startLoc = this.state.startLoc;
  10498. if (this.isContextual(108)) {
  10499. if (this.prodParam.hasYield) {
  10500. let left = this.parseYield();
  10501. if (afterLeftParse) {
  10502. left = afterLeftParse.call(this, left, startLoc);
  10503. }
  10504. return left;
  10505. }
  10506. }
  10507. let ownExpressionErrors;
  10508. if (refExpressionErrors) {
  10509. ownExpressionErrors = false;
  10510. } else {
  10511. refExpressionErrors = new ExpressionErrors();
  10512. ownExpressionErrors = true;
  10513. }
  10514. const {
  10515. type
  10516. } = this.state;
  10517. if (type === 10 || tokenIsIdentifier(type)) {
  10518. this.state.potentialArrowAt = this.state.start;
  10519. }
  10520. let left = this.parseMaybeConditional(refExpressionErrors);
  10521. if (afterLeftParse) {
  10522. left = afterLeftParse.call(this, left, startLoc);
  10523. }
  10524. if (tokenIsAssignment(this.state.type)) {
  10525. const node = this.startNodeAt(startLoc);
  10526. const operator = this.state.value;
  10527. node.operator = operator;
  10528. if (this.match(29)) {
  10529. this.toAssignable(left, true);
  10530. node.left = left;
  10531. const startIndex = startLoc.index;
  10532. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10533. refExpressionErrors.doubleProtoLoc = null;
  10534. }
  10535. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10536. refExpressionErrors.shorthandAssignLoc = null;
  10537. }
  10538. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10539. this.checkDestructuringPrivate(refExpressionErrors);
  10540. refExpressionErrors.privateKeyLoc = null;
  10541. }
  10542. } else {
  10543. node.left = left;
  10544. }
  10545. this.next();
  10546. node.right = this.parseMaybeAssign();
  10547. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"));
  10548. return node;
  10549. } else if (ownExpressionErrors) {
  10550. this.checkExpressionErrors(refExpressionErrors, true);
  10551. }
  10552. return left;
  10553. }
  10554. parseMaybeConditional(refExpressionErrors) {
  10555. const startLoc = this.state.startLoc;
  10556. const potentialArrowAt = this.state.potentialArrowAt;
  10557. const expr = this.parseExprOps(refExpressionErrors);
  10558. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10559. return expr;
  10560. }
  10561. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10562. }
  10563. parseConditional(expr, startLoc, refExpressionErrors) {
  10564. if (this.eat(17)) {
  10565. const node = this.startNodeAt(startLoc);
  10566. node.test = expr;
  10567. node.consequent = this.parseMaybeAssignAllowIn();
  10568. this.expect(14);
  10569. node.alternate = this.parseMaybeAssign();
  10570. return this.finishNode(node, "ConditionalExpression");
  10571. }
  10572. return expr;
  10573. }
  10574. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10575. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10576. }
  10577. parseExprOps(refExpressionErrors) {
  10578. const startLoc = this.state.startLoc;
  10579. const potentialArrowAt = this.state.potentialArrowAt;
  10580. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10581. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10582. return expr;
  10583. }
  10584. return this.parseExprOp(expr, startLoc, -1);
  10585. }
  10586. parseExprOp(left, leftStartLoc, minPrec) {
  10587. if (this.isPrivateName(left)) {
  10588. const value = this.getPrivateNameSV(left);
  10589. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10590. this.raise(Errors.PrivateInExpectedIn, left, {
  10591. identifierName: value
  10592. });
  10593. }
  10594. this.classScope.usePrivateName(value, left.loc.start);
  10595. }
  10596. const op = this.state.type;
  10597. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10598. let prec = tokenOperatorPrecedence(op);
  10599. if (prec > minPrec) {
  10600. if (op === 39) {
  10601. this.expectPlugin("pipelineOperator");
  10602. if (this.state.inFSharpPipelineDirectBody) {
  10603. return left;
  10604. }
  10605. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10606. }
  10607. const node = this.startNodeAt(leftStartLoc);
  10608. node.left = left;
  10609. node.operator = this.state.value;
  10610. const logical = op === 41 || op === 42;
  10611. const coalesce = op === 40;
  10612. if (coalesce) {
  10613. prec = tokenOperatorPrecedence(42);
  10614. }
  10615. this.next();
  10616. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10617. proposal: "minimal"
  10618. }])) {
  10619. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10620. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  10621. }
  10622. }
  10623. node.right = this.parseExprOpRightExpr(op, prec);
  10624. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10625. const nextOp = this.state.type;
  10626. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10627. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  10628. }
  10629. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10630. }
  10631. }
  10632. return left;
  10633. }
  10634. parseExprOpRightExpr(op, prec) {
  10635. const startLoc = this.state.startLoc;
  10636. switch (op) {
  10637. case 39:
  10638. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10639. case "hack":
  10640. return this.withTopicBindingContext(() => {
  10641. return this.parseHackPipeBody();
  10642. });
  10643. case "fsharp":
  10644. return this.withSoloAwaitPermittingContext(() => {
  10645. return this.parseFSharpPipelineBody(prec);
  10646. });
  10647. }
  10648. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  10649. return this.withTopicBindingContext(() => {
  10650. if (this.prodParam.hasYield && this.isContextual(108)) {
  10651. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  10652. }
  10653. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10654. });
  10655. }
  10656. default:
  10657. return this.parseExprOpBaseRightExpr(op, prec);
  10658. }
  10659. }
  10660. parseExprOpBaseRightExpr(op, prec) {
  10661. const startLoc = this.state.startLoc;
  10662. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10663. }
  10664. parseHackPipeBody() {
  10665. var _body$extra;
  10666. const {
  10667. startLoc
  10668. } = this.state;
  10669. const body = this.parseMaybeAssign();
  10670. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10671. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10672. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  10673. type: body.type
  10674. });
  10675. }
  10676. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10677. this.raise(Errors.PipeTopicUnused, startLoc);
  10678. }
  10679. return body;
  10680. }
  10681. checkExponentialAfterUnary(node) {
  10682. if (this.match(57)) {
  10683. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  10684. }
  10685. }
  10686. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10687. const startLoc = this.state.startLoc;
  10688. const isAwait = this.isContextual(96);
  10689. if (isAwait && this.recordAwaitIfAllowed()) {
  10690. this.next();
  10691. const expr = this.parseAwait(startLoc);
  10692. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10693. return expr;
  10694. }
  10695. const update = this.match(34);
  10696. const node = this.startNode();
  10697. if (tokenIsPrefix(this.state.type)) {
  10698. node.operator = this.state.value;
  10699. node.prefix = true;
  10700. if (this.match(72)) {
  10701. this.expectPlugin("throwExpressions");
  10702. }
  10703. const isDelete = this.match(89);
  10704. this.next();
  10705. node.argument = this.parseMaybeUnary(null, true);
  10706. this.checkExpressionErrors(refExpressionErrors, true);
  10707. if (this.state.strict && isDelete) {
  10708. const arg = node.argument;
  10709. if (arg.type === "Identifier") {
  10710. this.raise(Errors.StrictDelete, node);
  10711. } else if (this.hasPropertyAsPrivateName(arg)) {
  10712. this.raise(Errors.DeletePrivateField, node);
  10713. }
  10714. }
  10715. if (!update) {
  10716. if (!sawUnary) {
  10717. this.checkExponentialAfterUnary(node);
  10718. }
  10719. return this.finishNode(node, "UnaryExpression");
  10720. }
  10721. }
  10722. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10723. if (isAwait) {
  10724. const {
  10725. type
  10726. } = this.state;
  10727. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10728. if (startsExpr && !this.isAmbiguousAwait()) {
  10729. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  10730. return this.parseAwait(startLoc);
  10731. }
  10732. }
  10733. return expr;
  10734. }
  10735. parseUpdate(node, update, refExpressionErrors) {
  10736. if (update) {
  10737. const updateExpressionNode = node;
  10738. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  10739. return node;
  10740. }
  10741. const startLoc = this.state.startLoc;
  10742. let expr = this.parseExprSubscripts(refExpressionErrors);
  10743. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10744. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10745. const node = this.startNodeAt(startLoc);
  10746. node.operator = this.state.value;
  10747. node.prefix = false;
  10748. node.argument = expr;
  10749. this.next();
  10750. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  10751. }
  10752. return expr;
  10753. }
  10754. parseExprSubscripts(refExpressionErrors) {
  10755. const startLoc = this.state.startLoc;
  10756. const potentialArrowAt = this.state.potentialArrowAt;
  10757. const expr = this.parseExprAtom(refExpressionErrors);
  10758. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10759. return expr;
  10760. }
  10761. return this.parseSubscripts(expr, startLoc);
  10762. }
  10763. parseSubscripts(base, startLoc, noCalls) {
  10764. const state = {
  10765. optionalChainMember: false,
  10766. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10767. stop: false
  10768. };
  10769. do {
  10770. base = this.parseSubscript(base, startLoc, noCalls, state);
  10771. state.maybeAsyncArrow = false;
  10772. } while (!state.stop);
  10773. return base;
  10774. }
  10775. parseSubscript(base, startLoc, noCalls, state) {
  10776. const {
  10777. type
  10778. } = this.state;
  10779. if (!noCalls && type === 15) {
  10780. return this.parseBind(base, startLoc, noCalls, state);
  10781. } else if (tokenIsTemplate(type)) {
  10782. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10783. }
  10784. let optional = false;
  10785. if (type === 18) {
  10786. if (noCalls) {
  10787. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  10788. if (this.lookaheadCharCode() === 40) {
  10789. state.stop = true;
  10790. return base;
  10791. }
  10792. }
  10793. state.optionalChainMember = optional = true;
  10794. this.next();
  10795. }
  10796. if (!noCalls && this.match(10)) {
  10797. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10798. } else {
  10799. const computed = this.eat(0);
  10800. if (computed || optional || this.eat(16)) {
  10801. return this.parseMember(base, startLoc, state, computed, optional);
  10802. } else {
  10803. state.stop = true;
  10804. return base;
  10805. }
  10806. }
  10807. }
  10808. parseMember(base, startLoc, state, computed, optional) {
  10809. const node = this.startNodeAt(startLoc);
  10810. node.object = base;
  10811. node.computed = computed;
  10812. if (computed) {
  10813. node.property = this.parseExpression();
  10814. this.expect(3);
  10815. } else if (this.match(139)) {
  10816. if (base.type === "Super") {
  10817. this.raise(Errors.SuperPrivateField, startLoc);
  10818. }
  10819. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10820. node.property = this.parsePrivateName();
  10821. } else {
  10822. node.property = this.parseIdentifier(true);
  10823. }
  10824. if (state.optionalChainMember) {
  10825. node.optional = optional;
  10826. return this.finishNode(node, "OptionalMemberExpression");
  10827. } else {
  10828. return this.finishNode(node, "MemberExpression");
  10829. }
  10830. }
  10831. parseBind(base, startLoc, noCalls, state) {
  10832. const node = this.startNodeAt(startLoc);
  10833. node.object = base;
  10834. this.next();
  10835. node.callee = this.parseNoCallExpr();
  10836. state.stop = true;
  10837. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10838. }
  10839. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10840. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10841. let refExpressionErrors = null;
  10842. this.state.maybeInArrowParameters = true;
  10843. this.next();
  10844. const node = this.startNodeAt(startLoc);
  10845. node.callee = base;
  10846. const {
  10847. maybeAsyncArrow,
  10848. optionalChainMember
  10849. } = state;
  10850. if (maybeAsyncArrow) {
  10851. this.expressionScope.enter(newAsyncArrowScope());
  10852. refExpressionErrors = new ExpressionErrors();
  10853. }
  10854. if (optionalChainMember) {
  10855. node.optional = optional;
  10856. }
  10857. if (optional) {
  10858. node.arguments = this.parseCallExpressionArguments(11);
  10859. } else {
  10860. node.arguments = this.parseCallExpressionArguments(11, base.type !== "Super", node, refExpressionErrors);
  10861. }
  10862. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10863. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10864. state.stop = true;
  10865. this.checkDestructuringPrivate(refExpressionErrors);
  10866. this.expressionScope.validateAsPattern();
  10867. this.expressionScope.exit();
  10868. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  10869. } else {
  10870. if (maybeAsyncArrow) {
  10871. this.checkExpressionErrors(refExpressionErrors, true);
  10872. this.expressionScope.exit();
  10873. }
  10874. this.toReferencedArguments(finishedNode);
  10875. }
  10876. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10877. return finishedNode;
  10878. }
  10879. toReferencedArguments(node, isParenthesizedExpr) {
  10880. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  10881. }
  10882. parseTaggedTemplateExpression(base, startLoc, state) {
  10883. const node = this.startNodeAt(startLoc);
  10884. node.tag = base;
  10885. node.quasi = this.parseTemplate(true);
  10886. if (state.optionalChainMember) {
  10887. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  10888. }
  10889. return this.finishNode(node, "TaggedTemplateExpression");
  10890. }
  10891. atPossibleAsyncArrow(base) {
  10892. 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;
  10893. }
  10894. finishCallExpression(node, optional) {
  10895. if (node.callee.type === "Import") {
  10896. if (node.arguments.length === 0 || node.arguments.length > 2) {
  10897. this.raise(Errors.ImportCallArity, node);
  10898. } else {
  10899. for (const arg of node.arguments) {
  10900. if (arg.type === "SpreadElement") {
  10901. this.raise(Errors.ImportCallSpreadArgument, arg);
  10902. }
  10903. }
  10904. }
  10905. }
  10906. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  10907. }
  10908. parseCallExpressionArguments(close, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  10909. const elts = [];
  10910. let first = true;
  10911. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10912. this.state.inFSharpPipelineDirectBody = false;
  10913. while (!this.eat(close)) {
  10914. if (first) {
  10915. first = false;
  10916. } else {
  10917. this.expect(12);
  10918. if (this.match(close)) {
  10919. if (nodeForExtra) {
  10920. this.addTrailingCommaExtraToNode(nodeForExtra);
  10921. }
  10922. this.next();
  10923. break;
  10924. }
  10925. }
  10926. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  10927. }
  10928. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  10929. return elts;
  10930. }
  10931. shouldParseAsyncArrow() {
  10932. return this.match(19) && !this.canInsertSemicolon();
  10933. }
  10934. parseAsyncArrowFromCallExpression(node, call) {
  10935. var _call$extra;
  10936. this.resetPreviousNodeTrailingComments(call);
  10937. this.expect(19);
  10938. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  10939. if (call.innerComments) {
  10940. setInnerComments(node, call.innerComments);
  10941. }
  10942. if (call.callee.trailingComments) {
  10943. setInnerComments(node, call.callee.trailingComments);
  10944. }
  10945. return node;
  10946. }
  10947. parseNoCallExpr() {
  10948. const startLoc = this.state.startLoc;
  10949. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  10950. }
  10951. parseExprAtom(refExpressionErrors) {
  10952. let node;
  10953. let decorators = null;
  10954. const {
  10955. type
  10956. } = this.state;
  10957. switch (type) {
  10958. case 79:
  10959. return this.parseSuper();
  10960. case 83:
  10961. node = this.startNode();
  10962. this.next();
  10963. if (this.match(16)) {
  10964. return this.parseImportMetaProperty(node);
  10965. }
  10966. if (this.match(10)) {
  10967. if (this.optionFlags & 256) {
  10968. return this.parseImportCall(node);
  10969. } else {
  10970. return this.finishNode(node, "Import");
  10971. }
  10972. } else {
  10973. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  10974. return this.finishNode(node, "Import");
  10975. }
  10976. case 78:
  10977. node = this.startNode();
  10978. this.next();
  10979. return this.finishNode(node, "ThisExpression");
  10980. case 90:
  10981. {
  10982. return this.parseDo(this.startNode(), false);
  10983. }
  10984. case 56:
  10985. case 31:
  10986. {
  10987. this.readRegexp();
  10988. return this.parseRegExpLiteral(this.state.value);
  10989. }
  10990. case 135:
  10991. return this.parseNumericLiteral(this.state.value);
  10992. case 136:
  10993. return this.parseBigIntLiteral(this.state.value);
  10994. case 134:
  10995. return this.parseStringLiteral(this.state.value);
  10996. case 84:
  10997. return this.parseNullLiteral();
  10998. case 85:
  10999. return this.parseBooleanLiteral(true);
  11000. case 86:
  11001. return this.parseBooleanLiteral(false);
  11002. case 10:
  11003. {
  11004. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11005. return this.parseParenAndDistinguishExpression(canBeArrow);
  11006. }
  11007. case 2:
  11008. case 1:
  11009. {
  11010. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11011. }
  11012. case 0:
  11013. {
  11014. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11015. }
  11016. case 6:
  11017. case 7:
  11018. {
  11019. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11020. }
  11021. case 5:
  11022. {
  11023. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11024. }
  11025. case 68:
  11026. return this.parseFunctionOrFunctionSent();
  11027. case 26:
  11028. decorators = this.parseDecorators();
  11029. case 80:
  11030. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11031. case 77:
  11032. return this.parseNewOrNewTarget();
  11033. case 25:
  11034. case 24:
  11035. return this.parseTemplate(false);
  11036. case 15:
  11037. {
  11038. node = this.startNode();
  11039. this.next();
  11040. node.object = null;
  11041. const callee = node.callee = this.parseNoCallExpr();
  11042. if (callee.type === "MemberExpression") {
  11043. return this.finishNode(node, "BindExpression");
  11044. } else {
  11045. throw this.raise(Errors.UnsupportedBind, callee);
  11046. }
  11047. }
  11048. case 139:
  11049. {
  11050. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  11051. identifierName: this.state.value
  11052. });
  11053. return this.parsePrivateName();
  11054. }
  11055. case 33:
  11056. {
  11057. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11058. }
  11059. case 32:
  11060. {
  11061. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11062. }
  11063. case 37:
  11064. case 38:
  11065. {
  11066. return this.parseTopicReference("hack");
  11067. }
  11068. case 44:
  11069. case 54:
  11070. case 27:
  11071. {
  11072. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11073. if (pipeProposal) {
  11074. return this.parseTopicReference(pipeProposal);
  11075. }
  11076. this.unexpected();
  11077. break;
  11078. }
  11079. case 47:
  11080. {
  11081. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11082. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11083. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11084. } else {
  11085. this.unexpected();
  11086. }
  11087. break;
  11088. }
  11089. default:
  11090. if (type === 137) {
  11091. return this.parseDecimalLiteral(this.state.value);
  11092. }
  11093. if (tokenIsIdentifier(type)) {
  11094. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11095. return this.parseModuleExpression();
  11096. }
  11097. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11098. const containsEsc = this.state.containsEsc;
  11099. const id = this.parseIdentifier();
  11100. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11101. const {
  11102. type
  11103. } = this.state;
  11104. if (type === 68) {
  11105. this.resetPreviousNodeTrailingComments(id);
  11106. this.next();
  11107. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11108. } else if (tokenIsIdentifier(type)) {
  11109. if (this.lookaheadCharCode() === 61) {
  11110. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11111. } else {
  11112. return id;
  11113. }
  11114. } else if (type === 90) {
  11115. this.resetPreviousNodeTrailingComments(id);
  11116. return this.parseDo(this.startNodeAtNode(id), true);
  11117. }
  11118. }
  11119. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11120. this.next();
  11121. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11122. }
  11123. return id;
  11124. } else {
  11125. this.unexpected();
  11126. }
  11127. }
  11128. }
  11129. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11130. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11131. if (pipeProposal) {
  11132. this.state.type = topicTokenType;
  11133. this.state.value = topicTokenValue;
  11134. this.state.pos--;
  11135. this.state.end--;
  11136. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11137. return this.parseTopicReference(pipeProposal);
  11138. } else {
  11139. this.unexpected();
  11140. }
  11141. }
  11142. parseTopicReference(pipeProposal) {
  11143. const node = this.startNode();
  11144. const startLoc = this.state.startLoc;
  11145. const tokenType = this.state.type;
  11146. this.next();
  11147. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11148. }
  11149. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11150. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11151. if (pipeProposal === "hack") {
  11152. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11153. this.raise(Errors.PipeTopicUnbound, startLoc);
  11154. }
  11155. this.registerTopicReference();
  11156. return this.finishNode(node, "TopicReference");
  11157. } else {
  11158. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11159. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  11160. }
  11161. this.registerTopicReference();
  11162. return this.finishNode(node, "PipelinePrimaryTopicReference");
  11163. }
  11164. } else {
  11165. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11166. token: tokenLabelName(tokenType)
  11167. });
  11168. }
  11169. }
  11170. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11171. switch (pipeProposal) {
  11172. case "hack":
  11173. {
  11174. return this.hasPlugin(["pipelineOperator", {
  11175. topicToken: tokenLabelName(tokenType)
  11176. }]);
  11177. }
  11178. case "smart":
  11179. return tokenType === 27;
  11180. default:
  11181. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11182. }
  11183. }
  11184. parseAsyncArrowUnaryFunction(node) {
  11185. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11186. const params = [this.parseIdentifier()];
  11187. this.prodParam.exit();
  11188. if (this.hasPrecedingLineBreak()) {
  11189. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11190. }
  11191. this.expect(19);
  11192. return this.parseArrowExpression(node, params, true);
  11193. }
  11194. parseDo(node, isAsync) {
  11195. this.expectPlugin("doExpressions");
  11196. if (isAsync) {
  11197. this.expectPlugin("asyncDoExpressions");
  11198. }
  11199. node.async = isAsync;
  11200. this.next();
  11201. const oldLabels = this.state.labels;
  11202. this.state.labels = [];
  11203. if (isAsync) {
  11204. this.prodParam.enter(2);
  11205. node.body = this.parseBlock();
  11206. this.prodParam.exit();
  11207. } else {
  11208. node.body = this.parseBlock();
  11209. }
  11210. this.state.labels = oldLabels;
  11211. return this.finishNode(node, "DoExpression");
  11212. }
  11213. parseSuper() {
  11214. const node = this.startNode();
  11215. this.next();
  11216. if (this.match(10) && !this.scope.allowDirectSuper && !(this.optionFlags & 16)) {
  11217. this.raise(Errors.SuperNotAllowed, node);
  11218. } else if (!this.scope.allowSuper && !(this.optionFlags & 16)) {
  11219. this.raise(Errors.UnexpectedSuper, node);
  11220. }
  11221. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11222. this.raise(Errors.UnsupportedSuper, node);
  11223. }
  11224. return this.finishNode(node, "Super");
  11225. }
  11226. parsePrivateName() {
  11227. const node = this.startNode();
  11228. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11229. const name = this.state.value;
  11230. this.next();
  11231. node.id = this.createIdentifier(id, name);
  11232. return this.finishNode(node, "PrivateName");
  11233. }
  11234. parseFunctionOrFunctionSent() {
  11235. const node = this.startNode();
  11236. this.next();
  11237. if (this.prodParam.hasYield && this.match(16)) {
  11238. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11239. this.next();
  11240. if (this.match(103)) {
  11241. this.expectPlugin("functionSent");
  11242. } else if (!this.hasPlugin("functionSent")) {
  11243. this.unexpected();
  11244. }
  11245. return this.parseMetaProperty(node, meta, "sent");
  11246. }
  11247. return this.parseFunction(node);
  11248. }
  11249. parseMetaProperty(node, meta, propertyName) {
  11250. node.meta = meta;
  11251. const containsEsc = this.state.containsEsc;
  11252. node.property = this.parseIdentifier(true);
  11253. if (node.property.name !== propertyName || containsEsc) {
  11254. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11255. target: meta.name,
  11256. onlyValidPropertyName: propertyName
  11257. });
  11258. }
  11259. return this.finishNode(node, "MetaProperty");
  11260. }
  11261. parseImportMetaProperty(node) {
  11262. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11263. this.next();
  11264. if (this.isContextual(101)) {
  11265. if (!this.inModule) {
  11266. this.raise(Errors.ImportMetaOutsideModule, id);
  11267. }
  11268. this.sawUnambiguousESM = true;
  11269. } else if (this.isContextual(105) || this.isContextual(97)) {
  11270. const isSource = this.isContextual(105);
  11271. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11272. if (!(this.optionFlags & 256)) {
  11273. throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, this.state.startLoc, {
  11274. phase: this.state.value
  11275. });
  11276. }
  11277. this.next();
  11278. node.phase = isSource ? "source" : "defer";
  11279. return this.parseImportCall(node);
  11280. }
  11281. return this.parseMetaProperty(node, id, "meta");
  11282. }
  11283. parseLiteralAtNode(value, type, node) {
  11284. this.addExtra(node, "rawValue", value);
  11285. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11286. node.value = value;
  11287. this.next();
  11288. return this.finishNode(node, type);
  11289. }
  11290. parseLiteral(value, type) {
  11291. const node = this.startNode();
  11292. return this.parseLiteralAtNode(value, type, node);
  11293. }
  11294. parseStringLiteral(value) {
  11295. return this.parseLiteral(value, "StringLiteral");
  11296. }
  11297. parseNumericLiteral(value) {
  11298. return this.parseLiteral(value, "NumericLiteral");
  11299. }
  11300. parseBigIntLiteral(value) {
  11301. return this.parseLiteral(value, "BigIntLiteral");
  11302. }
  11303. parseDecimalLiteral(value) {
  11304. return this.parseLiteral(value, "DecimalLiteral");
  11305. }
  11306. parseRegExpLiteral(value) {
  11307. const node = this.startNode();
  11308. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11309. node.pattern = value.pattern;
  11310. node.flags = value.flags;
  11311. this.next();
  11312. return this.finishNode(node, "RegExpLiteral");
  11313. }
  11314. parseBooleanLiteral(value) {
  11315. const node = this.startNode();
  11316. node.value = value;
  11317. this.next();
  11318. return this.finishNode(node, "BooleanLiteral");
  11319. }
  11320. parseNullLiteral() {
  11321. const node = this.startNode();
  11322. this.next();
  11323. return this.finishNode(node, "NullLiteral");
  11324. }
  11325. parseParenAndDistinguishExpression(canBeArrow) {
  11326. const startLoc = this.state.startLoc;
  11327. let val;
  11328. this.next();
  11329. this.expressionScope.enter(newArrowHeadScope());
  11330. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11331. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11332. this.state.maybeInArrowParameters = true;
  11333. this.state.inFSharpPipelineDirectBody = false;
  11334. const innerStartLoc = this.state.startLoc;
  11335. const exprList = [];
  11336. const refExpressionErrors = new ExpressionErrors();
  11337. let first = true;
  11338. let spreadStartLoc;
  11339. let optionalCommaStartLoc;
  11340. while (!this.match(11)) {
  11341. if (first) {
  11342. first = false;
  11343. } else {
  11344. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11345. if (this.match(11)) {
  11346. optionalCommaStartLoc = this.state.startLoc;
  11347. break;
  11348. }
  11349. }
  11350. if (this.match(21)) {
  11351. const spreadNodeStartLoc = this.state.startLoc;
  11352. spreadStartLoc = this.state.startLoc;
  11353. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11354. if (!this.checkCommaAfterRest(41)) {
  11355. break;
  11356. }
  11357. } else {
  11358. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11359. }
  11360. }
  11361. const innerEndLoc = this.state.lastTokEndLoc;
  11362. this.expect(11);
  11363. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11364. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11365. let arrowNode = this.startNodeAt(startLoc);
  11366. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11367. this.checkDestructuringPrivate(refExpressionErrors);
  11368. this.expressionScope.validateAsPattern();
  11369. this.expressionScope.exit();
  11370. this.parseArrowExpression(arrowNode, exprList, false);
  11371. return arrowNode;
  11372. }
  11373. this.expressionScope.exit();
  11374. if (!exprList.length) {
  11375. this.unexpected(this.state.lastTokStartLoc);
  11376. }
  11377. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11378. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11379. this.checkExpressionErrors(refExpressionErrors, true);
  11380. this.toReferencedListDeep(exprList, true);
  11381. if (exprList.length > 1) {
  11382. val = this.startNodeAt(innerStartLoc);
  11383. val.expressions = exprList;
  11384. this.finishNode(val, "SequenceExpression");
  11385. this.resetEndLocation(val, innerEndLoc);
  11386. } else {
  11387. val = exprList[0];
  11388. }
  11389. return this.wrapParenthesis(startLoc, val);
  11390. }
  11391. wrapParenthesis(startLoc, expression) {
  11392. if (!(this.optionFlags & 512)) {
  11393. this.addExtra(expression, "parenthesized", true);
  11394. this.addExtra(expression, "parenStart", startLoc.index);
  11395. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11396. return expression;
  11397. }
  11398. const parenExpression = this.startNodeAt(startLoc);
  11399. parenExpression.expression = expression;
  11400. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11401. }
  11402. shouldParseArrow(params) {
  11403. return !this.canInsertSemicolon();
  11404. }
  11405. parseArrow(node) {
  11406. if (this.eat(19)) {
  11407. return node;
  11408. }
  11409. }
  11410. parseParenItem(node, startLoc) {
  11411. return node;
  11412. }
  11413. parseNewOrNewTarget() {
  11414. const node = this.startNode();
  11415. this.next();
  11416. if (this.match(16)) {
  11417. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11418. this.next();
  11419. const metaProp = this.parseMetaProperty(node, meta, "target");
  11420. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !(this.optionFlags & 4)) {
  11421. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11422. }
  11423. return metaProp;
  11424. }
  11425. return this.parseNew(node);
  11426. }
  11427. parseNew(node) {
  11428. this.parseNewCallee(node);
  11429. if (this.eat(10)) {
  11430. const args = this.parseExprList(11);
  11431. this.toReferencedList(args);
  11432. node.arguments = args;
  11433. } else {
  11434. node.arguments = [];
  11435. }
  11436. return this.finishNode(node, "NewExpression");
  11437. }
  11438. parseNewCallee(node) {
  11439. const isImport = this.match(83);
  11440. const callee = this.parseNoCallExpr();
  11441. node.callee = callee;
  11442. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11443. this.raise(Errors.ImportCallNotNewExpression, callee);
  11444. }
  11445. }
  11446. parseTemplateElement(isTagged) {
  11447. const {
  11448. start,
  11449. startLoc,
  11450. end,
  11451. value
  11452. } = this.state;
  11453. const elemStart = start + 1;
  11454. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11455. if (value === null) {
  11456. if (!isTagged) {
  11457. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11458. }
  11459. }
  11460. const isTail = this.match(24);
  11461. const endOffset = isTail ? -1 : -2;
  11462. const elemEnd = end + endOffset;
  11463. elem.value = {
  11464. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11465. cooked: value === null ? null : value.slice(1, endOffset)
  11466. };
  11467. elem.tail = isTail;
  11468. this.next();
  11469. const finishedNode = this.finishNode(elem, "TemplateElement");
  11470. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11471. return finishedNode;
  11472. }
  11473. parseTemplate(isTagged) {
  11474. const node = this.startNode();
  11475. let curElt = this.parseTemplateElement(isTagged);
  11476. const quasis = [curElt];
  11477. const substitutions = [];
  11478. while (!curElt.tail) {
  11479. substitutions.push(this.parseTemplateSubstitution());
  11480. this.readTemplateContinuation();
  11481. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11482. }
  11483. node.expressions = substitutions;
  11484. node.quasis = quasis;
  11485. return this.finishNode(node, "TemplateLiteral");
  11486. }
  11487. parseTemplateSubstitution() {
  11488. return this.parseExpression();
  11489. }
  11490. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11491. if (isRecord) {
  11492. this.expectPlugin("recordAndTuple");
  11493. }
  11494. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11495. this.state.inFSharpPipelineDirectBody = false;
  11496. const propHash = Object.create(null);
  11497. let first = true;
  11498. const node = this.startNode();
  11499. node.properties = [];
  11500. this.next();
  11501. while (!this.match(close)) {
  11502. if (first) {
  11503. first = false;
  11504. } else {
  11505. this.expect(12);
  11506. if (this.match(close)) {
  11507. this.addTrailingCommaExtraToNode(node);
  11508. break;
  11509. }
  11510. }
  11511. let prop;
  11512. if (isPattern) {
  11513. prop = this.parseBindingProperty();
  11514. } else {
  11515. prop = this.parsePropertyDefinition(refExpressionErrors);
  11516. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11517. }
  11518. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11519. this.raise(Errors.InvalidRecordProperty, prop);
  11520. }
  11521. {
  11522. if (prop.shorthand) {
  11523. this.addExtra(prop, "shorthand", true);
  11524. }
  11525. }
  11526. node.properties.push(prop);
  11527. }
  11528. this.next();
  11529. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11530. let type = "ObjectExpression";
  11531. if (isPattern) {
  11532. type = "ObjectPattern";
  11533. } else if (isRecord) {
  11534. type = "RecordExpression";
  11535. }
  11536. return this.finishNode(node, type);
  11537. }
  11538. addTrailingCommaExtraToNode(node) {
  11539. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11540. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11541. }
  11542. maybeAsyncOrAccessorProp(prop) {
  11543. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11544. }
  11545. parsePropertyDefinition(refExpressionErrors) {
  11546. let decorators = [];
  11547. if (this.match(26)) {
  11548. if (this.hasPlugin("decorators")) {
  11549. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11550. }
  11551. while (this.match(26)) {
  11552. decorators.push(this.parseDecorator());
  11553. }
  11554. }
  11555. const prop = this.startNode();
  11556. let isAsync = false;
  11557. let isAccessor = false;
  11558. let startLoc;
  11559. if (this.match(21)) {
  11560. if (decorators.length) this.unexpected();
  11561. return this.parseSpread();
  11562. }
  11563. if (decorators.length) {
  11564. prop.decorators = decorators;
  11565. decorators = [];
  11566. }
  11567. prop.method = false;
  11568. if (refExpressionErrors) {
  11569. startLoc = this.state.startLoc;
  11570. }
  11571. let isGenerator = this.eat(55);
  11572. this.parsePropertyNamePrefixOperator(prop);
  11573. const containsEsc = this.state.containsEsc;
  11574. this.parsePropertyName(prop, refExpressionErrors);
  11575. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11576. const {
  11577. key
  11578. } = prop;
  11579. const keyName = key.name;
  11580. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11581. isAsync = true;
  11582. this.resetPreviousNodeTrailingComments(key);
  11583. isGenerator = this.eat(55);
  11584. this.parsePropertyName(prop);
  11585. }
  11586. if (keyName === "get" || keyName === "set") {
  11587. isAccessor = true;
  11588. this.resetPreviousNodeTrailingComments(key);
  11589. prop.kind = keyName;
  11590. if (this.match(55)) {
  11591. isGenerator = true;
  11592. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11593. kind: keyName
  11594. });
  11595. this.next();
  11596. }
  11597. this.parsePropertyName(prop);
  11598. }
  11599. }
  11600. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11601. }
  11602. getGetterSetterExpectedParamCount(method) {
  11603. return method.kind === "get" ? 0 : 1;
  11604. }
  11605. getObjectOrClassMethodParams(method) {
  11606. return method.params;
  11607. }
  11608. checkGetterSetterParams(method) {
  11609. var _params;
  11610. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11611. const params = this.getObjectOrClassMethodParams(method);
  11612. if (params.length !== paramCount) {
  11613. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  11614. }
  11615. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11616. this.raise(Errors.BadSetterRestParameter, method);
  11617. }
  11618. }
  11619. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11620. if (isAccessor) {
  11621. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11622. this.checkGetterSetterParams(finishedProp);
  11623. return finishedProp;
  11624. }
  11625. if (isAsync || isGenerator || this.match(10)) {
  11626. if (isPattern) this.unexpected();
  11627. prop.kind = "method";
  11628. prop.method = true;
  11629. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11630. }
  11631. }
  11632. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11633. prop.shorthand = false;
  11634. if (this.eat(14)) {
  11635. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11636. return this.finishNode(prop, "ObjectProperty");
  11637. }
  11638. if (!prop.computed && prop.key.type === "Identifier") {
  11639. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11640. if (isPattern) {
  11641. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11642. } else if (this.match(29)) {
  11643. const shorthandAssignLoc = this.state.startLoc;
  11644. if (refExpressionErrors != null) {
  11645. if (refExpressionErrors.shorthandAssignLoc === null) {
  11646. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11647. }
  11648. } else {
  11649. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11650. }
  11651. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11652. } else {
  11653. prop.value = cloneIdentifier(prop.key);
  11654. }
  11655. prop.shorthand = true;
  11656. return this.finishNode(prop, "ObjectProperty");
  11657. }
  11658. }
  11659. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11660. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11661. if (!node) this.unexpected();
  11662. return node;
  11663. }
  11664. parsePropertyName(prop, refExpressionErrors) {
  11665. if (this.eat(0)) {
  11666. prop.computed = true;
  11667. prop.key = this.parseMaybeAssignAllowIn();
  11668. this.expect(3);
  11669. } else {
  11670. const {
  11671. type,
  11672. value
  11673. } = this.state;
  11674. let key;
  11675. if (tokenIsKeywordOrIdentifier(type)) {
  11676. key = this.parseIdentifier(true);
  11677. } else {
  11678. switch (type) {
  11679. case 135:
  11680. key = this.parseNumericLiteral(value);
  11681. break;
  11682. case 134:
  11683. key = this.parseStringLiteral(value);
  11684. break;
  11685. case 136:
  11686. key = this.parseBigIntLiteral(value);
  11687. break;
  11688. case 139:
  11689. {
  11690. const privateKeyLoc = this.state.startLoc;
  11691. if (refExpressionErrors != null) {
  11692. if (refExpressionErrors.privateKeyLoc === null) {
  11693. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11694. }
  11695. } else {
  11696. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  11697. }
  11698. key = this.parsePrivateName();
  11699. break;
  11700. }
  11701. default:
  11702. if (type === 137) {
  11703. key = this.parseDecimalLiteral(value);
  11704. break;
  11705. }
  11706. this.unexpected();
  11707. }
  11708. }
  11709. prop.key = key;
  11710. if (type !== 139) {
  11711. prop.computed = false;
  11712. }
  11713. }
  11714. }
  11715. initFunction(node, isAsync) {
  11716. node.id = null;
  11717. node.generator = false;
  11718. node.async = isAsync;
  11719. }
  11720. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11721. this.initFunction(node, isAsync);
  11722. node.generator = isGenerator;
  11723. this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
  11724. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11725. this.parseFunctionParams(node, isConstructor);
  11726. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11727. this.prodParam.exit();
  11728. this.scope.exit();
  11729. return finishedNode;
  11730. }
  11731. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11732. if (isTuple) {
  11733. this.expectPlugin("recordAndTuple");
  11734. }
  11735. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11736. this.state.inFSharpPipelineDirectBody = false;
  11737. const node = this.startNode();
  11738. this.next();
  11739. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11740. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11741. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11742. }
  11743. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11744. this.scope.enter(2 | 4);
  11745. let flags = functionFlags(isAsync, false);
  11746. if (!this.match(5) && this.prodParam.hasIn) {
  11747. flags |= 8;
  11748. }
  11749. this.prodParam.enter(flags);
  11750. this.initFunction(node, isAsync);
  11751. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11752. if (params) {
  11753. this.state.maybeInArrowParameters = true;
  11754. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11755. }
  11756. this.state.maybeInArrowParameters = false;
  11757. this.parseFunctionBody(node, true);
  11758. this.prodParam.exit();
  11759. this.scope.exit();
  11760. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11761. return this.finishNode(node, "ArrowFunctionExpression");
  11762. }
  11763. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11764. this.toAssignableList(params, trailingCommaLoc, false);
  11765. node.params = params;
  11766. }
  11767. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11768. this.parseFunctionBody(node, false, isMethod);
  11769. return this.finishNode(node, type);
  11770. }
  11771. parseFunctionBody(node, allowExpression, isMethod = false) {
  11772. const isExpression = allowExpression && !this.match(5);
  11773. this.expressionScope.enter(newExpressionScope());
  11774. if (isExpression) {
  11775. node.body = this.parseMaybeAssign();
  11776. this.checkParams(node, false, allowExpression, false);
  11777. } else {
  11778. const oldStrict = this.state.strict;
  11779. const oldLabels = this.state.labels;
  11780. this.state.labels = [];
  11781. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  11782. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11783. const nonSimple = !this.isSimpleParamList(node.params);
  11784. if (hasStrictModeDirective && nonSimple) {
  11785. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  11786. }
  11787. const strictModeChanged = !oldStrict && this.state.strict;
  11788. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11789. if (this.state.strict && node.id) {
  11790. this.checkIdentifier(node.id, 65, strictModeChanged);
  11791. }
  11792. });
  11793. this.prodParam.exit();
  11794. this.state.labels = oldLabels;
  11795. }
  11796. this.expressionScope.exit();
  11797. }
  11798. isSimpleParameter(node) {
  11799. return node.type === "Identifier";
  11800. }
  11801. isSimpleParamList(params) {
  11802. for (let i = 0, len = params.length; i < len; i++) {
  11803. if (!this.isSimpleParameter(params[i])) return false;
  11804. }
  11805. return true;
  11806. }
  11807. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11808. const checkClashes = !allowDuplicates && new Set();
  11809. const formalParameters = {
  11810. type: "FormalParameters"
  11811. };
  11812. for (const param of node.params) {
  11813. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  11814. }
  11815. }
  11816. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11817. const elts = [];
  11818. let first = true;
  11819. while (!this.eat(close)) {
  11820. if (first) {
  11821. first = false;
  11822. } else {
  11823. this.expect(12);
  11824. if (this.match(close)) {
  11825. if (nodeForExtra) {
  11826. this.addTrailingCommaExtraToNode(nodeForExtra);
  11827. }
  11828. this.next();
  11829. break;
  11830. }
  11831. }
  11832. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11833. }
  11834. return elts;
  11835. }
  11836. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  11837. let elt;
  11838. if (this.match(12)) {
  11839. if (!allowEmpty) {
  11840. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  11841. unexpected: ","
  11842. });
  11843. }
  11844. elt = null;
  11845. } else if (this.match(21)) {
  11846. const spreadNodeStartLoc = this.state.startLoc;
  11847. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  11848. } else if (this.match(17)) {
  11849. this.expectPlugin("partialApplication");
  11850. if (!allowPlaceholder) {
  11851. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  11852. }
  11853. const node = this.startNode();
  11854. this.next();
  11855. elt = this.finishNode(node, "ArgumentPlaceholder");
  11856. } else {
  11857. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  11858. }
  11859. return elt;
  11860. }
  11861. parseIdentifier(liberal) {
  11862. const node = this.startNode();
  11863. const name = this.parseIdentifierName(liberal);
  11864. return this.createIdentifier(node, name);
  11865. }
  11866. createIdentifier(node, name) {
  11867. node.name = name;
  11868. node.loc.identifierName = name;
  11869. return this.finishNode(node, "Identifier");
  11870. }
  11871. parseIdentifierName(liberal) {
  11872. let name;
  11873. const {
  11874. startLoc,
  11875. type
  11876. } = this.state;
  11877. if (tokenIsKeywordOrIdentifier(type)) {
  11878. name = this.state.value;
  11879. } else {
  11880. this.unexpected();
  11881. }
  11882. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  11883. if (liberal) {
  11884. if (tokenIsKeyword) {
  11885. this.replaceToken(132);
  11886. }
  11887. } else {
  11888. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  11889. }
  11890. this.next();
  11891. return name;
  11892. }
  11893. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  11894. if (word.length > 10) {
  11895. return;
  11896. }
  11897. if (!canBeReservedWord(word)) {
  11898. return;
  11899. }
  11900. if (checkKeywords && isKeyword(word)) {
  11901. this.raise(Errors.UnexpectedKeyword, startLoc, {
  11902. keyword: word
  11903. });
  11904. return;
  11905. }
  11906. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  11907. if (reservedTest(word, this.inModule)) {
  11908. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  11909. reservedWord: word
  11910. });
  11911. return;
  11912. } else if (word === "yield") {
  11913. if (this.prodParam.hasYield) {
  11914. this.raise(Errors.YieldBindingIdentifier, startLoc);
  11915. return;
  11916. }
  11917. } else if (word === "await") {
  11918. if (this.prodParam.hasAwait) {
  11919. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  11920. return;
  11921. }
  11922. if (this.scope.inStaticBlock) {
  11923. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  11924. return;
  11925. }
  11926. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  11927. } else if (word === "arguments") {
  11928. if (this.scope.inClassAndNotInNonArrowFunction) {
  11929. this.raise(Errors.ArgumentsInClass, startLoc);
  11930. return;
  11931. }
  11932. }
  11933. }
  11934. recordAwaitIfAllowed() {
  11935. const isAwaitAllowed = this.prodParam.hasAwait || this.optionFlags & 1 && !this.scope.inFunction;
  11936. if (isAwaitAllowed && !this.scope.inFunction) {
  11937. this.state.hasTopLevelAwait = true;
  11938. }
  11939. return isAwaitAllowed;
  11940. }
  11941. parseAwait(startLoc) {
  11942. const node = this.startNodeAt(startLoc);
  11943. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  11944. if (this.eat(55)) {
  11945. this.raise(Errors.ObsoleteAwaitStar, node);
  11946. }
  11947. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  11948. if (this.isAmbiguousAwait()) {
  11949. this.ambiguousScriptDifferentAst = true;
  11950. } else {
  11951. this.sawUnambiguousESM = true;
  11952. }
  11953. }
  11954. if (!this.state.soloAwait) {
  11955. node.argument = this.parseMaybeUnary(null, true);
  11956. }
  11957. return this.finishNode(node, "AwaitExpression");
  11958. }
  11959. isAmbiguousAwait() {
  11960. if (this.hasPrecedingLineBreak()) return true;
  11961. const {
  11962. type
  11963. } = this.state;
  11964. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  11965. }
  11966. parseYield() {
  11967. const node = this.startNode();
  11968. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  11969. this.next();
  11970. let delegating = false;
  11971. let argument = null;
  11972. if (!this.hasPrecedingLineBreak()) {
  11973. delegating = this.eat(55);
  11974. switch (this.state.type) {
  11975. case 13:
  11976. case 140:
  11977. case 8:
  11978. case 11:
  11979. case 3:
  11980. case 9:
  11981. case 14:
  11982. case 12:
  11983. if (!delegating) break;
  11984. default:
  11985. argument = this.parseMaybeAssign();
  11986. }
  11987. }
  11988. node.delegate = delegating;
  11989. node.argument = argument;
  11990. return this.finishNode(node, "YieldExpression");
  11991. }
  11992. parseImportCall(node) {
  11993. this.next();
  11994. node.source = this.parseMaybeAssignAllowIn();
  11995. node.options = null;
  11996. if (this.eat(12)) {
  11997. if (!this.match(11)) {
  11998. node.options = this.parseMaybeAssignAllowIn();
  11999. if (this.eat(12) && !this.match(11)) {
  12000. do {
  12001. this.parseMaybeAssignAllowIn();
  12002. } while (this.eat(12) && !this.match(11));
  12003. this.raise(Errors.ImportCallArity, node);
  12004. }
  12005. }
  12006. }
  12007. this.expect(11);
  12008. return this.finishNode(node, "ImportExpression");
  12009. }
  12010. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12011. if (this.hasPlugin(["pipelineOperator", {
  12012. proposal: "smart"
  12013. }])) {
  12014. if (left.type === "SequenceExpression") {
  12015. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  12016. }
  12017. }
  12018. }
  12019. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12020. if (this.isSimpleReference(childExpr)) {
  12021. const bodyNode = this.startNodeAt(startLoc);
  12022. bodyNode.callee = childExpr;
  12023. return this.finishNode(bodyNode, "PipelineBareFunction");
  12024. } else {
  12025. const bodyNode = this.startNodeAt(startLoc);
  12026. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12027. bodyNode.expression = childExpr;
  12028. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12029. }
  12030. }
  12031. isSimpleReference(expression) {
  12032. switch (expression.type) {
  12033. case "MemberExpression":
  12034. return !expression.computed && this.isSimpleReference(expression.object);
  12035. case "Identifier":
  12036. return true;
  12037. default:
  12038. return false;
  12039. }
  12040. }
  12041. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12042. if (this.match(19)) {
  12043. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  12044. }
  12045. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12046. this.raise(Errors.PipelineTopicUnused, startLoc);
  12047. }
  12048. }
  12049. withTopicBindingContext(callback) {
  12050. const outerContextTopicState = this.state.topicContext;
  12051. this.state.topicContext = {
  12052. maxNumOfResolvableTopics: 1,
  12053. maxTopicIndex: null
  12054. };
  12055. try {
  12056. return callback();
  12057. } finally {
  12058. this.state.topicContext = outerContextTopicState;
  12059. }
  12060. }
  12061. withSmartMixTopicForbiddingContext(callback) {
  12062. if (this.hasPlugin(["pipelineOperator", {
  12063. proposal: "smart"
  12064. }])) {
  12065. const outerContextTopicState = this.state.topicContext;
  12066. this.state.topicContext = {
  12067. maxNumOfResolvableTopics: 0,
  12068. maxTopicIndex: null
  12069. };
  12070. try {
  12071. return callback();
  12072. } finally {
  12073. this.state.topicContext = outerContextTopicState;
  12074. }
  12075. } else {
  12076. return callback();
  12077. }
  12078. }
  12079. withSoloAwaitPermittingContext(callback) {
  12080. const outerContextSoloAwaitState = this.state.soloAwait;
  12081. this.state.soloAwait = true;
  12082. try {
  12083. return callback();
  12084. } finally {
  12085. this.state.soloAwait = outerContextSoloAwaitState;
  12086. }
  12087. }
  12088. allowInAnd(callback) {
  12089. const flags = this.prodParam.currentFlags();
  12090. const prodParamToSet = 8 & ~flags;
  12091. if (prodParamToSet) {
  12092. this.prodParam.enter(flags | 8);
  12093. try {
  12094. return callback();
  12095. } finally {
  12096. this.prodParam.exit();
  12097. }
  12098. }
  12099. return callback();
  12100. }
  12101. disallowInAnd(callback) {
  12102. const flags = this.prodParam.currentFlags();
  12103. const prodParamToClear = 8 & flags;
  12104. if (prodParamToClear) {
  12105. this.prodParam.enter(flags & ~8);
  12106. try {
  12107. return callback();
  12108. } finally {
  12109. this.prodParam.exit();
  12110. }
  12111. }
  12112. return callback();
  12113. }
  12114. registerTopicReference() {
  12115. this.state.topicContext.maxTopicIndex = 0;
  12116. }
  12117. topicReferenceIsAllowedInCurrentContext() {
  12118. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12119. }
  12120. topicReferenceWasUsedInCurrentContext() {
  12121. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12122. }
  12123. parseFSharpPipelineBody(prec) {
  12124. const startLoc = this.state.startLoc;
  12125. this.state.potentialArrowAt = this.state.start;
  12126. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12127. this.state.inFSharpPipelineDirectBody = true;
  12128. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12129. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12130. return ret;
  12131. }
  12132. parseModuleExpression() {
  12133. this.expectPlugin("moduleBlocks");
  12134. const node = this.startNode();
  12135. this.next();
  12136. if (!this.match(5)) {
  12137. this.unexpected(null, 5);
  12138. }
  12139. const program = this.startNodeAt(this.state.endLoc);
  12140. this.next();
  12141. const revertScopes = this.initializeScopes(true);
  12142. this.enterInitialScopes();
  12143. try {
  12144. node.body = this.parseProgram(program, 8, "module");
  12145. } finally {
  12146. revertScopes();
  12147. }
  12148. return this.finishNode(node, "ModuleExpression");
  12149. }
  12150. parsePropertyNamePrefixOperator(prop) {}
  12151. }
  12152. const loopLabel = {
  12153. kind: 1
  12154. },
  12155. switchLabel = {
  12156. kind: 2
  12157. };
  12158. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12159. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12160. function babel7CompatTokens(tokens, input, startIndex) {
  12161. for (let i = 0; i < tokens.length; i++) {
  12162. const token = tokens[i];
  12163. const {
  12164. type
  12165. } = token;
  12166. if (typeof type === "number") {
  12167. {
  12168. if (type === 139) {
  12169. const {
  12170. loc,
  12171. start,
  12172. value,
  12173. end
  12174. } = token;
  12175. const hashEndPos = start + 1;
  12176. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12177. tokens.splice(i, 1, new Token({
  12178. type: getExportedToken(27),
  12179. value: "#",
  12180. start: start,
  12181. end: hashEndPos,
  12182. startLoc: loc.start,
  12183. endLoc: hashEndLoc
  12184. }), new Token({
  12185. type: getExportedToken(132),
  12186. value: value,
  12187. start: hashEndPos,
  12188. end: end,
  12189. startLoc: hashEndLoc,
  12190. endLoc: loc.end
  12191. }));
  12192. i++;
  12193. continue;
  12194. }
  12195. if (tokenIsTemplate(type)) {
  12196. const {
  12197. loc,
  12198. start,
  12199. value,
  12200. end
  12201. } = token;
  12202. const backquoteEnd = start + 1;
  12203. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12204. let startToken;
  12205. if (input.charCodeAt(start - startIndex) === 96) {
  12206. startToken = new Token({
  12207. type: getExportedToken(22),
  12208. value: "`",
  12209. start: start,
  12210. end: backquoteEnd,
  12211. startLoc: loc.start,
  12212. endLoc: backquoteEndLoc
  12213. });
  12214. } else {
  12215. startToken = new Token({
  12216. type: getExportedToken(8),
  12217. value: "}",
  12218. start: start,
  12219. end: backquoteEnd,
  12220. startLoc: loc.start,
  12221. endLoc: backquoteEndLoc
  12222. });
  12223. }
  12224. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12225. if (type === 24) {
  12226. templateElementEnd = end - 1;
  12227. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12228. templateValue = value === null ? null : value.slice(1, -1);
  12229. endToken = new Token({
  12230. type: getExportedToken(22),
  12231. value: "`",
  12232. start: templateElementEnd,
  12233. end: end,
  12234. startLoc: templateElementEndLoc,
  12235. endLoc: loc.end
  12236. });
  12237. } else {
  12238. templateElementEnd = end - 2;
  12239. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12240. templateValue = value === null ? null : value.slice(1, -2);
  12241. endToken = new Token({
  12242. type: getExportedToken(23),
  12243. value: "${",
  12244. start: templateElementEnd,
  12245. end: end,
  12246. startLoc: templateElementEndLoc,
  12247. endLoc: loc.end
  12248. });
  12249. }
  12250. tokens.splice(i, 1, startToken, new Token({
  12251. type: getExportedToken(20),
  12252. value: templateValue,
  12253. start: backquoteEnd,
  12254. end: templateElementEnd,
  12255. startLoc: backquoteEndLoc,
  12256. endLoc: templateElementEndLoc
  12257. }), endToken);
  12258. i += 2;
  12259. continue;
  12260. }
  12261. }
  12262. token.type = getExportedToken(type);
  12263. }
  12264. }
  12265. return tokens;
  12266. }
  12267. class StatementParser extends ExpressionParser {
  12268. parseTopLevel(file, program) {
  12269. file.program = this.parseProgram(program);
  12270. file.comments = this.comments;
  12271. if (this.optionFlags & 128) {
  12272. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  12273. }
  12274. return this.finishNode(file, "File");
  12275. }
  12276. parseProgram(program, end = 140, sourceType = this.options.sourceType) {
  12277. program.sourceType = sourceType;
  12278. program.interpreter = this.parseInterpreterDirective();
  12279. this.parseBlockBody(program, true, true, end);
  12280. if (this.inModule) {
  12281. if (!(this.optionFlags & 32) && this.scope.undefinedExports.size > 0) {
  12282. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12283. this.raise(Errors.ModuleExportUndefined, at, {
  12284. localName
  12285. });
  12286. }
  12287. }
  12288. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  12289. }
  12290. let finishedProgram;
  12291. if (end === 140) {
  12292. finishedProgram = this.finishNode(program, "Program");
  12293. } else {
  12294. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12295. }
  12296. return finishedProgram;
  12297. }
  12298. stmtToDirective(stmt) {
  12299. const directive = stmt;
  12300. directive.type = "Directive";
  12301. directive.value = directive.expression;
  12302. delete directive.expression;
  12303. const directiveLiteral = directive.value;
  12304. const expressionValue = directiveLiteral.value;
  12305. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  12306. const val = directiveLiteral.value = raw.slice(1, -1);
  12307. this.addExtra(directiveLiteral, "raw", raw);
  12308. this.addExtra(directiveLiteral, "rawValue", val);
  12309. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12310. directiveLiteral.type = "DirectiveLiteral";
  12311. return directive;
  12312. }
  12313. parseInterpreterDirective() {
  12314. if (!this.match(28)) {
  12315. return null;
  12316. }
  12317. const node = this.startNode();
  12318. node.value = this.state.value;
  12319. this.next();
  12320. return this.finishNode(node, "InterpreterDirective");
  12321. }
  12322. isLet() {
  12323. if (!this.isContextual(100)) {
  12324. return false;
  12325. }
  12326. return this.hasFollowingBindingAtom();
  12327. }
  12328. chStartsBindingIdentifier(ch, pos) {
  12329. if (isIdentifierStart(ch)) {
  12330. keywordRelationalOperator.lastIndex = pos;
  12331. if (keywordRelationalOperator.test(this.input)) {
  12332. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12333. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12334. return false;
  12335. }
  12336. }
  12337. return true;
  12338. } else if (ch === 92) {
  12339. return true;
  12340. } else {
  12341. return false;
  12342. }
  12343. }
  12344. chStartsBindingPattern(ch) {
  12345. return ch === 91 || ch === 123;
  12346. }
  12347. hasFollowingBindingAtom() {
  12348. const next = this.nextTokenStart();
  12349. const nextCh = this.codePointAtPos(next);
  12350. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12351. }
  12352. hasInLineFollowingBindingIdentifierOrBrace() {
  12353. const next = this.nextTokenInLineStart();
  12354. const nextCh = this.codePointAtPos(next);
  12355. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  12356. }
  12357. startsUsingForOf() {
  12358. const {
  12359. type,
  12360. containsEsc
  12361. } = this.lookahead();
  12362. if (type === 102 && !containsEsc) {
  12363. return false;
  12364. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12365. this.expectPlugin("explicitResourceManagement");
  12366. return true;
  12367. }
  12368. }
  12369. startsAwaitUsing() {
  12370. let next = this.nextTokenInLineStart();
  12371. if (this.isUnparsedContextual(next, "using")) {
  12372. next = this.nextTokenInLineStartSince(next + 5);
  12373. const nextCh = this.codePointAtPos(next);
  12374. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12375. this.expectPlugin("explicitResourceManagement");
  12376. return true;
  12377. }
  12378. }
  12379. return false;
  12380. }
  12381. parseModuleItem() {
  12382. return this.parseStatementLike(1 | 2 | 4 | 8);
  12383. }
  12384. parseStatementListItem() {
  12385. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12386. }
  12387. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12388. let flags = 0;
  12389. if (this.options.annexB && !this.state.strict) {
  12390. flags |= 4;
  12391. if (allowLabeledFunction) {
  12392. flags |= 8;
  12393. }
  12394. }
  12395. return this.parseStatementLike(flags);
  12396. }
  12397. parseStatement() {
  12398. return this.parseStatementLike(0);
  12399. }
  12400. parseStatementLike(flags) {
  12401. let decorators = null;
  12402. if (this.match(26)) {
  12403. decorators = this.parseDecorators(true);
  12404. }
  12405. return this.parseStatementContent(flags, decorators);
  12406. }
  12407. parseStatementContent(flags, decorators) {
  12408. const startType = this.state.type;
  12409. const node = this.startNode();
  12410. const allowDeclaration = !!(flags & 2);
  12411. const allowFunctionDeclaration = !!(flags & 4);
  12412. const topLevel = flags & 1;
  12413. switch (startType) {
  12414. case 60:
  12415. return this.parseBreakContinueStatement(node, true);
  12416. case 63:
  12417. return this.parseBreakContinueStatement(node, false);
  12418. case 64:
  12419. return this.parseDebuggerStatement(node);
  12420. case 90:
  12421. return this.parseDoWhileStatement(node);
  12422. case 91:
  12423. return this.parseForStatement(node);
  12424. case 68:
  12425. if (this.lookaheadCharCode() === 46) break;
  12426. if (!allowFunctionDeclaration) {
  12427. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12428. }
  12429. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12430. case 80:
  12431. if (!allowDeclaration) this.unexpected();
  12432. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12433. case 69:
  12434. return this.parseIfStatement(node);
  12435. case 70:
  12436. return this.parseReturnStatement(node);
  12437. case 71:
  12438. return this.parseSwitchStatement(node);
  12439. case 72:
  12440. return this.parseThrowStatement(node);
  12441. case 73:
  12442. return this.parseTryStatement(node);
  12443. case 96:
  12444. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  12445. if (!this.recordAwaitIfAllowed()) {
  12446. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12447. } else if (!allowDeclaration) {
  12448. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12449. }
  12450. this.next();
  12451. return this.parseVarStatement(node, "await using");
  12452. }
  12453. break;
  12454. case 107:
  12455. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  12456. break;
  12457. }
  12458. this.expectPlugin("explicitResourceManagement");
  12459. if (!this.scope.inModule && this.scope.inTopLevel) {
  12460. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12461. } else if (!allowDeclaration) {
  12462. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12463. }
  12464. return this.parseVarStatement(node, "using");
  12465. case 100:
  12466. {
  12467. if (this.state.containsEsc) {
  12468. break;
  12469. }
  12470. const next = this.nextTokenStart();
  12471. const nextCh = this.codePointAtPos(next);
  12472. if (nextCh !== 91) {
  12473. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12474. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12475. break;
  12476. }
  12477. }
  12478. }
  12479. case 75:
  12480. {
  12481. if (!allowDeclaration) {
  12482. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12483. }
  12484. }
  12485. case 74:
  12486. {
  12487. const kind = this.state.value;
  12488. return this.parseVarStatement(node, kind);
  12489. }
  12490. case 92:
  12491. return this.parseWhileStatement(node);
  12492. case 76:
  12493. return this.parseWithStatement(node);
  12494. case 5:
  12495. return this.parseBlock();
  12496. case 13:
  12497. return this.parseEmptyStatement(node);
  12498. case 83:
  12499. {
  12500. const nextTokenCharCode = this.lookaheadCharCode();
  12501. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12502. break;
  12503. }
  12504. }
  12505. case 82:
  12506. {
  12507. if (!(this.optionFlags & 8) && !topLevel) {
  12508. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12509. }
  12510. this.next();
  12511. let result;
  12512. if (startType === 83) {
  12513. result = this.parseImport(node);
  12514. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12515. this.sawUnambiguousESM = true;
  12516. }
  12517. } else {
  12518. result = this.parseExport(node, decorators);
  12519. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12520. this.sawUnambiguousESM = true;
  12521. }
  12522. }
  12523. this.assertModuleNodeAllowed(result);
  12524. return result;
  12525. }
  12526. default:
  12527. {
  12528. if (this.isAsyncFunction()) {
  12529. if (!allowDeclaration) {
  12530. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12531. }
  12532. this.next();
  12533. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12534. }
  12535. }
  12536. }
  12537. const maybeName = this.state.value;
  12538. const expr = this.parseExpression();
  12539. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  12540. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12541. } else {
  12542. return this.parseExpressionStatement(node, expr, decorators);
  12543. }
  12544. }
  12545. assertModuleNodeAllowed(node) {
  12546. if (!(this.optionFlags & 8) && !this.inModule) {
  12547. this.raise(Errors.ImportOutsideModule, node);
  12548. }
  12549. }
  12550. decoratorsEnabledBeforeExport() {
  12551. if (this.hasPlugin("decorators-legacy")) return true;
  12552. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12553. }
  12554. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12555. if (maybeDecorators) {
  12556. var _classNode$decorators;
  12557. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  12558. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12559. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12560. }
  12561. classNode.decorators.unshift(...maybeDecorators);
  12562. } else {
  12563. classNode.decorators = maybeDecorators;
  12564. }
  12565. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12566. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12567. }
  12568. return classNode;
  12569. }
  12570. canHaveLeadingDecorator() {
  12571. return this.match(80);
  12572. }
  12573. parseDecorators(allowExport) {
  12574. const decorators = [];
  12575. do {
  12576. decorators.push(this.parseDecorator());
  12577. } while (this.match(26));
  12578. if (this.match(82)) {
  12579. if (!allowExport) {
  12580. this.unexpected();
  12581. }
  12582. if (!this.decoratorsEnabledBeforeExport()) {
  12583. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  12584. }
  12585. } else if (!this.canHaveLeadingDecorator()) {
  12586. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  12587. }
  12588. return decorators;
  12589. }
  12590. parseDecorator() {
  12591. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12592. const node = this.startNode();
  12593. this.next();
  12594. if (this.hasPlugin("decorators")) {
  12595. const startLoc = this.state.startLoc;
  12596. let expr;
  12597. if (this.match(10)) {
  12598. const startLoc = this.state.startLoc;
  12599. this.next();
  12600. expr = this.parseExpression();
  12601. this.expect(11);
  12602. expr = this.wrapParenthesis(startLoc, expr);
  12603. const paramsStartLoc = this.state.startLoc;
  12604. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12605. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12606. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  12607. }
  12608. } else {
  12609. expr = this.parseIdentifier(false);
  12610. while (this.eat(16)) {
  12611. const node = this.startNodeAt(startLoc);
  12612. node.object = expr;
  12613. if (this.match(139)) {
  12614. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12615. node.property = this.parsePrivateName();
  12616. } else {
  12617. node.property = this.parseIdentifier(true);
  12618. }
  12619. node.computed = false;
  12620. expr = this.finishNode(node, "MemberExpression");
  12621. }
  12622. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12623. }
  12624. } else {
  12625. node.expression = this.parseExprSubscripts();
  12626. }
  12627. return this.finishNode(node, "Decorator");
  12628. }
  12629. parseMaybeDecoratorArguments(expr, startLoc) {
  12630. if (this.eat(10)) {
  12631. const node = this.startNodeAt(startLoc);
  12632. node.callee = expr;
  12633. node.arguments = this.parseCallExpressionArguments(11);
  12634. this.toReferencedList(node.arguments);
  12635. return this.finishNode(node, "CallExpression");
  12636. }
  12637. return expr;
  12638. }
  12639. parseBreakContinueStatement(node, isBreak) {
  12640. this.next();
  12641. if (this.isLineTerminator()) {
  12642. node.label = null;
  12643. } else {
  12644. node.label = this.parseIdentifier();
  12645. this.semicolon();
  12646. }
  12647. this.verifyBreakContinue(node, isBreak);
  12648. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12649. }
  12650. verifyBreakContinue(node, isBreak) {
  12651. let i;
  12652. for (i = 0; i < this.state.labels.length; ++i) {
  12653. const lab = this.state.labels[i];
  12654. if (node.label == null || lab.name === node.label.name) {
  12655. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  12656. break;
  12657. }
  12658. if (node.label && isBreak) break;
  12659. }
  12660. }
  12661. if (i === this.state.labels.length) {
  12662. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12663. this.raise(Errors.IllegalBreakContinue, node, {
  12664. type
  12665. });
  12666. }
  12667. }
  12668. parseDebuggerStatement(node) {
  12669. this.next();
  12670. this.semicolon();
  12671. return this.finishNode(node, "DebuggerStatement");
  12672. }
  12673. parseHeaderExpression() {
  12674. this.expect(10);
  12675. const val = this.parseExpression();
  12676. this.expect(11);
  12677. return val;
  12678. }
  12679. parseDoWhileStatement(node) {
  12680. this.next();
  12681. this.state.labels.push(loopLabel);
  12682. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12683. this.state.labels.pop();
  12684. this.expect(92);
  12685. node.test = this.parseHeaderExpression();
  12686. this.eat(13);
  12687. return this.finishNode(node, "DoWhileStatement");
  12688. }
  12689. parseForStatement(node) {
  12690. this.next();
  12691. this.state.labels.push(loopLabel);
  12692. let awaitAt = null;
  12693. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  12694. awaitAt = this.state.startLoc;
  12695. this.next();
  12696. }
  12697. this.scope.enter(0);
  12698. this.expect(10);
  12699. if (this.match(13)) {
  12700. if (awaitAt !== null) {
  12701. this.unexpected(awaitAt);
  12702. }
  12703. return this.parseFor(node, null);
  12704. }
  12705. const startsWithLet = this.isContextual(100);
  12706. {
  12707. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  12708. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(107) && this.startsUsingForOf();
  12709. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  12710. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12711. const initNode = this.startNode();
  12712. let kind;
  12713. if (startsWithAwaitUsing) {
  12714. kind = "await using";
  12715. if (!this.recordAwaitIfAllowed()) {
  12716. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  12717. }
  12718. this.next();
  12719. } else {
  12720. kind = this.state.value;
  12721. }
  12722. this.next();
  12723. this.parseVar(initNode, true, kind);
  12724. const init = this.finishNode(initNode, "VariableDeclaration");
  12725. const isForIn = this.match(58);
  12726. if (isForIn && starsWithUsingDeclaration) {
  12727. this.raise(Errors.ForInUsing, init);
  12728. }
  12729. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  12730. return this.parseForIn(node, init, awaitAt);
  12731. }
  12732. if (awaitAt !== null) {
  12733. this.unexpected(awaitAt);
  12734. }
  12735. return this.parseFor(node, init);
  12736. }
  12737. }
  12738. const startsWithAsync = this.isContextual(95);
  12739. const refExpressionErrors = new ExpressionErrors();
  12740. const init = this.parseExpression(true, refExpressionErrors);
  12741. const isForOf = this.isContextual(102);
  12742. if (isForOf) {
  12743. if (startsWithLet) {
  12744. this.raise(Errors.ForOfLet, init);
  12745. }
  12746. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12747. this.raise(Errors.ForOfAsync, init);
  12748. }
  12749. }
  12750. if (isForOf || this.match(58)) {
  12751. this.checkDestructuringPrivate(refExpressionErrors);
  12752. this.toAssignable(init, true);
  12753. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12754. this.checkLVal(init, {
  12755. type
  12756. });
  12757. return this.parseForIn(node, init, awaitAt);
  12758. } else {
  12759. this.checkExpressionErrors(refExpressionErrors, true);
  12760. }
  12761. if (awaitAt !== null) {
  12762. this.unexpected(awaitAt);
  12763. }
  12764. return this.parseFor(node, init);
  12765. }
  12766. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12767. this.next();
  12768. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  12769. }
  12770. parseIfStatement(node) {
  12771. this.next();
  12772. node.test = this.parseHeaderExpression();
  12773. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12774. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  12775. return this.finishNode(node, "IfStatement");
  12776. }
  12777. parseReturnStatement(node) {
  12778. if (!this.prodParam.hasReturn && !(this.optionFlags & 2)) {
  12779. this.raise(Errors.IllegalReturn, this.state.startLoc);
  12780. }
  12781. this.next();
  12782. if (this.isLineTerminator()) {
  12783. node.argument = null;
  12784. } else {
  12785. node.argument = this.parseExpression();
  12786. this.semicolon();
  12787. }
  12788. return this.finishNode(node, "ReturnStatement");
  12789. }
  12790. parseSwitchStatement(node) {
  12791. this.next();
  12792. node.discriminant = this.parseHeaderExpression();
  12793. const cases = node.cases = [];
  12794. this.expect(5);
  12795. this.state.labels.push(switchLabel);
  12796. this.scope.enter(0);
  12797. let cur;
  12798. for (let sawDefault; !this.match(8);) {
  12799. if (this.match(61) || this.match(65)) {
  12800. const isCase = this.match(61);
  12801. if (cur) this.finishNode(cur, "SwitchCase");
  12802. cases.push(cur = this.startNode());
  12803. cur.consequent = [];
  12804. this.next();
  12805. if (isCase) {
  12806. cur.test = this.parseExpression();
  12807. } else {
  12808. if (sawDefault) {
  12809. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  12810. }
  12811. sawDefault = true;
  12812. cur.test = null;
  12813. }
  12814. this.expect(14);
  12815. } else {
  12816. if (cur) {
  12817. cur.consequent.push(this.parseStatementListItem());
  12818. } else {
  12819. this.unexpected();
  12820. }
  12821. }
  12822. }
  12823. this.scope.exit();
  12824. if (cur) this.finishNode(cur, "SwitchCase");
  12825. this.next();
  12826. this.state.labels.pop();
  12827. return this.finishNode(node, "SwitchStatement");
  12828. }
  12829. parseThrowStatement(node) {
  12830. this.next();
  12831. if (this.hasPrecedingLineBreak()) {
  12832. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  12833. }
  12834. node.argument = this.parseExpression();
  12835. this.semicolon();
  12836. return this.finishNode(node, "ThrowStatement");
  12837. }
  12838. parseCatchClauseParam() {
  12839. const param = this.parseBindingAtom();
  12840. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  12841. this.checkLVal(param, {
  12842. type: "CatchClause"
  12843. }, 9);
  12844. return param;
  12845. }
  12846. parseTryStatement(node) {
  12847. this.next();
  12848. node.block = this.parseBlock();
  12849. node.handler = null;
  12850. if (this.match(62)) {
  12851. const clause = this.startNode();
  12852. this.next();
  12853. if (this.match(10)) {
  12854. this.expect(10);
  12855. clause.param = this.parseCatchClauseParam();
  12856. this.expect(11);
  12857. } else {
  12858. clause.param = null;
  12859. this.scope.enter(0);
  12860. }
  12861. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  12862. this.scope.exit();
  12863. node.handler = this.finishNode(clause, "CatchClause");
  12864. }
  12865. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  12866. if (!node.handler && !node.finalizer) {
  12867. this.raise(Errors.NoCatchOrFinally, node);
  12868. }
  12869. return this.finishNode(node, "TryStatement");
  12870. }
  12871. parseVarStatement(node, kind, allowMissingInitializer = false) {
  12872. this.next();
  12873. this.parseVar(node, false, kind, allowMissingInitializer);
  12874. this.semicolon();
  12875. return this.finishNode(node, "VariableDeclaration");
  12876. }
  12877. parseWhileStatement(node) {
  12878. this.next();
  12879. node.test = this.parseHeaderExpression();
  12880. this.state.labels.push(loopLabel);
  12881. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12882. this.state.labels.pop();
  12883. return this.finishNode(node, "WhileStatement");
  12884. }
  12885. parseWithStatement(node) {
  12886. if (this.state.strict) {
  12887. this.raise(Errors.StrictWith, this.state.startLoc);
  12888. }
  12889. this.next();
  12890. node.object = this.parseHeaderExpression();
  12891. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12892. return this.finishNode(node, "WithStatement");
  12893. }
  12894. parseEmptyStatement(node) {
  12895. this.next();
  12896. return this.finishNode(node, "EmptyStatement");
  12897. }
  12898. parseLabeledStatement(node, maybeName, expr, flags) {
  12899. for (const label of this.state.labels) {
  12900. if (label.name === maybeName) {
  12901. this.raise(Errors.LabelRedeclaration, expr, {
  12902. labelName: maybeName
  12903. });
  12904. }
  12905. }
  12906. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  12907. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  12908. const label = this.state.labels[i];
  12909. if (label.statementStart === node.start) {
  12910. label.statementStart = this.sourceToOffsetPos(this.state.start);
  12911. label.kind = kind;
  12912. } else {
  12913. break;
  12914. }
  12915. }
  12916. this.state.labels.push({
  12917. name: maybeName,
  12918. kind: kind,
  12919. statementStart: this.sourceToOffsetPos(this.state.start)
  12920. });
  12921. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  12922. this.state.labels.pop();
  12923. node.label = expr;
  12924. return this.finishNode(node, "LabeledStatement");
  12925. }
  12926. parseExpressionStatement(node, expr, decorators) {
  12927. node.expression = expr;
  12928. this.semicolon();
  12929. return this.finishNode(node, "ExpressionStatement");
  12930. }
  12931. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  12932. const node = this.startNode();
  12933. if (allowDirectives) {
  12934. this.state.strictErrors.clear();
  12935. }
  12936. this.expect(5);
  12937. if (createNewLexicalScope) {
  12938. this.scope.enter(0);
  12939. }
  12940. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  12941. if (createNewLexicalScope) {
  12942. this.scope.exit();
  12943. }
  12944. return this.finishNode(node, "BlockStatement");
  12945. }
  12946. isValidDirective(stmt) {
  12947. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  12948. }
  12949. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  12950. const body = node.body = [];
  12951. const directives = node.directives = [];
  12952. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  12953. }
  12954. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  12955. const oldStrict = this.state.strict;
  12956. let hasStrictModeDirective = false;
  12957. let parsedNonDirective = false;
  12958. while (!this.match(end)) {
  12959. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  12960. if (directives && !parsedNonDirective) {
  12961. if (this.isValidDirective(stmt)) {
  12962. const directive = this.stmtToDirective(stmt);
  12963. directives.push(directive);
  12964. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  12965. hasStrictModeDirective = true;
  12966. this.setStrict(true);
  12967. }
  12968. continue;
  12969. }
  12970. parsedNonDirective = true;
  12971. this.state.strictErrors.clear();
  12972. }
  12973. body.push(stmt);
  12974. }
  12975. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  12976. if (!oldStrict) {
  12977. this.setStrict(false);
  12978. }
  12979. this.next();
  12980. }
  12981. parseFor(node, init) {
  12982. node.init = init;
  12983. this.semicolon(false);
  12984. node.test = this.match(13) ? null : this.parseExpression();
  12985. this.semicolon(false);
  12986. node.update = this.match(11) ? null : this.parseExpression();
  12987. this.expect(11);
  12988. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12989. this.scope.exit();
  12990. this.state.labels.pop();
  12991. return this.finishNode(node, "ForStatement");
  12992. }
  12993. parseForIn(node, init, awaitAt) {
  12994. const isForIn = this.match(58);
  12995. this.next();
  12996. if (isForIn) {
  12997. if (awaitAt !== null) this.unexpected(awaitAt);
  12998. } else {
  12999. node.await = awaitAt !== null;
  13000. }
  13001. 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")) {
  13002. this.raise(Errors.ForInOfLoopInitializer, init, {
  13003. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13004. });
  13005. }
  13006. if (init.type === "AssignmentPattern") {
  13007. this.raise(Errors.InvalidLhs, init, {
  13008. ancestor: {
  13009. type: "ForStatement"
  13010. }
  13011. });
  13012. }
  13013. node.left = init;
  13014. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13015. this.expect(11);
  13016. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13017. this.scope.exit();
  13018. this.state.labels.pop();
  13019. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13020. }
  13021. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13022. const declarations = node.declarations = [];
  13023. node.kind = kind;
  13024. for (;;) {
  13025. const decl = this.startNode();
  13026. this.parseVarId(decl, kind);
  13027. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13028. if (decl.init === null && !allowMissingInitializer) {
  13029. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13030. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13031. kind: "destructuring"
  13032. });
  13033. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  13034. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13035. kind
  13036. });
  13037. }
  13038. }
  13039. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13040. if (!this.eat(12)) break;
  13041. }
  13042. return node;
  13043. }
  13044. parseVarId(decl, kind) {
  13045. const id = this.parseBindingAtom();
  13046. if (kind === "using" || kind === "await using") {
  13047. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  13048. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  13049. }
  13050. }
  13051. this.checkLVal(id, {
  13052. type: "VariableDeclarator"
  13053. }, kind === "var" ? 5 : 8201);
  13054. decl.id = id;
  13055. }
  13056. parseAsyncFunctionExpression(node) {
  13057. return this.parseFunction(node, 8);
  13058. }
  13059. parseFunction(node, flags = 0) {
  13060. const hangingDeclaration = flags & 2;
  13061. const isDeclaration = !!(flags & 1);
  13062. const requireId = isDeclaration && !(flags & 4);
  13063. const isAsync = !!(flags & 8);
  13064. this.initFunction(node, isAsync);
  13065. if (this.match(55)) {
  13066. if (hangingDeclaration) {
  13067. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  13068. }
  13069. this.next();
  13070. node.generator = true;
  13071. }
  13072. if (isDeclaration) {
  13073. node.id = this.parseFunctionId(requireId);
  13074. }
  13075. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13076. this.state.maybeInArrowParameters = false;
  13077. this.scope.enter(2);
  13078. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13079. if (!isDeclaration) {
  13080. node.id = this.parseFunctionId();
  13081. }
  13082. this.parseFunctionParams(node, false);
  13083. this.withSmartMixTopicForbiddingContext(() => {
  13084. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13085. });
  13086. this.prodParam.exit();
  13087. this.scope.exit();
  13088. if (isDeclaration && !hangingDeclaration) {
  13089. this.registerFunctionStatementId(node);
  13090. }
  13091. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13092. return node;
  13093. }
  13094. parseFunctionId(requireId) {
  13095. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13096. }
  13097. parseFunctionParams(node, isConstructor) {
  13098. this.expect(10);
  13099. this.expressionScope.enter(newParameterDeclarationScope());
  13100. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13101. this.expressionScope.exit();
  13102. }
  13103. registerFunctionStatementId(node) {
  13104. if (!node.id) return;
  13105. 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);
  13106. }
  13107. parseClass(node, isStatement, optionalId) {
  13108. this.next();
  13109. const oldStrict = this.state.strict;
  13110. this.state.strict = true;
  13111. this.parseClassId(node, isStatement, optionalId);
  13112. this.parseClassSuper(node);
  13113. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13114. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13115. }
  13116. isClassProperty() {
  13117. return this.match(29) || this.match(13) || this.match(8);
  13118. }
  13119. isClassMethod() {
  13120. return this.match(10);
  13121. }
  13122. nameIsConstructor(key) {
  13123. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  13124. }
  13125. isNonstaticConstructor(method) {
  13126. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  13127. }
  13128. parseClassBody(hadSuperClass, oldStrict) {
  13129. this.classScope.enter();
  13130. const state = {
  13131. hadConstructor: false,
  13132. hadSuperClass
  13133. };
  13134. let decorators = [];
  13135. const classBody = this.startNode();
  13136. classBody.body = [];
  13137. this.expect(5);
  13138. this.withSmartMixTopicForbiddingContext(() => {
  13139. while (!this.match(8)) {
  13140. if (this.eat(13)) {
  13141. if (decorators.length > 0) {
  13142. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  13143. }
  13144. continue;
  13145. }
  13146. if (this.match(26)) {
  13147. decorators.push(this.parseDecorator());
  13148. continue;
  13149. }
  13150. const member = this.startNode();
  13151. if (decorators.length) {
  13152. member.decorators = decorators;
  13153. this.resetStartLocationFromNode(member, decorators[0]);
  13154. decorators = [];
  13155. }
  13156. this.parseClassMember(classBody, member, state);
  13157. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13158. this.raise(Errors.DecoratorConstructor, member);
  13159. }
  13160. }
  13161. });
  13162. this.state.strict = oldStrict;
  13163. this.next();
  13164. if (decorators.length) {
  13165. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13166. }
  13167. this.classScope.exit();
  13168. return this.finishNode(classBody, "ClassBody");
  13169. }
  13170. parseClassMemberFromModifier(classBody, member) {
  13171. const key = this.parseIdentifier(true);
  13172. if (this.isClassMethod()) {
  13173. const method = member;
  13174. method.kind = "method";
  13175. method.computed = false;
  13176. method.key = key;
  13177. method.static = false;
  13178. this.pushClassMethod(classBody, method, false, false, false, false);
  13179. return true;
  13180. } else if (this.isClassProperty()) {
  13181. const prop = member;
  13182. prop.computed = false;
  13183. prop.key = key;
  13184. prop.static = false;
  13185. classBody.body.push(this.parseClassProperty(prop));
  13186. return true;
  13187. }
  13188. this.resetPreviousNodeTrailingComments(key);
  13189. return false;
  13190. }
  13191. parseClassMember(classBody, member, state) {
  13192. const isStatic = this.isContextual(106);
  13193. if (isStatic) {
  13194. if (this.parseClassMemberFromModifier(classBody, member)) {
  13195. return;
  13196. }
  13197. if (this.eat(5)) {
  13198. this.parseClassStaticBlock(classBody, member);
  13199. return;
  13200. }
  13201. }
  13202. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13203. }
  13204. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13205. const publicMethod = member;
  13206. const privateMethod = member;
  13207. const publicProp = member;
  13208. const privateProp = member;
  13209. const accessorProp = member;
  13210. const method = publicMethod;
  13211. const publicMember = publicMethod;
  13212. member.static = isStatic;
  13213. this.parsePropertyNamePrefixOperator(member);
  13214. if (this.eat(55)) {
  13215. method.kind = "method";
  13216. const isPrivateName = this.match(139);
  13217. this.parseClassElementName(method);
  13218. if (isPrivateName) {
  13219. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13220. return;
  13221. }
  13222. if (this.isNonstaticConstructor(publicMethod)) {
  13223. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13224. }
  13225. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13226. return;
  13227. }
  13228. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13229. const key = this.parseClassElementName(member);
  13230. const maybeContextualKw = isContextual ? key.name : null;
  13231. const isPrivate = this.isPrivateName(key);
  13232. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13233. this.parsePostMemberNameModifiers(publicMember);
  13234. if (this.isClassMethod()) {
  13235. method.kind = "method";
  13236. if (isPrivate) {
  13237. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13238. return;
  13239. }
  13240. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13241. let allowsDirectSuper = false;
  13242. if (isConstructor) {
  13243. publicMethod.kind = "constructor";
  13244. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13245. this.raise(Errors.DuplicateConstructor, key);
  13246. }
  13247. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13248. this.raise(Errors.OverrideOnConstructor, key);
  13249. }
  13250. state.hadConstructor = true;
  13251. allowsDirectSuper = state.hadSuperClass;
  13252. }
  13253. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13254. } else if (this.isClassProperty()) {
  13255. if (isPrivate) {
  13256. this.pushClassPrivateProperty(classBody, privateProp);
  13257. } else {
  13258. this.pushClassProperty(classBody, publicProp);
  13259. }
  13260. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13261. this.resetPreviousNodeTrailingComments(key);
  13262. const isGenerator = this.eat(55);
  13263. if (publicMember.optional) {
  13264. this.unexpected(maybeQuestionTokenStartLoc);
  13265. }
  13266. method.kind = "method";
  13267. const isPrivate = this.match(139);
  13268. this.parseClassElementName(method);
  13269. this.parsePostMemberNameModifiers(publicMember);
  13270. if (isPrivate) {
  13271. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13272. } else {
  13273. if (this.isNonstaticConstructor(publicMethod)) {
  13274. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13275. }
  13276. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13277. }
  13278. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13279. this.resetPreviousNodeTrailingComments(key);
  13280. method.kind = maybeContextualKw;
  13281. const isPrivate = this.match(139);
  13282. this.parseClassElementName(publicMethod);
  13283. if (isPrivate) {
  13284. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13285. } else {
  13286. if (this.isNonstaticConstructor(publicMethod)) {
  13287. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13288. }
  13289. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13290. }
  13291. this.checkGetterSetterParams(publicMethod);
  13292. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13293. this.expectPlugin("decoratorAutoAccessors");
  13294. this.resetPreviousNodeTrailingComments(key);
  13295. const isPrivate = this.match(139);
  13296. this.parseClassElementName(publicProp);
  13297. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13298. } else if (this.isLineTerminator()) {
  13299. if (isPrivate) {
  13300. this.pushClassPrivateProperty(classBody, privateProp);
  13301. } else {
  13302. this.pushClassProperty(classBody, publicProp);
  13303. }
  13304. } else {
  13305. this.unexpected();
  13306. }
  13307. }
  13308. parseClassElementName(member) {
  13309. const {
  13310. type,
  13311. value
  13312. } = this.state;
  13313. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  13314. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13315. }
  13316. if (type === 139) {
  13317. if (value === "constructor") {
  13318. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13319. }
  13320. const key = this.parsePrivateName();
  13321. member.key = key;
  13322. return key;
  13323. }
  13324. this.parsePropertyName(member);
  13325. return member.key;
  13326. }
  13327. parseClassStaticBlock(classBody, member) {
  13328. var _member$decorators;
  13329. this.scope.enter(64 | 128 | 16);
  13330. const oldLabels = this.state.labels;
  13331. this.state.labels = [];
  13332. this.prodParam.enter(0);
  13333. const body = member.body = [];
  13334. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13335. this.prodParam.exit();
  13336. this.scope.exit();
  13337. this.state.labels = oldLabels;
  13338. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13339. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13340. this.raise(Errors.DecoratorStaticBlock, member);
  13341. }
  13342. }
  13343. pushClassProperty(classBody, prop) {
  13344. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13345. this.raise(Errors.ConstructorClassField, prop.key);
  13346. }
  13347. classBody.body.push(this.parseClassProperty(prop));
  13348. }
  13349. pushClassPrivateProperty(classBody, prop) {
  13350. const node = this.parseClassPrivateProperty(prop);
  13351. classBody.body.push(node);
  13352. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13353. }
  13354. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13355. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13356. this.raise(Errors.ConstructorClassField, prop.key);
  13357. }
  13358. const node = this.parseClassAccessorProperty(prop);
  13359. classBody.body.push(node);
  13360. if (isPrivate) {
  13361. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13362. }
  13363. }
  13364. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13365. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13366. }
  13367. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13368. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13369. classBody.body.push(node);
  13370. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13371. this.declareClassPrivateMethodInScope(node, kind);
  13372. }
  13373. declareClassPrivateMethodInScope(node, kind) {
  13374. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13375. }
  13376. parsePostMemberNameModifiers(methodOrProp) {}
  13377. parseClassPrivateProperty(node) {
  13378. this.parseInitializer(node);
  13379. this.semicolon();
  13380. return this.finishNode(node, "ClassPrivateProperty");
  13381. }
  13382. parseClassProperty(node) {
  13383. this.parseInitializer(node);
  13384. this.semicolon();
  13385. return this.finishNode(node, "ClassProperty");
  13386. }
  13387. parseClassAccessorProperty(node) {
  13388. this.parseInitializer(node);
  13389. this.semicolon();
  13390. return this.finishNode(node, "ClassAccessorProperty");
  13391. }
  13392. parseInitializer(node) {
  13393. this.scope.enter(64 | 16);
  13394. this.expressionScope.enter(newExpressionScope());
  13395. this.prodParam.enter(0);
  13396. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13397. this.expressionScope.exit();
  13398. this.prodParam.exit();
  13399. this.scope.exit();
  13400. }
  13401. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13402. if (tokenIsIdentifier(this.state.type)) {
  13403. node.id = this.parseIdentifier();
  13404. if (isStatement) {
  13405. this.declareNameFromIdentifier(node.id, bindingType);
  13406. }
  13407. } else {
  13408. if (optionalId || !isStatement) {
  13409. node.id = null;
  13410. } else {
  13411. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13412. }
  13413. }
  13414. }
  13415. parseClassSuper(node) {
  13416. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13417. }
  13418. parseExport(node, decorators) {
  13419. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13420. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13421. const parseAfterDefault = !hasDefault || this.eat(12);
  13422. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13423. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13424. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13425. const isFromRequired = hasDefault || hasStar;
  13426. if (hasStar && !hasNamespace) {
  13427. if (hasDefault) this.unexpected();
  13428. if (decorators) {
  13429. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13430. }
  13431. this.parseExportFrom(node, true);
  13432. return this.finishNode(node, "ExportAllDeclaration");
  13433. }
  13434. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13435. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13436. this.unexpected(null, 5);
  13437. }
  13438. if (hasNamespace && parseAfterNamespace) {
  13439. this.unexpected(null, 98);
  13440. }
  13441. let hasDeclaration;
  13442. if (isFromRequired || hasSpecifiers) {
  13443. hasDeclaration = false;
  13444. if (decorators) {
  13445. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13446. }
  13447. this.parseExportFrom(node, isFromRequired);
  13448. } else {
  13449. hasDeclaration = this.maybeParseExportDeclaration(node);
  13450. }
  13451. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13452. var _node2$declaration;
  13453. const node2 = node;
  13454. this.checkExport(node2, true, false, !!node2.source);
  13455. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13456. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13457. } else if (decorators) {
  13458. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13459. }
  13460. return this.finishNode(node2, "ExportNamedDeclaration");
  13461. }
  13462. if (this.eat(65)) {
  13463. const node2 = node;
  13464. const decl = this.parseExportDefaultExpression();
  13465. node2.declaration = decl;
  13466. if (decl.type === "ClassDeclaration") {
  13467. this.maybeTakeDecorators(decorators, decl, node2);
  13468. } else if (decorators) {
  13469. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13470. }
  13471. this.checkExport(node2, true, true);
  13472. return this.finishNode(node2, "ExportDefaultDeclaration");
  13473. }
  13474. this.unexpected(null, 5);
  13475. }
  13476. eatExportStar(node) {
  13477. return this.eat(55);
  13478. }
  13479. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13480. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13481. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13482. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13483. const specifier = this.startNodeAtNode(id);
  13484. specifier.exported = id;
  13485. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13486. return true;
  13487. }
  13488. return false;
  13489. }
  13490. maybeParseExportNamespaceSpecifier(node) {
  13491. if (this.isContextual(93)) {
  13492. var _ref, _ref$specifiers;
  13493. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13494. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13495. this.next();
  13496. specifier.exported = this.parseModuleExportName();
  13497. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13498. return true;
  13499. }
  13500. return false;
  13501. }
  13502. maybeParseExportNamedSpecifiers(node) {
  13503. if (this.match(5)) {
  13504. const node2 = node;
  13505. if (!node2.specifiers) node2.specifiers = [];
  13506. const isTypeExport = node2.exportKind === "type";
  13507. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13508. node2.source = null;
  13509. node2.declaration = null;
  13510. if (this.hasPlugin("importAssertions")) {
  13511. node2.assertions = [];
  13512. }
  13513. return true;
  13514. }
  13515. return false;
  13516. }
  13517. maybeParseExportDeclaration(node) {
  13518. if (this.shouldParseExportDeclaration()) {
  13519. node.specifiers = [];
  13520. node.source = null;
  13521. if (this.hasPlugin("importAssertions")) {
  13522. node.assertions = [];
  13523. }
  13524. node.declaration = this.parseExportDeclaration(node);
  13525. return true;
  13526. }
  13527. return false;
  13528. }
  13529. isAsyncFunction() {
  13530. if (!this.isContextual(95)) return false;
  13531. const next = this.nextTokenInLineStart();
  13532. return this.isUnparsedContextual(next, "function");
  13533. }
  13534. parseExportDefaultExpression() {
  13535. const expr = this.startNode();
  13536. if (this.match(68)) {
  13537. this.next();
  13538. return this.parseFunction(expr, 1 | 4);
  13539. } else if (this.isAsyncFunction()) {
  13540. this.next();
  13541. this.next();
  13542. return this.parseFunction(expr, 1 | 4 | 8);
  13543. }
  13544. if (this.match(80)) {
  13545. return this.parseClass(expr, true, true);
  13546. }
  13547. if (this.match(26)) {
  13548. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13549. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13550. }
  13551. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13552. }
  13553. if (this.match(75) || this.match(74) || this.isLet()) {
  13554. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13555. }
  13556. const res = this.parseMaybeAssignAllowIn();
  13557. this.semicolon();
  13558. return res;
  13559. }
  13560. parseExportDeclaration(node) {
  13561. if (this.match(80)) {
  13562. const node = this.parseClass(this.startNode(), true, false);
  13563. return node;
  13564. }
  13565. return this.parseStatementListItem();
  13566. }
  13567. isExportDefaultSpecifier() {
  13568. const {
  13569. type
  13570. } = this.state;
  13571. if (tokenIsIdentifier(type)) {
  13572. if (type === 95 && !this.state.containsEsc || type === 100) {
  13573. return false;
  13574. }
  13575. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13576. const {
  13577. type: nextType
  13578. } = this.lookahead();
  13579. if (tokenIsIdentifier(nextType) && nextType !== 98 || nextType === 5) {
  13580. this.expectOnePlugin(["flow", "typescript"]);
  13581. return false;
  13582. }
  13583. }
  13584. } else if (!this.match(65)) {
  13585. return false;
  13586. }
  13587. const next = this.nextTokenStart();
  13588. const hasFrom = this.isUnparsedContextual(next, "from");
  13589. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13590. return true;
  13591. }
  13592. if (this.match(65) && hasFrom) {
  13593. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13594. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13595. }
  13596. return false;
  13597. }
  13598. parseExportFrom(node, expect) {
  13599. if (this.eatContextual(98)) {
  13600. node.source = this.parseImportSource();
  13601. this.checkExport(node);
  13602. this.maybeParseImportAttributes(node);
  13603. this.checkJSONModuleImport(node);
  13604. } else if (expect) {
  13605. this.unexpected();
  13606. }
  13607. this.semicolon();
  13608. }
  13609. shouldParseExportDeclaration() {
  13610. const {
  13611. type
  13612. } = this.state;
  13613. if (type === 26) {
  13614. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13615. if (this.hasPlugin("decorators")) {
  13616. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13617. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13618. }
  13619. return true;
  13620. }
  13621. }
  13622. if (this.isContextual(107)) {
  13623. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13624. return true;
  13625. }
  13626. if (this.isContextual(96) && this.startsAwaitUsing()) {
  13627. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13628. return true;
  13629. }
  13630. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13631. }
  13632. checkExport(node, checkNames, isDefault, isFrom) {
  13633. if (checkNames) {
  13634. var _node$specifiers;
  13635. if (isDefault) {
  13636. this.checkDuplicateExports(node, "default");
  13637. if (this.hasPlugin("exportDefaultFrom")) {
  13638. var _declaration$extra;
  13639. const declaration = node.declaration;
  13640. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13641. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  13642. }
  13643. }
  13644. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  13645. for (const specifier of node.specifiers) {
  13646. const {
  13647. exported
  13648. } = specifier;
  13649. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13650. this.checkDuplicateExports(specifier, exportName);
  13651. if (!isFrom && specifier.local) {
  13652. const {
  13653. local
  13654. } = specifier;
  13655. if (local.type !== "Identifier") {
  13656. this.raise(Errors.ExportBindingIsString, specifier, {
  13657. localName: local.value,
  13658. exportName
  13659. });
  13660. } else {
  13661. this.checkReservedWord(local.name, local.loc.start, true, false);
  13662. this.scope.checkLocalExport(local);
  13663. }
  13664. }
  13665. }
  13666. } else if (node.declaration) {
  13667. const decl = node.declaration;
  13668. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  13669. const {
  13670. id
  13671. } = decl;
  13672. if (!id) throw new Error("Assertion failure");
  13673. this.checkDuplicateExports(node, id.name);
  13674. } else if (decl.type === "VariableDeclaration") {
  13675. for (const declaration of decl.declarations) {
  13676. this.checkDeclaration(declaration.id);
  13677. }
  13678. }
  13679. }
  13680. }
  13681. }
  13682. checkDeclaration(node) {
  13683. if (node.type === "Identifier") {
  13684. this.checkDuplicateExports(node, node.name);
  13685. } else if (node.type === "ObjectPattern") {
  13686. for (const prop of node.properties) {
  13687. this.checkDeclaration(prop);
  13688. }
  13689. } else if (node.type === "ArrayPattern") {
  13690. for (const elem of node.elements) {
  13691. if (elem) {
  13692. this.checkDeclaration(elem);
  13693. }
  13694. }
  13695. } else if (node.type === "ObjectProperty") {
  13696. this.checkDeclaration(node.value);
  13697. } else if (node.type === "RestElement") {
  13698. this.checkDeclaration(node.argument);
  13699. } else if (node.type === "AssignmentPattern") {
  13700. this.checkDeclaration(node.left);
  13701. }
  13702. }
  13703. checkDuplicateExports(node, exportName) {
  13704. if (this.exportedIdentifiers.has(exportName)) {
  13705. if (exportName === "default") {
  13706. this.raise(Errors.DuplicateDefaultExport, node);
  13707. } else {
  13708. this.raise(Errors.DuplicateExport, node, {
  13709. exportName
  13710. });
  13711. }
  13712. }
  13713. this.exportedIdentifiers.add(exportName);
  13714. }
  13715. parseExportSpecifiers(isInTypeExport) {
  13716. const nodes = [];
  13717. let first = true;
  13718. this.expect(5);
  13719. while (!this.eat(8)) {
  13720. if (first) {
  13721. first = false;
  13722. } else {
  13723. this.expect(12);
  13724. if (this.eat(8)) break;
  13725. }
  13726. const isMaybeTypeOnly = this.isContextual(130);
  13727. const isString = this.match(134);
  13728. const node = this.startNode();
  13729. node.local = this.parseModuleExportName();
  13730. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13731. }
  13732. return nodes;
  13733. }
  13734. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  13735. if (this.eatContextual(93)) {
  13736. node.exported = this.parseModuleExportName();
  13737. } else if (isString) {
  13738. node.exported = cloneStringLiteral(node.local);
  13739. } else if (!node.exported) {
  13740. node.exported = cloneIdentifier(node.local);
  13741. }
  13742. return this.finishNode(node, "ExportSpecifier");
  13743. }
  13744. parseModuleExportName() {
  13745. if (this.match(134)) {
  13746. const result = this.parseStringLiteral(this.state.value);
  13747. const surrogate = loneSurrogate.exec(result.value);
  13748. if (surrogate) {
  13749. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  13750. surrogateCharCode: surrogate[0].charCodeAt(0)
  13751. });
  13752. }
  13753. return result;
  13754. }
  13755. return this.parseIdentifier(true);
  13756. }
  13757. isJSONModuleImport(node) {
  13758. if (node.assertions != null) {
  13759. return node.assertions.some(({
  13760. key,
  13761. value
  13762. }) => {
  13763. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  13764. });
  13765. }
  13766. return false;
  13767. }
  13768. checkImportReflection(node) {
  13769. const {
  13770. specifiers
  13771. } = node;
  13772. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  13773. if (node.phase === "source") {
  13774. if (singleBindingType !== "ImportDefaultSpecifier") {
  13775. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  13776. }
  13777. } else if (node.phase === "defer") {
  13778. if (singleBindingType !== "ImportNamespaceSpecifier") {
  13779. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  13780. }
  13781. } else if (node.module) {
  13782. var _node$assertions;
  13783. if (singleBindingType !== "ImportDefaultSpecifier") {
  13784. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  13785. }
  13786. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  13787. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  13788. }
  13789. }
  13790. }
  13791. checkJSONModuleImport(node) {
  13792. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  13793. const {
  13794. specifiers
  13795. } = node;
  13796. if (specifiers != null) {
  13797. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  13798. let imported;
  13799. if (specifier.type === "ExportSpecifier") {
  13800. imported = specifier.local;
  13801. } else if (specifier.type === "ImportSpecifier") {
  13802. imported = specifier.imported;
  13803. }
  13804. if (imported !== undefined) {
  13805. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  13806. }
  13807. });
  13808. if (nonDefaultNamedSpecifier !== undefined) {
  13809. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  13810. }
  13811. }
  13812. }
  13813. }
  13814. isPotentialImportPhase(isExport) {
  13815. if (isExport) return false;
  13816. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  13817. }
  13818. applyImportPhase(node, isExport, phase, loc) {
  13819. if (isExport) {
  13820. return;
  13821. }
  13822. if (phase === "module") {
  13823. this.expectPlugin("importReflection", loc);
  13824. node.module = true;
  13825. } else if (this.hasPlugin("importReflection")) {
  13826. node.module = false;
  13827. }
  13828. if (phase === "source") {
  13829. this.expectPlugin("sourcePhaseImports", loc);
  13830. node.phase = "source";
  13831. } else if (phase === "defer") {
  13832. this.expectPlugin("deferredImportEvaluation", loc);
  13833. node.phase = "defer";
  13834. } else if (this.hasPlugin("sourcePhaseImports")) {
  13835. node.phase = null;
  13836. }
  13837. }
  13838. parseMaybeImportPhase(node, isExport) {
  13839. if (!this.isPotentialImportPhase(isExport)) {
  13840. this.applyImportPhase(node, isExport, null);
  13841. return null;
  13842. }
  13843. const phaseIdentifier = this.parseIdentifier(true);
  13844. const {
  13845. type
  13846. } = this.state;
  13847. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  13848. if (isImportPhase) {
  13849. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  13850. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  13851. return null;
  13852. } else {
  13853. this.applyImportPhase(node, isExport, null);
  13854. return phaseIdentifier;
  13855. }
  13856. }
  13857. isPrecedingIdImportPhase(phase) {
  13858. const {
  13859. type
  13860. } = this.state;
  13861. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  13862. }
  13863. parseImport(node) {
  13864. if (this.match(134)) {
  13865. return this.parseImportSourceAndAttributes(node);
  13866. }
  13867. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  13868. }
  13869. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  13870. node.specifiers = [];
  13871. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  13872. const parseNext = !hasDefault || this.eat(12);
  13873. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  13874. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  13875. this.expectContextual(98);
  13876. return this.parseImportSourceAndAttributes(node);
  13877. }
  13878. parseImportSourceAndAttributes(node) {
  13879. var _node$specifiers2;
  13880. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  13881. node.source = this.parseImportSource();
  13882. this.maybeParseImportAttributes(node);
  13883. this.checkImportReflection(node);
  13884. this.checkJSONModuleImport(node);
  13885. this.semicolon();
  13886. return this.finishNode(node, "ImportDeclaration");
  13887. }
  13888. parseImportSource() {
  13889. if (!this.match(134)) this.unexpected();
  13890. return this.parseExprAtom();
  13891. }
  13892. parseImportSpecifierLocal(node, specifier, type) {
  13893. specifier.local = this.parseIdentifier();
  13894. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  13895. }
  13896. finishImportSpecifier(specifier, type, bindingType = 8201) {
  13897. this.checkLVal(specifier.local, {
  13898. type
  13899. }, bindingType);
  13900. return this.finishNode(specifier, type);
  13901. }
  13902. parseImportAttributes() {
  13903. this.expect(5);
  13904. const attrs = [];
  13905. const attrNames = new Set();
  13906. do {
  13907. if (this.match(8)) {
  13908. break;
  13909. }
  13910. const node = this.startNode();
  13911. const keyName = this.state.value;
  13912. if (attrNames.has(keyName)) {
  13913. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  13914. key: keyName
  13915. });
  13916. }
  13917. attrNames.add(keyName);
  13918. if (this.match(134)) {
  13919. node.key = this.parseStringLiteral(keyName);
  13920. } else {
  13921. node.key = this.parseIdentifier(true);
  13922. }
  13923. this.expect(14);
  13924. if (!this.match(134)) {
  13925. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  13926. }
  13927. node.value = this.parseStringLiteral(this.state.value);
  13928. attrs.push(this.finishNode(node, "ImportAttribute"));
  13929. } while (this.eat(12));
  13930. this.expect(8);
  13931. return attrs;
  13932. }
  13933. parseModuleAttributes() {
  13934. const attrs = [];
  13935. const attributes = new Set();
  13936. do {
  13937. const node = this.startNode();
  13938. node.key = this.parseIdentifier(true);
  13939. if (node.key.name !== "type") {
  13940. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  13941. }
  13942. if (attributes.has(node.key.name)) {
  13943. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  13944. key: node.key.name
  13945. });
  13946. }
  13947. attributes.add(node.key.name);
  13948. this.expect(14);
  13949. if (!this.match(134)) {
  13950. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  13951. }
  13952. node.value = this.parseStringLiteral(this.state.value);
  13953. attrs.push(this.finishNode(node, "ImportAttribute"));
  13954. } while (this.eat(12));
  13955. return attrs;
  13956. }
  13957. maybeParseImportAttributes(node) {
  13958. let attributes;
  13959. {
  13960. var useWith = false;
  13961. }
  13962. if (this.match(76)) {
  13963. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  13964. return;
  13965. }
  13966. this.next();
  13967. if (this.hasPlugin("moduleAttributes")) {
  13968. attributes = this.parseModuleAttributes();
  13969. } else {
  13970. attributes = this.parseImportAttributes();
  13971. }
  13972. {
  13973. useWith = true;
  13974. }
  13975. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  13976. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  13977. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  13978. }
  13979. if (!this.hasPlugin("importAssertions")) {
  13980. this.addExtra(node, "deprecatedAssertSyntax", true);
  13981. }
  13982. this.next();
  13983. attributes = this.parseImportAttributes();
  13984. } else {
  13985. attributes = [];
  13986. }
  13987. if (!useWith && this.hasPlugin("importAssertions")) {
  13988. node.assertions = attributes;
  13989. } else {
  13990. node.attributes = attributes;
  13991. }
  13992. }
  13993. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  13994. if (maybeDefaultIdentifier) {
  13995. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  13996. specifier.local = maybeDefaultIdentifier;
  13997. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  13998. return true;
  13999. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14000. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14001. return true;
  14002. }
  14003. return false;
  14004. }
  14005. maybeParseStarImportSpecifier(node) {
  14006. if (this.match(55)) {
  14007. const specifier = this.startNode();
  14008. this.next();
  14009. this.expectContextual(93);
  14010. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14011. return true;
  14012. }
  14013. return false;
  14014. }
  14015. parseNamedImportSpecifiers(node) {
  14016. let first = true;
  14017. this.expect(5);
  14018. while (!this.eat(8)) {
  14019. if (first) {
  14020. first = false;
  14021. } else {
  14022. if (this.eat(14)) {
  14023. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  14024. }
  14025. this.expect(12);
  14026. if (this.eat(8)) break;
  14027. }
  14028. const specifier = this.startNode();
  14029. const importedIsString = this.match(134);
  14030. const isMaybeTypeOnly = this.isContextual(130);
  14031. specifier.imported = this.parseModuleExportName();
  14032. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14033. node.specifiers.push(importSpecifier);
  14034. }
  14035. }
  14036. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14037. if (this.eatContextual(93)) {
  14038. specifier.local = this.parseIdentifier();
  14039. } else {
  14040. const {
  14041. imported
  14042. } = specifier;
  14043. if (importedIsString) {
  14044. throw this.raise(Errors.ImportBindingIsString, specifier, {
  14045. importName: imported.value
  14046. });
  14047. }
  14048. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14049. if (!specifier.local) {
  14050. specifier.local = cloneIdentifier(imported);
  14051. }
  14052. }
  14053. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14054. }
  14055. isThisParam(param) {
  14056. return param.type === "Identifier" && param.name === "this";
  14057. }
  14058. }
  14059. class Parser extends StatementParser {
  14060. constructor(options, input, pluginsMap) {
  14061. options = getOptions(options);
  14062. super(options, input);
  14063. this.options = options;
  14064. this.initializeScopes();
  14065. this.plugins = pluginsMap;
  14066. this.filename = options.sourceFilename;
  14067. this.startIndex = options.startIndex;
  14068. let optionFlags = 0;
  14069. if (options.allowAwaitOutsideFunction) {
  14070. optionFlags |= 1;
  14071. }
  14072. if (options.allowReturnOutsideFunction) {
  14073. optionFlags |= 2;
  14074. }
  14075. if (options.allowImportExportEverywhere) {
  14076. optionFlags |= 8;
  14077. }
  14078. if (options.allowSuperOutsideMethod) {
  14079. optionFlags |= 16;
  14080. }
  14081. if (options.allowUndeclaredExports) {
  14082. optionFlags |= 32;
  14083. }
  14084. if (options.allowNewTargetOutsideFunction) {
  14085. optionFlags |= 4;
  14086. }
  14087. if (options.ranges) {
  14088. optionFlags |= 64;
  14089. }
  14090. if (options.tokens) {
  14091. optionFlags |= 128;
  14092. }
  14093. if (options.createImportExpressions) {
  14094. optionFlags |= 256;
  14095. }
  14096. if (options.createParenthesizedExpressions) {
  14097. optionFlags |= 512;
  14098. }
  14099. if (options.errorRecovery) {
  14100. optionFlags |= 1024;
  14101. }
  14102. if (options.attachComment) {
  14103. optionFlags |= 2048;
  14104. }
  14105. if (options.annexB) {
  14106. optionFlags |= 4096;
  14107. }
  14108. this.optionFlags = optionFlags;
  14109. }
  14110. getScopeHandler() {
  14111. return ScopeHandler;
  14112. }
  14113. parse() {
  14114. this.enterInitialScopes();
  14115. const file = this.startNode();
  14116. const program = this.startNode();
  14117. this.nextToken();
  14118. file.errors = null;
  14119. this.parseTopLevel(file, program);
  14120. file.errors = this.state.errors;
  14121. file.comments.length = this.state.commentsLen;
  14122. return file;
  14123. }
  14124. }
  14125. function parse(input, options) {
  14126. var _options;
  14127. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14128. options = Object.assign({}, options);
  14129. try {
  14130. options.sourceType = "module";
  14131. const parser = getParser(options, input);
  14132. const ast = parser.parse();
  14133. if (parser.sawUnambiguousESM) {
  14134. return ast;
  14135. }
  14136. if (parser.ambiguousScriptDifferentAst) {
  14137. try {
  14138. options.sourceType = "script";
  14139. return getParser(options, input).parse();
  14140. } catch (_unused) {}
  14141. } else {
  14142. ast.program.sourceType = "script";
  14143. }
  14144. return ast;
  14145. } catch (moduleError) {
  14146. try {
  14147. options.sourceType = "script";
  14148. return getParser(options, input).parse();
  14149. } catch (_unused2) {}
  14150. throw moduleError;
  14151. }
  14152. } else {
  14153. return getParser(options, input).parse();
  14154. }
  14155. }
  14156. function parseExpression(input, options) {
  14157. const parser = getParser(options, input);
  14158. if (parser.options.strictMode) {
  14159. parser.state.strict = true;
  14160. }
  14161. return parser.getExpression();
  14162. }
  14163. function generateExportedTokenTypes(internalTokenTypes) {
  14164. const tokenTypes = {};
  14165. for (const typeName of Object.keys(internalTokenTypes)) {
  14166. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14167. }
  14168. return tokenTypes;
  14169. }
  14170. const tokTypes = generateExportedTokenTypes(tt);
  14171. function getParser(options, input) {
  14172. let cls = Parser;
  14173. const pluginsMap = new Map();
  14174. if (options != null && options.plugins) {
  14175. for (const plugin of options.plugins) {
  14176. let name, opts;
  14177. if (typeof plugin === "string") {
  14178. name = plugin;
  14179. } else {
  14180. [name, opts] = plugin;
  14181. }
  14182. if (!pluginsMap.has(name)) {
  14183. pluginsMap.set(name, opts || {});
  14184. }
  14185. }
  14186. validatePlugins(pluginsMap);
  14187. cls = getParserClass(pluginsMap);
  14188. }
  14189. return new cls(options, input, pluginsMap);
  14190. }
  14191. const parserClassCache = new Map();
  14192. function getParserClass(pluginsMap) {
  14193. const pluginList = [];
  14194. for (const name of mixinPluginNames) {
  14195. if (pluginsMap.has(name)) {
  14196. pluginList.push(name);
  14197. }
  14198. }
  14199. const key = pluginList.join("|");
  14200. let cls = parserClassCache.get(key);
  14201. if (!cls) {
  14202. cls = Parser;
  14203. for (const plugin of pluginList) {
  14204. cls = mixinPlugins[plugin](cls);
  14205. }
  14206. parserClassCache.set(key, cls);
  14207. }
  14208. return cls;
  14209. }
  14210. exports.parse = parse;
  14211. exports.parseExpression = parseExpression;
  14212. exports.tokTypes = tokTypes;
  14213. //# sourceMappingURL=index.js.map