index.js 478 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. function _objectWithoutPropertiesLoose(source, excluded) {
  6. if (source == null) return {};
  7. var target = {};
  8. var sourceKeys = Object.keys(source);
  9. var key, i;
  10. for (i = 0; i < sourceKeys.length; i++) {
  11. key = sourceKeys[i];
  12. if (excluded.indexOf(key) >= 0) continue;
  13. target[key] = source[key];
  14. }
  15. return target;
  16. }
  17. class Position {
  18. constructor(line, col, index) {
  19. this.line = void 0;
  20. this.column = void 0;
  21. this.index = void 0;
  22. this.line = line;
  23. this.column = col;
  24. this.index = index;
  25. }
  26. }
  27. class SourceLocation {
  28. constructor(start, end) {
  29. this.start = void 0;
  30. this.end = void 0;
  31. this.filename = void 0;
  32. this.identifierName = void 0;
  33. this.start = start;
  34. this.end = end;
  35. }
  36. }
  37. function createPositionWithColumnOffset(position, columnOffset) {
  38. const {
  39. line,
  40. column,
  41. index
  42. } = position;
  43. return new Position(line, column + columnOffset, index + columnOffset);
  44. }
  45. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  46. var ModuleErrors = {
  47. ImportMetaOutsideModule: {
  48. message: `import.meta may appear only with 'sourceType: "module"'`,
  49. code
  50. },
  51. ImportOutsideModule: {
  52. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  53. code
  54. }
  55. };
  56. const NodeDescriptions = {
  57. ArrayPattern: "array destructuring pattern",
  58. AssignmentExpression: "assignment expression",
  59. AssignmentPattern: "assignment expression",
  60. ArrowFunctionExpression: "arrow function expression",
  61. ConditionalExpression: "conditional expression",
  62. CatchClause: "catch clause",
  63. ForOfStatement: "for-of statement",
  64. ForInStatement: "for-in statement",
  65. ForStatement: "for-loop",
  66. FormalParameters: "function parameter list",
  67. Identifier: "identifier",
  68. ImportSpecifier: "import specifier",
  69. ImportDefaultSpecifier: "import default specifier",
  70. ImportNamespaceSpecifier: "import namespace specifier",
  71. ObjectPattern: "object destructuring pattern",
  72. ParenthesizedExpression: "parenthesized expression",
  73. RestElement: "rest element",
  74. UpdateExpression: {
  75. true: "prefix operation",
  76. false: "postfix operation"
  77. },
  78. VariableDeclarator: "variable declaration",
  79. YieldExpression: "yield expression"
  80. };
  81. const toNodeDescription = ({
  82. type,
  83. prefix
  84. }) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
  85. var StandardErrors = {
  86. AccessorIsGenerator: ({
  87. kind
  88. }) => `A ${kind}ter cannot be a generator.`,
  89. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  90. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  91. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  92. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  93. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  94. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  95. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  96. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  97. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  98. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  99. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  100. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  101. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  102. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  103. ConstructorIsAsync: "Constructor can't be an async function.",
  104. ConstructorIsGenerator: "Constructor can't be a generator.",
  105. DeclarationMissingInitializer: ({
  106. kind
  107. }) => `Missing initializer in ${kind} declaration.`,
  108. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  109. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  110. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  111. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  112. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  113. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  114. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  115. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  116. DeletePrivateField: "Deleting a private field is not allowed.",
  117. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  118. DuplicateConstructor: "Duplicate constructor in the same class.",
  119. DuplicateDefaultExport: "Only one default export allowed per module.",
  120. DuplicateExport: ({
  121. exportName
  122. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  123. DuplicateProto: "Redefinition of __proto__ property.",
  124. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  125. DynamicImportPhaseRequiresImportExpressions: ({
  126. phase
  127. }) => `'import.${phase}(...)' can only be parsed when using the 'createImportExpressions' option.`,
  128. ElementAfterRest: "Rest element must be last element.",
  129. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  130. ExportBindingIsString: ({
  131. localName,
  132. exportName
  133. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  134. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  135. ForInOfLoopInitializer: ({
  136. type
  137. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  138. ForInUsing: "For-in loop may not start with 'using' declaration.",
  139. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  140. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  141. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  142. IllegalBreakContinue: ({
  143. type
  144. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  145. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  146. IllegalReturn: "'return' outside of function.",
  147. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedAssertSyntax: true` option in the import attributes plugin to suppress this error.",
  148. ImportBindingIsString: ({
  149. importName
  150. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  151. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  152. ImportCallArity: ({
  153. maxArgumentCount
  154. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
  155. ImportCallNotNewExpression: "Cannot use new with import(...).",
  156. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  157. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  158. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  159. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  160. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  161. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  162. InvalidCodePoint: "Code point out of bounds.",
  163. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  164. InvalidDecimal: "Invalid decimal.",
  165. InvalidDigit: ({
  166. radix
  167. }) => `Expected number in radix ${radix}.`,
  168. InvalidEscapeSequence: "Bad character escape sequence.",
  169. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  170. InvalidEscapedReservedWord: ({
  171. reservedWord
  172. }) => `Escape sequence in keyword ${reservedWord}.`,
  173. InvalidIdentifier: ({
  174. identifierName
  175. }) => `Invalid identifier ${identifierName}.`,
  176. InvalidLhs: ({
  177. ancestor
  178. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  179. InvalidLhsBinding: ({
  180. ancestor
  181. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  182. InvalidLhsOptionalChaining: ({
  183. ancestor
  184. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  185. InvalidNumber: "Invalid number.",
  186. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  187. InvalidOrUnexpectedToken: ({
  188. unexpected
  189. }) => `Unexpected character '${unexpected}'.`,
  190. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  191. InvalidPrivateFieldResolution: ({
  192. identifierName
  193. }) => `Private name #${identifierName} is not defined.`,
  194. InvalidPropertyBindingPattern: "Binding member expression.",
  195. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  196. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  197. LabelRedeclaration: ({
  198. labelName
  199. }) => `Label '${labelName}' is already declared.`,
  200. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  201. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  202. MalformedRegExpFlags: "Invalid regular expression flag.",
  203. MissingClassName: "A class name is required.",
  204. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  205. MissingSemicolon: "Missing semicolon.",
  206. MissingPlugin: ({
  207. missingPlugin
  208. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  209. MissingOneOfPlugins: ({
  210. missingPlugin
  211. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  212. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  213. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  214. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  215. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  216. ModuleAttributesWithDuplicateKeys: ({
  217. key
  218. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  219. ModuleExportNameHasLoneSurrogate: ({
  220. surrogateCharCode
  221. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  222. ModuleExportUndefined: ({
  223. localName
  224. }) => `Export '${localName}' is not defined.`,
  225. MultipleDefaultsInSwitch: "Multiple default clauses.",
  226. NewlineAfterThrow: "Illegal newline after throw.",
  227. NoCatchOrFinally: "Missing catch or finally clause.",
  228. NumberIdentifier: "Identifier directly after number.",
  229. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  230. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  231. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  232. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  233. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  234. ParamDupe: "Argument name clash.",
  235. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  236. PatternHasMethod: "Object pattern can't contain methods.",
  237. PrivateInExpectedIn: ({
  238. identifierName
  239. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  240. PrivateNameRedeclaration: ({
  241. identifierName
  242. }) => `Duplicate private name #${identifierName}.`,
  243. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  244. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  245. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  246. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  247. RestTrailingComma: "Unexpected trailing comma after rest element.",
  248. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  249. 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.",
  250. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  251. StaticPrototype: "Classes may not have static property named prototype.",
  252. 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?",
  253. SuperPrivateField: "Private fields can't be accessed on super.",
  254. TrailingDecorator: "Decorators must be attached to a class element.",
  255. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  256. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  257. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  258. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  259. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  260. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  261. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  262. UnexpectedKeyword: ({
  263. keyword
  264. }) => `Unexpected keyword '${keyword}'.`,
  265. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  266. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  267. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  268. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  269. UnexpectedPrivateField: "Unexpected private name.",
  270. UnexpectedReservedWord: ({
  271. reservedWord
  272. }) => `Unexpected reserved word '${reservedWord}'.`,
  273. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  274. UnexpectedToken: ({
  275. expected,
  276. unexpected
  277. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  278. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  279. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  280. UnsupportedBind: "Binding should be performed on object property.",
  281. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  282. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  283. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  284. UnsupportedMetaProperty: ({
  285. target,
  286. onlyValidPropertyName
  287. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  288. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  289. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  290. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  291. UnterminatedComment: "Unterminated comment.",
  292. UnterminatedRegExp: "Unterminated regular expression.",
  293. UnterminatedString: "Unterminated string constant.",
  294. UnterminatedTemplate: "Unterminated template.",
  295. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  296. VarRedeclaration: ({
  297. identifierName
  298. }) => `Identifier '${identifierName}' has already been declared.`,
  299. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  300. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  301. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  302. };
  303. var StrictModeErrors = {
  304. StrictDelete: "Deleting local variable in strict mode.",
  305. StrictEvalArguments: ({
  306. referenceName
  307. }) => `Assigning to '${referenceName}' in strict mode.`,
  308. StrictEvalArgumentsBinding: ({
  309. bindingName
  310. }) => `Binding '${bindingName}' in strict mode.`,
  311. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  312. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  313. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  314. StrictWith: "'with' in strict mode."
  315. };
  316. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  317. var PipelineOperatorErrors = {
  318. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  319. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  320. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  321. PipeTopicUnconfiguredToken: ({
  322. token
  323. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  324. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  325. PipeUnparenthesizedBody: ({
  326. type
  327. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  328. type
  329. })}; please wrap it in parentheses.`,
  330. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  331. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  332. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  333. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  334. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  335. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  336. };
  337. const _excluded$1 = ["toMessage"],
  338. _excluded2$1 = ["message"];
  339. function defineHidden(obj, key, value) {
  340. Object.defineProperty(obj, key, {
  341. enumerable: false,
  342. configurable: true,
  343. value
  344. });
  345. }
  346. function toParseErrorConstructor(_ref) {
  347. let {
  348. toMessage
  349. } = _ref,
  350. properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  351. return function constructor({
  352. loc,
  353. details
  354. }) {
  355. const error = new SyntaxError();
  356. Object.assign(error, properties, {
  357. loc,
  358. pos: loc.index
  359. });
  360. if ("missingPlugin" in details) {
  361. Object.assign(error, {
  362. missingPlugin: details.missingPlugin
  363. });
  364. }
  365. defineHidden(error, "clone", function clone(overrides = {}) {
  366. var _overrides$loc;
  367. const {
  368. line,
  369. column,
  370. index
  371. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  372. return constructor({
  373. loc: new Position(line, column, index),
  374. details: Object.assign({}, details, overrides.details)
  375. });
  376. });
  377. defineHidden(error, "details", details);
  378. Object.defineProperty(error, "message", {
  379. configurable: true,
  380. get() {
  381. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  382. this.message = message;
  383. return message;
  384. },
  385. set(value) {
  386. Object.defineProperty(this, "message", {
  387. value,
  388. writable: true
  389. });
  390. }
  391. });
  392. return error;
  393. };
  394. }
  395. function ParseErrorEnum(argument, syntaxPlugin) {
  396. if (Array.isArray(argument)) {
  397. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  398. }
  399. const ParseErrorConstructors = {};
  400. for (const reasonCode of Object.keys(argument)) {
  401. const template = argument[reasonCode];
  402. const _ref2 = typeof template === "string" ? {
  403. message: () => template
  404. } : typeof template === "function" ? {
  405. message: template
  406. } : template,
  407. {
  408. message
  409. } = _ref2,
  410. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
  411. const toMessage = typeof message === "string" ? () => message : message;
  412. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  413. code: "BABEL_PARSER_SYNTAX_ERROR",
  414. reasonCode,
  415. toMessage
  416. }, syntaxPlugin ? {
  417. syntaxPlugin
  418. } : {}, rest));
  419. }
  420. return ParseErrorConstructors;
  421. }
  422. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  423. const {
  424. defineProperty
  425. } = Object;
  426. const toUnenumerable = (object, key) => defineProperty(object, key, {
  427. enumerable: false,
  428. value: object[key]
  429. });
  430. function toESTreeLocation(node) {
  431. node.loc.start && toUnenumerable(node.loc.start, "index");
  432. node.loc.end && toUnenumerable(node.loc.end, "index");
  433. return node;
  434. }
  435. var estree = superClass => class ESTreeParserMixin extends superClass {
  436. parse() {
  437. const file = toESTreeLocation(super.parse());
  438. if (this.options.tokens) {
  439. file.tokens = file.tokens.map(toESTreeLocation);
  440. }
  441. return file;
  442. }
  443. parseRegExpLiteral({
  444. pattern,
  445. flags
  446. }) {
  447. let regex = null;
  448. try {
  449. regex = new RegExp(pattern, flags);
  450. } catch (e) {}
  451. const node = this.estreeParseLiteral(regex);
  452. node.regex = {
  453. pattern,
  454. flags
  455. };
  456. return node;
  457. }
  458. parseBigIntLiteral(value) {
  459. let bigInt;
  460. try {
  461. bigInt = BigInt(value);
  462. } catch (_unused) {
  463. bigInt = null;
  464. }
  465. const node = this.estreeParseLiteral(bigInt);
  466. node.bigint = String(node.value || value);
  467. return node;
  468. }
  469. parseDecimalLiteral(value) {
  470. const decimal = null;
  471. const node = this.estreeParseLiteral(decimal);
  472. node.decimal = String(node.value || value);
  473. return node;
  474. }
  475. estreeParseLiteral(value) {
  476. return this.parseLiteral(value, "Literal");
  477. }
  478. parseStringLiteral(value) {
  479. return this.estreeParseLiteral(value);
  480. }
  481. parseNumericLiteral(value) {
  482. return this.estreeParseLiteral(value);
  483. }
  484. parseNullLiteral() {
  485. return this.estreeParseLiteral(null);
  486. }
  487. parseBooleanLiteral(value) {
  488. return this.estreeParseLiteral(value);
  489. }
  490. directiveToStmt(directive) {
  491. const expression = directive.value;
  492. delete directive.value;
  493. expression.type = "Literal";
  494. expression.raw = expression.extra.raw;
  495. expression.value = expression.extra.expressionValue;
  496. const stmt = directive;
  497. stmt.type = "ExpressionStatement";
  498. stmt.expression = expression;
  499. stmt.directive = expression.extra.rawValue;
  500. delete expression.extra;
  501. return stmt;
  502. }
  503. initFunction(node, isAsync) {
  504. super.initFunction(node, isAsync);
  505. node.expression = false;
  506. }
  507. checkDeclaration(node) {
  508. if (node != null && this.isObjectProperty(node)) {
  509. this.checkDeclaration(node.value);
  510. } else {
  511. super.checkDeclaration(node);
  512. }
  513. }
  514. getObjectOrClassMethodParams(method) {
  515. return method.value.params;
  516. }
  517. isValidDirective(stmt) {
  518. var _stmt$expression$extr;
  519. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  520. }
  521. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  522. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  523. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  524. node.body = directiveStatements.concat(node.body);
  525. delete node.directives;
  526. }
  527. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  528. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  529. if (method.typeParameters) {
  530. method.value.typeParameters = method.typeParameters;
  531. delete method.typeParameters;
  532. }
  533. classBody.body.push(method);
  534. }
  535. parsePrivateName() {
  536. const node = super.parsePrivateName();
  537. {
  538. if (!this.getPluginOption("estree", "classFeatures")) {
  539. return node;
  540. }
  541. }
  542. return this.convertPrivateNameToPrivateIdentifier(node);
  543. }
  544. convertPrivateNameToPrivateIdentifier(node) {
  545. const name = super.getPrivateNameSV(node);
  546. node = node;
  547. delete node.id;
  548. node.name = name;
  549. node.type = "PrivateIdentifier";
  550. return node;
  551. }
  552. isPrivateName(node) {
  553. {
  554. if (!this.getPluginOption("estree", "classFeatures")) {
  555. return super.isPrivateName(node);
  556. }
  557. }
  558. return node.type === "PrivateIdentifier";
  559. }
  560. getPrivateNameSV(node) {
  561. {
  562. if (!this.getPluginOption("estree", "classFeatures")) {
  563. return super.getPrivateNameSV(node);
  564. }
  565. }
  566. return node.name;
  567. }
  568. parseLiteral(value, type) {
  569. const node = super.parseLiteral(value, type);
  570. node.raw = node.extra.raw;
  571. delete node.extra;
  572. return node;
  573. }
  574. parseFunctionBody(node, allowExpression, isMethod = false) {
  575. super.parseFunctionBody(node, allowExpression, isMethod);
  576. node.expression = node.body.type !== "BlockStatement";
  577. }
  578. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  579. let funcNode = this.startNode();
  580. funcNode.kind = node.kind;
  581. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  582. funcNode.type = "FunctionExpression";
  583. delete funcNode.kind;
  584. node.value = funcNode;
  585. if (type === "ClassPrivateMethod") {
  586. node.computed = false;
  587. }
  588. return this.finishNode(node, "MethodDefinition");
  589. }
  590. parseClassProperty(...args) {
  591. const propertyNode = super.parseClassProperty(...args);
  592. {
  593. if (!this.getPluginOption("estree", "classFeatures")) {
  594. return propertyNode;
  595. }
  596. }
  597. propertyNode.type = "PropertyDefinition";
  598. return propertyNode;
  599. }
  600. parseClassPrivateProperty(...args) {
  601. const propertyNode = super.parseClassPrivateProperty(...args);
  602. {
  603. if (!this.getPluginOption("estree", "classFeatures")) {
  604. return propertyNode;
  605. }
  606. }
  607. propertyNode.type = "PropertyDefinition";
  608. propertyNode.computed = false;
  609. return propertyNode;
  610. }
  611. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  612. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  613. if (node) {
  614. node.type = "Property";
  615. if (node.kind === "method") {
  616. node.kind = "init";
  617. }
  618. node.shorthand = false;
  619. }
  620. return node;
  621. }
  622. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  623. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  624. if (node) {
  625. node.kind = "init";
  626. node.type = "Property";
  627. }
  628. return node;
  629. }
  630. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  631. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  632. }
  633. isAssignable(node, isBinding) {
  634. if (node != null && this.isObjectProperty(node)) {
  635. return this.isAssignable(node.value, isBinding);
  636. }
  637. return super.isAssignable(node, isBinding);
  638. }
  639. toAssignable(node, isLHS = false) {
  640. if (node != null && this.isObjectProperty(node)) {
  641. const {
  642. key,
  643. value
  644. } = node;
  645. if (this.isPrivateName(key)) {
  646. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  647. }
  648. this.toAssignable(value, isLHS);
  649. } else {
  650. super.toAssignable(node, isLHS);
  651. }
  652. }
  653. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  654. if (prop.kind === "get" || prop.kind === "set") {
  655. this.raise(Errors.PatternHasAccessor, {
  656. at: prop.key
  657. });
  658. } else if (prop.method) {
  659. this.raise(Errors.PatternHasMethod, {
  660. at: prop.key
  661. });
  662. } else {
  663. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  664. }
  665. }
  666. finishCallExpression(unfinished, optional) {
  667. const node = super.finishCallExpression(unfinished, optional);
  668. if (node.callee.type === "Import") {
  669. node.type = "ImportExpression";
  670. node.source = node.arguments[0];
  671. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  672. var _node$arguments$, _node$arguments$2;
  673. node.options = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  674. node.attributes = (_node$arguments$2 = node.arguments[1]) != null ? _node$arguments$2 : null;
  675. }
  676. delete node.arguments;
  677. delete node.callee;
  678. }
  679. return node;
  680. }
  681. toReferencedArguments(node) {
  682. if (node.type === "ImportExpression") {
  683. return;
  684. }
  685. super.toReferencedArguments(node);
  686. }
  687. parseExport(unfinished, decorators) {
  688. const exportStartLoc = this.state.lastTokStartLoc;
  689. const node = super.parseExport(unfinished, decorators);
  690. switch (node.type) {
  691. case "ExportAllDeclaration":
  692. node.exported = null;
  693. break;
  694. case "ExportNamedDeclaration":
  695. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  696. node.type = "ExportAllDeclaration";
  697. node.exported = node.specifiers[0].exported;
  698. delete node.specifiers;
  699. }
  700. case "ExportDefaultDeclaration":
  701. {
  702. var _declaration$decorato;
  703. const {
  704. declaration
  705. } = node;
  706. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  707. this.resetStartLocation(node, exportStartLoc);
  708. }
  709. }
  710. break;
  711. }
  712. return node;
  713. }
  714. parseSubscript(base, startLoc, noCalls, state) {
  715. const node = super.parseSubscript(base, startLoc, noCalls, state);
  716. if (state.optionalChainMember) {
  717. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  718. node.type = node.type.substring(8);
  719. }
  720. if (state.stop) {
  721. const chain = this.startNodeAtNode(node);
  722. chain.expression = node;
  723. return this.finishNode(chain, "ChainExpression");
  724. }
  725. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  726. node.optional = false;
  727. }
  728. return node;
  729. }
  730. isOptionalMemberExpression(node) {
  731. if (node.type === "ChainExpression") {
  732. return node.expression.type === "MemberExpression";
  733. }
  734. return super.isOptionalMemberExpression(node);
  735. }
  736. hasPropertyAsPrivateName(node) {
  737. if (node.type === "ChainExpression") {
  738. node = node.expression;
  739. }
  740. return super.hasPropertyAsPrivateName(node);
  741. }
  742. isObjectProperty(node) {
  743. return node.type === "Property" && node.kind === "init" && !node.method;
  744. }
  745. isObjectMethod(node) {
  746. return node.method || node.kind === "get" || node.kind === "set";
  747. }
  748. finishNodeAt(node, type, endLoc) {
  749. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  750. }
  751. resetStartLocation(node, startLoc) {
  752. super.resetStartLocation(node, startLoc);
  753. toESTreeLocation(node);
  754. }
  755. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  756. super.resetEndLocation(node, endLoc);
  757. toESTreeLocation(node);
  758. }
  759. };
  760. class TokContext {
  761. constructor(token, preserveSpace) {
  762. this.token = void 0;
  763. this.preserveSpace = void 0;
  764. this.token = token;
  765. this.preserveSpace = !!preserveSpace;
  766. }
  767. }
  768. const types = {
  769. brace: new TokContext("{"),
  770. j_oTag: new TokContext("<tag"),
  771. j_cTag: new TokContext("</tag"),
  772. j_expr: new TokContext("<tag>...</tag>", true)
  773. };
  774. {
  775. types.template = new TokContext("`", true);
  776. }
  777. const beforeExpr = true;
  778. const startsExpr = true;
  779. const isLoop = true;
  780. const isAssign = true;
  781. const prefix = true;
  782. const postfix = true;
  783. class ExportedTokenType {
  784. constructor(label, conf = {}) {
  785. this.label = void 0;
  786. this.keyword = void 0;
  787. this.beforeExpr = void 0;
  788. this.startsExpr = void 0;
  789. this.rightAssociative = void 0;
  790. this.isLoop = void 0;
  791. this.isAssign = void 0;
  792. this.prefix = void 0;
  793. this.postfix = void 0;
  794. this.binop = void 0;
  795. this.label = label;
  796. this.keyword = conf.keyword;
  797. this.beforeExpr = !!conf.beforeExpr;
  798. this.startsExpr = !!conf.startsExpr;
  799. this.rightAssociative = !!conf.rightAssociative;
  800. this.isLoop = !!conf.isLoop;
  801. this.isAssign = !!conf.isAssign;
  802. this.prefix = !!conf.prefix;
  803. this.postfix = !!conf.postfix;
  804. this.binop = conf.binop != null ? conf.binop : null;
  805. {
  806. this.updateContext = null;
  807. }
  808. }
  809. }
  810. const keywords$1 = new Map();
  811. function createKeyword(name, options = {}) {
  812. options.keyword = name;
  813. const token = createToken(name, options);
  814. keywords$1.set(name, token);
  815. return token;
  816. }
  817. function createBinop(name, binop) {
  818. return createToken(name, {
  819. beforeExpr,
  820. binop
  821. });
  822. }
  823. let tokenTypeCounter = -1;
  824. const tokenTypes = [];
  825. const tokenLabels = [];
  826. const tokenBinops = [];
  827. const tokenBeforeExprs = [];
  828. const tokenStartsExprs = [];
  829. const tokenPrefixes = [];
  830. function createToken(name, options = {}) {
  831. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  832. ++tokenTypeCounter;
  833. tokenLabels.push(name);
  834. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  835. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  836. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  837. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  838. tokenTypes.push(new ExportedTokenType(name, options));
  839. return tokenTypeCounter;
  840. }
  841. function createKeywordLike(name, options = {}) {
  842. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  843. ++tokenTypeCounter;
  844. keywords$1.set(name, tokenTypeCounter);
  845. tokenLabels.push(name);
  846. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  847. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  848. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  849. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  850. tokenTypes.push(new ExportedTokenType("name", options));
  851. return tokenTypeCounter;
  852. }
  853. const tt = {
  854. bracketL: createToken("[", {
  855. beforeExpr,
  856. startsExpr
  857. }),
  858. bracketHashL: createToken("#[", {
  859. beforeExpr,
  860. startsExpr
  861. }),
  862. bracketBarL: createToken("[|", {
  863. beforeExpr,
  864. startsExpr
  865. }),
  866. bracketR: createToken("]"),
  867. bracketBarR: createToken("|]"),
  868. braceL: createToken("{", {
  869. beforeExpr,
  870. startsExpr
  871. }),
  872. braceBarL: createToken("{|", {
  873. beforeExpr,
  874. startsExpr
  875. }),
  876. braceHashL: createToken("#{", {
  877. beforeExpr,
  878. startsExpr
  879. }),
  880. braceR: createToken("}"),
  881. braceBarR: createToken("|}"),
  882. parenL: createToken("(", {
  883. beforeExpr,
  884. startsExpr
  885. }),
  886. parenR: createToken(")"),
  887. comma: createToken(",", {
  888. beforeExpr
  889. }),
  890. semi: createToken(";", {
  891. beforeExpr
  892. }),
  893. colon: createToken(":", {
  894. beforeExpr
  895. }),
  896. doubleColon: createToken("::", {
  897. beforeExpr
  898. }),
  899. dot: createToken("."),
  900. question: createToken("?", {
  901. beforeExpr
  902. }),
  903. questionDot: createToken("?."),
  904. arrow: createToken("=>", {
  905. beforeExpr
  906. }),
  907. template: createToken("template"),
  908. ellipsis: createToken("...", {
  909. beforeExpr
  910. }),
  911. backQuote: createToken("`", {
  912. startsExpr
  913. }),
  914. dollarBraceL: createToken("${", {
  915. beforeExpr,
  916. startsExpr
  917. }),
  918. templateTail: createToken("...`", {
  919. startsExpr
  920. }),
  921. templateNonTail: createToken("...${", {
  922. beforeExpr,
  923. startsExpr
  924. }),
  925. at: createToken("@"),
  926. hash: createToken("#", {
  927. startsExpr
  928. }),
  929. interpreterDirective: createToken("#!..."),
  930. eq: createToken("=", {
  931. beforeExpr,
  932. isAssign
  933. }),
  934. assign: createToken("_=", {
  935. beforeExpr,
  936. isAssign
  937. }),
  938. slashAssign: createToken("_=", {
  939. beforeExpr,
  940. isAssign
  941. }),
  942. xorAssign: createToken("_=", {
  943. beforeExpr,
  944. isAssign
  945. }),
  946. moduloAssign: createToken("_=", {
  947. beforeExpr,
  948. isAssign
  949. }),
  950. incDec: createToken("++/--", {
  951. prefix,
  952. postfix,
  953. startsExpr
  954. }),
  955. bang: createToken("!", {
  956. beforeExpr,
  957. prefix,
  958. startsExpr
  959. }),
  960. tilde: createToken("~", {
  961. beforeExpr,
  962. prefix,
  963. startsExpr
  964. }),
  965. doubleCaret: createToken("^^", {
  966. startsExpr
  967. }),
  968. doubleAt: createToken("@@", {
  969. startsExpr
  970. }),
  971. pipeline: createBinop("|>", 0),
  972. nullishCoalescing: createBinop("??", 1),
  973. logicalOR: createBinop("||", 1),
  974. logicalAND: createBinop("&&", 2),
  975. bitwiseOR: createBinop("|", 3),
  976. bitwiseXOR: createBinop("^", 4),
  977. bitwiseAND: createBinop("&", 5),
  978. equality: createBinop("==/!=/===/!==", 6),
  979. lt: createBinop("</>/<=/>=", 7),
  980. gt: createBinop("</>/<=/>=", 7),
  981. relational: createBinop("</>/<=/>=", 7),
  982. bitShift: createBinop("<</>>/>>>", 8),
  983. bitShiftL: createBinop("<</>>/>>>", 8),
  984. bitShiftR: createBinop("<</>>/>>>", 8),
  985. plusMin: createToken("+/-", {
  986. beforeExpr,
  987. binop: 9,
  988. prefix,
  989. startsExpr
  990. }),
  991. modulo: createToken("%", {
  992. binop: 10,
  993. startsExpr
  994. }),
  995. star: createToken("*", {
  996. binop: 10
  997. }),
  998. slash: createBinop("/", 10),
  999. exponent: createToken("**", {
  1000. beforeExpr,
  1001. binop: 11,
  1002. rightAssociative: true
  1003. }),
  1004. _in: createKeyword("in", {
  1005. beforeExpr,
  1006. binop: 7
  1007. }),
  1008. _instanceof: createKeyword("instanceof", {
  1009. beforeExpr,
  1010. binop: 7
  1011. }),
  1012. _break: createKeyword("break"),
  1013. _case: createKeyword("case", {
  1014. beforeExpr
  1015. }),
  1016. _catch: createKeyword("catch"),
  1017. _continue: createKeyword("continue"),
  1018. _debugger: createKeyword("debugger"),
  1019. _default: createKeyword("default", {
  1020. beforeExpr
  1021. }),
  1022. _else: createKeyword("else", {
  1023. beforeExpr
  1024. }),
  1025. _finally: createKeyword("finally"),
  1026. _function: createKeyword("function", {
  1027. startsExpr
  1028. }),
  1029. _if: createKeyword("if"),
  1030. _return: createKeyword("return", {
  1031. beforeExpr
  1032. }),
  1033. _switch: createKeyword("switch"),
  1034. _throw: createKeyword("throw", {
  1035. beforeExpr,
  1036. prefix,
  1037. startsExpr
  1038. }),
  1039. _try: createKeyword("try"),
  1040. _var: createKeyword("var"),
  1041. _const: createKeyword("const"),
  1042. _with: createKeyword("with"),
  1043. _new: createKeyword("new", {
  1044. beforeExpr,
  1045. startsExpr
  1046. }),
  1047. _this: createKeyword("this", {
  1048. startsExpr
  1049. }),
  1050. _super: createKeyword("super", {
  1051. startsExpr
  1052. }),
  1053. _class: createKeyword("class", {
  1054. startsExpr
  1055. }),
  1056. _extends: createKeyword("extends", {
  1057. beforeExpr
  1058. }),
  1059. _export: createKeyword("export"),
  1060. _import: createKeyword("import", {
  1061. startsExpr
  1062. }),
  1063. _null: createKeyword("null", {
  1064. startsExpr
  1065. }),
  1066. _true: createKeyword("true", {
  1067. startsExpr
  1068. }),
  1069. _false: createKeyword("false", {
  1070. startsExpr
  1071. }),
  1072. _typeof: createKeyword("typeof", {
  1073. beforeExpr,
  1074. prefix,
  1075. startsExpr
  1076. }),
  1077. _void: createKeyword("void", {
  1078. beforeExpr,
  1079. prefix,
  1080. startsExpr
  1081. }),
  1082. _delete: createKeyword("delete", {
  1083. beforeExpr,
  1084. prefix,
  1085. startsExpr
  1086. }),
  1087. _do: createKeyword("do", {
  1088. isLoop,
  1089. beforeExpr
  1090. }),
  1091. _for: createKeyword("for", {
  1092. isLoop
  1093. }),
  1094. _while: createKeyword("while", {
  1095. isLoop
  1096. }),
  1097. _as: createKeywordLike("as", {
  1098. startsExpr
  1099. }),
  1100. _assert: createKeywordLike("assert", {
  1101. startsExpr
  1102. }),
  1103. _async: createKeywordLike("async", {
  1104. startsExpr
  1105. }),
  1106. _await: createKeywordLike("await", {
  1107. startsExpr
  1108. }),
  1109. _defer: createKeywordLike("defer", {
  1110. startsExpr
  1111. }),
  1112. _from: createKeywordLike("from", {
  1113. startsExpr
  1114. }),
  1115. _get: createKeywordLike("get", {
  1116. startsExpr
  1117. }),
  1118. _let: createKeywordLike("let", {
  1119. startsExpr
  1120. }),
  1121. _meta: createKeywordLike("meta", {
  1122. startsExpr
  1123. }),
  1124. _of: createKeywordLike("of", {
  1125. startsExpr
  1126. }),
  1127. _sent: createKeywordLike("sent", {
  1128. startsExpr
  1129. }),
  1130. _set: createKeywordLike("set", {
  1131. startsExpr
  1132. }),
  1133. _source: createKeywordLike("source", {
  1134. startsExpr
  1135. }),
  1136. _static: createKeywordLike("static", {
  1137. startsExpr
  1138. }),
  1139. _using: createKeywordLike("using", {
  1140. startsExpr
  1141. }),
  1142. _yield: createKeywordLike("yield", {
  1143. startsExpr
  1144. }),
  1145. _asserts: createKeywordLike("asserts", {
  1146. startsExpr
  1147. }),
  1148. _checks: createKeywordLike("checks", {
  1149. startsExpr
  1150. }),
  1151. _exports: createKeywordLike("exports", {
  1152. startsExpr
  1153. }),
  1154. _global: createKeywordLike("global", {
  1155. startsExpr
  1156. }),
  1157. _implements: createKeywordLike("implements", {
  1158. startsExpr
  1159. }),
  1160. _intrinsic: createKeywordLike("intrinsic", {
  1161. startsExpr
  1162. }),
  1163. _infer: createKeywordLike("infer", {
  1164. startsExpr
  1165. }),
  1166. _is: createKeywordLike("is", {
  1167. startsExpr
  1168. }),
  1169. _mixins: createKeywordLike("mixins", {
  1170. startsExpr
  1171. }),
  1172. _proto: createKeywordLike("proto", {
  1173. startsExpr
  1174. }),
  1175. _require: createKeywordLike("require", {
  1176. startsExpr
  1177. }),
  1178. _satisfies: createKeywordLike("satisfies", {
  1179. startsExpr
  1180. }),
  1181. _keyof: createKeywordLike("keyof", {
  1182. startsExpr
  1183. }),
  1184. _readonly: createKeywordLike("readonly", {
  1185. startsExpr
  1186. }),
  1187. _unique: createKeywordLike("unique", {
  1188. startsExpr
  1189. }),
  1190. _abstract: createKeywordLike("abstract", {
  1191. startsExpr
  1192. }),
  1193. _declare: createKeywordLike("declare", {
  1194. startsExpr
  1195. }),
  1196. _enum: createKeywordLike("enum", {
  1197. startsExpr
  1198. }),
  1199. _module: createKeywordLike("module", {
  1200. startsExpr
  1201. }),
  1202. _namespace: createKeywordLike("namespace", {
  1203. startsExpr
  1204. }),
  1205. _interface: createKeywordLike("interface", {
  1206. startsExpr
  1207. }),
  1208. _type: createKeywordLike("type", {
  1209. startsExpr
  1210. }),
  1211. _opaque: createKeywordLike("opaque", {
  1212. startsExpr
  1213. }),
  1214. name: createToken("name", {
  1215. startsExpr
  1216. }),
  1217. string: createToken("string", {
  1218. startsExpr
  1219. }),
  1220. num: createToken("num", {
  1221. startsExpr
  1222. }),
  1223. bigint: createToken("bigint", {
  1224. startsExpr
  1225. }),
  1226. decimal: createToken("decimal", {
  1227. startsExpr
  1228. }),
  1229. regexp: createToken("regexp", {
  1230. startsExpr
  1231. }),
  1232. privateName: createToken("#name", {
  1233. startsExpr
  1234. }),
  1235. eof: createToken("eof"),
  1236. jsxName: createToken("jsxName"),
  1237. jsxText: createToken("jsxText", {
  1238. beforeExpr: true
  1239. }),
  1240. jsxTagStart: createToken("jsxTagStart", {
  1241. startsExpr: true
  1242. }),
  1243. jsxTagEnd: createToken("jsxTagEnd"),
  1244. placeholder: createToken("%%", {
  1245. startsExpr: true
  1246. })
  1247. };
  1248. function tokenIsIdentifier(token) {
  1249. return token >= 93 && token <= 132;
  1250. }
  1251. function tokenKeywordOrIdentifierIsKeyword(token) {
  1252. return token <= 92;
  1253. }
  1254. function tokenIsKeywordOrIdentifier(token) {
  1255. return token >= 58 && token <= 132;
  1256. }
  1257. function tokenIsLiteralPropertyName(token) {
  1258. return token >= 58 && token <= 136;
  1259. }
  1260. function tokenComesBeforeExpression(token) {
  1261. return tokenBeforeExprs[token];
  1262. }
  1263. function tokenCanStartExpression(token) {
  1264. return tokenStartsExprs[token];
  1265. }
  1266. function tokenIsAssignment(token) {
  1267. return token >= 29 && token <= 33;
  1268. }
  1269. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1270. return token >= 129 && token <= 131;
  1271. }
  1272. function tokenIsLoop(token) {
  1273. return token >= 90 && token <= 92;
  1274. }
  1275. function tokenIsKeyword(token) {
  1276. return token >= 58 && token <= 92;
  1277. }
  1278. function tokenIsOperator(token) {
  1279. return token >= 39 && token <= 59;
  1280. }
  1281. function tokenIsPostfix(token) {
  1282. return token === 34;
  1283. }
  1284. function tokenIsPrefix(token) {
  1285. return tokenPrefixes[token];
  1286. }
  1287. function tokenIsTSTypeOperator(token) {
  1288. return token >= 121 && token <= 123;
  1289. }
  1290. function tokenIsTSDeclarationStart(token) {
  1291. return token >= 124 && token <= 130;
  1292. }
  1293. function tokenLabelName(token) {
  1294. return tokenLabels[token];
  1295. }
  1296. function tokenOperatorPrecedence(token) {
  1297. return tokenBinops[token];
  1298. }
  1299. function tokenIsRightAssociative(token) {
  1300. return token === 57;
  1301. }
  1302. function tokenIsTemplate(token) {
  1303. return token >= 24 && token <= 25;
  1304. }
  1305. function getExportedToken(token) {
  1306. return tokenTypes[token];
  1307. }
  1308. {
  1309. tokenTypes[8].updateContext = context => {
  1310. context.pop();
  1311. };
  1312. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1313. context.push(types.brace);
  1314. };
  1315. tokenTypes[22].updateContext = context => {
  1316. if (context[context.length - 1] === types.template) {
  1317. context.pop();
  1318. } else {
  1319. context.push(types.template);
  1320. }
  1321. };
  1322. tokenTypes[142].updateContext = context => {
  1323. context.push(types.j_expr, types.j_oTag);
  1324. };
  1325. }
  1326. let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ca\ua7d0\ua7d1\ua7d3\ua7d5-\ua7d9\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  1327. let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0898-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
  1328. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1329. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1330. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1331. 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, 68, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 4026, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 757, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
  1332. 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, 370, 1, 81, 2, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 9, 5351, 0, 7, 14, 13835, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 983, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1333. function isInAstralSet(code, set) {
  1334. let pos = 0x10000;
  1335. for (let i = 0, length = set.length; i < length; i += 2) {
  1336. pos += set[i];
  1337. if (pos > code) return false;
  1338. pos += set[i + 1];
  1339. if (pos >= code) return true;
  1340. }
  1341. return false;
  1342. }
  1343. function isIdentifierStart(code) {
  1344. if (code < 65) return code === 36;
  1345. if (code <= 90) return true;
  1346. if (code < 97) return code === 95;
  1347. if (code <= 122) return true;
  1348. if (code <= 0xffff) {
  1349. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1350. }
  1351. return isInAstralSet(code, astralIdentifierStartCodes);
  1352. }
  1353. function isIdentifierChar(code) {
  1354. if (code < 48) return code === 36;
  1355. if (code < 58) return true;
  1356. if (code < 65) return false;
  1357. if (code <= 90) return true;
  1358. if (code < 97) return code === 95;
  1359. if (code <= 122) return true;
  1360. if (code <= 0xffff) {
  1361. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1362. }
  1363. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1364. }
  1365. const reservedWords = {
  1366. 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"],
  1367. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1368. strictBind: ["eval", "arguments"]
  1369. };
  1370. const keywords = new Set(reservedWords.keyword);
  1371. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1372. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1373. function isReservedWord(word, inModule) {
  1374. return inModule && word === "await" || word === "enum";
  1375. }
  1376. function isStrictReservedWord(word, inModule) {
  1377. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1378. }
  1379. function isStrictBindOnlyReservedWord(word) {
  1380. return reservedWordsStrictBindSet.has(word);
  1381. }
  1382. function isStrictBindReservedWord(word, inModule) {
  1383. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1384. }
  1385. function isKeyword(word) {
  1386. return keywords.has(word);
  1387. }
  1388. function isIteratorStart(current, next, next2) {
  1389. return current === 64 && next === 64 && isIdentifierStart(next2);
  1390. }
  1391. 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"]);
  1392. function canBeReservedWord(word) {
  1393. return reservedWordLikeSet.has(word);
  1394. }
  1395. class Scope {
  1396. constructor(flags) {
  1397. this.var = new Set();
  1398. this.lexical = new Set();
  1399. this.functions = new Set();
  1400. this.flags = flags;
  1401. }
  1402. }
  1403. class ScopeHandler {
  1404. constructor(parser, inModule) {
  1405. this.parser = void 0;
  1406. this.scopeStack = [];
  1407. this.inModule = void 0;
  1408. this.undefinedExports = new Map();
  1409. this.parser = parser;
  1410. this.inModule = inModule;
  1411. }
  1412. get inTopLevel() {
  1413. return (this.currentScope().flags & 1) > 0;
  1414. }
  1415. get inFunction() {
  1416. return (this.currentVarScopeFlags() & 2) > 0;
  1417. }
  1418. get allowSuper() {
  1419. return (this.currentThisScopeFlags() & 16) > 0;
  1420. }
  1421. get allowDirectSuper() {
  1422. return (this.currentThisScopeFlags() & 32) > 0;
  1423. }
  1424. get inClass() {
  1425. return (this.currentThisScopeFlags() & 64) > 0;
  1426. }
  1427. get inClassAndNotInNonArrowFunction() {
  1428. const flags = this.currentThisScopeFlags();
  1429. return (flags & 64) > 0 && (flags & 2) === 0;
  1430. }
  1431. get inStaticBlock() {
  1432. for (let i = this.scopeStack.length - 1;; i--) {
  1433. const {
  1434. flags
  1435. } = this.scopeStack[i];
  1436. if (flags & 128) {
  1437. return true;
  1438. }
  1439. if (flags & (387 | 64)) {
  1440. return false;
  1441. }
  1442. }
  1443. }
  1444. get inNonArrowFunction() {
  1445. return (this.currentThisScopeFlags() & 2) > 0;
  1446. }
  1447. get treatFunctionsAsVar() {
  1448. return this.treatFunctionsAsVarInScope(this.currentScope());
  1449. }
  1450. createScope(flags) {
  1451. return new Scope(flags);
  1452. }
  1453. enter(flags) {
  1454. this.scopeStack.push(this.createScope(flags));
  1455. }
  1456. exit() {
  1457. const scope = this.scopeStack.pop();
  1458. return scope.flags;
  1459. }
  1460. treatFunctionsAsVarInScope(scope) {
  1461. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1462. }
  1463. declareName(name, bindingType, loc) {
  1464. let scope = this.currentScope();
  1465. if (bindingType & 8 || bindingType & 16) {
  1466. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1467. if (bindingType & 16) {
  1468. scope.functions.add(name);
  1469. } else {
  1470. scope.lexical.add(name);
  1471. }
  1472. if (bindingType & 8) {
  1473. this.maybeExportDefined(scope, name);
  1474. }
  1475. } else if (bindingType & 4) {
  1476. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1477. scope = this.scopeStack[i];
  1478. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1479. scope.var.add(name);
  1480. this.maybeExportDefined(scope, name);
  1481. if (scope.flags & 387) break;
  1482. }
  1483. }
  1484. if (this.parser.inModule && scope.flags & 1) {
  1485. this.undefinedExports.delete(name);
  1486. }
  1487. }
  1488. maybeExportDefined(scope, name) {
  1489. if (this.parser.inModule && scope.flags & 1) {
  1490. this.undefinedExports.delete(name);
  1491. }
  1492. }
  1493. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1494. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1495. this.parser.raise(Errors.VarRedeclaration, {
  1496. at: loc,
  1497. identifierName: name
  1498. });
  1499. }
  1500. }
  1501. isRedeclaredInScope(scope, name, bindingType) {
  1502. if (!(bindingType & 1)) return false;
  1503. if (bindingType & 8) {
  1504. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  1505. }
  1506. if (bindingType & 16) {
  1507. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  1508. }
  1509. return scope.lexical.has(name) && !(scope.flags & 8 && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  1510. }
  1511. checkLocalExport(id) {
  1512. const {
  1513. name
  1514. } = id;
  1515. const topLevelScope = this.scopeStack[0];
  1516. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
  1517. this.undefinedExports.set(name, id.loc.start);
  1518. }
  1519. }
  1520. currentScope() {
  1521. return this.scopeStack[this.scopeStack.length - 1];
  1522. }
  1523. currentVarScopeFlags() {
  1524. for (let i = this.scopeStack.length - 1;; i--) {
  1525. const {
  1526. flags
  1527. } = this.scopeStack[i];
  1528. if (flags & 387) {
  1529. return flags;
  1530. }
  1531. }
  1532. }
  1533. currentThisScopeFlags() {
  1534. for (let i = this.scopeStack.length - 1;; i--) {
  1535. const {
  1536. flags
  1537. } = this.scopeStack[i];
  1538. if (flags & (387 | 64) && !(flags & 4)) {
  1539. return flags;
  1540. }
  1541. }
  1542. }
  1543. }
  1544. class FlowScope extends Scope {
  1545. constructor(...args) {
  1546. super(...args);
  1547. this.declareFunctions = new Set();
  1548. }
  1549. }
  1550. class FlowScopeHandler extends ScopeHandler {
  1551. createScope(flags) {
  1552. return new FlowScope(flags);
  1553. }
  1554. declareName(name, bindingType, loc) {
  1555. const scope = this.currentScope();
  1556. if (bindingType & 2048) {
  1557. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1558. this.maybeExportDefined(scope, name);
  1559. scope.declareFunctions.add(name);
  1560. return;
  1561. }
  1562. super.declareName(name, bindingType, loc);
  1563. }
  1564. isRedeclaredInScope(scope, name, bindingType) {
  1565. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1566. if (bindingType & 2048) {
  1567. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  1568. }
  1569. return false;
  1570. }
  1571. checkLocalExport(id) {
  1572. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1573. super.checkLocalExport(id);
  1574. }
  1575. }
  1576. }
  1577. class BaseParser {
  1578. constructor() {
  1579. this.sawUnambiguousESM = false;
  1580. this.ambiguousScriptDifferentAst = false;
  1581. }
  1582. hasPlugin(pluginConfig) {
  1583. if (typeof pluginConfig === "string") {
  1584. return this.plugins.has(pluginConfig);
  1585. } else {
  1586. const [pluginName, pluginOptions] = pluginConfig;
  1587. if (!this.hasPlugin(pluginName)) {
  1588. return false;
  1589. }
  1590. const actualOptions = this.plugins.get(pluginName);
  1591. for (const key of Object.keys(pluginOptions)) {
  1592. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1593. return false;
  1594. }
  1595. }
  1596. return true;
  1597. }
  1598. }
  1599. getPluginOption(plugin, name) {
  1600. var _this$plugins$get;
  1601. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1602. }
  1603. }
  1604. function setTrailingComments(node, comments) {
  1605. if (node.trailingComments === undefined) {
  1606. node.trailingComments = comments;
  1607. } else {
  1608. node.trailingComments.unshift(...comments);
  1609. }
  1610. }
  1611. function setLeadingComments(node, comments) {
  1612. if (node.leadingComments === undefined) {
  1613. node.leadingComments = comments;
  1614. } else {
  1615. node.leadingComments.unshift(...comments);
  1616. }
  1617. }
  1618. function setInnerComments(node, comments) {
  1619. if (node.innerComments === undefined) {
  1620. node.innerComments = comments;
  1621. } else {
  1622. node.innerComments.unshift(...comments);
  1623. }
  1624. }
  1625. function adjustInnerComments(node, elements, commentWS) {
  1626. let lastElement = null;
  1627. let i = elements.length;
  1628. while (lastElement === null && i > 0) {
  1629. lastElement = elements[--i];
  1630. }
  1631. if (lastElement === null || lastElement.start > commentWS.start) {
  1632. setInnerComments(node, commentWS.comments);
  1633. } else {
  1634. setTrailingComments(lastElement, commentWS.comments);
  1635. }
  1636. }
  1637. class CommentsParser extends BaseParser {
  1638. addComment(comment) {
  1639. if (this.filename) comment.loc.filename = this.filename;
  1640. this.state.comments.push(comment);
  1641. }
  1642. processComment(node) {
  1643. const {
  1644. commentStack
  1645. } = this.state;
  1646. const commentStackLength = commentStack.length;
  1647. if (commentStackLength === 0) return;
  1648. let i = commentStackLength - 1;
  1649. const lastCommentWS = commentStack[i];
  1650. if (lastCommentWS.start === node.end) {
  1651. lastCommentWS.leadingNode = node;
  1652. i--;
  1653. }
  1654. const {
  1655. start: nodeStart
  1656. } = node;
  1657. for (; i >= 0; i--) {
  1658. const commentWS = commentStack[i];
  1659. const commentEnd = commentWS.end;
  1660. if (commentEnd > nodeStart) {
  1661. commentWS.containingNode = node;
  1662. this.finalizeComment(commentWS);
  1663. commentStack.splice(i, 1);
  1664. } else {
  1665. if (commentEnd === nodeStart) {
  1666. commentWS.trailingNode = node;
  1667. }
  1668. break;
  1669. }
  1670. }
  1671. }
  1672. finalizeComment(commentWS) {
  1673. const {
  1674. comments
  1675. } = commentWS;
  1676. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1677. if (commentWS.leadingNode !== null) {
  1678. setTrailingComments(commentWS.leadingNode, comments);
  1679. }
  1680. if (commentWS.trailingNode !== null) {
  1681. setLeadingComments(commentWS.trailingNode, comments);
  1682. }
  1683. } else {
  1684. const {
  1685. containingNode: node,
  1686. start: commentStart
  1687. } = commentWS;
  1688. if (this.input.charCodeAt(commentStart - 1) === 44) {
  1689. switch (node.type) {
  1690. case "ObjectExpression":
  1691. case "ObjectPattern":
  1692. case "RecordExpression":
  1693. adjustInnerComments(node, node.properties, commentWS);
  1694. break;
  1695. case "CallExpression":
  1696. case "OptionalCallExpression":
  1697. adjustInnerComments(node, node.arguments, commentWS);
  1698. break;
  1699. case "FunctionDeclaration":
  1700. case "FunctionExpression":
  1701. case "ArrowFunctionExpression":
  1702. case "ObjectMethod":
  1703. case "ClassMethod":
  1704. case "ClassPrivateMethod":
  1705. adjustInnerComments(node, node.params, commentWS);
  1706. break;
  1707. case "ArrayExpression":
  1708. case "ArrayPattern":
  1709. case "TupleExpression":
  1710. adjustInnerComments(node, node.elements, commentWS);
  1711. break;
  1712. case "ExportNamedDeclaration":
  1713. case "ImportDeclaration":
  1714. adjustInnerComments(node, node.specifiers, commentWS);
  1715. break;
  1716. default:
  1717. {
  1718. setInnerComments(node, comments);
  1719. }
  1720. }
  1721. } else {
  1722. setInnerComments(node, comments);
  1723. }
  1724. }
  1725. }
  1726. finalizeRemainingComments() {
  1727. const {
  1728. commentStack
  1729. } = this.state;
  1730. for (let i = commentStack.length - 1; i >= 0; i--) {
  1731. this.finalizeComment(commentStack[i]);
  1732. }
  1733. this.state.commentStack = [];
  1734. }
  1735. resetPreviousNodeTrailingComments(node) {
  1736. const {
  1737. commentStack
  1738. } = this.state;
  1739. const {
  1740. length
  1741. } = commentStack;
  1742. if (length === 0) return;
  1743. const commentWS = commentStack[length - 1];
  1744. if (commentWS.leadingNode === node) {
  1745. commentWS.leadingNode = null;
  1746. }
  1747. }
  1748. resetPreviousIdentifierLeadingComments(node) {
  1749. const {
  1750. commentStack
  1751. } = this.state;
  1752. const {
  1753. length
  1754. } = commentStack;
  1755. if (length === 0) return;
  1756. if (commentStack[length - 1].trailingNode === node) {
  1757. commentStack[length - 1].trailingNode = null;
  1758. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  1759. commentStack[length - 2].trailingNode = null;
  1760. }
  1761. }
  1762. takeSurroundingComments(node, start, end) {
  1763. const {
  1764. commentStack
  1765. } = this.state;
  1766. const commentStackLength = commentStack.length;
  1767. if (commentStackLength === 0) return;
  1768. let i = commentStackLength - 1;
  1769. for (; i >= 0; i--) {
  1770. const commentWS = commentStack[i];
  1771. const commentEnd = commentWS.end;
  1772. const commentStart = commentWS.start;
  1773. if (commentStart === end) {
  1774. commentWS.leadingNode = node;
  1775. } else if (commentEnd === start) {
  1776. commentWS.trailingNode = node;
  1777. } else if (commentEnd < start) {
  1778. break;
  1779. }
  1780. }
  1781. }
  1782. }
  1783. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  1784. const lineBreakG = new RegExp(lineBreak.source, "g");
  1785. function isNewLine(code) {
  1786. switch (code) {
  1787. case 10:
  1788. case 13:
  1789. case 8232:
  1790. case 8233:
  1791. return true;
  1792. default:
  1793. return false;
  1794. }
  1795. }
  1796. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1797. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1798. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  1799. function isWhitespace(code) {
  1800. switch (code) {
  1801. case 0x0009:
  1802. case 0x000b:
  1803. case 0x000c:
  1804. case 32:
  1805. case 160:
  1806. case 5760:
  1807. case 0x2000:
  1808. case 0x2001:
  1809. case 0x2002:
  1810. case 0x2003:
  1811. case 0x2004:
  1812. case 0x2005:
  1813. case 0x2006:
  1814. case 0x2007:
  1815. case 0x2008:
  1816. case 0x2009:
  1817. case 0x200a:
  1818. case 0x202f:
  1819. case 0x205f:
  1820. case 0x3000:
  1821. case 0xfeff:
  1822. return true;
  1823. default:
  1824. return false;
  1825. }
  1826. }
  1827. class State {
  1828. constructor() {
  1829. this.strict = void 0;
  1830. this.curLine = void 0;
  1831. this.lineStart = void 0;
  1832. this.startLoc = void 0;
  1833. this.endLoc = void 0;
  1834. this.errors = [];
  1835. this.potentialArrowAt = -1;
  1836. this.noArrowAt = [];
  1837. this.noArrowParamsConversionAt = [];
  1838. this.maybeInArrowParameters = false;
  1839. this.inType = false;
  1840. this.noAnonFunctionType = false;
  1841. this.hasFlowComment = false;
  1842. this.isAmbientContext = false;
  1843. this.inAbstractClass = false;
  1844. this.inDisallowConditionalTypesContext = false;
  1845. this.topicContext = {
  1846. maxNumOfResolvableTopics: 0,
  1847. maxTopicIndex: null
  1848. };
  1849. this.soloAwait = false;
  1850. this.inFSharpPipelineDirectBody = false;
  1851. this.labels = [];
  1852. this.comments = [];
  1853. this.commentStack = [];
  1854. this.pos = 0;
  1855. this.type = 139;
  1856. this.value = null;
  1857. this.start = 0;
  1858. this.end = 0;
  1859. this.lastTokEndLoc = null;
  1860. this.lastTokStartLoc = null;
  1861. this.lastTokStart = 0;
  1862. this.context = [types.brace];
  1863. this.canStartJSXElement = true;
  1864. this.containsEsc = false;
  1865. this.firstInvalidTemplateEscapePos = null;
  1866. this.strictErrors = new Map();
  1867. this.tokensLength = 0;
  1868. }
  1869. init({
  1870. strictMode,
  1871. sourceType,
  1872. startLine,
  1873. startColumn
  1874. }) {
  1875. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1876. this.curLine = startLine;
  1877. this.lineStart = -startColumn;
  1878. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  1879. }
  1880. curPosition() {
  1881. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  1882. }
  1883. clone(skipArrays) {
  1884. const state = new State();
  1885. const keys = Object.keys(this);
  1886. for (let i = 0, length = keys.length; i < length; i++) {
  1887. const key = keys[i];
  1888. let val = this[key];
  1889. if (!skipArrays && Array.isArray(val)) {
  1890. val = val.slice();
  1891. }
  1892. state[key] = val;
  1893. }
  1894. return state;
  1895. }
  1896. }
  1897. var _isDigit = function isDigit(code) {
  1898. return code >= 48 && code <= 57;
  1899. };
  1900. const forbiddenNumericSeparatorSiblings = {
  1901. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  1902. hex: new Set([46, 88, 95, 120])
  1903. };
  1904. const isAllowedNumericSeparatorSibling = {
  1905. bin: ch => ch === 48 || ch === 49,
  1906. oct: ch => ch >= 48 && ch <= 55,
  1907. dec: ch => ch >= 48 && ch <= 57,
  1908. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  1909. };
  1910. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  1911. const initialPos = pos;
  1912. const initialLineStart = lineStart;
  1913. const initialCurLine = curLine;
  1914. let out = "";
  1915. let firstInvalidLoc = null;
  1916. let chunkStart = pos;
  1917. const {
  1918. length
  1919. } = input;
  1920. for (;;) {
  1921. if (pos >= length) {
  1922. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1923. out += input.slice(chunkStart, pos);
  1924. break;
  1925. }
  1926. const ch = input.charCodeAt(pos);
  1927. if (isStringEnd(type, ch, input, pos)) {
  1928. out += input.slice(chunkStart, pos);
  1929. break;
  1930. }
  1931. if (ch === 92) {
  1932. out += input.slice(chunkStart, pos);
  1933. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  1934. if (res.ch === null && !firstInvalidLoc) {
  1935. firstInvalidLoc = {
  1936. pos,
  1937. lineStart,
  1938. curLine
  1939. };
  1940. } else {
  1941. out += res.ch;
  1942. }
  1943. ({
  1944. pos,
  1945. lineStart,
  1946. curLine
  1947. } = res);
  1948. chunkStart = pos;
  1949. } else if (ch === 8232 || ch === 8233) {
  1950. ++pos;
  1951. ++curLine;
  1952. lineStart = pos;
  1953. } else if (ch === 10 || ch === 13) {
  1954. if (type === "template") {
  1955. out += input.slice(chunkStart, pos) + "\n";
  1956. ++pos;
  1957. if (ch === 13 && input.charCodeAt(pos) === 10) {
  1958. ++pos;
  1959. }
  1960. ++curLine;
  1961. chunkStart = lineStart = pos;
  1962. } else {
  1963. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1964. }
  1965. } else {
  1966. ++pos;
  1967. }
  1968. }
  1969. return {
  1970. pos,
  1971. str: out,
  1972. firstInvalidLoc,
  1973. lineStart,
  1974. curLine,
  1975. containsInvalid: !!firstInvalidLoc
  1976. };
  1977. }
  1978. function isStringEnd(type, ch, input, pos) {
  1979. if (type === "template") {
  1980. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  1981. }
  1982. return ch === (type === "double" ? 34 : 39);
  1983. }
  1984. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  1985. const throwOnInvalid = !inTemplate;
  1986. pos++;
  1987. const res = ch => ({
  1988. pos,
  1989. ch,
  1990. lineStart,
  1991. curLine
  1992. });
  1993. const ch = input.charCodeAt(pos++);
  1994. switch (ch) {
  1995. case 110:
  1996. return res("\n");
  1997. case 114:
  1998. return res("\r");
  1999. case 120:
  2000. {
  2001. let code;
  2002. ({
  2003. code,
  2004. pos
  2005. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2006. return res(code === null ? null : String.fromCharCode(code));
  2007. }
  2008. case 117:
  2009. {
  2010. let code;
  2011. ({
  2012. code,
  2013. pos
  2014. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2015. return res(code === null ? null : String.fromCodePoint(code));
  2016. }
  2017. case 116:
  2018. return res("\t");
  2019. case 98:
  2020. return res("\b");
  2021. case 118:
  2022. return res("\u000b");
  2023. case 102:
  2024. return res("\f");
  2025. case 13:
  2026. if (input.charCodeAt(pos) === 10) {
  2027. ++pos;
  2028. }
  2029. case 10:
  2030. lineStart = pos;
  2031. ++curLine;
  2032. case 8232:
  2033. case 8233:
  2034. return res("");
  2035. case 56:
  2036. case 57:
  2037. if (inTemplate) {
  2038. return res(null);
  2039. } else {
  2040. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2041. }
  2042. default:
  2043. if (ch >= 48 && ch <= 55) {
  2044. const startPos = pos - 1;
  2045. const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
  2046. let octalStr = match[0];
  2047. let octal = parseInt(octalStr, 8);
  2048. if (octal > 255) {
  2049. octalStr = octalStr.slice(0, -1);
  2050. octal = parseInt(octalStr, 8);
  2051. }
  2052. pos += octalStr.length - 1;
  2053. const next = input.charCodeAt(pos);
  2054. if (octalStr !== "0" || next === 56 || next === 57) {
  2055. if (inTemplate) {
  2056. return res(null);
  2057. } else {
  2058. errors.strictNumericEscape(startPos, lineStart, curLine);
  2059. }
  2060. }
  2061. return res(String.fromCharCode(octal));
  2062. }
  2063. return res(String.fromCharCode(ch));
  2064. }
  2065. }
  2066. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2067. const initialPos = pos;
  2068. let n;
  2069. ({
  2070. n,
  2071. pos
  2072. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2073. if (n === null) {
  2074. if (throwOnInvalid) {
  2075. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2076. } else {
  2077. pos = initialPos - 1;
  2078. }
  2079. }
  2080. return {
  2081. code: n,
  2082. pos
  2083. };
  2084. }
  2085. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2086. const start = pos;
  2087. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2088. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2089. let invalid = false;
  2090. let total = 0;
  2091. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2092. const code = input.charCodeAt(pos);
  2093. let val;
  2094. if (code === 95 && allowNumSeparator !== "bail") {
  2095. const prev = input.charCodeAt(pos - 1);
  2096. const next = input.charCodeAt(pos + 1);
  2097. if (!allowNumSeparator) {
  2098. if (bailOnError) return {
  2099. n: null,
  2100. pos
  2101. };
  2102. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2103. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2104. if (bailOnError) return {
  2105. n: null,
  2106. pos
  2107. };
  2108. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2109. }
  2110. ++pos;
  2111. continue;
  2112. }
  2113. if (code >= 97) {
  2114. val = code - 97 + 10;
  2115. } else if (code >= 65) {
  2116. val = code - 65 + 10;
  2117. } else if (_isDigit(code)) {
  2118. val = code - 48;
  2119. } else {
  2120. val = Infinity;
  2121. }
  2122. if (val >= radix) {
  2123. if (val <= 9 && bailOnError) {
  2124. return {
  2125. n: null,
  2126. pos
  2127. };
  2128. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2129. val = 0;
  2130. } else if (forceLen) {
  2131. val = 0;
  2132. invalid = true;
  2133. } else {
  2134. break;
  2135. }
  2136. }
  2137. ++pos;
  2138. total = total * radix + val;
  2139. }
  2140. if (pos === start || len != null && pos - start !== len || invalid) {
  2141. return {
  2142. n: null,
  2143. pos
  2144. };
  2145. }
  2146. return {
  2147. n: total,
  2148. pos
  2149. };
  2150. }
  2151. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2152. const ch = input.charCodeAt(pos);
  2153. let code;
  2154. if (ch === 123) {
  2155. ++pos;
  2156. ({
  2157. code,
  2158. pos
  2159. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2160. ++pos;
  2161. if (code !== null && code > 0x10ffff) {
  2162. if (throwOnInvalid) {
  2163. errors.invalidCodePoint(pos, lineStart, curLine);
  2164. } else {
  2165. return {
  2166. code: null,
  2167. pos
  2168. };
  2169. }
  2170. }
  2171. } else {
  2172. ({
  2173. code,
  2174. pos
  2175. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2176. }
  2177. return {
  2178. code,
  2179. pos
  2180. };
  2181. }
  2182. const _excluded = ["at"],
  2183. _excluded2 = ["at"];
  2184. function buildPosition(pos, lineStart, curLine) {
  2185. return new Position(curLine, pos - lineStart, pos);
  2186. }
  2187. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2188. class Token {
  2189. constructor(state) {
  2190. this.type = state.type;
  2191. this.value = state.value;
  2192. this.start = state.start;
  2193. this.end = state.end;
  2194. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2195. }
  2196. }
  2197. class Tokenizer extends CommentsParser {
  2198. constructor(options, input) {
  2199. super();
  2200. this.isLookahead = void 0;
  2201. this.tokens = [];
  2202. this.errorHandlers_readInt = {
  2203. invalidDigit: (pos, lineStart, curLine, radix) => {
  2204. if (!this.options.errorRecovery) return false;
  2205. this.raise(Errors.InvalidDigit, {
  2206. at: buildPosition(pos, lineStart, curLine),
  2207. radix
  2208. });
  2209. return true;
  2210. },
  2211. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2212. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2213. };
  2214. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2215. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2216. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2217. });
  2218. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2219. strictNumericEscape: (pos, lineStart, curLine) => {
  2220. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2221. at: buildPosition(pos, lineStart, curLine)
  2222. });
  2223. },
  2224. unterminated: (pos, lineStart, curLine) => {
  2225. throw this.raise(Errors.UnterminatedString, {
  2226. at: buildPosition(pos - 1, lineStart, curLine)
  2227. });
  2228. }
  2229. });
  2230. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2231. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2232. unterminated: (pos, lineStart, curLine) => {
  2233. throw this.raise(Errors.UnterminatedTemplate, {
  2234. at: buildPosition(pos, lineStart, curLine)
  2235. });
  2236. }
  2237. });
  2238. this.state = new State();
  2239. this.state.init(options);
  2240. this.input = input;
  2241. this.length = input.length;
  2242. this.isLookahead = false;
  2243. }
  2244. pushToken(token) {
  2245. this.tokens.length = this.state.tokensLength;
  2246. this.tokens.push(token);
  2247. ++this.state.tokensLength;
  2248. }
  2249. next() {
  2250. this.checkKeywordEscapes();
  2251. if (this.options.tokens) {
  2252. this.pushToken(new Token(this.state));
  2253. }
  2254. this.state.lastTokStart = this.state.start;
  2255. this.state.lastTokEndLoc = this.state.endLoc;
  2256. this.state.lastTokStartLoc = this.state.startLoc;
  2257. this.nextToken();
  2258. }
  2259. eat(type) {
  2260. if (this.match(type)) {
  2261. this.next();
  2262. return true;
  2263. } else {
  2264. return false;
  2265. }
  2266. }
  2267. match(type) {
  2268. return this.state.type === type;
  2269. }
  2270. createLookaheadState(state) {
  2271. return {
  2272. pos: state.pos,
  2273. value: null,
  2274. type: state.type,
  2275. start: state.start,
  2276. end: state.end,
  2277. context: [this.curContext()],
  2278. inType: state.inType,
  2279. startLoc: state.startLoc,
  2280. lastTokEndLoc: state.lastTokEndLoc,
  2281. curLine: state.curLine,
  2282. lineStart: state.lineStart,
  2283. curPosition: state.curPosition
  2284. };
  2285. }
  2286. lookahead() {
  2287. const old = this.state;
  2288. this.state = this.createLookaheadState(old);
  2289. this.isLookahead = true;
  2290. this.nextToken();
  2291. this.isLookahead = false;
  2292. const curr = this.state;
  2293. this.state = old;
  2294. return curr;
  2295. }
  2296. nextTokenStart() {
  2297. return this.nextTokenStartSince(this.state.pos);
  2298. }
  2299. nextTokenStartSince(pos) {
  2300. skipWhiteSpace.lastIndex = pos;
  2301. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2302. }
  2303. lookaheadCharCode() {
  2304. return this.input.charCodeAt(this.nextTokenStart());
  2305. }
  2306. nextTokenInLineStart() {
  2307. return this.nextTokenInLineStartSince(this.state.pos);
  2308. }
  2309. nextTokenInLineStartSince(pos) {
  2310. skipWhiteSpaceInLine.lastIndex = pos;
  2311. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2312. }
  2313. lookaheadInLineCharCode() {
  2314. return this.input.charCodeAt(this.nextTokenInLineStart());
  2315. }
  2316. codePointAtPos(pos) {
  2317. let cp = this.input.charCodeAt(pos);
  2318. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2319. const trail = this.input.charCodeAt(pos);
  2320. if ((trail & 0xfc00) === 0xdc00) {
  2321. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2322. }
  2323. }
  2324. return cp;
  2325. }
  2326. setStrict(strict) {
  2327. this.state.strict = strict;
  2328. if (strict) {
  2329. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
  2330. at
  2331. }));
  2332. this.state.strictErrors.clear();
  2333. }
  2334. }
  2335. curContext() {
  2336. return this.state.context[this.state.context.length - 1];
  2337. }
  2338. nextToken() {
  2339. this.skipSpace();
  2340. this.state.start = this.state.pos;
  2341. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2342. if (this.state.pos >= this.length) {
  2343. this.finishToken(139);
  2344. return;
  2345. }
  2346. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2347. }
  2348. skipBlockComment(commentEnd) {
  2349. let startLoc;
  2350. if (!this.isLookahead) startLoc = this.state.curPosition();
  2351. const start = this.state.pos;
  2352. const end = this.input.indexOf(commentEnd, start + 2);
  2353. if (end === -1) {
  2354. throw this.raise(Errors.UnterminatedComment, {
  2355. at: this.state.curPosition()
  2356. });
  2357. }
  2358. this.state.pos = end + commentEnd.length;
  2359. lineBreakG.lastIndex = start + 2;
  2360. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2361. ++this.state.curLine;
  2362. this.state.lineStart = lineBreakG.lastIndex;
  2363. }
  2364. if (this.isLookahead) return;
  2365. const comment = {
  2366. type: "CommentBlock",
  2367. value: this.input.slice(start + 2, end),
  2368. start,
  2369. end: end + commentEnd.length,
  2370. loc: new SourceLocation(startLoc, this.state.curPosition())
  2371. };
  2372. if (this.options.tokens) this.pushToken(comment);
  2373. return comment;
  2374. }
  2375. skipLineComment(startSkip) {
  2376. const start = this.state.pos;
  2377. let startLoc;
  2378. if (!this.isLookahead) startLoc = this.state.curPosition();
  2379. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2380. if (this.state.pos < this.length) {
  2381. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2382. ch = this.input.charCodeAt(this.state.pos);
  2383. }
  2384. }
  2385. if (this.isLookahead) return;
  2386. const end = this.state.pos;
  2387. const value = this.input.slice(start + startSkip, end);
  2388. const comment = {
  2389. type: "CommentLine",
  2390. value,
  2391. start,
  2392. end,
  2393. loc: new SourceLocation(startLoc, this.state.curPosition())
  2394. };
  2395. if (this.options.tokens) this.pushToken(comment);
  2396. return comment;
  2397. }
  2398. skipSpace() {
  2399. const spaceStart = this.state.pos;
  2400. const comments = [];
  2401. loop: while (this.state.pos < this.length) {
  2402. const ch = this.input.charCodeAt(this.state.pos);
  2403. switch (ch) {
  2404. case 32:
  2405. case 160:
  2406. case 9:
  2407. ++this.state.pos;
  2408. break;
  2409. case 13:
  2410. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2411. ++this.state.pos;
  2412. }
  2413. case 10:
  2414. case 8232:
  2415. case 8233:
  2416. ++this.state.pos;
  2417. ++this.state.curLine;
  2418. this.state.lineStart = this.state.pos;
  2419. break;
  2420. case 47:
  2421. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2422. case 42:
  2423. {
  2424. const comment = this.skipBlockComment("*/");
  2425. if (comment !== undefined) {
  2426. this.addComment(comment);
  2427. if (this.options.attachComment) comments.push(comment);
  2428. }
  2429. break;
  2430. }
  2431. case 47:
  2432. {
  2433. const comment = this.skipLineComment(2);
  2434. if (comment !== undefined) {
  2435. this.addComment(comment);
  2436. if (this.options.attachComment) comments.push(comment);
  2437. }
  2438. break;
  2439. }
  2440. default:
  2441. break loop;
  2442. }
  2443. break;
  2444. default:
  2445. if (isWhitespace(ch)) {
  2446. ++this.state.pos;
  2447. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  2448. const pos = this.state.pos;
  2449. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2450. const comment = this.skipLineComment(3);
  2451. if (comment !== undefined) {
  2452. this.addComment(comment);
  2453. if (this.options.attachComment) comments.push(comment);
  2454. }
  2455. } else {
  2456. break loop;
  2457. }
  2458. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  2459. const pos = this.state.pos;
  2460. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2461. const comment = this.skipLineComment(4);
  2462. if (comment !== undefined) {
  2463. this.addComment(comment);
  2464. if (this.options.attachComment) comments.push(comment);
  2465. }
  2466. } else {
  2467. break loop;
  2468. }
  2469. } else {
  2470. break loop;
  2471. }
  2472. }
  2473. }
  2474. if (comments.length > 0) {
  2475. const end = this.state.pos;
  2476. const commentWhitespace = {
  2477. start: spaceStart,
  2478. end,
  2479. comments,
  2480. leadingNode: null,
  2481. trailingNode: null,
  2482. containingNode: null
  2483. };
  2484. this.state.commentStack.push(commentWhitespace);
  2485. }
  2486. }
  2487. finishToken(type, val) {
  2488. this.state.end = this.state.pos;
  2489. this.state.endLoc = this.state.curPosition();
  2490. const prevType = this.state.type;
  2491. this.state.type = type;
  2492. this.state.value = val;
  2493. if (!this.isLookahead) {
  2494. this.updateContext(prevType);
  2495. }
  2496. }
  2497. replaceToken(type) {
  2498. this.state.type = type;
  2499. this.updateContext();
  2500. }
  2501. readToken_numberSign() {
  2502. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2503. return;
  2504. }
  2505. const nextPos = this.state.pos + 1;
  2506. const next = this.codePointAtPos(nextPos);
  2507. if (next >= 48 && next <= 57) {
  2508. throw this.raise(Errors.UnexpectedDigitAfterHash, {
  2509. at: this.state.curPosition()
  2510. });
  2511. }
  2512. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2513. this.expectPlugin("recordAndTuple");
  2514. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2515. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
  2516. at: this.state.curPosition()
  2517. });
  2518. }
  2519. this.state.pos += 2;
  2520. if (next === 123) {
  2521. this.finishToken(7);
  2522. } else {
  2523. this.finishToken(1);
  2524. }
  2525. } else if (isIdentifierStart(next)) {
  2526. ++this.state.pos;
  2527. this.finishToken(138, this.readWord1(next));
  2528. } else if (next === 92) {
  2529. ++this.state.pos;
  2530. this.finishToken(138, this.readWord1());
  2531. } else {
  2532. this.finishOp(27, 1);
  2533. }
  2534. }
  2535. readToken_dot() {
  2536. const next = this.input.charCodeAt(this.state.pos + 1);
  2537. if (next >= 48 && next <= 57) {
  2538. this.readNumber(true);
  2539. return;
  2540. }
  2541. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2542. this.state.pos += 3;
  2543. this.finishToken(21);
  2544. } else {
  2545. ++this.state.pos;
  2546. this.finishToken(16);
  2547. }
  2548. }
  2549. readToken_slash() {
  2550. const next = this.input.charCodeAt(this.state.pos + 1);
  2551. if (next === 61) {
  2552. this.finishOp(31, 2);
  2553. } else {
  2554. this.finishOp(56, 1);
  2555. }
  2556. }
  2557. readToken_interpreter() {
  2558. if (this.state.pos !== 0 || this.length < 2) return false;
  2559. let ch = this.input.charCodeAt(this.state.pos + 1);
  2560. if (ch !== 33) return false;
  2561. const start = this.state.pos;
  2562. this.state.pos += 1;
  2563. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2564. ch = this.input.charCodeAt(this.state.pos);
  2565. }
  2566. const value = this.input.slice(start + 2, this.state.pos);
  2567. this.finishToken(28, value);
  2568. return true;
  2569. }
  2570. readToken_mult_modulo(code) {
  2571. let type = code === 42 ? 55 : 54;
  2572. let width = 1;
  2573. let next = this.input.charCodeAt(this.state.pos + 1);
  2574. if (code === 42 && next === 42) {
  2575. width++;
  2576. next = this.input.charCodeAt(this.state.pos + 2);
  2577. type = 57;
  2578. }
  2579. if (next === 61 && !this.state.inType) {
  2580. width++;
  2581. type = code === 37 ? 33 : 30;
  2582. }
  2583. this.finishOp(type, width);
  2584. }
  2585. readToken_pipe_amp(code) {
  2586. const next = this.input.charCodeAt(this.state.pos + 1);
  2587. if (next === code) {
  2588. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2589. this.finishOp(30, 3);
  2590. } else {
  2591. this.finishOp(code === 124 ? 41 : 42, 2);
  2592. }
  2593. return;
  2594. }
  2595. if (code === 124) {
  2596. if (next === 62) {
  2597. this.finishOp(39, 2);
  2598. return;
  2599. }
  2600. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2601. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2602. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
  2603. at: this.state.curPosition()
  2604. });
  2605. }
  2606. this.state.pos += 2;
  2607. this.finishToken(9);
  2608. return;
  2609. }
  2610. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2611. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2612. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
  2613. at: this.state.curPosition()
  2614. });
  2615. }
  2616. this.state.pos += 2;
  2617. this.finishToken(4);
  2618. return;
  2619. }
  2620. }
  2621. if (next === 61) {
  2622. this.finishOp(30, 2);
  2623. return;
  2624. }
  2625. this.finishOp(code === 124 ? 43 : 45, 1);
  2626. }
  2627. readToken_caret() {
  2628. const next = this.input.charCodeAt(this.state.pos + 1);
  2629. if (next === 61 && !this.state.inType) {
  2630. this.finishOp(32, 2);
  2631. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2632. proposal: "hack",
  2633. topicToken: "^^"
  2634. }])) {
  2635. this.finishOp(37, 2);
  2636. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2637. if (lookaheadCh === 94) {
  2638. this.unexpected();
  2639. }
  2640. } else {
  2641. this.finishOp(44, 1);
  2642. }
  2643. }
  2644. readToken_atSign() {
  2645. const next = this.input.charCodeAt(this.state.pos + 1);
  2646. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2647. proposal: "hack",
  2648. topicToken: "@@"
  2649. }])) {
  2650. this.finishOp(38, 2);
  2651. } else {
  2652. this.finishOp(26, 1);
  2653. }
  2654. }
  2655. readToken_plus_min(code) {
  2656. const next = this.input.charCodeAt(this.state.pos + 1);
  2657. if (next === code) {
  2658. this.finishOp(34, 2);
  2659. return;
  2660. }
  2661. if (next === 61) {
  2662. this.finishOp(30, 2);
  2663. } else {
  2664. this.finishOp(53, 1);
  2665. }
  2666. }
  2667. readToken_lt() {
  2668. const {
  2669. pos
  2670. } = this.state;
  2671. const next = this.input.charCodeAt(pos + 1);
  2672. if (next === 60) {
  2673. if (this.input.charCodeAt(pos + 2) === 61) {
  2674. this.finishOp(30, 3);
  2675. return;
  2676. }
  2677. this.finishOp(51, 2);
  2678. return;
  2679. }
  2680. if (next === 61) {
  2681. this.finishOp(49, 2);
  2682. return;
  2683. }
  2684. this.finishOp(47, 1);
  2685. }
  2686. readToken_gt() {
  2687. const {
  2688. pos
  2689. } = this.state;
  2690. const next = this.input.charCodeAt(pos + 1);
  2691. if (next === 62) {
  2692. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2693. if (this.input.charCodeAt(pos + size) === 61) {
  2694. this.finishOp(30, size + 1);
  2695. return;
  2696. }
  2697. this.finishOp(52, size);
  2698. return;
  2699. }
  2700. if (next === 61) {
  2701. this.finishOp(49, 2);
  2702. return;
  2703. }
  2704. this.finishOp(48, 1);
  2705. }
  2706. readToken_eq_excl(code) {
  2707. const next = this.input.charCodeAt(this.state.pos + 1);
  2708. if (next === 61) {
  2709. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2710. return;
  2711. }
  2712. if (code === 61 && next === 62) {
  2713. this.state.pos += 2;
  2714. this.finishToken(19);
  2715. return;
  2716. }
  2717. this.finishOp(code === 61 ? 29 : 35, 1);
  2718. }
  2719. readToken_question() {
  2720. const next = this.input.charCodeAt(this.state.pos + 1);
  2721. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2722. if (next === 63) {
  2723. if (next2 === 61) {
  2724. this.finishOp(30, 3);
  2725. } else {
  2726. this.finishOp(40, 2);
  2727. }
  2728. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2729. this.state.pos += 2;
  2730. this.finishToken(18);
  2731. } else {
  2732. ++this.state.pos;
  2733. this.finishToken(17);
  2734. }
  2735. }
  2736. getTokenFromCode(code) {
  2737. switch (code) {
  2738. case 46:
  2739. this.readToken_dot();
  2740. return;
  2741. case 40:
  2742. ++this.state.pos;
  2743. this.finishToken(10);
  2744. return;
  2745. case 41:
  2746. ++this.state.pos;
  2747. this.finishToken(11);
  2748. return;
  2749. case 59:
  2750. ++this.state.pos;
  2751. this.finishToken(13);
  2752. return;
  2753. case 44:
  2754. ++this.state.pos;
  2755. this.finishToken(12);
  2756. return;
  2757. case 91:
  2758. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2759. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2760. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
  2761. at: this.state.curPosition()
  2762. });
  2763. }
  2764. this.state.pos += 2;
  2765. this.finishToken(2);
  2766. } else {
  2767. ++this.state.pos;
  2768. this.finishToken(0);
  2769. }
  2770. return;
  2771. case 93:
  2772. ++this.state.pos;
  2773. this.finishToken(3);
  2774. return;
  2775. case 123:
  2776. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2777. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2778. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
  2779. at: this.state.curPosition()
  2780. });
  2781. }
  2782. this.state.pos += 2;
  2783. this.finishToken(6);
  2784. } else {
  2785. ++this.state.pos;
  2786. this.finishToken(5);
  2787. }
  2788. return;
  2789. case 125:
  2790. ++this.state.pos;
  2791. this.finishToken(8);
  2792. return;
  2793. case 58:
  2794. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2795. this.finishOp(15, 2);
  2796. } else {
  2797. ++this.state.pos;
  2798. this.finishToken(14);
  2799. }
  2800. return;
  2801. case 63:
  2802. this.readToken_question();
  2803. return;
  2804. case 96:
  2805. this.readTemplateToken();
  2806. return;
  2807. case 48:
  2808. {
  2809. const next = this.input.charCodeAt(this.state.pos + 1);
  2810. if (next === 120 || next === 88) {
  2811. this.readRadixNumber(16);
  2812. return;
  2813. }
  2814. if (next === 111 || next === 79) {
  2815. this.readRadixNumber(8);
  2816. return;
  2817. }
  2818. if (next === 98 || next === 66) {
  2819. this.readRadixNumber(2);
  2820. return;
  2821. }
  2822. }
  2823. case 49:
  2824. case 50:
  2825. case 51:
  2826. case 52:
  2827. case 53:
  2828. case 54:
  2829. case 55:
  2830. case 56:
  2831. case 57:
  2832. this.readNumber(false);
  2833. return;
  2834. case 34:
  2835. case 39:
  2836. this.readString(code);
  2837. return;
  2838. case 47:
  2839. this.readToken_slash();
  2840. return;
  2841. case 37:
  2842. case 42:
  2843. this.readToken_mult_modulo(code);
  2844. return;
  2845. case 124:
  2846. case 38:
  2847. this.readToken_pipe_amp(code);
  2848. return;
  2849. case 94:
  2850. this.readToken_caret();
  2851. return;
  2852. case 43:
  2853. case 45:
  2854. this.readToken_plus_min(code);
  2855. return;
  2856. case 60:
  2857. this.readToken_lt();
  2858. return;
  2859. case 62:
  2860. this.readToken_gt();
  2861. return;
  2862. case 61:
  2863. case 33:
  2864. this.readToken_eq_excl(code);
  2865. return;
  2866. case 126:
  2867. this.finishOp(36, 1);
  2868. return;
  2869. case 64:
  2870. this.readToken_atSign();
  2871. return;
  2872. case 35:
  2873. this.readToken_numberSign();
  2874. return;
  2875. case 92:
  2876. this.readWord();
  2877. return;
  2878. default:
  2879. if (isIdentifierStart(code)) {
  2880. this.readWord(code);
  2881. return;
  2882. }
  2883. }
  2884. throw this.raise(Errors.InvalidOrUnexpectedToken, {
  2885. at: this.state.curPosition(),
  2886. unexpected: String.fromCodePoint(code)
  2887. });
  2888. }
  2889. finishOp(type, size) {
  2890. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2891. this.state.pos += size;
  2892. this.finishToken(type, str);
  2893. }
  2894. readRegexp() {
  2895. const startLoc = this.state.startLoc;
  2896. const start = this.state.start + 1;
  2897. let escaped, inClass;
  2898. let {
  2899. pos
  2900. } = this.state;
  2901. for (;; ++pos) {
  2902. if (pos >= this.length) {
  2903. throw this.raise(Errors.UnterminatedRegExp, {
  2904. at: createPositionWithColumnOffset(startLoc, 1)
  2905. });
  2906. }
  2907. const ch = this.input.charCodeAt(pos);
  2908. if (isNewLine(ch)) {
  2909. throw this.raise(Errors.UnterminatedRegExp, {
  2910. at: createPositionWithColumnOffset(startLoc, 1)
  2911. });
  2912. }
  2913. if (escaped) {
  2914. escaped = false;
  2915. } else {
  2916. if (ch === 91) {
  2917. inClass = true;
  2918. } else if (ch === 93 && inClass) {
  2919. inClass = false;
  2920. } else if (ch === 47 && !inClass) {
  2921. break;
  2922. }
  2923. escaped = ch === 92;
  2924. }
  2925. }
  2926. const content = this.input.slice(start, pos);
  2927. ++pos;
  2928. let mods = "";
  2929. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  2930. while (pos < this.length) {
  2931. const cp = this.codePointAtPos(pos);
  2932. const char = String.fromCharCode(cp);
  2933. if (VALID_REGEX_FLAGS.has(cp)) {
  2934. if (cp === 118) {
  2935. if (mods.includes("u")) {
  2936. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2937. at: nextPos()
  2938. });
  2939. }
  2940. } else if (cp === 117) {
  2941. if (mods.includes("v")) {
  2942. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2943. at: nextPos()
  2944. });
  2945. }
  2946. }
  2947. if (mods.includes(char)) {
  2948. this.raise(Errors.DuplicateRegExpFlags, {
  2949. at: nextPos()
  2950. });
  2951. }
  2952. } else if (isIdentifierChar(cp) || cp === 92) {
  2953. this.raise(Errors.MalformedRegExpFlags, {
  2954. at: nextPos()
  2955. });
  2956. } else {
  2957. break;
  2958. }
  2959. ++pos;
  2960. mods += char;
  2961. }
  2962. this.state.pos = pos;
  2963. this.finishToken(137, {
  2964. pattern: content,
  2965. flags: mods
  2966. });
  2967. }
  2968. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  2969. const {
  2970. n,
  2971. pos
  2972. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  2973. this.state.pos = pos;
  2974. return n;
  2975. }
  2976. readRadixNumber(radix) {
  2977. const startLoc = this.state.curPosition();
  2978. let isBigInt = false;
  2979. this.state.pos += 2;
  2980. const val = this.readInt(radix);
  2981. if (val == null) {
  2982. this.raise(Errors.InvalidDigit, {
  2983. at: createPositionWithColumnOffset(startLoc, 2),
  2984. radix
  2985. });
  2986. }
  2987. const next = this.input.charCodeAt(this.state.pos);
  2988. if (next === 110) {
  2989. ++this.state.pos;
  2990. isBigInt = true;
  2991. } else if (next === 109) {
  2992. throw this.raise(Errors.InvalidDecimal, {
  2993. at: startLoc
  2994. });
  2995. }
  2996. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  2997. throw this.raise(Errors.NumberIdentifier, {
  2998. at: this.state.curPosition()
  2999. });
  3000. }
  3001. if (isBigInt) {
  3002. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  3003. this.finishToken(135, str);
  3004. return;
  3005. }
  3006. this.finishToken(134, val);
  3007. }
  3008. readNumber(startsWithDot) {
  3009. const start = this.state.pos;
  3010. const startLoc = this.state.curPosition();
  3011. let isFloat = false;
  3012. let isBigInt = false;
  3013. let isDecimal = false;
  3014. let hasExponent = false;
  3015. let isOctal = false;
  3016. if (!startsWithDot && this.readInt(10) === null) {
  3017. this.raise(Errors.InvalidNumber, {
  3018. at: this.state.curPosition()
  3019. });
  3020. }
  3021. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3022. if (hasLeadingZero) {
  3023. const integer = this.input.slice(start, this.state.pos);
  3024. this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
  3025. at: startLoc
  3026. });
  3027. if (!this.state.strict) {
  3028. const underscorePos = integer.indexOf("_");
  3029. if (underscorePos > 0) {
  3030. this.raise(Errors.ZeroDigitNumericSeparator, {
  3031. at: createPositionWithColumnOffset(startLoc, underscorePos)
  3032. });
  3033. }
  3034. }
  3035. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3036. }
  3037. let next = this.input.charCodeAt(this.state.pos);
  3038. if (next === 46 && !isOctal) {
  3039. ++this.state.pos;
  3040. this.readInt(10);
  3041. isFloat = true;
  3042. next = this.input.charCodeAt(this.state.pos);
  3043. }
  3044. if ((next === 69 || next === 101) && !isOctal) {
  3045. next = this.input.charCodeAt(++this.state.pos);
  3046. if (next === 43 || next === 45) {
  3047. ++this.state.pos;
  3048. }
  3049. if (this.readInt(10) === null) {
  3050. this.raise(Errors.InvalidOrMissingExponent, {
  3051. at: startLoc
  3052. });
  3053. }
  3054. isFloat = true;
  3055. hasExponent = true;
  3056. next = this.input.charCodeAt(this.state.pos);
  3057. }
  3058. if (next === 110) {
  3059. if (isFloat || hasLeadingZero) {
  3060. this.raise(Errors.InvalidBigIntLiteral, {
  3061. at: startLoc
  3062. });
  3063. }
  3064. ++this.state.pos;
  3065. isBigInt = true;
  3066. }
  3067. if (next === 109) {
  3068. this.expectPlugin("decimal", this.state.curPosition());
  3069. if (hasExponent || hasLeadingZero) {
  3070. this.raise(Errors.InvalidDecimal, {
  3071. at: startLoc
  3072. });
  3073. }
  3074. ++this.state.pos;
  3075. isDecimal = true;
  3076. }
  3077. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3078. throw this.raise(Errors.NumberIdentifier, {
  3079. at: this.state.curPosition()
  3080. });
  3081. }
  3082. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3083. if (isBigInt) {
  3084. this.finishToken(135, str);
  3085. return;
  3086. }
  3087. if (isDecimal) {
  3088. this.finishToken(136, str);
  3089. return;
  3090. }
  3091. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3092. this.finishToken(134, val);
  3093. }
  3094. readCodePoint(throwOnInvalid) {
  3095. const {
  3096. code,
  3097. pos
  3098. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3099. this.state.pos = pos;
  3100. return code;
  3101. }
  3102. readString(quote) {
  3103. const {
  3104. str,
  3105. pos,
  3106. curLine,
  3107. lineStart
  3108. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3109. this.state.pos = pos + 1;
  3110. this.state.lineStart = lineStart;
  3111. this.state.curLine = curLine;
  3112. this.finishToken(133, str);
  3113. }
  3114. readTemplateContinuation() {
  3115. if (!this.match(8)) {
  3116. this.unexpected(null, 8);
  3117. }
  3118. this.state.pos--;
  3119. this.readTemplateToken();
  3120. }
  3121. readTemplateToken() {
  3122. const opening = this.input[this.state.pos];
  3123. const {
  3124. str,
  3125. firstInvalidLoc,
  3126. pos,
  3127. curLine,
  3128. lineStart
  3129. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3130. this.state.pos = pos + 1;
  3131. this.state.lineStart = lineStart;
  3132. this.state.curLine = curLine;
  3133. if (firstInvalidLoc) {
  3134. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3135. }
  3136. if (this.input.codePointAt(pos) === 96) {
  3137. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3138. } else {
  3139. this.state.pos++;
  3140. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3141. }
  3142. }
  3143. recordStrictModeErrors(toParseError, {
  3144. at
  3145. }) {
  3146. const index = at.index;
  3147. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3148. this.raise(toParseError, {
  3149. at
  3150. });
  3151. } else {
  3152. this.state.strictErrors.set(index, [toParseError, at]);
  3153. }
  3154. }
  3155. readWord1(firstCode) {
  3156. this.state.containsEsc = false;
  3157. let word = "";
  3158. const start = this.state.pos;
  3159. let chunkStart = this.state.pos;
  3160. if (firstCode !== undefined) {
  3161. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3162. }
  3163. while (this.state.pos < this.length) {
  3164. const ch = this.codePointAtPos(this.state.pos);
  3165. if (isIdentifierChar(ch)) {
  3166. this.state.pos += ch <= 0xffff ? 1 : 2;
  3167. } else if (ch === 92) {
  3168. this.state.containsEsc = true;
  3169. word += this.input.slice(chunkStart, this.state.pos);
  3170. const escStart = this.state.curPosition();
  3171. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3172. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3173. this.raise(Errors.MissingUnicodeEscape, {
  3174. at: this.state.curPosition()
  3175. });
  3176. chunkStart = this.state.pos - 1;
  3177. continue;
  3178. }
  3179. ++this.state.pos;
  3180. const esc = this.readCodePoint(true);
  3181. if (esc !== null) {
  3182. if (!identifierCheck(esc)) {
  3183. this.raise(Errors.EscapedCharNotAnIdentifier, {
  3184. at: escStart
  3185. });
  3186. }
  3187. word += String.fromCodePoint(esc);
  3188. }
  3189. chunkStart = this.state.pos;
  3190. } else {
  3191. break;
  3192. }
  3193. }
  3194. return word + this.input.slice(chunkStart, this.state.pos);
  3195. }
  3196. readWord(firstCode) {
  3197. const word = this.readWord1(firstCode);
  3198. const type = keywords$1.get(word);
  3199. if (type !== undefined) {
  3200. this.finishToken(type, tokenLabelName(type));
  3201. } else {
  3202. this.finishToken(132, word);
  3203. }
  3204. }
  3205. checkKeywordEscapes() {
  3206. const {
  3207. type
  3208. } = this.state;
  3209. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3210. this.raise(Errors.InvalidEscapedReservedWord, {
  3211. at: this.state.startLoc,
  3212. reservedWord: tokenLabelName(type)
  3213. });
  3214. }
  3215. }
  3216. raise(toParseError, raiseProperties) {
  3217. const {
  3218. at
  3219. } = raiseProperties,
  3220. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
  3221. const loc = at instanceof Position ? at : at.loc.start;
  3222. const error = toParseError({
  3223. loc,
  3224. details
  3225. });
  3226. if (!this.options.errorRecovery) throw error;
  3227. if (!this.isLookahead) this.state.errors.push(error);
  3228. return error;
  3229. }
  3230. raiseOverwrite(toParseError, raiseProperties) {
  3231. const {
  3232. at
  3233. } = raiseProperties,
  3234. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
  3235. const loc = at instanceof Position ? at : at.loc.start;
  3236. const pos = loc.index;
  3237. const errors = this.state.errors;
  3238. for (let i = errors.length - 1; i >= 0; i--) {
  3239. const error = errors[i];
  3240. if (error.loc.index === pos) {
  3241. return errors[i] = toParseError({
  3242. loc,
  3243. details
  3244. });
  3245. }
  3246. if (error.loc.index < pos) break;
  3247. }
  3248. return this.raise(toParseError, raiseProperties);
  3249. }
  3250. updateContext(prevType) {}
  3251. unexpected(loc, type) {
  3252. throw this.raise(Errors.UnexpectedToken, {
  3253. expected: type ? tokenLabelName(type) : null,
  3254. at: loc != null ? loc : this.state.startLoc
  3255. });
  3256. }
  3257. expectPlugin(pluginName, loc) {
  3258. if (this.hasPlugin(pluginName)) {
  3259. return true;
  3260. }
  3261. throw this.raise(Errors.MissingPlugin, {
  3262. at: loc != null ? loc : this.state.startLoc,
  3263. missingPlugin: [pluginName]
  3264. });
  3265. }
  3266. expectOnePlugin(pluginNames) {
  3267. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3268. throw this.raise(Errors.MissingOneOfPlugins, {
  3269. at: this.state.startLoc,
  3270. missingPlugin: pluginNames
  3271. });
  3272. }
  3273. }
  3274. errorBuilder(error) {
  3275. return (pos, lineStart, curLine) => {
  3276. this.raise(error, {
  3277. at: buildPosition(pos, lineStart, curLine)
  3278. });
  3279. };
  3280. }
  3281. }
  3282. class ClassScope {
  3283. constructor() {
  3284. this.privateNames = new Set();
  3285. this.loneAccessors = new Map();
  3286. this.undefinedPrivateNames = new Map();
  3287. }
  3288. }
  3289. class ClassScopeHandler {
  3290. constructor(parser) {
  3291. this.parser = void 0;
  3292. this.stack = [];
  3293. this.undefinedPrivateNames = new Map();
  3294. this.parser = parser;
  3295. }
  3296. current() {
  3297. return this.stack[this.stack.length - 1];
  3298. }
  3299. enter() {
  3300. this.stack.push(new ClassScope());
  3301. }
  3302. exit() {
  3303. const oldClassScope = this.stack.pop();
  3304. const current = this.current();
  3305. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3306. if (current) {
  3307. if (!current.undefinedPrivateNames.has(name)) {
  3308. current.undefinedPrivateNames.set(name, loc);
  3309. }
  3310. } else {
  3311. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3312. at: loc,
  3313. identifierName: name
  3314. });
  3315. }
  3316. }
  3317. }
  3318. declarePrivateName(name, elementType, loc) {
  3319. const {
  3320. privateNames,
  3321. loneAccessors,
  3322. undefinedPrivateNames
  3323. } = this.current();
  3324. let redefined = privateNames.has(name);
  3325. if (elementType & 3) {
  3326. const accessor = redefined && loneAccessors.get(name);
  3327. if (accessor) {
  3328. const oldStatic = accessor & 4;
  3329. const newStatic = elementType & 4;
  3330. const oldKind = accessor & 3;
  3331. const newKind = elementType & 3;
  3332. redefined = oldKind === newKind || oldStatic !== newStatic;
  3333. if (!redefined) loneAccessors.delete(name);
  3334. } else if (!redefined) {
  3335. loneAccessors.set(name, elementType);
  3336. }
  3337. }
  3338. if (redefined) {
  3339. this.parser.raise(Errors.PrivateNameRedeclaration, {
  3340. at: loc,
  3341. identifierName: name
  3342. });
  3343. }
  3344. privateNames.add(name);
  3345. undefinedPrivateNames.delete(name);
  3346. }
  3347. usePrivateName(name, loc) {
  3348. let classScope;
  3349. for (classScope of this.stack) {
  3350. if (classScope.privateNames.has(name)) return;
  3351. }
  3352. if (classScope) {
  3353. classScope.undefinedPrivateNames.set(name, loc);
  3354. } else {
  3355. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3356. at: loc,
  3357. identifierName: name
  3358. });
  3359. }
  3360. }
  3361. }
  3362. class ExpressionScope {
  3363. constructor(type = 0) {
  3364. this.type = type;
  3365. }
  3366. canBeArrowParameterDeclaration() {
  3367. return this.type === 2 || this.type === 1;
  3368. }
  3369. isCertainlyParameterDeclaration() {
  3370. return this.type === 3;
  3371. }
  3372. }
  3373. class ArrowHeadParsingScope extends ExpressionScope {
  3374. constructor(type) {
  3375. super(type);
  3376. this.declarationErrors = new Map();
  3377. }
  3378. recordDeclarationError(ParsingErrorClass, {
  3379. at
  3380. }) {
  3381. const index = at.index;
  3382. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3383. }
  3384. clearDeclarationError(index) {
  3385. this.declarationErrors.delete(index);
  3386. }
  3387. iterateErrors(iterator) {
  3388. this.declarationErrors.forEach(iterator);
  3389. }
  3390. }
  3391. class ExpressionScopeHandler {
  3392. constructor(parser) {
  3393. this.parser = void 0;
  3394. this.stack = [new ExpressionScope()];
  3395. this.parser = parser;
  3396. }
  3397. enter(scope) {
  3398. this.stack.push(scope);
  3399. }
  3400. exit() {
  3401. this.stack.pop();
  3402. }
  3403. recordParameterInitializerError(toParseError, {
  3404. at: node
  3405. }) {
  3406. const origin = {
  3407. at: node.loc.start
  3408. };
  3409. const {
  3410. stack
  3411. } = this;
  3412. let i = stack.length - 1;
  3413. let scope = stack[i];
  3414. while (!scope.isCertainlyParameterDeclaration()) {
  3415. if (scope.canBeArrowParameterDeclaration()) {
  3416. scope.recordDeclarationError(toParseError, origin);
  3417. } else {
  3418. return;
  3419. }
  3420. scope = stack[--i];
  3421. }
  3422. this.parser.raise(toParseError, origin);
  3423. }
  3424. recordArrowParameterBindingError(error, {
  3425. at: node
  3426. }) {
  3427. const {
  3428. stack
  3429. } = this;
  3430. const scope = stack[stack.length - 1];
  3431. const origin = {
  3432. at: node.loc.start
  3433. };
  3434. if (scope.isCertainlyParameterDeclaration()) {
  3435. this.parser.raise(error, origin);
  3436. } else if (scope.canBeArrowParameterDeclaration()) {
  3437. scope.recordDeclarationError(error, origin);
  3438. } else {
  3439. return;
  3440. }
  3441. }
  3442. recordAsyncArrowParametersError({
  3443. at
  3444. }) {
  3445. const {
  3446. stack
  3447. } = this;
  3448. let i = stack.length - 1;
  3449. let scope = stack[i];
  3450. while (scope.canBeArrowParameterDeclaration()) {
  3451. if (scope.type === 2) {
  3452. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
  3453. at
  3454. });
  3455. }
  3456. scope = stack[--i];
  3457. }
  3458. }
  3459. validateAsPattern() {
  3460. const {
  3461. stack
  3462. } = this;
  3463. const currentScope = stack[stack.length - 1];
  3464. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3465. currentScope.iterateErrors(([toParseError, loc]) => {
  3466. this.parser.raise(toParseError, {
  3467. at: loc
  3468. });
  3469. let i = stack.length - 2;
  3470. let scope = stack[i];
  3471. while (scope.canBeArrowParameterDeclaration()) {
  3472. scope.clearDeclarationError(loc.index);
  3473. scope = stack[--i];
  3474. }
  3475. });
  3476. }
  3477. }
  3478. function newParameterDeclarationScope() {
  3479. return new ExpressionScope(3);
  3480. }
  3481. function newArrowHeadScope() {
  3482. return new ArrowHeadParsingScope(1);
  3483. }
  3484. function newAsyncArrowScope() {
  3485. return new ArrowHeadParsingScope(2);
  3486. }
  3487. function newExpressionScope() {
  3488. return new ExpressionScope();
  3489. }
  3490. class ProductionParameterHandler {
  3491. constructor() {
  3492. this.stacks = [];
  3493. }
  3494. enter(flags) {
  3495. this.stacks.push(flags);
  3496. }
  3497. exit() {
  3498. this.stacks.pop();
  3499. }
  3500. currentFlags() {
  3501. return this.stacks[this.stacks.length - 1];
  3502. }
  3503. get hasAwait() {
  3504. return (this.currentFlags() & 2) > 0;
  3505. }
  3506. get hasYield() {
  3507. return (this.currentFlags() & 1) > 0;
  3508. }
  3509. get hasReturn() {
  3510. return (this.currentFlags() & 4) > 0;
  3511. }
  3512. get hasIn() {
  3513. return (this.currentFlags() & 8) > 0;
  3514. }
  3515. }
  3516. function functionFlags(isAsync, isGenerator) {
  3517. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  3518. }
  3519. class UtilParser extends Tokenizer {
  3520. addExtra(node, key, value, enumerable = true) {
  3521. if (!node) return;
  3522. const extra = node.extra = node.extra || {};
  3523. if (enumerable) {
  3524. extra[key] = value;
  3525. } else {
  3526. Object.defineProperty(extra, key, {
  3527. enumerable,
  3528. value
  3529. });
  3530. }
  3531. }
  3532. isContextual(token) {
  3533. return this.state.type === token && !this.state.containsEsc;
  3534. }
  3535. isUnparsedContextual(nameStart, name) {
  3536. const nameEnd = nameStart + name.length;
  3537. if (this.input.slice(nameStart, nameEnd) === name) {
  3538. const nextCh = this.input.charCodeAt(nameEnd);
  3539. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3540. }
  3541. return false;
  3542. }
  3543. isLookaheadContextual(name) {
  3544. const next = this.nextTokenStart();
  3545. return this.isUnparsedContextual(next, name);
  3546. }
  3547. eatContextual(token) {
  3548. if (this.isContextual(token)) {
  3549. this.next();
  3550. return true;
  3551. }
  3552. return false;
  3553. }
  3554. expectContextual(token, toParseError) {
  3555. if (!this.eatContextual(token)) {
  3556. if (toParseError != null) {
  3557. throw this.raise(toParseError, {
  3558. at: this.state.startLoc
  3559. });
  3560. }
  3561. this.unexpected(null, token);
  3562. }
  3563. }
  3564. canInsertSemicolon() {
  3565. return this.match(139) || this.match(8) || this.hasPrecedingLineBreak();
  3566. }
  3567. hasPrecedingLineBreak() {
  3568. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  3569. }
  3570. hasFollowingLineBreak() {
  3571. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  3572. return skipWhiteSpaceToLineBreak.test(this.input);
  3573. }
  3574. isLineTerminator() {
  3575. return this.eat(13) || this.canInsertSemicolon();
  3576. }
  3577. semicolon(allowAsi = true) {
  3578. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3579. this.raise(Errors.MissingSemicolon, {
  3580. at: this.state.lastTokEndLoc
  3581. });
  3582. }
  3583. expect(type, loc) {
  3584. this.eat(type) || this.unexpected(loc, type);
  3585. }
  3586. tryParse(fn, oldState = this.state.clone()) {
  3587. const abortSignal = {
  3588. node: null
  3589. };
  3590. try {
  3591. const node = fn((node = null) => {
  3592. abortSignal.node = node;
  3593. throw abortSignal;
  3594. });
  3595. if (this.state.errors.length > oldState.errors.length) {
  3596. const failState = this.state;
  3597. this.state = oldState;
  3598. this.state.tokensLength = failState.tokensLength;
  3599. return {
  3600. node,
  3601. error: failState.errors[oldState.errors.length],
  3602. thrown: false,
  3603. aborted: false,
  3604. failState
  3605. };
  3606. }
  3607. return {
  3608. node,
  3609. error: null,
  3610. thrown: false,
  3611. aborted: false,
  3612. failState: null
  3613. };
  3614. } catch (error) {
  3615. const failState = this.state;
  3616. this.state = oldState;
  3617. if (error instanceof SyntaxError) {
  3618. return {
  3619. node: null,
  3620. error,
  3621. thrown: true,
  3622. aborted: false,
  3623. failState
  3624. };
  3625. }
  3626. if (error === abortSignal) {
  3627. return {
  3628. node: abortSignal.node,
  3629. error: null,
  3630. thrown: false,
  3631. aborted: true,
  3632. failState
  3633. };
  3634. }
  3635. throw error;
  3636. }
  3637. }
  3638. checkExpressionErrors(refExpressionErrors, andThrow) {
  3639. if (!refExpressionErrors) return false;
  3640. const {
  3641. shorthandAssignLoc,
  3642. doubleProtoLoc,
  3643. privateKeyLoc,
  3644. optionalParametersLoc
  3645. } = refExpressionErrors;
  3646. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3647. if (!andThrow) {
  3648. return hasErrors;
  3649. }
  3650. if (shorthandAssignLoc != null) {
  3651. this.raise(Errors.InvalidCoverInitializedName, {
  3652. at: shorthandAssignLoc
  3653. });
  3654. }
  3655. if (doubleProtoLoc != null) {
  3656. this.raise(Errors.DuplicateProto, {
  3657. at: doubleProtoLoc
  3658. });
  3659. }
  3660. if (privateKeyLoc != null) {
  3661. this.raise(Errors.UnexpectedPrivateField, {
  3662. at: privateKeyLoc
  3663. });
  3664. }
  3665. if (optionalParametersLoc != null) {
  3666. this.unexpected(optionalParametersLoc);
  3667. }
  3668. }
  3669. isLiteralPropertyName() {
  3670. return tokenIsLiteralPropertyName(this.state.type);
  3671. }
  3672. isPrivateName(node) {
  3673. return node.type === "PrivateName";
  3674. }
  3675. getPrivateNameSV(node) {
  3676. return node.id.name;
  3677. }
  3678. hasPropertyAsPrivateName(node) {
  3679. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3680. }
  3681. isObjectProperty(node) {
  3682. return node.type === "ObjectProperty";
  3683. }
  3684. isObjectMethod(node) {
  3685. return node.type === "ObjectMethod";
  3686. }
  3687. initializeScopes(inModule = this.options.sourceType === "module") {
  3688. const oldLabels = this.state.labels;
  3689. this.state.labels = [];
  3690. const oldExportedIdentifiers = this.exportedIdentifiers;
  3691. this.exportedIdentifiers = new Set();
  3692. const oldInModule = this.inModule;
  3693. this.inModule = inModule;
  3694. const oldScope = this.scope;
  3695. const ScopeHandler = this.getScopeHandler();
  3696. this.scope = new ScopeHandler(this, inModule);
  3697. const oldProdParam = this.prodParam;
  3698. this.prodParam = new ProductionParameterHandler();
  3699. const oldClassScope = this.classScope;
  3700. this.classScope = new ClassScopeHandler(this);
  3701. const oldExpressionScope = this.expressionScope;
  3702. this.expressionScope = new ExpressionScopeHandler(this);
  3703. return () => {
  3704. this.state.labels = oldLabels;
  3705. this.exportedIdentifiers = oldExportedIdentifiers;
  3706. this.inModule = oldInModule;
  3707. this.scope = oldScope;
  3708. this.prodParam = oldProdParam;
  3709. this.classScope = oldClassScope;
  3710. this.expressionScope = oldExpressionScope;
  3711. };
  3712. }
  3713. enterInitialScopes() {
  3714. let paramFlags = 0;
  3715. if (this.inModule) {
  3716. paramFlags |= 2;
  3717. }
  3718. this.scope.enter(1);
  3719. this.prodParam.enter(paramFlags);
  3720. }
  3721. checkDestructuringPrivate(refExpressionErrors) {
  3722. const {
  3723. privateKeyLoc
  3724. } = refExpressionErrors;
  3725. if (privateKeyLoc !== null) {
  3726. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3727. }
  3728. }
  3729. }
  3730. class ExpressionErrors {
  3731. constructor() {
  3732. this.shorthandAssignLoc = null;
  3733. this.doubleProtoLoc = null;
  3734. this.privateKeyLoc = null;
  3735. this.optionalParametersLoc = null;
  3736. }
  3737. }
  3738. class Node {
  3739. constructor(parser, pos, loc) {
  3740. this.type = "";
  3741. this.start = pos;
  3742. this.end = 0;
  3743. this.loc = new SourceLocation(loc);
  3744. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3745. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3746. }
  3747. }
  3748. const NodePrototype = Node.prototype;
  3749. {
  3750. NodePrototype.__clone = function () {
  3751. const newNode = new Node(undefined, this.start, this.loc.start);
  3752. const keys = Object.keys(this);
  3753. for (let i = 0, length = keys.length; i < length; i++) {
  3754. const key = keys[i];
  3755. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3756. newNode[key] = this[key];
  3757. }
  3758. }
  3759. return newNode;
  3760. };
  3761. }
  3762. function clonePlaceholder(node) {
  3763. return cloneIdentifier(node);
  3764. }
  3765. function cloneIdentifier(node) {
  3766. const {
  3767. type,
  3768. start,
  3769. end,
  3770. loc,
  3771. range,
  3772. extra,
  3773. name
  3774. } = node;
  3775. const cloned = Object.create(NodePrototype);
  3776. cloned.type = type;
  3777. cloned.start = start;
  3778. cloned.end = end;
  3779. cloned.loc = loc;
  3780. cloned.range = range;
  3781. cloned.extra = extra;
  3782. cloned.name = name;
  3783. if (type === "Placeholder") {
  3784. cloned.expectedNode = node.expectedNode;
  3785. }
  3786. return cloned;
  3787. }
  3788. function cloneStringLiteral(node) {
  3789. const {
  3790. type,
  3791. start,
  3792. end,
  3793. loc,
  3794. range,
  3795. extra
  3796. } = node;
  3797. if (type === "Placeholder") {
  3798. return clonePlaceholder(node);
  3799. }
  3800. const cloned = Object.create(NodePrototype);
  3801. cloned.type = type;
  3802. cloned.start = start;
  3803. cloned.end = end;
  3804. cloned.loc = loc;
  3805. cloned.range = range;
  3806. if (node.raw !== undefined) {
  3807. cloned.raw = node.raw;
  3808. } else {
  3809. cloned.extra = extra;
  3810. }
  3811. cloned.value = node.value;
  3812. return cloned;
  3813. }
  3814. class NodeUtils extends UtilParser {
  3815. startNode() {
  3816. return new Node(this, this.state.start, this.state.startLoc);
  3817. }
  3818. startNodeAt(loc) {
  3819. return new Node(this, loc.index, loc);
  3820. }
  3821. startNodeAtNode(type) {
  3822. return this.startNodeAt(type.loc.start);
  3823. }
  3824. finishNode(node, type) {
  3825. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3826. }
  3827. finishNodeAt(node, type, endLoc) {
  3828. node.type = type;
  3829. node.end = endLoc.index;
  3830. node.loc.end = endLoc;
  3831. if (this.options.ranges) node.range[1] = endLoc.index;
  3832. if (this.options.attachComment) this.processComment(node);
  3833. return node;
  3834. }
  3835. resetStartLocation(node, startLoc) {
  3836. node.start = startLoc.index;
  3837. node.loc.start = startLoc;
  3838. if (this.options.ranges) node.range[0] = startLoc.index;
  3839. }
  3840. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3841. node.end = endLoc.index;
  3842. node.loc.end = endLoc;
  3843. if (this.options.ranges) node.range[1] = endLoc.index;
  3844. }
  3845. resetStartLocationFromNode(node, locationNode) {
  3846. this.resetStartLocation(node, locationNode.loc.start);
  3847. }
  3848. }
  3849. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3850. const FlowErrors = ParseErrorEnum`flow`({
  3851. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3852. 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.",
  3853. AssignReservedType: ({
  3854. reservedType
  3855. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3856. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3857. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3858. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3859. EnumBooleanMemberNotInitialized: ({
  3860. memberName,
  3861. enumName
  3862. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3863. EnumDuplicateMemberName: ({
  3864. memberName,
  3865. enumName
  3866. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3867. EnumInconsistentMemberValues: ({
  3868. enumName
  3869. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3870. EnumInvalidExplicitType: ({
  3871. invalidEnumType,
  3872. enumName
  3873. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3874. EnumInvalidExplicitTypeUnknownSupplied: ({
  3875. enumName
  3876. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3877. EnumInvalidMemberInitializerPrimaryType: ({
  3878. enumName,
  3879. memberName,
  3880. explicitType
  3881. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3882. EnumInvalidMemberInitializerSymbolType: ({
  3883. enumName,
  3884. memberName
  3885. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3886. EnumInvalidMemberInitializerUnknownType: ({
  3887. enumName,
  3888. memberName
  3889. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3890. EnumInvalidMemberName: ({
  3891. enumName,
  3892. memberName,
  3893. suggestion
  3894. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3895. EnumNumberMemberNotInitialized: ({
  3896. enumName,
  3897. memberName
  3898. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3899. EnumStringMemberInconsistentlyInitialized: ({
  3900. enumName
  3901. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3902. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3903. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3904. 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.",
  3905. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3906. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3907. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3908. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3909. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3910. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3911. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3912. PatternIsOptional: Object.assign({
  3913. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3914. }, {
  3915. reasonCode: "OptionalBindingPattern"
  3916. }),
  3917. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3918. SpreadVariance: "Spread properties cannot have variance.",
  3919. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3920. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3921. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3922. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3923. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3924. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3925. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3926. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3927. UnexpectedReservedType: ({
  3928. reservedType
  3929. }) => `Unexpected reserved type ${reservedType}.`,
  3930. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3931. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3932. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3933. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3934. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3935. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3936. UnsupportedDeclareExportKind: ({
  3937. unsupportedExportKind,
  3938. suggestion
  3939. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  3940. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3941. UnterminatedFlowComment: "Unterminated flow-comment."
  3942. });
  3943. function isEsModuleType(bodyElement) {
  3944. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3945. }
  3946. function hasTypeImportKind(node) {
  3947. return node.importKind === "type" || node.importKind === "typeof";
  3948. }
  3949. const exportSuggestions = {
  3950. const: "declare export var",
  3951. let: "declare export var",
  3952. type: "export type",
  3953. interface: "export interface"
  3954. };
  3955. function partition(list, test) {
  3956. const list1 = [];
  3957. const list2 = [];
  3958. for (let i = 0; i < list.length; i++) {
  3959. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  3960. }
  3961. return [list1, list2];
  3962. }
  3963. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  3964. var flow = superClass => class FlowParserMixin extends superClass {
  3965. constructor(...args) {
  3966. super(...args);
  3967. this.flowPragma = undefined;
  3968. }
  3969. getScopeHandler() {
  3970. return FlowScopeHandler;
  3971. }
  3972. shouldParseTypes() {
  3973. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  3974. }
  3975. shouldParseEnums() {
  3976. return !!this.getPluginOption("flow", "enums");
  3977. }
  3978. finishToken(type, val) {
  3979. if (type !== 133 && type !== 13 && type !== 28) {
  3980. if (this.flowPragma === undefined) {
  3981. this.flowPragma = null;
  3982. }
  3983. }
  3984. super.finishToken(type, val);
  3985. }
  3986. addComment(comment) {
  3987. if (this.flowPragma === undefined) {
  3988. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  3989. if (!matches) ;else if (matches[1] === "flow") {
  3990. this.flowPragma = "flow";
  3991. } else if (matches[1] === "noflow") {
  3992. this.flowPragma = "noflow";
  3993. } else {
  3994. throw new Error("Unexpected flow pragma");
  3995. }
  3996. }
  3997. super.addComment(comment);
  3998. }
  3999. flowParseTypeInitialiser(tok) {
  4000. const oldInType = this.state.inType;
  4001. this.state.inType = true;
  4002. this.expect(tok || 14);
  4003. const type = this.flowParseType();
  4004. this.state.inType = oldInType;
  4005. return type;
  4006. }
  4007. flowParsePredicate() {
  4008. const node = this.startNode();
  4009. const moduloLoc = this.state.startLoc;
  4010. this.next();
  4011. this.expectContextual(110);
  4012. if (this.state.lastTokStart > moduloLoc.index + 1) {
  4013. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
  4014. at: moduloLoc
  4015. });
  4016. }
  4017. if (this.eat(10)) {
  4018. node.value = super.parseExpression();
  4019. this.expect(11);
  4020. return this.finishNode(node, "DeclaredPredicate");
  4021. } else {
  4022. return this.finishNode(node, "InferredPredicate");
  4023. }
  4024. }
  4025. flowParseTypeAndPredicateInitialiser() {
  4026. const oldInType = this.state.inType;
  4027. this.state.inType = true;
  4028. this.expect(14);
  4029. let type = null;
  4030. let predicate = null;
  4031. if (this.match(54)) {
  4032. this.state.inType = oldInType;
  4033. predicate = this.flowParsePredicate();
  4034. } else {
  4035. type = this.flowParseType();
  4036. this.state.inType = oldInType;
  4037. if (this.match(54)) {
  4038. predicate = this.flowParsePredicate();
  4039. }
  4040. }
  4041. return [type, predicate];
  4042. }
  4043. flowParseDeclareClass(node) {
  4044. this.next();
  4045. this.flowParseInterfaceish(node, true);
  4046. return this.finishNode(node, "DeclareClass");
  4047. }
  4048. flowParseDeclareFunction(node) {
  4049. this.next();
  4050. const id = node.id = this.parseIdentifier();
  4051. const typeNode = this.startNode();
  4052. const typeContainer = this.startNode();
  4053. if (this.match(47)) {
  4054. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4055. } else {
  4056. typeNode.typeParameters = null;
  4057. }
  4058. this.expect(10);
  4059. const tmp = this.flowParseFunctionTypeParams();
  4060. typeNode.params = tmp.params;
  4061. typeNode.rest = tmp.rest;
  4062. typeNode.this = tmp._this;
  4063. this.expect(11);
  4064. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4065. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4066. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4067. this.resetEndLocation(id);
  4068. this.semicolon();
  4069. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4070. return this.finishNode(node, "DeclareFunction");
  4071. }
  4072. flowParseDeclare(node, insideModule) {
  4073. if (this.match(80)) {
  4074. return this.flowParseDeclareClass(node);
  4075. } else if (this.match(68)) {
  4076. return this.flowParseDeclareFunction(node);
  4077. } else if (this.match(74)) {
  4078. return this.flowParseDeclareVariable(node);
  4079. } else if (this.eatContextual(127)) {
  4080. if (this.match(16)) {
  4081. return this.flowParseDeclareModuleExports(node);
  4082. } else {
  4083. if (insideModule) {
  4084. this.raise(FlowErrors.NestedDeclareModule, {
  4085. at: this.state.lastTokStartLoc
  4086. });
  4087. }
  4088. return this.flowParseDeclareModule(node);
  4089. }
  4090. } else if (this.isContextual(130)) {
  4091. return this.flowParseDeclareTypeAlias(node);
  4092. } else if (this.isContextual(131)) {
  4093. return this.flowParseDeclareOpaqueType(node);
  4094. } else if (this.isContextual(129)) {
  4095. return this.flowParseDeclareInterface(node);
  4096. } else if (this.match(82)) {
  4097. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4098. } else {
  4099. this.unexpected();
  4100. }
  4101. }
  4102. flowParseDeclareVariable(node) {
  4103. this.next();
  4104. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4105. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4106. this.semicolon();
  4107. return this.finishNode(node, "DeclareVariable");
  4108. }
  4109. flowParseDeclareModule(node) {
  4110. this.scope.enter(0);
  4111. if (this.match(133)) {
  4112. node.id = super.parseExprAtom();
  4113. } else {
  4114. node.id = this.parseIdentifier();
  4115. }
  4116. const bodyNode = node.body = this.startNode();
  4117. const body = bodyNode.body = [];
  4118. this.expect(5);
  4119. while (!this.match(8)) {
  4120. let bodyNode = this.startNode();
  4121. if (this.match(83)) {
  4122. this.next();
  4123. if (!this.isContextual(130) && !this.match(87)) {
  4124. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
  4125. at: this.state.lastTokStartLoc
  4126. });
  4127. }
  4128. super.parseImport(bodyNode);
  4129. } else {
  4130. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4131. bodyNode = this.flowParseDeclare(bodyNode, true);
  4132. }
  4133. body.push(bodyNode);
  4134. }
  4135. this.scope.exit();
  4136. this.expect(8);
  4137. this.finishNode(bodyNode, "BlockStatement");
  4138. let kind = null;
  4139. let hasModuleExport = false;
  4140. body.forEach(bodyElement => {
  4141. if (isEsModuleType(bodyElement)) {
  4142. if (kind === "CommonJS") {
  4143. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4144. at: bodyElement
  4145. });
  4146. }
  4147. kind = "ES";
  4148. } else if (bodyElement.type === "DeclareModuleExports") {
  4149. if (hasModuleExport) {
  4150. this.raise(FlowErrors.DuplicateDeclareModuleExports, {
  4151. at: bodyElement
  4152. });
  4153. }
  4154. if (kind === "ES") {
  4155. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4156. at: bodyElement
  4157. });
  4158. }
  4159. kind = "CommonJS";
  4160. hasModuleExport = true;
  4161. }
  4162. });
  4163. node.kind = kind || "CommonJS";
  4164. return this.finishNode(node, "DeclareModule");
  4165. }
  4166. flowParseDeclareExportDeclaration(node, insideModule) {
  4167. this.expect(82);
  4168. if (this.eat(65)) {
  4169. if (this.match(68) || this.match(80)) {
  4170. node.declaration = this.flowParseDeclare(this.startNode());
  4171. } else {
  4172. node.declaration = this.flowParseType();
  4173. this.semicolon();
  4174. }
  4175. node.default = true;
  4176. return this.finishNode(node, "DeclareExportDeclaration");
  4177. } else {
  4178. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4179. const label = this.state.value;
  4180. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
  4181. at: this.state.startLoc,
  4182. unsupportedExportKind: label,
  4183. suggestion: exportSuggestions[label]
  4184. });
  4185. }
  4186. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4187. node.declaration = this.flowParseDeclare(this.startNode());
  4188. node.default = false;
  4189. return this.finishNode(node, "DeclareExportDeclaration");
  4190. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4191. node = this.parseExport(node, null);
  4192. if (node.type === "ExportNamedDeclaration") {
  4193. node.type = "ExportDeclaration";
  4194. node.default = false;
  4195. delete node.exportKind;
  4196. }
  4197. node.type = "Declare" + node.type;
  4198. return node;
  4199. }
  4200. }
  4201. this.unexpected();
  4202. }
  4203. flowParseDeclareModuleExports(node) {
  4204. this.next();
  4205. this.expectContextual(111);
  4206. node.typeAnnotation = this.flowParseTypeAnnotation();
  4207. this.semicolon();
  4208. return this.finishNode(node, "DeclareModuleExports");
  4209. }
  4210. flowParseDeclareTypeAlias(node) {
  4211. this.next();
  4212. const finished = this.flowParseTypeAlias(node);
  4213. finished.type = "DeclareTypeAlias";
  4214. return finished;
  4215. }
  4216. flowParseDeclareOpaqueType(node) {
  4217. this.next();
  4218. const finished = this.flowParseOpaqueType(node, true);
  4219. finished.type = "DeclareOpaqueType";
  4220. return finished;
  4221. }
  4222. flowParseDeclareInterface(node) {
  4223. this.next();
  4224. this.flowParseInterfaceish(node, false);
  4225. return this.finishNode(node, "DeclareInterface");
  4226. }
  4227. flowParseInterfaceish(node, isClass) {
  4228. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4229. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4230. if (this.match(47)) {
  4231. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4232. } else {
  4233. node.typeParameters = null;
  4234. }
  4235. node.extends = [];
  4236. if (this.eat(81)) {
  4237. do {
  4238. node.extends.push(this.flowParseInterfaceExtends());
  4239. } while (!isClass && this.eat(12));
  4240. }
  4241. if (isClass) {
  4242. node.implements = [];
  4243. node.mixins = [];
  4244. if (this.eatContextual(117)) {
  4245. do {
  4246. node.mixins.push(this.flowParseInterfaceExtends());
  4247. } while (this.eat(12));
  4248. }
  4249. if (this.eatContextual(113)) {
  4250. do {
  4251. node.implements.push(this.flowParseInterfaceExtends());
  4252. } while (this.eat(12));
  4253. }
  4254. }
  4255. node.body = this.flowParseObjectType({
  4256. allowStatic: isClass,
  4257. allowExact: false,
  4258. allowSpread: false,
  4259. allowProto: isClass,
  4260. allowInexact: false
  4261. });
  4262. }
  4263. flowParseInterfaceExtends() {
  4264. const node = this.startNode();
  4265. node.id = this.flowParseQualifiedTypeIdentifier();
  4266. if (this.match(47)) {
  4267. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4268. } else {
  4269. node.typeParameters = null;
  4270. }
  4271. return this.finishNode(node, "InterfaceExtends");
  4272. }
  4273. flowParseInterface(node) {
  4274. this.flowParseInterfaceish(node, false);
  4275. return this.finishNode(node, "InterfaceDeclaration");
  4276. }
  4277. checkNotUnderscore(word) {
  4278. if (word === "_") {
  4279. this.raise(FlowErrors.UnexpectedReservedUnderscore, {
  4280. at: this.state.startLoc
  4281. });
  4282. }
  4283. }
  4284. checkReservedType(word, startLoc, declaration) {
  4285. if (!reservedTypes.has(word)) return;
  4286. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
  4287. at: startLoc,
  4288. reservedType: word
  4289. });
  4290. }
  4291. flowParseRestrictedIdentifier(liberal, declaration) {
  4292. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4293. return this.parseIdentifier(liberal);
  4294. }
  4295. flowParseTypeAlias(node) {
  4296. node.id = this.flowParseRestrictedIdentifier(false, true);
  4297. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4298. if (this.match(47)) {
  4299. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4300. } else {
  4301. node.typeParameters = null;
  4302. }
  4303. node.right = this.flowParseTypeInitialiser(29);
  4304. this.semicolon();
  4305. return this.finishNode(node, "TypeAlias");
  4306. }
  4307. flowParseOpaqueType(node, declare) {
  4308. this.expectContextual(130);
  4309. node.id = this.flowParseRestrictedIdentifier(true, true);
  4310. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4311. if (this.match(47)) {
  4312. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4313. } else {
  4314. node.typeParameters = null;
  4315. }
  4316. node.supertype = null;
  4317. if (this.match(14)) {
  4318. node.supertype = this.flowParseTypeInitialiser(14);
  4319. }
  4320. node.impltype = null;
  4321. if (!declare) {
  4322. node.impltype = this.flowParseTypeInitialiser(29);
  4323. }
  4324. this.semicolon();
  4325. return this.finishNode(node, "OpaqueType");
  4326. }
  4327. flowParseTypeParameter(requireDefault = false) {
  4328. const nodeStartLoc = this.state.startLoc;
  4329. const node = this.startNode();
  4330. const variance = this.flowParseVariance();
  4331. const ident = this.flowParseTypeAnnotatableIdentifier();
  4332. node.name = ident.name;
  4333. node.variance = variance;
  4334. node.bound = ident.typeAnnotation;
  4335. if (this.match(29)) {
  4336. this.eat(29);
  4337. node.default = this.flowParseType();
  4338. } else {
  4339. if (requireDefault) {
  4340. this.raise(FlowErrors.MissingTypeParamDefault, {
  4341. at: nodeStartLoc
  4342. });
  4343. }
  4344. }
  4345. return this.finishNode(node, "TypeParameter");
  4346. }
  4347. flowParseTypeParameterDeclaration() {
  4348. const oldInType = this.state.inType;
  4349. const node = this.startNode();
  4350. node.params = [];
  4351. this.state.inType = true;
  4352. if (this.match(47) || this.match(142)) {
  4353. this.next();
  4354. } else {
  4355. this.unexpected();
  4356. }
  4357. let defaultRequired = false;
  4358. do {
  4359. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4360. node.params.push(typeParameter);
  4361. if (typeParameter.default) {
  4362. defaultRequired = true;
  4363. }
  4364. if (!this.match(48)) {
  4365. this.expect(12);
  4366. }
  4367. } while (!this.match(48));
  4368. this.expect(48);
  4369. this.state.inType = oldInType;
  4370. return this.finishNode(node, "TypeParameterDeclaration");
  4371. }
  4372. flowParseTypeParameterInstantiation() {
  4373. const node = this.startNode();
  4374. const oldInType = this.state.inType;
  4375. node.params = [];
  4376. this.state.inType = true;
  4377. this.expect(47);
  4378. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4379. this.state.noAnonFunctionType = false;
  4380. while (!this.match(48)) {
  4381. node.params.push(this.flowParseType());
  4382. if (!this.match(48)) {
  4383. this.expect(12);
  4384. }
  4385. }
  4386. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4387. this.expect(48);
  4388. this.state.inType = oldInType;
  4389. return this.finishNode(node, "TypeParameterInstantiation");
  4390. }
  4391. flowParseTypeParameterInstantiationCallOrNew() {
  4392. const node = this.startNode();
  4393. const oldInType = this.state.inType;
  4394. node.params = [];
  4395. this.state.inType = true;
  4396. this.expect(47);
  4397. while (!this.match(48)) {
  4398. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4399. if (!this.match(48)) {
  4400. this.expect(12);
  4401. }
  4402. }
  4403. this.expect(48);
  4404. this.state.inType = oldInType;
  4405. return this.finishNode(node, "TypeParameterInstantiation");
  4406. }
  4407. flowParseInterfaceType() {
  4408. const node = this.startNode();
  4409. this.expectContextual(129);
  4410. node.extends = [];
  4411. if (this.eat(81)) {
  4412. do {
  4413. node.extends.push(this.flowParseInterfaceExtends());
  4414. } while (this.eat(12));
  4415. }
  4416. node.body = this.flowParseObjectType({
  4417. allowStatic: false,
  4418. allowExact: false,
  4419. allowSpread: false,
  4420. allowProto: false,
  4421. allowInexact: false
  4422. });
  4423. return this.finishNode(node, "InterfaceTypeAnnotation");
  4424. }
  4425. flowParseObjectPropertyKey() {
  4426. return this.match(134) || this.match(133) ? super.parseExprAtom() : this.parseIdentifier(true);
  4427. }
  4428. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4429. node.static = isStatic;
  4430. if (this.lookahead().type === 14) {
  4431. node.id = this.flowParseObjectPropertyKey();
  4432. node.key = this.flowParseTypeInitialiser();
  4433. } else {
  4434. node.id = null;
  4435. node.key = this.flowParseType();
  4436. }
  4437. this.expect(3);
  4438. node.value = this.flowParseTypeInitialiser();
  4439. node.variance = variance;
  4440. return this.finishNode(node, "ObjectTypeIndexer");
  4441. }
  4442. flowParseObjectTypeInternalSlot(node, isStatic) {
  4443. node.static = isStatic;
  4444. node.id = this.flowParseObjectPropertyKey();
  4445. this.expect(3);
  4446. this.expect(3);
  4447. if (this.match(47) || this.match(10)) {
  4448. node.method = true;
  4449. node.optional = false;
  4450. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4451. } else {
  4452. node.method = false;
  4453. if (this.eat(17)) {
  4454. node.optional = true;
  4455. }
  4456. node.value = this.flowParseTypeInitialiser();
  4457. }
  4458. return this.finishNode(node, "ObjectTypeInternalSlot");
  4459. }
  4460. flowParseObjectTypeMethodish(node) {
  4461. node.params = [];
  4462. node.rest = null;
  4463. node.typeParameters = null;
  4464. node.this = null;
  4465. if (this.match(47)) {
  4466. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4467. }
  4468. this.expect(10);
  4469. if (this.match(78)) {
  4470. node.this = this.flowParseFunctionTypeParam(true);
  4471. node.this.name = null;
  4472. if (!this.match(11)) {
  4473. this.expect(12);
  4474. }
  4475. }
  4476. while (!this.match(11) && !this.match(21)) {
  4477. node.params.push(this.flowParseFunctionTypeParam(false));
  4478. if (!this.match(11)) {
  4479. this.expect(12);
  4480. }
  4481. }
  4482. if (this.eat(21)) {
  4483. node.rest = this.flowParseFunctionTypeParam(false);
  4484. }
  4485. this.expect(11);
  4486. node.returnType = this.flowParseTypeInitialiser();
  4487. return this.finishNode(node, "FunctionTypeAnnotation");
  4488. }
  4489. flowParseObjectTypeCallProperty(node, isStatic) {
  4490. const valueNode = this.startNode();
  4491. node.static = isStatic;
  4492. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4493. return this.finishNode(node, "ObjectTypeCallProperty");
  4494. }
  4495. flowParseObjectType({
  4496. allowStatic,
  4497. allowExact,
  4498. allowSpread,
  4499. allowProto,
  4500. allowInexact
  4501. }) {
  4502. const oldInType = this.state.inType;
  4503. this.state.inType = true;
  4504. const nodeStart = this.startNode();
  4505. nodeStart.callProperties = [];
  4506. nodeStart.properties = [];
  4507. nodeStart.indexers = [];
  4508. nodeStart.internalSlots = [];
  4509. let endDelim;
  4510. let exact;
  4511. let inexact = false;
  4512. if (allowExact && this.match(6)) {
  4513. this.expect(6);
  4514. endDelim = 9;
  4515. exact = true;
  4516. } else {
  4517. this.expect(5);
  4518. endDelim = 8;
  4519. exact = false;
  4520. }
  4521. nodeStart.exact = exact;
  4522. while (!this.match(endDelim)) {
  4523. let isStatic = false;
  4524. let protoStartLoc = null;
  4525. let inexactStartLoc = null;
  4526. const node = this.startNode();
  4527. if (allowProto && this.isContextual(118)) {
  4528. const lookahead = this.lookahead();
  4529. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4530. this.next();
  4531. protoStartLoc = this.state.startLoc;
  4532. allowStatic = false;
  4533. }
  4534. }
  4535. if (allowStatic && this.isContextual(106)) {
  4536. const lookahead = this.lookahead();
  4537. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4538. this.next();
  4539. isStatic = true;
  4540. }
  4541. }
  4542. const variance = this.flowParseVariance();
  4543. if (this.eat(0)) {
  4544. if (protoStartLoc != null) {
  4545. this.unexpected(protoStartLoc);
  4546. }
  4547. if (this.eat(0)) {
  4548. if (variance) {
  4549. this.unexpected(variance.loc.start);
  4550. }
  4551. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4552. } else {
  4553. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4554. }
  4555. } else if (this.match(10) || this.match(47)) {
  4556. if (protoStartLoc != null) {
  4557. this.unexpected(protoStartLoc);
  4558. }
  4559. if (variance) {
  4560. this.unexpected(variance.loc.start);
  4561. }
  4562. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4563. } else {
  4564. let kind = "init";
  4565. if (this.isContextual(99) || this.isContextual(104)) {
  4566. const lookahead = this.lookahead();
  4567. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4568. kind = this.state.value;
  4569. this.next();
  4570. }
  4571. }
  4572. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4573. if (propOrInexact === null) {
  4574. inexact = true;
  4575. inexactStartLoc = this.state.lastTokStartLoc;
  4576. } else {
  4577. nodeStart.properties.push(propOrInexact);
  4578. }
  4579. }
  4580. this.flowObjectTypeSemicolon();
  4581. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4582. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
  4583. at: inexactStartLoc
  4584. });
  4585. }
  4586. }
  4587. this.expect(endDelim);
  4588. if (allowSpread) {
  4589. nodeStart.inexact = inexact;
  4590. }
  4591. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4592. this.state.inType = oldInType;
  4593. return out;
  4594. }
  4595. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4596. if (this.eat(21)) {
  4597. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4598. if (isInexactToken) {
  4599. if (!allowSpread) {
  4600. this.raise(FlowErrors.InexactInsideNonObject, {
  4601. at: this.state.lastTokStartLoc
  4602. });
  4603. } else if (!allowInexact) {
  4604. this.raise(FlowErrors.InexactInsideExact, {
  4605. at: this.state.lastTokStartLoc
  4606. });
  4607. }
  4608. if (variance) {
  4609. this.raise(FlowErrors.InexactVariance, {
  4610. at: variance
  4611. });
  4612. }
  4613. return null;
  4614. }
  4615. if (!allowSpread) {
  4616. this.raise(FlowErrors.UnexpectedSpreadType, {
  4617. at: this.state.lastTokStartLoc
  4618. });
  4619. }
  4620. if (protoStartLoc != null) {
  4621. this.unexpected(protoStartLoc);
  4622. }
  4623. if (variance) {
  4624. this.raise(FlowErrors.SpreadVariance, {
  4625. at: variance
  4626. });
  4627. }
  4628. node.argument = this.flowParseType();
  4629. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4630. } else {
  4631. node.key = this.flowParseObjectPropertyKey();
  4632. node.static = isStatic;
  4633. node.proto = protoStartLoc != null;
  4634. node.kind = kind;
  4635. let optional = false;
  4636. if (this.match(47) || this.match(10)) {
  4637. node.method = true;
  4638. if (protoStartLoc != null) {
  4639. this.unexpected(protoStartLoc);
  4640. }
  4641. if (variance) {
  4642. this.unexpected(variance.loc.start);
  4643. }
  4644. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4645. if (kind === "get" || kind === "set") {
  4646. this.flowCheckGetterSetterParams(node);
  4647. }
  4648. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4649. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  4650. at: node.value.this
  4651. });
  4652. }
  4653. } else {
  4654. if (kind !== "init") this.unexpected();
  4655. node.method = false;
  4656. if (this.eat(17)) {
  4657. optional = true;
  4658. }
  4659. node.value = this.flowParseTypeInitialiser();
  4660. node.variance = variance;
  4661. }
  4662. node.optional = optional;
  4663. return this.finishNode(node, "ObjectTypeProperty");
  4664. }
  4665. }
  4666. flowCheckGetterSetterParams(property) {
  4667. const paramCount = property.kind === "get" ? 0 : 1;
  4668. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4669. if (property.value.this) {
  4670. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
  4671. at: property.value.this
  4672. });
  4673. }
  4674. if (length !== paramCount) {
  4675. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  4676. at: property
  4677. });
  4678. }
  4679. if (property.kind === "set" && property.value.rest) {
  4680. this.raise(Errors.BadSetterRestParameter, {
  4681. at: property
  4682. });
  4683. }
  4684. }
  4685. flowObjectTypeSemicolon() {
  4686. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4687. this.unexpected();
  4688. }
  4689. }
  4690. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4691. var _startLoc;
  4692. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4693. let node = id || this.flowParseRestrictedIdentifier(true);
  4694. while (this.eat(16)) {
  4695. const node2 = this.startNodeAt(startLoc);
  4696. node2.qualification = node;
  4697. node2.id = this.flowParseRestrictedIdentifier(true);
  4698. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4699. }
  4700. return node;
  4701. }
  4702. flowParseGenericType(startLoc, id) {
  4703. const node = this.startNodeAt(startLoc);
  4704. node.typeParameters = null;
  4705. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4706. if (this.match(47)) {
  4707. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4708. }
  4709. return this.finishNode(node, "GenericTypeAnnotation");
  4710. }
  4711. flowParseTypeofType() {
  4712. const node = this.startNode();
  4713. this.expect(87);
  4714. node.argument = this.flowParsePrimaryType();
  4715. return this.finishNode(node, "TypeofTypeAnnotation");
  4716. }
  4717. flowParseTupleType() {
  4718. const node = this.startNode();
  4719. node.types = [];
  4720. this.expect(0);
  4721. while (this.state.pos < this.length && !this.match(3)) {
  4722. node.types.push(this.flowParseType());
  4723. if (this.match(3)) break;
  4724. this.expect(12);
  4725. }
  4726. this.expect(3);
  4727. return this.finishNode(node, "TupleTypeAnnotation");
  4728. }
  4729. flowParseFunctionTypeParam(first) {
  4730. let name = null;
  4731. let optional = false;
  4732. let typeAnnotation = null;
  4733. const node = this.startNode();
  4734. const lh = this.lookahead();
  4735. const isThis = this.state.type === 78;
  4736. if (lh.type === 14 || lh.type === 17) {
  4737. if (isThis && !first) {
  4738. this.raise(FlowErrors.ThisParamMustBeFirst, {
  4739. at: node
  4740. });
  4741. }
  4742. name = this.parseIdentifier(isThis);
  4743. if (this.eat(17)) {
  4744. optional = true;
  4745. if (isThis) {
  4746. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  4747. at: node
  4748. });
  4749. }
  4750. }
  4751. typeAnnotation = this.flowParseTypeInitialiser();
  4752. } else {
  4753. typeAnnotation = this.flowParseType();
  4754. }
  4755. node.name = name;
  4756. node.optional = optional;
  4757. node.typeAnnotation = typeAnnotation;
  4758. return this.finishNode(node, "FunctionTypeParam");
  4759. }
  4760. reinterpretTypeAsFunctionTypeParam(type) {
  4761. const node = this.startNodeAt(type.loc.start);
  4762. node.name = null;
  4763. node.optional = false;
  4764. node.typeAnnotation = type;
  4765. return this.finishNode(node, "FunctionTypeParam");
  4766. }
  4767. flowParseFunctionTypeParams(params = []) {
  4768. let rest = null;
  4769. let _this = null;
  4770. if (this.match(78)) {
  4771. _this = this.flowParseFunctionTypeParam(true);
  4772. _this.name = null;
  4773. if (!this.match(11)) {
  4774. this.expect(12);
  4775. }
  4776. }
  4777. while (!this.match(11) && !this.match(21)) {
  4778. params.push(this.flowParseFunctionTypeParam(false));
  4779. if (!this.match(11)) {
  4780. this.expect(12);
  4781. }
  4782. }
  4783. if (this.eat(21)) {
  4784. rest = this.flowParseFunctionTypeParam(false);
  4785. }
  4786. return {
  4787. params,
  4788. rest,
  4789. _this
  4790. };
  4791. }
  4792. flowIdentToTypeAnnotation(startLoc, node, id) {
  4793. switch (id.name) {
  4794. case "any":
  4795. return this.finishNode(node, "AnyTypeAnnotation");
  4796. case "bool":
  4797. case "boolean":
  4798. return this.finishNode(node, "BooleanTypeAnnotation");
  4799. case "mixed":
  4800. return this.finishNode(node, "MixedTypeAnnotation");
  4801. case "empty":
  4802. return this.finishNode(node, "EmptyTypeAnnotation");
  4803. case "number":
  4804. return this.finishNode(node, "NumberTypeAnnotation");
  4805. case "string":
  4806. return this.finishNode(node, "StringTypeAnnotation");
  4807. case "symbol":
  4808. return this.finishNode(node, "SymbolTypeAnnotation");
  4809. default:
  4810. this.checkNotUnderscore(id.name);
  4811. return this.flowParseGenericType(startLoc, id);
  4812. }
  4813. }
  4814. flowParsePrimaryType() {
  4815. const startLoc = this.state.startLoc;
  4816. const node = this.startNode();
  4817. let tmp;
  4818. let type;
  4819. let isGroupedType = false;
  4820. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4821. switch (this.state.type) {
  4822. case 5:
  4823. return this.flowParseObjectType({
  4824. allowStatic: false,
  4825. allowExact: false,
  4826. allowSpread: true,
  4827. allowProto: false,
  4828. allowInexact: true
  4829. });
  4830. case 6:
  4831. return this.flowParseObjectType({
  4832. allowStatic: false,
  4833. allowExact: true,
  4834. allowSpread: true,
  4835. allowProto: false,
  4836. allowInexact: false
  4837. });
  4838. case 0:
  4839. this.state.noAnonFunctionType = false;
  4840. type = this.flowParseTupleType();
  4841. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4842. return type;
  4843. case 47:
  4844. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4845. this.expect(10);
  4846. tmp = this.flowParseFunctionTypeParams();
  4847. node.params = tmp.params;
  4848. node.rest = tmp.rest;
  4849. node.this = tmp._this;
  4850. this.expect(11);
  4851. this.expect(19);
  4852. node.returnType = this.flowParseType();
  4853. return this.finishNode(node, "FunctionTypeAnnotation");
  4854. case 10:
  4855. this.next();
  4856. if (!this.match(11) && !this.match(21)) {
  4857. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4858. const token = this.lookahead().type;
  4859. isGroupedType = token !== 17 && token !== 14;
  4860. } else {
  4861. isGroupedType = true;
  4862. }
  4863. }
  4864. if (isGroupedType) {
  4865. this.state.noAnonFunctionType = false;
  4866. type = this.flowParseType();
  4867. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4868. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4869. this.expect(11);
  4870. return type;
  4871. } else {
  4872. this.eat(12);
  4873. }
  4874. }
  4875. if (type) {
  4876. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4877. } else {
  4878. tmp = this.flowParseFunctionTypeParams();
  4879. }
  4880. node.params = tmp.params;
  4881. node.rest = tmp.rest;
  4882. node.this = tmp._this;
  4883. this.expect(11);
  4884. this.expect(19);
  4885. node.returnType = this.flowParseType();
  4886. node.typeParameters = null;
  4887. return this.finishNode(node, "FunctionTypeAnnotation");
  4888. case 133:
  4889. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4890. case 85:
  4891. case 86:
  4892. node.value = this.match(85);
  4893. this.next();
  4894. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4895. case 53:
  4896. if (this.state.value === "-") {
  4897. this.next();
  4898. if (this.match(134)) {
  4899. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4900. }
  4901. if (this.match(135)) {
  4902. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4903. }
  4904. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
  4905. at: this.state.startLoc
  4906. });
  4907. }
  4908. this.unexpected();
  4909. return;
  4910. case 134:
  4911. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4912. case 135:
  4913. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4914. case 88:
  4915. this.next();
  4916. return this.finishNode(node, "VoidTypeAnnotation");
  4917. case 84:
  4918. this.next();
  4919. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4920. case 78:
  4921. this.next();
  4922. return this.finishNode(node, "ThisTypeAnnotation");
  4923. case 55:
  4924. this.next();
  4925. return this.finishNode(node, "ExistsTypeAnnotation");
  4926. case 87:
  4927. return this.flowParseTypeofType();
  4928. default:
  4929. if (tokenIsKeyword(this.state.type)) {
  4930. const label = tokenLabelName(this.state.type);
  4931. this.next();
  4932. return super.createIdentifier(node, label);
  4933. } else if (tokenIsIdentifier(this.state.type)) {
  4934. if (this.isContextual(129)) {
  4935. return this.flowParseInterfaceType();
  4936. }
  4937. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4938. }
  4939. }
  4940. this.unexpected();
  4941. }
  4942. flowParsePostfixType() {
  4943. const startLoc = this.state.startLoc;
  4944. let type = this.flowParsePrimaryType();
  4945. let seenOptionalIndexedAccess = false;
  4946. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4947. const node = this.startNodeAt(startLoc);
  4948. const optional = this.eat(18);
  4949. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  4950. this.expect(0);
  4951. if (!optional && this.match(3)) {
  4952. node.elementType = type;
  4953. this.next();
  4954. type = this.finishNode(node, "ArrayTypeAnnotation");
  4955. } else {
  4956. node.objectType = type;
  4957. node.indexType = this.flowParseType();
  4958. this.expect(3);
  4959. if (seenOptionalIndexedAccess) {
  4960. node.optional = optional;
  4961. type = this.finishNode(node, "OptionalIndexedAccessType");
  4962. } else {
  4963. type = this.finishNode(node, "IndexedAccessType");
  4964. }
  4965. }
  4966. }
  4967. return type;
  4968. }
  4969. flowParsePrefixType() {
  4970. const node = this.startNode();
  4971. if (this.eat(17)) {
  4972. node.typeAnnotation = this.flowParsePrefixType();
  4973. return this.finishNode(node, "NullableTypeAnnotation");
  4974. } else {
  4975. return this.flowParsePostfixType();
  4976. }
  4977. }
  4978. flowParseAnonFunctionWithoutParens() {
  4979. const param = this.flowParsePrefixType();
  4980. if (!this.state.noAnonFunctionType && this.eat(19)) {
  4981. const node = this.startNodeAt(param.loc.start);
  4982. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  4983. node.rest = null;
  4984. node.this = null;
  4985. node.returnType = this.flowParseType();
  4986. node.typeParameters = null;
  4987. return this.finishNode(node, "FunctionTypeAnnotation");
  4988. }
  4989. return param;
  4990. }
  4991. flowParseIntersectionType() {
  4992. const node = this.startNode();
  4993. this.eat(45);
  4994. const type = this.flowParseAnonFunctionWithoutParens();
  4995. node.types = [type];
  4996. while (this.eat(45)) {
  4997. node.types.push(this.flowParseAnonFunctionWithoutParens());
  4998. }
  4999. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5000. }
  5001. flowParseUnionType() {
  5002. const node = this.startNode();
  5003. this.eat(43);
  5004. const type = this.flowParseIntersectionType();
  5005. node.types = [type];
  5006. while (this.eat(43)) {
  5007. node.types.push(this.flowParseIntersectionType());
  5008. }
  5009. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5010. }
  5011. flowParseType() {
  5012. const oldInType = this.state.inType;
  5013. this.state.inType = true;
  5014. const type = this.flowParseUnionType();
  5015. this.state.inType = oldInType;
  5016. return type;
  5017. }
  5018. flowParseTypeOrImplicitInstantiation() {
  5019. if (this.state.type === 132 && this.state.value === "_") {
  5020. const startLoc = this.state.startLoc;
  5021. const node = this.parseIdentifier();
  5022. return this.flowParseGenericType(startLoc, node);
  5023. } else {
  5024. return this.flowParseType();
  5025. }
  5026. }
  5027. flowParseTypeAnnotation() {
  5028. const node = this.startNode();
  5029. node.typeAnnotation = this.flowParseTypeInitialiser();
  5030. return this.finishNode(node, "TypeAnnotation");
  5031. }
  5032. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5033. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5034. if (this.match(14)) {
  5035. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5036. this.resetEndLocation(ident);
  5037. }
  5038. return ident;
  5039. }
  5040. typeCastToParameter(node) {
  5041. node.expression.typeAnnotation = node.typeAnnotation;
  5042. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5043. return node.expression;
  5044. }
  5045. flowParseVariance() {
  5046. let variance = null;
  5047. if (this.match(53)) {
  5048. variance = this.startNode();
  5049. if (this.state.value === "+") {
  5050. variance.kind = "plus";
  5051. } else {
  5052. variance.kind = "minus";
  5053. }
  5054. this.next();
  5055. return this.finishNode(variance, "Variance");
  5056. }
  5057. return variance;
  5058. }
  5059. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5060. if (allowExpressionBody) {
  5061. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5062. return;
  5063. }
  5064. super.parseFunctionBody(node, false, isMethod);
  5065. }
  5066. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5067. if (this.match(14)) {
  5068. const typeNode = this.startNode();
  5069. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5070. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5071. }
  5072. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5073. }
  5074. parseStatementLike(flags) {
  5075. if (this.state.strict && this.isContextual(129)) {
  5076. const lookahead = this.lookahead();
  5077. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5078. const node = this.startNode();
  5079. this.next();
  5080. return this.flowParseInterface(node);
  5081. }
  5082. } else if (this.shouldParseEnums() && this.isContextual(126)) {
  5083. const node = this.startNode();
  5084. this.next();
  5085. return this.flowParseEnumDeclaration(node);
  5086. }
  5087. const stmt = super.parseStatementLike(flags);
  5088. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5089. this.flowPragma = null;
  5090. }
  5091. return stmt;
  5092. }
  5093. parseExpressionStatement(node, expr, decorators) {
  5094. if (expr.type === "Identifier") {
  5095. if (expr.name === "declare") {
  5096. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5097. return this.flowParseDeclare(node);
  5098. }
  5099. } else if (tokenIsIdentifier(this.state.type)) {
  5100. if (expr.name === "interface") {
  5101. return this.flowParseInterface(node);
  5102. } else if (expr.name === "type") {
  5103. return this.flowParseTypeAlias(node);
  5104. } else if (expr.name === "opaque") {
  5105. return this.flowParseOpaqueType(node, false);
  5106. }
  5107. }
  5108. }
  5109. return super.parseExpressionStatement(node, expr, decorators);
  5110. }
  5111. shouldParseExportDeclaration() {
  5112. const {
  5113. type
  5114. } = this.state;
  5115. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 126) {
  5116. return !this.state.containsEsc;
  5117. }
  5118. return super.shouldParseExportDeclaration();
  5119. }
  5120. isExportDefaultSpecifier() {
  5121. const {
  5122. type
  5123. } = this.state;
  5124. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 126) {
  5125. return this.state.containsEsc;
  5126. }
  5127. return super.isExportDefaultSpecifier();
  5128. }
  5129. parseExportDefaultExpression() {
  5130. if (this.shouldParseEnums() && this.isContextual(126)) {
  5131. const node = this.startNode();
  5132. this.next();
  5133. return this.flowParseEnumDeclaration(node);
  5134. }
  5135. return super.parseExportDefaultExpression();
  5136. }
  5137. parseConditional(expr, startLoc, refExpressionErrors) {
  5138. if (!this.match(17)) return expr;
  5139. if (this.state.maybeInArrowParameters) {
  5140. const nextCh = this.lookaheadCharCode();
  5141. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5142. this.setOptionalParametersError(refExpressionErrors);
  5143. return expr;
  5144. }
  5145. }
  5146. this.expect(17);
  5147. const state = this.state.clone();
  5148. const originalNoArrowAt = this.state.noArrowAt;
  5149. const node = this.startNodeAt(startLoc);
  5150. let {
  5151. consequent,
  5152. failed
  5153. } = this.tryParseConditionalConsequent();
  5154. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5155. if (failed || invalid.length > 0) {
  5156. const noArrowAt = [...originalNoArrowAt];
  5157. if (invalid.length > 0) {
  5158. this.state = state;
  5159. this.state.noArrowAt = noArrowAt;
  5160. for (let i = 0; i < invalid.length; i++) {
  5161. noArrowAt.push(invalid[i].start);
  5162. }
  5163. ({
  5164. consequent,
  5165. failed
  5166. } = this.tryParseConditionalConsequent());
  5167. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5168. }
  5169. if (failed && valid.length > 1) {
  5170. this.raise(FlowErrors.AmbiguousConditionalArrow, {
  5171. at: state.startLoc
  5172. });
  5173. }
  5174. if (failed && valid.length === 1) {
  5175. this.state = state;
  5176. noArrowAt.push(valid[0].start);
  5177. this.state.noArrowAt = noArrowAt;
  5178. ({
  5179. consequent,
  5180. failed
  5181. } = this.tryParseConditionalConsequent());
  5182. }
  5183. }
  5184. this.getArrowLikeExpressions(consequent, true);
  5185. this.state.noArrowAt = originalNoArrowAt;
  5186. this.expect(14);
  5187. node.test = expr;
  5188. node.consequent = consequent;
  5189. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5190. return this.finishNode(node, "ConditionalExpression");
  5191. }
  5192. tryParseConditionalConsequent() {
  5193. this.state.noArrowParamsConversionAt.push(this.state.start);
  5194. const consequent = this.parseMaybeAssignAllowIn();
  5195. const failed = !this.match(14);
  5196. this.state.noArrowParamsConversionAt.pop();
  5197. return {
  5198. consequent,
  5199. failed
  5200. };
  5201. }
  5202. getArrowLikeExpressions(node, disallowInvalid) {
  5203. const stack = [node];
  5204. const arrows = [];
  5205. while (stack.length !== 0) {
  5206. const node = stack.pop();
  5207. if (node.type === "ArrowFunctionExpression") {
  5208. if (node.typeParameters || !node.returnType) {
  5209. this.finishArrowValidation(node);
  5210. } else {
  5211. arrows.push(node);
  5212. }
  5213. stack.push(node.body);
  5214. } else if (node.type === "ConditionalExpression") {
  5215. stack.push(node.consequent);
  5216. stack.push(node.alternate);
  5217. }
  5218. }
  5219. if (disallowInvalid) {
  5220. arrows.forEach(node => this.finishArrowValidation(node));
  5221. return [arrows, []];
  5222. }
  5223. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5224. }
  5225. finishArrowValidation(node) {
  5226. var _node$extra;
  5227. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5228. this.scope.enter(2 | 4);
  5229. super.checkParams(node, false, true);
  5230. this.scope.exit();
  5231. }
  5232. forwardNoArrowParamsConversionAt(node, parse) {
  5233. let result;
  5234. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5235. this.state.noArrowParamsConversionAt.push(this.state.start);
  5236. result = parse();
  5237. this.state.noArrowParamsConversionAt.pop();
  5238. } else {
  5239. result = parse();
  5240. }
  5241. return result;
  5242. }
  5243. parseParenItem(node, startLoc) {
  5244. node = super.parseParenItem(node, startLoc);
  5245. if (this.eat(17)) {
  5246. node.optional = true;
  5247. this.resetEndLocation(node);
  5248. }
  5249. if (this.match(14)) {
  5250. const typeCastNode = this.startNodeAt(startLoc);
  5251. typeCastNode.expression = node;
  5252. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5253. return this.finishNode(typeCastNode, "TypeCastExpression");
  5254. }
  5255. return node;
  5256. }
  5257. assertModuleNodeAllowed(node) {
  5258. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5259. return;
  5260. }
  5261. super.assertModuleNodeAllowed(node);
  5262. }
  5263. parseExportDeclaration(node) {
  5264. if (this.isContextual(130)) {
  5265. node.exportKind = "type";
  5266. const declarationNode = this.startNode();
  5267. this.next();
  5268. if (this.match(5)) {
  5269. node.specifiers = this.parseExportSpecifiers(true);
  5270. super.parseExportFrom(node);
  5271. return null;
  5272. } else {
  5273. return this.flowParseTypeAlias(declarationNode);
  5274. }
  5275. } else if (this.isContextual(131)) {
  5276. node.exportKind = "type";
  5277. const declarationNode = this.startNode();
  5278. this.next();
  5279. return this.flowParseOpaqueType(declarationNode, false);
  5280. } else if (this.isContextual(129)) {
  5281. node.exportKind = "type";
  5282. const declarationNode = this.startNode();
  5283. this.next();
  5284. return this.flowParseInterface(declarationNode);
  5285. } else if (this.shouldParseEnums() && this.isContextual(126)) {
  5286. node.exportKind = "value";
  5287. const declarationNode = this.startNode();
  5288. this.next();
  5289. return this.flowParseEnumDeclaration(declarationNode);
  5290. } else {
  5291. return super.parseExportDeclaration(node);
  5292. }
  5293. }
  5294. eatExportStar(node) {
  5295. if (super.eatExportStar(node)) return true;
  5296. if (this.isContextual(130) && this.lookahead().type === 55) {
  5297. node.exportKind = "type";
  5298. this.next();
  5299. this.next();
  5300. return true;
  5301. }
  5302. return false;
  5303. }
  5304. maybeParseExportNamespaceSpecifier(node) {
  5305. const {
  5306. startLoc
  5307. } = this.state;
  5308. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5309. if (hasNamespace && node.exportKind === "type") {
  5310. this.unexpected(startLoc);
  5311. }
  5312. return hasNamespace;
  5313. }
  5314. parseClassId(node, isStatement, optionalId) {
  5315. super.parseClassId(node, isStatement, optionalId);
  5316. if (this.match(47)) {
  5317. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5318. }
  5319. }
  5320. parseClassMember(classBody, member, state) {
  5321. const {
  5322. startLoc
  5323. } = this.state;
  5324. if (this.isContextual(125)) {
  5325. if (super.parseClassMemberFromModifier(classBody, member)) {
  5326. return;
  5327. }
  5328. member.declare = true;
  5329. }
  5330. super.parseClassMember(classBody, member, state);
  5331. if (member.declare) {
  5332. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5333. this.raise(FlowErrors.DeclareClassElement, {
  5334. at: startLoc
  5335. });
  5336. } else if (member.value) {
  5337. this.raise(FlowErrors.DeclareClassFieldInitializer, {
  5338. at: member.value
  5339. });
  5340. }
  5341. }
  5342. }
  5343. isIterator(word) {
  5344. return word === "iterator" || word === "asyncIterator";
  5345. }
  5346. readIterator() {
  5347. const word = super.readWord1();
  5348. const fullWord = "@@" + word;
  5349. if (!this.isIterator(word) || !this.state.inType) {
  5350. this.raise(Errors.InvalidIdentifier, {
  5351. at: this.state.curPosition(),
  5352. identifierName: fullWord
  5353. });
  5354. }
  5355. this.finishToken(132, fullWord);
  5356. }
  5357. getTokenFromCode(code) {
  5358. const next = this.input.charCodeAt(this.state.pos + 1);
  5359. if (code === 123 && next === 124) {
  5360. this.finishOp(6, 2);
  5361. } else if (this.state.inType && (code === 62 || code === 60)) {
  5362. this.finishOp(code === 62 ? 48 : 47, 1);
  5363. } else if (this.state.inType && code === 63) {
  5364. if (next === 46) {
  5365. this.finishOp(18, 2);
  5366. } else {
  5367. this.finishOp(17, 1);
  5368. }
  5369. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5370. this.state.pos += 2;
  5371. this.readIterator();
  5372. } else {
  5373. super.getTokenFromCode(code);
  5374. }
  5375. }
  5376. isAssignable(node, isBinding) {
  5377. if (node.type === "TypeCastExpression") {
  5378. return this.isAssignable(node.expression, isBinding);
  5379. } else {
  5380. return super.isAssignable(node, isBinding);
  5381. }
  5382. }
  5383. toAssignable(node, isLHS = false) {
  5384. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5385. node.left = this.typeCastToParameter(node.left);
  5386. }
  5387. super.toAssignable(node, isLHS);
  5388. }
  5389. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5390. for (let i = 0; i < exprList.length; i++) {
  5391. const expr = exprList[i];
  5392. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5393. exprList[i] = this.typeCastToParameter(expr);
  5394. }
  5395. }
  5396. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5397. }
  5398. toReferencedList(exprList, isParenthesizedExpr) {
  5399. for (let i = 0; i < exprList.length; i++) {
  5400. var _expr$extra;
  5401. const expr = exprList[i];
  5402. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5403. this.raise(FlowErrors.TypeCastInPattern, {
  5404. at: expr.typeAnnotation
  5405. });
  5406. }
  5407. }
  5408. return exprList;
  5409. }
  5410. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5411. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5412. if (canBePattern && !this.state.maybeInArrowParameters) {
  5413. this.toReferencedList(node.elements);
  5414. }
  5415. return node;
  5416. }
  5417. isValidLVal(type, isParenthesized, binding) {
  5418. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5419. }
  5420. parseClassProperty(node) {
  5421. if (this.match(14)) {
  5422. node.typeAnnotation = this.flowParseTypeAnnotation();
  5423. }
  5424. return super.parseClassProperty(node);
  5425. }
  5426. parseClassPrivateProperty(node) {
  5427. if (this.match(14)) {
  5428. node.typeAnnotation = this.flowParseTypeAnnotation();
  5429. }
  5430. return super.parseClassPrivateProperty(node);
  5431. }
  5432. isClassMethod() {
  5433. return this.match(47) || super.isClassMethod();
  5434. }
  5435. isClassProperty() {
  5436. return this.match(14) || super.isClassProperty();
  5437. }
  5438. isNonstaticConstructor(method) {
  5439. return !this.match(14) && super.isNonstaticConstructor(method);
  5440. }
  5441. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5442. if (method.variance) {
  5443. this.unexpected(method.variance.loc.start);
  5444. }
  5445. delete method.variance;
  5446. if (this.match(47)) {
  5447. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5448. }
  5449. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5450. if (method.params && isConstructor) {
  5451. const params = method.params;
  5452. if (params.length > 0 && this.isThisParam(params[0])) {
  5453. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5454. at: method
  5455. });
  5456. }
  5457. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5458. const params = method.value.params;
  5459. if (params.length > 0 && this.isThisParam(params[0])) {
  5460. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5461. at: method
  5462. });
  5463. }
  5464. }
  5465. }
  5466. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5467. if (method.variance) {
  5468. this.unexpected(method.variance.loc.start);
  5469. }
  5470. delete method.variance;
  5471. if (this.match(47)) {
  5472. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5473. }
  5474. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5475. }
  5476. parseClassSuper(node) {
  5477. super.parseClassSuper(node);
  5478. if (node.superClass && this.match(47)) {
  5479. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  5480. }
  5481. if (this.isContextual(113)) {
  5482. this.next();
  5483. const implemented = node.implements = [];
  5484. do {
  5485. const node = this.startNode();
  5486. node.id = this.flowParseRestrictedIdentifier(true);
  5487. if (this.match(47)) {
  5488. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5489. } else {
  5490. node.typeParameters = null;
  5491. }
  5492. implemented.push(this.finishNode(node, "ClassImplements"));
  5493. } while (this.eat(12));
  5494. }
  5495. }
  5496. checkGetterSetterParams(method) {
  5497. super.checkGetterSetterParams(method);
  5498. const params = this.getObjectOrClassMethodParams(method);
  5499. if (params.length > 0) {
  5500. const param = params[0];
  5501. if (this.isThisParam(param) && method.kind === "get") {
  5502. this.raise(FlowErrors.GetterMayNotHaveThisParam, {
  5503. at: param
  5504. });
  5505. } else if (this.isThisParam(param)) {
  5506. this.raise(FlowErrors.SetterMayNotHaveThisParam, {
  5507. at: param
  5508. });
  5509. }
  5510. }
  5511. }
  5512. parsePropertyNamePrefixOperator(node) {
  5513. node.variance = this.flowParseVariance();
  5514. }
  5515. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5516. if (prop.variance) {
  5517. this.unexpected(prop.variance.loc.start);
  5518. }
  5519. delete prop.variance;
  5520. let typeParameters;
  5521. if (this.match(47) && !isAccessor) {
  5522. typeParameters = this.flowParseTypeParameterDeclaration();
  5523. if (!this.match(10)) this.unexpected();
  5524. }
  5525. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5526. if (typeParameters) {
  5527. (result.value || result).typeParameters = typeParameters;
  5528. }
  5529. return result;
  5530. }
  5531. parseAssignableListItemTypes(param) {
  5532. if (this.eat(17)) {
  5533. if (param.type !== "Identifier") {
  5534. this.raise(FlowErrors.PatternIsOptional, {
  5535. at: param
  5536. });
  5537. }
  5538. if (this.isThisParam(param)) {
  5539. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  5540. at: param
  5541. });
  5542. }
  5543. param.optional = true;
  5544. }
  5545. if (this.match(14)) {
  5546. param.typeAnnotation = this.flowParseTypeAnnotation();
  5547. } else if (this.isThisParam(param)) {
  5548. this.raise(FlowErrors.ThisParamAnnotationRequired, {
  5549. at: param
  5550. });
  5551. }
  5552. if (this.match(29) && this.isThisParam(param)) {
  5553. this.raise(FlowErrors.ThisParamNoDefault, {
  5554. at: param
  5555. });
  5556. }
  5557. this.resetEndLocation(param);
  5558. return param;
  5559. }
  5560. parseMaybeDefault(startLoc, left) {
  5561. const node = super.parseMaybeDefault(startLoc, left);
  5562. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5563. this.raise(FlowErrors.TypeBeforeInitializer, {
  5564. at: node.typeAnnotation
  5565. });
  5566. }
  5567. return node;
  5568. }
  5569. checkImportReflection(node) {
  5570. super.checkImportReflection(node);
  5571. if (node.module && node.importKind !== "value") {
  5572. this.raise(FlowErrors.ImportReflectionHasImportType, {
  5573. at: node.specifiers[0].loc.start
  5574. });
  5575. }
  5576. }
  5577. parseImportSpecifierLocal(node, specifier, type) {
  5578. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5579. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5580. }
  5581. isPotentialImportPhase(isExport) {
  5582. if (super.isPotentialImportPhase(isExport)) return true;
  5583. if (this.isContextual(130)) {
  5584. if (!isExport) return true;
  5585. const ch = this.lookaheadCharCode();
  5586. return ch === 123 || ch === 42;
  5587. }
  5588. return !isExport && this.isContextual(87);
  5589. }
  5590. applyImportPhase(node, isExport, phase, loc) {
  5591. super.applyImportPhase(node, isExport, phase, loc);
  5592. if (isExport) {
  5593. if (!phase && this.match(65)) {
  5594. return;
  5595. }
  5596. node.exportKind = phase === "type" ? phase : "value";
  5597. } else {
  5598. if (phase === "type" && this.match(55)) this.unexpected();
  5599. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5600. }
  5601. }
  5602. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5603. const firstIdent = specifier.imported;
  5604. let specifierTypeKind = null;
  5605. if (firstIdent.type === "Identifier") {
  5606. if (firstIdent.name === "type") {
  5607. specifierTypeKind = "type";
  5608. } else if (firstIdent.name === "typeof") {
  5609. specifierTypeKind = "typeof";
  5610. }
  5611. }
  5612. let isBinding = false;
  5613. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5614. const as_ident = this.parseIdentifier(true);
  5615. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5616. specifier.imported = as_ident;
  5617. specifier.importKind = specifierTypeKind;
  5618. specifier.local = cloneIdentifier(as_ident);
  5619. } else {
  5620. specifier.imported = firstIdent;
  5621. specifier.importKind = null;
  5622. specifier.local = this.parseIdentifier();
  5623. }
  5624. } else {
  5625. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5626. specifier.imported = this.parseIdentifier(true);
  5627. specifier.importKind = specifierTypeKind;
  5628. } else {
  5629. if (importedIsString) {
  5630. throw this.raise(Errors.ImportBindingIsString, {
  5631. at: specifier,
  5632. importName: firstIdent.value
  5633. });
  5634. }
  5635. specifier.imported = firstIdent;
  5636. specifier.importKind = null;
  5637. }
  5638. if (this.eatContextual(93)) {
  5639. specifier.local = this.parseIdentifier();
  5640. } else {
  5641. isBinding = true;
  5642. specifier.local = cloneIdentifier(specifier.imported);
  5643. }
  5644. }
  5645. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5646. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5647. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
  5648. at: specifier
  5649. });
  5650. }
  5651. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5652. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5653. }
  5654. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5655. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5656. }
  5657. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5658. }
  5659. parseBindingAtom() {
  5660. switch (this.state.type) {
  5661. case 78:
  5662. return this.parseIdentifier(true);
  5663. default:
  5664. return super.parseBindingAtom();
  5665. }
  5666. }
  5667. parseFunctionParams(node, isConstructor) {
  5668. const kind = node.kind;
  5669. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5670. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5671. }
  5672. super.parseFunctionParams(node, isConstructor);
  5673. }
  5674. parseVarId(decl, kind) {
  5675. super.parseVarId(decl, kind);
  5676. if (this.match(14)) {
  5677. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5678. this.resetEndLocation(decl.id);
  5679. }
  5680. }
  5681. parseAsyncArrowFromCallExpression(node, call) {
  5682. if (this.match(14)) {
  5683. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5684. this.state.noAnonFunctionType = true;
  5685. node.returnType = this.flowParseTypeAnnotation();
  5686. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5687. }
  5688. return super.parseAsyncArrowFromCallExpression(node, call);
  5689. }
  5690. shouldParseAsyncArrow() {
  5691. return this.match(14) || super.shouldParseAsyncArrow();
  5692. }
  5693. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5694. var _jsx;
  5695. let state = null;
  5696. let jsx;
  5697. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  5698. state = this.state.clone();
  5699. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5700. if (!jsx.error) return jsx.node;
  5701. const {
  5702. context
  5703. } = this.state;
  5704. const currentContext = context[context.length - 1];
  5705. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5706. context.pop();
  5707. }
  5708. }
  5709. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5710. var _jsx2, _jsx3;
  5711. state = state || this.state.clone();
  5712. let typeParameters;
  5713. const arrow = this.tryParse(abort => {
  5714. var _arrowExpression$extr;
  5715. typeParameters = this.flowParseTypeParameterDeclaration();
  5716. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5717. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5718. this.resetStartLocationFromNode(result, typeParameters);
  5719. return result;
  5720. });
  5721. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5722. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5723. if (expr.type !== "ArrowFunctionExpression") abort();
  5724. expr.typeParameters = typeParameters;
  5725. this.resetStartLocationFromNode(expr, typeParameters);
  5726. return arrowExpression;
  5727. }, state);
  5728. let arrowExpression = null;
  5729. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5730. if (!arrow.error && !arrow.aborted) {
  5731. if (arrow.node.async) {
  5732. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
  5733. at: typeParameters
  5734. });
  5735. }
  5736. return arrow.node;
  5737. }
  5738. arrowExpression = arrow.node;
  5739. }
  5740. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5741. this.state = jsx.failState;
  5742. return jsx.node;
  5743. }
  5744. if (arrowExpression) {
  5745. this.state = arrow.failState;
  5746. return arrowExpression;
  5747. }
  5748. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5749. if (arrow.thrown) throw arrow.error;
  5750. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
  5751. at: typeParameters
  5752. });
  5753. }
  5754. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5755. }
  5756. parseArrow(node) {
  5757. if (this.match(14)) {
  5758. const result = this.tryParse(() => {
  5759. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5760. this.state.noAnonFunctionType = true;
  5761. const typeNode = this.startNode();
  5762. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5763. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5764. if (this.canInsertSemicolon()) this.unexpected();
  5765. if (!this.match(19)) this.unexpected();
  5766. return typeNode;
  5767. });
  5768. if (result.thrown) return null;
  5769. if (result.error) this.state = result.failState;
  5770. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5771. }
  5772. return super.parseArrow(node);
  5773. }
  5774. shouldParseArrow(params) {
  5775. return this.match(14) || super.shouldParseArrow(params);
  5776. }
  5777. setArrowFunctionParameters(node, params) {
  5778. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5779. node.params = params;
  5780. } else {
  5781. super.setArrowFunctionParameters(node, params);
  5782. }
  5783. }
  5784. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5785. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5786. return;
  5787. }
  5788. for (let i = 0; i < node.params.length; i++) {
  5789. if (this.isThisParam(node.params[i]) && i > 0) {
  5790. this.raise(FlowErrors.ThisParamMustBeFirst, {
  5791. at: node.params[i]
  5792. });
  5793. }
  5794. }
  5795. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5796. }
  5797. parseParenAndDistinguishExpression(canBeArrow) {
  5798. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  5799. }
  5800. parseSubscripts(base, startLoc, noCalls) {
  5801. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
  5802. this.next();
  5803. const node = this.startNodeAt(startLoc);
  5804. node.callee = base;
  5805. node.arguments = super.parseCallExpressionArguments(11, false);
  5806. base = this.finishNode(node, "CallExpression");
  5807. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5808. const state = this.state.clone();
  5809. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5810. if (!arrow.error && !arrow.aborted) return arrow.node;
  5811. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5812. if (result.node && !result.error) return result.node;
  5813. if (arrow.node) {
  5814. this.state = arrow.failState;
  5815. return arrow.node;
  5816. }
  5817. if (result.node) {
  5818. this.state = result.failState;
  5819. return result.node;
  5820. }
  5821. throw arrow.error || result.error;
  5822. }
  5823. return super.parseSubscripts(base, startLoc, noCalls);
  5824. }
  5825. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5826. if (this.match(18) && this.isLookaheadToken_lt()) {
  5827. subscriptState.optionalChainMember = true;
  5828. if (noCalls) {
  5829. subscriptState.stop = true;
  5830. return base;
  5831. }
  5832. this.next();
  5833. const node = this.startNodeAt(startLoc);
  5834. node.callee = base;
  5835. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5836. this.expect(10);
  5837. node.arguments = this.parseCallExpressionArguments(11, false);
  5838. node.optional = true;
  5839. return this.finishCallExpression(node, true);
  5840. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  5841. const node = this.startNodeAt(startLoc);
  5842. node.callee = base;
  5843. const result = this.tryParse(() => {
  5844. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5845. this.expect(10);
  5846. node.arguments = super.parseCallExpressionArguments(11, false);
  5847. if (subscriptState.optionalChainMember) {
  5848. node.optional = false;
  5849. }
  5850. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5851. });
  5852. if (result.node) {
  5853. if (result.error) this.state = result.failState;
  5854. return result.node;
  5855. }
  5856. }
  5857. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5858. }
  5859. parseNewCallee(node) {
  5860. super.parseNewCallee(node);
  5861. let targs = null;
  5862. if (this.shouldParseTypes() && this.match(47)) {
  5863. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5864. }
  5865. node.typeArguments = targs;
  5866. }
  5867. parseAsyncArrowWithTypeParameters(startLoc) {
  5868. const node = this.startNodeAt(startLoc);
  5869. this.parseFunctionParams(node, false);
  5870. if (!this.parseArrow(node)) return;
  5871. return super.parseArrowExpression(node, undefined, true);
  5872. }
  5873. readToken_mult_modulo(code) {
  5874. const next = this.input.charCodeAt(this.state.pos + 1);
  5875. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5876. this.state.hasFlowComment = false;
  5877. this.state.pos += 2;
  5878. this.nextToken();
  5879. return;
  5880. }
  5881. super.readToken_mult_modulo(code);
  5882. }
  5883. readToken_pipe_amp(code) {
  5884. const next = this.input.charCodeAt(this.state.pos + 1);
  5885. if (code === 124 && next === 125) {
  5886. this.finishOp(9, 2);
  5887. return;
  5888. }
  5889. super.readToken_pipe_amp(code);
  5890. }
  5891. parseTopLevel(file, program) {
  5892. const fileNode = super.parseTopLevel(file, program);
  5893. if (this.state.hasFlowComment) {
  5894. this.raise(FlowErrors.UnterminatedFlowComment, {
  5895. at: this.state.curPosition()
  5896. });
  5897. }
  5898. return fileNode;
  5899. }
  5900. skipBlockComment() {
  5901. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5902. if (this.state.hasFlowComment) {
  5903. throw this.raise(FlowErrors.NestedFlowComment, {
  5904. at: this.state.startLoc
  5905. });
  5906. }
  5907. this.hasFlowCommentCompletion();
  5908. const commentSkip = this.skipFlowComment();
  5909. if (commentSkip) {
  5910. this.state.pos += commentSkip;
  5911. this.state.hasFlowComment = true;
  5912. }
  5913. return;
  5914. }
  5915. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5916. }
  5917. skipFlowComment() {
  5918. const {
  5919. pos
  5920. } = this.state;
  5921. let shiftToFirstNonWhiteSpace = 2;
  5922. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5923. shiftToFirstNonWhiteSpace++;
  5924. }
  5925. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5926. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5927. if (ch2 === 58 && ch3 === 58) {
  5928. return shiftToFirstNonWhiteSpace + 2;
  5929. }
  5930. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5931. return shiftToFirstNonWhiteSpace + 12;
  5932. }
  5933. if (ch2 === 58 && ch3 !== 58) {
  5934. return shiftToFirstNonWhiteSpace;
  5935. }
  5936. return false;
  5937. }
  5938. hasFlowCommentCompletion() {
  5939. const end = this.input.indexOf("*/", this.state.pos);
  5940. if (end === -1) {
  5941. throw this.raise(Errors.UnterminatedComment, {
  5942. at: this.state.curPosition()
  5943. });
  5944. }
  5945. }
  5946. flowEnumErrorBooleanMemberNotInitialized(loc, {
  5947. enumName,
  5948. memberName
  5949. }) {
  5950. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
  5951. at: loc,
  5952. memberName,
  5953. enumName
  5954. });
  5955. }
  5956. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  5957. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
  5958. at: loc
  5959. }, enumContext));
  5960. }
  5961. flowEnumErrorNumberMemberNotInitialized(loc, {
  5962. enumName,
  5963. memberName
  5964. }) {
  5965. this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
  5966. at: loc,
  5967. enumName,
  5968. memberName
  5969. });
  5970. }
  5971. flowEnumErrorStringMemberInconsistentlyInitialized(node, {
  5972. enumName
  5973. }) {
  5974. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, {
  5975. at: node,
  5976. enumName
  5977. });
  5978. }
  5979. flowEnumMemberInit() {
  5980. const startLoc = this.state.startLoc;
  5981. const endOfInit = () => this.match(12) || this.match(8);
  5982. switch (this.state.type) {
  5983. case 134:
  5984. {
  5985. const literal = this.parseNumericLiteral(this.state.value);
  5986. if (endOfInit()) {
  5987. return {
  5988. type: "number",
  5989. loc: literal.loc.start,
  5990. value: literal
  5991. };
  5992. }
  5993. return {
  5994. type: "invalid",
  5995. loc: startLoc
  5996. };
  5997. }
  5998. case 133:
  5999. {
  6000. const literal = this.parseStringLiteral(this.state.value);
  6001. if (endOfInit()) {
  6002. return {
  6003. type: "string",
  6004. loc: literal.loc.start,
  6005. value: literal
  6006. };
  6007. }
  6008. return {
  6009. type: "invalid",
  6010. loc: startLoc
  6011. };
  6012. }
  6013. case 85:
  6014. case 86:
  6015. {
  6016. const literal = this.parseBooleanLiteral(this.match(85));
  6017. if (endOfInit()) {
  6018. return {
  6019. type: "boolean",
  6020. loc: literal.loc.start,
  6021. value: literal
  6022. };
  6023. }
  6024. return {
  6025. type: "invalid",
  6026. loc: startLoc
  6027. };
  6028. }
  6029. default:
  6030. return {
  6031. type: "invalid",
  6032. loc: startLoc
  6033. };
  6034. }
  6035. }
  6036. flowEnumMemberRaw() {
  6037. const loc = this.state.startLoc;
  6038. const id = this.parseIdentifier(true);
  6039. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6040. type: "none",
  6041. loc
  6042. };
  6043. return {
  6044. id,
  6045. init
  6046. };
  6047. }
  6048. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6049. const {
  6050. explicitType
  6051. } = context;
  6052. if (explicitType === null) {
  6053. return;
  6054. }
  6055. if (explicitType !== expectedType) {
  6056. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6057. }
  6058. }
  6059. flowEnumMembers({
  6060. enumName,
  6061. explicitType
  6062. }) {
  6063. const seenNames = new Set();
  6064. const members = {
  6065. booleanMembers: [],
  6066. numberMembers: [],
  6067. stringMembers: [],
  6068. defaultedMembers: []
  6069. };
  6070. let hasUnknownMembers = false;
  6071. while (!this.match(8)) {
  6072. if (this.eat(21)) {
  6073. hasUnknownMembers = true;
  6074. break;
  6075. }
  6076. const memberNode = this.startNode();
  6077. const {
  6078. id,
  6079. init
  6080. } = this.flowEnumMemberRaw();
  6081. const memberName = id.name;
  6082. if (memberName === "") {
  6083. continue;
  6084. }
  6085. if (/^[a-z]/.test(memberName)) {
  6086. this.raise(FlowErrors.EnumInvalidMemberName, {
  6087. at: id,
  6088. memberName,
  6089. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6090. enumName
  6091. });
  6092. }
  6093. if (seenNames.has(memberName)) {
  6094. this.raise(FlowErrors.EnumDuplicateMemberName, {
  6095. at: id,
  6096. memberName,
  6097. enumName
  6098. });
  6099. }
  6100. seenNames.add(memberName);
  6101. const context = {
  6102. enumName,
  6103. explicitType,
  6104. memberName
  6105. };
  6106. memberNode.id = id;
  6107. switch (init.type) {
  6108. case "boolean":
  6109. {
  6110. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6111. memberNode.init = init.value;
  6112. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6113. break;
  6114. }
  6115. case "number":
  6116. {
  6117. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6118. memberNode.init = init.value;
  6119. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6120. break;
  6121. }
  6122. case "string":
  6123. {
  6124. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6125. memberNode.init = init.value;
  6126. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6127. break;
  6128. }
  6129. case "invalid":
  6130. {
  6131. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6132. }
  6133. case "none":
  6134. {
  6135. switch (explicitType) {
  6136. case "boolean":
  6137. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6138. break;
  6139. case "number":
  6140. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6141. break;
  6142. default:
  6143. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6144. }
  6145. }
  6146. }
  6147. if (!this.match(8)) {
  6148. this.expect(12);
  6149. }
  6150. }
  6151. return {
  6152. members,
  6153. hasUnknownMembers
  6154. };
  6155. }
  6156. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6157. enumName
  6158. }) {
  6159. if (initializedMembers.length === 0) {
  6160. return defaultedMembers;
  6161. } else if (defaultedMembers.length === 0) {
  6162. return initializedMembers;
  6163. } else if (defaultedMembers.length > initializedMembers.length) {
  6164. for (const member of initializedMembers) {
  6165. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6166. enumName
  6167. });
  6168. }
  6169. return defaultedMembers;
  6170. } else {
  6171. for (const member of defaultedMembers) {
  6172. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6173. enumName
  6174. });
  6175. }
  6176. return initializedMembers;
  6177. }
  6178. }
  6179. flowEnumParseExplicitType({
  6180. enumName
  6181. }) {
  6182. if (!this.eatContextual(102)) return null;
  6183. if (!tokenIsIdentifier(this.state.type)) {
  6184. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
  6185. at: this.state.startLoc,
  6186. enumName
  6187. });
  6188. }
  6189. const {
  6190. value
  6191. } = this.state;
  6192. this.next();
  6193. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6194. this.raise(FlowErrors.EnumInvalidExplicitType, {
  6195. at: this.state.startLoc,
  6196. enumName,
  6197. invalidEnumType: value
  6198. });
  6199. }
  6200. return value;
  6201. }
  6202. flowEnumBody(node, id) {
  6203. const enumName = id.name;
  6204. const nameLoc = id.loc.start;
  6205. const explicitType = this.flowEnumParseExplicitType({
  6206. enumName
  6207. });
  6208. this.expect(5);
  6209. const {
  6210. members,
  6211. hasUnknownMembers
  6212. } = this.flowEnumMembers({
  6213. enumName,
  6214. explicitType
  6215. });
  6216. node.hasUnknownMembers = hasUnknownMembers;
  6217. switch (explicitType) {
  6218. case "boolean":
  6219. node.explicitType = true;
  6220. node.members = members.booleanMembers;
  6221. this.expect(8);
  6222. return this.finishNode(node, "EnumBooleanBody");
  6223. case "number":
  6224. node.explicitType = true;
  6225. node.members = members.numberMembers;
  6226. this.expect(8);
  6227. return this.finishNode(node, "EnumNumberBody");
  6228. case "string":
  6229. node.explicitType = true;
  6230. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6231. enumName
  6232. });
  6233. this.expect(8);
  6234. return this.finishNode(node, "EnumStringBody");
  6235. case "symbol":
  6236. node.members = members.defaultedMembers;
  6237. this.expect(8);
  6238. return this.finishNode(node, "EnumSymbolBody");
  6239. default:
  6240. {
  6241. const empty = () => {
  6242. node.members = [];
  6243. this.expect(8);
  6244. return this.finishNode(node, "EnumStringBody");
  6245. };
  6246. node.explicitType = false;
  6247. const boolsLen = members.booleanMembers.length;
  6248. const numsLen = members.numberMembers.length;
  6249. const strsLen = members.stringMembers.length;
  6250. const defaultedLen = members.defaultedMembers.length;
  6251. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6252. return empty();
  6253. } else if (!boolsLen && !numsLen) {
  6254. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6255. enumName
  6256. });
  6257. this.expect(8);
  6258. return this.finishNode(node, "EnumStringBody");
  6259. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6260. for (const member of members.defaultedMembers) {
  6261. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6262. enumName,
  6263. memberName: member.id.name
  6264. });
  6265. }
  6266. node.members = members.booleanMembers;
  6267. this.expect(8);
  6268. return this.finishNode(node, "EnumBooleanBody");
  6269. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6270. for (const member of members.defaultedMembers) {
  6271. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6272. enumName,
  6273. memberName: member.id.name
  6274. });
  6275. }
  6276. node.members = members.numberMembers;
  6277. this.expect(8);
  6278. return this.finishNode(node, "EnumNumberBody");
  6279. } else {
  6280. this.raise(FlowErrors.EnumInconsistentMemberValues, {
  6281. at: nameLoc,
  6282. enumName
  6283. });
  6284. return empty();
  6285. }
  6286. }
  6287. }
  6288. }
  6289. flowParseEnumDeclaration(node) {
  6290. const id = this.parseIdentifier();
  6291. node.id = id;
  6292. node.body = this.flowEnumBody(this.startNode(), id);
  6293. return this.finishNode(node, "EnumDeclaration");
  6294. }
  6295. isLookaheadToken_lt() {
  6296. const next = this.nextTokenStart();
  6297. if (this.input.charCodeAt(next) === 60) {
  6298. const afterNext = this.input.charCodeAt(next + 1);
  6299. return afterNext !== 60 && afterNext !== 61;
  6300. }
  6301. return false;
  6302. }
  6303. maybeUnwrapTypeCastExpression(node) {
  6304. return node.type === "TypeCastExpression" ? node.expression : node;
  6305. }
  6306. };
  6307. const entities = {
  6308. __proto__: null,
  6309. quot: "\u0022",
  6310. amp: "&",
  6311. apos: "\u0027",
  6312. lt: "<",
  6313. gt: ">",
  6314. nbsp: "\u00A0",
  6315. iexcl: "\u00A1",
  6316. cent: "\u00A2",
  6317. pound: "\u00A3",
  6318. curren: "\u00A4",
  6319. yen: "\u00A5",
  6320. brvbar: "\u00A6",
  6321. sect: "\u00A7",
  6322. uml: "\u00A8",
  6323. copy: "\u00A9",
  6324. ordf: "\u00AA",
  6325. laquo: "\u00AB",
  6326. not: "\u00AC",
  6327. shy: "\u00AD",
  6328. reg: "\u00AE",
  6329. macr: "\u00AF",
  6330. deg: "\u00B0",
  6331. plusmn: "\u00B1",
  6332. sup2: "\u00B2",
  6333. sup3: "\u00B3",
  6334. acute: "\u00B4",
  6335. micro: "\u00B5",
  6336. para: "\u00B6",
  6337. middot: "\u00B7",
  6338. cedil: "\u00B8",
  6339. sup1: "\u00B9",
  6340. ordm: "\u00BA",
  6341. raquo: "\u00BB",
  6342. frac14: "\u00BC",
  6343. frac12: "\u00BD",
  6344. frac34: "\u00BE",
  6345. iquest: "\u00BF",
  6346. Agrave: "\u00C0",
  6347. Aacute: "\u00C1",
  6348. Acirc: "\u00C2",
  6349. Atilde: "\u00C3",
  6350. Auml: "\u00C4",
  6351. Aring: "\u00C5",
  6352. AElig: "\u00C6",
  6353. Ccedil: "\u00C7",
  6354. Egrave: "\u00C8",
  6355. Eacute: "\u00C9",
  6356. Ecirc: "\u00CA",
  6357. Euml: "\u00CB",
  6358. Igrave: "\u00CC",
  6359. Iacute: "\u00CD",
  6360. Icirc: "\u00CE",
  6361. Iuml: "\u00CF",
  6362. ETH: "\u00D0",
  6363. Ntilde: "\u00D1",
  6364. Ograve: "\u00D2",
  6365. Oacute: "\u00D3",
  6366. Ocirc: "\u00D4",
  6367. Otilde: "\u00D5",
  6368. Ouml: "\u00D6",
  6369. times: "\u00D7",
  6370. Oslash: "\u00D8",
  6371. Ugrave: "\u00D9",
  6372. Uacute: "\u00DA",
  6373. Ucirc: "\u00DB",
  6374. Uuml: "\u00DC",
  6375. Yacute: "\u00DD",
  6376. THORN: "\u00DE",
  6377. szlig: "\u00DF",
  6378. agrave: "\u00E0",
  6379. aacute: "\u00E1",
  6380. acirc: "\u00E2",
  6381. atilde: "\u00E3",
  6382. auml: "\u00E4",
  6383. aring: "\u00E5",
  6384. aelig: "\u00E6",
  6385. ccedil: "\u00E7",
  6386. egrave: "\u00E8",
  6387. eacute: "\u00E9",
  6388. ecirc: "\u00EA",
  6389. euml: "\u00EB",
  6390. igrave: "\u00EC",
  6391. iacute: "\u00ED",
  6392. icirc: "\u00EE",
  6393. iuml: "\u00EF",
  6394. eth: "\u00F0",
  6395. ntilde: "\u00F1",
  6396. ograve: "\u00F2",
  6397. oacute: "\u00F3",
  6398. ocirc: "\u00F4",
  6399. otilde: "\u00F5",
  6400. ouml: "\u00F6",
  6401. divide: "\u00F7",
  6402. oslash: "\u00F8",
  6403. ugrave: "\u00F9",
  6404. uacute: "\u00FA",
  6405. ucirc: "\u00FB",
  6406. uuml: "\u00FC",
  6407. yacute: "\u00FD",
  6408. thorn: "\u00FE",
  6409. yuml: "\u00FF",
  6410. OElig: "\u0152",
  6411. oelig: "\u0153",
  6412. Scaron: "\u0160",
  6413. scaron: "\u0161",
  6414. Yuml: "\u0178",
  6415. fnof: "\u0192",
  6416. circ: "\u02C6",
  6417. tilde: "\u02DC",
  6418. Alpha: "\u0391",
  6419. Beta: "\u0392",
  6420. Gamma: "\u0393",
  6421. Delta: "\u0394",
  6422. Epsilon: "\u0395",
  6423. Zeta: "\u0396",
  6424. Eta: "\u0397",
  6425. Theta: "\u0398",
  6426. Iota: "\u0399",
  6427. Kappa: "\u039A",
  6428. Lambda: "\u039B",
  6429. Mu: "\u039C",
  6430. Nu: "\u039D",
  6431. Xi: "\u039E",
  6432. Omicron: "\u039F",
  6433. Pi: "\u03A0",
  6434. Rho: "\u03A1",
  6435. Sigma: "\u03A3",
  6436. Tau: "\u03A4",
  6437. Upsilon: "\u03A5",
  6438. Phi: "\u03A6",
  6439. Chi: "\u03A7",
  6440. Psi: "\u03A8",
  6441. Omega: "\u03A9",
  6442. alpha: "\u03B1",
  6443. beta: "\u03B2",
  6444. gamma: "\u03B3",
  6445. delta: "\u03B4",
  6446. epsilon: "\u03B5",
  6447. zeta: "\u03B6",
  6448. eta: "\u03B7",
  6449. theta: "\u03B8",
  6450. iota: "\u03B9",
  6451. kappa: "\u03BA",
  6452. lambda: "\u03BB",
  6453. mu: "\u03BC",
  6454. nu: "\u03BD",
  6455. xi: "\u03BE",
  6456. omicron: "\u03BF",
  6457. pi: "\u03C0",
  6458. rho: "\u03C1",
  6459. sigmaf: "\u03C2",
  6460. sigma: "\u03C3",
  6461. tau: "\u03C4",
  6462. upsilon: "\u03C5",
  6463. phi: "\u03C6",
  6464. chi: "\u03C7",
  6465. psi: "\u03C8",
  6466. omega: "\u03C9",
  6467. thetasym: "\u03D1",
  6468. upsih: "\u03D2",
  6469. piv: "\u03D6",
  6470. ensp: "\u2002",
  6471. emsp: "\u2003",
  6472. thinsp: "\u2009",
  6473. zwnj: "\u200C",
  6474. zwj: "\u200D",
  6475. lrm: "\u200E",
  6476. rlm: "\u200F",
  6477. ndash: "\u2013",
  6478. mdash: "\u2014",
  6479. lsquo: "\u2018",
  6480. rsquo: "\u2019",
  6481. sbquo: "\u201A",
  6482. ldquo: "\u201C",
  6483. rdquo: "\u201D",
  6484. bdquo: "\u201E",
  6485. dagger: "\u2020",
  6486. Dagger: "\u2021",
  6487. bull: "\u2022",
  6488. hellip: "\u2026",
  6489. permil: "\u2030",
  6490. prime: "\u2032",
  6491. Prime: "\u2033",
  6492. lsaquo: "\u2039",
  6493. rsaquo: "\u203A",
  6494. oline: "\u203E",
  6495. frasl: "\u2044",
  6496. euro: "\u20AC",
  6497. image: "\u2111",
  6498. weierp: "\u2118",
  6499. real: "\u211C",
  6500. trade: "\u2122",
  6501. alefsym: "\u2135",
  6502. larr: "\u2190",
  6503. uarr: "\u2191",
  6504. rarr: "\u2192",
  6505. darr: "\u2193",
  6506. harr: "\u2194",
  6507. crarr: "\u21B5",
  6508. lArr: "\u21D0",
  6509. uArr: "\u21D1",
  6510. rArr: "\u21D2",
  6511. dArr: "\u21D3",
  6512. hArr: "\u21D4",
  6513. forall: "\u2200",
  6514. part: "\u2202",
  6515. exist: "\u2203",
  6516. empty: "\u2205",
  6517. nabla: "\u2207",
  6518. isin: "\u2208",
  6519. notin: "\u2209",
  6520. ni: "\u220B",
  6521. prod: "\u220F",
  6522. sum: "\u2211",
  6523. minus: "\u2212",
  6524. lowast: "\u2217",
  6525. radic: "\u221A",
  6526. prop: "\u221D",
  6527. infin: "\u221E",
  6528. ang: "\u2220",
  6529. and: "\u2227",
  6530. or: "\u2228",
  6531. cap: "\u2229",
  6532. cup: "\u222A",
  6533. int: "\u222B",
  6534. there4: "\u2234",
  6535. sim: "\u223C",
  6536. cong: "\u2245",
  6537. asymp: "\u2248",
  6538. ne: "\u2260",
  6539. equiv: "\u2261",
  6540. le: "\u2264",
  6541. ge: "\u2265",
  6542. sub: "\u2282",
  6543. sup: "\u2283",
  6544. nsub: "\u2284",
  6545. sube: "\u2286",
  6546. supe: "\u2287",
  6547. oplus: "\u2295",
  6548. otimes: "\u2297",
  6549. perp: "\u22A5",
  6550. sdot: "\u22C5",
  6551. lceil: "\u2308",
  6552. rceil: "\u2309",
  6553. lfloor: "\u230A",
  6554. rfloor: "\u230B",
  6555. lang: "\u2329",
  6556. rang: "\u232A",
  6557. loz: "\u25CA",
  6558. spades: "\u2660",
  6559. clubs: "\u2663",
  6560. hearts: "\u2665",
  6561. diams: "\u2666"
  6562. };
  6563. const JsxErrors = ParseErrorEnum`jsx`({
  6564. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6565. MissingClosingTagElement: ({
  6566. openingTagName
  6567. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6568. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6569. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6570. UnexpectedToken: ({
  6571. unexpected,
  6572. HTMLEntity
  6573. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6574. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6575. UnterminatedJsxContent: "Unterminated JSX contents.",
  6576. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6577. });
  6578. function isFragment(object) {
  6579. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6580. }
  6581. function getQualifiedJSXName(object) {
  6582. if (object.type === "JSXIdentifier") {
  6583. return object.name;
  6584. }
  6585. if (object.type === "JSXNamespacedName") {
  6586. return object.namespace.name + ":" + object.name.name;
  6587. }
  6588. if (object.type === "JSXMemberExpression") {
  6589. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6590. }
  6591. throw new Error("Node had unexpected type: " + object.type);
  6592. }
  6593. var jsx = superClass => class JSXParserMixin extends superClass {
  6594. jsxReadToken() {
  6595. let out = "";
  6596. let chunkStart = this.state.pos;
  6597. for (;;) {
  6598. if (this.state.pos >= this.length) {
  6599. throw this.raise(JsxErrors.UnterminatedJsxContent, {
  6600. at: this.state.startLoc
  6601. });
  6602. }
  6603. const ch = this.input.charCodeAt(this.state.pos);
  6604. switch (ch) {
  6605. case 60:
  6606. case 123:
  6607. if (this.state.pos === this.state.start) {
  6608. if (ch === 60 && this.state.canStartJSXElement) {
  6609. ++this.state.pos;
  6610. this.finishToken(142);
  6611. } else {
  6612. super.getTokenFromCode(ch);
  6613. }
  6614. return;
  6615. }
  6616. out += this.input.slice(chunkStart, this.state.pos);
  6617. this.finishToken(141, out);
  6618. return;
  6619. case 38:
  6620. out += this.input.slice(chunkStart, this.state.pos);
  6621. out += this.jsxReadEntity();
  6622. chunkStart = this.state.pos;
  6623. break;
  6624. case 62:
  6625. case 125:
  6626. default:
  6627. if (isNewLine(ch)) {
  6628. out += this.input.slice(chunkStart, this.state.pos);
  6629. out += this.jsxReadNewLine(true);
  6630. chunkStart = this.state.pos;
  6631. } else {
  6632. ++this.state.pos;
  6633. }
  6634. }
  6635. }
  6636. }
  6637. jsxReadNewLine(normalizeCRLF) {
  6638. const ch = this.input.charCodeAt(this.state.pos);
  6639. let out;
  6640. ++this.state.pos;
  6641. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6642. ++this.state.pos;
  6643. out = normalizeCRLF ? "\n" : "\r\n";
  6644. } else {
  6645. out = String.fromCharCode(ch);
  6646. }
  6647. ++this.state.curLine;
  6648. this.state.lineStart = this.state.pos;
  6649. return out;
  6650. }
  6651. jsxReadString(quote) {
  6652. let out = "";
  6653. let chunkStart = ++this.state.pos;
  6654. for (;;) {
  6655. if (this.state.pos >= this.length) {
  6656. throw this.raise(Errors.UnterminatedString, {
  6657. at: this.state.startLoc
  6658. });
  6659. }
  6660. const ch = this.input.charCodeAt(this.state.pos);
  6661. if (ch === quote) break;
  6662. if (ch === 38) {
  6663. out += this.input.slice(chunkStart, this.state.pos);
  6664. out += this.jsxReadEntity();
  6665. chunkStart = this.state.pos;
  6666. } else if (isNewLine(ch)) {
  6667. out += this.input.slice(chunkStart, this.state.pos);
  6668. out += this.jsxReadNewLine(false);
  6669. chunkStart = this.state.pos;
  6670. } else {
  6671. ++this.state.pos;
  6672. }
  6673. }
  6674. out += this.input.slice(chunkStart, this.state.pos++);
  6675. this.finishToken(133, out);
  6676. }
  6677. jsxReadEntity() {
  6678. const startPos = ++this.state.pos;
  6679. if (this.codePointAtPos(this.state.pos) === 35) {
  6680. ++this.state.pos;
  6681. let radix = 10;
  6682. if (this.codePointAtPos(this.state.pos) === 120) {
  6683. radix = 16;
  6684. ++this.state.pos;
  6685. }
  6686. const codePoint = this.readInt(radix, undefined, false, "bail");
  6687. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6688. ++this.state.pos;
  6689. return String.fromCodePoint(codePoint);
  6690. }
  6691. } else {
  6692. let count = 0;
  6693. let semi = false;
  6694. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
  6695. ++this.state.pos;
  6696. }
  6697. if (semi) {
  6698. const desc = this.input.slice(startPos, this.state.pos);
  6699. const entity = entities[desc];
  6700. ++this.state.pos;
  6701. if (entity) {
  6702. return entity;
  6703. }
  6704. }
  6705. }
  6706. this.state.pos = startPos;
  6707. return "&";
  6708. }
  6709. jsxReadWord() {
  6710. let ch;
  6711. const start = this.state.pos;
  6712. do {
  6713. ch = this.input.charCodeAt(++this.state.pos);
  6714. } while (isIdentifierChar(ch) || ch === 45);
  6715. this.finishToken(140, this.input.slice(start, this.state.pos));
  6716. }
  6717. jsxParseIdentifier() {
  6718. const node = this.startNode();
  6719. if (this.match(140)) {
  6720. node.name = this.state.value;
  6721. } else if (tokenIsKeyword(this.state.type)) {
  6722. node.name = tokenLabelName(this.state.type);
  6723. } else {
  6724. this.unexpected();
  6725. }
  6726. this.next();
  6727. return this.finishNode(node, "JSXIdentifier");
  6728. }
  6729. jsxParseNamespacedName() {
  6730. const startLoc = this.state.startLoc;
  6731. const name = this.jsxParseIdentifier();
  6732. if (!this.eat(14)) return name;
  6733. const node = this.startNodeAt(startLoc);
  6734. node.namespace = name;
  6735. node.name = this.jsxParseIdentifier();
  6736. return this.finishNode(node, "JSXNamespacedName");
  6737. }
  6738. jsxParseElementName() {
  6739. const startLoc = this.state.startLoc;
  6740. let node = this.jsxParseNamespacedName();
  6741. if (node.type === "JSXNamespacedName") {
  6742. return node;
  6743. }
  6744. while (this.eat(16)) {
  6745. const newNode = this.startNodeAt(startLoc);
  6746. newNode.object = node;
  6747. newNode.property = this.jsxParseIdentifier();
  6748. node = this.finishNode(newNode, "JSXMemberExpression");
  6749. }
  6750. return node;
  6751. }
  6752. jsxParseAttributeValue() {
  6753. let node;
  6754. switch (this.state.type) {
  6755. case 5:
  6756. node = this.startNode();
  6757. this.setContext(types.brace);
  6758. this.next();
  6759. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6760. if (node.expression.type === "JSXEmptyExpression") {
  6761. this.raise(JsxErrors.AttributeIsEmpty, {
  6762. at: node
  6763. });
  6764. }
  6765. return node;
  6766. case 142:
  6767. case 133:
  6768. return this.parseExprAtom();
  6769. default:
  6770. throw this.raise(JsxErrors.UnsupportedJsxValue, {
  6771. at: this.state.startLoc
  6772. });
  6773. }
  6774. }
  6775. jsxParseEmptyExpression() {
  6776. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6777. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6778. }
  6779. jsxParseSpreadChild(node) {
  6780. this.next();
  6781. node.expression = this.parseExpression();
  6782. this.setContext(types.j_expr);
  6783. this.state.canStartJSXElement = true;
  6784. this.expect(8);
  6785. return this.finishNode(node, "JSXSpreadChild");
  6786. }
  6787. jsxParseExpressionContainer(node, previousContext) {
  6788. if (this.match(8)) {
  6789. node.expression = this.jsxParseEmptyExpression();
  6790. } else {
  6791. const expression = this.parseExpression();
  6792. node.expression = expression;
  6793. }
  6794. this.setContext(previousContext);
  6795. this.state.canStartJSXElement = true;
  6796. this.expect(8);
  6797. return this.finishNode(node, "JSXExpressionContainer");
  6798. }
  6799. jsxParseAttribute() {
  6800. const node = this.startNode();
  6801. if (this.match(5)) {
  6802. this.setContext(types.brace);
  6803. this.next();
  6804. this.expect(21);
  6805. node.argument = this.parseMaybeAssignAllowIn();
  6806. this.setContext(types.j_oTag);
  6807. this.state.canStartJSXElement = true;
  6808. this.expect(8);
  6809. return this.finishNode(node, "JSXSpreadAttribute");
  6810. }
  6811. node.name = this.jsxParseNamespacedName();
  6812. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6813. return this.finishNode(node, "JSXAttribute");
  6814. }
  6815. jsxParseOpeningElementAt(startLoc) {
  6816. const node = this.startNodeAt(startLoc);
  6817. if (this.eat(143)) {
  6818. return this.finishNode(node, "JSXOpeningFragment");
  6819. }
  6820. node.name = this.jsxParseElementName();
  6821. return this.jsxParseOpeningElementAfterName(node);
  6822. }
  6823. jsxParseOpeningElementAfterName(node) {
  6824. const attributes = [];
  6825. while (!this.match(56) && !this.match(143)) {
  6826. attributes.push(this.jsxParseAttribute());
  6827. }
  6828. node.attributes = attributes;
  6829. node.selfClosing = this.eat(56);
  6830. this.expect(143);
  6831. return this.finishNode(node, "JSXOpeningElement");
  6832. }
  6833. jsxParseClosingElementAt(startLoc) {
  6834. const node = this.startNodeAt(startLoc);
  6835. if (this.eat(143)) {
  6836. return this.finishNode(node, "JSXClosingFragment");
  6837. }
  6838. node.name = this.jsxParseElementName();
  6839. this.expect(143);
  6840. return this.finishNode(node, "JSXClosingElement");
  6841. }
  6842. jsxParseElementAt(startLoc) {
  6843. const node = this.startNodeAt(startLoc);
  6844. const children = [];
  6845. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6846. let closingElement = null;
  6847. if (!openingElement.selfClosing) {
  6848. contents: for (;;) {
  6849. switch (this.state.type) {
  6850. case 142:
  6851. startLoc = this.state.startLoc;
  6852. this.next();
  6853. if (this.eat(56)) {
  6854. closingElement = this.jsxParseClosingElementAt(startLoc);
  6855. break contents;
  6856. }
  6857. children.push(this.jsxParseElementAt(startLoc));
  6858. break;
  6859. case 141:
  6860. children.push(this.parseExprAtom());
  6861. break;
  6862. case 5:
  6863. {
  6864. const node = this.startNode();
  6865. this.setContext(types.brace);
  6866. this.next();
  6867. if (this.match(21)) {
  6868. children.push(this.jsxParseSpreadChild(node));
  6869. } else {
  6870. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6871. }
  6872. break;
  6873. }
  6874. default:
  6875. this.unexpected();
  6876. }
  6877. }
  6878. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6879. this.raise(JsxErrors.MissingClosingTagFragment, {
  6880. at: closingElement
  6881. });
  6882. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6883. this.raise(JsxErrors.MissingClosingTagElement, {
  6884. at: closingElement,
  6885. openingTagName: getQualifiedJSXName(openingElement.name)
  6886. });
  6887. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6888. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6889. this.raise(JsxErrors.MissingClosingTagElement, {
  6890. at: closingElement,
  6891. openingTagName: getQualifiedJSXName(openingElement.name)
  6892. });
  6893. }
  6894. }
  6895. }
  6896. if (isFragment(openingElement)) {
  6897. node.openingFragment = openingElement;
  6898. node.closingFragment = closingElement;
  6899. } else {
  6900. node.openingElement = openingElement;
  6901. node.closingElement = closingElement;
  6902. }
  6903. node.children = children;
  6904. if (this.match(47)) {
  6905. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
  6906. at: this.state.startLoc
  6907. });
  6908. }
  6909. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6910. }
  6911. jsxParseElement() {
  6912. const startLoc = this.state.startLoc;
  6913. this.next();
  6914. return this.jsxParseElementAt(startLoc);
  6915. }
  6916. setContext(newContext) {
  6917. const {
  6918. context
  6919. } = this.state;
  6920. context[context.length - 1] = newContext;
  6921. }
  6922. parseExprAtom(refExpressionErrors) {
  6923. if (this.match(141)) {
  6924. return this.parseLiteral(this.state.value, "JSXText");
  6925. } else if (this.match(142)) {
  6926. return this.jsxParseElement();
  6927. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  6928. this.replaceToken(142);
  6929. return this.jsxParseElement();
  6930. } else {
  6931. return super.parseExprAtom(refExpressionErrors);
  6932. }
  6933. }
  6934. skipSpace() {
  6935. const curContext = this.curContext();
  6936. if (!curContext.preserveSpace) super.skipSpace();
  6937. }
  6938. getTokenFromCode(code) {
  6939. const context = this.curContext();
  6940. if (context === types.j_expr) {
  6941. this.jsxReadToken();
  6942. return;
  6943. }
  6944. if (context === types.j_oTag || context === types.j_cTag) {
  6945. if (isIdentifierStart(code)) {
  6946. this.jsxReadWord();
  6947. return;
  6948. }
  6949. if (code === 62) {
  6950. ++this.state.pos;
  6951. this.finishToken(143);
  6952. return;
  6953. }
  6954. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6955. this.jsxReadString(code);
  6956. return;
  6957. }
  6958. }
  6959. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  6960. ++this.state.pos;
  6961. this.finishToken(142);
  6962. return;
  6963. }
  6964. super.getTokenFromCode(code);
  6965. }
  6966. updateContext(prevType) {
  6967. const {
  6968. context,
  6969. type
  6970. } = this.state;
  6971. if (type === 56 && prevType === 142) {
  6972. context.splice(-2, 2, types.j_cTag);
  6973. this.state.canStartJSXElement = false;
  6974. } else if (type === 142) {
  6975. context.push(types.j_oTag);
  6976. } else if (type === 143) {
  6977. const out = context[context.length - 1];
  6978. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  6979. context.pop();
  6980. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  6981. } else {
  6982. this.setContext(types.j_expr);
  6983. this.state.canStartJSXElement = true;
  6984. }
  6985. } else {
  6986. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  6987. }
  6988. }
  6989. };
  6990. class TypeScriptScope extends Scope {
  6991. constructor(...args) {
  6992. super(...args);
  6993. this.types = new Set();
  6994. this.enums = new Set();
  6995. this.constEnums = new Set();
  6996. this.classes = new Set();
  6997. this.exportOnlyBindings = new Set();
  6998. }
  6999. }
  7000. class TypeScriptScopeHandler extends ScopeHandler {
  7001. constructor(...args) {
  7002. super(...args);
  7003. this.importsStack = [];
  7004. }
  7005. createScope(flags) {
  7006. this.importsStack.push(new Set());
  7007. return new TypeScriptScope(flags);
  7008. }
  7009. enter(flags) {
  7010. if (flags == 256) {
  7011. this.importsStack.push(new Set());
  7012. }
  7013. super.enter(flags);
  7014. }
  7015. exit() {
  7016. const flags = super.exit();
  7017. if (flags == 256) {
  7018. this.importsStack.pop();
  7019. }
  7020. return flags;
  7021. }
  7022. hasImport(name, allowShadow) {
  7023. const len = this.importsStack.length;
  7024. if (this.importsStack[len - 1].has(name)) {
  7025. return true;
  7026. }
  7027. if (!allowShadow && len > 1) {
  7028. for (let i = 0; i < len - 1; i++) {
  7029. if (this.importsStack[i].has(name)) return true;
  7030. }
  7031. }
  7032. return false;
  7033. }
  7034. declareName(name, bindingType, loc) {
  7035. if (bindingType & 4096) {
  7036. if (this.hasImport(name, true)) {
  7037. this.parser.raise(Errors.VarRedeclaration, {
  7038. at: loc,
  7039. identifierName: name
  7040. });
  7041. }
  7042. this.importsStack[this.importsStack.length - 1].add(name);
  7043. return;
  7044. }
  7045. const scope = this.currentScope();
  7046. if (bindingType & 1024) {
  7047. this.maybeExportDefined(scope, name);
  7048. scope.exportOnlyBindings.add(name);
  7049. return;
  7050. }
  7051. super.declareName(name, bindingType, loc);
  7052. if (bindingType & 2) {
  7053. if (!(bindingType & 1)) {
  7054. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7055. this.maybeExportDefined(scope, name);
  7056. }
  7057. scope.types.add(name);
  7058. }
  7059. if (bindingType & 256) scope.enums.add(name);
  7060. if (bindingType & 512) {
  7061. scope.constEnums.add(name);
  7062. }
  7063. if (bindingType & 128) scope.classes.add(name);
  7064. }
  7065. isRedeclaredInScope(scope, name, bindingType) {
  7066. if (scope.enums.has(name)) {
  7067. if (bindingType & 256) {
  7068. const isConst = !!(bindingType & 512);
  7069. const wasConst = scope.constEnums.has(name);
  7070. return isConst !== wasConst;
  7071. }
  7072. return true;
  7073. }
  7074. if (bindingType & 128 && scope.classes.has(name)) {
  7075. if (scope.lexical.has(name)) {
  7076. return !!(bindingType & 1);
  7077. } else {
  7078. return false;
  7079. }
  7080. }
  7081. if (bindingType & 2 && scope.types.has(name)) {
  7082. return true;
  7083. }
  7084. return super.isRedeclaredInScope(scope, name, bindingType);
  7085. }
  7086. checkLocalExport(id) {
  7087. const {
  7088. name
  7089. } = id;
  7090. if (this.hasImport(name)) return;
  7091. const len = this.scopeStack.length;
  7092. for (let i = len - 1; i >= 0; i--) {
  7093. const scope = this.scopeStack[i];
  7094. if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return;
  7095. }
  7096. super.checkLocalExport(id);
  7097. }
  7098. }
  7099. const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7100. const unwrapParenthesizedExpression = node => {
  7101. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7102. };
  7103. class LValParser extends NodeUtils {
  7104. toAssignable(node, isLHS = false) {
  7105. var _node$extra, _node$extra3;
  7106. let parenthesized = undefined;
  7107. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7108. parenthesized = unwrapParenthesizedExpression(node);
  7109. if (isLHS) {
  7110. if (parenthesized.type === "Identifier") {
  7111. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
  7112. at: node
  7113. });
  7114. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7115. this.raise(Errors.InvalidParenthesizedAssignment, {
  7116. at: node
  7117. });
  7118. }
  7119. } else {
  7120. this.raise(Errors.InvalidParenthesizedAssignment, {
  7121. at: node
  7122. });
  7123. }
  7124. }
  7125. switch (node.type) {
  7126. case "Identifier":
  7127. case "ObjectPattern":
  7128. case "ArrayPattern":
  7129. case "AssignmentPattern":
  7130. case "RestElement":
  7131. break;
  7132. case "ObjectExpression":
  7133. node.type = "ObjectPattern";
  7134. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7135. var _node$extra2;
  7136. const prop = node.properties[i];
  7137. const isLast = i === last;
  7138. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7139. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7140. this.raise(Errors.RestTrailingComma, {
  7141. at: node.extra.trailingCommaLoc
  7142. });
  7143. }
  7144. }
  7145. break;
  7146. case "ObjectProperty":
  7147. {
  7148. const {
  7149. key,
  7150. value
  7151. } = node;
  7152. if (this.isPrivateName(key)) {
  7153. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7154. }
  7155. this.toAssignable(value, isLHS);
  7156. break;
  7157. }
  7158. case "SpreadElement":
  7159. {
  7160. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7161. }
  7162. case "ArrayExpression":
  7163. node.type = "ArrayPattern";
  7164. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7165. break;
  7166. case "AssignmentExpression":
  7167. if (node.operator !== "=") {
  7168. this.raise(Errors.MissingEqInAssignment, {
  7169. at: node.left.loc.end
  7170. });
  7171. }
  7172. node.type = "AssignmentPattern";
  7173. delete node.operator;
  7174. this.toAssignable(node.left, isLHS);
  7175. break;
  7176. case "ParenthesizedExpression":
  7177. this.toAssignable(parenthesized, isLHS);
  7178. break;
  7179. }
  7180. }
  7181. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7182. if (prop.type === "ObjectMethod") {
  7183. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
  7184. at: prop.key
  7185. });
  7186. } else if (prop.type === "SpreadElement") {
  7187. prop.type = "RestElement";
  7188. const arg = prop.argument;
  7189. this.checkToRestConversion(arg, false);
  7190. this.toAssignable(arg, isLHS);
  7191. if (!isLast) {
  7192. this.raise(Errors.RestTrailingComma, {
  7193. at: prop
  7194. });
  7195. }
  7196. } else {
  7197. this.toAssignable(prop, isLHS);
  7198. }
  7199. }
  7200. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7201. const end = exprList.length - 1;
  7202. for (let i = 0; i <= end; i++) {
  7203. const elt = exprList[i];
  7204. if (!elt) continue;
  7205. if (elt.type === "SpreadElement") {
  7206. elt.type = "RestElement";
  7207. const arg = elt.argument;
  7208. this.checkToRestConversion(arg, true);
  7209. this.toAssignable(arg, isLHS);
  7210. } else {
  7211. this.toAssignable(elt, isLHS);
  7212. }
  7213. if (elt.type === "RestElement") {
  7214. if (i < end) {
  7215. this.raise(Errors.RestTrailingComma, {
  7216. at: elt
  7217. });
  7218. } else if (trailingCommaLoc) {
  7219. this.raise(Errors.RestTrailingComma, {
  7220. at: trailingCommaLoc
  7221. });
  7222. }
  7223. }
  7224. }
  7225. }
  7226. isAssignable(node, isBinding) {
  7227. switch (node.type) {
  7228. case "Identifier":
  7229. case "ObjectPattern":
  7230. case "ArrayPattern":
  7231. case "AssignmentPattern":
  7232. case "RestElement":
  7233. return true;
  7234. case "ObjectExpression":
  7235. {
  7236. const last = node.properties.length - 1;
  7237. return node.properties.every((prop, i) => {
  7238. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7239. });
  7240. }
  7241. case "ObjectProperty":
  7242. return this.isAssignable(node.value);
  7243. case "SpreadElement":
  7244. return this.isAssignable(node.argument);
  7245. case "ArrayExpression":
  7246. return node.elements.every(element => element === null || this.isAssignable(element));
  7247. case "AssignmentExpression":
  7248. return node.operator === "=";
  7249. case "ParenthesizedExpression":
  7250. return this.isAssignable(node.expression);
  7251. case "MemberExpression":
  7252. case "OptionalMemberExpression":
  7253. return !isBinding;
  7254. default:
  7255. return false;
  7256. }
  7257. }
  7258. toReferencedList(exprList, isParenthesizedExpr) {
  7259. return exprList;
  7260. }
  7261. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7262. this.toReferencedList(exprList, isParenthesizedExpr);
  7263. for (const expr of exprList) {
  7264. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7265. this.toReferencedListDeep(expr.elements);
  7266. }
  7267. }
  7268. }
  7269. parseSpread(refExpressionErrors) {
  7270. const node = this.startNode();
  7271. this.next();
  7272. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7273. return this.finishNode(node, "SpreadElement");
  7274. }
  7275. parseRestBinding() {
  7276. const node = this.startNode();
  7277. this.next();
  7278. node.argument = this.parseBindingAtom();
  7279. return this.finishNode(node, "RestElement");
  7280. }
  7281. parseBindingAtom() {
  7282. switch (this.state.type) {
  7283. case 0:
  7284. {
  7285. const node = this.startNode();
  7286. this.next();
  7287. node.elements = this.parseBindingList(3, 93, 1);
  7288. return this.finishNode(node, "ArrayPattern");
  7289. }
  7290. case 5:
  7291. return this.parseObjectLike(8, true);
  7292. }
  7293. return this.parseIdentifier();
  7294. }
  7295. parseBindingList(close, closeCharCode, flags) {
  7296. const allowEmpty = flags & 1;
  7297. const elts = [];
  7298. let first = true;
  7299. while (!this.eat(close)) {
  7300. if (first) {
  7301. first = false;
  7302. } else {
  7303. this.expect(12);
  7304. }
  7305. if (allowEmpty && this.match(12)) {
  7306. elts.push(null);
  7307. } else if (this.eat(close)) {
  7308. break;
  7309. } else if (this.match(21)) {
  7310. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
  7311. if (!this.checkCommaAfterRest(closeCharCode)) {
  7312. this.expect(close);
  7313. break;
  7314. }
  7315. } else {
  7316. const decorators = [];
  7317. if (this.match(26) && this.hasPlugin("decorators")) {
  7318. this.raise(Errors.UnsupportedParameterDecorator, {
  7319. at: this.state.startLoc
  7320. });
  7321. }
  7322. while (this.match(26)) {
  7323. decorators.push(this.parseDecorator());
  7324. }
  7325. elts.push(this.parseAssignableListItem(flags, decorators));
  7326. }
  7327. }
  7328. return elts;
  7329. }
  7330. parseBindingRestProperty(prop) {
  7331. this.next();
  7332. prop.argument = this.parseIdentifier();
  7333. this.checkCommaAfterRest(125);
  7334. return this.finishNode(prop, "RestElement");
  7335. }
  7336. parseBindingProperty() {
  7337. const prop = this.startNode();
  7338. const {
  7339. type,
  7340. startLoc
  7341. } = this.state;
  7342. if (type === 21) {
  7343. return this.parseBindingRestProperty(prop);
  7344. } else if (type === 138) {
  7345. this.expectPlugin("destructuringPrivate", startLoc);
  7346. this.classScope.usePrivateName(this.state.value, startLoc);
  7347. prop.key = this.parsePrivateName();
  7348. } else {
  7349. this.parsePropertyName(prop);
  7350. }
  7351. prop.method = false;
  7352. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7353. }
  7354. parseAssignableListItem(flags, decorators) {
  7355. const left = this.parseMaybeDefault();
  7356. this.parseAssignableListItemTypes(left, flags);
  7357. const elt = this.parseMaybeDefault(left.loc.start, left);
  7358. if (decorators.length) {
  7359. left.decorators = decorators;
  7360. }
  7361. return elt;
  7362. }
  7363. parseAssignableListItemTypes(param, flags) {
  7364. return param;
  7365. }
  7366. parseMaybeDefault(startLoc, left) {
  7367. var _startLoc, _left;
  7368. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  7369. left = (_left = left) != null ? _left : this.parseBindingAtom();
  7370. if (!this.eat(29)) return left;
  7371. const node = this.startNodeAt(startLoc);
  7372. node.left = left;
  7373. node.right = this.parseMaybeAssignAllowIn();
  7374. return this.finishNode(node, "AssignmentPattern");
  7375. }
  7376. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7377. return getOwn$1({
  7378. AssignmentPattern: "left",
  7379. RestElement: "argument",
  7380. ObjectProperty: "value",
  7381. ParenthesizedExpression: "expression",
  7382. ArrayPattern: "elements",
  7383. ObjectPattern: "properties"
  7384. }, type);
  7385. }
  7386. isOptionalMemberExpression(expression) {
  7387. return expression.type === "OptionalMemberExpression";
  7388. }
  7389. checkLVal(expression, {
  7390. in: ancestor,
  7391. binding = 64,
  7392. checkClashes = false,
  7393. strictModeChanged = false,
  7394. hasParenthesizedAncestor = false
  7395. }) {
  7396. var _expression$extra;
  7397. const type = expression.type;
  7398. if (this.isObjectMethod(expression)) return;
  7399. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7400. if (isOptionalMemberExpression || type === "MemberExpression") {
  7401. if (isOptionalMemberExpression) {
  7402. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7403. if (ancestor.type !== "AssignmentExpression") {
  7404. this.raise(Errors.InvalidLhsOptionalChaining, {
  7405. at: expression,
  7406. ancestor
  7407. });
  7408. }
  7409. }
  7410. if (binding !== 64) {
  7411. this.raise(Errors.InvalidPropertyBindingPattern, {
  7412. at: expression
  7413. });
  7414. }
  7415. return;
  7416. }
  7417. if (type === "Identifier") {
  7418. this.checkIdentifier(expression, binding, strictModeChanged);
  7419. const {
  7420. name
  7421. } = expression;
  7422. if (checkClashes) {
  7423. if (checkClashes.has(name)) {
  7424. this.raise(Errors.ParamDupe, {
  7425. at: expression
  7426. });
  7427. } else {
  7428. checkClashes.add(name);
  7429. }
  7430. }
  7431. return;
  7432. }
  7433. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7434. if (validity === true) return;
  7435. if (validity === false) {
  7436. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7437. this.raise(ParseErrorClass, {
  7438. at: expression,
  7439. ancestor
  7440. });
  7441. return;
  7442. }
  7443. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  7444. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7445. type
  7446. } : ancestor;
  7447. for (const child of [].concat(expression[key])) {
  7448. if (child) {
  7449. this.checkLVal(child, {
  7450. in: nextAncestor,
  7451. binding,
  7452. checkClashes,
  7453. strictModeChanged,
  7454. hasParenthesizedAncestor: isParenthesizedExpression
  7455. });
  7456. }
  7457. }
  7458. }
  7459. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7460. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7461. if (bindingType === 64) {
  7462. this.raise(Errors.StrictEvalArguments, {
  7463. at,
  7464. referenceName: at.name
  7465. });
  7466. } else {
  7467. this.raise(Errors.StrictEvalArgumentsBinding, {
  7468. at,
  7469. bindingName: at.name
  7470. });
  7471. }
  7472. }
  7473. if (bindingType & 8192 && at.name === "let") {
  7474. this.raise(Errors.LetInLexicalBinding, {
  7475. at
  7476. });
  7477. }
  7478. if (!(bindingType & 64)) {
  7479. this.declareNameFromIdentifier(at, bindingType);
  7480. }
  7481. }
  7482. declareNameFromIdentifier(identifier, binding) {
  7483. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7484. }
  7485. checkToRestConversion(node, allowPattern) {
  7486. switch (node.type) {
  7487. case "ParenthesizedExpression":
  7488. this.checkToRestConversion(node.expression, allowPattern);
  7489. break;
  7490. case "Identifier":
  7491. case "MemberExpression":
  7492. break;
  7493. case "ArrayExpression":
  7494. case "ObjectExpression":
  7495. if (allowPattern) break;
  7496. default:
  7497. this.raise(Errors.InvalidRestAssignmentPattern, {
  7498. at: node
  7499. });
  7500. }
  7501. }
  7502. checkCommaAfterRest(close) {
  7503. if (!this.match(12)) {
  7504. return false;
  7505. }
  7506. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
  7507. at: this.state.startLoc
  7508. });
  7509. return true;
  7510. }
  7511. }
  7512. const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7513. function nonNull(x) {
  7514. if (x == null) {
  7515. throw new Error(`Unexpected ${x} value.`);
  7516. }
  7517. return x;
  7518. }
  7519. function assert(x) {
  7520. if (!x) {
  7521. throw new Error("Assert fail");
  7522. }
  7523. }
  7524. const TSErrors = ParseErrorEnum`typescript`({
  7525. AbstractMethodHasImplementation: ({
  7526. methodName
  7527. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7528. AbstractPropertyHasInitializer: ({
  7529. propertyName
  7530. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7531. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7532. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7533. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7534. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7535. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7536. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7537. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7538. DeclareAccessor: ({
  7539. kind
  7540. }) => `'declare' is not allowed in ${kind}ters.`,
  7541. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7542. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7543. DuplicateAccessibilityModifier: ({
  7544. modifier
  7545. }) => `Accessibility modifier already seen.`,
  7546. DuplicateModifier: ({
  7547. modifier
  7548. }) => `Duplicate modifier: '${modifier}'.`,
  7549. EmptyHeritageClauseType: ({
  7550. token
  7551. }) => `'${token}' list cannot be empty.`,
  7552. EmptyTypeArguments: "Type argument list cannot be empty.",
  7553. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7554. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7555. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7556. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7557. IncompatibleModifiers: ({
  7558. modifiers
  7559. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7560. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7561. IndexSignatureHasAccessibility: ({
  7562. modifier
  7563. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7564. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7565. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7566. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7567. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7568. InvalidModifierOnTypeMember: ({
  7569. modifier
  7570. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7571. InvalidModifierOnTypeParameter: ({
  7572. modifier
  7573. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7574. InvalidModifierOnTypeParameterPositions: ({
  7575. modifier
  7576. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7577. InvalidModifiersOrder: ({
  7578. orderedModifiers
  7579. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7580. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7581. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7582. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7583. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7584. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7585. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7586. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7587. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7588. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7589. PrivateElementHasAccessibility: ({
  7590. modifier
  7591. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7592. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7593. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7594. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7595. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7596. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7597. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7598. SingleTypeParameterWithoutTrailingComma: ({
  7599. typeParameterName
  7600. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7601. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7602. 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?`).",
  7603. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7604. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7605. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7606. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7607. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7608. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7609. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7610. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7611. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7612. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7613. UnsupportedSignatureParameterKind: ({
  7614. type
  7615. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7616. });
  7617. function keywordTypeFromName(value) {
  7618. switch (value) {
  7619. case "any":
  7620. return "TSAnyKeyword";
  7621. case "boolean":
  7622. return "TSBooleanKeyword";
  7623. case "bigint":
  7624. return "TSBigIntKeyword";
  7625. case "never":
  7626. return "TSNeverKeyword";
  7627. case "number":
  7628. return "TSNumberKeyword";
  7629. case "object":
  7630. return "TSObjectKeyword";
  7631. case "string":
  7632. return "TSStringKeyword";
  7633. case "symbol":
  7634. return "TSSymbolKeyword";
  7635. case "undefined":
  7636. return "TSUndefinedKeyword";
  7637. case "unknown":
  7638. return "TSUnknownKeyword";
  7639. default:
  7640. return undefined;
  7641. }
  7642. }
  7643. function tsIsAccessModifier(modifier) {
  7644. return modifier === "private" || modifier === "public" || modifier === "protected";
  7645. }
  7646. function tsIsVarianceAnnotations(modifier) {
  7647. return modifier === "in" || modifier === "out";
  7648. }
  7649. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7650. constructor(...args) {
  7651. super(...args);
  7652. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7653. allowedModifiers: ["in", "out"],
  7654. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7655. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7656. });
  7657. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7658. allowedModifiers: ["const"],
  7659. disallowedModifiers: ["in", "out"],
  7660. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7661. });
  7662. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7663. allowedModifiers: ["in", "out", "const"],
  7664. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7665. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7666. });
  7667. }
  7668. getScopeHandler() {
  7669. return TypeScriptScopeHandler;
  7670. }
  7671. tsIsIdentifier() {
  7672. return tokenIsIdentifier(this.state.type);
  7673. }
  7674. tsTokenCanFollowModifier() {
  7675. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(138) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  7676. }
  7677. tsNextTokenCanFollowModifier() {
  7678. this.next();
  7679. return this.tsTokenCanFollowModifier();
  7680. }
  7681. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7682. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7683. return undefined;
  7684. }
  7685. const modifier = this.state.value;
  7686. if (allowedModifiers.indexOf(modifier) !== -1) {
  7687. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7688. return undefined;
  7689. }
  7690. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7691. return modifier;
  7692. }
  7693. }
  7694. return undefined;
  7695. }
  7696. tsParseModifiers({
  7697. allowedModifiers,
  7698. disallowedModifiers,
  7699. stopOnStartOfClassStaticBlock,
  7700. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7701. }, modified) {
  7702. const enforceOrder = (loc, modifier, before, after) => {
  7703. if (modifier === before && modified[after]) {
  7704. this.raise(TSErrors.InvalidModifiersOrder, {
  7705. at: loc,
  7706. orderedModifiers: [before, after]
  7707. });
  7708. }
  7709. };
  7710. const incompatible = (loc, modifier, mod1, mod2) => {
  7711. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7712. this.raise(TSErrors.IncompatibleModifiers, {
  7713. at: loc,
  7714. modifiers: [mod1, mod2]
  7715. });
  7716. }
  7717. };
  7718. for (;;) {
  7719. const {
  7720. startLoc
  7721. } = this.state;
  7722. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7723. if (!modifier) break;
  7724. if (tsIsAccessModifier(modifier)) {
  7725. if (modified.accessibility) {
  7726. this.raise(TSErrors.DuplicateAccessibilityModifier, {
  7727. at: startLoc,
  7728. modifier
  7729. });
  7730. } else {
  7731. enforceOrder(startLoc, modifier, modifier, "override");
  7732. enforceOrder(startLoc, modifier, modifier, "static");
  7733. enforceOrder(startLoc, modifier, modifier, "readonly");
  7734. modified.accessibility = modifier;
  7735. }
  7736. } else if (tsIsVarianceAnnotations(modifier)) {
  7737. if (modified[modifier]) {
  7738. this.raise(TSErrors.DuplicateModifier, {
  7739. at: startLoc,
  7740. modifier
  7741. });
  7742. }
  7743. modified[modifier] = true;
  7744. enforceOrder(startLoc, modifier, "in", "out");
  7745. } else {
  7746. if (Object.hasOwnProperty.call(modified, modifier)) {
  7747. this.raise(TSErrors.DuplicateModifier, {
  7748. at: startLoc,
  7749. modifier
  7750. });
  7751. } else {
  7752. enforceOrder(startLoc, modifier, "static", "readonly");
  7753. enforceOrder(startLoc, modifier, "static", "override");
  7754. enforceOrder(startLoc, modifier, "override", "readonly");
  7755. enforceOrder(startLoc, modifier, "abstract", "override");
  7756. incompatible(startLoc, modifier, "declare", "override");
  7757. incompatible(startLoc, modifier, "static", "abstract");
  7758. }
  7759. modified[modifier] = true;
  7760. }
  7761. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7762. this.raise(errorTemplate, {
  7763. at: startLoc,
  7764. modifier
  7765. });
  7766. }
  7767. }
  7768. }
  7769. tsIsListTerminator(kind) {
  7770. switch (kind) {
  7771. case "EnumMembers":
  7772. case "TypeMembers":
  7773. return this.match(8);
  7774. case "HeritageClauseElement":
  7775. return this.match(5);
  7776. case "TupleElementTypes":
  7777. return this.match(3);
  7778. case "TypeParametersOrArguments":
  7779. return this.match(48);
  7780. }
  7781. }
  7782. tsParseList(kind, parseElement) {
  7783. const result = [];
  7784. while (!this.tsIsListTerminator(kind)) {
  7785. result.push(parseElement());
  7786. }
  7787. return result;
  7788. }
  7789. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7790. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7791. }
  7792. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7793. const result = [];
  7794. let trailingCommaPos = -1;
  7795. for (;;) {
  7796. if (this.tsIsListTerminator(kind)) {
  7797. break;
  7798. }
  7799. trailingCommaPos = -1;
  7800. const element = parseElement();
  7801. if (element == null) {
  7802. return undefined;
  7803. }
  7804. result.push(element);
  7805. if (this.eat(12)) {
  7806. trailingCommaPos = this.state.lastTokStart;
  7807. continue;
  7808. }
  7809. if (this.tsIsListTerminator(kind)) {
  7810. break;
  7811. }
  7812. if (expectSuccess) {
  7813. this.expect(12);
  7814. }
  7815. return undefined;
  7816. }
  7817. if (refTrailingCommaPos) {
  7818. refTrailingCommaPos.value = trailingCommaPos;
  7819. }
  7820. return result;
  7821. }
  7822. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7823. if (!skipFirstToken) {
  7824. if (bracket) {
  7825. this.expect(0);
  7826. } else {
  7827. this.expect(47);
  7828. }
  7829. }
  7830. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7831. if (bracket) {
  7832. this.expect(3);
  7833. } else {
  7834. this.expect(48);
  7835. }
  7836. return result;
  7837. }
  7838. tsParseImportType() {
  7839. const node = this.startNode();
  7840. this.expect(83);
  7841. this.expect(10);
  7842. if (!this.match(133)) {
  7843. this.raise(TSErrors.UnsupportedImportTypeArgument, {
  7844. at: this.state.startLoc
  7845. });
  7846. }
  7847. node.argument = super.parseExprAtom();
  7848. this.expect(11);
  7849. if (this.eat(16)) {
  7850. node.qualifier = this.tsParseEntityName();
  7851. }
  7852. if (this.match(47)) {
  7853. node.typeParameters = this.tsParseTypeArguments();
  7854. }
  7855. return this.finishNode(node, "TSImportType");
  7856. }
  7857. tsParseEntityName(allowReservedWords = true) {
  7858. let entity = this.parseIdentifier(allowReservedWords);
  7859. while (this.eat(16)) {
  7860. const node = this.startNodeAtNode(entity);
  7861. node.left = entity;
  7862. node.right = this.parseIdentifier(allowReservedWords);
  7863. entity = this.finishNode(node, "TSQualifiedName");
  7864. }
  7865. return entity;
  7866. }
  7867. tsParseTypeReference() {
  7868. const node = this.startNode();
  7869. node.typeName = this.tsParseEntityName();
  7870. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7871. node.typeParameters = this.tsParseTypeArguments();
  7872. }
  7873. return this.finishNode(node, "TSTypeReference");
  7874. }
  7875. tsParseThisTypePredicate(lhs) {
  7876. this.next();
  7877. const node = this.startNodeAtNode(lhs);
  7878. node.parameterName = lhs;
  7879. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7880. node.asserts = false;
  7881. return this.finishNode(node, "TSTypePredicate");
  7882. }
  7883. tsParseThisTypeNode() {
  7884. const node = this.startNode();
  7885. this.next();
  7886. return this.finishNode(node, "TSThisType");
  7887. }
  7888. tsParseTypeQuery() {
  7889. const node = this.startNode();
  7890. this.expect(87);
  7891. if (this.match(83)) {
  7892. node.exprName = this.tsParseImportType();
  7893. } else {
  7894. node.exprName = this.tsParseEntityName();
  7895. }
  7896. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7897. node.typeParameters = this.tsParseTypeArguments();
  7898. }
  7899. return this.finishNode(node, "TSTypeQuery");
  7900. }
  7901. tsParseTypeParameter(parseModifiers) {
  7902. const node = this.startNode();
  7903. parseModifiers(node);
  7904. node.name = this.tsParseTypeParameterName();
  7905. node.constraint = this.tsEatThenParseType(81);
  7906. node.default = this.tsEatThenParseType(29);
  7907. return this.finishNode(node, "TSTypeParameter");
  7908. }
  7909. tsTryParseTypeParameters(parseModifiers) {
  7910. if (this.match(47)) {
  7911. return this.tsParseTypeParameters(parseModifiers);
  7912. }
  7913. }
  7914. tsParseTypeParameters(parseModifiers) {
  7915. const node = this.startNode();
  7916. if (this.match(47) || this.match(142)) {
  7917. this.next();
  7918. } else {
  7919. this.unexpected();
  7920. }
  7921. const refTrailingCommaPos = {
  7922. value: -1
  7923. };
  7924. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7925. if (node.params.length === 0) {
  7926. this.raise(TSErrors.EmptyTypeParameters, {
  7927. at: node
  7928. });
  7929. }
  7930. if (refTrailingCommaPos.value !== -1) {
  7931. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7932. }
  7933. return this.finishNode(node, "TSTypeParameterDeclaration");
  7934. }
  7935. tsFillSignature(returnToken, signature) {
  7936. const returnTokenRequired = returnToken === 19;
  7937. const paramsKey = "parameters";
  7938. const returnTypeKey = "typeAnnotation";
  7939. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  7940. this.expect(10);
  7941. signature[paramsKey] = this.tsParseBindingListForSignature();
  7942. if (returnTokenRequired) {
  7943. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7944. } else if (this.match(returnToken)) {
  7945. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7946. }
  7947. }
  7948. tsParseBindingListForSignature() {
  7949. const list = super.parseBindingList(11, 41, 2);
  7950. for (const pattern of list) {
  7951. const {
  7952. type
  7953. } = pattern;
  7954. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  7955. this.raise(TSErrors.UnsupportedSignatureParameterKind, {
  7956. at: pattern,
  7957. type
  7958. });
  7959. }
  7960. }
  7961. return list;
  7962. }
  7963. tsParseTypeMemberSemicolon() {
  7964. if (!this.eat(12) && !this.isLineTerminator()) {
  7965. this.expect(13);
  7966. }
  7967. }
  7968. tsParseSignatureMember(kind, node) {
  7969. this.tsFillSignature(14, node);
  7970. this.tsParseTypeMemberSemicolon();
  7971. return this.finishNode(node, kind);
  7972. }
  7973. tsIsUnambiguouslyIndexSignature() {
  7974. this.next();
  7975. if (tokenIsIdentifier(this.state.type)) {
  7976. this.next();
  7977. return this.match(14);
  7978. }
  7979. return false;
  7980. }
  7981. tsTryParseIndexSignature(node) {
  7982. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  7983. return;
  7984. }
  7985. this.expect(0);
  7986. const id = this.parseIdentifier();
  7987. id.typeAnnotation = this.tsParseTypeAnnotation();
  7988. this.resetEndLocation(id);
  7989. this.expect(3);
  7990. node.parameters = [id];
  7991. const type = this.tsTryParseTypeAnnotation();
  7992. if (type) node.typeAnnotation = type;
  7993. this.tsParseTypeMemberSemicolon();
  7994. return this.finishNode(node, "TSIndexSignature");
  7995. }
  7996. tsParsePropertyOrMethodSignature(node, readonly) {
  7997. if (this.eat(17)) node.optional = true;
  7998. const nodeAny = node;
  7999. if (this.match(10) || this.match(47)) {
  8000. if (readonly) {
  8001. this.raise(TSErrors.ReadonlyForMethodSignature, {
  8002. at: node
  8003. });
  8004. }
  8005. const method = nodeAny;
  8006. if (method.kind && this.match(47)) {
  8007. this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
  8008. at: this.state.curPosition()
  8009. });
  8010. }
  8011. this.tsFillSignature(14, method);
  8012. this.tsParseTypeMemberSemicolon();
  8013. const paramsKey = "parameters";
  8014. const returnTypeKey = "typeAnnotation";
  8015. if (method.kind === "get") {
  8016. if (method[paramsKey].length > 0) {
  8017. this.raise(Errors.BadGetterArity, {
  8018. at: this.state.curPosition()
  8019. });
  8020. if (this.isThisParam(method[paramsKey][0])) {
  8021. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8022. at: this.state.curPosition()
  8023. });
  8024. }
  8025. }
  8026. } else if (method.kind === "set") {
  8027. if (method[paramsKey].length !== 1) {
  8028. this.raise(Errors.BadSetterArity, {
  8029. at: this.state.curPosition()
  8030. });
  8031. } else {
  8032. const firstParameter = method[paramsKey][0];
  8033. if (this.isThisParam(firstParameter)) {
  8034. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8035. at: this.state.curPosition()
  8036. });
  8037. }
  8038. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8039. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
  8040. at: this.state.curPosition()
  8041. });
  8042. }
  8043. if (firstParameter.type === "RestElement") {
  8044. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
  8045. at: this.state.curPosition()
  8046. });
  8047. }
  8048. }
  8049. if (method[returnTypeKey]) {
  8050. this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
  8051. at: method[returnTypeKey]
  8052. });
  8053. }
  8054. } else {
  8055. method.kind = "method";
  8056. }
  8057. return this.finishNode(method, "TSMethodSignature");
  8058. } else {
  8059. const property = nodeAny;
  8060. if (readonly) property.readonly = true;
  8061. const type = this.tsTryParseTypeAnnotation();
  8062. if (type) property.typeAnnotation = type;
  8063. this.tsParseTypeMemberSemicolon();
  8064. return this.finishNode(property, "TSPropertySignature");
  8065. }
  8066. }
  8067. tsParseTypeMember() {
  8068. const node = this.startNode();
  8069. if (this.match(10) || this.match(47)) {
  8070. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8071. }
  8072. if (this.match(77)) {
  8073. const id = this.startNode();
  8074. this.next();
  8075. if (this.match(10) || this.match(47)) {
  8076. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8077. } else {
  8078. node.key = this.createIdentifier(id, "new");
  8079. return this.tsParsePropertyOrMethodSignature(node, false);
  8080. }
  8081. }
  8082. this.tsParseModifiers({
  8083. allowedModifiers: ["readonly"],
  8084. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8085. }, node);
  8086. const idx = this.tsTryParseIndexSignature(node);
  8087. if (idx) {
  8088. return idx;
  8089. }
  8090. super.parsePropertyName(node);
  8091. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8092. node.kind = node.key.name;
  8093. super.parsePropertyName(node);
  8094. }
  8095. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8096. }
  8097. tsParseTypeLiteral() {
  8098. const node = this.startNode();
  8099. node.members = this.tsParseObjectTypeMembers();
  8100. return this.finishNode(node, "TSTypeLiteral");
  8101. }
  8102. tsParseObjectTypeMembers() {
  8103. this.expect(5);
  8104. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8105. this.expect(8);
  8106. return members;
  8107. }
  8108. tsIsStartOfMappedType() {
  8109. this.next();
  8110. if (this.eat(53)) {
  8111. return this.isContextual(122);
  8112. }
  8113. if (this.isContextual(122)) {
  8114. this.next();
  8115. }
  8116. if (!this.match(0)) {
  8117. return false;
  8118. }
  8119. this.next();
  8120. if (!this.tsIsIdentifier()) {
  8121. return false;
  8122. }
  8123. this.next();
  8124. return this.match(58);
  8125. }
  8126. tsParseMappedTypeParameter() {
  8127. const node = this.startNode();
  8128. node.name = this.tsParseTypeParameterName();
  8129. node.constraint = this.tsExpectThenParseType(58);
  8130. return this.finishNode(node, "TSTypeParameter");
  8131. }
  8132. tsParseMappedType() {
  8133. const node = this.startNode();
  8134. this.expect(5);
  8135. if (this.match(53)) {
  8136. node.readonly = this.state.value;
  8137. this.next();
  8138. this.expectContextual(122);
  8139. } else if (this.eatContextual(122)) {
  8140. node.readonly = true;
  8141. }
  8142. this.expect(0);
  8143. node.typeParameter = this.tsParseMappedTypeParameter();
  8144. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8145. this.expect(3);
  8146. if (this.match(53)) {
  8147. node.optional = this.state.value;
  8148. this.next();
  8149. this.expect(17);
  8150. } else if (this.eat(17)) {
  8151. node.optional = true;
  8152. }
  8153. node.typeAnnotation = this.tsTryParseType();
  8154. this.semicolon();
  8155. this.expect(8);
  8156. return this.finishNode(node, "TSMappedType");
  8157. }
  8158. tsParseTupleType() {
  8159. const node = this.startNode();
  8160. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8161. let seenOptionalElement = false;
  8162. node.elementTypes.forEach(elementNode => {
  8163. const {
  8164. type
  8165. } = elementNode;
  8166. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8167. this.raise(TSErrors.OptionalTypeBeforeRequired, {
  8168. at: elementNode
  8169. });
  8170. }
  8171. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8172. });
  8173. return this.finishNode(node, "TSTupleType");
  8174. }
  8175. tsParseTupleElementType() {
  8176. const {
  8177. startLoc
  8178. } = this.state;
  8179. const rest = this.eat(21);
  8180. let labeled;
  8181. let label;
  8182. let optional;
  8183. let type;
  8184. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8185. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8186. if (chAfterWord === 58) {
  8187. labeled = true;
  8188. optional = false;
  8189. label = this.parseIdentifier(true);
  8190. this.expect(14);
  8191. type = this.tsParseType();
  8192. } else if (chAfterWord === 63) {
  8193. optional = true;
  8194. const startLoc = this.state.startLoc;
  8195. const wordName = this.state.value;
  8196. const typeOrLabel = this.tsParseNonArrayType();
  8197. if (this.lookaheadCharCode() === 58) {
  8198. labeled = true;
  8199. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8200. this.expect(17);
  8201. this.expect(14);
  8202. type = this.tsParseType();
  8203. } else {
  8204. labeled = false;
  8205. type = typeOrLabel;
  8206. this.expect(17);
  8207. }
  8208. } else {
  8209. type = this.tsParseType();
  8210. optional = this.eat(17);
  8211. labeled = this.eat(14);
  8212. }
  8213. if (labeled) {
  8214. let labeledNode;
  8215. if (label) {
  8216. labeledNode = this.startNodeAtNode(label);
  8217. labeledNode.optional = optional;
  8218. labeledNode.label = label;
  8219. labeledNode.elementType = type;
  8220. if (this.eat(17)) {
  8221. labeledNode.optional = true;
  8222. this.raise(TSErrors.TupleOptionalAfterType, {
  8223. at: this.state.lastTokStartLoc
  8224. });
  8225. }
  8226. } else {
  8227. labeledNode = this.startNodeAtNode(type);
  8228. labeledNode.optional = optional;
  8229. this.raise(TSErrors.InvalidTupleMemberLabel, {
  8230. at: type
  8231. });
  8232. labeledNode.label = type;
  8233. labeledNode.elementType = this.tsParseType();
  8234. }
  8235. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8236. } else if (optional) {
  8237. const optionalTypeNode = this.startNodeAtNode(type);
  8238. optionalTypeNode.typeAnnotation = type;
  8239. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8240. }
  8241. if (rest) {
  8242. const restNode = this.startNodeAt(startLoc);
  8243. restNode.typeAnnotation = type;
  8244. type = this.finishNode(restNode, "TSRestType");
  8245. }
  8246. return type;
  8247. }
  8248. tsParseParenthesizedType() {
  8249. const node = this.startNode();
  8250. this.expect(10);
  8251. node.typeAnnotation = this.tsParseType();
  8252. this.expect(11);
  8253. return this.finishNode(node, "TSParenthesizedType");
  8254. }
  8255. tsParseFunctionOrConstructorType(type, abstract) {
  8256. const node = this.startNode();
  8257. if (type === "TSConstructorType") {
  8258. node.abstract = !!abstract;
  8259. if (abstract) this.next();
  8260. this.next();
  8261. }
  8262. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8263. return this.finishNode(node, type);
  8264. }
  8265. tsParseLiteralTypeNode() {
  8266. const node = this.startNode();
  8267. switch (this.state.type) {
  8268. case 134:
  8269. case 135:
  8270. case 133:
  8271. case 85:
  8272. case 86:
  8273. node.literal = super.parseExprAtom();
  8274. break;
  8275. default:
  8276. this.unexpected();
  8277. }
  8278. return this.finishNode(node, "TSLiteralType");
  8279. }
  8280. tsParseTemplateLiteralType() {
  8281. const node = this.startNode();
  8282. node.literal = super.parseTemplate(false);
  8283. return this.finishNode(node, "TSLiteralType");
  8284. }
  8285. parseTemplateSubstitution() {
  8286. if (this.state.inType) return this.tsParseType();
  8287. return super.parseTemplateSubstitution();
  8288. }
  8289. tsParseThisTypeOrThisTypePredicate() {
  8290. const thisKeyword = this.tsParseThisTypeNode();
  8291. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8292. return this.tsParseThisTypePredicate(thisKeyword);
  8293. } else {
  8294. return thisKeyword;
  8295. }
  8296. }
  8297. tsParseNonArrayType() {
  8298. switch (this.state.type) {
  8299. case 133:
  8300. case 134:
  8301. case 135:
  8302. case 85:
  8303. case 86:
  8304. return this.tsParseLiteralTypeNode();
  8305. case 53:
  8306. if (this.state.value === "-") {
  8307. const node = this.startNode();
  8308. const nextToken = this.lookahead();
  8309. if (nextToken.type !== 134 && nextToken.type !== 135) {
  8310. this.unexpected();
  8311. }
  8312. node.literal = this.parseMaybeUnary();
  8313. return this.finishNode(node, "TSLiteralType");
  8314. }
  8315. break;
  8316. case 78:
  8317. return this.tsParseThisTypeOrThisTypePredicate();
  8318. case 87:
  8319. return this.tsParseTypeQuery();
  8320. case 83:
  8321. return this.tsParseImportType();
  8322. case 5:
  8323. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8324. case 0:
  8325. return this.tsParseTupleType();
  8326. case 10:
  8327. return this.tsParseParenthesizedType();
  8328. case 25:
  8329. case 24:
  8330. return this.tsParseTemplateLiteralType();
  8331. default:
  8332. {
  8333. const {
  8334. type
  8335. } = this.state;
  8336. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8337. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8338. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8339. const node = this.startNode();
  8340. this.next();
  8341. return this.finishNode(node, nodeType);
  8342. }
  8343. return this.tsParseTypeReference();
  8344. }
  8345. }
  8346. }
  8347. this.unexpected();
  8348. }
  8349. tsParseArrayTypeOrHigher() {
  8350. let type = this.tsParseNonArrayType();
  8351. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8352. if (this.match(3)) {
  8353. const node = this.startNodeAtNode(type);
  8354. node.elementType = type;
  8355. this.expect(3);
  8356. type = this.finishNode(node, "TSArrayType");
  8357. } else {
  8358. const node = this.startNodeAtNode(type);
  8359. node.objectType = type;
  8360. node.indexType = this.tsParseType();
  8361. this.expect(3);
  8362. type = this.finishNode(node, "TSIndexedAccessType");
  8363. }
  8364. }
  8365. return type;
  8366. }
  8367. tsParseTypeOperator() {
  8368. const node = this.startNode();
  8369. const operator = this.state.value;
  8370. this.next();
  8371. node.operator = operator;
  8372. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8373. if (operator === "readonly") {
  8374. this.tsCheckTypeAnnotationForReadOnly(node);
  8375. }
  8376. return this.finishNode(node, "TSTypeOperator");
  8377. }
  8378. tsCheckTypeAnnotationForReadOnly(node) {
  8379. switch (node.typeAnnotation.type) {
  8380. case "TSTupleType":
  8381. case "TSArrayType":
  8382. return;
  8383. default:
  8384. this.raise(TSErrors.UnexpectedReadonly, {
  8385. at: node
  8386. });
  8387. }
  8388. }
  8389. tsParseInferType() {
  8390. const node = this.startNode();
  8391. this.expectContextual(115);
  8392. const typeParameter = this.startNode();
  8393. typeParameter.name = this.tsParseTypeParameterName();
  8394. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8395. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8396. return this.finishNode(node, "TSInferType");
  8397. }
  8398. tsParseConstraintForInferType() {
  8399. if (this.eat(81)) {
  8400. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8401. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8402. return constraint;
  8403. }
  8404. }
  8405. }
  8406. tsParseTypeOperatorOrHigher() {
  8407. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8408. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8409. }
  8410. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8411. const node = this.startNode();
  8412. const hasLeadingOperator = this.eat(operator);
  8413. const types = [];
  8414. do {
  8415. types.push(parseConstituentType());
  8416. } while (this.eat(operator));
  8417. if (types.length === 1 && !hasLeadingOperator) {
  8418. return types[0];
  8419. }
  8420. node.types = types;
  8421. return this.finishNode(node, kind);
  8422. }
  8423. tsParseIntersectionTypeOrHigher() {
  8424. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8425. }
  8426. tsParseUnionTypeOrHigher() {
  8427. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8428. }
  8429. tsIsStartOfFunctionType() {
  8430. if (this.match(47)) {
  8431. return true;
  8432. }
  8433. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8434. }
  8435. tsSkipParameterStart() {
  8436. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8437. this.next();
  8438. return true;
  8439. }
  8440. if (this.match(5)) {
  8441. const {
  8442. errors
  8443. } = this.state;
  8444. const previousErrorCount = errors.length;
  8445. try {
  8446. this.parseObjectLike(8, true);
  8447. return errors.length === previousErrorCount;
  8448. } catch (_unused) {
  8449. return false;
  8450. }
  8451. }
  8452. if (this.match(0)) {
  8453. this.next();
  8454. const {
  8455. errors
  8456. } = this.state;
  8457. const previousErrorCount = errors.length;
  8458. try {
  8459. super.parseBindingList(3, 93, 1);
  8460. return errors.length === previousErrorCount;
  8461. } catch (_unused2) {
  8462. return false;
  8463. }
  8464. }
  8465. return false;
  8466. }
  8467. tsIsUnambiguouslyStartOfFunctionType() {
  8468. this.next();
  8469. if (this.match(11) || this.match(21)) {
  8470. return true;
  8471. }
  8472. if (this.tsSkipParameterStart()) {
  8473. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8474. return true;
  8475. }
  8476. if (this.match(11)) {
  8477. this.next();
  8478. if (this.match(19)) {
  8479. return true;
  8480. }
  8481. }
  8482. }
  8483. return false;
  8484. }
  8485. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8486. return this.tsInType(() => {
  8487. const t = this.startNode();
  8488. this.expect(returnToken);
  8489. const node = this.startNode();
  8490. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8491. if (asserts && this.match(78)) {
  8492. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8493. if (thisTypePredicate.type === "TSThisType") {
  8494. node.parameterName = thisTypePredicate;
  8495. node.asserts = true;
  8496. node.typeAnnotation = null;
  8497. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8498. } else {
  8499. this.resetStartLocationFromNode(thisTypePredicate, node);
  8500. thisTypePredicate.asserts = true;
  8501. }
  8502. t.typeAnnotation = thisTypePredicate;
  8503. return this.finishNode(t, "TSTypeAnnotation");
  8504. }
  8505. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8506. if (!typePredicateVariable) {
  8507. if (!asserts) {
  8508. return this.tsParseTypeAnnotation(false, t);
  8509. }
  8510. node.parameterName = this.parseIdentifier();
  8511. node.asserts = asserts;
  8512. node.typeAnnotation = null;
  8513. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8514. return this.finishNode(t, "TSTypeAnnotation");
  8515. }
  8516. const type = this.tsParseTypeAnnotation(false);
  8517. node.parameterName = typePredicateVariable;
  8518. node.typeAnnotation = type;
  8519. node.asserts = asserts;
  8520. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8521. return this.finishNode(t, "TSTypeAnnotation");
  8522. });
  8523. }
  8524. tsTryParseTypeOrTypePredicateAnnotation() {
  8525. if (this.match(14)) {
  8526. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8527. }
  8528. }
  8529. tsTryParseTypeAnnotation() {
  8530. if (this.match(14)) {
  8531. return this.tsParseTypeAnnotation();
  8532. }
  8533. }
  8534. tsTryParseType() {
  8535. return this.tsEatThenParseType(14);
  8536. }
  8537. tsParseTypePredicatePrefix() {
  8538. const id = this.parseIdentifier();
  8539. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8540. this.next();
  8541. return id;
  8542. }
  8543. }
  8544. tsParseTypePredicateAsserts() {
  8545. if (this.state.type !== 109) {
  8546. return false;
  8547. }
  8548. const containsEsc = this.state.containsEsc;
  8549. this.next();
  8550. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8551. return false;
  8552. }
  8553. if (containsEsc) {
  8554. this.raise(Errors.InvalidEscapedReservedWord, {
  8555. at: this.state.lastTokStartLoc,
  8556. reservedWord: "asserts"
  8557. });
  8558. }
  8559. return true;
  8560. }
  8561. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8562. this.tsInType(() => {
  8563. if (eatColon) this.expect(14);
  8564. t.typeAnnotation = this.tsParseType();
  8565. });
  8566. return this.finishNode(t, "TSTypeAnnotation");
  8567. }
  8568. tsParseType() {
  8569. assert(this.state.inType);
  8570. const type = this.tsParseNonConditionalType();
  8571. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8572. return type;
  8573. }
  8574. const node = this.startNodeAtNode(type);
  8575. node.checkType = type;
  8576. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8577. this.expect(17);
  8578. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8579. this.expect(14);
  8580. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8581. return this.finishNode(node, "TSConditionalType");
  8582. }
  8583. isAbstractConstructorSignature() {
  8584. return this.isContextual(124) && this.lookahead().type === 77;
  8585. }
  8586. tsParseNonConditionalType() {
  8587. if (this.tsIsStartOfFunctionType()) {
  8588. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8589. }
  8590. if (this.match(77)) {
  8591. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8592. } else if (this.isAbstractConstructorSignature()) {
  8593. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8594. }
  8595. return this.tsParseUnionTypeOrHigher();
  8596. }
  8597. tsParseTypeAssertion() {
  8598. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8599. this.raise(TSErrors.ReservedTypeAssertion, {
  8600. at: this.state.startLoc
  8601. });
  8602. }
  8603. const node = this.startNode();
  8604. node.typeAnnotation = this.tsInType(() => {
  8605. this.next();
  8606. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8607. });
  8608. this.expect(48);
  8609. node.expression = this.parseMaybeUnary();
  8610. return this.finishNode(node, "TSTypeAssertion");
  8611. }
  8612. tsParseHeritageClause(token) {
  8613. const originalStartLoc = this.state.startLoc;
  8614. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8615. const node = this.startNode();
  8616. node.expression = this.tsParseEntityName();
  8617. if (this.match(47)) {
  8618. node.typeParameters = this.tsParseTypeArguments();
  8619. }
  8620. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8621. });
  8622. if (!delimitedList.length) {
  8623. this.raise(TSErrors.EmptyHeritageClauseType, {
  8624. at: originalStartLoc,
  8625. token
  8626. });
  8627. }
  8628. return delimitedList;
  8629. }
  8630. tsParseInterfaceDeclaration(node, properties = {}) {
  8631. if (this.hasFollowingLineBreak()) return null;
  8632. this.expectContextual(129);
  8633. if (properties.declare) node.declare = true;
  8634. if (tokenIsIdentifier(this.state.type)) {
  8635. node.id = this.parseIdentifier();
  8636. this.checkIdentifier(node.id, 130);
  8637. } else {
  8638. node.id = null;
  8639. this.raise(TSErrors.MissingInterfaceName, {
  8640. at: this.state.startLoc
  8641. });
  8642. }
  8643. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8644. if (this.eat(81)) {
  8645. node.extends = this.tsParseHeritageClause("extends");
  8646. }
  8647. const body = this.startNode();
  8648. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8649. node.body = this.finishNode(body, "TSInterfaceBody");
  8650. return this.finishNode(node, "TSInterfaceDeclaration");
  8651. }
  8652. tsParseTypeAliasDeclaration(node) {
  8653. node.id = this.parseIdentifier();
  8654. this.checkIdentifier(node.id, 2);
  8655. node.typeAnnotation = this.tsInType(() => {
  8656. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8657. this.expect(29);
  8658. if (this.isContextual(114) && this.lookahead().type !== 16) {
  8659. const node = this.startNode();
  8660. this.next();
  8661. return this.finishNode(node, "TSIntrinsicKeyword");
  8662. }
  8663. return this.tsParseType();
  8664. });
  8665. this.semicolon();
  8666. return this.finishNode(node, "TSTypeAliasDeclaration");
  8667. }
  8668. tsInNoContext(cb) {
  8669. const oldContext = this.state.context;
  8670. this.state.context = [oldContext[0]];
  8671. try {
  8672. return cb();
  8673. } finally {
  8674. this.state.context = oldContext;
  8675. }
  8676. }
  8677. tsInType(cb) {
  8678. const oldInType = this.state.inType;
  8679. this.state.inType = true;
  8680. try {
  8681. return cb();
  8682. } finally {
  8683. this.state.inType = oldInType;
  8684. }
  8685. }
  8686. tsInDisallowConditionalTypesContext(cb) {
  8687. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8688. this.state.inDisallowConditionalTypesContext = true;
  8689. try {
  8690. return cb();
  8691. } finally {
  8692. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8693. }
  8694. }
  8695. tsInAllowConditionalTypesContext(cb) {
  8696. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8697. this.state.inDisallowConditionalTypesContext = false;
  8698. try {
  8699. return cb();
  8700. } finally {
  8701. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8702. }
  8703. }
  8704. tsEatThenParseType(token) {
  8705. if (this.match(token)) {
  8706. return this.tsNextThenParseType();
  8707. }
  8708. }
  8709. tsExpectThenParseType(token) {
  8710. return this.tsInType(() => {
  8711. this.expect(token);
  8712. return this.tsParseType();
  8713. });
  8714. }
  8715. tsNextThenParseType() {
  8716. return this.tsInType(() => {
  8717. this.next();
  8718. return this.tsParseType();
  8719. });
  8720. }
  8721. tsParseEnumMember() {
  8722. const node = this.startNode();
  8723. node.id = this.match(133) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8724. if (this.eat(29)) {
  8725. node.initializer = super.parseMaybeAssignAllowIn();
  8726. }
  8727. return this.finishNode(node, "TSEnumMember");
  8728. }
  8729. tsParseEnumDeclaration(node, properties = {}) {
  8730. if (properties.const) node.const = true;
  8731. if (properties.declare) node.declare = true;
  8732. this.expectContextual(126);
  8733. node.id = this.parseIdentifier();
  8734. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8735. this.expect(5);
  8736. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8737. this.expect(8);
  8738. return this.finishNode(node, "TSEnumDeclaration");
  8739. }
  8740. tsParseModuleBlock() {
  8741. const node = this.startNode();
  8742. this.scope.enter(0);
  8743. this.expect(5);
  8744. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8745. this.scope.exit();
  8746. return this.finishNode(node, "TSModuleBlock");
  8747. }
  8748. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8749. node.id = this.parseIdentifier();
  8750. if (!nested) {
  8751. this.checkIdentifier(node.id, 1024);
  8752. }
  8753. if (this.eat(16)) {
  8754. const inner = this.startNode();
  8755. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8756. node.body = inner;
  8757. } else {
  8758. this.scope.enter(256);
  8759. this.prodParam.enter(0);
  8760. node.body = this.tsParseModuleBlock();
  8761. this.prodParam.exit();
  8762. this.scope.exit();
  8763. }
  8764. return this.finishNode(node, "TSModuleDeclaration");
  8765. }
  8766. tsParseAmbientExternalModuleDeclaration(node) {
  8767. if (this.isContextual(112)) {
  8768. node.global = true;
  8769. node.id = this.parseIdentifier();
  8770. } else if (this.match(133)) {
  8771. node.id = super.parseStringLiteral(this.state.value);
  8772. } else {
  8773. this.unexpected();
  8774. }
  8775. if (this.match(5)) {
  8776. this.scope.enter(256);
  8777. this.prodParam.enter(0);
  8778. node.body = this.tsParseModuleBlock();
  8779. this.prodParam.exit();
  8780. this.scope.exit();
  8781. } else {
  8782. this.semicolon();
  8783. }
  8784. return this.finishNode(node, "TSModuleDeclaration");
  8785. }
  8786. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8787. node.isExport = isExport || false;
  8788. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8789. this.checkIdentifier(node.id, 4096);
  8790. this.expect(29);
  8791. const moduleReference = this.tsParseModuleReference();
  8792. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8793. this.raise(TSErrors.ImportAliasHasImportType, {
  8794. at: moduleReference
  8795. });
  8796. }
  8797. node.moduleReference = moduleReference;
  8798. this.semicolon();
  8799. return this.finishNode(node, "TSImportEqualsDeclaration");
  8800. }
  8801. tsIsExternalModuleReference() {
  8802. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8803. }
  8804. tsParseModuleReference() {
  8805. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  8806. }
  8807. tsParseExternalModuleReference() {
  8808. const node = this.startNode();
  8809. this.expectContextual(119);
  8810. this.expect(10);
  8811. if (!this.match(133)) {
  8812. this.unexpected();
  8813. }
  8814. node.expression = super.parseExprAtom();
  8815. this.expect(11);
  8816. this.sawUnambiguousESM = true;
  8817. return this.finishNode(node, "TSExternalModuleReference");
  8818. }
  8819. tsLookAhead(f) {
  8820. const state = this.state.clone();
  8821. const res = f();
  8822. this.state = state;
  8823. return res;
  8824. }
  8825. tsTryParseAndCatch(f) {
  8826. const result = this.tryParse(abort => f() || abort());
  8827. if (result.aborted || !result.node) return;
  8828. if (result.error) this.state = result.failState;
  8829. return result.node;
  8830. }
  8831. tsTryParse(f) {
  8832. const state = this.state.clone();
  8833. const result = f();
  8834. if (result !== undefined && result !== false) {
  8835. return result;
  8836. }
  8837. this.state = state;
  8838. }
  8839. tsTryParseDeclare(nany) {
  8840. if (this.isLineTerminator()) {
  8841. return;
  8842. }
  8843. let startType = this.state.type;
  8844. let kind;
  8845. if (this.isContextual(100)) {
  8846. startType = 74;
  8847. kind = "let";
  8848. }
  8849. return this.tsInAmbientContext(() => {
  8850. switch (startType) {
  8851. case 68:
  8852. nany.declare = true;
  8853. return super.parseFunctionStatement(nany, false, false);
  8854. case 80:
  8855. nany.declare = true;
  8856. return this.parseClass(nany, true, false);
  8857. case 126:
  8858. return this.tsParseEnumDeclaration(nany, {
  8859. declare: true
  8860. });
  8861. case 112:
  8862. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8863. case 75:
  8864. case 74:
  8865. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8866. nany.declare = true;
  8867. return this.parseVarStatement(nany, kind || this.state.value, true);
  8868. }
  8869. this.expect(75);
  8870. return this.tsParseEnumDeclaration(nany, {
  8871. const: true,
  8872. declare: true
  8873. });
  8874. case 129:
  8875. {
  8876. const result = this.tsParseInterfaceDeclaration(nany, {
  8877. declare: true
  8878. });
  8879. if (result) return result;
  8880. }
  8881. default:
  8882. if (tokenIsIdentifier(startType)) {
  8883. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8884. }
  8885. }
  8886. });
  8887. }
  8888. tsTryParseExportDeclaration() {
  8889. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  8890. }
  8891. tsParseExpressionStatement(node, expr, decorators) {
  8892. switch (expr.name) {
  8893. case "declare":
  8894. {
  8895. const declaration = this.tsTryParseDeclare(node);
  8896. if (declaration) {
  8897. declaration.declare = true;
  8898. }
  8899. return declaration;
  8900. }
  8901. case "global":
  8902. if (this.match(5)) {
  8903. this.scope.enter(256);
  8904. this.prodParam.enter(0);
  8905. const mod = node;
  8906. mod.global = true;
  8907. mod.id = expr;
  8908. mod.body = this.tsParseModuleBlock();
  8909. this.scope.exit();
  8910. this.prodParam.exit();
  8911. return this.finishNode(mod, "TSModuleDeclaration");
  8912. }
  8913. break;
  8914. default:
  8915. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8916. }
  8917. }
  8918. tsParseDeclaration(node, value, next, decorators) {
  8919. switch (value) {
  8920. case "abstract":
  8921. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8922. return this.tsParseAbstractDeclaration(node, decorators);
  8923. }
  8924. break;
  8925. case "module":
  8926. if (this.tsCheckLineTerminator(next)) {
  8927. if (this.match(133)) {
  8928. return this.tsParseAmbientExternalModuleDeclaration(node);
  8929. } else if (tokenIsIdentifier(this.state.type)) {
  8930. return this.tsParseModuleOrNamespaceDeclaration(node);
  8931. }
  8932. }
  8933. break;
  8934. case "namespace":
  8935. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8936. return this.tsParseModuleOrNamespaceDeclaration(node);
  8937. }
  8938. break;
  8939. case "type":
  8940. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8941. return this.tsParseTypeAliasDeclaration(node);
  8942. }
  8943. break;
  8944. }
  8945. }
  8946. tsCheckLineTerminator(next) {
  8947. if (next) {
  8948. if (this.hasFollowingLineBreak()) return false;
  8949. this.next();
  8950. return true;
  8951. }
  8952. return !this.isLineTerminator();
  8953. }
  8954. tsTryParseGenericAsyncArrowFunction(startLoc) {
  8955. if (!this.match(47)) return;
  8956. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8957. this.state.maybeInArrowParameters = true;
  8958. const res = this.tsTryParseAndCatch(() => {
  8959. const node = this.startNodeAt(startLoc);
  8960. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  8961. super.parseFunctionParams(node);
  8962. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  8963. this.expect(19);
  8964. return node;
  8965. });
  8966. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  8967. if (!res) return;
  8968. return super.parseArrowExpression(res, null, true);
  8969. }
  8970. tsParseTypeArgumentsInExpression() {
  8971. if (this.reScan_lt() !== 47) return;
  8972. return this.tsParseTypeArguments();
  8973. }
  8974. tsParseTypeArguments() {
  8975. const node = this.startNode();
  8976. node.params = this.tsInType(() => this.tsInNoContext(() => {
  8977. this.expect(47);
  8978. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  8979. }));
  8980. if (node.params.length === 0) {
  8981. this.raise(TSErrors.EmptyTypeArguments, {
  8982. at: node
  8983. });
  8984. } else if (!this.state.inType && this.curContext() === types.brace) {
  8985. this.reScan_lt_gt();
  8986. }
  8987. this.expect(48);
  8988. return this.finishNode(node, "TSTypeParameterInstantiation");
  8989. }
  8990. tsIsDeclarationStart() {
  8991. return tokenIsTSDeclarationStart(this.state.type);
  8992. }
  8993. isExportDefaultSpecifier() {
  8994. if (this.tsIsDeclarationStart()) return false;
  8995. return super.isExportDefaultSpecifier();
  8996. }
  8997. parseAssignableListItem(flags, decorators) {
  8998. const startLoc = this.state.startLoc;
  8999. const modified = {};
  9000. this.tsParseModifiers({
  9001. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9002. }, modified);
  9003. const accessibility = modified.accessibility;
  9004. const override = modified.override;
  9005. const readonly = modified.readonly;
  9006. if (!(flags & 4) && (accessibility || readonly || override)) {
  9007. this.raise(TSErrors.UnexpectedParameterModifier, {
  9008. at: startLoc
  9009. });
  9010. }
  9011. const left = this.parseMaybeDefault();
  9012. this.parseAssignableListItemTypes(left, flags);
  9013. const elt = this.parseMaybeDefault(left.loc.start, left);
  9014. if (accessibility || readonly || override) {
  9015. const pp = this.startNodeAt(startLoc);
  9016. if (decorators.length) {
  9017. pp.decorators = decorators;
  9018. }
  9019. if (accessibility) pp.accessibility = accessibility;
  9020. if (readonly) pp.readonly = readonly;
  9021. if (override) pp.override = override;
  9022. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9023. this.raise(TSErrors.UnsupportedParameterPropertyKind, {
  9024. at: pp
  9025. });
  9026. }
  9027. pp.parameter = elt;
  9028. return this.finishNode(pp, "TSParameterProperty");
  9029. }
  9030. if (decorators.length) {
  9031. left.decorators = decorators;
  9032. }
  9033. return elt;
  9034. }
  9035. isSimpleParameter(node) {
  9036. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9037. }
  9038. tsDisallowOptionalPattern(node) {
  9039. for (const param of node.params) {
  9040. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9041. this.raise(TSErrors.PatternIsOptional, {
  9042. at: param
  9043. });
  9044. }
  9045. }
  9046. }
  9047. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9048. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9049. this.tsDisallowOptionalPattern(node);
  9050. }
  9051. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9052. if (this.match(14)) {
  9053. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9054. }
  9055. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9056. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9057. return this.finishNode(node, bodilessType);
  9058. }
  9059. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9060. this.raise(TSErrors.DeclareFunctionHasImplementation, {
  9061. at: node
  9062. });
  9063. if (node.declare) {
  9064. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9065. }
  9066. }
  9067. this.tsDisallowOptionalPattern(node);
  9068. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9069. }
  9070. registerFunctionStatementId(node) {
  9071. if (!node.body && node.id) {
  9072. this.checkIdentifier(node.id, 1024);
  9073. } else {
  9074. super.registerFunctionStatementId(node);
  9075. }
  9076. }
  9077. tsCheckForInvalidTypeCasts(items) {
  9078. items.forEach(node => {
  9079. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9080. this.raise(TSErrors.UnexpectedTypeAnnotation, {
  9081. at: node.typeAnnotation
  9082. });
  9083. }
  9084. });
  9085. }
  9086. toReferencedList(exprList, isInParens) {
  9087. this.tsCheckForInvalidTypeCasts(exprList);
  9088. return exprList;
  9089. }
  9090. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9091. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9092. if (node.type === "ArrayExpression") {
  9093. this.tsCheckForInvalidTypeCasts(node.elements);
  9094. }
  9095. return node;
  9096. }
  9097. parseSubscript(base, startLoc, noCalls, state) {
  9098. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9099. this.state.canStartJSXElement = false;
  9100. this.next();
  9101. const nonNullExpression = this.startNodeAt(startLoc);
  9102. nonNullExpression.expression = base;
  9103. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9104. }
  9105. let isOptionalCall = false;
  9106. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9107. if (noCalls) {
  9108. state.stop = true;
  9109. return base;
  9110. }
  9111. state.optionalChainMember = isOptionalCall = true;
  9112. this.next();
  9113. }
  9114. if (this.match(47) || this.match(51)) {
  9115. let missingParenErrorLoc;
  9116. const result = this.tsTryParseAndCatch(() => {
  9117. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9118. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9119. if (asyncArrowFn) {
  9120. return asyncArrowFn;
  9121. }
  9122. }
  9123. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9124. if (!typeArguments) return;
  9125. if (isOptionalCall && !this.match(10)) {
  9126. missingParenErrorLoc = this.state.curPosition();
  9127. return;
  9128. }
  9129. if (tokenIsTemplate(this.state.type)) {
  9130. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9131. result.typeParameters = typeArguments;
  9132. return result;
  9133. }
  9134. if (!noCalls && this.eat(10)) {
  9135. const node = this.startNodeAt(startLoc);
  9136. node.callee = base;
  9137. node.arguments = this.parseCallExpressionArguments(11, false);
  9138. this.tsCheckForInvalidTypeCasts(node.arguments);
  9139. node.typeParameters = typeArguments;
  9140. if (state.optionalChainMember) {
  9141. node.optional = isOptionalCall;
  9142. }
  9143. return this.finishCallExpression(node, state.optionalChainMember);
  9144. }
  9145. const tokenType = this.state.type;
  9146. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9147. return;
  9148. }
  9149. const node = this.startNodeAt(startLoc);
  9150. node.expression = base;
  9151. node.typeParameters = typeArguments;
  9152. return this.finishNode(node, "TSInstantiationExpression");
  9153. });
  9154. if (missingParenErrorLoc) {
  9155. this.unexpected(missingParenErrorLoc, 10);
  9156. }
  9157. if (result) {
  9158. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  9159. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
  9160. at: this.state.startLoc
  9161. });
  9162. }
  9163. return result;
  9164. }
  9165. }
  9166. return super.parseSubscript(base, startLoc, noCalls, state);
  9167. }
  9168. parseNewCallee(node) {
  9169. var _callee$extra;
  9170. super.parseNewCallee(node);
  9171. const {
  9172. callee
  9173. } = node;
  9174. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9175. node.typeParameters = callee.typeParameters;
  9176. node.callee = callee.expression;
  9177. }
  9178. }
  9179. parseExprOp(left, leftStartLoc, minPrec) {
  9180. let isSatisfies;
  9181. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9182. const node = this.startNodeAt(leftStartLoc);
  9183. node.expression = left;
  9184. node.typeAnnotation = this.tsInType(() => {
  9185. this.next();
  9186. if (this.match(75)) {
  9187. if (isSatisfies) {
  9188. this.raise(Errors.UnexpectedKeyword, {
  9189. at: this.state.startLoc,
  9190. keyword: "const"
  9191. });
  9192. }
  9193. return this.tsParseTypeReference();
  9194. }
  9195. return this.tsParseType();
  9196. });
  9197. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9198. this.reScan_lt_gt();
  9199. return this.parseExprOp(node, leftStartLoc, minPrec);
  9200. }
  9201. return super.parseExprOp(left, leftStartLoc, minPrec);
  9202. }
  9203. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9204. if (!this.state.isAmbientContext) {
  9205. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9206. }
  9207. }
  9208. checkImportReflection(node) {
  9209. super.checkImportReflection(node);
  9210. if (node.module && node.importKind !== "value") {
  9211. this.raise(TSErrors.ImportReflectionHasImportType, {
  9212. at: node.specifiers[0].loc.start
  9213. });
  9214. }
  9215. }
  9216. checkDuplicateExports() {}
  9217. isPotentialImportPhase(isExport) {
  9218. if (super.isPotentialImportPhase(isExport)) return true;
  9219. if (this.isContextual(130)) {
  9220. const ch = this.lookaheadCharCode();
  9221. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9222. }
  9223. return !isExport && this.isContextual(87);
  9224. }
  9225. applyImportPhase(node, isExport, phase, loc) {
  9226. super.applyImportPhase(node, isExport, phase, loc);
  9227. if (isExport) {
  9228. node.exportKind = phase === "type" ? "type" : "value";
  9229. } else {
  9230. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9231. }
  9232. }
  9233. parseImport(node) {
  9234. if (this.match(133)) {
  9235. node.importKind = "value";
  9236. return super.parseImport(node);
  9237. }
  9238. let importNode;
  9239. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9240. node.importKind = "value";
  9241. return this.tsParseImportEqualsDeclaration(node);
  9242. } else if (this.isContextual(130)) {
  9243. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9244. if (this.lookaheadCharCode() === 61) {
  9245. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9246. } else {
  9247. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9248. }
  9249. } else {
  9250. importNode = super.parseImport(node);
  9251. }
  9252. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9253. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
  9254. at: importNode
  9255. });
  9256. }
  9257. return importNode;
  9258. }
  9259. parseExport(node, decorators) {
  9260. if (this.match(83)) {
  9261. this.next();
  9262. let maybeDefaultIdentifier = null;
  9263. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9264. maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9265. } else {
  9266. node.importKind = "value";
  9267. }
  9268. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, true);
  9269. } else if (this.eat(29)) {
  9270. const assign = node;
  9271. assign.expression = super.parseExpression();
  9272. this.semicolon();
  9273. this.sawUnambiguousESM = true;
  9274. return this.finishNode(assign, "TSExportAssignment");
  9275. } else if (this.eatContextual(93)) {
  9276. const decl = node;
  9277. this.expectContextual(128);
  9278. decl.id = this.parseIdentifier();
  9279. this.semicolon();
  9280. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9281. } else {
  9282. return super.parseExport(node, decorators);
  9283. }
  9284. }
  9285. isAbstractClass() {
  9286. return this.isContextual(124) && this.lookahead().type === 80;
  9287. }
  9288. parseExportDefaultExpression() {
  9289. if (this.isAbstractClass()) {
  9290. const cls = this.startNode();
  9291. this.next();
  9292. cls.abstract = true;
  9293. return this.parseClass(cls, true, true);
  9294. }
  9295. if (this.match(129)) {
  9296. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9297. if (result) return result;
  9298. }
  9299. return super.parseExportDefaultExpression();
  9300. }
  9301. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9302. const {
  9303. isAmbientContext
  9304. } = this.state;
  9305. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9306. if (!isAmbientContext) return declaration;
  9307. for (const {
  9308. id,
  9309. init
  9310. } of declaration.declarations) {
  9311. if (!init) continue;
  9312. if (kind !== "const" || !!id.typeAnnotation) {
  9313. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
  9314. at: init
  9315. });
  9316. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9317. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
  9318. at: init
  9319. });
  9320. }
  9321. }
  9322. return declaration;
  9323. }
  9324. parseStatementContent(flags, decorators) {
  9325. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9326. const node = this.startNode();
  9327. this.expect(75);
  9328. return this.tsParseEnumDeclaration(node, {
  9329. const: true
  9330. });
  9331. }
  9332. if (this.isContextual(126)) {
  9333. return this.tsParseEnumDeclaration(this.startNode());
  9334. }
  9335. if (this.isContextual(129)) {
  9336. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9337. if (result) return result;
  9338. }
  9339. return super.parseStatementContent(flags, decorators);
  9340. }
  9341. parseAccessModifier() {
  9342. return this.tsParseModifier(["public", "protected", "private"]);
  9343. }
  9344. tsHasSomeModifiers(member, modifiers) {
  9345. return modifiers.some(modifier => {
  9346. if (tsIsAccessModifier(modifier)) {
  9347. return member.accessibility === modifier;
  9348. }
  9349. return !!member[modifier];
  9350. });
  9351. }
  9352. tsIsStartOfStaticBlocks() {
  9353. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9354. }
  9355. parseClassMember(classBody, member, state) {
  9356. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9357. this.tsParseModifiers({
  9358. allowedModifiers: modifiers,
  9359. disallowedModifiers: ["in", "out"],
  9360. stopOnStartOfClassStaticBlock: true,
  9361. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9362. }, member);
  9363. const callParseClassMemberWithIsStatic = () => {
  9364. if (this.tsIsStartOfStaticBlocks()) {
  9365. this.next();
  9366. this.next();
  9367. if (this.tsHasSomeModifiers(member, modifiers)) {
  9368. this.raise(TSErrors.StaticBlockCannotHaveModifier, {
  9369. at: this.state.curPosition()
  9370. });
  9371. }
  9372. super.parseClassStaticBlock(classBody, member);
  9373. } else {
  9374. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9375. }
  9376. };
  9377. if (member.declare) {
  9378. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9379. } else {
  9380. callParseClassMemberWithIsStatic();
  9381. }
  9382. }
  9383. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9384. const idx = this.tsTryParseIndexSignature(member);
  9385. if (idx) {
  9386. classBody.body.push(idx);
  9387. if (member.abstract) {
  9388. this.raise(TSErrors.IndexSignatureHasAbstract, {
  9389. at: member
  9390. });
  9391. }
  9392. if (member.accessibility) {
  9393. this.raise(TSErrors.IndexSignatureHasAccessibility, {
  9394. at: member,
  9395. modifier: member.accessibility
  9396. });
  9397. }
  9398. if (member.declare) {
  9399. this.raise(TSErrors.IndexSignatureHasDeclare, {
  9400. at: member
  9401. });
  9402. }
  9403. if (member.override) {
  9404. this.raise(TSErrors.IndexSignatureHasOverride, {
  9405. at: member
  9406. });
  9407. }
  9408. return;
  9409. }
  9410. if (!this.state.inAbstractClass && member.abstract) {
  9411. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
  9412. at: member
  9413. });
  9414. }
  9415. if (member.override) {
  9416. if (!state.hadSuperClass) {
  9417. this.raise(TSErrors.OverrideNotInSubClass, {
  9418. at: member
  9419. });
  9420. }
  9421. }
  9422. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9423. }
  9424. parsePostMemberNameModifiers(methodOrProp) {
  9425. const optional = this.eat(17);
  9426. if (optional) methodOrProp.optional = true;
  9427. if (methodOrProp.readonly && this.match(10)) {
  9428. this.raise(TSErrors.ClassMethodHasReadonly, {
  9429. at: methodOrProp
  9430. });
  9431. }
  9432. if (methodOrProp.declare && this.match(10)) {
  9433. this.raise(TSErrors.ClassMethodHasDeclare, {
  9434. at: methodOrProp
  9435. });
  9436. }
  9437. }
  9438. parseExpressionStatement(node, expr, decorators) {
  9439. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9440. return decl || super.parseExpressionStatement(node, expr, decorators);
  9441. }
  9442. shouldParseExportDeclaration() {
  9443. if (this.tsIsDeclarationStart()) return true;
  9444. return super.shouldParseExportDeclaration();
  9445. }
  9446. parseConditional(expr, startLoc, refExpressionErrors) {
  9447. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9448. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9449. }
  9450. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9451. if (!result.node) {
  9452. if (result.error) {
  9453. super.setOptionalParametersError(refExpressionErrors, result.error);
  9454. }
  9455. return expr;
  9456. }
  9457. if (result.error) this.state = result.failState;
  9458. return result.node;
  9459. }
  9460. parseParenItem(node, startLoc) {
  9461. node = super.parseParenItem(node, startLoc);
  9462. if (this.eat(17)) {
  9463. node.optional = true;
  9464. this.resetEndLocation(node);
  9465. }
  9466. if (this.match(14)) {
  9467. const typeCastNode = this.startNodeAt(startLoc);
  9468. typeCastNode.expression = node;
  9469. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9470. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9471. }
  9472. return node;
  9473. }
  9474. parseExportDeclaration(node) {
  9475. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9476. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9477. }
  9478. const startLoc = this.state.startLoc;
  9479. const isDeclare = this.eatContextual(125);
  9480. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9481. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
  9482. at: this.state.startLoc
  9483. });
  9484. }
  9485. const isIdentifier = tokenIsIdentifier(this.state.type);
  9486. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9487. if (!declaration) return null;
  9488. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9489. node.exportKind = "type";
  9490. }
  9491. if (isDeclare) {
  9492. this.resetStartLocation(declaration, startLoc);
  9493. declaration.declare = true;
  9494. }
  9495. return declaration;
  9496. }
  9497. parseClassId(node, isStatement, optionalId, bindingType) {
  9498. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9499. return;
  9500. }
  9501. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9502. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9503. if (typeParameters) node.typeParameters = typeParameters;
  9504. }
  9505. parseClassPropertyAnnotation(node) {
  9506. if (!node.optional) {
  9507. if (this.eat(35)) {
  9508. node.definite = true;
  9509. } else if (this.eat(17)) {
  9510. node.optional = true;
  9511. }
  9512. }
  9513. const type = this.tsTryParseTypeAnnotation();
  9514. if (type) node.typeAnnotation = type;
  9515. }
  9516. parseClassProperty(node) {
  9517. this.parseClassPropertyAnnotation(node);
  9518. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9519. this.raise(TSErrors.DeclareClassFieldHasInitializer, {
  9520. at: this.state.startLoc
  9521. });
  9522. }
  9523. if (node.abstract && this.match(29)) {
  9524. const {
  9525. key
  9526. } = node;
  9527. this.raise(TSErrors.AbstractPropertyHasInitializer, {
  9528. at: this.state.startLoc,
  9529. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9530. });
  9531. }
  9532. return super.parseClassProperty(node);
  9533. }
  9534. parseClassPrivateProperty(node) {
  9535. if (node.abstract) {
  9536. this.raise(TSErrors.PrivateElementHasAbstract, {
  9537. at: node
  9538. });
  9539. }
  9540. if (node.accessibility) {
  9541. this.raise(TSErrors.PrivateElementHasAccessibility, {
  9542. at: node,
  9543. modifier: node.accessibility
  9544. });
  9545. }
  9546. this.parseClassPropertyAnnotation(node);
  9547. return super.parseClassPrivateProperty(node);
  9548. }
  9549. parseClassAccessorProperty(node) {
  9550. this.parseClassPropertyAnnotation(node);
  9551. if (node.optional) {
  9552. this.raise(TSErrors.AccessorCannotBeOptional, {
  9553. at: node
  9554. });
  9555. }
  9556. return super.parseClassAccessorProperty(node);
  9557. }
  9558. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9559. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9560. if (typeParameters && isConstructor) {
  9561. this.raise(TSErrors.ConstructorHasTypeParameters, {
  9562. at: typeParameters
  9563. });
  9564. }
  9565. const {
  9566. declare = false,
  9567. kind
  9568. } = method;
  9569. if (declare && (kind === "get" || kind === "set")) {
  9570. this.raise(TSErrors.DeclareAccessor, {
  9571. at: method,
  9572. kind
  9573. });
  9574. }
  9575. if (typeParameters) method.typeParameters = typeParameters;
  9576. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9577. }
  9578. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9579. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9580. if (typeParameters) method.typeParameters = typeParameters;
  9581. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9582. }
  9583. declareClassPrivateMethodInScope(node, kind) {
  9584. if (node.type === "TSDeclareMethod") return;
  9585. if (node.type === "MethodDefinition" && !node.value.body) return;
  9586. super.declareClassPrivateMethodInScope(node, kind);
  9587. }
  9588. parseClassSuper(node) {
  9589. super.parseClassSuper(node);
  9590. if (node.superClass && (this.match(47) || this.match(51))) {
  9591. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9592. }
  9593. if (this.eatContextual(113)) {
  9594. node.implements = this.tsParseHeritageClause("implements");
  9595. }
  9596. }
  9597. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9598. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9599. if (typeParameters) prop.typeParameters = typeParameters;
  9600. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9601. }
  9602. parseFunctionParams(node, isConstructor) {
  9603. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9604. if (typeParameters) node.typeParameters = typeParameters;
  9605. super.parseFunctionParams(node, isConstructor);
  9606. }
  9607. parseVarId(decl, kind) {
  9608. super.parseVarId(decl, kind);
  9609. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9610. decl.definite = true;
  9611. }
  9612. const type = this.tsTryParseTypeAnnotation();
  9613. if (type) {
  9614. decl.id.typeAnnotation = type;
  9615. this.resetEndLocation(decl.id);
  9616. }
  9617. }
  9618. parseAsyncArrowFromCallExpression(node, call) {
  9619. if (this.match(14)) {
  9620. node.returnType = this.tsParseTypeAnnotation();
  9621. }
  9622. return super.parseAsyncArrowFromCallExpression(node, call);
  9623. }
  9624. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9625. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9626. let state;
  9627. let jsx;
  9628. let typeCast;
  9629. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  9630. state = this.state.clone();
  9631. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9632. if (!jsx.error) return jsx.node;
  9633. const {
  9634. context
  9635. } = this.state;
  9636. const currentContext = context[context.length - 1];
  9637. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9638. context.pop();
  9639. }
  9640. }
  9641. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9642. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9643. }
  9644. if (!state || state === this.state) state = this.state.clone();
  9645. let typeParameters;
  9646. const arrow = this.tryParse(abort => {
  9647. var _expr$extra, _typeParameters;
  9648. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9649. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9650. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9651. abort();
  9652. }
  9653. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9654. this.resetStartLocationFromNode(expr, typeParameters);
  9655. }
  9656. expr.typeParameters = typeParameters;
  9657. return expr;
  9658. }, state);
  9659. if (!arrow.error && !arrow.aborted) {
  9660. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9661. return arrow.node;
  9662. }
  9663. if (!jsx) {
  9664. assert(!this.hasPlugin("jsx"));
  9665. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9666. if (!typeCast.error) return typeCast.node;
  9667. }
  9668. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9669. this.state = jsx.failState;
  9670. return jsx.node;
  9671. }
  9672. if (arrow.node) {
  9673. this.state = arrow.failState;
  9674. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9675. return arrow.node;
  9676. }
  9677. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9678. this.state = typeCast.failState;
  9679. return typeCast.node;
  9680. }
  9681. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9682. }
  9683. reportReservedArrowTypeParam(node) {
  9684. var _node$extra;
  9685. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9686. this.raise(TSErrors.ReservedArrowTypeParam, {
  9687. at: node
  9688. });
  9689. }
  9690. }
  9691. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9692. if (!this.hasPlugin("jsx") && this.match(47)) {
  9693. return this.tsParseTypeAssertion();
  9694. }
  9695. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9696. }
  9697. parseArrow(node) {
  9698. if (this.match(14)) {
  9699. const result = this.tryParse(abort => {
  9700. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9701. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9702. return returnType;
  9703. });
  9704. if (result.aborted) return;
  9705. if (!result.thrown) {
  9706. if (result.error) this.state = result.failState;
  9707. node.returnType = result.node;
  9708. }
  9709. }
  9710. return super.parseArrow(node);
  9711. }
  9712. parseAssignableListItemTypes(param, flags) {
  9713. if (!(flags & 2)) return param;
  9714. if (this.eat(17)) {
  9715. param.optional = true;
  9716. }
  9717. const type = this.tsTryParseTypeAnnotation();
  9718. if (type) param.typeAnnotation = type;
  9719. this.resetEndLocation(param);
  9720. return param;
  9721. }
  9722. isAssignable(node, isBinding) {
  9723. switch (node.type) {
  9724. case "TSTypeCastExpression":
  9725. return this.isAssignable(node.expression, isBinding);
  9726. case "TSParameterProperty":
  9727. return true;
  9728. default:
  9729. return super.isAssignable(node, isBinding);
  9730. }
  9731. }
  9732. toAssignable(node, isLHS = false) {
  9733. switch (node.type) {
  9734. case "ParenthesizedExpression":
  9735. this.toAssignableParenthesizedExpression(node, isLHS);
  9736. break;
  9737. case "TSAsExpression":
  9738. case "TSSatisfiesExpression":
  9739. case "TSNonNullExpression":
  9740. case "TSTypeAssertion":
  9741. if (isLHS) {
  9742. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
  9743. at: node
  9744. });
  9745. } else {
  9746. this.raise(TSErrors.UnexpectedTypeCastInParameter, {
  9747. at: node
  9748. });
  9749. }
  9750. this.toAssignable(node.expression, isLHS);
  9751. break;
  9752. case "AssignmentExpression":
  9753. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9754. node.left = this.typeCastToParameter(node.left);
  9755. }
  9756. default:
  9757. super.toAssignable(node, isLHS);
  9758. }
  9759. }
  9760. toAssignableParenthesizedExpression(node, isLHS) {
  9761. switch (node.expression.type) {
  9762. case "TSAsExpression":
  9763. case "TSSatisfiesExpression":
  9764. case "TSNonNullExpression":
  9765. case "TSTypeAssertion":
  9766. case "ParenthesizedExpression":
  9767. this.toAssignable(node.expression, isLHS);
  9768. break;
  9769. default:
  9770. super.toAssignable(node, isLHS);
  9771. }
  9772. }
  9773. checkToRestConversion(node, allowPattern) {
  9774. switch (node.type) {
  9775. case "TSAsExpression":
  9776. case "TSSatisfiesExpression":
  9777. case "TSTypeAssertion":
  9778. case "TSNonNullExpression":
  9779. this.checkToRestConversion(node.expression, false);
  9780. break;
  9781. default:
  9782. super.checkToRestConversion(node, allowPattern);
  9783. }
  9784. }
  9785. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9786. return getOwn({
  9787. TSTypeCastExpression: true,
  9788. TSParameterProperty: "parameter",
  9789. TSNonNullExpression: "expression",
  9790. TSAsExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  9791. TSSatisfiesExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  9792. TSTypeAssertion: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true]
  9793. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9794. }
  9795. parseBindingAtom() {
  9796. if (this.state.type === 78) {
  9797. return this.parseIdentifier(true);
  9798. }
  9799. return super.parseBindingAtom();
  9800. }
  9801. parseMaybeDecoratorArguments(expr) {
  9802. if (this.match(47) || this.match(51)) {
  9803. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9804. if (this.match(10)) {
  9805. const call = super.parseMaybeDecoratorArguments(expr);
  9806. call.typeParameters = typeArguments;
  9807. return call;
  9808. }
  9809. this.unexpected(null, 10);
  9810. }
  9811. return super.parseMaybeDecoratorArguments(expr);
  9812. }
  9813. checkCommaAfterRest(close) {
  9814. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9815. this.next();
  9816. return false;
  9817. }
  9818. return super.checkCommaAfterRest(close);
  9819. }
  9820. isClassMethod() {
  9821. return this.match(47) || super.isClassMethod();
  9822. }
  9823. isClassProperty() {
  9824. return this.match(35) || this.match(14) || super.isClassProperty();
  9825. }
  9826. parseMaybeDefault(startLoc, left) {
  9827. const node = super.parseMaybeDefault(startLoc, left);
  9828. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9829. this.raise(TSErrors.TypeAnnotationAfterAssign, {
  9830. at: node.typeAnnotation
  9831. });
  9832. }
  9833. return node;
  9834. }
  9835. getTokenFromCode(code) {
  9836. if (this.state.inType) {
  9837. if (code === 62) {
  9838. this.finishOp(48, 1);
  9839. return;
  9840. }
  9841. if (code === 60) {
  9842. this.finishOp(47, 1);
  9843. return;
  9844. }
  9845. }
  9846. super.getTokenFromCode(code);
  9847. }
  9848. reScan_lt_gt() {
  9849. const {
  9850. type
  9851. } = this.state;
  9852. if (type === 47) {
  9853. this.state.pos -= 1;
  9854. this.readToken_lt();
  9855. } else if (type === 48) {
  9856. this.state.pos -= 1;
  9857. this.readToken_gt();
  9858. }
  9859. }
  9860. reScan_lt() {
  9861. const {
  9862. type
  9863. } = this.state;
  9864. if (type === 51) {
  9865. this.state.pos -= 2;
  9866. this.finishOp(47, 1);
  9867. return 47;
  9868. }
  9869. return type;
  9870. }
  9871. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9872. for (let i = 0; i < exprList.length; i++) {
  9873. const expr = exprList[i];
  9874. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9875. exprList[i] = this.typeCastToParameter(expr);
  9876. }
  9877. }
  9878. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9879. }
  9880. typeCastToParameter(node) {
  9881. node.expression.typeAnnotation = node.typeAnnotation;
  9882. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9883. return node.expression;
  9884. }
  9885. shouldParseArrow(params) {
  9886. if (this.match(14)) {
  9887. return params.every(expr => this.isAssignable(expr, true));
  9888. }
  9889. return super.shouldParseArrow(params);
  9890. }
  9891. shouldParseAsyncArrow() {
  9892. return this.match(14) || super.shouldParseAsyncArrow();
  9893. }
  9894. canHaveLeadingDecorator() {
  9895. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9896. }
  9897. jsxParseOpeningElementAfterName(node) {
  9898. if (this.match(47) || this.match(51)) {
  9899. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9900. if (typeArguments) node.typeParameters = typeArguments;
  9901. }
  9902. return super.jsxParseOpeningElementAfterName(node);
  9903. }
  9904. getGetterSetterExpectedParamCount(method) {
  9905. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9906. const params = this.getObjectOrClassMethodParams(method);
  9907. const firstParam = params[0];
  9908. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9909. return hasContextParam ? baseCount + 1 : baseCount;
  9910. }
  9911. parseCatchClauseParam() {
  9912. const param = super.parseCatchClauseParam();
  9913. const type = this.tsTryParseTypeAnnotation();
  9914. if (type) {
  9915. param.typeAnnotation = type;
  9916. this.resetEndLocation(param);
  9917. }
  9918. return param;
  9919. }
  9920. tsInAmbientContext(cb) {
  9921. const oldIsAmbientContext = this.state.isAmbientContext;
  9922. this.state.isAmbientContext = true;
  9923. try {
  9924. return cb();
  9925. } finally {
  9926. this.state.isAmbientContext = oldIsAmbientContext;
  9927. }
  9928. }
  9929. parseClass(node, isStatement, optionalId) {
  9930. const oldInAbstractClass = this.state.inAbstractClass;
  9931. this.state.inAbstractClass = !!node.abstract;
  9932. try {
  9933. return super.parseClass(node, isStatement, optionalId);
  9934. } finally {
  9935. this.state.inAbstractClass = oldInAbstractClass;
  9936. }
  9937. }
  9938. tsParseAbstractDeclaration(node, decorators) {
  9939. if (this.match(80)) {
  9940. node.abstract = true;
  9941. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  9942. } else if (this.isContextual(129)) {
  9943. if (!this.hasFollowingLineBreak()) {
  9944. node.abstract = true;
  9945. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
  9946. at: node
  9947. });
  9948. return this.tsParseInterfaceDeclaration(node);
  9949. }
  9950. } else {
  9951. this.unexpected(null, 80);
  9952. }
  9953. }
  9954. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  9955. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  9956. if (method.abstract) {
  9957. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  9958. if (hasBody) {
  9959. const {
  9960. key
  9961. } = method;
  9962. this.raise(TSErrors.AbstractMethodHasImplementation, {
  9963. at: method,
  9964. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9965. });
  9966. }
  9967. }
  9968. return method;
  9969. }
  9970. tsParseTypeParameterName() {
  9971. const typeName = this.parseIdentifier();
  9972. return typeName.name;
  9973. }
  9974. shouldParseAsAmbientContext() {
  9975. return !!this.getPluginOption("typescript", "dts");
  9976. }
  9977. parse() {
  9978. if (this.shouldParseAsAmbientContext()) {
  9979. this.state.isAmbientContext = true;
  9980. }
  9981. return super.parse();
  9982. }
  9983. getExpression() {
  9984. if (this.shouldParseAsAmbientContext()) {
  9985. this.state.isAmbientContext = true;
  9986. }
  9987. return super.getExpression();
  9988. }
  9989. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  9990. if (!isString && isMaybeTypeOnly) {
  9991. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  9992. return this.finishNode(node, "ExportSpecifier");
  9993. }
  9994. node.exportKind = "value";
  9995. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  9996. }
  9997. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  9998. if (!importedIsString && isMaybeTypeOnly) {
  9999. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10000. return this.finishNode(specifier, "ImportSpecifier");
  10001. }
  10002. specifier.importKind = "value";
  10003. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  10004. }
  10005. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10006. const leftOfAsKey = isImport ? "imported" : "local";
  10007. const rightOfAsKey = isImport ? "local" : "exported";
  10008. let leftOfAs = node[leftOfAsKey];
  10009. let rightOfAs;
  10010. let hasTypeSpecifier = false;
  10011. let canParseAsKeyword = true;
  10012. const loc = leftOfAs.loc.start;
  10013. if (this.isContextual(93)) {
  10014. const firstAs = this.parseIdentifier();
  10015. if (this.isContextual(93)) {
  10016. const secondAs = this.parseIdentifier();
  10017. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10018. hasTypeSpecifier = true;
  10019. leftOfAs = firstAs;
  10020. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10021. canParseAsKeyword = false;
  10022. } else {
  10023. rightOfAs = secondAs;
  10024. canParseAsKeyword = false;
  10025. }
  10026. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10027. canParseAsKeyword = false;
  10028. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10029. } else {
  10030. hasTypeSpecifier = true;
  10031. leftOfAs = firstAs;
  10032. }
  10033. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10034. hasTypeSpecifier = true;
  10035. if (isImport) {
  10036. leftOfAs = this.parseIdentifier(true);
  10037. if (!this.isContextual(93)) {
  10038. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10039. }
  10040. } else {
  10041. leftOfAs = this.parseModuleExportName();
  10042. }
  10043. }
  10044. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10045. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
  10046. at: loc
  10047. });
  10048. }
  10049. node[leftOfAsKey] = leftOfAs;
  10050. node[rightOfAsKey] = rightOfAs;
  10051. const kindKey = isImport ? "importKind" : "exportKind";
  10052. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10053. if (canParseAsKeyword && this.eatContextual(93)) {
  10054. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10055. }
  10056. if (!node[rightOfAsKey]) {
  10057. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  10058. }
  10059. if (isImport) {
  10060. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10061. }
  10062. }
  10063. };
  10064. function isPossiblyLiteralEnum(expression) {
  10065. if (expression.type !== "MemberExpression") return false;
  10066. const {
  10067. computed,
  10068. property
  10069. } = expression;
  10070. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10071. return false;
  10072. }
  10073. return isUncomputedMemberExpressionChain(expression.object);
  10074. }
  10075. function isValidAmbientConstInitializer(expression, estree) {
  10076. var _expression$extra;
  10077. const {
  10078. type
  10079. } = expression;
  10080. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10081. return false;
  10082. }
  10083. if (estree) {
  10084. if (type === "Literal") {
  10085. const {
  10086. value
  10087. } = expression;
  10088. if (typeof value === "string" || typeof value === "boolean") {
  10089. return true;
  10090. }
  10091. }
  10092. } else {
  10093. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10094. return true;
  10095. }
  10096. }
  10097. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10098. return true;
  10099. }
  10100. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10101. return true;
  10102. }
  10103. if (isPossiblyLiteralEnum(expression)) {
  10104. return true;
  10105. }
  10106. return false;
  10107. }
  10108. function isNumber(expression, estree) {
  10109. if (estree) {
  10110. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10111. }
  10112. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10113. }
  10114. function isNegativeNumber(expression, estree) {
  10115. if (expression.type === "UnaryExpression") {
  10116. const {
  10117. operator,
  10118. argument
  10119. } = expression;
  10120. if (operator === "-" && isNumber(argument, estree)) {
  10121. return true;
  10122. }
  10123. }
  10124. return false;
  10125. }
  10126. function isUncomputedMemberExpressionChain(expression) {
  10127. if (expression.type === "Identifier") return true;
  10128. if (expression.type !== "MemberExpression" || expression.computed) {
  10129. return false;
  10130. }
  10131. return isUncomputedMemberExpressionChain(expression.object);
  10132. }
  10133. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10134. ClassNameIsRequired: "A class name is required.",
  10135. UnexpectedSpace: "Unexpected space in placeholder."
  10136. });
  10137. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10138. parsePlaceholder(expectedNode) {
  10139. if (this.match(144)) {
  10140. const node = this.startNode();
  10141. this.next();
  10142. this.assertNoSpace();
  10143. node.name = super.parseIdentifier(true);
  10144. this.assertNoSpace();
  10145. this.expect(144);
  10146. return this.finishPlaceholder(node, expectedNode);
  10147. }
  10148. }
  10149. finishPlaceholder(node, expectedNode) {
  10150. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  10151. node.expectedNode = expectedNode;
  10152. return isFinished ? node : this.finishNode(node, "Placeholder");
  10153. }
  10154. getTokenFromCode(code) {
  10155. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10156. this.finishOp(144, 2);
  10157. } else {
  10158. super.getTokenFromCode(code);
  10159. }
  10160. }
  10161. parseExprAtom(refExpressionErrors) {
  10162. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10163. }
  10164. parseIdentifier(liberal) {
  10165. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10166. }
  10167. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10168. if (word !== undefined) {
  10169. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10170. }
  10171. }
  10172. parseBindingAtom() {
  10173. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10174. }
  10175. isValidLVal(type, isParenthesized, binding) {
  10176. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10177. }
  10178. toAssignable(node, isLHS) {
  10179. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10180. node.expectedNode = "Pattern";
  10181. } else {
  10182. super.toAssignable(node, isLHS);
  10183. }
  10184. }
  10185. chStartsBindingIdentifier(ch, pos) {
  10186. if (super.chStartsBindingIdentifier(ch, pos)) {
  10187. return true;
  10188. }
  10189. const nextToken = this.lookahead();
  10190. if (nextToken.type === 144) {
  10191. return true;
  10192. }
  10193. return false;
  10194. }
  10195. verifyBreakContinue(node, isBreak) {
  10196. if (node.label && node.label.type === "Placeholder") return;
  10197. super.verifyBreakContinue(node, isBreak);
  10198. }
  10199. parseExpressionStatement(node, expr) {
  10200. var _expr$extra;
  10201. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10202. return super.parseExpressionStatement(node, expr);
  10203. }
  10204. if (this.match(14)) {
  10205. const stmt = node;
  10206. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10207. this.next();
  10208. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10209. return this.finishNode(stmt, "LabeledStatement");
  10210. }
  10211. this.semicolon();
  10212. node.name = expr.name;
  10213. return this.finishPlaceholder(node, "Statement");
  10214. }
  10215. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10216. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10217. }
  10218. parseFunctionId(requireId) {
  10219. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10220. }
  10221. parseClass(node, isStatement, optionalId) {
  10222. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10223. this.next();
  10224. const oldStrict = this.state.strict;
  10225. const placeholder = this.parsePlaceholder("Identifier");
  10226. if (placeholder) {
  10227. if (this.match(81) || this.match(144) || this.match(5)) {
  10228. node.id = placeholder;
  10229. } else if (optionalId || !isStatement) {
  10230. node.id = null;
  10231. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10232. return this.finishNode(node, type);
  10233. } else {
  10234. throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
  10235. at: this.state.startLoc
  10236. });
  10237. }
  10238. } else {
  10239. this.parseClassId(node, isStatement, optionalId);
  10240. }
  10241. super.parseClassSuper(node);
  10242. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10243. return this.finishNode(node, type);
  10244. }
  10245. parseExport(node, decorators) {
  10246. const placeholder = this.parsePlaceholder("Identifier");
  10247. if (!placeholder) return super.parseExport(node, decorators);
  10248. if (!this.isContextual(98) && !this.match(12)) {
  10249. node.specifiers = [];
  10250. node.source = null;
  10251. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10252. return this.finishNode(node, "ExportNamedDeclaration");
  10253. }
  10254. this.expectPlugin("exportDefaultFrom");
  10255. const specifier = this.startNode();
  10256. specifier.exported = placeholder;
  10257. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10258. return super.parseExport(node, decorators);
  10259. }
  10260. isExportDefaultSpecifier() {
  10261. if (this.match(65)) {
  10262. const next = this.nextTokenStart();
  10263. if (this.isUnparsedContextual(next, "from")) {
  10264. if (this.input.startsWith(tokenLabelName(144), this.nextTokenStartSince(next + 4))) {
  10265. return true;
  10266. }
  10267. }
  10268. }
  10269. return super.isExportDefaultSpecifier();
  10270. }
  10271. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10272. var _specifiers;
  10273. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10274. return true;
  10275. }
  10276. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10277. }
  10278. checkExport(node) {
  10279. const {
  10280. specifiers
  10281. } = node;
  10282. if (specifiers != null && specifiers.length) {
  10283. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10284. }
  10285. super.checkExport(node);
  10286. node.specifiers = specifiers;
  10287. }
  10288. parseImport(node) {
  10289. const placeholder = this.parsePlaceholder("Identifier");
  10290. if (!placeholder) return super.parseImport(node);
  10291. node.specifiers = [];
  10292. if (!this.isContextual(98) && !this.match(12)) {
  10293. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10294. this.semicolon();
  10295. return this.finishNode(node, "ImportDeclaration");
  10296. }
  10297. const specifier = this.startNodeAtNode(placeholder);
  10298. specifier.local = placeholder;
  10299. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10300. if (this.eat(12)) {
  10301. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10302. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10303. }
  10304. this.expectContextual(98);
  10305. node.source = this.parseImportSource();
  10306. this.semicolon();
  10307. return this.finishNode(node, "ImportDeclaration");
  10308. }
  10309. parseImportSource() {
  10310. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10311. }
  10312. assertNoSpace() {
  10313. if (this.state.start > this.state.lastTokEndLoc.index) {
  10314. this.raise(PlaceholderErrors.UnexpectedSpace, {
  10315. at: this.state.lastTokEndLoc
  10316. });
  10317. }
  10318. }
  10319. };
  10320. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10321. parseV8Intrinsic() {
  10322. if (this.match(54)) {
  10323. const v8IntrinsicStartLoc = this.state.startLoc;
  10324. const node = this.startNode();
  10325. this.next();
  10326. if (tokenIsIdentifier(this.state.type)) {
  10327. const name = this.parseIdentifierName();
  10328. const identifier = this.createIdentifier(node, name);
  10329. identifier.type = "V8IntrinsicIdentifier";
  10330. if (this.match(10)) {
  10331. return identifier;
  10332. }
  10333. }
  10334. this.unexpected(v8IntrinsicStartLoc);
  10335. }
  10336. }
  10337. parseExprAtom(refExpressionErrors) {
  10338. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10339. }
  10340. };
  10341. function hasPlugin(plugins, expectedConfig) {
  10342. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  10343. const expectedKeys = Object.keys(expectedOptions);
  10344. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  10345. return plugins.some(p => {
  10346. if (typeof p === "string") {
  10347. return expectedOptionsIsEmpty && p === expectedName;
  10348. } else {
  10349. const [pluginName, pluginOptions] = p;
  10350. if (pluginName !== expectedName) {
  10351. return false;
  10352. }
  10353. for (const key of expectedKeys) {
  10354. if (pluginOptions[key] !== expectedOptions[key]) {
  10355. return false;
  10356. }
  10357. }
  10358. return true;
  10359. }
  10360. });
  10361. }
  10362. function getPluginOption(plugins, name, option) {
  10363. const plugin = plugins.find(plugin => {
  10364. if (Array.isArray(plugin)) {
  10365. return plugin[0] === name;
  10366. } else {
  10367. return plugin === name;
  10368. }
  10369. });
  10370. if (plugin && Array.isArray(plugin) && plugin.length > 1) {
  10371. return plugin[1][option];
  10372. }
  10373. return null;
  10374. }
  10375. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10376. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10377. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10378. function validatePlugins(plugins) {
  10379. if (hasPlugin(plugins, "decorators")) {
  10380. if (hasPlugin(plugins, "decorators-legacy")) {
  10381. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10382. }
  10383. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  10384. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10385. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10386. }
  10387. const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
  10388. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10389. throw new Error("'allowCallParenthesized' must be a boolean.");
  10390. }
  10391. }
  10392. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  10393. throw new Error("Cannot combine flow and typescript plugins.");
  10394. }
  10395. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  10396. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10397. }
  10398. if (hasPlugin(plugins, "pipelineOperator")) {
  10399. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  10400. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10401. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10402. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10403. }
  10404. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  10405. syntaxType: "hash"
  10406. }]);
  10407. if (proposal === "hack") {
  10408. if (hasPlugin(plugins, "placeholders")) {
  10409. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10410. }
  10411. if (hasPlugin(plugins, "v8intrinsic")) {
  10412. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10413. }
  10414. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  10415. if (!TOPIC_TOKENS.includes(topicToken)) {
  10416. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10417. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10418. }
  10419. if (topicToken === "#" && tupleSyntaxIsHash) {
  10420. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10421. }
  10422. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  10423. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10424. }
  10425. }
  10426. if (hasPlugin(plugins, "moduleAttributes")) {
  10427. {
  10428. if (hasPlugin(plugins, "importAssertions") || hasPlugin(plugins, "importAttributes")) {
  10429. throw new Error("Cannot combine importAssertions, importAttributes and moduleAttributes plugins.");
  10430. }
  10431. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  10432. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10433. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10434. }
  10435. }
  10436. }
  10437. if (hasPlugin(plugins, "importAssertions") && hasPlugin(plugins, "importAttributes")) {
  10438. throw new Error("Cannot combine importAssertions and importAttributes plugins.");
  10439. }
  10440. if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  10441. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10442. }
  10443. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  10444. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10445. error.missingPlugins = "doExpressions";
  10446. throw error;
  10447. }
  10448. if (hasPlugin(plugins, "optionalChainingAssign") && getPluginOption(plugins, "optionalChainingAssign", "version") !== "2023-07") {
  10449. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10450. }
  10451. }
  10452. const mixinPlugins = {
  10453. estree,
  10454. jsx,
  10455. flow,
  10456. typescript,
  10457. v8intrinsic,
  10458. placeholders
  10459. };
  10460. const mixinPluginNames = Object.keys(mixinPlugins);
  10461. const defaultOptions = {
  10462. sourceType: "script",
  10463. sourceFilename: undefined,
  10464. startColumn: 0,
  10465. startLine: 1,
  10466. allowAwaitOutsideFunction: false,
  10467. allowReturnOutsideFunction: false,
  10468. allowNewTargetOutsideFunction: false,
  10469. allowImportExportEverywhere: false,
  10470. allowSuperOutsideMethod: false,
  10471. allowUndeclaredExports: false,
  10472. plugins: [],
  10473. strictMode: null,
  10474. ranges: false,
  10475. tokens: false,
  10476. createImportExpressions: false,
  10477. createParenthesizedExpressions: false,
  10478. errorRecovery: false,
  10479. attachComment: true,
  10480. annexB: true
  10481. };
  10482. function getOptions(opts) {
  10483. if (opts == null) {
  10484. return Object.assign({}, defaultOptions);
  10485. }
  10486. if (opts.annexB != null && opts.annexB !== false) {
  10487. throw new Error("The `annexB` option can only be set to `false`.");
  10488. }
  10489. const options = {};
  10490. for (const key of Object.keys(defaultOptions)) {
  10491. var _opts$key;
  10492. options[key] = (_opts$key = opts[key]) != null ? _opts$key : defaultOptions[key];
  10493. }
  10494. return options;
  10495. }
  10496. class ExpressionParser extends LValParser {
  10497. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10498. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10499. return;
  10500. }
  10501. const key = prop.key;
  10502. const name = key.type === "Identifier" ? key.name : key.value;
  10503. if (name === "__proto__") {
  10504. if (isRecord) {
  10505. this.raise(Errors.RecordNoProto, {
  10506. at: key
  10507. });
  10508. return;
  10509. }
  10510. if (protoRef.used) {
  10511. if (refExpressionErrors) {
  10512. if (refExpressionErrors.doubleProtoLoc === null) {
  10513. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10514. }
  10515. } else {
  10516. this.raise(Errors.DuplicateProto, {
  10517. at: key
  10518. });
  10519. }
  10520. }
  10521. protoRef.used = true;
  10522. }
  10523. }
  10524. shouldExitDescending(expr, potentialArrowAt) {
  10525. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  10526. }
  10527. getExpression() {
  10528. this.enterInitialScopes();
  10529. this.nextToken();
  10530. const expr = this.parseExpression();
  10531. if (!this.match(139)) {
  10532. this.unexpected();
  10533. }
  10534. this.finalizeRemainingComments();
  10535. expr.comments = this.state.comments;
  10536. expr.errors = this.state.errors;
  10537. if (this.options.tokens) {
  10538. expr.tokens = this.tokens;
  10539. }
  10540. return expr;
  10541. }
  10542. parseExpression(disallowIn, refExpressionErrors) {
  10543. if (disallowIn) {
  10544. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10545. }
  10546. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10547. }
  10548. parseExpressionBase(refExpressionErrors) {
  10549. const startLoc = this.state.startLoc;
  10550. const expr = this.parseMaybeAssign(refExpressionErrors);
  10551. if (this.match(12)) {
  10552. const node = this.startNodeAt(startLoc);
  10553. node.expressions = [expr];
  10554. while (this.eat(12)) {
  10555. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10556. }
  10557. this.toReferencedList(node.expressions);
  10558. return this.finishNode(node, "SequenceExpression");
  10559. }
  10560. return expr;
  10561. }
  10562. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10563. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10564. }
  10565. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10566. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10567. }
  10568. setOptionalParametersError(refExpressionErrors, resultError) {
  10569. var _resultError$loc;
  10570. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10571. }
  10572. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10573. const startLoc = this.state.startLoc;
  10574. if (this.isContextual(108)) {
  10575. if (this.prodParam.hasYield) {
  10576. let left = this.parseYield();
  10577. if (afterLeftParse) {
  10578. left = afterLeftParse.call(this, left, startLoc);
  10579. }
  10580. return left;
  10581. }
  10582. }
  10583. let ownExpressionErrors;
  10584. if (refExpressionErrors) {
  10585. ownExpressionErrors = false;
  10586. } else {
  10587. refExpressionErrors = new ExpressionErrors();
  10588. ownExpressionErrors = true;
  10589. }
  10590. const {
  10591. type
  10592. } = this.state;
  10593. if (type === 10 || tokenIsIdentifier(type)) {
  10594. this.state.potentialArrowAt = this.state.start;
  10595. }
  10596. let left = this.parseMaybeConditional(refExpressionErrors);
  10597. if (afterLeftParse) {
  10598. left = afterLeftParse.call(this, left, startLoc);
  10599. }
  10600. if (tokenIsAssignment(this.state.type)) {
  10601. const node = this.startNodeAt(startLoc);
  10602. const operator = this.state.value;
  10603. node.operator = operator;
  10604. if (this.match(29)) {
  10605. this.toAssignable(left, true);
  10606. node.left = left;
  10607. const startIndex = startLoc.index;
  10608. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10609. refExpressionErrors.doubleProtoLoc = null;
  10610. }
  10611. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10612. refExpressionErrors.shorthandAssignLoc = null;
  10613. }
  10614. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10615. this.checkDestructuringPrivate(refExpressionErrors);
  10616. refExpressionErrors.privateKeyLoc = null;
  10617. }
  10618. } else {
  10619. node.left = left;
  10620. }
  10621. this.next();
  10622. node.right = this.parseMaybeAssign();
  10623. this.checkLVal(left, {
  10624. in: this.finishNode(node, "AssignmentExpression")
  10625. });
  10626. return node;
  10627. } else if (ownExpressionErrors) {
  10628. this.checkExpressionErrors(refExpressionErrors, true);
  10629. }
  10630. return left;
  10631. }
  10632. parseMaybeConditional(refExpressionErrors) {
  10633. const startLoc = this.state.startLoc;
  10634. const potentialArrowAt = this.state.potentialArrowAt;
  10635. const expr = this.parseExprOps(refExpressionErrors);
  10636. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10637. return expr;
  10638. }
  10639. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10640. }
  10641. parseConditional(expr, startLoc, refExpressionErrors) {
  10642. if (this.eat(17)) {
  10643. const node = this.startNodeAt(startLoc);
  10644. node.test = expr;
  10645. node.consequent = this.parseMaybeAssignAllowIn();
  10646. this.expect(14);
  10647. node.alternate = this.parseMaybeAssign();
  10648. return this.finishNode(node, "ConditionalExpression");
  10649. }
  10650. return expr;
  10651. }
  10652. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10653. return this.match(138) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10654. }
  10655. parseExprOps(refExpressionErrors) {
  10656. const startLoc = this.state.startLoc;
  10657. const potentialArrowAt = this.state.potentialArrowAt;
  10658. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10659. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10660. return expr;
  10661. }
  10662. return this.parseExprOp(expr, startLoc, -1);
  10663. }
  10664. parseExprOp(left, leftStartLoc, minPrec) {
  10665. if (this.isPrivateName(left)) {
  10666. const value = this.getPrivateNameSV(left);
  10667. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10668. this.raise(Errors.PrivateInExpectedIn, {
  10669. at: left,
  10670. identifierName: value
  10671. });
  10672. }
  10673. this.classScope.usePrivateName(value, left.loc.start);
  10674. }
  10675. const op = this.state.type;
  10676. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10677. let prec = tokenOperatorPrecedence(op);
  10678. if (prec > minPrec) {
  10679. if (op === 39) {
  10680. this.expectPlugin("pipelineOperator");
  10681. if (this.state.inFSharpPipelineDirectBody) {
  10682. return left;
  10683. }
  10684. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10685. }
  10686. const node = this.startNodeAt(leftStartLoc);
  10687. node.left = left;
  10688. node.operator = this.state.value;
  10689. const logical = op === 41 || op === 42;
  10690. const coalesce = op === 40;
  10691. if (coalesce) {
  10692. prec = tokenOperatorPrecedence(42);
  10693. }
  10694. this.next();
  10695. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10696. proposal: "minimal"
  10697. }])) {
  10698. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10699. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
  10700. at: this.state.startLoc
  10701. });
  10702. }
  10703. }
  10704. node.right = this.parseExprOpRightExpr(op, prec);
  10705. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10706. const nextOp = this.state.type;
  10707. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10708. throw this.raise(Errors.MixingCoalesceWithLogical, {
  10709. at: this.state.startLoc
  10710. });
  10711. }
  10712. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10713. }
  10714. }
  10715. return left;
  10716. }
  10717. parseExprOpRightExpr(op, prec) {
  10718. const startLoc = this.state.startLoc;
  10719. switch (op) {
  10720. case 39:
  10721. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10722. case "hack":
  10723. return this.withTopicBindingContext(() => {
  10724. return this.parseHackPipeBody();
  10725. });
  10726. case "smart":
  10727. return this.withTopicBindingContext(() => {
  10728. if (this.prodParam.hasYield && this.isContextual(108)) {
  10729. throw this.raise(Errors.PipeBodyIsTighter, {
  10730. at: this.state.startLoc
  10731. });
  10732. }
  10733. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10734. });
  10735. case "fsharp":
  10736. return this.withSoloAwaitPermittingContext(() => {
  10737. return this.parseFSharpPipelineBody(prec);
  10738. });
  10739. }
  10740. default:
  10741. return this.parseExprOpBaseRightExpr(op, prec);
  10742. }
  10743. }
  10744. parseExprOpBaseRightExpr(op, prec) {
  10745. const startLoc = this.state.startLoc;
  10746. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10747. }
  10748. parseHackPipeBody() {
  10749. var _body$extra;
  10750. const {
  10751. startLoc
  10752. } = this.state;
  10753. const body = this.parseMaybeAssign();
  10754. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10755. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10756. this.raise(Errors.PipeUnparenthesizedBody, {
  10757. at: startLoc,
  10758. type: body.type
  10759. });
  10760. }
  10761. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10762. this.raise(Errors.PipeTopicUnused, {
  10763. at: startLoc
  10764. });
  10765. }
  10766. return body;
  10767. }
  10768. checkExponentialAfterUnary(node) {
  10769. if (this.match(57)) {
  10770. this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
  10771. at: node.argument
  10772. });
  10773. }
  10774. }
  10775. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10776. const startLoc = this.state.startLoc;
  10777. const isAwait = this.isContextual(96);
  10778. if (isAwait && this.isAwaitAllowed()) {
  10779. this.next();
  10780. const expr = this.parseAwait(startLoc);
  10781. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10782. return expr;
  10783. }
  10784. const update = this.match(34);
  10785. const node = this.startNode();
  10786. if (tokenIsPrefix(this.state.type)) {
  10787. node.operator = this.state.value;
  10788. node.prefix = true;
  10789. if (this.match(72)) {
  10790. this.expectPlugin("throwExpressions");
  10791. }
  10792. const isDelete = this.match(89);
  10793. this.next();
  10794. node.argument = this.parseMaybeUnary(null, true);
  10795. this.checkExpressionErrors(refExpressionErrors, true);
  10796. if (this.state.strict && isDelete) {
  10797. const arg = node.argument;
  10798. if (arg.type === "Identifier") {
  10799. this.raise(Errors.StrictDelete, {
  10800. at: node
  10801. });
  10802. } else if (this.hasPropertyAsPrivateName(arg)) {
  10803. this.raise(Errors.DeletePrivateField, {
  10804. at: node
  10805. });
  10806. }
  10807. }
  10808. if (!update) {
  10809. if (!sawUnary) {
  10810. this.checkExponentialAfterUnary(node);
  10811. }
  10812. return this.finishNode(node, "UnaryExpression");
  10813. }
  10814. }
  10815. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10816. if (isAwait) {
  10817. const {
  10818. type
  10819. } = this.state;
  10820. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10821. if (startsExpr && !this.isAmbiguousAwait()) {
  10822. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
  10823. at: startLoc
  10824. });
  10825. return this.parseAwait(startLoc);
  10826. }
  10827. }
  10828. return expr;
  10829. }
  10830. parseUpdate(node, update, refExpressionErrors) {
  10831. if (update) {
  10832. const updateExpressionNode = node;
  10833. this.checkLVal(updateExpressionNode.argument, {
  10834. in: this.finishNode(updateExpressionNode, "UpdateExpression")
  10835. });
  10836. return node;
  10837. }
  10838. const startLoc = this.state.startLoc;
  10839. let expr = this.parseExprSubscripts(refExpressionErrors);
  10840. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10841. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10842. const node = this.startNodeAt(startLoc);
  10843. node.operator = this.state.value;
  10844. node.prefix = false;
  10845. node.argument = expr;
  10846. this.next();
  10847. this.checkLVal(expr, {
  10848. in: expr = this.finishNode(node, "UpdateExpression")
  10849. });
  10850. }
  10851. return expr;
  10852. }
  10853. parseExprSubscripts(refExpressionErrors) {
  10854. const startLoc = this.state.startLoc;
  10855. const potentialArrowAt = this.state.potentialArrowAt;
  10856. const expr = this.parseExprAtom(refExpressionErrors);
  10857. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10858. return expr;
  10859. }
  10860. return this.parseSubscripts(expr, startLoc);
  10861. }
  10862. parseSubscripts(base, startLoc, noCalls) {
  10863. const state = {
  10864. optionalChainMember: false,
  10865. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10866. stop: false
  10867. };
  10868. do {
  10869. base = this.parseSubscript(base, startLoc, noCalls, state);
  10870. state.maybeAsyncArrow = false;
  10871. } while (!state.stop);
  10872. return base;
  10873. }
  10874. parseSubscript(base, startLoc, noCalls, state) {
  10875. const {
  10876. type
  10877. } = this.state;
  10878. if (!noCalls && type === 15) {
  10879. return this.parseBind(base, startLoc, noCalls, state);
  10880. } else if (tokenIsTemplate(type)) {
  10881. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10882. }
  10883. let optional = false;
  10884. if (type === 18) {
  10885. if (noCalls) {
  10886. this.raise(Errors.OptionalChainingNoNew, {
  10887. at: this.state.startLoc
  10888. });
  10889. if (this.lookaheadCharCode() === 40) {
  10890. state.stop = true;
  10891. return base;
  10892. }
  10893. }
  10894. state.optionalChainMember = optional = true;
  10895. this.next();
  10896. }
  10897. if (!noCalls && this.match(10)) {
  10898. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10899. } else {
  10900. const computed = this.eat(0);
  10901. if (computed || optional || this.eat(16)) {
  10902. return this.parseMember(base, startLoc, state, computed, optional);
  10903. } else {
  10904. state.stop = true;
  10905. return base;
  10906. }
  10907. }
  10908. }
  10909. parseMember(base, startLoc, state, computed, optional) {
  10910. const node = this.startNodeAt(startLoc);
  10911. node.object = base;
  10912. node.computed = computed;
  10913. if (computed) {
  10914. node.property = this.parseExpression();
  10915. this.expect(3);
  10916. } else if (this.match(138)) {
  10917. if (base.type === "Super") {
  10918. this.raise(Errors.SuperPrivateField, {
  10919. at: startLoc
  10920. });
  10921. }
  10922. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10923. node.property = this.parsePrivateName();
  10924. } else {
  10925. node.property = this.parseIdentifier(true);
  10926. }
  10927. if (state.optionalChainMember) {
  10928. node.optional = optional;
  10929. return this.finishNode(node, "OptionalMemberExpression");
  10930. } else {
  10931. return this.finishNode(node, "MemberExpression");
  10932. }
  10933. }
  10934. parseBind(base, startLoc, noCalls, state) {
  10935. const node = this.startNodeAt(startLoc);
  10936. node.object = base;
  10937. this.next();
  10938. node.callee = this.parseNoCallExpr();
  10939. state.stop = true;
  10940. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10941. }
  10942. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10943. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10944. let refExpressionErrors = null;
  10945. this.state.maybeInArrowParameters = true;
  10946. this.next();
  10947. const node = this.startNodeAt(startLoc);
  10948. node.callee = base;
  10949. const {
  10950. maybeAsyncArrow,
  10951. optionalChainMember
  10952. } = state;
  10953. if (maybeAsyncArrow) {
  10954. this.expressionScope.enter(newAsyncArrowScope());
  10955. refExpressionErrors = new ExpressionErrors();
  10956. }
  10957. if (optionalChainMember) {
  10958. node.optional = optional;
  10959. }
  10960. if (optional) {
  10961. node.arguments = this.parseCallExpressionArguments(11);
  10962. } else {
  10963. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  10964. }
  10965. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10966. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10967. state.stop = true;
  10968. this.checkDestructuringPrivate(refExpressionErrors);
  10969. this.expressionScope.validateAsPattern();
  10970. this.expressionScope.exit();
  10971. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  10972. } else {
  10973. if (maybeAsyncArrow) {
  10974. this.checkExpressionErrors(refExpressionErrors, true);
  10975. this.expressionScope.exit();
  10976. }
  10977. this.toReferencedArguments(finishedNode);
  10978. }
  10979. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10980. return finishedNode;
  10981. }
  10982. toReferencedArguments(node, isParenthesizedExpr) {
  10983. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  10984. }
  10985. parseTaggedTemplateExpression(base, startLoc, state) {
  10986. const node = this.startNodeAt(startLoc);
  10987. node.tag = base;
  10988. node.quasi = this.parseTemplate(true);
  10989. if (state.optionalChainMember) {
  10990. this.raise(Errors.OptionalChainingNoTemplate, {
  10991. at: startLoc
  10992. });
  10993. }
  10994. return this.finishNode(node, "TaggedTemplateExpression");
  10995. }
  10996. atPossibleAsyncArrow(base) {
  10997. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.state.potentialArrowAt;
  10998. }
  10999. expectImportAttributesPlugin() {
  11000. if (!this.hasPlugin("importAssertions")) {
  11001. this.expectPlugin("importAttributes");
  11002. }
  11003. }
  11004. finishCallExpression(node, optional) {
  11005. if (node.callee.type === "Import") {
  11006. if (node.arguments.length === 2) {
  11007. {
  11008. if (!this.hasPlugin("moduleAttributes")) {
  11009. this.expectImportAttributesPlugin();
  11010. }
  11011. }
  11012. }
  11013. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11014. this.raise(Errors.ImportCallArity, {
  11015. at: node,
  11016. maxArgumentCount: this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  11017. });
  11018. } else {
  11019. for (const arg of node.arguments) {
  11020. if (arg.type === "SpreadElement") {
  11021. this.raise(Errors.ImportCallSpreadArgument, {
  11022. at: arg
  11023. });
  11024. }
  11025. }
  11026. }
  11027. }
  11028. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11029. }
  11030. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11031. const elts = [];
  11032. let first = true;
  11033. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11034. this.state.inFSharpPipelineDirectBody = false;
  11035. while (!this.eat(close)) {
  11036. if (first) {
  11037. first = false;
  11038. } else {
  11039. this.expect(12);
  11040. if (this.match(close)) {
  11041. if (dynamicImport && !this.hasPlugin("importAttributes") && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  11042. this.raise(Errors.ImportCallArgumentTrailingComma, {
  11043. at: this.state.lastTokStartLoc
  11044. });
  11045. }
  11046. if (nodeForExtra) {
  11047. this.addTrailingCommaExtraToNode(nodeForExtra);
  11048. }
  11049. this.next();
  11050. break;
  11051. }
  11052. }
  11053. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  11054. }
  11055. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11056. return elts;
  11057. }
  11058. shouldParseAsyncArrow() {
  11059. return this.match(19) && !this.canInsertSemicolon();
  11060. }
  11061. parseAsyncArrowFromCallExpression(node, call) {
  11062. var _call$extra;
  11063. this.resetPreviousNodeTrailingComments(call);
  11064. this.expect(19);
  11065. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11066. if (call.innerComments) {
  11067. setInnerComments(node, call.innerComments);
  11068. }
  11069. if (call.callee.trailingComments) {
  11070. setInnerComments(node, call.callee.trailingComments);
  11071. }
  11072. return node;
  11073. }
  11074. parseNoCallExpr() {
  11075. const startLoc = this.state.startLoc;
  11076. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11077. }
  11078. parseExprAtom(refExpressionErrors) {
  11079. let node;
  11080. let decorators = null;
  11081. const {
  11082. type
  11083. } = this.state;
  11084. switch (type) {
  11085. case 79:
  11086. return this.parseSuper();
  11087. case 83:
  11088. node = this.startNode();
  11089. this.next();
  11090. if (this.match(16)) {
  11091. return this.parseImportMetaProperty(node);
  11092. }
  11093. if (this.match(10)) {
  11094. if (this.options.createImportExpressions) {
  11095. return this.parseImportCall(node);
  11096. } else {
  11097. return this.finishNode(node, "Import");
  11098. }
  11099. } else {
  11100. this.raise(Errors.UnsupportedImport, {
  11101. at: this.state.lastTokStartLoc
  11102. });
  11103. return this.finishNode(node, "Import");
  11104. }
  11105. case 78:
  11106. node = this.startNode();
  11107. this.next();
  11108. return this.finishNode(node, "ThisExpression");
  11109. case 90:
  11110. {
  11111. return this.parseDo(this.startNode(), false);
  11112. }
  11113. case 56:
  11114. case 31:
  11115. {
  11116. this.readRegexp();
  11117. return this.parseRegExpLiteral(this.state.value);
  11118. }
  11119. case 134:
  11120. return this.parseNumericLiteral(this.state.value);
  11121. case 135:
  11122. return this.parseBigIntLiteral(this.state.value);
  11123. case 136:
  11124. return this.parseDecimalLiteral(this.state.value);
  11125. case 133:
  11126. return this.parseStringLiteral(this.state.value);
  11127. case 84:
  11128. return this.parseNullLiteral();
  11129. case 85:
  11130. return this.parseBooleanLiteral(true);
  11131. case 86:
  11132. return this.parseBooleanLiteral(false);
  11133. case 10:
  11134. {
  11135. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11136. return this.parseParenAndDistinguishExpression(canBeArrow);
  11137. }
  11138. case 2:
  11139. case 1:
  11140. {
  11141. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11142. }
  11143. case 0:
  11144. {
  11145. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11146. }
  11147. case 6:
  11148. case 7:
  11149. {
  11150. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11151. }
  11152. case 5:
  11153. {
  11154. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11155. }
  11156. case 68:
  11157. return this.parseFunctionOrFunctionSent();
  11158. case 26:
  11159. decorators = this.parseDecorators();
  11160. case 80:
  11161. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11162. case 77:
  11163. return this.parseNewOrNewTarget();
  11164. case 25:
  11165. case 24:
  11166. return this.parseTemplate(false);
  11167. case 15:
  11168. {
  11169. node = this.startNode();
  11170. this.next();
  11171. node.object = null;
  11172. const callee = node.callee = this.parseNoCallExpr();
  11173. if (callee.type === "MemberExpression") {
  11174. return this.finishNode(node, "BindExpression");
  11175. } else {
  11176. throw this.raise(Errors.UnsupportedBind, {
  11177. at: callee
  11178. });
  11179. }
  11180. }
  11181. case 138:
  11182. {
  11183. this.raise(Errors.PrivateInExpectedIn, {
  11184. at: this.state.startLoc,
  11185. identifierName: this.state.value
  11186. });
  11187. return this.parsePrivateName();
  11188. }
  11189. case 33:
  11190. {
  11191. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11192. }
  11193. case 32:
  11194. {
  11195. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11196. }
  11197. case 37:
  11198. case 38:
  11199. {
  11200. return this.parseTopicReference("hack");
  11201. }
  11202. case 44:
  11203. case 54:
  11204. case 27:
  11205. {
  11206. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11207. if (pipeProposal) {
  11208. return this.parseTopicReference(pipeProposal);
  11209. }
  11210. this.unexpected();
  11211. break;
  11212. }
  11213. case 47:
  11214. {
  11215. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11216. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11217. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11218. } else {
  11219. this.unexpected();
  11220. }
  11221. break;
  11222. }
  11223. default:
  11224. if (tokenIsIdentifier(type)) {
  11225. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11226. return this.parseModuleExpression();
  11227. }
  11228. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11229. const containsEsc = this.state.containsEsc;
  11230. const id = this.parseIdentifier();
  11231. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11232. const {
  11233. type
  11234. } = this.state;
  11235. if (type === 68) {
  11236. this.resetPreviousNodeTrailingComments(id);
  11237. this.next();
  11238. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11239. } else if (tokenIsIdentifier(type)) {
  11240. if (this.lookaheadCharCode() === 61) {
  11241. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11242. } else {
  11243. return id;
  11244. }
  11245. } else if (type === 90) {
  11246. this.resetPreviousNodeTrailingComments(id);
  11247. return this.parseDo(this.startNodeAtNode(id), true);
  11248. }
  11249. }
  11250. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11251. this.next();
  11252. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11253. }
  11254. return id;
  11255. } else {
  11256. this.unexpected();
  11257. }
  11258. }
  11259. }
  11260. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11261. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11262. if (pipeProposal) {
  11263. this.state.type = topicTokenType;
  11264. this.state.value = topicTokenValue;
  11265. this.state.pos--;
  11266. this.state.end--;
  11267. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11268. return this.parseTopicReference(pipeProposal);
  11269. } else {
  11270. this.unexpected();
  11271. }
  11272. }
  11273. parseTopicReference(pipeProposal) {
  11274. const node = this.startNode();
  11275. const startLoc = this.state.startLoc;
  11276. const tokenType = this.state.type;
  11277. this.next();
  11278. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11279. }
  11280. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11281. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11282. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11283. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11284. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, {
  11285. at: startLoc
  11286. });
  11287. }
  11288. this.registerTopicReference();
  11289. return this.finishNode(node, nodeType);
  11290. } else {
  11291. throw this.raise(Errors.PipeTopicUnconfiguredToken, {
  11292. at: startLoc,
  11293. token: tokenLabelName(tokenType)
  11294. });
  11295. }
  11296. }
  11297. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11298. switch (pipeProposal) {
  11299. case "hack":
  11300. {
  11301. return this.hasPlugin(["pipelineOperator", {
  11302. topicToken: tokenLabelName(tokenType)
  11303. }]);
  11304. }
  11305. case "smart":
  11306. return tokenType === 27;
  11307. default:
  11308. throw this.raise(Errors.PipeTopicRequiresHackPipes, {
  11309. at: startLoc
  11310. });
  11311. }
  11312. }
  11313. parseAsyncArrowUnaryFunction(node) {
  11314. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11315. const params = [this.parseIdentifier()];
  11316. this.prodParam.exit();
  11317. if (this.hasPrecedingLineBreak()) {
  11318. this.raise(Errors.LineTerminatorBeforeArrow, {
  11319. at: this.state.curPosition()
  11320. });
  11321. }
  11322. this.expect(19);
  11323. return this.parseArrowExpression(node, params, true);
  11324. }
  11325. parseDo(node, isAsync) {
  11326. this.expectPlugin("doExpressions");
  11327. if (isAsync) {
  11328. this.expectPlugin("asyncDoExpressions");
  11329. }
  11330. node.async = isAsync;
  11331. this.next();
  11332. const oldLabels = this.state.labels;
  11333. this.state.labels = [];
  11334. if (isAsync) {
  11335. this.prodParam.enter(2);
  11336. node.body = this.parseBlock();
  11337. this.prodParam.exit();
  11338. } else {
  11339. node.body = this.parseBlock();
  11340. }
  11341. this.state.labels = oldLabels;
  11342. return this.finishNode(node, "DoExpression");
  11343. }
  11344. parseSuper() {
  11345. const node = this.startNode();
  11346. this.next();
  11347. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  11348. this.raise(Errors.SuperNotAllowed, {
  11349. at: node
  11350. });
  11351. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  11352. this.raise(Errors.UnexpectedSuper, {
  11353. at: node
  11354. });
  11355. }
  11356. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11357. this.raise(Errors.UnsupportedSuper, {
  11358. at: node
  11359. });
  11360. }
  11361. return this.finishNode(node, "Super");
  11362. }
  11363. parsePrivateName() {
  11364. const node = this.startNode();
  11365. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11366. const name = this.state.value;
  11367. this.next();
  11368. node.id = this.createIdentifier(id, name);
  11369. return this.finishNode(node, "PrivateName");
  11370. }
  11371. parseFunctionOrFunctionSent() {
  11372. const node = this.startNode();
  11373. this.next();
  11374. if (this.prodParam.hasYield && this.match(16)) {
  11375. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11376. this.next();
  11377. if (this.match(103)) {
  11378. this.expectPlugin("functionSent");
  11379. } else if (!this.hasPlugin("functionSent")) {
  11380. this.unexpected();
  11381. }
  11382. return this.parseMetaProperty(node, meta, "sent");
  11383. }
  11384. return this.parseFunction(node);
  11385. }
  11386. parseMetaProperty(node, meta, propertyName) {
  11387. node.meta = meta;
  11388. const containsEsc = this.state.containsEsc;
  11389. node.property = this.parseIdentifier(true);
  11390. if (node.property.name !== propertyName || containsEsc) {
  11391. this.raise(Errors.UnsupportedMetaProperty, {
  11392. at: node.property,
  11393. target: meta.name,
  11394. onlyValidPropertyName: propertyName
  11395. });
  11396. }
  11397. return this.finishNode(node, "MetaProperty");
  11398. }
  11399. parseImportMetaProperty(node) {
  11400. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11401. this.next();
  11402. if (this.isContextual(101)) {
  11403. if (!this.inModule) {
  11404. this.raise(Errors.ImportMetaOutsideModule, {
  11405. at: id
  11406. });
  11407. }
  11408. this.sawUnambiguousESM = true;
  11409. } else if (this.isContextual(105) || this.isContextual(97)) {
  11410. const isSource = this.isContextual(105);
  11411. if (!isSource) this.unexpected();
  11412. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11413. if (!this.options.createImportExpressions) {
  11414. throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, {
  11415. at: this.state.startLoc,
  11416. phase: this.state.value
  11417. });
  11418. }
  11419. this.next();
  11420. node.phase = isSource ? "source" : "defer";
  11421. return this.parseImportCall(node);
  11422. }
  11423. return this.parseMetaProperty(node, id, "meta");
  11424. }
  11425. parseLiteralAtNode(value, type, node) {
  11426. this.addExtra(node, "rawValue", value);
  11427. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  11428. node.value = value;
  11429. this.next();
  11430. return this.finishNode(node, type);
  11431. }
  11432. parseLiteral(value, type) {
  11433. const node = this.startNode();
  11434. return this.parseLiteralAtNode(value, type, node);
  11435. }
  11436. parseStringLiteral(value) {
  11437. return this.parseLiteral(value, "StringLiteral");
  11438. }
  11439. parseNumericLiteral(value) {
  11440. return this.parseLiteral(value, "NumericLiteral");
  11441. }
  11442. parseBigIntLiteral(value) {
  11443. return this.parseLiteral(value, "BigIntLiteral");
  11444. }
  11445. parseDecimalLiteral(value) {
  11446. return this.parseLiteral(value, "DecimalLiteral");
  11447. }
  11448. parseRegExpLiteral(value) {
  11449. const node = this.parseLiteral(value.value, "RegExpLiteral");
  11450. node.pattern = value.pattern;
  11451. node.flags = value.flags;
  11452. return node;
  11453. }
  11454. parseBooleanLiteral(value) {
  11455. const node = this.startNode();
  11456. node.value = value;
  11457. this.next();
  11458. return this.finishNode(node, "BooleanLiteral");
  11459. }
  11460. parseNullLiteral() {
  11461. const node = this.startNode();
  11462. this.next();
  11463. return this.finishNode(node, "NullLiteral");
  11464. }
  11465. parseParenAndDistinguishExpression(canBeArrow) {
  11466. const startLoc = this.state.startLoc;
  11467. let val;
  11468. this.next();
  11469. this.expressionScope.enter(newArrowHeadScope());
  11470. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11471. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11472. this.state.maybeInArrowParameters = true;
  11473. this.state.inFSharpPipelineDirectBody = false;
  11474. const innerStartLoc = this.state.startLoc;
  11475. const exprList = [];
  11476. const refExpressionErrors = new ExpressionErrors();
  11477. let first = true;
  11478. let spreadStartLoc;
  11479. let optionalCommaStartLoc;
  11480. while (!this.match(11)) {
  11481. if (first) {
  11482. first = false;
  11483. } else {
  11484. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11485. if (this.match(11)) {
  11486. optionalCommaStartLoc = this.state.startLoc;
  11487. break;
  11488. }
  11489. }
  11490. if (this.match(21)) {
  11491. const spreadNodeStartLoc = this.state.startLoc;
  11492. spreadStartLoc = this.state.startLoc;
  11493. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11494. if (!this.checkCommaAfterRest(41)) {
  11495. break;
  11496. }
  11497. } else {
  11498. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11499. }
  11500. }
  11501. const innerEndLoc = this.state.lastTokEndLoc;
  11502. this.expect(11);
  11503. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11504. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11505. let arrowNode = this.startNodeAt(startLoc);
  11506. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11507. this.checkDestructuringPrivate(refExpressionErrors);
  11508. this.expressionScope.validateAsPattern();
  11509. this.expressionScope.exit();
  11510. this.parseArrowExpression(arrowNode, exprList, false);
  11511. return arrowNode;
  11512. }
  11513. this.expressionScope.exit();
  11514. if (!exprList.length) {
  11515. this.unexpected(this.state.lastTokStartLoc);
  11516. }
  11517. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11518. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11519. this.checkExpressionErrors(refExpressionErrors, true);
  11520. this.toReferencedListDeep(exprList, true);
  11521. if (exprList.length > 1) {
  11522. val = this.startNodeAt(innerStartLoc);
  11523. val.expressions = exprList;
  11524. this.finishNode(val, "SequenceExpression");
  11525. this.resetEndLocation(val, innerEndLoc);
  11526. } else {
  11527. val = exprList[0];
  11528. }
  11529. return this.wrapParenthesis(startLoc, val);
  11530. }
  11531. wrapParenthesis(startLoc, expression) {
  11532. if (!this.options.createParenthesizedExpressions) {
  11533. this.addExtra(expression, "parenthesized", true);
  11534. this.addExtra(expression, "parenStart", startLoc.index);
  11535. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11536. return expression;
  11537. }
  11538. const parenExpression = this.startNodeAt(startLoc);
  11539. parenExpression.expression = expression;
  11540. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11541. }
  11542. shouldParseArrow(params) {
  11543. return !this.canInsertSemicolon();
  11544. }
  11545. parseArrow(node) {
  11546. if (this.eat(19)) {
  11547. return node;
  11548. }
  11549. }
  11550. parseParenItem(node, startLoc) {
  11551. return node;
  11552. }
  11553. parseNewOrNewTarget() {
  11554. const node = this.startNode();
  11555. this.next();
  11556. if (this.match(16)) {
  11557. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11558. this.next();
  11559. const metaProp = this.parseMetaProperty(node, meta, "target");
  11560. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
  11561. this.raise(Errors.UnexpectedNewTarget, {
  11562. at: metaProp
  11563. });
  11564. }
  11565. return metaProp;
  11566. }
  11567. return this.parseNew(node);
  11568. }
  11569. parseNew(node) {
  11570. this.parseNewCallee(node);
  11571. if (this.eat(10)) {
  11572. const args = this.parseExprList(11);
  11573. this.toReferencedList(args);
  11574. node.arguments = args;
  11575. } else {
  11576. node.arguments = [];
  11577. }
  11578. return this.finishNode(node, "NewExpression");
  11579. }
  11580. parseNewCallee(node) {
  11581. const isImport = this.match(83);
  11582. const callee = this.parseNoCallExpr();
  11583. node.callee = callee;
  11584. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11585. this.raise(Errors.ImportCallNotNewExpression, {
  11586. at: callee
  11587. });
  11588. }
  11589. }
  11590. parseTemplateElement(isTagged) {
  11591. const {
  11592. start,
  11593. startLoc,
  11594. end,
  11595. value
  11596. } = this.state;
  11597. const elemStart = start + 1;
  11598. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11599. if (value === null) {
  11600. if (!isTagged) {
  11601. this.raise(Errors.InvalidEscapeSequenceTemplate, {
  11602. at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)
  11603. });
  11604. }
  11605. }
  11606. const isTail = this.match(24);
  11607. const endOffset = isTail ? -1 : -2;
  11608. const elemEnd = end + endOffset;
  11609. elem.value = {
  11610. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11611. cooked: value === null ? null : value.slice(1, endOffset)
  11612. };
  11613. elem.tail = isTail;
  11614. this.next();
  11615. const finishedNode = this.finishNode(elem, "TemplateElement");
  11616. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11617. return finishedNode;
  11618. }
  11619. parseTemplate(isTagged) {
  11620. const node = this.startNode();
  11621. node.expressions = [];
  11622. let curElt = this.parseTemplateElement(isTagged);
  11623. node.quasis = [curElt];
  11624. while (!curElt.tail) {
  11625. node.expressions.push(this.parseTemplateSubstitution());
  11626. this.readTemplateContinuation();
  11627. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  11628. }
  11629. return this.finishNode(node, "TemplateLiteral");
  11630. }
  11631. parseTemplateSubstitution() {
  11632. return this.parseExpression();
  11633. }
  11634. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11635. if (isRecord) {
  11636. this.expectPlugin("recordAndTuple");
  11637. }
  11638. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11639. this.state.inFSharpPipelineDirectBody = false;
  11640. const propHash = Object.create(null);
  11641. let first = true;
  11642. const node = this.startNode();
  11643. node.properties = [];
  11644. this.next();
  11645. while (!this.match(close)) {
  11646. if (first) {
  11647. first = false;
  11648. } else {
  11649. this.expect(12);
  11650. if (this.match(close)) {
  11651. this.addTrailingCommaExtraToNode(node);
  11652. break;
  11653. }
  11654. }
  11655. let prop;
  11656. if (isPattern) {
  11657. prop = this.parseBindingProperty();
  11658. } else {
  11659. prop = this.parsePropertyDefinition(refExpressionErrors);
  11660. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11661. }
  11662. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11663. this.raise(Errors.InvalidRecordProperty, {
  11664. at: prop
  11665. });
  11666. }
  11667. if (prop.shorthand) {
  11668. this.addExtra(prop, "shorthand", true);
  11669. }
  11670. node.properties.push(prop);
  11671. }
  11672. this.next();
  11673. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11674. let type = "ObjectExpression";
  11675. if (isPattern) {
  11676. type = "ObjectPattern";
  11677. } else if (isRecord) {
  11678. type = "RecordExpression";
  11679. }
  11680. return this.finishNode(node, type);
  11681. }
  11682. addTrailingCommaExtraToNode(node) {
  11683. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  11684. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11685. }
  11686. maybeAsyncOrAccessorProp(prop) {
  11687. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11688. }
  11689. parsePropertyDefinition(refExpressionErrors) {
  11690. let decorators = [];
  11691. if (this.match(26)) {
  11692. if (this.hasPlugin("decorators")) {
  11693. this.raise(Errors.UnsupportedPropertyDecorator, {
  11694. at: this.state.startLoc
  11695. });
  11696. }
  11697. while (this.match(26)) {
  11698. decorators.push(this.parseDecorator());
  11699. }
  11700. }
  11701. const prop = this.startNode();
  11702. let isAsync = false;
  11703. let isAccessor = false;
  11704. let startLoc;
  11705. if (this.match(21)) {
  11706. if (decorators.length) this.unexpected();
  11707. return this.parseSpread();
  11708. }
  11709. if (decorators.length) {
  11710. prop.decorators = decorators;
  11711. decorators = [];
  11712. }
  11713. prop.method = false;
  11714. if (refExpressionErrors) {
  11715. startLoc = this.state.startLoc;
  11716. }
  11717. let isGenerator = this.eat(55);
  11718. this.parsePropertyNamePrefixOperator(prop);
  11719. const containsEsc = this.state.containsEsc;
  11720. const key = this.parsePropertyName(prop, refExpressionErrors);
  11721. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11722. const keyName = key.name;
  11723. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11724. isAsync = true;
  11725. this.resetPreviousNodeTrailingComments(key);
  11726. isGenerator = this.eat(55);
  11727. this.parsePropertyName(prop);
  11728. }
  11729. if (keyName === "get" || keyName === "set") {
  11730. isAccessor = true;
  11731. this.resetPreviousNodeTrailingComments(key);
  11732. prop.kind = keyName;
  11733. if (this.match(55)) {
  11734. isGenerator = true;
  11735. this.raise(Errors.AccessorIsGenerator, {
  11736. at: this.state.curPosition(),
  11737. kind: keyName
  11738. });
  11739. this.next();
  11740. }
  11741. this.parsePropertyName(prop);
  11742. }
  11743. }
  11744. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11745. }
  11746. getGetterSetterExpectedParamCount(method) {
  11747. return method.kind === "get" ? 0 : 1;
  11748. }
  11749. getObjectOrClassMethodParams(method) {
  11750. return method.params;
  11751. }
  11752. checkGetterSetterParams(method) {
  11753. var _params;
  11754. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11755. const params = this.getObjectOrClassMethodParams(method);
  11756. if (params.length !== paramCount) {
  11757. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  11758. at: method
  11759. });
  11760. }
  11761. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11762. this.raise(Errors.BadSetterRestParameter, {
  11763. at: method
  11764. });
  11765. }
  11766. }
  11767. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11768. if (isAccessor) {
  11769. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11770. this.checkGetterSetterParams(finishedProp);
  11771. return finishedProp;
  11772. }
  11773. if (isAsync || isGenerator || this.match(10)) {
  11774. if (isPattern) this.unexpected();
  11775. prop.kind = "method";
  11776. prop.method = true;
  11777. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11778. }
  11779. }
  11780. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11781. prop.shorthand = false;
  11782. if (this.eat(14)) {
  11783. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11784. return this.finishNode(prop, "ObjectProperty");
  11785. }
  11786. if (!prop.computed && prop.key.type === "Identifier") {
  11787. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11788. if (isPattern) {
  11789. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11790. } else if (this.match(29)) {
  11791. const shorthandAssignLoc = this.state.startLoc;
  11792. if (refExpressionErrors != null) {
  11793. if (refExpressionErrors.shorthandAssignLoc === null) {
  11794. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11795. }
  11796. } else {
  11797. this.raise(Errors.InvalidCoverInitializedName, {
  11798. at: shorthandAssignLoc
  11799. });
  11800. }
  11801. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11802. } else {
  11803. prop.value = cloneIdentifier(prop.key);
  11804. }
  11805. prop.shorthand = true;
  11806. return this.finishNode(prop, "ObjectProperty");
  11807. }
  11808. }
  11809. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11810. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11811. if (!node) this.unexpected();
  11812. return node;
  11813. }
  11814. parsePropertyName(prop, refExpressionErrors) {
  11815. if (this.eat(0)) {
  11816. prop.computed = true;
  11817. prop.key = this.parseMaybeAssignAllowIn();
  11818. this.expect(3);
  11819. } else {
  11820. const {
  11821. type,
  11822. value
  11823. } = this.state;
  11824. let key;
  11825. if (tokenIsKeywordOrIdentifier(type)) {
  11826. key = this.parseIdentifier(true);
  11827. } else {
  11828. switch (type) {
  11829. case 134:
  11830. key = this.parseNumericLiteral(value);
  11831. break;
  11832. case 133:
  11833. key = this.parseStringLiteral(value);
  11834. break;
  11835. case 135:
  11836. key = this.parseBigIntLiteral(value);
  11837. break;
  11838. case 136:
  11839. key = this.parseDecimalLiteral(value);
  11840. break;
  11841. case 138:
  11842. {
  11843. const privateKeyLoc = this.state.startLoc;
  11844. if (refExpressionErrors != null) {
  11845. if (refExpressionErrors.privateKeyLoc === null) {
  11846. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11847. }
  11848. } else {
  11849. this.raise(Errors.UnexpectedPrivateField, {
  11850. at: privateKeyLoc
  11851. });
  11852. }
  11853. key = this.parsePrivateName();
  11854. break;
  11855. }
  11856. default:
  11857. this.unexpected();
  11858. }
  11859. }
  11860. prop.key = key;
  11861. if (type !== 138) {
  11862. prop.computed = false;
  11863. }
  11864. }
  11865. return prop.key;
  11866. }
  11867. initFunction(node, isAsync) {
  11868. node.id = null;
  11869. node.generator = false;
  11870. node.async = isAsync;
  11871. }
  11872. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11873. this.initFunction(node, isAsync);
  11874. node.generator = isGenerator;
  11875. this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
  11876. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11877. this.parseFunctionParams(node, isConstructor);
  11878. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11879. this.prodParam.exit();
  11880. this.scope.exit();
  11881. return finishedNode;
  11882. }
  11883. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11884. if (isTuple) {
  11885. this.expectPlugin("recordAndTuple");
  11886. }
  11887. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11888. this.state.inFSharpPipelineDirectBody = false;
  11889. const node = this.startNode();
  11890. this.next();
  11891. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11892. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11893. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11894. }
  11895. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11896. this.scope.enter(2 | 4);
  11897. let flags = functionFlags(isAsync, false);
  11898. if (!this.match(5) && this.prodParam.hasIn) {
  11899. flags |= 8;
  11900. }
  11901. this.prodParam.enter(flags);
  11902. this.initFunction(node, isAsync);
  11903. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11904. if (params) {
  11905. this.state.maybeInArrowParameters = true;
  11906. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11907. }
  11908. this.state.maybeInArrowParameters = false;
  11909. this.parseFunctionBody(node, true);
  11910. this.prodParam.exit();
  11911. this.scope.exit();
  11912. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11913. return this.finishNode(node, "ArrowFunctionExpression");
  11914. }
  11915. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11916. this.toAssignableList(params, trailingCommaLoc, false);
  11917. node.params = params;
  11918. }
  11919. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11920. this.parseFunctionBody(node, false, isMethod);
  11921. return this.finishNode(node, type);
  11922. }
  11923. parseFunctionBody(node, allowExpression, isMethod = false) {
  11924. const isExpression = allowExpression && !this.match(5);
  11925. this.expressionScope.enter(newExpressionScope());
  11926. if (isExpression) {
  11927. node.body = this.parseMaybeAssign();
  11928. this.checkParams(node, false, allowExpression, false);
  11929. } else {
  11930. const oldStrict = this.state.strict;
  11931. const oldLabels = this.state.labels;
  11932. this.state.labels = [];
  11933. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  11934. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11935. const nonSimple = !this.isSimpleParamList(node.params);
  11936. if (hasStrictModeDirective && nonSimple) {
  11937. this.raise(Errors.IllegalLanguageModeDirective, {
  11938. at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node
  11939. });
  11940. }
  11941. const strictModeChanged = !oldStrict && this.state.strict;
  11942. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11943. if (this.state.strict && node.id) {
  11944. this.checkIdentifier(node.id, 65, strictModeChanged);
  11945. }
  11946. });
  11947. this.prodParam.exit();
  11948. this.state.labels = oldLabels;
  11949. }
  11950. this.expressionScope.exit();
  11951. }
  11952. isSimpleParameter(node) {
  11953. return node.type === "Identifier";
  11954. }
  11955. isSimpleParamList(params) {
  11956. for (let i = 0, len = params.length; i < len; i++) {
  11957. if (!this.isSimpleParameter(params[i])) return false;
  11958. }
  11959. return true;
  11960. }
  11961. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11962. const checkClashes = !allowDuplicates && new Set();
  11963. const formalParameters = {
  11964. type: "FormalParameters"
  11965. };
  11966. for (const param of node.params) {
  11967. this.checkLVal(param, {
  11968. in: formalParameters,
  11969. binding: 5,
  11970. checkClashes,
  11971. strictModeChanged
  11972. });
  11973. }
  11974. }
  11975. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11976. const elts = [];
  11977. let first = true;
  11978. while (!this.eat(close)) {
  11979. if (first) {
  11980. first = false;
  11981. } else {
  11982. this.expect(12);
  11983. if (this.match(close)) {
  11984. if (nodeForExtra) {
  11985. this.addTrailingCommaExtraToNode(nodeForExtra);
  11986. }
  11987. this.next();
  11988. break;
  11989. }
  11990. }
  11991. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11992. }
  11993. return elts;
  11994. }
  11995. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  11996. let elt;
  11997. if (this.match(12)) {
  11998. if (!allowEmpty) {
  11999. this.raise(Errors.UnexpectedToken, {
  12000. at: this.state.curPosition(),
  12001. unexpected: ","
  12002. });
  12003. }
  12004. elt = null;
  12005. } else if (this.match(21)) {
  12006. const spreadNodeStartLoc = this.state.startLoc;
  12007. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12008. } else if (this.match(17)) {
  12009. this.expectPlugin("partialApplication");
  12010. if (!allowPlaceholder) {
  12011. this.raise(Errors.UnexpectedArgumentPlaceholder, {
  12012. at: this.state.startLoc
  12013. });
  12014. }
  12015. const node = this.startNode();
  12016. this.next();
  12017. elt = this.finishNode(node, "ArgumentPlaceholder");
  12018. } else {
  12019. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  12020. }
  12021. return elt;
  12022. }
  12023. parseIdentifier(liberal) {
  12024. const node = this.startNode();
  12025. const name = this.parseIdentifierName(liberal);
  12026. return this.createIdentifier(node, name);
  12027. }
  12028. createIdentifier(node, name) {
  12029. node.name = name;
  12030. node.loc.identifierName = name;
  12031. return this.finishNode(node, "Identifier");
  12032. }
  12033. parseIdentifierName(liberal) {
  12034. let name;
  12035. const {
  12036. startLoc,
  12037. type
  12038. } = this.state;
  12039. if (tokenIsKeywordOrIdentifier(type)) {
  12040. name = this.state.value;
  12041. } else {
  12042. this.unexpected();
  12043. }
  12044. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12045. if (liberal) {
  12046. if (tokenIsKeyword) {
  12047. this.replaceToken(132);
  12048. }
  12049. } else {
  12050. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12051. }
  12052. this.next();
  12053. return name;
  12054. }
  12055. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12056. if (word.length > 10) {
  12057. return;
  12058. }
  12059. if (!canBeReservedWord(word)) {
  12060. return;
  12061. }
  12062. if (checkKeywords && isKeyword(word)) {
  12063. this.raise(Errors.UnexpectedKeyword, {
  12064. at: startLoc,
  12065. keyword: word
  12066. });
  12067. return;
  12068. }
  12069. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12070. if (reservedTest(word, this.inModule)) {
  12071. this.raise(Errors.UnexpectedReservedWord, {
  12072. at: startLoc,
  12073. reservedWord: word
  12074. });
  12075. return;
  12076. } else if (word === "yield") {
  12077. if (this.prodParam.hasYield) {
  12078. this.raise(Errors.YieldBindingIdentifier, {
  12079. at: startLoc
  12080. });
  12081. return;
  12082. }
  12083. } else if (word === "await") {
  12084. if (this.prodParam.hasAwait) {
  12085. this.raise(Errors.AwaitBindingIdentifier, {
  12086. at: startLoc
  12087. });
  12088. return;
  12089. }
  12090. if (this.scope.inStaticBlock) {
  12091. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
  12092. at: startLoc
  12093. });
  12094. return;
  12095. }
  12096. this.expressionScope.recordAsyncArrowParametersError({
  12097. at: startLoc
  12098. });
  12099. } else if (word === "arguments") {
  12100. if (this.scope.inClassAndNotInNonArrowFunction) {
  12101. this.raise(Errors.ArgumentsInClass, {
  12102. at: startLoc
  12103. });
  12104. return;
  12105. }
  12106. }
  12107. }
  12108. isAwaitAllowed() {
  12109. if (this.prodParam.hasAwait) return true;
  12110. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  12111. return true;
  12112. }
  12113. return false;
  12114. }
  12115. parseAwait(startLoc) {
  12116. const node = this.startNodeAt(startLoc);
  12117. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
  12118. at: node
  12119. });
  12120. if (this.eat(55)) {
  12121. this.raise(Errors.ObsoleteAwaitStar, {
  12122. at: node
  12123. });
  12124. }
  12125. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  12126. if (this.isAmbiguousAwait()) {
  12127. this.ambiguousScriptDifferentAst = true;
  12128. } else {
  12129. this.sawUnambiguousESM = true;
  12130. }
  12131. }
  12132. if (!this.state.soloAwait) {
  12133. node.argument = this.parseMaybeUnary(null, true);
  12134. }
  12135. return this.finishNode(node, "AwaitExpression");
  12136. }
  12137. isAmbiguousAwait() {
  12138. if (this.hasPrecedingLineBreak()) return true;
  12139. const {
  12140. type
  12141. } = this.state;
  12142. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 137 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12143. }
  12144. parseYield() {
  12145. const node = this.startNode();
  12146. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
  12147. at: node
  12148. });
  12149. this.next();
  12150. let delegating = false;
  12151. let argument = null;
  12152. if (!this.hasPrecedingLineBreak()) {
  12153. delegating = this.eat(55);
  12154. switch (this.state.type) {
  12155. case 13:
  12156. case 139:
  12157. case 8:
  12158. case 11:
  12159. case 3:
  12160. case 9:
  12161. case 14:
  12162. case 12:
  12163. if (!delegating) break;
  12164. default:
  12165. argument = this.parseMaybeAssign();
  12166. }
  12167. }
  12168. node.delegate = delegating;
  12169. node.argument = argument;
  12170. return this.finishNode(node, "YieldExpression");
  12171. }
  12172. parseImportCall(node) {
  12173. this.next();
  12174. node.source = this.parseMaybeAssignAllowIn();
  12175. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  12176. node.options = null;
  12177. }
  12178. if (this.eat(12)) {
  12179. this.expectImportAttributesPlugin();
  12180. if (!this.match(11)) {
  12181. node.options = this.parseMaybeAssignAllowIn();
  12182. this.eat(12);
  12183. }
  12184. }
  12185. this.expect(11);
  12186. return this.finishNode(node, "ImportExpression");
  12187. }
  12188. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12189. if (this.hasPlugin(["pipelineOperator", {
  12190. proposal: "smart"
  12191. }])) {
  12192. if (left.type === "SequenceExpression") {
  12193. this.raise(Errors.PipelineHeadSequenceExpression, {
  12194. at: leftStartLoc
  12195. });
  12196. }
  12197. }
  12198. }
  12199. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12200. if (this.isSimpleReference(childExpr)) {
  12201. const bodyNode = this.startNodeAt(startLoc);
  12202. bodyNode.callee = childExpr;
  12203. return this.finishNode(bodyNode, "PipelineBareFunction");
  12204. } else {
  12205. const bodyNode = this.startNodeAt(startLoc);
  12206. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12207. bodyNode.expression = childExpr;
  12208. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12209. }
  12210. }
  12211. isSimpleReference(expression) {
  12212. switch (expression.type) {
  12213. case "MemberExpression":
  12214. return !expression.computed && this.isSimpleReference(expression.object);
  12215. case "Identifier":
  12216. return true;
  12217. default:
  12218. return false;
  12219. }
  12220. }
  12221. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12222. if (this.match(19)) {
  12223. throw this.raise(Errors.PipelineBodyNoArrow, {
  12224. at: this.state.startLoc
  12225. });
  12226. }
  12227. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12228. this.raise(Errors.PipelineTopicUnused, {
  12229. at: startLoc
  12230. });
  12231. }
  12232. }
  12233. withTopicBindingContext(callback) {
  12234. const outerContextTopicState = this.state.topicContext;
  12235. this.state.topicContext = {
  12236. maxNumOfResolvableTopics: 1,
  12237. maxTopicIndex: null
  12238. };
  12239. try {
  12240. return callback();
  12241. } finally {
  12242. this.state.topicContext = outerContextTopicState;
  12243. }
  12244. }
  12245. withSmartMixTopicForbiddingContext(callback) {
  12246. if (this.hasPlugin(["pipelineOperator", {
  12247. proposal: "smart"
  12248. }])) {
  12249. const outerContextTopicState = this.state.topicContext;
  12250. this.state.topicContext = {
  12251. maxNumOfResolvableTopics: 0,
  12252. maxTopicIndex: null
  12253. };
  12254. try {
  12255. return callback();
  12256. } finally {
  12257. this.state.topicContext = outerContextTopicState;
  12258. }
  12259. } else {
  12260. return callback();
  12261. }
  12262. }
  12263. withSoloAwaitPermittingContext(callback) {
  12264. const outerContextSoloAwaitState = this.state.soloAwait;
  12265. this.state.soloAwait = true;
  12266. try {
  12267. return callback();
  12268. } finally {
  12269. this.state.soloAwait = outerContextSoloAwaitState;
  12270. }
  12271. }
  12272. allowInAnd(callback) {
  12273. const flags = this.prodParam.currentFlags();
  12274. const prodParamToSet = 8 & ~flags;
  12275. if (prodParamToSet) {
  12276. this.prodParam.enter(flags | 8);
  12277. try {
  12278. return callback();
  12279. } finally {
  12280. this.prodParam.exit();
  12281. }
  12282. }
  12283. return callback();
  12284. }
  12285. disallowInAnd(callback) {
  12286. const flags = this.prodParam.currentFlags();
  12287. const prodParamToClear = 8 & flags;
  12288. if (prodParamToClear) {
  12289. this.prodParam.enter(flags & ~8);
  12290. try {
  12291. return callback();
  12292. } finally {
  12293. this.prodParam.exit();
  12294. }
  12295. }
  12296. return callback();
  12297. }
  12298. registerTopicReference() {
  12299. this.state.topicContext.maxTopicIndex = 0;
  12300. }
  12301. topicReferenceIsAllowedInCurrentContext() {
  12302. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12303. }
  12304. topicReferenceWasUsedInCurrentContext() {
  12305. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12306. }
  12307. parseFSharpPipelineBody(prec) {
  12308. const startLoc = this.state.startLoc;
  12309. this.state.potentialArrowAt = this.state.start;
  12310. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12311. this.state.inFSharpPipelineDirectBody = true;
  12312. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12313. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12314. return ret;
  12315. }
  12316. parseModuleExpression() {
  12317. this.expectPlugin("moduleBlocks");
  12318. const node = this.startNode();
  12319. this.next();
  12320. if (!this.match(5)) {
  12321. this.unexpected(null, 5);
  12322. }
  12323. const program = this.startNodeAt(this.state.endLoc);
  12324. this.next();
  12325. const revertScopes = this.initializeScopes(true);
  12326. this.enterInitialScopes();
  12327. try {
  12328. node.body = this.parseProgram(program, 8, "module");
  12329. } finally {
  12330. revertScopes();
  12331. }
  12332. return this.finishNode(node, "ModuleExpression");
  12333. }
  12334. parsePropertyNamePrefixOperator(prop) {}
  12335. }
  12336. const loopLabel = {
  12337. kind: "loop"
  12338. },
  12339. switchLabel = {
  12340. kind: "switch"
  12341. };
  12342. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12343. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12344. function babel7CompatTokens(tokens, input) {
  12345. for (let i = 0; i < tokens.length; i++) {
  12346. const token = tokens[i];
  12347. const {
  12348. type
  12349. } = token;
  12350. if (typeof type === "number") {
  12351. {
  12352. if (type === 138) {
  12353. const {
  12354. loc,
  12355. start,
  12356. value,
  12357. end
  12358. } = token;
  12359. const hashEndPos = start + 1;
  12360. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12361. tokens.splice(i, 1, new Token({
  12362. type: getExportedToken(27),
  12363. value: "#",
  12364. start: start,
  12365. end: hashEndPos,
  12366. startLoc: loc.start,
  12367. endLoc: hashEndLoc
  12368. }), new Token({
  12369. type: getExportedToken(132),
  12370. value: value,
  12371. start: hashEndPos,
  12372. end: end,
  12373. startLoc: hashEndLoc,
  12374. endLoc: loc.end
  12375. }));
  12376. i++;
  12377. continue;
  12378. }
  12379. if (tokenIsTemplate(type)) {
  12380. const {
  12381. loc,
  12382. start,
  12383. value,
  12384. end
  12385. } = token;
  12386. const backquoteEnd = start + 1;
  12387. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12388. let startToken;
  12389. if (input.charCodeAt(start) === 96) {
  12390. startToken = new Token({
  12391. type: getExportedToken(22),
  12392. value: "`",
  12393. start: start,
  12394. end: backquoteEnd,
  12395. startLoc: loc.start,
  12396. endLoc: backquoteEndLoc
  12397. });
  12398. } else {
  12399. startToken = new Token({
  12400. type: getExportedToken(8),
  12401. value: "}",
  12402. start: start,
  12403. end: backquoteEnd,
  12404. startLoc: loc.start,
  12405. endLoc: backquoteEndLoc
  12406. });
  12407. }
  12408. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12409. if (type === 24) {
  12410. templateElementEnd = end - 1;
  12411. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12412. templateValue = value === null ? null : value.slice(1, -1);
  12413. endToken = new Token({
  12414. type: getExportedToken(22),
  12415. value: "`",
  12416. start: templateElementEnd,
  12417. end: end,
  12418. startLoc: templateElementEndLoc,
  12419. endLoc: loc.end
  12420. });
  12421. } else {
  12422. templateElementEnd = end - 2;
  12423. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12424. templateValue = value === null ? null : value.slice(1, -2);
  12425. endToken = new Token({
  12426. type: getExportedToken(23),
  12427. value: "${",
  12428. start: templateElementEnd,
  12429. end: end,
  12430. startLoc: templateElementEndLoc,
  12431. endLoc: loc.end
  12432. });
  12433. }
  12434. tokens.splice(i, 1, startToken, new Token({
  12435. type: getExportedToken(20),
  12436. value: templateValue,
  12437. start: backquoteEnd,
  12438. end: templateElementEnd,
  12439. startLoc: backquoteEndLoc,
  12440. endLoc: templateElementEndLoc
  12441. }), endToken);
  12442. i += 2;
  12443. continue;
  12444. }
  12445. }
  12446. token.type = getExportedToken(type);
  12447. }
  12448. }
  12449. return tokens;
  12450. }
  12451. class StatementParser extends ExpressionParser {
  12452. parseTopLevel(file, program) {
  12453. file.program = this.parseProgram(program);
  12454. file.comments = this.state.comments;
  12455. if (this.options.tokens) {
  12456. file.tokens = babel7CompatTokens(this.tokens, this.input);
  12457. }
  12458. return this.finishNode(file, "File");
  12459. }
  12460. parseProgram(program, end = 139, sourceType = this.options.sourceType) {
  12461. program.sourceType = sourceType;
  12462. program.interpreter = this.parseInterpreterDirective();
  12463. this.parseBlockBody(program, true, true, end);
  12464. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  12465. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12466. this.raise(Errors.ModuleExportUndefined, {
  12467. at,
  12468. localName
  12469. });
  12470. }
  12471. }
  12472. let finishedProgram;
  12473. if (end === 139) {
  12474. finishedProgram = this.finishNode(program, "Program");
  12475. } else {
  12476. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12477. }
  12478. return finishedProgram;
  12479. }
  12480. stmtToDirective(stmt) {
  12481. const directive = stmt;
  12482. directive.type = "Directive";
  12483. directive.value = directive.expression;
  12484. delete directive.expression;
  12485. const directiveLiteral = directive.value;
  12486. const expressionValue = directiveLiteral.value;
  12487. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  12488. const val = directiveLiteral.value = raw.slice(1, -1);
  12489. this.addExtra(directiveLiteral, "raw", raw);
  12490. this.addExtra(directiveLiteral, "rawValue", val);
  12491. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12492. directiveLiteral.type = "DirectiveLiteral";
  12493. return directive;
  12494. }
  12495. parseInterpreterDirective() {
  12496. if (!this.match(28)) {
  12497. return null;
  12498. }
  12499. const node = this.startNode();
  12500. node.value = this.state.value;
  12501. this.next();
  12502. return this.finishNode(node, "InterpreterDirective");
  12503. }
  12504. isLet() {
  12505. if (!this.isContextual(100)) {
  12506. return false;
  12507. }
  12508. return this.hasFollowingBindingAtom();
  12509. }
  12510. chStartsBindingIdentifier(ch, pos) {
  12511. if (isIdentifierStart(ch)) {
  12512. keywordRelationalOperator.lastIndex = pos;
  12513. if (keywordRelationalOperator.test(this.input)) {
  12514. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12515. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12516. return false;
  12517. }
  12518. }
  12519. return true;
  12520. } else if (ch === 92) {
  12521. return true;
  12522. } else {
  12523. return false;
  12524. }
  12525. }
  12526. chStartsBindingPattern(ch) {
  12527. return ch === 91 || ch === 123;
  12528. }
  12529. hasFollowingBindingAtom() {
  12530. const next = this.nextTokenStart();
  12531. const nextCh = this.codePointAtPos(next);
  12532. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12533. }
  12534. hasInLineFollowingBindingIdentifier() {
  12535. const next = this.nextTokenInLineStart();
  12536. const nextCh = this.codePointAtPos(next);
  12537. return this.chStartsBindingIdentifier(nextCh, next);
  12538. }
  12539. startsUsingForOf() {
  12540. const {
  12541. type,
  12542. containsEsc
  12543. } = this.lookahead();
  12544. if (type === 102 && !containsEsc) {
  12545. return false;
  12546. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12547. this.expectPlugin("explicitResourceManagement");
  12548. return true;
  12549. }
  12550. }
  12551. startsAwaitUsing() {
  12552. let next = this.nextTokenInLineStart();
  12553. if (this.isUnparsedContextual(next, "using")) {
  12554. next = this.nextTokenInLineStartSince(next + 5);
  12555. const nextCh = this.codePointAtPos(next);
  12556. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12557. this.expectPlugin("explicitResourceManagement");
  12558. return true;
  12559. }
  12560. }
  12561. return false;
  12562. }
  12563. parseModuleItem() {
  12564. return this.parseStatementLike(1 | 2 | 4 | 8);
  12565. }
  12566. parseStatementListItem() {
  12567. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12568. }
  12569. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12570. let flags = 0;
  12571. if (this.options.annexB && !this.state.strict) {
  12572. flags |= 4;
  12573. if (allowLabeledFunction) {
  12574. flags |= 8;
  12575. }
  12576. }
  12577. return this.parseStatementLike(flags);
  12578. }
  12579. parseStatement() {
  12580. return this.parseStatementLike(0);
  12581. }
  12582. parseStatementLike(flags) {
  12583. let decorators = null;
  12584. if (this.match(26)) {
  12585. decorators = this.parseDecorators(true);
  12586. }
  12587. return this.parseStatementContent(flags, decorators);
  12588. }
  12589. parseStatementContent(flags, decorators) {
  12590. const starttype = this.state.type;
  12591. const node = this.startNode();
  12592. const allowDeclaration = !!(flags & 2);
  12593. const allowFunctionDeclaration = !!(flags & 4);
  12594. const topLevel = flags & 1;
  12595. switch (starttype) {
  12596. case 60:
  12597. return this.parseBreakContinueStatement(node, true);
  12598. case 63:
  12599. return this.parseBreakContinueStatement(node, false);
  12600. case 64:
  12601. return this.parseDebuggerStatement(node);
  12602. case 90:
  12603. return this.parseDoWhileStatement(node);
  12604. case 91:
  12605. return this.parseForStatement(node);
  12606. case 68:
  12607. if (this.lookaheadCharCode() === 46) break;
  12608. if (!allowFunctionDeclaration) {
  12609. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, {
  12610. at: this.state.startLoc
  12611. });
  12612. }
  12613. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12614. case 80:
  12615. if (!allowDeclaration) this.unexpected();
  12616. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12617. case 69:
  12618. return this.parseIfStatement(node);
  12619. case 70:
  12620. return this.parseReturnStatement(node);
  12621. case 71:
  12622. return this.parseSwitchStatement(node);
  12623. case 72:
  12624. return this.parseThrowStatement(node);
  12625. case 73:
  12626. return this.parseTryStatement(node);
  12627. case 96:
  12628. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  12629. if (!this.isAwaitAllowed()) {
  12630. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  12631. at: node
  12632. });
  12633. } else if (!allowDeclaration) {
  12634. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12635. at: node
  12636. });
  12637. }
  12638. this.next();
  12639. return this.parseVarStatement(node, "await using");
  12640. }
  12641. break;
  12642. case 107:
  12643. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifier()) {
  12644. break;
  12645. }
  12646. this.expectPlugin("explicitResourceManagement");
  12647. if (!this.scope.inModule && this.scope.inTopLevel) {
  12648. this.raise(Errors.UnexpectedUsingDeclaration, {
  12649. at: this.state.startLoc
  12650. });
  12651. } else if (!allowDeclaration) {
  12652. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12653. at: this.state.startLoc
  12654. });
  12655. }
  12656. return this.parseVarStatement(node, "using");
  12657. case 100:
  12658. {
  12659. if (this.state.containsEsc) {
  12660. break;
  12661. }
  12662. const next = this.nextTokenStart();
  12663. const nextCh = this.codePointAtPos(next);
  12664. if (nextCh !== 91) {
  12665. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12666. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12667. break;
  12668. }
  12669. }
  12670. }
  12671. case 75:
  12672. {
  12673. if (!allowDeclaration) {
  12674. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12675. at: this.state.startLoc
  12676. });
  12677. }
  12678. }
  12679. case 74:
  12680. {
  12681. const kind = this.state.value;
  12682. return this.parseVarStatement(node, kind);
  12683. }
  12684. case 92:
  12685. return this.parseWhileStatement(node);
  12686. case 76:
  12687. return this.parseWithStatement(node);
  12688. case 5:
  12689. return this.parseBlock();
  12690. case 13:
  12691. return this.parseEmptyStatement(node);
  12692. case 83:
  12693. {
  12694. const nextTokenCharCode = this.lookaheadCharCode();
  12695. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12696. break;
  12697. }
  12698. }
  12699. case 82:
  12700. {
  12701. if (!this.options.allowImportExportEverywhere && !topLevel) {
  12702. this.raise(Errors.UnexpectedImportExport, {
  12703. at: this.state.startLoc
  12704. });
  12705. }
  12706. this.next();
  12707. let result;
  12708. if (starttype === 83) {
  12709. result = this.parseImport(node);
  12710. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12711. this.sawUnambiguousESM = true;
  12712. }
  12713. } else {
  12714. result = this.parseExport(node, decorators);
  12715. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12716. this.sawUnambiguousESM = true;
  12717. }
  12718. }
  12719. this.assertModuleNodeAllowed(result);
  12720. return result;
  12721. }
  12722. default:
  12723. {
  12724. if (this.isAsyncFunction()) {
  12725. if (!allowDeclaration) {
  12726. this.raise(Errors.AsyncFunctionInSingleStatementContext, {
  12727. at: this.state.startLoc
  12728. });
  12729. }
  12730. this.next();
  12731. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12732. }
  12733. }
  12734. }
  12735. const maybeName = this.state.value;
  12736. const expr = this.parseExpression();
  12737. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  12738. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12739. } else {
  12740. return this.parseExpressionStatement(node, expr, decorators);
  12741. }
  12742. }
  12743. assertModuleNodeAllowed(node) {
  12744. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  12745. this.raise(Errors.ImportOutsideModule, {
  12746. at: node
  12747. });
  12748. }
  12749. }
  12750. decoratorsEnabledBeforeExport() {
  12751. if (this.hasPlugin("decorators-legacy")) return true;
  12752. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12753. }
  12754. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12755. if (maybeDecorators) {
  12756. if (classNode.decorators && classNode.decorators.length > 0) {
  12757. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12758. this.raise(Errors.DecoratorsBeforeAfterExport, {
  12759. at: classNode.decorators[0]
  12760. });
  12761. }
  12762. classNode.decorators.unshift(...maybeDecorators);
  12763. } else {
  12764. classNode.decorators = maybeDecorators;
  12765. }
  12766. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12767. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12768. }
  12769. return classNode;
  12770. }
  12771. canHaveLeadingDecorator() {
  12772. return this.match(80);
  12773. }
  12774. parseDecorators(allowExport) {
  12775. const decorators = [];
  12776. do {
  12777. decorators.push(this.parseDecorator());
  12778. } while (this.match(26));
  12779. if (this.match(82)) {
  12780. if (!allowExport) {
  12781. this.unexpected();
  12782. }
  12783. if (!this.decoratorsEnabledBeforeExport()) {
  12784. this.raise(Errors.DecoratorExportClass, {
  12785. at: this.state.startLoc
  12786. });
  12787. }
  12788. } else if (!this.canHaveLeadingDecorator()) {
  12789. throw this.raise(Errors.UnexpectedLeadingDecorator, {
  12790. at: this.state.startLoc
  12791. });
  12792. }
  12793. return decorators;
  12794. }
  12795. parseDecorator() {
  12796. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12797. const node = this.startNode();
  12798. this.next();
  12799. if (this.hasPlugin("decorators")) {
  12800. const startLoc = this.state.startLoc;
  12801. let expr;
  12802. if (this.match(10)) {
  12803. const startLoc = this.state.startLoc;
  12804. this.next();
  12805. expr = this.parseExpression();
  12806. this.expect(11);
  12807. expr = this.wrapParenthesis(startLoc, expr);
  12808. const paramsStartLoc = this.state.startLoc;
  12809. node.expression = this.parseMaybeDecoratorArguments(expr);
  12810. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12811. this.raise(Errors.DecoratorArgumentsOutsideParentheses, {
  12812. at: paramsStartLoc
  12813. });
  12814. }
  12815. } else {
  12816. expr = this.parseIdentifier(false);
  12817. while (this.eat(16)) {
  12818. const node = this.startNodeAt(startLoc);
  12819. node.object = expr;
  12820. if (this.match(138)) {
  12821. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12822. node.property = this.parsePrivateName();
  12823. } else {
  12824. node.property = this.parseIdentifier(true);
  12825. }
  12826. node.computed = false;
  12827. expr = this.finishNode(node, "MemberExpression");
  12828. }
  12829. node.expression = this.parseMaybeDecoratorArguments(expr);
  12830. }
  12831. } else {
  12832. node.expression = this.parseExprSubscripts();
  12833. }
  12834. return this.finishNode(node, "Decorator");
  12835. }
  12836. parseMaybeDecoratorArguments(expr) {
  12837. if (this.eat(10)) {
  12838. const node = this.startNodeAtNode(expr);
  12839. node.callee = expr;
  12840. node.arguments = this.parseCallExpressionArguments(11, false);
  12841. this.toReferencedList(node.arguments);
  12842. return this.finishNode(node, "CallExpression");
  12843. }
  12844. return expr;
  12845. }
  12846. parseBreakContinueStatement(node, isBreak) {
  12847. this.next();
  12848. if (this.isLineTerminator()) {
  12849. node.label = null;
  12850. } else {
  12851. node.label = this.parseIdentifier();
  12852. this.semicolon();
  12853. }
  12854. this.verifyBreakContinue(node, isBreak);
  12855. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12856. }
  12857. verifyBreakContinue(node, isBreak) {
  12858. let i;
  12859. for (i = 0; i < this.state.labels.length; ++i) {
  12860. const lab = this.state.labels[i];
  12861. if (node.label == null || lab.name === node.label.name) {
  12862. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  12863. if (node.label && isBreak) break;
  12864. }
  12865. }
  12866. if (i === this.state.labels.length) {
  12867. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12868. this.raise(Errors.IllegalBreakContinue, {
  12869. at: node,
  12870. type
  12871. });
  12872. }
  12873. }
  12874. parseDebuggerStatement(node) {
  12875. this.next();
  12876. this.semicolon();
  12877. return this.finishNode(node, "DebuggerStatement");
  12878. }
  12879. parseHeaderExpression() {
  12880. this.expect(10);
  12881. const val = this.parseExpression();
  12882. this.expect(11);
  12883. return val;
  12884. }
  12885. parseDoWhileStatement(node) {
  12886. this.next();
  12887. this.state.labels.push(loopLabel);
  12888. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12889. this.state.labels.pop();
  12890. this.expect(92);
  12891. node.test = this.parseHeaderExpression();
  12892. this.eat(13);
  12893. return this.finishNode(node, "DoWhileStatement");
  12894. }
  12895. parseForStatement(node) {
  12896. this.next();
  12897. this.state.labels.push(loopLabel);
  12898. let awaitAt = null;
  12899. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  12900. awaitAt = this.state.lastTokStartLoc;
  12901. }
  12902. this.scope.enter(0);
  12903. this.expect(10);
  12904. if (this.match(13)) {
  12905. if (awaitAt !== null) {
  12906. this.unexpected(awaitAt);
  12907. }
  12908. return this.parseFor(node, null);
  12909. }
  12910. const startsWithLet = this.isContextual(100);
  12911. {
  12912. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  12913. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(107) && this.startsUsingForOf();
  12914. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  12915. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12916. const initNode = this.startNode();
  12917. let kind;
  12918. if (startsWithAwaitUsing) {
  12919. kind = "await using";
  12920. if (!this.isAwaitAllowed()) {
  12921. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  12922. at: this.state.startLoc
  12923. });
  12924. }
  12925. this.next();
  12926. } else {
  12927. kind = this.state.value;
  12928. }
  12929. this.next();
  12930. this.parseVar(initNode, true, kind);
  12931. const init = this.finishNode(initNode, "VariableDeclaration");
  12932. const isForIn = this.match(58);
  12933. if (isForIn && starsWithUsingDeclaration) {
  12934. this.raise(Errors.ForInUsing, {
  12935. at: init
  12936. });
  12937. }
  12938. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  12939. return this.parseForIn(node, init, awaitAt);
  12940. }
  12941. if (awaitAt !== null) {
  12942. this.unexpected(awaitAt);
  12943. }
  12944. return this.parseFor(node, init);
  12945. }
  12946. }
  12947. const startsWithAsync = this.isContextual(95);
  12948. const refExpressionErrors = new ExpressionErrors();
  12949. const init = this.parseExpression(true, refExpressionErrors);
  12950. const isForOf = this.isContextual(102);
  12951. if (isForOf) {
  12952. if (startsWithLet) {
  12953. this.raise(Errors.ForOfLet, {
  12954. at: init
  12955. });
  12956. }
  12957. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12958. this.raise(Errors.ForOfAsync, {
  12959. at: init
  12960. });
  12961. }
  12962. }
  12963. if (isForOf || this.match(58)) {
  12964. this.checkDestructuringPrivate(refExpressionErrors);
  12965. this.toAssignable(init, true);
  12966. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12967. this.checkLVal(init, {
  12968. in: {
  12969. type
  12970. }
  12971. });
  12972. return this.parseForIn(node, init, awaitAt);
  12973. } else {
  12974. this.checkExpressionErrors(refExpressionErrors, true);
  12975. }
  12976. if (awaitAt !== null) {
  12977. this.unexpected(awaitAt);
  12978. }
  12979. return this.parseFor(node, init);
  12980. }
  12981. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12982. this.next();
  12983. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  12984. }
  12985. parseIfStatement(node) {
  12986. this.next();
  12987. node.test = this.parseHeaderExpression();
  12988. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12989. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  12990. return this.finishNode(node, "IfStatement");
  12991. }
  12992. parseReturnStatement(node) {
  12993. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  12994. this.raise(Errors.IllegalReturn, {
  12995. at: this.state.startLoc
  12996. });
  12997. }
  12998. this.next();
  12999. if (this.isLineTerminator()) {
  13000. node.argument = null;
  13001. } else {
  13002. node.argument = this.parseExpression();
  13003. this.semicolon();
  13004. }
  13005. return this.finishNode(node, "ReturnStatement");
  13006. }
  13007. parseSwitchStatement(node) {
  13008. this.next();
  13009. node.discriminant = this.parseHeaderExpression();
  13010. const cases = node.cases = [];
  13011. this.expect(5);
  13012. this.state.labels.push(switchLabel);
  13013. this.scope.enter(0);
  13014. let cur;
  13015. for (let sawDefault; !this.match(8);) {
  13016. if (this.match(61) || this.match(65)) {
  13017. const isCase = this.match(61);
  13018. if (cur) this.finishNode(cur, "SwitchCase");
  13019. cases.push(cur = this.startNode());
  13020. cur.consequent = [];
  13021. this.next();
  13022. if (isCase) {
  13023. cur.test = this.parseExpression();
  13024. } else {
  13025. if (sawDefault) {
  13026. this.raise(Errors.MultipleDefaultsInSwitch, {
  13027. at: this.state.lastTokStartLoc
  13028. });
  13029. }
  13030. sawDefault = true;
  13031. cur.test = null;
  13032. }
  13033. this.expect(14);
  13034. } else {
  13035. if (cur) {
  13036. cur.consequent.push(this.parseStatementListItem());
  13037. } else {
  13038. this.unexpected();
  13039. }
  13040. }
  13041. }
  13042. this.scope.exit();
  13043. if (cur) this.finishNode(cur, "SwitchCase");
  13044. this.next();
  13045. this.state.labels.pop();
  13046. return this.finishNode(node, "SwitchStatement");
  13047. }
  13048. parseThrowStatement(node) {
  13049. this.next();
  13050. if (this.hasPrecedingLineBreak()) {
  13051. this.raise(Errors.NewlineAfterThrow, {
  13052. at: this.state.lastTokEndLoc
  13053. });
  13054. }
  13055. node.argument = this.parseExpression();
  13056. this.semicolon();
  13057. return this.finishNode(node, "ThrowStatement");
  13058. }
  13059. parseCatchClauseParam() {
  13060. const param = this.parseBindingAtom();
  13061. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13062. this.checkLVal(param, {
  13063. in: {
  13064. type: "CatchClause"
  13065. },
  13066. binding: 9
  13067. });
  13068. return param;
  13069. }
  13070. parseTryStatement(node) {
  13071. this.next();
  13072. node.block = this.parseBlock();
  13073. node.handler = null;
  13074. if (this.match(62)) {
  13075. const clause = this.startNode();
  13076. this.next();
  13077. if (this.match(10)) {
  13078. this.expect(10);
  13079. clause.param = this.parseCatchClauseParam();
  13080. this.expect(11);
  13081. } else {
  13082. clause.param = null;
  13083. this.scope.enter(0);
  13084. }
  13085. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13086. this.scope.exit();
  13087. node.handler = this.finishNode(clause, "CatchClause");
  13088. }
  13089. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13090. if (!node.handler && !node.finalizer) {
  13091. this.raise(Errors.NoCatchOrFinally, {
  13092. at: node
  13093. });
  13094. }
  13095. return this.finishNode(node, "TryStatement");
  13096. }
  13097. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13098. this.next();
  13099. this.parseVar(node, false, kind, allowMissingInitializer);
  13100. this.semicolon();
  13101. return this.finishNode(node, "VariableDeclaration");
  13102. }
  13103. parseWhileStatement(node) {
  13104. this.next();
  13105. node.test = this.parseHeaderExpression();
  13106. this.state.labels.push(loopLabel);
  13107. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13108. this.state.labels.pop();
  13109. return this.finishNode(node, "WhileStatement");
  13110. }
  13111. parseWithStatement(node) {
  13112. if (this.state.strict) {
  13113. this.raise(Errors.StrictWith, {
  13114. at: this.state.startLoc
  13115. });
  13116. }
  13117. this.next();
  13118. node.object = this.parseHeaderExpression();
  13119. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13120. return this.finishNode(node, "WithStatement");
  13121. }
  13122. parseEmptyStatement(node) {
  13123. this.next();
  13124. return this.finishNode(node, "EmptyStatement");
  13125. }
  13126. parseLabeledStatement(node, maybeName, expr, flags) {
  13127. for (const label of this.state.labels) {
  13128. if (label.name === maybeName) {
  13129. this.raise(Errors.LabelRedeclaration, {
  13130. at: expr,
  13131. labelName: maybeName
  13132. });
  13133. }
  13134. }
  13135. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
  13136. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13137. const label = this.state.labels[i];
  13138. if (label.statementStart === node.start) {
  13139. label.statementStart = this.state.start;
  13140. label.kind = kind;
  13141. } else {
  13142. break;
  13143. }
  13144. }
  13145. this.state.labels.push({
  13146. name: maybeName,
  13147. kind: kind,
  13148. statementStart: this.state.start
  13149. });
  13150. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13151. this.state.labels.pop();
  13152. node.label = expr;
  13153. return this.finishNode(node, "LabeledStatement");
  13154. }
  13155. parseExpressionStatement(node, expr, decorators) {
  13156. node.expression = expr;
  13157. this.semicolon();
  13158. return this.finishNode(node, "ExpressionStatement");
  13159. }
  13160. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13161. const node = this.startNode();
  13162. if (allowDirectives) {
  13163. this.state.strictErrors.clear();
  13164. }
  13165. this.expect(5);
  13166. if (createNewLexicalScope) {
  13167. this.scope.enter(0);
  13168. }
  13169. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13170. if (createNewLexicalScope) {
  13171. this.scope.exit();
  13172. }
  13173. return this.finishNode(node, "BlockStatement");
  13174. }
  13175. isValidDirective(stmt) {
  13176. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13177. }
  13178. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13179. const body = node.body = [];
  13180. const directives = node.directives = [];
  13181. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13182. }
  13183. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13184. const oldStrict = this.state.strict;
  13185. let hasStrictModeDirective = false;
  13186. let parsedNonDirective = false;
  13187. while (!this.match(end)) {
  13188. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13189. if (directives && !parsedNonDirective) {
  13190. if (this.isValidDirective(stmt)) {
  13191. const directive = this.stmtToDirective(stmt);
  13192. directives.push(directive);
  13193. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13194. hasStrictModeDirective = true;
  13195. this.setStrict(true);
  13196. }
  13197. continue;
  13198. }
  13199. parsedNonDirective = true;
  13200. this.state.strictErrors.clear();
  13201. }
  13202. body.push(stmt);
  13203. }
  13204. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  13205. if (!oldStrict) {
  13206. this.setStrict(false);
  13207. }
  13208. this.next();
  13209. }
  13210. parseFor(node, init) {
  13211. node.init = init;
  13212. this.semicolon(false);
  13213. node.test = this.match(13) ? null : this.parseExpression();
  13214. this.semicolon(false);
  13215. node.update = this.match(11) ? null : this.parseExpression();
  13216. this.expect(11);
  13217. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13218. this.scope.exit();
  13219. this.state.labels.pop();
  13220. return this.finishNode(node, "ForStatement");
  13221. }
  13222. parseForIn(node, init, awaitAt) {
  13223. const isForIn = this.match(58);
  13224. this.next();
  13225. if (isForIn) {
  13226. if (awaitAt !== null) this.unexpected(awaitAt);
  13227. } else {
  13228. node.await = awaitAt !== null;
  13229. }
  13230. 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")) {
  13231. this.raise(Errors.ForInOfLoopInitializer, {
  13232. at: init,
  13233. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13234. });
  13235. }
  13236. if (init.type === "AssignmentPattern") {
  13237. this.raise(Errors.InvalidLhs, {
  13238. at: init,
  13239. ancestor: {
  13240. type: "ForStatement"
  13241. }
  13242. });
  13243. }
  13244. node.left = init;
  13245. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13246. this.expect(11);
  13247. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13248. this.scope.exit();
  13249. this.state.labels.pop();
  13250. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13251. }
  13252. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13253. const declarations = node.declarations = [];
  13254. node.kind = kind;
  13255. for (;;) {
  13256. const decl = this.startNode();
  13257. this.parseVarId(decl, kind);
  13258. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13259. if (decl.init === null && !allowMissingInitializer) {
  13260. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13261. this.raise(Errors.DeclarationMissingInitializer, {
  13262. at: this.state.lastTokEndLoc,
  13263. kind: "destructuring"
  13264. });
  13265. } else if (kind === "const" && !(this.match(58) || this.isContextual(102))) {
  13266. this.raise(Errors.DeclarationMissingInitializer, {
  13267. at: this.state.lastTokEndLoc,
  13268. kind: "const"
  13269. });
  13270. }
  13271. }
  13272. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13273. if (!this.eat(12)) break;
  13274. }
  13275. return node;
  13276. }
  13277. parseVarId(decl, kind) {
  13278. const id = this.parseBindingAtom();
  13279. this.checkLVal(id, {
  13280. in: {
  13281. type: "VariableDeclarator"
  13282. },
  13283. binding: kind === "var" ? 5 : 8201
  13284. });
  13285. decl.id = id;
  13286. }
  13287. parseAsyncFunctionExpression(node) {
  13288. return this.parseFunction(node, 8);
  13289. }
  13290. parseFunction(node, flags = 0) {
  13291. const hangingDeclaration = flags & 2;
  13292. const isDeclaration = !!(flags & 1);
  13293. const requireId = isDeclaration && !(flags & 4);
  13294. const isAsync = !!(flags & 8);
  13295. this.initFunction(node, isAsync);
  13296. if (this.match(55)) {
  13297. if (hangingDeclaration) {
  13298. this.raise(Errors.GeneratorInSingleStatementContext, {
  13299. at: this.state.startLoc
  13300. });
  13301. }
  13302. this.next();
  13303. node.generator = true;
  13304. }
  13305. if (isDeclaration) {
  13306. node.id = this.parseFunctionId(requireId);
  13307. }
  13308. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13309. this.state.maybeInArrowParameters = false;
  13310. this.scope.enter(2);
  13311. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13312. if (!isDeclaration) {
  13313. node.id = this.parseFunctionId();
  13314. }
  13315. this.parseFunctionParams(node, false);
  13316. this.withSmartMixTopicForbiddingContext(() => {
  13317. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13318. });
  13319. this.prodParam.exit();
  13320. this.scope.exit();
  13321. if (isDeclaration && !hangingDeclaration) {
  13322. this.registerFunctionStatementId(node);
  13323. }
  13324. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13325. return node;
  13326. }
  13327. parseFunctionId(requireId) {
  13328. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13329. }
  13330. parseFunctionParams(node, isConstructor) {
  13331. this.expect(10);
  13332. this.expressionScope.enter(newParameterDeclarationScope());
  13333. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13334. this.expressionScope.exit();
  13335. }
  13336. registerFunctionStatementId(node) {
  13337. if (!node.id) return;
  13338. 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);
  13339. }
  13340. parseClass(node, isStatement, optionalId) {
  13341. this.next();
  13342. const oldStrict = this.state.strict;
  13343. this.state.strict = true;
  13344. this.parseClassId(node, isStatement, optionalId);
  13345. this.parseClassSuper(node);
  13346. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13347. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13348. }
  13349. isClassProperty() {
  13350. return this.match(29) || this.match(13) || this.match(8);
  13351. }
  13352. isClassMethod() {
  13353. return this.match(10);
  13354. }
  13355. isNonstaticConstructor(method) {
  13356. return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
  13357. }
  13358. parseClassBody(hadSuperClass, oldStrict) {
  13359. this.classScope.enter();
  13360. const state = {
  13361. hadConstructor: false,
  13362. hadSuperClass
  13363. };
  13364. let decorators = [];
  13365. const classBody = this.startNode();
  13366. classBody.body = [];
  13367. this.expect(5);
  13368. this.withSmartMixTopicForbiddingContext(() => {
  13369. while (!this.match(8)) {
  13370. if (this.eat(13)) {
  13371. if (decorators.length > 0) {
  13372. throw this.raise(Errors.DecoratorSemicolon, {
  13373. at: this.state.lastTokEndLoc
  13374. });
  13375. }
  13376. continue;
  13377. }
  13378. if (this.match(26)) {
  13379. decorators.push(this.parseDecorator());
  13380. continue;
  13381. }
  13382. const member = this.startNode();
  13383. if (decorators.length) {
  13384. member.decorators = decorators;
  13385. this.resetStartLocationFromNode(member, decorators[0]);
  13386. decorators = [];
  13387. }
  13388. this.parseClassMember(classBody, member, state);
  13389. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13390. this.raise(Errors.DecoratorConstructor, {
  13391. at: member
  13392. });
  13393. }
  13394. }
  13395. });
  13396. this.state.strict = oldStrict;
  13397. this.next();
  13398. if (decorators.length) {
  13399. throw this.raise(Errors.TrailingDecorator, {
  13400. at: this.state.startLoc
  13401. });
  13402. }
  13403. this.classScope.exit();
  13404. return this.finishNode(classBody, "ClassBody");
  13405. }
  13406. parseClassMemberFromModifier(classBody, member) {
  13407. const key = this.parseIdentifier(true);
  13408. if (this.isClassMethod()) {
  13409. const method = member;
  13410. method.kind = "method";
  13411. method.computed = false;
  13412. method.key = key;
  13413. method.static = false;
  13414. this.pushClassMethod(classBody, method, false, false, false, false);
  13415. return true;
  13416. } else if (this.isClassProperty()) {
  13417. const prop = member;
  13418. prop.computed = false;
  13419. prop.key = key;
  13420. prop.static = false;
  13421. classBody.body.push(this.parseClassProperty(prop));
  13422. return true;
  13423. }
  13424. this.resetPreviousNodeTrailingComments(key);
  13425. return false;
  13426. }
  13427. parseClassMember(classBody, member, state) {
  13428. const isStatic = this.isContextual(106);
  13429. if (isStatic) {
  13430. if (this.parseClassMemberFromModifier(classBody, member)) {
  13431. return;
  13432. }
  13433. if (this.eat(5)) {
  13434. this.parseClassStaticBlock(classBody, member);
  13435. return;
  13436. }
  13437. }
  13438. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13439. }
  13440. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13441. const publicMethod = member;
  13442. const privateMethod = member;
  13443. const publicProp = member;
  13444. const privateProp = member;
  13445. const accessorProp = member;
  13446. const method = publicMethod;
  13447. const publicMember = publicMethod;
  13448. member.static = isStatic;
  13449. this.parsePropertyNamePrefixOperator(member);
  13450. if (this.eat(55)) {
  13451. method.kind = "method";
  13452. const isPrivateName = this.match(138);
  13453. this.parseClassElementName(method);
  13454. if (isPrivateName) {
  13455. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13456. return;
  13457. }
  13458. if (this.isNonstaticConstructor(publicMethod)) {
  13459. this.raise(Errors.ConstructorIsGenerator, {
  13460. at: publicMethod.key
  13461. });
  13462. }
  13463. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13464. return;
  13465. }
  13466. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  13467. const isPrivate = this.match(138);
  13468. const key = this.parseClassElementName(member);
  13469. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13470. this.parsePostMemberNameModifiers(publicMember);
  13471. if (this.isClassMethod()) {
  13472. method.kind = "method";
  13473. if (isPrivate) {
  13474. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13475. return;
  13476. }
  13477. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13478. let allowsDirectSuper = false;
  13479. if (isConstructor) {
  13480. publicMethod.kind = "constructor";
  13481. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13482. this.raise(Errors.DuplicateConstructor, {
  13483. at: key
  13484. });
  13485. }
  13486. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13487. this.raise(Errors.OverrideOnConstructor, {
  13488. at: key
  13489. });
  13490. }
  13491. state.hadConstructor = true;
  13492. allowsDirectSuper = state.hadSuperClass;
  13493. }
  13494. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13495. } else if (this.isClassProperty()) {
  13496. if (isPrivate) {
  13497. this.pushClassPrivateProperty(classBody, privateProp);
  13498. } else {
  13499. this.pushClassProperty(classBody, publicProp);
  13500. }
  13501. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  13502. this.resetPreviousNodeTrailingComments(key);
  13503. const isGenerator = this.eat(55);
  13504. if (publicMember.optional) {
  13505. this.unexpected(maybeQuestionTokenStartLoc);
  13506. }
  13507. method.kind = "method";
  13508. const isPrivate = this.match(138);
  13509. this.parseClassElementName(method);
  13510. this.parsePostMemberNameModifiers(publicMember);
  13511. if (isPrivate) {
  13512. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13513. } else {
  13514. if (this.isNonstaticConstructor(publicMethod)) {
  13515. this.raise(Errors.ConstructorIsAsync, {
  13516. at: publicMethod.key
  13517. });
  13518. }
  13519. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13520. }
  13521. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
  13522. this.resetPreviousNodeTrailingComments(key);
  13523. method.kind = key.name;
  13524. const isPrivate = this.match(138);
  13525. this.parseClassElementName(publicMethod);
  13526. if (isPrivate) {
  13527. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13528. } else {
  13529. if (this.isNonstaticConstructor(publicMethod)) {
  13530. this.raise(Errors.ConstructorIsAccessor, {
  13531. at: publicMethod.key
  13532. });
  13533. }
  13534. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13535. }
  13536. this.checkGetterSetterParams(publicMethod);
  13537. } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
  13538. this.expectPlugin("decoratorAutoAccessors");
  13539. this.resetPreviousNodeTrailingComments(key);
  13540. const isPrivate = this.match(138);
  13541. this.parseClassElementName(publicProp);
  13542. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13543. } else if (this.isLineTerminator()) {
  13544. if (isPrivate) {
  13545. this.pushClassPrivateProperty(classBody, privateProp);
  13546. } else {
  13547. this.pushClassProperty(classBody, publicProp);
  13548. }
  13549. } else {
  13550. this.unexpected();
  13551. }
  13552. }
  13553. parseClassElementName(member) {
  13554. const {
  13555. type,
  13556. value
  13557. } = this.state;
  13558. if ((type === 132 || type === 133) && member.static && value === "prototype") {
  13559. this.raise(Errors.StaticPrototype, {
  13560. at: this.state.startLoc
  13561. });
  13562. }
  13563. if (type === 138) {
  13564. if (value === "constructor") {
  13565. this.raise(Errors.ConstructorClassPrivateField, {
  13566. at: this.state.startLoc
  13567. });
  13568. }
  13569. const key = this.parsePrivateName();
  13570. member.key = key;
  13571. return key;
  13572. }
  13573. return this.parsePropertyName(member);
  13574. }
  13575. parseClassStaticBlock(classBody, member) {
  13576. var _member$decorators;
  13577. this.scope.enter(64 | 128 | 16);
  13578. const oldLabels = this.state.labels;
  13579. this.state.labels = [];
  13580. this.prodParam.enter(0);
  13581. const body = member.body = [];
  13582. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13583. this.prodParam.exit();
  13584. this.scope.exit();
  13585. this.state.labels = oldLabels;
  13586. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13587. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13588. this.raise(Errors.DecoratorStaticBlock, {
  13589. at: member
  13590. });
  13591. }
  13592. }
  13593. pushClassProperty(classBody, prop) {
  13594. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  13595. this.raise(Errors.ConstructorClassField, {
  13596. at: prop.key
  13597. });
  13598. }
  13599. classBody.body.push(this.parseClassProperty(prop));
  13600. }
  13601. pushClassPrivateProperty(classBody, prop) {
  13602. const node = this.parseClassPrivateProperty(prop);
  13603. classBody.body.push(node);
  13604. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13605. }
  13606. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13607. if (!isPrivate && !prop.computed) {
  13608. const key = prop.key;
  13609. if (key.name === "constructor" || key.value === "constructor") {
  13610. this.raise(Errors.ConstructorClassField, {
  13611. at: key
  13612. });
  13613. }
  13614. }
  13615. const node = this.parseClassAccessorProperty(prop);
  13616. classBody.body.push(node);
  13617. if (isPrivate) {
  13618. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13619. }
  13620. }
  13621. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13622. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13623. }
  13624. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13625. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13626. classBody.body.push(node);
  13627. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13628. this.declareClassPrivateMethodInScope(node, kind);
  13629. }
  13630. declareClassPrivateMethodInScope(node, kind) {
  13631. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13632. }
  13633. parsePostMemberNameModifiers(methodOrProp) {}
  13634. parseClassPrivateProperty(node) {
  13635. this.parseInitializer(node);
  13636. this.semicolon();
  13637. return this.finishNode(node, "ClassPrivateProperty");
  13638. }
  13639. parseClassProperty(node) {
  13640. this.parseInitializer(node);
  13641. this.semicolon();
  13642. return this.finishNode(node, "ClassProperty");
  13643. }
  13644. parseClassAccessorProperty(node) {
  13645. this.parseInitializer(node);
  13646. this.semicolon();
  13647. return this.finishNode(node, "ClassAccessorProperty");
  13648. }
  13649. parseInitializer(node) {
  13650. this.scope.enter(64 | 16);
  13651. this.expressionScope.enter(newExpressionScope());
  13652. this.prodParam.enter(0);
  13653. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13654. this.expressionScope.exit();
  13655. this.prodParam.exit();
  13656. this.scope.exit();
  13657. }
  13658. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13659. if (tokenIsIdentifier(this.state.type)) {
  13660. node.id = this.parseIdentifier();
  13661. if (isStatement) {
  13662. this.declareNameFromIdentifier(node.id, bindingType);
  13663. }
  13664. } else {
  13665. if (optionalId || !isStatement) {
  13666. node.id = null;
  13667. } else {
  13668. throw this.raise(Errors.MissingClassName, {
  13669. at: this.state.startLoc
  13670. });
  13671. }
  13672. }
  13673. }
  13674. parseClassSuper(node) {
  13675. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13676. }
  13677. parseExport(node, decorators) {
  13678. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13679. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13680. const parseAfterDefault = !hasDefault || this.eat(12);
  13681. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13682. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13683. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13684. const isFromRequired = hasDefault || hasStar;
  13685. if (hasStar && !hasNamespace) {
  13686. if (hasDefault) this.unexpected();
  13687. if (decorators) {
  13688. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13689. at: node
  13690. });
  13691. }
  13692. this.parseExportFrom(node, true);
  13693. return this.finishNode(node, "ExportAllDeclaration");
  13694. }
  13695. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13696. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13697. this.unexpected(null, 5);
  13698. }
  13699. if (hasNamespace && parseAfterNamespace) {
  13700. this.unexpected(null, 98);
  13701. }
  13702. let hasDeclaration;
  13703. if (isFromRequired || hasSpecifiers) {
  13704. hasDeclaration = false;
  13705. if (decorators) {
  13706. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13707. at: node
  13708. });
  13709. }
  13710. this.parseExportFrom(node, isFromRequired);
  13711. } else {
  13712. hasDeclaration = this.maybeParseExportDeclaration(node);
  13713. }
  13714. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13715. var _node2$declaration;
  13716. const node2 = node;
  13717. this.checkExport(node2, true, false, !!node2.source);
  13718. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13719. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13720. } else if (decorators) {
  13721. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13722. at: node
  13723. });
  13724. }
  13725. return this.finishNode(node2, "ExportNamedDeclaration");
  13726. }
  13727. if (this.eat(65)) {
  13728. const node2 = node;
  13729. const decl = this.parseExportDefaultExpression();
  13730. node2.declaration = decl;
  13731. if (decl.type === "ClassDeclaration") {
  13732. this.maybeTakeDecorators(decorators, decl, node2);
  13733. } else if (decorators) {
  13734. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13735. at: node
  13736. });
  13737. }
  13738. this.checkExport(node2, true, true);
  13739. return this.finishNode(node2, "ExportDefaultDeclaration");
  13740. }
  13741. this.unexpected(null, 5);
  13742. }
  13743. eatExportStar(node) {
  13744. return this.eat(55);
  13745. }
  13746. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13747. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13748. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13749. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13750. const specifier = this.startNodeAtNode(id);
  13751. specifier.exported = id;
  13752. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13753. return true;
  13754. }
  13755. return false;
  13756. }
  13757. maybeParseExportNamespaceSpecifier(node) {
  13758. if (this.isContextual(93)) {
  13759. if (!node.specifiers) node.specifiers = [];
  13760. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13761. this.next();
  13762. specifier.exported = this.parseModuleExportName();
  13763. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13764. return true;
  13765. }
  13766. return false;
  13767. }
  13768. maybeParseExportNamedSpecifiers(node) {
  13769. if (this.match(5)) {
  13770. if (!node.specifiers) node.specifiers = [];
  13771. const isTypeExport = node.exportKind === "type";
  13772. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13773. node.source = null;
  13774. node.declaration = null;
  13775. if (this.hasPlugin("importAssertions")) {
  13776. node.assertions = [];
  13777. }
  13778. return true;
  13779. }
  13780. return false;
  13781. }
  13782. maybeParseExportDeclaration(node) {
  13783. if (this.shouldParseExportDeclaration()) {
  13784. node.specifiers = [];
  13785. node.source = null;
  13786. if (this.hasPlugin("importAssertions")) {
  13787. node.assertions = [];
  13788. }
  13789. node.declaration = this.parseExportDeclaration(node);
  13790. return true;
  13791. }
  13792. return false;
  13793. }
  13794. isAsyncFunction() {
  13795. if (!this.isContextual(95)) return false;
  13796. const next = this.nextTokenInLineStart();
  13797. return this.isUnparsedContextual(next, "function");
  13798. }
  13799. parseExportDefaultExpression() {
  13800. const expr = this.startNode();
  13801. if (this.match(68)) {
  13802. this.next();
  13803. return this.parseFunction(expr, 1 | 4);
  13804. } else if (this.isAsyncFunction()) {
  13805. this.next();
  13806. this.next();
  13807. return this.parseFunction(expr, 1 | 4 | 8);
  13808. }
  13809. if (this.match(80)) {
  13810. return this.parseClass(expr, true, true);
  13811. }
  13812. if (this.match(26)) {
  13813. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13814. this.raise(Errors.DecoratorBeforeExport, {
  13815. at: this.state.startLoc
  13816. });
  13817. }
  13818. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13819. }
  13820. if (this.match(75) || this.match(74) || this.isLet()) {
  13821. throw this.raise(Errors.UnsupportedDefaultExport, {
  13822. at: this.state.startLoc
  13823. });
  13824. }
  13825. const res = this.parseMaybeAssignAllowIn();
  13826. this.semicolon();
  13827. return res;
  13828. }
  13829. parseExportDeclaration(node) {
  13830. if (this.match(80)) {
  13831. const node = this.parseClass(this.startNode(), true, false);
  13832. return node;
  13833. }
  13834. return this.parseStatementListItem();
  13835. }
  13836. isExportDefaultSpecifier() {
  13837. const {
  13838. type
  13839. } = this.state;
  13840. if (tokenIsIdentifier(type)) {
  13841. if (type === 95 && !this.state.containsEsc || type === 100) {
  13842. return false;
  13843. }
  13844. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13845. const {
  13846. type: nextType
  13847. } = this.lookahead();
  13848. if (tokenIsIdentifier(nextType) && nextType !== 98 || nextType === 5) {
  13849. this.expectOnePlugin(["flow", "typescript"]);
  13850. return false;
  13851. }
  13852. }
  13853. } else if (!this.match(65)) {
  13854. return false;
  13855. }
  13856. const next = this.nextTokenStart();
  13857. const hasFrom = this.isUnparsedContextual(next, "from");
  13858. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13859. return true;
  13860. }
  13861. if (this.match(65) && hasFrom) {
  13862. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13863. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13864. }
  13865. return false;
  13866. }
  13867. parseExportFrom(node, expect) {
  13868. if (this.eatContextual(98)) {
  13869. node.source = this.parseImportSource();
  13870. this.checkExport(node);
  13871. this.maybeParseImportAttributes(node);
  13872. this.checkJSONModuleImport(node);
  13873. } else if (expect) {
  13874. this.unexpected();
  13875. }
  13876. this.semicolon();
  13877. }
  13878. shouldParseExportDeclaration() {
  13879. const {
  13880. type
  13881. } = this.state;
  13882. if (type === 26) {
  13883. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13884. if (this.hasPlugin("decorators")) {
  13885. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13886. this.raise(Errors.DecoratorBeforeExport, {
  13887. at: this.state.startLoc
  13888. });
  13889. }
  13890. return true;
  13891. }
  13892. }
  13893. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13894. }
  13895. checkExport(node, checkNames, isDefault, isFrom) {
  13896. if (checkNames) {
  13897. var _node$specifiers;
  13898. if (isDefault) {
  13899. this.checkDuplicateExports(node, "default");
  13900. if (this.hasPlugin("exportDefaultFrom")) {
  13901. var _declaration$extra;
  13902. const declaration = node.declaration;
  13903. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13904. this.raise(Errors.ExportDefaultFromAsIdentifier, {
  13905. at: declaration
  13906. });
  13907. }
  13908. }
  13909. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  13910. for (const specifier of node.specifiers) {
  13911. const {
  13912. exported
  13913. } = specifier;
  13914. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13915. this.checkDuplicateExports(specifier, exportName);
  13916. if (!isFrom && specifier.local) {
  13917. const {
  13918. local
  13919. } = specifier;
  13920. if (local.type !== "Identifier") {
  13921. this.raise(Errors.ExportBindingIsString, {
  13922. at: specifier,
  13923. localName: local.value,
  13924. exportName
  13925. });
  13926. } else {
  13927. this.checkReservedWord(local.name, local.loc.start, true, false);
  13928. this.scope.checkLocalExport(local);
  13929. }
  13930. }
  13931. }
  13932. } else if (node.declaration) {
  13933. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  13934. const id = node.declaration.id;
  13935. if (!id) throw new Error("Assertion failure");
  13936. this.checkDuplicateExports(node, id.name);
  13937. } else if (node.declaration.type === "VariableDeclaration") {
  13938. for (const declaration of node.declaration.declarations) {
  13939. this.checkDeclaration(declaration.id);
  13940. }
  13941. }
  13942. }
  13943. }
  13944. }
  13945. checkDeclaration(node) {
  13946. if (node.type === "Identifier") {
  13947. this.checkDuplicateExports(node, node.name);
  13948. } else if (node.type === "ObjectPattern") {
  13949. for (const prop of node.properties) {
  13950. this.checkDeclaration(prop);
  13951. }
  13952. } else if (node.type === "ArrayPattern") {
  13953. for (const elem of node.elements) {
  13954. if (elem) {
  13955. this.checkDeclaration(elem);
  13956. }
  13957. }
  13958. } else if (node.type === "ObjectProperty") {
  13959. this.checkDeclaration(node.value);
  13960. } else if (node.type === "RestElement") {
  13961. this.checkDeclaration(node.argument);
  13962. } else if (node.type === "AssignmentPattern") {
  13963. this.checkDeclaration(node.left);
  13964. }
  13965. }
  13966. checkDuplicateExports(node, exportName) {
  13967. if (this.exportedIdentifiers.has(exportName)) {
  13968. if (exportName === "default") {
  13969. this.raise(Errors.DuplicateDefaultExport, {
  13970. at: node
  13971. });
  13972. } else {
  13973. this.raise(Errors.DuplicateExport, {
  13974. at: node,
  13975. exportName
  13976. });
  13977. }
  13978. }
  13979. this.exportedIdentifiers.add(exportName);
  13980. }
  13981. parseExportSpecifiers(isInTypeExport) {
  13982. const nodes = [];
  13983. let first = true;
  13984. this.expect(5);
  13985. while (!this.eat(8)) {
  13986. if (first) {
  13987. first = false;
  13988. } else {
  13989. this.expect(12);
  13990. if (this.eat(8)) break;
  13991. }
  13992. const isMaybeTypeOnly = this.isContextual(130);
  13993. const isString = this.match(133);
  13994. const node = this.startNode();
  13995. node.local = this.parseModuleExportName();
  13996. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13997. }
  13998. return nodes;
  13999. }
  14000. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14001. if (this.eatContextual(93)) {
  14002. node.exported = this.parseModuleExportName();
  14003. } else if (isString) {
  14004. node.exported = cloneStringLiteral(node.local);
  14005. } else if (!node.exported) {
  14006. node.exported = cloneIdentifier(node.local);
  14007. }
  14008. return this.finishNode(node, "ExportSpecifier");
  14009. }
  14010. parseModuleExportName() {
  14011. if (this.match(133)) {
  14012. const result = this.parseStringLiteral(this.state.value);
  14013. const surrogate = result.value.match(loneSurrogate);
  14014. if (surrogate) {
  14015. this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
  14016. at: result,
  14017. surrogateCharCode: surrogate[0].charCodeAt(0)
  14018. });
  14019. }
  14020. return result;
  14021. }
  14022. return this.parseIdentifier(true);
  14023. }
  14024. isJSONModuleImport(node) {
  14025. if (node.assertions != null) {
  14026. return node.assertions.some(({
  14027. key,
  14028. value
  14029. }) => {
  14030. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14031. });
  14032. }
  14033. return false;
  14034. }
  14035. checkImportReflection(node) {
  14036. const {
  14037. specifiers
  14038. } = node;
  14039. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  14040. if (node.phase === "source") {
  14041. if (singleBindingType !== "ImportDefaultSpecifier") {
  14042. this.raise(Errors.SourcePhaseImportRequiresDefault, {
  14043. at: specifiers[0].loc.start
  14044. });
  14045. }
  14046. } else if (node.phase === "defer") {
  14047. if (singleBindingType !== "ImportNamespaceSpecifier") {
  14048. this.raise(Errors.DeferImportRequiresNamespace, {
  14049. at: specifiers[0].loc.start
  14050. });
  14051. }
  14052. } else if (node.module) {
  14053. var _node$assertions;
  14054. if (singleBindingType !== "ImportDefaultSpecifier") {
  14055. this.raise(Errors.ImportReflectionNotBinding, {
  14056. at: specifiers[0].loc.start
  14057. });
  14058. }
  14059. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14060. this.raise(Errors.ImportReflectionHasAssertion, {
  14061. at: node.specifiers[0].loc.start
  14062. });
  14063. }
  14064. }
  14065. }
  14066. checkJSONModuleImport(node) {
  14067. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14068. const {
  14069. specifiers
  14070. } = node;
  14071. if (specifiers != null) {
  14072. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14073. let imported;
  14074. if (specifier.type === "ExportSpecifier") {
  14075. imported = specifier.local;
  14076. } else if (specifier.type === "ImportSpecifier") {
  14077. imported = specifier.imported;
  14078. }
  14079. if (imported !== undefined) {
  14080. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14081. }
  14082. });
  14083. if (nonDefaultNamedSpecifier !== undefined) {
  14084. this.raise(Errors.ImportJSONBindingNotDefault, {
  14085. at: nonDefaultNamedSpecifier.loc.start
  14086. });
  14087. }
  14088. }
  14089. }
  14090. }
  14091. isPotentialImportPhase(isExport) {
  14092. if (isExport) return false;
  14093. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  14094. }
  14095. applyImportPhase(node, isExport, phase, loc) {
  14096. if (isExport) {
  14097. return;
  14098. }
  14099. if (phase === "module") {
  14100. this.expectPlugin("importReflection", loc);
  14101. node.module = true;
  14102. } else if (this.hasPlugin("importReflection")) {
  14103. node.module = false;
  14104. }
  14105. if (phase === "source") {
  14106. this.expectPlugin("sourcePhaseImports", loc);
  14107. node.phase = "source";
  14108. } else if (phase === "defer") {
  14109. this.expectPlugin("deferredImportEvaluation", loc);
  14110. node.phase = "defer";
  14111. } else if (this.hasPlugin("sourcePhaseImports")) {
  14112. node.phase = null;
  14113. }
  14114. }
  14115. parseMaybeImportPhase(node, isExport) {
  14116. if (!this.isPotentialImportPhase(isExport)) {
  14117. this.applyImportPhase(node, isExport, null);
  14118. return null;
  14119. }
  14120. const phaseIdentifier = this.parseIdentifier(true);
  14121. const {
  14122. type
  14123. } = this.state;
  14124. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14125. if (isImportPhase) {
  14126. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  14127. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  14128. return null;
  14129. } else {
  14130. this.applyImportPhase(node, isExport, null);
  14131. return phaseIdentifier;
  14132. }
  14133. }
  14134. isPrecedingIdImportPhase(phase) {
  14135. const {
  14136. type
  14137. } = this.state;
  14138. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14139. }
  14140. parseImport(node) {
  14141. if (this.match(133)) {
  14142. return this.parseImportSourceAndAttributes(node);
  14143. }
  14144. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14145. }
  14146. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14147. node.specifiers = [];
  14148. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14149. const parseNext = !hasDefault || this.eat(12);
  14150. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14151. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14152. this.expectContextual(98);
  14153. return this.parseImportSourceAndAttributes(node);
  14154. }
  14155. parseImportSourceAndAttributes(node) {
  14156. var _node$specifiers2;
  14157. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14158. node.source = this.parseImportSource();
  14159. this.maybeParseImportAttributes(node);
  14160. this.checkImportReflection(node);
  14161. this.checkJSONModuleImport(node);
  14162. this.semicolon();
  14163. return this.finishNode(node, "ImportDeclaration");
  14164. }
  14165. parseImportSource() {
  14166. if (!this.match(133)) this.unexpected();
  14167. return this.parseExprAtom();
  14168. }
  14169. parseImportSpecifierLocal(node, specifier, type) {
  14170. specifier.local = this.parseIdentifier();
  14171. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14172. }
  14173. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14174. this.checkLVal(specifier.local, {
  14175. in: {
  14176. type
  14177. },
  14178. binding: bindingType
  14179. });
  14180. return this.finishNode(specifier, type);
  14181. }
  14182. parseImportAttributes() {
  14183. this.expect(5);
  14184. const attrs = [];
  14185. const attrNames = new Set();
  14186. do {
  14187. if (this.match(8)) {
  14188. break;
  14189. }
  14190. const node = this.startNode();
  14191. const keyName = this.state.value;
  14192. if (attrNames.has(keyName)) {
  14193. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14194. at: this.state.startLoc,
  14195. key: keyName
  14196. });
  14197. }
  14198. attrNames.add(keyName);
  14199. if (this.match(133)) {
  14200. node.key = this.parseStringLiteral(keyName);
  14201. } else {
  14202. node.key = this.parseIdentifier(true);
  14203. }
  14204. this.expect(14);
  14205. if (!this.match(133)) {
  14206. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14207. at: this.state.startLoc
  14208. });
  14209. }
  14210. node.value = this.parseStringLiteral(this.state.value);
  14211. attrs.push(this.finishNode(node, "ImportAttribute"));
  14212. } while (this.eat(12));
  14213. this.expect(8);
  14214. return attrs;
  14215. }
  14216. parseModuleAttributes() {
  14217. const attrs = [];
  14218. const attributes = new Set();
  14219. do {
  14220. const node = this.startNode();
  14221. node.key = this.parseIdentifier(true);
  14222. if (node.key.name !== "type") {
  14223. this.raise(Errors.ModuleAttributeDifferentFromType, {
  14224. at: node.key
  14225. });
  14226. }
  14227. if (attributes.has(node.key.name)) {
  14228. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14229. at: node.key,
  14230. key: node.key.name
  14231. });
  14232. }
  14233. attributes.add(node.key.name);
  14234. this.expect(14);
  14235. if (!this.match(133)) {
  14236. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14237. at: this.state.startLoc
  14238. });
  14239. }
  14240. node.value = this.parseStringLiteral(this.state.value);
  14241. attrs.push(this.finishNode(node, "ImportAttribute"));
  14242. } while (this.eat(12));
  14243. return attrs;
  14244. }
  14245. maybeParseImportAttributes(node) {
  14246. let attributes;
  14247. let useWith = false;
  14248. if (this.match(76)) {
  14249. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14250. return;
  14251. }
  14252. this.next();
  14253. {
  14254. if (this.hasPlugin("moduleAttributes")) {
  14255. attributes = this.parseModuleAttributes();
  14256. } else {
  14257. this.expectImportAttributesPlugin();
  14258. attributes = this.parseImportAttributes();
  14259. }
  14260. }
  14261. useWith = true;
  14262. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14263. if (this.hasPlugin("importAttributes")) {
  14264. if (this.getPluginOption("importAttributes", "deprecatedAssertSyntax") !== true) {
  14265. this.raise(Errors.ImportAttributesUseAssert, {
  14266. at: this.state.startLoc
  14267. });
  14268. }
  14269. this.addExtra(node, "deprecatedAssertSyntax", true);
  14270. } else {
  14271. this.expectOnePlugin(["importAttributes", "importAssertions"]);
  14272. }
  14273. this.next();
  14274. attributes = this.parseImportAttributes();
  14275. } else if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  14276. attributes = [];
  14277. } else {
  14278. if (this.hasPlugin("moduleAttributes")) {
  14279. attributes = [];
  14280. } else return;
  14281. }
  14282. if (!useWith && this.hasPlugin("importAssertions")) {
  14283. node.assertions = attributes;
  14284. } else {
  14285. node.attributes = attributes;
  14286. }
  14287. }
  14288. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14289. if (maybeDefaultIdentifier) {
  14290. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14291. specifier.local = maybeDefaultIdentifier;
  14292. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14293. return true;
  14294. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14295. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14296. return true;
  14297. }
  14298. return false;
  14299. }
  14300. maybeParseStarImportSpecifier(node) {
  14301. if (this.match(55)) {
  14302. const specifier = this.startNode();
  14303. this.next();
  14304. this.expectContextual(93);
  14305. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14306. return true;
  14307. }
  14308. return false;
  14309. }
  14310. parseNamedImportSpecifiers(node) {
  14311. let first = true;
  14312. this.expect(5);
  14313. while (!this.eat(8)) {
  14314. if (first) {
  14315. first = false;
  14316. } else {
  14317. if (this.eat(14)) {
  14318. throw this.raise(Errors.DestructureNamedImport, {
  14319. at: this.state.startLoc
  14320. });
  14321. }
  14322. this.expect(12);
  14323. if (this.eat(8)) break;
  14324. }
  14325. const specifier = this.startNode();
  14326. const importedIsString = this.match(133);
  14327. const isMaybeTypeOnly = this.isContextual(130);
  14328. specifier.imported = this.parseModuleExportName();
  14329. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14330. node.specifiers.push(importSpecifier);
  14331. }
  14332. }
  14333. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14334. if (this.eatContextual(93)) {
  14335. specifier.local = this.parseIdentifier();
  14336. } else {
  14337. const {
  14338. imported
  14339. } = specifier;
  14340. if (importedIsString) {
  14341. throw this.raise(Errors.ImportBindingIsString, {
  14342. at: specifier,
  14343. importName: imported.value
  14344. });
  14345. }
  14346. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14347. if (!specifier.local) {
  14348. specifier.local = cloneIdentifier(imported);
  14349. }
  14350. }
  14351. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14352. }
  14353. isThisParam(param) {
  14354. return param.type === "Identifier" && param.name === "this";
  14355. }
  14356. }
  14357. class Parser extends StatementParser {
  14358. constructor(options, input) {
  14359. options = getOptions(options);
  14360. super(options, input);
  14361. this.options = options;
  14362. this.initializeScopes();
  14363. this.plugins = pluginsMap(this.options.plugins);
  14364. this.filename = options.sourceFilename;
  14365. }
  14366. getScopeHandler() {
  14367. return ScopeHandler;
  14368. }
  14369. parse() {
  14370. this.enterInitialScopes();
  14371. const file = this.startNode();
  14372. const program = this.startNode();
  14373. this.nextToken();
  14374. file.errors = null;
  14375. this.parseTopLevel(file, program);
  14376. file.errors = this.state.errors;
  14377. return file;
  14378. }
  14379. }
  14380. function pluginsMap(plugins) {
  14381. const pluginMap = new Map();
  14382. for (const plugin of plugins) {
  14383. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  14384. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  14385. }
  14386. return pluginMap;
  14387. }
  14388. function parse(input, options) {
  14389. var _options;
  14390. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14391. options = Object.assign({}, options);
  14392. try {
  14393. options.sourceType = "module";
  14394. const parser = getParser(options, input);
  14395. const ast = parser.parse();
  14396. if (parser.sawUnambiguousESM) {
  14397. return ast;
  14398. }
  14399. if (parser.ambiguousScriptDifferentAst) {
  14400. try {
  14401. options.sourceType = "script";
  14402. return getParser(options, input).parse();
  14403. } catch (_unused) {}
  14404. } else {
  14405. ast.program.sourceType = "script";
  14406. }
  14407. return ast;
  14408. } catch (moduleError) {
  14409. try {
  14410. options.sourceType = "script";
  14411. return getParser(options, input).parse();
  14412. } catch (_unused2) {}
  14413. throw moduleError;
  14414. }
  14415. } else {
  14416. return getParser(options, input).parse();
  14417. }
  14418. }
  14419. function parseExpression(input, options) {
  14420. const parser = getParser(options, input);
  14421. if (parser.options.strictMode) {
  14422. parser.state.strict = true;
  14423. }
  14424. return parser.getExpression();
  14425. }
  14426. function generateExportedTokenTypes(internalTokenTypes) {
  14427. const tokenTypes = {};
  14428. for (const typeName of Object.keys(internalTokenTypes)) {
  14429. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14430. }
  14431. return tokenTypes;
  14432. }
  14433. const tokTypes = generateExportedTokenTypes(tt);
  14434. function getParser(options, input) {
  14435. let cls = Parser;
  14436. if (options != null && options.plugins) {
  14437. validatePlugins(options.plugins);
  14438. cls = getParserClass(options.plugins);
  14439. }
  14440. return new cls(options, input);
  14441. }
  14442. const parserClassCache = {};
  14443. function getParserClass(pluginsFromOptions) {
  14444. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  14445. const key = pluginList.join("/");
  14446. let cls = parserClassCache[key];
  14447. if (!cls) {
  14448. cls = Parser;
  14449. for (const plugin of pluginList) {
  14450. cls = mixinPlugins[plugin](cls);
  14451. }
  14452. parserClassCache[key] = cls;
  14453. }
  14454. return cls;
  14455. }
  14456. exports.parse = parse;
  14457. exports.parseExpression = parseExpression;
  14458. exports.tokTypes = tokTypes;
  14459. //# sourceMappingURL=index.js.map