index.js 501 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. function _objectWithoutPropertiesLoose(r, e) {
  6. if (null == r) return {};
  7. var t = {};
  8. for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
  9. if (-1 !== e.indexOf(n)) continue;
  10. t[n] = r[n];
  11. }
  12. return t;
  13. }
  14. class Position {
  15. constructor(line, col, index) {
  16. this.line = void 0;
  17. this.column = void 0;
  18. this.index = void 0;
  19. this.line = line;
  20. this.column = col;
  21. this.index = index;
  22. }
  23. }
  24. class SourceLocation {
  25. constructor(start, end) {
  26. this.start = void 0;
  27. this.end = void 0;
  28. this.filename = void 0;
  29. this.identifierName = void 0;
  30. this.start = start;
  31. this.end = end;
  32. }
  33. }
  34. function createPositionWithColumnOffset(position, columnOffset) {
  35. const {
  36. line,
  37. column,
  38. index
  39. } = position;
  40. return new Position(line, column + columnOffset, index + columnOffset);
  41. }
  42. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  43. var ModuleErrors = {
  44. ImportMetaOutsideModule: {
  45. message: `import.meta may appear only with 'sourceType: "module"'`,
  46. code
  47. },
  48. ImportOutsideModule: {
  49. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  50. code
  51. }
  52. };
  53. const NodeDescriptions = {
  54. ArrayPattern: "array destructuring pattern",
  55. AssignmentExpression: "assignment expression",
  56. AssignmentPattern: "assignment expression",
  57. ArrowFunctionExpression: "arrow function expression",
  58. ConditionalExpression: "conditional expression",
  59. CatchClause: "catch clause",
  60. ForOfStatement: "for-of statement",
  61. ForInStatement: "for-in statement",
  62. ForStatement: "for-loop",
  63. FormalParameters: "function parameter list",
  64. Identifier: "identifier",
  65. ImportSpecifier: "import specifier",
  66. ImportDefaultSpecifier: "import default specifier",
  67. ImportNamespaceSpecifier: "import namespace specifier",
  68. ObjectPattern: "object destructuring pattern",
  69. ParenthesizedExpression: "parenthesized expression",
  70. RestElement: "rest element",
  71. UpdateExpression: {
  72. true: "prefix operation",
  73. false: "postfix operation"
  74. },
  75. VariableDeclarator: "variable declaration",
  76. YieldExpression: "yield expression"
  77. };
  78. const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type];
  79. var StandardErrors = {
  80. AccessorIsGenerator: ({
  81. kind
  82. }) => `A ${kind}ter cannot be a generator.`,
  83. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  84. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  85. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  86. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  87. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  88. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  89. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  90. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  91. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  92. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  93. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  94. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  95. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  96. ConstructorIsAsync: "Constructor can't be an async function.",
  97. ConstructorIsGenerator: "Constructor can't be a generator.",
  98. DeclarationMissingInitializer: ({
  99. kind
  100. }) => `Missing initializer in ${kind} declaration.`,
  101. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  102. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  103. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  104. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  105. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  106. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  107. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  108. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  109. DeletePrivateField: "Deleting a private field is not allowed.",
  110. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  111. DuplicateConstructor: "Duplicate constructor in the same class.",
  112. DuplicateDefaultExport: "Only one default export allowed per module.",
  113. DuplicateExport: ({
  114. exportName
  115. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  116. DuplicateProto: "Redefinition of __proto__ property.",
  117. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  118. ElementAfterRest: "Rest element must be last element.",
  119. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  120. ExportBindingIsString: ({
  121. localName,
  122. exportName
  123. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  124. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  125. ForInOfLoopInitializer: ({
  126. type
  127. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  128. ForInUsing: "For-in loop may not start with 'using' declaration.",
  129. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  130. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  131. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  132. IllegalBreakContinue: ({
  133. type
  134. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  135. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  136. IllegalReturn: "'return' outside of function.",
  137. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedImportAssert` parser plugin to suppress this error.",
  138. ImportBindingIsString: ({
  139. importName
  140. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  141. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  142. ImportCallNotNewExpression: "Cannot use new with import(...).",
  143. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  144. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  145. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  146. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  147. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  148. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  149. InvalidCodePoint: "Code point out of bounds.",
  150. InvalidCoverDiscardElement: "'void' must be followed by an expression when not used in a binding position.",
  151. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  152. InvalidDecimal: "Invalid decimal.",
  153. InvalidDigit: ({
  154. radix
  155. }) => `Expected number in radix ${radix}.`,
  156. InvalidEscapeSequence: "Bad character escape sequence.",
  157. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  158. InvalidEscapedReservedWord: ({
  159. reservedWord
  160. }) => `Escape sequence in keyword ${reservedWord}.`,
  161. InvalidIdentifier: ({
  162. identifierName
  163. }) => `Invalid identifier ${identifierName}.`,
  164. InvalidLhs: ({
  165. ancestor
  166. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  167. InvalidLhsBinding: ({
  168. ancestor
  169. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  170. InvalidLhsOptionalChaining: ({
  171. ancestor
  172. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  173. InvalidNumber: "Invalid number.",
  174. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  175. InvalidOrUnexpectedToken: ({
  176. unexpected
  177. }) => `Unexpected character '${unexpected}'.`,
  178. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  179. InvalidPrivateFieldResolution: ({
  180. identifierName
  181. }) => `Private name #${identifierName} is not defined.`,
  182. InvalidPropertyBindingPattern: "Binding member expression.",
  183. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  184. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  185. LabelRedeclaration: ({
  186. labelName
  187. }) => `Label '${labelName}' is already declared.`,
  188. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  189. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  190. MalformedRegExpFlags: "Invalid regular expression flag.",
  191. MissingClassName: "A class name is required.",
  192. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  193. MissingSemicolon: "Missing semicolon.",
  194. MissingPlugin: ({
  195. missingPlugin
  196. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  197. MissingOneOfPlugins: ({
  198. missingPlugin
  199. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  200. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  201. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  202. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  203. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  204. ModuleAttributesWithDuplicateKeys: ({
  205. key
  206. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  207. ModuleExportNameHasLoneSurrogate: ({
  208. surrogateCharCode
  209. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  210. ModuleExportUndefined: ({
  211. localName
  212. }) => `Export '${localName}' is not defined.`,
  213. MultipleDefaultsInSwitch: "Multiple default clauses.",
  214. NewlineAfterThrow: "Illegal newline after throw.",
  215. NoCatchOrFinally: "Missing catch or finally clause.",
  216. NumberIdentifier: "Identifier directly after number.",
  217. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  218. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  219. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  220. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  221. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  222. ParamDupe: "Argument name clash.",
  223. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  224. PatternHasMethod: "Object pattern can't contain methods.",
  225. PrivateInExpectedIn: ({
  226. identifierName
  227. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  228. PrivateNameRedeclaration: ({
  229. identifierName
  230. }) => `Duplicate private name #${identifierName}.`,
  231. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  232. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  233. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  234. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  235. RestTrailingComma: "Unexpected trailing comma after rest element.",
  236. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  237. SloppyFunctionAnnexB: "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement.",
  238. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  239. StaticPrototype: "Classes may not have static property named prototype.",
  240. SuperCallNotNewExpression: "Cannot use new with super(...).",
  241. 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?",
  242. SuperPrivateField: "Private fields can't be accessed on super.",
  243. TrailingDecorator: "Decorators must be attached to a class element.",
  244. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  245. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  246. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  247. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  248. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  249. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  250. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  251. UnexpectedKeyword: ({
  252. keyword
  253. }) => `Unexpected keyword '${keyword}'.`,
  254. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  255. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  256. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  257. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  258. UnexpectedPrivateField: "Unexpected private name.",
  259. UnexpectedReservedWord: ({
  260. reservedWord
  261. }) => `Unexpected reserved word '${reservedWord}'.`,
  262. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  263. UnexpectedToken: ({
  264. expected,
  265. unexpected
  266. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  267. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  268. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement.",
  269. UnexpectedVoidPattern: "Unexpected void binding.",
  270. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  271. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  272. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  273. UnsupportedMetaProperty: ({
  274. target,
  275. onlyValidPropertyName
  276. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  277. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  278. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  279. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  280. UnterminatedComment: "Unterminated comment.",
  281. UnterminatedRegExp: "Unterminated regular expression.",
  282. UnterminatedString: "Unterminated string constant.",
  283. UnterminatedTemplate: "Unterminated template.",
  284. UsingDeclarationExport: "Using declaration cannot be exported.",
  285. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  286. VarRedeclaration: ({
  287. identifierName
  288. }) => `Identifier '${identifierName}' has already been declared.`,
  289. VoidPatternCatchClauseParam: "A void binding can not be the catch clause parameter. Use `try { ... } catch { ... }` if you want to discard the caught error.",
  290. VoidPatternInitializer: "A void binding may not have an initializer.",
  291. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  292. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  293. YieldNotInGeneratorFunction: "'yield' is only allowed within generator functions.",
  294. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  295. };
  296. var StrictModeErrors = {
  297. StrictDelete: "Deleting local variable in strict mode.",
  298. StrictEvalArguments: ({
  299. referenceName
  300. }) => `Assigning to '${referenceName}' in strict mode.`,
  301. StrictEvalArgumentsBinding: ({
  302. bindingName
  303. }) => `Binding '${bindingName}' in strict mode.`,
  304. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  305. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  306. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  307. StrictWith: "'with' in strict mode."
  308. };
  309. var ParseExpressionErrors = {
  310. ParseExpressionEmptyInput: "Unexpected parseExpression() input: The input is empty or contains only comments.",
  311. ParseExpressionExpectsEOF: ({
  312. unexpected
  313. }) => `Unexpected parseExpression() input: The input should contain exactly one expression, but the first expression is followed by the unexpected character \`${String.fromCodePoint(unexpected)}\`.`
  314. };
  315. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  316. var PipelineOperatorErrors = Object.assign({
  317. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  318. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  319. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  320. PipeTopicUnconfiguredToken: ({
  321. token
  322. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  323. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  324. PipeUnparenthesizedBody: ({
  325. type
  326. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  327. type
  328. })}; please wrap it in parentheses.`
  329. }, {
  330. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  331. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  332. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  333. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  334. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  335. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  336. });
  337. var FunctionBindErrors = {
  338. UnsupportedBind: "Binding should be performed on object property.",
  339. UnsupportedBindRHS: "The right-hand side of binding can not be super or import."
  340. };
  341. const _excluded = ["message"];
  342. function defineHidden(obj, key, value) {
  343. Object.defineProperty(obj, key, {
  344. enumerable: false,
  345. configurable: true,
  346. value
  347. });
  348. }
  349. function toParseErrorConstructor({
  350. toMessage,
  351. code,
  352. reasonCode,
  353. syntaxPlugin
  354. }) {
  355. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  356. const oldReasonCodes = {
  357. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  358. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  359. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  360. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  361. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  362. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  363. };
  364. if (oldReasonCodes[reasonCode]) {
  365. reasonCode = oldReasonCodes[reasonCode];
  366. }
  367. return function constructor(loc, details) {
  368. const error = new SyntaxError();
  369. error.code = code;
  370. error.reasonCode = reasonCode;
  371. error.loc = loc;
  372. error.pos = loc.index;
  373. error.syntaxPlugin = syntaxPlugin;
  374. if (hasMissingPlugin) {
  375. error.missingPlugin = details.missingPlugin;
  376. }
  377. defineHidden(error, "clone", function clone(overrides = {}) {
  378. var _overrides$loc;
  379. const {
  380. line,
  381. column,
  382. index
  383. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  384. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  385. });
  386. defineHidden(error, "details", details);
  387. Object.defineProperty(error, "message", {
  388. configurable: true,
  389. get() {
  390. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  391. this.message = message;
  392. return message;
  393. },
  394. set(value) {
  395. Object.defineProperty(this, "message", {
  396. value,
  397. writable: true
  398. });
  399. }
  400. });
  401. return error;
  402. };
  403. }
  404. function ParseErrorEnum(argument, syntaxPlugin) {
  405. if (Array.isArray(argument)) {
  406. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  407. }
  408. const ParseErrorConstructors = {};
  409. for (const reasonCode of Object.keys(argument)) {
  410. const template = argument[reasonCode];
  411. const _ref = typeof template === "string" ? {
  412. message: () => template
  413. } : typeof template === "function" ? {
  414. message: template
  415. } : template,
  416. {
  417. message
  418. } = _ref,
  419. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  420. const toMessage = typeof message === "string" ? () => message : message;
  421. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  422. code: "BABEL_PARSER_SYNTAX_ERROR",
  423. reasonCode,
  424. toMessage
  425. }, syntaxPlugin ? {
  426. syntaxPlugin
  427. } : {}, rest));
  428. }
  429. return ParseErrorConstructors;
  430. }
  431. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum(ParseExpressionErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors), ParseErrorEnum`functionBind`(FunctionBindErrors));
  432. function createDefaultOptions() {
  433. return {
  434. sourceType: "script",
  435. sourceFilename: undefined,
  436. startIndex: 0,
  437. startColumn: 0,
  438. startLine: 1,
  439. allowAwaitOutsideFunction: false,
  440. allowReturnOutsideFunction: false,
  441. allowNewTargetOutsideFunction: false,
  442. allowImportExportEverywhere: false,
  443. allowSuperOutsideMethod: false,
  444. allowUndeclaredExports: false,
  445. allowYieldOutsideFunction: false,
  446. plugins: [],
  447. strictMode: undefined,
  448. ranges: false,
  449. tokens: false,
  450. createImportExpressions: false,
  451. createParenthesizedExpressions: false,
  452. errorRecovery: false,
  453. attachComment: true,
  454. annexB: true
  455. };
  456. }
  457. function getOptions(opts) {
  458. const options = createDefaultOptions();
  459. if (opts == null) {
  460. return options;
  461. }
  462. if (opts.annexB != null && opts.annexB !== false) {
  463. throw new Error("The `annexB` option can only be set to `false`.");
  464. }
  465. for (const key of Object.keys(options)) {
  466. if (opts[key] != null) options[key] = opts[key];
  467. }
  468. if (options.startLine === 1) {
  469. if (opts.startIndex == null && options.startColumn > 0) {
  470. options.startIndex = options.startColumn;
  471. } else if (opts.startColumn == null && options.startIndex > 0) {
  472. options.startColumn = options.startIndex;
  473. }
  474. } else if (opts.startColumn == null || opts.startIndex == null) {
  475. if (opts.startIndex != null) {
  476. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  477. }
  478. }
  479. if (options.sourceType === "commonjs") {
  480. if (opts.allowAwaitOutsideFunction != null) {
  481. throw new Error("The `allowAwaitOutsideFunction` option cannot be used with `sourceType: 'commonjs'`.");
  482. }
  483. if (opts.allowReturnOutsideFunction != null) {
  484. throw new Error("`sourceType: 'commonjs'` implies `allowReturnOutsideFunction: true`, please remove the `allowReturnOutsideFunction` option or use `sourceType: 'script'`.");
  485. }
  486. if (opts.allowNewTargetOutsideFunction != null) {
  487. throw new Error("`sourceType: 'commonjs'` implies `allowNewTargetOutsideFunction: true`, please remove the `allowNewTargetOutsideFunction` option or use `sourceType: 'script'`.");
  488. }
  489. }
  490. return options;
  491. }
  492. const {
  493. defineProperty
  494. } = Object;
  495. const toUnenumerable = (object, key) => {
  496. if (object) {
  497. defineProperty(object, key, {
  498. enumerable: false,
  499. value: object[key]
  500. });
  501. }
  502. };
  503. function toESTreeLocation(node) {
  504. toUnenumerable(node.loc.start, "index");
  505. toUnenumerable(node.loc.end, "index");
  506. return node;
  507. }
  508. var estree = superClass => class ESTreeParserMixin extends superClass {
  509. parse() {
  510. const file = toESTreeLocation(super.parse());
  511. if (this.optionFlags & 256) {
  512. file.tokens = file.tokens.map(toESTreeLocation);
  513. }
  514. return file;
  515. }
  516. parseRegExpLiteral({
  517. pattern,
  518. flags
  519. }) {
  520. let regex = null;
  521. try {
  522. regex = new RegExp(pattern, flags);
  523. } catch (_) {}
  524. const node = this.estreeParseLiteral(regex);
  525. node.regex = {
  526. pattern,
  527. flags
  528. };
  529. return node;
  530. }
  531. parseBigIntLiteral(value) {
  532. let bigInt;
  533. try {
  534. bigInt = BigInt(value);
  535. } catch (_unused) {
  536. bigInt = null;
  537. }
  538. const node = this.estreeParseLiteral(bigInt);
  539. node.bigint = String(node.value || value);
  540. return node;
  541. }
  542. parseDecimalLiteral(value) {
  543. const decimal = null;
  544. const node = this.estreeParseLiteral(decimal);
  545. node.decimal = String(node.value || value);
  546. return node;
  547. }
  548. estreeParseLiteral(value) {
  549. return this.parseLiteral(value, "Literal");
  550. }
  551. parseStringLiteral(value) {
  552. return this.estreeParseLiteral(value);
  553. }
  554. parseNumericLiteral(value) {
  555. return this.estreeParseLiteral(value);
  556. }
  557. parseNullLiteral() {
  558. return this.estreeParseLiteral(null);
  559. }
  560. parseBooleanLiteral(value) {
  561. return this.estreeParseLiteral(value);
  562. }
  563. estreeParseChainExpression(node, endLoc) {
  564. const chain = this.startNodeAtNode(node);
  565. chain.expression = node;
  566. return this.finishNodeAt(chain, "ChainExpression", endLoc);
  567. }
  568. directiveToStmt(directive) {
  569. const expression = directive.value;
  570. delete directive.value;
  571. this.castNodeTo(expression, "Literal");
  572. expression.raw = expression.extra.raw;
  573. expression.value = expression.extra.expressionValue;
  574. const stmt = this.castNodeTo(directive, "ExpressionStatement");
  575. stmt.expression = expression;
  576. stmt.directive = expression.extra.rawValue;
  577. delete expression.extra;
  578. return stmt;
  579. }
  580. fillOptionalPropertiesForTSESLint(node) {}
  581. cloneEstreeStringLiteral(node) {
  582. const {
  583. start,
  584. end,
  585. loc,
  586. range,
  587. raw,
  588. value
  589. } = node;
  590. const cloned = Object.create(node.constructor.prototype);
  591. cloned.type = "Literal";
  592. cloned.start = start;
  593. cloned.end = end;
  594. cloned.loc = loc;
  595. cloned.range = range;
  596. cloned.raw = raw;
  597. cloned.value = value;
  598. return cloned;
  599. }
  600. initFunction(node, isAsync) {
  601. super.initFunction(node, isAsync);
  602. node.expression = false;
  603. }
  604. checkDeclaration(node) {
  605. if (node != null && this.isObjectProperty(node)) {
  606. this.checkDeclaration(node.value);
  607. } else {
  608. super.checkDeclaration(node);
  609. }
  610. }
  611. getObjectOrClassMethodParams(method) {
  612. return method.value.params;
  613. }
  614. isValidDirective(stmt) {
  615. var _stmt$expression$extr;
  616. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  617. }
  618. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  619. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  620. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  621. node.body = directiveStatements.concat(node.body);
  622. delete node.directives;
  623. }
  624. parsePrivateName() {
  625. const node = super.parsePrivateName();
  626. if (!this.getPluginOption("estree", "classFeatures")) {
  627. return node;
  628. }
  629. return this.convertPrivateNameToPrivateIdentifier(node);
  630. }
  631. convertPrivateNameToPrivateIdentifier(node) {
  632. const name = super.getPrivateNameSV(node);
  633. delete node.id;
  634. node.name = name;
  635. return this.castNodeTo(node, "PrivateIdentifier");
  636. }
  637. isPrivateName(node) {
  638. if (!this.getPluginOption("estree", "classFeatures")) {
  639. return super.isPrivateName(node);
  640. }
  641. return node.type === "PrivateIdentifier";
  642. }
  643. getPrivateNameSV(node) {
  644. if (!this.getPluginOption("estree", "classFeatures")) {
  645. return super.getPrivateNameSV(node);
  646. }
  647. return node.name;
  648. }
  649. parseLiteral(value, type) {
  650. const node = super.parseLiteral(value, type);
  651. node.raw = node.extra.raw;
  652. delete node.extra;
  653. return node;
  654. }
  655. parseFunctionBody(node, allowExpression, isMethod = false) {
  656. super.parseFunctionBody(node, allowExpression, isMethod);
  657. node.expression = node.body.type !== "BlockStatement";
  658. }
  659. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  660. let funcNode = this.startNode();
  661. funcNode.kind = node.kind;
  662. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  663. delete funcNode.kind;
  664. const {
  665. typeParameters
  666. } = node;
  667. if (typeParameters) {
  668. delete node.typeParameters;
  669. funcNode.typeParameters = typeParameters;
  670. this.resetStartLocationFromNode(funcNode, typeParameters);
  671. }
  672. const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
  673. node.value = valueNode;
  674. if (type === "ClassPrivateMethod") {
  675. node.computed = false;
  676. }
  677. if (type === "ObjectMethod") {
  678. if (node.kind === "method") {
  679. node.kind = "init";
  680. }
  681. node.shorthand = false;
  682. return this.finishNode(node, "Property");
  683. } else {
  684. return this.finishNode(node, "MethodDefinition");
  685. }
  686. }
  687. nameIsConstructor(key) {
  688. if (key.type === "Literal") return key.value === "constructor";
  689. return super.nameIsConstructor(key);
  690. }
  691. parseClassProperty(...args) {
  692. const propertyNode = super.parseClassProperty(...args);
  693. if (!this.getPluginOption("estree", "classFeatures")) {
  694. return propertyNode;
  695. }
  696. this.castNodeTo(propertyNode, "PropertyDefinition");
  697. return propertyNode;
  698. }
  699. parseClassPrivateProperty(...args) {
  700. const propertyNode = super.parseClassPrivateProperty(...args);
  701. if (!this.getPluginOption("estree", "classFeatures")) {
  702. return propertyNode;
  703. }
  704. this.castNodeTo(propertyNode, "PropertyDefinition");
  705. propertyNode.computed = false;
  706. return propertyNode;
  707. }
  708. parseClassAccessorProperty(node) {
  709. const accessorPropertyNode = super.parseClassAccessorProperty(node);
  710. if (!this.getPluginOption("estree", "classFeatures")) {
  711. return accessorPropertyNode;
  712. }
  713. if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
  714. delete accessorPropertyNode.abstract;
  715. this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
  716. } else {
  717. this.castNodeTo(accessorPropertyNode, "AccessorProperty");
  718. }
  719. return accessorPropertyNode;
  720. }
  721. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  722. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  723. if (node) {
  724. node.kind = "init";
  725. this.castNodeTo(node, "Property");
  726. }
  727. return node;
  728. }
  729. finishObjectProperty(node) {
  730. node.kind = "init";
  731. return this.finishNode(node, "Property");
  732. }
  733. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  734. return type === "Property" ? "value" : super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  735. }
  736. isAssignable(node, isBinding) {
  737. if (node != null && this.isObjectProperty(node)) {
  738. return this.isAssignable(node.value, isBinding);
  739. }
  740. return super.isAssignable(node, isBinding);
  741. }
  742. toAssignable(node, isLHS = false) {
  743. if (node != null && this.isObjectProperty(node)) {
  744. const {
  745. key,
  746. value
  747. } = node;
  748. if (this.isPrivateName(key)) {
  749. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  750. }
  751. this.toAssignable(value, isLHS);
  752. } else {
  753. super.toAssignable(node, isLHS);
  754. }
  755. }
  756. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  757. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  758. this.raise(Errors.PatternHasAccessor, prop.key);
  759. } else if (prop.type === "Property" && prop.method) {
  760. this.raise(Errors.PatternHasMethod, prop.key);
  761. } else {
  762. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  763. }
  764. }
  765. finishCallExpression(unfinished, optional) {
  766. const node = super.finishCallExpression(unfinished, optional);
  767. if (node.callee.type === "Import") {
  768. var _ref, _ref2;
  769. this.castNodeTo(node, "ImportExpression");
  770. node.source = node.arguments[0];
  771. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  772. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  773. delete node.arguments;
  774. delete node.callee;
  775. } else if (node.type === "OptionalCallExpression") {
  776. this.castNodeTo(node, "CallExpression");
  777. } else {
  778. node.optional = false;
  779. }
  780. return node;
  781. }
  782. toReferencedArguments(node) {
  783. if (node.type === "ImportExpression") {
  784. return;
  785. }
  786. super.toReferencedArguments(node);
  787. }
  788. parseExport(unfinished, decorators) {
  789. const exportStartLoc = this.state.lastTokStartLoc;
  790. const node = super.parseExport(unfinished, decorators);
  791. switch (node.type) {
  792. case "ExportAllDeclaration":
  793. node.exported = null;
  794. break;
  795. case "ExportNamedDeclaration":
  796. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  797. this.castNodeTo(node, "ExportAllDeclaration");
  798. node.exported = node.specifiers[0].exported;
  799. delete node.specifiers;
  800. }
  801. case "ExportDefaultDeclaration":
  802. {
  803. var _declaration$decorato;
  804. const {
  805. declaration
  806. } = node;
  807. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  808. this.resetStartLocation(node, exportStartLoc);
  809. }
  810. }
  811. break;
  812. }
  813. return node;
  814. }
  815. stopParseSubscript(base, state) {
  816. const node = super.stopParseSubscript(base, state);
  817. if (state.optionalChainMember) {
  818. return this.estreeParseChainExpression(node, base.loc.end);
  819. }
  820. return node;
  821. }
  822. parseMember(base, startLoc, state, computed, optional) {
  823. const node = super.parseMember(base, startLoc, state, computed, optional);
  824. if (node.type === "OptionalMemberExpression") {
  825. this.castNodeTo(node, "MemberExpression");
  826. } else {
  827. node.optional = false;
  828. }
  829. return node;
  830. }
  831. isOptionalMemberExpression(node) {
  832. if (node.type === "ChainExpression") {
  833. return node.expression.type === "MemberExpression";
  834. }
  835. return super.isOptionalMemberExpression(node);
  836. }
  837. hasPropertyAsPrivateName(node) {
  838. if (node.type === "ChainExpression") {
  839. node = node.expression;
  840. }
  841. return super.hasPropertyAsPrivateName(node);
  842. }
  843. isObjectProperty(node) {
  844. return node.type === "Property" && node.kind === "init" && !node.method;
  845. }
  846. isObjectMethod(node) {
  847. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  848. }
  849. castNodeTo(node, type) {
  850. const result = super.castNodeTo(node, type);
  851. this.fillOptionalPropertiesForTSESLint(result);
  852. return result;
  853. }
  854. cloneIdentifier(node) {
  855. const cloned = super.cloneIdentifier(node);
  856. this.fillOptionalPropertiesForTSESLint(cloned);
  857. return cloned;
  858. }
  859. cloneStringLiteral(node) {
  860. if (node.type === "Literal") {
  861. return this.cloneEstreeStringLiteral(node);
  862. }
  863. return super.cloneStringLiteral(node);
  864. }
  865. finishNodeAt(node, type, endLoc) {
  866. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  867. }
  868. finishNode(node, type) {
  869. const result = super.finishNode(node, type);
  870. this.fillOptionalPropertiesForTSESLint(result);
  871. return result;
  872. }
  873. resetStartLocation(node, startLoc) {
  874. super.resetStartLocation(node, startLoc);
  875. toESTreeLocation(node);
  876. }
  877. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  878. super.resetEndLocation(node, endLoc);
  879. toESTreeLocation(node);
  880. }
  881. };
  882. class TokContext {
  883. constructor(token, preserveSpace) {
  884. this.token = void 0;
  885. this.preserveSpace = void 0;
  886. this.token = token;
  887. this.preserveSpace = !!preserveSpace;
  888. }
  889. }
  890. const types = {
  891. brace: new TokContext("{"),
  892. j_oTag: new TokContext("<tag"),
  893. j_cTag: new TokContext("</tag"),
  894. j_expr: new TokContext("<tag>...</tag>", true)
  895. };
  896. types.template = new TokContext("`", true);
  897. const beforeExpr = true;
  898. const startsExpr = true;
  899. const isLoop = true;
  900. const isAssign = true;
  901. const prefix = true;
  902. const postfix = true;
  903. class ExportedTokenType {
  904. constructor(label, conf = {}) {
  905. this.label = void 0;
  906. this.keyword = void 0;
  907. this.beforeExpr = void 0;
  908. this.startsExpr = void 0;
  909. this.rightAssociative = void 0;
  910. this.isLoop = void 0;
  911. this.isAssign = void 0;
  912. this.prefix = void 0;
  913. this.postfix = void 0;
  914. this.binop = void 0;
  915. this.label = label;
  916. this.keyword = conf.keyword;
  917. this.beforeExpr = !!conf.beforeExpr;
  918. this.startsExpr = !!conf.startsExpr;
  919. this.rightAssociative = !!conf.rightAssociative;
  920. this.isLoop = !!conf.isLoop;
  921. this.isAssign = !!conf.isAssign;
  922. this.prefix = !!conf.prefix;
  923. this.postfix = !!conf.postfix;
  924. this.binop = conf.binop != null ? conf.binop : null;
  925. this.updateContext = null;
  926. }
  927. }
  928. const keywords$1 = new Map();
  929. function createKeyword(name, options = {}) {
  930. options.keyword = name;
  931. const token = createToken(name, options);
  932. keywords$1.set(name, token);
  933. return token;
  934. }
  935. function createBinop(name, binop) {
  936. return createToken(name, {
  937. beforeExpr,
  938. binop
  939. });
  940. }
  941. let tokenTypeCounter = -1;
  942. const tokenTypes = [];
  943. const tokenLabels = [];
  944. const tokenBinops = [];
  945. const tokenBeforeExprs = [];
  946. const tokenStartsExprs = [];
  947. const tokenPrefixes = [];
  948. function createToken(name, options = {}) {
  949. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  950. ++tokenTypeCounter;
  951. tokenLabels.push(name);
  952. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  953. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  954. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  955. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  956. tokenTypes.push(new ExportedTokenType(name, options));
  957. return tokenTypeCounter;
  958. }
  959. function createKeywordLike(name, options = {}) {
  960. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  961. ++tokenTypeCounter;
  962. keywords$1.set(name, tokenTypeCounter);
  963. tokenLabels.push(name);
  964. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  965. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  966. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  967. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  968. tokenTypes.push(new ExportedTokenType("name", options));
  969. return tokenTypeCounter;
  970. }
  971. const tt = {
  972. bracketL: createToken("[", {
  973. beforeExpr,
  974. startsExpr
  975. }),
  976. bracketHashL: createToken("#[", {
  977. beforeExpr,
  978. startsExpr
  979. }),
  980. bracketBarL: createToken("[|", {
  981. beforeExpr,
  982. startsExpr
  983. }),
  984. bracketR: createToken("]"),
  985. bracketBarR: createToken("|]"),
  986. braceL: createToken("{", {
  987. beforeExpr,
  988. startsExpr
  989. }),
  990. braceBarL: createToken("{|", {
  991. beforeExpr,
  992. startsExpr
  993. }),
  994. braceHashL: createToken("#{", {
  995. beforeExpr,
  996. startsExpr
  997. }),
  998. braceR: createToken("}"),
  999. braceBarR: createToken("|}"),
  1000. parenL: createToken("(", {
  1001. beforeExpr,
  1002. startsExpr
  1003. }),
  1004. parenR: createToken(")"),
  1005. comma: createToken(",", {
  1006. beforeExpr
  1007. }),
  1008. semi: createToken(";", {
  1009. beforeExpr
  1010. }),
  1011. colon: createToken(":", {
  1012. beforeExpr
  1013. }),
  1014. doubleColon: createToken("::", {
  1015. beforeExpr
  1016. }),
  1017. dot: createToken("."),
  1018. question: createToken("?", {
  1019. beforeExpr
  1020. }),
  1021. questionDot: createToken("?."),
  1022. arrow: createToken("=>", {
  1023. beforeExpr
  1024. }),
  1025. template: createToken("template"),
  1026. ellipsis: createToken("...", {
  1027. beforeExpr
  1028. }),
  1029. backQuote: createToken("`", {
  1030. startsExpr
  1031. }),
  1032. dollarBraceL: createToken("${", {
  1033. beforeExpr,
  1034. startsExpr
  1035. }),
  1036. templateTail: createToken("...`", {
  1037. startsExpr
  1038. }),
  1039. templateNonTail: createToken("...${", {
  1040. beforeExpr,
  1041. startsExpr
  1042. }),
  1043. at: createToken("@"),
  1044. hash: createToken("#", {
  1045. startsExpr
  1046. }),
  1047. interpreterDirective: createToken("#!..."),
  1048. eq: createToken("=", {
  1049. beforeExpr,
  1050. isAssign
  1051. }),
  1052. assign: createToken("_=", {
  1053. beforeExpr,
  1054. isAssign
  1055. }),
  1056. slashAssign: createToken("_=", {
  1057. beforeExpr,
  1058. isAssign
  1059. }),
  1060. xorAssign: createToken("_=", {
  1061. beforeExpr,
  1062. isAssign
  1063. }),
  1064. moduloAssign: createToken("_=", {
  1065. beforeExpr,
  1066. isAssign
  1067. }),
  1068. incDec: createToken("++/--", {
  1069. prefix,
  1070. postfix,
  1071. startsExpr
  1072. }),
  1073. bang: createToken("!", {
  1074. beforeExpr,
  1075. prefix,
  1076. startsExpr
  1077. }),
  1078. tilde: createToken("~", {
  1079. beforeExpr,
  1080. prefix,
  1081. startsExpr
  1082. }),
  1083. doubleCaret: createToken("^^", {
  1084. startsExpr
  1085. }),
  1086. doubleAt: createToken("@@", {
  1087. startsExpr
  1088. }),
  1089. pipeline: createBinop("|>", 0),
  1090. nullishCoalescing: createBinop("??", 1),
  1091. logicalOR: createBinop("||", 1),
  1092. logicalAND: createBinop("&&", 2),
  1093. bitwiseOR: createBinop("|", 3),
  1094. bitwiseXOR: createBinop("^", 4),
  1095. bitwiseAND: createBinop("&", 5),
  1096. equality: createBinop("==/!=/===/!==", 6),
  1097. lt: createBinop("</>/<=/>=", 7),
  1098. gt: createBinop("</>/<=/>=", 7),
  1099. relational: createBinop("</>/<=/>=", 7),
  1100. bitShift: createBinop("<</>>/>>>", 8),
  1101. bitShiftL: createBinop("<</>>/>>>", 8),
  1102. bitShiftR: createBinop("<</>>/>>>", 8),
  1103. plusMin: createToken("+/-", {
  1104. beforeExpr,
  1105. binop: 9,
  1106. prefix,
  1107. startsExpr
  1108. }),
  1109. modulo: createToken("%", {
  1110. binop: 10,
  1111. startsExpr
  1112. }),
  1113. star: createToken("*", {
  1114. binop: 10
  1115. }),
  1116. slash: createBinop("/", 10),
  1117. exponent: createToken("**", {
  1118. beforeExpr,
  1119. binop: 11,
  1120. rightAssociative: true
  1121. }),
  1122. _in: createKeyword("in", {
  1123. beforeExpr,
  1124. binop: 7
  1125. }),
  1126. _instanceof: createKeyword("instanceof", {
  1127. beforeExpr,
  1128. binop: 7
  1129. }),
  1130. _break: createKeyword("break"),
  1131. _case: createKeyword("case", {
  1132. beforeExpr
  1133. }),
  1134. _catch: createKeyword("catch"),
  1135. _continue: createKeyword("continue"),
  1136. _debugger: createKeyword("debugger"),
  1137. _default: createKeyword("default", {
  1138. beforeExpr
  1139. }),
  1140. _else: createKeyword("else", {
  1141. beforeExpr
  1142. }),
  1143. _finally: createKeyword("finally"),
  1144. _function: createKeyword("function", {
  1145. startsExpr
  1146. }),
  1147. _if: createKeyword("if"),
  1148. _return: createKeyword("return", {
  1149. beforeExpr
  1150. }),
  1151. _switch: createKeyword("switch"),
  1152. _throw: createKeyword("throw", {
  1153. beforeExpr,
  1154. prefix,
  1155. startsExpr
  1156. }),
  1157. _try: createKeyword("try"),
  1158. _var: createKeyword("var"),
  1159. _const: createKeyword("const"),
  1160. _with: createKeyword("with"),
  1161. _new: createKeyword("new", {
  1162. beforeExpr,
  1163. startsExpr
  1164. }),
  1165. _this: createKeyword("this", {
  1166. startsExpr
  1167. }),
  1168. _super: createKeyword("super", {
  1169. startsExpr
  1170. }),
  1171. _class: createKeyword("class", {
  1172. startsExpr
  1173. }),
  1174. _extends: createKeyword("extends", {
  1175. beforeExpr
  1176. }),
  1177. _export: createKeyword("export"),
  1178. _import: createKeyword("import", {
  1179. startsExpr
  1180. }),
  1181. _null: createKeyword("null", {
  1182. startsExpr
  1183. }),
  1184. _true: createKeyword("true", {
  1185. startsExpr
  1186. }),
  1187. _false: createKeyword("false", {
  1188. startsExpr
  1189. }),
  1190. _typeof: createKeyword("typeof", {
  1191. beforeExpr,
  1192. prefix,
  1193. startsExpr
  1194. }),
  1195. _void: createKeyword("void", {
  1196. beforeExpr,
  1197. prefix,
  1198. startsExpr
  1199. }),
  1200. _delete: createKeyword("delete", {
  1201. beforeExpr,
  1202. prefix,
  1203. startsExpr
  1204. }),
  1205. _do: createKeyword("do", {
  1206. isLoop,
  1207. beforeExpr
  1208. }),
  1209. _for: createKeyword("for", {
  1210. isLoop
  1211. }),
  1212. _while: createKeyword("while", {
  1213. isLoop
  1214. }),
  1215. _as: createKeywordLike("as", {
  1216. startsExpr
  1217. }),
  1218. _assert: createKeywordLike("assert", {
  1219. startsExpr
  1220. }),
  1221. _async: createKeywordLike("async", {
  1222. startsExpr
  1223. }),
  1224. _await: createKeywordLike("await", {
  1225. startsExpr
  1226. }),
  1227. _defer: createKeywordLike("defer", {
  1228. startsExpr
  1229. }),
  1230. _from: createKeywordLike("from", {
  1231. startsExpr
  1232. }),
  1233. _get: createKeywordLike("get", {
  1234. startsExpr
  1235. }),
  1236. _let: createKeywordLike("let", {
  1237. startsExpr
  1238. }),
  1239. _meta: createKeywordLike("meta", {
  1240. startsExpr
  1241. }),
  1242. _of: createKeywordLike("of", {
  1243. startsExpr
  1244. }),
  1245. _sent: createKeywordLike("sent", {
  1246. startsExpr
  1247. }),
  1248. _set: createKeywordLike("set", {
  1249. startsExpr
  1250. }),
  1251. _source: createKeywordLike("source", {
  1252. startsExpr
  1253. }),
  1254. _static: createKeywordLike("static", {
  1255. startsExpr
  1256. }),
  1257. _using: createKeywordLike("using", {
  1258. startsExpr
  1259. }),
  1260. _yield: createKeywordLike("yield", {
  1261. startsExpr
  1262. }),
  1263. _asserts: createKeywordLike("asserts", {
  1264. startsExpr
  1265. }),
  1266. _checks: createKeywordLike("checks", {
  1267. startsExpr
  1268. }),
  1269. _exports: createKeywordLike("exports", {
  1270. startsExpr
  1271. }),
  1272. _global: createKeywordLike("global", {
  1273. startsExpr
  1274. }),
  1275. _implements: createKeywordLike("implements", {
  1276. startsExpr
  1277. }),
  1278. _intrinsic: createKeywordLike("intrinsic", {
  1279. startsExpr
  1280. }),
  1281. _infer: createKeywordLike("infer", {
  1282. startsExpr
  1283. }),
  1284. _is: createKeywordLike("is", {
  1285. startsExpr
  1286. }),
  1287. _mixins: createKeywordLike("mixins", {
  1288. startsExpr
  1289. }),
  1290. _proto: createKeywordLike("proto", {
  1291. startsExpr
  1292. }),
  1293. _require: createKeywordLike("require", {
  1294. startsExpr
  1295. }),
  1296. _satisfies: createKeywordLike("satisfies", {
  1297. startsExpr
  1298. }),
  1299. _keyof: createKeywordLike("keyof", {
  1300. startsExpr
  1301. }),
  1302. _readonly: createKeywordLike("readonly", {
  1303. startsExpr
  1304. }),
  1305. _unique: createKeywordLike("unique", {
  1306. startsExpr
  1307. }),
  1308. _abstract: createKeywordLike("abstract", {
  1309. startsExpr
  1310. }),
  1311. _declare: createKeywordLike("declare", {
  1312. startsExpr
  1313. }),
  1314. _enum: createKeywordLike("enum", {
  1315. startsExpr
  1316. }),
  1317. _module: createKeywordLike("module", {
  1318. startsExpr
  1319. }),
  1320. _namespace: createKeywordLike("namespace", {
  1321. startsExpr
  1322. }),
  1323. _interface: createKeywordLike("interface", {
  1324. startsExpr
  1325. }),
  1326. _type: createKeywordLike("type", {
  1327. startsExpr
  1328. }),
  1329. _opaque: createKeywordLike("opaque", {
  1330. startsExpr
  1331. }),
  1332. name: createToken("name", {
  1333. startsExpr
  1334. }),
  1335. placeholder: createToken("%%", {
  1336. startsExpr
  1337. }),
  1338. string: createToken("string", {
  1339. startsExpr
  1340. }),
  1341. num: createToken("num", {
  1342. startsExpr
  1343. }),
  1344. bigint: createToken("bigint", {
  1345. startsExpr
  1346. }),
  1347. decimal: createToken("decimal", {
  1348. startsExpr
  1349. }),
  1350. regexp: createToken("regexp", {
  1351. startsExpr
  1352. }),
  1353. privateName: createToken("#name", {
  1354. startsExpr
  1355. }),
  1356. eof: createToken("eof"),
  1357. jsxName: createToken("jsxName"),
  1358. jsxText: createToken("jsxText", {
  1359. beforeExpr
  1360. }),
  1361. jsxTagStart: createToken("jsxTagStart", {
  1362. startsExpr
  1363. }),
  1364. jsxTagEnd: createToken("jsxTagEnd")
  1365. };
  1366. function tokenIsIdentifier(token) {
  1367. return token >= 93 && token <= 133;
  1368. }
  1369. function tokenKeywordOrIdentifierIsKeyword(token) {
  1370. return token <= 92;
  1371. }
  1372. function tokenIsKeywordOrIdentifier(token) {
  1373. return token >= 58 && token <= 133;
  1374. }
  1375. function tokenIsLiteralPropertyName(token) {
  1376. return token >= 58 && token <= 137;
  1377. }
  1378. function tokenComesBeforeExpression(token) {
  1379. return tokenBeforeExprs[token];
  1380. }
  1381. function tokenCanStartExpression(token) {
  1382. return tokenStartsExprs[token];
  1383. }
  1384. function tokenIsAssignment(token) {
  1385. return token >= 29 && token <= 33;
  1386. }
  1387. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1388. return token >= 129 && token <= 131;
  1389. }
  1390. function tokenIsLoop(token) {
  1391. return token >= 90 && token <= 92;
  1392. }
  1393. function tokenIsKeyword(token) {
  1394. return token >= 58 && token <= 92;
  1395. }
  1396. function tokenIsOperator(token) {
  1397. return token >= 39 && token <= 59;
  1398. }
  1399. function tokenIsPostfix(token) {
  1400. return token === 34;
  1401. }
  1402. function tokenIsPrefix(token) {
  1403. return tokenPrefixes[token];
  1404. }
  1405. function tokenIsTSTypeOperator(token) {
  1406. return token >= 121 && token <= 123;
  1407. }
  1408. function tokenIsTSDeclarationStart(token) {
  1409. return token >= 124 && token <= 130;
  1410. }
  1411. function tokenLabelName(token) {
  1412. return tokenLabels[token];
  1413. }
  1414. function tokenOperatorPrecedence(token) {
  1415. return tokenBinops[token];
  1416. }
  1417. function tokenIsRightAssociative(token) {
  1418. return token === 57;
  1419. }
  1420. function tokenIsTemplate(token) {
  1421. return token >= 24 && token <= 25;
  1422. }
  1423. function getExportedToken(token) {
  1424. return tokenTypes[token];
  1425. }
  1426. tokenTypes[8].updateContext = context => {
  1427. context.pop();
  1428. };
  1429. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1430. context.push(types.brace);
  1431. };
  1432. tokenTypes[22].updateContext = context => {
  1433. if (context[context.length - 1] === types.template) {
  1434. context.pop();
  1435. } else {
  1436. context.push(types.template);
  1437. }
  1438. };
  1439. tokenTypes[143].updateContext = context => {
  1440. context.push(types.j_expr, types.j_oTag);
  1441. };
  1442. let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088f\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5c\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdc-\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7dc\ua7f1-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  1443. let nonASCIIidentifierChars = "\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1add\u1ae0-\u1aeb\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
  1444. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1445. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1446. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1447. const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 7, 25, 39, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 57, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 261, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489];
  1448. const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 78, 5, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1449. function isInAstralSet(code, set) {
  1450. let pos = 0x10000;
  1451. for (let i = 0, length = set.length; i < length; i += 2) {
  1452. pos += set[i];
  1453. if (pos > code) return false;
  1454. pos += set[i + 1];
  1455. if (pos >= code) return true;
  1456. }
  1457. return false;
  1458. }
  1459. function isIdentifierStart(code) {
  1460. if (code < 65) return code === 36;
  1461. if (code <= 90) return true;
  1462. if (code < 97) return code === 95;
  1463. if (code <= 122) return true;
  1464. if (code <= 0xffff) {
  1465. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1466. }
  1467. return isInAstralSet(code, astralIdentifierStartCodes);
  1468. }
  1469. function isIdentifierChar(code) {
  1470. if (code < 48) return code === 36;
  1471. if (code < 58) return true;
  1472. if (code < 65) return false;
  1473. if (code <= 90) return true;
  1474. if (code < 97) return code === 95;
  1475. if (code <= 122) return true;
  1476. if (code <= 0xffff) {
  1477. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1478. }
  1479. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1480. }
  1481. const reservedWords = {
  1482. 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"],
  1483. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1484. strictBind: ["eval", "arguments"]
  1485. };
  1486. const keywords = new Set(reservedWords.keyword);
  1487. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1488. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1489. function isReservedWord(word, inModule) {
  1490. return inModule && word === "await" || word === "enum";
  1491. }
  1492. function isStrictReservedWord(word, inModule) {
  1493. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1494. }
  1495. function isStrictBindOnlyReservedWord(word) {
  1496. return reservedWordsStrictBindSet.has(word);
  1497. }
  1498. function isStrictBindReservedWord(word, inModule) {
  1499. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1500. }
  1501. function isKeyword(word) {
  1502. return keywords.has(word);
  1503. }
  1504. function isIteratorStart(current, next, next2) {
  1505. return current === 64 && next === 64 && isIdentifierStart(next2);
  1506. }
  1507. 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"]);
  1508. function canBeReservedWord(word) {
  1509. return reservedWordLikeSet.has(word);
  1510. }
  1511. class Scope {
  1512. constructor(flags) {
  1513. this.flags = 0;
  1514. this.names = new Map();
  1515. this.firstLexicalName = "";
  1516. this.flags = flags;
  1517. }
  1518. }
  1519. class ScopeHandler {
  1520. constructor(parser, inModule) {
  1521. this.parser = void 0;
  1522. this.scopeStack = [];
  1523. this.inModule = void 0;
  1524. this.undefinedExports = new Map();
  1525. this.parser = parser;
  1526. this.inModule = inModule;
  1527. }
  1528. get inTopLevel() {
  1529. return (this.currentScope().flags & 1) > 0;
  1530. }
  1531. get inFunction() {
  1532. return (this.currentVarScopeFlags() & 2) > 0;
  1533. }
  1534. get allowSuper() {
  1535. return (this.currentThisScopeFlags() & 16) > 0;
  1536. }
  1537. get allowDirectSuper() {
  1538. return (this.currentThisScopeFlags() & 32) > 0;
  1539. }
  1540. get allowNewTarget() {
  1541. return (this.currentThisScopeFlags() & 512) > 0;
  1542. }
  1543. get inClass() {
  1544. return (this.currentThisScopeFlags() & 64) > 0;
  1545. }
  1546. get inClassAndNotInNonArrowFunction() {
  1547. const flags = this.currentThisScopeFlags();
  1548. return (flags & 64) > 0 && (flags & 2) === 0;
  1549. }
  1550. get inStaticBlock() {
  1551. for (let i = this.scopeStack.length - 1;; i--) {
  1552. const {
  1553. flags
  1554. } = this.scopeStack[i];
  1555. if (flags & 128) {
  1556. return true;
  1557. }
  1558. if (flags & (1667 | 64)) {
  1559. return false;
  1560. }
  1561. }
  1562. }
  1563. get inNonArrowFunction() {
  1564. return (this.currentThisScopeFlags() & 2) > 0;
  1565. }
  1566. get inBareCaseStatement() {
  1567. return (this.currentScope().flags & 256) > 0;
  1568. }
  1569. get treatFunctionsAsVar() {
  1570. return this.treatFunctionsAsVarInScope(this.currentScope());
  1571. }
  1572. createScope(flags) {
  1573. return new Scope(flags);
  1574. }
  1575. enter(flags) {
  1576. this.scopeStack.push(this.createScope(flags));
  1577. }
  1578. exit() {
  1579. const scope = this.scopeStack.pop();
  1580. return scope.flags;
  1581. }
  1582. treatFunctionsAsVarInScope(scope) {
  1583. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1584. }
  1585. declareName(name, bindingType, loc) {
  1586. let scope = this.currentScope();
  1587. if (bindingType & 8 || bindingType & 16) {
  1588. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1589. let type = scope.names.get(name) || 0;
  1590. if (bindingType & 16) {
  1591. type = type | 4;
  1592. } else {
  1593. if (!scope.firstLexicalName) {
  1594. scope.firstLexicalName = name;
  1595. }
  1596. type = type | 2;
  1597. }
  1598. scope.names.set(name, type);
  1599. if (bindingType & 8) {
  1600. this.maybeExportDefined(scope, name);
  1601. }
  1602. } else if (bindingType & 4) {
  1603. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1604. scope = this.scopeStack[i];
  1605. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1606. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1607. this.maybeExportDefined(scope, name);
  1608. if (scope.flags & 1667) break;
  1609. }
  1610. }
  1611. if (this.parser.inModule && scope.flags & 1) {
  1612. this.undefinedExports.delete(name);
  1613. }
  1614. }
  1615. maybeExportDefined(scope, name) {
  1616. if (this.parser.inModule && scope.flags & 1) {
  1617. this.undefinedExports.delete(name);
  1618. }
  1619. }
  1620. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1621. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1622. this.parser.raise(Errors.VarRedeclaration, loc, {
  1623. identifierName: name
  1624. });
  1625. }
  1626. }
  1627. isRedeclaredInScope(scope, name, bindingType) {
  1628. if (!(bindingType & 1)) return false;
  1629. if (bindingType & 8) {
  1630. return scope.names.has(name);
  1631. }
  1632. const type = scope.names.get(name) || 0;
  1633. if (bindingType & 16) {
  1634. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1635. }
  1636. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1637. }
  1638. checkLocalExport(id) {
  1639. const {
  1640. name
  1641. } = id;
  1642. const topLevelScope = this.scopeStack[0];
  1643. if (!topLevelScope.names.has(name)) {
  1644. this.undefinedExports.set(name, id.loc.start);
  1645. }
  1646. }
  1647. currentScope() {
  1648. return this.scopeStack[this.scopeStack.length - 1];
  1649. }
  1650. currentVarScopeFlags() {
  1651. for (let i = this.scopeStack.length - 1;; i--) {
  1652. const {
  1653. flags
  1654. } = this.scopeStack[i];
  1655. if (flags & 1667) {
  1656. return flags;
  1657. }
  1658. }
  1659. }
  1660. currentThisScopeFlags() {
  1661. for (let i = this.scopeStack.length - 1;; i--) {
  1662. const {
  1663. flags
  1664. } = this.scopeStack[i];
  1665. if (flags & (1667 | 64) && !(flags & 4)) {
  1666. return flags;
  1667. }
  1668. }
  1669. }
  1670. }
  1671. class FlowScope extends Scope {
  1672. constructor(...args) {
  1673. super(...args);
  1674. this.declareFunctions = new Set();
  1675. }
  1676. }
  1677. class FlowScopeHandler extends ScopeHandler {
  1678. createScope(flags) {
  1679. return new FlowScope(flags);
  1680. }
  1681. declareName(name, bindingType, loc) {
  1682. const scope = this.currentScope();
  1683. if (bindingType & 2048) {
  1684. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1685. this.maybeExportDefined(scope, name);
  1686. scope.declareFunctions.add(name);
  1687. return;
  1688. }
  1689. super.declareName(name, bindingType, loc);
  1690. }
  1691. isRedeclaredInScope(scope, name, bindingType) {
  1692. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1693. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1694. const type = scope.names.get(name);
  1695. return (type & 4) > 0 || (type & 2) > 0;
  1696. }
  1697. return false;
  1698. }
  1699. checkLocalExport(id) {
  1700. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1701. super.checkLocalExport(id);
  1702. }
  1703. }
  1704. }
  1705. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  1706. const FlowErrors = ParseErrorEnum`flow`({
  1707. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  1708. 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.",
  1709. AssignReservedType: ({
  1710. reservedType
  1711. }) => `Cannot overwrite reserved type ${reservedType}.`,
  1712. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  1713. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  1714. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  1715. EnumBooleanMemberNotInitialized: ({
  1716. memberName,
  1717. enumName
  1718. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  1719. EnumDuplicateMemberName: ({
  1720. memberName,
  1721. enumName
  1722. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  1723. EnumInconsistentMemberValues: ({
  1724. enumName
  1725. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  1726. EnumInvalidExplicitType: ({
  1727. invalidEnumType,
  1728. enumName
  1729. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1730. EnumInvalidExplicitTypeUnknownSupplied: ({
  1731. enumName
  1732. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1733. EnumInvalidMemberInitializerPrimaryType: ({
  1734. enumName,
  1735. memberName,
  1736. explicitType
  1737. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  1738. EnumInvalidMemberInitializerSymbolType: ({
  1739. enumName,
  1740. memberName
  1741. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  1742. EnumInvalidMemberInitializerUnknownType: ({
  1743. enumName,
  1744. memberName
  1745. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  1746. EnumInvalidMemberName: ({
  1747. enumName,
  1748. memberName,
  1749. suggestion
  1750. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  1751. EnumNumberMemberNotInitialized: ({
  1752. enumName,
  1753. memberName
  1754. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  1755. EnumStringMemberInconsistentlyInitialized: ({
  1756. enumName
  1757. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  1758. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  1759. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  1760. 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.",
  1761. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  1762. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  1763. InexactVariance: "Explicit inexact syntax cannot have variance.",
  1764. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  1765. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  1766. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  1767. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  1768. PatternIsOptional: Object.assign({
  1769. message: "A binding pattern parameter cannot be optional in an implementation signature."
  1770. }, {
  1771. reasonCode: "OptionalBindingPattern"
  1772. }),
  1773. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  1774. SpreadVariance: "Spread properties cannot have variance.",
  1775. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  1776. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  1777. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  1778. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  1779. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  1780. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  1781. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  1782. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  1783. UnexpectedReservedType: ({
  1784. reservedType
  1785. }) => `Unexpected reserved type ${reservedType}.`,
  1786. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  1787. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  1788. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  1789. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  1790. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  1791. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  1792. UnsupportedDeclareExportKind: ({
  1793. unsupportedExportKind,
  1794. suggestion
  1795. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  1796. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  1797. UnterminatedFlowComment: "Unterminated flow-comment."
  1798. });
  1799. function isEsModuleType(bodyElement) {
  1800. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  1801. }
  1802. function hasTypeImportKind(node) {
  1803. return node.importKind === "type" || node.importKind === "typeof";
  1804. }
  1805. const exportSuggestions = {
  1806. const: "declare export var",
  1807. let: "declare export var",
  1808. type: "export type",
  1809. interface: "export interface"
  1810. };
  1811. function partition(list, test) {
  1812. const list1 = [];
  1813. const list2 = [];
  1814. for (let i = 0; i < list.length; i++) {
  1815. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  1816. }
  1817. return [list1, list2];
  1818. }
  1819. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  1820. var flow = superClass => class FlowParserMixin extends superClass {
  1821. constructor(...args) {
  1822. super(...args);
  1823. this.flowPragma = undefined;
  1824. }
  1825. getScopeHandler() {
  1826. return FlowScopeHandler;
  1827. }
  1828. shouldParseTypes() {
  1829. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  1830. }
  1831. finishToken(type, val) {
  1832. if (type !== 134 && type !== 13 && type !== 28) {
  1833. if (this.flowPragma === undefined) {
  1834. this.flowPragma = null;
  1835. }
  1836. }
  1837. super.finishToken(type, val);
  1838. }
  1839. addComment(comment) {
  1840. if (this.flowPragma === undefined) {
  1841. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  1842. if (!matches) ;else if (matches[1] === "flow") {
  1843. this.flowPragma = "flow";
  1844. } else if (matches[1] === "noflow") {
  1845. this.flowPragma = "noflow";
  1846. } else {
  1847. throw new Error("Unexpected flow pragma");
  1848. }
  1849. }
  1850. super.addComment(comment);
  1851. }
  1852. flowParseTypeInitialiser(tok) {
  1853. const oldInType = this.state.inType;
  1854. this.state.inType = true;
  1855. this.expect(tok || 14);
  1856. const type = this.flowParseType();
  1857. this.state.inType = oldInType;
  1858. return type;
  1859. }
  1860. flowParsePredicate() {
  1861. const node = this.startNode();
  1862. const moduloLoc = this.state.startLoc;
  1863. this.next();
  1864. this.expectContextual(110);
  1865. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  1866. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  1867. }
  1868. if (this.eat(10)) {
  1869. node.value = super.parseExpression();
  1870. this.expect(11);
  1871. return this.finishNode(node, "DeclaredPredicate");
  1872. } else {
  1873. return this.finishNode(node, "InferredPredicate");
  1874. }
  1875. }
  1876. flowParseTypeAndPredicateInitialiser() {
  1877. const oldInType = this.state.inType;
  1878. this.state.inType = true;
  1879. this.expect(14);
  1880. let type = null;
  1881. let predicate = null;
  1882. if (this.match(54)) {
  1883. this.state.inType = oldInType;
  1884. predicate = this.flowParsePredicate();
  1885. } else {
  1886. type = this.flowParseType();
  1887. this.state.inType = oldInType;
  1888. if (this.match(54)) {
  1889. predicate = this.flowParsePredicate();
  1890. }
  1891. }
  1892. return [type, predicate];
  1893. }
  1894. flowParseDeclareClass(node) {
  1895. this.next();
  1896. this.flowParseInterfaceish(node, true);
  1897. return this.finishNode(node, "DeclareClass");
  1898. }
  1899. flowParseDeclareFunction(node) {
  1900. this.next();
  1901. const id = node.id = this.parseIdentifier();
  1902. const typeNode = this.startNode();
  1903. const typeContainer = this.startNode();
  1904. if (this.match(47)) {
  1905. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  1906. } else {
  1907. typeNode.typeParameters = null;
  1908. }
  1909. this.expect(10);
  1910. const tmp = this.flowParseFunctionTypeParams();
  1911. typeNode.params = tmp.params;
  1912. typeNode.rest = tmp.rest;
  1913. typeNode.this = tmp._this;
  1914. this.expect(11);
  1915. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  1916. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  1917. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  1918. this.resetEndLocation(id);
  1919. this.semicolon();
  1920. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  1921. return this.finishNode(node, "DeclareFunction");
  1922. }
  1923. flowParseDeclare(node, insideModule) {
  1924. if (this.match(80)) {
  1925. return this.flowParseDeclareClass(node);
  1926. } else if (this.match(68)) {
  1927. return this.flowParseDeclareFunction(node);
  1928. } else if (this.match(74)) {
  1929. return this.flowParseDeclareVariable(node);
  1930. } else if (this.eatContextual(127)) {
  1931. if (this.match(16)) {
  1932. return this.flowParseDeclareModuleExports(node);
  1933. } else {
  1934. if (insideModule) {
  1935. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  1936. }
  1937. return this.flowParseDeclareModule(node);
  1938. }
  1939. } else if (this.isContextual(130)) {
  1940. return this.flowParseDeclareTypeAlias(node);
  1941. } else if (this.isContextual(131)) {
  1942. return this.flowParseDeclareOpaqueType(node);
  1943. } else if (this.isContextual(129)) {
  1944. return this.flowParseDeclareInterface(node);
  1945. } else if (this.match(82)) {
  1946. return this.flowParseDeclareExportDeclaration(node, insideModule);
  1947. }
  1948. throw this.unexpected();
  1949. }
  1950. flowParseDeclareVariable(node) {
  1951. this.next();
  1952. node.id = this.flowParseTypeAnnotatableIdentifier();
  1953. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  1954. this.semicolon();
  1955. return this.finishNode(node, "DeclareVariable");
  1956. }
  1957. flowParseDeclareModule(node) {
  1958. this.scope.enter(0);
  1959. if (this.match(134)) {
  1960. node.id = super.parseExprAtom();
  1961. } else {
  1962. node.id = this.parseIdentifier();
  1963. }
  1964. const bodyNode = node.body = this.startNode();
  1965. const body = bodyNode.body = [];
  1966. this.expect(5);
  1967. while (!this.match(8)) {
  1968. const bodyNode = this.startNode();
  1969. if (this.match(83)) {
  1970. this.next();
  1971. if (!this.isContextual(130) && !this.match(87)) {
  1972. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  1973. }
  1974. body.push(super.parseImport(bodyNode));
  1975. } else {
  1976. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  1977. body.push(this.flowParseDeclare(bodyNode, true));
  1978. }
  1979. }
  1980. this.scope.exit();
  1981. this.expect(8);
  1982. this.finishNode(bodyNode, "BlockStatement");
  1983. let kind = null;
  1984. let hasModuleExport = false;
  1985. body.forEach(bodyElement => {
  1986. if (isEsModuleType(bodyElement)) {
  1987. if (kind === "CommonJS") {
  1988. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  1989. }
  1990. kind = "ES";
  1991. } else if (bodyElement.type === "DeclareModuleExports") {
  1992. if (hasModuleExport) {
  1993. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  1994. }
  1995. if (kind === "ES") {
  1996. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  1997. }
  1998. kind = "CommonJS";
  1999. hasModuleExport = true;
  2000. }
  2001. });
  2002. node.kind = kind || "CommonJS";
  2003. return this.finishNode(node, "DeclareModule");
  2004. }
  2005. flowParseDeclareExportDeclaration(node, insideModule) {
  2006. this.expect(82);
  2007. if (this.eat(65)) {
  2008. if (this.match(68) || this.match(80)) {
  2009. node.declaration = this.flowParseDeclare(this.startNode());
  2010. } else {
  2011. node.declaration = this.flowParseType();
  2012. this.semicolon();
  2013. }
  2014. node.default = true;
  2015. return this.finishNode(node, "DeclareExportDeclaration");
  2016. } else {
  2017. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  2018. const label = this.state.value;
  2019. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  2020. unsupportedExportKind: label,
  2021. suggestion: exportSuggestions[label]
  2022. });
  2023. }
  2024. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  2025. node.declaration = this.flowParseDeclare(this.startNode());
  2026. node.default = false;
  2027. return this.finishNode(node, "DeclareExportDeclaration");
  2028. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  2029. node = this.parseExport(node, null);
  2030. if (node.type === "ExportNamedDeclaration") {
  2031. node.default = false;
  2032. delete node.exportKind;
  2033. return this.castNodeTo(node, "DeclareExportDeclaration");
  2034. } else {
  2035. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  2036. }
  2037. }
  2038. }
  2039. throw this.unexpected();
  2040. }
  2041. flowParseDeclareModuleExports(node) {
  2042. this.next();
  2043. this.expectContextual(111);
  2044. node.typeAnnotation = this.flowParseTypeAnnotation();
  2045. this.semicolon();
  2046. return this.finishNode(node, "DeclareModuleExports");
  2047. }
  2048. flowParseDeclareTypeAlias(node) {
  2049. this.next();
  2050. const finished = this.flowParseTypeAlias(node);
  2051. this.castNodeTo(finished, "DeclareTypeAlias");
  2052. return finished;
  2053. }
  2054. flowParseDeclareOpaqueType(node) {
  2055. this.next();
  2056. const finished = this.flowParseOpaqueType(node, true);
  2057. this.castNodeTo(finished, "DeclareOpaqueType");
  2058. return finished;
  2059. }
  2060. flowParseDeclareInterface(node) {
  2061. this.next();
  2062. this.flowParseInterfaceish(node, false);
  2063. return this.finishNode(node, "DeclareInterface");
  2064. }
  2065. flowParseInterfaceish(node, isClass) {
  2066. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  2067. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  2068. if (this.match(47)) {
  2069. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2070. } else {
  2071. node.typeParameters = null;
  2072. }
  2073. node.extends = [];
  2074. if (this.eat(81)) {
  2075. do {
  2076. node.extends.push(this.flowParseInterfaceExtends());
  2077. } while (!isClass && this.eat(12));
  2078. }
  2079. if (isClass) {
  2080. node.implements = [];
  2081. node.mixins = [];
  2082. if (this.eatContextual(117)) {
  2083. do {
  2084. node.mixins.push(this.flowParseInterfaceExtends());
  2085. } while (this.eat(12));
  2086. }
  2087. if (this.eatContextual(113)) {
  2088. do {
  2089. node.implements.push(this.flowParseInterfaceExtends());
  2090. } while (this.eat(12));
  2091. }
  2092. }
  2093. node.body = this.flowParseObjectType({
  2094. allowStatic: isClass,
  2095. allowExact: false,
  2096. allowSpread: false,
  2097. allowProto: isClass,
  2098. allowInexact: false
  2099. });
  2100. }
  2101. flowParseInterfaceExtends() {
  2102. const node = this.startNode();
  2103. node.id = this.flowParseQualifiedTypeIdentifier();
  2104. if (this.match(47)) {
  2105. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2106. } else {
  2107. node.typeParameters = null;
  2108. }
  2109. return this.finishNode(node, "InterfaceExtends");
  2110. }
  2111. flowParseInterface(node) {
  2112. this.flowParseInterfaceish(node, false);
  2113. return this.finishNode(node, "InterfaceDeclaration");
  2114. }
  2115. checkNotUnderscore(word) {
  2116. if (word === "_") {
  2117. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  2118. }
  2119. }
  2120. checkReservedType(word, startLoc, declaration) {
  2121. if (!reservedTypes.has(word)) return;
  2122. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  2123. reservedType: word
  2124. });
  2125. }
  2126. flowParseRestrictedIdentifierName(liberal, declaration) {
  2127. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  2128. return this.parseIdentifierName(liberal);
  2129. }
  2130. flowParseRestrictedIdentifier(liberal, declaration) {
  2131. const node = this.startNode();
  2132. const name = this.flowParseRestrictedIdentifierName(liberal, declaration);
  2133. return this.createIdentifier(node, name);
  2134. }
  2135. flowParseTypeAlias(node) {
  2136. node.id = this.flowParseRestrictedIdentifier(false, true);
  2137. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2138. if (this.match(47)) {
  2139. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2140. } else {
  2141. node.typeParameters = null;
  2142. }
  2143. node.right = this.flowParseTypeInitialiser(29);
  2144. this.semicolon();
  2145. return this.finishNode(node, "TypeAlias");
  2146. }
  2147. flowParseOpaqueType(node, declare) {
  2148. this.expectContextual(130);
  2149. node.id = this.flowParseRestrictedIdentifier(true, true);
  2150. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2151. if (this.match(47)) {
  2152. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2153. } else {
  2154. node.typeParameters = null;
  2155. }
  2156. node.supertype = null;
  2157. if (this.match(14)) {
  2158. node.supertype = this.flowParseTypeInitialiser(14);
  2159. }
  2160. node.impltype = null;
  2161. if (!declare) {
  2162. node.impltype = this.flowParseTypeInitialiser(29);
  2163. }
  2164. this.semicolon();
  2165. return this.finishNode(node, "OpaqueType");
  2166. }
  2167. flowParseTypeParameterBound() {
  2168. if (this.match(14) || this.isContextual(81)) {
  2169. const node = this.startNode();
  2170. this.next();
  2171. node.typeAnnotation = this.flowParseType();
  2172. return this.finishNode(node, "TypeAnnotation");
  2173. }
  2174. }
  2175. flowParseTypeParameter(requireDefault = false) {
  2176. const nodeStartLoc = this.state.startLoc;
  2177. const node = this.startNode();
  2178. const variance = this.flowParseVariance();
  2179. node.name = this.flowParseRestrictedIdentifierName();
  2180. node.variance = variance;
  2181. node.bound = this.flowParseTypeParameterBound();
  2182. if (this.match(29)) {
  2183. this.eat(29);
  2184. node.default = this.flowParseType();
  2185. } else {
  2186. if (requireDefault) {
  2187. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  2188. }
  2189. }
  2190. return this.finishNode(node, "TypeParameter");
  2191. }
  2192. flowParseTypeParameterDeclaration() {
  2193. const oldInType = this.state.inType;
  2194. const node = this.startNode();
  2195. node.params = [];
  2196. this.state.inType = true;
  2197. if (this.match(47) || this.match(143)) {
  2198. this.next();
  2199. } else {
  2200. this.unexpected();
  2201. }
  2202. let defaultRequired = false;
  2203. do {
  2204. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  2205. node.params.push(typeParameter);
  2206. if (typeParameter.default) {
  2207. defaultRequired = true;
  2208. }
  2209. if (!this.match(48)) {
  2210. this.expect(12);
  2211. }
  2212. } while (!this.match(48));
  2213. this.expect(48);
  2214. this.state.inType = oldInType;
  2215. return this.finishNode(node, "TypeParameterDeclaration");
  2216. }
  2217. flowInTopLevelContext(cb) {
  2218. if (this.curContext() !== types.brace) {
  2219. const oldContext = this.state.context;
  2220. this.state.context = [oldContext[0]];
  2221. try {
  2222. return cb();
  2223. } finally {
  2224. this.state.context = oldContext;
  2225. }
  2226. } else {
  2227. return cb();
  2228. }
  2229. }
  2230. flowParseTypeParameterInstantiationInExpression() {
  2231. if (this.reScan_lt() !== 47) return;
  2232. return this.flowParseTypeParameterInstantiation();
  2233. }
  2234. flowParseTypeParameterInstantiation() {
  2235. const node = this.startNode();
  2236. const oldInType = this.state.inType;
  2237. this.state.inType = true;
  2238. node.params = [];
  2239. this.flowInTopLevelContext(() => {
  2240. this.expect(47);
  2241. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2242. this.state.noAnonFunctionType = false;
  2243. while (!this.match(48)) {
  2244. node.params.push(this.flowParseType());
  2245. if (!this.match(48)) {
  2246. this.expect(12);
  2247. }
  2248. }
  2249. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2250. });
  2251. this.state.inType = oldInType;
  2252. if (!this.state.inType && this.curContext() === types.brace) {
  2253. this.reScan_lt_gt();
  2254. }
  2255. this.expect(48);
  2256. return this.finishNode(node, "TypeParameterInstantiation");
  2257. }
  2258. flowParseTypeParameterInstantiationCallOrNew() {
  2259. if (this.reScan_lt() !== 47) return null;
  2260. const node = this.startNode();
  2261. const oldInType = this.state.inType;
  2262. node.params = [];
  2263. this.state.inType = true;
  2264. this.expect(47);
  2265. while (!this.match(48)) {
  2266. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  2267. if (!this.match(48)) {
  2268. this.expect(12);
  2269. }
  2270. }
  2271. this.expect(48);
  2272. this.state.inType = oldInType;
  2273. return this.finishNode(node, "TypeParameterInstantiation");
  2274. }
  2275. flowParseInterfaceType() {
  2276. const node = this.startNode();
  2277. this.expectContextual(129);
  2278. node.extends = [];
  2279. if (this.eat(81)) {
  2280. do {
  2281. node.extends.push(this.flowParseInterfaceExtends());
  2282. } while (this.eat(12));
  2283. }
  2284. node.body = this.flowParseObjectType({
  2285. allowStatic: false,
  2286. allowExact: false,
  2287. allowSpread: false,
  2288. allowProto: false,
  2289. allowInexact: false
  2290. });
  2291. return this.finishNode(node, "InterfaceTypeAnnotation");
  2292. }
  2293. flowParseObjectPropertyKey() {
  2294. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  2295. }
  2296. flowParseObjectTypeIndexer(node, isStatic, variance) {
  2297. node.static = isStatic;
  2298. if (this.lookahead().type === 14) {
  2299. node.id = this.flowParseObjectPropertyKey();
  2300. node.key = this.flowParseTypeInitialiser();
  2301. } else {
  2302. node.id = null;
  2303. node.key = this.flowParseType();
  2304. }
  2305. this.expect(3);
  2306. node.value = this.flowParseTypeInitialiser();
  2307. node.variance = variance;
  2308. return this.finishNode(node, "ObjectTypeIndexer");
  2309. }
  2310. flowParseObjectTypeInternalSlot(node, isStatic) {
  2311. node.static = isStatic;
  2312. node.id = this.flowParseObjectPropertyKey();
  2313. this.expect(3);
  2314. this.expect(3);
  2315. if (this.match(47) || this.match(10)) {
  2316. node.method = true;
  2317. node.optional = false;
  2318. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2319. } else {
  2320. node.method = false;
  2321. if (this.eat(17)) {
  2322. node.optional = true;
  2323. }
  2324. node.value = this.flowParseTypeInitialiser();
  2325. }
  2326. return this.finishNode(node, "ObjectTypeInternalSlot");
  2327. }
  2328. flowParseObjectTypeMethodish(node) {
  2329. node.params = [];
  2330. node.rest = null;
  2331. node.typeParameters = null;
  2332. node.this = null;
  2333. if (this.match(47)) {
  2334. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2335. }
  2336. this.expect(10);
  2337. if (this.match(78)) {
  2338. node.this = this.flowParseFunctionTypeParam(true);
  2339. node.this.name = null;
  2340. if (!this.match(11)) {
  2341. this.expect(12);
  2342. }
  2343. }
  2344. while (!this.match(11) && !this.match(21)) {
  2345. node.params.push(this.flowParseFunctionTypeParam(false));
  2346. if (!this.match(11)) {
  2347. this.expect(12);
  2348. }
  2349. }
  2350. if (this.eat(21)) {
  2351. node.rest = this.flowParseFunctionTypeParam(false);
  2352. }
  2353. this.expect(11);
  2354. node.returnType = this.flowParseTypeInitialiser();
  2355. return this.finishNode(node, "FunctionTypeAnnotation");
  2356. }
  2357. flowParseObjectTypeCallProperty(node, isStatic) {
  2358. const valueNode = this.startNode();
  2359. node.static = isStatic;
  2360. node.value = this.flowParseObjectTypeMethodish(valueNode);
  2361. return this.finishNode(node, "ObjectTypeCallProperty");
  2362. }
  2363. flowParseObjectType({
  2364. allowStatic,
  2365. allowExact,
  2366. allowSpread,
  2367. allowProto,
  2368. allowInexact
  2369. }) {
  2370. const oldInType = this.state.inType;
  2371. this.state.inType = true;
  2372. const nodeStart = this.startNode();
  2373. nodeStart.callProperties = [];
  2374. nodeStart.properties = [];
  2375. nodeStart.indexers = [];
  2376. nodeStart.internalSlots = [];
  2377. let endDelim;
  2378. let exact;
  2379. let inexact = false;
  2380. if (allowExact && this.match(6)) {
  2381. this.expect(6);
  2382. endDelim = 9;
  2383. exact = true;
  2384. } else {
  2385. this.expect(5);
  2386. endDelim = 8;
  2387. exact = false;
  2388. }
  2389. nodeStart.exact = exact;
  2390. while (!this.match(endDelim)) {
  2391. let isStatic = false;
  2392. let protoStartLoc = null;
  2393. let inexactStartLoc = null;
  2394. const node = this.startNode();
  2395. if (allowProto && this.isContextual(118)) {
  2396. const lookahead = this.lookahead();
  2397. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2398. this.next();
  2399. protoStartLoc = this.state.startLoc;
  2400. allowStatic = false;
  2401. }
  2402. }
  2403. if (allowStatic && this.isContextual(106)) {
  2404. const lookahead = this.lookahead();
  2405. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2406. this.next();
  2407. isStatic = true;
  2408. }
  2409. }
  2410. const variance = this.flowParseVariance();
  2411. if (this.eat(0)) {
  2412. if (protoStartLoc != null) {
  2413. this.unexpected(protoStartLoc);
  2414. }
  2415. if (this.eat(0)) {
  2416. if (variance) {
  2417. this.unexpected(variance.loc.start);
  2418. }
  2419. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  2420. } else {
  2421. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  2422. }
  2423. } else if (this.match(10) || this.match(47)) {
  2424. if (protoStartLoc != null) {
  2425. this.unexpected(protoStartLoc);
  2426. }
  2427. if (variance) {
  2428. this.unexpected(variance.loc.start);
  2429. }
  2430. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  2431. } else {
  2432. let kind = "init";
  2433. if (this.isContextual(99) || this.isContextual(104)) {
  2434. const lookahead = this.lookahead();
  2435. if (tokenIsLiteralPropertyName(lookahead.type)) {
  2436. kind = this.state.value;
  2437. this.next();
  2438. }
  2439. }
  2440. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  2441. if (propOrInexact === null) {
  2442. inexact = true;
  2443. inexactStartLoc = this.state.lastTokStartLoc;
  2444. } else {
  2445. nodeStart.properties.push(propOrInexact);
  2446. }
  2447. }
  2448. this.flowObjectTypeSemicolon();
  2449. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  2450. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  2451. }
  2452. }
  2453. this.expect(endDelim);
  2454. if (allowSpread) {
  2455. nodeStart.inexact = inexact;
  2456. }
  2457. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  2458. this.state.inType = oldInType;
  2459. return out;
  2460. }
  2461. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  2462. if (this.eat(21)) {
  2463. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  2464. if (isInexactToken) {
  2465. if (!allowSpread) {
  2466. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  2467. } else if (!allowInexact) {
  2468. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  2469. }
  2470. if (variance) {
  2471. this.raise(FlowErrors.InexactVariance, variance);
  2472. }
  2473. return null;
  2474. }
  2475. if (!allowSpread) {
  2476. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  2477. }
  2478. if (protoStartLoc != null) {
  2479. this.unexpected(protoStartLoc);
  2480. }
  2481. if (variance) {
  2482. this.raise(FlowErrors.SpreadVariance, variance);
  2483. }
  2484. node.argument = this.flowParseType();
  2485. return this.finishNode(node, "ObjectTypeSpreadProperty");
  2486. } else {
  2487. node.key = this.flowParseObjectPropertyKey();
  2488. node.static = isStatic;
  2489. node.proto = protoStartLoc != null;
  2490. node.kind = kind;
  2491. let optional = false;
  2492. if (this.match(47) || this.match(10)) {
  2493. node.method = true;
  2494. if (protoStartLoc != null) {
  2495. this.unexpected(protoStartLoc);
  2496. }
  2497. if (variance) {
  2498. this.unexpected(variance.loc.start);
  2499. }
  2500. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2501. if (kind === "get" || kind === "set") {
  2502. this.flowCheckGetterSetterParams(node);
  2503. }
  2504. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  2505. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  2506. }
  2507. } else {
  2508. if (kind !== "init") this.unexpected();
  2509. node.method = false;
  2510. if (this.eat(17)) {
  2511. optional = true;
  2512. }
  2513. node.value = this.flowParseTypeInitialiser();
  2514. node.variance = variance;
  2515. }
  2516. node.optional = optional;
  2517. return this.finishNode(node, "ObjectTypeProperty");
  2518. }
  2519. }
  2520. flowCheckGetterSetterParams(property) {
  2521. const paramCount = property.kind === "get" ? 0 : 1;
  2522. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  2523. if (property.value.this) {
  2524. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  2525. }
  2526. if (length !== paramCount) {
  2527. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  2528. }
  2529. if (property.kind === "set" && property.value.rest) {
  2530. this.raise(Errors.BadSetterRestParameter, property);
  2531. }
  2532. }
  2533. flowObjectTypeSemicolon() {
  2534. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  2535. this.unexpected();
  2536. }
  2537. }
  2538. flowParseQualifiedTypeIdentifier(startLoc, id) {
  2539. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  2540. let node = id || this.flowParseRestrictedIdentifier(true);
  2541. while (this.eat(16)) {
  2542. const node2 = this.startNodeAt(startLoc);
  2543. node2.qualification = node;
  2544. node2.id = this.flowParseRestrictedIdentifier(true);
  2545. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  2546. }
  2547. return node;
  2548. }
  2549. flowParseGenericType(startLoc, id) {
  2550. const node = this.startNodeAt(startLoc);
  2551. node.typeParameters = null;
  2552. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  2553. if (this.match(47)) {
  2554. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2555. }
  2556. return this.finishNode(node, "GenericTypeAnnotation");
  2557. }
  2558. flowParseTypeofType() {
  2559. const node = this.startNode();
  2560. this.expect(87);
  2561. node.argument = this.flowParsePrimaryType();
  2562. return this.finishNode(node, "TypeofTypeAnnotation");
  2563. }
  2564. flowParseTupleType() {
  2565. const node = this.startNode();
  2566. node.types = [];
  2567. this.expect(0);
  2568. while (this.state.pos < this.length && !this.match(3)) {
  2569. node.types.push(this.flowParseType());
  2570. if (this.match(3)) break;
  2571. this.expect(12);
  2572. }
  2573. this.expect(3);
  2574. return this.finishNode(node, "TupleTypeAnnotation");
  2575. }
  2576. flowParseFunctionTypeParam(first) {
  2577. let name = null;
  2578. let optional = false;
  2579. let typeAnnotation = null;
  2580. const node = this.startNode();
  2581. const lh = this.lookahead();
  2582. const isThis = this.state.type === 78;
  2583. if (lh.type === 14 || lh.type === 17) {
  2584. if (isThis && !first) {
  2585. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  2586. }
  2587. name = this.parseIdentifier(isThis);
  2588. if (this.eat(17)) {
  2589. optional = true;
  2590. if (isThis) {
  2591. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  2592. }
  2593. }
  2594. typeAnnotation = this.flowParseTypeInitialiser();
  2595. } else {
  2596. typeAnnotation = this.flowParseType();
  2597. }
  2598. node.name = name;
  2599. node.optional = optional;
  2600. node.typeAnnotation = typeAnnotation;
  2601. return this.finishNode(node, "FunctionTypeParam");
  2602. }
  2603. reinterpretTypeAsFunctionTypeParam(type) {
  2604. const node = this.startNodeAt(type.loc.start);
  2605. node.name = null;
  2606. node.optional = false;
  2607. node.typeAnnotation = type;
  2608. return this.finishNode(node, "FunctionTypeParam");
  2609. }
  2610. flowParseFunctionTypeParams(params = []) {
  2611. let rest = null;
  2612. let _this = null;
  2613. if (this.match(78)) {
  2614. _this = this.flowParseFunctionTypeParam(true);
  2615. _this.name = null;
  2616. if (!this.match(11)) {
  2617. this.expect(12);
  2618. }
  2619. }
  2620. while (!this.match(11) && !this.match(21)) {
  2621. params.push(this.flowParseFunctionTypeParam(false));
  2622. if (!this.match(11)) {
  2623. this.expect(12);
  2624. }
  2625. }
  2626. if (this.eat(21)) {
  2627. rest = this.flowParseFunctionTypeParam(false);
  2628. }
  2629. return {
  2630. params,
  2631. rest,
  2632. _this
  2633. };
  2634. }
  2635. flowIdentToTypeAnnotation(startLoc, node, id) {
  2636. switch (id.name) {
  2637. case "any":
  2638. return this.finishNode(node, "AnyTypeAnnotation");
  2639. case "bool":
  2640. case "boolean":
  2641. return this.finishNode(node, "BooleanTypeAnnotation");
  2642. case "mixed":
  2643. return this.finishNode(node, "MixedTypeAnnotation");
  2644. case "empty":
  2645. return this.finishNode(node, "EmptyTypeAnnotation");
  2646. case "number":
  2647. return this.finishNode(node, "NumberTypeAnnotation");
  2648. case "string":
  2649. return this.finishNode(node, "StringTypeAnnotation");
  2650. case "symbol":
  2651. return this.finishNode(node, "SymbolTypeAnnotation");
  2652. default:
  2653. this.checkNotUnderscore(id.name);
  2654. return this.flowParseGenericType(startLoc, id);
  2655. }
  2656. }
  2657. flowParsePrimaryType() {
  2658. const startLoc = this.state.startLoc;
  2659. const node = this.startNode();
  2660. let tmp;
  2661. let type;
  2662. let isGroupedType = false;
  2663. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2664. switch (this.state.type) {
  2665. case 5:
  2666. return this.flowParseObjectType({
  2667. allowStatic: false,
  2668. allowExact: false,
  2669. allowSpread: true,
  2670. allowProto: false,
  2671. allowInexact: true
  2672. });
  2673. case 6:
  2674. return this.flowParseObjectType({
  2675. allowStatic: false,
  2676. allowExact: true,
  2677. allowSpread: true,
  2678. allowProto: false,
  2679. allowInexact: false
  2680. });
  2681. case 0:
  2682. this.state.noAnonFunctionType = false;
  2683. type = this.flowParseTupleType();
  2684. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2685. return type;
  2686. case 47:
  2687. {
  2688. const node = this.startNode();
  2689. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2690. this.expect(10);
  2691. tmp = this.flowParseFunctionTypeParams();
  2692. node.params = tmp.params;
  2693. node.rest = tmp.rest;
  2694. node.this = tmp._this;
  2695. this.expect(11);
  2696. this.expect(19);
  2697. node.returnType = this.flowParseType();
  2698. return this.finishNode(node, "FunctionTypeAnnotation");
  2699. }
  2700. case 10:
  2701. {
  2702. const node = this.startNode();
  2703. this.next();
  2704. if (!this.match(11) && !this.match(21)) {
  2705. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  2706. const token = this.lookahead().type;
  2707. isGroupedType = token !== 17 && token !== 14;
  2708. } else {
  2709. isGroupedType = true;
  2710. }
  2711. }
  2712. if (isGroupedType) {
  2713. this.state.noAnonFunctionType = false;
  2714. type = this.flowParseType();
  2715. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2716. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  2717. this.expect(11);
  2718. return type;
  2719. } else {
  2720. this.eat(12);
  2721. }
  2722. }
  2723. if (type) {
  2724. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  2725. } else {
  2726. tmp = this.flowParseFunctionTypeParams();
  2727. }
  2728. node.params = tmp.params;
  2729. node.rest = tmp.rest;
  2730. node.this = tmp._this;
  2731. this.expect(11);
  2732. this.expect(19);
  2733. node.returnType = this.flowParseType();
  2734. node.typeParameters = null;
  2735. return this.finishNode(node, "FunctionTypeAnnotation");
  2736. }
  2737. case 134:
  2738. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  2739. case 85:
  2740. case 86:
  2741. node.value = this.match(85);
  2742. this.next();
  2743. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  2744. case 53:
  2745. if (this.state.value === "-") {
  2746. this.next();
  2747. if (this.match(135)) {
  2748. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  2749. }
  2750. if (this.match(136)) {
  2751. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  2752. }
  2753. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  2754. }
  2755. throw this.unexpected();
  2756. case 135:
  2757. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  2758. case 136:
  2759. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  2760. case 88:
  2761. this.next();
  2762. return this.finishNode(node, "VoidTypeAnnotation");
  2763. case 84:
  2764. this.next();
  2765. return this.finishNode(node, "NullLiteralTypeAnnotation");
  2766. case 78:
  2767. this.next();
  2768. return this.finishNode(node, "ThisTypeAnnotation");
  2769. case 55:
  2770. this.next();
  2771. return this.finishNode(node, "ExistsTypeAnnotation");
  2772. case 87:
  2773. return this.flowParseTypeofType();
  2774. default:
  2775. if (tokenIsKeyword(this.state.type)) {
  2776. const label = tokenLabelName(this.state.type);
  2777. this.next();
  2778. return super.createIdentifier(node, label);
  2779. } else if (tokenIsIdentifier(this.state.type)) {
  2780. if (this.isContextual(129)) {
  2781. return this.flowParseInterfaceType();
  2782. }
  2783. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  2784. }
  2785. }
  2786. throw this.unexpected();
  2787. }
  2788. flowParsePostfixType() {
  2789. const startLoc = this.state.startLoc;
  2790. let type = this.flowParsePrimaryType();
  2791. let seenOptionalIndexedAccess = false;
  2792. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  2793. const node = this.startNodeAt(startLoc);
  2794. const optional = this.eat(18);
  2795. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  2796. this.expect(0);
  2797. if (!optional && this.match(3)) {
  2798. node.elementType = type;
  2799. this.next();
  2800. type = this.finishNode(node, "ArrayTypeAnnotation");
  2801. } else {
  2802. node.objectType = type;
  2803. node.indexType = this.flowParseType();
  2804. this.expect(3);
  2805. if (seenOptionalIndexedAccess) {
  2806. node.optional = optional;
  2807. type = this.finishNode(node, "OptionalIndexedAccessType");
  2808. } else {
  2809. type = this.finishNode(node, "IndexedAccessType");
  2810. }
  2811. }
  2812. }
  2813. return type;
  2814. }
  2815. flowParsePrefixType() {
  2816. const node = this.startNode();
  2817. if (this.eat(17)) {
  2818. node.typeAnnotation = this.flowParsePrefixType();
  2819. return this.finishNode(node, "NullableTypeAnnotation");
  2820. } else {
  2821. return this.flowParsePostfixType();
  2822. }
  2823. }
  2824. flowParseAnonFunctionWithoutParens() {
  2825. const param = this.flowParsePrefixType();
  2826. if (!this.state.noAnonFunctionType && this.eat(19)) {
  2827. const node = this.startNodeAt(param.loc.start);
  2828. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  2829. node.rest = null;
  2830. node.this = null;
  2831. node.returnType = this.flowParseType();
  2832. node.typeParameters = null;
  2833. return this.finishNode(node, "FunctionTypeAnnotation");
  2834. }
  2835. return param;
  2836. }
  2837. flowParseIntersectionType() {
  2838. const node = this.startNode();
  2839. this.eat(45);
  2840. const type = this.flowParseAnonFunctionWithoutParens();
  2841. node.types = [type];
  2842. while (this.eat(45)) {
  2843. node.types.push(this.flowParseAnonFunctionWithoutParens());
  2844. }
  2845. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  2846. }
  2847. flowParseUnionType() {
  2848. const node = this.startNode();
  2849. this.eat(43);
  2850. const type = this.flowParseIntersectionType();
  2851. node.types = [type];
  2852. while (this.eat(43)) {
  2853. node.types.push(this.flowParseIntersectionType());
  2854. }
  2855. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  2856. }
  2857. flowParseType() {
  2858. const oldInType = this.state.inType;
  2859. this.state.inType = true;
  2860. const type = this.flowParseUnionType();
  2861. this.state.inType = oldInType;
  2862. return type;
  2863. }
  2864. flowParseTypeOrImplicitInstantiation() {
  2865. if (this.state.type === 132 && this.state.value === "_") {
  2866. const startLoc = this.state.startLoc;
  2867. const node = this.parseIdentifier();
  2868. return this.flowParseGenericType(startLoc, node);
  2869. } else {
  2870. return this.flowParseType();
  2871. }
  2872. }
  2873. flowParseTypeAnnotation() {
  2874. const node = this.startNode();
  2875. node.typeAnnotation = this.flowParseTypeInitialiser();
  2876. return this.finishNode(node, "TypeAnnotation");
  2877. }
  2878. flowParseTypeAnnotatableIdentifier() {
  2879. const node = this.startNode();
  2880. const name = this.parseIdentifierName();
  2881. if (this.match(14)) {
  2882. node.typeAnnotation = this.flowParseTypeAnnotation();
  2883. }
  2884. return this.createIdentifier(node, name);
  2885. }
  2886. typeCastToParameter(node) {
  2887. node.expression.typeAnnotation = node.typeAnnotation;
  2888. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  2889. return node.expression;
  2890. }
  2891. flowParseVariance() {
  2892. let variance = null;
  2893. if (this.match(53)) {
  2894. variance = this.startNode();
  2895. if (this.state.value === "+") {
  2896. variance.kind = "plus";
  2897. } else {
  2898. variance.kind = "minus";
  2899. }
  2900. this.next();
  2901. return this.finishNode(variance, "Variance");
  2902. }
  2903. return variance;
  2904. }
  2905. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  2906. if (allowExpressionBody) {
  2907. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  2908. return;
  2909. }
  2910. super.parseFunctionBody(node, false, isMethod);
  2911. }
  2912. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  2913. if (this.match(14)) {
  2914. const typeNode = this.startNode();
  2915. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  2916. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  2917. }
  2918. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  2919. }
  2920. parseStatementLike(flags) {
  2921. if (this.state.strict && this.isContextual(129)) {
  2922. const lookahead = this.lookahead();
  2923. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  2924. const node = this.startNode();
  2925. this.next();
  2926. return this.flowParseInterface(node);
  2927. }
  2928. } else if (this.isContextual(126)) {
  2929. const node = this.startNode();
  2930. this.next();
  2931. return this.flowParseEnumDeclaration(node);
  2932. }
  2933. const stmt = super.parseStatementLike(flags);
  2934. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  2935. this.flowPragma = null;
  2936. }
  2937. return stmt;
  2938. }
  2939. parseExpressionStatement(node, expr, decorators) {
  2940. if (expr.type === "Identifier") {
  2941. if (expr.name === "declare") {
  2942. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  2943. return this.flowParseDeclare(node);
  2944. }
  2945. } else if (tokenIsIdentifier(this.state.type)) {
  2946. if (expr.name === "interface") {
  2947. return this.flowParseInterface(node);
  2948. } else if (expr.name === "type") {
  2949. return this.flowParseTypeAlias(node);
  2950. } else if (expr.name === "opaque") {
  2951. return this.flowParseOpaqueType(node, false);
  2952. }
  2953. }
  2954. }
  2955. return super.parseExpressionStatement(node, expr, decorators);
  2956. }
  2957. shouldParseExportDeclaration() {
  2958. const {
  2959. type
  2960. } = this.state;
  2961. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2962. return !this.state.containsEsc;
  2963. }
  2964. return super.shouldParseExportDeclaration();
  2965. }
  2966. isExportDefaultSpecifier() {
  2967. const {
  2968. type
  2969. } = this.state;
  2970. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2971. return this.state.containsEsc;
  2972. }
  2973. return super.isExportDefaultSpecifier();
  2974. }
  2975. parseExportDefaultExpression() {
  2976. if (this.isContextual(126)) {
  2977. const node = this.startNode();
  2978. this.next();
  2979. return this.flowParseEnumDeclaration(node);
  2980. }
  2981. return super.parseExportDefaultExpression();
  2982. }
  2983. parseConditional(expr, startLoc, refExpressionErrors) {
  2984. if (!this.match(17)) return expr;
  2985. if (this.state.maybeInArrowParameters) {
  2986. const nextCh = this.lookaheadCharCode();
  2987. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  2988. this.setOptionalParametersError(refExpressionErrors);
  2989. return expr;
  2990. }
  2991. }
  2992. this.expect(17);
  2993. const state = this.state.clone();
  2994. const originalNoArrowAt = this.state.noArrowAt;
  2995. const node = this.startNodeAt(startLoc);
  2996. let {
  2997. consequent,
  2998. failed
  2999. } = this.tryParseConditionalConsequent();
  3000. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  3001. if (failed || invalid.length > 0) {
  3002. const noArrowAt = [...originalNoArrowAt];
  3003. if (invalid.length > 0) {
  3004. this.state = state;
  3005. this.state.noArrowAt = noArrowAt;
  3006. for (let i = 0; i < invalid.length; i++) {
  3007. noArrowAt.push(invalid[i].start);
  3008. }
  3009. ({
  3010. consequent,
  3011. failed
  3012. } = this.tryParseConditionalConsequent());
  3013. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  3014. }
  3015. if (failed && valid.length > 1) {
  3016. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  3017. }
  3018. if (failed && valid.length === 1) {
  3019. this.state = state;
  3020. noArrowAt.push(valid[0].start);
  3021. this.state.noArrowAt = noArrowAt;
  3022. ({
  3023. consequent,
  3024. failed
  3025. } = this.tryParseConditionalConsequent());
  3026. }
  3027. }
  3028. this.getArrowLikeExpressions(consequent, true);
  3029. this.state.noArrowAt = originalNoArrowAt;
  3030. this.expect(14);
  3031. node.test = expr;
  3032. node.consequent = consequent;
  3033. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  3034. return this.finishNode(node, "ConditionalExpression");
  3035. }
  3036. tryParseConditionalConsequent() {
  3037. this.state.noArrowParamsConversionAt.push(this.state.start);
  3038. const consequent = this.parseMaybeAssignAllowIn();
  3039. const failed = !this.match(14);
  3040. this.state.noArrowParamsConversionAt.pop();
  3041. return {
  3042. consequent,
  3043. failed
  3044. };
  3045. }
  3046. getArrowLikeExpressions(node, disallowInvalid) {
  3047. const stack = [node];
  3048. const arrows = [];
  3049. while (stack.length !== 0) {
  3050. const node = stack.pop();
  3051. if (node.type === "ArrowFunctionExpression") {
  3052. if (node.typeParameters || !node.returnType) {
  3053. this.finishArrowValidation(node);
  3054. } else {
  3055. arrows.push(node);
  3056. }
  3057. if (node.body.type !== "BlockStatement") {
  3058. stack.push(node.body);
  3059. }
  3060. } else if (node.type === "ConditionalExpression") {
  3061. stack.push(node.consequent);
  3062. stack.push(node.alternate);
  3063. }
  3064. }
  3065. if (disallowInvalid) {
  3066. arrows.forEach(node => this.finishArrowValidation(node));
  3067. return [arrows, []];
  3068. }
  3069. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  3070. }
  3071. finishArrowValidation(node) {
  3072. var _node$extra;
  3073. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  3074. this.scope.enter(514 | 4);
  3075. super.checkParams(node, false, true);
  3076. this.scope.exit();
  3077. }
  3078. forwardNoArrowParamsConversionAt(node, parse) {
  3079. let result;
  3080. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3081. this.state.noArrowParamsConversionAt.push(this.state.start);
  3082. result = parse();
  3083. this.state.noArrowParamsConversionAt.pop();
  3084. } else {
  3085. result = parse();
  3086. }
  3087. return result;
  3088. }
  3089. parseParenItem(node, startLoc) {
  3090. const newNode = super.parseParenItem(node, startLoc);
  3091. if (this.eat(17)) {
  3092. newNode.optional = true;
  3093. this.resetEndLocation(node);
  3094. }
  3095. if (this.match(14)) {
  3096. const typeCastNode = this.startNodeAt(startLoc);
  3097. typeCastNode.expression = newNode;
  3098. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  3099. return this.finishNode(typeCastNode, "TypeCastExpression");
  3100. }
  3101. return newNode;
  3102. }
  3103. assertModuleNodeAllowed(node) {
  3104. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  3105. return;
  3106. }
  3107. super.assertModuleNodeAllowed(node);
  3108. }
  3109. parseExportDeclaration(node) {
  3110. if (this.isContextual(130)) {
  3111. node.exportKind = "type";
  3112. const declarationNode = this.startNode();
  3113. this.next();
  3114. if (this.match(5)) {
  3115. node.specifiers = this.parseExportSpecifiers(true);
  3116. super.parseExportFrom(node);
  3117. return null;
  3118. } else {
  3119. return this.flowParseTypeAlias(declarationNode);
  3120. }
  3121. } else if (this.isContextual(131)) {
  3122. node.exportKind = "type";
  3123. const declarationNode = this.startNode();
  3124. this.next();
  3125. return this.flowParseOpaqueType(declarationNode, false);
  3126. } else if (this.isContextual(129)) {
  3127. node.exportKind = "type";
  3128. const declarationNode = this.startNode();
  3129. this.next();
  3130. return this.flowParseInterface(declarationNode);
  3131. } else if (this.isContextual(126)) {
  3132. node.exportKind = "value";
  3133. const declarationNode = this.startNode();
  3134. this.next();
  3135. return this.flowParseEnumDeclaration(declarationNode);
  3136. } else {
  3137. return super.parseExportDeclaration(node);
  3138. }
  3139. }
  3140. eatExportStar(node) {
  3141. if (super.eatExportStar(node)) return true;
  3142. if (this.isContextual(130) && this.lookahead().type === 55) {
  3143. node.exportKind = "type";
  3144. this.next();
  3145. this.next();
  3146. return true;
  3147. }
  3148. return false;
  3149. }
  3150. maybeParseExportNamespaceSpecifier(node) {
  3151. const {
  3152. startLoc
  3153. } = this.state;
  3154. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  3155. if (hasNamespace && node.exportKind === "type") {
  3156. this.unexpected(startLoc);
  3157. }
  3158. return hasNamespace;
  3159. }
  3160. parseClassId(node, isStatement, optionalId) {
  3161. super.parseClassId(node, isStatement, optionalId);
  3162. if (this.match(47)) {
  3163. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3164. }
  3165. }
  3166. parseClassMember(classBody, member, state) {
  3167. const {
  3168. startLoc
  3169. } = this.state;
  3170. if (this.isContextual(125)) {
  3171. if (super.parseClassMemberFromModifier(classBody, member)) {
  3172. return;
  3173. }
  3174. member.declare = true;
  3175. }
  3176. super.parseClassMember(classBody, member, state);
  3177. if (member.declare) {
  3178. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  3179. this.raise(FlowErrors.DeclareClassElement, startLoc);
  3180. } else if (member.value) {
  3181. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  3182. }
  3183. }
  3184. }
  3185. isIterator(word) {
  3186. return word === "iterator" || word === "asyncIterator";
  3187. }
  3188. readIterator() {
  3189. const word = super.readWord1();
  3190. const fullWord = "@@" + word;
  3191. if (!this.isIterator(word) || !this.state.inType) {
  3192. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  3193. identifierName: fullWord
  3194. });
  3195. }
  3196. this.finishToken(132, fullWord);
  3197. }
  3198. getTokenFromCode(code) {
  3199. const next = this.input.charCodeAt(this.state.pos + 1);
  3200. if (code === 123 && next === 124) {
  3201. this.finishOp(6, 2);
  3202. } else if (this.state.inType && (code === 62 || code === 60)) {
  3203. this.finishOp(code === 62 ? 48 : 47, 1);
  3204. } else if (this.state.inType && code === 63) {
  3205. if (next === 46) {
  3206. this.finishOp(18, 2);
  3207. } else {
  3208. this.finishOp(17, 1);
  3209. }
  3210. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  3211. this.state.pos += 2;
  3212. this.readIterator();
  3213. } else {
  3214. super.getTokenFromCode(code);
  3215. }
  3216. }
  3217. isAssignable(node, isBinding) {
  3218. if (node.type === "TypeCastExpression") {
  3219. return this.isAssignable(node.expression, isBinding);
  3220. } else {
  3221. return super.isAssignable(node, isBinding);
  3222. }
  3223. }
  3224. toAssignable(node, isLHS = false) {
  3225. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  3226. node.left = this.typeCastToParameter(node.left);
  3227. }
  3228. super.toAssignable(node, isLHS);
  3229. }
  3230. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  3231. for (let i = 0; i < exprList.length; i++) {
  3232. const expr = exprList[i];
  3233. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  3234. exprList[i] = this.typeCastToParameter(expr);
  3235. }
  3236. }
  3237. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  3238. }
  3239. toReferencedList(exprList, isParenthesizedExpr) {
  3240. for (let i = 0; i < exprList.length; i++) {
  3241. var _expr$extra;
  3242. const expr = exprList[i];
  3243. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  3244. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  3245. }
  3246. }
  3247. return exprList;
  3248. }
  3249. parseArrayLike(close, isTuple, refExpressionErrors) {
  3250. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  3251. if (refExpressionErrors != null && !this.state.maybeInArrowParameters) {
  3252. this.toReferencedList(node.elements);
  3253. }
  3254. return node;
  3255. }
  3256. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  3257. return type === "TypeCastExpression" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  3258. }
  3259. parseClassProperty(node) {
  3260. if (this.match(14)) {
  3261. node.typeAnnotation = this.flowParseTypeAnnotation();
  3262. }
  3263. return super.parseClassProperty(node);
  3264. }
  3265. parseClassPrivateProperty(node) {
  3266. if (this.match(14)) {
  3267. node.typeAnnotation = this.flowParseTypeAnnotation();
  3268. }
  3269. return super.parseClassPrivateProperty(node);
  3270. }
  3271. isClassMethod() {
  3272. return this.match(47) || super.isClassMethod();
  3273. }
  3274. isClassProperty() {
  3275. return this.match(14) || super.isClassProperty();
  3276. }
  3277. isNonstaticConstructor(method) {
  3278. return !this.match(14) && super.isNonstaticConstructor(method);
  3279. }
  3280. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  3281. if (method.variance) {
  3282. this.unexpected(method.variance.loc.start);
  3283. }
  3284. delete method.variance;
  3285. if (this.match(47)) {
  3286. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3287. }
  3288. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  3289. if (method.params && isConstructor) {
  3290. const params = method.params;
  3291. if (params.length > 0 && this.isThisParam(params[0])) {
  3292. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3293. }
  3294. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  3295. const params = method.value.params;
  3296. if (params.length > 0 && this.isThisParam(params[0])) {
  3297. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3298. }
  3299. }
  3300. }
  3301. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  3302. if (method.variance) {
  3303. this.unexpected(method.variance.loc.start);
  3304. }
  3305. delete method.variance;
  3306. if (this.match(47)) {
  3307. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3308. }
  3309. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  3310. }
  3311. parseClassSuper(node) {
  3312. super.parseClassSuper(node);
  3313. if (node.superClass && (this.match(47) || this.match(51))) {
  3314. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  3315. }
  3316. if (this.isContextual(113)) {
  3317. this.next();
  3318. const implemented = node.implements = [];
  3319. do {
  3320. const node = this.startNode();
  3321. node.id = this.flowParseRestrictedIdentifier(true);
  3322. if (this.match(47)) {
  3323. node.typeParameters = this.flowParseTypeParameterInstantiation();
  3324. } else {
  3325. node.typeParameters = null;
  3326. }
  3327. implemented.push(this.finishNode(node, "ClassImplements"));
  3328. } while (this.eat(12));
  3329. }
  3330. }
  3331. checkGetterSetterParams(method) {
  3332. super.checkGetterSetterParams(method);
  3333. const params = this.getObjectOrClassMethodParams(method);
  3334. if (params.length > 0) {
  3335. const param = params[0];
  3336. if (this.isThisParam(param) && method.kind === "get") {
  3337. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  3338. } else if (this.isThisParam(param)) {
  3339. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  3340. }
  3341. }
  3342. }
  3343. parsePropertyNamePrefixOperator(node) {
  3344. node.variance = this.flowParseVariance();
  3345. }
  3346. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  3347. if (prop.variance) {
  3348. this.unexpected(prop.variance.loc.start);
  3349. }
  3350. delete prop.variance;
  3351. let typeParameters;
  3352. if (this.match(47) && !isAccessor) {
  3353. typeParameters = this.flowParseTypeParameterDeclaration();
  3354. if (!this.match(10)) this.unexpected();
  3355. }
  3356. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  3357. if (typeParameters) {
  3358. (result.value || result).typeParameters = typeParameters;
  3359. }
  3360. return result;
  3361. }
  3362. parseFunctionParamType(param) {
  3363. if (this.eat(17)) {
  3364. if (param.type !== "Identifier") {
  3365. this.raise(FlowErrors.PatternIsOptional, param);
  3366. }
  3367. if (this.isThisParam(param)) {
  3368. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  3369. }
  3370. param.optional = true;
  3371. }
  3372. if (this.match(14)) {
  3373. param.typeAnnotation = this.flowParseTypeAnnotation();
  3374. } else if (this.isThisParam(param)) {
  3375. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  3376. }
  3377. if (this.match(29) && this.isThisParam(param)) {
  3378. this.raise(FlowErrors.ThisParamNoDefault, param);
  3379. }
  3380. this.resetEndLocation(param);
  3381. return param;
  3382. }
  3383. parseMaybeDefault(startLoc, left) {
  3384. const node = super.parseMaybeDefault(startLoc, left);
  3385. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  3386. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  3387. }
  3388. return node;
  3389. }
  3390. checkImportReflection(node) {
  3391. super.checkImportReflection(node);
  3392. if (node.module && node.importKind !== "value") {
  3393. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  3394. }
  3395. }
  3396. parseImportSpecifierLocal(node, specifier, type) {
  3397. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  3398. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  3399. }
  3400. isPotentialImportPhase(isExport) {
  3401. if (super.isPotentialImportPhase(isExport)) return true;
  3402. if (this.isContextual(130)) {
  3403. if (!isExport) return true;
  3404. const ch = this.lookaheadCharCode();
  3405. return ch === 123 || ch === 42;
  3406. }
  3407. return !isExport && this.isContextual(87);
  3408. }
  3409. applyImportPhase(node, isExport, phase, loc) {
  3410. super.applyImportPhase(node, isExport, phase, loc);
  3411. if (isExport) {
  3412. if (!phase && this.match(65)) {
  3413. return;
  3414. }
  3415. node.exportKind = phase === "type" ? phase : "value";
  3416. } else {
  3417. if (phase === "type" && this.match(55)) this.unexpected();
  3418. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  3419. }
  3420. }
  3421. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  3422. const firstIdent = specifier.imported;
  3423. let specifierTypeKind = null;
  3424. if (firstIdent.type === "Identifier") {
  3425. if (firstIdent.name === "type") {
  3426. specifierTypeKind = "type";
  3427. } else if (firstIdent.name === "typeof") {
  3428. specifierTypeKind = "typeof";
  3429. }
  3430. }
  3431. let isBinding = false;
  3432. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  3433. const as_ident = this.parseIdentifier(true);
  3434. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  3435. specifier.imported = as_ident;
  3436. specifier.importKind = specifierTypeKind;
  3437. specifier.local = this.cloneIdentifier(as_ident);
  3438. } else {
  3439. specifier.imported = firstIdent;
  3440. specifier.importKind = null;
  3441. specifier.local = this.parseIdentifier();
  3442. }
  3443. } else {
  3444. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  3445. specifier.imported = this.parseIdentifier(true);
  3446. specifier.importKind = specifierTypeKind;
  3447. } else {
  3448. if (importedIsString) {
  3449. throw this.raise(Errors.ImportBindingIsString, specifier, {
  3450. importName: firstIdent.value
  3451. });
  3452. }
  3453. specifier.imported = firstIdent;
  3454. specifier.importKind = null;
  3455. }
  3456. if (this.eatContextual(93)) {
  3457. specifier.local = this.parseIdentifier();
  3458. } else {
  3459. isBinding = true;
  3460. specifier.local = this.cloneIdentifier(specifier.imported);
  3461. }
  3462. }
  3463. const specifierIsTypeImport = hasTypeImportKind(specifier);
  3464. if (isInTypeOnlyImport && specifierIsTypeImport) {
  3465. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  3466. }
  3467. if (isInTypeOnlyImport || specifierIsTypeImport) {
  3468. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  3469. }
  3470. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  3471. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  3472. }
  3473. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  3474. }
  3475. parseBindingAtom() {
  3476. switch (this.state.type) {
  3477. case 78:
  3478. return this.parseIdentifier(true);
  3479. default:
  3480. return super.parseBindingAtom();
  3481. }
  3482. }
  3483. parseFunctionParams(node, isConstructor) {
  3484. const kind = node.kind;
  3485. if (kind !== "get" && kind !== "set" && this.match(47)) {
  3486. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3487. }
  3488. super.parseFunctionParams(node, isConstructor);
  3489. }
  3490. parseVarId(decl, kind) {
  3491. super.parseVarId(decl, kind);
  3492. if (this.match(14)) {
  3493. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  3494. this.resetEndLocation(decl.id);
  3495. }
  3496. }
  3497. parseAsyncArrowFromCallExpression(node, call) {
  3498. if (this.match(14)) {
  3499. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3500. this.state.noAnonFunctionType = true;
  3501. node.returnType = this.flowParseTypeAnnotation();
  3502. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3503. }
  3504. return super.parseAsyncArrowFromCallExpression(node, call);
  3505. }
  3506. shouldParseAsyncArrow() {
  3507. return this.match(14) || super.shouldParseAsyncArrow();
  3508. }
  3509. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  3510. var _jsx;
  3511. let state = null;
  3512. let jsx;
  3513. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  3514. state = this.state.clone();
  3515. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  3516. if (!jsx.error) return jsx.node;
  3517. const {
  3518. context
  3519. } = this.state;
  3520. const currentContext = context[context.length - 1];
  3521. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  3522. context.pop();
  3523. }
  3524. }
  3525. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  3526. var _jsx2, _jsx3;
  3527. state = state || this.state.clone();
  3528. let typeParameters;
  3529. const arrow = this.tryParse(abort => {
  3530. var _arrowExpression$extr;
  3531. typeParameters = this.flowParseTypeParameterDeclaration();
  3532. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  3533. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3534. this.resetStartLocationFromNode(result, typeParameters);
  3535. return result;
  3536. });
  3537. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  3538. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  3539. if (expr.type !== "ArrowFunctionExpression") abort();
  3540. expr.typeParameters = typeParameters;
  3541. this.resetStartLocationFromNode(expr, typeParameters);
  3542. return arrowExpression;
  3543. }, state);
  3544. let arrowExpression = null;
  3545. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  3546. if (!arrow.error && !arrow.aborted) {
  3547. if (arrow.node.async) {
  3548. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  3549. }
  3550. return arrow.node;
  3551. }
  3552. arrowExpression = arrow.node;
  3553. }
  3554. if ((_jsx2 = jsx) != null && _jsx2.node) {
  3555. this.state = jsx.failState;
  3556. return jsx.node;
  3557. }
  3558. if (arrowExpression) {
  3559. this.state = arrow.failState;
  3560. return arrowExpression;
  3561. }
  3562. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  3563. if (arrow.thrown) throw arrow.error;
  3564. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  3565. }
  3566. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3567. }
  3568. parseArrow(node) {
  3569. if (this.match(14)) {
  3570. const result = this.tryParse(() => {
  3571. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3572. this.state.noAnonFunctionType = true;
  3573. const typeNode = this.startNode();
  3574. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  3575. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3576. if (this.canInsertSemicolon()) this.unexpected();
  3577. if (!this.match(19)) this.unexpected();
  3578. return typeNode;
  3579. });
  3580. if (result.thrown) return null;
  3581. if (result.error) this.state = result.failState;
  3582. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  3583. }
  3584. return super.parseArrow(node);
  3585. }
  3586. shouldParseArrow(params) {
  3587. return this.match(14) || super.shouldParseArrow(params);
  3588. }
  3589. setArrowFunctionParameters(node, params) {
  3590. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3591. node.params = params;
  3592. } else {
  3593. super.setArrowFunctionParameters(node, params);
  3594. }
  3595. }
  3596. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  3597. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3598. return;
  3599. }
  3600. for (let i = 0; i < node.params.length; i++) {
  3601. if (this.isThisParam(node.params[i]) && i > 0) {
  3602. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  3603. }
  3604. }
  3605. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  3606. }
  3607. parseParenAndDistinguishExpression(canBeArrow) {
  3608. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  3609. }
  3610. parseSubscripts(base, startLoc, noCalls) {
  3611. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  3612. this.next();
  3613. const node = this.startNodeAt(startLoc);
  3614. node.callee = base;
  3615. node.arguments = super.parseCallExpressionArguments();
  3616. base = this.finishNode(node, "CallExpression");
  3617. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  3618. const state = this.state.clone();
  3619. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  3620. if (!arrow.error && !arrow.aborted) return arrow.node;
  3621. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  3622. if (result.node && !result.error) return result.node;
  3623. if (arrow.node) {
  3624. this.state = arrow.failState;
  3625. return arrow.node;
  3626. }
  3627. if (result.node) {
  3628. this.state = result.failState;
  3629. return result.node;
  3630. }
  3631. throw arrow.error || result.error;
  3632. }
  3633. return super.parseSubscripts(base, startLoc, noCalls);
  3634. }
  3635. parseSubscript(base, startLoc, noCalls, subscriptState) {
  3636. if (this.match(18) && this.isLookaheadToken_lt()) {
  3637. subscriptState.optionalChainMember = true;
  3638. if (noCalls) {
  3639. subscriptState.stop = true;
  3640. return base;
  3641. }
  3642. this.next();
  3643. const node = this.startNodeAt(startLoc);
  3644. node.callee = base;
  3645. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  3646. this.expect(10);
  3647. node.arguments = this.parseCallExpressionArguments();
  3648. node.optional = true;
  3649. return this.finishCallExpression(node, true);
  3650. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  3651. const node = this.startNodeAt(startLoc);
  3652. node.callee = base;
  3653. const result = this.tryParse(() => {
  3654. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  3655. this.expect(10);
  3656. node.arguments = super.parseCallExpressionArguments();
  3657. if (subscriptState.optionalChainMember) {
  3658. node.optional = false;
  3659. }
  3660. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  3661. });
  3662. if (result.node) {
  3663. if (result.error) this.state = result.failState;
  3664. return result.node;
  3665. }
  3666. }
  3667. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  3668. }
  3669. parseNewCallee(node) {
  3670. super.parseNewCallee(node);
  3671. let targs = null;
  3672. if (this.shouldParseTypes() && this.match(47)) {
  3673. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  3674. }
  3675. node.typeArguments = targs;
  3676. }
  3677. parseAsyncArrowWithTypeParameters(startLoc) {
  3678. const node = this.startNodeAt(startLoc);
  3679. this.parseFunctionParams(node, false);
  3680. if (!this.parseArrow(node)) return;
  3681. return super.parseArrowExpression(node, undefined, true);
  3682. }
  3683. readToken_mult_modulo(code) {
  3684. const next = this.input.charCodeAt(this.state.pos + 1);
  3685. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  3686. this.state.hasFlowComment = false;
  3687. this.state.pos += 2;
  3688. this.nextToken();
  3689. return;
  3690. }
  3691. super.readToken_mult_modulo(code);
  3692. }
  3693. readToken_pipe_amp(code) {
  3694. const next = this.input.charCodeAt(this.state.pos + 1);
  3695. if (code === 124 && next === 125) {
  3696. this.finishOp(9, 2);
  3697. return;
  3698. }
  3699. super.readToken_pipe_amp(code);
  3700. }
  3701. parseTopLevel(file, program) {
  3702. const fileNode = super.parseTopLevel(file, program);
  3703. if (this.state.hasFlowComment) {
  3704. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  3705. }
  3706. return fileNode;
  3707. }
  3708. skipBlockComment() {
  3709. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  3710. if (this.state.hasFlowComment) {
  3711. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  3712. }
  3713. this.hasFlowCommentCompletion();
  3714. const commentSkip = this.skipFlowComment();
  3715. if (commentSkip) {
  3716. this.state.pos += commentSkip;
  3717. this.state.hasFlowComment = true;
  3718. }
  3719. return;
  3720. }
  3721. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  3722. }
  3723. skipFlowComment() {
  3724. const {
  3725. pos
  3726. } = this.state;
  3727. let shiftToFirstNonWhiteSpace = 2;
  3728. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  3729. shiftToFirstNonWhiteSpace++;
  3730. }
  3731. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  3732. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  3733. if (ch2 === 58 && ch3 === 58) {
  3734. return shiftToFirstNonWhiteSpace + 2;
  3735. }
  3736. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  3737. return shiftToFirstNonWhiteSpace + 12;
  3738. }
  3739. if (ch2 === 58 && ch3 !== 58) {
  3740. return shiftToFirstNonWhiteSpace;
  3741. }
  3742. return false;
  3743. }
  3744. hasFlowCommentCompletion() {
  3745. const end = this.input.indexOf("*/", this.state.pos);
  3746. if (end === -1) {
  3747. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  3748. }
  3749. }
  3750. flowEnumErrorBooleanMemberNotInitialized(loc, {
  3751. enumName,
  3752. memberName
  3753. }) {
  3754. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  3755. memberName,
  3756. enumName
  3757. });
  3758. }
  3759. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  3760. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  3761. }
  3762. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  3763. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  3764. }
  3765. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  3766. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  3767. }
  3768. flowEnumMemberInit() {
  3769. const startLoc = this.state.startLoc;
  3770. const endOfInit = () => this.match(12) || this.match(8);
  3771. switch (this.state.type) {
  3772. case 135:
  3773. {
  3774. const literal = this.parseNumericLiteral(this.state.value);
  3775. if (endOfInit()) {
  3776. return {
  3777. type: "number",
  3778. loc: literal.loc.start,
  3779. value: literal
  3780. };
  3781. }
  3782. return {
  3783. type: "invalid",
  3784. loc: startLoc
  3785. };
  3786. }
  3787. case 134:
  3788. {
  3789. const literal = this.parseStringLiteral(this.state.value);
  3790. if (endOfInit()) {
  3791. return {
  3792. type: "string",
  3793. loc: literal.loc.start,
  3794. value: literal
  3795. };
  3796. }
  3797. return {
  3798. type: "invalid",
  3799. loc: startLoc
  3800. };
  3801. }
  3802. case 85:
  3803. case 86:
  3804. {
  3805. const literal = this.parseBooleanLiteral(this.match(85));
  3806. if (endOfInit()) {
  3807. return {
  3808. type: "boolean",
  3809. loc: literal.loc.start,
  3810. value: literal
  3811. };
  3812. }
  3813. return {
  3814. type: "invalid",
  3815. loc: startLoc
  3816. };
  3817. }
  3818. default:
  3819. return {
  3820. type: "invalid",
  3821. loc: startLoc
  3822. };
  3823. }
  3824. }
  3825. flowEnumMemberRaw() {
  3826. const loc = this.state.startLoc;
  3827. const id = this.parseIdentifier(true);
  3828. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  3829. type: "none",
  3830. loc
  3831. };
  3832. return {
  3833. id,
  3834. init
  3835. };
  3836. }
  3837. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  3838. const {
  3839. explicitType
  3840. } = context;
  3841. if (explicitType === null) {
  3842. return;
  3843. }
  3844. if (explicitType !== expectedType) {
  3845. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  3846. }
  3847. }
  3848. flowEnumMembers({
  3849. enumName,
  3850. explicitType
  3851. }) {
  3852. const seenNames = new Set();
  3853. const members = {
  3854. booleanMembers: [],
  3855. numberMembers: [],
  3856. stringMembers: [],
  3857. defaultedMembers: []
  3858. };
  3859. let hasUnknownMembers = false;
  3860. while (!this.match(8)) {
  3861. if (this.eat(21)) {
  3862. hasUnknownMembers = true;
  3863. break;
  3864. }
  3865. const memberNode = this.startNode();
  3866. const {
  3867. id,
  3868. init
  3869. } = this.flowEnumMemberRaw();
  3870. const memberName = id.name;
  3871. if (memberName === "") {
  3872. continue;
  3873. }
  3874. if (/^[a-z]/.test(memberName)) {
  3875. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  3876. memberName,
  3877. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  3878. enumName
  3879. });
  3880. }
  3881. if (seenNames.has(memberName)) {
  3882. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  3883. memberName,
  3884. enumName
  3885. });
  3886. }
  3887. seenNames.add(memberName);
  3888. const context = {
  3889. enumName,
  3890. explicitType,
  3891. memberName
  3892. };
  3893. memberNode.id = id;
  3894. switch (init.type) {
  3895. case "boolean":
  3896. {
  3897. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  3898. memberNode.init = init.value;
  3899. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  3900. break;
  3901. }
  3902. case "number":
  3903. {
  3904. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  3905. memberNode.init = init.value;
  3906. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  3907. break;
  3908. }
  3909. case "string":
  3910. {
  3911. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  3912. memberNode.init = init.value;
  3913. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  3914. break;
  3915. }
  3916. case "invalid":
  3917. {
  3918. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  3919. }
  3920. case "none":
  3921. {
  3922. switch (explicitType) {
  3923. case "boolean":
  3924. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  3925. break;
  3926. case "number":
  3927. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  3928. break;
  3929. default:
  3930. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  3931. }
  3932. }
  3933. }
  3934. if (!this.match(8)) {
  3935. this.expect(12);
  3936. }
  3937. }
  3938. return {
  3939. members,
  3940. hasUnknownMembers
  3941. };
  3942. }
  3943. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  3944. enumName
  3945. }) {
  3946. if (initializedMembers.length === 0) {
  3947. return defaultedMembers;
  3948. } else if (defaultedMembers.length === 0) {
  3949. return initializedMembers;
  3950. } else if (defaultedMembers.length > initializedMembers.length) {
  3951. for (const member of initializedMembers) {
  3952. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3953. enumName
  3954. });
  3955. }
  3956. return defaultedMembers;
  3957. } else {
  3958. for (const member of defaultedMembers) {
  3959. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3960. enumName
  3961. });
  3962. }
  3963. return initializedMembers;
  3964. }
  3965. }
  3966. flowEnumParseExplicitType({
  3967. enumName
  3968. }) {
  3969. if (!this.eatContextual(102)) return null;
  3970. if (!tokenIsIdentifier(this.state.type)) {
  3971. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  3972. enumName
  3973. });
  3974. }
  3975. const {
  3976. value
  3977. } = this.state;
  3978. this.next();
  3979. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  3980. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  3981. enumName,
  3982. invalidEnumType: value
  3983. });
  3984. }
  3985. return value;
  3986. }
  3987. flowEnumBody(node, id) {
  3988. const enumName = id.name;
  3989. const nameLoc = id.loc.start;
  3990. const explicitType = this.flowEnumParseExplicitType({
  3991. enumName
  3992. });
  3993. this.expect(5);
  3994. const {
  3995. members,
  3996. hasUnknownMembers
  3997. } = this.flowEnumMembers({
  3998. enumName,
  3999. explicitType
  4000. });
  4001. node.hasUnknownMembers = hasUnknownMembers;
  4002. switch (explicitType) {
  4003. case "boolean":
  4004. node.explicitType = true;
  4005. node.members = members.booleanMembers;
  4006. this.expect(8);
  4007. return this.finishNode(node, "EnumBooleanBody");
  4008. case "number":
  4009. node.explicitType = true;
  4010. node.members = members.numberMembers;
  4011. this.expect(8);
  4012. return this.finishNode(node, "EnumNumberBody");
  4013. case "string":
  4014. node.explicitType = true;
  4015. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4016. enumName
  4017. });
  4018. this.expect(8);
  4019. return this.finishNode(node, "EnumStringBody");
  4020. case "symbol":
  4021. node.members = members.defaultedMembers;
  4022. this.expect(8);
  4023. return this.finishNode(node, "EnumSymbolBody");
  4024. default:
  4025. {
  4026. const empty = () => {
  4027. node.members = [];
  4028. this.expect(8);
  4029. return this.finishNode(node, "EnumStringBody");
  4030. };
  4031. node.explicitType = false;
  4032. const boolsLen = members.booleanMembers.length;
  4033. const numsLen = members.numberMembers.length;
  4034. const strsLen = members.stringMembers.length;
  4035. const defaultedLen = members.defaultedMembers.length;
  4036. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  4037. return empty();
  4038. } else if (!boolsLen && !numsLen) {
  4039. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4040. enumName
  4041. });
  4042. this.expect(8);
  4043. return this.finishNode(node, "EnumStringBody");
  4044. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  4045. for (const member of members.defaultedMembers) {
  4046. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  4047. enumName,
  4048. memberName: member.id.name
  4049. });
  4050. }
  4051. node.members = members.booleanMembers;
  4052. this.expect(8);
  4053. return this.finishNode(node, "EnumBooleanBody");
  4054. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  4055. for (const member of members.defaultedMembers) {
  4056. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  4057. enumName,
  4058. memberName: member.id.name
  4059. });
  4060. }
  4061. node.members = members.numberMembers;
  4062. this.expect(8);
  4063. return this.finishNode(node, "EnumNumberBody");
  4064. } else {
  4065. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  4066. enumName
  4067. });
  4068. return empty();
  4069. }
  4070. }
  4071. }
  4072. }
  4073. flowParseEnumDeclaration(node) {
  4074. const id = this.parseIdentifier();
  4075. node.id = id;
  4076. node.body = this.flowEnumBody(this.startNode(), id);
  4077. return this.finishNode(node, "EnumDeclaration");
  4078. }
  4079. jsxParseOpeningElementAfterName(node) {
  4080. if (this.shouldParseTypes()) {
  4081. if (this.match(47) || this.match(51)) {
  4082. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  4083. }
  4084. }
  4085. return super.jsxParseOpeningElementAfterName(node);
  4086. }
  4087. isLookaheadToken_lt() {
  4088. const next = this.nextTokenStart();
  4089. if (this.input.charCodeAt(next) === 60) {
  4090. const afterNext = this.input.charCodeAt(next + 1);
  4091. return afterNext !== 60 && afterNext !== 61;
  4092. }
  4093. return false;
  4094. }
  4095. reScan_lt_gt() {
  4096. const {
  4097. type
  4098. } = this.state;
  4099. if (type === 47) {
  4100. this.state.pos -= 1;
  4101. this.readToken_lt();
  4102. } else if (type === 48) {
  4103. this.state.pos -= 1;
  4104. this.readToken_gt();
  4105. }
  4106. }
  4107. reScan_lt() {
  4108. const {
  4109. type
  4110. } = this.state;
  4111. if (type === 51) {
  4112. this.state.pos -= 2;
  4113. this.finishOp(47, 1);
  4114. return 47;
  4115. }
  4116. return type;
  4117. }
  4118. maybeUnwrapTypeCastExpression(node) {
  4119. return node.type === "TypeCastExpression" ? node.expression : node;
  4120. }
  4121. };
  4122. const entities = {
  4123. __proto__: null,
  4124. quot: "\u0022",
  4125. amp: "&",
  4126. apos: "\u0027",
  4127. lt: "<",
  4128. gt: ">",
  4129. nbsp: "\u00A0",
  4130. iexcl: "\u00A1",
  4131. cent: "\u00A2",
  4132. pound: "\u00A3",
  4133. curren: "\u00A4",
  4134. yen: "\u00A5",
  4135. brvbar: "\u00A6",
  4136. sect: "\u00A7",
  4137. uml: "\u00A8",
  4138. copy: "\u00A9",
  4139. ordf: "\u00AA",
  4140. laquo: "\u00AB",
  4141. not: "\u00AC",
  4142. shy: "\u00AD",
  4143. reg: "\u00AE",
  4144. macr: "\u00AF",
  4145. deg: "\u00B0",
  4146. plusmn: "\u00B1",
  4147. sup2: "\u00B2",
  4148. sup3: "\u00B3",
  4149. acute: "\u00B4",
  4150. micro: "\u00B5",
  4151. para: "\u00B6",
  4152. middot: "\u00B7",
  4153. cedil: "\u00B8",
  4154. sup1: "\u00B9",
  4155. ordm: "\u00BA",
  4156. raquo: "\u00BB",
  4157. frac14: "\u00BC",
  4158. frac12: "\u00BD",
  4159. frac34: "\u00BE",
  4160. iquest: "\u00BF",
  4161. Agrave: "\u00C0",
  4162. Aacute: "\u00C1",
  4163. Acirc: "\u00C2",
  4164. Atilde: "\u00C3",
  4165. Auml: "\u00C4",
  4166. Aring: "\u00C5",
  4167. AElig: "\u00C6",
  4168. Ccedil: "\u00C7",
  4169. Egrave: "\u00C8",
  4170. Eacute: "\u00C9",
  4171. Ecirc: "\u00CA",
  4172. Euml: "\u00CB",
  4173. Igrave: "\u00CC",
  4174. Iacute: "\u00CD",
  4175. Icirc: "\u00CE",
  4176. Iuml: "\u00CF",
  4177. ETH: "\u00D0",
  4178. Ntilde: "\u00D1",
  4179. Ograve: "\u00D2",
  4180. Oacute: "\u00D3",
  4181. Ocirc: "\u00D4",
  4182. Otilde: "\u00D5",
  4183. Ouml: "\u00D6",
  4184. times: "\u00D7",
  4185. Oslash: "\u00D8",
  4186. Ugrave: "\u00D9",
  4187. Uacute: "\u00DA",
  4188. Ucirc: "\u00DB",
  4189. Uuml: "\u00DC",
  4190. Yacute: "\u00DD",
  4191. THORN: "\u00DE",
  4192. szlig: "\u00DF",
  4193. agrave: "\u00E0",
  4194. aacute: "\u00E1",
  4195. acirc: "\u00E2",
  4196. atilde: "\u00E3",
  4197. auml: "\u00E4",
  4198. aring: "\u00E5",
  4199. aelig: "\u00E6",
  4200. ccedil: "\u00E7",
  4201. egrave: "\u00E8",
  4202. eacute: "\u00E9",
  4203. ecirc: "\u00EA",
  4204. euml: "\u00EB",
  4205. igrave: "\u00EC",
  4206. iacute: "\u00ED",
  4207. icirc: "\u00EE",
  4208. iuml: "\u00EF",
  4209. eth: "\u00F0",
  4210. ntilde: "\u00F1",
  4211. ograve: "\u00F2",
  4212. oacute: "\u00F3",
  4213. ocirc: "\u00F4",
  4214. otilde: "\u00F5",
  4215. ouml: "\u00F6",
  4216. divide: "\u00F7",
  4217. oslash: "\u00F8",
  4218. ugrave: "\u00F9",
  4219. uacute: "\u00FA",
  4220. ucirc: "\u00FB",
  4221. uuml: "\u00FC",
  4222. yacute: "\u00FD",
  4223. thorn: "\u00FE",
  4224. yuml: "\u00FF",
  4225. OElig: "\u0152",
  4226. oelig: "\u0153",
  4227. Scaron: "\u0160",
  4228. scaron: "\u0161",
  4229. Yuml: "\u0178",
  4230. fnof: "\u0192",
  4231. circ: "\u02C6",
  4232. tilde: "\u02DC",
  4233. Alpha: "\u0391",
  4234. Beta: "\u0392",
  4235. Gamma: "\u0393",
  4236. Delta: "\u0394",
  4237. Epsilon: "\u0395",
  4238. Zeta: "\u0396",
  4239. Eta: "\u0397",
  4240. Theta: "\u0398",
  4241. Iota: "\u0399",
  4242. Kappa: "\u039A",
  4243. Lambda: "\u039B",
  4244. Mu: "\u039C",
  4245. Nu: "\u039D",
  4246. Xi: "\u039E",
  4247. Omicron: "\u039F",
  4248. Pi: "\u03A0",
  4249. Rho: "\u03A1",
  4250. Sigma: "\u03A3",
  4251. Tau: "\u03A4",
  4252. Upsilon: "\u03A5",
  4253. Phi: "\u03A6",
  4254. Chi: "\u03A7",
  4255. Psi: "\u03A8",
  4256. Omega: "\u03A9",
  4257. alpha: "\u03B1",
  4258. beta: "\u03B2",
  4259. gamma: "\u03B3",
  4260. delta: "\u03B4",
  4261. epsilon: "\u03B5",
  4262. zeta: "\u03B6",
  4263. eta: "\u03B7",
  4264. theta: "\u03B8",
  4265. iota: "\u03B9",
  4266. kappa: "\u03BA",
  4267. lambda: "\u03BB",
  4268. mu: "\u03BC",
  4269. nu: "\u03BD",
  4270. xi: "\u03BE",
  4271. omicron: "\u03BF",
  4272. pi: "\u03C0",
  4273. rho: "\u03C1",
  4274. sigmaf: "\u03C2",
  4275. sigma: "\u03C3",
  4276. tau: "\u03C4",
  4277. upsilon: "\u03C5",
  4278. phi: "\u03C6",
  4279. chi: "\u03C7",
  4280. psi: "\u03C8",
  4281. omega: "\u03C9",
  4282. thetasym: "\u03D1",
  4283. upsih: "\u03D2",
  4284. piv: "\u03D6",
  4285. ensp: "\u2002",
  4286. emsp: "\u2003",
  4287. thinsp: "\u2009",
  4288. zwnj: "\u200C",
  4289. zwj: "\u200D",
  4290. lrm: "\u200E",
  4291. rlm: "\u200F",
  4292. ndash: "\u2013",
  4293. mdash: "\u2014",
  4294. lsquo: "\u2018",
  4295. rsquo: "\u2019",
  4296. sbquo: "\u201A",
  4297. ldquo: "\u201C",
  4298. rdquo: "\u201D",
  4299. bdquo: "\u201E",
  4300. dagger: "\u2020",
  4301. Dagger: "\u2021",
  4302. bull: "\u2022",
  4303. hellip: "\u2026",
  4304. permil: "\u2030",
  4305. prime: "\u2032",
  4306. Prime: "\u2033",
  4307. lsaquo: "\u2039",
  4308. rsaquo: "\u203A",
  4309. oline: "\u203E",
  4310. frasl: "\u2044",
  4311. euro: "\u20AC",
  4312. image: "\u2111",
  4313. weierp: "\u2118",
  4314. real: "\u211C",
  4315. trade: "\u2122",
  4316. alefsym: "\u2135",
  4317. larr: "\u2190",
  4318. uarr: "\u2191",
  4319. rarr: "\u2192",
  4320. darr: "\u2193",
  4321. harr: "\u2194",
  4322. crarr: "\u21B5",
  4323. lArr: "\u21D0",
  4324. uArr: "\u21D1",
  4325. rArr: "\u21D2",
  4326. dArr: "\u21D3",
  4327. hArr: "\u21D4",
  4328. forall: "\u2200",
  4329. part: "\u2202",
  4330. exist: "\u2203",
  4331. empty: "\u2205",
  4332. nabla: "\u2207",
  4333. isin: "\u2208",
  4334. notin: "\u2209",
  4335. ni: "\u220B",
  4336. prod: "\u220F",
  4337. sum: "\u2211",
  4338. minus: "\u2212",
  4339. lowast: "\u2217",
  4340. radic: "\u221A",
  4341. prop: "\u221D",
  4342. infin: "\u221E",
  4343. ang: "\u2220",
  4344. and: "\u2227",
  4345. or: "\u2228",
  4346. cap: "\u2229",
  4347. cup: "\u222A",
  4348. int: "\u222B",
  4349. there4: "\u2234",
  4350. sim: "\u223C",
  4351. cong: "\u2245",
  4352. asymp: "\u2248",
  4353. ne: "\u2260",
  4354. equiv: "\u2261",
  4355. le: "\u2264",
  4356. ge: "\u2265",
  4357. sub: "\u2282",
  4358. sup: "\u2283",
  4359. nsub: "\u2284",
  4360. sube: "\u2286",
  4361. supe: "\u2287",
  4362. oplus: "\u2295",
  4363. otimes: "\u2297",
  4364. perp: "\u22A5",
  4365. sdot: "\u22C5",
  4366. lceil: "\u2308",
  4367. rceil: "\u2309",
  4368. lfloor: "\u230A",
  4369. rfloor: "\u230B",
  4370. lang: "\u2329",
  4371. rang: "\u232A",
  4372. loz: "\u25CA",
  4373. spades: "\u2660",
  4374. clubs: "\u2663",
  4375. hearts: "\u2665",
  4376. diams: "\u2666"
  4377. };
  4378. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  4379. const lineBreakG = new RegExp(lineBreak.source, "g");
  4380. function isNewLine(code) {
  4381. switch (code) {
  4382. case 10:
  4383. case 13:
  4384. case 8232:
  4385. case 8233:
  4386. return true;
  4387. default:
  4388. return false;
  4389. }
  4390. }
  4391. function hasNewLine(input, start, end) {
  4392. for (let i = start; i < end; i++) {
  4393. if (isNewLine(input.charCodeAt(i))) {
  4394. return true;
  4395. }
  4396. }
  4397. return false;
  4398. }
  4399. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  4400. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  4401. function isWhitespace(code) {
  4402. switch (code) {
  4403. case 0x0009:
  4404. case 0x000b:
  4405. case 0x000c:
  4406. case 32:
  4407. case 160:
  4408. case 5760:
  4409. case 0x2000:
  4410. case 0x2001:
  4411. case 0x2002:
  4412. case 0x2003:
  4413. case 0x2004:
  4414. case 0x2005:
  4415. case 0x2006:
  4416. case 0x2007:
  4417. case 0x2008:
  4418. case 0x2009:
  4419. case 0x200a:
  4420. case 0x202f:
  4421. case 0x205f:
  4422. case 0x3000:
  4423. case 0xfeff:
  4424. return true;
  4425. default:
  4426. return false;
  4427. }
  4428. }
  4429. const JsxErrors = ParseErrorEnum`jsx`({
  4430. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  4431. MissingClosingTagElement: ({
  4432. openingTagName
  4433. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  4434. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  4435. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  4436. UnexpectedToken: ({
  4437. unexpected,
  4438. HTMLEntity
  4439. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  4440. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  4441. UnterminatedJsxContent: "Unterminated JSX contents.",
  4442. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  4443. });
  4444. function isFragment(object) {
  4445. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  4446. }
  4447. function getQualifiedJSXName(object) {
  4448. if (object.type === "JSXIdentifier") {
  4449. return object.name;
  4450. }
  4451. if (object.type === "JSXNamespacedName") {
  4452. return object.namespace.name + ":" + object.name.name;
  4453. }
  4454. if (object.type === "JSXMemberExpression") {
  4455. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  4456. }
  4457. throw new Error("Node had unexpected type: " + object.type);
  4458. }
  4459. var jsx = superClass => class JSXParserMixin extends superClass {
  4460. jsxReadToken() {
  4461. let out = "";
  4462. let chunkStart = this.state.pos;
  4463. for (;;) {
  4464. if (this.state.pos >= this.length) {
  4465. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  4466. }
  4467. const ch = this.input.charCodeAt(this.state.pos);
  4468. switch (ch) {
  4469. case 60:
  4470. case 123:
  4471. if (this.state.pos === this.state.start) {
  4472. if (ch === 60 && this.state.canStartJSXElement) {
  4473. ++this.state.pos;
  4474. this.finishToken(143);
  4475. } else {
  4476. super.getTokenFromCode(ch);
  4477. }
  4478. return;
  4479. }
  4480. out += this.input.slice(chunkStart, this.state.pos);
  4481. this.finishToken(142, out);
  4482. return;
  4483. case 38:
  4484. out += this.input.slice(chunkStart, this.state.pos);
  4485. out += this.jsxReadEntity();
  4486. chunkStart = this.state.pos;
  4487. break;
  4488. case 62:
  4489. case 125:
  4490. default:
  4491. if (isNewLine(ch)) {
  4492. out += this.input.slice(chunkStart, this.state.pos);
  4493. out += this.jsxReadNewLine(true);
  4494. chunkStart = this.state.pos;
  4495. } else {
  4496. ++this.state.pos;
  4497. }
  4498. }
  4499. }
  4500. }
  4501. jsxReadNewLine(normalizeCRLF) {
  4502. const ch = this.input.charCodeAt(this.state.pos);
  4503. let out;
  4504. ++this.state.pos;
  4505. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  4506. ++this.state.pos;
  4507. out = normalizeCRLF ? "\n" : "\r\n";
  4508. } else {
  4509. out = String.fromCharCode(ch);
  4510. }
  4511. ++this.state.curLine;
  4512. this.state.lineStart = this.state.pos;
  4513. return out;
  4514. }
  4515. jsxReadString(quote) {
  4516. let out = "";
  4517. let chunkStart = ++this.state.pos;
  4518. for (;;) {
  4519. if (this.state.pos >= this.length) {
  4520. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  4521. }
  4522. const ch = this.input.charCodeAt(this.state.pos);
  4523. if (ch === quote) break;
  4524. if (ch === 38) {
  4525. out += this.input.slice(chunkStart, this.state.pos);
  4526. out += this.jsxReadEntity();
  4527. chunkStart = this.state.pos;
  4528. } else if (isNewLine(ch)) {
  4529. out += this.input.slice(chunkStart, this.state.pos);
  4530. out += this.jsxReadNewLine(false);
  4531. chunkStart = this.state.pos;
  4532. } else {
  4533. ++this.state.pos;
  4534. }
  4535. }
  4536. out += this.input.slice(chunkStart, this.state.pos++);
  4537. this.finishToken(134, out);
  4538. }
  4539. jsxReadEntity() {
  4540. const startPos = ++this.state.pos;
  4541. if (this.codePointAtPos(this.state.pos) === 35) {
  4542. ++this.state.pos;
  4543. let radix = 10;
  4544. if (this.codePointAtPos(this.state.pos) === 120) {
  4545. radix = 16;
  4546. ++this.state.pos;
  4547. }
  4548. const codePoint = this.readInt(radix, undefined, false, "bail");
  4549. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  4550. ++this.state.pos;
  4551. return String.fromCodePoint(codePoint);
  4552. }
  4553. } else {
  4554. let count = 0;
  4555. let semi = false;
  4556. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  4557. ++this.state.pos;
  4558. }
  4559. if (semi) {
  4560. const desc = this.input.slice(startPos, this.state.pos);
  4561. const entity = entities[desc];
  4562. ++this.state.pos;
  4563. if (entity) {
  4564. return entity;
  4565. }
  4566. }
  4567. }
  4568. this.state.pos = startPos;
  4569. return "&";
  4570. }
  4571. jsxReadWord() {
  4572. let ch;
  4573. const start = this.state.pos;
  4574. do {
  4575. ch = this.input.charCodeAt(++this.state.pos);
  4576. } while (isIdentifierChar(ch) || ch === 45);
  4577. this.finishToken(141, this.input.slice(start, this.state.pos));
  4578. }
  4579. jsxParseIdentifier() {
  4580. const node = this.startNode();
  4581. if (this.match(141)) {
  4582. node.name = this.state.value;
  4583. } else if (tokenIsKeyword(this.state.type)) {
  4584. node.name = tokenLabelName(this.state.type);
  4585. } else {
  4586. this.unexpected();
  4587. }
  4588. this.next();
  4589. return this.finishNode(node, "JSXIdentifier");
  4590. }
  4591. jsxParseNamespacedName() {
  4592. const startLoc = this.state.startLoc;
  4593. const name = this.jsxParseIdentifier();
  4594. if (!this.eat(14)) return name;
  4595. const node = this.startNodeAt(startLoc);
  4596. node.namespace = name;
  4597. node.name = this.jsxParseIdentifier();
  4598. return this.finishNode(node, "JSXNamespacedName");
  4599. }
  4600. jsxParseElementName() {
  4601. const startLoc = this.state.startLoc;
  4602. let node = this.jsxParseNamespacedName();
  4603. if (node.type === "JSXNamespacedName") {
  4604. return node;
  4605. }
  4606. while (this.eat(16)) {
  4607. const newNode = this.startNodeAt(startLoc);
  4608. newNode.object = node;
  4609. newNode.property = this.jsxParseIdentifier();
  4610. node = this.finishNode(newNode, "JSXMemberExpression");
  4611. }
  4612. return node;
  4613. }
  4614. jsxParseAttributeValue() {
  4615. let node;
  4616. switch (this.state.type) {
  4617. case 5:
  4618. node = this.startNode();
  4619. this.setContext(types.brace);
  4620. this.next();
  4621. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  4622. if (node.expression.type === "JSXEmptyExpression") {
  4623. this.raise(JsxErrors.AttributeIsEmpty, node);
  4624. }
  4625. return node;
  4626. case 143:
  4627. case 134:
  4628. return this.parseExprAtom();
  4629. default:
  4630. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  4631. }
  4632. }
  4633. jsxParseEmptyExpression() {
  4634. const node = this.startNodeAt(this.state.lastTokEndLoc);
  4635. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  4636. }
  4637. jsxParseSpreadChild(node) {
  4638. this.next();
  4639. node.expression = this.parseExpression();
  4640. this.setContext(types.j_expr);
  4641. this.state.canStartJSXElement = true;
  4642. this.expect(8);
  4643. return this.finishNode(node, "JSXSpreadChild");
  4644. }
  4645. jsxParseExpressionContainer(node, previousContext) {
  4646. if (this.match(8)) {
  4647. node.expression = this.jsxParseEmptyExpression();
  4648. } else {
  4649. const expression = this.parseExpression();
  4650. node.expression = expression;
  4651. }
  4652. this.setContext(previousContext);
  4653. this.state.canStartJSXElement = true;
  4654. this.expect(8);
  4655. return this.finishNode(node, "JSXExpressionContainer");
  4656. }
  4657. jsxParseAttribute() {
  4658. const node = this.startNode();
  4659. if (this.match(5)) {
  4660. this.setContext(types.brace);
  4661. this.next();
  4662. this.expect(21);
  4663. node.argument = this.parseMaybeAssignAllowIn();
  4664. this.setContext(types.j_oTag);
  4665. this.state.canStartJSXElement = true;
  4666. this.expect(8);
  4667. return this.finishNode(node, "JSXSpreadAttribute");
  4668. }
  4669. node.name = this.jsxParseNamespacedName();
  4670. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  4671. return this.finishNode(node, "JSXAttribute");
  4672. }
  4673. jsxParseOpeningElementAt(startLoc) {
  4674. const node = this.startNodeAt(startLoc);
  4675. if (this.eat(144)) {
  4676. return this.finishNode(node, "JSXOpeningFragment");
  4677. }
  4678. node.name = this.jsxParseElementName();
  4679. return this.jsxParseOpeningElementAfterName(node);
  4680. }
  4681. jsxParseOpeningElementAfterName(node) {
  4682. const attributes = [];
  4683. while (!this.match(56) && !this.match(144)) {
  4684. attributes.push(this.jsxParseAttribute());
  4685. }
  4686. node.attributes = attributes;
  4687. node.selfClosing = this.eat(56);
  4688. this.expect(144);
  4689. return this.finishNode(node, "JSXOpeningElement");
  4690. }
  4691. jsxParseClosingElementAt(startLoc) {
  4692. const node = this.startNodeAt(startLoc);
  4693. if (this.eat(144)) {
  4694. return this.finishNode(node, "JSXClosingFragment");
  4695. }
  4696. node.name = this.jsxParseElementName();
  4697. this.expect(144);
  4698. return this.finishNode(node, "JSXClosingElement");
  4699. }
  4700. jsxParseElementAt(startLoc) {
  4701. const node = this.startNodeAt(startLoc);
  4702. const children = [];
  4703. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  4704. let closingElement = null;
  4705. if (!openingElement.selfClosing) {
  4706. contents: for (;;) {
  4707. switch (this.state.type) {
  4708. case 143:
  4709. startLoc = this.state.startLoc;
  4710. this.next();
  4711. if (this.eat(56)) {
  4712. closingElement = this.jsxParseClosingElementAt(startLoc);
  4713. break contents;
  4714. }
  4715. children.push(this.jsxParseElementAt(startLoc));
  4716. break;
  4717. case 142:
  4718. children.push(this.parseLiteral(this.state.value, "JSXText"));
  4719. break;
  4720. case 5:
  4721. {
  4722. const node = this.startNode();
  4723. this.setContext(types.brace);
  4724. this.next();
  4725. if (this.match(21)) {
  4726. children.push(this.jsxParseSpreadChild(node));
  4727. } else {
  4728. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  4729. }
  4730. break;
  4731. }
  4732. default:
  4733. this.unexpected();
  4734. }
  4735. }
  4736. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  4737. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  4738. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  4739. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4740. openingTagName: getQualifiedJSXName(openingElement.name)
  4741. });
  4742. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  4743. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  4744. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4745. openingTagName: getQualifiedJSXName(openingElement.name)
  4746. });
  4747. }
  4748. }
  4749. }
  4750. if (isFragment(openingElement)) {
  4751. node.openingFragment = openingElement;
  4752. node.closingFragment = closingElement;
  4753. } else {
  4754. node.openingElement = openingElement;
  4755. node.closingElement = closingElement;
  4756. }
  4757. node.children = children;
  4758. if (this.match(47)) {
  4759. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  4760. }
  4761. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  4762. }
  4763. jsxParseElement() {
  4764. const startLoc = this.state.startLoc;
  4765. this.next();
  4766. return this.jsxParseElementAt(startLoc);
  4767. }
  4768. setContext(newContext) {
  4769. const {
  4770. context
  4771. } = this.state;
  4772. context[context.length - 1] = newContext;
  4773. }
  4774. parseExprAtom(refExpressionErrors) {
  4775. if (this.match(143)) {
  4776. return this.jsxParseElement();
  4777. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  4778. this.replaceToken(143);
  4779. return this.jsxParseElement();
  4780. } else {
  4781. return super.parseExprAtom(refExpressionErrors);
  4782. }
  4783. }
  4784. skipSpace() {
  4785. const curContext = this.curContext();
  4786. if (!curContext.preserveSpace) super.skipSpace();
  4787. }
  4788. getTokenFromCode(code) {
  4789. const context = this.curContext();
  4790. if (context === types.j_expr) {
  4791. this.jsxReadToken();
  4792. return;
  4793. }
  4794. if (context === types.j_oTag || context === types.j_cTag) {
  4795. if (isIdentifierStart(code)) {
  4796. this.jsxReadWord();
  4797. return;
  4798. }
  4799. if (code === 62) {
  4800. ++this.state.pos;
  4801. this.finishToken(144);
  4802. return;
  4803. }
  4804. if ((code === 34 || code === 39) && context === types.j_oTag) {
  4805. this.jsxReadString(code);
  4806. return;
  4807. }
  4808. }
  4809. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  4810. ++this.state.pos;
  4811. this.finishToken(143);
  4812. return;
  4813. }
  4814. super.getTokenFromCode(code);
  4815. }
  4816. updateContext(prevType) {
  4817. const {
  4818. context,
  4819. type
  4820. } = this.state;
  4821. if (type === 56 && prevType === 143) {
  4822. context.splice(-2, 2, types.j_cTag);
  4823. this.state.canStartJSXElement = false;
  4824. } else if (type === 143) {
  4825. context.push(types.j_oTag);
  4826. } else if (type === 144) {
  4827. const out = context[context.length - 1];
  4828. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  4829. context.pop();
  4830. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  4831. } else {
  4832. this.setContext(types.j_expr);
  4833. this.state.canStartJSXElement = true;
  4834. }
  4835. } else {
  4836. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  4837. }
  4838. }
  4839. };
  4840. class TypeScriptScope extends Scope {
  4841. constructor(...args) {
  4842. super(...args);
  4843. this.tsNames = new Map();
  4844. }
  4845. }
  4846. class TypeScriptScopeHandler extends ScopeHandler {
  4847. constructor(...args) {
  4848. super(...args);
  4849. this.importsStack = [];
  4850. }
  4851. createScope(flags) {
  4852. this.importsStack.push(new Set());
  4853. return new TypeScriptScope(flags);
  4854. }
  4855. enter(flags) {
  4856. if (flags === 1024) {
  4857. this.importsStack.push(new Set());
  4858. }
  4859. super.enter(flags);
  4860. }
  4861. exit() {
  4862. const flags = super.exit();
  4863. if (flags === 1024) {
  4864. this.importsStack.pop();
  4865. }
  4866. return flags;
  4867. }
  4868. hasImport(name, allowShadow) {
  4869. const len = this.importsStack.length;
  4870. if (this.importsStack[len - 1].has(name)) {
  4871. return true;
  4872. }
  4873. if (!allowShadow && len > 1) {
  4874. for (let i = 0; i < len - 1; i++) {
  4875. if (this.importsStack[i].has(name)) return true;
  4876. }
  4877. }
  4878. return false;
  4879. }
  4880. declareName(name, bindingType, loc) {
  4881. if (bindingType & 4096) {
  4882. if (this.hasImport(name, true)) {
  4883. this.parser.raise(Errors.VarRedeclaration, loc, {
  4884. identifierName: name
  4885. });
  4886. }
  4887. this.importsStack[this.importsStack.length - 1].add(name);
  4888. return;
  4889. }
  4890. const scope = this.currentScope();
  4891. let type = scope.tsNames.get(name) || 0;
  4892. if (bindingType & 1024) {
  4893. this.maybeExportDefined(scope, name);
  4894. scope.tsNames.set(name, type | 16);
  4895. return;
  4896. }
  4897. super.declareName(name, bindingType, loc);
  4898. if (bindingType & 2) {
  4899. if (!(bindingType & 1)) {
  4900. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4901. this.maybeExportDefined(scope, name);
  4902. }
  4903. type = type | 1;
  4904. }
  4905. if (bindingType & 256) {
  4906. type = type | 2;
  4907. }
  4908. if (bindingType & 512) {
  4909. type = type | 4;
  4910. }
  4911. if (bindingType & 128) {
  4912. type = type | 8;
  4913. }
  4914. if (type) scope.tsNames.set(name, type);
  4915. }
  4916. isRedeclaredInScope(scope, name, bindingType) {
  4917. const type = scope.tsNames.get(name);
  4918. if ((type & 2) > 0) {
  4919. if (bindingType & 256) {
  4920. const isConst = !!(bindingType & 512);
  4921. const wasConst = (type & 4) > 0;
  4922. return isConst !== wasConst;
  4923. }
  4924. return true;
  4925. }
  4926. if (bindingType & 128 && (type & 8) > 0) {
  4927. if (scope.names.get(name) & 2) {
  4928. return !!(bindingType & 1);
  4929. } else {
  4930. return false;
  4931. }
  4932. }
  4933. if (bindingType & 2 && (type & 1) > 0) {
  4934. return true;
  4935. }
  4936. return super.isRedeclaredInScope(scope, name, bindingType);
  4937. }
  4938. checkLocalExport(id) {
  4939. const {
  4940. name
  4941. } = id;
  4942. if (this.hasImport(name)) return;
  4943. const len = this.scopeStack.length;
  4944. for (let i = len - 1; i >= 0; i--) {
  4945. const scope = this.scopeStack[i];
  4946. const type = scope.tsNames.get(name);
  4947. if ((type & 1) > 0 || (type & 16) > 0) {
  4948. return;
  4949. }
  4950. }
  4951. super.checkLocalExport(id);
  4952. }
  4953. }
  4954. class ProductionParameterHandler {
  4955. constructor() {
  4956. this.stacks = [];
  4957. }
  4958. enter(flags) {
  4959. this.stacks.push(flags);
  4960. }
  4961. exit() {
  4962. this.stacks.pop();
  4963. }
  4964. currentFlags() {
  4965. return this.stacks[this.stacks.length - 1];
  4966. }
  4967. get hasAwait() {
  4968. return (this.currentFlags() & 2) > 0;
  4969. }
  4970. get hasYield() {
  4971. return (this.currentFlags() & 1) > 0;
  4972. }
  4973. get hasReturn() {
  4974. return (this.currentFlags() & 4) > 0;
  4975. }
  4976. get hasIn() {
  4977. return (this.currentFlags() & 8) > 0;
  4978. }
  4979. }
  4980. function functionFlags(isAsync, isGenerator) {
  4981. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  4982. }
  4983. class BaseParser {
  4984. constructor() {
  4985. this.sawUnambiguousESM = false;
  4986. this.ambiguousScriptDifferentAst = false;
  4987. }
  4988. sourceToOffsetPos(sourcePos) {
  4989. return sourcePos + this.startIndex;
  4990. }
  4991. offsetToSourcePos(offsetPos) {
  4992. return offsetPos - this.startIndex;
  4993. }
  4994. hasPlugin(pluginConfig) {
  4995. if (typeof pluginConfig === "string") {
  4996. return this.plugins.has(pluginConfig);
  4997. } else {
  4998. const [pluginName, pluginOptions] = pluginConfig;
  4999. if (!this.hasPlugin(pluginName)) {
  5000. return false;
  5001. }
  5002. const actualOptions = this.plugins.get(pluginName);
  5003. for (const key of Object.keys(pluginOptions)) {
  5004. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  5005. return false;
  5006. }
  5007. }
  5008. return true;
  5009. }
  5010. }
  5011. getPluginOption(plugin, name) {
  5012. var _this$plugins$get;
  5013. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  5014. }
  5015. }
  5016. function setTrailingComments(node, comments) {
  5017. if (node.trailingComments === undefined) {
  5018. node.trailingComments = comments;
  5019. } else {
  5020. node.trailingComments.unshift(...comments);
  5021. }
  5022. }
  5023. function setLeadingComments(node, comments) {
  5024. if (node.leadingComments === undefined) {
  5025. node.leadingComments = comments;
  5026. } else {
  5027. node.leadingComments.unshift(...comments);
  5028. }
  5029. }
  5030. function setInnerComments(node, comments) {
  5031. if (node.innerComments === undefined) {
  5032. node.innerComments = comments;
  5033. } else {
  5034. node.innerComments.unshift(...comments);
  5035. }
  5036. }
  5037. function adjustInnerComments(node, elements, commentWS) {
  5038. let lastElement = null;
  5039. let i = elements.length;
  5040. while (lastElement === null && i > 0) {
  5041. lastElement = elements[--i];
  5042. }
  5043. if (lastElement === null || lastElement.start > commentWS.start) {
  5044. setInnerComments(node, commentWS.comments);
  5045. } else {
  5046. setTrailingComments(lastElement, commentWS.comments);
  5047. }
  5048. }
  5049. class CommentsParser extends BaseParser {
  5050. addComment(comment) {
  5051. if (this.filename) comment.loc.filename = this.filename;
  5052. const {
  5053. commentsLen
  5054. } = this.state;
  5055. if (this.comments.length !== commentsLen) {
  5056. this.comments.length = commentsLen;
  5057. }
  5058. this.comments.push(comment);
  5059. this.state.commentsLen++;
  5060. }
  5061. processComment(node) {
  5062. const {
  5063. commentStack
  5064. } = this.state;
  5065. const commentStackLength = commentStack.length;
  5066. if (commentStackLength === 0) return;
  5067. let i = commentStackLength - 1;
  5068. const lastCommentWS = commentStack[i];
  5069. if (lastCommentWS.start === node.end) {
  5070. lastCommentWS.leadingNode = node;
  5071. i--;
  5072. }
  5073. const {
  5074. start: nodeStart
  5075. } = node;
  5076. for (; i >= 0; i--) {
  5077. const commentWS = commentStack[i];
  5078. const commentEnd = commentWS.end;
  5079. if (commentEnd > nodeStart) {
  5080. commentWS.containingNode = node;
  5081. this.finalizeComment(commentWS);
  5082. commentStack.splice(i, 1);
  5083. } else {
  5084. if (commentEnd === nodeStart) {
  5085. commentWS.trailingNode = node;
  5086. }
  5087. break;
  5088. }
  5089. }
  5090. }
  5091. finalizeComment(commentWS) {
  5092. var _node$options;
  5093. const {
  5094. comments
  5095. } = commentWS;
  5096. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  5097. if (commentWS.leadingNode !== null) {
  5098. setTrailingComments(commentWS.leadingNode, comments);
  5099. }
  5100. if (commentWS.trailingNode !== null) {
  5101. setLeadingComments(commentWS.trailingNode, comments);
  5102. }
  5103. } else {
  5104. const node = commentWS.containingNode;
  5105. const commentStart = commentWS.start;
  5106. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  5107. switch (node.type) {
  5108. case "ObjectExpression":
  5109. case "ObjectPattern":
  5110. adjustInnerComments(node, node.properties, commentWS);
  5111. break;
  5112. case "CallExpression":
  5113. case "NewExpression":
  5114. case "OptionalCallExpression":
  5115. adjustInnerComments(node, node.arguments, commentWS);
  5116. break;
  5117. case "ImportExpression":
  5118. adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
  5119. break;
  5120. case "FunctionDeclaration":
  5121. case "FunctionExpression":
  5122. case "ArrowFunctionExpression":
  5123. case "ObjectMethod":
  5124. case "ClassMethod":
  5125. case "ClassPrivateMethod":
  5126. case "TSTypeParameterDeclaration":
  5127. adjustInnerComments(node, node.params, commentWS);
  5128. break;
  5129. case "ArrayExpression":
  5130. case "ArrayPattern":
  5131. adjustInnerComments(node, node.elements, commentWS);
  5132. break;
  5133. case "ExportNamedDeclaration":
  5134. case "ImportDeclaration":
  5135. adjustInnerComments(node, node.specifiers, commentWS);
  5136. break;
  5137. case "TSEnumDeclaration":
  5138. adjustInnerComments(node, node.members, commentWS);
  5139. break;
  5140. case "TSEnumBody":
  5141. adjustInnerComments(node, node.members, commentWS);
  5142. break;
  5143. case "TSInterfaceBody":
  5144. adjustInnerComments(node, node.body, commentWS);
  5145. break;
  5146. default:
  5147. {
  5148. if (node.type === "RecordExpression") {
  5149. adjustInnerComments(node, node.properties, commentWS);
  5150. break;
  5151. }
  5152. if (node.type === "TupleExpression") {
  5153. adjustInnerComments(node, node.elements, commentWS);
  5154. break;
  5155. }
  5156. setInnerComments(node, comments);
  5157. }
  5158. }
  5159. } else {
  5160. setInnerComments(node, comments);
  5161. }
  5162. }
  5163. }
  5164. finalizeRemainingComments() {
  5165. const {
  5166. commentStack
  5167. } = this.state;
  5168. for (let i = commentStack.length - 1; i >= 0; i--) {
  5169. this.finalizeComment(commentStack[i]);
  5170. }
  5171. this.state.commentStack = [];
  5172. }
  5173. resetPreviousNodeTrailingComments(node) {
  5174. const {
  5175. commentStack
  5176. } = this.state;
  5177. const {
  5178. length
  5179. } = commentStack;
  5180. if (length === 0) return;
  5181. const commentWS = commentStack[length - 1];
  5182. if (commentWS.leadingNode === node) {
  5183. commentWS.leadingNode = null;
  5184. }
  5185. }
  5186. takeSurroundingComments(node, start, end) {
  5187. const {
  5188. commentStack
  5189. } = this.state;
  5190. const commentStackLength = commentStack.length;
  5191. if (commentStackLength === 0) return;
  5192. let i = commentStackLength - 1;
  5193. for (; i >= 0; i--) {
  5194. const commentWS = commentStack[i];
  5195. const commentEnd = commentWS.end;
  5196. const commentStart = commentWS.start;
  5197. if (commentStart === end) {
  5198. commentWS.leadingNode = node;
  5199. } else if (commentEnd === start) {
  5200. commentWS.trailingNode = node;
  5201. } else if (commentEnd < start) {
  5202. break;
  5203. }
  5204. }
  5205. }
  5206. }
  5207. class State {
  5208. constructor() {
  5209. this.flags = 1024;
  5210. this.startIndex = void 0;
  5211. this.curLine = void 0;
  5212. this.lineStart = void 0;
  5213. this.startLoc = void 0;
  5214. this.endLoc = void 0;
  5215. this.errors = [];
  5216. this.potentialArrowAt = -1;
  5217. this.noArrowAt = [];
  5218. this.noArrowParamsConversionAt = [];
  5219. this.topicContext = {
  5220. maxNumOfResolvableTopics: 0,
  5221. maxTopicIndex: null
  5222. };
  5223. this.labels = [];
  5224. this.commentsLen = 0;
  5225. this.commentStack = [];
  5226. this.pos = 0;
  5227. this.type = 140;
  5228. this.value = null;
  5229. this.start = 0;
  5230. this.end = 0;
  5231. this.lastTokEndLoc = null;
  5232. this.lastTokStartLoc = null;
  5233. this.context = [types.brace];
  5234. this.firstInvalidTemplateEscapePos = null;
  5235. this.strictErrors = new Map();
  5236. this.tokensLength = 0;
  5237. }
  5238. get strict() {
  5239. return (this.flags & 1) > 0;
  5240. }
  5241. set strict(v) {
  5242. if (v) this.flags |= 1;else this.flags &= -2;
  5243. }
  5244. init({
  5245. strictMode,
  5246. sourceType,
  5247. startIndex,
  5248. startLine,
  5249. startColumn
  5250. }) {
  5251. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  5252. this.startIndex = startIndex;
  5253. this.curLine = startLine;
  5254. this.lineStart = -startColumn;
  5255. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  5256. }
  5257. get maybeInArrowParameters() {
  5258. return (this.flags & 2) > 0;
  5259. }
  5260. set maybeInArrowParameters(v) {
  5261. if (v) this.flags |= 2;else this.flags &= -3;
  5262. }
  5263. get inType() {
  5264. return (this.flags & 4) > 0;
  5265. }
  5266. set inType(v) {
  5267. if (v) this.flags |= 4;else this.flags &= -5;
  5268. }
  5269. get noAnonFunctionType() {
  5270. return (this.flags & 8) > 0;
  5271. }
  5272. set noAnonFunctionType(v) {
  5273. if (v) this.flags |= 8;else this.flags &= -9;
  5274. }
  5275. get hasFlowComment() {
  5276. return (this.flags & 16) > 0;
  5277. }
  5278. set hasFlowComment(v) {
  5279. if (v) this.flags |= 16;else this.flags &= -17;
  5280. }
  5281. get isAmbientContext() {
  5282. return (this.flags & 32) > 0;
  5283. }
  5284. set isAmbientContext(v) {
  5285. if (v) this.flags |= 32;else this.flags &= -33;
  5286. }
  5287. get inAbstractClass() {
  5288. return (this.flags & 64) > 0;
  5289. }
  5290. set inAbstractClass(v) {
  5291. if (v) this.flags |= 64;else this.flags &= -65;
  5292. }
  5293. get inDisallowConditionalTypesContext() {
  5294. return (this.flags & 128) > 0;
  5295. }
  5296. set inDisallowConditionalTypesContext(v) {
  5297. if (v) this.flags |= 128;else this.flags &= -129;
  5298. }
  5299. get soloAwait() {
  5300. return (this.flags & 256) > 0;
  5301. }
  5302. set soloAwait(v) {
  5303. if (v) this.flags |= 256;else this.flags &= -257;
  5304. }
  5305. get inFSharpPipelineDirectBody() {
  5306. return (this.flags & 512) > 0;
  5307. }
  5308. set inFSharpPipelineDirectBody(v) {
  5309. if (v) this.flags |= 512;else this.flags &= -513;
  5310. }
  5311. get canStartJSXElement() {
  5312. return (this.flags & 1024) > 0;
  5313. }
  5314. set canStartJSXElement(v) {
  5315. if (v) this.flags |= 1024;else this.flags &= -1025;
  5316. }
  5317. get containsEsc() {
  5318. return (this.flags & 2048) > 0;
  5319. }
  5320. set containsEsc(v) {
  5321. if (v) this.flags |= 2048;else this.flags &= -2049;
  5322. }
  5323. get hasTopLevelAwait() {
  5324. return (this.flags & 4096) > 0;
  5325. }
  5326. set hasTopLevelAwait(v) {
  5327. if (v) this.flags |= 4096;else this.flags &= -4097;
  5328. }
  5329. curPosition() {
  5330. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  5331. }
  5332. clone() {
  5333. const state = new State();
  5334. state.flags = this.flags;
  5335. state.startIndex = this.startIndex;
  5336. state.curLine = this.curLine;
  5337. state.lineStart = this.lineStart;
  5338. state.startLoc = this.startLoc;
  5339. state.endLoc = this.endLoc;
  5340. state.errors = this.errors.slice();
  5341. state.potentialArrowAt = this.potentialArrowAt;
  5342. state.noArrowAt = this.noArrowAt.slice();
  5343. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  5344. state.topicContext = this.topicContext;
  5345. state.labels = this.labels.slice();
  5346. state.commentsLen = this.commentsLen;
  5347. state.commentStack = this.commentStack.slice();
  5348. state.pos = this.pos;
  5349. state.type = this.type;
  5350. state.value = this.value;
  5351. state.start = this.start;
  5352. state.end = this.end;
  5353. state.lastTokEndLoc = this.lastTokEndLoc;
  5354. state.lastTokStartLoc = this.lastTokStartLoc;
  5355. state.context = this.context.slice();
  5356. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  5357. state.strictErrors = this.strictErrors;
  5358. state.tokensLength = this.tokensLength;
  5359. return state;
  5360. }
  5361. }
  5362. var _isDigit = function isDigit(code) {
  5363. return code >= 48 && code <= 57;
  5364. };
  5365. const forbiddenNumericSeparatorSiblings = {
  5366. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  5367. hex: new Set([46, 88, 95, 120])
  5368. };
  5369. const isAllowedNumericSeparatorSibling = {
  5370. bin: ch => ch === 48 || ch === 49,
  5371. oct: ch => ch >= 48 && ch <= 55,
  5372. dec: ch => ch >= 48 && ch <= 57,
  5373. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  5374. };
  5375. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  5376. const initialPos = pos;
  5377. const initialLineStart = lineStart;
  5378. const initialCurLine = curLine;
  5379. let out = "";
  5380. let firstInvalidLoc = null;
  5381. let chunkStart = pos;
  5382. const {
  5383. length
  5384. } = input;
  5385. for (;;) {
  5386. if (pos >= length) {
  5387. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5388. out += input.slice(chunkStart, pos);
  5389. break;
  5390. }
  5391. const ch = input.charCodeAt(pos);
  5392. if (isStringEnd(type, ch, input, pos)) {
  5393. out += input.slice(chunkStart, pos);
  5394. break;
  5395. }
  5396. if (ch === 92) {
  5397. out += input.slice(chunkStart, pos);
  5398. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  5399. if (res.ch === null && !firstInvalidLoc) {
  5400. firstInvalidLoc = {
  5401. pos,
  5402. lineStart,
  5403. curLine
  5404. };
  5405. } else {
  5406. out += res.ch;
  5407. }
  5408. ({
  5409. pos,
  5410. lineStart,
  5411. curLine
  5412. } = res);
  5413. chunkStart = pos;
  5414. } else if (ch === 8232 || ch === 8233) {
  5415. ++pos;
  5416. ++curLine;
  5417. lineStart = pos;
  5418. } else if (ch === 10 || ch === 13) {
  5419. if (type === "template") {
  5420. out += input.slice(chunkStart, pos) + "\n";
  5421. ++pos;
  5422. if (ch === 13 && input.charCodeAt(pos) === 10) {
  5423. ++pos;
  5424. }
  5425. ++curLine;
  5426. chunkStart = lineStart = pos;
  5427. } else {
  5428. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5429. }
  5430. } else {
  5431. ++pos;
  5432. }
  5433. }
  5434. return {
  5435. pos,
  5436. str: out,
  5437. firstInvalidLoc,
  5438. lineStart,
  5439. curLine,
  5440. containsInvalid: !!firstInvalidLoc
  5441. };
  5442. }
  5443. function isStringEnd(type, ch, input, pos) {
  5444. if (type === "template") {
  5445. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  5446. }
  5447. return ch === (type === "double" ? 34 : 39);
  5448. }
  5449. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  5450. const throwOnInvalid = !inTemplate;
  5451. pos++;
  5452. const res = ch => ({
  5453. pos,
  5454. ch,
  5455. lineStart,
  5456. curLine
  5457. });
  5458. const ch = input.charCodeAt(pos++);
  5459. switch (ch) {
  5460. case 110:
  5461. return res("\n");
  5462. case 114:
  5463. return res("\r");
  5464. case 120:
  5465. {
  5466. let code;
  5467. ({
  5468. code,
  5469. pos
  5470. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  5471. return res(code === null ? null : String.fromCharCode(code));
  5472. }
  5473. case 117:
  5474. {
  5475. let code;
  5476. ({
  5477. code,
  5478. pos
  5479. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  5480. return res(code === null ? null : String.fromCodePoint(code));
  5481. }
  5482. case 116:
  5483. return res("\t");
  5484. case 98:
  5485. return res("\b");
  5486. case 118:
  5487. return res("\u000b");
  5488. case 102:
  5489. return res("\f");
  5490. case 13:
  5491. if (input.charCodeAt(pos) === 10) {
  5492. ++pos;
  5493. }
  5494. case 10:
  5495. lineStart = pos;
  5496. ++curLine;
  5497. case 8232:
  5498. case 8233:
  5499. return res("");
  5500. case 56:
  5501. case 57:
  5502. if (inTemplate) {
  5503. return res(null);
  5504. } else {
  5505. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  5506. }
  5507. default:
  5508. if (ch >= 48 && ch <= 55) {
  5509. const startPos = pos - 1;
  5510. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  5511. let octalStr = match[0];
  5512. let octal = parseInt(octalStr, 8);
  5513. if (octal > 255) {
  5514. octalStr = octalStr.slice(0, -1);
  5515. octal = parseInt(octalStr, 8);
  5516. }
  5517. pos += octalStr.length - 1;
  5518. const next = input.charCodeAt(pos);
  5519. if (octalStr !== "0" || next === 56 || next === 57) {
  5520. if (inTemplate) {
  5521. return res(null);
  5522. } else {
  5523. errors.strictNumericEscape(startPos, lineStart, curLine);
  5524. }
  5525. }
  5526. return res(String.fromCharCode(octal));
  5527. }
  5528. return res(String.fromCharCode(ch));
  5529. }
  5530. }
  5531. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  5532. const initialPos = pos;
  5533. let n;
  5534. ({
  5535. n,
  5536. pos
  5537. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  5538. if (n === null) {
  5539. if (throwOnInvalid) {
  5540. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  5541. } else {
  5542. pos = initialPos - 1;
  5543. }
  5544. }
  5545. return {
  5546. code: n,
  5547. pos
  5548. };
  5549. }
  5550. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  5551. const start = pos;
  5552. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  5553. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  5554. let invalid = false;
  5555. let total = 0;
  5556. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  5557. const code = input.charCodeAt(pos);
  5558. let val;
  5559. if (code === 95 && allowNumSeparator !== "bail") {
  5560. const prev = input.charCodeAt(pos - 1);
  5561. const next = input.charCodeAt(pos + 1);
  5562. if (!allowNumSeparator) {
  5563. if (bailOnError) return {
  5564. n: null,
  5565. pos
  5566. };
  5567. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  5568. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  5569. if (bailOnError) return {
  5570. n: null,
  5571. pos
  5572. };
  5573. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  5574. }
  5575. ++pos;
  5576. continue;
  5577. }
  5578. if (code >= 97) {
  5579. val = code - 97 + 10;
  5580. } else if (code >= 65) {
  5581. val = code - 65 + 10;
  5582. } else if (_isDigit(code)) {
  5583. val = code - 48;
  5584. } else {
  5585. val = Infinity;
  5586. }
  5587. if (val >= radix) {
  5588. if (val <= 9 && bailOnError) {
  5589. return {
  5590. n: null,
  5591. pos
  5592. };
  5593. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  5594. val = 0;
  5595. } else if (forceLen) {
  5596. val = 0;
  5597. invalid = true;
  5598. } else {
  5599. break;
  5600. }
  5601. }
  5602. ++pos;
  5603. total = total * radix + val;
  5604. }
  5605. if (pos === start || len != null && pos - start !== len || invalid) {
  5606. return {
  5607. n: null,
  5608. pos
  5609. };
  5610. }
  5611. return {
  5612. n: total,
  5613. pos
  5614. };
  5615. }
  5616. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  5617. const ch = input.charCodeAt(pos);
  5618. let code;
  5619. if (ch === 123) {
  5620. ++pos;
  5621. ({
  5622. code,
  5623. pos
  5624. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  5625. ++pos;
  5626. if (code !== null && code > 0x10ffff) {
  5627. if (throwOnInvalid) {
  5628. errors.invalidCodePoint(pos, lineStart, curLine);
  5629. } else {
  5630. return {
  5631. code: null,
  5632. pos
  5633. };
  5634. }
  5635. }
  5636. } else {
  5637. ({
  5638. code,
  5639. pos
  5640. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  5641. }
  5642. return {
  5643. code,
  5644. pos
  5645. };
  5646. }
  5647. function buildPosition(pos, lineStart, curLine) {
  5648. return new Position(curLine, pos - lineStart, pos);
  5649. }
  5650. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  5651. class Token {
  5652. constructor(state) {
  5653. const startIndex = state.startIndex || 0;
  5654. this.type = state.type;
  5655. this.value = state.value;
  5656. this.start = startIndex + state.start;
  5657. this.end = startIndex + state.end;
  5658. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  5659. }
  5660. }
  5661. class Tokenizer extends CommentsParser {
  5662. constructor(options, input) {
  5663. super();
  5664. this.isLookahead = void 0;
  5665. this.tokens = [];
  5666. this.errorHandlers_readInt = {
  5667. invalidDigit: (pos, lineStart, curLine, radix) => {
  5668. if (!(this.optionFlags & 2048)) return false;
  5669. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  5670. radix
  5671. });
  5672. return true;
  5673. },
  5674. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  5675. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  5676. };
  5677. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  5678. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  5679. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  5680. });
  5681. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  5682. strictNumericEscape: (pos, lineStart, curLine) => {
  5683. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  5684. },
  5685. unterminated: (pos, lineStart, curLine) => {
  5686. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  5687. }
  5688. });
  5689. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  5690. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  5691. unterminated: (pos, lineStart, curLine) => {
  5692. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  5693. }
  5694. });
  5695. this.state = new State();
  5696. this.state.init(options);
  5697. this.input = input;
  5698. this.length = input.length;
  5699. this.comments = [];
  5700. this.isLookahead = false;
  5701. }
  5702. pushToken(token) {
  5703. this.tokens.length = this.state.tokensLength;
  5704. this.tokens.push(token);
  5705. ++this.state.tokensLength;
  5706. }
  5707. next() {
  5708. this.checkKeywordEscapes();
  5709. if (this.optionFlags & 256) {
  5710. this.pushToken(new Token(this.state));
  5711. }
  5712. this.state.lastTokEndLoc = this.state.endLoc;
  5713. this.state.lastTokStartLoc = this.state.startLoc;
  5714. this.nextToken();
  5715. }
  5716. eat(type) {
  5717. if (this.match(type)) {
  5718. this.next();
  5719. return true;
  5720. } else {
  5721. return false;
  5722. }
  5723. }
  5724. match(type) {
  5725. return this.state.type === type;
  5726. }
  5727. createLookaheadState(state) {
  5728. return {
  5729. pos: state.pos,
  5730. value: null,
  5731. type: state.type,
  5732. start: state.start,
  5733. end: state.end,
  5734. context: [this.curContext()],
  5735. inType: state.inType,
  5736. startLoc: state.startLoc,
  5737. lastTokEndLoc: state.lastTokEndLoc,
  5738. curLine: state.curLine,
  5739. lineStart: state.lineStart,
  5740. curPosition: state.curPosition
  5741. };
  5742. }
  5743. lookahead() {
  5744. const old = this.state;
  5745. this.state = this.createLookaheadState(old);
  5746. this.isLookahead = true;
  5747. this.nextToken();
  5748. this.isLookahead = false;
  5749. const curr = this.state;
  5750. this.state = old;
  5751. return curr;
  5752. }
  5753. nextTokenStart() {
  5754. return this.nextTokenStartSince(this.state.pos);
  5755. }
  5756. nextTokenStartSince(pos) {
  5757. skipWhiteSpace.lastIndex = pos;
  5758. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  5759. }
  5760. lookaheadCharCode() {
  5761. return this.lookaheadCharCodeSince(this.state.pos);
  5762. }
  5763. lookaheadCharCodeSince(pos) {
  5764. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  5765. }
  5766. nextTokenInLineStart() {
  5767. return this.nextTokenInLineStartSince(this.state.pos);
  5768. }
  5769. nextTokenInLineStartSince(pos) {
  5770. skipWhiteSpaceInLine.lastIndex = pos;
  5771. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  5772. }
  5773. lookaheadInLineCharCode() {
  5774. return this.input.charCodeAt(this.nextTokenInLineStart());
  5775. }
  5776. codePointAtPos(pos) {
  5777. let cp = this.input.charCodeAt(pos);
  5778. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  5779. const trail = this.input.charCodeAt(pos);
  5780. if ((trail & 0xfc00) === 0xdc00) {
  5781. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  5782. }
  5783. }
  5784. return cp;
  5785. }
  5786. setStrict(strict) {
  5787. this.state.strict = strict;
  5788. if (strict) {
  5789. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  5790. this.state.strictErrors.clear();
  5791. }
  5792. }
  5793. curContext() {
  5794. return this.state.context[this.state.context.length - 1];
  5795. }
  5796. nextToken() {
  5797. this.skipSpace();
  5798. this.state.start = this.state.pos;
  5799. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  5800. if (this.state.pos >= this.length) {
  5801. this.finishToken(140);
  5802. return;
  5803. }
  5804. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  5805. }
  5806. skipBlockComment(commentEnd) {
  5807. let startLoc;
  5808. if (!this.isLookahead) startLoc = this.state.curPosition();
  5809. const start = this.state.pos;
  5810. const end = this.input.indexOf(commentEnd, start + 2);
  5811. if (end === -1) {
  5812. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5813. }
  5814. this.state.pos = end + commentEnd.length;
  5815. lineBreakG.lastIndex = start + 2;
  5816. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  5817. ++this.state.curLine;
  5818. this.state.lineStart = lineBreakG.lastIndex;
  5819. }
  5820. if (this.isLookahead) return;
  5821. const comment = {
  5822. type: "CommentBlock",
  5823. value: this.input.slice(start + 2, end),
  5824. start: this.sourceToOffsetPos(start),
  5825. end: this.sourceToOffsetPos(end + commentEnd.length),
  5826. loc: new SourceLocation(startLoc, this.state.curPosition())
  5827. };
  5828. if (this.optionFlags & 256) this.pushToken(comment);
  5829. return comment;
  5830. }
  5831. skipLineComment(startSkip) {
  5832. const start = this.state.pos;
  5833. let startLoc;
  5834. if (!this.isLookahead) startLoc = this.state.curPosition();
  5835. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  5836. if (this.state.pos < this.length) {
  5837. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  5838. ch = this.input.charCodeAt(this.state.pos);
  5839. }
  5840. }
  5841. if (this.isLookahead) return;
  5842. const end = this.state.pos;
  5843. const value = this.input.slice(start + startSkip, end);
  5844. const comment = {
  5845. type: "CommentLine",
  5846. value,
  5847. start: this.sourceToOffsetPos(start),
  5848. end: this.sourceToOffsetPos(end),
  5849. loc: new SourceLocation(startLoc, this.state.curPosition())
  5850. };
  5851. if (this.optionFlags & 256) this.pushToken(comment);
  5852. return comment;
  5853. }
  5854. skipSpace() {
  5855. const spaceStart = this.state.pos;
  5856. const comments = this.optionFlags & 4096 ? [] : null;
  5857. loop: while (this.state.pos < this.length) {
  5858. const ch = this.input.charCodeAt(this.state.pos);
  5859. switch (ch) {
  5860. case 32:
  5861. case 160:
  5862. case 9:
  5863. ++this.state.pos;
  5864. break;
  5865. case 13:
  5866. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  5867. ++this.state.pos;
  5868. }
  5869. case 10:
  5870. case 8232:
  5871. case 8233:
  5872. ++this.state.pos;
  5873. ++this.state.curLine;
  5874. this.state.lineStart = this.state.pos;
  5875. break;
  5876. case 47:
  5877. switch (this.input.charCodeAt(this.state.pos + 1)) {
  5878. case 42:
  5879. {
  5880. const comment = this.skipBlockComment("*/");
  5881. if (comment !== undefined) {
  5882. this.addComment(comment);
  5883. comments == null || comments.push(comment);
  5884. }
  5885. break;
  5886. }
  5887. case 47:
  5888. {
  5889. const comment = this.skipLineComment(2);
  5890. if (comment !== undefined) {
  5891. this.addComment(comment);
  5892. comments == null || comments.push(comment);
  5893. }
  5894. break;
  5895. }
  5896. default:
  5897. break loop;
  5898. }
  5899. break;
  5900. default:
  5901. if (isWhitespace(ch)) {
  5902. ++this.state.pos;
  5903. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  5904. const pos = this.state.pos;
  5905. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  5906. const comment = this.skipLineComment(3);
  5907. if (comment !== undefined) {
  5908. this.addComment(comment);
  5909. comments == null || comments.push(comment);
  5910. }
  5911. } else {
  5912. break loop;
  5913. }
  5914. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  5915. const pos = this.state.pos;
  5916. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  5917. const comment = this.skipLineComment(4);
  5918. if (comment !== undefined) {
  5919. this.addComment(comment);
  5920. comments == null || comments.push(comment);
  5921. }
  5922. } else {
  5923. break loop;
  5924. }
  5925. } else {
  5926. break loop;
  5927. }
  5928. }
  5929. }
  5930. if ((comments == null ? void 0 : comments.length) > 0) {
  5931. const end = this.state.pos;
  5932. const commentWhitespace = {
  5933. start: this.sourceToOffsetPos(spaceStart),
  5934. end: this.sourceToOffsetPos(end),
  5935. comments: comments,
  5936. leadingNode: null,
  5937. trailingNode: null,
  5938. containingNode: null
  5939. };
  5940. this.state.commentStack.push(commentWhitespace);
  5941. }
  5942. }
  5943. finishToken(type, val) {
  5944. this.state.end = this.state.pos;
  5945. this.state.endLoc = this.state.curPosition();
  5946. const prevType = this.state.type;
  5947. this.state.type = type;
  5948. this.state.value = val;
  5949. if (!this.isLookahead) {
  5950. this.updateContext(prevType);
  5951. }
  5952. }
  5953. replaceToken(type) {
  5954. this.state.type = type;
  5955. this.updateContext();
  5956. }
  5957. readToken_numberSign() {
  5958. if (this.state.pos === 0 && this.readToken_interpreter()) {
  5959. return;
  5960. }
  5961. const nextPos = this.state.pos + 1;
  5962. const next = this.codePointAtPos(nextPos);
  5963. if (next >= 48 && next <= 57) {
  5964. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  5965. }
  5966. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  5967. this.expectPlugin("recordAndTuple");
  5968. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  5969. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  5970. }
  5971. this.state.pos += 2;
  5972. if (next === 123) {
  5973. this.finishToken(7);
  5974. } else {
  5975. this.finishToken(1);
  5976. }
  5977. } else if (isIdentifierStart(next)) {
  5978. ++this.state.pos;
  5979. this.finishToken(139, this.readWord1(next));
  5980. } else if (next === 92) {
  5981. ++this.state.pos;
  5982. this.finishToken(139, this.readWord1());
  5983. } else {
  5984. this.finishOp(27, 1);
  5985. }
  5986. }
  5987. readToken_dot() {
  5988. const next = this.input.charCodeAt(this.state.pos + 1);
  5989. if (next >= 48 && next <= 57) {
  5990. this.readNumber(true);
  5991. return;
  5992. }
  5993. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  5994. this.state.pos += 3;
  5995. this.finishToken(21);
  5996. } else {
  5997. ++this.state.pos;
  5998. this.finishToken(16);
  5999. }
  6000. }
  6001. readToken_slash() {
  6002. const next = this.input.charCodeAt(this.state.pos + 1);
  6003. if (next === 61) {
  6004. this.finishOp(31, 2);
  6005. } else {
  6006. this.finishOp(56, 1);
  6007. }
  6008. }
  6009. readToken_interpreter() {
  6010. if (this.state.pos !== 0 || this.length < 2) return false;
  6011. let ch = this.input.charCodeAt(this.state.pos + 1);
  6012. if (ch !== 33) return false;
  6013. const start = this.state.pos;
  6014. this.state.pos += 1;
  6015. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  6016. ch = this.input.charCodeAt(this.state.pos);
  6017. }
  6018. const value = this.input.slice(start + 2, this.state.pos);
  6019. this.finishToken(28, value);
  6020. return true;
  6021. }
  6022. readToken_mult_modulo(code) {
  6023. let type = code === 42 ? 55 : 54;
  6024. let width = 1;
  6025. let next = this.input.charCodeAt(this.state.pos + 1);
  6026. if (code === 42 && next === 42) {
  6027. width++;
  6028. next = this.input.charCodeAt(this.state.pos + 2);
  6029. type = 57;
  6030. }
  6031. if (next === 61 && !this.state.inType) {
  6032. width++;
  6033. type = code === 37 ? 33 : 30;
  6034. }
  6035. this.finishOp(type, width);
  6036. }
  6037. readToken_pipe_amp(code) {
  6038. const next = this.input.charCodeAt(this.state.pos + 1);
  6039. if (next === code) {
  6040. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  6041. this.finishOp(30, 3);
  6042. } else {
  6043. this.finishOp(code === 124 ? 41 : 42, 2);
  6044. }
  6045. return;
  6046. }
  6047. if (code === 124) {
  6048. if (next === 62) {
  6049. this.finishOp(39, 2);
  6050. return;
  6051. }
  6052. if (this.hasPlugin("recordAndTuple") && next === 125) {
  6053. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6054. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6055. }
  6056. this.state.pos += 2;
  6057. this.finishToken(9);
  6058. return;
  6059. }
  6060. if (this.hasPlugin("recordAndTuple") && next === 93) {
  6061. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6062. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6063. }
  6064. this.state.pos += 2;
  6065. this.finishToken(4);
  6066. return;
  6067. }
  6068. }
  6069. if (next === 61) {
  6070. this.finishOp(30, 2);
  6071. return;
  6072. }
  6073. this.finishOp(code === 124 ? 43 : 45, 1);
  6074. }
  6075. readToken_caret() {
  6076. const next = this.input.charCodeAt(this.state.pos + 1);
  6077. if (next === 61 && !this.state.inType) {
  6078. this.finishOp(32, 2);
  6079. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  6080. proposal: "hack",
  6081. topicToken: "^^"
  6082. }])) {
  6083. this.finishOp(37, 2);
  6084. const lookaheadCh = this.input.codePointAt(this.state.pos);
  6085. if (lookaheadCh === 94) {
  6086. this.unexpected();
  6087. }
  6088. } else {
  6089. this.finishOp(44, 1);
  6090. }
  6091. }
  6092. readToken_atSign() {
  6093. const next = this.input.charCodeAt(this.state.pos + 1);
  6094. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  6095. proposal: "hack",
  6096. topicToken: "@@"
  6097. }])) {
  6098. this.finishOp(38, 2);
  6099. } else {
  6100. this.finishOp(26, 1);
  6101. }
  6102. }
  6103. readToken_plus_min(code) {
  6104. const next = this.input.charCodeAt(this.state.pos + 1);
  6105. if (next === code) {
  6106. this.finishOp(34, 2);
  6107. return;
  6108. }
  6109. if (next === 61) {
  6110. this.finishOp(30, 2);
  6111. } else {
  6112. this.finishOp(53, 1);
  6113. }
  6114. }
  6115. readToken_lt() {
  6116. const {
  6117. pos
  6118. } = this.state;
  6119. const next = this.input.charCodeAt(pos + 1);
  6120. if (next === 60) {
  6121. if (this.input.charCodeAt(pos + 2) === 61) {
  6122. this.finishOp(30, 3);
  6123. return;
  6124. }
  6125. this.finishOp(51, 2);
  6126. return;
  6127. }
  6128. if (next === 61) {
  6129. this.finishOp(49, 2);
  6130. return;
  6131. }
  6132. this.finishOp(47, 1);
  6133. }
  6134. readToken_gt() {
  6135. const {
  6136. pos
  6137. } = this.state;
  6138. const next = this.input.charCodeAt(pos + 1);
  6139. if (next === 62) {
  6140. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  6141. if (this.input.charCodeAt(pos + size) === 61) {
  6142. this.finishOp(30, size + 1);
  6143. return;
  6144. }
  6145. this.finishOp(52, size);
  6146. return;
  6147. }
  6148. if (next === 61) {
  6149. this.finishOp(49, 2);
  6150. return;
  6151. }
  6152. this.finishOp(48, 1);
  6153. }
  6154. readToken_eq_excl(code) {
  6155. const next = this.input.charCodeAt(this.state.pos + 1);
  6156. if (next === 61) {
  6157. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  6158. return;
  6159. }
  6160. if (code === 61 && next === 62) {
  6161. this.state.pos += 2;
  6162. this.finishToken(19);
  6163. return;
  6164. }
  6165. this.finishOp(code === 61 ? 29 : 35, 1);
  6166. }
  6167. readToken_question() {
  6168. const next = this.input.charCodeAt(this.state.pos + 1);
  6169. const next2 = this.input.charCodeAt(this.state.pos + 2);
  6170. if (next === 63) {
  6171. if (next2 === 61) {
  6172. this.finishOp(30, 3);
  6173. } else {
  6174. this.finishOp(40, 2);
  6175. }
  6176. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  6177. this.state.pos += 2;
  6178. this.finishToken(18);
  6179. } else {
  6180. ++this.state.pos;
  6181. this.finishToken(17);
  6182. }
  6183. }
  6184. getTokenFromCode(code) {
  6185. switch (code) {
  6186. case 46:
  6187. this.readToken_dot();
  6188. return;
  6189. case 40:
  6190. ++this.state.pos;
  6191. this.finishToken(10);
  6192. return;
  6193. case 41:
  6194. ++this.state.pos;
  6195. this.finishToken(11);
  6196. return;
  6197. case 59:
  6198. ++this.state.pos;
  6199. this.finishToken(13);
  6200. return;
  6201. case 44:
  6202. ++this.state.pos;
  6203. this.finishToken(12);
  6204. return;
  6205. case 91:
  6206. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6207. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6208. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6209. }
  6210. this.state.pos += 2;
  6211. this.finishToken(2);
  6212. } else {
  6213. ++this.state.pos;
  6214. this.finishToken(0);
  6215. }
  6216. return;
  6217. case 93:
  6218. ++this.state.pos;
  6219. this.finishToken(3);
  6220. return;
  6221. case 123:
  6222. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6223. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6224. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6225. }
  6226. this.state.pos += 2;
  6227. this.finishToken(6);
  6228. } else {
  6229. ++this.state.pos;
  6230. this.finishToken(5);
  6231. }
  6232. return;
  6233. case 125:
  6234. ++this.state.pos;
  6235. this.finishToken(8);
  6236. return;
  6237. case 58:
  6238. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  6239. this.finishOp(15, 2);
  6240. } else {
  6241. ++this.state.pos;
  6242. this.finishToken(14);
  6243. }
  6244. return;
  6245. case 63:
  6246. this.readToken_question();
  6247. return;
  6248. case 96:
  6249. this.readTemplateToken();
  6250. return;
  6251. case 48:
  6252. {
  6253. const next = this.input.charCodeAt(this.state.pos + 1);
  6254. if (next === 120 || next === 88) {
  6255. this.readRadixNumber(16);
  6256. return;
  6257. }
  6258. if (next === 111 || next === 79) {
  6259. this.readRadixNumber(8);
  6260. return;
  6261. }
  6262. if (next === 98 || next === 66) {
  6263. this.readRadixNumber(2);
  6264. return;
  6265. }
  6266. }
  6267. case 49:
  6268. case 50:
  6269. case 51:
  6270. case 52:
  6271. case 53:
  6272. case 54:
  6273. case 55:
  6274. case 56:
  6275. case 57:
  6276. this.readNumber(false);
  6277. return;
  6278. case 34:
  6279. case 39:
  6280. this.readString(code);
  6281. return;
  6282. case 47:
  6283. this.readToken_slash();
  6284. return;
  6285. case 37:
  6286. case 42:
  6287. this.readToken_mult_modulo(code);
  6288. return;
  6289. case 124:
  6290. case 38:
  6291. this.readToken_pipe_amp(code);
  6292. return;
  6293. case 94:
  6294. this.readToken_caret();
  6295. return;
  6296. case 43:
  6297. case 45:
  6298. this.readToken_plus_min(code);
  6299. return;
  6300. case 60:
  6301. this.readToken_lt();
  6302. return;
  6303. case 62:
  6304. this.readToken_gt();
  6305. return;
  6306. case 61:
  6307. case 33:
  6308. this.readToken_eq_excl(code);
  6309. return;
  6310. case 126:
  6311. this.finishOp(36, 1);
  6312. return;
  6313. case 64:
  6314. this.readToken_atSign();
  6315. return;
  6316. case 35:
  6317. this.readToken_numberSign();
  6318. return;
  6319. case 92:
  6320. this.readWord();
  6321. return;
  6322. default:
  6323. if (isIdentifierStart(code)) {
  6324. this.readWord(code);
  6325. return;
  6326. }
  6327. }
  6328. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  6329. unexpected: String.fromCodePoint(code)
  6330. });
  6331. }
  6332. finishOp(type, size) {
  6333. const str = this.input.slice(this.state.pos, this.state.pos + size);
  6334. this.state.pos += size;
  6335. this.finishToken(type, str);
  6336. }
  6337. readRegexp() {
  6338. const startLoc = this.state.startLoc;
  6339. const start = this.state.start + 1;
  6340. let escaped, inClass;
  6341. let {
  6342. pos
  6343. } = this.state;
  6344. for (;; ++pos) {
  6345. if (pos >= this.length) {
  6346. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6347. }
  6348. const ch = this.input.charCodeAt(pos);
  6349. if (isNewLine(ch)) {
  6350. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6351. }
  6352. if (escaped) {
  6353. escaped = false;
  6354. } else {
  6355. if (ch === 91) {
  6356. inClass = true;
  6357. } else if (ch === 93 && inClass) {
  6358. inClass = false;
  6359. } else if (ch === 47 && !inClass) {
  6360. break;
  6361. }
  6362. escaped = ch === 92;
  6363. }
  6364. }
  6365. const content = this.input.slice(start, pos);
  6366. ++pos;
  6367. let mods = "";
  6368. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  6369. while (pos < this.length) {
  6370. const cp = this.codePointAtPos(pos);
  6371. const char = String.fromCharCode(cp);
  6372. if (VALID_REGEX_FLAGS.has(cp)) {
  6373. if (cp === 118) {
  6374. if (mods.includes("u")) {
  6375. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6376. }
  6377. } else if (cp === 117) {
  6378. if (mods.includes("v")) {
  6379. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6380. }
  6381. }
  6382. if (mods.includes(char)) {
  6383. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  6384. }
  6385. } else if (isIdentifierChar(cp) || cp === 92) {
  6386. this.raise(Errors.MalformedRegExpFlags, nextPos());
  6387. } else {
  6388. break;
  6389. }
  6390. ++pos;
  6391. mods += char;
  6392. }
  6393. this.state.pos = pos;
  6394. this.finishToken(138, {
  6395. pattern: content,
  6396. flags: mods
  6397. });
  6398. }
  6399. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  6400. const {
  6401. n,
  6402. pos
  6403. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  6404. this.state.pos = pos;
  6405. return n;
  6406. }
  6407. readRadixNumber(radix) {
  6408. const start = this.state.pos;
  6409. const startLoc = this.state.curPosition();
  6410. let isBigInt = false;
  6411. this.state.pos += 2;
  6412. const val = this.readInt(radix);
  6413. if (val == null) {
  6414. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  6415. radix
  6416. });
  6417. }
  6418. const next = this.input.charCodeAt(this.state.pos);
  6419. if (next === 110) {
  6420. ++this.state.pos;
  6421. isBigInt = true;
  6422. } else if (next === 109) {
  6423. throw this.raise(Errors.InvalidDecimal, startLoc);
  6424. }
  6425. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6426. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6427. }
  6428. if (isBigInt) {
  6429. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  6430. this.finishToken(136, str);
  6431. return;
  6432. }
  6433. this.finishToken(135, val);
  6434. }
  6435. readNumber(startsWithDot) {
  6436. const start = this.state.pos;
  6437. const startLoc = this.state.curPosition();
  6438. let isFloat = false;
  6439. let isBigInt = false;
  6440. let hasExponent = false;
  6441. let isOctal = false;
  6442. if (!startsWithDot && this.readInt(10) === null) {
  6443. this.raise(Errors.InvalidNumber, this.state.curPosition());
  6444. }
  6445. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  6446. if (hasLeadingZero) {
  6447. const integer = this.input.slice(start, this.state.pos);
  6448. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  6449. if (!this.state.strict) {
  6450. const underscorePos = integer.indexOf("_");
  6451. if (underscorePos > 0) {
  6452. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  6453. }
  6454. }
  6455. isOctal = hasLeadingZero && !/[89]/.test(integer);
  6456. }
  6457. let next = this.input.charCodeAt(this.state.pos);
  6458. if (next === 46 && !isOctal) {
  6459. ++this.state.pos;
  6460. this.readInt(10);
  6461. isFloat = true;
  6462. next = this.input.charCodeAt(this.state.pos);
  6463. }
  6464. if ((next === 69 || next === 101) && !isOctal) {
  6465. next = this.input.charCodeAt(++this.state.pos);
  6466. if (next === 43 || next === 45) {
  6467. ++this.state.pos;
  6468. }
  6469. if (this.readInt(10) === null) {
  6470. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  6471. }
  6472. isFloat = true;
  6473. hasExponent = true;
  6474. next = this.input.charCodeAt(this.state.pos);
  6475. }
  6476. if (next === 110) {
  6477. if (isFloat || hasLeadingZero) {
  6478. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  6479. }
  6480. ++this.state.pos;
  6481. isBigInt = true;
  6482. }
  6483. if (next === 109) {
  6484. this.expectPlugin("decimal", this.state.curPosition());
  6485. if (hasExponent || hasLeadingZero) {
  6486. this.raise(Errors.InvalidDecimal, startLoc);
  6487. }
  6488. ++this.state.pos;
  6489. var isDecimal = true;
  6490. }
  6491. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6492. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6493. }
  6494. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  6495. if (isBigInt) {
  6496. this.finishToken(136, str);
  6497. return;
  6498. }
  6499. if (isDecimal) {
  6500. this.finishToken(137, str);
  6501. return;
  6502. }
  6503. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  6504. this.finishToken(135, val);
  6505. }
  6506. readCodePoint(throwOnInvalid) {
  6507. const {
  6508. code,
  6509. pos
  6510. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  6511. this.state.pos = pos;
  6512. return code;
  6513. }
  6514. readString(quote) {
  6515. const {
  6516. str,
  6517. pos,
  6518. curLine,
  6519. lineStart
  6520. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  6521. this.state.pos = pos + 1;
  6522. this.state.lineStart = lineStart;
  6523. this.state.curLine = curLine;
  6524. this.finishToken(134, str);
  6525. }
  6526. readTemplateContinuation() {
  6527. if (!this.match(8)) {
  6528. this.unexpected(null, 8);
  6529. }
  6530. this.state.pos--;
  6531. this.readTemplateToken();
  6532. }
  6533. readTemplateToken() {
  6534. const opening = this.input[this.state.pos];
  6535. const {
  6536. str,
  6537. firstInvalidLoc,
  6538. pos,
  6539. curLine,
  6540. lineStart
  6541. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  6542. this.state.pos = pos + 1;
  6543. this.state.lineStart = lineStart;
  6544. this.state.curLine = curLine;
  6545. if (firstInvalidLoc) {
  6546. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  6547. }
  6548. if (this.input.codePointAt(pos) === 96) {
  6549. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  6550. } else {
  6551. this.state.pos++;
  6552. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  6553. }
  6554. }
  6555. recordStrictModeErrors(toParseError, at) {
  6556. const index = at.index;
  6557. if (this.state.strict && !this.state.strictErrors.has(index)) {
  6558. this.raise(toParseError, at);
  6559. } else {
  6560. this.state.strictErrors.set(index, [toParseError, at]);
  6561. }
  6562. }
  6563. readWord1(firstCode) {
  6564. this.state.containsEsc = false;
  6565. let word = "";
  6566. const start = this.state.pos;
  6567. let chunkStart = this.state.pos;
  6568. if (firstCode !== undefined) {
  6569. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  6570. }
  6571. while (this.state.pos < this.length) {
  6572. const ch = this.codePointAtPos(this.state.pos);
  6573. if (isIdentifierChar(ch)) {
  6574. this.state.pos += ch <= 0xffff ? 1 : 2;
  6575. } else if (ch === 92) {
  6576. this.state.containsEsc = true;
  6577. word += this.input.slice(chunkStart, this.state.pos);
  6578. const escStart = this.state.curPosition();
  6579. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  6580. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  6581. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  6582. chunkStart = this.state.pos - 1;
  6583. continue;
  6584. }
  6585. ++this.state.pos;
  6586. const esc = this.readCodePoint(true);
  6587. if (esc !== null) {
  6588. if (!identifierCheck(esc)) {
  6589. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  6590. }
  6591. word += String.fromCodePoint(esc);
  6592. }
  6593. chunkStart = this.state.pos;
  6594. } else {
  6595. break;
  6596. }
  6597. }
  6598. return word + this.input.slice(chunkStart, this.state.pos);
  6599. }
  6600. readWord(firstCode) {
  6601. const word = this.readWord1(firstCode);
  6602. const type = keywords$1.get(word);
  6603. if (type !== undefined) {
  6604. this.finishToken(type, tokenLabelName(type));
  6605. } else {
  6606. this.finishToken(132, word);
  6607. }
  6608. }
  6609. checkKeywordEscapes() {
  6610. const {
  6611. type
  6612. } = this.state;
  6613. if (tokenIsKeyword(type) && this.state.containsEsc) {
  6614. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  6615. reservedWord: tokenLabelName(type)
  6616. });
  6617. }
  6618. }
  6619. raise(toParseError, at, details = {}) {
  6620. const loc = at instanceof Position ? at : at.loc.start;
  6621. const error = toParseError(loc, details);
  6622. if (!(this.optionFlags & 2048)) throw error;
  6623. if (!this.isLookahead) this.state.errors.push(error);
  6624. return error;
  6625. }
  6626. raiseOverwrite(toParseError, at, details = {}) {
  6627. const loc = at instanceof Position ? at : at.loc.start;
  6628. const pos = loc.index;
  6629. const errors = this.state.errors;
  6630. for (let i = errors.length - 1; i >= 0; i--) {
  6631. const error = errors[i];
  6632. if (error.loc.index === pos) {
  6633. return errors[i] = toParseError(loc, details);
  6634. }
  6635. if (error.loc.index < pos) break;
  6636. }
  6637. return this.raise(toParseError, at, details);
  6638. }
  6639. updateContext(prevType) {}
  6640. unexpected(loc, type) {
  6641. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  6642. expected: type ? tokenLabelName(type) : null
  6643. });
  6644. }
  6645. expectPlugin(pluginName, loc) {
  6646. if (this.hasPlugin(pluginName)) {
  6647. return true;
  6648. }
  6649. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  6650. missingPlugin: [pluginName]
  6651. });
  6652. }
  6653. expectOnePlugin(pluginNames) {
  6654. if (!pluginNames.some(name => this.hasPlugin(name))) {
  6655. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  6656. missingPlugin: pluginNames
  6657. });
  6658. }
  6659. }
  6660. errorBuilder(error) {
  6661. return (pos, lineStart, curLine) => {
  6662. this.raise(error, buildPosition(pos, lineStart, curLine));
  6663. };
  6664. }
  6665. }
  6666. class ClassScope {
  6667. constructor() {
  6668. this.privateNames = new Set();
  6669. this.loneAccessors = new Map();
  6670. this.undefinedPrivateNames = new Map();
  6671. }
  6672. }
  6673. class ClassScopeHandler {
  6674. constructor(parser) {
  6675. this.parser = void 0;
  6676. this.stack = [];
  6677. this.undefinedPrivateNames = new Map();
  6678. this.parser = parser;
  6679. }
  6680. current() {
  6681. return this.stack[this.stack.length - 1];
  6682. }
  6683. enter() {
  6684. this.stack.push(new ClassScope());
  6685. }
  6686. exit() {
  6687. const oldClassScope = this.stack.pop();
  6688. const current = this.current();
  6689. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  6690. if (current) {
  6691. if (!current.undefinedPrivateNames.has(name)) {
  6692. current.undefinedPrivateNames.set(name, loc);
  6693. }
  6694. } else {
  6695. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6696. identifierName: name
  6697. });
  6698. }
  6699. }
  6700. }
  6701. declarePrivateName(name, elementType, loc) {
  6702. const {
  6703. privateNames,
  6704. loneAccessors,
  6705. undefinedPrivateNames
  6706. } = this.current();
  6707. let redefined = privateNames.has(name);
  6708. if (elementType & 3) {
  6709. const accessor = redefined && loneAccessors.get(name);
  6710. if (accessor) {
  6711. const oldStatic = accessor & 4;
  6712. const newStatic = elementType & 4;
  6713. const oldKind = accessor & 3;
  6714. const newKind = elementType & 3;
  6715. redefined = oldKind === newKind || oldStatic !== newStatic;
  6716. if (!redefined) loneAccessors.delete(name);
  6717. } else if (!redefined) {
  6718. loneAccessors.set(name, elementType);
  6719. }
  6720. }
  6721. if (redefined) {
  6722. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  6723. identifierName: name
  6724. });
  6725. }
  6726. privateNames.add(name);
  6727. undefinedPrivateNames.delete(name);
  6728. }
  6729. usePrivateName(name, loc) {
  6730. let classScope;
  6731. for (classScope of this.stack) {
  6732. if (classScope.privateNames.has(name)) return;
  6733. }
  6734. if (classScope) {
  6735. classScope.undefinedPrivateNames.set(name, loc);
  6736. } else {
  6737. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6738. identifierName: name
  6739. });
  6740. }
  6741. }
  6742. }
  6743. class ExpressionScope {
  6744. constructor(type = 0) {
  6745. this.type = type;
  6746. }
  6747. canBeArrowParameterDeclaration() {
  6748. return this.type === 2 || this.type === 1;
  6749. }
  6750. isCertainlyParameterDeclaration() {
  6751. return this.type === 3;
  6752. }
  6753. }
  6754. class ArrowHeadParsingScope extends ExpressionScope {
  6755. constructor(type) {
  6756. super(type);
  6757. this.declarationErrors = new Map();
  6758. }
  6759. recordDeclarationError(ParsingErrorClass, at) {
  6760. const index = at.index;
  6761. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  6762. }
  6763. clearDeclarationError(index) {
  6764. this.declarationErrors.delete(index);
  6765. }
  6766. iterateErrors(iterator) {
  6767. this.declarationErrors.forEach(iterator);
  6768. }
  6769. }
  6770. class ExpressionScopeHandler {
  6771. constructor(parser) {
  6772. this.parser = void 0;
  6773. this.stack = [new ExpressionScope()];
  6774. this.parser = parser;
  6775. }
  6776. enter(scope) {
  6777. this.stack.push(scope);
  6778. }
  6779. exit() {
  6780. this.stack.pop();
  6781. }
  6782. recordParameterInitializerError(toParseError, node) {
  6783. const origin = node.loc.start;
  6784. const {
  6785. stack
  6786. } = this;
  6787. let i = stack.length - 1;
  6788. let scope = stack[i];
  6789. while (!scope.isCertainlyParameterDeclaration()) {
  6790. if (scope.canBeArrowParameterDeclaration()) {
  6791. scope.recordDeclarationError(toParseError, origin);
  6792. } else {
  6793. return;
  6794. }
  6795. scope = stack[--i];
  6796. }
  6797. this.parser.raise(toParseError, origin);
  6798. }
  6799. recordArrowParameterBindingError(error, node) {
  6800. const {
  6801. stack
  6802. } = this;
  6803. const scope = stack[stack.length - 1];
  6804. const origin = node.loc.start;
  6805. if (scope.isCertainlyParameterDeclaration()) {
  6806. this.parser.raise(error, origin);
  6807. } else if (scope.canBeArrowParameterDeclaration()) {
  6808. scope.recordDeclarationError(error, origin);
  6809. } else {
  6810. return;
  6811. }
  6812. }
  6813. recordAsyncArrowParametersError(at) {
  6814. const {
  6815. stack
  6816. } = this;
  6817. let i = stack.length - 1;
  6818. let scope = stack[i];
  6819. while (scope.canBeArrowParameterDeclaration()) {
  6820. if (scope.type === 2) {
  6821. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  6822. }
  6823. scope = stack[--i];
  6824. }
  6825. }
  6826. validateAsPattern() {
  6827. const {
  6828. stack
  6829. } = this;
  6830. const currentScope = stack[stack.length - 1];
  6831. if (!currentScope.canBeArrowParameterDeclaration()) return;
  6832. currentScope.iterateErrors(([toParseError, loc]) => {
  6833. this.parser.raise(toParseError, loc);
  6834. let i = stack.length - 2;
  6835. let scope = stack[i];
  6836. while (scope.canBeArrowParameterDeclaration()) {
  6837. scope.clearDeclarationError(loc.index);
  6838. scope = stack[--i];
  6839. }
  6840. });
  6841. }
  6842. }
  6843. function newParameterDeclarationScope() {
  6844. return new ExpressionScope(3);
  6845. }
  6846. function newArrowHeadScope() {
  6847. return new ArrowHeadParsingScope(1);
  6848. }
  6849. function newAsyncArrowScope() {
  6850. return new ArrowHeadParsingScope(2);
  6851. }
  6852. function newExpressionScope() {
  6853. return new ExpressionScope();
  6854. }
  6855. class UtilParser extends Tokenizer {
  6856. addExtra(node, key, value, enumerable = true) {
  6857. if (!node) return;
  6858. let {
  6859. extra
  6860. } = node;
  6861. if (extra == null) {
  6862. extra = {};
  6863. node.extra = extra;
  6864. }
  6865. if (enumerable) {
  6866. extra[key] = value;
  6867. } else {
  6868. Object.defineProperty(extra, key, {
  6869. enumerable,
  6870. value
  6871. });
  6872. }
  6873. }
  6874. isContextual(token) {
  6875. return this.state.type === token && !this.state.containsEsc;
  6876. }
  6877. isUnparsedContextual(nameStart, name) {
  6878. if (this.input.startsWith(name, nameStart)) {
  6879. const nextCh = this.input.charCodeAt(nameStart + name.length);
  6880. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  6881. }
  6882. return false;
  6883. }
  6884. isLookaheadContextual(name) {
  6885. const next = this.nextTokenStart();
  6886. return this.isUnparsedContextual(next, name);
  6887. }
  6888. eatContextual(token) {
  6889. if (this.isContextual(token)) {
  6890. this.next();
  6891. return true;
  6892. }
  6893. return false;
  6894. }
  6895. expectContextual(token, toParseError) {
  6896. if (!this.eatContextual(token)) {
  6897. if (toParseError != null) {
  6898. throw this.raise(toParseError, this.state.startLoc);
  6899. }
  6900. this.unexpected(null, token);
  6901. }
  6902. }
  6903. canInsertSemicolon() {
  6904. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  6905. }
  6906. hasPrecedingLineBreak() {
  6907. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  6908. }
  6909. hasFollowingLineBreak() {
  6910. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  6911. }
  6912. isLineTerminator() {
  6913. return this.eat(13) || this.canInsertSemicolon();
  6914. }
  6915. semicolon(allowAsi = true) {
  6916. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  6917. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  6918. }
  6919. expect(type, loc) {
  6920. if (!this.eat(type)) {
  6921. this.unexpected(loc, type);
  6922. }
  6923. }
  6924. tryParse(fn, oldState = this.state.clone()) {
  6925. const abortSignal = {
  6926. node: null
  6927. };
  6928. try {
  6929. const node = fn((node = null) => {
  6930. abortSignal.node = node;
  6931. throw abortSignal;
  6932. });
  6933. if (this.state.errors.length > oldState.errors.length) {
  6934. const failState = this.state;
  6935. this.state = oldState;
  6936. this.state.tokensLength = failState.tokensLength;
  6937. return {
  6938. node,
  6939. error: failState.errors[oldState.errors.length],
  6940. thrown: false,
  6941. aborted: false,
  6942. failState
  6943. };
  6944. }
  6945. return {
  6946. node: node,
  6947. error: null,
  6948. thrown: false,
  6949. aborted: false,
  6950. failState: null
  6951. };
  6952. } catch (error) {
  6953. const failState = this.state;
  6954. this.state = oldState;
  6955. if (error instanceof SyntaxError) {
  6956. return {
  6957. node: null,
  6958. error,
  6959. thrown: true,
  6960. aborted: false,
  6961. failState
  6962. };
  6963. }
  6964. if (error === abortSignal) {
  6965. return {
  6966. node: abortSignal.node,
  6967. error: null,
  6968. thrown: false,
  6969. aborted: true,
  6970. failState
  6971. };
  6972. }
  6973. throw error;
  6974. }
  6975. }
  6976. checkExpressionErrors(refExpressionErrors, andThrow) {
  6977. if (!refExpressionErrors) return false;
  6978. const {
  6979. shorthandAssignLoc,
  6980. doubleProtoLoc,
  6981. privateKeyLoc,
  6982. optionalParametersLoc,
  6983. voidPatternLoc
  6984. } = refExpressionErrors;
  6985. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
  6986. if (!andThrow) {
  6987. return hasErrors;
  6988. }
  6989. if (shorthandAssignLoc != null) {
  6990. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  6991. }
  6992. if (doubleProtoLoc != null) {
  6993. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  6994. }
  6995. if (privateKeyLoc != null) {
  6996. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  6997. }
  6998. if (optionalParametersLoc != null) {
  6999. this.unexpected(optionalParametersLoc);
  7000. }
  7001. if (voidPatternLoc != null) {
  7002. this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
  7003. }
  7004. }
  7005. isLiteralPropertyName() {
  7006. return tokenIsLiteralPropertyName(this.state.type);
  7007. }
  7008. isPrivateName(node) {
  7009. return node.type === "PrivateName";
  7010. }
  7011. getPrivateNameSV(node) {
  7012. return node.id.name;
  7013. }
  7014. hasPropertyAsPrivateName(node) {
  7015. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  7016. }
  7017. isObjectProperty(node) {
  7018. return node.type === "ObjectProperty";
  7019. }
  7020. isObjectMethod(node) {
  7021. return node.type === "ObjectMethod";
  7022. }
  7023. initializeScopes(inModule = this.options.sourceType === "module") {
  7024. const oldLabels = this.state.labels;
  7025. this.state.labels = [];
  7026. const oldExportedIdentifiers = this.exportedIdentifiers;
  7027. this.exportedIdentifiers = new Set();
  7028. const oldInModule = this.inModule;
  7029. this.inModule = inModule;
  7030. const oldScope = this.scope;
  7031. const ScopeHandler = this.getScopeHandler();
  7032. this.scope = new ScopeHandler(this, inModule);
  7033. const oldProdParam = this.prodParam;
  7034. this.prodParam = new ProductionParameterHandler();
  7035. const oldClassScope = this.classScope;
  7036. this.classScope = new ClassScopeHandler(this);
  7037. const oldExpressionScope = this.expressionScope;
  7038. this.expressionScope = new ExpressionScopeHandler(this);
  7039. return () => {
  7040. this.state.labels = oldLabels;
  7041. this.exportedIdentifiers = oldExportedIdentifiers;
  7042. this.inModule = oldInModule;
  7043. this.scope = oldScope;
  7044. this.prodParam = oldProdParam;
  7045. this.classScope = oldClassScope;
  7046. this.expressionScope = oldExpressionScope;
  7047. };
  7048. }
  7049. enterInitialScopes() {
  7050. let paramFlags = 0;
  7051. if (this.inModule || this.optionFlags & 1) {
  7052. paramFlags |= 2;
  7053. }
  7054. if (this.optionFlags & 32) {
  7055. paramFlags |= 1;
  7056. }
  7057. const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
  7058. if (isCommonJS || this.optionFlags & 2) {
  7059. paramFlags |= 4;
  7060. }
  7061. this.prodParam.enter(paramFlags);
  7062. let scopeFlags = isCommonJS ? 514 : 1;
  7063. if (this.optionFlags & 4) {
  7064. scopeFlags |= 512;
  7065. }
  7066. this.scope.enter(scopeFlags);
  7067. }
  7068. checkDestructuringPrivate(refExpressionErrors) {
  7069. const {
  7070. privateKeyLoc
  7071. } = refExpressionErrors;
  7072. if (privateKeyLoc !== null) {
  7073. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  7074. }
  7075. }
  7076. }
  7077. class ExpressionErrors {
  7078. constructor() {
  7079. this.shorthandAssignLoc = null;
  7080. this.doubleProtoLoc = null;
  7081. this.privateKeyLoc = null;
  7082. this.optionalParametersLoc = null;
  7083. this.voidPatternLoc = null;
  7084. }
  7085. }
  7086. class Node {
  7087. constructor(parser, pos, loc) {
  7088. this.type = "";
  7089. this.start = pos;
  7090. this.end = 0;
  7091. this.loc = new SourceLocation(loc);
  7092. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  7093. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  7094. }
  7095. }
  7096. const NodePrototype = Node.prototype;
  7097. NodePrototype.__clone = function () {
  7098. const newNode = new Node(undefined, this.start, this.loc.start);
  7099. const keys = Object.keys(this);
  7100. for (let i = 0, length = keys.length; i < length; i++) {
  7101. const key = keys[i];
  7102. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  7103. newNode[key] = this[key];
  7104. }
  7105. }
  7106. return newNode;
  7107. };
  7108. class NodeUtils extends UtilParser {
  7109. startNode() {
  7110. const loc = this.state.startLoc;
  7111. return new Node(this, loc.index, loc);
  7112. }
  7113. startNodeAt(loc) {
  7114. return new Node(this, loc.index, loc);
  7115. }
  7116. startNodeAtNode(type) {
  7117. return this.startNodeAt(type.loc.start);
  7118. }
  7119. finishNode(node, type) {
  7120. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  7121. }
  7122. finishNodeAt(node, type, endLoc) {
  7123. node.type = type;
  7124. node.end = endLoc.index;
  7125. node.loc.end = endLoc;
  7126. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7127. if (this.optionFlags & 4096) {
  7128. this.processComment(node);
  7129. }
  7130. return node;
  7131. }
  7132. resetStartLocation(node, startLoc) {
  7133. node.start = startLoc.index;
  7134. node.loc.start = startLoc;
  7135. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  7136. }
  7137. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  7138. node.end = endLoc.index;
  7139. node.loc.end = endLoc;
  7140. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7141. }
  7142. resetStartLocationFromNode(node, locationNode) {
  7143. this.resetStartLocation(node, locationNode.loc.start);
  7144. }
  7145. castNodeTo(node, type) {
  7146. node.type = type;
  7147. return node;
  7148. }
  7149. cloneIdentifier(node) {
  7150. const {
  7151. type,
  7152. start,
  7153. end,
  7154. loc,
  7155. range,
  7156. name
  7157. } = node;
  7158. const cloned = Object.create(NodePrototype);
  7159. cloned.type = type;
  7160. cloned.start = start;
  7161. cloned.end = end;
  7162. cloned.loc = loc;
  7163. cloned.range = range;
  7164. cloned.name = name;
  7165. if (node.extra) cloned.extra = node.extra;
  7166. return cloned;
  7167. }
  7168. cloneStringLiteral(node) {
  7169. const {
  7170. type,
  7171. start,
  7172. end,
  7173. loc,
  7174. range,
  7175. extra
  7176. } = node;
  7177. const cloned = Object.create(NodePrototype);
  7178. cloned.type = type;
  7179. cloned.start = start;
  7180. cloned.end = end;
  7181. cloned.loc = loc;
  7182. cloned.range = range;
  7183. cloned.extra = extra;
  7184. cloned.value = node.value;
  7185. return cloned;
  7186. }
  7187. }
  7188. const unwrapParenthesizedExpression = node => {
  7189. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7190. };
  7191. class LValParser extends NodeUtils {
  7192. toAssignable(node, isLHS = false) {
  7193. var _node$extra, _node$extra3;
  7194. let parenthesized = undefined;
  7195. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7196. parenthesized = unwrapParenthesizedExpression(node);
  7197. if (isLHS) {
  7198. if (parenthesized.type === "Identifier") {
  7199. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7200. } else if (parenthesized.type !== "CallExpression" && parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7201. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7202. }
  7203. } else {
  7204. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7205. }
  7206. }
  7207. switch (node.type) {
  7208. case "Identifier":
  7209. case "ObjectPattern":
  7210. case "ArrayPattern":
  7211. case "AssignmentPattern":
  7212. case "RestElement":
  7213. case "VoidPattern":
  7214. break;
  7215. case "ObjectExpression":
  7216. this.castNodeTo(node, "ObjectPattern");
  7217. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7218. var _node$extra2;
  7219. const prop = node.properties[i];
  7220. const isLast = i === last;
  7221. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7222. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7223. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7224. }
  7225. }
  7226. break;
  7227. case "ObjectProperty":
  7228. {
  7229. const {
  7230. key,
  7231. value
  7232. } = node;
  7233. if (this.isPrivateName(key)) {
  7234. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7235. }
  7236. this.toAssignable(value, isLHS);
  7237. break;
  7238. }
  7239. case "SpreadElement":
  7240. {
  7241. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7242. }
  7243. case "ArrayExpression":
  7244. this.castNodeTo(node, "ArrayPattern");
  7245. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7246. break;
  7247. case "AssignmentExpression":
  7248. if (node.operator !== "=") {
  7249. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7250. }
  7251. this.castNodeTo(node, "AssignmentPattern");
  7252. delete node.operator;
  7253. if (node.left.type === "VoidPattern") {
  7254. this.raise(Errors.VoidPatternInitializer, node.left);
  7255. }
  7256. this.toAssignable(node.left, isLHS);
  7257. break;
  7258. case "ParenthesizedExpression":
  7259. this.toAssignable(parenthesized, isLHS);
  7260. break;
  7261. }
  7262. }
  7263. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7264. if (prop.type === "ObjectMethod") {
  7265. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7266. } else if (prop.type === "SpreadElement") {
  7267. this.castNodeTo(prop, "RestElement");
  7268. const arg = prop.argument;
  7269. this.checkToRestConversion(arg, false);
  7270. this.toAssignable(arg, isLHS);
  7271. if (!isLast) {
  7272. this.raise(Errors.RestTrailingComma, prop);
  7273. }
  7274. } else {
  7275. this.toAssignable(prop, isLHS);
  7276. }
  7277. }
  7278. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7279. const end = exprList.length - 1;
  7280. for (let i = 0; i <= end; i++) {
  7281. const elt = exprList[i];
  7282. if (!elt) continue;
  7283. this.toAssignableListItem(exprList, i, isLHS);
  7284. if (elt.type === "RestElement") {
  7285. if (i < end) {
  7286. this.raise(Errors.RestTrailingComma, elt);
  7287. } else if (trailingCommaLoc) {
  7288. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7289. }
  7290. }
  7291. }
  7292. }
  7293. toAssignableListItem(exprList, index, isLHS) {
  7294. const node = exprList[index];
  7295. if (node.type === "SpreadElement") {
  7296. this.castNodeTo(node, "RestElement");
  7297. const arg = node.argument;
  7298. this.checkToRestConversion(arg, true);
  7299. this.toAssignable(arg, isLHS);
  7300. } else {
  7301. this.toAssignable(node, isLHS);
  7302. }
  7303. }
  7304. isAssignable(node, isBinding) {
  7305. switch (node.type) {
  7306. case "Identifier":
  7307. case "ObjectPattern":
  7308. case "ArrayPattern":
  7309. case "AssignmentPattern":
  7310. case "RestElement":
  7311. case "VoidPattern":
  7312. return true;
  7313. case "ObjectExpression":
  7314. {
  7315. const last = node.properties.length - 1;
  7316. return node.properties.every((prop, i) => {
  7317. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7318. });
  7319. }
  7320. case "ObjectProperty":
  7321. return this.isAssignable(node.value);
  7322. case "SpreadElement":
  7323. return this.isAssignable(node.argument);
  7324. case "ArrayExpression":
  7325. return node.elements.every(element => element === null || this.isAssignable(element));
  7326. case "AssignmentExpression":
  7327. return node.operator === "=";
  7328. case "ParenthesizedExpression":
  7329. return this.isAssignable(node.expression);
  7330. case "MemberExpression":
  7331. case "OptionalMemberExpression":
  7332. return !isBinding;
  7333. default:
  7334. return false;
  7335. }
  7336. }
  7337. toReferencedList(exprList, isParenthesizedExpr) {
  7338. return exprList;
  7339. }
  7340. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7341. this.toReferencedList(exprList, isParenthesizedExpr);
  7342. for (const expr of exprList) {
  7343. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7344. this.toReferencedListDeep(expr.elements);
  7345. }
  7346. }
  7347. }
  7348. parseSpread(refExpressionErrors) {
  7349. const node = this.startNode();
  7350. this.next();
  7351. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7352. return this.finishNode(node, "SpreadElement");
  7353. }
  7354. parseRestBinding() {
  7355. const node = this.startNode();
  7356. this.next();
  7357. const argument = this.parseBindingAtom();
  7358. if (argument.type === "VoidPattern") {
  7359. this.raise(Errors.UnexpectedVoidPattern, argument);
  7360. }
  7361. node.argument = argument;
  7362. return this.finishNode(node, "RestElement");
  7363. }
  7364. parseBindingAtom() {
  7365. switch (this.state.type) {
  7366. case 0:
  7367. {
  7368. const node = this.startNode();
  7369. this.next();
  7370. node.elements = this.parseBindingList(3, 93, 1);
  7371. return this.finishNode(node, "ArrayPattern");
  7372. }
  7373. case 5:
  7374. return this.parseObjectLike(8, true);
  7375. case 88:
  7376. return this.parseVoidPattern(null);
  7377. }
  7378. return this.parseIdentifier();
  7379. }
  7380. parseBindingList(close, closeCharCode, flags) {
  7381. const allowEmpty = flags & 1;
  7382. const elts = [];
  7383. let first = true;
  7384. while (!this.eat(close)) {
  7385. if (first) {
  7386. first = false;
  7387. } else {
  7388. this.expect(12);
  7389. }
  7390. if (allowEmpty && this.match(12)) {
  7391. elts.push(null);
  7392. } else if (this.eat(close)) {
  7393. break;
  7394. } else if (this.match(21)) {
  7395. let rest = this.parseRestBinding();
  7396. if (this.hasPlugin("flow") || flags & 2) {
  7397. rest = this.parseFunctionParamType(rest);
  7398. }
  7399. elts.push(rest);
  7400. if (!this.checkCommaAfterRest(closeCharCode)) {
  7401. this.expect(close);
  7402. break;
  7403. }
  7404. } else {
  7405. const decorators = [];
  7406. if (flags & 2) {
  7407. if (this.match(26) && this.hasPlugin("decorators")) {
  7408. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7409. }
  7410. while (this.match(26)) {
  7411. decorators.push(this.parseDecorator());
  7412. }
  7413. }
  7414. elts.push(this.parseBindingElement(flags, decorators));
  7415. }
  7416. }
  7417. return elts;
  7418. }
  7419. parseBindingRestProperty(prop) {
  7420. this.next();
  7421. if (this.hasPlugin("discardBinding") && this.match(88)) {
  7422. prop.argument = this.parseVoidPattern(null);
  7423. this.raise(Errors.UnexpectedVoidPattern, prop.argument);
  7424. } else {
  7425. prop.argument = this.parseIdentifier();
  7426. }
  7427. this.checkCommaAfterRest(125);
  7428. return this.finishNode(prop, "RestElement");
  7429. }
  7430. parseBindingProperty() {
  7431. const {
  7432. type,
  7433. startLoc
  7434. } = this.state;
  7435. if (type === 21) {
  7436. return this.parseBindingRestProperty(this.startNode());
  7437. }
  7438. const prop = this.startNode();
  7439. if (type === 139) {
  7440. this.expectPlugin("destructuringPrivate", startLoc);
  7441. this.classScope.usePrivateName(this.state.value, startLoc);
  7442. prop.key = this.parsePrivateName();
  7443. } else {
  7444. this.parsePropertyName(prop);
  7445. }
  7446. prop.method = false;
  7447. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7448. }
  7449. parseBindingElement(flags, decorators) {
  7450. const left = this.parseMaybeDefault();
  7451. if (this.hasPlugin("flow") || flags & 2) {
  7452. this.parseFunctionParamType(left);
  7453. }
  7454. if (decorators.length) {
  7455. left.decorators = decorators;
  7456. this.resetStartLocationFromNode(left, decorators[0]);
  7457. }
  7458. const elt = this.parseMaybeDefault(left.loc.start, left);
  7459. return elt;
  7460. }
  7461. parseFunctionParamType(param) {
  7462. return param;
  7463. }
  7464. parseMaybeDefault(startLoc, left) {
  7465. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  7466. left = left != null ? left : this.parseBindingAtom();
  7467. if (!this.eat(29)) return left;
  7468. const node = this.startNodeAt(startLoc);
  7469. if (left.type === "VoidPattern") {
  7470. this.raise(Errors.VoidPatternInitializer, left);
  7471. }
  7472. node.left = left;
  7473. node.right = this.parseMaybeAssignAllowIn();
  7474. return this.finishNode(node, "AssignmentPattern");
  7475. }
  7476. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  7477. switch (type) {
  7478. case "AssignmentPattern":
  7479. return "left";
  7480. case "RestElement":
  7481. return "argument";
  7482. case "ObjectProperty":
  7483. return "value";
  7484. case "ParenthesizedExpression":
  7485. return "expression";
  7486. case "ArrayPattern":
  7487. return "elements";
  7488. case "ObjectPattern":
  7489. return "properties";
  7490. case "VoidPattern":
  7491. return true;
  7492. case "CallExpression":
  7493. if (!disallowCallExpression && !this.state.strict && this.optionFlags & 8192) {
  7494. return true;
  7495. }
  7496. }
  7497. return false;
  7498. }
  7499. isOptionalMemberExpression(expression) {
  7500. return expression.type === "OptionalMemberExpression";
  7501. }
  7502. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false, disallowCallExpression = false) {
  7503. var _expression$extra;
  7504. const type = expression.type;
  7505. if (this.isObjectMethod(expression)) return;
  7506. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7507. if (isOptionalMemberExpression || type === "MemberExpression") {
  7508. if (isOptionalMemberExpression) {
  7509. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7510. if (ancestor.type !== "AssignmentExpression") {
  7511. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7512. ancestor
  7513. });
  7514. }
  7515. }
  7516. if (binding !== 64) {
  7517. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7518. }
  7519. return;
  7520. }
  7521. if (type === "Identifier") {
  7522. this.checkIdentifier(expression, binding, strictModeChanged);
  7523. const {
  7524. name
  7525. } = expression;
  7526. if (checkClashes) {
  7527. if (checkClashes.has(name)) {
  7528. this.raise(Errors.ParamDupe, expression);
  7529. } else {
  7530. checkClashes.add(name);
  7531. }
  7532. }
  7533. return;
  7534. } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
  7535. this.raise(Errors.VoidPatternCatchClauseParam, expression);
  7536. }
  7537. const unwrappedExpression = unwrapParenthesizedExpression(expression);
  7538. disallowCallExpression || (disallowCallExpression = unwrappedExpression.type === "CallExpression" && (unwrappedExpression.callee.type === "Import" || unwrappedExpression.callee.type === "Super"));
  7539. const validity = this.isValidLVal(type, disallowCallExpression, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7540. if (validity === true) return;
  7541. if (validity === false) {
  7542. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7543. this.raise(ParseErrorClass, expression, {
  7544. ancestor
  7545. });
  7546. return;
  7547. }
  7548. let key, isParenthesizedExpression;
  7549. if (typeof validity === "string") {
  7550. key = validity;
  7551. isParenthesizedExpression = type === "ParenthesizedExpression";
  7552. } else {
  7553. [key, isParenthesizedExpression] = validity;
  7554. }
  7555. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7556. type
  7557. } : ancestor;
  7558. const val = expression[key];
  7559. if (Array.isArray(val)) {
  7560. for (const child of val) {
  7561. if (child) {
  7562. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, true);
  7563. }
  7564. }
  7565. } else if (val) {
  7566. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, disallowCallExpression);
  7567. }
  7568. }
  7569. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7570. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7571. if (bindingType === 64) {
  7572. this.raise(Errors.StrictEvalArguments, at, {
  7573. referenceName: at.name
  7574. });
  7575. } else {
  7576. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  7577. bindingName: at.name
  7578. });
  7579. }
  7580. }
  7581. if (bindingType & 8192 && at.name === "let") {
  7582. this.raise(Errors.LetInLexicalBinding, at);
  7583. }
  7584. if (!(bindingType & 64)) {
  7585. this.declareNameFromIdentifier(at, bindingType);
  7586. }
  7587. }
  7588. declareNameFromIdentifier(identifier, binding) {
  7589. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7590. }
  7591. checkToRestConversion(node, allowPattern) {
  7592. switch (node.type) {
  7593. case "ParenthesizedExpression":
  7594. this.checkToRestConversion(node.expression, allowPattern);
  7595. break;
  7596. case "Identifier":
  7597. case "MemberExpression":
  7598. break;
  7599. case "ArrayExpression":
  7600. case "ObjectExpression":
  7601. if (allowPattern) break;
  7602. default:
  7603. this.raise(Errors.InvalidRestAssignmentPattern, node);
  7604. }
  7605. }
  7606. checkCommaAfterRest(close) {
  7607. if (!this.match(12)) {
  7608. return false;
  7609. }
  7610. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  7611. return true;
  7612. }
  7613. }
  7614. const keywordAndTSRelationalOperator = /in(?:stanceof)?|as|satisfies/y;
  7615. function nonNull(x) {
  7616. if (x == null) {
  7617. throw new Error(`Unexpected ${x} value.`);
  7618. }
  7619. return x;
  7620. }
  7621. function assert(x) {
  7622. if (!x) {
  7623. throw new Error("Assert fail");
  7624. }
  7625. }
  7626. const TSErrors = ParseErrorEnum`typescript`({
  7627. AbstractMethodHasImplementation: ({
  7628. methodName
  7629. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7630. AbstractPropertyHasInitializer: ({
  7631. propertyName
  7632. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7633. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7634. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7635. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7636. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7637. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7638. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7639. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7640. DeclareAccessor: ({
  7641. kind
  7642. }) => `'declare' is not allowed in ${kind}ters.`,
  7643. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7644. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7645. DuplicateAccessibilityModifier: ({
  7646. modifier
  7647. }) => `Accessibility modifier already seen: '${modifier}'.`,
  7648. DuplicateModifier: ({
  7649. modifier
  7650. }) => `Duplicate modifier: '${modifier}'.`,
  7651. EmptyHeritageClauseType: ({
  7652. token
  7653. }) => `'${token}' list cannot be empty.`,
  7654. EmptyTypeArguments: "Type argument list cannot be empty.",
  7655. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7656. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7657. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7658. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7659. IncompatibleModifiers: ({
  7660. modifiers
  7661. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7662. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7663. IndexSignatureHasAccessibility: ({
  7664. modifier
  7665. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7666. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7667. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7668. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7669. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7670. InvalidHeritageClauseType: ({
  7671. token
  7672. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  7673. InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
  7674. InvalidModifierOnTypeMember: ({
  7675. modifier
  7676. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7677. InvalidModifierOnTypeParameter: ({
  7678. modifier
  7679. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7680. InvalidModifierOnTypeParameterPositions: ({
  7681. modifier
  7682. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7683. InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
  7684. InvalidModifiersOrder: ({
  7685. orderedModifiers
  7686. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7687. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7688. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7689. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7690. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7691. NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7692. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7693. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7694. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7695. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7696. PrivateElementHasAccessibility: ({
  7697. modifier
  7698. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7699. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7700. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7701. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7702. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7703. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7704. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7705. SingleTypeParameterWithoutTrailingComma: ({
  7706. typeParameterName
  7707. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7708. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7709. 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?`).",
  7710. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7711. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7712. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7713. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7714. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7715. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7716. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7717. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7718. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7719. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7720. UnsupportedSignatureParameterKind: ({
  7721. type
  7722. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
  7723. UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
  7724. });
  7725. function keywordTypeFromName(value) {
  7726. switch (value) {
  7727. case "any":
  7728. return "TSAnyKeyword";
  7729. case "boolean":
  7730. return "TSBooleanKeyword";
  7731. case "bigint":
  7732. return "TSBigIntKeyword";
  7733. case "never":
  7734. return "TSNeverKeyword";
  7735. case "number":
  7736. return "TSNumberKeyword";
  7737. case "object":
  7738. return "TSObjectKeyword";
  7739. case "string":
  7740. return "TSStringKeyword";
  7741. case "symbol":
  7742. return "TSSymbolKeyword";
  7743. case "undefined":
  7744. return "TSUndefinedKeyword";
  7745. case "unknown":
  7746. return "TSUnknownKeyword";
  7747. default:
  7748. return undefined;
  7749. }
  7750. }
  7751. function tsIsAccessModifier(modifier) {
  7752. return modifier === "private" || modifier === "public" || modifier === "protected";
  7753. }
  7754. function tsIsVarianceAnnotations(modifier) {
  7755. return modifier === "in" || modifier === "out";
  7756. }
  7757. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7758. constructor(...args) {
  7759. super(...args);
  7760. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7761. allowedModifiers: ["in", "out"],
  7762. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7763. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7764. });
  7765. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7766. allowedModifiers: ["const"],
  7767. disallowedModifiers: ["in", "out"],
  7768. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7769. });
  7770. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7771. allowedModifiers: ["in", "out", "const"],
  7772. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7773. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7774. });
  7775. }
  7776. getScopeHandler() {
  7777. return TypeScriptScopeHandler;
  7778. }
  7779. tsIsIdentifier() {
  7780. return tokenIsIdentifier(this.state.type);
  7781. }
  7782. tsTokenCanFollowModifier() {
  7783. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  7784. }
  7785. tsNextTokenOnSameLineAndCanFollowModifier() {
  7786. this.next();
  7787. if (this.hasPrecedingLineBreak()) {
  7788. return false;
  7789. }
  7790. return this.tsTokenCanFollowModifier();
  7791. }
  7792. tsNextTokenCanFollowModifier() {
  7793. if (this.match(106)) {
  7794. this.next();
  7795. return this.tsTokenCanFollowModifier();
  7796. }
  7797. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  7798. }
  7799. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
  7800. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7801. return undefined;
  7802. }
  7803. const modifier = this.state.value;
  7804. if (allowedModifiers.includes(modifier)) {
  7805. if (hasSeenStaticModifier && this.match(106)) {
  7806. return undefined;
  7807. }
  7808. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7809. return undefined;
  7810. }
  7811. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7812. return modifier;
  7813. }
  7814. }
  7815. return undefined;
  7816. }
  7817. tsParseModifiers({
  7818. allowedModifiers,
  7819. disallowedModifiers,
  7820. stopOnStartOfClassStaticBlock,
  7821. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7822. }, modified) {
  7823. const enforceOrder = (loc, modifier, before, after) => {
  7824. if (modifier === before && modified[after]) {
  7825. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7826. orderedModifiers: [before, after]
  7827. });
  7828. }
  7829. };
  7830. const incompatible = (loc, modifier, mod1, mod2) => {
  7831. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7832. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7833. modifiers: [mod1, mod2]
  7834. });
  7835. }
  7836. };
  7837. for (;;) {
  7838. const {
  7839. startLoc
  7840. } = this.state;
  7841. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
  7842. if (!modifier) break;
  7843. if (tsIsAccessModifier(modifier)) {
  7844. if (modified.accessibility) {
  7845. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7846. modifier
  7847. });
  7848. } else {
  7849. enforceOrder(startLoc, modifier, modifier, "override");
  7850. enforceOrder(startLoc, modifier, modifier, "static");
  7851. enforceOrder(startLoc, modifier, modifier, "readonly");
  7852. modified.accessibility = modifier;
  7853. }
  7854. } else if (tsIsVarianceAnnotations(modifier)) {
  7855. if (modified[modifier]) {
  7856. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7857. modifier
  7858. });
  7859. }
  7860. modified[modifier] = true;
  7861. enforceOrder(startLoc, modifier, "in", "out");
  7862. } else {
  7863. if (hasOwnProperty.call(modified, modifier)) {
  7864. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7865. modifier
  7866. });
  7867. } else {
  7868. enforceOrder(startLoc, modifier, "static", "readonly");
  7869. enforceOrder(startLoc, modifier, "static", "override");
  7870. enforceOrder(startLoc, modifier, "override", "readonly");
  7871. enforceOrder(startLoc, modifier, "abstract", "override");
  7872. incompatible(startLoc, modifier, "declare", "override");
  7873. incompatible(startLoc, modifier, "static", "abstract");
  7874. }
  7875. modified[modifier] = true;
  7876. }
  7877. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7878. this.raise(errorTemplate, startLoc, {
  7879. modifier
  7880. });
  7881. }
  7882. }
  7883. }
  7884. tsIsListTerminator(kind) {
  7885. switch (kind) {
  7886. case "EnumMembers":
  7887. case "TypeMembers":
  7888. return this.match(8);
  7889. case "HeritageClauseElement":
  7890. return this.match(5);
  7891. case "TupleElementTypes":
  7892. return this.match(3);
  7893. case "TypeParametersOrArguments":
  7894. return this.match(48);
  7895. }
  7896. }
  7897. tsParseList(kind, parseElement) {
  7898. const result = [];
  7899. while (!this.tsIsListTerminator(kind)) {
  7900. result.push(parseElement());
  7901. }
  7902. return result;
  7903. }
  7904. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7905. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7906. }
  7907. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7908. const result = [];
  7909. let trailingCommaPos = -1;
  7910. for (;;) {
  7911. if (this.tsIsListTerminator(kind)) {
  7912. break;
  7913. }
  7914. trailingCommaPos = -1;
  7915. const element = parseElement();
  7916. if (element == null) {
  7917. return undefined;
  7918. }
  7919. result.push(element);
  7920. if (this.eat(12)) {
  7921. trailingCommaPos = this.state.lastTokStartLoc.index;
  7922. continue;
  7923. }
  7924. if (this.tsIsListTerminator(kind)) {
  7925. break;
  7926. }
  7927. if (expectSuccess) {
  7928. this.expect(12);
  7929. }
  7930. return undefined;
  7931. }
  7932. if (refTrailingCommaPos) {
  7933. refTrailingCommaPos.value = trailingCommaPos;
  7934. }
  7935. return result;
  7936. }
  7937. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7938. if (!skipFirstToken) {
  7939. if (bracket) {
  7940. this.expect(0);
  7941. } else {
  7942. this.expect(47);
  7943. }
  7944. }
  7945. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7946. if (bracket) {
  7947. this.expect(3);
  7948. } else {
  7949. this.expect(48);
  7950. }
  7951. return result;
  7952. }
  7953. tsParseImportType() {
  7954. const node = this.startNode();
  7955. this.expect(83);
  7956. this.expect(10);
  7957. if (!this.match(134)) {
  7958. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7959. node.argument = super.parseExprAtom();
  7960. } else {
  7961. node.argument = this.parseStringLiteral(this.state.value);
  7962. }
  7963. if (this.eat(12)) {
  7964. node.options = this.tsParseImportTypeOptions();
  7965. } else {
  7966. node.options = null;
  7967. }
  7968. this.expect(11);
  7969. if (this.eat(16)) {
  7970. node.qualifier = this.tsParseEntityName(1 | 2);
  7971. }
  7972. if (this.match(47)) {
  7973. node.typeParameters = this.tsParseTypeArguments();
  7974. }
  7975. return this.finishNode(node, "TSImportType");
  7976. }
  7977. tsParseImportTypeOptions() {
  7978. const node = this.startNode();
  7979. this.expect(5);
  7980. const withProperty = this.startNode();
  7981. if (this.isContextual(76)) {
  7982. withProperty.method = false;
  7983. withProperty.key = this.parseIdentifier(true);
  7984. withProperty.computed = false;
  7985. withProperty.shorthand = false;
  7986. } else {
  7987. this.unexpected(null, 76);
  7988. }
  7989. this.expect(14);
  7990. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  7991. node.properties = [this.finishObjectProperty(withProperty)];
  7992. this.eat(12);
  7993. this.expect(8);
  7994. return this.finishNode(node, "ObjectExpression");
  7995. }
  7996. tsParseImportTypeWithPropertyValue() {
  7997. const node = this.startNode();
  7998. const properties = [];
  7999. this.expect(5);
  8000. while (!this.match(8)) {
  8001. const type = this.state.type;
  8002. if (tokenIsIdentifier(type) || type === 134) {
  8003. properties.push(super.parsePropertyDefinition(null));
  8004. } else {
  8005. this.unexpected();
  8006. }
  8007. this.eat(12);
  8008. }
  8009. node.properties = properties;
  8010. this.next();
  8011. return this.finishNode(node, "ObjectExpression");
  8012. }
  8013. tsParseEntityName(flags) {
  8014. let entity;
  8015. if (flags & 1 && this.match(78)) {
  8016. if (flags & 2) {
  8017. entity = this.parseIdentifier(true);
  8018. } else {
  8019. const node = this.startNode();
  8020. this.next();
  8021. entity = this.finishNode(node, "ThisExpression");
  8022. }
  8023. } else {
  8024. entity = this.parseIdentifier(!!(flags & 1));
  8025. }
  8026. while (this.eat(16)) {
  8027. const node = this.startNodeAtNode(entity);
  8028. node.left = entity;
  8029. node.right = this.parseIdentifier(!!(flags & 1));
  8030. entity = this.finishNode(node, "TSQualifiedName");
  8031. }
  8032. return entity;
  8033. }
  8034. tsParseTypeReference() {
  8035. const node = this.startNode();
  8036. node.typeName = this.tsParseEntityName(1);
  8037. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8038. node.typeParameters = this.tsParseTypeArguments();
  8039. }
  8040. return this.finishNode(node, "TSTypeReference");
  8041. }
  8042. tsParseThisTypePredicate(lhs) {
  8043. this.next();
  8044. const node = this.startNodeAtNode(lhs);
  8045. node.parameterName = lhs;
  8046. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  8047. node.asserts = false;
  8048. return this.finishNode(node, "TSTypePredicate");
  8049. }
  8050. tsParseThisTypeNode() {
  8051. const node = this.startNode();
  8052. this.next();
  8053. return this.finishNode(node, "TSThisType");
  8054. }
  8055. tsParseTypeQuery() {
  8056. const node = this.startNode();
  8057. this.expect(87);
  8058. if (this.match(83)) {
  8059. node.exprName = this.tsParseImportType();
  8060. } else {
  8061. node.exprName = this.tsParseEntityName(1 | 2);
  8062. }
  8063. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8064. node.typeParameters = this.tsParseTypeArguments();
  8065. }
  8066. return this.finishNode(node, "TSTypeQuery");
  8067. }
  8068. tsParseTypeParameter(parseModifiers) {
  8069. const node = this.startNode();
  8070. parseModifiers(node);
  8071. node.name = this.tsParseTypeParameterName();
  8072. node.constraint = this.tsEatThenParseType(81);
  8073. node.default = this.tsEatThenParseType(29);
  8074. return this.finishNode(node, "TSTypeParameter");
  8075. }
  8076. tsTryParseTypeParameters(parseModifiers) {
  8077. if (this.match(47)) {
  8078. return this.tsParseTypeParameters(parseModifiers);
  8079. }
  8080. }
  8081. tsParseTypeParameters(parseModifiers) {
  8082. const node = this.startNode();
  8083. if (this.match(47) || this.match(143)) {
  8084. this.next();
  8085. } else {
  8086. this.unexpected();
  8087. }
  8088. const refTrailingCommaPos = {
  8089. value: -1
  8090. };
  8091. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  8092. if (node.params.length === 0) {
  8093. this.raise(TSErrors.EmptyTypeParameters, node);
  8094. }
  8095. if (refTrailingCommaPos.value !== -1) {
  8096. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  8097. }
  8098. return this.finishNode(node, "TSTypeParameterDeclaration");
  8099. }
  8100. tsFillSignature(returnToken, signature) {
  8101. const returnTokenRequired = returnToken === 19;
  8102. const paramsKey = "parameters";
  8103. const returnTypeKey = "typeAnnotation";
  8104. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  8105. this.expect(10);
  8106. signature[paramsKey] = this.tsParseBindingListForSignature();
  8107. if (returnTokenRequired) {
  8108. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8109. } else if (this.match(returnToken)) {
  8110. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8111. }
  8112. }
  8113. tsParseBindingListForSignature() {
  8114. const list = super.parseBindingList(11, 41, 2);
  8115. for (const pattern of list) {
  8116. const {
  8117. type
  8118. } = pattern;
  8119. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  8120. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  8121. type
  8122. });
  8123. }
  8124. }
  8125. return list;
  8126. }
  8127. tsParseTypeMemberSemicolon() {
  8128. if (!this.eat(12) && !this.isLineTerminator()) {
  8129. this.expect(13);
  8130. }
  8131. }
  8132. tsParseSignatureMember(kind, node) {
  8133. this.tsFillSignature(14, node);
  8134. this.tsParseTypeMemberSemicolon();
  8135. return this.finishNode(node, kind);
  8136. }
  8137. tsIsUnambiguouslyIndexSignature() {
  8138. this.next();
  8139. if (tokenIsIdentifier(this.state.type)) {
  8140. this.next();
  8141. return this.match(14);
  8142. }
  8143. return false;
  8144. }
  8145. tsTryParseIndexSignature(node) {
  8146. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8147. return;
  8148. }
  8149. this.expect(0);
  8150. const id = this.parseIdentifier();
  8151. id.typeAnnotation = this.tsParseTypeAnnotation();
  8152. this.resetEndLocation(id);
  8153. this.expect(3);
  8154. node.parameters = [id];
  8155. const type = this.tsTryParseTypeAnnotation();
  8156. if (type) node.typeAnnotation = type;
  8157. this.tsParseTypeMemberSemicolon();
  8158. return this.finishNode(node, "TSIndexSignature");
  8159. }
  8160. tsParsePropertyOrMethodSignature(node, readonly) {
  8161. if (this.eat(17)) node.optional = true;
  8162. if (this.match(10) || this.match(47)) {
  8163. if (readonly) {
  8164. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  8165. }
  8166. const method = node;
  8167. if (method.kind && this.match(47)) {
  8168. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  8169. }
  8170. this.tsFillSignature(14, method);
  8171. this.tsParseTypeMemberSemicolon();
  8172. const paramsKey = "parameters";
  8173. const returnTypeKey = "typeAnnotation";
  8174. if (method.kind === "get") {
  8175. if (method[paramsKey].length > 0) {
  8176. this.raise(Errors.BadGetterArity, this.state.curPosition());
  8177. if (this.isThisParam(method[paramsKey][0])) {
  8178. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8179. }
  8180. }
  8181. } else if (method.kind === "set") {
  8182. if (method[paramsKey].length !== 1) {
  8183. this.raise(Errors.BadSetterArity, this.state.curPosition());
  8184. } else {
  8185. const firstParameter = method[paramsKey][0];
  8186. if (this.isThisParam(firstParameter)) {
  8187. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8188. }
  8189. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8190. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  8191. }
  8192. if (firstParameter.type === "RestElement") {
  8193. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  8194. }
  8195. }
  8196. if (method[returnTypeKey]) {
  8197. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  8198. }
  8199. } else {
  8200. method.kind = "method";
  8201. }
  8202. return this.finishNode(method, "TSMethodSignature");
  8203. } else {
  8204. const property = node;
  8205. if (readonly) property.readonly = true;
  8206. const type = this.tsTryParseTypeAnnotation();
  8207. if (type) property.typeAnnotation = type;
  8208. this.tsParseTypeMemberSemicolon();
  8209. return this.finishNode(property, "TSPropertySignature");
  8210. }
  8211. }
  8212. tsParseTypeMember() {
  8213. const node = this.startNode();
  8214. if (this.match(10) || this.match(47)) {
  8215. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8216. }
  8217. if (this.match(77)) {
  8218. const id = this.startNode();
  8219. this.next();
  8220. if (this.match(10) || this.match(47)) {
  8221. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8222. } else {
  8223. node.key = this.createIdentifier(id, "new");
  8224. return this.tsParsePropertyOrMethodSignature(node, false);
  8225. }
  8226. }
  8227. this.tsParseModifiers({
  8228. allowedModifiers: ["readonly"],
  8229. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8230. }, node);
  8231. const idx = this.tsTryParseIndexSignature(node);
  8232. if (idx) {
  8233. return idx;
  8234. }
  8235. super.parsePropertyName(node);
  8236. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8237. node.kind = node.key.name;
  8238. super.parsePropertyName(node);
  8239. if (!this.match(10) && !this.match(47)) {
  8240. this.unexpected(null, 10);
  8241. }
  8242. }
  8243. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8244. }
  8245. tsParseTypeLiteral() {
  8246. const node = this.startNode();
  8247. node.members = this.tsParseObjectTypeMembers();
  8248. return this.finishNode(node, "TSTypeLiteral");
  8249. }
  8250. tsParseObjectTypeMembers() {
  8251. this.expect(5);
  8252. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8253. this.expect(8);
  8254. return members;
  8255. }
  8256. tsIsStartOfMappedType() {
  8257. this.next();
  8258. if (this.eat(53)) {
  8259. return this.isContextual(122);
  8260. }
  8261. if (this.isContextual(122)) {
  8262. this.next();
  8263. }
  8264. if (!this.match(0)) {
  8265. return false;
  8266. }
  8267. this.next();
  8268. if (!this.tsIsIdentifier()) {
  8269. return false;
  8270. }
  8271. this.next();
  8272. return this.match(58);
  8273. }
  8274. tsParseMappedType() {
  8275. const node = this.startNode();
  8276. this.expect(5);
  8277. if (this.match(53)) {
  8278. node.readonly = this.state.value;
  8279. this.next();
  8280. this.expectContextual(122);
  8281. } else if (this.eatContextual(122)) {
  8282. node.readonly = true;
  8283. }
  8284. this.expect(0);
  8285. const typeParameter = this.startNode();
  8286. typeParameter.name = this.tsParseTypeParameterName();
  8287. typeParameter.constraint = this.tsExpectThenParseType(58);
  8288. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8289. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8290. this.expect(3);
  8291. if (this.match(53)) {
  8292. node.optional = this.state.value;
  8293. this.next();
  8294. this.expect(17);
  8295. } else if (this.eat(17)) {
  8296. node.optional = true;
  8297. }
  8298. node.typeAnnotation = this.tsTryParseType();
  8299. this.semicolon();
  8300. this.expect(8);
  8301. return this.finishNode(node, "TSMappedType");
  8302. }
  8303. tsParseTupleType() {
  8304. const node = this.startNode();
  8305. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8306. let seenOptionalElement = false;
  8307. node.elementTypes.forEach(elementNode => {
  8308. const {
  8309. type
  8310. } = elementNode;
  8311. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8312. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8313. }
  8314. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8315. });
  8316. return this.finishNode(node, "TSTupleType");
  8317. }
  8318. tsParseTupleElementType() {
  8319. const restStartLoc = this.state.startLoc;
  8320. const rest = this.eat(21);
  8321. const {
  8322. startLoc
  8323. } = this.state;
  8324. let labeled;
  8325. let label;
  8326. let optional;
  8327. let type;
  8328. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8329. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8330. if (chAfterWord === 58) {
  8331. labeled = true;
  8332. optional = false;
  8333. label = this.parseIdentifier(true);
  8334. this.expect(14);
  8335. type = this.tsParseType();
  8336. } else if (chAfterWord === 63) {
  8337. optional = true;
  8338. const wordName = this.state.value;
  8339. const typeOrLabel = this.tsParseNonArrayType();
  8340. if (this.lookaheadCharCode() === 58) {
  8341. labeled = true;
  8342. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8343. this.expect(17);
  8344. this.expect(14);
  8345. type = this.tsParseType();
  8346. } else {
  8347. labeled = false;
  8348. type = typeOrLabel;
  8349. this.expect(17);
  8350. }
  8351. } else {
  8352. type = this.tsParseType();
  8353. optional = this.eat(17);
  8354. labeled = this.eat(14);
  8355. }
  8356. if (labeled) {
  8357. let labeledNode;
  8358. if (label) {
  8359. labeledNode = this.startNodeAt(startLoc);
  8360. labeledNode.optional = optional;
  8361. labeledNode.label = label;
  8362. labeledNode.elementType = type;
  8363. if (this.eat(17)) {
  8364. labeledNode.optional = true;
  8365. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8366. }
  8367. } else {
  8368. labeledNode = this.startNodeAt(startLoc);
  8369. labeledNode.optional = optional;
  8370. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8371. labeledNode.label = type;
  8372. labeledNode.elementType = this.tsParseType();
  8373. }
  8374. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8375. } else if (optional) {
  8376. const optionalTypeNode = this.startNodeAt(startLoc);
  8377. optionalTypeNode.typeAnnotation = type;
  8378. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8379. }
  8380. if (rest) {
  8381. const restNode = this.startNodeAt(restStartLoc);
  8382. restNode.typeAnnotation = type;
  8383. type = this.finishNode(restNode, "TSRestType");
  8384. }
  8385. return type;
  8386. }
  8387. tsParseParenthesizedType() {
  8388. const node = this.startNode();
  8389. this.expect(10);
  8390. node.typeAnnotation = this.tsParseType();
  8391. this.expect(11);
  8392. return this.finishNode(node, "TSParenthesizedType");
  8393. }
  8394. tsParseFunctionOrConstructorType(type, abstract) {
  8395. const node = this.startNode();
  8396. if (type === "TSConstructorType") {
  8397. node.abstract = !!abstract;
  8398. if (abstract) this.next();
  8399. this.next();
  8400. }
  8401. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8402. return this.finishNode(node, type);
  8403. }
  8404. tsParseLiteralTypeNode() {
  8405. const node = this.startNode();
  8406. switch (this.state.type) {
  8407. case 135:
  8408. case 136:
  8409. case 134:
  8410. case 85:
  8411. case 86:
  8412. node.literal = super.parseExprAtom();
  8413. break;
  8414. default:
  8415. this.unexpected();
  8416. }
  8417. return this.finishNode(node, "TSLiteralType");
  8418. }
  8419. tsParseTemplateLiteralType() {
  8420. const node = this.startNode();
  8421. node.literal = super.parseTemplate(false);
  8422. return this.finishNode(node, "TSLiteralType");
  8423. }
  8424. parseTemplateSubstitution() {
  8425. if (this.state.inType) return this.tsParseType();
  8426. return super.parseTemplateSubstitution();
  8427. }
  8428. tsParseThisTypeOrThisTypePredicate() {
  8429. const thisKeyword = this.tsParseThisTypeNode();
  8430. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8431. return this.tsParseThisTypePredicate(thisKeyword);
  8432. } else {
  8433. return thisKeyword;
  8434. }
  8435. }
  8436. tsParseNonArrayType() {
  8437. switch (this.state.type) {
  8438. case 134:
  8439. case 135:
  8440. case 136:
  8441. case 85:
  8442. case 86:
  8443. return this.tsParseLiteralTypeNode();
  8444. case 53:
  8445. if (this.state.value === "-") {
  8446. const node = this.startNode();
  8447. const nextToken = this.lookahead();
  8448. if (nextToken.type !== 135 && nextToken.type !== 136) {
  8449. this.unexpected();
  8450. }
  8451. node.literal = this.parseMaybeUnary();
  8452. return this.finishNode(node, "TSLiteralType");
  8453. }
  8454. break;
  8455. case 78:
  8456. return this.tsParseThisTypeOrThisTypePredicate();
  8457. case 87:
  8458. return this.tsParseTypeQuery();
  8459. case 83:
  8460. return this.tsParseImportType();
  8461. case 5:
  8462. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8463. case 0:
  8464. return this.tsParseTupleType();
  8465. case 10:
  8466. return this.tsParseParenthesizedType();
  8467. case 25:
  8468. case 24:
  8469. return this.tsParseTemplateLiteralType();
  8470. default:
  8471. {
  8472. const {
  8473. type
  8474. } = this.state;
  8475. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8476. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8477. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8478. const node = this.startNode();
  8479. this.next();
  8480. return this.finishNode(node, nodeType);
  8481. }
  8482. return this.tsParseTypeReference();
  8483. }
  8484. }
  8485. }
  8486. throw this.unexpected();
  8487. }
  8488. tsParseArrayTypeOrHigher() {
  8489. const {
  8490. startLoc
  8491. } = this.state;
  8492. let type = this.tsParseNonArrayType();
  8493. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8494. if (this.match(3)) {
  8495. const node = this.startNodeAt(startLoc);
  8496. node.elementType = type;
  8497. this.expect(3);
  8498. type = this.finishNode(node, "TSArrayType");
  8499. } else {
  8500. const node = this.startNodeAt(startLoc);
  8501. node.objectType = type;
  8502. node.indexType = this.tsParseType();
  8503. this.expect(3);
  8504. type = this.finishNode(node, "TSIndexedAccessType");
  8505. }
  8506. }
  8507. return type;
  8508. }
  8509. tsParseTypeOperator() {
  8510. const node = this.startNode();
  8511. const operator = this.state.value;
  8512. this.next();
  8513. node.operator = operator;
  8514. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8515. if (operator === "readonly") {
  8516. this.tsCheckTypeAnnotationForReadOnly(node);
  8517. }
  8518. return this.finishNode(node, "TSTypeOperator");
  8519. }
  8520. tsCheckTypeAnnotationForReadOnly(node) {
  8521. switch (node.typeAnnotation.type) {
  8522. case "TSTupleType":
  8523. case "TSArrayType":
  8524. return;
  8525. default:
  8526. this.raise(TSErrors.UnexpectedReadonly, node);
  8527. }
  8528. }
  8529. tsParseInferType() {
  8530. const node = this.startNode();
  8531. this.expectContextual(115);
  8532. const typeParameter = this.startNode();
  8533. typeParameter.name = this.tsParseTypeParameterName();
  8534. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8535. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8536. return this.finishNode(node, "TSInferType");
  8537. }
  8538. tsParseConstraintForInferType() {
  8539. if (this.eat(81)) {
  8540. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8541. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8542. return constraint;
  8543. }
  8544. }
  8545. }
  8546. tsParseTypeOperatorOrHigher() {
  8547. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8548. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8549. }
  8550. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8551. const node = this.startNode();
  8552. const hasLeadingOperator = this.eat(operator);
  8553. const types = [];
  8554. do {
  8555. types.push(parseConstituentType());
  8556. } while (this.eat(operator));
  8557. if (types.length === 1 && !hasLeadingOperator) {
  8558. return types[0];
  8559. }
  8560. node.types = types;
  8561. return this.finishNode(node, kind);
  8562. }
  8563. tsParseIntersectionTypeOrHigher() {
  8564. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8565. }
  8566. tsParseUnionTypeOrHigher() {
  8567. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8568. }
  8569. tsIsStartOfFunctionType() {
  8570. if (this.match(47)) {
  8571. return true;
  8572. }
  8573. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8574. }
  8575. tsSkipParameterStart() {
  8576. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8577. this.next();
  8578. return true;
  8579. }
  8580. if (this.match(5)) {
  8581. const {
  8582. errors
  8583. } = this.state;
  8584. const previousErrorCount = errors.length;
  8585. try {
  8586. this.parseObjectLike(8, true);
  8587. return errors.length === previousErrorCount;
  8588. } catch (_unused) {
  8589. return false;
  8590. }
  8591. }
  8592. if (this.match(0)) {
  8593. this.next();
  8594. const {
  8595. errors
  8596. } = this.state;
  8597. const previousErrorCount = errors.length;
  8598. try {
  8599. super.parseBindingList(3, 93, 1);
  8600. return errors.length === previousErrorCount;
  8601. } catch (_unused2) {
  8602. return false;
  8603. }
  8604. }
  8605. return false;
  8606. }
  8607. tsIsUnambiguouslyStartOfFunctionType() {
  8608. this.next();
  8609. if (this.match(11) || this.match(21)) {
  8610. return true;
  8611. }
  8612. if (this.tsSkipParameterStart()) {
  8613. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8614. return true;
  8615. }
  8616. if (this.match(11)) {
  8617. this.next();
  8618. if (this.match(19)) {
  8619. return true;
  8620. }
  8621. }
  8622. }
  8623. return false;
  8624. }
  8625. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8626. return this.tsInType(() => {
  8627. const t = this.startNode();
  8628. this.expect(returnToken);
  8629. const node = this.startNode();
  8630. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8631. if (asserts && this.match(78)) {
  8632. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8633. if (thisTypePredicate.type === "TSThisType") {
  8634. node.parameterName = thisTypePredicate;
  8635. node.asserts = true;
  8636. node.typeAnnotation = null;
  8637. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8638. } else {
  8639. this.resetStartLocationFromNode(thisTypePredicate, node);
  8640. thisTypePredicate.asserts = true;
  8641. }
  8642. t.typeAnnotation = thisTypePredicate;
  8643. return this.finishNode(t, "TSTypeAnnotation");
  8644. }
  8645. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8646. if (!typePredicateVariable) {
  8647. if (!asserts) {
  8648. return this.tsParseTypeAnnotation(false, t);
  8649. }
  8650. node.parameterName = this.parseIdentifier();
  8651. node.asserts = asserts;
  8652. node.typeAnnotation = null;
  8653. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8654. return this.finishNode(t, "TSTypeAnnotation");
  8655. }
  8656. const type = this.tsParseTypeAnnotation(false);
  8657. node.parameterName = typePredicateVariable;
  8658. node.typeAnnotation = type;
  8659. node.asserts = asserts;
  8660. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8661. return this.finishNode(t, "TSTypeAnnotation");
  8662. });
  8663. }
  8664. tsTryParseTypeOrTypePredicateAnnotation() {
  8665. if (this.match(14)) {
  8666. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8667. }
  8668. }
  8669. tsTryParseTypeAnnotation() {
  8670. if (this.match(14)) {
  8671. return this.tsParseTypeAnnotation();
  8672. }
  8673. }
  8674. tsTryParseType() {
  8675. return this.tsEatThenParseType(14);
  8676. }
  8677. tsParseTypePredicatePrefix() {
  8678. const id = this.parseIdentifier();
  8679. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8680. this.next();
  8681. return id;
  8682. }
  8683. }
  8684. tsParseTypePredicateAsserts() {
  8685. if (this.state.type !== 109) {
  8686. return false;
  8687. }
  8688. const containsEsc = this.state.containsEsc;
  8689. this.next();
  8690. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8691. return false;
  8692. }
  8693. if (containsEsc) {
  8694. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8695. reservedWord: "asserts"
  8696. });
  8697. }
  8698. return true;
  8699. }
  8700. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8701. this.tsInType(() => {
  8702. if (eatColon) this.expect(14);
  8703. t.typeAnnotation = this.tsParseType();
  8704. });
  8705. return this.finishNode(t, "TSTypeAnnotation");
  8706. }
  8707. tsParseType() {
  8708. assert(this.state.inType);
  8709. const type = this.tsParseNonConditionalType();
  8710. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8711. return type;
  8712. }
  8713. const node = this.startNodeAtNode(type);
  8714. node.checkType = type;
  8715. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8716. this.expect(17);
  8717. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8718. this.expect(14);
  8719. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8720. return this.finishNode(node, "TSConditionalType");
  8721. }
  8722. isAbstractConstructorSignature() {
  8723. return this.isContextual(124) && this.isLookaheadContextual("new");
  8724. }
  8725. tsParseNonConditionalType() {
  8726. if (this.tsIsStartOfFunctionType()) {
  8727. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8728. }
  8729. if (this.match(77)) {
  8730. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8731. } else if (this.isAbstractConstructorSignature()) {
  8732. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8733. }
  8734. return this.tsParseUnionTypeOrHigher();
  8735. }
  8736. tsParseTypeAssertion() {
  8737. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8738. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8739. }
  8740. const node = this.startNode();
  8741. node.typeAnnotation = this.tsInType(() => {
  8742. this.next();
  8743. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8744. });
  8745. this.expect(48);
  8746. node.expression = this.parseMaybeUnary();
  8747. return this.finishNode(node, "TSTypeAssertion");
  8748. }
  8749. tsParseHeritageClause(token) {
  8750. const originalStartLoc = this.state.startLoc;
  8751. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8752. const node = this.startNode();
  8753. node.expression = this.tsParseEntityName(1 | 2);
  8754. if (this.match(47)) {
  8755. node.typeParameters = this.tsParseTypeArguments();
  8756. }
  8757. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8758. });
  8759. if (!delimitedList.length) {
  8760. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8761. token
  8762. });
  8763. }
  8764. return delimitedList;
  8765. }
  8766. tsParseInterfaceDeclaration(node, properties = {}) {
  8767. if (this.hasFollowingLineBreak()) return null;
  8768. this.expectContextual(129);
  8769. if (properties.declare) node.declare = true;
  8770. if (tokenIsIdentifier(this.state.type)) {
  8771. node.id = this.parseIdentifier();
  8772. this.checkIdentifier(node.id, 130);
  8773. } else {
  8774. node.id = null;
  8775. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8776. }
  8777. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8778. if (this.eat(81)) {
  8779. node.extends = this.tsParseHeritageClause("extends");
  8780. }
  8781. const body = this.startNode();
  8782. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8783. node.body = this.finishNode(body, "TSInterfaceBody");
  8784. return this.finishNode(node, "TSInterfaceDeclaration");
  8785. }
  8786. tsParseTypeAliasDeclaration(node) {
  8787. node.id = this.parseIdentifier();
  8788. this.checkIdentifier(node.id, 2);
  8789. node.typeAnnotation = this.tsInType(() => {
  8790. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8791. this.expect(29);
  8792. if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
  8793. const node = this.startNode();
  8794. this.next();
  8795. return this.finishNode(node, "TSIntrinsicKeyword");
  8796. }
  8797. return this.tsParseType();
  8798. });
  8799. this.semicolon();
  8800. return this.finishNode(node, "TSTypeAliasDeclaration");
  8801. }
  8802. tsInTopLevelContext(cb) {
  8803. if (this.curContext() !== types.brace) {
  8804. const oldContext = this.state.context;
  8805. this.state.context = [oldContext[0]];
  8806. try {
  8807. return cb();
  8808. } finally {
  8809. this.state.context = oldContext;
  8810. }
  8811. } else {
  8812. return cb();
  8813. }
  8814. }
  8815. tsInType(cb) {
  8816. const oldInType = this.state.inType;
  8817. this.state.inType = true;
  8818. try {
  8819. return cb();
  8820. } finally {
  8821. this.state.inType = oldInType;
  8822. }
  8823. }
  8824. tsInDisallowConditionalTypesContext(cb) {
  8825. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8826. this.state.inDisallowConditionalTypesContext = true;
  8827. try {
  8828. return cb();
  8829. } finally {
  8830. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8831. }
  8832. }
  8833. tsInAllowConditionalTypesContext(cb) {
  8834. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8835. this.state.inDisallowConditionalTypesContext = false;
  8836. try {
  8837. return cb();
  8838. } finally {
  8839. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8840. }
  8841. }
  8842. tsEatThenParseType(token) {
  8843. if (this.match(token)) {
  8844. return this.tsNextThenParseType();
  8845. }
  8846. }
  8847. tsExpectThenParseType(token) {
  8848. return this.tsInType(() => {
  8849. this.expect(token);
  8850. return this.tsParseType();
  8851. });
  8852. }
  8853. tsNextThenParseType() {
  8854. return this.tsInType(() => {
  8855. this.next();
  8856. return this.tsParseType();
  8857. });
  8858. }
  8859. tsParseEnumMember() {
  8860. const node = this.startNode();
  8861. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8862. if (this.eat(29)) {
  8863. node.initializer = super.parseMaybeAssignAllowIn();
  8864. }
  8865. return this.finishNode(node, "TSEnumMember");
  8866. }
  8867. tsParseEnumDeclaration(node, properties = {}) {
  8868. if (properties.const) node.const = true;
  8869. if (properties.declare) node.declare = true;
  8870. this.expectContextual(126);
  8871. node.id = this.parseIdentifier();
  8872. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8873. this.expect(5);
  8874. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8875. this.expect(8);
  8876. return this.finishNode(node, "TSEnumDeclaration");
  8877. }
  8878. tsParseEnumBody() {
  8879. const node = this.startNode();
  8880. this.expect(5);
  8881. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8882. this.expect(8);
  8883. return this.finishNode(node, "TSEnumBody");
  8884. }
  8885. tsParseModuleBlock() {
  8886. const node = this.startNode();
  8887. this.scope.enter(0);
  8888. this.expect(5);
  8889. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8890. this.scope.exit();
  8891. return this.finishNode(node, "TSModuleBlock");
  8892. }
  8893. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8894. node.id = this.parseIdentifier();
  8895. if (!nested) {
  8896. this.checkIdentifier(node.id, 1024);
  8897. }
  8898. if (this.eat(16)) {
  8899. const inner = this.startNode();
  8900. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8901. node.body = inner;
  8902. } else {
  8903. this.scope.enter(1024);
  8904. this.prodParam.enter(0);
  8905. node.body = this.tsParseModuleBlock();
  8906. this.prodParam.exit();
  8907. this.scope.exit();
  8908. }
  8909. return this.finishNode(node, "TSModuleDeclaration");
  8910. }
  8911. tsParseAmbientExternalModuleDeclaration(node) {
  8912. if (this.isContextual(112)) {
  8913. node.kind = "global";
  8914. node.global = true;
  8915. node.id = this.parseIdentifier();
  8916. } else if (this.match(134)) {
  8917. node.kind = "module";
  8918. node.id = super.parseStringLiteral(this.state.value);
  8919. } else {
  8920. this.unexpected();
  8921. }
  8922. if (this.match(5)) {
  8923. this.scope.enter(1024);
  8924. this.prodParam.enter(0);
  8925. node.body = this.tsParseModuleBlock();
  8926. this.prodParam.exit();
  8927. this.scope.exit();
  8928. } else {
  8929. this.semicolon();
  8930. }
  8931. return this.finishNode(node, "TSModuleDeclaration");
  8932. }
  8933. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8934. node.isExport = isExport || false;
  8935. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8936. this.checkIdentifier(node.id, 4096);
  8937. this.expect(29);
  8938. const moduleReference = this.tsParseModuleReference();
  8939. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8940. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8941. }
  8942. node.moduleReference = moduleReference;
  8943. this.semicolon();
  8944. return this.finishNode(node, "TSImportEqualsDeclaration");
  8945. }
  8946. tsIsExternalModuleReference() {
  8947. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8948. }
  8949. tsParseModuleReference() {
  8950. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  8951. }
  8952. tsParseExternalModuleReference() {
  8953. const node = this.startNode();
  8954. this.expectContextual(119);
  8955. this.expect(10);
  8956. if (!this.match(134)) {
  8957. this.unexpected();
  8958. }
  8959. node.expression = super.parseExprAtom();
  8960. this.expect(11);
  8961. this.sawUnambiguousESM = true;
  8962. return this.finishNode(node, "TSExternalModuleReference");
  8963. }
  8964. tsLookAhead(f) {
  8965. const state = this.state.clone();
  8966. const res = f();
  8967. this.state = state;
  8968. return res;
  8969. }
  8970. tsTryParseAndCatch(f) {
  8971. const result = this.tryParse(abort => f() || abort());
  8972. if (result.aborted || !result.node) return;
  8973. if (result.error) this.state = result.failState;
  8974. return result.node;
  8975. }
  8976. tsTryParse(f) {
  8977. const state = this.state.clone();
  8978. const result = f();
  8979. if (result !== undefined && result !== false) {
  8980. return result;
  8981. }
  8982. this.state = state;
  8983. }
  8984. tsTryParseDeclare(node) {
  8985. if (this.isLineTerminator()) {
  8986. return;
  8987. }
  8988. const startType = this.state.type;
  8989. return this.tsInAmbientContext(() => {
  8990. switch (startType) {
  8991. case 68:
  8992. node.declare = true;
  8993. return super.parseFunctionStatement(node, false, false);
  8994. case 80:
  8995. node.declare = true;
  8996. return this.parseClass(node, true, false);
  8997. case 126:
  8998. return this.tsParseEnumDeclaration(node, {
  8999. declare: true
  9000. });
  9001. case 112:
  9002. return this.tsParseAmbientExternalModuleDeclaration(node);
  9003. case 100:
  9004. if (this.state.containsEsc) {
  9005. return;
  9006. }
  9007. case 75:
  9008. case 74:
  9009. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  9010. node.declare = true;
  9011. return this.parseVarStatement(node, this.state.value, true);
  9012. }
  9013. this.expect(75);
  9014. return this.tsParseEnumDeclaration(node, {
  9015. const: true,
  9016. declare: true
  9017. });
  9018. case 107:
  9019. if (this.isUsing()) {
  9020. this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
  9021. node.declare = true;
  9022. return this.parseVarStatement(node, "using", true);
  9023. }
  9024. break;
  9025. case 96:
  9026. if (this.isAwaitUsing()) {
  9027. this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
  9028. node.declare = true;
  9029. this.next();
  9030. return this.parseVarStatement(node, "await using", true);
  9031. }
  9032. break;
  9033. case 129:
  9034. {
  9035. const result = this.tsParseInterfaceDeclaration(node, {
  9036. declare: true
  9037. });
  9038. if (result) return result;
  9039. }
  9040. default:
  9041. if (tokenIsIdentifier(startType)) {
  9042. return this.tsParseDeclaration(node, this.state.type, true, null);
  9043. }
  9044. }
  9045. });
  9046. }
  9047. tsTryParseExportDeclaration() {
  9048. return this.tsParseDeclaration(this.startNode(), this.state.type, true, null);
  9049. }
  9050. tsParseDeclaration(node, type, next, decorators) {
  9051. switch (type) {
  9052. case 124:
  9053. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  9054. return this.tsParseAbstractDeclaration(node, decorators);
  9055. }
  9056. break;
  9057. case 127:
  9058. if (this.tsCheckLineTerminator(next)) {
  9059. if (this.match(134)) {
  9060. return this.tsParseAmbientExternalModuleDeclaration(node);
  9061. } else if (tokenIsIdentifier(this.state.type)) {
  9062. node.kind = "module";
  9063. return this.tsParseModuleOrNamespaceDeclaration(node);
  9064. }
  9065. }
  9066. break;
  9067. case 128:
  9068. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9069. node.kind = "namespace";
  9070. return this.tsParseModuleOrNamespaceDeclaration(node);
  9071. }
  9072. break;
  9073. case 130:
  9074. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9075. return this.tsParseTypeAliasDeclaration(node);
  9076. }
  9077. break;
  9078. }
  9079. }
  9080. tsCheckLineTerminator(next) {
  9081. if (next) {
  9082. if (this.hasFollowingLineBreak()) return false;
  9083. this.next();
  9084. return true;
  9085. }
  9086. return !this.isLineTerminator();
  9087. }
  9088. tsTryParseGenericAsyncArrowFunction(startLoc) {
  9089. if (!this.match(47)) return;
  9090. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9091. this.state.maybeInArrowParameters = true;
  9092. const res = this.tsTryParseAndCatch(() => {
  9093. const node = this.startNodeAt(startLoc);
  9094. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9095. super.parseFunctionParams(node);
  9096. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9097. this.expect(19);
  9098. return node;
  9099. });
  9100. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9101. if (!res) return;
  9102. return super.parseArrowExpression(res, null, true);
  9103. }
  9104. tsParseTypeArgumentsInExpression() {
  9105. if (this.reScan_lt() !== 47) return;
  9106. return this.tsParseTypeArguments();
  9107. }
  9108. tsParseTypeArguments() {
  9109. const node = this.startNode();
  9110. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  9111. this.expect(47);
  9112. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9113. }));
  9114. if (node.params.length === 0) {
  9115. this.raise(TSErrors.EmptyTypeArguments, node);
  9116. } else if (!this.state.inType && this.curContext() === types.brace) {
  9117. this.reScan_lt_gt();
  9118. }
  9119. this.expect(48);
  9120. return this.finishNode(node, "TSTypeParameterInstantiation");
  9121. }
  9122. tsIsDeclarationStart() {
  9123. return tokenIsTSDeclarationStart(this.state.type);
  9124. }
  9125. isExportDefaultSpecifier() {
  9126. if (this.tsIsDeclarationStart()) return false;
  9127. return super.isExportDefaultSpecifier();
  9128. }
  9129. parseBindingElement(flags, decorators) {
  9130. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  9131. const modified = {};
  9132. this.tsParseModifiers({
  9133. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9134. }, modified);
  9135. const accessibility = modified.accessibility;
  9136. const override = modified.override;
  9137. const readonly = modified.readonly;
  9138. if (!(flags & 4) && (accessibility || readonly || override)) {
  9139. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  9140. }
  9141. const left = this.parseMaybeDefault();
  9142. if (flags & 2) {
  9143. this.parseFunctionParamType(left);
  9144. }
  9145. const elt = this.parseMaybeDefault(left.loc.start, left);
  9146. if (accessibility || readonly || override) {
  9147. const pp = this.startNodeAt(startLoc);
  9148. if (decorators.length) {
  9149. pp.decorators = decorators;
  9150. }
  9151. if (accessibility) pp.accessibility = accessibility;
  9152. if (readonly) pp.readonly = readonly;
  9153. if (override) pp.override = override;
  9154. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9155. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  9156. }
  9157. pp.parameter = elt;
  9158. return this.finishNode(pp, "TSParameterProperty");
  9159. }
  9160. if (decorators.length) {
  9161. left.decorators = decorators;
  9162. }
  9163. return elt;
  9164. }
  9165. isSimpleParameter(node) {
  9166. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9167. }
  9168. tsDisallowOptionalPattern(node) {
  9169. for (const param of node.params) {
  9170. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9171. this.raise(TSErrors.PatternIsOptional, param);
  9172. }
  9173. }
  9174. }
  9175. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9176. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9177. this.tsDisallowOptionalPattern(node);
  9178. }
  9179. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9180. if (this.match(14)) {
  9181. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9182. }
  9183. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9184. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9185. return this.finishNode(node, bodilessType);
  9186. }
  9187. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9188. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  9189. if (node.declare) {
  9190. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9191. }
  9192. }
  9193. this.tsDisallowOptionalPattern(node);
  9194. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9195. }
  9196. registerFunctionStatementId(node) {
  9197. if (!node.body && node.id) {
  9198. this.checkIdentifier(node.id, 1024);
  9199. } else {
  9200. super.registerFunctionStatementId(node);
  9201. }
  9202. }
  9203. tsCheckForInvalidTypeCasts(items) {
  9204. items.forEach(node => {
  9205. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9206. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  9207. }
  9208. });
  9209. }
  9210. toReferencedList(exprList, isInParens) {
  9211. this.tsCheckForInvalidTypeCasts(exprList);
  9212. return exprList;
  9213. }
  9214. parseArrayLike(close, isTuple, refExpressionErrors) {
  9215. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  9216. if (node.type === "ArrayExpression") {
  9217. this.tsCheckForInvalidTypeCasts(node.elements);
  9218. }
  9219. return node;
  9220. }
  9221. parseSubscript(base, startLoc, noCalls, state) {
  9222. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9223. this.state.canStartJSXElement = false;
  9224. this.next();
  9225. const nonNullExpression = this.startNodeAt(startLoc);
  9226. nonNullExpression.expression = base;
  9227. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9228. }
  9229. let isOptionalCall = false;
  9230. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9231. if (noCalls) {
  9232. state.stop = true;
  9233. return base;
  9234. }
  9235. state.optionalChainMember = isOptionalCall = true;
  9236. this.next();
  9237. }
  9238. if (this.match(47) || this.match(51)) {
  9239. let missingParenErrorLoc;
  9240. const result = this.tsTryParseAndCatch(() => {
  9241. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9242. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9243. if (asyncArrowFn) {
  9244. state.stop = true;
  9245. return asyncArrowFn;
  9246. }
  9247. }
  9248. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9249. if (!typeArguments) return;
  9250. if (isOptionalCall && !this.match(10)) {
  9251. missingParenErrorLoc = this.state.curPosition();
  9252. return;
  9253. }
  9254. if (tokenIsTemplate(this.state.type)) {
  9255. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9256. result.typeParameters = typeArguments;
  9257. return result;
  9258. }
  9259. if (!noCalls && this.eat(10)) {
  9260. const node = this.startNodeAt(startLoc);
  9261. node.callee = base;
  9262. node.arguments = this.parseCallExpressionArguments();
  9263. this.tsCheckForInvalidTypeCasts(node.arguments);
  9264. node.typeParameters = typeArguments;
  9265. if (state.optionalChainMember) {
  9266. node.optional = isOptionalCall;
  9267. }
  9268. return this.finishCallExpression(node, state.optionalChainMember);
  9269. }
  9270. const tokenType = this.state.type;
  9271. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenType !== 93 && tokenType !== 120 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9272. return;
  9273. }
  9274. const node = this.startNodeAt(startLoc);
  9275. node.expression = base;
  9276. node.typeParameters = typeArguments;
  9277. return this.finishNode(node, "TSInstantiationExpression");
  9278. });
  9279. if (missingParenErrorLoc) {
  9280. this.unexpected(missingParenErrorLoc, 10);
  9281. }
  9282. if (result) {
  9283. if (result.type === "TSInstantiationExpression") {
  9284. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  9285. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  9286. }
  9287. if (!this.match(16) && !this.match(18)) {
  9288. result.expression = super.stopParseSubscript(base, state);
  9289. }
  9290. }
  9291. return result;
  9292. }
  9293. }
  9294. return super.parseSubscript(base, startLoc, noCalls, state);
  9295. }
  9296. parseNewCallee(node) {
  9297. var _callee$extra;
  9298. super.parseNewCallee(node);
  9299. const {
  9300. callee
  9301. } = node;
  9302. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9303. node.typeParameters = callee.typeParameters;
  9304. node.callee = callee.expression;
  9305. }
  9306. }
  9307. parseExprOp(left, leftStartLoc, minPrec) {
  9308. let isSatisfies;
  9309. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9310. const node = this.startNodeAt(leftStartLoc);
  9311. node.expression = left;
  9312. node.typeAnnotation = this.tsInType(() => {
  9313. this.next();
  9314. if (this.match(75)) {
  9315. if (isSatisfies) {
  9316. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9317. keyword: "const"
  9318. });
  9319. }
  9320. return this.tsParseTypeReference();
  9321. }
  9322. return this.tsParseType();
  9323. });
  9324. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9325. this.reScan_lt_gt();
  9326. return this.parseExprOp(node, leftStartLoc, minPrec);
  9327. }
  9328. return super.parseExprOp(left, leftStartLoc, minPrec);
  9329. }
  9330. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9331. if (!this.state.isAmbientContext) {
  9332. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9333. }
  9334. }
  9335. checkImportReflection(node) {
  9336. super.checkImportReflection(node);
  9337. if (node.module && node.importKind !== "value") {
  9338. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9339. }
  9340. }
  9341. checkDuplicateExports() {}
  9342. isPotentialImportPhase(isExport) {
  9343. if (super.isPotentialImportPhase(isExport)) return true;
  9344. if (this.isContextual(130)) {
  9345. const ch = this.lookaheadCharCode();
  9346. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9347. }
  9348. return !isExport && this.isContextual(87);
  9349. }
  9350. applyImportPhase(node, isExport, phase, loc) {
  9351. super.applyImportPhase(node, isExport, phase, loc);
  9352. if (isExport) {
  9353. node.exportKind = phase === "type" ? "type" : "value";
  9354. } else {
  9355. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9356. }
  9357. }
  9358. parseImport(node) {
  9359. if (this.match(134)) {
  9360. node.importKind = "value";
  9361. return super.parseImport(node);
  9362. }
  9363. let importNode;
  9364. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9365. node.importKind = "value";
  9366. return this.tsParseImportEqualsDeclaration(node);
  9367. } else if (this.isContextual(130)) {
  9368. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9369. if (this.lookaheadCharCode() === 61) {
  9370. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9371. } else {
  9372. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9373. }
  9374. } else {
  9375. importNode = super.parseImport(node);
  9376. }
  9377. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9378. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9379. }
  9380. return importNode;
  9381. }
  9382. parseExport(node, decorators) {
  9383. if (this.match(83)) {
  9384. const nodeImportEquals = node;
  9385. this.next();
  9386. let maybeDefaultIdentifier = null;
  9387. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9388. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9389. } else {
  9390. nodeImportEquals.importKind = "value";
  9391. }
  9392. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9393. return declaration;
  9394. } else if (this.eat(29)) {
  9395. const assign = node;
  9396. assign.expression = super.parseExpression();
  9397. this.semicolon();
  9398. this.sawUnambiguousESM = true;
  9399. return this.finishNode(assign, "TSExportAssignment");
  9400. } else if (this.eatContextual(93)) {
  9401. const decl = node;
  9402. this.expectContextual(128);
  9403. decl.id = this.parseIdentifier();
  9404. this.semicolon();
  9405. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9406. } else {
  9407. return super.parseExport(node, decorators);
  9408. }
  9409. }
  9410. isAbstractClass() {
  9411. return this.isContextual(124) && this.isLookaheadContextual("class");
  9412. }
  9413. parseExportDefaultExpression() {
  9414. if (this.isAbstractClass()) {
  9415. const cls = this.startNode();
  9416. this.next();
  9417. cls.abstract = true;
  9418. return this.parseClass(cls, true, true);
  9419. }
  9420. if (this.match(129)) {
  9421. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9422. if (result) return result;
  9423. }
  9424. return super.parseExportDefaultExpression();
  9425. }
  9426. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9427. const {
  9428. isAmbientContext
  9429. } = this.state;
  9430. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9431. if (!isAmbientContext) return declaration;
  9432. if (!node.declare && (kind === "using" || kind === "await using")) {
  9433. this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
  9434. return declaration;
  9435. }
  9436. for (const {
  9437. id,
  9438. init
  9439. } of declaration.declarations) {
  9440. if (!init) continue;
  9441. if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
  9442. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9443. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9444. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9445. }
  9446. }
  9447. return declaration;
  9448. }
  9449. parseStatementContent(flags, decorators) {
  9450. if (!this.state.containsEsc) {
  9451. switch (this.state.type) {
  9452. case 75:
  9453. {
  9454. if (this.isLookaheadContextual("enum")) {
  9455. const node = this.startNode();
  9456. this.expect(75);
  9457. return this.tsParseEnumDeclaration(node, {
  9458. const: true
  9459. });
  9460. }
  9461. break;
  9462. }
  9463. case 124:
  9464. case 125:
  9465. {
  9466. if (this.nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine()) {
  9467. const token = this.state.type;
  9468. const node = this.startNode();
  9469. this.next();
  9470. const declaration = token === 125 ? this.tsTryParseDeclare(node) : this.tsParseAbstractDeclaration(node, decorators);
  9471. if (declaration) {
  9472. if (token === 125) {
  9473. declaration.declare = true;
  9474. }
  9475. return declaration;
  9476. } else {
  9477. node.expression = this.createIdentifier(this.startNodeAt(node.loc.start), token === 125 ? "declare" : "abstract");
  9478. this.semicolon(false);
  9479. return this.finishNode(node, "ExpressionStatement");
  9480. }
  9481. }
  9482. break;
  9483. }
  9484. case 126:
  9485. return this.tsParseEnumDeclaration(this.startNode());
  9486. case 112:
  9487. {
  9488. const nextCh = this.lookaheadCharCode();
  9489. if (nextCh === 123) {
  9490. const node = this.startNode();
  9491. return this.tsParseAmbientExternalModuleDeclaration(node);
  9492. }
  9493. break;
  9494. }
  9495. case 129:
  9496. {
  9497. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9498. if (result) return result;
  9499. break;
  9500. }
  9501. case 127:
  9502. {
  9503. if (this.nextTokenIsIdentifierOrStringLiteralOnSameLine()) {
  9504. const node = this.startNode();
  9505. this.next();
  9506. return this.tsParseDeclaration(node, 127, false, decorators);
  9507. }
  9508. break;
  9509. }
  9510. case 128:
  9511. {
  9512. if (this.nextTokenIsIdentifierOnSameLine()) {
  9513. const node = this.startNode();
  9514. this.next();
  9515. return this.tsParseDeclaration(node, 128, false, decorators);
  9516. }
  9517. break;
  9518. }
  9519. case 130:
  9520. {
  9521. if (this.nextTokenIsIdentifierOnSameLine()) {
  9522. const node = this.startNode();
  9523. this.next();
  9524. return this.tsParseTypeAliasDeclaration(node);
  9525. }
  9526. break;
  9527. }
  9528. }
  9529. }
  9530. return super.parseStatementContent(flags, decorators);
  9531. }
  9532. parseAccessModifier() {
  9533. return this.tsParseModifier(["public", "protected", "private"]);
  9534. }
  9535. tsHasSomeModifiers(member, modifiers) {
  9536. return modifiers.some(modifier => {
  9537. if (tsIsAccessModifier(modifier)) {
  9538. return member.accessibility === modifier;
  9539. }
  9540. return !!member[modifier];
  9541. });
  9542. }
  9543. tsIsStartOfStaticBlocks() {
  9544. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9545. }
  9546. parseClassMember(classBody, member, state) {
  9547. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9548. this.tsParseModifiers({
  9549. allowedModifiers: modifiers,
  9550. disallowedModifiers: ["in", "out"],
  9551. stopOnStartOfClassStaticBlock: true,
  9552. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9553. }, member);
  9554. const callParseClassMemberWithIsStatic = () => {
  9555. if (this.tsIsStartOfStaticBlocks()) {
  9556. this.next();
  9557. this.next();
  9558. if (this.tsHasSomeModifiers(member, modifiers)) {
  9559. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9560. }
  9561. super.parseClassStaticBlock(classBody, member);
  9562. } else {
  9563. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9564. }
  9565. };
  9566. if (member.declare) {
  9567. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9568. } else {
  9569. callParseClassMemberWithIsStatic();
  9570. }
  9571. }
  9572. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9573. const idx = this.tsTryParseIndexSignature(member);
  9574. if (idx) {
  9575. classBody.body.push(idx);
  9576. if (member.abstract) {
  9577. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9578. }
  9579. if (member.accessibility) {
  9580. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9581. modifier: member.accessibility
  9582. });
  9583. }
  9584. if (member.declare) {
  9585. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9586. }
  9587. if (member.override) {
  9588. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9589. }
  9590. return;
  9591. }
  9592. if (!this.state.inAbstractClass && member.abstract) {
  9593. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9594. }
  9595. if (member.override) {
  9596. if (!state.hadSuperClass) {
  9597. this.raise(TSErrors.OverrideNotInSubClass, member);
  9598. }
  9599. }
  9600. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9601. }
  9602. parsePostMemberNameModifiers(methodOrProp) {
  9603. const optional = this.eat(17);
  9604. if (optional) methodOrProp.optional = true;
  9605. if (methodOrProp.readonly && this.match(10)) {
  9606. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9607. }
  9608. if (methodOrProp.declare && this.match(10)) {
  9609. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9610. }
  9611. }
  9612. shouldParseExportDeclaration() {
  9613. if (this.tsIsDeclarationStart()) return true;
  9614. return super.shouldParseExportDeclaration();
  9615. }
  9616. parseConditional(expr, startLoc, refExpressionErrors) {
  9617. if (!this.match(17)) return expr;
  9618. if (this.state.maybeInArrowParameters) {
  9619. const nextCh = this.lookaheadCharCode();
  9620. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  9621. this.setOptionalParametersError(refExpressionErrors);
  9622. return expr;
  9623. }
  9624. }
  9625. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9626. }
  9627. parseParenItem(node, startLoc) {
  9628. const newNode = super.parseParenItem(node, startLoc);
  9629. if (this.eat(17)) {
  9630. newNode.optional = true;
  9631. this.resetEndLocation(node);
  9632. }
  9633. if (this.match(14)) {
  9634. const typeCastNode = this.startNodeAt(startLoc);
  9635. typeCastNode.expression = node;
  9636. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9637. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9638. }
  9639. return node;
  9640. }
  9641. parseExportDeclaration(node) {
  9642. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9643. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9644. }
  9645. const startLoc = this.state.startLoc;
  9646. const isDeclare = this.eatContextual(125);
  9647. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9648. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9649. }
  9650. const isIdentifier = tokenIsIdentifier(this.state.type);
  9651. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9652. if (!declaration) return null;
  9653. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9654. node.exportKind = "type";
  9655. }
  9656. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  9657. this.resetStartLocation(declaration, startLoc);
  9658. declaration.declare = true;
  9659. }
  9660. return declaration;
  9661. }
  9662. parseClassId(node, isStatement, optionalId, bindingType) {
  9663. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9664. return;
  9665. }
  9666. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9667. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9668. if (typeParameters) node.typeParameters = typeParameters;
  9669. }
  9670. parseClassPropertyAnnotation(node) {
  9671. if (!node.optional) {
  9672. if (this.eat(35)) {
  9673. node.definite = true;
  9674. } else if (this.eat(17)) {
  9675. node.optional = true;
  9676. }
  9677. }
  9678. const type = this.tsTryParseTypeAnnotation();
  9679. if (type) node.typeAnnotation = type;
  9680. }
  9681. parseClassProperty(node) {
  9682. this.parseClassPropertyAnnotation(node);
  9683. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9684. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9685. }
  9686. if (node.abstract && this.match(29)) {
  9687. const {
  9688. key
  9689. } = node;
  9690. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9691. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9692. });
  9693. }
  9694. return super.parseClassProperty(node);
  9695. }
  9696. parseClassPrivateProperty(node) {
  9697. if (node.abstract) {
  9698. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9699. }
  9700. if (node.accessibility) {
  9701. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9702. modifier: node.accessibility
  9703. });
  9704. }
  9705. this.parseClassPropertyAnnotation(node);
  9706. return super.parseClassPrivateProperty(node);
  9707. }
  9708. parseClassAccessorProperty(node) {
  9709. this.parseClassPropertyAnnotation(node);
  9710. if (node.optional) {
  9711. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9712. }
  9713. return super.parseClassAccessorProperty(node);
  9714. }
  9715. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9716. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9717. if (typeParameters && isConstructor) {
  9718. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9719. }
  9720. const {
  9721. declare = false,
  9722. kind
  9723. } = method;
  9724. if (declare && (kind === "get" || kind === "set")) {
  9725. this.raise(TSErrors.DeclareAccessor, method, {
  9726. kind
  9727. });
  9728. }
  9729. if (typeParameters) method.typeParameters = typeParameters;
  9730. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9731. }
  9732. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9733. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9734. if (typeParameters) method.typeParameters = typeParameters;
  9735. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9736. }
  9737. declareClassPrivateMethodInScope(node, kind) {
  9738. if (node.type === "TSDeclareMethod") return;
  9739. if (node.type === "MethodDefinition" && node.value.body == null) {
  9740. return;
  9741. }
  9742. super.declareClassPrivateMethodInScope(node, kind);
  9743. }
  9744. parseClassSuper(node) {
  9745. super.parseClassSuper(node);
  9746. if (node.superClass) {
  9747. if (node.superClass.type === "TSInstantiationExpression") {
  9748. const tsInstantiationExpression = node.superClass;
  9749. const superClass = tsInstantiationExpression.expression;
  9750. this.takeSurroundingComments(superClass, superClass.start, superClass.end);
  9751. const superTypeArguments = tsInstantiationExpression.typeParameters;
  9752. this.takeSurroundingComments(superTypeArguments, superTypeArguments.start, superTypeArguments.end);
  9753. node.superClass = superClass;
  9754. node.superTypeParameters = superTypeArguments;
  9755. } else if (this.match(47) || this.match(51)) {
  9756. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9757. }
  9758. }
  9759. if (this.eatContextual(113)) {
  9760. node.implements = this.tsParseHeritageClause("implements");
  9761. }
  9762. }
  9763. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9764. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9765. if (typeParameters) prop.typeParameters = typeParameters;
  9766. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9767. }
  9768. parseFunctionParams(node, isConstructor) {
  9769. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9770. if (typeParameters) node.typeParameters = typeParameters;
  9771. super.parseFunctionParams(node, isConstructor);
  9772. }
  9773. parseVarId(decl, kind) {
  9774. super.parseVarId(decl, kind);
  9775. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9776. decl.definite = true;
  9777. }
  9778. const type = this.tsTryParseTypeAnnotation();
  9779. if (type) {
  9780. decl.id.typeAnnotation = type;
  9781. this.resetEndLocation(decl.id);
  9782. }
  9783. }
  9784. parseAsyncArrowFromCallExpression(node, call) {
  9785. if (this.match(14)) {
  9786. node.returnType = this.tsParseTypeAnnotation();
  9787. }
  9788. return super.parseAsyncArrowFromCallExpression(node, call);
  9789. }
  9790. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9791. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9792. let state;
  9793. let jsx;
  9794. let typeCast;
  9795. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  9796. state = this.state.clone();
  9797. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9798. if (!jsx.error) return jsx.node;
  9799. const {
  9800. context
  9801. } = this.state;
  9802. const currentContext = context[context.length - 1];
  9803. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9804. context.pop();
  9805. }
  9806. }
  9807. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9808. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9809. }
  9810. if (!state || state === this.state) state = this.state.clone();
  9811. let typeParameters;
  9812. const arrow = this.tryParse(abort => {
  9813. var _expr$extra, _typeParameters;
  9814. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9815. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9816. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9817. abort();
  9818. }
  9819. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9820. this.resetStartLocationFromNode(expr, typeParameters);
  9821. }
  9822. expr.typeParameters = typeParameters;
  9823. return expr;
  9824. }, state);
  9825. if (!arrow.error && !arrow.aborted) {
  9826. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9827. return arrow.node;
  9828. }
  9829. if (!jsx) {
  9830. assert(!this.hasPlugin("jsx"));
  9831. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9832. if (!typeCast.error) return typeCast.node;
  9833. }
  9834. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9835. this.state = jsx.failState;
  9836. return jsx.node;
  9837. }
  9838. if (arrow.node) {
  9839. this.state = arrow.failState;
  9840. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9841. return arrow.node;
  9842. }
  9843. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9844. this.state = typeCast.failState;
  9845. return typeCast.node;
  9846. }
  9847. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9848. }
  9849. reportReservedArrowTypeParam(node) {
  9850. var _node$extra2;
  9851. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9852. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9853. }
  9854. }
  9855. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9856. if (!this.hasPlugin("jsx") && this.match(47)) {
  9857. return this.tsParseTypeAssertion();
  9858. }
  9859. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9860. }
  9861. parseArrow(node) {
  9862. if (this.match(14)) {
  9863. const result = this.tryParse(abort => {
  9864. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9865. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9866. return returnType;
  9867. });
  9868. if (result.aborted) return;
  9869. if (!result.thrown) {
  9870. if (result.error) this.state = result.failState;
  9871. node.returnType = result.node;
  9872. }
  9873. }
  9874. return super.parseArrow(node);
  9875. }
  9876. parseFunctionParamType(param) {
  9877. if (this.eat(17)) {
  9878. param.optional = true;
  9879. }
  9880. const type = this.tsTryParseTypeAnnotation();
  9881. if (type) param.typeAnnotation = type;
  9882. this.resetEndLocation(param);
  9883. return param;
  9884. }
  9885. isAssignable(node, isBinding) {
  9886. switch (node.type) {
  9887. case "TSTypeCastExpression":
  9888. return this.isAssignable(node.expression, isBinding);
  9889. case "TSParameterProperty":
  9890. return true;
  9891. default:
  9892. return super.isAssignable(node, isBinding);
  9893. }
  9894. }
  9895. toAssignable(node, isLHS = false) {
  9896. switch (node.type) {
  9897. case "ParenthesizedExpression":
  9898. this.toAssignableParenthesizedExpression(node, isLHS);
  9899. break;
  9900. case "TSAsExpression":
  9901. case "TSSatisfiesExpression":
  9902. case "TSNonNullExpression":
  9903. case "TSTypeAssertion":
  9904. if (isLHS) {
  9905. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9906. } else {
  9907. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9908. }
  9909. this.toAssignable(node.expression, isLHS);
  9910. break;
  9911. case "AssignmentExpression":
  9912. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9913. node.left = this.typeCastToParameter(node.left);
  9914. }
  9915. default:
  9916. super.toAssignable(node, isLHS);
  9917. }
  9918. }
  9919. toAssignableParenthesizedExpression(node, isLHS) {
  9920. switch (node.expression.type) {
  9921. case "TSAsExpression":
  9922. case "TSSatisfiesExpression":
  9923. case "TSNonNullExpression":
  9924. case "TSTypeAssertion":
  9925. case "ParenthesizedExpression":
  9926. this.toAssignable(node.expression, isLHS);
  9927. break;
  9928. default:
  9929. super.toAssignable(node, isLHS);
  9930. }
  9931. }
  9932. checkToRestConversion(node, allowPattern) {
  9933. switch (node.type) {
  9934. case "TSAsExpression":
  9935. case "TSSatisfiesExpression":
  9936. case "TSTypeAssertion":
  9937. case "TSNonNullExpression":
  9938. this.checkToRestConversion(node.expression, false);
  9939. break;
  9940. default:
  9941. super.checkToRestConversion(node, allowPattern);
  9942. }
  9943. }
  9944. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  9945. switch (type) {
  9946. case "TSTypeCastExpression":
  9947. return true;
  9948. case "TSParameterProperty":
  9949. return "parameter";
  9950. case "TSNonNullExpression":
  9951. return "expression";
  9952. case "TSAsExpression":
  9953. case "TSSatisfiesExpression":
  9954. case "TSTypeAssertion":
  9955. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  9956. default:
  9957. return super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  9958. }
  9959. }
  9960. parseBindingAtom() {
  9961. if (this.state.type === 78) {
  9962. return this.parseIdentifier(true);
  9963. }
  9964. return super.parseBindingAtom();
  9965. }
  9966. parseMaybeDecoratorArguments(expr, startLoc) {
  9967. if (this.match(47) || this.match(51)) {
  9968. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9969. if (this.match(10)) {
  9970. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  9971. call.typeParameters = typeArguments;
  9972. return call;
  9973. }
  9974. this.unexpected(null, 10);
  9975. }
  9976. return super.parseMaybeDecoratorArguments(expr, startLoc);
  9977. }
  9978. checkCommaAfterRest(close) {
  9979. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9980. this.next();
  9981. return false;
  9982. }
  9983. return super.checkCommaAfterRest(close);
  9984. }
  9985. isClassMethod() {
  9986. return this.match(47) || super.isClassMethod();
  9987. }
  9988. isClassProperty() {
  9989. return this.match(35) || this.match(14) || super.isClassProperty();
  9990. }
  9991. parseMaybeDefault(startLoc, left) {
  9992. const node = super.parseMaybeDefault(startLoc, left);
  9993. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9994. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  9995. }
  9996. return node;
  9997. }
  9998. getTokenFromCode(code) {
  9999. if (this.state.inType) {
  10000. if (code === 62) {
  10001. this.finishOp(48, 1);
  10002. return;
  10003. }
  10004. if (code === 60) {
  10005. this.finishOp(47, 1);
  10006. return;
  10007. }
  10008. }
  10009. super.getTokenFromCode(code);
  10010. }
  10011. reScan_lt_gt() {
  10012. const {
  10013. type
  10014. } = this.state;
  10015. if (type === 47) {
  10016. this.state.pos -= 1;
  10017. this.readToken_lt();
  10018. } else if (type === 48) {
  10019. this.state.pos -= 1;
  10020. this.readToken_gt();
  10021. }
  10022. }
  10023. reScan_lt() {
  10024. const {
  10025. type
  10026. } = this.state;
  10027. if (type === 51) {
  10028. this.state.pos -= 2;
  10029. this.finishOp(47, 1);
  10030. return 47;
  10031. }
  10032. return type;
  10033. }
  10034. toAssignableListItem(exprList, index, isLHS) {
  10035. const node = exprList[index];
  10036. if (node.type === "TSTypeCastExpression") {
  10037. exprList[index] = this.typeCastToParameter(node);
  10038. }
  10039. super.toAssignableListItem(exprList, index, isLHS);
  10040. }
  10041. typeCastToParameter(node) {
  10042. node.expression.typeAnnotation = node.typeAnnotation;
  10043. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  10044. return node.expression;
  10045. }
  10046. shouldParseArrow(params) {
  10047. if (this.match(14)) {
  10048. return params.every(expr => this.isAssignable(expr, true));
  10049. }
  10050. return super.shouldParseArrow(params);
  10051. }
  10052. shouldParseAsyncArrow() {
  10053. return this.match(14) || super.shouldParseAsyncArrow();
  10054. }
  10055. canHaveLeadingDecorator() {
  10056. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  10057. }
  10058. jsxParseOpeningElementAfterName(node) {
  10059. if (this.match(47) || this.match(51)) {
  10060. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  10061. if (typeArguments) {
  10062. node.typeParameters = typeArguments;
  10063. }
  10064. }
  10065. return super.jsxParseOpeningElementAfterName(node);
  10066. }
  10067. getGetterSetterExpectedParamCount(method) {
  10068. const baseCount = super.getGetterSetterExpectedParamCount(method);
  10069. const params = this.getObjectOrClassMethodParams(method);
  10070. const firstParam = params[0];
  10071. const hasContextParam = firstParam && this.isThisParam(firstParam);
  10072. return hasContextParam ? baseCount + 1 : baseCount;
  10073. }
  10074. parseCatchClauseParam() {
  10075. const param = super.parseCatchClauseParam();
  10076. const type = this.tsTryParseTypeAnnotation();
  10077. if (type) {
  10078. param.typeAnnotation = type;
  10079. this.resetEndLocation(param);
  10080. }
  10081. return param;
  10082. }
  10083. tsInAmbientContext(cb) {
  10084. const {
  10085. isAmbientContext: oldIsAmbientContext,
  10086. strict: oldStrict
  10087. } = this.state;
  10088. this.state.isAmbientContext = true;
  10089. this.state.strict = false;
  10090. try {
  10091. return cb();
  10092. } finally {
  10093. this.state.isAmbientContext = oldIsAmbientContext;
  10094. this.state.strict = oldStrict;
  10095. }
  10096. }
  10097. parseClass(node, isStatement, optionalId) {
  10098. const oldInAbstractClass = this.state.inAbstractClass;
  10099. this.state.inAbstractClass = !!node.abstract;
  10100. try {
  10101. return super.parseClass(node, isStatement, optionalId);
  10102. } finally {
  10103. this.state.inAbstractClass = oldInAbstractClass;
  10104. }
  10105. }
  10106. tsParseAbstractDeclaration(node, decorators) {
  10107. if (this.match(80)) {
  10108. node.abstract = true;
  10109. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  10110. } else if (this.isContextual(129)) {
  10111. if (!this.hasFollowingLineBreak()) {
  10112. node.abstract = true;
  10113. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
  10114. return this.tsParseInterfaceDeclaration(node);
  10115. } else {
  10116. return null;
  10117. }
  10118. }
  10119. throw this.unexpected(null, 80);
  10120. }
  10121. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  10122. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  10123. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  10124. const hasEstreePlugin = this.hasPlugin("estree");
  10125. const methodFn = hasEstreePlugin ? method.value : method;
  10126. if (methodFn.body) {
  10127. const {
  10128. key
  10129. } = method;
  10130. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  10131. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  10132. });
  10133. }
  10134. }
  10135. return method;
  10136. }
  10137. tsParseTypeParameterName() {
  10138. const typeName = this.parseIdentifier();
  10139. return typeName.name;
  10140. }
  10141. shouldParseAsAmbientContext() {
  10142. return !!this.getPluginOption("typescript", "dts");
  10143. }
  10144. parse() {
  10145. if (this.shouldParseAsAmbientContext()) {
  10146. this.state.isAmbientContext = true;
  10147. }
  10148. return super.parse();
  10149. }
  10150. getExpression() {
  10151. if (this.shouldParseAsAmbientContext()) {
  10152. this.state.isAmbientContext = true;
  10153. }
  10154. return super.getExpression();
  10155. }
  10156. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10157. if (!isString && isMaybeTypeOnly) {
  10158. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10159. return this.finishNode(node, "ExportSpecifier");
  10160. }
  10161. node.exportKind = "value";
  10162. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10163. }
  10164. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10165. if (!importedIsString && isMaybeTypeOnly) {
  10166. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10167. return this.finishNode(specifier, "ImportSpecifier");
  10168. }
  10169. specifier.importKind = "value";
  10170. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  10171. }
  10172. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10173. const leftOfAsKey = isImport ? "imported" : "local";
  10174. const rightOfAsKey = isImport ? "local" : "exported";
  10175. let leftOfAs = node[leftOfAsKey];
  10176. let rightOfAs;
  10177. let hasTypeSpecifier = false;
  10178. let canParseAsKeyword = true;
  10179. const loc = leftOfAs.loc.start;
  10180. if (this.isContextual(93)) {
  10181. const firstAs = this.parseIdentifier();
  10182. if (this.isContextual(93)) {
  10183. const secondAs = this.parseIdentifier();
  10184. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10185. hasTypeSpecifier = true;
  10186. leftOfAs = firstAs;
  10187. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10188. canParseAsKeyword = false;
  10189. } else {
  10190. rightOfAs = secondAs;
  10191. canParseAsKeyword = false;
  10192. }
  10193. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10194. canParseAsKeyword = false;
  10195. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10196. } else {
  10197. hasTypeSpecifier = true;
  10198. leftOfAs = firstAs;
  10199. }
  10200. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10201. hasTypeSpecifier = true;
  10202. if (isImport) {
  10203. leftOfAs = this.parseIdentifier(true);
  10204. if (!this.isContextual(93)) {
  10205. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10206. }
  10207. } else {
  10208. leftOfAs = this.parseModuleExportName();
  10209. }
  10210. }
  10211. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10212. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  10213. }
  10214. node[leftOfAsKey] = leftOfAs;
  10215. node[rightOfAsKey] = rightOfAs;
  10216. const kindKey = isImport ? "importKind" : "exportKind";
  10217. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10218. if (canParseAsKeyword && this.eatContextual(93)) {
  10219. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10220. }
  10221. if (!node[rightOfAsKey]) {
  10222. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  10223. }
  10224. if (isImport) {
  10225. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10226. }
  10227. }
  10228. fillOptionalPropertiesForTSESLint(node) {
  10229. var _node$phase, _node$directive, _node$decorators, _node$optional, _node$typeAnnotation, _node$accessibility, _node$decorators2, _node$override, _node$readonly, _node$static, _node$declare, _node$returnType, _node$typeParameters, _node$optional2, _node$optional3, _node$accessibility2, _node$readonly2, _node$static2, _node$declare2, _node$definite, _node$readonly3, _node$typeAnnotation2, _node$accessibility3, _node$decorators3, _node$override2, _node$optional4, _node$id, _node$abstract, _node$declare3, _node$decorators4, _node$implements, _node$superTypeArgume, _node$typeParameters2, _node$declare4, _node$definite2, _node$const, _node$declare5, _node$computed, _node$qualifier, _node$options, _node$declare6, _node$extends, _node$optional5, _node$readonly4, _node$declare7, _node$global, _node$const2, _node$in, _node$out;
  10230. switch (node.type) {
  10231. case "ImportDeclaration":
  10232. (_node$phase = node.phase) != null ? _node$phase : node.phase = null;
  10233. return;
  10234. case "ExpressionStatement":
  10235. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  10236. return;
  10237. case "RestElement":
  10238. node.value = undefined;
  10239. case "Identifier":
  10240. case "ArrayPattern":
  10241. case "AssignmentPattern":
  10242. case "ObjectPattern":
  10243. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  10244. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  10245. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  10246. return;
  10247. case "TSParameterProperty":
  10248. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  10249. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  10250. (_node$override = node.override) != null ? _node$override : node.override = false;
  10251. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  10252. (_node$static = node.static) != null ? _node$static : node.static = false;
  10253. return;
  10254. case "TSEmptyBodyFunctionExpression":
  10255. node.body = null;
  10256. case "TSDeclareFunction":
  10257. case "FunctionDeclaration":
  10258. case "FunctionExpression":
  10259. case "ClassMethod":
  10260. case "ClassPrivateMethod":
  10261. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  10262. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  10263. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  10264. return;
  10265. case "Property":
  10266. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  10267. return;
  10268. case "TSMethodSignature":
  10269. case "TSPropertySignature":
  10270. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  10271. case "TSIndexSignature":
  10272. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  10273. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  10274. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  10275. return;
  10276. case "TSAbstractPropertyDefinition":
  10277. case "PropertyDefinition":
  10278. case "TSAbstractAccessorProperty":
  10279. case "AccessorProperty":
  10280. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  10281. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  10282. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  10283. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  10284. case "TSAbstractMethodDefinition":
  10285. case "MethodDefinition":
  10286. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  10287. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  10288. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  10289. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  10290. return;
  10291. case "ClassExpression":
  10292. (_node$id = node.id) != null ? _node$id : node.id = null;
  10293. case "ClassDeclaration":
  10294. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  10295. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  10296. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  10297. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  10298. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  10299. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  10300. return;
  10301. case "TSTypeAliasDeclaration":
  10302. case "VariableDeclaration":
  10303. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  10304. return;
  10305. case "VariableDeclarator":
  10306. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  10307. return;
  10308. case "TSEnumDeclaration":
  10309. (_node$const = node.const) != null ? _node$const : node.const = false;
  10310. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  10311. return;
  10312. case "TSEnumMember":
  10313. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  10314. return;
  10315. case "TSImportType":
  10316. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  10317. (_node$options = node.options) != null ? _node$options : node.options = null;
  10318. return;
  10319. case "TSInterfaceDeclaration":
  10320. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  10321. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  10322. return;
  10323. case "TSMappedType":
  10324. (_node$optional5 = node.optional) != null ? _node$optional5 : node.optional = false;
  10325. (_node$readonly4 = node.readonly) != null ? _node$readonly4 : node.readonly = undefined;
  10326. return;
  10327. case "TSModuleDeclaration":
  10328. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  10329. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  10330. return;
  10331. case "TSTypeParameter":
  10332. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  10333. (_node$in = node.in) != null ? _node$in : node.in = false;
  10334. (_node$out = node.out) != null ? _node$out : node.out = false;
  10335. return;
  10336. }
  10337. }
  10338. chStartsBindingIdentifierAndNotRelationalOperator(ch, pos) {
  10339. if (isIdentifierStart(ch)) {
  10340. keywordAndTSRelationalOperator.lastIndex = pos;
  10341. if (keywordAndTSRelationalOperator.test(this.input)) {
  10342. const endCh = this.codePointAtPos(keywordAndTSRelationalOperator.lastIndex);
  10343. if (!isIdentifierChar(endCh) && endCh !== 92) {
  10344. return false;
  10345. }
  10346. }
  10347. return true;
  10348. } else if (ch === 92) {
  10349. return true;
  10350. } else {
  10351. return false;
  10352. }
  10353. }
  10354. nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine() {
  10355. const next = this.nextTokenInLineStart();
  10356. const nextCh = this.codePointAtPos(next);
  10357. return this.chStartsBindingIdentifierAndNotRelationalOperator(nextCh, next);
  10358. }
  10359. nextTokenIsIdentifierOrStringLiteralOnSameLine() {
  10360. const next = this.nextTokenInLineStart();
  10361. const nextCh = this.codePointAtPos(next);
  10362. return this.chStartsBindingIdentifier(nextCh, next) || nextCh === 34 || nextCh === 39;
  10363. }
  10364. };
  10365. function isPossiblyLiteralEnum(expression) {
  10366. if (expression.type !== "MemberExpression") return false;
  10367. const {
  10368. computed,
  10369. property
  10370. } = expression;
  10371. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10372. return false;
  10373. }
  10374. return isUncomputedMemberExpressionChain(expression.object);
  10375. }
  10376. function isValidAmbientConstInitializer(expression, estree) {
  10377. var _expression$extra;
  10378. const {
  10379. type
  10380. } = expression;
  10381. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10382. return false;
  10383. }
  10384. if (estree) {
  10385. if (type === "Literal") {
  10386. const {
  10387. value
  10388. } = expression;
  10389. if (typeof value === "string" || typeof value === "boolean") {
  10390. return true;
  10391. }
  10392. }
  10393. } else {
  10394. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10395. return true;
  10396. }
  10397. }
  10398. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10399. return true;
  10400. }
  10401. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10402. return true;
  10403. }
  10404. if (isPossiblyLiteralEnum(expression)) {
  10405. return true;
  10406. }
  10407. return false;
  10408. }
  10409. function isNumber(expression, estree) {
  10410. if (estree) {
  10411. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10412. }
  10413. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10414. }
  10415. function isNegativeNumber(expression, estree) {
  10416. if (expression.type === "UnaryExpression") {
  10417. const {
  10418. operator,
  10419. argument
  10420. } = expression;
  10421. if (operator === "-" && isNumber(argument, estree)) {
  10422. return true;
  10423. }
  10424. }
  10425. return false;
  10426. }
  10427. function isUncomputedMemberExpressionChain(expression) {
  10428. if (expression.type === "Identifier") return true;
  10429. if (expression.type !== "MemberExpression" || expression.computed) {
  10430. return false;
  10431. }
  10432. return isUncomputedMemberExpressionChain(expression.object);
  10433. }
  10434. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10435. ClassNameIsRequired: "A class name is required.",
  10436. UnexpectedSpace: "Unexpected space in placeholder."
  10437. });
  10438. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10439. parsePlaceholder(expectedNode) {
  10440. if (this.match(133)) {
  10441. const node = this.startNode();
  10442. this.next();
  10443. this.assertNoSpace();
  10444. node.name = super.parseIdentifier(true);
  10445. this.assertNoSpace();
  10446. this.expect(133);
  10447. return this.finishPlaceholder(node, expectedNode);
  10448. }
  10449. }
  10450. finishPlaceholder(node, expectedNode) {
  10451. let placeholder = node;
  10452. if (!placeholder.expectedNode || !placeholder.type) {
  10453. placeholder = this.finishNode(placeholder, "Placeholder");
  10454. }
  10455. placeholder.expectedNode = expectedNode;
  10456. return placeholder;
  10457. }
  10458. getTokenFromCode(code) {
  10459. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10460. this.finishOp(133, 2);
  10461. } else {
  10462. super.getTokenFromCode(code);
  10463. }
  10464. }
  10465. parseExprAtom(refExpressionErrors) {
  10466. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10467. }
  10468. parseIdentifier(liberal) {
  10469. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10470. }
  10471. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10472. if (word !== undefined) {
  10473. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10474. }
  10475. }
  10476. cloneIdentifier(node) {
  10477. const cloned = super.cloneIdentifier(node);
  10478. if (cloned.type === "Placeholder") {
  10479. cloned.expectedNode = node.expectedNode;
  10480. }
  10481. return cloned;
  10482. }
  10483. cloneStringLiteral(node) {
  10484. if (node.type === "Placeholder") {
  10485. return this.cloneIdentifier(node);
  10486. }
  10487. return super.cloneStringLiteral(node);
  10488. }
  10489. parseBindingAtom() {
  10490. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10491. }
  10492. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  10493. return type === "Placeholder" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  10494. }
  10495. toAssignable(node, isLHS) {
  10496. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10497. node.expectedNode = "Pattern";
  10498. } else {
  10499. super.toAssignable(node, isLHS);
  10500. }
  10501. }
  10502. chStartsBindingIdentifier(ch, pos) {
  10503. if (super.chStartsBindingIdentifier(ch, pos)) {
  10504. return true;
  10505. }
  10506. const next = this.nextTokenStart();
  10507. if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
  10508. return true;
  10509. }
  10510. return false;
  10511. }
  10512. verifyBreakContinue(node, isBreak) {
  10513. var _node$label;
  10514. if (((_node$label = node.label) == null ? void 0 : _node$label.type) === "Placeholder") return;
  10515. super.verifyBreakContinue(node, isBreak);
  10516. }
  10517. parseExpressionStatement(node, expr) {
  10518. var _expr$extra;
  10519. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10520. return super.parseExpressionStatement(node, expr);
  10521. }
  10522. if (this.match(14)) {
  10523. const stmt = node;
  10524. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10525. this.next();
  10526. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10527. return this.finishNode(stmt, "LabeledStatement");
  10528. }
  10529. this.semicolon();
  10530. const stmtPlaceholder = node;
  10531. stmtPlaceholder.name = expr.name;
  10532. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  10533. }
  10534. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10535. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10536. }
  10537. parseFunctionId(requireId) {
  10538. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10539. }
  10540. parseClass(node, isStatement, optionalId) {
  10541. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10542. this.next();
  10543. const oldStrict = this.state.strict;
  10544. const placeholder = this.parsePlaceholder("Identifier");
  10545. if (placeholder) {
  10546. if (this.match(81) || this.match(133) || this.match(5)) {
  10547. node.id = placeholder;
  10548. } else if (optionalId || !isStatement) {
  10549. node.id = null;
  10550. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10551. return this.finishNode(node, type);
  10552. } else {
  10553. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10554. }
  10555. } else {
  10556. this.parseClassId(node, isStatement, optionalId);
  10557. }
  10558. super.parseClassSuper(node);
  10559. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10560. return this.finishNode(node, type);
  10561. }
  10562. parseExport(node, decorators) {
  10563. const placeholder = this.parsePlaceholder("Identifier");
  10564. if (!placeholder) return super.parseExport(node, decorators);
  10565. const node2 = node;
  10566. if (!this.isContextual(98) && !this.match(12)) {
  10567. node2.specifiers = [];
  10568. node2.source = null;
  10569. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10570. return this.finishNode(node2, "ExportNamedDeclaration");
  10571. }
  10572. this.expectPlugin("exportDefaultFrom");
  10573. const specifier = this.startNode();
  10574. specifier.exported = placeholder;
  10575. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10576. return super.parseExport(node2, decorators);
  10577. }
  10578. isExportDefaultSpecifier() {
  10579. if (this.match(65)) {
  10580. const next = this.nextTokenStart();
  10581. if (this.isUnparsedContextual(next, "from")) {
  10582. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  10583. return true;
  10584. }
  10585. }
  10586. }
  10587. return super.isExportDefaultSpecifier();
  10588. }
  10589. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10590. var _specifiers;
  10591. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10592. return true;
  10593. }
  10594. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10595. }
  10596. checkExport(node) {
  10597. const {
  10598. specifiers
  10599. } = node;
  10600. if (specifiers != null && specifiers.length) {
  10601. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10602. }
  10603. super.checkExport(node);
  10604. node.specifiers = specifiers;
  10605. }
  10606. parseImport(node) {
  10607. const placeholder = this.parsePlaceholder("Identifier");
  10608. if (!placeholder) return super.parseImport(node);
  10609. node.specifiers = [];
  10610. if (!this.isContextual(98) && !this.match(12)) {
  10611. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10612. this.semicolon();
  10613. return this.finishNode(node, "ImportDeclaration");
  10614. }
  10615. const specifier = this.startNodeAtNode(placeholder);
  10616. specifier.local = placeholder;
  10617. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10618. if (this.eat(12)) {
  10619. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10620. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10621. }
  10622. this.expectContextual(98);
  10623. node.source = this.parseImportSource();
  10624. this.semicolon();
  10625. return this.finishNode(node, "ImportDeclaration");
  10626. }
  10627. parseImportSource() {
  10628. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10629. }
  10630. assertNoSpace() {
  10631. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  10632. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10633. }
  10634. }
  10635. };
  10636. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10637. parseV8Intrinsic() {
  10638. if (this.match(54)) {
  10639. const v8IntrinsicStartLoc = this.state.startLoc;
  10640. const node = this.startNode();
  10641. this.next();
  10642. if (tokenIsIdentifier(this.state.type)) {
  10643. const name = this.parseIdentifierName();
  10644. const identifier = this.createIdentifier(node, name);
  10645. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  10646. if (this.match(10)) {
  10647. return identifier;
  10648. }
  10649. }
  10650. this.unexpected(v8IntrinsicStartLoc);
  10651. }
  10652. }
  10653. parseExprAtom(refExpressionErrors) {
  10654. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10655. }
  10656. };
  10657. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10658. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10659. function validatePlugins(pluginsMap) {
  10660. if (pluginsMap.has("decorators")) {
  10661. if (pluginsMap.has("decorators-legacy")) {
  10662. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10663. }
  10664. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  10665. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10666. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10667. }
  10668. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  10669. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10670. throw new Error("'allowCallParenthesized' must be a boolean.");
  10671. }
  10672. }
  10673. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  10674. throw new Error("Cannot combine flow and typescript plugins.");
  10675. }
  10676. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  10677. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10678. }
  10679. if (pluginsMap.has("pipelineOperator")) {
  10680. var _pluginsMap$get2;
  10681. const proposal = pluginsMap.get("pipelineOperator").proposal;
  10682. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10683. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10684. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10685. }
  10686. if (proposal === "hack") {
  10687. var _pluginsMap$get;
  10688. if (pluginsMap.has("placeholders")) {
  10689. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10690. }
  10691. if (pluginsMap.has("v8intrinsic")) {
  10692. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10693. }
  10694. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  10695. if (!TOPIC_TOKENS.includes(topicToken)) {
  10696. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10697. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10698. }
  10699. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  10700. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10701. }
  10702. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  10703. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10704. }
  10705. }
  10706. if (pluginsMap.has("moduleAttributes")) {
  10707. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  10708. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  10709. }
  10710. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  10711. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10712. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10713. }
  10714. }
  10715. if (pluginsMap.has("importAssertions")) {
  10716. if (pluginsMap.has("deprecatedImportAssert")) {
  10717. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  10718. }
  10719. }
  10720. if (pluginsMap.has("deprecatedImportAssert")) ;else if (pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  10721. pluginsMap.set("deprecatedImportAssert", {});
  10722. }
  10723. if (pluginsMap.has("recordAndTuple")) {
  10724. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  10725. if (syntaxType != null) {
  10726. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10727. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  10728. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10729. }
  10730. }
  10731. }
  10732. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  10733. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10734. error.missingPlugins = "doExpressions";
  10735. throw error;
  10736. }
  10737. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  10738. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10739. }
  10740. if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
  10741. throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
  10742. }
  10743. }
  10744. const mixinPlugins = {
  10745. estree,
  10746. jsx,
  10747. flow,
  10748. typescript,
  10749. v8intrinsic,
  10750. placeholders
  10751. };
  10752. const mixinPluginNames = Object.keys(mixinPlugins);
  10753. class ExpressionParser extends LValParser {
  10754. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  10755. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10756. return sawProto;
  10757. }
  10758. const key = prop.key;
  10759. const name = key.type === "Identifier" ? key.name : key.value;
  10760. if (name === "__proto__") {
  10761. if (isRecord) {
  10762. this.raise(Errors.RecordNoProto, key);
  10763. return true;
  10764. }
  10765. if (sawProto) {
  10766. if (refExpressionErrors) {
  10767. if (refExpressionErrors.doubleProtoLoc === null) {
  10768. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10769. }
  10770. } else {
  10771. this.raise(Errors.DuplicateProto, key);
  10772. }
  10773. }
  10774. return true;
  10775. }
  10776. return sawProto;
  10777. }
  10778. shouldExitDescending(expr, potentialArrowAt) {
  10779. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  10780. }
  10781. getExpression() {
  10782. this.enterInitialScopes();
  10783. this.nextToken();
  10784. if (this.match(140)) {
  10785. throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
  10786. }
  10787. const expr = this.parseExpression();
  10788. if (!this.match(140)) {
  10789. throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
  10790. unexpected: this.input.codePointAt(this.state.start)
  10791. });
  10792. }
  10793. this.finalizeRemainingComments();
  10794. expr.comments = this.comments;
  10795. expr.errors = this.state.errors;
  10796. if (this.optionFlags & 256) {
  10797. expr.tokens = this.tokens;
  10798. }
  10799. return expr;
  10800. }
  10801. parseExpression(disallowIn, refExpressionErrors) {
  10802. if (disallowIn) {
  10803. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10804. }
  10805. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10806. }
  10807. parseExpressionBase(refExpressionErrors) {
  10808. const startLoc = this.state.startLoc;
  10809. const expr = this.parseMaybeAssign(refExpressionErrors);
  10810. if (this.match(12)) {
  10811. const node = this.startNodeAt(startLoc);
  10812. node.expressions = [expr];
  10813. while (this.eat(12)) {
  10814. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10815. }
  10816. this.toReferencedList(node.expressions);
  10817. return this.finishNode(node, "SequenceExpression");
  10818. }
  10819. return expr;
  10820. }
  10821. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10822. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10823. }
  10824. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10825. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10826. }
  10827. setOptionalParametersError(refExpressionErrors) {
  10828. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  10829. }
  10830. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10831. const startLoc = this.state.startLoc;
  10832. const isYield = this.isContextual(108);
  10833. if (isYield) {
  10834. if (this.prodParam.hasYield) {
  10835. this.next();
  10836. let left = this.parseYield(startLoc);
  10837. if (afterLeftParse) {
  10838. left = afterLeftParse.call(this, left, startLoc);
  10839. }
  10840. return left;
  10841. }
  10842. }
  10843. let ownExpressionErrors;
  10844. if (refExpressionErrors) {
  10845. ownExpressionErrors = false;
  10846. } else {
  10847. refExpressionErrors = new ExpressionErrors();
  10848. ownExpressionErrors = true;
  10849. }
  10850. const {
  10851. type
  10852. } = this.state;
  10853. if (type === 10 || tokenIsIdentifier(type)) {
  10854. this.state.potentialArrowAt = this.state.start;
  10855. }
  10856. let left = this.parseMaybeConditional(refExpressionErrors);
  10857. if (afterLeftParse) {
  10858. left = afterLeftParse.call(this, left, startLoc);
  10859. }
  10860. if (tokenIsAssignment(this.state.type)) {
  10861. const node = this.startNodeAt(startLoc);
  10862. const operator = this.state.value;
  10863. node.operator = operator;
  10864. if (this.match(29)) {
  10865. this.toAssignable(left, true);
  10866. node.left = left;
  10867. const startIndex = startLoc.index;
  10868. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10869. refExpressionErrors.doubleProtoLoc = null;
  10870. }
  10871. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10872. refExpressionErrors.shorthandAssignLoc = null;
  10873. }
  10874. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10875. this.checkDestructuringPrivate(refExpressionErrors);
  10876. refExpressionErrors.privateKeyLoc = null;
  10877. }
  10878. if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
  10879. refExpressionErrors.voidPatternLoc = null;
  10880. }
  10881. } else {
  10882. node.left = left;
  10883. }
  10884. this.next();
  10885. node.right = this.parseMaybeAssign();
  10886. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"), undefined, undefined, undefined, undefined, operator === "||=" || operator === "&&=" || operator === "??=");
  10887. return node;
  10888. } else if (ownExpressionErrors) {
  10889. this.checkExpressionErrors(refExpressionErrors, true);
  10890. }
  10891. if (isYield) {
  10892. const {
  10893. type
  10894. } = this.state;
  10895. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10896. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  10897. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  10898. return this.parseYield(startLoc);
  10899. }
  10900. }
  10901. return left;
  10902. }
  10903. parseMaybeConditional(refExpressionErrors) {
  10904. const startLoc = this.state.startLoc;
  10905. const potentialArrowAt = this.state.potentialArrowAt;
  10906. const expr = this.parseExprOps(refExpressionErrors);
  10907. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10908. return expr;
  10909. }
  10910. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10911. }
  10912. parseConditional(expr, startLoc, refExpressionErrors) {
  10913. if (this.eat(17)) {
  10914. const node = this.startNodeAt(startLoc);
  10915. node.test = expr;
  10916. node.consequent = this.parseMaybeAssignAllowIn();
  10917. this.expect(14);
  10918. node.alternate = this.parseMaybeAssign();
  10919. return this.finishNode(node, "ConditionalExpression");
  10920. }
  10921. return expr;
  10922. }
  10923. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10924. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10925. }
  10926. parseExprOps(refExpressionErrors) {
  10927. const startLoc = this.state.startLoc;
  10928. const potentialArrowAt = this.state.potentialArrowAt;
  10929. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10930. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10931. return expr;
  10932. }
  10933. return this.parseExprOp(expr, startLoc, -1);
  10934. }
  10935. parseExprOp(left, leftStartLoc, minPrec) {
  10936. if (this.isPrivateName(left)) {
  10937. const value = this.getPrivateNameSV(left);
  10938. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10939. this.raise(Errors.PrivateInExpectedIn, left, {
  10940. identifierName: value
  10941. });
  10942. }
  10943. this.classScope.usePrivateName(value, left.loc.start);
  10944. }
  10945. const op = this.state.type;
  10946. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10947. let prec = tokenOperatorPrecedence(op);
  10948. if (prec > minPrec) {
  10949. if (op === 39) {
  10950. this.expectPlugin("pipelineOperator");
  10951. if (this.state.inFSharpPipelineDirectBody) {
  10952. return left;
  10953. }
  10954. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10955. }
  10956. const node = this.startNodeAt(leftStartLoc);
  10957. node.left = left;
  10958. node.operator = this.state.value;
  10959. const logical = op === 41 || op === 42;
  10960. const coalesce = op === 40;
  10961. if (coalesce) {
  10962. prec = tokenOperatorPrecedence(42);
  10963. }
  10964. this.next();
  10965. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10966. proposal: "minimal"
  10967. }])) {
  10968. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10969. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  10970. }
  10971. }
  10972. node.right = this.parseExprOpRightExpr(op, prec);
  10973. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10974. const nextOp = this.state.type;
  10975. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10976. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  10977. }
  10978. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10979. }
  10980. }
  10981. return left;
  10982. }
  10983. parseExprOpRightExpr(op, prec) {
  10984. const startLoc = this.state.startLoc;
  10985. switch (op) {
  10986. case 39:
  10987. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10988. case "hack":
  10989. return this.withTopicBindingContext(() => {
  10990. return this.parseHackPipeBody();
  10991. });
  10992. case "fsharp":
  10993. return this.withSoloAwaitPermittingContext(() => {
  10994. return this.parseFSharpPipelineBody(prec);
  10995. });
  10996. }
  10997. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  10998. return this.withTopicBindingContext(() => {
  10999. if (this.prodParam.hasYield && this.isContextual(108)) {
  11000. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  11001. }
  11002. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  11003. });
  11004. }
  11005. default:
  11006. return this.parseExprOpBaseRightExpr(op, prec);
  11007. }
  11008. }
  11009. parseExprOpBaseRightExpr(op, prec) {
  11010. const startLoc = this.state.startLoc;
  11011. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  11012. }
  11013. parseHackPipeBody() {
  11014. var _body$extra;
  11015. const {
  11016. startLoc
  11017. } = this.state;
  11018. const body = this.parseMaybeAssign();
  11019. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  11020. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  11021. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  11022. type: body.type
  11023. });
  11024. }
  11025. if (!this.topicReferenceWasUsedInCurrentContext()) {
  11026. this.raise(Errors.PipeTopicUnused, startLoc);
  11027. }
  11028. return body;
  11029. }
  11030. checkExponentialAfterUnary(node) {
  11031. if (this.match(57)) {
  11032. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  11033. }
  11034. }
  11035. parseMaybeUnary(refExpressionErrors, sawUnary) {
  11036. const startLoc = this.state.startLoc;
  11037. const isAwait = this.isContextual(96);
  11038. if (isAwait && this.recordAwaitIfAllowed()) {
  11039. this.next();
  11040. const expr = this.parseAwait(startLoc);
  11041. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  11042. return expr;
  11043. }
  11044. const update = this.match(34);
  11045. const node = this.startNode();
  11046. if (tokenIsPrefix(this.state.type)) {
  11047. node.operator = this.state.value;
  11048. node.prefix = true;
  11049. if (this.match(72)) {
  11050. this.expectPlugin("throwExpressions");
  11051. }
  11052. const isDelete = this.match(89);
  11053. this.next();
  11054. node.argument = this.parseMaybeUnary(null, true);
  11055. this.checkExpressionErrors(refExpressionErrors, true);
  11056. if (this.state.strict && isDelete) {
  11057. const arg = node.argument;
  11058. if (arg.type === "Identifier") {
  11059. this.raise(Errors.StrictDelete, node);
  11060. } else if (this.hasPropertyAsPrivateName(arg)) {
  11061. this.raise(Errors.DeletePrivateField, node);
  11062. }
  11063. }
  11064. if (!update) {
  11065. if (!sawUnary) {
  11066. this.checkExponentialAfterUnary(node);
  11067. }
  11068. return this.finishNode(node, "UnaryExpression");
  11069. }
  11070. }
  11071. const expr = this.parseUpdate(node, update, refExpressionErrors);
  11072. if (isAwait) {
  11073. const {
  11074. type
  11075. } = this.state;
  11076. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  11077. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  11078. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  11079. return this.parseAwait(startLoc);
  11080. }
  11081. }
  11082. return expr;
  11083. }
  11084. parseUpdate(node, update, refExpressionErrors) {
  11085. if (update) {
  11086. const updateExpressionNode = node;
  11087. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  11088. return node;
  11089. }
  11090. const startLoc = this.state.startLoc;
  11091. let expr = this.parseExprSubscripts(refExpressionErrors);
  11092. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  11093. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  11094. const node = this.startNodeAt(startLoc);
  11095. node.operator = this.state.value;
  11096. node.prefix = false;
  11097. node.argument = expr;
  11098. this.next();
  11099. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  11100. }
  11101. return expr;
  11102. }
  11103. parseExprSubscripts(refExpressionErrors) {
  11104. const startLoc = this.state.startLoc;
  11105. const potentialArrowAt = this.state.potentialArrowAt;
  11106. const expr = this.parseExprAtom(refExpressionErrors);
  11107. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11108. return expr;
  11109. }
  11110. return this.parseSubscripts(expr, startLoc);
  11111. }
  11112. parseSubscripts(base, startLoc, noCalls) {
  11113. const state = {
  11114. optionalChainMember: false,
  11115. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  11116. stop: false
  11117. };
  11118. do {
  11119. base = this.parseSubscript(base, startLoc, noCalls, state);
  11120. state.maybeAsyncArrow = false;
  11121. } while (!state.stop);
  11122. return base;
  11123. }
  11124. parseSubscript(base, startLoc, noCalls, state) {
  11125. const {
  11126. type
  11127. } = this.state;
  11128. if (!noCalls && type === 15) {
  11129. return this.parseBind(base, startLoc, state);
  11130. } else if (tokenIsTemplate(type)) {
  11131. return this.parseTaggedTemplateExpression(base, startLoc, state);
  11132. }
  11133. let optional = false;
  11134. if (type === 18) {
  11135. if (noCalls) {
  11136. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  11137. if (this.lookaheadCharCode() === 40) {
  11138. return this.stopParseSubscript(base, state);
  11139. }
  11140. }
  11141. state.optionalChainMember = optional = true;
  11142. this.next();
  11143. }
  11144. if (!noCalls && this.match(10)) {
  11145. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  11146. } else {
  11147. const computed = this.eat(0);
  11148. if (computed || optional || this.eat(16)) {
  11149. return this.parseMember(base, startLoc, state, computed, optional);
  11150. } else {
  11151. return this.stopParseSubscript(base, state);
  11152. }
  11153. }
  11154. }
  11155. stopParseSubscript(base, state) {
  11156. state.stop = true;
  11157. return base;
  11158. }
  11159. parseMember(base, startLoc, state, computed, optional) {
  11160. const node = this.startNodeAt(startLoc);
  11161. node.object = base;
  11162. node.computed = computed;
  11163. if (computed) {
  11164. node.property = this.parseExpression();
  11165. this.expect(3);
  11166. } else if (this.match(139)) {
  11167. if (base.type === "Super") {
  11168. this.raise(Errors.SuperPrivateField, startLoc);
  11169. }
  11170. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  11171. node.property = this.parsePrivateName();
  11172. } else {
  11173. node.property = this.parseIdentifier(true);
  11174. }
  11175. if (state.optionalChainMember) {
  11176. node.optional = optional;
  11177. return this.finishNode(node, "OptionalMemberExpression");
  11178. } else {
  11179. return this.finishNode(node, "MemberExpression");
  11180. }
  11181. }
  11182. parseBind(base, startLoc, state) {
  11183. const node = this.startNodeAt(startLoc);
  11184. node.object = base;
  11185. this.next();
  11186. const isImport = this.match(83);
  11187. const callee = this.parseNoCallExpr();
  11188. if (callee.type === "Super" || isImport && callee.type === "ImportExpression" || callee.type === "Import") {
  11189. throw this.raise(Errors.UnsupportedBindRHS, callee);
  11190. }
  11191. node.callee = callee;
  11192. state.stop = true;
  11193. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, false);
  11194. }
  11195. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  11196. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11197. let refExpressionErrors = null;
  11198. this.state.maybeInArrowParameters = true;
  11199. this.next();
  11200. const node = this.startNodeAt(startLoc);
  11201. node.callee = base;
  11202. const {
  11203. maybeAsyncArrow,
  11204. optionalChainMember
  11205. } = state;
  11206. if (maybeAsyncArrow) {
  11207. this.expressionScope.enter(newAsyncArrowScope());
  11208. refExpressionErrors = new ExpressionErrors();
  11209. }
  11210. if (optionalChainMember) {
  11211. node.optional = optional;
  11212. }
  11213. if (optional) {
  11214. node.arguments = this.parseCallExpressionArguments();
  11215. } else {
  11216. node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
  11217. }
  11218. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  11219. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  11220. state.stop = true;
  11221. this.checkDestructuringPrivate(refExpressionErrors);
  11222. this.expressionScope.validateAsPattern();
  11223. this.expressionScope.exit();
  11224. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  11225. } else {
  11226. if (maybeAsyncArrow) {
  11227. this.checkExpressionErrors(refExpressionErrors, true);
  11228. this.expressionScope.exit();
  11229. }
  11230. this.toReferencedArguments(finishedNode);
  11231. }
  11232. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11233. return finishedNode;
  11234. }
  11235. toReferencedArguments(node, isParenthesizedExpr) {
  11236. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11237. }
  11238. parseTaggedTemplateExpression(base, startLoc, state) {
  11239. const node = this.startNodeAt(startLoc);
  11240. node.tag = base;
  11241. node.quasi = this.parseTemplate(true);
  11242. if (state.optionalChainMember) {
  11243. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  11244. }
  11245. return this.finishNode(node, "TaggedTemplateExpression");
  11246. }
  11247. atPossibleAsyncArrow(base) {
  11248. 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;
  11249. }
  11250. finishCallExpression(node, optional) {
  11251. if (node.callee.type === "Import") {
  11252. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11253. this.raise(Errors.ImportCallArity, node);
  11254. } else {
  11255. for (const arg of node.arguments) {
  11256. if (arg.type === "SpreadElement") {
  11257. this.raise(Errors.ImportCallSpreadArgument, arg);
  11258. }
  11259. }
  11260. }
  11261. }
  11262. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11263. }
  11264. parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11265. const elts = [];
  11266. let first = true;
  11267. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11268. this.state.inFSharpPipelineDirectBody = false;
  11269. while (!this.eat(11)) {
  11270. if (first) {
  11271. first = false;
  11272. } else {
  11273. this.expect(12);
  11274. if (this.match(11)) {
  11275. if (nodeForExtra) {
  11276. this.addTrailingCommaExtraToNode(nodeForExtra);
  11277. }
  11278. this.next();
  11279. break;
  11280. }
  11281. }
  11282. elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
  11283. }
  11284. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11285. return elts;
  11286. }
  11287. shouldParseAsyncArrow() {
  11288. return this.match(19) && !this.canInsertSemicolon();
  11289. }
  11290. parseAsyncArrowFromCallExpression(node, call) {
  11291. var _call$extra;
  11292. this.resetPreviousNodeTrailingComments(call);
  11293. this.expect(19);
  11294. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11295. if (call.innerComments) {
  11296. setInnerComments(node, call.innerComments);
  11297. }
  11298. if (call.callee.trailingComments) {
  11299. setInnerComments(node, call.callee.trailingComments);
  11300. }
  11301. return node;
  11302. }
  11303. parseNoCallExpr() {
  11304. const startLoc = this.state.startLoc;
  11305. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11306. }
  11307. parseExprAtom(refExpressionErrors) {
  11308. let node;
  11309. let decorators = null;
  11310. const {
  11311. type
  11312. } = this.state;
  11313. switch (type) {
  11314. case 79:
  11315. return this.parseSuper();
  11316. case 83:
  11317. node = this.startNode();
  11318. this.next();
  11319. if (this.match(16)) {
  11320. return this.parseImportMetaPropertyOrPhaseCall(node);
  11321. }
  11322. if (this.match(10)) {
  11323. if (this.optionFlags & 512) {
  11324. return this.parseImportCall(node);
  11325. } else {
  11326. return this.finishNode(node, "Import");
  11327. }
  11328. } else {
  11329. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  11330. return this.finishNode(node, "Import");
  11331. }
  11332. case 78:
  11333. node = this.startNode();
  11334. this.next();
  11335. return this.finishNode(node, "ThisExpression");
  11336. case 90:
  11337. {
  11338. return this.parseDo(this.startNode(), false);
  11339. }
  11340. case 56:
  11341. case 31:
  11342. {
  11343. this.readRegexp();
  11344. return this.parseRegExpLiteral(this.state.value);
  11345. }
  11346. case 135:
  11347. return this.parseNumericLiteral(this.state.value);
  11348. case 136:
  11349. return this.parseBigIntLiteral(this.state.value);
  11350. case 134:
  11351. return this.parseStringLiteral(this.state.value);
  11352. case 84:
  11353. return this.parseNullLiteral();
  11354. case 85:
  11355. return this.parseBooleanLiteral(true);
  11356. case 86:
  11357. return this.parseBooleanLiteral(false);
  11358. case 10:
  11359. {
  11360. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11361. return this.parseParenAndDistinguishExpression(canBeArrow);
  11362. }
  11363. case 0:
  11364. {
  11365. return this.parseArrayLike(3, false, refExpressionErrors);
  11366. }
  11367. case 5:
  11368. {
  11369. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11370. }
  11371. case 68:
  11372. return this.parseFunctionOrFunctionSent();
  11373. case 26:
  11374. decorators = this.parseDecorators();
  11375. case 80:
  11376. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11377. case 77:
  11378. return this.parseNewOrNewTarget();
  11379. case 25:
  11380. case 24:
  11381. return this.parseTemplate(false);
  11382. case 15:
  11383. {
  11384. node = this.startNode();
  11385. this.next();
  11386. node.object = null;
  11387. const callee = node.callee = this.parseNoCallExpr();
  11388. if (callee.type === "MemberExpression") {
  11389. return this.finishNode(node, "BindExpression");
  11390. } else {
  11391. throw this.raise(Errors.UnsupportedBind, callee);
  11392. }
  11393. }
  11394. case 139:
  11395. {
  11396. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  11397. identifierName: this.state.value
  11398. });
  11399. return this.parsePrivateName();
  11400. }
  11401. case 33:
  11402. {
  11403. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11404. }
  11405. case 32:
  11406. {
  11407. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11408. }
  11409. case 37:
  11410. case 38:
  11411. {
  11412. return this.parseTopicReference("hack");
  11413. }
  11414. case 44:
  11415. case 54:
  11416. case 27:
  11417. {
  11418. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11419. if (pipeProposal) {
  11420. return this.parseTopicReference(pipeProposal);
  11421. }
  11422. throw this.unexpected();
  11423. }
  11424. case 47:
  11425. {
  11426. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11427. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11428. throw this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11429. }
  11430. throw this.unexpected();
  11431. }
  11432. default:
  11433. if (type === 137) {
  11434. return this.parseDecimalLiteral(this.state.value);
  11435. } else if (type === 2 || type === 1) {
  11436. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, true);
  11437. } else if (type === 6 || type === 7) {
  11438. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11439. }
  11440. if (tokenIsIdentifier(type)) {
  11441. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11442. return this.parseModuleExpression();
  11443. }
  11444. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11445. const containsEsc = this.state.containsEsc;
  11446. const id = this.parseIdentifier();
  11447. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11448. const {
  11449. type
  11450. } = this.state;
  11451. if (type === 68) {
  11452. this.resetPreviousNodeTrailingComments(id);
  11453. this.next();
  11454. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11455. } else if (tokenIsIdentifier(type)) {
  11456. if (canBeArrow && this.lookaheadCharCode() === 61) {
  11457. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11458. } else {
  11459. return id;
  11460. }
  11461. } else if (type === 90) {
  11462. this.resetPreviousNodeTrailingComments(id);
  11463. return this.parseDo(this.startNodeAtNode(id), true);
  11464. }
  11465. }
  11466. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11467. this.next();
  11468. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11469. }
  11470. return id;
  11471. } else {
  11472. throw this.unexpected();
  11473. }
  11474. }
  11475. }
  11476. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11477. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11478. if (pipeProposal) {
  11479. this.state.type = topicTokenType;
  11480. this.state.value = topicTokenValue;
  11481. this.state.pos--;
  11482. this.state.end--;
  11483. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11484. return this.parseTopicReference(pipeProposal);
  11485. }
  11486. throw this.unexpected();
  11487. }
  11488. parseTopicReference(pipeProposal) {
  11489. const node = this.startNode();
  11490. const startLoc = this.state.startLoc;
  11491. const tokenType = this.state.type;
  11492. this.next();
  11493. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11494. }
  11495. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11496. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11497. if (pipeProposal === "hack") {
  11498. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11499. this.raise(Errors.PipeTopicUnbound, startLoc);
  11500. }
  11501. this.registerTopicReference();
  11502. return this.finishNode(node, "TopicReference");
  11503. } else {
  11504. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11505. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  11506. }
  11507. this.registerTopicReference();
  11508. return this.finishNode(node, "PipelinePrimaryTopicReference");
  11509. }
  11510. } else {
  11511. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11512. token: tokenLabelName(tokenType)
  11513. });
  11514. }
  11515. }
  11516. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11517. switch (pipeProposal) {
  11518. case "hack":
  11519. {
  11520. return this.hasPlugin(["pipelineOperator", {
  11521. topicToken: tokenLabelName(tokenType)
  11522. }]);
  11523. }
  11524. case "smart":
  11525. return tokenType === 27;
  11526. default:
  11527. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11528. }
  11529. }
  11530. parseAsyncArrowUnaryFunction(node) {
  11531. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11532. const params = [this.parseIdentifier()];
  11533. this.prodParam.exit();
  11534. if (this.hasPrecedingLineBreak()) {
  11535. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11536. }
  11537. this.expect(19);
  11538. return this.parseArrowExpression(node, params, true);
  11539. }
  11540. parseDo(node, isAsync) {
  11541. this.expectPlugin("doExpressions");
  11542. if (isAsync) {
  11543. this.expectPlugin("asyncDoExpressions");
  11544. }
  11545. node.async = isAsync;
  11546. this.next();
  11547. const oldLabels = this.state.labels;
  11548. this.state.labels = [];
  11549. if (isAsync) {
  11550. this.prodParam.enter(2);
  11551. node.body = this.parseBlock();
  11552. this.prodParam.exit();
  11553. } else {
  11554. node.body = this.parseBlock();
  11555. }
  11556. this.state.labels = oldLabels;
  11557. return this.finishNode(node, "DoExpression");
  11558. }
  11559. parseSuper() {
  11560. const node = this.startNode();
  11561. this.next();
  11562. if (this.match(10) && !this.scope.allowDirectSuper) {
  11563. if (!(this.optionFlags & 16)) {
  11564. this.raise(Errors.SuperNotAllowed, node);
  11565. }
  11566. } else if (!this.scope.allowSuper) {
  11567. if (!(this.optionFlags & 16)) {
  11568. this.raise(Errors.UnexpectedSuper, node);
  11569. }
  11570. }
  11571. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11572. this.raise(Errors.UnsupportedSuper, node);
  11573. }
  11574. return this.finishNode(node, "Super");
  11575. }
  11576. parsePrivateName() {
  11577. const node = this.startNode();
  11578. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11579. const name = this.state.value;
  11580. this.next();
  11581. node.id = this.createIdentifier(id, name);
  11582. return this.finishNode(node, "PrivateName");
  11583. }
  11584. parseFunctionOrFunctionSent() {
  11585. const node = this.startNode();
  11586. this.next();
  11587. if (this.prodParam.hasYield && this.match(16)) {
  11588. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11589. this.next();
  11590. if (this.match(103)) {
  11591. this.expectPlugin("functionSent");
  11592. } else if (!this.hasPlugin("functionSent")) {
  11593. this.unexpected();
  11594. }
  11595. return this.parseMetaProperty(node, meta, "sent");
  11596. }
  11597. return this.parseFunction(node);
  11598. }
  11599. parseMetaProperty(node, meta, propertyName) {
  11600. node.meta = meta;
  11601. const containsEsc = this.state.containsEsc;
  11602. node.property = this.parseIdentifier(true);
  11603. if (node.property.name !== propertyName || containsEsc) {
  11604. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11605. target: meta.name,
  11606. onlyValidPropertyName: propertyName
  11607. });
  11608. }
  11609. return this.finishNode(node, "MetaProperty");
  11610. }
  11611. parseImportMetaPropertyOrPhaseCall(node) {
  11612. this.next();
  11613. if (this.isContextual(105) || this.isContextual(97)) {
  11614. const isSource = this.isContextual(105);
  11615. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11616. this.next();
  11617. node.phase = isSource ? "source" : "defer";
  11618. return this.parseImportCall(node);
  11619. } else {
  11620. const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
  11621. if (this.isContextual(101)) {
  11622. if (!this.inModule) {
  11623. this.raise(Errors.ImportMetaOutsideModule, id);
  11624. }
  11625. this.sawUnambiguousESM = true;
  11626. }
  11627. return this.parseMetaProperty(node, id, "meta");
  11628. }
  11629. }
  11630. parseLiteralAtNode(value, type, node) {
  11631. this.addExtra(node, "rawValue", value);
  11632. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11633. node.value = value;
  11634. this.next();
  11635. return this.finishNode(node, type);
  11636. }
  11637. parseLiteral(value, type) {
  11638. const node = this.startNode();
  11639. return this.parseLiteralAtNode(value, type, node);
  11640. }
  11641. parseStringLiteral(value) {
  11642. return this.parseLiteral(value, "StringLiteral");
  11643. }
  11644. parseNumericLiteral(value) {
  11645. return this.parseLiteral(value, "NumericLiteral");
  11646. }
  11647. parseBigIntLiteral(value) {
  11648. return this.parseLiteral(value, "BigIntLiteral");
  11649. }
  11650. parseDecimalLiteral(value) {
  11651. return this.parseLiteral(value, "DecimalLiteral");
  11652. }
  11653. parseRegExpLiteral(value) {
  11654. const node = this.startNode();
  11655. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11656. node.pattern = value.pattern;
  11657. node.flags = value.flags;
  11658. this.next();
  11659. return this.finishNode(node, "RegExpLiteral");
  11660. }
  11661. parseBooleanLiteral(value) {
  11662. const node = this.startNode();
  11663. node.value = value;
  11664. this.next();
  11665. return this.finishNode(node, "BooleanLiteral");
  11666. }
  11667. parseNullLiteral() {
  11668. const node = this.startNode();
  11669. this.next();
  11670. return this.finishNode(node, "NullLiteral");
  11671. }
  11672. parseParenAndDistinguishExpression(canBeArrow) {
  11673. const startLoc = this.state.startLoc;
  11674. let val;
  11675. this.next();
  11676. this.expressionScope.enter(newArrowHeadScope());
  11677. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11678. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11679. this.state.maybeInArrowParameters = true;
  11680. this.state.inFSharpPipelineDirectBody = false;
  11681. const innerStartLoc = this.state.startLoc;
  11682. const exprList = [];
  11683. const refExpressionErrors = new ExpressionErrors();
  11684. let first = true;
  11685. let spreadStartLoc;
  11686. let optionalCommaStartLoc;
  11687. while (!this.match(11)) {
  11688. if (first) {
  11689. first = false;
  11690. } else {
  11691. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11692. if (this.match(11)) {
  11693. optionalCommaStartLoc = this.state.startLoc;
  11694. break;
  11695. }
  11696. }
  11697. if (this.match(21)) {
  11698. const spreadNodeStartLoc = this.state.startLoc;
  11699. spreadStartLoc = this.state.startLoc;
  11700. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11701. if (!this.checkCommaAfterRest(41)) {
  11702. break;
  11703. }
  11704. } else {
  11705. exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
  11706. }
  11707. }
  11708. const innerEndLoc = this.state.lastTokEndLoc;
  11709. this.expect(11);
  11710. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11711. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11712. let arrowNode = this.startNodeAt(startLoc);
  11713. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11714. this.checkDestructuringPrivate(refExpressionErrors);
  11715. this.expressionScope.validateAsPattern();
  11716. this.expressionScope.exit();
  11717. this.parseArrowExpression(arrowNode, exprList, false);
  11718. return arrowNode;
  11719. }
  11720. this.expressionScope.exit();
  11721. if (!exprList.length) {
  11722. this.unexpected(this.state.lastTokStartLoc);
  11723. }
  11724. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11725. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11726. this.checkExpressionErrors(refExpressionErrors, true);
  11727. this.toReferencedListDeep(exprList, true);
  11728. if (exprList.length > 1) {
  11729. val = this.startNodeAt(innerStartLoc);
  11730. val.expressions = exprList;
  11731. this.finishNode(val, "SequenceExpression");
  11732. this.resetEndLocation(val, innerEndLoc);
  11733. } else {
  11734. val = exprList[0];
  11735. }
  11736. return this.wrapParenthesis(startLoc, val);
  11737. }
  11738. wrapParenthesis(startLoc, expression) {
  11739. if (!(this.optionFlags & 1024)) {
  11740. this.addExtra(expression, "parenthesized", true);
  11741. this.addExtra(expression, "parenStart", startLoc.index);
  11742. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11743. return expression;
  11744. }
  11745. const parenExpression = this.startNodeAt(startLoc);
  11746. parenExpression.expression = expression;
  11747. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11748. }
  11749. shouldParseArrow(params) {
  11750. return !this.canInsertSemicolon();
  11751. }
  11752. parseArrow(node) {
  11753. if (this.eat(19)) {
  11754. return node;
  11755. }
  11756. }
  11757. parseParenItem(node, startLoc) {
  11758. return node;
  11759. }
  11760. parseNewOrNewTarget() {
  11761. const node = this.startNode();
  11762. this.next();
  11763. if (this.match(16)) {
  11764. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11765. this.next();
  11766. const metaProp = this.parseMetaProperty(node, meta, "target");
  11767. if (!this.scope.allowNewTarget) {
  11768. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11769. }
  11770. return metaProp;
  11771. }
  11772. return this.parseNew(node);
  11773. }
  11774. parseNew(node) {
  11775. this.parseNewCallee(node);
  11776. if (this.eat(10)) {
  11777. const args = this.parseExprList(11);
  11778. this.toReferencedList(args);
  11779. node.arguments = args;
  11780. } else {
  11781. node.arguments = [];
  11782. }
  11783. return this.finishNode(node, "NewExpression");
  11784. }
  11785. parseNewCallee(node) {
  11786. const isImport = this.match(83);
  11787. const callee = this.parseNoCallExpr();
  11788. node.callee = callee;
  11789. if (isImport && callee.type === "ImportExpression" || callee.type === "Import") {
  11790. this.raise(Errors.ImportCallNotNewExpression, callee);
  11791. }
  11792. if (callee.type === "Super") {
  11793. this.raise(Errors.SuperCallNotNewExpression, callee);
  11794. }
  11795. }
  11796. parseTemplateElement(isTagged) {
  11797. const {
  11798. start,
  11799. startLoc,
  11800. end,
  11801. value
  11802. } = this.state;
  11803. const elemStart = start + 1;
  11804. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11805. if (value === null) {
  11806. if (!isTagged) {
  11807. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11808. }
  11809. }
  11810. const isTail = this.match(24);
  11811. const endOffset = isTail ? -1 : -2;
  11812. const elemEnd = end + endOffset;
  11813. elem.value = {
  11814. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11815. cooked: value === null ? null : value.slice(1, endOffset)
  11816. };
  11817. elem.tail = isTail;
  11818. this.next();
  11819. const finishedNode = this.finishNode(elem, "TemplateElement");
  11820. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11821. return finishedNode;
  11822. }
  11823. parseTemplate(isTagged) {
  11824. const node = this.startNode();
  11825. let curElt = this.parseTemplateElement(isTagged);
  11826. const quasis = [curElt];
  11827. const substitutions = [];
  11828. while (!curElt.tail) {
  11829. substitutions.push(this.parseTemplateSubstitution());
  11830. this.readTemplateContinuation();
  11831. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11832. }
  11833. node.expressions = substitutions;
  11834. node.quasis = quasis;
  11835. return this.finishNode(node, "TemplateLiteral");
  11836. }
  11837. parseTemplateSubstitution() {
  11838. return this.parseExpression();
  11839. }
  11840. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11841. if (isRecord) {
  11842. this.expectPlugin("recordAndTuple");
  11843. }
  11844. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11845. this.state.inFSharpPipelineDirectBody = false;
  11846. let sawProto = false;
  11847. let first = true;
  11848. const node = this.startNode();
  11849. node.properties = [];
  11850. this.next();
  11851. while (!this.match(close)) {
  11852. if (first) {
  11853. first = false;
  11854. } else {
  11855. this.expect(12);
  11856. if (this.match(close)) {
  11857. this.addTrailingCommaExtraToNode(node);
  11858. break;
  11859. }
  11860. }
  11861. let prop;
  11862. if (isPattern) {
  11863. prop = this.parseBindingProperty();
  11864. } else {
  11865. prop = this.parsePropertyDefinition(refExpressionErrors);
  11866. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  11867. }
  11868. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11869. this.raise(Errors.InvalidRecordProperty, prop);
  11870. }
  11871. if (prop.shorthand) {
  11872. this.addExtra(prop, "shorthand", true);
  11873. }
  11874. node.properties.push(prop);
  11875. }
  11876. this.next();
  11877. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11878. let type = "ObjectExpression";
  11879. if (isPattern) {
  11880. type = "ObjectPattern";
  11881. } else if (isRecord) {
  11882. type = "RecordExpression";
  11883. }
  11884. return this.finishNode(node, type);
  11885. }
  11886. addTrailingCommaExtraToNode(node) {
  11887. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11888. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11889. }
  11890. maybeAsyncOrAccessorProp(prop) {
  11891. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11892. }
  11893. parsePropertyDefinition(refExpressionErrors) {
  11894. let decorators = [];
  11895. if (this.match(26)) {
  11896. if (this.hasPlugin("decorators")) {
  11897. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11898. }
  11899. while (this.match(26)) {
  11900. decorators.push(this.parseDecorator());
  11901. }
  11902. }
  11903. const prop = this.startNode();
  11904. let isAsync = false;
  11905. let isAccessor = false;
  11906. let startLoc;
  11907. if (this.match(21)) {
  11908. if (decorators.length) this.unexpected();
  11909. return this.parseSpread();
  11910. }
  11911. if (decorators.length) {
  11912. prop.decorators = decorators;
  11913. decorators = [];
  11914. }
  11915. prop.method = false;
  11916. if (refExpressionErrors) {
  11917. startLoc = this.state.startLoc;
  11918. }
  11919. let isGenerator = this.eat(55);
  11920. this.parsePropertyNamePrefixOperator(prop);
  11921. const containsEsc = this.state.containsEsc;
  11922. this.parsePropertyName(prop, refExpressionErrors);
  11923. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11924. const {
  11925. key
  11926. } = prop;
  11927. const keyName = key.name;
  11928. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11929. isAsync = true;
  11930. this.resetPreviousNodeTrailingComments(key);
  11931. isGenerator = this.eat(55);
  11932. this.parsePropertyName(prop);
  11933. }
  11934. if (keyName === "get" || keyName === "set") {
  11935. isAccessor = true;
  11936. this.resetPreviousNodeTrailingComments(key);
  11937. prop.kind = keyName;
  11938. if (this.match(55)) {
  11939. isGenerator = true;
  11940. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11941. kind: keyName
  11942. });
  11943. this.next();
  11944. }
  11945. this.parsePropertyName(prop);
  11946. }
  11947. }
  11948. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11949. }
  11950. getGetterSetterExpectedParamCount(method) {
  11951. return method.kind === "get" ? 0 : 1;
  11952. }
  11953. getObjectOrClassMethodParams(method) {
  11954. return method.params;
  11955. }
  11956. checkGetterSetterParams(method) {
  11957. var _params;
  11958. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11959. const params = this.getObjectOrClassMethodParams(method);
  11960. if (params.length !== paramCount) {
  11961. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  11962. }
  11963. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11964. this.raise(Errors.BadSetterRestParameter, method);
  11965. }
  11966. }
  11967. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11968. if (isAccessor) {
  11969. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11970. this.checkGetterSetterParams(finishedProp);
  11971. return finishedProp;
  11972. }
  11973. if (isAsync || isGenerator || this.match(10)) {
  11974. if (isPattern) this.unexpected();
  11975. prop.kind = "method";
  11976. prop.method = true;
  11977. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11978. }
  11979. }
  11980. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11981. prop.shorthand = false;
  11982. if (this.eat(14)) {
  11983. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
  11984. return this.finishObjectProperty(prop);
  11985. }
  11986. if (!prop.computed && prop.key.type === "Identifier") {
  11987. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11988. if (isPattern) {
  11989. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  11990. } else if (this.match(29)) {
  11991. const shorthandAssignLoc = this.state.startLoc;
  11992. if (refExpressionErrors != null) {
  11993. if (refExpressionErrors.shorthandAssignLoc === null) {
  11994. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11995. }
  11996. } else {
  11997. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11998. }
  11999. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  12000. } else {
  12001. prop.value = this.cloneIdentifier(prop.key);
  12002. }
  12003. prop.shorthand = true;
  12004. return this.finishObjectProperty(prop);
  12005. }
  12006. }
  12007. finishObjectProperty(node) {
  12008. return this.finishNode(node, "ObjectProperty");
  12009. }
  12010. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  12011. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  12012. if (!node) this.unexpected();
  12013. return node;
  12014. }
  12015. parsePropertyName(prop, refExpressionErrors) {
  12016. if (this.eat(0)) {
  12017. prop.computed = true;
  12018. prop.key = this.parseMaybeAssignAllowIn();
  12019. this.expect(3);
  12020. } else {
  12021. const {
  12022. type,
  12023. value
  12024. } = this.state;
  12025. let key;
  12026. if (tokenIsKeywordOrIdentifier(type)) {
  12027. key = this.parseIdentifier(true);
  12028. } else {
  12029. switch (type) {
  12030. case 135:
  12031. key = this.parseNumericLiteral(value);
  12032. break;
  12033. case 134:
  12034. key = this.parseStringLiteral(value);
  12035. break;
  12036. case 136:
  12037. key = this.parseBigIntLiteral(value);
  12038. break;
  12039. case 139:
  12040. {
  12041. const privateKeyLoc = this.state.startLoc;
  12042. if (refExpressionErrors != null) {
  12043. if (refExpressionErrors.privateKeyLoc === null) {
  12044. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  12045. }
  12046. } else {
  12047. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  12048. }
  12049. key = this.parsePrivateName();
  12050. break;
  12051. }
  12052. default:
  12053. if (type === 137) {
  12054. key = this.parseDecimalLiteral(value);
  12055. break;
  12056. }
  12057. this.unexpected();
  12058. }
  12059. }
  12060. prop.key = key;
  12061. if (type !== 139) {
  12062. prop.computed = false;
  12063. }
  12064. }
  12065. }
  12066. initFunction(node, isAsync) {
  12067. node.id = null;
  12068. node.generator = false;
  12069. node.async = isAsync;
  12070. }
  12071. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  12072. this.initFunction(node, isAsync);
  12073. node.generator = isGenerator;
  12074. this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
  12075. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12076. this.parseFunctionParams(node, isConstructor);
  12077. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  12078. this.prodParam.exit();
  12079. this.scope.exit();
  12080. return finishedNode;
  12081. }
  12082. parseArrayLike(close, isTuple, refExpressionErrors) {
  12083. if (isTuple) {
  12084. this.expectPlugin("recordAndTuple");
  12085. }
  12086. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12087. this.state.inFSharpPipelineDirectBody = false;
  12088. const node = this.startNode();
  12089. this.next();
  12090. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  12091. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12092. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  12093. }
  12094. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  12095. this.scope.enter(514 | 4);
  12096. let flags = functionFlags(isAsync, false);
  12097. if (!this.match(5) && this.prodParam.hasIn) {
  12098. flags |= 8;
  12099. }
  12100. this.prodParam.enter(flags);
  12101. this.initFunction(node, isAsync);
  12102. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12103. if (params) {
  12104. this.state.maybeInArrowParameters = true;
  12105. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  12106. }
  12107. this.state.maybeInArrowParameters = false;
  12108. this.parseFunctionBody(node, true);
  12109. this.prodParam.exit();
  12110. this.scope.exit();
  12111. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12112. return this.finishNode(node, "ArrowFunctionExpression");
  12113. }
  12114. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  12115. this.toAssignableList(params, trailingCommaLoc, false);
  12116. node.params = params;
  12117. }
  12118. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  12119. this.parseFunctionBody(node, false, isMethod);
  12120. return this.finishNode(node, type);
  12121. }
  12122. parseFunctionBody(node, allowExpression, isMethod = false) {
  12123. const isExpression = allowExpression && !this.match(5);
  12124. this.expressionScope.enter(newExpressionScope());
  12125. if (isExpression) {
  12126. node.body = this.parseMaybeAssign();
  12127. this.checkParams(node, false, allowExpression, false);
  12128. } else {
  12129. const oldStrict = this.state.strict;
  12130. const oldLabels = this.state.labels;
  12131. this.state.labels = [];
  12132. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  12133. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  12134. const nonSimple = !this.isSimpleParamList(node.params);
  12135. if (hasStrictModeDirective && nonSimple) {
  12136. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  12137. }
  12138. const strictModeChanged = !oldStrict && this.state.strict;
  12139. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  12140. if (this.state.strict && node.id) {
  12141. this.checkIdentifier(node.id, 65, strictModeChanged);
  12142. }
  12143. });
  12144. this.prodParam.exit();
  12145. this.state.labels = oldLabels;
  12146. }
  12147. this.expressionScope.exit();
  12148. }
  12149. isSimpleParameter(node) {
  12150. return node.type === "Identifier";
  12151. }
  12152. isSimpleParamList(params) {
  12153. for (let i = 0, len = params.length; i < len; i++) {
  12154. if (!this.isSimpleParameter(params[i])) return false;
  12155. }
  12156. return true;
  12157. }
  12158. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  12159. const checkClashes = !allowDuplicates && new Set();
  12160. const formalParameters = {
  12161. type: "FormalParameters"
  12162. };
  12163. for (const param of node.params) {
  12164. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  12165. }
  12166. }
  12167. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  12168. const elts = [];
  12169. let first = true;
  12170. while (!this.eat(close)) {
  12171. if (first) {
  12172. first = false;
  12173. } else {
  12174. this.expect(12);
  12175. if (this.match(close)) {
  12176. if (nodeForExtra) {
  12177. this.addTrailingCommaExtraToNode(nodeForExtra);
  12178. }
  12179. this.next();
  12180. break;
  12181. }
  12182. }
  12183. elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
  12184. }
  12185. return elts;
  12186. }
  12187. parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
  12188. let elt;
  12189. if (this.match(12)) {
  12190. if (!allowEmpty) {
  12191. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  12192. unexpected: ","
  12193. });
  12194. }
  12195. elt = null;
  12196. } else if (this.match(21)) {
  12197. const spreadNodeStartLoc = this.state.startLoc;
  12198. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12199. } else if (this.match(17)) {
  12200. this.expectPlugin("partialApplication");
  12201. if (!allowPlaceholder) {
  12202. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  12203. }
  12204. const node = this.startNode();
  12205. this.next();
  12206. elt = this.finishNode(node, "ArgumentPlaceholder");
  12207. } else {
  12208. elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
  12209. }
  12210. return elt;
  12211. }
  12212. parseIdentifier(liberal) {
  12213. const node = this.startNode();
  12214. const name = this.parseIdentifierName(liberal);
  12215. return this.createIdentifier(node, name);
  12216. }
  12217. createIdentifier(node, name) {
  12218. node.name = name;
  12219. node.loc.identifierName = name;
  12220. return this.finishNode(node, "Identifier");
  12221. }
  12222. createIdentifierAt(node, name, endLoc) {
  12223. node.name = name;
  12224. node.loc.identifierName = name;
  12225. return this.finishNodeAt(node, "Identifier", endLoc);
  12226. }
  12227. parseIdentifierName(liberal) {
  12228. let name;
  12229. const {
  12230. startLoc,
  12231. type
  12232. } = this.state;
  12233. if (tokenIsKeywordOrIdentifier(type)) {
  12234. name = this.state.value;
  12235. } else {
  12236. this.unexpected();
  12237. }
  12238. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12239. if (liberal) {
  12240. if (tokenIsKeyword) {
  12241. this.replaceToken(132);
  12242. }
  12243. } else {
  12244. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12245. }
  12246. this.next();
  12247. return name;
  12248. }
  12249. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12250. if (word.length > 10) {
  12251. return;
  12252. }
  12253. if (!canBeReservedWord(word)) {
  12254. return;
  12255. }
  12256. if (checkKeywords && isKeyword(word)) {
  12257. this.raise(Errors.UnexpectedKeyword, startLoc, {
  12258. keyword: word
  12259. });
  12260. return;
  12261. }
  12262. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12263. if (reservedTest(word, this.inModule)) {
  12264. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  12265. reservedWord: word
  12266. });
  12267. return;
  12268. } else if (word === "yield") {
  12269. if (this.prodParam.hasYield) {
  12270. this.raise(Errors.YieldBindingIdentifier, startLoc);
  12271. return;
  12272. }
  12273. } else if (word === "await") {
  12274. if (this.prodParam.hasAwait) {
  12275. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  12276. return;
  12277. }
  12278. if (this.scope.inStaticBlock) {
  12279. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  12280. return;
  12281. }
  12282. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  12283. } else if (word === "arguments") {
  12284. if (this.scope.inClassAndNotInNonArrowFunction) {
  12285. this.raise(Errors.ArgumentsInClass, startLoc);
  12286. return;
  12287. }
  12288. }
  12289. }
  12290. recordAwaitIfAllowed() {
  12291. const isAwaitAllowed = this.prodParam.hasAwait;
  12292. if (isAwaitAllowed && !this.scope.inFunction) {
  12293. this.state.hasTopLevelAwait = true;
  12294. }
  12295. return isAwaitAllowed;
  12296. }
  12297. parseAwait(startLoc) {
  12298. const node = this.startNodeAt(startLoc);
  12299. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  12300. if (this.eat(55)) {
  12301. this.raise(Errors.ObsoleteAwaitStar, node);
  12302. }
  12303. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  12304. if (this.isAmbiguousPrefixOrIdentifier()) {
  12305. this.ambiguousScriptDifferentAst = true;
  12306. } else {
  12307. this.sawUnambiguousESM = true;
  12308. }
  12309. }
  12310. if (!this.state.soloAwait) {
  12311. node.argument = this.parseMaybeUnary(null, true);
  12312. }
  12313. return this.finishNode(node, "AwaitExpression");
  12314. }
  12315. isAmbiguousPrefixOrIdentifier() {
  12316. if (this.hasPrecedingLineBreak()) return true;
  12317. const {
  12318. type
  12319. } = this.state;
  12320. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12321. }
  12322. parseYield(startLoc) {
  12323. const node = this.startNodeAt(startLoc);
  12324. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  12325. let delegating = false;
  12326. let argument = null;
  12327. if (!this.hasPrecedingLineBreak()) {
  12328. delegating = this.eat(55);
  12329. switch (this.state.type) {
  12330. case 13:
  12331. case 140:
  12332. case 8:
  12333. case 11:
  12334. case 3:
  12335. case 9:
  12336. case 14:
  12337. case 12:
  12338. if (!delegating) break;
  12339. default:
  12340. argument = this.parseMaybeAssign();
  12341. }
  12342. }
  12343. node.delegate = delegating;
  12344. node.argument = argument;
  12345. return this.finishNode(node, "YieldExpression");
  12346. }
  12347. parseImportCall(node) {
  12348. this.next();
  12349. node.source = this.parseMaybeAssignAllowIn();
  12350. node.options = null;
  12351. if (this.eat(12)) {
  12352. if (!this.match(11)) {
  12353. node.options = this.parseMaybeAssignAllowIn();
  12354. if (this.eat(12)) {
  12355. this.addTrailingCommaExtraToNode(node.options);
  12356. if (!this.match(11)) {
  12357. do {
  12358. this.parseMaybeAssignAllowIn();
  12359. } while (this.eat(12) && !this.match(11));
  12360. this.raise(Errors.ImportCallArity, node);
  12361. }
  12362. }
  12363. } else {
  12364. this.addTrailingCommaExtraToNode(node.source);
  12365. }
  12366. }
  12367. this.expect(11);
  12368. return this.finishNode(node, "ImportExpression");
  12369. }
  12370. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12371. if (this.hasPlugin(["pipelineOperator", {
  12372. proposal: "smart"
  12373. }])) {
  12374. if (left.type === "SequenceExpression") {
  12375. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  12376. }
  12377. }
  12378. }
  12379. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12380. if (this.isSimpleReference(childExpr)) {
  12381. const bodyNode = this.startNodeAt(startLoc);
  12382. bodyNode.callee = childExpr;
  12383. return this.finishNode(bodyNode, "PipelineBareFunction");
  12384. } else {
  12385. const bodyNode = this.startNodeAt(startLoc);
  12386. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12387. bodyNode.expression = childExpr;
  12388. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12389. }
  12390. }
  12391. isSimpleReference(expression) {
  12392. switch (expression.type) {
  12393. case "MemberExpression":
  12394. return !expression.computed && this.isSimpleReference(expression.object);
  12395. case "Identifier":
  12396. return true;
  12397. default:
  12398. return false;
  12399. }
  12400. }
  12401. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12402. if (this.match(19)) {
  12403. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  12404. }
  12405. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12406. this.raise(Errors.PipelineTopicUnused, startLoc);
  12407. }
  12408. }
  12409. withTopicBindingContext(callback) {
  12410. const outerContextTopicState = this.state.topicContext;
  12411. this.state.topicContext = {
  12412. maxNumOfResolvableTopics: 1,
  12413. maxTopicIndex: null
  12414. };
  12415. try {
  12416. return callback();
  12417. } finally {
  12418. this.state.topicContext = outerContextTopicState;
  12419. }
  12420. }
  12421. withSmartMixTopicForbiddingContext(callback) {
  12422. if (this.hasPlugin(["pipelineOperator", {
  12423. proposal: "smart"
  12424. }])) {
  12425. const outerContextTopicState = this.state.topicContext;
  12426. this.state.topicContext = {
  12427. maxNumOfResolvableTopics: 0,
  12428. maxTopicIndex: null
  12429. };
  12430. try {
  12431. return callback();
  12432. } finally {
  12433. this.state.topicContext = outerContextTopicState;
  12434. }
  12435. } else {
  12436. return callback();
  12437. }
  12438. }
  12439. withSoloAwaitPermittingContext(callback) {
  12440. const outerContextSoloAwaitState = this.state.soloAwait;
  12441. this.state.soloAwait = true;
  12442. try {
  12443. return callback();
  12444. } finally {
  12445. this.state.soloAwait = outerContextSoloAwaitState;
  12446. }
  12447. }
  12448. allowInAnd(callback) {
  12449. const flags = this.prodParam.currentFlags();
  12450. const prodParamToSet = 8 & ~flags;
  12451. if (prodParamToSet) {
  12452. this.prodParam.enter(flags | 8);
  12453. try {
  12454. return callback();
  12455. } finally {
  12456. this.prodParam.exit();
  12457. }
  12458. }
  12459. return callback();
  12460. }
  12461. disallowInAnd(callback) {
  12462. const flags = this.prodParam.currentFlags();
  12463. const prodParamToClear = 8 & flags;
  12464. if (prodParamToClear) {
  12465. this.prodParam.enter(flags & ~8);
  12466. try {
  12467. return callback();
  12468. } finally {
  12469. this.prodParam.exit();
  12470. }
  12471. }
  12472. return callback();
  12473. }
  12474. registerTopicReference() {
  12475. this.state.topicContext.maxTopicIndex = 0;
  12476. }
  12477. topicReferenceIsAllowedInCurrentContext() {
  12478. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12479. }
  12480. topicReferenceWasUsedInCurrentContext() {
  12481. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12482. }
  12483. parseFSharpPipelineBody(prec) {
  12484. const startLoc = this.state.startLoc;
  12485. this.state.potentialArrowAt = this.state.start;
  12486. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12487. this.state.inFSharpPipelineDirectBody = true;
  12488. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12489. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12490. return ret;
  12491. }
  12492. parseModuleExpression() {
  12493. this.expectPlugin("moduleBlocks");
  12494. const node = this.startNode();
  12495. this.next();
  12496. if (!this.match(5)) {
  12497. this.unexpected(null, 5);
  12498. }
  12499. const program = this.startNodeAt(this.state.endLoc);
  12500. this.next();
  12501. const revertScopes = this.initializeScopes(true);
  12502. this.enterInitialScopes();
  12503. try {
  12504. node.body = this.parseProgram(program, 8, "module");
  12505. } finally {
  12506. revertScopes();
  12507. }
  12508. return this.finishNode(node, "ModuleExpression");
  12509. }
  12510. parseVoidPattern(refExpressionErrors) {
  12511. this.expectPlugin("discardBinding");
  12512. const node = this.startNode();
  12513. if (refExpressionErrors != null) {
  12514. refExpressionErrors.voidPatternLoc = this.state.startLoc;
  12515. }
  12516. this.next();
  12517. return this.finishNode(node, "VoidPattern");
  12518. }
  12519. parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
  12520. if (refExpressionErrors != null && this.match(88)) {
  12521. const nextCode = this.lookaheadCharCode();
  12522. if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
  12523. return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
  12524. }
  12525. }
  12526. return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
  12527. }
  12528. parsePropertyNamePrefixOperator(prop) {}
  12529. }
  12530. const loopLabel = {
  12531. kind: 1
  12532. },
  12533. switchLabel = {
  12534. kind: 2
  12535. };
  12536. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12537. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12538. function babel7CompatTokens(tokens, input, startIndex) {
  12539. for (let i = 0; i < tokens.length; i++) {
  12540. const token = tokens[i];
  12541. const {
  12542. type
  12543. } = token;
  12544. if (typeof type === "number") {
  12545. if (type === 139) {
  12546. const {
  12547. loc,
  12548. start,
  12549. value,
  12550. end
  12551. } = token;
  12552. const hashEndPos = start + 1;
  12553. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12554. tokens.splice(i, 1, new Token({
  12555. type: getExportedToken(27),
  12556. value: "#",
  12557. start: start,
  12558. end: hashEndPos,
  12559. startLoc: loc.start,
  12560. endLoc: hashEndLoc
  12561. }), new Token({
  12562. type: getExportedToken(132),
  12563. value: value,
  12564. start: hashEndPos,
  12565. end: end,
  12566. startLoc: hashEndLoc,
  12567. endLoc: loc.end
  12568. }));
  12569. i++;
  12570. continue;
  12571. }
  12572. if (tokenIsTemplate(type)) {
  12573. const {
  12574. loc,
  12575. start,
  12576. value,
  12577. end
  12578. } = token;
  12579. const backquoteEnd = start + 1;
  12580. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12581. let startToken;
  12582. if (input.charCodeAt(start - startIndex) === 96) {
  12583. startToken = new Token({
  12584. type: getExportedToken(22),
  12585. value: "`",
  12586. start: start,
  12587. end: backquoteEnd,
  12588. startLoc: loc.start,
  12589. endLoc: backquoteEndLoc
  12590. });
  12591. } else {
  12592. startToken = new Token({
  12593. type: getExportedToken(8),
  12594. value: "}",
  12595. start: start,
  12596. end: backquoteEnd,
  12597. startLoc: loc.start,
  12598. endLoc: backquoteEndLoc
  12599. });
  12600. }
  12601. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12602. if (type === 24) {
  12603. templateElementEnd = end - 1;
  12604. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12605. templateValue = value === null ? null : value.slice(1, -1);
  12606. endToken = new Token({
  12607. type: getExportedToken(22),
  12608. value: "`",
  12609. start: templateElementEnd,
  12610. end: end,
  12611. startLoc: templateElementEndLoc,
  12612. endLoc: loc.end
  12613. });
  12614. } else {
  12615. templateElementEnd = end - 2;
  12616. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12617. templateValue = value === null ? null : value.slice(1, -2);
  12618. endToken = new Token({
  12619. type: getExportedToken(23),
  12620. value: "${",
  12621. start: templateElementEnd,
  12622. end: end,
  12623. startLoc: templateElementEndLoc,
  12624. endLoc: loc.end
  12625. });
  12626. }
  12627. tokens.splice(i, 1, startToken, new Token({
  12628. type: getExportedToken(20),
  12629. value: templateValue,
  12630. start: backquoteEnd,
  12631. end: templateElementEnd,
  12632. startLoc: backquoteEndLoc,
  12633. endLoc: templateElementEndLoc
  12634. }), endToken);
  12635. i += 2;
  12636. continue;
  12637. }
  12638. token.type = getExportedToken(type);
  12639. }
  12640. }
  12641. return tokens;
  12642. }
  12643. class StatementParser extends ExpressionParser {
  12644. parseTopLevel(file, program) {
  12645. file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
  12646. file.comments = this.comments;
  12647. if (this.optionFlags & 256) {
  12648. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  12649. }
  12650. return this.finishNode(file, "File");
  12651. }
  12652. parseProgram(program, end, sourceType) {
  12653. program.sourceType = sourceType;
  12654. program.interpreter = this.parseInterpreterDirective();
  12655. this.parseBlockBody(program, true, true, end);
  12656. if (this.inModule) {
  12657. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  12658. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12659. this.raise(Errors.ModuleExportUndefined, at, {
  12660. localName
  12661. });
  12662. }
  12663. }
  12664. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  12665. }
  12666. let finishedProgram;
  12667. if (end === 140) {
  12668. finishedProgram = this.finishNode(program, "Program");
  12669. } else {
  12670. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12671. }
  12672. return finishedProgram;
  12673. }
  12674. stmtToDirective(stmt) {
  12675. const directive = this.castNodeTo(stmt, "Directive");
  12676. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  12677. const expressionValue = directiveLiteral.value;
  12678. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  12679. const val = directiveLiteral.value = raw.slice(1, -1);
  12680. this.addExtra(directiveLiteral, "raw", raw);
  12681. this.addExtra(directiveLiteral, "rawValue", val);
  12682. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12683. directive.value = directiveLiteral;
  12684. delete stmt.expression;
  12685. return directive;
  12686. }
  12687. parseInterpreterDirective() {
  12688. if (!this.match(28)) {
  12689. return null;
  12690. }
  12691. const node = this.startNode();
  12692. node.value = this.state.value;
  12693. this.next();
  12694. return this.finishNode(node, "InterpreterDirective");
  12695. }
  12696. isLet() {
  12697. if (!this.isContextual(100)) {
  12698. return false;
  12699. }
  12700. return this.hasFollowingBindingAtom();
  12701. }
  12702. isUsing() {
  12703. if (!this.isContextual(107)) {
  12704. return false;
  12705. }
  12706. return this.nextTokenIsIdentifierOnSameLine();
  12707. }
  12708. isForUsing() {
  12709. if (!this.isContextual(107)) {
  12710. return false;
  12711. }
  12712. const next = this.nextTokenInLineStart();
  12713. const nextCh = this.codePointAtPos(next);
  12714. if (this.isUnparsedContextual(next, "of")) {
  12715. const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
  12716. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  12717. return false;
  12718. }
  12719. }
  12720. if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
  12721. return true;
  12722. }
  12723. return false;
  12724. }
  12725. nextTokenIsIdentifierOnSameLine() {
  12726. const next = this.nextTokenInLineStart();
  12727. const nextCh = this.codePointAtPos(next);
  12728. return this.chStartsBindingIdentifier(nextCh, next);
  12729. }
  12730. isAwaitUsing() {
  12731. if (!this.isContextual(96)) {
  12732. return false;
  12733. }
  12734. let next = this.nextTokenInLineStart();
  12735. if (this.isUnparsedContextual(next, "using")) {
  12736. next = this.nextTokenInLineStartSince(next + 5);
  12737. const nextCh = this.codePointAtPos(next);
  12738. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12739. return true;
  12740. }
  12741. }
  12742. return false;
  12743. }
  12744. chStartsBindingIdentifier(ch, pos) {
  12745. if (isIdentifierStart(ch)) {
  12746. keywordRelationalOperator.lastIndex = pos;
  12747. if (keywordRelationalOperator.test(this.input)) {
  12748. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12749. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12750. return false;
  12751. }
  12752. }
  12753. return true;
  12754. } else if (ch === 92) {
  12755. return true;
  12756. } else {
  12757. return false;
  12758. }
  12759. }
  12760. chStartsBindingPattern(ch) {
  12761. return ch === 91 || ch === 123;
  12762. }
  12763. hasFollowingBindingAtom() {
  12764. const next = this.nextTokenStart();
  12765. const nextCh = this.codePointAtPos(next);
  12766. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12767. }
  12768. hasInLineFollowingBindingIdentifierOrBrace() {
  12769. const next = this.nextTokenInLineStart();
  12770. const nextCh = this.codePointAtPos(next);
  12771. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  12772. }
  12773. allowsUsing() {
  12774. return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
  12775. }
  12776. parseModuleItem() {
  12777. return this.parseStatementLike(1 | 2 | 4 | 8);
  12778. }
  12779. parseStatementListItem() {
  12780. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12781. }
  12782. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12783. let flags = 0;
  12784. if (this.options.annexB && !this.state.strict) {
  12785. flags |= 4;
  12786. if (allowLabeledFunction) {
  12787. flags |= 8;
  12788. }
  12789. }
  12790. return this.parseStatementLike(flags);
  12791. }
  12792. parseStatement() {
  12793. return this.parseStatementLike(0);
  12794. }
  12795. parseStatementLike(flags) {
  12796. let decorators = null;
  12797. if (this.match(26)) {
  12798. decorators = this.parseDecorators(true);
  12799. }
  12800. return this.parseStatementContent(flags, decorators);
  12801. }
  12802. parseStatementContent(flags, decorators) {
  12803. const startType = this.state.type;
  12804. const node = this.startNode();
  12805. const allowDeclaration = !!(flags & 2);
  12806. const allowFunctionDeclaration = !!(flags & 4);
  12807. const topLevel = flags & 1;
  12808. switch (startType) {
  12809. case 60:
  12810. return this.parseBreakContinueStatement(node, true);
  12811. case 63:
  12812. return this.parseBreakContinueStatement(node, false);
  12813. case 64:
  12814. return this.parseDebuggerStatement(node);
  12815. case 90:
  12816. return this.parseDoWhileStatement(node);
  12817. case 91:
  12818. return this.parseForStatement(node);
  12819. case 68:
  12820. if (this.lookaheadCharCode() === 46) break;
  12821. if (!allowFunctionDeclaration) {
  12822. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12823. }
  12824. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12825. case 80:
  12826. if (!allowDeclaration) this.unexpected();
  12827. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12828. case 69:
  12829. return this.parseIfStatement(node);
  12830. case 70:
  12831. return this.parseReturnStatement(node);
  12832. case 71:
  12833. return this.parseSwitchStatement(node);
  12834. case 72:
  12835. return this.parseThrowStatement(node);
  12836. case 73:
  12837. return this.parseTryStatement(node);
  12838. case 96:
  12839. if (this.isAwaitUsing()) {
  12840. if (!this.allowsUsing()) {
  12841. this.raise(Errors.UnexpectedUsingDeclaration, node);
  12842. } else if (!allowDeclaration) {
  12843. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12844. } else if (!this.recordAwaitIfAllowed()) {
  12845. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12846. }
  12847. this.next();
  12848. return this.parseVarStatement(node, "await using");
  12849. }
  12850. break;
  12851. case 107:
  12852. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  12853. break;
  12854. }
  12855. if (!this.allowsUsing()) {
  12856. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12857. } else if (!allowDeclaration) {
  12858. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12859. }
  12860. return this.parseVarStatement(node, "using");
  12861. case 100:
  12862. {
  12863. if (this.state.containsEsc) {
  12864. break;
  12865. }
  12866. const next = this.nextTokenStart();
  12867. const nextCh = this.codePointAtPos(next);
  12868. if (nextCh !== 91) {
  12869. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12870. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12871. break;
  12872. }
  12873. }
  12874. }
  12875. case 75:
  12876. {
  12877. if (!allowDeclaration) {
  12878. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12879. }
  12880. }
  12881. case 74:
  12882. {
  12883. const kind = this.state.value;
  12884. return this.parseVarStatement(node, kind);
  12885. }
  12886. case 92:
  12887. return this.parseWhileStatement(node);
  12888. case 76:
  12889. return this.parseWithStatement(node);
  12890. case 5:
  12891. return this.parseBlock();
  12892. case 13:
  12893. return this.parseEmptyStatement(node);
  12894. case 83:
  12895. {
  12896. const nextTokenCharCode = this.lookaheadCharCode();
  12897. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12898. break;
  12899. }
  12900. }
  12901. case 82:
  12902. {
  12903. if (!(this.optionFlags & 8) && !topLevel) {
  12904. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12905. }
  12906. this.next();
  12907. let result;
  12908. if (startType === 83) {
  12909. result = this.parseImport(node);
  12910. } else {
  12911. result = this.parseExport(node, decorators);
  12912. }
  12913. this.assertModuleNodeAllowed(result);
  12914. return result;
  12915. }
  12916. default:
  12917. {
  12918. if (this.isAsyncFunction()) {
  12919. if (!allowDeclaration) {
  12920. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12921. }
  12922. this.next();
  12923. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12924. }
  12925. }
  12926. }
  12927. const maybeName = this.state.value;
  12928. const expr = this.parseExpression();
  12929. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  12930. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12931. } else {
  12932. return this.parseExpressionStatement(node, expr, decorators);
  12933. }
  12934. }
  12935. assertModuleNodeAllowed(node) {
  12936. if (!(this.optionFlags & 8) && !this.inModule) {
  12937. this.raise(Errors.ImportOutsideModule, node);
  12938. }
  12939. }
  12940. decoratorsEnabledBeforeExport() {
  12941. if (this.hasPlugin("decorators-legacy")) return true;
  12942. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12943. }
  12944. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12945. if (maybeDecorators) {
  12946. var _classNode$decorators;
  12947. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  12948. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12949. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12950. }
  12951. classNode.decorators.unshift(...maybeDecorators);
  12952. } else {
  12953. classNode.decorators = maybeDecorators;
  12954. }
  12955. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12956. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12957. }
  12958. return classNode;
  12959. }
  12960. canHaveLeadingDecorator() {
  12961. return this.match(80);
  12962. }
  12963. parseDecorators(allowExport) {
  12964. const decorators = [];
  12965. do {
  12966. decorators.push(this.parseDecorator());
  12967. } while (this.match(26));
  12968. if (this.match(82)) {
  12969. if (!allowExport) {
  12970. this.unexpected();
  12971. }
  12972. if (!this.decoratorsEnabledBeforeExport()) {
  12973. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  12974. }
  12975. } else if (!this.canHaveLeadingDecorator()) {
  12976. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  12977. }
  12978. return decorators;
  12979. }
  12980. parseDecorator() {
  12981. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12982. const node = this.startNode();
  12983. this.next();
  12984. if (this.hasPlugin("decorators")) {
  12985. const startLoc = this.state.startLoc;
  12986. let expr;
  12987. if (this.match(10)) {
  12988. const startLoc = this.state.startLoc;
  12989. this.next();
  12990. expr = this.parseExpression();
  12991. this.expect(11);
  12992. expr = this.wrapParenthesis(startLoc, expr);
  12993. const paramsStartLoc = this.state.startLoc;
  12994. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12995. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12996. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  12997. }
  12998. } else {
  12999. expr = this.parseIdentifier(false);
  13000. while (this.eat(16)) {
  13001. const node = this.startNodeAt(startLoc);
  13002. node.object = expr;
  13003. if (this.match(139)) {
  13004. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  13005. node.property = this.parsePrivateName();
  13006. } else {
  13007. node.property = this.parseIdentifier(true);
  13008. }
  13009. node.computed = false;
  13010. expr = this.finishNode(node, "MemberExpression");
  13011. }
  13012. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  13013. }
  13014. } else {
  13015. node.expression = this.parseExprSubscripts();
  13016. }
  13017. return this.finishNode(node, "Decorator");
  13018. }
  13019. parseMaybeDecoratorArguments(expr, startLoc) {
  13020. if (this.eat(10)) {
  13021. const node = this.startNodeAt(startLoc);
  13022. node.callee = expr;
  13023. node.arguments = this.parseCallExpressionArguments();
  13024. this.toReferencedList(node.arguments);
  13025. return this.finishNode(node, "CallExpression");
  13026. }
  13027. return expr;
  13028. }
  13029. parseBreakContinueStatement(node, isBreak) {
  13030. this.next();
  13031. if (this.isLineTerminator()) {
  13032. node.label = null;
  13033. } else {
  13034. node.label = this.parseIdentifier();
  13035. this.semicolon();
  13036. }
  13037. this.verifyBreakContinue(node, isBreak);
  13038. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  13039. }
  13040. verifyBreakContinue(node, isBreak) {
  13041. let i;
  13042. for (i = 0; i < this.state.labels.length; ++i) {
  13043. const lab = this.state.labels[i];
  13044. if (node.label == null || lab.name === node.label.name) {
  13045. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  13046. break;
  13047. }
  13048. if (node.label && isBreak) break;
  13049. }
  13050. }
  13051. if (i === this.state.labels.length) {
  13052. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  13053. this.raise(Errors.IllegalBreakContinue, node, {
  13054. type
  13055. });
  13056. }
  13057. }
  13058. parseDebuggerStatement(node) {
  13059. this.next();
  13060. this.semicolon();
  13061. return this.finishNode(node, "DebuggerStatement");
  13062. }
  13063. parseHeaderExpression() {
  13064. this.expect(10);
  13065. const val = this.parseExpression();
  13066. this.expect(11);
  13067. return val;
  13068. }
  13069. parseDoWhileStatement(node) {
  13070. this.next();
  13071. this.state.labels.push(loopLabel);
  13072. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13073. this.state.labels.pop();
  13074. this.expect(92);
  13075. node.test = this.parseHeaderExpression();
  13076. this.eat(13);
  13077. return this.finishNode(node, "DoWhileStatement");
  13078. }
  13079. parseForStatement(node) {
  13080. this.next();
  13081. this.state.labels.push(loopLabel);
  13082. let awaitAt = null;
  13083. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  13084. awaitAt = this.state.startLoc;
  13085. this.next();
  13086. }
  13087. this.scope.enter(0);
  13088. this.expect(10);
  13089. if (this.match(13)) {
  13090. if (awaitAt !== null) {
  13091. this.unexpected(awaitAt);
  13092. }
  13093. return this.parseFor(node, null);
  13094. }
  13095. const startsWithLet = this.isContextual(100);
  13096. {
  13097. const startsWithAwaitUsing = this.isAwaitUsing();
  13098. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
  13099. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  13100. if (this.match(74) || this.match(75) || isLetOrUsing) {
  13101. const initNode = this.startNode();
  13102. let kind;
  13103. if (startsWithAwaitUsing) {
  13104. kind = "await using";
  13105. if (!this.recordAwaitIfAllowed()) {
  13106. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  13107. }
  13108. this.next();
  13109. } else {
  13110. kind = this.state.value;
  13111. }
  13112. this.next();
  13113. this.parseVar(initNode, true, kind);
  13114. const init = this.finishNode(initNode, "VariableDeclaration");
  13115. const isForIn = this.match(58);
  13116. if (isForIn && starsWithUsingDeclaration) {
  13117. this.raise(Errors.ForInUsing, init);
  13118. }
  13119. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  13120. return this.parseForIn(node, init, awaitAt);
  13121. }
  13122. if (awaitAt !== null) {
  13123. this.unexpected(awaitAt);
  13124. }
  13125. return this.parseFor(node, init);
  13126. }
  13127. }
  13128. const startsWithAsync = this.isContextual(95);
  13129. const refExpressionErrors = new ExpressionErrors();
  13130. const init = this.parseExpression(true, refExpressionErrors);
  13131. const isForOf = this.isContextual(102);
  13132. if (isForOf) {
  13133. if (startsWithLet) {
  13134. this.raise(Errors.ForOfLet, init);
  13135. }
  13136. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  13137. this.raise(Errors.ForOfAsync, init);
  13138. }
  13139. }
  13140. if (isForOf || this.match(58)) {
  13141. this.checkDestructuringPrivate(refExpressionErrors);
  13142. this.toAssignable(init, true);
  13143. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  13144. this.checkLVal(init, {
  13145. type
  13146. });
  13147. return this.parseForIn(node, init, awaitAt);
  13148. } else {
  13149. this.checkExpressionErrors(refExpressionErrors, true);
  13150. }
  13151. if (awaitAt !== null) {
  13152. this.unexpected(awaitAt);
  13153. }
  13154. return this.parseFor(node, init);
  13155. }
  13156. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  13157. this.next();
  13158. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  13159. }
  13160. parseIfStatement(node) {
  13161. this.next();
  13162. node.test = this.parseHeaderExpression();
  13163. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  13164. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  13165. return this.finishNode(node, "IfStatement");
  13166. }
  13167. parseReturnStatement(node) {
  13168. if (!this.prodParam.hasReturn) {
  13169. this.raise(Errors.IllegalReturn, this.state.startLoc);
  13170. }
  13171. this.next();
  13172. if (this.isLineTerminator()) {
  13173. node.argument = null;
  13174. } else {
  13175. node.argument = this.parseExpression();
  13176. this.semicolon();
  13177. }
  13178. return this.finishNode(node, "ReturnStatement");
  13179. }
  13180. parseSwitchStatement(node) {
  13181. this.next();
  13182. node.discriminant = this.parseHeaderExpression();
  13183. const cases = node.cases = [];
  13184. this.expect(5);
  13185. this.state.labels.push(switchLabel);
  13186. this.scope.enter(256);
  13187. let cur;
  13188. for (let sawDefault; !this.match(8);) {
  13189. if (this.match(61) || this.match(65)) {
  13190. const isCase = this.match(61);
  13191. if (cur) this.finishNode(cur, "SwitchCase");
  13192. cases.push(cur = this.startNode());
  13193. cur.consequent = [];
  13194. this.next();
  13195. if (isCase) {
  13196. cur.test = this.parseExpression();
  13197. } else {
  13198. if (sawDefault) {
  13199. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  13200. }
  13201. sawDefault = true;
  13202. cur.test = null;
  13203. }
  13204. this.expect(14);
  13205. } else {
  13206. if (cur) {
  13207. cur.consequent.push(this.parseStatementListItem());
  13208. } else {
  13209. this.unexpected();
  13210. }
  13211. }
  13212. }
  13213. this.scope.exit();
  13214. if (cur) this.finishNode(cur, "SwitchCase");
  13215. this.next();
  13216. this.state.labels.pop();
  13217. return this.finishNode(node, "SwitchStatement");
  13218. }
  13219. parseThrowStatement(node) {
  13220. this.next();
  13221. if (this.hasPrecedingLineBreak()) {
  13222. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  13223. }
  13224. node.argument = this.parseExpression();
  13225. this.semicolon();
  13226. return this.finishNode(node, "ThrowStatement");
  13227. }
  13228. parseCatchClauseParam() {
  13229. const param = this.parseBindingAtom();
  13230. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13231. this.checkLVal(param, {
  13232. type: "CatchClause"
  13233. }, 9);
  13234. return param;
  13235. }
  13236. parseTryStatement(node) {
  13237. this.next();
  13238. node.block = this.parseBlock();
  13239. node.handler = null;
  13240. if (this.match(62)) {
  13241. const clause = this.startNode();
  13242. this.next();
  13243. if (this.match(10)) {
  13244. this.expect(10);
  13245. clause.param = this.parseCatchClauseParam();
  13246. this.expect(11);
  13247. } else {
  13248. clause.param = null;
  13249. this.scope.enter(0);
  13250. }
  13251. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13252. this.scope.exit();
  13253. node.handler = this.finishNode(clause, "CatchClause");
  13254. }
  13255. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13256. if (!node.handler && !node.finalizer) {
  13257. this.raise(Errors.NoCatchOrFinally, node);
  13258. }
  13259. return this.finishNode(node, "TryStatement");
  13260. }
  13261. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13262. this.next();
  13263. this.parseVar(node, false, kind, allowMissingInitializer);
  13264. this.semicolon();
  13265. return this.finishNode(node, "VariableDeclaration");
  13266. }
  13267. parseWhileStatement(node) {
  13268. this.next();
  13269. node.test = this.parseHeaderExpression();
  13270. this.state.labels.push(loopLabel);
  13271. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13272. this.state.labels.pop();
  13273. return this.finishNode(node, "WhileStatement");
  13274. }
  13275. parseWithStatement(node) {
  13276. if (this.state.strict) {
  13277. this.raise(Errors.StrictWith, this.state.startLoc);
  13278. }
  13279. this.next();
  13280. node.object = this.parseHeaderExpression();
  13281. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13282. return this.finishNode(node, "WithStatement");
  13283. }
  13284. parseEmptyStatement(node) {
  13285. this.next();
  13286. return this.finishNode(node, "EmptyStatement");
  13287. }
  13288. parseLabeledStatement(node, maybeName, expr, flags) {
  13289. for (const label of this.state.labels) {
  13290. if (label.name === maybeName) {
  13291. this.raise(Errors.LabelRedeclaration, expr, {
  13292. labelName: maybeName
  13293. });
  13294. }
  13295. }
  13296. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  13297. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13298. const label = this.state.labels[i];
  13299. if (label.statementStart === node.start) {
  13300. label.statementStart = this.sourceToOffsetPos(this.state.start);
  13301. label.kind = kind;
  13302. } else {
  13303. break;
  13304. }
  13305. }
  13306. this.state.labels.push({
  13307. name: maybeName,
  13308. kind: kind,
  13309. statementStart: this.sourceToOffsetPos(this.state.start)
  13310. });
  13311. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13312. this.state.labels.pop();
  13313. node.label = expr;
  13314. return this.finishNode(node, "LabeledStatement");
  13315. }
  13316. parseExpressionStatement(node, expr, decorators) {
  13317. node.expression = expr;
  13318. this.semicolon();
  13319. return this.finishNode(node, "ExpressionStatement");
  13320. }
  13321. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13322. const node = this.startNode();
  13323. if (allowDirectives) {
  13324. this.state.strictErrors.clear();
  13325. }
  13326. this.expect(5);
  13327. if (createNewLexicalScope) {
  13328. this.scope.enter(0);
  13329. }
  13330. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13331. if (createNewLexicalScope) {
  13332. this.scope.exit();
  13333. }
  13334. return this.finishNode(node, "BlockStatement");
  13335. }
  13336. isValidDirective(stmt) {
  13337. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13338. }
  13339. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13340. const body = node.body = [];
  13341. const directives = node.directives = [];
  13342. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13343. }
  13344. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13345. const oldStrict = this.state.strict;
  13346. let hasStrictModeDirective = false;
  13347. let parsedNonDirective = false;
  13348. while (!this.match(end)) {
  13349. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13350. if (directives && !parsedNonDirective) {
  13351. if (this.isValidDirective(stmt)) {
  13352. const directive = this.stmtToDirective(stmt);
  13353. directives.push(directive);
  13354. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13355. hasStrictModeDirective = true;
  13356. this.setStrict(true);
  13357. }
  13358. continue;
  13359. }
  13360. parsedNonDirective = true;
  13361. this.state.strictErrors.clear();
  13362. }
  13363. body.push(stmt);
  13364. }
  13365. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  13366. if (!oldStrict) {
  13367. this.setStrict(false);
  13368. }
  13369. this.next();
  13370. }
  13371. parseFor(node, init) {
  13372. node.init = init;
  13373. this.semicolon(false);
  13374. node.test = this.match(13) ? null : this.parseExpression();
  13375. this.semicolon(false);
  13376. node.update = this.match(11) ? null : this.parseExpression();
  13377. this.expect(11);
  13378. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13379. this.scope.exit();
  13380. this.state.labels.pop();
  13381. return this.finishNode(node, "ForStatement");
  13382. }
  13383. parseForIn(node, init, awaitAt) {
  13384. const isForIn = this.match(58);
  13385. this.next();
  13386. if (isForIn) {
  13387. if (awaitAt !== null) this.unexpected(awaitAt);
  13388. } else {
  13389. node.await = awaitAt !== null;
  13390. }
  13391. 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")) {
  13392. this.raise(Errors.ForInOfLoopInitializer, init, {
  13393. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13394. });
  13395. }
  13396. if (init.type === "AssignmentPattern") {
  13397. this.raise(Errors.InvalidLhs, init, {
  13398. ancestor: {
  13399. type: "ForStatement"
  13400. }
  13401. });
  13402. }
  13403. node.left = init;
  13404. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13405. this.expect(11);
  13406. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13407. this.scope.exit();
  13408. this.state.labels.pop();
  13409. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13410. }
  13411. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13412. const declarations = node.declarations = [];
  13413. node.kind = kind;
  13414. for (;;) {
  13415. const decl = this.startNode();
  13416. this.parseVarId(decl, kind);
  13417. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13418. if (decl.init === null && !allowMissingInitializer) {
  13419. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13420. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13421. kind: "destructuring"
  13422. });
  13423. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  13424. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13425. kind
  13426. });
  13427. }
  13428. }
  13429. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13430. if (!this.eat(12)) break;
  13431. }
  13432. return node;
  13433. }
  13434. parseVarId(decl, kind) {
  13435. const id = this.parseBindingAtom();
  13436. if (kind === "using" || kind === "await using") {
  13437. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  13438. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  13439. }
  13440. } else {
  13441. if (id.type === "VoidPattern") {
  13442. this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
  13443. }
  13444. }
  13445. this.checkLVal(id, {
  13446. type: "VariableDeclarator"
  13447. }, kind === "var" ? 5 : 8201);
  13448. decl.id = id;
  13449. }
  13450. parseAsyncFunctionExpression(node) {
  13451. return this.parseFunction(node, 8);
  13452. }
  13453. parseFunction(node, flags = 0) {
  13454. const hangingDeclaration = flags & 2;
  13455. const isDeclaration = !!(flags & 1);
  13456. const requireId = isDeclaration && !(flags & 4);
  13457. const isAsync = !!(flags & 8);
  13458. this.initFunction(node, isAsync);
  13459. if (this.match(55)) {
  13460. if (hangingDeclaration) {
  13461. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  13462. }
  13463. this.next();
  13464. node.generator = true;
  13465. }
  13466. if (isDeclaration) {
  13467. node.id = this.parseFunctionId(requireId);
  13468. }
  13469. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13470. this.state.maybeInArrowParameters = false;
  13471. this.scope.enter(514);
  13472. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13473. if (!isDeclaration) {
  13474. node.id = this.parseFunctionId();
  13475. }
  13476. this.parseFunctionParams(node, false);
  13477. this.withSmartMixTopicForbiddingContext(() => {
  13478. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13479. });
  13480. this.prodParam.exit();
  13481. this.scope.exit();
  13482. if (isDeclaration && !hangingDeclaration) {
  13483. this.registerFunctionStatementId(node);
  13484. }
  13485. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13486. return node;
  13487. }
  13488. parseFunctionId(requireId) {
  13489. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13490. }
  13491. parseFunctionParams(node, isConstructor) {
  13492. this.expect(10);
  13493. this.expressionScope.enter(newParameterDeclarationScope());
  13494. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13495. this.expressionScope.exit();
  13496. }
  13497. registerFunctionStatementId(node) {
  13498. if (!node.id) return;
  13499. 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);
  13500. }
  13501. parseClass(node, isStatement, optionalId) {
  13502. this.next();
  13503. const oldStrict = this.state.strict;
  13504. this.state.strict = true;
  13505. this.parseClassId(node, isStatement, optionalId);
  13506. this.parseClassSuper(node);
  13507. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13508. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13509. }
  13510. isClassProperty() {
  13511. return this.match(29) || this.match(13) || this.match(8);
  13512. }
  13513. isClassMethod() {
  13514. return this.match(10);
  13515. }
  13516. nameIsConstructor(key) {
  13517. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  13518. }
  13519. isNonstaticConstructor(method) {
  13520. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  13521. }
  13522. parseClassBody(hadSuperClass, oldStrict) {
  13523. this.classScope.enter();
  13524. const state = {
  13525. hadConstructor: false,
  13526. hadSuperClass
  13527. };
  13528. let decorators = [];
  13529. const classBody = this.startNode();
  13530. classBody.body = [];
  13531. this.expect(5);
  13532. this.withSmartMixTopicForbiddingContext(() => {
  13533. while (!this.match(8)) {
  13534. if (this.eat(13)) {
  13535. if (decorators.length > 0) {
  13536. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  13537. }
  13538. continue;
  13539. }
  13540. if (this.match(26)) {
  13541. decorators.push(this.parseDecorator());
  13542. continue;
  13543. }
  13544. const member = this.startNode();
  13545. if (decorators.length) {
  13546. member.decorators = decorators;
  13547. this.resetStartLocationFromNode(member, decorators[0]);
  13548. decorators = [];
  13549. }
  13550. this.parseClassMember(classBody, member, state);
  13551. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13552. this.raise(Errors.DecoratorConstructor, member);
  13553. }
  13554. }
  13555. });
  13556. this.state.strict = oldStrict;
  13557. this.next();
  13558. if (decorators.length) {
  13559. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13560. }
  13561. this.classScope.exit();
  13562. return this.finishNode(classBody, "ClassBody");
  13563. }
  13564. parseClassMemberFromModifier(classBody, member) {
  13565. const key = this.parseIdentifier(true);
  13566. if (this.isClassMethod()) {
  13567. const method = member;
  13568. method.kind = "method";
  13569. method.computed = false;
  13570. method.key = key;
  13571. method.static = false;
  13572. this.pushClassMethod(classBody, method, false, false, false, false);
  13573. return true;
  13574. } else if (this.isClassProperty()) {
  13575. const prop = member;
  13576. prop.computed = false;
  13577. prop.key = key;
  13578. prop.static = false;
  13579. classBody.body.push(this.parseClassProperty(prop));
  13580. return true;
  13581. }
  13582. this.resetPreviousNodeTrailingComments(key);
  13583. return false;
  13584. }
  13585. parseClassMember(classBody, member, state) {
  13586. const isStatic = this.isContextual(106);
  13587. if (isStatic) {
  13588. if (this.parseClassMemberFromModifier(classBody, member)) {
  13589. return;
  13590. }
  13591. if (this.eat(5)) {
  13592. this.parseClassStaticBlock(classBody, member);
  13593. return;
  13594. }
  13595. }
  13596. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13597. }
  13598. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13599. const publicMethod = member;
  13600. const privateMethod = member;
  13601. const publicProp = member;
  13602. const privateProp = member;
  13603. const accessorProp = member;
  13604. const method = publicMethod;
  13605. const publicMember = publicMethod;
  13606. member.static = isStatic;
  13607. this.parsePropertyNamePrefixOperator(member);
  13608. if (this.eat(55)) {
  13609. method.kind = "method";
  13610. const isPrivateName = this.match(139);
  13611. this.parseClassElementName(method);
  13612. this.parsePostMemberNameModifiers(method);
  13613. if (isPrivateName) {
  13614. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13615. return;
  13616. }
  13617. if (this.isNonstaticConstructor(publicMethod)) {
  13618. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13619. }
  13620. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13621. return;
  13622. }
  13623. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13624. const key = this.parseClassElementName(member);
  13625. const maybeContextualKw = isContextual ? key.name : null;
  13626. const isPrivate = this.isPrivateName(key);
  13627. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13628. this.parsePostMemberNameModifiers(publicMember);
  13629. if (this.isClassMethod()) {
  13630. method.kind = "method";
  13631. if (isPrivate) {
  13632. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13633. return;
  13634. }
  13635. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13636. let allowsDirectSuper = false;
  13637. if (isConstructor) {
  13638. publicMethod.kind = "constructor";
  13639. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13640. this.raise(Errors.DuplicateConstructor, key);
  13641. }
  13642. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13643. this.raise(Errors.OverrideOnConstructor, key);
  13644. }
  13645. state.hadConstructor = true;
  13646. allowsDirectSuper = state.hadSuperClass;
  13647. }
  13648. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13649. } else if (this.isClassProperty()) {
  13650. if (isPrivate) {
  13651. this.pushClassPrivateProperty(classBody, privateProp);
  13652. } else {
  13653. this.pushClassProperty(classBody, publicProp);
  13654. }
  13655. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13656. this.resetPreviousNodeTrailingComments(key);
  13657. const isGenerator = this.eat(55);
  13658. if (publicMember.optional) {
  13659. this.unexpected(maybeQuestionTokenStartLoc);
  13660. }
  13661. method.kind = "method";
  13662. const isPrivate = this.match(139);
  13663. this.parseClassElementName(method);
  13664. this.parsePostMemberNameModifiers(publicMember);
  13665. if (isPrivate) {
  13666. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13667. } else {
  13668. if (this.isNonstaticConstructor(publicMethod)) {
  13669. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13670. }
  13671. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13672. }
  13673. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13674. this.resetPreviousNodeTrailingComments(key);
  13675. method.kind = maybeContextualKw;
  13676. const isPrivate = this.match(139);
  13677. this.parseClassElementName(publicMethod);
  13678. if (isPrivate) {
  13679. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13680. } else {
  13681. if (this.isNonstaticConstructor(publicMethod)) {
  13682. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13683. }
  13684. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13685. }
  13686. this.checkGetterSetterParams(publicMethod);
  13687. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13688. this.expectPlugin("decoratorAutoAccessors");
  13689. this.resetPreviousNodeTrailingComments(key);
  13690. const isPrivate = this.match(139);
  13691. this.parseClassElementName(publicProp);
  13692. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13693. } else if (this.isLineTerminator()) {
  13694. if (isPrivate) {
  13695. this.pushClassPrivateProperty(classBody, privateProp);
  13696. } else {
  13697. this.pushClassProperty(classBody, publicProp);
  13698. }
  13699. } else {
  13700. this.unexpected();
  13701. }
  13702. }
  13703. parseClassElementName(member) {
  13704. const {
  13705. type,
  13706. value
  13707. } = this.state;
  13708. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  13709. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13710. }
  13711. if (type === 139) {
  13712. if (value === "constructor") {
  13713. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13714. }
  13715. const key = this.parsePrivateName();
  13716. member.key = key;
  13717. return key;
  13718. }
  13719. this.parsePropertyName(member);
  13720. return member.key;
  13721. }
  13722. parseClassStaticBlock(classBody, member) {
  13723. var _member$decorators;
  13724. this.scope.enter(576 | 128 | 16);
  13725. const oldLabels = this.state.labels;
  13726. this.state.labels = [];
  13727. this.prodParam.enter(0);
  13728. const body = member.body = [];
  13729. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13730. this.prodParam.exit();
  13731. this.scope.exit();
  13732. this.state.labels = oldLabels;
  13733. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13734. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13735. this.raise(Errors.DecoratorStaticBlock, member);
  13736. }
  13737. }
  13738. pushClassProperty(classBody, prop) {
  13739. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13740. this.raise(Errors.ConstructorClassField, prop.key);
  13741. }
  13742. classBody.body.push(this.parseClassProperty(prop));
  13743. }
  13744. pushClassPrivateProperty(classBody, prop) {
  13745. const node = this.parseClassPrivateProperty(prop);
  13746. classBody.body.push(node);
  13747. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13748. }
  13749. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13750. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13751. this.raise(Errors.ConstructorClassField, prop.key);
  13752. }
  13753. const node = this.parseClassAccessorProperty(prop);
  13754. classBody.body.push(node);
  13755. if (isPrivate) {
  13756. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13757. }
  13758. }
  13759. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13760. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13761. }
  13762. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13763. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13764. classBody.body.push(node);
  13765. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13766. this.declareClassPrivateMethodInScope(node, kind);
  13767. }
  13768. declareClassPrivateMethodInScope(node, kind) {
  13769. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13770. }
  13771. parsePostMemberNameModifiers(methodOrProp) {}
  13772. parseClassPrivateProperty(node) {
  13773. this.parseInitializer(node);
  13774. this.semicolon();
  13775. return this.finishNode(node, "ClassPrivateProperty");
  13776. }
  13777. parseClassProperty(node) {
  13778. this.parseInitializer(node);
  13779. this.semicolon();
  13780. return this.finishNode(node, "ClassProperty");
  13781. }
  13782. parseClassAccessorProperty(node) {
  13783. this.parseInitializer(node);
  13784. this.semicolon();
  13785. return this.finishNode(node, "ClassAccessorProperty");
  13786. }
  13787. parseInitializer(node) {
  13788. this.scope.enter(576 | 16);
  13789. this.expressionScope.enter(newExpressionScope());
  13790. this.prodParam.enter(0);
  13791. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13792. this.expressionScope.exit();
  13793. this.prodParam.exit();
  13794. this.scope.exit();
  13795. }
  13796. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13797. if (tokenIsIdentifier(this.state.type)) {
  13798. node.id = this.parseIdentifier();
  13799. if (isStatement) {
  13800. this.declareNameFromIdentifier(node.id, bindingType);
  13801. }
  13802. } else {
  13803. if (optionalId || !isStatement) {
  13804. node.id = null;
  13805. } else {
  13806. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13807. }
  13808. }
  13809. }
  13810. parseClassSuper(node) {
  13811. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13812. }
  13813. parseExport(node, decorators) {
  13814. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13815. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13816. const parseAfterDefault = !hasDefault || this.eat(12);
  13817. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13818. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13819. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13820. const isFromRequired = hasDefault || hasStar;
  13821. if (hasStar && !hasNamespace) {
  13822. if (hasDefault) this.unexpected();
  13823. if (decorators) {
  13824. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13825. }
  13826. this.parseExportFrom(node, true);
  13827. this.sawUnambiguousESM = true;
  13828. return this.finishNode(node, "ExportAllDeclaration");
  13829. }
  13830. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13831. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13832. this.unexpected(null, 5);
  13833. }
  13834. if (hasNamespace && parseAfterNamespace) {
  13835. this.unexpected(null, 98);
  13836. }
  13837. let hasDeclaration;
  13838. if (isFromRequired || hasSpecifiers) {
  13839. hasDeclaration = false;
  13840. if (decorators) {
  13841. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13842. }
  13843. this.parseExportFrom(node, isFromRequired);
  13844. } else {
  13845. hasDeclaration = this.maybeParseExportDeclaration(node);
  13846. }
  13847. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13848. var _node2$declaration;
  13849. const node2 = node;
  13850. this.checkExport(node2, true, false, !!node2.source);
  13851. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13852. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13853. } else if (decorators) {
  13854. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13855. }
  13856. this.sawUnambiguousESM = true;
  13857. return this.finishNode(node2, "ExportNamedDeclaration");
  13858. }
  13859. if (this.eat(65)) {
  13860. const node2 = node;
  13861. const decl = this.parseExportDefaultExpression();
  13862. node2.declaration = decl;
  13863. if (decl.type === "ClassDeclaration") {
  13864. this.maybeTakeDecorators(decorators, decl, node2);
  13865. } else if (decorators) {
  13866. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13867. }
  13868. this.checkExport(node2, true, true);
  13869. this.sawUnambiguousESM = true;
  13870. return this.finishNode(node2, "ExportDefaultDeclaration");
  13871. }
  13872. throw this.unexpected(null, 5);
  13873. }
  13874. eatExportStar(node) {
  13875. return this.eat(55);
  13876. }
  13877. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13878. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13879. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13880. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13881. const specifier = this.startNodeAtNode(id);
  13882. specifier.exported = id;
  13883. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13884. return true;
  13885. }
  13886. return false;
  13887. }
  13888. maybeParseExportNamespaceSpecifier(node) {
  13889. if (this.isContextual(93)) {
  13890. var _ref, _ref$specifiers;
  13891. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13892. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13893. this.next();
  13894. specifier.exported = this.parseModuleExportName();
  13895. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13896. return true;
  13897. }
  13898. return false;
  13899. }
  13900. maybeParseExportNamedSpecifiers(node) {
  13901. if (this.match(5)) {
  13902. const node2 = node;
  13903. if (!node2.specifiers) node2.specifiers = [];
  13904. const isTypeExport = node2.exportKind === "type";
  13905. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13906. node2.source = null;
  13907. if (this.hasPlugin("importAssertions")) {
  13908. node2.assertions = [];
  13909. } else {
  13910. node2.attributes = [];
  13911. }
  13912. node2.declaration = null;
  13913. return true;
  13914. }
  13915. return false;
  13916. }
  13917. maybeParseExportDeclaration(node) {
  13918. if (this.shouldParseExportDeclaration()) {
  13919. node.specifiers = [];
  13920. node.source = null;
  13921. if (this.hasPlugin("importAssertions")) {
  13922. node.assertions = [];
  13923. } else {
  13924. node.attributes = [];
  13925. }
  13926. node.declaration = this.parseExportDeclaration(node);
  13927. return true;
  13928. }
  13929. return false;
  13930. }
  13931. isAsyncFunction() {
  13932. if (!this.isContextual(95)) return false;
  13933. const next = this.nextTokenInLineStart();
  13934. return this.isUnparsedContextual(next, "function");
  13935. }
  13936. parseExportDefaultExpression() {
  13937. const expr = this.startNode();
  13938. if (this.match(68)) {
  13939. this.next();
  13940. return this.parseFunction(expr, 1 | 4);
  13941. } else if (this.isAsyncFunction()) {
  13942. this.next();
  13943. this.next();
  13944. return this.parseFunction(expr, 1 | 4 | 8);
  13945. }
  13946. if (this.match(80)) {
  13947. return this.parseClass(expr, true, true);
  13948. }
  13949. if (this.match(26)) {
  13950. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13951. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13952. }
  13953. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13954. }
  13955. if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
  13956. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13957. }
  13958. const res = this.parseMaybeAssignAllowIn();
  13959. this.semicolon();
  13960. return res;
  13961. }
  13962. parseExportDeclaration(node) {
  13963. if (this.match(80)) {
  13964. const node = this.parseClass(this.startNode(), true, false);
  13965. return node;
  13966. }
  13967. return this.parseStatementListItem();
  13968. }
  13969. isExportDefaultSpecifier() {
  13970. const {
  13971. type
  13972. } = this.state;
  13973. if (tokenIsIdentifier(type)) {
  13974. if (type === 95 && !this.state.containsEsc || type === 100) {
  13975. return false;
  13976. }
  13977. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13978. const next = this.nextTokenStart();
  13979. const nextChar = this.input.charCodeAt(next);
  13980. if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
  13981. this.expectOnePlugin(["flow", "typescript"]);
  13982. return false;
  13983. }
  13984. }
  13985. } else if (!this.match(65)) {
  13986. return false;
  13987. }
  13988. const next = this.nextTokenStart();
  13989. const hasFrom = this.isUnparsedContextual(next, "from");
  13990. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13991. return true;
  13992. }
  13993. if (this.match(65) && hasFrom) {
  13994. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13995. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13996. }
  13997. return false;
  13998. }
  13999. parseExportFrom(node, expect) {
  14000. if (this.eatContextual(98)) {
  14001. node.source = this.parseImportSource();
  14002. this.checkExport(node);
  14003. this.maybeParseImportAttributes(node);
  14004. this.checkJSONModuleImport(node);
  14005. } else if (expect) {
  14006. this.unexpected();
  14007. }
  14008. this.semicolon();
  14009. }
  14010. shouldParseExportDeclaration() {
  14011. const {
  14012. type
  14013. } = this.state;
  14014. if (type === 26) {
  14015. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  14016. if (this.hasPlugin("decorators")) {
  14017. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  14018. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  14019. }
  14020. return true;
  14021. }
  14022. }
  14023. if (this.isUsing()) {
  14024. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  14025. return true;
  14026. }
  14027. if (this.isAwaitUsing()) {
  14028. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  14029. return true;
  14030. }
  14031. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  14032. }
  14033. checkExport(node, checkNames, isDefault, isFrom) {
  14034. if (checkNames) {
  14035. var _node$specifiers;
  14036. if (isDefault) {
  14037. this.checkDuplicateExports(node, "default");
  14038. if (this.hasPlugin("exportDefaultFrom")) {
  14039. var _declaration$extra;
  14040. const declaration = node.declaration;
  14041. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  14042. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  14043. }
  14044. }
  14045. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  14046. for (const specifier of node.specifiers) {
  14047. const {
  14048. exported
  14049. } = specifier;
  14050. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  14051. this.checkDuplicateExports(specifier, exportName);
  14052. if (!isFrom && specifier.local) {
  14053. const {
  14054. local
  14055. } = specifier;
  14056. if (local.type !== "Identifier") {
  14057. this.raise(Errors.ExportBindingIsString, specifier, {
  14058. localName: local.value,
  14059. exportName
  14060. });
  14061. } else {
  14062. this.checkReservedWord(local.name, local.loc.start, true, false);
  14063. this.scope.checkLocalExport(local);
  14064. }
  14065. }
  14066. }
  14067. } else if (node.declaration) {
  14068. const decl = node.declaration;
  14069. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  14070. const {
  14071. id
  14072. } = decl;
  14073. if (!id) throw new Error("Assertion failure");
  14074. this.checkDuplicateExports(node, id.name);
  14075. } else if (decl.type === "VariableDeclaration") {
  14076. for (const declaration of decl.declarations) {
  14077. this.checkDeclaration(declaration.id);
  14078. }
  14079. }
  14080. }
  14081. }
  14082. }
  14083. checkDeclaration(node) {
  14084. if (node.type === "Identifier") {
  14085. this.checkDuplicateExports(node, node.name);
  14086. } else if (node.type === "ObjectPattern") {
  14087. for (const prop of node.properties) {
  14088. this.checkDeclaration(prop);
  14089. }
  14090. } else if (node.type === "ArrayPattern") {
  14091. for (const elem of node.elements) {
  14092. if (elem) {
  14093. this.checkDeclaration(elem);
  14094. }
  14095. }
  14096. } else if (node.type === "ObjectProperty") {
  14097. this.checkDeclaration(node.value);
  14098. } else if (node.type === "RestElement") {
  14099. this.checkDeclaration(node.argument);
  14100. } else if (node.type === "AssignmentPattern") {
  14101. this.checkDeclaration(node.left);
  14102. }
  14103. }
  14104. checkDuplicateExports(node, exportName) {
  14105. if (this.exportedIdentifiers.has(exportName)) {
  14106. if (exportName === "default") {
  14107. this.raise(Errors.DuplicateDefaultExport, node);
  14108. } else {
  14109. this.raise(Errors.DuplicateExport, node, {
  14110. exportName
  14111. });
  14112. }
  14113. }
  14114. this.exportedIdentifiers.add(exportName);
  14115. }
  14116. parseExportSpecifiers(isInTypeExport) {
  14117. const nodes = [];
  14118. let first = true;
  14119. this.expect(5);
  14120. while (!this.eat(8)) {
  14121. if (first) {
  14122. first = false;
  14123. } else {
  14124. this.expect(12);
  14125. if (this.eat(8)) break;
  14126. }
  14127. const isMaybeTypeOnly = this.isContextual(130);
  14128. const isString = this.match(134);
  14129. const node = this.startNode();
  14130. node.local = this.parseModuleExportName();
  14131. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  14132. }
  14133. return nodes;
  14134. }
  14135. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14136. if (this.eatContextual(93)) {
  14137. node.exported = this.parseModuleExportName();
  14138. } else if (isString) {
  14139. node.exported = this.cloneStringLiteral(node.local);
  14140. } else if (!node.exported) {
  14141. node.exported = this.cloneIdentifier(node.local);
  14142. }
  14143. return this.finishNode(node, "ExportSpecifier");
  14144. }
  14145. parseModuleExportName() {
  14146. if (this.match(134)) {
  14147. const result = this.parseStringLiteral(this.state.value);
  14148. const surrogate = loneSurrogate.exec(result.value);
  14149. if (surrogate) {
  14150. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  14151. surrogateCharCode: surrogate[0].charCodeAt(0)
  14152. });
  14153. }
  14154. return result;
  14155. }
  14156. return this.parseIdentifier(true);
  14157. }
  14158. isJSONModuleImport(node) {
  14159. if (node.assertions != null) {
  14160. return node.assertions.some(({
  14161. key,
  14162. value
  14163. }) => {
  14164. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14165. });
  14166. }
  14167. return false;
  14168. }
  14169. checkImportReflection(node) {
  14170. const {
  14171. specifiers
  14172. } = node;
  14173. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  14174. if (node.phase === "source") {
  14175. if (singleBindingType !== "ImportDefaultSpecifier") {
  14176. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  14177. }
  14178. } else if (node.phase === "defer") {
  14179. if (singleBindingType !== "ImportNamespaceSpecifier") {
  14180. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  14181. }
  14182. } else if (node.module) {
  14183. var _node$assertions;
  14184. if (singleBindingType !== "ImportDefaultSpecifier") {
  14185. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  14186. }
  14187. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14188. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  14189. }
  14190. }
  14191. }
  14192. checkJSONModuleImport(node) {
  14193. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14194. const {
  14195. specifiers
  14196. } = node;
  14197. if (specifiers != null) {
  14198. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14199. let imported;
  14200. if (specifier.type === "ExportSpecifier") {
  14201. imported = specifier.local;
  14202. } else if (specifier.type === "ImportSpecifier") {
  14203. imported = specifier.imported;
  14204. }
  14205. if (imported !== undefined) {
  14206. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14207. }
  14208. });
  14209. if (nonDefaultNamedSpecifier !== undefined) {
  14210. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  14211. }
  14212. }
  14213. }
  14214. }
  14215. isPotentialImportPhase(isExport) {
  14216. if (isExport) return false;
  14217. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  14218. }
  14219. applyImportPhase(node, isExport, phase, loc) {
  14220. if (isExport) {
  14221. return;
  14222. }
  14223. if (phase === "module") {
  14224. this.expectPlugin("importReflection", loc);
  14225. node.module = true;
  14226. } else if (this.hasPlugin("importReflection")) {
  14227. node.module = false;
  14228. }
  14229. if (phase === "source") {
  14230. this.expectPlugin("sourcePhaseImports", loc);
  14231. node.phase = "source";
  14232. } else if (phase === "defer") {
  14233. this.expectPlugin("deferredImportEvaluation", loc);
  14234. node.phase = "defer";
  14235. } else if (this.hasPlugin("sourcePhaseImports")) {
  14236. node.phase = null;
  14237. }
  14238. }
  14239. parseMaybeImportPhase(node, isExport) {
  14240. if (!this.isPotentialImportPhase(isExport)) {
  14241. this.applyImportPhase(node, isExport, null);
  14242. return null;
  14243. }
  14244. const phaseIdentifier = this.startNode();
  14245. const phaseIdentifierName = this.parseIdentifierName(true);
  14246. const {
  14247. type
  14248. } = this.state;
  14249. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14250. if (isImportPhase) {
  14251. this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
  14252. return null;
  14253. } else {
  14254. this.applyImportPhase(node, isExport, null);
  14255. return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
  14256. }
  14257. }
  14258. isPrecedingIdImportPhase(phase) {
  14259. const {
  14260. type
  14261. } = this.state;
  14262. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14263. }
  14264. parseImport(node) {
  14265. if (this.match(134)) {
  14266. return this.parseImportSourceAndAttributes(node);
  14267. }
  14268. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14269. }
  14270. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14271. node.specifiers = [];
  14272. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14273. const parseNext = !hasDefault || this.eat(12);
  14274. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14275. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14276. this.expectContextual(98);
  14277. return this.parseImportSourceAndAttributes(node);
  14278. }
  14279. parseImportSourceAndAttributes(node) {
  14280. var _node$specifiers2;
  14281. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14282. node.source = this.parseImportSource();
  14283. this.maybeParseImportAttributes(node);
  14284. this.checkImportReflection(node);
  14285. this.checkJSONModuleImport(node);
  14286. this.semicolon();
  14287. this.sawUnambiguousESM = true;
  14288. return this.finishNode(node, "ImportDeclaration");
  14289. }
  14290. parseImportSource() {
  14291. if (!this.match(134)) this.unexpected();
  14292. return this.parseExprAtom();
  14293. }
  14294. parseImportSpecifierLocal(node, specifier, type) {
  14295. specifier.local = this.parseIdentifier();
  14296. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14297. }
  14298. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14299. this.checkLVal(specifier.local, {
  14300. type
  14301. }, bindingType);
  14302. return this.finishNode(specifier, type);
  14303. }
  14304. parseImportAttributes() {
  14305. this.expect(5);
  14306. const attrs = [];
  14307. const attrNames = new Set();
  14308. do {
  14309. if (this.match(8)) {
  14310. break;
  14311. }
  14312. const node = this.startNode();
  14313. const keyName = this.state.value;
  14314. if (attrNames.has(keyName)) {
  14315. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  14316. key: keyName
  14317. });
  14318. }
  14319. attrNames.add(keyName);
  14320. if (this.match(134)) {
  14321. node.key = this.parseStringLiteral(keyName);
  14322. } else {
  14323. node.key = this.parseIdentifier(true);
  14324. }
  14325. this.expect(14);
  14326. if (!this.match(134)) {
  14327. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14328. }
  14329. node.value = this.parseStringLiteral(this.state.value);
  14330. attrs.push(this.finishNode(node, "ImportAttribute"));
  14331. } while (this.eat(12));
  14332. this.expect(8);
  14333. return attrs;
  14334. }
  14335. parseModuleAttributes() {
  14336. const attrs = [];
  14337. const attributes = new Set();
  14338. do {
  14339. const node = this.startNode();
  14340. node.key = this.parseIdentifier(true);
  14341. if (node.key.name !== "type") {
  14342. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  14343. }
  14344. if (attributes.has(node.key.name)) {
  14345. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  14346. key: node.key.name
  14347. });
  14348. }
  14349. attributes.add(node.key.name);
  14350. this.expect(14);
  14351. if (!this.match(134)) {
  14352. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14353. }
  14354. node.value = this.parseStringLiteral(this.state.value);
  14355. attrs.push(this.finishNode(node, "ImportAttribute"));
  14356. } while (this.eat(12));
  14357. return attrs;
  14358. }
  14359. maybeParseImportAttributes(node) {
  14360. let attributes;
  14361. var useWith = false;
  14362. if (this.match(76)) {
  14363. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14364. return;
  14365. }
  14366. this.next();
  14367. if (this.hasPlugin("moduleAttributes")) {
  14368. attributes = this.parseModuleAttributes();
  14369. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  14370. } else {
  14371. attributes = this.parseImportAttributes();
  14372. }
  14373. useWith = true;
  14374. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14375. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  14376. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  14377. }
  14378. if (!this.hasPlugin("importAssertions")) {
  14379. this.addExtra(node, "deprecatedAssertSyntax", true);
  14380. }
  14381. this.next();
  14382. attributes = this.parseImportAttributes();
  14383. } else {
  14384. attributes = [];
  14385. }
  14386. if (!useWith && this.hasPlugin("importAssertions")) {
  14387. node.assertions = attributes;
  14388. } else {
  14389. node.attributes = attributes;
  14390. }
  14391. }
  14392. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14393. if (maybeDefaultIdentifier) {
  14394. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14395. specifier.local = maybeDefaultIdentifier;
  14396. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14397. return true;
  14398. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14399. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14400. return true;
  14401. }
  14402. return false;
  14403. }
  14404. maybeParseStarImportSpecifier(node) {
  14405. if (this.match(55)) {
  14406. const specifier = this.startNode();
  14407. this.next();
  14408. this.expectContextual(93);
  14409. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14410. return true;
  14411. }
  14412. return false;
  14413. }
  14414. parseNamedImportSpecifiers(node) {
  14415. let first = true;
  14416. this.expect(5);
  14417. while (!this.eat(8)) {
  14418. if (first) {
  14419. first = false;
  14420. } else {
  14421. if (this.eat(14)) {
  14422. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  14423. }
  14424. this.expect(12);
  14425. if (this.eat(8)) break;
  14426. }
  14427. const specifier = this.startNode();
  14428. const importedIsString = this.match(134);
  14429. const isMaybeTypeOnly = this.isContextual(130);
  14430. specifier.imported = this.parseModuleExportName();
  14431. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14432. node.specifiers.push(importSpecifier);
  14433. }
  14434. }
  14435. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14436. if (this.eatContextual(93)) {
  14437. specifier.local = this.parseIdentifier();
  14438. } else {
  14439. const {
  14440. imported
  14441. } = specifier;
  14442. if (importedIsString) {
  14443. throw this.raise(Errors.ImportBindingIsString, specifier, {
  14444. importName: imported.value
  14445. });
  14446. }
  14447. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14448. if (!specifier.local) {
  14449. specifier.local = this.cloneIdentifier(imported);
  14450. }
  14451. }
  14452. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14453. }
  14454. isThisParam(param) {
  14455. return param.type === "Identifier" && param.name === "this";
  14456. }
  14457. }
  14458. class Parser extends StatementParser {
  14459. constructor(options, input, pluginsMap) {
  14460. const normalizedOptions = getOptions(options);
  14461. super(normalizedOptions, input);
  14462. this.options = normalizedOptions;
  14463. this.initializeScopes();
  14464. this.plugins = pluginsMap;
  14465. this.filename = normalizedOptions.sourceFilename;
  14466. this.startIndex = normalizedOptions.startIndex;
  14467. let optionFlags = 0;
  14468. if (normalizedOptions.allowAwaitOutsideFunction) {
  14469. optionFlags |= 1;
  14470. }
  14471. if (normalizedOptions.allowReturnOutsideFunction) {
  14472. optionFlags |= 2;
  14473. }
  14474. if (normalizedOptions.allowImportExportEverywhere) {
  14475. optionFlags |= 8;
  14476. }
  14477. if (normalizedOptions.allowSuperOutsideMethod) {
  14478. optionFlags |= 16;
  14479. }
  14480. if (normalizedOptions.allowUndeclaredExports) {
  14481. optionFlags |= 64;
  14482. }
  14483. if (normalizedOptions.allowNewTargetOutsideFunction) {
  14484. optionFlags |= 4;
  14485. }
  14486. if (normalizedOptions.allowYieldOutsideFunction) {
  14487. optionFlags |= 32;
  14488. }
  14489. if (normalizedOptions.ranges) {
  14490. optionFlags |= 128;
  14491. }
  14492. if (normalizedOptions.tokens) {
  14493. optionFlags |= 256;
  14494. }
  14495. if (normalizedOptions.createImportExpressions) {
  14496. optionFlags |= 512;
  14497. }
  14498. if (normalizedOptions.createParenthesizedExpressions) {
  14499. optionFlags |= 1024;
  14500. }
  14501. if (normalizedOptions.errorRecovery) {
  14502. optionFlags |= 2048;
  14503. }
  14504. if (normalizedOptions.attachComment) {
  14505. optionFlags |= 4096;
  14506. }
  14507. if (normalizedOptions.annexB) {
  14508. optionFlags |= 8192;
  14509. }
  14510. this.optionFlags = optionFlags;
  14511. }
  14512. getScopeHandler() {
  14513. return ScopeHandler;
  14514. }
  14515. parse() {
  14516. this.enterInitialScopes();
  14517. const file = this.startNode();
  14518. const program = this.startNode();
  14519. this.nextToken();
  14520. file.errors = null;
  14521. const result = this.parseTopLevel(file, program);
  14522. result.errors = this.state.errors;
  14523. result.comments.length = this.state.commentsLen;
  14524. return result;
  14525. }
  14526. }
  14527. function parse(input, options) {
  14528. var _options;
  14529. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14530. options = Object.assign({}, options);
  14531. try {
  14532. options.sourceType = "module";
  14533. const parser = getParser(options, input);
  14534. const ast = parser.parse();
  14535. if (parser.sawUnambiguousESM) {
  14536. return ast;
  14537. }
  14538. if (parser.ambiguousScriptDifferentAst) {
  14539. try {
  14540. options.sourceType = "script";
  14541. return getParser(options, input).parse();
  14542. } catch (_unused) {}
  14543. } else {
  14544. ast.program.sourceType = "script";
  14545. }
  14546. return ast;
  14547. } catch (moduleError) {
  14548. try {
  14549. options.sourceType = "script";
  14550. return getParser(options, input).parse();
  14551. } catch (_unused2) {}
  14552. throw moduleError;
  14553. }
  14554. } else {
  14555. return getParser(options, input).parse();
  14556. }
  14557. }
  14558. function parseExpression(input, options) {
  14559. const parser = getParser(options, input);
  14560. if (parser.options.strictMode) {
  14561. parser.state.strict = true;
  14562. }
  14563. return parser.getExpression();
  14564. }
  14565. function generateExportedTokenTypes(internalTokenTypes) {
  14566. const tokenTypes = {};
  14567. for (const typeName of Object.keys(internalTokenTypes)) {
  14568. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14569. }
  14570. return tokenTypes;
  14571. }
  14572. const tokTypes = generateExportedTokenTypes(tt);
  14573. function getParser(options, input) {
  14574. let cls = Parser;
  14575. const pluginsMap = new Map();
  14576. if (options != null && options.plugins) {
  14577. for (const plugin of options.plugins) {
  14578. let name, opts;
  14579. if (typeof plugin === "string") {
  14580. name = plugin;
  14581. } else {
  14582. [name, opts] = plugin;
  14583. }
  14584. if (!pluginsMap.has(name)) {
  14585. pluginsMap.set(name, opts || {});
  14586. }
  14587. }
  14588. validatePlugins(pluginsMap);
  14589. cls = getParserClass(pluginsMap);
  14590. }
  14591. return new cls(options, input, pluginsMap);
  14592. }
  14593. const parserClassCache = new Map();
  14594. function getParserClass(pluginsMap) {
  14595. const pluginList = [];
  14596. for (const name of mixinPluginNames) {
  14597. if (pluginsMap.has(name)) {
  14598. pluginList.push(name);
  14599. }
  14600. }
  14601. const key = pluginList.join("|");
  14602. let cls = parserClassCache.get(key);
  14603. if (!cls) {
  14604. cls = Parser;
  14605. for (const plugin of pluginList) {
  14606. cls = mixinPlugins[plugin](cls);
  14607. }
  14608. parserClassCache.set(key, cls);
  14609. }
  14610. return cls;
  14611. }
  14612. exports.parse = parse;
  14613. exports.parseExpression = parseExpression;
  14614. exports.tokTypes = tokTypes;
  14615. //# sourceMappingURL=index.js.map