index.js 480 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430
  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. var ParseErrorCode = {
  46. SyntaxError: "BABEL_PARSER_SYNTAX_ERROR",
  47. SourceTypeModuleError: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"
  48. };
  49. const reflect = (keys, last = keys.length - 1) => ({
  50. get() {
  51. return keys.reduce((object, key) => object[key], this);
  52. },
  53. set(value) {
  54. keys.reduce((item, key, i) => i === last ? item[key] = value : item[key], this);
  55. }
  56. });
  57. const instantiate = (constructor, properties, descriptors) => Object.keys(descriptors).map(key => [key, descriptors[key]]).filter(([, descriptor]) => !!descriptor).map(([key, descriptor]) => [key, typeof descriptor === "function" ? {
  58. value: descriptor,
  59. enumerable: false
  60. } : typeof descriptor.reflect === "string" ? Object.assign({}, descriptor, reflect(descriptor.reflect.split("."))) : descriptor]).reduce((instance, [key, descriptor]) => Object.defineProperty(instance, key, Object.assign({
  61. configurable: true
  62. }, descriptor)), Object.assign(new constructor(), properties));
  63. var ModuleErrors = {
  64. ImportMetaOutsideModule: {
  65. message: `import.meta may appear only with 'sourceType: "module"'`,
  66. code: ParseErrorCode.SourceTypeModuleError
  67. },
  68. ImportOutsideModule: {
  69. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  70. code: ParseErrorCode.SourceTypeModuleError
  71. }
  72. };
  73. const NodeDescriptions = {
  74. ArrayPattern: "array destructuring pattern",
  75. AssignmentExpression: "assignment expression",
  76. AssignmentPattern: "assignment expression",
  77. ArrowFunctionExpression: "arrow function expression",
  78. ConditionalExpression: "conditional expression",
  79. CatchClause: "catch clause",
  80. ForOfStatement: "for-of statement",
  81. ForInStatement: "for-in statement",
  82. ForStatement: "for-loop",
  83. FormalParameters: "function parameter list",
  84. Identifier: "identifier",
  85. ImportSpecifier: "import specifier",
  86. ImportDefaultSpecifier: "import default specifier",
  87. ImportNamespaceSpecifier: "import namespace specifier",
  88. ObjectPattern: "object destructuring pattern",
  89. ParenthesizedExpression: "parenthesized expression",
  90. RestElement: "rest element",
  91. UpdateExpression: {
  92. true: "prefix operation",
  93. false: "postfix operation"
  94. },
  95. VariableDeclarator: "variable declaration",
  96. YieldExpression: "yield expression"
  97. };
  98. const toNodeDescription = ({
  99. type,
  100. prefix
  101. }) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
  102. var StandardErrors = {
  103. AccessorIsGenerator: ({
  104. kind
  105. }) => `A ${kind}ter cannot be a generator.`,
  106. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  107. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  108. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  109. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  110. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  111. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  112. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  113. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  114. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  115. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  116. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  117. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  118. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  119. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  120. ConstructorIsAsync: "Constructor can't be an async function.",
  121. ConstructorIsGenerator: "Constructor can't be a generator.",
  122. DeclarationMissingInitializer: ({
  123. kind
  124. }) => `Missing initializer in ${kind} declaration.`,
  125. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  126. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  127. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  128. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  129. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  130. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  131. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  132. DeletePrivateField: "Deleting a private field is not allowed.",
  133. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  134. DuplicateConstructor: "Duplicate constructor in the same class.",
  135. DuplicateDefaultExport: "Only one default export allowed per module.",
  136. DuplicateExport: ({
  137. exportName
  138. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  139. DuplicateProto: "Redefinition of __proto__ property.",
  140. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  141. ElementAfterRest: "Rest element must be last element.",
  142. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  143. ExportBindingIsString: ({
  144. localName,
  145. exportName
  146. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  147. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  148. ForInOfLoopInitializer: ({
  149. type
  150. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  151. ForInUsing: "For-in loop may not start with 'using' declaration.",
  152. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  153. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  154. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  155. IllegalBreakContinue: ({
  156. type
  157. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  158. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  159. IllegalReturn: "'return' outside of function.",
  160. 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.",
  161. ImportBindingIsString: ({
  162. importName
  163. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  164. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  165. ImportCallArity: ({
  166. maxArgumentCount
  167. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
  168. ImportCallNotNewExpression: "Cannot use new with import(...).",
  169. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  170. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  171. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  172. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  173. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  174. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  175. InvalidCodePoint: "Code point out of bounds.",
  176. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  177. InvalidDecimal: "Invalid decimal.",
  178. InvalidDigit: ({
  179. radix
  180. }) => `Expected number in radix ${radix}.`,
  181. InvalidEscapeSequence: "Bad character escape sequence.",
  182. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  183. InvalidEscapedReservedWord: ({
  184. reservedWord
  185. }) => `Escape sequence in keyword ${reservedWord}.`,
  186. InvalidIdentifier: ({
  187. identifierName
  188. }) => `Invalid identifier ${identifierName}.`,
  189. InvalidLhs: ({
  190. ancestor
  191. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  192. InvalidLhsBinding: ({
  193. ancestor
  194. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  195. InvalidNumber: "Invalid number.",
  196. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  197. InvalidOrUnexpectedToken: ({
  198. unexpected
  199. }) => `Unexpected character '${unexpected}'.`,
  200. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  201. InvalidPrivateFieldResolution: ({
  202. identifierName
  203. }) => `Private name #${identifierName} is not defined.`,
  204. InvalidPropertyBindingPattern: "Binding member expression.",
  205. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  206. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  207. LabelRedeclaration: ({
  208. labelName
  209. }) => `Label '${labelName}' is already declared.`,
  210. LetInLexicalBinding: "'let' is not allowed to be used as a name in 'let' or 'const' declarations.",
  211. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  212. MalformedRegExpFlags: "Invalid regular expression flag.",
  213. MissingClassName: "A class name is required.",
  214. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  215. MissingSemicolon: "Missing semicolon.",
  216. MissingPlugin: ({
  217. missingPlugin
  218. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  219. MissingOneOfPlugins: ({
  220. missingPlugin
  221. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  222. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  223. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  224. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  225. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  226. ModuleAttributesWithDuplicateKeys: ({
  227. key
  228. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  229. ModuleExportNameHasLoneSurrogate: ({
  230. surrogateCharCode
  231. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  232. ModuleExportUndefined: ({
  233. localName
  234. }) => `Export '${localName}' is not defined.`,
  235. MultipleDefaultsInSwitch: "Multiple default clauses.",
  236. NewlineAfterThrow: "Illegal newline after throw.",
  237. NoCatchOrFinally: "Missing catch or finally clause.",
  238. NumberIdentifier: "Identifier directly after number.",
  239. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  240. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  241. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  242. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  243. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  244. ParamDupe: "Argument name clash.",
  245. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  246. PatternHasMethod: "Object pattern can't contain methods.",
  247. PrivateInExpectedIn: ({
  248. identifierName
  249. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  250. PrivateNameRedeclaration: ({
  251. identifierName
  252. }) => `Duplicate private name #${identifierName}.`,
  253. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  254. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  255. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  256. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  257. RestTrailingComma: "Unexpected trailing comma after rest element.",
  258. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  259. 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.",
  260. StaticPrototype: "Classes may not have static property named prototype.",
  261. 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?",
  262. SuperPrivateField: "Private fields can't be accessed on super.",
  263. TrailingDecorator: "Decorators must be attached to a class element.",
  264. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  265. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  266. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  267. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  268. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  269. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  270. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  271. UnexpectedKeyword: ({
  272. keyword
  273. }) => `Unexpected keyword '${keyword}'.`,
  274. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  275. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  276. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  277. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  278. UnexpectedPrivateField: "Unexpected private name.",
  279. UnexpectedReservedWord: ({
  280. reservedWord
  281. }) => `Unexpected reserved word '${reservedWord}'.`,
  282. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  283. UnexpectedToken: ({
  284. expected,
  285. unexpected
  286. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  287. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  288. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  289. UnsupportedBind: "Binding should be performed on object property.",
  290. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  291. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  292. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  293. UnsupportedMetaProperty: ({
  294. target,
  295. onlyValidPropertyName
  296. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  297. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  298. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  299. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  300. UnterminatedComment: "Unterminated comment.",
  301. UnterminatedRegExp: "Unterminated regular expression.",
  302. UnterminatedString: "Unterminated string constant.",
  303. UnterminatedTemplate: "Unterminated template.",
  304. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  305. VarRedeclaration: ({
  306. identifierName
  307. }) => `Identifier '${identifierName}' has already been declared.`,
  308. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  309. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  310. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  311. };
  312. var StrictModeErrors = {
  313. StrictDelete: "Deleting local variable in strict mode.",
  314. StrictEvalArguments: ({
  315. referenceName
  316. }) => `Assigning to '${referenceName}' in strict mode.`,
  317. StrictEvalArgumentsBinding: ({
  318. bindingName
  319. }) => `Binding '${bindingName}' in strict mode.`,
  320. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  321. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  322. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  323. StrictWith: "'with' in strict mode."
  324. };
  325. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  326. var PipelineOperatorErrors = {
  327. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  328. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  329. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  330. PipeTopicUnconfiguredToken: ({
  331. token
  332. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  333. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  334. PipeUnparenthesizedBody: ({
  335. type
  336. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  337. type
  338. })}; please wrap it in parentheses.`,
  339. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  340. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  341. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  342. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  343. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  344. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  345. };
  346. const _excluded$1 = ["toMessage"],
  347. _excluded2$1 = ["message"];
  348. function toParseErrorConstructor(_ref) {
  349. let {
  350. toMessage
  351. } = _ref,
  352. properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  353. return function constructor({
  354. loc,
  355. details
  356. }) {
  357. return instantiate(SyntaxError, Object.assign({}, properties, {
  358. loc
  359. }), {
  360. clone(overrides = {}) {
  361. const loc = overrides.loc || {};
  362. return constructor({
  363. loc: new Position("line" in loc ? loc.line : this.loc.line, "column" in loc ? loc.column : this.loc.column, "index" in loc ? loc.index : this.loc.index),
  364. details: Object.assign({}, this.details, overrides.details)
  365. });
  366. },
  367. details: {
  368. value: details,
  369. enumerable: false
  370. },
  371. message: {
  372. get() {
  373. return `${toMessage(this.details)} (${this.loc.line}:${this.loc.column})`;
  374. },
  375. set(value) {
  376. Object.defineProperty(this, "message", {
  377. value
  378. });
  379. }
  380. },
  381. pos: {
  382. reflect: "loc.index",
  383. enumerable: true
  384. },
  385. missingPlugin: "missingPlugin" in details && {
  386. reflect: "details.missingPlugin",
  387. enumerable: true
  388. }
  389. });
  390. };
  391. }
  392. function ParseErrorEnum(argument, syntaxPlugin) {
  393. if (Array.isArray(argument)) {
  394. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  395. }
  396. const ParseErrorConstructors = {};
  397. for (const reasonCode of Object.keys(argument)) {
  398. const template = argument[reasonCode];
  399. const _ref2 = typeof template === "string" ? {
  400. message: () => template
  401. } : typeof template === "function" ? {
  402. message: template
  403. } : template,
  404. {
  405. message
  406. } = _ref2,
  407. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
  408. const toMessage = typeof message === "string" ? () => message : message;
  409. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  410. code: ParseErrorCode.SyntaxError,
  411. reasonCode,
  412. toMessage
  413. }, syntaxPlugin ? {
  414. syntaxPlugin
  415. } : {}, rest));
  416. }
  417. return ParseErrorConstructors;
  418. }
  419. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  420. const {
  421. defineProperty
  422. } = Object;
  423. const toUnenumerable = (object, key) => defineProperty(object, key, {
  424. enumerable: false,
  425. value: object[key]
  426. });
  427. function toESTreeLocation(node) {
  428. node.loc.start && toUnenumerable(node.loc.start, "index");
  429. node.loc.end && toUnenumerable(node.loc.end, "index");
  430. return node;
  431. }
  432. var estree = superClass => class ESTreeParserMixin extends superClass {
  433. parse() {
  434. const file = toESTreeLocation(super.parse());
  435. if (this.options.tokens) {
  436. file.tokens = file.tokens.map(toESTreeLocation);
  437. }
  438. return file;
  439. }
  440. parseRegExpLiteral({
  441. pattern,
  442. flags
  443. }) {
  444. let regex = null;
  445. try {
  446. regex = new RegExp(pattern, flags);
  447. } catch (e) {}
  448. const node = this.estreeParseLiteral(regex);
  449. node.regex = {
  450. pattern,
  451. flags
  452. };
  453. return node;
  454. }
  455. parseBigIntLiteral(value) {
  456. let bigInt;
  457. try {
  458. bigInt = BigInt(value);
  459. } catch (_unused) {
  460. bigInt = null;
  461. }
  462. const node = this.estreeParseLiteral(bigInt);
  463. node.bigint = String(node.value || value);
  464. return node;
  465. }
  466. parseDecimalLiteral(value) {
  467. const decimal = null;
  468. const node = this.estreeParseLiteral(decimal);
  469. node.decimal = String(node.value || value);
  470. return node;
  471. }
  472. estreeParseLiteral(value) {
  473. return this.parseLiteral(value, "Literal");
  474. }
  475. parseStringLiteral(value) {
  476. return this.estreeParseLiteral(value);
  477. }
  478. parseNumericLiteral(value) {
  479. return this.estreeParseLiteral(value);
  480. }
  481. parseNullLiteral() {
  482. return this.estreeParseLiteral(null);
  483. }
  484. parseBooleanLiteral(value) {
  485. return this.estreeParseLiteral(value);
  486. }
  487. directiveToStmt(directive) {
  488. const expression = directive.value;
  489. delete directive.value;
  490. expression.type = "Literal";
  491. expression.raw = expression.extra.raw;
  492. expression.value = expression.extra.expressionValue;
  493. const stmt = directive;
  494. stmt.type = "ExpressionStatement";
  495. stmt.expression = expression;
  496. stmt.directive = expression.extra.rawValue;
  497. delete expression.extra;
  498. return stmt;
  499. }
  500. initFunction(node, isAsync) {
  501. super.initFunction(node, isAsync);
  502. node.expression = false;
  503. }
  504. checkDeclaration(node) {
  505. if (node != null && this.isObjectProperty(node)) {
  506. this.checkDeclaration(node.value);
  507. } else {
  508. super.checkDeclaration(node);
  509. }
  510. }
  511. getObjectOrClassMethodParams(method) {
  512. return method.value.params;
  513. }
  514. isValidDirective(stmt) {
  515. var _stmt$expression$extr;
  516. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  517. }
  518. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  519. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  520. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  521. node.body = directiveStatements.concat(node.body);
  522. delete node.directives;
  523. }
  524. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  525. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  526. if (method.typeParameters) {
  527. method.value.typeParameters = method.typeParameters;
  528. delete method.typeParameters;
  529. }
  530. classBody.body.push(method);
  531. }
  532. parsePrivateName() {
  533. const node = super.parsePrivateName();
  534. {
  535. if (!this.getPluginOption("estree", "classFeatures")) {
  536. return node;
  537. }
  538. }
  539. return this.convertPrivateNameToPrivateIdentifier(node);
  540. }
  541. convertPrivateNameToPrivateIdentifier(node) {
  542. const name = super.getPrivateNameSV(node);
  543. node = node;
  544. delete node.id;
  545. node.name = name;
  546. node.type = "PrivateIdentifier";
  547. return node;
  548. }
  549. isPrivateName(node) {
  550. {
  551. if (!this.getPluginOption("estree", "classFeatures")) {
  552. return super.isPrivateName(node);
  553. }
  554. }
  555. return node.type === "PrivateIdentifier";
  556. }
  557. getPrivateNameSV(node) {
  558. {
  559. if (!this.getPluginOption("estree", "classFeatures")) {
  560. return super.getPrivateNameSV(node);
  561. }
  562. }
  563. return node.name;
  564. }
  565. parseLiteral(value, type) {
  566. const node = super.parseLiteral(value, type);
  567. node.raw = node.extra.raw;
  568. delete node.extra;
  569. return node;
  570. }
  571. parseFunctionBody(node, allowExpression, isMethod = false) {
  572. super.parseFunctionBody(node, allowExpression, isMethod);
  573. node.expression = node.body.type !== "BlockStatement";
  574. }
  575. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  576. let funcNode = this.startNode();
  577. funcNode.kind = node.kind;
  578. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  579. funcNode.type = "FunctionExpression";
  580. delete funcNode.kind;
  581. node.value = funcNode;
  582. if (type === "ClassPrivateMethod") {
  583. node.computed = false;
  584. }
  585. return this.finishNode(node, "MethodDefinition");
  586. }
  587. parseClassProperty(...args) {
  588. const propertyNode = super.parseClassProperty(...args);
  589. {
  590. if (!this.getPluginOption("estree", "classFeatures")) {
  591. return propertyNode;
  592. }
  593. }
  594. propertyNode.type = "PropertyDefinition";
  595. return propertyNode;
  596. }
  597. parseClassPrivateProperty(...args) {
  598. const propertyNode = super.parseClassPrivateProperty(...args);
  599. {
  600. if (!this.getPluginOption("estree", "classFeatures")) {
  601. return propertyNode;
  602. }
  603. }
  604. propertyNode.type = "PropertyDefinition";
  605. propertyNode.computed = false;
  606. return propertyNode;
  607. }
  608. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  609. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  610. if (node) {
  611. node.type = "Property";
  612. if (node.kind === "method") {
  613. node.kind = "init";
  614. }
  615. node.shorthand = false;
  616. }
  617. return node;
  618. }
  619. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  620. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  621. if (node) {
  622. node.kind = "init";
  623. node.type = "Property";
  624. }
  625. return node;
  626. }
  627. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  628. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  629. }
  630. isAssignable(node, isBinding) {
  631. if (node != null && this.isObjectProperty(node)) {
  632. return this.isAssignable(node.value, isBinding);
  633. }
  634. return super.isAssignable(node, isBinding);
  635. }
  636. toAssignable(node, isLHS = false) {
  637. if (node != null && this.isObjectProperty(node)) {
  638. const {
  639. key,
  640. value
  641. } = node;
  642. if (this.isPrivateName(key)) {
  643. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  644. }
  645. this.toAssignable(value, isLHS);
  646. } else {
  647. super.toAssignable(node, isLHS);
  648. }
  649. }
  650. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  651. if (prop.kind === "get" || prop.kind === "set") {
  652. this.raise(Errors.PatternHasAccessor, {
  653. at: prop.key
  654. });
  655. } else if (prop.method) {
  656. this.raise(Errors.PatternHasMethod, {
  657. at: prop.key
  658. });
  659. } else {
  660. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  661. }
  662. }
  663. finishCallExpression(unfinished, optional) {
  664. const node = super.finishCallExpression(unfinished, optional);
  665. if (node.callee.type === "Import") {
  666. node.type = "ImportExpression";
  667. node.source = node.arguments[0];
  668. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  669. var _node$arguments$;
  670. node.attributes = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  671. }
  672. delete node.arguments;
  673. delete node.callee;
  674. }
  675. return node;
  676. }
  677. toReferencedArguments(node) {
  678. if (node.type === "ImportExpression") {
  679. return;
  680. }
  681. super.toReferencedArguments(node);
  682. }
  683. parseExport(unfinished, decorators) {
  684. const exportStartLoc = this.state.lastTokStartLoc;
  685. const node = super.parseExport(unfinished, decorators);
  686. switch (node.type) {
  687. case "ExportAllDeclaration":
  688. node.exported = null;
  689. break;
  690. case "ExportNamedDeclaration":
  691. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  692. node.type = "ExportAllDeclaration";
  693. node.exported = node.specifiers[0].exported;
  694. delete node.specifiers;
  695. }
  696. case "ExportDefaultDeclaration":
  697. {
  698. var _declaration$decorato;
  699. const {
  700. declaration
  701. } = node;
  702. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  703. this.resetStartLocation(node, exportStartLoc);
  704. }
  705. }
  706. break;
  707. }
  708. return node;
  709. }
  710. parseSubscript(base, startLoc, noCalls, state) {
  711. const node = super.parseSubscript(base, startLoc, noCalls, state);
  712. if (state.optionalChainMember) {
  713. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  714. node.type = node.type.substring(8);
  715. }
  716. if (state.stop) {
  717. const chain = this.startNodeAtNode(node);
  718. chain.expression = node;
  719. return this.finishNode(chain, "ChainExpression");
  720. }
  721. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  722. node.optional = false;
  723. }
  724. return node;
  725. }
  726. hasPropertyAsPrivateName(node) {
  727. if (node.type === "ChainExpression") {
  728. node = node.expression;
  729. }
  730. return super.hasPropertyAsPrivateName(node);
  731. }
  732. isObjectProperty(node) {
  733. return node.type === "Property" && node.kind === "init" && !node.method;
  734. }
  735. isObjectMethod(node) {
  736. return node.method || node.kind === "get" || node.kind === "set";
  737. }
  738. finishNodeAt(node, type, endLoc) {
  739. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  740. }
  741. resetStartLocation(node, startLoc) {
  742. super.resetStartLocation(node, startLoc);
  743. toESTreeLocation(node);
  744. }
  745. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  746. super.resetEndLocation(node, endLoc);
  747. toESTreeLocation(node);
  748. }
  749. };
  750. class TokContext {
  751. constructor(token, preserveSpace) {
  752. this.token = void 0;
  753. this.preserveSpace = void 0;
  754. this.token = token;
  755. this.preserveSpace = !!preserveSpace;
  756. }
  757. }
  758. const types = {
  759. brace: new TokContext("{"),
  760. j_oTag: new TokContext("<tag"),
  761. j_cTag: new TokContext("</tag"),
  762. j_expr: new TokContext("<tag>...</tag>", true)
  763. };
  764. {
  765. types.template = new TokContext("`", true);
  766. }
  767. const beforeExpr = true;
  768. const startsExpr = true;
  769. const isLoop = true;
  770. const isAssign = true;
  771. const prefix = true;
  772. const postfix = true;
  773. class ExportedTokenType {
  774. constructor(label, conf = {}) {
  775. this.label = void 0;
  776. this.keyword = void 0;
  777. this.beforeExpr = void 0;
  778. this.startsExpr = void 0;
  779. this.rightAssociative = void 0;
  780. this.isLoop = void 0;
  781. this.isAssign = void 0;
  782. this.prefix = void 0;
  783. this.postfix = void 0;
  784. this.binop = void 0;
  785. this.label = label;
  786. this.keyword = conf.keyword;
  787. this.beforeExpr = !!conf.beforeExpr;
  788. this.startsExpr = !!conf.startsExpr;
  789. this.rightAssociative = !!conf.rightAssociative;
  790. this.isLoop = !!conf.isLoop;
  791. this.isAssign = !!conf.isAssign;
  792. this.prefix = !!conf.prefix;
  793. this.postfix = !!conf.postfix;
  794. this.binop = conf.binop != null ? conf.binop : null;
  795. {
  796. this.updateContext = null;
  797. }
  798. }
  799. }
  800. const keywords$1 = new Map();
  801. function createKeyword(name, options = {}) {
  802. options.keyword = name;
  803. const token = createToken(name, options);
  804. keywords$1.set(name, token);
  805. return token;
  806. }
  807. function createBinop(name, binop) {
  808. return createToken(name, {
  809. beforeExpr,
  810. binop
  811. });
  812. }
  813. let tokenTypeCounter = -1;
  814. const tokenTypes = [];
  815. const tokenLabels = [];
  816. const tokenBinops = [];
  817. const tokenBeforeExprs = [];
  818. const tokenStartsExprs = [];
  819. const tokenPrefixes = [];
  820. function createToken(name, options = {}) {
  821. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  822. ++tokenTypeCounter;
  823. tokenLabels.push(name);
  824. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  825. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  826. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  827. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  828. tokenTypes.push(new ExportedTokenType(name, options));
  829. return tokenTypeCounter;
  830. }
  831. function createKeywordLike(name, options = {}) {
  832. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  833. ++tokenTypeCounter;
  834. keywords$1.set(name, tokenTypeCounter);
  835. tokenLabels.push(name);
  836. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  837. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  838. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  839. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  840. tokenTypes.push(new ExportedTokenType("name", options));
  841. return tokenTypeCounter;
  842. }
  843. const tt = {
  844. bracketL: createToken("[", {
  845. beforeExpr,
  846. startsExpr
  847. }),
  848. bracketHashL: createToken("#[", {
  849. beforeExpr,
  850. startsExpr
  851. }),
  852. bracketBarL: createToken("[|", {
  853. beforeExpr,
  854. startsExpr
  855. }),
  856. bracketR: createToken("]"),
  857. bracketBarR: createToken("|]"),
  858. braceL: createToken("{", {
  859. beforeExpr,
  860. startsExpr
  861. }),
  862. braceBarL: createToken("{|", {
  863. beforeExpr,
  864. startsExpr
  865. }),
  866. braceHashL: createToken("#{", {
  867. beforeExpr,
  868. startsExpr
  869. }),
  870. braceR: createToken("}"),
  871. braceBarR: createToken("|}"),
  872. parenL: createToken("(", {
  873. beforeExpr,
  874. startsExpr
  875. }),
  876. parenR: createToken(")"),
  877. comma: createToken(",", {
  878. beforeExpr
  879. }),
  880. semi: createToken(";", {
  881. beforeExpr
  882. }),
  883. colon: createToken(":", {
  884. beforeExpr
  885. }),
  886. doubleColon: createToken("::", {
  887. beforeExpr
  888. }),
  889. dot: createToken("."),
  890. question: createToken("?", {
  891. beforeExpr
  892. }),
  893. questionDot: createToken("?."),
  894. arrow: createToken("=>", {
  895. beforeExpr
  896. }),
  897. template: createToken("template"),
  898. ellipsis: createToken("...", {
  899. beforeExpr
  900. }),
  901. backQuote: createToken("`", {
  902. startsExpr
  903. }),
  904. dollarBraceL: createToken("${", {
  905. beforeExpr,
  906. startsExpr
  907. }),
  908. templateTail: createToken("...`", {
  909. startsExpr
  910. }),
  911. templateNonTail: createToken("...${", {
  912. beforeExpr,
  913. startsExpr
  914. }),
  915. at: createToken("@"),
  916. hash: createToken("#", {
  917. startsExpr
  918. }),
  919. interpreterDirective: createToken("#!..."),
  920. eq: createToken("=", {
  921. beforeExpr,
  922. isAssign
  923. }),
  924. assign: createToken("_=", {
  925. beforeExpr,
  926. isAssign
  927. }),
  928. slashAssign: createToken("_=", {
  929. beforeExpr,
  930. isAssign
  931. }),
  932. xorAssign: createToken("_=", {
  933. beforeExpr,
  934. isAssign
  935. }),
  936. moduloAssign: createToken("_=", {
  937. beforeExpr,
  938. isAssign
  939. }),
  940. incDec: createToken("++/--", {
  941. prefix,
  942. postfix,
  943. startsExpr
  944. }),
  945. bang: createToken("!", {
  946. beforeExpr,
  947. prefix,
  948. startsExpr
  949. }),
  950. tilde: createToken("~", {
  951. beforeExpr,
  952. prefix,
  953. startsExpr
  954. }),
  955. doubleCaret: createToken("^^", {
  956. startsExpr
  957. }),
  958. doubleAt: createToken("@@", {
  959. startsExpr
  960. }),
  961. pipeline: createBinop("|>", 0),
  962. nullishCoalescing: createBinop("??", 1),
  963. logicalOR: createBinop("||", 1),
  964. logicalAND: createBinop("&&", 2),
  965. bitwiseOR: createBinop("|", 3),
  966. bitwiseXOR: createBinop("^", 4),
  967. bitwiseAND: createBinop("&", 5),
  968. equality: createBinop("==/!=/===/!==", 6),
  969. lt: createBinop("</>/<=/>=", 7),
  970. gt: createBinop("</>/<=/>=", 7),
  971. relational: createBinop("</>/<=/>=", 7),
  972. bitShift: createBinop("<</>>/>>>", 8),
  973. bitShiftL: createBinop("<</>>/>>>", 8),
  974. bitShiftR: createBinop("<</>>/>>>", 8),
  975. plusMin: createToken("+/-", {
  976. beforeExpr,
  977. binop: 9,
  978. prefix,
  979. startsExpr
  980. }),
  981. modulo: createToken("%", {
  982. binop: 10,
  983. startsExpr
  984. }),
  985. star: createToken("*", {
  986. binop: 10
  987. }),
  988. slash: createBinop("/", 10),
  989. exponent: createToken("**", {
  990. beforeExpr,
  991. binop: 11,
  992. rightAssociative: true
  993. }),
  994. _in: createKeyword("in", {
  995. beforeExpr,
  996. binop: 7
  997. }),
  998. _instanceof: createKeyword("instanceof", {
  999. beforeExpr,
  1000. binop: 7
  1001. }),
  1002. _break: createKeyword("break"),
  1003. _case: createKeyword("case", {
  1004. beforeExpr
  1005. }),
  1006. _catch: createKeyword("catch"),
  1007. _continue: createKeyword("continue"),
  1008. _debugger: createKeyword("debugger"),
  1009. _default: createKeyword("default", {
  1010. beforeExpr
  1011. }),
  1012. _else: createKeyword("else", {
  1013. beforeExpr
  1014. }),
  1015. _finally: createKeyword("finally"),
  1016. _function: createKeyword("function", {
  1017. startsExpr
  1018. }),
  1019. _if: createKeyword("if"),
  1020. _return: createKeyword("return", {
  1021. beforeExpr
  1022. }),
  1023. _switch: createKeyword("switch"),
  1024. _throw: createKeyword("throw", {
  1025. beforeExpr,
  1026. prefix,
  1027. startsExpr
  1028. }),
  1029. _try: createKeyword("try"),
  1030. _var: createKeyword("var"),
  1031. _const: createKeyword("const"),
  1032. _with: createKeyword("with"),
  1033. _new: createKeyword("new", {
  1034. beforeExpr,
  1035. startsExpr
  1036. }),
  1037. _this: createKeyword("this", {
  1038. startsExpr
  1039. }),
  1040. _super: createKeyword("super", {
  1041. startsExpr
  1042. }),
  1043. _class: createKeyword("class", {
  1044. startsExpr
  1045. }),
  1046. _extends: createKeyword("extends", {
  1047. beforeExpr
  1048. }),
  1049. _export: createKeyword("export"),
  1050. _import: createKeyword("import", {
  1051. startsExpr
  1052. }),
  1053. _null: createKeyword("null", {
  1054. startsExpr
  1055. }),
  1056. _true: createKeyword("true", {
  1057. startsExpr
  1058. }),
  1059. _false: createKeyword("false", {
  1060. startsExpr
  1061. }),
  1062. _typeof: createKeyword("typeof", {
  1063. beforeExpr,
  1064. prefix,
  1065. startsExpr
  1066. }),
  1067. _void: createKeyword("void", {
  1068. beforeExpr,
  1069. prefix,
  1070. startsExpr
  1071. }),
  1072. _delete: createKeyword("delete", {
  1073. beforeExpr,
  1074. prefix,
  1075. startsExpr
  1076. }),
  1077. _do: createKeyword("do", {
  1078. isLoop,
  1079. beforeExpr
  1080. }),
  1081. _for: createKeyword("for", {
  1082. isLoop
  1083. }),
  1084. _while: createKeyword("while", {
  1085. isLoop
  1086. }),
  1087. _as: createKeywordLike("as", {
  1088. startsExpr
  1089. }),
  1090. _assert: createKeywordLike("assert", {
  1091. startsExpr
  1092. }),
  1093. _async: createKeywordLike("async", {
  1094. startsExpr
  1095. }),
  1096. _await: createKeywordLike("await", {
  1097. startsExpr
  1098. }),
  1099. _from: createKeywordLike("from", {
  1100. startsExpr
  1101. }),
  1102. _get: createKeywordLike("get", {
  1103. startsExpr
  1104. }),
  1105. _let: createKeywordLike("let", {
  1106. startsExpr
  1107. }),
  1108. _meta: createKeywordLike("meta", {
  1109. startsExpr
  1110. }),
  1111. _of: createKeywordLike("of", {
  1112. startsExpr
  1113. }),
  1114. _sent: createKeywordLike("sent", {
  1115. startsExpr
  1116. }),
  1117. _set: createKeywordLike("set", {
  1118. startsExpr
  1119. }),
  1120. _static: createKeywordLike("static", {
  1121. startsExpr
  1122. }),
  1123. _using: createKeywordLike("using", {
  1124. startsExpr
  1125. }),
  1126. _yield: createKeywordLike("yield", {
  1127. startsExpr
  1128. }),
  1129. _asserts: createKeywordLike("asserts", {
  1130. startsExpr
  1131. }),
  1132. _checks: createKeywordLike("checks", {
  1133. startsExpr
  1134. }),
  1135. _exports: createKeywordLike("exports", {
  1136. startsExpr
  1137. }),
  1138. _global: createKeywordLike("global", {
  1139. startsExpr
  1140. }),
  1141. _implements: createKeywordLike("implements", {
  1142. startsExpr
  1143. }),
  1144. _intrinsic: createKeywordLike("intrinsic", {
  1145. startsExpr
  1146. }),
  1147. _infer: createKeywordLike("infer", {
  1148. startsExpr
  1149. }),
  1150. _is: createKeywordLike("is", {
  1151. startsExpr
  1152. }),
  1153. _mixins: createKeywordLike("mixins", {
  1154. startsExpr
  1155. }),
  1156. _proto: createKeywordLike("proto", {
  1157. startsExpr
  1158. }),
  1159. _require: createKeywordLike("require", {
  1160. startsExpr
  1161. }),
  1162. _satisfies: createKeywordLike("satisfies", {
  1163. startsExpr
  1164. }),
  1165. _keyof: createKeywordLike("keyof", {
  1166. startsExpr
  1167. }),
  1168. _readonly: createKeywordLike("readonly", {
  1169. startsExpr
  1170. }),
  1171. _unique: createKeywordLike("unique", {
  1172. startsExpr
  1173. }),
  1174. _abstract: createKeywordLike("abstract", {
  1175. startsExpr
  1176. }),
  1177. _declare: createKeywordLike("declare", {
  1178. startsExpr
  1179. }),
  1180. _enum: createKeywordLike("enum", {
  1181. startsExpr
  1182. }),
  1183. _module: createKeywordLike("module", {
  1184. startsExpr
  1185. }),
  1186. _namespace: createKeywordLike("namespace", {
  1187. startsExpr
  1188. }),
  1189. _interface: createKeywordLike("interface", {
  1190. startsExpr
  1191. }),
  1192. _type: createKeywordLike("type", {
  1193. startsExpr
  1194. }),
  1195. _opaque: createKeywordLike("opaque", {
  1196. startsExpr
  1197. }),
  1198. name: createToken("name", {
  1199. startsExpr
  1200. }),
  1201. string: createToken("string", {
  1202. startsExpr
  1203. }),
  1204. num: createToken("num", {
  1205. startsExpr
  1206. }),
  1207. bigint: createToken("bigint", {
  1208. startsExpr
  1209. }),
  1210. decimal: createToken("decimal", {
  1211. startsExpr
  1212. }),
  1213. regexp: createToken("regexp", {
  1214. startsExpr
  1215. }),
  1216. privateName: createToken("#name", {
  1217. startsExpr
  1218. }),
  1219. eof: createToken("eof"),
  1220. jsxName: createToken("jsxName"),
  1221. jsxText: createToken("jsxText", {
  1222. beforeExpr: true
  1223. }),
  1224. jsxTagStart: createToken("jsxTagStart", {
  1225. startsExpr: true
  1226. }),
  1227. jsxTagEnd: createToken("jsxTagEnd"),
  1228. placeholder: createToken("%%", {
  1229. startsExpr: true
  1230. })
  1231. };
  1232. function tokenIsIdentifier(token) {
  1233. return token >= 93 && token <= 130;
  1234. }
  1235. function tokenKeywordOrIdentifierIsKeyword(token) {
  1236. return token <= 92;
  1237. }
  1238. function tokenIsKeywordOrIdentifier(token) {
  1239. return token >= 58 && token <= 130;
  1240. }
  1241. function tokenIsLiteralPropertyName(token) {
  1242. return token >= 58 && token <= 134;
  1243. }
  1244. function tokenComesBeforeExpression(token) {
  1245. return tokenBeforeExprs[token];
  1246. }
  1247. function tokenCanStartExpression(token) {
  1248. return tokenStartsExprs[token];
  1249. }
  1250. function tokenIsAssignment(token) {
  1251. return token >= 29 && token <= 33;
  1252. }
  1253. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1254. return token >= 127 && token <= 129;
  1255. }
  1256. function tokenIsLoop(token) {
  1257. return token >= 90 && token <= 92;
  1258. }
  1259. function tokenIsKeyword(token) {
  1260. return token >= 58 && token <= 92;
  1261. }
  1262. function tokenIsOperator(token) {
  1263. return token >= 39 && token <= 59;
  1264. }
  1265. function tokenIsPostfix(token) {
  1266. return token === 34;
  1267. }
  1268. function tokenIsPrefix(token) {
  1269. return tokenPrefixes[token];
  1270. }
  1271. function tokenIsTSTypeOperator(token) {
  1272. return token >= 119 && token <= 121;
  1273. }
  1274. function tokenIsTSDeclarationStart(token) {
  1275. return token >= 122 && token <= 128;
  1276. }
  1277. function tokenLabelName(token) {
  1278. return tokenLabels[token];
  1279. }
  1280. function tokenOperatorPrecedence(token) {
  1281. return tokenBinops[token];
  1282. }
  1283. function tokenIsRightAssociative(token) {
  1284. return token === 57;
  1285. }
  1286. function tokenIsTemplate(token) {
  1287. return token >= 24 && token <= 25;
  1288. }
  1289. function getExportedToken(token) {
  1290. return tokenTypes[token];
  1291. }
  1292. {
  1293. tokenTypes[8].updateContext = context => {
  1294. context.pop();
  1295. };
  1296. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1297. context.push(types.brace);
  1298. };
  1299. tokenTypes[22].updateContext = context => {
  1300. if (context[context.length - 1] === types.template) {
  1301. context.pop();
  1302. } else {
  1303. context.push(types.template);
  1304. }
  1305. };
  1306. tokenTypes[140].updateContext = context => {
  1307. context.push(types.j_expr, types.j_oTag);
  1308. };
  1309. }
  1310. 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";
  1311. 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\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  1312. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1313. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1314. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1315. 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, 3104, 541, 1507, 4938, 6, 4191];
  1316. 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];
  1317. function isInAstralSet(code, set) {
  1318. let pos = 0x10000;
  1319. for (let i = 0, length = set.length; i < length; i += 2) {
  1320. pos += set[i];
  1321. if (pos > code) return false;
  1322. pos += set[i + 1];
  1323. if (pos >= code) return true;
  1324. }
  1325. return false;
  1326. }
  1327. function isIdentifierStart(code) {
  1328. if (code < 65) return code === 36;
  1329. if (code <= 90) return true;
  1330. if (code < 97) return code === 95;
  1331. if (code <= 122) return true;
  1332. if (code <= 0xffff) {
  1333. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1334. }
  1335. return isInAstralSet(code, astralIdentifierStartCodes);
  1336. }
  1337. function isIdentifierChar(code) {
  1338. if (code < 48) return code === 36;
  1339. if (code < 58) return true;
  1340. if (code < 65) return false;
  1341. if (code <= 90) return true;
  1342. if (code < 97) return code === 95;
  1343. if (code <= 122) return true;
  1344. if (code <= 0xffff) {
  1345. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1346. }
  1347. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1348. }
  1349. const reservedWords = {
  1350. 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"],
  1351. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1352. strictBind: ["eval", "arguments"]
  1353. };
  1354. const keywords = new Set(reservedWords.keyword);
  1355. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1356. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1357. function isReservedWord(word, inModule) {
  1358. return inModule && word === "await" || word === "enum";
  1359. }
  1360. function isStrictReservedWord(word, inModule) {
  1361. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1362. }
  1363. function isStrictBindOnlyReservedWord(word) {
  1364. return reservedWordsStrictBindSet.has(word);
  1365. }
  1366. function isStrictBindReservedWord(word, inModule) {
  1367. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1368. }
  1369. function isKeyword(word) {
  1370. return keywords.has(word);
  1371. }
  1372. function isIteratorStart(current, next, next2) {
  1373. return current === 64 && next === 64 && isIdentifierStart(next2);
  1374. }
  1375. 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"]);
  1376. function canBeReservedWord(word) {
  1377. return reservedWordLikeSet.has(word);
  1378. }
  1379. const SCOPE_OTHER = 0b000000000,
  1380. SCOPE_PROGRAM = 0b000000001,
  1381. SCOPE_FUNCTION = 0b000000010,
  1382. SCOPE_ARROW = 0b000000100,
  1383. SCOPE_SIMPLE_CATCH = 0b000001000,
  1384. SCOPE_SUPER = 0b000010000,
  1385. SCOPE_DIRECT_SUPER = 0b000100000,
  1386. SCOPE_CLASS = 0b001000000,
  1387. SCOPE_STATIC_BLOCK = 0b010000000,
  1388. SCOPE_TS_MODULE = 0b100000000,
  1389. SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_STATIC_BLOCK | SCOPE_TS_MODULE;
  1390. const BIND_KIND_VALUE = 0b0000000000001,
  1391. BIND_KIND_TYPE = 0b0000000000010,
  1392. BIND_SCOPE_VAR = 0b0000000000100,
  1393. BIND_SCOPE_LEXICAL = 0b0000000001000,
  1394. BIND_SCOPE_FUNCTION = 0b0000000010000,
  1395. BIND_FLAGS_NONE = 0b00000001000000,
  1396. BIND_FLAGS_CLASS = 0b00000010000000,
  1397. BIND_FLAGS_TS_ENUM = 0b00000100000000,
  1398. BIND_FLAGS_TS_CONST_ENUM = 0b00001000000000,
  1399. BIND_FLAGS_TS_EXPORT_ONLY = 0b00010000000000,
  1400. BIND_FLAGS_FLOW_DECLARE_FN = 0b00100000000000,
  1401. BIND_FLAGS_TS_IMPORT = 0b01000000000000,
  1402. BIND_FLAGS_NO_LET_IN_LEXICAL = 0b10000000000000;
  1403. const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS | BIND_FLAGS_NO_LET_IN_LEXICAL,
  1404. BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | BIND_FLAGS_NO_LET_IN_LEXICAL,
  1405. BIND_CATCH_PARAM = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0,
  1406. BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0,
  1407. BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0,
  1408. BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS,
  1409. BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0,
  1410. BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM | BIND_FLAGS_NO_LET_IN_LEXICAL,
  1411. BIND_TS_AMBIENT = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1412. BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE,
  1413. BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE,
  1414. BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM,
  1415. BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1416. BIND_TS_TYPE_IMPORT = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_TS_IMPORT,
  1417. BIND_FLOW_DECLARE_FN = BIND_FLAGS_FLOW_DECLARE_FN;
  1418. const CLASS_ELEMENT_FLAG_STATIC = 0b100,
  1419. CLASS_ELEMENT_KIND_GETTER = 0b010,
  1420. CLASS_ELEMENT_KIND_SETTER = 0b001,
  1421. CLASS_ELEMENT_KIND_ACCESSOR = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_KIND_SETTER;
  1422. const CLASS_ELEMENT_STATIC_GETTER = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_FLAG_STATIC,
  1423. CLASS_ELEMENT_STATIC_SETTER = CLASS_ELEMENT_KIND_SETTER | CLASS_ELEMENT_FLAG_STATIC,
  1424. CLASS_ELEMENT_INSTANCE_GETTER = CLASS_ELEMENT_KIND_GETTER,
  1425. CLASS_ELEMENT_INSTANCE_SETTER = CLASS_ELEMENT_KIND_SETTER,
  1426. CLASS_ELEMENT_OTHER = 0;
  1427. class Scope {
  1428. constructor(flags) {
  1429. this.var = new Set();
  1430. this.lexical = new Set();
  1431. this.functions = new Set();
  1432. this.flags = flags;
  1433. }
  1434. }
  1435. class ScopeHandler {
  1436. constructor(parser, inModule) {
  1437. this.parser = void 0;
  1438. this.scopeStack = [];
  1439. this.inModule = void 0;
  1440. this.undefinedExports = new Map();
  1441. this.parser = parser;
  1442. this.inModule = inModule;
  1443. }
  1444. get inTopLevel() {
  1445. return (this.currentScope().flags & SCOPE_PROGRAM) > 0;
  1446. }
  1447. get inFunction() {
  1448. return (this.currentVarScopeFlags() & SCOPE_FUNCTION) > 0;
  1449. }
  1450. get allowSuper() {
  1451. return (this.currentThisScopeFlags() & SCOPE_SUPER) > 0;
  1452. }
  1453. get allowDirectSuper() {
  1454. return (this.currentThisScopeFlags() & SCOPE_DIRECT_SUPER) > 0;
  1455. }
  1456. get inClass() {
  1457. return (this.currentThisScopeFlags() & SCOPE_CLASS) > 0;
  1458. }
  1459. get inClassAndNotInNonArrowFunction() {
  1460. const flags = this.currentThisScopeFlags();
  1461. return (flags & SCOPE_CLASS) > 0 && (flags & SCOPE_FUNCTION) === 0;
  1462. }
  1463. get inStaticBlock() {
  1464. for (let i = this.scopeStack.length - 1;; i--) {
  1465. const {
  1466. flags
  1467. } = this.scopeStack[i];
  1468. if (flags & SCOPE_STATIC_BLOCK) {
  1469. return true;
  1470. }
  1471. if (flags & (SCOPE_VAR | SCOPE_CLASS)) {
  1472. return false;
  1473. }
  1474. }
  1475. }
  1476. get inNonArrowFunction() {
  1477. return (this.currentThisScopeFlags() & SCOPE_FUNCTION) > 0;
  1478. }
  1479. get treatFunctionsAsVar() {
  1480. return this.treatFunctionsAsVarInScope(this.currentScope());
  1481. }
  1482. createScope(flags) {
  1483. return new Scope(flags);
  1484. }
  1485. enter(flags) {
  1486. this.scopeStack.push(this.createScope(flags));
  1487. }
  1488. exit() {
  1489. const scope = this.scopeStack.pop();
  1490. return scope.flags;
  1491. }
  1492. treatFunctionsAsVarInScope(scope) {
  1493. return !!(scope.flags & (SCOPE_FUNCTION | SCOPE_STATIC_BLOCK) || !this.parser.inModule && scope.flags & SCOPE_PROGRAM);
  1494. }
  1495. declareName(name, bindingType, loc) {
  1496. let scope = this.currentScope();
  1497. if (bindingType & BIND_SCOPE_LEXICAL || bindingType & BIND_SCOPE_FUNCTION) {
  1498. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1499. if (bindingType & BIND_SCOPE_FUNCTION) {
  1500. scope.functions.add(name);
  1501. } else {
  1502. scope.lexical.add(name);
  1503. }
  1504. if (bindingType & BIND_SCOPE_LEXICAL) {
  1505. this.maybeExportDefined(scope, name);
  1506. }
  1507. } else if (bindingType & BIND_SCOPE_VAR) {
  1508. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1509. scope = this.scopeStack[i];
  1510. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1511. scope.var.add(name);
  1512. this.maybeExportDefined(scope, name);
  1513. if (scope.flags & SCOPE_VAR) break;
  1514. }
  1515. }
  1516. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  1517. this.undefinedExports.delete(name);
  1518. }
  1519. }
  1520. maybeExportDefined(scope, name) {
  1521. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  1522. this.undefinedExports.delete(name);
  1523. }
  1524. }
  1525. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1526. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1527. this.parser.raise(Errors.VarRedeclaration, {
  1528. at: loc,
  1529. identifierName: name
  1530. });
  1531. }
  1532. }
  1533. isRedeclaredInScope(scope, name, bindingType) {
  1534. if (!(bindingType & BIND_KIND_VALUE)) return false;
  1535. if (bindingType & BIND_SCOPE_LEXICAL) {
  1536. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  1537. }
  1538. if (bindingType & BIND_SCOPE_FUNCTION) {
  1539. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  1540. }
  1541. return scope.lexical.has(name) && !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  1542. }
  1543. checkLocalExport(id) {
  1544. const {
  1545. name
  1546. } = id;
  1547. const topLevelScope = this.scopeStack[0];
  1548. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
  1549. this.undefinedExports.set(name, id.loc.start);
  1550. }
  1551. }
  1552. currentScope() {
  1553. return this.scopeStack[this.scopeStack.length - 1];
  1554. }
  1555. currentVarScopeFlags() {
  1556. for (let i = this.scopeStack.length - 1;; i--) {
  1557. const {
  1558. flags
  1559. } = this.scopeStack[i];
  1560. if (flags & SCOPE_VAR) {
  1561. return flags;
  1562. }
  1563. }
  1564. }
  1565. currentThisScopeFlags() {
  1566. for (let i = this.scopeStack.length - 1;; i--) {
  1567. const {
  1568. flags
  1569. } = this.scopeStack[i];
  1570. if (flags & (SCOPE_VAR | SCOPE_CLASS) && !(flags & SCOPE_ARROW)) {
  1571. return flags;
  1572. }
  1573. }
  1574. }
  1575. }
  1576. class FlowScope extends Scope {
  1577. constructor(...args) {
  1578. super(...args);
  1579. this.declareFunctions = new Set();
  1580. }
  1581. }
  1582. class FlowScopeHandler extends ScopeHandler {
  1583. createScope(flags) {
  1584. return new FlowScope(flags);
  1585. }
  1586. declareName(name, bindingType, loc) {
  1587. const scope = this.currentScope();
  1588. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  1589. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1590. this.maybeExportDefined(scope, name);
  1591. scope.declareFunctions.add(name);
  1592. return;
  1593. }
  1594. super.declareName(name, bindingType, loc);
  1595. }
  1596. isRedeclaredInScope(scope, name, bindingType) {
  1597. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1598. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  1599. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  1600. }
  1601. return false;
  1602. }
  1603. checkLocalExport(id) {
  1604. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1605. super.checkLocalExport(id);
  1606. }
  1607. }
  1608. }
  1609. class BaseParser {
  1610. constructor() {
  1611. this.sawUnambiguousESM = false;
  1612. this.ambiguousScriptDifferentAst = false;
  1613. }
  1614. hasPlugin(pluginConfig) {
  1615. if (typeof pluginConfig === "string") {
  1616. return this.plugins.has(pluginConfig);
  1617. } else {
  1618. const [pluginName, pluginOptions] = pluginConfig;
  1619. if (!this.hasPlugin(pluginName)) {
  1620. return false;
  1621. }
  1622. const actualOptions = this.plugins.get(pluginName);
  1623. for (const key of Object.keys(pluginOptions)) {
  1624. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1625. return false;
  1626. }
  1627. }
  1628. return true;
  1629. }
  1630. }
  1631. getPluginOption(plugin, name) {
  1632. var _this$plugins$get;
  1633. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1634. }
  1635. }
  1636. function setTrailingComments(node, comments) {
  1637. if (node.trailingComments === undefined) {
  1638. node.trailingComments = comments;
  1639. } else {
  1640. node.trailingComments.unshift(...comments);
  1641. }
  1642. }
  1643. function setLeadingComments(node, comments) {
  1644. if (node.leadingComments === undefined) {
  1645. node.leadingComments = comments;
  1646. } else {
  1647. node.leadingComments.unshift(...comments);
  1648. }
  1649. }
  1650. function setInnerComments(node, comments) {
  1651. if (node.innerComments === undefined) {
  1652. node.innerComments = comments;
  1653. } else {
  1654. node.innerComments.unshift(...comments);
  1655. }
  1656. }
  1657. function adjustInnerComments(node, elements, commentWS) {
  1658. let lastElement = null;
  1659. let i = elements.length;
  1660. while (lastElement === null && i > 0) {
  1661. lastElement = elements[--i];
  1662. }
  1663. if (lastElement === null || lastElement.start > commentWS.start) {
  1664. setInnerComments(node, commentWS.comments);
  1665. } else {
  1666. setTrailingComments(lastElement, commentWS.comments);
  1667. }
  1668. }
  1669. class CommentsParser extends BaseParser {
  1670. addComment(comment) {
  1671. if (this.filename) comment.loc.filename = this.filename;
  1672. this.state.comments.push(comment);
  1673. }
  1674. processComment(node) {
  1675. const {
  1676. commentStack
  1677. } = this.state;
  1678. const commentStackLength = commentStack.length;
  1679. if (commentStackLength === 0) return;
  1680. let i = commentStackLength - 1;
  1681. const lastCommentWS = commentStack[i];
  1682. if (lastCommentWS.start === node.end) {
  1683. lastCommentWS.leadingNode = node;
  1684. i--;
  1685. }
  1686. const {
  1687. start: nodeStart
  1688. } = node;
  1689. for (; i >= 0; i--) {
  1690. const commentWS = commentStack[i];
  1691. const commentEnd = commentWS.end;
  1692. if (commentEnd > nodeStart) {
  1693. commentWS.containingNode = node;
  1694. this.finalizeComment(commentWS);
  1695. commentStack.splice(i, 1);
  1696. } else {
  1697. if (commentEnd === nodeStart) {
  1698. commentWS.trailingNode = node;
  1699. }
  1700. break;
  1701. }
  1702. }
  1703. }
  1704. finalizeComment(commentWS) {
  1705. const {
  1706. comments
  1707. } = commentWS;
  1708. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1709. if (commentWS.leadingNode !== null) {
  1710. setTrailingComments(commentWS.leadingNode, comments);
  1711. }
  1712. if (commentWS.trailingNode !== null) {
  1713. setLeadingComments(commentWS.trailingNode, comments);
  1714. }
  1715. } else {
  1716. const {
  1717. containingNode: node,
  1718. start: commentStart
  1719. } = commentWS;
  1720. if (this.input.charCodeAt(commentStart - 1) === 44) {
  1721. switch (node.type) {
  1722. case "ObjectExpression":
  1723. case "ObjectPattern":
  1724. case "RecordExpression":
  1725. adjustInnerComments(node, node.properties, commentWS);
  1726. break;
  1727. case "CallExpression":
  1728. case "OptionalCallExpression":
  1729. adjustInnerComments(node, node.arguments, commentWS);
  1730. break;
  1731. case "FunctionDeclaration":
  1732. case "FunctionExpression":
  1733. case "ArrowFunctionExpression":
  1734. case "ObjectMethod":
  1735. case "ClassMethod":
  1736. case "ClassPrivateMethod":
  1737. adjustInnerComments(node, node.params, commentWS);
  1738. break;
  1739. case "ArrayExpression":
  1740. case "ArrayPattern":
  1741. case "TupleExpression":
  1742. adjustInnerComments(node, node.elements, commentWS);
  1743. break;
  1744. case "ExportNamedDeclaration":
  1745. case "ImportDeclaration":
  1746. adjustInnerComments(node, node.specifiers, commentWS);
  1747. break;
  1748. default:
  1749. {
  1750. setInnerComments(node, comments);
  1751. }
  1752. }
  1753. } else {
  1754. setInnerComments(node, comments);
  1755. }
  1756. }
  1757. }
  1758. finalizeRemainingComments() {
  1759. const {
  1760. commentStack
  1761. } = this.state;
  1762. for (let i = commentStack.length - 1; i >= 0; i--) {
  1763. this.finalizeComment(commentStack[i]);
  1764. }
  1765. this.state.commentStack = [];
  1766. }
  1767. resetPreviousNodeTrailingComments(node) {
  1768. const {
  1769. commentStack
  1770. } = this.state;
  1771. const {
  1772. length
  1773. } = commentStack;
  1774. if (length === 0) return;
  1775. const commentWS = commentStack[length - 1];
  1776. if (commentWS.leadingNode === node) {
  1777. commentWS.leadingNode = null;
  1778. }
  1779. }
  1780. resetPreviousIdentifierLeadingComments(node) {
  1781. const {
  1782. commentStack
  1783. } = this.state;
  1784. const {
  1785. length
  1786. } = commentStack;
  1787. if (length === 0) return;
  1788. if (commentStack[length - 1].trailingNode === node) {
  1789. commentStack[length - 1].trailingNode = null;
  1790. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  1791. commentStack[length - 2].trailingNode = null;
  1792. }
  1793. }
  1794. takeSurroundingComments(node, start, end) {
  1795. const {
  1796. commentStack
  1797. } = this.state;
  1798. const commentStackLength = commentStack.length;
  1799. if (commentStackLength === 0) return;
  1800. let i = commentStackLength - 1;
  1801. for (; i >= 0; i--) {
  1802. const commentWS = commentStack[i];
  1803. const commentEnd = commentWS.end;
  1804. const commentStart = commentWS.start;
  1805. if (commentStart === end) {
  1806. commentWS.leadingNode = node;
  1807. } else if (commentEnd === start) {
  1808. commentWS.trailingNode = node;
  1809. } else if (commentEnd < start) {
  1810. break;
  1811. }
  1812. }
  1813. }
  1814. }
  1815. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  1816. const lineBreakG = new RegExp(lineBreak.source, "g");
  1817. function isNewLine(code) {
  1818. switch (code) {
  1819. case 10:
  1820. case 13:
  1821. case 8232:
  1822. case 8233:
  1823. return true;
  1824. default:
  1825. return false;
  1826. }
  1827. }
  1828. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1829. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1830. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  1831. function isWhitespace(code) {
  1832. switch (code) {
  1833. case 0x0009:
  1834. case 0x000b:
  1835. case 0x000c:
  1836. case 32:
  1837. case 160:
  1838. case 5760:
  1839. case 0x2000:
  1840. case 0x2001:
  1841. case 0x2002:
  1842. case 0x2003:
  1843. case 0x2004:
  1844. case 0x2005:
  1845. case 0x2006:
  1846. case 0x2007:
  1847. case 0x2008:
  1848. case 0x2009:
  1849. case 0x200a:
  1850. case 0x202f:
  1851. case 0x205f:
  1852. case 0x3000:
  1853. case 0xfeff:
  1854. return true;
  1855. default:
  1856. return false;
  1857. }
  1858. }
  1859. class State {
  1860. constructor() {
  1861. this.strict = void 0;
  1862. this.curLine = void 0;
  1863. this.lineStart = void 0;
  1864. this.startLoc = void 0;
  1865. this.endLoc = void 0;
  1866. this.errors = [];
  1867. this.potentialArrowAt = -1;
  1868. this.noArrowAt = [];
  1869. this.noArrowParamsConversionAt = [];
  1870. this.maybeInArrowParameters = false;
  1871. this.inType = false;
  1872. this.noAnonFunctionType = false;
  1873. this.hasFlowComment = false;
  1874. this.isAmbientContext = false;
  1875. this.inAbstractClass = false;
  1876. this.inDisallowConditionalTypesContext = false;
  1877. this.topicContext = {
  1878. maxNumOfResolvableTopics: 0,
  1879. maxTopicIndex: null
  1880. };
  1881. this.soloAwait = false;
  1882. this.inFSharpPipelineDirectBody = false;
  1883. this.labels = [];
  1884. this.comments = [];
  1885. this.commentStack = [];
  1886. this.pos = 0;
  1887. this.type = 137;
  1888. this.value = null;
  1889. this.start = 0;
  1890. this.end = 0;
  1891. this.lastTokEndLoc = null;
  1892. this.lastTokStartLoc = null;
  1893. this.lastTokStart = 0;
  1894. this.context = [types.brace];
  1895. this.canStartJSXElement = true;
  1896. this.containsEsc = false;
  1897. this.firstInvalidTemplateEscapePos = null;
  1898. this.strictErrors = new Map();
  1899. this.tokensLength = 0;
  1900. }
  1901. init({
  1902. strictMode,
  1903. sourceType,
  1904. startLine,
  1905. startColumn
  1906. }) {
  1907. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1908. this.curLine = startLine;
  1909. this.lineStart = -startColumn;
  1910. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  1911. }
  1912. curPosition() {
  1913. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  1914. }
  1915. clone(skipArrays) {
  1916. const state = new State();
  1917. const keys = Object.keys(this);
  1918. for (let i = 0, length = keys.length; i < length; i++) {
  1919. const key = keys[i];
  1920. let val = this[key];
  1921. if (!skipArrays && Array.isArray(val)) {
  1922. val = val.slice();
  1923. }
  1924. state[key] = val;
  1925. }
  1926. return state;
  1927. }
  1928. }
  1929. var _isDigit = function isDigit(code) {
  1930. return code >= 48 && code <= 57;
  1931. };
  1932. const forbiddenNumericSeparatorSiblings = {
  1933. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  1934. hex: new Set([46, 88, 95, 120])
  1935. };
  1936. const isAllowedNumericSeparatorSibling = {
  1937. bin: ch => ch === 48 || ch === 49,
  1938. oct: ch => ch >= 48 && ch <= 55,
  1939. dec: ch => ch >= 48 && ch <= 57,
  1940. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  1941. };
  1942. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  1943. const initialPos = pos;
  1944. const initialLineStart = lineStart;
  1945. const initialCurLine = curLine;
  1946. let out = "";
  1947. let firstInvalidLoc = null;
  1948. let chunkStart = pos;
  1949. const {
  1950. length
  1951. } = input;
  1952. for (;;) {
  1953. if (pos >= length) {
  1954. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1955. out += input.slice(chunkStart, pos);
  1956. break;
  1957. }
  1958. const ch = input.charCodeAt(pos);
  1959. if (isStringEnd(type, ch, input, pos)) {
  1960. out += input.slice(chunkStart, pos);
  1961. break;
  1962. }
  1963. if (ch === 92) {
  1964. out += input.slice(chunkStart, pos);
  1965. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  1966. if (res.ch === null && !firstInvalidLoc) {
  1967. firstInvalidLoc = {
  1968. pos,
  1969. lineStart,
  1970. curLine
  1971. };
  1972. } else {
  1973. out += res.ch;
  1974. }
  1975. ({
  1976. pos,
  1977. lineStart,
  1978. curLine
  1979. } = res);
  1980. chunkStart = pos;
  1981. } else if (ch === 8232 || ch === 8233) {
  1982. ++pos;
  1983. ++curLine;
  1984. lineStart = pos;
  1985. } else if (ch === 10 || ch === 13) {
  1986. if (type === "template") {
  1987. out += input.slice(chunkStart, pos) + "\n";
  1988. ++pos;
  1989. if (ch === 13 && input.charCodeAt(pos) === 10) {
  1990. ++pos;
  1991. }
  1992. ++curLine;
  1993. chunkStart = lineStart = pos;
  1994. } else {
  1995. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1996. }
  1997. } else {
  1998. ++pos;
  1999. }
  2000. }
  2001. return {
  2002. pos,
  2003. str: out,
  2004. firstInvalidLoc,
  2005. lineStart,
  2006. curLine,
  2007. containsInvalid: !!firstInvalidLoc
  2008. };
  2009. }
  2010. function isStringEnd(type, ch, input, pos) {
  2011. if (type === "template") {
  2012. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2013. }
  2014. return ch === (type === "double" ? 34 : 39);
  2015. }
  2016. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2017. const throwOnInvalid = !inTemplate;
  2018. pos++;
  2019. const res = ch => ({
  2020. pos,
  2021. ch,
  2022. lineStart,
  2023. curLine
  2024. });
  2025. const ch = input.charCodeAt(pos++);
  2026. switch (ch) {
  2027. case 110:
  2028. return res("\n");
  2029. case 114:
  2030. return res("\r");
  2031. case 120:
  2032. {
  2033. let code;
  2034. ({
  2035. code,
  2036. pos
  2037. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2038. return res(code === null ? null : String.fromCharCode(code));
  2039. }
  2040. case 117:
  2041. {
  2042. let code;
  2043. ({
  2044. code,
  2045. pos
  2046. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2047. return res(code === null ? null : String.fromCodePoint(code));
  2048. }
  2049. case 116:
  2050. return res("\t");
  2051. case 98:
  2052. return res("\b");
  2053. case 118:
  2054. return res("\u000b");
  2055. case 102:
  2056. return res("\f");
  2057. case 13:
  2058. if (input.charCodeAt(pos) === 10) {
  2059. ++pos;
  2060. }
  2061. case 10:
  2062. lineStart = pos;
  2063. ++curLine;
  2064. case 8232:
  2065. case 8233:
  2066. return res("");
  2067. case 56:
  2068. case 57:
  2069. if (inTemplate) {
  2070. return res(null);
  2071. } else {
  2072. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2073. }
  2074. default:
  2075. if (ch >= 48 && ch <= 55) {
  2076. const startPos = pos - 1;
  2077. const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
  2078. let octalStr = match[0];
  2079. let octal = parseInt(octalStr, 8);
  2080. if (octal > 255) {
  2081. octalStr = octalStr.slice(0, -1);
  2082. octal = parseInt(octalStr, 8);
  2083. }
  2084. pos += octalStr.length - 1;
  2085. const next = input.charCodeAt(pos);
  2086. if (octalStr !== "0" || next === 56 || next === 57) {
  2087. if (inTemplate) {
  2088. return res(null);
  2089. } else {
  2090. errors.strictNumericEscape(startPos, lineStart, curLine);
  2091. }
  2092. }
  2093. return res(String.fromCharCode(octal));
  2094. }
  2095. return res(String.fromCharCode(ch));
  2096. }
  2097. }
  2098. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2099. const initialPos = pos;
  2100. let n;
  2101. ({
  2102. n,
  2103. pos
  2104. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2105. if (n === null) {
  2106. if (throwOnInvalid) {
  2107. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2108. } else {
  2109. pos = initialPos - 1;
  2110. }
  2111. }
  2112. return {
  2113. code: n,
  2114. pos
  2115. };
  2116. }
  2117. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2118. const start = pos;
  2119. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2120. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2121. let invalid = false;
  2122. let total = 0;
  2123. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2124. const code = input.charCodeAt(pos);
  2125. let val;
  2126. if (code === 95 && allowNumSeparator !== "bail") {
  2127. const prev = input.charCodeAt(pos - 1);
  2128. const next = input.charCodeAt(pos + 1);
  2129. if (!allowNumSeparator) {
  2130. if (bailOnError) return {
  2131. n: null,
  2132. pos
  2133. };
  2134. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2135. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2136. if (bailOnError) return {
  2137. n: null,
  2138. pos
  2139. };
  2140. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2141. }
  2142. ++pos;
  2143. continue;
  2144. }
  2145. if (code >= 97) {
  2146. val = code - 97 + 10;
  2147. } else if (code >= 65) {
  2148. val = code - 65 + 10;
  2149. } else if (_isDigit(code)) {
  2150. val = code - 48;
  2151. } else {
  2152. val = Infinity;
  2153. }
  2154. if (val >= radix) {
  2155. if (val <= 9 && bailOnError) {
  2156. return {
  2157. n: null,
  2158. pos
  2159. };
  2160. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2161. val = 0;
  2162. } else if (forceLen) {
  2163. val = 0;
  2164. invalid = true;
  2165. } else {
  2166. break;
  2167. }
  2168. }
  2169. ++pos;
  2170. total = total * radix + val;
  2171. }
  2172. if (pos === start || len != null && pos - start !== len || invalid) {
  2173. return {
  2174. n: null,
  2175. pos
  2176. };
  2177. }
  2178. return {
  2179. n: total,
  2180. pos
  2181. };
  2182. }
  2183. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2184. const ch = input.charCodeAt(pos);
  2185. let code;
  2186. if (ch === 123) {
  2187. ++pos;
  2188. ({
  2189. code,
  2190. pos
  2191. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2192. ++pos;
  2193. if (code !== null && code > 0x10ffff) {
  2194. if (throwOnInvalid) {
  2195. errors.invalidCodePoint(pos, lineStart, curLine);
  2196. } else {
  2197. return {
  2198. code: null,
  2199. pos
  2200. };
  2201. }
  2202. }
  2203. } else {
  2204. ({
  2205. code,
  2206. pos
  2207. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2208. }
  2209. return {
  2210. code,
  2211. pos
  2212. };
  2213. }
  2214. const _excluded = ["at"],
  2215. _excluded2 = ["at"];
  2216. function buildPosition(pos, lineStart, curLine) {
  2217. return new Position(curLine, pos - lineStart, pos);
  2218. }
  2219. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2220. class Token {
  2221. constructor(state) {
  2222. this.type = state.type;
  2223. this.value = state.value;
  2224. this.start = state.start;
  2225. this.end = state.end;
  2226. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2227. }
  2228. }
  2229. class Tokenizer extends CommentsParser {
  2230. constructor(options, input) {
  2231. super();
  2232. this.isLookahead = void 0;
  2233. this.tokens = [];
  2234. this.errorHandlers_readInt = {
  2235. invalidDigit: (pos, lineStart, curLine, radix) => {
  2236. if (!this.options.errorRecovery) return false;
  2237. this.raise(Errors.InvalidDigit, {
  2238. at: buildPosition(pos, lineStart, curLine),
  2239. radix
  2240. });
  2241. return true;
  2242. },
  2243. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2244. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2245. };
  2246. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2247. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2248. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2249. });
  2250. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2251. strictNumericEscape: (pos, lineStart, curLine) => {
  2252. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2253. at: buildPosition(pos, lineStart, curLine)
  2254. });
  2255. },
  2256. unterminated: (pos, lineStart, curLine) => {
  2257. throw this.raise(Errors.UnterminatedString, {
  2258. at: buildPosition(pos - 1, lineStart, curLine)
  2259. });
  2260. }
  2261. });
  2262. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2263. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2264. unterminated: (pos, lineStart, curLine) => {
  2265. throw this.raise(Errors.UnterminatedTemplate, {
  2266. at: buildPosition(pos, lineStart, curLine)
  2267. });
  2268. }
  2269. });
  2270. this.state = new State();
  2271. this.state.init(options);
  2272. this.input = input;
  2273. this.length = input.length;
  2274. this.isLookahead = false;
  2275. }
  2276. pushToken(token) {
  2277. this.tokens.length = this.state.tokensLength;
  2278. this.tokens.push(token);
  2279. ++this.state.tokensLength;
  2280. }
  2281. next() {
  2282. this.checkKeywordEscapes();
  2283. if (this.options.tokens) {
  2284. this.pushToken(new Token(this.state));
  2285. }
  2286. this.state.lastTokStart = this.state.start;
  2287. this.state.lastTokEndLoc = this.state.endLoc;
  2288. this.state.lastTokStartLoc = this.state.startLoc;
  2289. this.nextToken();
  2290. }
  2291. eat(type) {
  2292. if (this.match(type)) {
  2293. this.next();
  2294. return true;
  2295. } else {
  2296. return false;
  2297. }
  2298. }
  2299. match(type) {
  2300. return this.state.type === type;
  2301. }
  2302. createLookaheadState(state) {
  2303. return {
  2304. pos: state.pos,
  2305. value: null,
  2306. type: state.type,
  2307. start: state.start,
  2308. end: state.end,
  2309. context: [this.curContext()],
  2310. inType: state.inType,
  2311. startLoc: state.startLoc,
  2312. lastTokEndLoc: state.lastTokEndLoc,
  2313. curLine: state.curLine,
  2314. lineStart: state.lineStart,
  2315. curPosition: state.curPosition
  2316. };
  2317. }
  2318. lookahead() {
  2319. const old = this.state;
  2320. this.state = this.createLookaheadState(old);
  2321. this.isLookahead = true;
  2322. this.nextToken();
  2323. this.isLookahead = false;
  2324. const curr = this.state;
  2325. this.state = old;
  2326. return curr;
  2327. }
  2328. nextTokenStart() {
  2329. return this.nextTokenStartSince(this.state.pos);
  2330. }
  2331. nextTokenStartSince(pos) {
  2332. skipWhiteSpace.lastIndex = pos;
  2333. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2334. }
  2335. lookaheadCharCode() {
  2336. return this.input.charCodeAt(this.nextTokenStart());
  2337. }
  2338. nextTokenInLineStart() {
  2339. return this.nextTokenInLineStartSince(this.state.pos);
  2340. }
  2341. nextTokenInLineStartSince(pos) {
  2342. skipWhiteSpaceInLine.lastIndex = pos;
  2343. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2344. }
  2345. lookaheadInLineCharCode() {
  2346. return this.input.charCodeAt(this.nextTokenInLineStart());
  2347. }
  2348. codePointAtPos(pos) {
  2349. let cp = this.input.charCodeAt(pos);
  2350. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2351. const trail = this.input.charCodeAt(pos);
  2352. if ((trail & 0xfc00) === 0xdc00) {
  2353. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2354. }
  2355. }
  2356. return cp;
  2357. }
  2358. setStrict(strict) {
  2359. this.state.strict = strict;
  2360. if (strict) {
  2361. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
  2362. at
  2363. }));
  2364. this.state.strictErrors.clear();
  2365. }
  2366. }
  2367. curContext() {
  2368. return this.state.context[this.state.context.length - 1];
  2369. }
  2370. nextToken() {
  2371. this.skipSpace();
  2372. this.state.start = this.state.pos;
  2373. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2374. if (this.state.pos >= this.length) {
  2375. this.finishToken(137);
  2376. return;
  2377. }
  2378. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2379. }
  2380. skipBlockComment(commentEnd) {
  2381. let startLoc;
  2382. if (!this.isLookahead) startLoc = this.state.curPosition();
  2383. const start = this.state.pos;
  2384. const end = this.input.indexOf(commentEnd, start + 2);
  2385. if (end === -1) {
  2386. throw this.raise(Errors.UnterminatedComment, {
  2387. at: this.state.curPosition()
  2388. });
  2389. }
  2390. this.state.pos = end + commentEnd.length;
  2391. lineBreakG.lastIndex = start + 2;
  2392. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2393. ++this.state.curLine;
  2394. this.state.lineStart = lineBreakG.lastIndex;
  2395. }
  2396. if (this.isLookahead) return;
  2397. const comment = {
  2398. type: "CommentBlock",
  2399. value: this.input.slice(start + 2, end),
  2400. start,
  2401. end: end + commentEnd.length,
  2402. loc: new SourceLocation(startLoc, this.state.curPosition())
  2403. };
  2404. if (this.options.tokens) this.pushToken(comment);
  2405. return comment;
  2406. }
  2407. skipLineComment(startSkip) {
  2408. const start = this.state.pos;
  2409. let startLoc;
  2410. if (!this.isLookahead) startLoc = this.state.curPosition();
  2411. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2412. if (this.state.pos < this.length) {
  2413. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2414. ch = this.input.charCodeAt(this.state.pos);
  2415. }
  2416. }
  2417. if (this.isLookahead) return;
  2418. const end = this.state.pos;
  2419. const value = this.input.slice(start + startSkip, end);
  2420. const comment = {
  2421. type: "CommentLine",
  2422. value,
  2423. start,
  2424. end,
  2425. loc: new SourceLocation(startLoc, this.state.curPosition())
  2426. };
  2427. if (this.options.tokens) this.pushToken(comment);
  2428. return comment;
  2429. }
  2430. skipSpace() {
  2431. const spaceStart = this.state.pos;
  2432. const comments = [];
  2433. loop: while (this.state.pos < this.length) {
  2434. const ch = this.input.charCodeAt(this.state.pos);
  2435. switch (ch) {
  2436. case 32:
  2437. case 160:
  2438. case 9:
  2439. ++this.state.pos;
  2440. break;
  2441. case 13:
  2442. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2443. ++this.state.pos;
  2444. }
  2445. case 10:
  2446. case 8232:
  2447. case 8233:
  2448. ++this.state.pos;
  2449. ++this.state.curLine;
  2450. this.state.lineStart = this.state.pos;
  2451. break;
  2452. case 47:
  2453. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2454. case 42:
  2455. {
  2456. const comment = this.skipBlockComment("*/");
  2457. if (comment !== undefined) {
  2458. this.addComment(comment);
  2459. if (this.options.attachComment) comments.push(comment);
  2460. }
  2461. break;
  2462. }
  2463. case 47:
  2464. {
  2465. const comment = this.skipLineComment(2);
  2466. if (comment !== undefined) {
  2467. this.addComment(comment);
  2468. if (this.options.attachComment) comments.push(comment);
  2469. }
  2470. break;
  2471. }
  2472. default:
  2473. break loop;
  2474. }
  2475. break;
  2476. default:
  2477. if (isWhitespace(ch)) {
  2478. ++this.state.pos;
  2479. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  2480. const pos = this.state.pos;
  2481. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2482. const comment = this.skipLineComment(3);
  2483. if (comment !== undefined) {
  2484. this.addComment(comment);
  2485. if (this.options.attachComment) comments.push(comment);
  2486. }
  2487. } else {
  2488. break loop;
  2489. }
  2490. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  2491. const pos = this.state.pos;
  2492. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2493. const comment = this.skipLineComment(4);
  2494. if (comment !== undefined) {
  2495. this.addComment(comment);
  2496. if (this.options.attachComment) comments.push(comment);
  2497. }
  2498. } else {
  2499. break loop;
  2500. }
  2501. } else {
  2502. break loop;
  2503. }
  2504. }
  2505. }
  2506. if (comments.length > 0) {
  2507. const end = this.state.pos;
  2508. const commentWhitespace = {
  2509. start: spaceStart,
  2510. end,
  2511. comments,
  2512. leadingNode: null,
  2513. trailingNode: null,
  2514. containingNode: null
  2515. };
  2516. this.state.commentStack.push(commentWhitespace);
  2517. }
  2518. }
  2519. finishToken(type, val) {
  2520. this.state.end = this.state.pos;
  2521. this.state.endLoc = this.state.curPosition();
  2522. const prevType = this.state.type;
  2523. this.state.type = type;
  2524. this.state.value = val;
  2525. if (!this.isLookahead) {
  2526. this.updateContext(prevType);
  2527. }
  2528. }
  2529. replaceToken(type) {
  2530. this.state.type = type;
  2531. this.updateContext();
  2532. }
  2533. readToken_numberSign() {
  2534. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2535. return;
  2536. }
  2537. const nextPos = this.state.pos + 1;
  2538. const next = this.codePointAtPos(nextPos);
  2539. if (next >= 48 && next <= 57) {
  2540. throw this.raise(Errors.UnexpectedDigitAfterHash, {
  2541. at: this.state.curPosition()
  2542. });
  2543. }
  2544. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2545. this.expectPlugin("recordAndTuple");
  2546. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2547. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
  2548. at: this.state.curPosition()
  2549. });
  2550. }
  2551. this.state.pos += 2;
  2552. if (next === 123) {
  2553. this.finishToken(7);
  2554. } else {
  2555. this.finishToken(1);
  2556. }
  2557. } else if (isIdentifierStart(next)) {
  2558. ++this.state.pos;
  2559. this.finishToken(136, this.readWord1(next));
  2560. } else if (next === 92) {
  2561. ++this.state.pos;
  2562. this.finishToken(136, this.readWord1());
  2563. } else {
  2564. this.finishOp(27, 1);
  2565. }
  2566. }
  2567. readToken_dot() {
  2568. const next = this.input.charCodeAt(this.state.pos + 1);
  2569. if (next >= 48 && next <= 57) {
  2570. this.readNumber(true);
  2571. return;
  2572. }
  2573. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2574. this.state.pos += 3;
  2575. this.finishToken(21);
  2576. } else {
  2577. ++this.state.pos;
  2578. this.finishToken(16);
  2579. }
  2580. }
  2581. readToken_slash() {
  2582. const next = this.input.charCodeAt(this.state.pos + 1);
  2583. if (next === 61) {
  2584. this.finishOp(31, 2);
  2585. } else {
  2586. this.finishOp(56, 1);
  2587. }
  2588. }
  2589. readToken_interpreter() {
  2590. if (this.state.pos !== 0 || this.length < 2) return false;
  2591. let ch = this.input.charCodeAt(this.state.pos + 1);
  2592. if (ch !== 33) return false;
  2593. const start = this.state.pos;
  2594. this.state.pos += 1;
  2595. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2596. ch = this.input.charCodeAt(this.state.pos);
  2597. }
  2598. const value = this.input.slice(start + 2, this.state.pos);
  2599. this.finishToken(28, value);
  2600. return true;
  2601. }
  2602. readToken_mult_modulo(code) {
  2603. let type = code === 42 ? 55 : 54;
  2604. let width = 1;
  2605. let next = this.input.charCodeAt(this.state.pos + 1);
  2606. if (code === 42 && next === 42) {
  2607. width++;
  2608. next = this.input.charCodeAt(this.state.pos + 2);
  2609. type = 57;
  2610. }
  2611. if (next === 61 && !this.state.inType) {
  2612. width++;
  2613. type = code === 37 ? 33 : 30;
  2614. }
  2615. this.finishOp(type, width);
  2616. }
  2617. readToken_pipe_amp(code) {
  2618. const next = this.input.charCodeAt(this.state.pos + 1);
  2619. if (next === code) {
  2620. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2621. this.finishOp(30, 3);
  2622. } else {
  2623. this.finishOp(code === 124 ? 41 : 42, 2);
  2624. }
  2625. return;
  2626. }
  2627. if (code === 124) {
  2628. if (next === 62) {
  2629. this.finishOp(39, 2);
  2630. return;
  2631. }
  2632. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2633. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2634. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
  2635. at: this.state.curPosition()
  2636. });
  2637. }
  2638. this.state.pos += 2;
  2639. this.finishToken(9);
  2640. return;
  2641. }
  2642. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2643. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2644. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
  2645. at: this.state.curPosition()
  2646. });
  2647. }
  2648. this.state.pos += 2;
  2649. this.finishToken(4);
  2650. return;
  2651. }
  2652. }
  2653. if (next === 61) {
  2654. this.finishOp(30, 2);
  2655. return;
  2656. }
  2657. this.finishOp(code === 124 ? 43 : 45, 1);
  2658. }
  2659. readToken_caret() {
  2660. const next = this.input.charCodeAt(this.state.pos + 1);
  2661. if (next === 61 && !this.state.inType) {
  2662. this.finishOp(32, 2);
  2663. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2664. proposal: "hack",
  2665. topicToken: "^^"
  2666. }])) {
  2667. this.finishOp(37, 2);
  2668. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2669. if (lookaheadCh === 94) {
  2670. this.unexpected();
  2671. }
  2672. } else {
  2673. this.finishOp(44, 1);
  2674. }
  2675. }
  2676. readToken_atSign() {
  2677. const next = this.input.charCodeAt(this.state.pos + 1);
  2678. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2679. proposal: "hack",
  2680. topicToken: "@@"
  2681. }])) {
  2682. this.finishOp(38, 2);
  2683. } else {
  2684. this.finishOp(26, 1);
  2685. }
  2686. }
  2687. readToken_plus_min(code) {
  2688. const next = this.input.charCodeAt(this.state.pos + 1);
  2689. if (next === code) {
  2690. this.finishOp(34, 2);
  2691. return;
  2692. }
  2693. if (next === 61) {
  2694. this.finishOp(30, 2);
  2695. } else {
  2696. this.finishOp(53, 1);
  2697. }
  2698. }
  2699. readToken_lt() {
  2700. const {
  2701. pos
  2702. } = this.state;
  2703. const next = this.input.charCodeAt(pos + 1);
  2704. if (next === 60) {
  2705. if (this.input.charCodeAt(pos + 2) === 61) {
  2706. this.finishOp(30, 3);
  2707. return;
  2708. }
  2709. this.finishOp(51, 2);
  2710. return;
  2711. }
  2712. if (next === 61) {
  2713. this.finishOp(49, 2);
  2714. return;
  2715. }
  2716. this.finishOp(47, 1);
  2717. }
  2718. readToken_gt() {
  2719. const {
  2720. pos
  2721. } = this.state;
  2722. const next = this.input.charCodeAt(pos + 1);
  2723. if (next === 62) {
  2724. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2725. if (this.input.charCodeAt(pos + size) === 61) {
  2726. this.finishOp(30, size + 1);
  2727. return;
  2728. }
  2729. this.finishOp(52, size);
  2730. return;
  2731. }
  2732. if (next === 61) {
  2733. this.finishOp(49, 2);
  2734. return;
  2735. }
  2736. this.finishOp(48, 1);
  2737. }
  2738. readToken_eq_excl(code) {
  2739. const next = this.input.charCodeAt(this.state.pos + 1);
  2740. if (next === 61) {
  2741. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2742. return;
  2743. }
  2744. if (code === 61 && next === 62) {
  2745. this.state.pos += 2;
  2746. this.finishToken(19);
  2747. return;
  2748. }
  2749. this.finishOp(code === 61 ? 29 : 35, 1);
  2750. }
  2751. readToken_question() {
  2752. const next = this.input.charCodeAt(this.state.pos + 1);
  2753. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2754. if (next === 63) {
  2755. if (next2 === 61) {
  2756. this.finishOp(30, 3);
  2757. } else {
  2758. this.finishOp(40, 2);
  2759. }
  2760. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2761. this.state.pos += 2;
  2762. this.finishToken(18);
  2763. } else {
  2764. ++this.state.pos;
  2765. this.finishToken(17);
  2766. }
  2767. }
  2768. getTokenFromCode(code) {
  2769. switch (code) {
  2770. case 46:
  2771. this.readToken_dot();
  2772. return;
  2773. case 40:
  2774. ++this.state.pos;
  2775. this.finishToken(10);
  2776. return;
  2777. case 41:
  2778. ++this.state.pos;
  2779. this.finishToken(11);
  2780. return;
  2781. case 59:
  2782. ++this.state.pos;
  2783. this.finishToken(13);
  2784. return;
  2785. case 44:
  2786. ++this.state.pos;
  2787. this.finishToken(12);
  2788. return;
  2789. case 91:
  2790. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2791. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2792. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
  2793. at: this.state.curPosition()
  2794. });
  2795. }
  2796. this.state.pos += 2;
  2797. this.finishToken(2);
  2798. } else {
  2799. ++this.state.pos;
  2800. this.finishToken(0);
  2801. }
  2802. return;
  2803. case 93:
  2804. ++this.state.pos;
  2805. this.finishToken(3);
  2806. return;
  2807. case 123:
  2808. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2809. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2810. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
  2811. at: this.state.curPosition()
  2812. });
  2813. }
  2814. this.state.pos += 2;
  2815. this.finishToken(6);
  2816. } else {
  2817. ++this.state.pos;
  2818. this.finishToken(5);
  2819. }
  2820. return;
  2821. case 125:
  2822. ++this.state.pos;
  2823. this.finishToken(8);
  2824. return;
  2825. case 58:
  2826. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2827. this.finishOp(15, 2);
  2828. } else {
  2829. ++this.state.pos;
  2830. this.finishToken(14);
  2831. }
  2832. return;
  2833. case 63:
  2834. this.readToken_question();
  2835. return;
  2836. case 96:
  2837. this.readTemplateToken();
  2838. return;
  2839. case 48:
  2840. {
  2841. const next = this.input.charCodeAt(this.state.pos + 1);
  2842. if (next === 120 || next === 88) {
  2843. this.readRadixNumber(16);
  2844. return;
  2845. }
  2846. if (next === 111 || next === 79) {
  2847. this.readRadixNumber(8);
  2848. return;
  2849. }
  2850. if (next === 98 || next === 66) {
  2851. this.readRadixNumber(2);
  2852. return;
  2853. }
  2854. }
  2855. case 49:
  2856. case 50:
  2857. case 51:
  2858. case 52:
  2859. case 53:
  2860. case 54:
  2861. case 55:
  2862. case 56:
  2863. case 57:
  2864. this.readNumber(false);
  2865. return;
  2866. case 34:
  2867. case 39:
  2868. this.readString(code);
  2869. return;
  2870. case 47:
  2871. this.readToken_slash();
  2872. return;
  2873. case 37:
  2874. case 42:
  2875. this.readToken_mult_modulo(code);
  2876. return;
  2877. case 124:
  2878. case 38:
  2879. this.readToken_pipe_amp(code);
  2880. return;
  2881. case 94:
  2882. this.readToken_caret();
  2883. return;
  2884. case 43:
  2885. case 45:
  2886. this.readToken_plus_min(code);
  2887. return;
  2888. case 60:
  2889. this.readToken_lt();
  2890. return;
  2891. case 62:
  2892. this.readToken_gt();
  2893. return;
  2894. case 61:
  2895. case 33:
  2896. this.readToken_eq_excl(code);
  2897. return;
  2898. case 126:
  2899. this.finishOp(36, 1);
  2900. return;
  2901. case 64:
  2902. this.readToken_atSign();
  2903. return;
  2904. case 35:
  2905. this.readToken_numberSign();
  2906. return;
  2907. case 92:
  2908. this.readWord();
  2909. return;
  2910. default:
  2911. if (isIdentifierStart(code)) {
  2912. this.readWord(code);
  2913. return;
  2914. }
  2915. }
  2916. throw this.raise(Errors.InvalidOrUnexpectedToken, {
  2917. at: this.state.curPosition(),
  2918. unexpected: String.fromCodePoint(code)
  2919. });
  2920. }
  2921. finishOp(type, size) {
  2922. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2923. this.state.pos += size;
  2924. this.finishToken(type, str);
  2925. }
  2926. readRegexp() {
  2927. const startLoc = this.state.startLoc;
  2928. const start = this.state.start + 1;
  2929. let escaped, inClass;
  2930. let {
  2931. pos
  2932. } = this.state;
  2933. for (;; ++pos) {
  2934. if (pos >= this.length) {
  2935. throw this.raise(Errors.UnterminatedRegExp, {
  2936. at: createPositionWithColumnOffset(startLoc, 1)
  2937. });
  2938. }
  2939. const ch = this.input.charCodeAt(pos);
  2940. if (isNewLine(ch)) {
  2941. throw this.raise(Errors.UnterminatedRegExp, {
  2942. at: createPositionWithColumnOffset(startLoc, 1)
  2943. });
  2944. }
  2945. if (escaped) {
  2946. escaped = false;
  2947. } else {
  2948. if (ch === 91) {
  2949. inClass = true;
  2950. } else if (ch === 93 && inClass) {
  2951. inClass = false;
  2952. } else if (ch === 47 && !inClass) {
  2953. break;
  2954. }
  2955. escaped = ch === 92;
  2956. }
  2957. }
  2958. const content = this.input.slice(start, pos);
  2959. ++pos;
  2960. let mods = "";
  2961. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  2962. while (pos < this.length) {
  2963. const cp = this.codePointAtPos(pos);
  2964. const char = String.fromCharCode(cp);
  2965. if (VALID_REGEX_FLAGS.has(cp)) {
  2966. if (cp === 118) {
  2967. if (mods.includes("u")) {
  2968. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2969. at: nextPos()
  2970. });
  2971. }
  2972. } else if (cp === 117) {
  2973. if (mods.includes("v")) {
  2974. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2975. at: nextPos()
  2976. });
  2977. }
  2978. }
  2979. if (mods.includes(char)) {
  2980. this.raise(Errors.DuplicateRegExpFlags, {
  2981. at: nextPos()
  2982. });
  2983. }
  2984. } else if (isIdentifierChar(cp) || cp === 92) {
  2985. this.raise(Errors.MalformedRegExpFlags, {
  2986. at: nextPos()
  2987. });
  2988. } else {
  2989. break;
  2990. }
  2991. ++pos;
  2992. mods += char;
  2993. }
  2994. this.state.pos = pos;
  2995. this.finishToken(135, {
  2996. pattern: content,
  2997. flags: mods
  2998. });
  2999. }
  3000. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  3001. const {
  3002. n,
  3003. pos
  3004. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  3005. this.state.pos = pos;
  3006. return n;
  3007. }
  3008. readRadixNumber(radix) {
  3009. const startLoc = this.state.curPosition();
  3010. let isBigInt = false;
  3011. this.state.pos += 2;
  3012. const val = this.readInt(radix);
  3013. if (val == null) {
  3014. this.raise(Errors.InvalidDigit, {
  3015. at: createPositionWithColumnOffset(startLoc, 2),
  3016. radix
  3017. });
  3018. }
  3019. const next = this.input.charCodeAt(this.state.pos);
  3020. if (next === 110) {
  3021. ++this.state.pos;
  3022. isBigInt = true;
  3023. } else if (next === 109) {
  3024. throw this.raise(Errors.InvalidDecimal, {
  3025. at: startLoc
  3026. });
  3027. }
  3028. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3029. throw this.raise(Errors.NumberIdentifier, {
  3030. at: this.state.curPosition()
  3031. });
  3032. }
  3033. if (isBigInt) {
  3034. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  3035. this.finishToken(133, str);
  3036. return;
  3037. }
  3038. this.finishToken(132, val);
  3039. }
  3040. readNumber(startsWithDot) {
  3041. const start = this.state.pos;
  3042. const startLoc = this.state.curPosition();
  3043. let isFloat = false;
  3044. let isBigInt = false;
  3045. let isDecimal = false;
  3046. let hasExponent = false;
  3047. let isOctal = false;
  3048. if (!startsWithDot && this.readInt(10) === null) {
  3049. this.raise(Errors.InvalidNumber, {
  3050. at: this.state.curPosition()
  3051. });
  3052. }
  3053. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3054. if (hasLeadingZero) {
  3055. const integer = this.input.slice(start, this.state.pos);
  3056. this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
  3057. at: startLoc
  3058. });
  3059. if (!this.state.strict) {
  3060. const underscorePos = integer.indexOf("_");
  3061. if (underscorePos > 0) {
  3062. this.raise(Errors.ZeroDigitNumericSeparator, {
  3063. at: createPositionWithColumnOffset(startLoc, underscorePos)
  3064. });
  3065. }
  3066. }
  3067. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3068. }
  3069. let next = this.input.charCodeAt(this.state.pos);
  3070. if (next === 46 && !isOctal) {
  3071. ++this.state.pos;
  3072. this.readInt(10);
  3073. isFloat = true;
  3074. next = this.input.charCodeAt(this.state.pos);
  3075. }
  3076. if ((next === 69 || next === 101) && !isOctal) {
  3077. next = this.input.charCodeAt(++this.state.pos);
  3078. if (next === 43 || next === 45) {
  3079. ++this.state.pos;
  3080. }
  3081. if (this.readInt(10) === null) {
  3082. this.raise(Errors.InvalidOrMissingExponent, {
  3083. at: startLoc
  3084. });
  3085. }
  3086. isFloat = true;
  3087. hasExponent = true;
  3088. next = this.input.charCodeAt(this.state.pos);
  3089. }
  3090. if (next === 110) {
  3091. if (isFloat || hasLeadingZero) {
  3092. this.raise(Errors.InvalidBigIntLiteral, {
  3093. at: startLoc
  3094. });
  3095. }
  3096. ++this.state.pos;
  3097. isBigInt = true;
  3098. }
  3099. if (next === 109) {
  3100. this.expectPlugin("decimal", this.state.curPosition());
  3101. if (hasExponent || hasLeadingZero) {
  3102. this.raise(Errors.InvalidDecimal, {
  3103. at: startLoc
  3104. });
  3105. }
  3106. ++this.state.pos;
  3107. isDecimal = true;
  3108. }
  3109. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3110. throw this.raise(Errors.NumberIdentifier, {
  3111. at: this.state.curPosition()
  3112. });
  3113. }
  3114. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3115. if (isBigInt) {
  3116. this.finishToken(133, str);
  3117. return;
  3118. }
  3119. if (isDecimal) {
  3120. this.finishToken(134, str);
  3121. return;
  3122. }
  3123. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3124. this.finishToken(132, val);
  3125. }
  3126. readCodePoint(throwOnInvalid) {
  3127. const {
  3128. code,
  3129. pos
  3130. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3131. this.state.pos = pos;
  3132. return code;
  3133. }
  3134. readString(quote) {
  3135. const {
  3136. str,
  3137. pos,
  3138. curLine,
  3139. lineStart
  3140. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3141. this.state.pos = pos + 1;
  3142. this.state.lineStart = lineStart;
  3143. this.state.curLine = curLine;
  3144. this.finishToken(131, str);
  3145. }
  3146. readTemplateContinuation() {
  3147. if (!this.match(8)) {
  3148. this.unexpected(null, 8);
  3149. }
  3150. this.state.pos--;
  3151. this.readTemplateToken();
  3152. }
  3153. readTemplateToken() {
  3154. const opening = this.input[this.state.pos];
  3155. const {
  3156. str,
  3157. firstInvalidLoc,
  3158. pos,
  3159. curLine,
  3160. lineStart
  3161. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3162. this.state.pos = pos + 1;
  3163. this.state.lineStart = lineStart;
  3164. this.state.curLine = curLine;
  3165. if (firstInvalidLoc) {
  3166. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3167. }
  3168. if (this.input.codePointAt(pos) === 96) {
  3169. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3170. } else {
  3171. this.state.pos++;
  3172. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3173. }
  3174. }
  3175. recordStrictModeErrors(toParseError, {
  3176. at
  3177. }) {
  3178. const index = at.index;
  3179. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3180. this.raise(toParseError, {
  3181. at
  3182. });
  3183. } else {
  3184. this.state.strictErrors.set(index, [toParseError, at]);
  3185. }
  3186. }
  3187. readWord1(firstCode) {
  3188. this.state.containsEsc = false;
  3189. let word = "";
  3190. const start = this.state.pos;
  3191. let chunkStart = this.state.pos;
  3192. if (firstCode !== undefined) {
  3193. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3194. }
  3195. while (this.state.pos < this.length) {
  3196. const ch = this.codePointAtPos(this.state.pos);
  3197. if (isIdentifierChar(ch)) {
  3198. this.state.pos += ch <= 0xffff ? 1 : 2;
  3199. } else if (ch === 92) {
  3200. this.state.containsEsc = true;
  3201. word += this.input.slice(chunkStart, this.state.pos);
  3202. const escStart = this.state.curPosition();
  3203. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3204. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3205. this.raise(Errors.MissingUnicodeEscape, {
  3206. at: this.state.curPosition()
  3207. });
  3208. chunkStart = this.state.pos - 1;
  3209. continue;
  3210. }
  3211. ++this.state.pos;
  3212. const esc = this.readCodePoint(true);
  3213. if (esc !== null) {
  3214. if (!identifierCheck(esc)) {
  3215. this.raise(Errors.EscapedCharNotAnIdentifier, {
  3216. at: escStart
  3217. });
  3218. }
  3219. word += String.fromCodePoint(esc);
  3220. }
  3221. chunkStart = this.state.pos;
  3222. } else {
  3223. break;
  3224. }
  3225. }
  3226. return word + this.input.slice(chunkStart, this.state.pos);
  3227. }
  3228. readWord(firstCode) {
  3229. const word = this.readWord1(firstCode);
  3230. const type = keywords$1.get(word);
  3231. if (type !== undefined) {
  3232. this.finishToken(type, tokenLabelName(type));
  3233. } else {
  3234. this.finishToken(130, word);
  3235. }
  3236. }
  3237. checkKeywordEscapes() {
  3238. const {
  3239. type
  3240. } = this.state;
  3241. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3242. this.raise(Errors.InvalidEscapedReservedWord, {
  3243. at: this.state.startLoc,
  3244. reservedWord: tokenLabelName(type)
  3245. });
  3246. }
  3247. }
  3248. raise(toParseError, raiseProperties) {
  3249. const {
  3250. at
  3251. } = raiseProperties,
  3252. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
  3253. const loc = at instanceof Position ? at : at.loc.start;
  3254. const error = toParseError({
  3255. loc,
  3256. details
  3257. });
  3258. if (!this.options.errorRecovery) throw error;
  3259. if (!this.isLookahead) this.state.errors.push(error);
  3260. return error;
  3261. }
  3262. raiseOverwrite(toParseError, raiseProperties) {
  3263. const {
  3264. at
  3265. } = raiseProperties,
  3266. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
  3267. const loc = at instanceof Position ? at : at.loc.start;
  3268. const pos = loc.index;
  3269. const errors = this.state.errors;
  3270. for (let i = errors.length - 1; i >= 0; i--) {
  3271. const error = errors[i];
  3272. if (error.loc.index === pos) {
  3273. return errors[i] = toParseError({
  3274. loc,
  3275. details
  3276. });
  3277. }
  3278. if (error.loc.index < pos) break;
  3279. }
  3280. return this.raise(toParseError, raiseProperties);
  3281. }
  3282. updateContext(prevType) {}
  3283. unexpected(loc, type) {
  3284. throw this.raise(Errors.UnexpectedToken, {
  3285. expected: type ? tokenLabelName(type) : null,
  3286. at: loc != null ? loc : this.state.startLoc
  3287. });
  3288. }
  3289. expectPlugin(pluginName, loc) {
  3290. if (this.hasPlugin(pluginName)) {
  3291. return true;
  3292. }
  3293. throw this.raise(Errors.MissingPlugin, {
  3294. at: loc != null ? loc : this.state.startLoc,
  3295. missingPlugin: [pluginName]
  3296. });
  3297. }
  3298. expectOnePlugin(pluginNames) {
  3299. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3300. throw this.raise(Errors.MissingOneOfPlugins, {
  3301. at: this.state.startLoc,
  3302. missingPlugin: pluginNames
  3303. });
  3304. }
  3305. }
  3306. errorBuilder(error) {
  3307. return (pos, lineStart, curLine) => {
  3308. this.raise(error, {
  3309. at: buildPosition(pos, lineStart, curLine)
  3310. });
  3311. };
  3312. }
  3313. }
  3314. class ClassScope {
  3315. constructor() {
  3316. this.privateNames = new Set();
  3317. this.loneAccessors = new Map();
  3318. this.undefinedPrivateNames = new Map();
  3319. }
  3320. }
  3321. class ClassScopeHandler {
  3322. constructor(parser) {
  3323. this.parser = void 0;
  3324. this.stack = [];
  3325. this.undefinedPrivateNames = new Map();
  3326. this.parser = parser;
  3327. }
  3328. current() {
  3329. return this.stack[this.stack.length - 1];
  3330. }
  3331. enter() {
  3332. this.stack.push(new ClassScope());
  3333. }
  3334. exit() {
  3335. const oldClassScope = this.stack.pop();
  3336. const current = this.current();
  3337. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3338. if (current) {
  3339. if (!current.undefinedPrivateNames.has(name)) {
  3340. current.undefinedPrivateNames.set(name, loc);
  3341. }
  3342. } else {
  3343. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3344. at: loc,
  3345. identifierName: name
  3346. });
  3347. }
  3348. }
  3349. }
  3350. declarePrivateName(name, elementType, loc) {
  3351. const {
  3352. privateNames,
  3353. loneAccessors,
  3354. undefinedPrivateNames
  3355. } = this.current();
  3356. let redefined = privateNames.has(name);
  3357. if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) {
  3358. const accessor = redefined && loneAccessors.get(name);
  3359. if (accessor) {
  3360. const oldStatic = accessor & CLASS_ELEMENT_FLAG_STATIC;
  3361. const newStatic = elementType & CLASS_ELEMENT_FLAG_STATIC;
  3362. const oldKind = accessor & CLASS_ELEMENT_KIND_ACCESSOR;
  3363. const newKind = elementType & CLASS_ELEMENT_KIND_ACCESSOR;
  3364. redefined = oldKind === newKind || oldStatic !== newStatic;
  3365. if (!redefined) loneAccessors.delete(name);
  3366. } else if (!redefined) {
  3367. loneAccessors.set(name, elementType);
  3368. }
  3369. }
  3370. if (redefined) {
  3371. this.parser.raise(Errors.PrivateNameRedeclaration, {
  3372. at: loc,
  3373. identifierName: name
  3374. });
  3375. }
  3376. privateNames.add(name);
  3377. undefinedPrivateNames.delete(name);
  3378. }
  3379. usePrivateName(name, loc) {
  3380. let classScope;
  3381. for (classScope of this.stack) {
  3382. if (classScope.privateNames.has(name)) return;
  3383. }
  3384. if (classScope) {
  3385. classScope.undefinedPrivateNames.set(name, loc);
  3386. } else {
  3387. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3388. at: loc,
  3389. identifierName: name
  3390. });
  3391. }
  3392. }
  3393. }
  3394. const kExpression = 0,
  3395. kMaybeArrowParameterDeclaration = 1,
  3396. kMaybeAsyncArrowParameterDeclaration = 2,
  3397. kParameterDeclaration = 3;
  3398. class ExpressionScope {
  3399. constructor(type = kExpression) {
  3400. this.type = void 0;
  3401. this.type = type;
  3402. }
  3403. canBeArrowParameterDeclaration() {
  3404. return this.type === kMaybeAsyncArrowParameterDeclaration || this.type === kMaybeArrowParameterDeclaration;
  3405. }
  3406. isCertainlyParameterDeclaration() {
  3407. return this.type === kParameterDeclaration;
  3408. }
  3409. }
  3410. class ArrowHeadParsingScope extends ExpressionScope {
  3411. constructor(type) {
  3412. super(type);
  3413. this.declarationErrors = new Map();
  3414. }
  3415. recordDeclarationError(ParsingErrorClass, {
  3416. at
  3417. }) {
  3418. const index = at.index;
  3419. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3420. }
  3421. clearDeclarationError(index) {
  3422. this.declarationErrors.delete(index);
  3423. }
  3424. iterateErrors(iterator) {
  3425. this.declarationErrors.forEach(iterator);
  3426. }
  3427. }
  3428. class ExpressionScopeHandler {
  3429. constructor(parser) {
  3430. this.parser = void 0;
  3431. this.stack = [new ExpressionScope()];
  3432. this.parser = parser;
  3433. }
  3434. enter(scope) {
  3435. this.stack.push(scope);
  3436. }
  3437. exit() {
  3438. this.stack.pop();
  3439. }
  3440. recordParameterInitializerError(toParseError, {
  3441. at: node
  3442. }) {
  3443. const origin = {
  3444. at: node.loc.start
  3445. };
  3446. const {
  3447. stack
  3448. } = this;
  3449. let i = stack.length - 1;
  3450. let scope = stack[i];
  3451. while (!scope.isCertainlyParameterDeclaration()) {
  3452. if (scope.canBeArrowParameterDeclaration()) {
  3453. scope.recordDeclarationError(toParseError, origin);
  3454. } else {
  3455. return;
  3456. }
  3457. scope = stack[--i];
  3458. }
  3459. this.parser.raise(toParseError, origin);
  3460. }
  3461. recordArrowParameterBindingError(error, {
  3462. at: node
  3463. }) {
  3464. const {
  3465. stack
  3466. } = this;
  3467. const scope = stack[stack.length - 1];
  3468. const origin = {
  3469. at: node.loc.start
  3470. };
  3471. if (scope.isCertainlyParameterDeclaration()) {
  3472. this.parser.raise(error, origin);
  3473. } else if (scope.canBeArrowParameterDeclaration()) {
  3474. scope.recordDeclarationError(error, origin);
  3475. } else {
  3476. return;
  3477. }
  3478. }
  3479. recordAsyncArrowParametersError({
  3480. at
  3481. }) {
  3482. const {
  3483. stack
  3484. } = this;
  3485. let i = stack.length - 1;
  3486. let scope = stack[i];
  3487. while (scope.canBeArrowParameterDeclaration()) {
  3488. if (scope.type === kMaybeAsyncArrowParameterDeclaration) {
  3489. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
  3490. at
  3491. });
  3492. }
  3493. scope = stack[--i];
  3494. }
  3495. }
  3496. validateAsPattern() {
  3497. const {
  3498. stack
  3499. } = this;
  3500. const currentScope = stack[stack.length - 1];
  3501. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3502. currentScope.iterateErrors(([toParseError, loc]) => {
  3503. this.parser.raise(toParseError, {
  3504. at: loc
  3505. });
  3506. let i = stack.length - 2;
  3507. let scope = stack[i];
  3508. while (scope.canBeArrowParameterDeclaration()) {
  3509. scope.clearDeclarationError(loc.index);
  3510. scope = stack[--i];
  3511. }
  3512. });
  3513. }
  3514. }
  3515. function newParameterDeclarationScope() {
  3516. return new ExpressionScope(kParameterDeclaration);
  3517. }
  3518. function newArrowHeadScope() {
  3519. return new ArrowHeadParsingScope(kMaybeArrowParameterDeclaration);
  3520. }
  3521. function newAsyncArrowScope() {
  3522. return new ArrowHeadParsingScope(kMaybeAsyncArrowParameterDeclaration);
  3523. }
  3524. function newExpressionScope() {
  3525. return new ExpressionScope();
  3526. }
  3527. const PARAM = 0b0000,
  3528. PARAM_YIELD = 0b0001,
  3529. PARAM_AWAIT = 0b0010,
  3530. PARAM_RETURN = 0b0100,
  3531. PARAM_IN = 0b1000;
  3532. class ProductionParameterHandler {
  3533. constructor() {
  3534. this.stacks = [];
  3535. }
  3536. enter(flags) {
  3537. this.stacks.push(flags);
  3538. }
  3539. exit() {
  3540. this.stacks.pop();
  3541. }
  3542. currentFlags() {
  3543. return this.stacks[this.stacks.length - 1];
  3544. }
  3545. get hasAwait() {
  3546. return (this.currentFlags() & PARAM_AWAIT) > 0;
  3547. }
  3548. get hasYield() {
  3549. return (this.currentFlags() & PARAM_YIELD) > 0;
  3550. }
  3551. get hasReturn() {
  3552. return (this.currentFlags() & PARAM_RETURN) > 0;
  3553. }
  3554. get hasIn() {
  3555. return (this.currentFlags() & PARAM_IN) > 0;
  3556. }
  3557. }
  3558. function functionFlags(isAsync, isGenerator) {
  3559. return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
  3560. }
  3561. class UtilParser extends Tokenizer {
  3562. addExtra(node, key, value, enumerable = true) {
  3563. if (!node) return;
  3564. const extra = node.extra = node.extra || {};
  3565. if (enumerable) {
  3566. extra[key] = value;
  3567. } else {
  3568. Object.defineProperty(extra, key, {
  3569. enumerable,
  3570. value
  3571. });
  3572. }
  3573. }
  3574. isContextual(token) {
  3575. return this.state.type === token && !this.state.containsEsc;
  3576. }
  3577. isUnparsedContextual(nameStart, name) {
  3578. const nameEnd = nameStart + name.length;
  3579. if (this.input.slice(nameStart, nameEnd) === name) {
  3580. const nextCh = this.input.charCodeAt(nameEnd);
  3581. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3582. }
  3583. return false;
  3584. }
  3585. isLookaheadContextual(name) {
  3586. const next = this.nextTokenStart();
  3587. return this.isUnparsedContextual(next, name);
  3588. }
  3589. eatContextual(token) {
  3590. if (this.isContextual(token)) {
  3591. this.next();
  3592. return true;
  3593. }
  3594. return false;
  3595. }
  3596. expectContextual(token, toParseError) {
  3597. if (!this.eatContextual(token)) {
  3598. if (toParseError != null) {
  3599. throw this.raise(toParseError, {
  3600. at: this.state.startLoc
  3601. });
  3602. }
  3603. this.unexpected(null, token);
  3604. }
  3605. }
  3606. canInsertSemicolon() {
  3607. return this.match(137) || this.match(8) || this.hasPrecedingLineBreak();
  3608. }
  3609. hasPrecedingLineBreak() {
  3610. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  3611. }
  3612. hasFollowingLineBreak() {
  3613. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  3614. return skipWhiteSpaceToLineBreak.test(this.input);
  3615. }
  3616. isLineTerminator() {
  3617. return this.eat(13) || this.canInsertSemicolon();
  3618. }
  3619. semicolon(allowAsi = true) {
  3620. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3621. this.raise(Errors.MissingSemicolon, {
  3622. at: this.state.lastTokEndLoc
  3623. });
  3624. }
  3625. expect(type, loc) {
  3626. this.eat(type) || this.unexpected(loc, type);
  3627. }
  3628. tryParse(fn, oldState = this.state.clone()) {
  3629. const abortSignal = {
  3630. node: null
  3631. };
  3632. try {
  3633. const node = fn((node = null) => {
  3634. abortSignal.node = node;
  3635. throw abortSignal;
  3636. });
  3637. if (this.state.errors.length > oldState.errors.length) {
  3638. const failState = this.state;
  3639. this.state = oldState;
  3640. this.state.tokensLength = failState.tokensLength;
  3641. return {
  3642. node,
  3643. error: failState.errors[oldState.errors.length],
  3644. thrown: false,
  3645. aborted: false,
  3646. failState
  3647. };
  3648. }
  3649. return {
  3650. node,
  3651. error: null,
  3652. thrown: false,
  3653. aborted: false,
  3654. failState: null
  3655. };
  3656. } catch (error) {
  3657. const failState = this.state;
  3658. this.state = oldState;
  3659. if (error instanceof SyntaxError) {
  3660. return {
  3661. node: null,
  3662. error,
  3663. thrown: true,
  3664. aborted: false,
  3665. failState
  3666. };
  3667. }
  3668. if (error === abortSignal) {
  3669. return {
  3670. node: abortSignal.node,
  3671. error: null,
  3672. thrown: false,
  3673. aborted: true,
  3674. failState
  3675. };
  3676. }
  3677. throw error;
  3678. }
  3679. }
  3680. checkExpressionErrors(refExpressionErrors, andThrow) {
  3681. if (!refExpressionErrors) return false;
  3682. const {
  3683. shorthandAssignLoc,
  3684. doubleProtoLoc,
  3685. privateKeyLoc,
  3686. optionalParametersLoc
  3687. } = refExpressionErrors;
  3688. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3689. if (!andThrow) {
  3690. return hasErrors;
  3691. }
  3692. if (shorthandAssignLoc != null) {
  3693. this.raise(Errors.InvalidCoverInitializedName, {
  3694. at: shorthandAssignLoc
  3695. });
  3696. }
  3697. if (doubleProtoLoc != null) {
  3698. this.raise(Errors.DuplicateProto, {
  3699. at: doubleProtoLoc
  3700. });
  3701. }
  3702. if (privateKeyLoc != null) {
  3703. this.raise(Errors.UnexpectedPrivateField, {
  3704. at: privateKeyLoc
  3705. });
  3706. }
  3707. if (optionalParametersLoc != null) {
  3708. this.unexpected(optionalParametersLoc);
  3709. }
  3710. }
  3711. isLiteralPropertyName() {
  3712. return tokenIsLiteralPropertyName(this.state.type);
  3713. }
  3714. isPrivateName(node) {
  3715. return node.type === "PrivateName";
  3716. }
  3717. getPrivateNameSV(node) {
  3718. return node.id.name;
  3719. }
  3720. hasPropertyAsPrivateName(node) {
  3721. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3722. }
  3723. isObjectProperty(node) {
  3724. return node.type === "ObjectProperty";
  3725. }
  3726. isObjectMethod(node) {
  3727. return node.type === "ObjectMethod";
  3728. }
  3729. initializeScopes(inModule = this.options.sourceType === "module") {
  3730. const oldLabels = this.state.labels;
  3731. this.state.labels = [];
  3732. const oldExportedIdentifiers = this.exportedIdentifiers;
  3733. this.exportedIdentifiers = new Set();
  3734. const oldInModule = this.inModule;
  3735. this.inModule = inModule;
  3736. const oldScope = this.scope;
  3737. const ScopeHandler = this.getScopeHandler();
  3738. this.scope = new ScopeHandler(this, inModule);
  3739. const oldProdParam = this.prodParam;
  3740. this.prodParam = new ProductionParameterHandler();
  3741. const oldClassScope = this.classScope;
  3742. this.classScope = new ClassScopeHandler(this);
  3743. const oldExpressionScope = this.expressionScope;
  3744. this.expressionScope = new ExpressionScopeHandler(this);
  3745. return () => {
  3746. this.state.labels = oldLabels;
  3747. this.exportedIdentifiers = oldExportedIdentifiers;
  3748. this.inModule = oldInModule;
  3749. this.scope = oldScope;
  3750. this.prodParam = oldProdParam;
  3751. this.classScope = oldClassScope;
  3752. this.expressionScope = oldExpressionScope;
  3753. };
  3754. }
  3755. enterInitialScopes() {
  3756. let paramFlags = PARAM;
  3757. if (this.inModule) {
  3758. paramFlags |= PARAM_AWAIT;
  3759. }
  3760. this.scope.enter(SCOPE_PROGRAM);
  3761. this.prodParam.enter(paramFlags);
  3762. }
  3763. checkDestructuringPrivate(refExpressionErrors) {
  3764. const {
  3765. privateKeyLoc
  3766. } = refExpressionErrors;
  3767. if (privateKeyLoc !== null) {
  3768. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3769. }
  3770. }
  3771. }
  3772. class ExpressionErrors {
  3773. constructor() {
  3774. this.shorthandAssignLoc = null;
  3775. this.doubleProtoLoc = null;
  3776. this.privateKeyLoc = null;
  3777. this.optionalParametersLoc = null;
  3778. }
  3779. }
  3780. class Node {
  3781. constructor(parser, pos, loc) {
  3782. this.type = "";
  3783. this.start = pos;
  3784. this.end = 0;
  3785. this.loc = new SourceLocation(loc);
  3786. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3787. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3788. }
  3789. }
  3790. const NodePrototype = Node.prototype;
  3791. {
  3792. NodePrototype.__clone = function () {
  3793. const newNode = new Node(undefined, this.start, this.loc.start);
  3794. const keys = Object.keys(this);
  3795. for (let i = 0, length = keys.length; i < length; i++) {
  3796. const key = keys[i];
  3797. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3798. newNode[key] = this[key];
  3799. }
  3800. }
  3801. return newNode;
  3802. };
  3803. }
  3804. function clonePlaceholder(node) {
  3805. return cloneIdentifier(node);
  3806. }
  3807. function cloneIdentifier(node) {
  3808. const {
  3809. type,
  3810. start,
  3811. end,
  3812. loc,
  3813. range,
  3814. extra,
  3815. name
  3816. } = node;
  3817. const cloned = Object.create(NodePrototype);
  3818. cloned.type = type;
  3819. cloned.start = start;
  3820. cloned.end = end;
  3821. cloned.loc = loc;
  3822. cloned.range = range;
  3823. cloned.extra = extra;
  3824. cloned.name = name;
  3825. if (type === "Placeholder") {
  3826. cloned.expectedNode = node.expectedNode;
  3827. }
  3828. return cloned;
  3829. }
  3830. function cloneStringLiteral(node) {
  3831. const {
  3832. type,
  3833. start,
  3834. end,
  3835. loc,
  3836. range,
  3837. extra
  3838. } = node;
  3839. if (type === "Placeholder") {
  3840. return clonePlaceholder(node);
  3841. }
  3842. const cloned = Object.create(NodePrototype);
  3843. cloned.type = type;
  3844. cloned.start = start;
  3845. cloned.end = end;
  3846. cloned.loc = loc;
  3847. cloned.range = range;
  3848. if (node.raw !== undefined) {
  3849. cloned.raw = node.raw;
  3850. } else {
  3851. cloned.extra = extra;
  3852. }
  3853. cloned.value = node.value;
  3854. return cloned;
  3855. }
  3856. class NodeUtils extends UtilParser {
  3857. startNode() {
  3858. return new Node(this, this.state.start, this.state.startLoc);
  3859. }
  3860. startNodeAt(loc) {
  3861. return new Node(this, loc.index, loc);
  3862. }
  3863. startNodeAtNode(type) {
  3864. return this.startNodeAt(type.loc.start);
  3865. }
  3866. finishNode(node, type) {
  3867. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3868. }
  3869. finishNodeAt(node, type, endLoc) {
  3870. node.type = type;
  3871. node.end = endLoc.index;
  3872. node.loc.end = endLoc;
  3873. if (this.options.ranges) node.range[1] = endLoc.index;
  3874. if (this.options.attachComment) this.processComment(node);
  3875. return node;
  3876. }
  3877. resetStartLocation(node, startLoc) {
  3878. node.start = startLoc.index;
  3879. node.loc.start = startLoc;
  3880. if (this.options.ranges) node.range[0] = startLoc.index;
  3881. }
  3882. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3883. node.end = endLoc.index;
  3884. node.loc.end = endLoc;
  3885. if (this.options.ranges) node.range[1] = endLoc.index;
  3886. }
  3887. resetStartLocationFromNode(node, locationNode) {
  3888. this.resetStartLocation(node, locationNode.loc.start);
  3889. }
  3890. }
  3891. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3892. const FlowErrors = ParseErrorEnum`flow`({
  3893. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3894. 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.",
  3895. AssignReservedType: ({
  3896. reservedType
  3897. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3898. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3899. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3900. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3901. EnumBooleanMemberNotInitialized: ({
  3902. memberName,
  3903. enumName
  3904. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3905. EnumDuplicateMemberName: ({
  3906. memberName,
  3907. enumName
  3908. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3909. EnumInconsistentMemberValues: ({
  3910. enumName
  3911. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3912. EnumInvalidExplicitType: ({
  3913. invalidEnumType,
  3914. enumName
  3915. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3916. EnumInvalidExplicitTypeUnknownSupplied: ({
  3917. enumName
  3918. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3919. EnumInvalidMemberInitializerPrimaryType: ({
  3920. enumName,
  3921. memberName,
  3922. explicitType
  3923. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3924. EnumInvalidMemberInitializerSymbolType: ({
  3925. enumName,
  3926. memberName
  3927. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3928. EnumInvalidMemberInitializerUnknownType: ({
  3929. enumName,
  3930. memberName
  3931. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3932. EnumInvalidMemberName: ({
  3933. enumName,
  3934. memberName,
  3935. suggestion
  3936. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3937. EnumNumberMemberNotInitialized: ({
  3938. enumName,
  3939. memberName
  3940. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3941. EnumStringMemberInconsistentlyInitailized: ({
  3942. enumName
  3943. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3944. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3945. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3946. 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.",
  3947. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3948. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3949. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3950. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3951. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3952. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3953. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3954. PatternIsOptional: Object.assign({
  3955. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3956. }, {
  3957. reasonCode: "OptionalBindingPattern"
  3958. }),
  3959. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3960. SpreadVariance: "Spread properties cannot have variance.",
  3961. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3962. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3963. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3964. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3965. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3966. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3967. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3968. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3969. UnexpectedReservedType: ({
  3970. reservedType
  3971. }) => `Unexpected reserved type ${reservedType}.`,
  3972. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3973. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3974. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3975. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3976. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3977. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3978. UnsupportedDeclareExportKind: ({
  3979. unsupportedExportKind,
  3980. suggestion
  3981. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  3982. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3983. UnterminatedFlowComment: "Unterminated flow-comment."
  3984. });
  3985. function isEsModuleType(bodyElement) {
  3986. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3987. }
  3988. function hasTypeImportKind(node) {
  3989. return node.importKind === "type" || node.importKind === "typeof";
  3990. }
  3991. const exportSuggestions = {
  3992. const: "declare export var",
  3993. let: "declare export var",
  3994. type: "export type",
  3995. interface: "export interface"
  3996. };
  3997. function partition(list, test) {
  3998. const list1 = [];
  3999. const list2 = [];
  4000. for (let i = 0; i < list.length; i++) {
  4001. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  4002. }
  4003. return [list1, list2];
  4004. }
  4005. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  4006. var flow = superClass => class FlowParserMixin extends superClass {
  4007. constructor(...args) {
  4008. super(...args);
  4009. this.flowPragma = undefined;
  4010. }
  4011. getScopeHandler() {
  4012. return FlowScopeHandler;
  4013. }
  4014. shouldParseTypes() {
  4015. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  4016. }
  4017. shouldParseEnums() {
  4018. return !!this.getPluginOption("flow", "enums");
  4019. }
  4020. finishToken(type, val) {
  4021. if (type !== 131 && type !== 13 && type !== 28) {
  4022. if (this.flowPragma === undefined) {
  4023. this.flowPragma = null;
  4024. }
  4025. }
  4026. super.finishToken(type, val);
  4027. }
  4028. addComment(comment) {
  4029. if (this.flowPragma === undefined) {
  4030. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4031. if (!matches) ;else if (matches[1] === "flow") {
  4032. this.flowPragma = "flow";
  4033. } else if (matches[1] === "noflow") {
  4034. this.flowPragma = "noflow";
  4035. } else {
  4036. throw new Error("Unexpected flow pragma");
  4037. }
  4038. }
  4039. super.addComment(comment);
  4040. }
  4041. flowParseTypeInitialiser(tok) {
  4042. const oldInType = this.state.inType;
  4043. this.state.inType = true;
  4044. this.expect(tok || 14);
  4045. const type = this.flowParseType();
  4046. this.state.inType = oldInType;
  4047. return type;
  4048. }
  4049. flowParsePredicate() {
  4050. const node = this.startNode();
  4051. const moduloLoc = this.state.startLoc;
  4052. this.next();
  4053. this.expectContextual(108);
  4054. if (this.state.lastTokStart > moduloLoc.index + 1) {
  4055. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
  4056. at: moduloLoc
  4057. });
  4058. }
  4059. if (this.eat(10)) {
  4060. node.value = super.parseExpression();
  4061. this.expect(11);
  4062. return this.finishNode(node, "DeclaredPredicate");
  4063. } else {
  4064. return this.finishNode(node, "InferredPredicate");
  4065. }
  4066. }
  4067. flowParseTypeAndPredicateInitialiser() {
  4068. const oldInType = this.state.inType;
  4069. this.state.inType = true;
  4070. this.expect(14);
  4071. let type = null;
  4072. let predicate = null;
  4073. if (this.match(54)) {
  4074. this.state.inType = oldInType;
  4075. predicate = this.flowParsePredicate();
  4076. } else {
  4077. type = this.flowParseType();
  4078. this.state.inType = oldInType;
  4079. if (this.match(54)) {
  4080. predicate = this.flowParsePredicate();
  4081. }
  4082. }
  4083. return [type, predicate];
  4084. }
  4085. flowParseDeclareClass(node) {
  4086. this.next();
  4087. this.flowParseInterfaceish(node, true);
  4088. return this.finishNode(node, "DeclareClass");
  4089. }
  4090. flowParseDeclareFunction(node) {
  4091. this.next();
  4092. const id = node.id = this.parseIdentifier();
  4093. const typeNode = this.startNode();
  4094. const typeContainer = this.startNode();
  4095. if (this.match(47)) {
  4096. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4097. } else {
  4098. typeNode.typeParameters = null;
  4099. }
  4100. this.expect(10);
  4101. const tmp = this.flowParseFunctionTypeParams();
  4102. typeNode.params = tmp.params;
  4103. typeNode.rest = tmp.rest;
  4104. typeNode.this = tmp._this;
  4105. this.expect(11);
  4106. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4107. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4108. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4109. this.resetEndLocation(id);
  4110. this.semicolon();
  4111. this.scope.declareName(node.id.name, BIND_FLOW_DECLARE_FN, node.id.loc.start);
  4112. return this.finishNode(node, "DeclareFunction");
  4113. }
  4114. flowParseDeclare(node, insideModule) {
  4115. if (this.match(80)) {
  4116. return this.flowParseDeclareClass(node);
  4117. } else if (this.match(68)) {
  4118. return this.flowParseDeclareFunction(node);
  4119. } else if (this.match(74)) {
  4120. return this.flowParseDeclareVariable(node);
  4121. } else if (this.eatContextual(125)) {
  4122. if (this.match(16)) {
  4123. return this.flowParseDeclareModuleExports(node);
  4124. } else {
  4125. if (insideModule) {
  4126. this.raise(FlowErrors.NestedDeclareModule, {
  4127. at: this.state.lastTokStartLoc
  4128. });
  4129. }
  4130. return this.flowParseDeclareModule(node);
  4131. }
  4132. } else if (this.isContextual(128)) {
  4133. return this.flowParseDeclareTypeAlias(node);
  4134. } else if (this.isContextual(129)) {
  4135. return this.flowParseDeclareOpaqueType(node);
  4136. } else if (this.isContextual(127)) {
  4137. return this.flowParseDeclareInterface(node);
  4138. } else if (this.match(82)) {
  4139. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4140. } else {
  4141. this.unexpected();
  4142. }
  4143. }
  4144. flowParseDeclareVariable(node) {
  4145. this.next();
  4146. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4147. this.scope.declareName(node.id.name, BIND_VAR, node.id.loc.start);
  4148. this.semicolon();
  4149. return this.finishNode(node, "DeclareVariable");
  4150. }
  4151. flowParseDeclareModule(node) {
  4152. this.scope.enter(SCOPE_OTHER);
  4153. if (this.match(131)) {
  4154. node.id = super.parseExprAtom();
  4155. } else {
  4156. node.id = this.parseIdentifier();
  4157. }
  4158. const bodyNode = node.body = this.startNode();
  4159. const body = bodyNode.body = [];
  4160. this.expect(5);
  4161. while (!this.match(8)) {
  4162. let bodyNode = this.startNode();
  4163. if (this.match(83)) {
  4164. this.next();
  4165. if (!this.isContextual(128) && !this.match(87)) {
  4166. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
  4167. at: this.state.lastTokStartLoc
  4168. });
  4169. }
  4170. super.parseImport(bodyNode);
  4171. } else {
  4172. this.expectContextual(123, FlowErrors.UnsupportedStatementInDeclareModule);
  4173. bodyNode = this.flowParseDeclare(bodyNode, true);
  4174. }
  4175. body.push(bodyNode);
  4176. }
  4177. this.scope.exit();
  4178. this.expect(8);
  4179. this.finishNode(bodyNode, "BlockStatement");
  4180. let kind = null;
  4181. let hasModuleExport = false;
  4182. body.forEach(bodyElement => {
  4183. if (isEsModuleType(bodyElement)) {
  4184. if (kind === "CommonJS") {
  4185. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4186. at: bodyElement
  4187. });
  4188. }
  4189. kind = "ES";
  4190. } else if (bodyElement.type === "DeclareModuleExports") {
  4191. if (hasModuleExport) {
  4192. this.raise(FlowErrors.DuplicateDeclareModuleExports, {
  4193. at: bodyElement
  4194. });
  4195. }
  4196. if (kind === "ES") {
  4197. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4198. at: bodyElement
  4199. });
  4200. }
  4201. kind = "CommonJS";
  4202. hasModuleExport = true;
  4203. }
  4204. });
  4205. node.kind = kind || "CommonJS";
  4206. return this.finishNode(node, "DeclareModule");
  4207. }
  4208. flowParseDeclareExportDeclaration(node, insideModule) {
  4209. this.expect(82);
  4210. if (this.eat(65)) {
  4211. if (this.match(68) || this.match(80)) {
  4212. node.declaration = this.flowParseDeclare(this.startNode());
  4213. } else {
  4214. node.declaration = this.flowParseType();
  4215. this.semicolon();
  4216. }
  4217. node.default = true;
  4218. return this.finishNode(node, "DeclareExportDeclaration");
  4219. } else {
  4220. if (this.match(75) || this.isLet() || (this.isContextual(128) || this.isContextual(127)) && !insideModule) {
  4221. const label = this.state.value;
  4222. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
  4223. at: this.state.startLoc,
  4224. unsupportedExportKind: label,
  4225. suggestion: exportSuggestions[label]
  4226. });
  4227. }
  4228. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(129)) {
  4229. node.declaration = this.flowParseDeclare(this.startNode());
  4230. node.default = false;
  4231. return this.finishNode(node, "DeclareExportDeclaration");
  4232. } else if (this.match(55) || this.match(5) || this.isContextual(127) || this.isContextual(128) || this.isContextual(129)) {
  4233. node = this.parseExport(node, null);
  4234. if (node.type === "ExportNamedDeclaration") {
  4235. node.type = "ExportDeclaration";
  4236. node.default = false;
  4237. delete node.exportKind;
  4238. }
  4239. node.type = "Declare" + node.type;
  4240. return node;
  4241. }
  4242. }
  4243. this.unexpected();
  4244. }
  4245. flowParseDeclareModuleExports(node) {
  4246. this.next();
  4247. this.expectContextual(109);
  4248. node.typeAnnotation = this.flowParseTypeAnnotation();
  4249. this.semicolon();
  4250. return this.finishNode(node, "DeclareModuleExports");
  4251. }
  4252. flowParseDeclareTypeAlias(node) {
  4253. this.next();
  4254. const finished = this.flowParseTypeAlias(node);
  4255. finished.type = "DeclareTypeAlias";
  4256. return finished;
  4257. }
  4258. flowParseDeclareOpaqueType(node) {
  4259. this.next();
  4260. const finished = this.flowParseOpaqueType(node, true);
  4261. finished.type = "DeclareOpaqueType";
  4262. return finished;
  4263. }
  4264. flowParseDeclareInterface(node) {
  4265. this.next();
  4266. this.flowParseInterfaceish(node, false);
  4267. return this.finishNode(node, "DeclareInterface");
  4268. }
  4269. flowParseInterfaceish(node, isClass) {
  4270. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4271. this.scope.declareName(node.id.name, isClass ? BIND_FUNCTION : BIND_LEXICAL, node.id.loc.start);
  4272. if (this.match(47)) {
  4273. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4274. } else {
  4275. node.typeParameters = null;
  4276. }
  4277. node.extends = [];
  4278. if (this.eat(81)) {
  4279. do {
  4280. node.extends.push(this.flowParseInterfaceExtends());
  4281. } while (!isClass && this.eat(12));
  4282. }
  4283. if (isClass) {
  4284. node.implements = [];
  4285. node.mixins = [];
  4286. if (this.eatContextual(115)) {
  4287. do {
  4288. node.mixins.push(this.flowParseInterfaceExtends());
  4289. } while (this.eat(12));
  4290. }
  4291. if (this.eatContextual(111)) {
  4292. do {
  4293. node.implements.push(this.flowParseInterfaceExtends());
  4294. } while (this.eat(12));
  4295. }
  4296. }
  4297. node.body = this.flowParseObjectType({
  4298. allowStatic: isClass,
  4299. allowExact: false,
  4300. allowSpread: false,
  4301. allowProto: isClass,
  4302. allowInexact: false
  4303. });
  4304. }
  4305. flowParseInterfaceExtends() {
  4306. const node = this.startNode();
  4307. node.id = this.flowParseQualifiedTypeIdentifier();
  4308. if (this.match(47)) {
  4309. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4310. } else {
  4311. node.typeParameters = null;
  4312. }
  4313. return this.finishNode(node, "InterfaceExtends");
  4314. }
  4315. flowParseInterface(node) {
  4316. this.flowParseInterfaceish(node, false);
  4317. return this.finishNode(node, "InterfaceDeclaration");
  4318. }
  4319. checkNotUnderscore(word) {
  4320. if (word === "_") {
  4321. this.raise(FlowErrors.UnexpectedReservedUnderscore, {
  4322. at: this.state.startLoc
  4323. });
  4324. }
  4325. }
  4326. checkReservedType(word, startLoc, declaration) {
  4327. if (!reservedTypes.has(word)) return;
  4328. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
  4329. at: startLoc,
  4330. reservedType: word
  4331. });
  4332. }
  4333. flowParseRestrictedIdentifier(liberal, declaration) {
  4334. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4335. return this.parseIdentifier(liberal);
  4336. }
  4337. flowParseTypeAlias(node) {
  4338. node.id = this.flowParseRestrictedIdentifier(false, true);
  4339. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  4340. if (this.match(47)) {
  4341. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4342. } else {
  4343. node.typeParameters = null;
  4344. }
  4345. node.right = this.flowParseTypeInitialiser(29);
  4346. this.semicolon();
  4347. return this.finishNode(node, "TypeAlias");
  4348. }
  4349. flowParseOpaqueType(node, declare) {
  4350. this.expectContextual(128);
  4351. node.id = this.flowParseRestrictedIdentifier(true, true);
  4352. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  4353. if (this.match(47)) {
  4354. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4355. } else {
  4356. node.typeParameters = null;
  4357. }
  4358. node.supertype = null;
  4359. if (this.match(14)) {
  4360. node.supertype = this.flowParseTypeInitialiser(14);
  4361. }
  4362. node.impltype = null;
  4363. if (!declare) {
  4364. node.impltype = this.flowParseTypeInitialiser(29);
  4365. }
  4366. this.semicolon();
  4367. return this.finishNode(node, "OpaqueType");
  4368. }
  4369. flowParseTypeParameter(requireDefault = false) {
  4370. const nodeStartLoc = this.state.startLoc;
  4371. const node = this.startNode();
  4372. const variance = this.flowParseVariance();
  4373. const ident = this.flowParseTypeAnnotatableIdentifier();
  4374. node.name = ident.name;
  4375. node.variance = variance;
  4376. node.bound = ident.typeAnnotation;
  4377. if (this.match(29)) {
  4378. this.eat(29);
  4379. node.default = this.flowParseType();
  4380. } else {
  4381. if (requireDefault) {
  4382. this.raise(FlowErrors.MissingTypeParamDefault, {
  4383. at: nodeStartLoc
  4384. });
  4385. }
  4386. }
  4387. return this.finishNode(node, "TypeParameter");
  4388. }
  4389. flowParseTypeParameterDeclaration() {
  4390. const oldInType = this.state.inType;
  4391. const node = this.startNode();
  4392. node.params = [];
  4393. this.state.inType = true;
  4394. if (this.match(47) || this.match(140)) {
  4395. this.next();
  4396. } else {
  4397. this.unexpected();
  4398. }
  4399. let defaultRequired = false;
  4400. do {
  4401. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4402. node.params.push(typeParameter);
  4403. if (typeParameter.default) {
  4404. defaultRequired = true;
  4405. }
  4406. if (!this.match(48)) {
  4407. this.expect(12);
  4408. }
  4409. } while (!this.match(48));
  4410. this.expect(48);
  4411. this.state.inType = oldInType;
  4412. return this.finishNode(node, "TypeParameterDeclaration");
  4413. }
  4414. flowParseTypeParameterInstantiation() {
  4415. const node = this.startNode();
  4416. const oldInType = this.state.inType;
  4417. node.params = [];
  4418. this.state.inType = true;
  4419. this.expect(47);
  4420. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4421. this.state.noAnonFunctionType = false;
  4422. while (!this.match(48)) {
  4423. node.params.push(this.flowParseType());
  4424. if (!this.match(48)) {
  4425. this.expect(12);
  4426. }
  4427. }
  4428. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4429. this.expect(48);
  4430. this.state.inType = oldInType;
  4431. return this.finishNode(node, "TypeParameterInstantiation");
  4432. }
  4433. flowParseTypeParameterInstantiationCallOrNew() {
  4434. const node = this.startNode();
  4435. const oldInType = this.state.inType;
  4436. node.params = [];
  4437. this.state.inType = true;
  4438. this.expect(47);
  4439. while (!this.match(48)) {
  4440. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4441. if (!this.match(48)) {
  4442. this.expect(12);
  4443. }
  4444. }
  4445. this.expect(48);
  4446. this.state.inType = oldInType;
  4447. return this.finishNode(node, "TypeParameterInstantiation");
  4448. }
  4449. flowParseInterfaceType() {
  4450. const node = this.startNode();
  4451. this.expectContextual(127);
  4452. node.extends = [];
  4453. if (this.eat(81)) {
  4454. do {
  4455. node.extends.push(this.flowParseInterfaceExtends());
  4456. } while (this.eat(12));
  4457. }
  4458. node.body = this.flowParseObjectType({
  4459. allowStatic: false,
  4460. allowExact: false,
  4461. allowSpread: false,
  4462. allowProto: false,
  4463. allowInexact: false
  4464. });
  4465. return this.finishNode(node, "InterfaceTypeAnnotation");
  4466. }
  4467. flowParseObjectPropertyKey() {
  4468. return this.match(132) || this.match(131) ? super.parseExprAtom() : this.parseIdentifier(true);
  4469. }
  4470. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4471. node.static = isStatic;
  4472. if (this.lookahead().type === 14) {
  4473. node.id = this.flowParseObjectPropertyKey();
  4474. node.key = this.flowParseTypeInitialiser();
  4475. } else {
  4476. node.id = null;
  4477. node.key = this.flowParseType();
  4478. }
  4479. this.expect(3);
  4480. node.value = this.flowParseTypeInitialiser();
  4481. node.variance = variance;
  4482. return this.finishNode(node, "ObjectTypeIndexer");
  4483. }
  4484. flowParseObjectTypeInternalSlot(node, isStatic) {
  4485. node.static = isStatic;
  4486. node.id = this.flowParseObjectPropertyKey();
  4487. this.expect(3);
  4488. this.expect(3);
  4489. if (this.match(47) || this.match(10)) {
  4490. node.method = true;
  4491. node.optional = false;
  4492. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4493. } else {
  4494. node.method = false;
  4495. if (this.eat(17)) {
  4496. node.optional = true;
  4497. }
  4498. node.value = this.flowParseTypeInitialiser();
  4499. }
  4500. return this.finishNode(node, "ObjectTypeInternalSlot");
  4501. }
  4502. flowParseObjectTypeMethodish(node) {
  4503. node.params = [];
  4504. node.rest = null;
  4505. node.typeParameters = null;
  4506. node.this = null;
  4507. if (this.match(47)) {
  4508. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4509. }
  4510. this.expect(10);
  4511. if (this.match(78)) {
  4512. node.this = this.flowParseFunctionTypeParam(true);
  4513. node.this.name = null;
  4514. if (!this.match(11)) {
  4515. this.expect(12);
  4516. }
  4517. }
  4518. while (!this.match(11) && !this.match(21)) {
  4519. node.params.push(this.flowParseFunctionTypeParam(false));
  4520. if (!this.match(11)) {
  4521. this.expect(12);
  4522. }
  4523. }
  4524. if (this.eat(21)) {
  4525. node.rest = this.flowParseFunctionTypeParam(false);
  4526. }
  4527. this.expect(11);
  4528. node.returnType = this.flowParseTypeInitialiser();
  4529. return this.finishNode(node, "FunctionTypeAnnotation");
  4530. }
  4531. flowParseObjectTypeCallProperty(node, isStatic) {
  4532. const valueNode = this.startNode();
  4533. node.static = isStatic;
  4534. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4535. return this.finishNode(node, "ObjectTypeCallProperty");
  4536. }
  4537. flowParseObjectType({
  4538. allowStatic,
  4539. allowExact,
  4540. allowSpread,
  4541. allowProto,
  4542. allowInexact
  4543. }) {
  4544. const oldInType = this.state.inType;
  4545. this.state.inType = true;
  4546. const nodeStart = this.startNode();
  4547. nodeStart.callProperties = [];
  4548. nodeStart.properties = [];
  4549. nodeStart.indexers = [];
  4550. nodeStart.internalSlots = [];
  4551. let endDelim;
  4552. let exact;
  4553. let inexact = false;
  4554. if (allowExact && this.match(6)) {
  4555. this.expect(6);
  4556. endDelim = 9;
  4557. exact = true;
  4558. } else {
  4559. this.expect(5);
  4560. endDelim = 8;
  4561. exact = false;
  4562. }
  4563. nodeStart.exact = exact;
  4564. while (!this.match(endDelim)) {
  4565. let isStatic = false;
  4566. let protoStartLoc = null;
  4567. let inexactStartLoc = null;
  4568. const node = this.startNode();
  4569. if (allowProto && this.isContextual(116)) {
  4570. const lookahead = this.lookahead();
  4571. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4572. this.next();
  4573. protoStartLoc = this.state.startLoc;
  4574. allowStatic = false;
  4575. }
  4576. }
  4577. if (allowStatic && this.isContextual(104)) {
  4578. const lookahead = this.lookahead();
  4579. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4580. this.next();
  4581. isStatic = true;
  4582. }
  4583. }
  4584. const variance = this.flowParseVariance();
  4585. if (this.eat(0)) {
  4586. if (protoStartLoc != null) {
  4587. this.unexpected(protoStartLoc);
  4588. }
  4589. if (this.eat(0)) {
  4590. if (variance) {
  4591. this.unexpected(variance.loc.start);
  4592. }
  4593. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4594. } else {
  4595. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4596. }
  4597. } else if (this.match(10) || this.match(47)) {
  4598. if (protoStartLoc != null) {
  4599. this.unexpected(protoStartLoc);
  4600. }
  4601. if (variance) {
  4602. this.unexpected(variance.loc.start);
  4603. }
  4604. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4605. } else {
  4606. let kind = "init";
  4607. if (this.isContextual(98) || this.isContextual(103)) {
  4608. const lookahead = this.lookahead();
  4609. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4610. kind = this.state.value;
  4611. this.next();
  4612. }
  4613. }
  4614. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4615. if (propOrInexact === null) {
  4616. inexact = true;
  4617. inexactStartLoc = this.state.lastTokStartLoc;
  4618. } else {
  4619. nodeStart.properties.push(propOrInexact);
  4620. }
  4621. }
  4622. this.flowObjectTypeSemicolon();
  4623. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4624. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
  4625. at: inexactStartLoc
  4626. });
  4627. }
  4628. }
  4629. this.expect(endDelim);
  4630. if (allowSpread) {
  4631. nodeStart.inexact = inexact;
  4632. }
  4633. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4634. this.state.inType = oldInType;
  4635. return out;
  4636. }
  4637. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4638. if (this.eat(21)) {
  4639. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4640. if (isInexactToken) {
  4641. if (!allowSpread) {
  4642. this.raise(FlowErrors.InexactInsideNonObject, {
  4643. at: this.state.lastTokStartLoc
  4644. });
  4645. } else if (!allowInexact) {
  4646. this.raise(FlowErrors.InexactInsideExact, {
  4647. at: this.state.lastTokStartLoc
  4648. });
  4649. }
  4650. if (variance) {
  4651. this.raise(FlowErrors.InexactVariance, {
  4652. at: variance
  4653. });
  4654. }
  4655. return null;
  4656. }
  4657. if (!allowSpread) {
  4658. this.raise(FlowErrors.UnexpectedSpreadType, {
  4659. at: this.state.lastTokStartLoc
  4660. });
  4661. }
  4662. if (protoStartLoc != null) {
  4663. this.unexpected(protoStartLoc);
  4664. }
  4665. if (variance) {
  4666. this.raise(FlowErrors.SpreadVariance, {
  4667. at: variance
  4668. });
  4669. }
  4670. node.argument = this.flowParseType();
  4671. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4672. } else {
  4673. node.key = this.flowParseObjectPropertyKey();
  4674. node.static = isStatic;
  4675. node.proto = protoStartLoc != null;
  4676. node.kind = kind;
  4677. let optional = false;
  4678. if (this.match(47) || this.match(10)) {
  4679. node.method = true;
  4680. if (protoStartLoc != null) {
  4681. this.unexpected(protoStartLoc);
  4682. }
  4683. if (variance) {
  4684. this.unexpected(variance.loc.start);
  4685. }
  4686. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4687. if (kind === "get" || kind === "set") {
  4688. this.flowCheckGetterSetterParams(node);
  4689. }
  4690. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4691. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  4692. at: node.value.this
  4693. });
  4694. }
  4695. } else {
  4696. if (kind !== "init") this.unexpected();
  4697. node.method = false;
  4698. if (this.eat(17)) {
  4699. optional = true;
  4700. }
  4701. node.value = this.flowParseTypeInitialiser();
  4702. node.variance = variance;
  4703. }
  4704. node.optional = optional;
  4705. return this.finishNode(node, "ObjectTypeProperty");
  4706. }
  4707. }
  4708. flowCheckGetterSetterParams(property) {
  4709. const paramCount = property.kind === "get" ? 0 : 1;
  4710. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4711. if (property.value.this) {
  4712. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
  4713. at: property.value.this
  4714. });
  4715. }
  4716. if (length !== paramCount) {
  4717. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  4718. at: property
  4719. });
  4720. }
  4721. if (property.kind === "set" && property.value.rest) {
  4722. this.raise(Errors.BadSetterRestParameter, {
  4723. at: property
  4724. });
  4725. }
  4726. }
  4727. flowObjectTypeSemicolon() {
  4728. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4729. this.unexpected();
  4730. }
  4731. }
  4732. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4733. var _startLoc;
  4734. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4735. let node = id || this.flowParseRestrictedIdentifier(true);
  4736. while (this.eat(16)) {
  4737. const node2 = this.startNodeAt(startLoc);
  4738. node2.qualification = node;
  4739. node2.id = this.flowParseRestrictedIdentifier(true);
  4740. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4741. }
  4742. return node;
  4743. }
  4744. flowParseGenericType(startLoc, id) {
  4745. const node = this.startNodeAt(startLoc);
  4746. node.typeParameters = null;
  4747. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4748. if (this.match(47)) {
  4749. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4750. }
  4751. return this.finishNode(node, "GenericTypeAnnotation");
  4752. }
  4753. flowParseTypeofType() {
  4754. const node = this.startNode();
  4755. this.expect(87);
  4756. node.argument = this.flowParsePrimaryType();
  4757. return this.finishNode(node, "TypeofTypeAnnotation");
  4758. }
  4759. flowParseTupleType() {
  4760. const node = this.startNode();
  4761. node.types = [];
  4762. this.expect(0);
  4763. while (this.state.pos < this.length && !this.match(3)) {
  4764. node.types.push(this.flowParseType());
  4765. if (this.match(3)) break;
  4766. this.expect(12);
  4767. }
  4768. this.expect(3);
  4769. return this.finishNode(node, "TupleTypeAnnotation");
  4770. }
  4771. flowParseFunctionTypeParam(first) {
  4772. let name = null;
  4773. let optional = false;
  4774. let typeAnnotation = null;
  4775. const node = this.startNode();
  4776. const lh = this.lookahead();
  4777. const isThis = this.state.type === 78;
  4778. if (lh.type === 14 || lh.type === 17) {
  4779. if (isThis && !first) {
  4780. this.raise(FlowErrors.ThisParamMustBeFirst, {
  4781. at: node
  4782. });
  4783. }
  4784. name = this.parseIdentifier(isThis);
  4785. if (this.eat(17)) {
  4786. optional = true;
  4787. if (isThis) {
  4788. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  4789. at: node
  4790. });
  4791. }
  4792. }
  4793. typeAnnotation = this.flowParseTypeInitialiser();
  4794. } else {
  4795. typeAnnotation = this.flowParseType();
  4796. }
  4797. node.name = name;
  4798. node.optional = optional;
  4799. node.typeAnnotation = typeAnnotation;
  4800. return this.finishNode(node, "FunctionTypeParam");
  4801. }
  4802. reinterpretTypeAsFunctionTypeParam(type) {
  4803. const node = this.startNodeAt(type.loc.start);
  4804. node.name = null;
  4805. node.optional = false;
  4806. node.typeAnnotation = type;
  4807. return this.finishNode(node, "FunctionTypeParam");
  4808. }
  4809. flowParseFunctionTypeParams(params = []) {
  4810. let rest = null;
  4811. let _this = null;
  4812. if (this.match(78)) {
  4813. _this = this.flowParseFunctionTypeParam(true);
  4814. _this.name = null;
  4815. if (!this.match(11)) {
  4816. this.expect(12);
  4817. }
  4818. }
  4819. while (!this.match(11) && !this.match(21)) {
  4820. params.push(this.flowParseFunctionTypeParam(false));
  4821. if (!this.match(11)) {
  4822. this.expect(12);
  4823. }
  4824. }
  4825. if (this.eat(21)) {
  4826. rest = this.flowParseFunctionTypeParam(false);
  4827. }
  4828. return {
  4829. params,
  4830. rest,
  4831. _this
  4832. };
  4833. }
  4834. flowIdentToTypeAnnotation(startLoc, node, id) {
  4835. switch (id.name) {
  4836. case "any":
  4837. return this.finishNode(node, "AnyTypeAnnotation");
  4838. case "bool":
  4839. case "boolean":
  4840. return this.finishNode(node, "BooleanTypeAnnotation");
  4841. case "mixed":
  4842. return this.finishNode(node, "MixedTypeAnnotation");
  4843. case "empty":
  4844. return this.finishNode(node, "EmptyTypeAnnotation");
  4845. case "number":
  4846. return this.finishNode(node, "NumberTypeAnnotation");
  4847. case "string":
  4848. return this.finishNode(node, "StringTypeAnnotation");
  4849. case "symbol":
  4850. return this.finishNode(node, "SymbolTypeAnnotation");
  4851. default:
  4852. this.checkNotUnderscore(id.name);
  4853. return this.flowParseGenericType(startLoc, id);
  4854. }
  4855. }
  4856. flowParsePrimaryType() {
  4857. const startLoc = this.state.startLoc;
  4858. const node = this.startNode();
  4859. let tmp;
  4860. let type;
  4861. let isGroupedType = false;
  4862. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4863. switch (this.state.type) {
  4864. case 5:
  4865. return this.flowParseObjectType({
  4866. allowStatic: false,
  4867. allowExact: false,
  4868. allowSpread: true,
  4869. allowProto: false,
  4870. allowInexact: true
  4871. });
  4872. case 6:
  4873. return this.flowParseObjectType({
  4874. allowStatic: false,
  4875. allowExact: true,
  4876. allowSpread: true,
  4877. allowProto: false,
  4878. allowInexact: false
  4879. });
  4880. case 0:
  4881. this.state.noAnonFunctionType = false;
  4882. type = this.flowParseTupleType();
  4883. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4884. return type;
  4885. case 47:
  4886. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4887. this.expect(10);
  4888. tmp = this.flowParseFunctionTypeParams();
  4889. node.params = tmp.params;
  4890. node.rest = tmp.rest;
  4891. node.this = tmp._this;
  4892. this.expect(11);
  4893. this.expect(19);
  4894. node.returnType = this.flowParseType();
  4895. return this.finishNode(node, "FunctionTypeAnnotation");
  4896. case 10:
  4897. this.next();
  4898. if (!this.match(11) && !this.match(21)) {
  4899. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4900. const token = this.lookahead().type;
  4901. isGroupedType = token !== 17 && token !== 14;
  4902. } else {
  4903. isGroupedType = true;
  4904. }
  4905. }
  4906. if (isGroupedType) {
  4907. this.state.noAnonFunctionType = false;
  4908. type = this.flowParseType();
  4909. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4910. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4911. this.expect(11);
  4912. return type;
  4913. } else {
  4914. this.eat(12);
  4915. }
  4916. }
  4917. if (type) {
  4918. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4919. } else {
  4920. tmp = this.flowParseFunctionTypeParams();
  4921. }
  4922. node.params = tmp.params;
  4923. node.rest = tmp.rest;
  4924. node.this = tmp._this;
  4925. this.expect(11);
  4926. this.expect(19);
  4927. node.returnType = this.flowParseType();
  4928. node.typeParameters = null;
  4929. return this.finishNode(node, "FunctionTypeAnnotation");
  4930. case 131:
  4931. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4932. case 85:
  4933. case 86:
  4934. node.value = this.match(85);
  4935. this.next();
  4936. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4937. case 53:
  4938. if (this.state.value === "-") {
  4939. this.next();
  4940. if (this.match(132)) {
  4941. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4942. }
  4943. if (this.match(133)) {
  4944. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4945. }
  4946. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
  4947. at: this.state.startLoc
  4948. });
  4949. }
  4950. this.unexpected();
  4951. return;
  4952. case 132:
  4953. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4954. case 133:
  4955. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4956. case 88:
  4957. this.next();
  4958. return this.finishNode(node, "VoidTypeAnnotation");
  4959. case 84:
  4960. this.next();
  4961. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4962. case 78:
  4963. this.next();
  4964. return this.finishNode(node, "ThisTypeAnnotation");
  4965. case 55:
  4966. this.next();
  4967. return this.finishNode(node, "ExistsTypeAnnotation");
  4968. case 87:
  4969. return this.flowParseTypeofType();
  4970. default:
  4971. if (tokenIsKeyword(this.state.type)) {
  4972. const label = tokenLabelName(this.state.type);
  4973. this.next();
  4974. return super.createIdentifier(node, label);
  4975. } else if (tokenIsIdentifier(this.state.type)) {
  4976. if (this.isContextual(127)) {
  4977. return this.flowParseInterfaceType();
  4978. }
  4979. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4980. }
  4981. }
  4982. this.unexpected();
  4983. }
  4984. flowParsePostfixType() {
  4985. const startLoc = this.state.startLoc;
  4986. let type = this.flowParsePrimaryType();
  4987. let seenOptionalIndexedAccess = false;
  4988. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4989. const node = this.startNodeAt(startLoc);
  4990. const optional = this.eat(18);
  4991. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  4992. this.expect(0);
  4993. if (!optional && this.match(3)) {
  4994. node.elementType = type;
  4995. this.next();
  4996. type = this.finishNode(node, "ArrayTypeAnnotation");
  4997. } else {
  4998. node.objectType = type;
  4999. node.indexType = this.flowParseType();
  5000. this.expect(3);
  5001. if (seenOptionalIndexedAccess) {
  5002. node.optional = optional;
  5003. type = this.finishNode(node, "OptionalIndexedAccessType");
  5004. } else {
  5005. type = this.finishNode(node, "IndexedAccessType");
  5006. }
  5007. }
  5008. }
  5009. return type;
  5010. }
  5011. flowParsePrefixType() {
  5012. const node = this.startNode();
  5013. if (this.eat(17)) {
  5014. node.typeAnnotation = this.flowParsePrefixType();
  5015. return this.finishNode(node, "NullableTypeAnnotation");
  5016. } else {
  5017. return this.flowParsePostfixType();
  5018. }
  5019. }
  5020. flowParseAnonFunctionWithoutParens() {
  5021. const param = this.flowParsePrefixType();
  5022. if (!this.state.noAnonFunctionType && this.eat(19)) {
  5023. const node = this.startNodeAt(param.loc.start);
  5024. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  5025. node.rest = null;
  5026. node.this = null;
  5027. node.returnType = this.flowParseType();
  5028. node.typeParameters = null;
  5029. return this.finishNode(node, "FunctionTypeAnnotation");
  5030. }
  5031. return param;
  5032. }
  5033. flowParseIntersectionType() {
  5034. const node = this.startNode();
  5035. this.eat(45);
  5036. const type = this.flowParseAnonFunctionWithoutParens();
  5037. node.types = [type];
  5038. while (this.eat(45)) {
  5039. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5040. }
  5041. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5042. }
  5043. flowParseUnionType() {
  5044. const node = this.startNode();
  5045. this.eat(43);
  5046. const type = this.flowParseIntersectionType();
  5047. node.types = [type];
  5048. while (this.eat(43)) {
  5049. node.types.push(this.flowParseIntersectionType());
  5050. }
  5051. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5052. }
  5053. flowParseType() {
  5054. const oldInType = this.state.inType;
  5055. this.state.inType = true;
  5056. const type = this.flowParseUnionType();
  5057. this.state.inType = oldInType;
  5058. return type;
  5059. }
  5060. flowParseTypeOrImplicitInstantiation() {
  5061. if (this.state.type === 130 && this.state.value === "_") {
  5062. const startLoc = this.state.startLoc;
  5063. const node = this.parseIdentifier();
  5064. return this.flowParseGenericType(startLoc, node);
  5065. } else {
  5066. return this.flowParseType();
  5067. }
  5068. }
  5069. flowParseTypeAnnotation() {
  5070. const node = this.startNode();
  5071. node.typeAnnotation = this.flowParseTypeInitialiser();
  5072. return this.finishNode(node, "TypeAnnotation");
  5073. }
  5074. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5075. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5076. if (this.match(14)) {
  5077. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5078. this.resetEndLocation(ident);
  5079. }
  5080. return ident;
  5081. }
  5082. typeCastToParameter(node) {
  5083. node.expression.typeAnnotation = node.typeAnnotation;
  5084. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5085. return node.expression;
  5086. }
  5087. flowParseVariance() {
  5088. let variance = null;
  5089. if (this.match(53)) {
  5090. variance = this.startNode();
  5091. if (this.state.value === "+") {
  5092. variance.kind = "plus";
  5093. } else {
  5094. variance.kind = "minus";
  5095. }
  5096. this.next();
  5097. return this.finishNode(variance, "Variance");
  5098. }
  5099. return variance;
  5100. }
  5101. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5102. if (allowExpressionBody) {
  5103. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5104. return;
  5105. }
  5106. super.parseFunctionBody(node, false, isMethod);
  5107. }
  5108. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5109. if (this.match(14)) {
  5110. const typeNode = this.startNode();
  5111. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5112. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5113. }
  5114. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5115. }
  5116. parseStatementLike(flags) {
  5117. if (this.state.strict && this.isContextual(127)) {
  5118. const lookahead = this.lookahead();
  5119. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5120. const node = this.startNode();
  5121. this.next();
  5122. return this.flowParseInterface(node);
  5123. }
  5124. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  5125. const node = this.startNode();
  5126. this.next();
  5127. return this.flowParseEnumDeclaration(node);
  5128. }
  5129. const stmt = super.parseStatementLike(flags);
  5130. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5131. this.flowPragma = null;
  5132. }
  5133. return stmt;
  5134. }
  5135. parseExpressionStatement(node, expr, decorators) {
  5136. if (expr.type === "Identifier") {
  5137. if (expr.name === "declare") {
  5138. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5139. return this.flowParseDeclare(node);
  5140. }
  5141. } else if (tokenIsIdentifier(this.state.type)) {
  5142. if (expr.name === "interface") {
  5143. return this.flowParseInterface(node);
  5144. } else if (expr.name === "type") {
  5145. return this.flowParseTypeAlias(node);
  5146. } else if (expr.name === "opaque") {
  5147. return this.flowParseOpaqueType(node, false);
  5148. }
  5149. }
  5150. }
  5151. return super.parseExpressionStatement(node, expr, decorators);
  5152. }
  5153. shouldParseExportDeclaration() {
  5154. const {
  5155. type
  5156. } = this.state;
  5157. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5158. return !this.state.containsEsc;
  5159. }
  5160. return super.shouldParseExportDeclaration();
  5161. }
  5162. isExportDefaultSpecifier() {
  5163. const {
  5164. type
  5165. } = this.state;
  5166. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5167. return this.state.containsEsc;
  5168. }
  5169. return super.isExportDefaultSpecifier();
  5170. }
  5171. parseExportDefaultExpression() {
  5172. if (this.shouldParseEnums() && this.isContextual(124)) {
  5173. const node = this.startNode();
  5174. this.next();
  5175. return this.flowParseEnumDeclaration(node);
  5176. }
  5177. return super.parseExportDefaultExpression();
  5178. }
  5179. parseConditional(expr, startLoc, refExpressionErrors) {
  5180. if (!this.match(17)) return expr;
  5181. if (this.state.maybeInArrowParameters) {
  5182. const nextCh = this.lookaheadCharCode();
  5183. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5184. this.setOptionalParametersError(refExpressionErrors);
  5185. return expr;
  5186. }
  5187. }
  5188. this.expect(17);
  5189. const state = this.state.clone();
  5190. const originalNoArrowAt = this.state.noArrowAt;
  5191. const node = this.startNodeAt(startLoc);
  5192. let {
  5193. consequent,
  5194. failed
  5195. } = this.tryParseConditionalConsequent();
  5196. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5197. if (failed || invalid.length > 0) {
  5198. const noArrowAt = [...originalNoArrowAt];
  5199. if (invalid.length > 0) {
  5200. this.state = state;
  5201. this.state.noArrowAt = noArrowAt;
  5202. for (let i = 0; i < invalid.length; i++) {
  5203. noArrowAt.push(invalid[i].start);
  5204. }
  5205. ({
  5206. consequent,
  5207. failed
  5208. } = this.tryParseConditionalConsequent());
  5209. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5210. }
  5211. if (failed && valid.length > 1) {
  5212. this.raise(FlowErrors.AmbiguousConditionalArrow, {
  5213. at: state.startLoc
  5214. });
  5215. }
  5216. if (failed && valid.length === 1) {
  5217. this.state = state;
  5218. noArrowAt.push(valid[0].start);
  5219. this.state.noArrowAt = noArrowAt;
  5220. ({
  5221. consequent,
  5222. failed
  5223. } = this.tryParseConditionalConsequent());
  5224. }
  5225. }
  5226. this.getArrowLikeExpressions(consequent, true);
  5227. this.state.noArrowAt = originalNoArrowAt;
  5228. this.expect(14);
  5229. node.test = expr;
  5230. node.consequent = consequent;
  5231. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5232. return this.finishNode(node, "ConditionalExpression");
  5233. }
  5234. tryParseConditionalConsequent() {
  5235. this.state.noArrowParamsConversionAt.push(this.state.start);
  5236. const consequent = this.parseMaybeAssignAllowIn();
  5237. const failed = !this.match(14);
  5238. this.state.noArrowParamsConversionAt.pop();
  5239. return {
  5240. consequent,
  5241. failed
  5242. };
  5243. }
  5244. getArrowLikeExpressions(node, disallowInvalid) {
  5245. const stack = [node];
  5246. const arrows = [];
  5247. while (stack.length !== 0) {
  5248. const node = stack.pop();
  5249. if (node.type === "ArrowFunctionExpression") {
  5250. if (node.typeParameters || !node.returnType) {
  5251. this.finishArrowValidation(node);
  5252. } else {
  5253. arrows.push(node);
  5254. }
  5255. stack.push(node.body);
  5256. } else if (node.type === "ConditionalExpression") {
  5257. stack.push(node.consequent);
  5258. stack.push(node.alternate);
  5259. }
  5260. }
  5261. if (disallowInvalid) {
  5262. arrows.forEach(node => this.finishArrowValidation(node));
  5263. return [arrows, []];
  5264. }
  5265. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5266. }
  5267. finishArrowValidation(node) {
  5268. var _node$extra;
  5269. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5270. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  5271. super.checkParams(node, false, true);
  5272. this.scope.exit();
  5273. }
  5274. forwardNoArrowParamsConversionAt(node, parse) {
  5275. let result;
  5276. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5277. this.state.noArrowParamsConversionAt.push(this.state.start);
  5278. result = parse();
  5279. this.state.noArrowParamsConversionAt.pop();
  5280. } else {
  5281. result = parse();
  5282. }
  5283. return result;
  5284. }
  5285. parseParenItem(node, startLoc) {
  5286. node = super.parseParenItem(node, startLoc);
  5287. if (this.eat(17)) {
  5288. node.optional = true;
  5289. this.resetEndLocation(node);
  5290. }
  5291. if (this.match(14)) {
  5292. const typeCastNode = this.startNodeAt(startLoc);
  5293. typeCastNode.expression = node;
  5294. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5295. return this.finishNode(typeCastNode, "TypeCastExpression");
  5296. }
  5297. return node;
  5298. }
  5299. assertModuleNodeAllowed(node) {
  5300. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5301. return;
  5302. }
  5303. super.assertModuleNodeAllowed(node);
  5304. }
  5305. parseExportDeclaration(node) {
  5306. if (this.isContextual(128)) {
  5307. node.exportKind = "type";
  5308. const declarationNode = this.startNode();
  5309. this.next();
  5310. if (this.match(5)) {
  5311. node.specifiers = this.parseExportSpecifiers(true);
  5312. super.parseExportFrom(node);
  5313. return null;
  5314. } else {
  5315. return this.flowParseTypeAlias(declarationNode);
  5316. }
  5317. } else if (this.isContextual(129)) {
  5318. node.exportKind = "type";
  5319. const declarationNode = this.startNode();
  5320. this.next();
  5321. return this.flowParseOpaqueType(declarationNode, false);
  5322. } else if (this.isContextual(127)) {
  5323. node.exportKind = "type";
  5324. const declarationNode = this.startNode();
  5325. this.next();
  5326. return this.flowParseInterface(declarationNode);
  5327. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  5328. node.exportKind = "value";
  5329. const declarationNode = this.startNode();
  5330. this.next();
  5331. return this.flowParseEnumDeclaration(declarationNode);
  5332. } else {
  5333. return super.parseExportDeclaration(node);
  5334. }
  5335. }
  5336. eatExportStar(node) {
  5337. if (super.eatExportStar(node)) return true;
  5338. if (this.isContextual(128) && this.lookahead().type === 55) {
  5339. node.exportKind = "type";
  5340. this.next();
  5341. this.next();
  5342. return true;
  5343. }
  5344. return false;
  5345. }
  5346. maybeParseExportNamespaceSpecifier(node) {
  5347. const {
  5348. startLoc
  5349. } = this.state;
  5350. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5351. if (hasNamespace && node.exportKind === "type") {
  5352. this.unexpected(startLoc);
  5353. }
  5354. return hasNamespace;
  5355. }
  5356. parseClassId(node, isStatement, optionalId) {
  5357. super.parseClassId(node, isStatement, optionalId);
  5358. if (this.match(47)) {
  5359. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5360. }
  5361. }
  5362. parseClassMember(classBody, member, state) {
  5363. const {
  5364. startLoc
  5365. } = this.state;
  5366. if (this.isContextual(123)) {
  5367. if (super.parseClassMemberFromModifier(classBody, member)) {
  5368. return;
  5369. }
  5370. member.declare = true;
  5371. }
  5372. super.parseClassMember(classBody, member, state);
  5373. if (member.declare) {
  5374. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5375. this.raise(FlowErrors.DeclareClassElement, {
  5376. at: startLoc
  5377. });
  5378. } else if (member.value) {
  5379. this.raise(FlowErrors.DeclareClassFieldInitializer, {
  5380. at: member.value
  5381. });
  5382. }
  5383. }
  5384. }
  5385. isIterator(word) {
  5386. return word === "iterator" || word === "asyncIterator";
  5387. }
  5388. readIterator() {
  5389. const word = super.readWord1();
  5390. const fullWord = "@@" + word;
  5391. if (!this.isIterator(word) || !this.state.inType) {
  5392. this.raise(Errors.InvalidIdentifier, {
  5393. at: this.state.curPosition(),
  5394. identifierName: fullWord
  5395. });
  5396. }
  5397. this.finishToken(130, fullWord);
  5398. }
  5399. getTokenFromCode(code) {
  5400. const next = this.input.charCodeAt(this.state.pos + 1);
  5401. if (code === 123 && next === 124) {
  5402. this.finishOp(6, 2);
  5403. } else if (this.state.inType && (code === 62 || code === 60)) {
  5404. this.finishOp(code === 62 ? 48 : 47, 1);
  5405. } else if (this.state.inType && code === 63) {
  5406. if (next === 46) {
  5407. this.finishOp(18, 2);
  5408. } else {
  5409. this.finishOp(17, 1);
  5410. }
  5411. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5412. this.state.pos += 2;
  5413. this.readIterator();
  5414. } else {
  5415. super.getTokenFromCode(code);
  5416. }
  5417. }
  5418. isAssignable(node, isBinding) {
  5419. if (node.type === "TypeCastExpression") {
  5420. return this.isAssignable(node.expression, isBinding);
  5421. } else {
  5422. return super.isAssignable(node, isBinding);
  5423. }
  5424. }
  5425. toAssignable(node, isLHS = false) {
  5426. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5427. node.left = this.typeCastToParameter(node.left);
  5428. }
  5429. super.toAssignable(node, isLHS);
  5430. }
  5431. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5432. for (let i = 0; i < exprList.length; i++) {
  5433. const expr = exprList[i];
  5434. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5435. exprList[i] = this.typeCastToParameter(expr);
  5436. }
  5437. }
  5438. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5439. }
  5440. toReferencedList(exprList, isParenthesizedExpr) {
  5441. for (let i = 0; i < exprList.length; i++) {
  5442. var _expr$extra;
  5443. const expr = exprList[i];
  5444. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5445. this.raise(FlowErrors.TypeCastInPattern, {
  5446. at: expr.typeAnnotation
  5447. });
  5448. }
  5449. }
  5450. return exprList;
  5451. }
  5452. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5453. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5454. if (canBePattern && !this.state.maybeInArrowParameters) {
  5455. this.toReferencedList(node.elements);
  5456. }
  5457. return node;
  5458. }
  5459. isValidLVal(type, isParenthesized, binding) {
  5460. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5461. }
  5462. parseClassProperty(node) {
  5463. if (this.match(14)) {
  5464. node.typeAnnotation = this.flowParseTypeAnnotation();
  5465. }
  5466. return super.parseClassProperty(node);
  5467. }
  5468. parseClassPrivateProperty(node) {
  5469. if (this.match(14)) {
  5470. node.typeAnnotation = this.flowParseTypeAnnotation();
  5471. }
  5472. return super.parseClassPrivateProperty(node);
  5473. }
  5474. isClassMethod() {
  5475. return this.match(47) || super.isClassMethod();
  5476. }
  5477. isClassProperty() {
  5478. return this.match(14) || super.isClassProperty();
  5479. }
  5480. isNonstaticConstructor(method) {
  5481. return !this.match(14) && super.isNonstaticConstructor(method);
  5482. }
  5483. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5484. if (method.variance) {
  5485. this.unexpected(method.variance.loc.start);
  5486. }
  5487. delete method.variance;
  5488. if (this.match(47)) {
  5489. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5490. }
  5491. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5492. if (method.params && isConstructor) {
  5493. const params = method.params;
  5494. if (params.length > 0 && this.isThisParam(params[0])) {
  5495. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5496. at: method
  5497. });
  5498. }
  5499. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5500. const params = method.value.params;
  5501. if (params.length > 0 && this.isThisParam(params[0])) {
  5502. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5503. at: method
  5504. });
  5505. }
  5506. }
  5507. }
  5508. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5509. if (method.variance) {
  5510. this.unexpected(method.variance.loc.start);
  5511. }
  5512. delete method.variance;
  5513. if (this.match(47)) {
  5514. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5515. }
  5516. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5517. }
  5518. parseClassSuper(node) {
  5519. super.parseClassSuper(node);
  5520. if (node.superClass && this.match(47)) {
  5521. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  5522. }
  5523. if (this.isContextual(111)) {
  5524. this.next();
  5525. const implemented = node.implements = [];
  5526. do {
  5527. const node = this.startNode();
  5528. node.id = this.flowParseRestrictedIdentifier(true);
  5529. if (this.match(47)) {
  5530. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5531. } else {
  5532. node.typeParameters = null;
  5533. }
  5534. implemented.push(this.finishNode(node, "ClassImplements"));
  5535. } while (this.eat(12));
  5536. }
  5537. }
  5538. checkGetterSetterParams(method) {
  5539. super.checkGetterSetterParams(method);
  5540. const params = this.getObjectOrClassMethodParams(method);
  5541. if (params.length > 0) {
  5542. const param = params[0];
  5543. if (this.isThisParam(param) && method.kind === "get") {
  5544. this.raise(FlowErrors.GetterMayNotHaveThisParam, {
  5545. at: param
  5546. });
  5547. } else if (this.isThisParam(param)) {
  5548. this.raise(FlowErrors.SetterMayNotHaveThisParam, {
  5549. at: param
  5550. });
  5551. }
  5552. }
  5553. }
  5554. parsePropertyNamePrefixOperator(node) {
  5555. node.variance = this.flowParseVariance();
  5556. }
  5557. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5558. if (prop.variance) {
  5559. this.unexpected(prop.variance.loc.start);
  5560. }
  5561. delete prop.variance;
  5562. let typeParameters;
  5563. if (this.match(47) && !isAccessor) {
  5564. typeParameters = this.flowParseTypeParameterDeclaration();
  5565. if (!this.match(10)) this.unexpected();
  5566. }
  5567. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5568. if (typeParameters) {
  5569. (result.value || result).typeParameters = typeParameters;
  5570. }
  5571. return result;
  5572. }
  5573. parseAssignableListItemTypes(param) {
  5574. if (this.eat(17)) {
  5575. if (param.type !== "Identifier") {
  5576. this.raise(FlowErrors.PatternIsOptional, {
  5577. at: param
  5578. });
  5579. }
  5580. if (this.isThisParam(param)) {
  5581. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  5582. at: param
  5583. });
  5584. }
  5585. param.optional = true;
  5586. }
  5587. if (this.match(14)) {
  5588. param.typeAnnotation = this.flowParseTypeAnnotation();
  5589. } else if (this.isThisParam(param)) {
  5590. this.raise(FlowErrors.ThisParamAnnotationRequired, {
  5591. at: param
  5592. });
  5593. }
  5594. if (this.match(29) && this.isThisParam(param)) {
  5595. this.raise(FlowErrors.ThisParamNoDefault, {
  5596. at: param
  5597. });
  5598. }
  5599. this.resetEndLocation(param);
  5600. return param;
  5601. }
  5602. parseMaybeDefault(startLoc, left) {
  5603. const node = super.parseMaybeDefault(startLoc, left);
  5604. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5605. this.raise(FlowErrors.TypeBeforeInitializer, {
  5606. at: node.typeAnnotation
  5607. });
  5608. }
  5609. return node;
  5610. }
  5611. checkImportReflection(node) {
  5612. super.checkImportReflection(node);
  5613. if (node.module && node.importKind !== "value") {
  5614. this.raise(FlowErrors.ImportReflectionHasImportType, {
  5615. at: node.specifiers[0].loc.start
  5616. });
  5617. }
  5618. }
  5619. parseImportSpecifierLocal(node, specifier, type) {
  5620. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5621. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5622. }
  5623. isPotentialImportPhase(isExport) {
  5624. if (super.isPotentialImportPhase(isExport)) return true;
  5625. if (this.isContextual(128)) {
  5626. if (!isExport) return true;
  5627. const ch = this.lookaheadCharCode();
  5628. return ch === 123 || ch === 42;
  5629. }
  5630. return !isExport && this.isContextual(87);
  5631. }
  5632. applyImportPhase(node, isExport, phase, loc) {
  5633. super.applyImportPhase(node, isExport, phase, loc);
  5634. if (isExport) {
  5635. if (!phase && this.match(65)) {
  5636. return;
  5637. }
  5638. node.exportKind = phase === "type" ? phase : "value";
  5639. } else {
  5640. if (phase === "type" && this.match(55)) this.unexpected();
  5641. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5642. }
  5643. }
  5644. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5645. const firstIdent = specifier.imported;
  5646. let specifierTypeKind = null;
  5647. if (firstIdent.type === "Identifier") {
  5648. if (firstIdent.name === "type") {
  5649. specifierTypeKind = "type";
  5650. } else if (firstIdent.name === "typeof") {
  5651. specifierTypeKind = "typeof";
  5652. }
  5653. }
  5654. let isBinding = false;
  5655. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5656. const as_ident = this.parseIdentifier(true);
  5657. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5658. specifier.imported = as_ident;
  5659. specifier.importKind = specifierTypeKind;
  5660. specifier.local = cloneIdentifier(as_ident);
  5661. } else {
  5662. specifier.imported = firstIdent;
  5663. specifier.importKind = null;
  5664. specifier.local = this.parseIdentifier();
  5665. }
  5666. } else {
  5667. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5668. specifier.imported = this.parseIdentifier(true);
  5669. specifier.importKind = specifierTypeKind;
  5670. } else {
  5671. if (importedIsString) {
  5672. throw this.raise(Errors.ImportBindingIsString, {
  5673. at: specifier,
  5674. importName: firstIdent.value
  5675. });
  5676. }
  5677. specifier.imported = firstIdent;
  5678. specifier.importKind = null;
  5679. }
  5680. if (this.eatContextual(93)) {
  5681. specifier.local = this.parseIdentifier();
  5682. } else {
  5683. isBinding = true;
  5684. specifier.local = cloneIdentifier(specifier.imported);
  5685. }
  5686. }
  5687. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5688. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5689. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
  5690. at: specifier
  5691. });
  5692. }
  5693. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5694. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5695. }
  5696. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5697. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5698. }
  5699. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5700. }
  5701. parseBindingAtom() {
  5702. switch (this.state.type) {
  5703. case 78:
  5704. return this.parseIdentifier(true);
  5705. default:
  5706. return super.parseBindingAtom();
  5707. }
  5708. }
  5709. parseFunctionParams(node, isConstructor) {
  5710. const kind = node.kind;
  5711. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5712. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5713. }
  5714. super.parseFunctionParams(node, isConstructor);
  5715. }
  5716. parseVarId(decl, kind) {
  5717. super.parseVarId(decl, kind);
  5718. if (this.match(14)) {
  5719. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5720. this.resetEndLocation(decl.id);
  5721. }
  5722. }
  5723. parseAsyncArrowFromCallExpression(node, call) {
  5724. if (this.match(14)) {
  5725. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5726. this.state.noAnonFunctionType = true;
  5727. node.returnType = this.flowParseTypeAnnotation();
  5728. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5729. }
  5730. return super.parseAsyncArrowFromCallExpression(node, call);
  5731. }
  5732. shouldParseAsyncArrow() {
  5733. return this.match(14) || super.shouldParseAsyncArrow();
  5734. }
  5735. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5736. var _jsx;
  5737. let state = null;
  5738. let jsx;
  5739. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  5740. state = this.state.clone();
  5741. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5742. if (!jsx.error) return jsx.node;
  5743. const {
  5744. context
  5745. } = this.state;
  5746. const currentContext = context[context.length - 1];
  5747. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5748. context.pop();
  5749. }
  5750. }
  5751. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5752. var _jsx2, _jsx3;
  5753. state = state || this.state.clone();
  5754. let typeParameters;
  5755. const arrow = this.tryParse(abort => {
  5756. var _arrowExpression$extr;
  5757. typeParameters = this.flowParseTypeParameterDeclaration();
  5758. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5759. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5760. this.resetStartLocationFromNode(result, typeParameters);
  5761. return result;
  5762. });
  5763. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5764. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5765. if (expr.type !== "ArrowFunctionExpression") abort();
  5766. expr.typeParameters = typeParameters;
  5767. this.resetStartLocationFromNode(expr, typeParameters);
  5768. return arrowExpression;
  5769. }, state);
  5770. let arrowExpression = null;
  5771. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5772. if (!arrow.error && !arrow.aborted) {
  5773. if (arrow.node.async) {
  5774. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
  5775. at: typeParameters
  5776. });
  5777. }
  5778. return arrow.node;
  5779. }
  5780. arrowExpression = arrow.node;
  5781. }
  5782. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5783. this.state = jsx.failState;
  5784. return jsx.node;
  5785. }
  5786. if (arrowExpression) {
  5787. this.state = arrow.failState;
  5788. return arrowExpression;
  5789. }
  5790. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5791. if (arrow.thrown) throw arrow.error;
  5792. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
  5793. at: typeParameters
  5794. });
  5795. }
  5796. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5797. }
  5798. parseArrow(node) {
  5799. if (this.match(14)) {
  5800. const result = this.tryParse(() => {
  5801. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5802. this.state.noAnonFunctionType = true;
  5803. const typeNode = this.startNode();
  5804. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5805. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5806. if (this.canInsertSemicolon()) this.unexpected();
  5807. if (!this.match(19)) this.unexpected();
  5808. return typeNode;
  5809. });
  5810. if (result.thrown) return null;
  5811. if (result.error) this.state = result.failState;
  5812. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5813. }
  5814. return super.parseArrow(node);
  5815. }
  5816. shouldParseArrow(params) {
  5817. return this.match(14) || super.shouldParseArrow(params);
  5818. }
  5819. setArrowFunctionParameters(node, params) {
  5820. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5821. node.params = params;
  5822. } else {
  5823. super.setArrowFunctionParameters(node, params);
  5824. }
  5825. }
  5826. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5827. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5828. return;
  5829. }
  5830. for (let i = 0; i < node.params.length; i++) {
  5831. if (this.isThisParam(node.params[i]) && i > 0) {
  5832. this.raise(FlowErrors.ThisParamMustBeFirst, {
  5833. at: node.params[i]
  5834. });
  5835. }
  5836. }
  5837. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5838. }
  5839. parseParenAndDistinguishExpression(canBeArrow) {
  5840. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  5841. }
  5842. parseSubscripts(base, startLoc, noCalls) {
  5843. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
  5844. this.next();
  5845. const node = this.startNodeAt(startLoc);
  5846. node.callee = base;
  5847. node.arguments = super.parseCallExpressionArguments(11, false);
  5848. base = this.finishNode(node, "CallExpression");
  5849. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5850. const state = this.state.clone();
  5851. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5852. if (!arrow.error && !arrow.aborted) return arrow.node;
  5853. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5854. if (result.node && !result.error) return result.node;
  5855. if (arrow.node) {
  5856. this.state = arrow.failState;
  5857. return arrow.node;
  5858. }
  5859. if (result.node) {
  5860. this.state = result.failState;
  5861. return result.node;
  5862. }
  5863. throw arrow.error || result.error;
  5864. }
  5865. return super.parseSubscripts(base, startLoc, noCalls);
  5866. }
  5867. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5868. if (this.match(18) && this.isLookaheadToken_lt()) {
  5869. subscriptState.optionalChainMember = true;
  5870. if (noCalls) {
  5871. subscriptState.stop = true;
  5872. return base;
  5873. }
  5874. this.next();
  5875. const node = this.startNodeAt(startLoc);
  5876. node.callee = base;
  5877. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5878. this.expect(10);
  5879. node.arguments = this.parseCallExpressionArguments(11, false);
  5880. node.optional = true;
  5881. return this.finishCallExpression(node, true);
  5882. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  5883. const node = this.startNodeAt(startLoc);
  5884. node.callee = base;
  5885. const result = this.tryParse(() => {
  5886. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5887. this.expect(10);
  5888. node.arguments = super.parseCallExpressionArguments(11, false);
  5889. if (subscriptState.optionalChainMember) {
  5890. node.optional = false;
  5891. }
  5892. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5893. });
  5894. if (result.node) {
  5895. if (result.error) this.state = result.failState;
  5896. return result.node;
  5897. }
  5898. }
  5899. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5900. }
  5901. parseNewCallee(node) {
  5902. super.parseNewCallee(node);
  5903. let targs = null;
  5904. if (this.shouldParseTypes() && this.match(47)) {
  5905. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5906. }
  5907. node.typeArguments = targs;
  5908. }
  5909. parseAsyncArrowWithTypeParameters(startLoc) {
  5910. const node = this.startNodeAt(startLoc);
  5911. this.parseFunctionParams(node, false);
  5912. if (!this.parseArrow(node)) return;
  5913. return super.parseArrowExpression(node, undefined, true);
  5914. }
  5915. readToken_mult_modulo(code) {
  5916. const next = this.input.charCodeAt(this.state.pos + 1);
  5917. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5918. this.state.hasFlowComment = false;
  5919. this.state.pos += 2;
  5920. this.nextToken();
  5921. return;
  5922. }
  5923. super.readToken_mult_modulo(code);
  5924. }
  5925. readToken_pipe_amp(code) {
  5926. const next = this.input.charCodeAt(this.state.pos + 1);
  5927. if (code === 124 && next === 125) {
  5928. this.finishOp(9, 2);
  5929. return;
  5930. }
  5931. super.readToken_pipe_amp(code);
  5932. }
  5933. parseTopLevel(file, program) {
  5934. const fileNode = super.parseTopLevel(file, program);
  5935. if (this.state.hasFlowComment) {
  5936. this.raise(FlowErrors.UnterminatedFlowComment, {
  5937. at: this.state.curPosition()
  5938. });
  5939. }
  5940. return fileNode;
  5941. }
  5942. skipBlockComment() {
  5943. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5944. if (this.state.hasFlowComment) {
  5945. throw this.raise(FlowErrors.NestedFlowComment, {
  5946. at: this.state.startLoc
  5947. });
  5948. }
  5949. this.hasFlowCommentCompletion();
  5950. const commentSkip = this.skipFlowComment();
  5951. if (commentSkip) {
  5952. this.state.pos += commentSkip;
  5953. this.state.hasFlowComment = true;
  5954. }
  5955. return;
  5956. }
  5957. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5958. }
  5959. skipFlowComment() {
  5960. const {
  5961. pos
  5962. } = this.state;
  5963. let shiftToFirstNonWhiteSpace = 2;
  5964. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5965. shiftToFirstNonWhiteSpace++;
  5966. }
  5967. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5968. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5969. if (ch2 === 58 && ch3 === 58) {
  5970. return shiftToFirstNonWhiteSpace + 2;
  5971. }
  5972. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5973. return shiftToFirstNonWhiteSpace + 12;
  5974. }
  5975. if (ch2 === 58 && ch3 !== 58) {
  5976. return shiftToFirstNonWhiteSpace;
  5977. }
  5978. return false;
  5979. }
  5980. hasFlowCommentCompletion() {
  5981. const end = this.input.indexOf("*/", this.state.pos);
  5982. if (end === -1) {
  5983. throw this.raise(Errors.UnterminatedComment, {
  5984. at: this.state.curPosition()
  5985. });
  5986. }
  5987. }
  5988. flowEnumErrorBooleanMemberNotInitialized(loc, {
  5989. enumName,
  5990. memberName
  5991. }) {
  5992. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
  5993. at: loc,
  5994. memberName,
  5995. enumName
  5996. });
  5997. }
  5998. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  5999. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
  6000. at: loc
  6001. }, enumContext));
  6002. }
  6003. flowEnumErrorNumberMemberNotInitialized(loc, {
  6004. enumName,
  6005. memberName
  6006. }) {
  6007. this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
  6008. at: loc,
  6009. enumName,
  6010. memberName
  6011. });
  6012. }
  6013. flowEnumErrorStringMemberInconsistentlyInitailized(node, {
  6014. enumName
  6015. }) {
  6016. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitailized, {
  6017. at: node,
  6018. enumName
  6019. });
  6020. }
  6021. flowEnumMemberInit() {
  6022. const startLoc = this.state.startLoc;
  6023. const endOfInit = () => this.match(12) || this.match(8);
  6024. switch (this.state.type) {
  6025. case 132:
  6026. {
  6027. const literal = this.parseNumericLiteral(this.state.value);
  6028. if (endOfInit()) {
  6029. return {
  6030. type: "number",
  6031. loc: literal.loc.start,
  6032. value: literal
  6033. };
  6034. }
  6035. return {
  6036. type: "invalid",
  6037. loc: startLoc
  6038. };
  6039. }
  6040. case 131:
  6041. {
  6042. const literal = this.parseStringLiteral(this.state.value);
  6043. if (endOfInit()) {
  6044. return {
  6045. type: "string",
  6046. loc: literal.loc.start,
  6047. value: literal
  6048. };
  6049. }
  6050. return {
  6051. type: "invalid",
  6052. loc: startLoc
  6053. };
  6054. }
  6055. case 85:
  6056. case 86:
  6057. {
  6058. const literal = this.parseBooleanLiteral(this.match(85));
  6059. if (endOfInit()) {
  6060. return {
  6061. type: "boolean",
  6062. loc: literal.loc.start,
  6063. value: literal
  6064. };
  6065. }
  6066. return {
  6067. type: "invalid",
  6068. loc: startLoc
  6069. };
  6070. }
  6071. default:
  6072. return {
  6073. type: "invalid",
  6074. loc: startLoc
  6075. };
  6076. }
  6077. }
  6078. flowEnumMemberRaw() {
  6079. const loc = this.state.startLoc;
  6080. const id = this.parseIdentifier(true);
  6081. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6082. type: "none",
  6083. loc
  6084. };
  6085. return {
  6086. id,
  6087. init
  6088. };
  6089. }
  6090. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6091. const {
  6092. explicitType
  6093. } = context;
  6094. if (explicitType === null) {
  6095. return;
  6096. }
  6097. if (explicitType !== expectedType) {
  6098. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6099. }
  6100. }
  6101. flowEnumMembers({
  6102. enumName,
  6103. explicitType
  6104. }) {
  6105. const seenNames = new Set();
  6106. const members = {
  6107. booleanMembers: [],
  6108. numberMembers: [],
  6109. stringMembers: [],
  6110. defaultedMembers: []
  6111. };
  6112. let hasUnknownMembers = false;
  6113. while (!this.match(8)) {
  6114. if (this.eat(21)) {
  6115. hasUnknownMembers = true;
  6116. break;
  6117. }
  6118. const memberNode = this.startNode();
  6119. const {
  6120. id,
  6121. init
  6122. } = this.flowEnumMemberRaw();
  6123. const memberName = id.name;
  6124. if (memberName === "") {
  6125. continue;
  6126. }
  6127. if (/^[a-z]/.test(memberName)) {
  6128. this.raise(FlowErrors.EnumInvalidMemberName, {
  6129. at: id,
  6130. memberName,
  6131. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6132. enumName
  6133. });
  6134. }
  6135. if (seenNames.has(memberName)) {
  6136. this.raise(FlowErrors.EnumDuplicateMemberName, {
  6137. at: id,
  6138. memberName,
  6139. enumName
  6140. });
  6141. }
  6142. seenNames.add(memberName);
  6143. const context = {
  6144. enumName,
  6145. explicitType,
  6146. memberName
  6147. };
  6148. memberNode.id = id;
  6149. switch (init.type) {
  6150. case "boolean":
  6151. {
  6152. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6153. memberNode.init = init.value;
  6154. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6155. break;
  6156. }
  6157. case "number":
  6158. {
  6159. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6160. memberNode.init = init.value;
  6161. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6162. break;
  6163. }
  6164. case "string":
  6165. {
  6166. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6167. memberNode.init = init.value;
  6168. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6169. break;
  6170. }
  6171. case "invalid":
  6172. {
  6173. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6174. }
  6175. case "none":
  6176. {
  6177. switch (explicitType) {
  6178. case "boolean":
  6179. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6180. break;
  6181. case "number":
  6182. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6183. break;
  6184. default:
  6185. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6186. }
  6187. }
  6188. }
  6189. if (!this.match(8)) {
  6190. this.expect(12);
  6191. }
  6192. }
  6193. return {
  6194. members,
  6195. hasUnknownMembers
  6196. };
  6197. }
  6198. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6199. enumName
  6200. }) {
  6201. if (initializedMembers.length === 0) {
  6202. return defaultedMembers;
  6203. } else if (defaultedMembers.length === 0) {
  6204. return initializedMembers;
  6205. } else if (defaultedMembers.length > initializedMembers.length) {
  6206. for (const member of initializedMembers) {
  6207. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6208. enumName
  6209. });
  6210. }
  6211. return defaultedMembers;
  6212. } else {
  6213. for (const member of defaultedMembers) {
  6214. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6215. enumName
  6216. });
  6217. }
  6218. return initializedMembers;
  6219. }
  6220. }
  6221. flowEnumParseExplicitType({
  6222. enumName
  6223. }) {
  6224. if (!this.eatContextual(101)) return null;
  6225. if (!tokenIsIdentifier(this.state.type)) {
  6226. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
  6227. at: this.state.startLoc,
  6228. enumName
  6229. });
  6230. }
  6231. const {
  6232. value
  6233. } = this.state;
  6234. this.next();
  6235. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6236. this.raise(FlowErrors.EnumInvalidExplicitType, {
  6237. at: this.state.startLoc,
  6238. enumName,
  6239. invalidEnumType: value
  6240. });
  6241. }
  6242. return value;
  6243. }
  6244. flowEnumBody(node, id) {
  6245. const enumName = id.name;
  6246. const nameLoc = id.loc.start;
  6247. const explicitType = this.flowEnumParseExplicitType({
  6248. enumName
  6249. });
  6250. this.expect(5);
  6251. const {
  6252. members,
  6253. hasUnknownMembers
  6254. } = this.flowEnumMembers({
  6255. enumName,
  6256. explicitType
  6257. });
  6258. node.hasUnknownMembers = hasUnknownMembers;
  6259. switch (explicitType) {
  6260. case "boolean":
  6261. node.explicitType = true;
  6262. node.members = members.booleanMembers;
  6263. this.expect(8);
  6264. return this.finishNode(node, "EnumBooleanBody");
  6265. case "number":
  6266. node.explicitType = true;
  6267. node.members = members.numberMembers;
  6268. this.expect(8);
  6269. return this.finishNode(node, "EnumNumberBody");
  6270. case "string":
  6271. node.explicitType = true;
  6272. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6273. enumName
  6274. });
  6275. this.expect(8);
  6276. return this.finishNode(node, "EnumStringBody");
  6277. case "symbol":
  6278. node.members = members.defaultedMembers;
  6279. this.expect(8);
  6280. return this.finishNode(node, "EnumSymbolBody");
  6281. default:
  6282. {
  6283. const empty = () => {
  6284. node.members = [];
  6285. this.expect(8);
  6286. return this.finishNode(node, "EnumStringBody");
  6287. };
  6288. node.explicitType = false;
  6289. const boolsLen = members.booleanMembers.length;
  6290. const numsLen = members.numberMembers.length;
  6291. const strsLen = members.stringMembers.length;
  6292. const defaultedLen = members.defaultedMembers.length;
  6293. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6294. return empty();
  6295. } else if (!boolsLen && !numsLen) {
  6296. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6297. enumName
  6298. });
  6299. this.expect(8);
  6300. return this.finishNode(node, "EnumStringBody");
  6301. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6302. for (const member of members.defaultedMembers) {
  6303. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6304. enumName,
  6305. memberName: member.id.name
  6306. });
  6307. }
  6308. node.members = members.booleanMembers;
  6309. this.expect(8);
  6310. return this.finishNode(node, "EnumBooleanBody");
  6311. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6312. for (const member of members.defaultedMembers) {
  6313. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6314. enumName,
  6315. memberName: member.id.name
  6316. });
  6317. }
  6318. node.members = members.numberMembers;
  6319. this.expect(8);
  6320. return this.finishNode(node, "EnumNumberBody");
  6321. } else {
  6322. this.raise(FlowErrors.EnumInconsistentMemberValues, {
  6323. at: nameLoc,
  6324. enumName
  6325. });
  6326. return empty();
  6327. }
  6328. }
  6329. }
  6330. }
  6331. flowParseEnumDeclaration(node) {
  6332. const id = this.parseIdentifier();
  6333. node.id = id;
  6334. node.body = this.flowEnumBody(this.startNode(), id);
  6335. return this.finishNode(node, "EnumDeclaration");
  6336. }
  6337. isLookaheadToken_lt() {
  6338. const next = this.nextTokenStart();
  6339. if (this.input.charCodeAt(next) === 60) {
  6340. const afterNext = this.input.charCodeAt(next + 1);
  6341. return afterNext !== 60 && afterNext !== 61;
  6342. }
  6343. return false;
  6344. }
  6345. maybeUnwrapTypeCastExpression(node) {
  6346. return node.type === "TypeCastExpression" ? node.expression : node;
  6347. }
  6348. };
  6349. const entities = {
  6350. __proto__: null,
  6351. quot: "\u0022",
  6352. amp: "&",
  6353. apos: "\u0027",
  6354. lt: "<",
  6355. gt: ">",
  6356. nbsp: "\u00A0",
  6357. iexcl: "\u00A1",
  6358. cent: "\u00A2",
  6359. pound: "\u00A3",
  6360. curren: "\u00A4",
  6361. yen: "\u00A5",
  6362. brvbar: "\u00A6",
  6363. sect: "\u00A7",
  6364. uml: "\u00A8",
  6365. copy: "\u00A9",
  6366. ordf: "\u00AA",
  6367. laquo: "\u00AB",
  6368. not: "\u00AC",
  6369. shy: "\u00AD",
  6370. reg: "\u00AE",
  6371. macr: "\u00AF",
  6372. deg: "\u00B0",
  6373. plusmn: "\u00B1",
  6374. sup2: "\u00B2",
  6375. sup3: "\u00B3",
  6376. acute: "\u00B4",
  6377. micro: "\u00B5",
  6378. para: "\u00B6",
  6379. middot: "\u00B7",
  6380. cedil: "\u00B8",
  6381. sup1: "\u00B9",
  6382. ordm: "\u00BA",
  6383. raquo: "\u00BB",
  6384. frac14: "\u00BC",
  6385. frac12: "\u00BD",
  6386. frac34: "\u00BE",
  6387. iquest: "\u00BF",
  6388. Agrave: "\u00C0",
  6389. Aacute: "\u00C1",
  6390. Acirc: "\u00C2",
  6391. Atilde: "\u00C3",
  6392. Auml: "\u00C4",
  6393. Aring: "\u00C5",
  6394. AElig: "\u00C6",
  6395. Ccedil: "\u00C7",
  6396. Egrave: "\u00C8",
  6397. Eacute: "\u00C9",
  6398. Ecirc: "\u00CA",
  6399. Euml: "\u00CB",
  6400. Igrave: "\u00CC",
  6401. Iacute: "\u00CD",
  6402. Icirc: "\u00CE",
  6403. Iuml: "\u00CF",
  6404. ETH: "\u00D0",
  6405. Ntilde: "\u00D1",
  6406. Ograve: "\u00D2",
  6407. Oacute: "\u00D3",
  6408. Ocirc: "\u00D4",
  6409. Otilde: "\u00D5",
  6410. Ouml: "\u00D6",
  6411. times: "\u00D7",
  6412. Oslash: "\u00D8",
  6413. Ugrave: "\u00D9",
  6414. Uacute: "\u00DA",
  6415. Ucirc: "\u00DB",
  6416. Uuml: "\u00DC",
  6417. Yacute: "\u00DD",
  6418. THORN: "\u00DE",
  6419. szlig: "\u00DF",
  6420. agrave: "\u00E0",
  6421. aacute: "\u00E1",
  6422. acirc: "\u00E2",
  6423. atilde: "\u00E3",
  6424. auml: "\u00E4",
  6425. aring: "\u00E5",
  6426. aelig: "\u00E6",
  6427. ccedil: "\u00E7",
  6428. egrave: "\u00E8",
  6429. eacute: "\u00E9",
  6430. ecirc: "\u00EA",
  6431. euml: "\u00EB",
  6432. igrave: "\u00EC",
  6433. iacute: "\u00ED",
  6434. icirc: "\u00EE",
  6435. iuml: "\u00EF",
  6436. eth: "\u00F0",
  6437. ntilde: "\u00F1",
  6438. ograve: "\u00F2",
  6439. oacute: "\u00F3",
  6440. ocirc: "\u00F4",
  6441. otilde: "\u00F5",
  6442. ouml: "\u00F6",
  6443. divide: "\u00F7",
  6444. oslash: "\u00F8",
  6445. ugrave: "\u00F9",
  6446. uacute: "\u00FA",
  6447. ucirc: "\u00FB",
  6448. uuml: "\u00FC",
  6449. yacute: "\u00FD",
  6450. thorn: "\u00FE",
  6451. yuml: "\u00FF",
  6452. OElig: "\u0152",
  6453. oelig: "\u0153",
  6454. Scaron: "\u0160",
  6455. scaron: "\u0161",
  6456. Yuml: "\u0178",
  6457. fnof: "\u0192",
  6458. circ: "\u02C6",
  6459. tilde: "\u02DC",
  6460. Alpha: "\u0391",
  6461. Beta: "\u0392",
  6462. Gamma: "\u0393",
  6463. Delta: "\u0394",
  6464. Epsilon: "\u0395",
  6465. Zeta: "\u0396",
  6466. Eta: "\u0397",
  6467. Theta: "\u0398",
  6468. Iota: "\u0399",
  6469. Kappa: "\u039A",
  6470. Lambda: "\u039B",
  6471. Mu: "\u039C",
  6472. Nu: "\u039D",
  6473. Xi: "\u039E",
  6474. Omicron: "\u039F",
  6475. Pi: "\u03A0",
  6476. Rho: "\u03A1",
  6477. Sigma: "\u03A3",
  6478. Tau: "\u03A4",
  6479. Upsilon: "\u03A5",
  6480. Phi: "\u03A6",
  6481. Chi: "\u03A7",
  6482. Psi: "\u03A8",
  6483. Omega: "\u03A9",
  6484. alpha: "\u03B1",
  6485. beta: "\u03B2",
  6486. gamma: "\u03B3",
  6487. delta: "\u03B4",
  6488. epsilon: "\u03B5",
  6489. zeta: "\u03B6",
  6490. eta: "\u03B7",
  6491. theta: "\u03B8",
  6492. iota: "\u03B9",
  6493. kappa: "\u03BA",
  6494. lambda: "\u03BB",
  6495. mu: "\u03BC",
  6496. nu: "\u03BD",
  6497. xi: "\u03BE",
  6498. omicron: "\u03BF",
  6499. pi: "\u03C0",
  6500. rho: "\u03C1",
  6501. sigmaf: "\u03C2",
  6502. sigma: "\u03C3",
  6503. tau: "\u03C4",
  6504. upsilon: "\u03C5",
  6505. phi: "\u03C6",
  6506. chi: "\u03C7",
  6507. psi: "\u03C8",
  6508. omega: "\u03C9",
  6509. thetasym: "\u03D1",
  6510. upsih: "\u03D2",
  6511. piv: "\u03D6",
  6512. ensp: "\u2002",
  6513. emsp: "\u2003",
  6514. thinsp: "\u2009",
  6515. zwnj: "\u200C",
  6516. zwj: "\u200D",
  6517. lrm: "\u200E",
  6518. rlm: "\u200F",
  6519. ndash: "\u2013",
  6520. mdash: "\u2014",
  6521. lsquo: "\u2018",
  6522. rsquo: "\u2019",
  6523. sbquo: "\u201A",
  6524. ldquo: "\u201C",
  6525. rdquo: "\u201D",
  6526. bdquo: "\u201E",
  6527. dagger: "\u2020",
  6528. Dagger: "\u2021",
  6529. bull: "\u2022",
  6530. hellip: "\u2026",
  6531. permil: "\u2030",
  6532. prime: "\u2032",
  6533. Prime: "\u2033",
  6534. lsaquo: "\u2039",
  6535. rsaquo: "\u203A",
  6536. oline: "\u203E",
  6537. frasl: "\u2044",
  6538. euro: "\u20AC",
  6539. image: "\u2111",
  6540. weierp: "\u2118",
  6541. real: "\u211C",
  6542. trade: "\u2122",
  6543. alefsym: "\u2135",
  6544. larr: "\u2190",
  6545. uarr: "\u2191",
  6546. rarr: "\u2192",
  6547. darr: "\u2193",
  6548. harr: "\u2194",
  6549. crarr: "\u21B5",
  6550. lArr: "\u21D0",
  6551. uArr: "\u21D1",
  6552. rArr: "\u21D2",
  6553. dArr: "\u21D3",
  6554. hArr: "\u21D4",
  6555. forall: "\u2200",
  6556. part: "\u2202",
  6557. exist: "\u2203",
  6558. empty: "\u2205",
  6559. nabla: "\u2207",
  6560. isin: "\u2208",
  6561. notin: "\u2209",
  6562. ni: "\u220B",
  6563. prod: "\u220F",
  6564. sum: "\u2211",
  6565. minus: "\u2212",
  6566. lowast: "\u2217",
  6567. radic: "\u221A",
  6568. prop: "\u221D",
  6569. infin: "\u221E",
  6570. ang: "\u2220",
  6571. and: "\u2227",
  6572. or: "\u2228",
  6573. cap: "\u2229",
  6574. cup: "\u222A",
  6575. int: "\u222B",
  6576. there4: "\u2234",
  6577. sim: "\u223C",
  6578. cong: "\u2245",
  6579. asymp: "\u2248",
  6580. ne: "\u2260",
  6581. equiv: "\u2261",
  6582. le: "\u2264",
  6583. ge: "\u2265",
  6584. sub: "\u2282",
  6585. sup: "\u2283",
  6586. nsub: "\u2284",
  6587. sube: "\u2286",
  6588. supe: "\u2287",
  6589. oplus: "\u2295",
  6590. otimes: "\u2297",
  6591. perp: "\u22A5",
  6592. sdot: "\u22C5",
  6593. lceil: "\u2308",
  6594. rceil: "\u2309",
  6595. lfloor: "\u230A",
  6596. rfloor: "\u230B",
  6597. lang: "\u2329",
  6598. rang: "\u232A",
  6599. loz: "\u25CA",
  6600. spades: "\u2660",
  6601. clubs: "\u2663",
  6602. hearts: "\u2665",
  6603. diams: "\u2666"
  6604. };
  6605. const JsxErrors = ParseErrorEnum`jsx`({
  6606. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6607. MissingClosingTagElement: ({
  6608. openingTagName
  6609. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6610. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6611. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6612. UnexpectedToken: ({
  6613. unexpected,
  6614. HTMLEntity
  6615. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6616. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6617. UnterminatedJsxContent: "Unterminated JSX contents.",
  6618. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6619. });
  6620. function isFragment(object) {
  6621. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6622. }
  6623. function getQualifiedJSXName(object) {
  6624. if (object.type === "JSXIdentifier") {
  6625. return object.name;
  6626. }
  6627. if (object.type === "JSXNamespacedName") {
  6628. return object.namespace.name + ":" + object.name.name;
  6629. }
  6630. if (object.type === "JSXMemberExpression") {
  6631. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6632. }
  6633. throw new Error("Node had unexpected type: " + object.type);
  6634. }
  6635. var jsx = superClass => class JSXParserMixin extends superClass {
  6636. jsxReadToken() {
  6637. let out = "";
  6638. let chunkStart = this.state.pos;
  6639. for (;;) {
  6640. if (this.state.pos >= this.length) {
  6641. throw this.raise(JsxErrors.UnterminatedJsxContent, {
  6642. at: this.state.startLoc
  6643. });
  6644. }
  6645. const ch = this.input.charCodeAt(this.state.pos);
  6646. switch (ch) {
  6647. case 60:
  6648. case 123:
  6649. if (this.state.pos === this.state.start) {
  6650. if (ch === 60 && this.state.canStartJSXElement) {
  6651. ++this.state.pos;
  6652. this.finishToken(140);
  6653. } else {
  6654. super.getTokenFromCode(ch);
  6655. }
  6656. return;
  6657. }
  6658. out += this.input.slice(chunkStart, this.state.pos);
  6659. this.finishToken(139, out);
  6660. return;
  6661. case 38:
  6662. out += this.input.slice(chunkStart, this.state.pos);
  6663. out += this.jsxReadEntity();
  6664. chunkStart = this.state.pos;
  6665. break;
  6666. case 62:
  6667. case 125:
  6668. default:
  6669. if (isNewLine(ch)) {
  6670. out += this.input.slice(chunkStart, this.state.pos);
  6671. out += this.jsxReadNewLine(true);
  6672. chunkStart = this.state.pos;
  6673. } else {
  6674. ++this.state.pos;
  6675. }
  6676. }
  6677. }
  6678. }
  6679. jsxReadNewLine(normalizeCRLF) {
  6680. const ch = this.input.charCodeAt(this.state.pos);
  6681. let out;
  6682. ++this.state.pos;
  6683. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6684. ++this.state.pos;
  6685. out = normalizeCRLF ? "\n" : "\r\n";
  6686. } else {
  6687. out = String.fromCharCode(ch);
  6688. }
  6689. ++this.state.curLine;
  6690. this.state.lineStart = this.state.pos;
  6691. return out;
  6692. }
  6693. jsxReadString(quote) {
  6694. let out = "";
  6695. let chunkStart = ++this.state.pos;
  6696. for (;;) {
  6697. if (this.state.pos >= this.length) {
  6698. throw this.raise(Errors.UnterminatedString, {
  6699. at: this.state.startLoc
  6700. });
  6701. }
  6702. const ch = this.input.charCodeAt(this.state.pos);
  6703. if (ch === quote) break;
  6704. if (ch === 38) {
  6705. out += this.input.slice(chunkStart, this.state.pos);
  6706. out += this.jsxReadEntity();
  6707. chunkStart = this.state.pos;
  6708. } else if (isNewLine(ch)) {
  6709. out += this.input.slice(chunkStart, this.state.pos);
  6710. out += this.jsxReadNewLine(false);
  6711. chunkStart = this.state.pos;
  6712. } else {
  6713. ++this.state.pos;
  6714. }
  6715. }
  6716. out += this.input.slice(chunkStart, this.state.pos++);
  6717. this.finishToken(131, out);
  6718. }
  6719. jsxReadEntity() {
  6720. const startPos = ++this.state.pos;
  6721. if (this.codePointAtPos(this.state.pos) === 35) {
  6722. ++this.state.pos;
  6723. let radix = 10;
  6724. if (this.codePointAtPos(this.state.pos) === 120) {
  6725. radix = 16;
  6726. ++this.state.pos;
  6727. }
  6728. const codePoint = this.readInt(radix, undefined, false, "bail");
  6729. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6730. ++this.state.pos;
  6731. return String.fromCodePoint(codePoint);
  6732. }
  6733. } else {
  6734. let count = 0;
  6735. let semi = false;
  6736. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
  6737. ++this.state.pos;
  6738. }
  6739. if (semi) {
  6740. const desc = this.input.slice(startPos, this.state.pos);
  6741. const entity = entities[desc];
  6742. ++this.state.pos;
  6743. if (entity) {
  6744. return entity;
  6745. }
  6746. }
  6747. }
  6748. this.state.pos = startPos;
  6749. return "&";
  6750. }
  6751. jsxReadWord() {
  6752. let ch;
  6753. const start = this.state.pos;
  6754. do {
  6755. ch = this.input.charCodeAt(++this.state.pos);
  6756. } while (isIdentifierChar(ch) || ch === 45);
  6757. this.finishToken(138, this.input.slice(start, this.state.pos));
  6758. }
  6759. jsxParseIdentifier() {
  6760. const node = this.startNode();
  6761. if (this.match(138)) {
  6762. node.name = this.state.value;
  6763. } else if (tokenIsKeyword(this.state.type)) {
  6764. node.name = tokenLabelName(this.state.type);
  6765. } else {
  6766. this.unexpected();
  6767. }
  6768. this.next();
  6769. return this.finishNode(node, "JSXIdentifier");
  6770. }
  6771. jsxParseNamespacedName() {
  6772. const startLoc = this.state.startLoc;
  6773. const name = this.jsxParseIdentifier();
  6774. if (!this.eat(14)) return name;
  6775. const node = this.startNodeAt(startLoc);
  6776. node.namespace = name;
  6777. node.name = this.jsxParseIdentifier();
  6778. return this.finishNode(node, "JSXNamespacedName");
  6779. }
  6780. jsxParseElementName() {
  6781. const startLoc = this.state.startLoc;
  6782. let node = this.jsxParseNamespacedName();
  6783. if (node.type === "JSXNamespacedName") {
  6784. return node;
  6785. }
  6786. while (this.eat(16)) {
  6787. const newNode = this.startNodeAt(startLoc);
  6788. newNode.object = node;
  6789. newNode.property = this.jsxParseIdentifier();
  6790. node = this.finishNode(newNode, "JSXMemberExpression");
  6791. }
  6792. return node;
  6793. }
  6794. jsxParseAttributeValue() {
  6795. let node;
  6796. switch (this.state.type) {
  6797. case 5:
  6798. node = this.startNode();
  6799. this.setContext(types.brace);
  6800. this.next();
  6801. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6802. if (node.expression.type === "JSXEmptyExpression") {
  6803. this.raise(JsxErrors.AttributeIsEmpty, {
  6804. at: node
  6805. });
  6806. }
  6807. return node;
  6808. case 140:
  6809. case 131:
  6810. return this.parseExprAtom();
  6811. default:
  6812. throw this.raise(JsxErrors.UnsupportedJsxValue, {
  6813. at: this.state.startLoc
  6814. });
  6815. }
  6816. }
  6817. jsxParseEmptyExpression() {
  6818. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6819. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6820. }
  6821. jsxParseSpreadChild(node) {
  6822. this.next();
  6823. node.expression = this.parseExpression();
  6824. this.setContext(types.j_expr);
  6825. this.state.canStartJSXElement = true;
  6826. this.expect(8);
  6827. return this.finishNode(node, "JSXSpreadChild");
  6828. }
  6829. jsxParseExpressionContainer(node, previousContext) {
  6830. if (this.match(8)) {
  6831. node.expression = this.jsxParseEmptyExpression();
  6832. } else {
  6833. const expression = this.parseExpression();
  6834. node.expression = expression;
  6835. }
  6836. this.setContext(previousContext);
  6837. this.state.canStartJSXElement = true;
  6838. this.expect(8);
  6839. return this.finishNode(node, "JSXExpressionContainer");
  6840. }
  6841. jsxParseAttribute() {
  6842. const node = this.startNode();
  6843. if (this.match(5)) {
  6844. this.setContext(types.brace);
  6845. this.next();
  6846. this.expect(21);
  6847. node.argument = this.parseMaybeAssignAllowIn();
  6848. this.setContext(types.j_oTag);
  6849. this.state.canStartJSXElement = true;
  6850. this.expect(8);
  6851. return this.finishNode(node, "JSXSpreadAttribute");
  6852. }
  6853. node.name = this.jsxParseNamespacedName();
  6854. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6855. return this.finishNode(node, "JSXAttribute");
  6856. }
  6857. jsxParseOpeningElementAt(startLoc) {
  6858. const node = this.startNodeAt(startLoc);
  6859. if (this.eat(141)) {
  6860. return this.finishNode(node, "JSXOpeningFragment");
  6861. }
  6862. node.name = this.jsxParseElementName();
  6863. return this.jsxParseOpeningElementAfterName(node);
  6864. }
  6865. jsxParseOpeningElementAfterName(node) {
  6866. const attributes = [];
  6867. while (!this.match(56) && !this.match(141)) {
  6868. attributes.push(this.jsxParseAttribute());
  6869. }
  6870. node.attributes = attributes;
  6871. node.selfClosing = this.eat(56);
  6872. this.expect(141);
  6873. return this.finishNode(node, "JSXOpeningElement");
  6874. }
  6875. jsxParseClosingElementAt(startLoc) {
  6876. const node = this.startNodeAt(startLoc);
  6877. if (this.eat(141)) {
  6878. return this.finishNode(node, "JSXClosingFragment");
  6879. }
  6880. node.name = this.jsxParseElementName();
  6881. this.expect(141);
  6882. return this.finishNode(node, "JSXClosingElement");
  6883. }
  6884. jsxParseElementAt(startLoc) {
  6885. const node = this.startNodeAt(startLoc);
  6886. const children = [];
  6887. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6888. let closingElement = null;
  6889. if (!openingElement.selfClosing) {
  6890. contents: for (;;) {
  6891. switch (this.state.type) {
  6892. case 140:
  6893. startLoc = this.state.startLoc;
  6894. this.next();
  6895. if (this.eat(56)) {
  6896. closingElement = this.jsxParseClosingElementAt(startLoc);
  6897. break contents;
  6898. }
  6899. children.push(this.jsxParseElementAt(startLoc));
  6900. break;
  6901. case 139:
  6902. children.push(this.parseExprAtom());
  6903. break;
  6904. case 5:
  6905. {
  6906. const node = this.startNode();
  6907. this.setContext(types.brace);
  6908. this.next();
  6909. if (this.match(21)) {
  6910. children.push(this.jsxParseSpreadChild(node));
  6911. } else {
  6912. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6913. }
  6914. break;
  6915. }
  6916. default:
  6917. this.unexpected();
  6918. }
  6919. }
  6920. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6921. this.raise(JsxErrors.MissingClosingTagFragment, {
  6922. at: closingElement
  6923. });
  6924. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6925. this.raise(JsxErrors.MissingClosingTagElement, {
  6926. at: closingElement,
  6927. openingTagName: getQualifiedJSXName(openingElement.name)
  6928. });
  6929. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6930. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6931. this.raise(JsxErrors.MissingClosingTagElement, {
  6932. at: closingElement,
  6933. openingTagName: getQualifiedJSXName(openingElement.name)
  6934. });
  6935. }
  6936. }
  6937. }
  6938. if (isFragment(openingElement)) {
  6939. node.openingFragment = openingElement;
  6940. node.closingFragment = closingElement;
  6941. } else {
  6942. node.openingElement = openingElement;
  6943. node.closingElement = closingElement;
  6944. }
  6945. node.children = children;
  6946. if (this.match(47)) {
  6947. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
  6948. at: this.state.startLoc
  6949. });
  6950. }
  6951. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6952. }
  6953. jsxParseElement() {
  6954. const startLoc = this.state.startLoc;
  6955. this.next();
  6956. return this.jsxParseElementAt(startLoc);
  6957. }
  6958. setContext(newContext) {
  6959. const {
  6960. context
  6961. } = this.state;
  6962. context[context.length - 1] = newContext;
  6963. }
  6964. parseExprAtom(refExpressionErrors) {
  6965. if (this.match(139)) {
  6966. return this.parseLiteral(this.state.value, "JSXText");
  6967. } else if (this.match(140)) {
  6968. return this.jsxParseElement();
  6969. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  6970. this.replaceToken(140);
  6971. return this.jsxParseElement();
  6972. } else {
  6973. return super.parseExprAtom(refExpressionErrors);
  6974. }
  6975. }
  6976. skipSpace() {
  6977. const curContext = this.curContext();
  6978. if (!curContext.preserveSpace) super.skipSpace();
  6979. }
  6980. getTokenFromCode(code) {
  6981. const context = this.curContext();
  6982. if (context === types.j_expr) {
  6983. this.jsxReadToken();
  6984. return;
  6985. }
  6986. if (context === types.j_oTag || context === types.j_cTag) {
  6987. if (isIdentifierStart(code)) {
  6988. this.jsxReadWord();
  6989. return;
  6990. }
  6991. if (code === 62) {
  6992. ++this.state.pos;
  6993. this.finishToken(141);
  6994. return;
  6995. }
  6996. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6997. this.jsxReadString(code);
  6998. return;
  6999. }
  7000. }
  7001. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  7002. ++this.state.pos;
  7003. this.finishToken(140);
  7004. return;
  7005. }
  7006. super.getTokenFromCode(code);
  7007. }
  7008. updateContext(prevType) {
  7009. const {
  7010. context,
  7011. type
  7012. } = this.state;
  7013. if (type === 56 && prevType === 140) {
  7014. context.splice(-2, 2, types.j_cTag);
  7015. this.state.canStartJSXElement = false;
  7016. } else if (type === 140) {
  7017. context.push(types.j_oTag);
  7018. } else if (type === 141) {
  7019. const out = context[context.length - 1];
  7020. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  7021. context.pop();
  7022. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  7023. } else {
  7024. this.setContext(types.j_expr);
  7025. this.state.canStartJSXElement = true;
  7026. }
  7027. } else {
  7028. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  7029. }
  7030. }
  7031. };
  7032. class TypeScriptScope extends Scope {
  7033. constructor(...args) {
  7034. super(...args);
  7035. this.types = new Set();
  7036. this.enums = new Set();
  7037. this.constEnums = new Set();
  7038. this.classes = new Set();
  7039. this.exportOnlyBindings = new Set();
  7040. }
  7041. }
  7042. class TypeScriptScopeHandler extends ScopeHandler {
  7043. constructor(...args) {
  7044. super(...args);
  7045. this.importsStack = [];
  7046. }
  7047. createScope(flags) {
  7048. this.importsStack.push(new Set());
  7049. return new TypeScriptScope(flags);
  7050. }
  7051. enter(flags) {
  7052. if (flags == SCOPE_TS_MODULE) {
  7053. this.importsStack.push(new Set());
  7054. }
  7055. super.enter(flags);
  7056. }
  7057. exit() {
  7058. const flags = super.exit();
  7059. if (flags == SCOPE_TS_MODULE) {
  7060. this.importsStack.pop();
  7061. }
  7062. return flags;
  7063. }
  7064. hasImport(name, allowShadow) {
  7065. const len = this.importsStack.length;
  7066. if (this.importsStack[len - 1].has(name)) {
  7067. return true;
  7068. }
  7069. if (!allowShadow && len > 1) {
  7070. for (let i = 0; i < len - 1; i++) {
  7071. if (this.importsStack[i].has(name)) return true;
  7072. }
  7073. }
  7074. return false;
  7075. }
  7076. declareName(name, bindingType, loc) {
  7077. if (bindingType & BIND_FLAGS_TS_IMPORT) {
  7078. if (this.hasImport(name, true)) {
  7079. this.parser.raise(Errors.VarRedeclaration, {
  7080. at: loc,
  7081. identifierName: name
  7082. });
  7083. }
  7084. this.importsStack[this.importsStack.length - 1].add(name);
  7085. return;
  7086. }
  7087. const scope = this.currentScope();
  7088. if (bindingType & BIND_FLAGS_TS_EXPORT_ONLY) {
  7089. this.maybeExportDefined(scope, name);
  7090. scope.exportOnlyBindings.add(name);
  7091. return;
  7092. }
  7093. super.declareName(name, bindingType, loc);
  7094. if (bindingType & BIND_KIND_TYPE) {
  7095. if (!(bindingType & BIND_KIND_VALUE)) {
  7096. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7097. this.maybeExportDefined(scope, name);
  7098. }
  7099. scope.types.add(name);
  7100. }
  7101. if (bindingType & BIND_FLAGS_TS_ENUM) scope.enums.add(name);
  7102. if (bindingType & BIND_FLAGS_TS_CONST_ENUM) scope.constEnums.add(name);
  7103. if (bindingType & BIND_FLAGS_CLASS) scope.classes.add(name);
  7104. }
  7105. isRedeclaredInScope(scope, name, bindingType) {
  7106. if (scope.enums.has(name)) {
  7107. if (bindingType & BIND_FLAGS_TS_ENUM) {
  7108. const isConst = !!(bindingType & BIND_FLAGS_TS_CONST_ENUM);
  7109. const wasConst = scope.constEnums.has(name);
  7110. return isConst !== wasConst;
  7111. }
  7112. return true;
  7113. }
  7114. if (bindingType & BIND_FLAGS_CLASS && scope.classes.has(name)) {
  7115. if (scope.lexical.has(name)) {
  7116. return !!(bindingType & BIND_KIND_VALUE);
  7117. } else {
  7118. return false;
  7119. }
  7120. }
  7121. if (bindingType & BIND_KIND_TYPE && scope.types.has(name)) {
  7122. return true;
  7123. }
  7124. return super.isRedeclaredInScope(scope, name, bindingType);
  7125. }
  7126. checkLocalExport(id) {
  7127. const {
  7128. name
  7129. } = id;
  7130. if (this.hasImport(name)) return;
  7131. const len = this.scopeStack.length;
  7132. for (let i = len - 1; i >= 0; i--) {
  7133. const scope = this.scopeStack[i];
  7134. if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return;
  7135. }
  7136. super.checkLocalExport(id);
  7137. }
  7138. }
  7139. const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7140. const unwrapParenthesizedExpression = node => {
  7141. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7142. };
  7143. class LValParser extends NodeUtils {
  7144. toAssignable(node, isLHS = false) {
  7145. var _node$extra, _node$extra3;
  7146. let parenthesized = undefined;
  7147. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7148. parenthesized = unwrapParenthesizedExpression(node);
  7149. if (isLHS) {
  7150. if (parenthesized.type === "Identifier") {
  7151. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
  7152. at: node
  7153. });
  7154. } else if (parenthesized.type !== "MemberExpression") {
  7155. this.raise(Errors.InvalidParenthesizedAssignment, {
  7156. at: node
  7157. });
  7158. }
  7159. } else {
  7160. this.raise(Errors.InvalidParenthesizedAssignment, {
  7161. at: node
  7162. });
  7163. }
  7164. }
  7165. switch (node.type) {
  7166. case "Identifier":
  7167. case "ObjectPattern":
  7168. case "ArrayPattern":
  7169. case "AssignmentPattern":
  7170. case "RestElement":
  7171. break;
  7172. case "ObjectExpression":
  7173. node.type = "ObjectPattern";
  7174. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7175. var _node$extra2;
  7176. const prop = node.properties[i];
  7177. const isLast = i === last;
  7178. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7179. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7180. this.raise(Errors.RestTrailingComma, {
  7181. at: node.extra.trailingCommaLoc
  7182. });
  7183. }
  7184. }
  7185. break;
  7186. case "ObjectProperty":
  7187. {
  7188. const {
  7189. key,
  7190. value
  7191. } = node;
  7192. if (this.isPrivateName(key)) {
  7193. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7194. }
  7195. this.toAssignable(value, isLHS);
  7196. break;
  7197. }
  7198. case "SpreadElement":
  7199. {
  7200. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7201. }
  7202. case "ArrayExpression":
  7203. node.type = "ArrayPattern";
  7204. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7205. break;
  7206. case "AssignmentExpression":
  7207. if (node.operator !== "=") {
  7208. this.raise(Errors.MissingEqInAssignment, {
  7209. at: node.left.loc.end
  7210. });
  7211. }
  7212. node.type = "AssignmentPattern";
  7213. delete node.operator;
  7214. this.toAssignable(node.left, isLHS);
  7215. break;
  7216. case "ParenthesizedExpression":
  7217. this.toAssignable(parenthesized, isLHS);
  7218. break;
  7219. }
  7220. }
  7221. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7222. if (prop.type === "ObjectMethod") {
  7223. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
  7224. at: prop.key
  7225. });
  7226. } else if (prop.type === "SpreadElement") {
  7227. prop.type = "RestElement";
  7228. const arg = prop.argument;
  7229. this.checkToRestConversion(arg, false);
  7230. this.toAssignable(arg, isLHS);
  7231. if (!isLast) {
  7232. this.raise(Errors.RestTrailingComma, {
  7233. at: prop
  7234. });
  7235. }
  7236. } else {
  7237. this.toAssignable(prop, isLHS);
  7238. }
  7239. }
  7240. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7241. const end = exprList.length - 1;
  7242. for (let i = 0; i <= end; i++) {
  7243. const elt = exprList[i];
  7244. if (!elt) continue;
  7245. if (elt.type === "SpreadElement") {
  7246. elt.type = "RestElement";
  7247. const arg = elt.argument;
  7248. this.checkToRestConversion(arg, true);
  7249. this.toAssignable(arg, isLHS);
  7250. } else {
  7251. this.toAssignable(elt, isLHS);
  7252. }
  7253. if (elt.type === "RestElement") {
  7254. if (i < end) {
  7255. this.raise(Errors.RestTrailingComma, {
  7256. at: elt
  7257. });
  7258. } else if (trailingCommaLoc) {
  7259. this.raise(Errors.RestTrailingComma, {
  7260. at: trailingCommaLoc
  7261. });
  7262. }
  7263. }
  7264. }
  7265. }
  7266. isAssignable(node, isBinding) {
  7267. switch (node.type) {
  7268. case "Identifier":
  7269. case "ObjectPattern":
  7270. case "ArrayPattern":
  7271. case "AssignmentPattern":
  7272. case "RestElement":
  7273. return true;
  7274. case "ObjectExpression":
  7275. {
  7276. const last = node.properties.length - 1;
  7277. return node.properties.every((prop, i) => {
  7278. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7279. });
  7280. }
  7281. case "ObjectProperty":
  7282. return this.isAssignable(node.value);
  7283. case "SpreadElement":
  7284. return this.isAssignable(node.argument);
  7285. case "ArrayExpression":
  7286. return node.elements.every(element => element === null || this.isAssignable(element));
  7287. case "AssignmentExpression":
  7288. return node.operator === "=";
  7289. case "ParenthesizedExpression":
  7290. return this.isAssignable(node.expression);
  7291. case "MemberExpression":
  7292. case "OptionalMemberExpression":
  7293. return !isBinding;
  7294. default:
  7295. return false;
  7296. }
  7297. }
  7298. toReferencedList(exprList, isParenthesizedExpr) {
  7299. return exprList;
  7300. }
  7301. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7302. this.toReferencedList(exprList, isParenthesizedExpr);
  7303. for (const expr of exprList) {
  7304. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7305. this.toReferencedListDeep(expr.elements);
  7306. }
  7307. }
  7308. }
  7309. parseSpread(refExpressionErrors) {
  7310. const node = this.startNode();
  7311. this.next();
  7312. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7313. return this.finishNode(node, "SpreadElement");
  7314. }
  7315. parseRestBinding() {
  7316. const node = this.startNode();
  7317. this.next();
  7318. node.argument = this.parseBindingAtom();
  7319. return this.finishNode(node, "RestElement");
  7320. }
  7321. parseBindingAtom() {
  7322. switch (this.state.type) {
  7323. case 0:
  7324. {
  7325. const node = this.startNode();
  7326. this.next();
  7327. node.elements = this.parseBindingList(3, 93, 1);
  7328. return this.finishNode(node, "ArrayPattern");
  7329. }
  7330. case 5:
  7331. return this.parseObjectLike(8, true);
  7332. }
  7333. return this.parseIdentifier();
  7334. }
  7335. parseBindingList(close, closeCharCode, flags) {
  7336. const allowEmpty = flags & 1;
  7337. const elts = [];
  7338. let first = true;
  7339. while (!this.eat(close)) {
  7340. if (first) {
  7341. first = false;
  7342. } else {
  7343. this.expect(12);
  7344. }
  7345. if (allowEmpty && this.match(12)) {
  7346. elts.push(null);
  7347. } else if (this.eat(close)) {
  7348. break;
  7349. } else if (this.match(21)) {
  7350. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
  7351. if (!this.checkCommaAfterRest(closeCharCode)) {
  7352. this.expect(close);
  7353. break;
  7354. }
  7355. } else {
  7356. const decorators = [];
  7357. if (this.match(26) && this.hasPlugin("decorators")) {
  7358. this.raise(Errors.UnsupportedParameterDecorator, {
  7359. at: this.state.startLoc
  7360. });
  7361. }
  7362. while (this.match(26)) {
  7363. decorators.push(this.parseDecorator());
  7364. }
  7365. elts.push(this.parseAssignableListItem(flags, decorators));
  7366. }
  7367. }
  7368. return elts;
  7369. }
  7370. parseBindingRestProperty(prop) {
  7371. this.next();
  7372. prop.argument = this.parseIdentifier();
  7373. this.checkCommaAfterRest(125);
  7374. return this.finishNode(prop, "RestElement");
  7375. }
  7376. parseBindingProperty() {
  7377. const prop = this.startNode();
  7378. const {
  7379. type,
  7380. startLoc
  7381. } = this.state;
  7382. if (type === 21) {
  7383. return this.parseBindingRestProperty(prop);
  7384. } else if (type === 136) {
  7385. this.expectPlugin("destructuringPrivate", startLoc);
  7386. this.classScope.usePrivateName(this.state.value, startLoc);
  7387. prop.key = this.parsePrivateName();
  7388. } else {
  7389. this.parsePropertyName(prop);
  7390. }
  7391. prop.method = false;
  7392. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7393. }
  7394. parseAssignableListItem(flags, decorators) {
  7395. const left = this.parseMaybeDefault();
  7396. this.parseAssignableListItemTypes(left, flags);
  7397. const elt = this.parseMaybeDefault(left.loc.start, left);
  7398. if (decorators.length) {
  7399. left.decorators = decorators;
  7400. }
  7401. return elt;
  7402. }
  7403. parseAssignableListItemTypes(param, flags) {
  7404. return param;
  7405. }
  7406. parseMaybeDefault(startLoc, left) {
  7407. var _startLoc, _left;
  7408. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  7409. left = (_left = left) != null ? _left : this.parseBindingAtom();
  7410. if (!this.eat(29)) return left;
  7411. const node = this.startNodeAt(startLoc);
  7412. node.left = left;
  7413. node.right = this.parseMaybeAssignAllowIn();
  7414. return this.finishNode(node, "AssignmentPattern");
  7415. }
  7416. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7417. return getOwn$1({
  7418. AssignmentPattern: "left",
  7419. RestElement: "argument",
  7420. ObjectProperty: "value",
  7421. ParenthesizedExpression: "expression",
  7422. ArrayPattern: "elements",
  7423. ObjectPattern: "properties"
  7424. }, type);
  7425. }
  7426. checkLVal(expression, {
  7427. in: ancestor,
  7428. binding = BIND_NONE,
  7429. checkClashes = false,
  7430. strictModeChanged = false,
  7431. hasParenthesizedAncestor = false
  7432. }) {
  7433. var _expression$extra;
  7434. const type = expression.type;
  7435. if (this.isObjectMethod(expression)) return;
  7436. if (type === "MemberExpression") {
  7437. if (binding !== BIND_NONE) {
  7438. this.raise(Errors.InvalidPropertyBindingPattern, {
  7439. at: expression
  7440. });
  7441. }
  7442. return;
  7443. }
  7444. if (type === "Identifier") {
  7445. this.checkIdentifier(expression, binding, strictModeChanged);
  7446. const {
  7447. name
  7448. } = expression;
  7449. if (checkClashes) {
  7450. if (checkClashes.has(name)) {
  7451. this.raise(Errors.ParamDupe, {
  7452. at: expression
  7453. });
  7454. } else {
  7455. checkClashes.add(name);
  7456. }
  7457. }
  7458. return;
  7459. }
  7460. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7461. if (validity === true) return;
  7462. if (validity === false) {
  7463. const ParseErrorClass = binding === BIND_NONE ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7464. this.raise(ParseErrorClass, {
  7465. at: expression,
  7466. ancestor
  7467. });
  7468. return;
  7469. }
  7470. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  7471. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" || type === "ParenthesizedExpression" ? {
  7472. type
  7473. } : ancestor;
  7474. for (const child of [].concat(expression[key])) {
  7475. if (child) {
  7476. this.checkLVal(child, {
  7477. in: nextAncestor,
  7478. binding,
  7479. checkClashes,
  7480. strictModeChanged,
  7481. hasParenthesizedAncestor: isParenthesizedExpression
  7482. });
  7483. }
  7484. }
  7485. }
  7486. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7487. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7488. if (bindingType === BIND_NONE) {
  7489. this.raise(Errors.StrictEvalArguments, {
  7490. at,
  7491. referenceName: at.name
  7492. });
  7493. } else {
  7494. this.raise(Errors.StrictEvalArgumentsBinding, {
  7495. at,
  7496. bindingName: at.name
  7497. });
  7498. }
  7499. }
  7500. if (bindingType & BIND_FLAGS_NO_LET_IN_LEXICAL && at.name === "let") {
  7501. this.raise(Errors.LetInLexicalBinding, {
  7502. at
  7503. });
  7504. }
  7505. if (!(bindingType & BIND_NONE)) {
  7506. this.declareNameFromIdentifier(at, bindingType);
  7507. }
  7508. }
  7509. declareNameFromIdentifier(identifier, binding) {
  7510. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7511. }
  7512. checkToRestConversion(node, allowPattern) {
  7513. switch (node.type) {
  7514. case "ParenthesizedExpression":
  7515. this.checkToRestConversion(node.expression, allowPattern);
  7516. break;
  7517. case "Identifier":
  7518. case "MemberExpression":
  7519. break;
  7520. case "ArrayExpression":
  7521. case "ObjectExpression":
  7522. if (allowPattern) break;
  7523. default:
  7524. this.raise(Errors.InvalidRestAssignmentPattern, {
  7525. at: node
  7526. });
  7527. }
  7528. }
  7529. checkCommaAfterRest(close) {
  7530. if (!this.match(12)) {
  7531. return false;
  7532. }
  7533. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
  7534. at: this.state.startLoc
  7535. });
  7536. return true;
  7537. }
  7538. }
  7539. const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7540. function nonNull(x) {
  7541. if (x == null) {
  7542. throw new Error(`Unexpected ${x} value.`);
  7543. }
  7544. return x;
  7545. }
  7546. function assert(x) {
  7547. if (!x) {
  7548. throw new Error("Assert fail");
  7549. }
  7550. }
  7551. const TSErrors = ParseErrorEnum`typescript`({
  7552. AbstractMethodHasImplementation: ({
  7553. methodName
  7554. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7555. AbstractPropertyHasInitializer: ({
  7556. propertyName
  7557. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7558. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7559. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7560. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7561. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7562. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7563. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7564. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7565. DeclareAccessor: ({
  7566. kind
  7567. }) => `'declare' is not allowed in ${kind}ters.`,
  7568. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7569. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7570. DuplicateAccessibilityModifier: ({
  7571. modifier
  7572. }) => `Accessibility modifier already seen.`,
  7573. DuplicateModifier: ({
  7574. modifier
  7575. }) => `Duplicate modifier: '${modifier}'.`,
  7576. EmptyHeritageClauseType: ({
  7577. token
  7578. }) => `'${token}' list cannot be empty.`,
  7579. EmptyTypeArguments: "Type argument list cannot be empty.",
  7580. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7581. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7582. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7583. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7584. IncompatibleModifiers: ({
  7585. modifiers
  7586. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7587. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7588. IndexSignatureHasAccessibility: ({
  7589. modifier
  7590. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7591. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7592. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7593. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7594. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7595. InvalidModifierOnTypeMember: ({
  7596. modifier
  7597. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7598. InvalidModifierOnTypeParameter: ({
  7599. modifier
  7600. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7601. InvalidModifierOnTypeParameterPositions: ({
  7602. modifier
  7603. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7604. InvalidModifiersOrder: ({
  7605. orderedModifiers
  7606. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7607. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7608. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7609. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7610. MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
  7611. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7612. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7613. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7614. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7615. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7616. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7617. PrivateElementHasAccessibility: ({
  7618. modifier
  7619. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7620. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7621. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7622. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7623. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7624. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7625. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7626. SingleTypeParameterWithoutTrailingComma: ({
  7627. typeParameterName
  7628. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7629. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7630. 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?`).",
  7631. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7632. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7633. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7634. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7635. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7636. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7637. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7638. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7639. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7640. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7641. UnsupportedSignatureParameterKind: ({
  7642. type
  7643. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7644. });
  7645. function keywordTypeFromName(value) {
  7646. switch (value) {
  7647. case "any":
  7648. return "TSAnyKeyword";
  7649. case "boolean":
  7650. return "TSBooleanKeyword";
  7651. case "bigint":
  7652. return "TSBigIntKeyword";
  7653. case "never":
  7654. return "TSNeverKeyword";
  7655. case "number":
  7656. return "TSNumberKeyword";
  7657. case "object":
  7658. return "TSObjectKeyword";
  7659. case "string":
  7660. return "TSStringKeyword";
  7661. case "symbol":
  7662. return "TSSymbolKeyword";
  7663. case "undefined":
  7664. return "TSUndefinedKeyword";
  7665. case "unknown":
  7666. return "TSUnknownKeyword";
  7667. default:
  7668. return undefined;
  7669. }
  7670. }
  7671. function tsIsAccessModifier(modifier) {
  7672. return modifier === "private" || modifier === "public" || modifier === "protected";
  7673. }
  7674. function tsIsVarianceAnnotations(modifier) {
  7675. return modifier === "in" || modifier === "out";
  7676. }
  7677. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7678. constructor(...args) {
  7679. super(...args);
  7680. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7681. allowedModifiers: ["in", "out"],
  7682. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7683. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7684. });
  7685. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7686. allowedModifiers: ["const"],
  7687. disallowedModifiers: ["in", "out"],
  7688. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7689. });
  7690. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7691. allowedModifiers: ["in", "out", "const"],
  7692. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7693. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7694. });
  7695. }
  7696. getScopeHandler() {
  7697. return TypeScriptScopeHandler;
  7698. }
  7699. tsIsIdentifier() {
  7700. return tokenIsIdentifier(this.state.type);
  7701. }
  7702. tsTokenCanFollowModifier() {
  7703. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(136) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  7704. }
  7705. tsNextTokenCanFollowModifier() {
  7706. this.next();
  7707. return this.tsTokenCanFollowModifier();
  7708. }
  7709. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7710. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7711. return undefined;
  7712. }
  7713. const modifier = this.state.value;
  7714. if (allowedModifiers.indexOf(modifier) !== -1) {
  7715. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7716. return undefined;
  7717. }
  7718. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7719. return modifier;
  7720. }
  7721. }
  7722. return undefined;
  7723. }
  7724. tsParseModifiers({
  7725. allowedModifiers,
  7726. disallowedModifiers,
  7727. stopOnStartOfClassStaticBlock,
  7728. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7729. }, modified) {
  7730. const enforceOrder = (loc, modifier, before, after) => {
  7731. if (modifier === before && modified[after]) {
  7732. this.raise(TSErrors.InvalidModifiersOrder, {
  7733. at: loc,
  7734. orderedModifiers: [before, after]
  7735. });
  7736. }
  7737. };
  7738. const incompatible = (loc, modifier, mod1, mod2) => {
  7739. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7740. this.raise(TSErrors.IncompatibleModifiers, {
  7741. at: loc,
  7742. modifiers: [mod1, mod2]
  7743. });
  7744. }
  7745. };
  7746. for (;;) {
  7747. const {
  7748. startLoc
  7749. } = this.state;
  7750. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7751. if (!modifier) break;
  7752. if (tsIsAccessModifier(modifier)) {
  7753. if (modified.accessibility) {
  7754. this.raise(TSErrors.DuplicateAccessibilityModifier, {
  7755. at: startLoc,
  7756. modifier
  7757. });
  7758. } else {
  7759. enforceOrder(startLoc, modifier, modifier, "override");
  7760. enforceOrder(startLoc, modifier, modifier, "static");
  7761. enforceOrder(startLoc, modifier, modifier, "readonly");
  7762. modified.accessibility = modifier;
  7763. }
  7764. } else if (tsIsVarianceAnnotations(modifier)) {
  7765. if (modified[modifier]) {
  7766. this.raise(TSErrors.DuplicateModifier, {
  7767. at: startLoc,
  7768. modifier
  7769. });
  7770. }
  7771. modified[modifier] = true;
  7772. enforceOrder(startLoc, modifier, "in", "out");
  7773. } else {
  7774. if (Object.hasOwnProperty.call(modified, modifier)) {
  7775. this.raise(TSErrors.DuplicateModifier, {
  7776. at: startLoc,
  7777. modifier
  7778. });
  7779. } else {
  7780. enforceOrder(startLoc, modifier, "static", "readonly");
  7781. enforceOrder(startLoc, modifier, "static", "override");
  7782. enforceOrder(startLoc, modifier, "override", "readonly");
  7783. enforceOrder(startLoc, modifier, "abstract", "override");
  7784. incompatible(startLoc, modifier, "declare", "override");
  7785. incompatible(startLoc, modifier, "static", "abstract");
  7786. }
  7787. modified[modifier] = true;
  7788. }
  7789. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7790. this.raise(errorTemplate, {
  7791. at: startLoc,
  7792. modifier
  7793. });
  7794. }
  7795. }
  7796. }
  7797. tsIsListTerminator(kind) {
  7798. switch (kind) {
  7799. case "EnumMembers":
  7800. case "TypeMembers":
  7801. return this.match(8);
  7802. case "HeritageClauseElement":
  7803. return this.match(5);
  7804. case "TupleElementTypes":
  7805. return this.match(3);
  7806. case "TypeParametersOrArguments":
  7807. return this.match(48);
  7808. }
  7809. }
  7810. tsParseList(kind, parseElement) {
  7811. const result = [];
  7812. while (!this.tsIsListTerminator(kind)) {
  7813. result.push(parseElement());
  7814. }
  7815. return result;
  7816. }
  7817. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7818. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7819. }
  7820. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7821. const result = [];
  7822. let trailingCommaPos = -1;
  7823. for (;;) {
  7824. if (this.tsIsListTerminator(kind)) {
  7825. break;
  7826. }
  7827. trailingCommaPos = -1;
  7828. const element = parseElement();
  7829. if (element == null) {
  7830. return undefined;
  7831. }
  7832. result.push(element);
  7833. if (this.eat(12)) {
  7834. trailingCommaPos = this.state.lastTokStart;
  7835. continue;
  7836. }
  7837. if (this.tsIsListTerminator(kind)) {
  7838. break;
  7839. }
  7840. if (expectSuccess) {
  7841. this.expect(12);
  7842. }
  7843. return undefined;
  7844. }
  7845. if (refTrailingCommaPos) {
  7846. refTrailingCommaPos.value = trailingCommaPos;
  7847. }
  7848. return result;
  7849. }
  7850. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7851. if (!skipFirstToken) {
  7852. if (bracket) {
  7853. this.expect(0);
  7854. } else {
  7855. this.expect(47);
  7856. }
  7857. }
  7858. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7859. if (bracket) {
  7860. this.expect(3);
  7861. } else {
  7862. this.expect(48);
  7863. }
  7864. return result;
  7865. }
  7866. tsParseImportType() {
  7867. const node = this.startNode();
  7868. this.expect(83);
  7869. this.expect(10);
  7870. if (!this.match(131)) {
  7871. this.raise(TSErrors.UnsupportedImportTypeArgument, {
  7872. at: this.state.startLoc
  7873. });
  7874. }
  7875. node.argument = super.parseExprAtom();
  7876. this.expect(11);
  7877. if (this.eat(16)) {
  7878. node.qualifier = this.tsParseEntityName();
  7879. }
  7880. if (this.match(47)) {
  7881. node.typeParameters = this.tsParseTypeArguments();
  7882. }
  7883. return this.finishNode(node, "TSImportType");
  7884. }
  7885. tsParseEntityName(allowReservedWords = true) {
  7886. let entity = this.parseIdentifier(allowReservedWords);
  7887. while (this.eat(16)) {
  7888. const node = this.startNodeAtNode(entity);
  7889. node.left = entity;
  7890. node.right = this.parseIdentifier(allowReservedWords);
  7891. entity = this.finishNode(node, "TSQualifiedName");
  7892. }
  7893. return entity;
  7894. }
  7895. tsParseTypeReference() {
  7896. const node = this.startNode();
  7897. node.typeName = this.tsParseEntityName();
  7898. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7899. node.typeParameters = this.tsParseTypeArguments();
  7900. }
  7901. return this.finishNode(node, "TSTypeReference");
  7902. }
  7903. tsParseThisTypePredicate(lhs) {
  7904. this.next();
  7905. const node = this.startNodeAtNode(lhs);
  7906. node.parameterName = lhs;
  7907. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7908. node.asserts = false;
  7909. return this.finishNode(node, "TSTypePredicate");
  7910. }
  7911. tsParseThisTypeNode() {
  7912. const node = this.startNode();
  7913. this.next();
  7914. return this.finishNode(node, "TSThisType");
  7915. }
  7916. tsParseTypeQuery() {
  7917. const node = this.startNode();
  7918. this.expect(87);
  7919. if (this.match(83)) {
  7920. node.exprName = this.tsParseImportType();
  7921. } else {
  7922. node.exprName = this.tsParseEntityName();
  7923. }
  7924. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7925. node.typeParameters = this.tsParseTypeArguments();
  7926. }
  7927. return this.finishNode(node, "TSTypeQuery");
  7928. }
  7929. tsParseTypeParameter(parseModifiers) {
  7930. const node = this.startNode();
  7931. parseModifiers(node);
  7932. node.name = this.tsParseTypeParameterName();
  7933. node.constraint = this.tsEatThenParseType(81);
  7934. node.default = this.tsEatThenParseType(29);
  7935. return this.finishNode(node, "TSTypeParameter");
  7936. }
  7937. tsTryParseTypeParameters(parseModifiers) {
  7938. if (this.match(47)) {
  7939. return this.tsParseTypeParameters(parseModifiers);
  7940. }
  7941. }
  7942. tsParseTypeParameters(parseModifiers) {
  7943. const node = this.startNode();
  7944. if (this.match(47) || this.match(140)) {
  7945. this.next();
  7946. } else {
  7947. this.unexpected();
  7948. }
  7949. const refTrailingCommaPos = {
  7950. value: -1
  7951. };
  7952. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7953. if (node.params.length === 0) {
  7954. this.raise(TSErrors.EmptyTypeParameters, {
  7955. at: node
  7956. });
  7957. }
  7958. if (refTrailingCommaPos.value !== -1) {
  7959. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7960. }
  7961. return this.finishNode(node, "TSTypeParameterDeclaration");
  7962. }
  7963. tsFillSignature(returnToken, signature) {
  7964. const returnTokenRequired = returnToken === 19;
  7965. const paramsKey = "parameters";
  7966. const returnTypeKey = "typeAnnotation";
  7967. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  7968. this.expect(10);
  7969. signature[paramsKey] = this.tsParseBindingListForSignature();
  7970. if (returnTokenRequired) {
  7971. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7972. } else if (this.match(returnToken)) {
  7973. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7974. }
  7975. }
  7976. tsParseBindingListForSignature() {
  7977. const list = super.parseBindingList(11, 41, 2);
  7978. for (const pattern of list) {
  7979. const {
  7980. type
  7981. } = pattern;
  7982. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  7983. this.raise(TSErrors.UnsupportedSignatureParameterKind, {
  7984. at: pattern,
  7985. type
  7986. });
  7987. }
  7988. }
  7989. return list;
  7990. }
  7991. tsParseTypeMemberSemicolon() {
  7992. if (!this.eat(12) && !this.isLineTerminator()) {
  7993. this.expect(13);
  7994. }
  7995. }
  7996. tsParseSignatureMember(kind, node) {
  7997. this.tsFillSignature(14, node);
  7998. this.tsParseTypeMemberSemicolon();
  7999. return this.finishNode(node, kind);
  8000. }
  8001. tsIsUnambiguouslyIndexSignature() {
  8002. this.next();
  8003. if (tokenIsIdentifier(this.state.type)) {
  8004. this.next();
  8005. return this.match(14);
  8006. }
  8007. return false;
  8008. }
  8009. tsTryParseIndexSignature(node) {
  8010. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8011. return;
  8012. }
  8013. this.expect(0);
  8014. const id = this.parseIdentifier();
  8015. id.typeAnnotation = this.tsParseTypeAnnotation();
  8016. this.resetEndLocation(id);
  8017. this.expect(3);
  8018. node.parameters = [id];
  8019. const type = this.tsTryParseTypeAnnotation();
  8020. if (type) node.typeAnnotation = type;
  8021. this.tsParseTypeMemberSemicolon();
  8022. return this.finishNode(node, "TSIndexSignature");
  8023. }
  8024. tsParsePropertyOrMethodSignature(node, readonly) {
  8025. if (this.eat(17)) node.optional = true;
  8026. const nodeAny = node;
  8027. if (this.match(10) || this.match(47)) {
  8028. if (readonly) {
  8029. this.raise(TSErrors.ReadonlyForMethodSignature, {
  8030. at: node
  8031. });
  8032. }
  8033. const method = nodeAny;
  8034. if (method.kind && this.match(47)) {
  8035. this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
  8036. at: this.state.curPosition()
  8037. });
  8038. }
  8039. this.tsFillSignature(14, method);
  8040. this.tsParseTypeMemberSemicolon();
  8041. const paramsKey = "parameters";
  8042. const returnTypeKey = "typeAnnotation";
  8043. if (method.kind === "get") {
  8044. if (method[paramsKey].length > 0) {
  8045. this.raise(Errors.BadGetterArity, {
  8046. at: this.state.curPosition()
  8047. });
  8048. if (this.isThisParam(method[paramsKey][0])) {
  8049. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8050. at: this.state.curPosition()
  8051. });
  8052. }
  8053. }
  8054. } else if (method.kind === "set") {
  8055. if (method[paramsKey].length !== 1) {
  8056. this.raise(Errors.BadSetterArity, {
  8057. at: this.state.curPosition()
  8058. });
  8059. } else {
  8060. const firstParameter = method[paramsKey][0];
  8061. if (this.isThisParam(firstParameter)) {
  8062. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8063. at: this.state.curPosition()
  8064. });
  8065. }
  8066. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8067. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
  8068. at: this.state.curPosition()
  8069. });
  8070. }
  8071. if (firstParameter.type === "RestElement") {
  8072. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
  8073. at: this.state.curPosition()
  8074. });
  8075. }
  8076. }
  8077. if (method[returnTypeKey]) {
  8078. this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
  8079. at: method[returnTypeKey]
  8080. });
  8081. }
  8082. } else {
  8083. method.kind = "method";
  8084. }
  8085. return this.finishNode(method, "TSMethodSignature");
  8086. } else {
  8087. const property = nodeAny;
  8088. if (readonly) property.readonly = true;
  8089. const type = this.tsTryParseTypeAnnotation();
  8090. if (type) property.typeAnnotation = type;
  8091. this.tsParseTypeMemberSemicolon();
  8092. return this.finishNode(property, "TSPropertySignature");
  8093. }
  8094. }
  8095. tsParseTypeMember() {
  8096. const node = this.startNode();
  8097. if (this.match(10) || this.match(47)) {
  8098. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8099. }
  8100. if (this.match(77)) {
  8101. const id = this.startNode();
  8102. this.next();
  8103. if (this.match(10) || this.match(47)) {
  8104. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8105. } else {
  8106. node.key = this.createIdentifier(id, "new");
  8107. return this.tsParsePropertyOrMethodSignature(node, false);
  8108. }
  8109. }
  8110. this.tsParseModifiers({
  8111. allowedModifiers: ["readonly"],
  8112. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8113. }, node);
  8114. const idx = this.tsTryParseIndexSignature(node);
  8115. if (idx) {
  8116. return idx;
  8117. }
  8118. super.parsePropertyName(node);
  8119. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8120. node.kind = node.key.name;
  8121. super.parsePropertyName(node);
  8122. }
  8123. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8124. }
  8125. tsParseTypeLiteral() {
  8126. const node = this.startNode();
  8127. node.members = this.tsParseObjectTypeMembers();
  8128. return this.finishNode(node, "TSTypeLiteral");
  8129. }
  8130. tsParseObjectTypeMembers() {
  8131. this.expect(5);
  8132. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8133. this.expect(8);
  8134. return members;
  8135. }
  8136. tsIsStartOfMappedType() {
  8137. this.next();
  8138. if (this.eat(53)) {
  8139. return this.isContextual(120);
  8140. }
  8141. if (this.isContextual(120)) {
  8142. this.next();
  8143. }
  8144. if (!this.match(0)) {
  8145. return false;
  8146. }
  8147. this.next();
  8148. if (!this.tsIsIdentifier()) {
  8149. return false;
  8150. }
  8151. this.next();
  8152. return this.match(58);
  8153. }
  8154. tsParseMappedTypeParameter() {
  8155. const node = this.startNode();
  8156. node.name = this.tsParseTypeParameterName();
  8157. node.constraint = this.tsExpectThenParseType(58);
  8158. return this.finishNode(node, "TSTypeParameter");
  8159. }
  8160. tsParseMappedType() {
  8161. const node = this.startNode();
  8162. this.expect(5);
  8163. if (this.match(53)) {
  8164. node.readonly = this.state.value;
  8165. this.next();
  8166. this.expectContextual(120);
  8167. } else if (this.eatContextual(120)) {
  8168. node.readonly = true;
  8169. }
  8170. this.expect(0);
  8171. node.typeParameter = this.tsParseMappedTypeParameter();
  8172. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8173. this.expect(3);
  8174. if (this.match(53)) {
  8175. node.optional = this.state.value;
  8176. this.next();
  8177. this.expect(17);
  8178. } else if (this.eat(17)) {
  8179. node.optional = true;
  8180. }
  8181. node.typeAnnotation = this.tsTryParseType();
  8182. this.semicolon();
  8183. this.expect(8);
  8184. return this.finishNode(node, "TSMappedType");
  8185. }
  8186. tsParseTupleType() {
  8187. const node = this.startNode();
  8188. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8189. let seenOptionalElement = false;
  8190. let labeledElements = null;
  8191. node.elementTypes.forEach(elementNode => {
  8192. var _labeledElements;
  8193. const {
  8194. type
  8195. } = elementNode;
  8196. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8197. this.raise(TSErrors.OptionalTypeBeforeRequired, {
  8198. at: elementNode
  8199. });
  8200. }
  8201. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8202. let checkType = type;
  8203. if (type === "TSRestType") {
  8204. elementNode = elementNode.typeAnnotation;
  8205. checkType = elementNode.type;
  8206. }
  8207. const isLabeled = checkType === "TSNamedTupleMember";
  8208. (_labeledElements = labeledElements) != null ? _labeledElements : labeledElements = isLabeled;
  8209. if (labeledElements !== isLabeled) {
  8210. this.raise(TSErrors.MixedLabeledAndUnlabeledElements, {
  8211. at: elementNode
  8212. });
  8213. }
  8214. });
  8215. return this.finishNode(node, "TSTupleType");
  8216. }
  8217. tsParseTupleElementType() {
  8218. const {
  8219. startLoc
  8220. } = this.state;
  8221. const rest = this.eat(21);
  8222. let labeled;
  8223. let label;
  8224. let optional;
  8225. let type;
  8226. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8227. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8228. if (chAfterWord === 58) {
  8229. labeled = true;
  8230. optional = false;
  8231. label = this.parseIdentifier(true);
  8232. this.expect(14);
  8233. type = this.tsParseType();
  8234. } else if (chAfterWord === 63) {
  8235. optional = true;
  8236. const startLoc = this.state.startLoc;
  8237. const wordName = this.state.value;
  8238. const typeOrLabel = this.tsParseNonArrayType();
  8239. if (this.lookaheadCharCode() === 58) {
  8240. labeled = true;
  8241. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8242. this.expect(17);
  8243. this.expect(14);
  8244. type = this.tsParseType();
  8245. } else {
  8246. labeled = false;
  8247. type = typeOrLabel;
  8248. this.expect(17);
  8249. }
  8250. } else {
  8251. type = this.tsParseType();
  8252. optional = this.eat(17);
  8253. labeled = this.eat(14);
  8254. }
  8255. if (labeled) {
  8256. let labeledNode;
  8257. if (label) {
  8258. labeledNode = this.startNodeAtNode(label);
  8259. labeledNode.optional = optional;
  8260. labeledNode.label = label;
  8261. labeledNode.elementType = type;
  8262. if (this.eat(17)) {
  8263. labeledNode.optional = true;
  8264. this.raise(TSErrors.TupleOptionalAfterType, {
  8265. at: this.state.lastTokStartLoc
  8266. });
  8267. }
  8268. } else {
  8269. labeledNode = this.startNodeAtNode(type);
  8270. labeledNode.optional = optional;
  8271. this.raise(TSErrors.InvalidTupleMemberLabel, {
  8272. at: type
  8273. });
  8274. labeledNode.label = type;
  8275. labeledNode.elementType = this.tsParseType();
  8276. }
  8277. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8278. } else if (optional) {
  8279. const optionalTypeNode = this.startNodeAtNode(type);
  8280. optionalTypeNode.typeAnnotation = type;
  8281. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8282. }
  8283. if (rest) {
  8284. const restNode = this.startNodeAt(startLoc);
  8285. restNode.typeAnnotation = type;
  8286. type = this.finishNode(restNode, "TSRestType");
  8287. }
  8288. return type;
  8289. }
  8290. tsParseParenthesizedType() {
  8291. const node = this.startNode();
  8292. this.expect(10);
  8293. node.typeAnnotation = this.tsParseType();
  8294. this.expect(11);
  8295. return this.finishNode(node, "TSParenthesizedType");
  8296. }
  8297. tsParseFunctionOrConstructorType(type, abstract) {
  8298. const node = this.startNode();
  8299. if (type === "TSConstructorType") {
  8300. node.abstract = !!abstract;
  8301. if (abstract) this.next();
  8302. this.next();
  8303. }
  8304. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8305. return this.finishNode(node, type);
  8306. }
  8307. tsParseLiteralTypeNode() {
  8308. const node = this.startNode();
  8309. switch (this.state.type) {
  8310. case 132:
  8311. case 133:
  8312. case 131:
  8313. case 85:
  8314. case 86:
  8315. node.literal = super.parseExprAtom();
  8316. break;
  8317. default:
  8318. this.unexpected();
  8319. }
  8320. return this.finishNode(node, "TSLiteralType");
  8321. }
  8322. tsParseTemplateLiteralType() {
  8323. const node = this.startNode();
  8324. node.literal = super.parseTemplate(false);
  8325. return this.finishNode(node, "TSLiteralType");
  8326. }
  8327. parseTemplateSubstitution() {
  8328. if (this.state.inType) return this.tsParseType();
  8329. return super.parseTemplateSubstitution();
  8330. }
  8331. tsParseThisTypeOrThisTypePredicate() {
  8332. const thisKeyword = this.tsParseThisTypeNode();
  8333. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  8334. return this.tsParseThisTypePredicate(thisKeyword);
  8335. } else {
  8336. return thisKeyword;
  8337. }
  8338. }
  8339. tsParseNonArrayType() {
  8340. switch (this.state.type) {
  8341. case 131:
  8342. case 132:
  8343. case 133:
  8344. case 85:
  8345. case 86:
  8346. return this.tsParseLiteralTypeNode();
  8347. case 53:
  8348. if (this.state.value === "-") {
  8349. const node = this.startNode();
  8350. const nextToken = this.lookahead();
  8351. if (nextToken.type !== 132 && nextToken.type !== 133) {
  8352. this.unexpected();
  8353. }
  8354. node.literal = this.parseMaybeUnary();
  8355. return this.finishNode(node, "TSLiteralType");
  8356. }
  8357. break;
  8358. case 78:
  8359. return this.tsParseThisTypeOrThisTypePredicate();
  8360. case 87:
  8361. return this.tsParseTypeQuery();
  8362. case 83:
  8363. return this.tsParseImportType();
  8364. case 5:
  8365. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8366. case 0:
  8367. return this.tsParseTupleType();
  8368. case 10:
  8369. return this.tsParseParenthesizedType();
  8370. case 25:
  8371. case 24:
  8372. return this.tsParseTemplateLiteralType();
  8373. default:
  8374. {
  8375. const {
  8376. type
  8377. } = this.state;
  8378. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8379. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8380. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8381. const node = this.startNode();
  8382. this.next();
  8383. return this.finishNode(node, nodeType);
  8384. }
  8385. return this.tsParseTypeReference();
  8386. }
  8387. }
  8388. }
  8389. this.unexpected();
  8390. }
  8391. tsParseArrayTypeOrHigher() {
  8392. let type = this.tsParseNonArrayType();
  8393. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8394. if (this.match(3)) {
  8395. const node = this.startNodeAtNode(type);
  8396. node.elementType = type;
  8397. this.expect(3);
  8398. type = this.finishNode(node, "TSArrayType");
  8399. } else {
  8400. const node = this.startNodeAtNode(type);
  8401. node.objectType = type;
  8402. node.indexType = this.tsParseType();
  8403. this.expect(3);
  8404. type = this.finishNode(node, "TSIndexedAccessType");
  8405. }
  8406. }
  8407. return type;
  8408. }
  8409. tsParseTypeOperator() {
  8410. const node = this.startNode();
  8411. const operator = this.state.value;
  8412. this.next();
  8413. node.operator = operator;
  8414. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8415. if (operator === "readonly") {
  8416. this.tsCheckTypeAnnotationForReadOnly(node);
  8417. }
  8418. return this.finishNode(node, "TSTypeOperator");
  8419. }
  8420. tsCheckTypeAnnotationForReadOnly(node) {
  8421. switch (node.typeAnnotation.type) {
  8422. case "TSTupleType":
  8423. case "TSArrayType":
  8424. return;
  8425. default:
  8426. this.raise(TSErrors.UnexpectedReadonly, {
  8427. at: node
  8428. });
  8429. }
  8430. }
  8431. tsParseInferType() {
  8432. const node = this.startNode();
  8433. this.expectContextual(113);
  8434. const typeParameter = this.startNode();
  8435. typeParameter.name = this.tsParseTypeParameterName();
  8436. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8437. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8438. return this.finishNode(node, "TSInferType");
  8439. }
  8440. tsParseConstraintForInferType() {
  8441. if (this.eat(81)) {
  8442. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8443. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8444. return constraint;
  8445. }
  8446. }
  8447. }
  8448. tsParseTypeOperatorOrHigher() {
  8449. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8450. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(113) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8451. }
  8452. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8453. const node = this.startNode();
  8454. const hasLeadingOperator = this.eat(operator);
  8455. const types = [];
  8456. do {
  8457. types.push(parseConstituentType());
  8458. } while (this.eat(operator));
  8459. if (types.length === 1 && !hasLeadingOperator) {
  8460. return types[0];
  8461. }
  8462. node.types = types;
  8463. return this.finishNode(node, kind);
  8464. }
  8465. tsParseIntersectionTypeOrHigher() {
  8466. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8467. }
  8468. tsParseUnionTypeOrHigher() {
  8469. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8470. }
  8471. tsIsStartOfFunctionType() {
  8472. if (this.match(47)) {
  8473. return true;
  8474. }
  8475. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8476. }
  8477. tsSkipParameterStart() {
  8478. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8479. this.next();
  8480. return true;
  8481. }
  8482. if (this.match(5)) {
  8483. const {
  8484. errors
  8485. } = this.state;
  8486. const previousErrorCount = errors.length;
  8487. try {
  8488. this.parseObjectLike(8, true);
  8489. return errors.length === previousErrorCount;
  8490. } catch (_unused) {
  8491. return false;
  8492. }
  8493. }
  8494. if (this.match(0)) {
  8495. this.next();
  8496. const {
  8497. errors
  8498. } = this.state;
  8499. const previousErrorCount = errors.length;
  8500. try {
  8501. super.parseBindingList(3, 93, 1);
  8502. return errors.length === previousErrorCount;
  8503. } catch (_unused2) {
  8504. return false;
  8505. }
  8506. }
  8507. return false;
  8508. }
  8509. tsIsUnambiguouslyStartOfFunctionType() {
  8510. this.next();
  8511. if (this.match(11) || this.match(21)) {
  8512. return true;
  8513. }
  8514. if (this.tsSkipParameterStart()) {
  8515. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8516. return true;
  8517. }
  8518. if (this.match(11)) {
  8519. this.next();
  8520. if (this.match(19)) {
  8521. return true;
  8522. }
  8523. }
  8524. }
  8525. return false;
  8526. }
  8527. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8528. return this.tsInType(() => {
  8529. const t = this.startNode();
  8530. this.expect(returnToken);
  8531. const node = this.startNode();
  8532. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8533. if (asserts && this.match(78)) {
  8534. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8535. if (thisTypePredicate.type === "TSThisType") {
  8536. node.parameterName = thisTypePredicate;
  8537. node.asserts = true;
  8538. node.typeAnnotation = null;
  8539. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8540. } else {
  8541. this.resetStartLocationFromNode(thisTypePredicate, node);
  8542. thisTypePredicate.asserts = true;
  8543. }
  8544. t.typeAnnotation = thisTypePredicate;
  8545. return this.finishNode(t, "TSTypeAnnotation");
  8546. }
  8547. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8548. if (!typePredicateVariable) {
  8549. if (!asserts) {
  8550. return this.tsParseTypeAnnotation(false, t);
  8551. }
  8552. node.parameterName = this.parseIdentifier();
  8553. node.asserts = asserts;
  8554. node.typeAnnotation = null;
  8555. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8556. return this.finishNode(t, "TSTypeAnnotation");
  8557. }
  8558. const type = this.tsParseTypeAnnotation(false);
  8559. node.parameterName = typePredicateVariable;
  8560. node.typeAnnotation = type;
  8561. node.asserts = asserts;
  8562. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8563. return this.finishNode(t, "TSTypeAnnotation");
  8564. });
  8565. }
  8566. tsTryParseTypeOrTypePredicateAnnotation() {
  8567. if (this.match(14)) {
  8568. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8569. }
  8570. }
  8571. tsTryParseTypeAnnotation() {
  8572. if (this.match(14)) {
  8573. return this.tsParseTypeAnnotation();
  8574. }
  8575. }
  8576. tsTryParseType() {
  8577. return this.tsEatThenParseType(14);
  8578. }
  8579. tsParseTypePredicatePrefix() {
  8580. const id = this.parseIdentifier();
  8581. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  8582. this.next();
  8583. return id;
  8584. }
  8585. }
  8586. tsParseTypePredicateAsserts() {
  8587. if (this.state.type !== 107) {
  8588. return false;
  8589. }
  8590. const containsEsc = this.state.containsEsc;
  8591. this.next();
  8592. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8593. return false;
  8594. }
  8595. if (containsEsc) {
  8596. this.raise(Errors.InvalidEscapedReservedWord, {
  8597. at: this.state.lastTokStartLoc,
  8598. reservedWord: "asserts"
  8599. });
  8600. }
  8601. return true;
  8602. }
  8603. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8604. this.tsInType(() => {
  8605. if (eatColon) this.expect(14);
  8606. t.typeAnnotation = this.tsParseType();
  8607. });
  8608. return this.finishNode(t, "TSTypeAnnotation");
  8609. }
  8610. tsParseType() {
  8611. assert(this.state.inType);
  8612. const type = this.tsParseNonConditionalType();
  8613. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8614. return type;
  8615. }
  8616. const node = this.startNodeAtNode(type);
  8617. node.checkType = type;
  8618. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8619. this.expect(17);
  8620. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8621. this.expect(14);
  8622. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8623. return this.finishNode(node, "TSConditionalType");
  8624. }
  8625. isAbstractConstructorSignature() {
  8626. return this.isContextual(122) && this.lookahead().type === 77;
  8627. }
  8628. tsParseNonConditionalType() {
  8629. if (this.tsIsStartOfFunctionType()) {
  8630. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8631. }
  8632. if (this.match(77)) {
  8633. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8634. } else if (this.isAbstractConstructorSignature()) {
  8635. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8636. }
  8637. return this.tsParseUnionTypeOrHigher();
  8638. }
  8639. tsParseTypeAssertion() {
  8640. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8641. this.raise(TSErrors.ReservedTypeAssertion, {
  8642. at: this.state.startLoc
  8643. });
  8644. }
  8645. const node = this.startNode();
  8646. node.typeAnnotation = this.tsInType(() => {
  8647. this.next();
  8648. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8649. });
  8650. this.expect(48);
  8651. node.expression = this.parseMaybeUnary();
  8652. return this.finishNode(node, "TSTypeAssertion");
  8653. }
  8654. tsParseHeritageClause(token) {
  8655. const originalStartLoc = this.state.startLoc;
  8656. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8657. const node = this.startNode();
  8658. node.expression = this.tsParseEntityName();
  8659. if (this.match(47)) {
  8660. node.typeParameters = this.tsParseTypeArguments();
  8661. }
  8662. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8663. });
  8664. if (!delimitedList.length) {
  8665. this.raise(TSErrors.EmptyHeritageClauseType, {
  8666. at: originalStartLoc,
  8667. token
  8668. });
  8669. }
  8670. return delimitedList;
  8671. }
  8672. tsParseInterfaceDeclaration(node, properties = {}) {
  8673. if (this.hasFollowingLineBreak()) return null;
  8674. this.expectContextual(127);
  8675. if (properties.declare) node.declare = true;
  8676. if (tokenIsIdentifier(this.state.type)) {
  8677. node.id = this.parseIdentifier();
  8678. this.checkIdentifier(node.id, BIND_TS_INTERFACE);
  8679. } else {
  8680. node.id = null;
  8681. this.raise(TSErrors.MissingInterfaceName, {
  8682. at: this.state.startLoc
  8683. });
  8684. }
  8685. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8686. if (this.eat(81)) {
  8687. node.extends = this.tsParseHeritageClause("extends");
  8688. }
  8689. const body = this.startNode();
  8690. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8691. node.body = this.finishNode(body, "TSInterfaceBody");
  8692. return this.finishNode(node, "TSInterfaceDeclaration");
  8693. }
  8694. tsParseTypeAliasDeclaration(node) {
  8695. node.id = this.parseIdentifier();
  8696. this.checkIdentifier(node.id, BIND_TS_TYPE);
  8697. node.typeAnnotation = this.tsInType(() => {
  8698. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8699. this.expect(29);
  8700. if (this.isContextual(112) && this.lookahead().type !== 16) {
  8701. const node = this.startNode();
  8702. this.next();
  8703. return this.finishNode(node, "TSIntrinsicKeyword");
  8704. }
  8705. return this.tsParseType();
  8706. });
  8707. this.semicolon();
  8708. return this.finishNode(node, "TSTypeAliasDeclaration");
  8709. }
  8710. tsInNoContext(cb) {
  8711. const oldContext = this.state.context;
  8712. this.state.context = [oldContext[0]];
  8713. try {
  8714. return cb();
  8715. } finally {
  8716. this.state.context = oldContext;
  8717. }
  8718. }
  8719. tsInType(cb) {
  8720. const oldInType = this.state.inType;
  8721. this.state.inType = true;
  8722. try {
  8723. return cb();
  8724. } finally {
  8725. this.state.inType = oldInType;
  8726. }
  8727. }
  8728. tsInDisallowConditionalTypesContext(cb) {
  8729. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8730. this.state.inDisallowConditionalTypesContext = true;
  8731. try {
  8732. return cb();
  8733. } finally {
  8734. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8735. }
  8736. }
  8737. tsInAllowConditionalTypesContext(cb) {
  8738. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8739. this.state.inDisallowConditionalTypesContext = false;
  8740. try {
  8741. return cb();
  8742. } finally {
  8743. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8744. }
  8745. }
  8746. tsEatThenParseType(token) {
  8747. if (this.match(token)) {
  8748. return this.tsNextThenParseType();
  8749. }
  8750. }
  8751. tsExpectThenParseType(token) {
  8752. return this.tsInType(() => {
  8753. this.expect(token);
  8754. return this.tsParseType();
  8755. });
  8756. }
  8757. tsNextThenParseType() {
  8758. return this.tsInType(() => {
  8759. this.next();
  8760. return this.tsParseType();
  8761. });
  8762. }
  8763. tsParseEnumMember() {
  8764. const node = this.startNode();
  8765. node.id = this.match(131) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8766. if (this.eat(29)) {
  8767. node.initializer = super.parseMaybeAssignAllowIn();
  8768. }
  8769. return this.finishNode(node, "TSEnumMember");
  8770. }
  8771. tsParseEnumDeclaration(node, properties = {}) {
  8772. if (properties.const) node.const = true;
  8773. if (properties.declare) node.declare = true;
  8774. this.expectContextual(124);
  8775. node.id = this.parseIdentifier();
  8776. this.checkIdentifier(node.id, node.const ? BIND_TS_CONST_ENUM : BIND_TS_ENUM);
  8777. this.expect(5);
  8778. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8779. this.expect(8);
  8780. return this.finishNode(node, "TSEnumDeclaration");
  8781. }
  8782. tsParseModuleBlock() {
  8783. const node = this.startNode();
  8784. this.scope.enter(SCOPE_OTHER);
  8785. this.expect(5);
  8786. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8787. this.scope.exit();
  8788. return this.finishNode(node, "TSModuleBlock");
  8789. }
  8790. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8791. node.id = this.parseIdentifier();
  8792. if (!nested) {
  8793. this.checkIdentifier(node.id, BIND_TS_NAMESPACE);
  8794. }
  8795. if (this.eat(16)) {
  8796. const inner = this.startNode();
  8797. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8798. node.body = inner;
  8799. } else {
  8800. this.scope.enter(SCOPE_TS_MODULE);
  8801. this.prodParam.enter(PARAM);
  8802. node.body = this.tsParseModuleBlock();
  8803. this.prodParam.exit();
  8804. this.scope.exit();
  8805. }
  8806. return this.finishNode(node, "TSModuleDeclaration");
  8807. }
  8808. tsParseAmbientExternalModuleDeclaration(node) {
  8809. if (this.isContextual(110)) {
  8810. node.global = true;
  8811. node.id = this.parseIdentifier();
  8812. } else if (this.match(131)) {
  8813. node.id = super.parseStringLiteral(this.state.value);
  8814. } else {
  8815. this.unexpected();
  8816. }
  8817. if (this.match(5)) {
  8818. this.scope.enter(SCOPE_TS_MODULE);
  8819. this.prodParam.enter(PARAM);
  8820. node.body = this.tsParseModuleBlock();
  8821. this.prodParam.exit();
  8822. this.scope.exit();
  8823. } else {
  8824. this.semicolon();
  8825. }
  8826. return this.finishNode(node, "TSModuleDeclaration");
  8827. }
  8828. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8829. node.isExport = isExport || false;
  8830. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8831. this.checkIdentifier(node.id, BIND_FLAGS_TS_IMPORT);
  8832. this.expect(29);
  8833. const moduleReference = this.tsParseModuleReference();
  8834. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8835. this.raise(TSErrors.ImportAliasHasImportType, {
  8836. at: moduleReference
  8837. });
  8838. }
  8839. node.moduleReference = moduleReference;
  8840. this.semicolon();
  8841. return this.finishNode(node, "TSImportEqualsDeclaration");
  8842. }
  8843. tsIsExternalModuleReference() {
  8844. return this.isContextual(117) && this.lookaheadCharCode() === 40;
  8845. }
  8846. tsParseModuleReference() {
  8847. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  8848. }
  8849. tsParseExternalModuleReference() {
  8850. const node = this.startNode();
  8851. this.expectContextual(117);
  8852. this.expect(10);
  8853. if (!this.match(131)) {
  8854. this.unexpected();
  8855. }
  8856. node.expression = super.parseExprAtom();
  8857. this.expect(11);
  8858. this.sawUnambiguousESM = true;
  8859. return this.finishNode(node, "TSExternalModuleReference");
  8860. }
  8861. tsLookAhead(f) {
  8862. const state = this.state.clone();
  8863. const res = f();
  8864. this.state = state;
  8865. return res;
  8866. }
  8867. tsTryParseAndCatch(f) {
  8868. const result = this.tryParse(abort => f() || abort());
  8869. if (result.aborted || !result.node) return;
  8870. if (result.error) this.state = result.failState;
  8871. return result.node;
  8872. }
  8873. tsTryParse(f) {
  8874. const state = this.state.clone();
  8875. const result = f();
  8876. if (result !== undefined && result !== false) {
  8877. return result;
  8878. }
  8879. this.state = state;
  8880. }
  8881. tsTryParseDeclare(nany) {
  8882. if (this.isLineTerminator()) {
  8883. return;
  8884. }
  8885. let startType = this.state.type;
  8886. let kind;
  8887. if (this.isContextual(99)) {
  8888. startType = 74;
  8889. kind = "let";
  8890. }
  8891. return this.tsInAmbientContext(() => {
  8892. switch (startType) {
  8893. case 68:
  8894. nany.declare = true;
  8895. return super.parseFunctionStatement(nany, false, false);
  8896. case 80:
  8897. nany.declare = true;
  8898. return this.parseClass(nany, true, false);
  8899. case 124:
  8900. return this.tsParseEnumDeclaration(nany, {
  8901. declare: true
  8902. });
  8903. case 110:
  8904. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8905. case 75:
  8906. case 74:
  8907. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8908. nany.declare = true;
  8909. return this.parseVarStatement(nany, kind || this.state.value, true);
  8910. }
  8911. this.expect(75);
  8912. return this.tsParseEnumDeclaration(nany, {
  8913. const: true,
  8914. declare: true
  8915. });
  8916. case 127:
  8917. {
  8918. const result = this.tsParseInterfaceDeclaration(nany, {
  8919. declare: true
  8920. });
  8921. if (result) return result;
  8922. }
  8923. default:
  8924. if (tokenIsIdentifier(startType)) {
  8925. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8926. }
  8927. }
  8928. });
  8929. }
  8930. tsTryParseExportDeclaration() {
  8931. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  8932. }
  8933. tsParseExpressionStatement(node, expr, decorators) {
  8934. switch (expr.name) {
  8935. case "declare":
  8936. {
  8937. const declaration = this.tsTryParseDeclare(node);
  8938. if (declaration) {
  8939. declaration.declare = true;
  8940. }
  8941. return declaration;
  8942. }
  8943. case "global":
  8944. if (this.match(5)) {
  8945. this.scope.enter(SCOPE_TS_MODULE);
  8946. this.prodParam.enter(PARAM);
  8947. const mod = node;
  8948. mod.global = true;
  8949. mod.id = expr;
  8950. mod.body = this.tsParseModuleBlock();
  8951. this.scope.exit();
  8952. this.prodParam.exit();
  8953. return this.finishNode(mod, "TSModuleDeclaration");
  8954. }
  8955. break;
  8956. default:
  8957. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8958. }
  8959. }
  8960. tsParseDeclaration(node, value, next, decorators) {
  8961. switch (value) {
  8962. case "abstract":
  8963. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8964. return this.tsParseAbstractDeclaration(node, decorators);
  8965. }
  8966. break;
  8967. case "module":
  8968. if (this.tsCheckLineTerminator(next)) {
  8969. if (this.match(131)) {
  8970. return this.tsParseAmbientExternalModuleDeclaration(node);
  8971. } else if (tokenIsIdentifier(this.state.type)) {
  8972. return this.tsParseModuleOrNamespaceDeclaration(node);
  8973. }
  8974. }
  8975. break;
  8976. case "namespace":
  8977. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8978. return this.tsParseModuleOrNamespaceDeclaration(node);
  8979. }
  8980. break;
  8981. case "type":
  8982. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8983. return this.tsParseTypeAliasDeclaration(node);
  8984. }
  8985. break;
  8986. }
  8987. }
  8988. tsCheckLineTerminator(next) {
  8989. if (next) {
  8990. if (this.hasFollowingLineBreak()) return false;
  8991. this.next();
  8992. return true;
  8993. }
  8994. return !this.isLineTerminator();
  8995. }
  8996. tsTryParseGenericAsyncArrowFunction(startLoc) {
  8997. if (!this.match(47)) return;
  8998. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8999. this.state.maybeInArrowParameters = true;
  9000. const res = this.tsTryParseAndCatch(() => {
  9001. const node = this.startNodeAt(startLoc);
  9002. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9003. super.parseFunctionParams(node);
  9004. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9005. this.expect(19);
  9006. return node;
  9007. });
  9008. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9009. if (!res) return;
  9010. return super.parseArrowExpression(res, null, true);
  9011. }
  9012. tsParseTypeArgumentsInExpression() {
  9013. if (this.reScan_lt() !== 47) return;
  9014. return this.tsParseTypeArguments();
  9015. }
  9016. tsParseTypeArguments() {
  9017. const node = this.startNode();
  9018. node.params = this.tsInType(() => this.tsInNoContext(() => {
  9019. this.expect(47);
  9020. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9021. }));
  9022. if (node.params.length === 0) {
  9023. this.raise(TSErrors.EmptyTypeArguments, {
  9024. at: node
  9025. });
  9026. } else if (!this.state.inType && this.curContext() === types.brace) {
  9027. this.reScan_lt_gt();
  9028. }
  9029. this.expect(48);
  9030. return this.finishNode(node, "TSTypeParameterInstantiation");
  9031. }
  9032. tsIsDeclarationStart() {
  9033. return tokenIsTSDeclarationStart(this.state.type);
  9034. }
  9035. isExportDefaultSpecifier() {
  9036. if (this.tsIsDeclarationStart()) return false;
  9037. return super.isExportDefaultSpecifier();
  9038. }
  9039. parseAssignableListItem(flags, decorators) {
  9040. const startLoc = this.state.startLoc;
  9041. const modified = {};
  9042. this.tsParseModifiers({
  9043. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9044. }, modified);
  9045. const accessibility = modified.accessibility;
  9046. const override = modified.override;
  9047. const readonly = modified.readonly;
  9048. if (!(flags & 4) && (accessibility || readonly || override)) {
  9049. this.raise(TSErrors.UnexpectedParameterModifier, {
  9050. at: startLoc
  9051. });
  9052. }
  9053. const left = this.parseMaybeDefault();
  9054. this.parseAssignableListItemTypes(left, flags);
  9055. const elt = this.parseMaybeDefault(left.loc.start, left);
  9056. if (accessibility || readonly || override) {
  9057. const pp = this.startNodeAt(startLoc);
  9058. if (decorators.length) {
  9059. pp.decorators = decorators;
  9060. }
  9061. if (accessibility) pp.accessibility = accessibility;
  9062. if (readonly) pp.readonly = readonly;
  9063. if (override) pp.override = override;
  9064. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9065. this.raise(TSErrors.UnsupportedParameterPropertyKind, {
  9066. at: pp
  9067. });
  9068. }
  9069. pp.parameter = elt;
  9070. return this.finishNode(pp, "TSParameterProperty");
  9071. }
  9072. if (decorators.length) {
  9073. left.decorators = decorators;
  9074. }
  9075. return elt;
  9076. }
  9077. isSimpleParameter(node) {
  9078. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9079. }
  9080. tsDisallowOptionalPattern(node) {
  9081. for (const param of node.params) {
  9082. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9083. this.raise(TSErrors.PatternIsOptional, {
  9084. at: param
  9085. });
  9086. }
  9087. }
  9088. }
  9089. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9090. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9091. this.tsDisallowOptionalPattern(node);
  9092. }
  9093. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9094. if (this.match(14)) {
  9095. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9096. }
  9097. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9098. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9099. return this.finishNode(node, bodilessType);
  9100. }
  9101. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9102. this.raise(TSErrors.DeclareFunctionHasImplementation, {
  9103. at: node
  9104. });
  9105. if (node.declare) {
  9106. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9107. }
  9108. }
  9109. this.tsDisallowOptionalPattern(node);
  9110. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9111. }
  9112. registerFunctionStatementId(node) {
  9113. if (!node.body && node.id) {
  9114. this.checkIdentifier(node.id, BIND_TS_AMBIENT);
  9115. } else {
  9116. super.registerFunctionStatementId(node);
  9117. }
  9118. }
  9119. tsCheckForInvalidTypeCasts(items) {
  9120. items.forEach(node => {
  9121. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9122. this.raise(TSErrors.UnexpectedTypeAnnotation, {
  9123. at: node.typeAnnotation
  9124. });
  9125. }
  9126. });
  9127. }
  9128. toReferencedList(exprList, isInParens) {
  9129. this.tsCheckForInvalidTypeCasts(exprList);
  9130. return exprList;
  9131. }
  9132. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9133. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9134. if (node.type === "ArrayExpression") {
  9135. this.tsCheckForInvalidTypeCasts(node.elements);
  9136. }
  9137. return node;
  9138. }
  9139. parseSubscript(base, startLoc, noCalls, state) {
  9140. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9141. this.state.canStartJSXElement = false;
  9142. this.next();
  9143. const nonNullExpression = this.startNodeAt(startLoc);
  9144. nonNullExpression.expression = base;
  9145. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9146. }
  9147. let isOptionalCall = false;
  9148. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9149. if (noCalls) {
  9150. state.stop = true;
  9151. return base;
  9152. }
  9153. state.optionalChainMember = isOptionalCall = true;
  9154. this.next();
  9155. }
  9156. if (this.match(47) || this.match(51)) {
  9157. let missingParenErrorLoc;
  9158. const result = this.tsTryParseAndCatch(() => {
  9159. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9160. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9161. if (asyncArrowFn) {
  9162. return asyncArrowFn;
  9163. }
  9164. }
  9165. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9166. if (!typeArguments) return;
  9167. if (isOptionalCall && !this.match(10)) {
  9168. missingParenErrorLoc = this.state.curPosition();
  9169. return;
  9170. }
  9171. if (tokenIsTemplate(this.state.type)) {
  9172. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9173. result.typeParameters = typeArguments;
  9174. return result;
  9175. }
  9176. if (!noCalls && this.eat(10)) {
  9177. const node = this.startNodeAt(startLoc);
  9178. node.callee = base;
  9179. node.arguments = this.parseCallExpressionArguments(11, false);
  9180. this.tsCheckForInvalidTypeCasts(node.arguments);
  9181. node.typeParameters = typeArguments;
  9182. if (state.optionalChainMember) {
  9183. node.optional = isOptionalCall;
  9184. }
  9185. return this.finishCallExpression(node, state.optionalChainMember);
  9186. }
  9187. const tokenType = this.state.type;
  9188. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9189. return;
  9190. }
  9191. const node = this.startNodeAt(startLoc);
  9192. node.expression = base;
  9193. node.typeParameters = typeArguments;
  9194. return this.finishNode(node, "TSInstantiationExpression");
  9195. });
  9196. if (missingParenErrorLoc) {
  9197. this.unexpected(missingParenErrorLoc, 10);
  9198. }
  9199. if (result) {
  9200. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  9201. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
  9202. at: this.state.startLoc
  9203. });
  9204. }
  9205. return result;
  9206. }
  9207. }
  9208. return super.parseSubscript(base, startLoc, noCalls, state);
  9209. }
  9210. parseNewCallee(node) {
  9211. var _callee$extra;
  9212. super.parseNewCallee(node);
  9213. const {
  9214. callee
  9215. } = node;
  9216. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9217. node.typeParameters = callee.typeParameters;
  9218. node.callee = callee.expression;
  9219. }
  9220. }
  9221. parseExprOp(left, leftStartLoc, minPrec) {
  9222. let isSatisfies;
  9223. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(118)))) {
  9224. const node = this.startNodeAt(leftStartLoc);
  9225. node.expression = left;
  9226. node.typeAnnotation = this.tsInType(() => {
  9227. this.next();
  9228. if (this.match(75)) {
  9229. if (isSatisfies) {
  9230. this.raise(Errors.UnexpectedKeyword, {
  9231. at: this.state.startLoc,
  9232. keyword: "const"
  9233. });
  9234. }
  9235. return this.tsParseTypeReference();
  9236. }
  9237. return this.tsParseType();
  9238. });
  9239. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9240. this.reScan_lt_gt();
  9241. return this.parseExprOp(node, leftStartLoc, minPrec);
  9242. }
  9243. return super.parseExprOp(left, leftStartLoc, minPrec);
  9244. }
  9245. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9246. if (!this.state.isAmbientContext) {
  9247. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9248. }
  9249. }
  9250. checkImportReflection(node) {
  9251. super.checkImportReflection(node);
  9252. if (node.module && node.importKind !== "value") {
  9253. this.raise(TSErrors.ImportReflectionHasImportType, {
  9254. at: node.specifiers[0].loc.start
  9255. });
  9256. }
  9257. }
  9258. checkDuplicateExports() {}
  9259. isPotentialImportPhase(isExport) {
  9260. if (super.isPotentialImportPhase(isExport)) return true;
  9261. if (this.isContextual(128)) {
  9262. const ch = this.lookaheadCharCode();
  9263. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9264. }
  9265. return !isExport && this.isContextual(87);
  9266. }
  9267. applyImportPhase(node, isExport, phase, loc) {
  9268. super.applyImportPhase(node, isExport, phase, loc);
  9269. if (isExport) {
  9270. node.exportKind = phase === "type" ? "type" : "value";
  9271. } else {
  9272. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9273. }
  9274. }
  9275. parseImport(node) {
  9276. if (this.match(131)) {
  9277. node.importKind = "value";
  9278. return super.parseImport(node);
  9279. }
  9280. let importNode;
  9281. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9282. node.importKind = "value";
  9283. return this.tsParseImportEqualsDeclaration(node);
  9284. } else if (this.isContextual(128)) {
  9285. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9286. if (this.lookaheadCharCode() === 61) {
  9287. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9288. } else {
  9289. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9290. }
  9291. } else {
  9292. importNode = super.parseImport(node);
  9293. }
  9294. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9295. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
  9296. at: importNode
  9297. });
  9298. }
  9299. return importNode;
  9300. }
  9301. parseExport(node, decorators) {
  9302. if (this.match(83)) {
  9303. this.next();
  9304. let maybeDefaultIdentifier = null;
  9305. if (this.isContextual(128) && this.isPotentialImportPhase(false)) {
  9306. maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9307. } else {
  9308. node.importKind = "value";
  9309. }
  9310. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, true);
  9311. } else if (this.eat(29)) {
  9312. const assign = node;
  9313. assign.expression = super.parseExpression();
  9314. this.semicolon();
  9315. this.sawUnambiguousESM = true;
  9316. return this.finishNode(assign, "TSExportAssignment");
  9317. } else if (this.eatContextual(93)) {
  9318. const decl = node;
  9319. this.expectContextual(126);
  9320. decl.id = this.parseIdentifier();
  9321. this.semicolon();
  9322. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9323. } else {
  9324. return super.parseExport(node, decorators);
  9325. }
  9326. }
  9327. isAbstractClass() {
  9328. return this.isContextual(122) && this.lookahead().type === 80;
  9329. }
  9330. parseExportDefaultExpression() {
  9331. if (this.isAbstractClass()) {
  9332. const cls = this.startNode();
  9333. this.next();
  9334. cls.abstract = true;
  9335. return this.parseClass(cls, true, true);
  9336. }
  9337. if (this.match(127)) {
  9338. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9339. if (result) return result;
  9340. }
  9341. return super.parseExportDefaultExpression();
  9342. }
  9343. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9344. const {
  9345. isAmbientContext
  9346. } = this.state;
  9347. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9348. if (!isAmbientContext) return declaration;
  9349. for (const {
  9350. id,
  9351. init
  9352. } of declaration.declarations) {
  9353. if (!init) continue;
  9354. if (kind !== "const" || !!id.typeAnnotation) {
  9355. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
  9356. at: init
  9357. });
  9358. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9359. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
  9360. at: init
  9361. });
  9362. }
  9363. }
  9364. return declaration;
  9365. }
  9366. parseStatementContent(flags, decorators) {
  9367. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9368. const node = this.startNode();
  9369. this.expect(75);
  9370. return this.tsParseEnumDeclaration(node, {
  9371. const: true
  9372. });
  9373. }
  9374. if (this.isContextual(124)) {
  9375. return this.tsParseEnumDeclaration(this.startNode());
  9376. }
  9377. if (this.isContextual(127)) {
  9378. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9379. if (result) return result;
  9380. }
  9381. return super.parseStatementContent(flags, decorators);
  9382. }
  9383. parseAccessModifier() {
  9384. return this.tsParseModifier(["public", "protected", "private"]);
  9385. }
  9386. tsHasSomeModifiers(member, modifiers) {
  9387. return modifiers.some(modifier => {
  9388. if (tsIsAccessModifier(modifier)) {
  9389. return member.accessibility === modifier;
  9390. }
  9391. return !!member[modifier];
  9392. });
  9393. }
  9394. tsIsStartOfStaticBlocks() {
  9395. return this.isContextual(104) && this.lookaheadCharCode() === 123;
  9396. }
  9397. parseClassMember(classBody, member, state) {
  9398. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9399. this.tsParseModifiers({
  9400. allowedModifiers: modifiers,
  9401. disallowedModifiers: ["in", "out"],
  9402. stopOnStartOfClassStaticBlock: true,
  9403. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9404. }, member);
  9405. const callParseClassMemberWithIsStatic = () => {
  9406. if (this.tsIsStartOfStaticBlocks()) {
  9407. this.next();
  9408. this.next();
  9409. if (this.tsHasSomeModifiers(member, modifiers)) {
  9410. this.raise(TSErrors.StaticBlockCannotHaveModifier, {
  9411. at: this.state.curPosition()
  9412. });
  9413. }
  9414. super.parseClassStaticBlock(classBody, member);
  9415. } else {
  9416. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9417. }
  9418. };
  9419. if (member.declare) {
  9420. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9421. } else {
  9422. callParseClassMemberWithIsStatic();
  9423. }
  9424. }
  9425. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9426. const idx = this.tsTryParseIndexSignature(member);
  9427. if (idx) {
  9428. classBody.body.push(idx);
  9429. if (member.abstract) {
  9430. this.raise(TSErrors.IndexSignatureHasAbstract, {
  9431. at: member
  9432. });
  9433. }
  9434. if (member.accessibility) {
  9435. this.raise(TSErrors.IndexSignatureHasAccessibility, {
  9436. at: member,
  9437. modifier: member.accessibility
  9438. });
  9439. }
  9440. if (member.declare) {
  9441. this.raise(TSErrors.IndexSignatureHasDeclare, {
  9442. at: member
  9443. });
  9444. }
  9445. if (member.override) {
  9446. this.raise(TSErrors.IndexSignatureHasOverride, {
  9447. at: member
  9448. });
  9449. }
  9450. return;
  9451. }
  9452. if (!this.state.inAbstractClass && member.abstract) {
  9453. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
  9454. at: member
  9455. });
  9456. }
  9457. if (member.override) {
  9458. if (!state.hadSuperClass) {
  9459. this.raise(TSErrors.OverrideNotInSubClass, {
  9460. at: member
  9461. });
  9462. }
  9463. }
  9464. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9465. }
  9466. parsePostMemberNameModifiers(methodOrProp) {
  9467. const optional = this.eat(17);
  9468. if (optional) methodOrProp.optional = true;
  9469. if (methodOrProp.readonly && this.match(10)) {
  9470. this.raise(TSErrors.ClassMethodHasReadonly, {
  9471. at: methodOrProp
  9472. });
  9473. }
  9474. if (methodOrProp.declare && this.match(10)) {
  9475. this.raise(TSErrors.ClassMethodHasDeclare, {
  9476. at: methodOrProp
  9477. });
  9478. }
  9479. }
  9480. parseExpressionStatement(node, expr, decorators) {
  9481. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9482. return decl || super.parseExpressionStatement(node, expr, decorators);
  9483. }
  9484. shouldParseExportDeclaration() {
  9485. if (this.tsIsDeclarationStart()) return true;
  9486. return super.shouldParseExportDeclaration();
  9487. }
  9488. parseConditional(expr, startLoc, refExpressionErrors) {
  9489. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9490. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9491. }
  9492. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9493. if (!result.node) {
  9494. if (result.error) {
  9495. super.setOptionalParametersError(refExpressionErrors, result.error);
  9496. }
  9497. return expr;
  9498. }
  9499. if (result.error) this.state = result.failState;
  9500. return result.node;
  9501. }
  9502. parseParenItem(node, startLoc) {
  9503. node = super.parseParenItem(node, startLoc);
  9504. if (this.eat(17)) {
  9505. node.optional = true;
  9506. this.resetEndLocation(node);
  9507. }
  9508. if (this.match(14)) {
  9509. const typeCastNode = this.startNodeAt(startLoc);
  9510. typeCastNode.expression = node;
  9511. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9512. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9513. }
  9514. return node;
  9515. }
  9516. parseExportDeclaration(node) {
  9517. if (!this.state.isAmbientContext && this.isContextual(123)) {
  9518. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9519. }
  9520. const startLoc = this.state.startLoc;
  9521. const isDeclare = this.eatContextual(123);
  9522. if (isDeclare && (this.isContextual(123) || !this.shouldParseExportDeclaration())) {
  9523. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
  9524. at: this.state.startLoc
  9525. });
  9526. }
  9527. const isIdentifier = tokenIsIdentifier(this.state.type);
  9528. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9529. if (!declaration) return null;
  9530. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9531. node.exportKind = "type";
  9532. }
  9533. if (isDeclare) {
  9534. this.resetStartLocation(declaration, startLoc);
  9535. declaration.declare = true;
  9536. }
  9537. return declaration;
  9538. }
  9539. parseClassId(node, isStatement, optionalId, bindingType) {
  9540. if ((!isStatement || optionalId) && this.isContextual(111)) {
  9541. return;
  9542. }
  9543. super.parseClassId(node, isStatement, optionalId, node.declare ? BIND_TS_AMBIENT : BIND_CLASS);
  9544. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9545. if (typeParameters) node.typeParameters = typeParameters;
  9546. }
  9547. parseClassPropertyAnnotation(node) {
  9548. if (!node.optional) {
  9549. if (this.eat(35)) {
  9550. node.definite = true;
  9551. } else if (this.eat(17)) {
  9552. node.optional = true;
  9553. }
  9554. }
  9555. const type = this.tsTryParseTypeAnnotation();
  9556. if (type) node.typeAnnotation = type;
  9557. }
  9558. parseClassProperty(node) {
  9559. this.parseClassPropertyAnnotation(node);
  9560. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9561. this.raise(TSErrors.DeclareClassFieldHasInitializer, {
  9562. at: this.state.startLoc
  9563. });
  9564. }
  9565. if (node.abstract && this.match(29)) {
  9566. const {
  9567. key
  9568. } = node;
  9569. this.raise(TSErrors.AbstractPropertyHasInitializer, {
  9570. at: this.state.startLoc,
  9571. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9572. });
  9573. }
  9574. return super.parseClassProperty(node);
  9575. }
  9576. parseClassPrivateProperty(node) {
  9577. if (node.abstract) {
  9578. this.raise(TSErrors.PrivateElementHasAbstract, {
  9579. at: node
  9580. });
  9581. }
  9582. if (node.accessibility) {
  9583. this.raise(TSErrors.PrivateElementHasAccessibility, {
  9584. at: node,
  9585. modifier: node.accessibility
  9586. });
  9587. }
  9588. this.parseClassPropertyAnnotation(node);
  9589. return super.parseClassPrivateProperty(node);
  9590. }
  9591. parseClassAccessorProperty(node) {
  9592. this.parseClassPropertyAnnotation(node);
  9593. if (node.optional) {
  9594. this.raise(TSErrors.AccessorCannotBeOptional, {
  9595. at: node
  9596. });
  9597. }
  9598. return super.parseClassAccessorProperty(node);
  9599. }
  9600. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9601. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9602. if (typeParameters && isConstructor) {
  9603. this.raise(TSErrors.ConstructorHasTypeParameters, {
  9604. at: typeParameters
  9605. });
  9606. }
  9607. const {
  9608. declare = false,
  9609. kind
  9610. } = method;
  9611. if (declare && (kind === "get" || kind === "set")) {
  9612. this.raise(TSErrors.DeclareAccessor, {
  9613. at: method,
  9614. kind
  9615. });
  9616. }
  9617. if (typeParameters) method.typeParameters = typeParameters;
  9618. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9619. }
  9620. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9621. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9622. if (typeParameters) method.typeParameters = typeParameters;
  9623. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9624. }
  9625. declareClassPrivateMethodInScope(node, kind) {
  9626. if (node.type === "TSDeclareMethod") return;
  9627. if (node.type === "MethodDefinition" && !node.value.body) return;
  9628. super.declareClassPrivateMethodInScope(node, kind);
  9629. }
  9630. parseClassSuper(node) {
  9631. super.parseClassSuper(node);
  9632. if (node.superClass && (this.match(47) || this.match(51))) {
  9633. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9634. }
  9635. if (this.eatContextual(111)) {
  9636. node.implements = this.tsParseHeritageClause("implements");
  9637. }
  9638. }
  9639. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9640. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9641. if (typeParameters) prop.typeParameters = typeParameters;
  9642. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9643. }
  9644. parseFunctionParams(node, isConstructor) {
  9645. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9646. if (typeParameters) node.typeParameters = typeParameters;
  9647. super.parseFunctionParams(node, isConstructor);
  9648. }
  9649. parseVarId(decl, kind) {
  9650. super.parseVarId(decl, kind);
  9651. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9652. decl.definite = true;
  9653. }
  9654. const type = this.tsTryParseTypeAnnotation();
  9655. if (type) {
  9656. decl.id.typeAnnotation = type;
  9657. this.resetEndLocation(decl.id);
  9658. }
  9659. }
  9660. parseAsyncArrowFromCallExpression(node, call) {
  9661. if (this.match(14)) {
  9662. node.returnType = this.tsParseTypeAnnotation();
  9663. }
  9664. return super.parseAsyncArrowFromCallExpression(node, call);
  9665. }
  9666. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9667. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9668. let state;
  9669. let jsx;
  9670. let typeCast;
  9671. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  9672. state = this.state.clone();
  9673. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9674. if (!jsx.error) return jsx.node;
  9675. const {
  9676. context
  9677. } = this.state;
  9678. const currentContext = context[context.length - 1];
  9679. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9680. context.pop();
  9681. }
  9682. }
  9683. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9684. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9685. }
  9686. if (!state || state === this.state) state = this.state.clone();
  9687. let typeParameters;
  9688. const arrow = this.tryParse(abort => {
  9689. var _expr$extra, _typeParameters;
  9690. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9691. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9692. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9693. abort();
  9694. }
  9695. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9696. this.resetStartLocationFromNode(expr, typeParameters);
  9697. }
  9698. expr.typeParameters = typeParameters;
  9699. return expr;
  9700. }, state);
  9701. if (!arrow.error && !arrow.aborted) {
  9702. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9703. return arrow.node;
  9704. }
  9705. if (!jsx) {
  9706. assert(!this.hasPlugin("jsx"));
  9707. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9708. if (!typeCast.error) return typeCast.node;
  9709. }
  9710. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9711. this.state = jsx.failState;
  9712. return jsx.node;
  9713. }
  9714. if (arrow.node) {
  9715. this.state = arrow.failState;
  9716. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9717. return arrow.node;
  9718. }
  9719. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9720. this.state = typeCast.failState;
  9721. return typeCast.node;
  9722. }
  9723. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9724. }
  9725. reportReservedArrowTypeParam(node) {
  9726. var _node$extra;
  9727. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9728. this.raise(TSErrors.ReservedArrowTypeParam, {
  9729. at: node
  9730. });
  9731. }
  9732. }
  9733. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9734. if (!this.hasPlugin("jsx") && this.match(47)) {
  9735. return this.tsParseTypeAssertion();
  9736. }
  9737. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9738. }
  9739. parseArrow(node) {
  9740. if (this.match(14)) {
  9741. const result = this.tryParse(abort => {
  9742. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9743. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9744. return returnType;
  9745. });
  9746. if (result.aborted) return;
  9747. if (!result.thrown) {
  9748. if (result.error) this.state = result.failState;
  9749. node.returnType = result.node;
  9750. }
  9751. }
  9752. return super.parseArrow(node);
  9753. }
  9754. parseAssignableListItemTypes(param, flags) {
  9755. if (!(flags & 2)) return param;
  9756. if (this.eat(17)) {
  9757. param.optional = true;
  9758. }
  9759. const type = this.tsTryParseTypeAnnotation();
  9760. if (type) param.typeAnnotation = type;
  9761. this.resetEndLocation(param);
  9762. return param;
  9763. }
  9764. isAssignable(node, isBinding) {
  9765. switch (node.type) {
  9766. case "TSTypeCastExpression":
  9767. return this.isAssignable(node.expression, isBinding);
  9768. case "TSParameterProperty":
  9769. return true;
  9770. default:
  9771. return super.isAssignable(node, isBinding);
  9772. }
  9773. }
  9774. toAssignable(node, isLHS = false) {
  9775. switch (node.type) {
  9776. case "ParenthesizedExpression":
  9777. this.toAssignableParenthesizedExpression(node, isLHS);
  9778. break;
  9779. case "TSAsExpression":
  9780. case "TSSatisfiesExpression":
  9781. case "TSNonNullExpression":
  9782. case "TSTypeAssertion":
  9783. if (isLHS) {
  9784. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
  9785. at: node
  9786. });
  9787. } else {
  9788. this.raise(TSErrors.UnexpectedTypeCastInParameter, {
  9789. at: node
  9790. });
  9791. }
  9792. this.toAssignable(node.expression, isLHS);
  9793. break;
  9794. case "AssignmentExpression":
  9795. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9796. node.left = this.typeCastToParameter(node.left);
  9797. }
  9798. default:
  9799. super.toAssignable(node, isLHS);
  9800. }
  9801. }
  9802. toAssignableParenthesizedExpression(node, isLHS) {
  9803. switch (node.expression.type) {
  9804. case "TSAsExpression":
  9805. case "TSSatisfiesExpression":
  9806. case "TSNonNullExpression":
  9807. case "TSTypeAssertion":
  9808. case "ParenthesizedExpression":
  9809. this.toAssignable(node.expression, isLHS);
  9810. break;
  9811. default:
  9812. super.toAssignable(node, isLHS);
  9813. }
  9814. }
  9815. checkToRestConversion(node, allowPattern) {
  9816. switch (node.type) {
  9817. case "TSAsExpression":
  9818. case "TSSatisfiesExpression":
  9819. case "TSTypeAssertion":
  9820. case "TSNonNullExpression":
  9821. this.checkToRestConversion(node.expression, false);
  9822. break;
  9823. default:
  9824. super.checkToRestConversion(node, allowPattern);
  9825. }
  9826. }
  9827. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9828. return getOwn({
  9829. TSTypeCastExpression: true,
  9830. TSParameterProperty: "parameter",
  9831. TSNonNullExpression: "expression",
  9832. TSAsExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
  9833. TSSatisfiesExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
  9834. TSTypeAssertion: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true]
  9835. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9836. }
  9837. parseBindingAtom() {
  9838. if (this.state.type === 78) {
  9839. return this.parseIdentifier(true);
  9840. }
  9841. return super.parseBindingAtom();
  9842. }
  9843. parseMaybeDecoratorArguments(expr) {
  9844. if (this.match(47) || this.match(51)) {
  9845. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9846. if (this.match(10)) {
  9847. const call = super.parseMaybeDecoratorArguments(expr);
  9848. call.typeParameters = typeArguments;
  9849. return call;
  9850. }
  9851. this.unexpected(null, 10);
  9852. }
  9853. return super.parseMaybeDecoratorArguments(expr);
  9854. }
  9855. checkCommaAfterRest(close) {
  9856. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9857. this.next();
  9858. return false;
  9859. }
  9860. return super.checkCommaAfterRest(close);
  9861. }
  9862. isClassMethod() {
  9863. return this.match(47) || super.isClassMethod();
  9864. }
  9865. isClassProperty() {
  9866. return this.match(35) || this.match(14) || super.isClassProperty();
  9867. }
  9868. parseMaybeDefault(startLoc, left) {
  9869. const node = super.parseMaybeDefault(startLoc, left);
  9870. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9871. this.raise(TSErrors.TypeAnnotationAfterAssign, {
  9872. at: node.typeAnnotation
  9873. });
  9874. }
  9875. return node;
  9876. }
  9877. getTokenFromCode(code) {
  9878. if (this.state.inType) {
  9879. if (code === 62) {
  9880. this.finishOp(48, 1);
  9881. return;
  9882. }
  9883. if (code === 60) {
  9884. this.finishOp(47, 1);
  9885. return;
  9886. }
  9887. }
  9888. super.getTokenFromCode(code);
  9889. }
  9890. reScan_lt_gt() {
  9891. const {
  9892. type
  9893. } = this.state;
  9894. if (type === 47) {
  9895. this.state.pos -= 1;
  9896. this.readToken_lt();
  9897. } else if (type === 48) {
  9898. this.state.pos -= 1;
  9899. this.readToken_gt();
  9900. }
  9901. }
  9902. reScan_lt() {
  9903. const {
  9904. type
  9905. } = this.state;
  9906. if (type === 51) {
  9907. this.state.pos -= 2;
  9908. this.finishOp(47, 1);
  9909. return 47;
  9910. }
  9911. return type;
  9912. }
  9913. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9914. for (let i = 0; i < exprList.length; i++) {
  9915. const expr = exprList[i];
  9916. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9917. exprList[i] = this.typeCastToParameter(expr);
  9918. }
  9919. }
  9920. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9921. }
  9922. typeCastToParameter(node) {
  9923. node.expression.typeAnnotation = node.typeAnnotation;
  9924. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9925. return node.expression;
  9926. }
  9927. shouldParseArrow(params) {
  9928. if (this.match(14)) {
  9929. return params.every(expr => this.isAssignable(expr, true));
  9930. }
  9931. return super.shouldParseArrow(params);
  9932. }
  9933. shouldParseAsyncArrow() {
  9934. return this.match(14) || super.shouldParseAsyncArrow();
  9935. }
  9936. canHaveLeadingDecorator() {
  9937. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9938. }
  9939. jsxParseOpeningElementAfterName(node) {
  9940. if (this.match(47) || this.match(51)) {
  9941. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9942. if (typeArguments) node.typeParameters = typeArguments;
  9943. }
  9944. return super.jsxParseOpeningElementAfterName(node);
  9945. }
  9946. getGetterSetterExpectedParamCount(method) {
  9947. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9948. const params = this.getObjectOrClassMethodParams(method);
  9949. const firstParam = params[0];
  9950. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9951. return hasContextParam ? baseCount + 1 : baseCount;
  9952. }
  9953. parseCatchClauseParam() {
  9954. const param = super.parseCatchClauseParam();
  9955. const type = this.tsTryParseTypeAnnotation();
  9956. if (type) {
  9957. param.typeAnnotation = type;
  9958. this.resetEndLocation(param);
  9959. }
  9960. return param;
  9961. }
  9962. tsInAmbientContext(cb) {
  9963. const oldIsAmbientContext = this.state.isAmbientContext;
  9964. this.state.isAmbientContext = true;
  9965. try {
  9966. return cb();
  9967. } finally {
  9968. this.state.isAmbientContext = oldIsAmbientContext;
  9969. }
  9970. }
  9971. parseClass(node, isStatement, optionalId) {
  9972. const oldInAbstractClass = this.state.inAbstractClass;
  9973. this.state.inAbstractClass = !!node.abstract;
  9974. try {
  9975. return super.parseClass(node, isStatement, optionalId);
  9976. } finally {
  9977. this.state.inAbstractClass = oldInAbstractClass;
  9978. }
  9979. }
  9980. tsParseAbstractDeclaration(node, decorators) {
  9981. if (this.match(80)) {
  9982. node.abstract = true;
  9983. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  9984. } else if (this.isContextual(127)) {
  9985. if (!this.hasFollowingLineBreak()) {
  9986. node.abstract = true;
  9987. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
  9988. at: node
  9989. });
  9990. return this.tsParseInterfaceDeclaration(node);
  9991. }
  9992. } else {
  9993. this.unexpected(null, 80);
  9994. }
  9995. }
  9996. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  9997. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  9998. if (method.abstract) {
  9999. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  10000. if (hasBody) {
  10001. const {
  10002. key
  10003. } = method;
  10004. this.raise(TSErrors.AbstractMethodHasImplementation, {
  10005. at: method,
  10006. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  10007. });
  10008. }
  10009. }
  10010. return method;
  10011. }
  10012. tsParseTypeParameterName() {
  10013. const typeName = this.parseIdentifier();
  10014. return typeName.name;
  10015. }
  10016. shouldParseAsAmbientContext() {
  10017. return !!this.getPluginOption("typescript", "dts");
  10018. }
  10019. parse() {
  10020. if (this.shouldParseAsAmbientContext()) {
  10021. this.state.isAmbientContext = true;
  10022. }
  10023. return super.parse();
  10024. }
  10025. getExpression() {
  10026. if (this.shouldParseAsAmbientContext()) {
  10027. this.state.isAmbientContext = true;
  10028. }
  10029. return super.getExpression();
  10030. }
  10031. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10032. if (!isString && isMaybeTypeOnly) {
  10033. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10034. return this.finishNode(node, "ExportSpecifier");
  10035. }
  10036. node.exportKind = "value";
  10037. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10038. }
  10039. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10040. if (!importedIsString && isMaybeTypeOnly) {
  10041. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10042. return this.finishNode(specifier, "ImportSpecifier");
  10043. }
  10044. specifier.importKind = "value";
  10045. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
  10046. }
  10047. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10048. const leftOfAsKey = isImport ? "imported" : "local";
  10049. const rightOfAsKey = isImport ? "local" : "exported";
  10050. let leftOfAs = node[leftOfAsKey];
  10051. let rightOfAs;
  10052. let hasTypeSpecifier = false;
  10053. let canParseAsKeyword = true;
  10054. const loc = leftOfAs.loc.start;
  10055. if (this.isContextual(93)) {
  10056. const firstAs = this.parseIdentifier();
  10057. if (this.isContextual(93)) {
  10058. const secondAs = this.parseIdentifier();
  10059. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10060. hasTypeSpecifier = true;
  10061. leftOfAs = firstAs;
  10062. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10063. canParseAsKeyword = false;
  10064. } else {
  10065. rightOfAs = secondAs;
  10066. canParseAsKeyword = false;
  10067. }
  10068. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10069. canParseAsKeyword = false;
  10070. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10071. } else {
  10072. hasTypeSpecifier = true;
  10073. leftOfAs = firstAs;
  10074. }
  10075. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10076. hasTypeSpecifier = true;
  10077. if (isImport) {
  10078. leftOfAs = this.parseIdentifier(true);
  10079. if (!this.isContextual(93)) {
  10080. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10081. }
  10082. } else {
  10083. leftOfAs = this.parseModuleExportName();
  10084. }
  10085. }
  10086. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10087. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
  10088. at: loc
  10089. });
  10090. }
  10091. node[leftOfAsKey] = leftOfAs;
  10092. node[rightOfAsKey] = rightOfAs;
  10093. const kindKey = isImport ? "importKind" : "exportKind";
  10094. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10095. if (canParseAsKeyword && this.eatContextual(93)) {
  10096. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10097. }
  10098. if (!node[rightOfAsKey]) {
  10099. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  10100. }
  10101. if (isImport) {
  10102. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
  10103. }
  10104. }
  10105. };
  10106. function isPossiblyLiteralEnum(expression) {
  10107. if (expression.type !== "MemberExpression") return false;
  10108. const {
  10109. computed,
  10110. property
  10111. } = expression;
  10112. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10113. return false;
  10114. }
  10115. return isUncomputedMemberExpressionChain(expression.object);
  10116. }
  10117. function isValidAmbientConstInitializer(expression, estree) {
  10118. var _expression$extra;
  10119. const {
  10120. type
  10121. } = expression;
  10122. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10123. return false;
  10124. }
  10125. if (estree) {
  10126. if (type === "Literal") {
  10127. const {
  10128. value
  10129. } = expression;
  10130. if (typeof value === "string" || typeof value === "boolean") {
  10131. return true;
  10132. }
  10133. }
  10134. } else {
  10135. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10136. return true;
  10137. }
  10138. }
  10139. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10140. return true;
  10141. }
  10142. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10143. return true;
  10144. }
  10145. if (isPossiblyLiteralEnum(expression)) {
  10146. return true;
  10147. }
  10148. return false;
  10149. }
  10150. function isNumber(expression, estree) {
  10151. if (estree) {
  10152. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10153. }
  10154. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10155. }
  10156. function isNegativeNumber(expression, estree) {
  10157. if (expression.type === "UnaryExpression") {
  10158. const {
  10159. operator,
  10160. argument
  10161. } = expression;
  10162. if (operator === "-" && isNumber(argument, estree)) {
  10163. return true;
  10164. }
  10165. }
  10166. return false;
  10167. }
  10168. function isUncomputedMemberExpressionChain(expression) {
  10169. if (expression.type === "Identifier") return true;
  10170. if (expression.type !== "MemberExpression" || expression.computed) {
  10171. return false;
  10172. }
  10173. return isUncomputedMemberExpressionChain(expression.object);
  10174. }
  10175. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10176. ClassNameIsRequired: "A class name is required.",
  10177. UnexpectedSpace: "Unexpected space in placeholder."
  10178. });
  10179. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10180. parsePlaceholder(expectedNode) {
  10181. if (this.match(142)) {
  10182. const node = this.startNode();
  10183. this.next();
  10184. this.assertNoSpace();
  10185. node.name = super.parseIdentifier(true);
  10186. this.assertNoSpace();
  10187. this.expect(142);
  10188. return this.finishPlaceholder(node, expectedNode);
  10189. }
  10190. }
  10191. finishPlaceholder(node, expectedNode) {
  10192. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  10193. node.expectedNode = expectedNode;
  10194. return isFinished ? node : this.finishNode(node, "Placeholder");
  10195. }
  10196. getTokenFromCode(code) {
  10197. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10198. this.finishOp(142, 2);
  10199. } else {
  10200. super.getTokenFromCode(code);
  10201. }
  10202. }
  10203. parseExprAtom(refExpressionErrors) {
  10204. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10205. }
  10206. parseIdentifier(liberal) {
  10207. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10208. }
  10209. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10210. if (word !== undefined) {
  10211. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10212. }
  10213. }
  10214. parseBindingAtom() {
  10215. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10216. }
  10217. isValidLVal(type, isParenthesized, binding) {
  10218. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10219. }
  10220. toAssignable(node, isLHS) {
  10221. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10222. node.expectedNode = "Pattern";
  10223. } else {
  10224. super.toAssignable(node, isLHS);
  10225. }
  10226. }
  10227. chStartsBindingIdentifier(ch, pos) {
  10228. if (super.chStartsBindingIdentifier(ch, pos)) {
  10229. return true;
  10230. }
  10231. const nextToken = this.lookahead();
  10232. if (nextToken.type === 142) {
  10233. return true;
  10234. }
  10235. return false;
  10236. }
  10237. verifyBreakContinue(node, isBreak) {
  10238. if (node.label && node.label.type === "Placeholder") return;
  10239. super.verifyBreakContinue(node, isBreak);
  10240. }
  10241. parseExpressionStatement(node, expr) {
  10242. if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) {
  10243. return super.parseExpressionStatement(node, expr);
  10244. }
  10245. if (this.match(14)) {
  10246. const stmt = node;
  10247. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10248. this.next();
  10249. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10250. return this.finishNode(stmt, "LabeledStatement");
  10251. }
  10252. this.semicolon();
  10253. node.name = expr.name;
  10254. return this.finishPlaceholder(node, "Statement");
  10255. }
  10256. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10257. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10258. }
  10259. parseFunctionId(requireId) {
  10260. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10261. }
  10262. parseClass(node, isStatement, optionalId) {
  10263. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10264. this.next();
  10265. const oldStrict = this.state.strict;
  10266. const placeholder = this.parsePlaceholder("Identifier");
  10267. if (placeholder) {
  10268. if (this.match(81) || this.match(142) || this.match(5)) {
  10269. node.id = placeholder;
  10270. } else if (optionalId || !isStatement) {
  10271. node.id = null;
  10272. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10273. return this.finishNode(node, type);
  10274. } else {
  10275. throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
  10276. at: this.state.startLoc
  10277. });
  10278. }
  10279. } else {
  10280. this.parseClassId(node, isStatement, optionalId);
  10281. }
  10282. super.parseClassSuper(node);
  10283. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10284. return this.finishNode(node, type);
  10285. }
  10286. parseExport(node, decorators) {
  10287. const placeholder = this.parsePlaceholder("Identifier");
  10288. if (!placeholder) return super.parseExport(node, decorators);
  10289. if (!this.isContextual(97) && !this.match(12)) {
  10290. node.specifiers = [];
  10291. node.source = null;
  10292. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10293. return this.finishNode(node, "ExportNamedDeclaration");
  10294. }
  10295. this.expectPlugin("exportDefaultFrom");
  10296. const specifier = this.startNode();
  10297. specifier.exported = placeholder;
  10298. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10299. return super.parseExport(node, decorators);
  10300. }
  10301. isExportDefaultSpecifier() {
  10302. if (this.match(65)) {
  10303. const next = this.nextTokenStart();
  10304. if (this.isUnparsedContextual(next, "from")) {
  10305. if (this.input.startsWith(tokenLabelName(142), this.nextTokenStartSince(next + 4))) {
  10306. return true;
  10307. }
  10308. }
  10309. }
  10310. return super.isExportDefaultSpecifier();
  10311. }
  10312. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10313. var _specifiers;
  10314. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10315. return true;
  10316. }
  10317. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10318. }
  10319. checkExport(node) {
  10320. const {
  10321. specifiers
  10322. } = node;
  10323. if (specifiers != null && specifiers.length) {
  10324. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10325. }
  10326. super.checkExport(node);
  10327. node.specifiers = specifiers;
  10328. }
  10329. parseImport(node) {
  10330. const placeholder = this.parsePlaceholder("Identifier");
  10331. if (!placeholder) return super.parseImport(node);
  10332. node.specifiers = [];
  10333. if (!this.isContextual(97) && !this.match(12)) {
  10334. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10335. this.semicolon();
  10336. return this.finishNode(node, "ImportDeclaration");
  10337. }
  10338. const specifier = this.startNodeAtNode(placeholder);
  10339. specifier.local = placeholder;
  10340. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10341. if (this.eat(12)) {
  10342. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10343. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10344. }
  10345. this.expectContextual(97);
  10346. node.source = this.parseImportSource();
  10347. this.semicolon();
  10348. return this.finishNode(node, "ImportDeclaration");
  10349. }
  10350. parseImportSource() {
  10351. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10352. }
  10353. assertNoSpace() {
  10354. if (this.state.start > this.state.lastTokEndLoc.index) {
  10355. this.raise(PlaceholderErrors.UnexpectedSpace, {
  10356. at: this.state.lastTokEndLoc
  10357. });
  10358. }
  10359. }
  10360. };
  10361. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10362. parseV8Intrinsic() {
  10363. if (this.match(54)) {
  10364. const v8IntrinsicStartLoc = this.state.startLoc;
  10365. const node = this.startNode();
  10366. this.next();
  10367. if (tokenIsIdentifier(this.state.type)) {
  10368. const name = this.parseIdentifierName();
  10369. const identifier = this.createIdentifier(node, name);
  10370. identifier.type = "V8IntrinsicIdentifier";
  10371. if (this.match(10)) {
  10372. return identifier;
  10373. }
  10374. }
  10375. this.unexpected(v8IntrinsicStartLoc);
  10376. }
  10377. }
  10378. parseExprAtom(refExpressionErrors) {
  10379. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10380. }
  10381. };
  10382. function hasPlugin(plugins, expectedConfig) {
  10383. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  10384. const expectedKeys = Object.keys(expectedOptions);
  10385. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  10386. return plugins.some(p => {
  10387. if (typeof p === "string") {
  10388. return expectedOptionsIsEmpty && p === expectedName;
  10389. } else {
  10390. const [pluginName, pluginOptions] = p;
  10391. if (pluginName !== expectedName) {
  10392. return false;
  10393. }
  10394. for (const key of expectedKeys) {
  10395. if (pluginOptions[key] !== expectedOptions[key]) {
  10396. return false;
  10397. }
  10398. }
  10399. return true;
  10400. }
  10401. });
  10402. }
  10403. function getPluginOption(plugins, name, option) {
  10404. const plugin = plugins.find(plugin => {
  10405. if (Array.isArray(plugin)) {
  10406. return plugin[0] === name;
  10407. } else {
  10408. return plugin === name;
  10409. }
  10410. });
  10411. if (plugin && Array.isArray(plugin) && plugin.length > 1) {
  10412. return plugin[1][option];
  10413. }
  10414. return null;
  10415. }
  10416. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10417. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10418. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10419. function validatePlugins(plugins) {
  10420. if (hasPlugin(plugins, "decorators")) {
  10421. if (hasPlugin(plugins, "decorators-legacy")) {
  10422. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10423. }
  10424. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  10425. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10426. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10427. }
  10428. const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
  10429. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10430. throw new Error("'allowCallParenthesized' must be a boolean.");
  10431. }
  10432. }
  10433. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  10434. throw new Error("Cannot combine flow and typescript plugins.");
  10435. }
  10436. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  10437. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10438. }
  10439. if (hasPlugin(plugins, "pipelineOperator")) {
  10440. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  10441. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10442. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10443. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10444. }
  10445. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  10446. syntaxType: "hash"
  10447. }]);
  10448. if (proposal === "hack") {
  10449. if (hasPlugin(plugins, "placeholders")) {
  10450. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10451. }
  10452. if (hasPlugin(plugins, "v8intrinsic")) {
  10453. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10454. }
  10455. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  10456. if (!TOPIC_TOKENS.includes(topicToken)) {
  10457. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10458. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10459. }
  10460. if (topicToken === "#" && tupleSyntaxIsHash) {
  10461. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10462. }
  10463. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  10464. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10465. }
  10466. }
  10467. if (hasPlugin(plugins, "moduleAttributes")) {
  10468. {
  10469. if (hasPlugin(plugins, "importAssertions") || hasPlugin(plugins, "importAttributes")) {
  10470. throw new Error("Cannot combine importAssertions, importAttributes and moduleAttributes plugins.");
  10471. }
  10472. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  10473. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10474. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10475. }
  10476. }
  10477. }
  10478. if (hasPlugin(plugins, "importAssertions") && hasPlugin(plugins, "importAttributes")) {
  10479. throw new Error("Cannot combine importAssertions and importAttributes plugins.");
  10480. }
  10481. if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  10482. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10483. }
  10484. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  10485. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10486. error.missingPlugins = "doExpressions";
  10487. throw error;
  10488. }
  10489. }
  10490. const mixinPlugins = {
  10491. estree,
  10492. jsx,
  10493. flow,
  10494. typescript,
  10495. v8intrinsic,
  10496. placeholders
  10497. };
  10498. const mixinPluginNames = Object.keys(mixinPlugins);
  10499. const defaultOptions = {
  10500. sourceType: "script",
  10501. sourceFilename: undefined,
  10502. startColumn: 0,
  10503. startLine: 1,
  10504. allowAwaitOutsideFunction: false,
  10505. allowReturnOutsideFunction: false,
  10506. allowNewTargetOutsideFunction: false,
  10507. allowImportExportEverywhere: false,
  10508. allowSuperOutsideMethod: false,
  10509. allowUndeclaredExports: false,
  10510. plugins: [],
  10511. strictMode: null,
  10512. ranges: false,
  10513. tokens: false,
  10514. createParenthesizedExpressions: false,
  10515. errorRecovery: false,
  10516. attachComment: true,
  10517. annexB: true
  10518. };
  10519. function getOptions(opts) {
  10520. if (opts && opts.annexB != null && opts.annexB !== false) {
  10521. throw new Error("The `annexB` option can only be set to `false`.");
  10522. }
  10523. const options = {};
  10524. for (const key of Object.keys(defaultOptions)) {
  10525. options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key];
  10526. }
  10527. return options;
  10528. }
  10529. class ExpressionParser extends LValParser {
  10530. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10531. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10532. return;
  10533. }
  10534. const key = prop.key;
  10535. const name = key.type === "Identifier" ? key.name : key.value;
  10536. if (name === "__proto__") {
  10537. if (isRecord) {
  10538. this.raise(Errors.RecordNoProto, {
  10539. at: key
  10540. });
  10541. return;
  10542. }
  10543. if (protoRef.used) {
  10544. if (refExpressionErrors) {
  10545. if (refExpressionErrors.doubleProtoLoc === null) {
  10546. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10547. }
  10548. } else {
  10549. this.raise(Errors.DuplicateProto, {
  10550. at: key
  10551. });
  10552. }
  10553. }
  10554. protoRef.used = true;
  10555. }
  10556. }
  10557. shouldExitDescending(expr, potentialArrowAt) {
  10558. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  10559. }
  10560. getExpression() {
  10561. this.enterInitialScopes();
  10562. this.nextToken();
  10563. const expr = this.parseExpression();
  10564. if (!this.match(137)) {
  10565. this.unexpected();
  10566. }
  10567. this.finalizeRemainingComments();
  10568. expr.comments = this.state.comments;
  10569. expr.errors = this.state.errors;
  10570. if (this.options.tokens) {
  10571. expr.tokens = this.tokens;
  10572. }
  10573. return expr;
  10574. }
  10575. parseExpression(disallowIn, refExpressionErrors) {
  10576. if (disallowIn) {
  10577. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10578. }
  10579. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10580. }
  10581. parseExpressionBase(refExpressionErrors) {
  10582. const startLoc = this.state.startLoc;
  10583. const expr = this.parseMaybeAssign(refExpressionErrors);
  10584. if (this.match(12)) {
  10585. const node = this.startNodeAt(startLoc);
  10586. node.expressions = [expr];
  10587. while (this.eat(12)) {
  10588. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10589. }
  10590. this.toReferencedList(node.expressions);
  10591. return this.finishNode(node, "SequenceExpression");
  10592. }
  10593. return expr;
  10594. }
  10595. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10596. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10597. }
  10598. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10599. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10600. }
  10601. setOptionalParametersError(refExpressionErrors, resultError) {
  10602. var _resultError$loc;
  10603. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10604. }
  10605. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10606. const startLoc = this.state.startLoc;
  10607. if (this.isContextual(106)) {
  10608. if (this.prodParam.hasYield) {
  10609. let left = this.parseYield();
  10610. if (afterLeftParse) {
  10611. left = afterLeftParse.call(this, left, startLoc);
  10612. }
  10613. return left;
  10614. }
  10615. }
  10616. let ownExpressionErrors;
  10617. if (refExpressionErrors) {
  10618. ownExpressionErrors = false;
  10619. } else {
  10620. refExpressionErrors = new ExpressionErrors();
  10621. ownExpressionErrors = true;
  10622. }
  10623. const {
  10624. type
  10625. } = this.state;
  10626. if (type === 10 || tokenIsIdentifier(type)) {
  10627. this.state.potentialArrowAt = this.state.start;
  10628. }
  10629. let left = this.parseMaybeConditional(refExpressionErrors);
  10630. if (afterLeftParse) {
  10631. left = afterLeftParse.call(this, left, startLoc);
  10632. }
  10633. if (tokenIsAssignment(this.state.type)) {
  10634. const node = this.startNodeAt(startLoc);
  10635. const operator = this.state.value;
  10636. node.operator = operator;
  10637. if (this.match(29)) {
  10638. this.toAssignable(left, true);
  10639. node.left = left;
  10640. const startIndex = startLoc.index;
  10641. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10642. refExpressionErrors.doubleProtoLoc = null;
  10643. }
  10644. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10645. refExpressionErrors.shorthandAssignLoc = null;
  10646. }
  10647. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10648. this.checkDestructuringPrivate(refExpressionErrors);
  10649. refExpressionErrors.privateKeyLoc = null;
  10650. }
  10651. } else {
  10652. node.left = left;
  10653. }
  10654. this.next();
  10655. node.right = this.parseMaybeAssign();
  10656. this.checkLVal(left, {
  10657. in: this.finishNode(node, "AssignmentExpression")
  10658. });
  10659. return node;
  10660. } else if (ownExpressionErrors) {
  10661. this.checkExpressionErrors(refExpressionErrors, true);
  10662. }
  10663. return left;
  10664. }
  10665. parseMaybeConditional(refExpressionErrors) {
  10666. const startLoc = this.state.startLoc;
  10667. const potentialArrowAt = this.state.potentialArrowAt;
  10668. const expr = this.parseExprOps(refExpressionErrors);
  10669. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10670. return expr;
  10671. }
  10672. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10673. }
  10674. parseConditional(expr, startLoc, refExpressionErrors) {
  10675. if (this.eat(17)) {
  10676. const node = this.startNodeAt(startLoc);
  10677. node.test = expr;
  10678. node.consequent = this.parseMaybeAssignAllowIn();
  10679. this.expect(14);
  10680. node.alternate = this.parseMaybeAssign();
  10681. return this.finishNode(node, "ConditionalExpression");
  10682. }
  10683. return expr;
  10684. }
  10685. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10686. return this.match(136) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10687. }
  10688. parseExprOps(refExpressionErrors) {
  10689. const startLoc = this.state.startLoc;
  10690. const potentialArrowAt = this.state.potentialArrowAt;
  10691. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10692. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10693. return expr;
  10694. }
  10695. return this.parseExprOp(expr, startLoc, -1);
  10696. }
  10697. parseExprOp(left, leftStartLoc, minPrec) {
  10698. if (this.isPrivateName(left)) {
  10699. const value = this.getPrivateNameSV(left);
  10700. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10701. this.raise(Errors.PrivateInExpectedIn, {
  10702. at: left,
  10703. identifierName: value
  10704. });
  10705. }
  10706. this.classScope.usePrivateName(value, left.loc.start);
  10707. }
  10708. const op = this.state.type;
  10709. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10710. let prec = tokenOperatorPrecedence(op);
  10711. if (prec > minPrec) {
  10712. if (op === 39) {
  10713. this.expectPlugin("pipelineOperator");
  10714. if (this.state.inFSharpPipelineDirectBody) {
  10715. return left;
  10716. }
  10717. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10718. }
  10719. const node = this.startNodeAt(leftStartLoc);
  10720. node.left = left;
  10721. node.operator = this.state.value;
  10722. const logical = op === 41 || op === 42;
  10723. const coalesce = op === 40;
  10724. if (coalesce) {
  10725. prec = tokenOperatorPrecedence(42);
  10726. }
  10727. this.next();
  10728. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10729. proposal: "minimal"
  10730. }])) {
  10731. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10732. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
  10733. at: this.state.startLoc
  10734. });
  10735. }
  10736. }
  10737. node.right = this.parseExprOpRightExpr(op, prec);
  10738. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10739. const nextOp = this.state.type;
  10740. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10741. throw this.raise(Errors.MixingCoalesceWithLogical, {
  10742. at: this.state.startLoc
  10743. });
  10744. }
  10745. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10746. }
  10747. }
  10748. return left;
  10749. }
  10750. parseExprOpRightExpr(op, prec) {
  10751. const startLoc = this.state.startLoc;
  10752. switch (op) {
  10753. case 39:
  10754. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10755. case "hack":
  10756. return this.withTopicBindingContext(() => {
  10757. return this.parseHackPipeBody();
  10758. });
  10759. case "smart":
  10760. return this.withTopicBindingContext(() => {
  10761. if (this.prodParam.hasYield && this.isContextual(106)) {
  10762. throw this.raise(Errors.PipeBodyIsTighter, {
  10763. at: this.state.startLoc
  10764. });
  10765. }
  10766. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10767. });
  10768. case "fsharp":
  10769. return this.withSoloAwaitPermittingContext(() => {
  10770. return this.parseFSharpPipelineBody(prec);
  10771. });
  10772. }
  10773. default:
  10774. return this.parseExprOpBaseRightExpr(op, prec);
  10775. }
  10776. }
  10777. parseExprOpBaseRightExpr(op, prec) {
  10778. const startLoc = this.state.startLoc;
  10779. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10780. }
  10781. parseHackPipeBody() {
  10782. var _body$extra;
  10783. const {
  10784. startLoc
  10785. } = this.state;
  10786. const body = this.parseMaybeAssign();
  10787. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10788. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10789. this.raise(Errors.PipeUnparenthesizedBody, {
  10790. at: startLoc,
  10791. type: body.type
  10792. });
  10793. }
  10794. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10795. this.raise(Errors.PipeTopicUnused, {
  10796. at: startLoc
  10797. });
  10798. }
  10799. return body;
  10800. }
  10801. checkExponentialAfterUnary(node) {
  10802. if (this.match(57)) {
  10803. this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
  10804. at: node.argument
  10805. });
  10806. }
  10807. }
  10808. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10809. const startLoc = this.state.startLoc;
  10810. const isAwait = this.isContextual(96);
  10811. if (isAwait && this.isAwaitAllowed()) {
  10812. this.next();
  10813. const expr = this.parseAwait(startLoc);
  10814. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10815. return expr;
  10816. }
  10817. const update = this.match(34);
  10818. const node = this.startNode();
  10819. if (tokenIsPrefix(this.state.type)) {
  10820. node.operator = this.state.value;
  10821. node.prefix = true;
  10822. if (this.match(72)) {
  10823. this.expectPlugin("throwExpressions");
  10824. }
  10825. const isDelete = this.match(89);
  10826. this.next();
  10827. node.argument = this.parseMaybeUnary(null, true);
  10828. this.checkExpressionErrors(refExpressionErrors, true);
  10829. if (this.state.strict && isDelete) {
  10830. const arg = node.argument;
  10831. if (arg.type === "Identifier") {
  10832. this.raise(Errors.StrictDelete, {
  10833. at: node
  10834. });
  10835. } else if (this.hasPropertyAsPrivateName(arg)) {
  10836. this.raise(Errors.DeletePrivateField, {
  10837. at: node
  10838. });
  10839. }
  10840. }
  10841. if (!update) {
  10842. if (!sawUnary) {
  10843. this.checkExponentialAfterUnary(node);
  10844. }
  10845. return this.finishNode(node, "UnaryExpression");
  10846. }
  10847. }
  10848. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10849. if (isAwait) {
  10850. const {
  10851. type
  10852. } = this.state;
  10853. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10854. if (startsExpr && !this.isAmbiguousAwait()) {
  10855. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
  10856. at: startLoc
  10857. });
  10858. return this.parseAwait(startLoc);
  10859. }
  10860. }
  10861. return expr;
  10862. }
  10863. parseUpdate(node, update, refExpressionErrors) {
  10864. if (update) {
  10865. const updateExpressionNode = node;
  10866. this.checkLVal(updateExpressionNode.argument, {
  10867. in: this.finishNode(updateExpressionNode, "UpdateExpression")
  10868. });
  10869. return node;
  10870. }
  10871. const startLoc = this.state.startLoc;
  10872. let expr = this.parseExprSubscripts(refExpressionErrors);
  10873. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10874. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10875. const node = this.startNodeAt(startLoc);
  10876. node.operator = this.state.value;
  10877. node.prefix = false;
  10878. node.argument = expr;
  10879. this.next();
  10880. this.checkLVal(expr, {
  10881. in: expr = this.finishNode(node, "UpdateExpression")
  10882. });
  10883. }
  10884. return expr;
  10885. }
  10886. parseExprSubscripts(refExpressionErrors) {
  10887. const startLoc = this.state.startLoc;
  10888. const potentialArrowAt = this.state.potentialArrowAt;
  10889. const expr = this.parseExprAtom(refExpressionErrors);
  10890. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10891. return expr;
  10892. }
  10893. return this.parseSubscripts(expr, startLoc);
  10894. }
  10895. parseSubscripts(base, startLoc, noCalls) {
  10896. const state = {
  10897. optionalChainMember: false,
  10898. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10899. stop: false
  10900. };
  10901. do {
  10902. base = this.parseSubscript(base, startLoc, noCalls, state);
  10903. state.maybeAsyncArrow = false;
  10904. } while (!state.stop);
  10905. return base;
  10906. }
  10907. parseSubscript(base, startLoc, noCalls, state) {
  10908. const {
  10909. type
  10910. } = this.state;
  10911. if (!noCalls && type === 15) {
  10912. return this.parseBind(base, startLoc, noCalls, state);
  10913. } else if (tokenIsTemplate(type)) {
  10914. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10915. }
  10916. let optional = false;
  10917. if (type === 18) {
  10918. if (noCalls) {
  10919. this.raise(Errors.OptionalChainingNoNew, {
  10920. at: this.state.startLoc
  10921. });
  10922. if (this.lookaheadCharCode() === 40) {
  10923. state.stop = true;
  10924. return base;
  10925. }
  10926. }
  10927. state.optionalChainMember = optional = true;
  10928. this.next();
  10929. }
  10930. if (!noCalls && this.match(10)) {
  10931. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10932. } else {
  10933. const computed = this.eat(0);
  10934. if (computed || optional || this.eat(16)) {
  10935. return this.parseMember(base, startLoc, state, computed, optional);
  10936. } else {
  10937. state.stop = true;
  10938. return base;
  10939. }
  10940. }
  10941. }
  10942. parseMember(base, startLoc, state, computed, optional) {
  10943. const node = this.startNodeAt(startLoc);
  10944. node.object = base;
  10945. node.computed = computed;
  10946. if (computed) {
  10947. node.property = this.parseExpression();
  10948. this.expect(3);
  10949. } else if (this.match(136)) {
  10950. if (base.type === "Super") {
  10951. this.raise(Errors.SuperPrivateField, {
  10952. at: startLoc
  10953. });
  10954. }
  10955. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10956. node.property = this.parsePrivateName();
  10957. } else {
  10958. node.property = this.parseIdentifier(true);
  10959. }
  10960. if (state.optionalChainMember) {
  10961. node.optional = optional;
  10962. return this.finishNode(node, "OptionalMemberExpression");
  10963. } else {
  10964. return this.finishNode(node, "MemberExpression");
  10965. }
  10966. }
  10967. parseBind(base, startLoc, noCalls, state) {
  10968. const node = this.startNodeAt(startLoc);
  10969. node.object = base;
  10970. this.next();
  10971. node.callee = this.parseNoCallExpr();
  10972. state.stop = true;
  10973. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10974. }
  10975. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10976. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10977. let refExpressionErrors = null;
  10978. this.state.maybeInArrowParameters = true;
  10979. this.next();
  10980. const node = this.startNodeAt(startLoc);
  10981. node.callee = base;
  10982. const {
  10983. maybeAsyncArrow,
  10984. optionalChainMember
  10985. } = state;
  10986. if (maybeAsyncArrow) {
  10987. this.expressionScope.enter(newAsyncArrowScope());
  10988. refExpressionErrors = new ExpressionErrors();
  10989. }
  10990. if (optionalChainMember) {
  10991. node.optional = optional;
  10992. }
  10993. if (optional) {
  10994. node.arguments = this.parseCallExpressionArguments(11);
  10995. } else {
  10996. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  10997. }
  10998. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10999. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  11000. state.stop = true;
  11001. this.checkDestructuringPrivate(refExpressionErrors);
  11002. this.expressionScope.validateAsPattern();
  11003. this.expressionScope.exit();
  11004. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  11005. } else {
  11006. if (maybeAsyncArrow) {
  11007. this.checkExpressionErrors(refExpressionErrors, true);
  11008. this.expressionScope.exit();
  11009. }
  11010. this.toReferencedArguments(finishedNode);
  11011. }
  11012. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11013. return finishedNode;
  11014. }
  11015. toReferencedArguments(node, isParenthesizedExpr) {
  11016. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11017. }
  11018. parseTaggedTemplateExpression(base, startLoc, state) {
  11019. const node = this.startNodeAt(startLoc);
  11020. node.tag = base;
  11021. node.quasi = this.parseTemplate(true);
  11022. if (state.optionalChainMember) {
  11023. this.raise(Errors.OptionalChainingNoTemplate, {
  11024. at: startLoc
  11025. });
  11026. }
  11027. return this.finishNode(node, "TaggedTemplateExpression");
  11028. }
  11029. atPossibleAsyncArrow(base) {
  11030. 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;
  11031. }
  11032. expectImportAttributesPlugin() {
  11033. if (!this.hasPlugin("importAssertions")) {
  11034. this.expectPlugin("importAttributes");
  11035. }
  11036. }
  11037. finishCallExpression(node, optional) {
  11038. if (node.callee.type === "Import") {
  11039. if (node.arguments.length === 2) {
  11040. {
  11041. if (!this.hasPlugin("moduleAttributes")) {
  11042. this.expectImportAttributesPlugin();
  11043. }
  11044. }
  11045. }
  11046. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11047. this.raise(Errors.ImportCallArity, {
  11048. at: node,
  11049. maxArgumentCount: this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  11050. });
  11051. } else {
  11052. for (const arg of node.arguments) {
  11053. if (arg.type === "SpreadElement") {
  11054. this.raise(Errors.ImportCallSpreadArgument, {
  11055. at: arg
  11056. });
  11057. }
  11058. }
  11059. }
  11060. }
  11061. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11062. }
  11063. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11064. const elts = [];
  11065. let first = true;
  11066. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11067. this.state.inFSharpPipelineDirectBody = false;
  11068. while (!this.eat(close)) {
  11069. if (first) {
  11070. first = false;
  11071. } else {
  11072. this.expect(12);
  11073. if (this.match(close)) {
  11074. if (dynamicImport && !this.hasPlugin("importAttributes") && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  11075. this.raise(Errors.ImportCallArgumentTrailingComma, {
  11076. at: this.state.lastTokStartLoc
  11077. });
  11078. }
  11079. if (nodeForExtra) {
  11080. this.addTrailingCommaExtraToNode(nodeForExtra);
  11081. }
  11082. this.next();
  11083. break;
  11084. }
  11085. }
  11086. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  11087. }
  11088. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11089. return elts;
  11090. }
  11091. shouldParseAsyncArrow() {
  11092. return this.match(19) && !this.canInsertSemicolon();
  11093. }
  11094. parseAsyncArrowFromCallExpression(node, call) {
  11095. var _call$extra;
  11096. this.resetPreviousNodeTrailingComments(call);
  11097. this.expect(19);
  11098. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11099. if (call.innerComments) {
  11100. setInnerComments(node, call.innerComments);
  11101. }
  11102. if (call.callee.trailingComments) {
  11103. setInnerComments(node, call.callee.trailingComments);
  11104. }
  11105. return node;
  11106. }
  11107. parseNoCallExpr() {
  11108. const startLoc = this.state.startLoc;
  11109. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11110. }
  11111. parseExprAtom(refExpressionErrors) {
  11112. let node;
  11113. let decorators = null;
  11114. const {
  11115. type
  11116. } = this.state;
  11117. switch (type) {
  11118. case 79:
  11119. return this.parseSuper();
  11120. case 83:
  11121. node = this.startNode();
  11122. this.next();
  11123. if (this.match(16)) {
  11124. return this.parseImportMetaProperty(node);
  11125. }
  11126. if (!this.match(10)) {
  11127. this.raise(Errors.UnsupportedImport, {
  11128. at: this.state.lastTokStartLoc
  11129. });
  11130. }
  11131. return this.finishNode(node, "Import");
  11132. case 78:
  11133. node = this.startNode();
  11134. this.next();
  11135. return this.finishNode(node, "ThisExpression");
  11136. case 90:
  11137. {
  11138. return this.parseDo(this.startNode(), false);
  11139. }
  11140. case 56:
  11141. case 31:
  11142. {
  11143. this.readRegexp();
  11144. return this.parseRegExpLiteral(this.state.value);
  11145. }
  11146. case 132:
  11147. return this.parseNumericLiteral(this.state.value);
  11148. case 133:
  11149. return this.parseBigIntLiteral(this.state.value);
  11150. case 134:
  11151. return this.parseDecimalLiteral(this.state.value);
  11152. case 131:
  11153. return this.parseStringLiteral(this.state.value);
  11154. case 84:
  11155. return this.parseNullLiteral();
  11156. case 85:
  11157. return this.parseBooleanLiteral(true);
  11158. case 86:
  11159. return this.parseBooleanLiteral(false);
  11160. case 10:
  11161. {
  11162. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11163. return this.parseParenAndDistinguishExpression(canBeArrow);
  11164. }
  11165. case 2:
  11166. case 1:
  11167. {
  11168. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11169. }
  11170. case 0:
  11171. {
  11172. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11173. }
  11174. case 6:
  11175. case 7:
  11176. {
  11177. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11178. }
  11179. case 5:
  11180. {
  11181. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11182. }
  11183. case 68:
  11184. return this.parseFunctionOrFunctionSent();
  11185. case 26:
  11186. decorators = this.parseDecorators();
  11187. case 80:
  11188. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11189. case 77:
  11190. return this.parseNewOrNewTarget();
  11191. case 25:
  11192. case 24:
  11193. return this.parseTemplate(false);
  11194. case 15:
  11195. {
  11196. node = this.startNode();
  11197. this.next();
  11198. node.object = null;
  11199. const callee = node.callee = this.parseNoCallExpr();
  11200. if (callee.type === "MemberExpression") {
  11201. return this.finishNode(node, "BindExpression");
  11202. } else {
  11203. throw this.raise(Errors.UnsupportedBind, {
  11204. at: callee
  11205. });
  11206. }
  11207. }
  11208. case 136:
  11209. {
  11210. this.raise(Errors.PrivateInExpectedIn, {
  11211. at: this.state.startLoc,
  11212. identifierName: this.state.value
  11213. });
  11214. return this.parsePrivateName();
  11215. }
  11216. case 33:
  11217. {
  11218. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11219. }
  11220. case 32:
  11221. {
  11222. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11223. }
  11224. case 37:
  11225. case 38:
  11226. {
  11227. return this.parseTopicReference("hack");
  11228. }
  11229. case 44:
  11230. case 54:
  11231. case 27:
  11232. {
  11233. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11234. if (pipeProposal) {
  11235. return this.parseTopicReference(pipeProposal);
  11236. }
  11237. this.unexpected();
  11238. break;
  11239. }
  11240. case 47:
  11241. {
  11242. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11243. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11244. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11245. } else {
  11246. this.unexpected();
  11247. }
  11248. break;
  11249. }
  11250. default:
  11251. if (tokenIsIdentifier(type)) {
  11252. if (this.isContextual(125) && this.lookaheadInLineCharCode() === 123) {
  11253. return this.parseModuleExpression();
  11254. }
  11255. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11256. const containsEsc = this.state.containsEsc;
  11257. const id = this.parseIdentifier();
  11258. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11259. const {
  11260. type
  11261. } = this.state;
  11262. if (type === 68) {
  11263. this.resetPreviousNodeTrailingComments(id);
  11264. this.next();
  11265. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11266. } else if (tokenIsIdentifier(type)) {
  11267. if (this.lookaheadCharCode() === 61) {
  11268. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11269. } else {
  11270. return id;
  11271. }
  11272. } else if (type === 90) {
  11273. this.resetPreviousNodeTrailingComments(id);
  11274. return this.parseDo(this.startNodeAtNode(id), true);
  11275. }
  11276. }
  11277. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11278. this.next();
  11279. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11280. }
  11281. return id;
  11282. } else {
  11283. this.unexpected();
  11284. }
  11285. }
  11286. }
  11287. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11288. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11289. if (pipeProposal) {
  11290. this.state.type = topicTokenType;
  11291. this.state.value = topicTokenValue;
  11292. this.state.pos--;
  11293. this.state.end--;
  11294. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11295. return this.parseTopicReference(pipeProposal);
  11296. } else {
  11297. this.unexpected();
  11298. }
  11299. }
  11300. parseTopicReference(pipeProposal) {
  11301. const node = this.startNode();
  11302. const startLoc = this.state.startLoc;
  11303. const tokenType = this.state.type;
  11304. this.next();
  11305. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11306. }
  11307. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11308. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11309. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11310. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11311. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, {
  11312. at: startLoc
  11313. });
  11314. }
  11315. this.registerTopicReference();
  11316. return this.finishNode(node, nodeType);
  11317. } else {
  11318. throw this.raise(Errors.PipeTopicUnconfiguredToken, {
  11319. at: startLoc,
  11320. token: tokenLabelName(tokenType)
  11321. });
  11322. }
  11323. }
  11324. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11325. switch (pipeProposal) {
  11326. case "hack":
  11327. {
  11328. return this.hasPlugin(["pipelineOperator", {
  11329. topicToken: tokenLabelName(tokenType)
  11330. }]);
  11331. }
  11332. case "smart":
  11333. return tokenType === 27;
  11334. default:
  11335. throw this.raise(Errors.PipeTopicRequiresHackPipes, {
  11336. at: startLoc
  11337. });
  11338. }
  11339. }
  11340. parseAsyncArrowUnaryFunction(node) {
  11341. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11342. const params = [this.parseIdentifier()];
  11343. this.prodParam.exit();
  11344. if (this.hasPrecedingLineBreak()) {
  11345. this.raise(Errors.LineTerminatorBeforeArrow, {
  11346. at: this.state.curPosition()
  11347. });
  11348. }
  11349. this.expect(19);
  11350. return this.parseArrowExpression(node, params, true);
  11351. }
  11352. parseDo(node, isAsync) {
  11353. this.expectPlugin("doExpressions");
  11354. if (isAsync) {
  11355. this.expectPlugin("asyncDoExpressions");
  11356. }
  11357. node.async = isAsync;
  11358. this.next();
  11359. const oldLabels = this.state.labels;
  11360. this.state.labels = [];
  11361. if (isAsync) {
  11362. this.prodParam.enter(PARAM_AWAIT);
  11363. node.body = this.parseBlock();
  11364. this.prodParam.exit();
  11365. } else {
  11366. node.body = this.parseBlock();
  11367. }
  11368. this.state.labels = oldLabels;
  11369. return this.finishNode(node, "DoExpression");
  11370. }
  11371. parseSuper() {
  11372. const node = this.startNode();
  11373. this.next();
  11374. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  11375. this.raise(Errors.SuperNotAllowed, {
  11376. at: node
  11377. });
  11378. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  11379. this.raise(Errors.UnexpectedSuper, {
  11380. at: node
  11381. });
  11382. }
  11383. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11384. this.raise(Errors.UnsupportedSuper, {
  11385. at: node
  11386. });
  11387. }
  11388. return this.finishNode(node, "Super");
  11389. }
  11390. parsePrivateName() {
  11391. const node = this.startNode();
  11392. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11393. const name = this.state.value;
  11394. this.next();
  11395. node.id = this.createIdentifier(id, name);
  11396. return this.finishNode(node, "PrivateName");
  11397. }
  11398. parseFunctionOrFunctionSent() {
  11399. const node = this.startNode();
  11400. this.next();
  11401. if (this.prodParam.hasYield && this.match(16)) {
  11402. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11403. this.next();
  11404. if (this.match(102)) {
  11405. this.expectPlugin("functionSent");
  11406. } else if (!this.hasPlugin("functionSent")) {
  11407. this.unexpected();
  11408. }
  11409. return this.parseMetaProperty(node, meta, "sent");
  11410. }
  11411. return this.parseFunction(node);
  11412. }
  11413. parseMetaProperty(node, meta, propertyName) {
  11414. node.meta = meta;
  11415. const containsEsc = this.state.containsEsc;
  11416. node.property = this.parseIdentifier(true);
  11417. if (node.property.name !== propertyName || containsEsc) {
  11418. this.raise(Errors.UnsupportedMetaProperty, {
  11419. at: node.property,
  11420. target: meta.name,
  11421. onlyValidPropertyName: propertyName
  11422. });
  11423. }
  11424. return this.finishNode(node, "MetaProperty");
  11425. }
  11426. parseImportMetaProperty(node) {
  11427. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11428. this.next();
  11429. if (this.isContextual(100)) {
  11430. if (!this.inModule) {
  11431. this.raise(Errors.ImportMetaOutsideModule, {
  11432. at: id
  11433. });
  11434. }
  11435. this.sawUnambiguousESM = true;
  11436. }
  11437. return this.parseMetaProperty(node, id, "meta");
  11438. }
  11439. parseLiteralAtNode(value, type, node) {
  11440. this.addExtra(node, "rawValue", value);
  11441. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  11442. node.value = value;
  11443. this.next();
  11444. return this.finishNode(node, type);
  11445. }
  11446. parseLiteral(value, type) {
  11447. const node = this.startNode();
  11448. return this.parseLiteralAtNode(value, type, node);
  11449. }
  11450. parseStringLiteral(value) {
  11451. return this.parseLiteral(value, "StringLiteral");
  11452. }
  11453. parseNumericLiteral(value) {
  11454. return this.parseLiteral(value, "NumericLiteral");
  11455. }
  11456. parseBigIntLiteral(value) {
  11457. return this.parseLiteral(value, "BigIntLiteral");
  11458. }
  11459. parseDecimalLiteral(value) {
  11460. return this.parseLiteral(value, "DecimalLiteral");
  11461. }
  11462. parseRegExpLiteral(value) {
  11463. const node = this.parseLiteral(value.value, "RegExpLiteral");
  11464. node.pattern = value.pattern;
  11465. node.flags = value.flags;
  11466. return node;
  11467. }
  11468. parseBooleanLiteral(value) {
  11469. const node = this.startNode();
  11470. node.value = value;
  11471. this.next();
  11472. return this.finishNode(node, "BooleanLiteral");
  11473. }
  11474. parseNullLiteral() {
  11475. const node = this.startNode();
  11476. this.next();
  11477. return this.finishNode(node, "NullLiteral");
  11478. }
  11479. parseParenAndDistinguishExpression(canBeArrow) {
  11480. const startLoc = this.state.startLoc;
  11481. let val;
  11482. this.next();
  11483. this.expressionScope.enter(newArrowHeadScope());
  11484. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11485. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11486. this.state.maybeInArrowParameters = true;
  11487. this.state.inFSharpPipelineDirectBody = false;
  11488. const innerStartLoc = this.state.startLoc;
  11489. const exprList = [];
  11490. const refExpressionErrors = new ExpressionErrors();
  11491. let first = true;
  11492. let spreadStartLoc;
  11493. let optionalCommaStartLoc;
  11494. while (!this.match(11)) {
  11495. if (first) {
  11496. first = false;
  11497. } else {
  11498. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11499. if (this.match(11)) {
  11500. optionalCommaStartLoc = this.state.startLoc;
  11501. break;
  11502. }
  11503. }
  11504. if (this.match(21)) {
  11505. const spreadNodeStartLoc = this.state.startLoc;
  11506. spreadStartLoc = this.state.startLoc;
  11507. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11508. if (!this.checkCommaAfterRest(41)) {
  11509. break;
  11510. }
  11511. } else {
  11512. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11513. }
  11514. }
  11515. const innerEndLoc = this.state.lastTokEndLoc;
  11516. this.expect(11);
  11517. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11518. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11519. let arrowNode = this.startNodeAt(startLoc);
  11520. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11521. this.checkDestructuringPrivate(refExpressionErrors);
  11522. this.expressionScope.validateAsPattern();
  11523. this.expressionScope.exit();
  11524. this.parseArrowExpression(arrowNode, exprList, false);
  11525. return arrowNode;
  11526. }
  11527. this.expressionScope.exit();
  11528. if (!exprList.length) {
  11529. this.unexpected(this.state.lastTokStartLoc);
  11530. }
  11531. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11532. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11533. this.checkExpressionErrors(refExpressionErrors, true);
  11534. this.toReferencedListDeep(exprList, true);
  11535. if (exprList.length > 1) {
  11536. val = this.startNodeAt(innerStartLoc);
  11537. val.expressions = exprList;
  11538. this.finishNode(val, "SequenceExpression");
  11539. this.resetEndLocation(val, innerEndLoc);
  11540. } else {
  11541. val = exprList[0];
  11542. }
  11543. return this.wrapParenthesis(startLoc, val);
  11544. }
  11545. wrapParenthesis(startLoc, expression) {
  11546. if (!this.options.createParenthesizedExpressions) {
  11547. this.addExtra(expression, "parenthesized", true);
  11548. this.addExtra(expression, "parenStart", startLoc.index);
  11549. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11550. return expression;
  11551. }
  11552. const parenExpression = this.startNodeAt(startLoc);
  11553. parenExpression.expression = expression;
  11554. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11555. }
  11556. shouldParseArrow(params) {
  11557. return !this.canInsertSemicolon();
  11558. }
  11559. parseArrow(node) {
  11560. if (this.eat(19)) {
  11561. return node;
  11562. }
  11563. }
  11564. parseParenItem(node, startLoc) {
  11565. return node;
  11566. }
  11567. parseNewOrNewTarget() {
  11568. const node = this.startNode();
  11569. this.next();
  11570. if (this.match(16)) {
  11571. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11572. this.next();
  11573. const metaProp = this.parseMetaProperty(node, meta, "target");
  11574. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
  11575. this.raise(Errors.UnexpectedNewTarget, {
  11576. at: metaProp
  11577. });
  11578. }
  11579. return metaProp;
  11580. }
  11581. return this.parseNew(node);
  11582. }
  11583. parseNew(node) {
  11584. this.parseNewCallee(node);
  11585. if (this.eat(10)) {
  11586. const args = this.parseExprList(11);
  11587. this.toReferencedList(args);
  11588. node.arguments = args;
  11589. } else {
  11590. node.arguments = [];
  11591. }
  11592. return this.finishNode(node, "NewExpression");
  11593. }
  11594. parseNewCallee(node) {
  11595. node.callee = this.parseNoCallExpr();
  11596. if (node.callee.type === "Import") {
  11597. this.raise(Errors.ImportCallNotNewExpression, {
  11598. at: node.callee
  11599. });
  11600. }
  11601. }
  11602. parseTemplateElement(isTagged) {
  11603. const {
  11604. start,
  11605. startLoc,
  11606. end,
  11607. value
  11608. } = this.state;
  11609. const elemStart = start + 1;
  11610. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11611. if (value === null) {
  11612. if (!isTagged) {
  11613. this.raise(Errors.InvalidEscapeSequenceTemplate, {
  11614. at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)
  11615. });
  11616. }
  11617. }
  11618. const isTail = this.match(24);
  11619. const endOffset = isTail ? -1 : -2;
  11620. const elemEnd = end + endOffset;
  11621. elem.value = {
  11622. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11623. cooked: value === null ? null : value.slice(1, endOffset)
  11624. };
  11625. elem.tail = isTail;
  11626. this.next();
  11627. const finishedNode = this.finishNode(elem, "TemplateElement");
  11628. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11629. return finishedNode;
  11630. }
  11631. parseTemplate(isTagged) {
  11632. const node = this.startNode();
  11633. node.expressions = [];
  11634. let curElt = this.parseTemplateElement(isTagged);
  11635. node.quasis = [curElt];
  11636. while (!curElt.tail) {
  11637. node.expressions.push(this.parseTemplateSubstitution());
  11638. this.readTemplateContinuation();
  11639. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  11640. }
  11641. return this.finishNode(node, "TemplateLiteral");
  11642. }
  11643. parseTemplateSubstitution() {
  11644. return this.parseExpression();
  11645. }
  11646. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11647. if (isRecord) {
  11648. this.expectPlugin("recordAndTuple");
  11649. }
  11650. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11651. this.state.inFSharpPipelineDirectBody = false;
  11652. const propHash = Object.create(null);
  11653. let first = true;
  11654. const node = this.startNode();
  11655. node.properties = [];
  11656. this.next();
  11657. while (!this.match(close)) {
  11658. if (first) {
  11659. first = false;
  11660. } else {
  11661. this.expect(12);
  11662. if (this.match(close)) {
  11663. this.addTrailingCommaExtraToNode(node);
  11664. break;
  11665. }
  11666. }
  11667. let prop;
  11668. if (isPattern) {
  11669. prop = this.parseBindingProperty();
  11670. } else {
  11671. prop = this.parsePropertyDefinition(refExpressionErrors);
  11672. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11673. }
  11674. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11675. this.raise(Errors.InvalidRecordProperty, {
  11676. at: prop
  11677. });
  11678. }
  11679. if (prop.shorthand) {
  11680. this.addExtra(prop, "shorthand", true);
  11681. }
  11682. node.properties.push(prop);
  11683. }
  11684. this.next();
  11685. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11686. let type = "ObjectExpression";
  11687. if (isPattern) {
  11688. type = "ObjectPattern";
  11689. } else if (isRecord) {
  11690. type = "RecordExpression";
  11691. }
  11692. return this.finishNode(node, type);
  11693. }
  11694. addTrailingCommaExtraToNode(node) {
  11695. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  11696. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11697. }
  11698. maybeAsyncOrAccessorProp(prop) {
  11699. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11700. }
  11701. parsePropertyDefinition(refExpressionErrors) {
  11702. let decorators = [];
  11703. if (this.match(26)) {
  11704. if (this.hasPlugin("decorators")) {
  11705. this.raise(Errors.UnsupportedPropertyDecorator, {
  11706. at: this.state.startLoc
  11707. });
  11708. }
  11709. while (this.match(26)) {
  11710. decorators.push(this.parseDecorator());
  11711. }
  11712. }
  11713. const prop = this.startNode();
  11714. let isAsync = false;
  11715. let isAccessor = false;
  11716. let startLoc;
  11717. if (this.match(21)) {
  11718. if (decorators.length) this.unexpected();
  11719. return this.parseSpread();
  11720. }
  11721. if (decorators.length) {
  11722. prop.decorators = decorators;
  11723. decorators = [];
  11724. }
  11725. prop.method = false;
  11726. if (refExpressionErrors) {
  11727. startLoc = this.state.startLoc;
  11728. }
  11729. let isGenerator = this.eat(55);
  11730. this.parsePropertyNamePrefixOperator(prop);
  11731. const containsEsc = this.state.containsEsc;
  11732. const key = this.parsePropertyName(prop, refExpressionErrors);
  11733. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11734. const keyName = key.name;
  11735. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11736. isAsync = true;
  11737. this.resetPreviousNodeTrailingComments(key);
  11738. isGenerator = this.eat(55);
  11739. this.parsePropertyName(prop);
  11740. }
  11741. if (keyName === "get" || keyName === "set") {
  11742. isAccessor = true;
  11743. this.resetPreviousNodeTrailingComments(key);
  11744. prop.kind = keyName;
  11745. if (this.match(55)) {
  11746. isGenerator = true;
  11747. this.raise(Errors.AccessorIsGenerator, {
  11748. at: this.state.curPosition(),
  11749. kind: keyName
  11750. });
  11751. this.next();
  11752. }
  11753. this.parsePropertyName(prop);
  11754. }
  11755. }
  11756. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11757. }
  11758. getGetterSetterExpectedParamCount(method) {
  11759. return method.kind === "get" ? 0 : 1;
  11760. }
  11761. getObjectOrClassMethodParams(method) {
  11762. return method.params;
  11763. }
  11764. checkGetterSetterParams(method) {
  11765. var _params;
  11766. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11767. const params = this.getObjectOrClassMethodParams(method);
  11768. if (params.length !== paramCount) {
  11769. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  11770. at: method
  11771. });
  11772. }
  11773. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11774. this.raise(Errors.BadSetterRestParameter, {
  11775. at: method
  11776. });
  11777. }
  11778. }
  11779. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11780. if (isAccessor) {
  11781. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11782. this.checkGetterSetterParams(finishedProp);
  11783. return finishedProp;
  11784. }
  11785. if (isAsync || isGenerator || this.match(10)) {
  11786. if (isPattern) this.unexpected();
  11787. prop.kind = "method";
  11788. prop.method = true;
  11789. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11790. }
  11791. }
  11792. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11793. prop.shorthand = false;
  11794. if (this.eat(14)) {
  11795. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11796. return this.finishNode(prop, "ObjectProperty");
  11797. }
  11798. if (!prop.computed && prop.key.type === "Identifier") {
  11799. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11800. if (isPattern) {
  11801. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11802. } else if (this.match(29)) {
  11803. const shorthandAssignLoc = this.state.startLoc;
  11804. if (refExpressionErrors != null) {
  11805. if (refExpressionErrors.shorthandAssignLoc === null) {
  11806. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11807. }
  11808. } else {
  11809. this.raise(Errors.InvalidCoverInitializedName, {
  11810. at: shorthandAssignLoc
  11811. });
  11812. }
  11813. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11814. } else {
  11815. prop.value = cloneIdentifier(prop.key);
  11816. }
  11817. prop.shorthand = true;
  11818. return this.finishNode(prop, "ObjectProperty");
  11819. }
  11820. }
  11821. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11822. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11823. if (!node) this.unexpected();
  11824. return node;
  11825. }
  11826. parsePropertyName(prop, refExpressionErrors) {
  11827. if (this.eat(0)) {
  11828. prop.computed = true;
  11829. prop.key = this.parseMaybeAssignAllowIn();
  11830. this.expect(3);
  11831. } else {
  11832. const {
  11833. type,
  11834. value
  11835. } = this.state;
  11836. let key;
  11837. if (tokenIsKeywordOrIdentifier(type)) {
  11838. key = this.parseIdentifier(true);
  11839. } else {
  11840. switch (type) {
  11841. case 132:
  11842. key = this.parseNumericLiteral(value);
  11843. break;
  11844. case 131:
  11845. key = this.parseStringLiteral(value);
  11846. break;
  11847. case 133:
  11848. key = this.parseBigIntLiteral(value);
  11849. break;
  11850. case 134:
  11851. key = this.parseDecimalLiteral(value);
  11852. break;
  11853. case 136:
  11854. {
  11855. const privateKeyLoc = this.state.startLoc;
  11856. if (refExpressionErrors != null) {
  11857. if (refExpressionErrors.privateKeyLoc === null) {
  11858. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11859. }
  11860. } else {
  11861. this.raise(Errors.UnexpectedPrivateField, {
  11862. at: privateKeyLoc
  11863. });
  11864. }
  11865. key = this.parsePrivateName();
  11866. break;
  11867. }
  11868. default:
  11869. this.unexpected();
  11870. }
  11871. }
  11872. prop.key = key;
  11873. if (type !== 136) {
  11874. prop.computed = false;
  11875. }
  11876. }
  11877. return prop.key;
  11878. }
  11879. initFunction(node, isAsync) {
  11880. node.id = null;
  11881. node.generator = false;
  11882. node.async = isAsync;
  11883. }
  11884. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11885. this.initFunction(node, isAsync);
  11886. node.generator = isGenerator;
  11887. this.scope.enter(SCOPE_FUNCTION | SCOPE_SUPER | (inClassScope ? SCOPE_CLASS : 0) | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  11888. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11889. this.parseFunctionParams(node, isConstructor);
  11890. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11891. this.prodParam.exit();
  11892. this.scope.exit();
  11893. return finishedNode;
  11894. }
  11895. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11896. if (isTuple) {
  11897. this.expectPlugin("recordAndTuple");
  11898. }
  11899. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11900. this.state.inFSharpPipelineDirectBody = false;
  11901. const node = this.startNode();
  11902. this.next();
  11903. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11904. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11905. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11906. }
  11907. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11908. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  11909. let flags = functionFlags(isAsync, false);
  11910. if (!this.match(5) && this.prodParam.hasIn) {
  11911. flags |= PARAM_IN;
  11912. }
  11913. this.prodParam.enter(flags);
  11914. this.initFunction(node, isAsync);
  11915. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11916. if (params) {
  11917. this.state.maybeInArrowParameters = true;
  11918. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11919. }
  11920. this.state.maybeInArrowParameters = false;
  11921. this.parseFunctionBody(node, true);
  11922. this.prodParam.exit();
  11923. this.scope.exit();
  11924. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11925. return this.finishNode(node, "ArrowFunctionExpression");
  11926. }
  11927. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11928. this.toAssignableList(params, trailingCommaLoc, false);
  11929. node.params = params;
  11930. }
  11931. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11932. this.parseFunctionBody(node, false, isMethod);
  11933. return this.finishNode(node, type);
  11934. }
  11935. parseFunctionBody(node, allowExpression, isMethod = false) {
  11936. const isExpression = allowExpression && !this.match(5);
  11937. this.expressionScope.enter(newExpressionScope());
  11938. if (isExpression) {
  11939. node.body = this.parseMaybeAssign();
  11940. this.checkParams(node, false, allowExpression, false);
  11941. } else {
  11942. const oldStrict = this.state.strict;
  11943. const oldLabels = this.state.labels;
  11944. this.state.labels = [];
  11945. this.prodParam.enter(this.prodParam.currentFlags() | PARAM_RETURN);
  11946. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11947. const nonSimple = !this.isSimpleParamList(node.params);
  11948. if (hasStrictModeDirective && nonSimple) {
  11949. this.raise(Errors.IllegalLanguageModeDirective, {
  11950. at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node
  11951. });
  11952. }
  11953. const strictModeChanged = !oldStrict && this.state.strict;
  11954. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11955. if (this.state.strict && node.id) {
  11956. this.checkIdentifier(node.id, BIND_OUTSIDE, strictModeChanged);
  11957. }
  11958. });
  11959. this.prodParam.exit();
  11960. this.state.labels = oldLabels;
  11961. }
  11962. this.expressionScope.exit();
  11963. }
  11964. isSimpleParameter(node) {
  11965. return node.type === "Identifier";
  11966. }
  11967. isSimpleParamList(params) {
  11968. for (let i = 0, len = params.length; i < len; i++) {
  11969. if (!this.isSimpleParameter(params[i])) return false;
  11970. }
  11971. return true;
  11972. }
  11973. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11974. const checkClashes = !allowDuplicates && new Set();
  11975. const formalParameters = {
  11976. type: "FormalParameters"
  11977. };
  11978. for (const param of node.params) {
  11979. this.checkLVal(param, {
  11980. in: formalParameters,
  11981. binding: BIND_VAR,
  11982. checkClashes,
  11983. strictModeChanged
  11984. });
  11985. }
  11986. }
  11987. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11988. const elts = [];
  11989. let first = true;
  11990. while (!this.eat(close)) {
  11991. if (first) {
  11992. first = false;
  11993. } else {
  11994. this.expect(12);
  11995. if (this.match(close)) {
  11996. if (nodeForExtra) {
  11997. this.addTrailingCommaExtraToNode(nodeForExtra);
  11998. }
  11999. this.next();
  12000. break;
  12001. }
  12002. }
  12003. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  12004. }
  12005. return elts;
  12006. }
  12007. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  12008. let elt;
  12009. if (this.match(12)) {
  12010. if (!allowEmpty) {
  12011. this.raise(Errors.UnexpectedToken, {
  12012. at: this.state.curPosition(),
  12013. unexpected: ","
  12014. });
  12015. }
  12016. elt = null;
  12017. } else if (this.match(21)) {
  12018. const spreadNodeStartLoc = this.state.startLoc;
  12019. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12020. } else if (this.match(17)) {
  12021. this.expectPlugin("partialApplication");
  12022. if (!allowPlaceholder) {
  12023. this.raise(Errors.UnexpectedArgumentPlaceholder, {
  12024. at: this.state.startLoc
  12025. });
  12026. }
  12027. const node = this.startNode();
  12028. this.next();
  12029. elt = this.finishNode(node, "ArgumentPlaceholder");
  12030. } else {
  12031. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  12032. }
  12033. return elt;
  12034. }
  12035. parseIdentifier(liberal) {
  12036. const node = this.startNode();
  12037. const name = this.parseIdentifierName(liberal);
  12038. return this.createIdentifier(node, name);
  12039. }
  12040. createIdentifier(node, name) {
  12041. node.name = name;
  12042. node.loc.identifierName = name;
  12043. return this.finishNode(node, "Identifier");
  12044. }
  12045. parseIdentifierName(liberal) {
  12046. let name;
  12047. const {
  12048. startLoc,
  12049. type
  12050. } = this.state;
  12051. if (tokenIsKeywordOrIdentifier(type)) {
  12052. name = this.state.value;
  12053. } else {
  12054. this.unexpected();
  12055. }
  12056. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12057. if (liberal) {
  12058. if (tokenIsKeyword) {
  12059. this.replaceToken(130);
  12060. }
  12061. } else {
  12062. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12063. }
  12064. this.next();
  12065. return name;
  12066. }
  12067. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12068. if (word.length > 10) {
  12069. return;
  12070. }
  12071. if (!canBeReservedWord(word)) {
  12072. return;
  12073. }
  12074. if (checkKeywords && isKeyword(word)) {
  12075. this.raise(Errors.UnexpectedKeyword, {
  12076. at: startLoc,
  12077. keyword: word
  12078. });
  12079. return;
  12080. }
  12081. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12082. if (reservedTest(word, this.inModule)) {
  12083. this.raise(Errors.UnexpectedReservedWord, {
  12084. at: startLoc,
  12085. reservedWord: word
  12086. });
  12087. return;
  12088. } else if (word === "yield") {
  12089. if (this.prodParam.hasYield) {
  12090. this.raise(Errors.YieldBindingIdentifier, {
  12091. at: startLoc
  12092. });
  12093. return;
  12094. }
  12095. } else if (word === "await") {
  12096. if (this.prodParam.hasAwait) {
  12097. this.raise(Errors.AwaitBindingIdentifier, {
  12098. at: startLoc
  12099. });
  12100. return;
  12101. }
  12102. if (this.scope.inStaticBlock) {
  12103. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
  12104. at: startLoc
  12105. });
  12106. return;
  12107. }
  12108. this.expressionScope.recordAsyncArrowParametersError({
  12109. at: startLoc
  12110. });
  12111. } else if (word === "arguments") {
  12112. if (this.scope.inClassAndNotInNonArrowFunction) {
  12113. this.raise(Errors.ArgumentsInClass, {
  12114. at: startLoc
  12115. });
  12116. return;
  12117. }
  12118. }
  12119. }
  12120. isAwaitAllowed() {
  12121. if (this.prodParam.hasAwait) return true;
  12122. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  12123. return true;
  12124. }
  12125. return false;
  12126. }
  12127. parseAwait(startLoc) {
  12128. const node = this.startNodeAt(startLoc);
  12129. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
  12130. at: node
  12131. });
  12132. if (this.eat(55)) {
  12133. this.raise(Errors.ObsoleteAwaitStar, {
  12134. at: node
  12135. });
  12136. }
  12137. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  12138. if (this.isAmbiguousAwait()) {
  12139. this.ambiguousScriptDifferentAst = true;
  12140. } else {
  12141. this.sawUnambiguousESM = true;
  12142. }
  12143. }
  12144. if (!this.state.soloAwait) {
  12145. node.argument = this.parseMaybeUnary(null, true);
  12146. }
  12147. return this.finishNode(node, "AwaitExpression");
  12148. }
  12149. isAmbiguousAwait() {
  12150. if (this.hasPrecedingLineBreak()) return true;
  12151. const {
  12152. type
  12153. } = this.state;
  12154. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 101 && !this.state.containsEsc || type === 135 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12155. }
  12156. parseYield() {
  12157. const node = this.startNode();
  12158. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
  12159. at: node
  12160. });
  12161. this.next();
  12162. let delegating = false;
  12163. let argument = null;
  12164. if (!this.hasPrecedingLineBreak()) {
  12165. delegating = this.eat(55);
  12166. switch (this.state.type) {
  12167. case 13:
  12168. case 137:
  12169. case 8:
  12170. case 11:
  12171. case 3:
  12172. case 9:
  12173. case 14:
  12174. case 12:
  12175. if (!delegating) break;
  12176. default:
  12177. argument = this.parseMaybeAssign();
  12178. }
  12179. }
  12180. node.delegate = delegating;
  12181. node.argument = argument;
  12182. return this.finishNode(node, "YieldExpression");
  12183. }
  12184. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12185. if (this.hasPlugin(["pipelineOperator", {
  12186. proposal: "smart"
  12187. }])) {
  12188. if (left.type === "SequenceExpression") {
  12189. this.raise(Errors.PipelineHeadSequenceExpression, {
  12190. at: leftStartLoc
  12191. });
  12192. }
  12193. }
  12194. }
  12195. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12196. if (this.isSimpleReference(childExpr)) {
  12197. const bodyNode = this.startNodeAt(startLoc);
  12198. bodyNode.callee = childExpr;
  12199. return this.finishNode(bodyNode, "PipelineBareFunction");
  12200. } else {
  12201. const bodyNode = this.startNodeAt(startLoc);
  12202. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12203. bodyNode.expression = childExpr;
  12204. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12205. }
  12206. }
  12207. isSimpleReference(expression) {
  12208. switch (expression.type) {
  12209. case "MemberExpression":
  12210. return !expression.computed && this.isSimpleReference(expression.object);
  12211. case "Identifier":
  12212. return true;
  12213. default:
  12214. return false;
  12215. }
  12216. }
  12217. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12218. if (this.match(19)) {
  12219. throw this.raise(Errors.PipelineBodyNoArrow, {
  12220. at: this.state.startLoc
  12221. });
  12222. }
  12223. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12224. this.raise(Errors.PipelineTopicUnused, {
  12225. at: startLoc
  12226. });
  12227. }
  12228. }
  12229. withTopicBindingContext(callback) {
  12230. const outerContextTopicState = this.state.topicContext;
  12231. this.state.topicContext = {
  12232. maxNumOfResolvableTopics: 1,
  12233. maxTopicIndex: null
  12234. };
  12235. try {
  12236. return callback();
  12237. } finally {
  12238. this.state.topicContext = outerContextTopicState;
  12239. }
  12240. }
  12241. withSmartMixTopicForbiddingContext(callback) {
  12242. if (this.hasPlugin(["pipelineOperator", {
  12243. proposal: "smart"
  12244. }])) {
  12245. const outerContextTopicState = this.state.topicContext;
  12246. this.state.topicContext = {
  12247. maxNumOfResolvableTopics: 0,
  12248. maxTopicIndex: null
  12249. };
  12250. try {
  12251. return callback();
  12252. } finally {
  12253. this.state.topicContext = outerContextTopicState;
  12254. }
  12255. } else {
  12256. return callback();
  12257. }
  12258. }
  12259. withSoloAwaitPermittingContext(callback) {
  12260. const outerContextSoloAwaitState = this.state.soloAwait;
  12261. this.state.soloAwait = true;
  12262. try {
  12263. return callback();
  12264. } finally {
  12265. this.state.soloAwait = outerContextSoloAwaitState;
  12266. }
  12267. }
  12268. allowInAnd(callback) {
  12269. const flags = this.prodParam.currentFlags();
  12270. const prodParamToSet = PARAM_IN & ~flags;
  12271. if (prodParamToSet) {
  12272. this.prodParam.enter(flags | PARAM_IN);
  12273. try {
  12274. return callback();
  12275. } finally {
  12276. this.prodParam.exit();
  12277. }
  12278. }
  12279. return callback();
  12280. }
  12281. disallowInAnd(callback) {
  12282. const flags = this.prodParam.currentFlags();
  12283. const prodParamToClear = PARAM_IN & flags;
  12284. if (prodParamToClear) {
  12285. this.prodParam.enter(flags & ~PARAM_IN);
  12286. try {
  12287. return callback();
  12288. } finally {
  12289. this.prodParam.exit();
  12290. }
  12291. }
  12292. return callback();
  12293. }
  12294. registerTopicReference() {
  12295. this.state.topicContext.maxTopicIndex = 0;
  12296. }
  12297. topicReferenceIsAllowedInCurrentContext() {
  12298. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12299. }
  12300. topicReferenceWasUsedInCurrentContext() {
  12301. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12302. }
  12303. parseFSharpPipelineBody(prec) {
  12304. const startLoc = this.state.startLoc;
  12305. this.state.potentialArrowAt = this.state.start;
  12306. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12307. this.state.inFSharpPipelineDirectBody = true;
  12308. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12309. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12310. return ret;
  12311. }
  12312. parseModuleExpression() {
  12313. this.expectPlugin("moduleBlocks");
  12314. const node = this.startNode();
  12315. this.next();
  12316. if (!this.match(5)) {
  12317. this.unexpected(null, 5);
  12318. }
  12319. const program = this.startNodeAt(this.state.endLoc);
  12320. this.next();
  12321. const revertScopes = this.initializeScopes(true);
  12322. this.enterInitialScopes();
  12323. try {
  12324. node.body = this.parseProgram(program, 8, "module");
  12325. } finally {
  12326. revertScopes();
  12327. }
  12328. return this.finishNode(node, "ModuleExpression");
  12329. }
  12330. parsePropertyNamePrefixOperator(prop) {}
  12331. }
  12332. const loopLabel = {
  12333. kind: "loop"
  12334. },
  12335. switchLabel = {
  12336. kind: "switch"
  12337. };
  12338. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12339. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12340. function babel7CompatTokens(tokens, input) {
  12341. for (let i = 0; i < tokens.length; i++) {
  12342. const token = tokens[i];
  12343. const {
  12344. type
  12345. } = token;
  12346. if (typeof type === "number") {
  12347. {
  12348. if (type === 136) {
  12349. const {
  12350. loc,
  12351. start,
  12352. value,
  12353. end
  12354. } = token;
  12355. const hashEndPos = start + 1;
  12356. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12357. tokens.splice(i, 1, new Token({
  12358. type: getExportedToken(27),
  12359. value: "#",
  12360. start: start,
  12361. end: hashEndPos,
  12362. startLoc: loc.start,
  12363. endLoc: hashEndLoc
  12364. }), new Token({
  12365. type: getExportedToken(130),
  12366. value: value,
  12367. start: hashEndPos,
  12368. end: end,
  12369. startLoc: hashEndLoc,
  12370. endLoc: loc.end
  12371. }));
  12372. i++;
  12373. continue;
  12374. }
  12375. if (tokenIsTemplate(type)) {
  12376. const {
  12377. loc,
  12378. start,
  12379. value,
  12380. end
  12381. } = token;
  12382. const backquoteEnd = start + 1;
  12383. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12384. let startToken;
  12385. if (input.charCodeAt(start) === 96) {
  12386. startToken = new Token({
  12387. type: getExportedToken(22),
  12388. value: "`",
  12389. start: start,
  12390. end: backquoteEnd,
  12391. startLoc: loc.start,
  12392. endLoc: backquoteEndLoc
  12393. });
  12394. } else {
  12395. startToken = new Token({
  12396. type: getExportedToken(8),
  12397. value: "}",
  12398. start: start,
  12399. end: backquoteEnd,
  12400. startLoc: loc.start,
  12401. endLoc: backquoteEndLoc
  12402. });
  12403. }
  12404. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12405. if (type === 24) {
  12406. templateElementEnd = end - 1;
  12407. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12408. templateValue = value === null ? null : value.slice(1, -1);
  12409. endToken = new Token({
  12410. type: getExportedToken(22),
  12411. value: "`",
  12412. start: templateElementEnd,
  12413. end: end,
  12414. startLoc: templateElementEndLoc,
  12415. endLoc: loc.end
  12416. });
  12417. } else {
  12418. templateElementEnd = end - 2;
  12419. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12420. templateValue = value === null ? null : value.slice(1, -2);
  12421. endToken = new Token({
  12422. type: getExportedToken(23),
  12423. value: "${",
  12424. start: templateElementEnd,
  12425. end: end,
  12426. startLoc: templateElementEndLoc,
  12427. endLoc: loc.end
  12428. });
  12429. }
  12430. tokens.splice(i, 1, startToken, new Token({
  12431. type: getExportedToken(20),
  12432. value: templateValue,
  12433. start: backquoteEnd,
  12434. end: templateElementEnd,
  12435. startLoc: backquoteEndLoc,
  12436. endLoc: templateElementEndLoc
  12437. }), endToken);
  12438. i += 2;
  12439. continue;
  12440. }
  12441. }
  12442. token.type = getExportedToken(type);
  12443. }
  12444. }
  12445. return tokens;
  12446. }
  12447. class StatementParser extends ExpressionParser {
  12448. parseTopLevel(file, program) {
  12449. file.program = this.parseProgram(program);
  12450. file.comments = this.state.comments;
  12451. if (this.options.tokens) {
  12452. file.tokens = babel7CompatTokens(this.tokens, this.input);
  12453. }
  12454. return this.finishNode(file, "File");
  12455. }
  12456. parseProgram(program, end = 137, sourceType = this.options.sourceType) {
  12457. program.sourceType = sourceType;
  12458. program.interpreter = this.parseInterpreterDirective();
  12459. this.parseBlockBody(program, true, true, end);
  12460. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  12461. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12462. this.raise(Errors.ModuleExportUndefined, {
  12463. at,
  12464. localName
  12465. });
  12466. }
  12467. }
  12468. let finishedProgram;
  12469. if (end === 137) {
  12470. finishedProgram = this.finishNode(program, "Program");
  12471. } else {
  12472. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12473. }
  12474. return finishedProgram;
  12475. }
  12476. stmtToDirective(stmt) {
  12477. const directive = stmt;
  12478. directive.type = "Directive";
  12479. directive.value = directive.expression;
  12480. delete directive.expression;
  12481. const directiveLiteral = directive.value;
  12482. const expressionValue = directiveLiteral.value;
  12483. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  12484. const val = directiveLiteral.value = raw.slice(1, -1);
  12485. this.addExtra(directiveLiteral, "raw", raw);
  12486. this.addExtra(directiveLiteral, "rawValue", val);
  12487. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12488. directiveLiteral.type = "DirectiveLiteral";
  12489. return directive;
  12490. }
  12491. parseInterpreterDirective() {
  12492. if (!this.match(28)) {
  12493. return null;
  12494. }
  12495. const node = this.startNode();
  12496. node.value = this.state.value;
  12497. this.next();
  12498. return this.finishNode(node, "InterpreterDirective");
  12499. }
  12500. isLet() {
  12501. if (!this.isContextual(99)) {
  12502. return false;
  12503. }
  12504. return this.hasFollowingBindingAtom();
  12505. }
  12506. chStartsBindingIdentifier(ch, pos) {
  12507. if (isIdentifierStart(ch)) {
  12508. keywordRelationalOperator.lastIndex = pos;
  12509. if (keywordRelationalOperator.test(this.input)) {
  12510. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12511. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12512. return false;
  12513. }
  12514. }
  12515. return true;
  12516. } else if (ch === 92) {
  12517. return true;
  12518. } else {
  12519. return false;
  12520. }
  12521. }
  12522. chStartsBindingPattern(ch) {
  12523. return ch === 91 || ch === 123;
  12524. }
  12525. hasFollowingBindingAtom() {
  12526. const next = this.nextTokenStart();
  12527. const nextCh = this.codePointAtPos(next);
  12528. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12529. }
  12530. hasInLineFollowingBindingIdentifier() {
  12531. const next = this.nextTokenInLineStart();
  12532. const nextCh = this.codePointAtPos(next);
  12533. return this.chStartsBindingIdentifier(nextCh, next);
  12534. }
  12535. startsUsingForOf() {
  12536. const {
  12537. type,
  12538. containsEsc
  12539. } = this.lookahead();
  12540. if (type === 101 && !containsEsc) {
  12541. return false;
  12542. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12543. this.expectPlugin("explicitResourceManagement");
  12544. return true;
  12545. }
  12546. }
  12547. startsAwaitUsing() {
  12548. let next = this.nextTokenInLineStart();
  12549. if (this.isUnparsedContextual(next, "using")) {
  12550. next = this.nextTokenInLineStartSince(next + 5);
  12551. const nextCh = this.codePointAtPos(next);
  12552. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12553. this.expectPlugin("explicitResourceManagement");
  12554. return true;
  12555. }
  12556. }
  12557. return false;
  12558. }
  12559. parseModuleItem() {
  12560. return this.parseStatementLike(1 | 2 | 4 | 8);
  12561. }
  12562. parseStatementListItem() {
  12563. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12564. }
  12565. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12566. let flags = 0;
  12567. if (this.options.annexB && !this.state.strict) {
  12568. flags |= 4;
  12569. if (allowLabeledFunction) {
  12570. flags |= 8;
  12571. }
  12572. }
  12573. return this.parseStatementLike(flags);
  12574. }
  12575. parseStatement() {
  12576. return this.parseStatementLike(0);
  12577. }
  12578. parseStatementLike(flags) {
  12579. let decorators = null;
  12580. if (this.match(26)) {
  12581. decorators = this.parseDecorators(true);
  12582. }
  12583. return this.parseStatementContent(flags, decorators);
  12584. }
  12585. parseStatementContent(flags, decorators) {
  12586. const starttype = this.state.type;
  12587. const node = this.startNode();
  12588. const allowDeclaration = !!(flags & 2);
  12589. const allowFunctionDeclaration = !!(flags & 4);
  12590. const topLevel = flags & 1;
  12591. switch (starttype) {
  12592. case 60:
  12593. return this.parseBreakContinueStatement(node, true);
  12594. case 63:
  12595. return this.parseBreakContinueStatement(node, false);
  12596. case 64:
  12597. return this.parseDebuggerStatement(node);
  12598. case 90:
  12599. return this.parseDoWhileStatement(node);
  12600. case 91:
  12601. return this.parseForStatement(node);
  12602. case 68:
  12603. if (this.lookaheadCharCode() === 46) break;
  12604. if (!allowFunctionDeclaration) {
  12605. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, {
  12606. at: this.state.startLoc
  12607. });
  12608. }
  12609. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12610. case 80:
  12611. if (!allowDeclaration) this.unexpected();
  12612. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12613. case 69:
  12614. return this.parseIfStatement(node);
  12615. case 70:
  12616. return this.parseReturnStatement(node);
  12617. case 71:
  12618. return this.parseSwitchStatement(node);
  12619. case 72:
  12620. return this.parseThrowStatement(node);
  12621. case 73:
  12622. return this.parseTryStatement(node);
  12623. case 96:
  12624. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  12625. if (!this.isAwaitAllowed()) {
  12626. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  12627. at: node
  12628. });
  12629. } else if (!allowDeclaration) {
  12630. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12631. at: node
  12632. });
  12633. }
  12634. this.next();
  12635. return this.parseVarStatement(node, "await using");
  12636. }
  12637. break;
  12638. case 105:
  12639. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifier()) {
  12640. break;
  12641. }
  12642. this.expectPlugin("explicitResourceManagement");
  12643. if (!this.scope.inModule && this.scope.inTopLevel) {
  12644. this.raise(Errors.UnexpectedUsingDeclaration, {
  12645. at: this.state.startLoc
  12646. });
  12647. } else if (!allowDeclaration) {
  12648. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12649. at: this.state.startLoc
  12650. });
  12651. }
  12652. return this.parseVarStatement(node, "using");
  12653. case 99:
  12654. {
  12655. if (this.state.containsEsc) {
  12656. break;
  12657. }
  12658. const next = this.nextTokenStart();
  12659. const nextCh = this.codePointAtPos(next);
  12660. if (nextCh !== 91) {
  12661. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12662. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12663. break;
  12664. }
  12665. }
  12666. }
  12667. case 75:
  12668. {
  12669. if (!allowDeclaration) {
  12670. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12671. at: this.state.startLoc
  12672. });
  12673. }
  12674. }
  12675. case 74:
  12676. {
  12677. const kind = this.state.value;
  12678. return this.parseVarStatement(node, kind);
  12679. }
  12680. case 92:
  12681. return this.parseWhileStatement(node);
  12682. case 76:
  12683. return this.parseWithStatement(node);
  12684. case 5:
  12685. return this.parseBlock();
  12686. case 13:
  12687. return this.parseEmptyStatement(node);
  12688. case 83:
  12689. {
  12690. const nextTokenCharCode = this.lookaheadCharCode();
  12691. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12692. break;
  12693. }
  12694. }
  12695. case 82:
  12696. {
  12697. if (!this.options.allowImportExportEverywhere && !topLevel) {
  12698. this.raise(Errors.UnexpectedImportExport, {
  12699. at: this.state.startLoc
  12700. });
  12701. }
  12702. this.next();
  12703. let result;
  12704. if (starttype === 83) {
  12705. result = this.parseImport(node);
  12706. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12707. this.sawUnambiguousESM = true;
  12708. }
  12709. } else {
  12710. result = this.parseExport(node, decorators);
  12711. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12712. this.sawUnambiguousESM = true;
  12713. }
  12714. }
  12715. this.assertModuleNodeAllowed(result);
  12716. return result;
  12717. }
  12718. default:
  12719. {
  12720. if (this.isAsyncFunction()) {
  12721. if (!allowDeclaration) {
  12722. this.raise(Errors.AsyncFunctionInSingleStatementContext, {
  12723. at: this.state.startLoc
  12724. });
  12725. }
  12726. this.next();
  12727. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12728. }
  12729. }
  12730. }
  12731. const maybeName = this.state.value;
  12732. const expr = this.parseExpression();
  12733. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  12734. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12735. } else {
  12736. return this.parseExpressionStatement(node, expr, decorators);
  12737. }
  12738. }
  12739. assertModuleNodeAllowed(node) {
  12740. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  12741. this.raise(Errors.ImportOutsideModule, {
  12742. at: node
  12743. });
  12744. }
  12745. }
  12746. decoratorsEnabledBeforeExport() {
  12747. if (this.hasPlugin("decorators-legacy")) return true;
  12748. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12749. }
  12750. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12751. if (maybeDecorators) {
  12752. if (classNode.decorators && classNode.decorators.length > 0) {
  12753. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12754. this.raise(Errors.DecoratorsBeforeAfterExport, {
  12755. at: classNode.decorators[0]
  12756. });
  12757. }
  12758. classNode.decorators.unshift(...maybeDecorators);
  12759. } else {
  12760. classNode.decorators = maybeDecorators;
  12761. }
  12762. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12763. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12764. }
  12765. return classNode;
  12766. }
  12767. canHaveLeadingDecorator() {
  12768. return this.match(80);
  12769. }
  12770. parseDecorators(allowExport) {
  12771. const decorators = [];
  12772. do {
  12773. decorators.push(this.parseDecorator());
  12774. } while (this.match(26));
  12775. if (this.match(82)) {
  12776. if (!allowExport) {
  12777. this.unexpected();
  12778. }
  12779. if (!this.decoratorsEnabledBeforeExport()) {
  12780. this.raise(Errors.DecoratorExportClass, {
  12781. at: this.state.startLoc
  12782. });
  12783. }
  12784. } else if (!this.canHaveLeadingDecorator()) {
  12785. throw this.raise(Errors.UnexpectedLeadingDecorator, {
  12786. at: this.state.startLoc
  12787. });
  12788. }
  12789. return decorators;
  12790. }
  12791. parseDecorator() {
  12792. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12793. const node = this.startNode();
  12794. this.next();
  12795. if (this.hasPlugin("decorators")) {
  12796. const startLoc = this.state.startLoc;
  12797. let expr;
  12798. if (this.match(10)) {
  12799. const startLoc = this.state.startLoc;
  12800. this.next();
  12801. expr = this.parseExpression();
  12802. this.expect(11);
  12803. expr = this.wrapParenthesis(startLoc, expr);
  12804. const paramsStartLoc = this.state.startLoc;
  12805. node.expression = this.parseMaybeDecoratorArguments(expr);
  12806. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12807. this.raise(Errors.DecoratorArgumentsOutsideParentheses, {
  12808. at: paramsStartLoc
  12809. });
  12810. }
  12811. } else {
  12812. expr = this.parseIdentifier(false);
  12813. while (this.eat(16)) {
  12814. const node = this.startNodeAt(startLoc);
  12815. node.object = expr;
  12816. if (this.match(136)) {
  12817. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12818. node.property = this.parsePrivateName();
  12819. } else {
  12820. node.property = this.parseIdentifier(true);
  12821. }
  12822. node.computed = false;
  12823. expr = this.finishNode(node, "MemberExpression");
  12824. }
  12825. node.expression = this.parseMaybeDecoratorArguments(expr);
  12826. }
  12827. } else {
  12828. node.expression = this.parseExprSubscripts();
  12829. }
  12830. return this.finishNode(node, "Decorator");
  12831. }
  12832. parseMaybeDecoratorArguments(expr) {
  12833. if (this.eat(10)) {
  12834. const node = this.startNodeAtNode(expr);
  12835. node.callee = expr;
  12836. node.arguments = this.parseCallExpressionArguments(11, false);
  12837. this.toReferencedList(node.arguments);
  12838. return this.finishNode(node, "CallExpression");
  12839. }
  12840. return expr;
  12841. }
  12842. parseBreakContinueStatement(node, isBreak) {
  12843. this.next();
  12844. if (this.isLineTerminator()) {
  12845. node.label = null;
  12846. } else {
  12847. node.label = this.parseIdentifier();
  12848. this.semicolon();
  12849. }
  12850. this.verifyBreakContinue(node, isBreak);
  12851. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12852. }
  12853. verifyBreakContinue(node, isBreak) {
  12854. let i;
  12855. for (i = 0; i < this.state.labels.length; ++i) {
  12856. const lab = this.state.labels[i];
  12857. if (node.label == null || lab.name === node.label.name) {
  12858. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  12859. if (node.label && isBreak) break;
  12860. }
  12861. }
  12862. if (i === this.state.labels.length) {
  12863. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12864. this.raise(Errors.IllegalBreakContinue, {
  12865. at: node,
  12866. type
  12867. });
  12868. }
  12869. }
  12870. parseDebuggerStatement(node) {
  12871. this.next();
  12872. this.semicolon();
  12873. return this.finishNode(node, "DebuggerStatement");
  12874. }
  12875. parseHeaderExpression() {
  12876. this.expect(10);
  12877. const val = this.parseExpression();
  12878. this.expect(11);
  12879. return val;
  12880. }
  12881. parseDoWhileStatement(node) {
  12882. this.next();
  12883. this.state.labels.push(loopLabel);
  12884. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12885. this.state.labels.pop();
  12886. this.expect(92);
  12887. node.test = this.parseHeaderExpression();
  12888. this.eat(13);
  12889. return this.finishNode(node, "DoWhileStatement");
  12890. }
  12891. parseForStatement(node) {
  12892. this.next();
  12893. this.state.labels.push(loopLabel);
  12894. let awaitAt = null;
  12895. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  12896. awaitAt = this.state.lastTokStartLoc;
  12897. }
  12898. this.scope.enter(SCOPE_OTHER);
  12899. this.expect(10);
  12900. if (this.match(13)) {
  12901. if (awaitAt !== null) {
  12902. this.unexpected(awaitAt);
  12903. }
  12904. return this.parseFor(node, null);
  12905. }
  12906. const startsWithLet = this.isContextual(99);
  12907. {
  12908. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  12909. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(105) && this.startsUsingForOf();
  12910. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  12911. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12912. const initNode = this.startNode();
  12913. let kind;
  12914. if (startsWithAwaitUsing) {
  12915. kind = "await using";
  12916. if (!this.isAwaitAllowed()) {
  12917. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  12918. at: this.state.startLoc
  12919. });
  12920. }
  12921. this.next();
  12922. } else {
  12923. kind = this.state.value;
  12924. }
  12925. this.next();
  12926. this.parseVar(initNode, true, kind);
  12927. const init = this.finishNode(initNode, "VariableDeclaration");
  12928. const isForIn = this.match(58);
  12929. if (isForIn && starsWithUsingDeclaration) {
  12930. this.raise(Errors.ForInUsing, {
  12931. at: init
  12932. });
  12933. }
  12934. if ((isForIn || this.isContextual(101)) && init.declarations.length === 1) {
  12935. return this.parseForIn(node, init, awaitAt);
  12936. }
  12937. if (awaitAt !== null) {
  12938. this.unexpected(awaitAt);
  12939. }
  12940. return this.parseFor(node, init);
  12941. }
  12942. }
  12943. const startsWithAsync = this.isContextual(95);
  12944. const refExpressionErrors = new ExpressionErrors();
  12945. const init = this.parseExpression(true, refExpressionErrors);
  12946. const isForOf = this.isContextual(101);
  12947. if (isForOf) {
  12948. if (startsWithLet) {
  12949. this.raise(Errors.ForOfLet, {
  12950. at: init
  12951. });
  12952. }
  12953. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12954. this.raise(Errors.ForOfAsync, {
  12955. at: init
  12956. });
  12957. }
  12958. }
  12959. if (isForOf || this.match(58)) {
  12960. this.checkDestructuringPrivate(refExpressionErrors);
  12961. this.toAssignable(init, true);
  12962. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12963. this.checkLVal(init, {
  12964. in: {
  12965. type
  12966. }
  12967. });
  12968. return this.parseForIn(node, init, awaitAt);
  12969. } else {
  12970. this.checkExpressionErrors(refExpressionErrors, true);
  12971. }
  12972. if (awaitAt !== null) {
  12973. this.unexpected(awaitAt);
  12974. }
  12975. return this.parseFor(node, init);
  12976. }
  12977. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12978. this.next();
  12979. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  12980. }
  12981. parseIfStatement(node) {
  12982. this.next();
  12983. node.test = this.parseHeaderExpression();
  12984. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12985. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  12986. return this.finishNode(node, "IfStatement");
  12987. }
  12988. parseReturnStatement(node) {
  12989. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  12990. this.raise(Errors.IllegalReturn, {
  12991. at: this.state.startLoc
  12992. });
  12993. }
  12994. this.next();
  12995. if (this.isLineTerminator()) {
  12996. node.argument = null;
  12997. } else {
  12998. node.argument = this.parseExpression();
  12999. this.semicolon();
  13000. }
  13001. return this.finishNode(node, "ReturnStatement");
  13002. }
  13003. parseSwitchStatement(node) {
  13004. this.next();
  13005. node.discriminant = this.parseHeaderExpression();
  13006. const cases = node.cases = [];
  13007. this.expect(5);
  13008. this.state.labels.push(switchLabel);
  13009. this.scope.enter(SCOPE_OTHER);
  13010. let cur;
  13011. for (let sawDefault; !this.match(8);) {
  13012. if (this.match(61) || this.match(65)) {
  13013. const isCase = this.match(61);
  13014. if (cur) this.finishNode(cur, "SwitchCase");
  13015. cases.push(cur = this.startNode());
  13016. cur.consequent = [];
  13017. this.next();
  13018. if (isCase) {
  13019. cur.test = this.parseExpression();
  13020. } else {
  13021. if (sawDefault) {
  13022. this.raise(Errors.MultipleDefaultsInSwitch, {
  13023. at: this.state.lastTokStartLoc
  13024. });
  13025. }
  13026. sawDefault = true;
  13027. cur.test = null;
  13028. }
  13029. this.expect(14);
  13030. } else {
  13031. if (cur) {
  13032. cur.consequent.push(this.parseStatementListItem());
  13033. } else {
  13034. this.unexpected();
  13035. }
  13036. }
  13037. }
  13038. this.scope.exit();
  13039. if (cur) this.finishNode(cur, "SwitchCase");
  13040. this.next();
  13041. this.state.labels.pop();
  13042. return this.finishNode(node, "SwitchStatement");
  13043. }
  13044. parseThrowStatement(node) {
  13045. this.next();
  13046. if (this.hasPrecedingLineBreak()) {
  13047. this.raise(Errors.NewlineAfterThrow, {
  13048. at: this.state.lastTokEndLoc
  13049. });
  13050. }
  13051. node.argument = this.parseExpression();
  13052. this.semicolon();
  13053. return this.finishNode(node, "ThrowStatement");
  13054. }
  13055. parseCatchClauseParam() {
  13056. const param = this.parseBindingAtom();
  13057. this.scope.enter(this.options.annexB && param.type === "Identifier" ? SCOPE_SIMPLE_CATCH : 0);
  13058. this.checkLVal(param, {
  13059. in: {
  13060. type: "CatchClause"
  13061. },
  13062. binding: BIND_CATCH_PARAM
  13063. });
  13064. return param;
  13065. }
  13066. parseTryStatement(node) {
  13067. this.next();
  13068. node.block = this.parseBlock();
  13069. node.handler = null;
  13070. if (this.match(62)) {
  13071. const clause = this.startNode();
  13072. this.next();
  13073. if (this.match(10)) {
  13074. this.expect(10);
  13075. clause.param = this.parseCatchClauseParam();
  13076. this.expect(11);
  13077. } else {
  13078. clause.param = null;
  13079. this.scope.enter(SCOPE_OTHER);
  13080. }
  13081. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13082. this.scope.exit();
  13083. node.handler = this.finishNode(clause, "CatchClause");
  13084. }
  13085. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13086. if (!node.handler && !node.finalizer) {
  13087. this.raise(Errors.NoCatchOrFinally, {
  13088. at: node
  13089. });
  13090. }
  13091. return this.finishNode(node, "TryStatement");
  13092. }
  13093. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13094. this.next();
  13095. this.parseVar(node, false, kind, allowMissingInitializer);
  13096. this.semicolon();
  13097. return this.finishNode(node, "VariableDeclaration");
  13098. }
  13099. parseWhileStatement(node) {
  13100. this.next();
  13101. node.test = this.parseHeaderExpression();
  13102. this.state.labels.push(loopLabel);
  13103. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13104. this.state.labels.pop();
  13105. return this.finishNode(node, "WhileStatement");
  13106. }
  13107. parseWithStatement(node) {
  13108. if (this.state.strict) {
  13109. this.raise(Errors.StrictWith, {
  13110. at: this.state.startLoc
  13111. });
  13112. }
  13113. this.next();
  13114. node.object = this.parseHeaderExpression();
  13115. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13116. return this.finishNode(node, "WithStatement");
  13117. }
  13118. parseEmptyStatement(node) {
  13119. this.next();
  13120. return this.finishNode(node, "EmptyStatement");
  13121. }
  13122. parseLabeledStatement(node, maybeName, expr, flags) {
  13123. for (const label of this.state.labels) {
  13124. if (label.name === maybeName) {
  13125. this.raise(Errors.LabelRedeclaration, {
  13126. at: expr,
  13127. labelName: maybeName
  13128. });
  13129. }
  13130. }
  13131. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
  13132. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13133. const label = this.state.labels[i];
  13134. if (label.statementStart === node.start) {
  13135. label.statementStart = this.state.start;
  13136. label.kind = kind;
  13137. } else {
  13138. break;
  13139. }
  13140. }
  13141. this.state.labels.push({
  13142. name: maybeName,
  13143. kind: kind,
  13144. statementStart: this.state.start
  13145. });
  13146. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13147. this.state.labels.pop();
  13148. node.label = expr;
  13149. return this.finishNode(node, "LabeledStatement");
  13150. }
  13151. parseExpressionStatement(node, expr, decorators) {
  13152. node.expression = expr;
  13153. this.semicolon();
  13154. return this.finishNode(node, "ExpressionStatement");
  13155. }
  13156. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13157. const node = this.startNode();
  13158. if (allowDirectives) {
  13159. this.state.strictErrors.clear();
  13160. }
  13161. this.expect(5);
  13162. if (createNewLexicalScope) {
  13163. this.scope.enter(SCOPE_OTHER);
  13164. }
  13165. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13166. if (createNewLexicalScope) {
  13167. this.scope.exit();
  13168. }
  13169. return this.finishNode(node, "BlockStatement");
  13170. }
  13171. isValidDirective(stmt) {
  13172. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13173. }
  13174. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13175. const body = node.body = [];
  13176. const directives = node.directives = [];
  13177. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13178. }
  13179. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13180. const oldStrict = this.state.strict;
  13181. let hasStrictModeDirective = false;
  13182. let parsedNonDirective = false;
  13183. while (!this.match(end)) {
  13184. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13185. if (directives && !parsedNonDirective) {
  13186. if (this.isValidDirective(stmt)) {
  13187. const directive = this.stmtToDirective(stmt);
  13188. directives.push(directive);
  13189. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13190. hasStrictModeDirective = true;
  13191. this.setStrict(true);
  13192. }
  13193. continue;
  13194. }
  13195. parsedNonDirective = true;
  13196. this.state.strictErrors.clear();
  13197. }
  13198. body.push(stmt);
  13199. }
  13200. afterBlockParse == null ? void 0 : afterBlockParse.call(this, hasStrictModeDirective);
  13201. if (!oldStrict) {
  13202. this.setStrict(false);
  13203. }
  13204. this.next();
  13205. }
  13206. parseFor(node, init) {
  13207. node.init = init;
  13208. this.semicolon(false);
  13209. node.test = this.match(13) ? null : this.parseExpression();
  13210. this.semicolon(false);
  13211. node.update = this.match(11) ? null : this.parseExpression();
  13212. this.expect(11);
  13213. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13214. this.scope.exit();
  13215. this.state.labels.pop();
  13216. return this.finishNode(node, "ForStatement");
  13217. }
  13218. parseForIn(node, init, awaitAt) {
  13219. const isForIn = this.match(58);
  13220. this.next();
  13221. if (isForIn) {
  13222. if (awaitAt !== null) this.unexpected(awaitAt);
  13223. } else {
  13224. node.await = awaitAt !== null;
  13225. }
  13226. 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")) {
  13227. this.raise(Errors.ForInOfLoopInitializer, {
  13228. at: init,
  13229. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13230. });
  13231. }
  13232. if (init.type === "AssignmentPattern") {
  13233. this.raise(Errors.InvalidLhs, {
  13234. at: init,
  13235. ancestor: {
  13236. type: "ForStatement"
  13237. }
  13238. });
  13239. }
  13240. node.left = init;
  13241. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13242. this.expect(11);
  13243. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13244. this.scope.exit();
  13245. this.state.labels.pop();
  13246. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13247. }
  13248. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13249. const declarations = node.declarations = [];
  13250. node.kind = kind;
  13251. for (;;) {
  13252. const decl = this.startNode();
  13253. this.parseVarId(decl, kind);
  13254. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13255. if (decl.init === null && !allowMissingInitializer) {
  13256. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(101)))) {
  13257. this.raise(Errors.DeclarationMissingInitializer, {
  13258. at: this.state.lastTokEndLoc,
  13259. kind: "destructuring"
  13260. });
  13261. } else if (kind === "const" && !(this.match(58) || this.isContextual(101))) {
  13262. this.raise(Errors.DeclarationMissingInitializer, {
  13263. at: this.state.lastTokEndLoc,
  13264. kind: "const"
  13265. });
  13266. }
  13267. }
  13268. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13269. if (!this.eat(12)) break;
  13270. }
  13271. return node;
  13272. }
  13273. parseVarId(decl, kind) {
  13274. const id = this.parseBindingAtom();
  13275. this.checkLVal(id, {
  13276. in: {
  13277. type: "VariableDeclarator"
  13278. },
  13279. binding: kind === "var" ? BIND_VAR : BIND_LEXICAL
  13280. });
  13281. decl.id = id;
  13282. }
  13283. parseAsyncFunctionExpression(node) {
  13284. return this.parseFunction(node, 8);
  13285. }
  13286. parseFunction(node, flags = 0) {
  13287. const hangingDeclaration = flags & 2;
  13288. const isDeclaration = !!(flags & 1);
  13289. const requireId = isDeclaration && !(flags & 4);
  13290. const isAsync = !!(flags & 8);
  13291. this.initFunction(node, isAsync);
  13292. if (this.match(55)) {
  13293. if (hangingDeclaration) {
  13294. this.raise(Errors.GeneratorInSingleStatementContext, {
  13295. at: this.state.startLoc
  13296. });
  13297. }
  13298. this.next();
  13299. node.generator = true;
  13300. }
  13301. if (isDeclaration) {
  13302. node.id = this.parseFunctionId(requireId);
  13303. }
  13304. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13305. this.state.maybeInArrowParameters = false;
  13306. this.scope.enter(SCOPE_FUNCTION);
  13307. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13308. if (!isDeclaration) {
  13309. node.id = this.parseFunctionId();
  13310. }
  13311. this.parseFunctionParams(node, false);
  13312. this.withSmartMixTopicForbiddingContext(() => {
  13313. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13314. });
  13315. this.prodParam.exit();
  13316. this.scope.exit();
  13317. if (isDeclaration && !hangingDeclaration) {
  13318. this.registerFunctionStatementId(node);
  13319. }
  13320. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13321. return node;
  13322. }
  13323. parseFunctionId(requireId) {
  13324. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13325. }
  13326. parseFunctionParams(node, isConstructor) {
  13327. this.expect(10);
  13328. this.expressionScope.enter(newParameterDeclarationScope());
  13329. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13330. this.expressionScope.exit();
  13331. }
  13332. registerFunctionStatementId(node) {
  13333. if (!node.id) return;
  13334. this.scope.declareName(node.id.name, !this.options.annexB || this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION, node.id.loc.start);
  13335. }
  13336. parseClass(node, isStatement, optionalId) {
  13337. this.next();
  13338. const oldStrict = this.state.strict;
  13339. this.state.strict = true;
  13340. this.parseClassId(node, isStatement, optionalId);
  13341. this.parseClassSuper(node);
  13342. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13343. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13344. }
  13345. isClassProperty() {
  13346. return this.match(29) || this.match(13) || this.match(8);
  13347. }
  13348. isClassMethod() {
  13349. return this.match(10);
  13350. }
  13351. isNonstaticConstructor(method) {
  13352. return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
  13353. }
  13354. parseClassBody(hadSuperClass, oldStrict) {
  13355. this.classScope.enter();
  13356. const state = {
  13357. hadConstructor: false,
  13358. hadSuperClass
  13359. };
  13360. let decorators = [];
  13361. const classBody = this.startNode();
  13362. classBody.body = [];
  13363. this.expect(5);
  13364. this.withSmartMixTopicForbiddingContext(() => {
  13365. while (!this.match(8)) {
  13366. if (this.eat(13)) {
  13367. if (decorators.length > 0) {
  13368. throw this.raise(Errors.DecoratorSemicolon, {
  13369. at: this.state.lastTokEndLoc
  13370. });
  13371. }
  13372. continue;
  13373. }
  13374. if (this.match(26)) {
  13375. decorators.push(this.parseDecorator());
  13376. continue;
  13377. }
  13378. const member = this.startNode();
  13379. if (decorators.length) {
  13380. member.decorators = decorators;
  13381. this.resetStartLocationFromNode(member, decorators[0]);
  13382. decorators = [];
  13383. }
  13384. this.parseClassMember(classBody, member, state);
  13385. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13386. this.raise(Errors.DecoratorConstructor, {
  13387. at: member
  13388. });
  13389. }
  13390. }
  13391. });
  13392. this.state.strict = oldStrict;
  13393. this.next();
  13394. if (decorators.length) {
  13395. throw this.raise(Errors.TrailingDecorator, {
  13396. at: this.state.startLoc
  13397. });
  13398. }
  13399. this.classScope.exit();
  13400. return this.finishNode(classBody, "ClassBody");
  13401. }
  13402. parseClassMemberFromModifier(classBody, member) {
  13403. const key = this.parseIdentifier(true);
  13404. if (this.isClassMethod()) {
  13405. const method = member;
  13406. method.kind = "method";
  13407. method.computed = false;
  13408. method.key = key;
  13409. method.static = false;
  13410. this.pushClassMethod(classBody, method, false, false, false, false);
  13411. return true;
  13412. } else if (this.isClassProperty()) {
  13413. const prop = member;
  13414. prop.computed = false;
  13415. prop.key = key;
  13416. prop.static = false;
  13417. classBody.body.push(this.parseClassProperty(prop));
  13418. return true;
  13419. }
  13420. this.resetPreviousNodeTrailingComments(key);
  13421. return false;
  13422. }
  13423. parseClassMember(classBody, member, state) {
  13424. const isStatic = this.isContextual(104);
  13425. if (isStatic) {
  13426. if (this.parseClassMemberFromModifier(classBody, member)) {
  13427. return;
  13428. }
  13429. if (this.eat(5)) {
  13430. this.parseClassStaticBlock(classBody, member);
  13431. return;
  13432. }
  13433. }
  13434. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13435. }
  13436. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13437. const publicMethod = member;
  13438. const privateMethod = member;
  13439. const publicProp = member;
  13440. const privateProp = member;
  13441. const accessorProp = member;
  13442. const method = publicMethod;
  13443. const publicMember = publicMethod;
  13444. member.static = isStatic;
  13445. this.parsePropertyNamePrefixOperator(member);
  13446. if (this.eat(55)) {
  13447. method.kind = "method";
  13448. const isPrivateName = this.match(136);
  13449. this.parseClassElementName(method);
  13450. if (isPrivateName) {
  13451. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13452. return;
  13453. }
  13454. if (this.isNonstaticConstructor(publicMethod)) {
  13455. this.raise(Errors.ConstructorIsGenerator, {
  13456. at: publicMethod.key
  13457. });
  13458. }
  13459. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13460. return;
  13461. }
  13462. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  13463. const isPrivate = this.match(136);
  13464. const key = this.parseClassElementName(member);
  13465. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13466. this.parsePostMemberNameModifiers(publicMember);
  13467. if (this.isClassMethod()) {
  13468. method.kind = "method";
  13469. if (isPrivate) {
  13470. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13471. return;
  13472. }
  13473. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13474. let allowsDirectSuper = false;
  13475. if (isConstructor) {
  13476. publicMethod.kind = "constructor";
  13477. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13478. this.raise(Errors.DuplicateConstructor, {
  13479. at: key
  13480. });
  13481. }
  13482. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13483. this.raise(Errors.OverrideOnConstructor, {
  13484. at: key
  13485. });
  13486. }
  13487. state.hadConstructor = true;
  13488. allowsDirectSuper = state.hadSuperClass;
  13489. }
  13490. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13491. } else if (this.isClassProperty()) {
  13492. if (isPrivate) {
  13493. this.pushClassPrivateProperty(classBody, privateProp);
  13494. } else {
  13495. this.pushClassProperty(classBody, publicProp);
  13496. }
  13497. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  13498. this.resetPreviousNodeTrailingComments(key);
  13499. const isGenerator = this.eat(55);
  13500. if (publicMember.optional) {
  13501. this.unexpected(maybeQuestionTokenStartLoc);
  13502. }
  13503. method.kind = "method";
  13504. const isPrivate = this.match(136);
  13505. this.parseClassElementName(method);
  13506. this.parsePostMemberNameModifiers(publicMember);
  13507. if (isPrivate) {
  13508. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13509. } else {
  13510. if (this.isNonstaticConstructor(publicMethod)) {
  13511. this.raise(Errors.ConstructorIsAsync, {
  13512. at: publicMethod.key
  13513. });
  13514. }
  13515. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13516. }
  13517. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
  13518. this.resetPreviousNodeTrailingComments(key);
  13519. method.kind = key.name;
  13520. const isPrivate = this.match(136);
  13521. this.parseClassElementName(publicMethod);
  13522. if (isPrivate) {
  13523. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13524. } else {
  13525. if (this.isNonstaticConstructor(publicMethod)) {
  13526. this.raise(Errors.ConstructorIsAccessor, {
  13527. at: publicMethod.key
  13528. });
  13529. }
  13530. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13531. }
  13532. this.checkGetterSetterParams(publicMethod);
  13533. } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
  13534. this.expectPlugin("decoratorAutoAccessors");
  13535. this.resetPreviousNodeTrailingComments(key);
  13536. const isPrivate = this.match(136);
  13537. this.parseClassElementName(publicProp);
  13538. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13539. } else if (this.isLineTerminator()) {
  13540. if (isPrivate) {
  13541. this.pushClassPrivateProperty(classBody, privateProp);
  13542. } else {
  13543. this.pushClassProperty(classBody, publicProp);
  13544. }
  13545. } else {
  13546. this.unexpected();
  13547. }
  13548. }
  13549. parseClassElementName(member) {
  13550. const {
  13551. type,
  13552. value
  13553. } = this.state;
  13554. if ((type === 130 || type === 131) && member.static && value === "prototype") {
  13555. this.raise(Errors.StaticPrototype, {
  13556. at: this.state.startLoc
  13557. });
  13558. }
  13559. if (type === 136) {
  13560. if (value === "constructor") {
  13561. this.raise(Errors.ConstructorClassPrivateField, {
  13562. at: this.state.startLoc
  13563. });
  13564. }
  13565. const key = this.parsePrivateName();
  13566. member.key = key;
  13567. return key;
  13568. }
  13569. return this.parsePropertyName(member);
  13570. }
  13571. parseClassStaticBlock(classBody, member) {
  13572. var _member$decorators;
  13573. this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER);
  13574. const oldLabels = this.state.labels;
  13575. this.state.labels = [];
  13576. this.prodParam.enter(PARAM);
  13577. const body = member.body = [];
  13578. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13579. this.prodParam.exit();
  13580. this.scope.exit();
  13581. this.state.labels = oldLabels;
  13582. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13583. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13584. this.raise(Errors.DecoratorStaticBlock, {
  13585. at: member
  13586. });
  13587. }
  13588. }
  13589. pushClassProperty(classBody, prop) {
  13590. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  13591. this.raise(Errors.ConstructorClassField, {
  13592. at: prop.key
  13593. });
  13594. }
  13595. classBody.body.push(this.parseClassProperty(prop));
  13596. }
  13597. pushClassPrivateProperty(classBody, prop) {
  13598. const node = this.parseClassPrivateProperty(prop);
  13599. classBody.body.push(node);
  13600. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  13601. }
  13602. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13603. if (!isPrivate && !prop.computed) {
  13604. const key = prop.key;
  13605. if (key.name === "constructor" || key.value === "constructor") {
  13606. this.raise(Errors.ConstructorClassField, {
  13607. at: key
  13608. });
  13609. }
  13610. }
  13611. const node = this.parseClassAccessorProperty(prop);
  13612. classBody.body.push(node);
  13613. if (isPrivate) {
  13614. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  13615. }
  13616. }
  13617. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13618. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13619. }
  13620. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13621. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13622. classBody.body.push(node);
  13623. const kind = node.kind === "get" ? node.static ? CLASS_ELEMENT_STATIC_GETTER : CLASS_ELEMENT_INSTANCE_GETTER : node.kind === "set" ? node.static ? CLASS_ELEMENT_STATIC_SETTER : CLASS_ELEMENT_INSTANCE_SETTER : CLASS_ELEMENT_OTHER;
  13624. this.declareClassPrivateMethodInScope(node, kind);
  13625. }
  13626. declareClassPrivateMethodInScope(node, kind) {
  13627. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13628. }
  13629. parsePostMemberNameModifiers(methodOrProp) {}
  13630. parseClassPrivateProperty(node) {
  13631. this.parseInitializer(node);
  13632. this.semicolon();
  13633. return this.finishNode(node, "ClassPrivateProperty");
  13634. }
  13635. parseClassProperty(node) {
  13636. this.parseInitializer(node);
  13637. this.semicolon();
  13638. return this.finishNode(node, "ClassProperty");
  13639. }
  13640. parseClassAccessorProperty(node) {
  13641. this.parseInitializer(node);
  13642. this.semicolon();
  13643. return this.finishNode(node, "ClassAccessorProperty");
  13644. }
  13645. parseInitializer(node) {
  13646. this.scope.enter(SCOPE_CLASS | SCOPE_SUPER);
  13647. this.expressionScope.enter(newExpressionScope());
  13648. this.prodParam.enter(PARAM);
  13649. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13650. this.expressionScope.exit();
  13651. this.prodParam.exit();
  13652. this.scope.exit();
  13653. }
  13654. parseClassId(node, isStatement, optionalId, bindingType = BIND_CLASS) {
  13655. if (tokenIsIdentifier(this.state.type)) {
  13656. node.id = this.parseIdentifier();
  13657. if (isStatement) {
  13658. this.declareNameFromIdentifier(node.id, bindingType);
  13659. }
  13660. } else {
  13661. if (optionalId || !isStatement) {
  13662. node.id = null;
  13663. } else {
  13664. throw this.raise(Errors.MissingClassName, {
  13665. at: this.state.startLoc
  13666. });
  13667. }
  13668. }
  13669. }
  13670. parseClassSuper(node) {
  13671. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13672. }
  13673. parseExport(node, decorators) {
  13674. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13675. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13676. const parseAfterDefault = !hasDefault || this.eat(12);
  13677. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13678. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13679. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13680. const isFromRequired = hasDefault || hasStar;
  13681. if (hasStar && !hasNamespace) {
  13682. if (hasDefault) this.unexpected();
  13683. if (decorators) {
  13684. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13685. at: node
  13686. });
  13687. }
  13688. this.parseExportFrom(node, true);
  13689. return this.finishNode(node, "ExportAllDeclaration");
  13690. }
  13691. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13692. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13693. this.unexpected(null, 5);
  13694. }
  13695. if (hasNamespace && parseAfterNamespace) {
  13696. this.unexpected(null, 97);
  13697. }
  13698. let hasDeclaration;
  13699. if (isFromRequired || hasSpecifiers) {
  13700. hasDeclaration = false;
  13701. if (decorators) {
  13702. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13703. at: node
  13704. });
  13705. }
  13706. this.parseExportFrom(node, isFromRequired);
  13707. } else {
  13708. hasDeclaration = this.maybeParseExportDeclaration(node);
  13709. }
  13710. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13711. var _node2$declaration;
  13712. const node2 = node;
  13713. this.checkExport(node2, true, false, !!node2.source);
  13714. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13715. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13716. } else if (decorators) {
  13717. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13718. at: node
  13719. });
  13720. }
  13721. return this.finishNode(node2, "ExportNamedDeclaration");
  13722. }
  13723. if (this.eat(65)) {
  13724. const node2 = node;
  13725. const decl = this.parseExportDefaultExpression();
  13726. node2.declaration = decl;
  13727. if (decl.type === "ClassDeclaration") {
  13728. this.maybeTakeDecorators(decorators, decl, node2);
  13729. } else if (decorators) {
  13730. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13731. at: node
  13732. });
  13733. }
  13734. this.checkExport(node2, true, true);
  13735. return this.finishNode(node2, "ExportDefaultDeclaration");
  13736. }
  13737. this.unexpected(null, 5);
  13738. }
  13739. eatExportStar(node) {
  13740. return this.eat(55);
  13741. }
  13742. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13743. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13744. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13745. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13746. const specifier = this.startNodeAtNode(id);
  13747. specifier.exported = id;
  13748. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13749. return true;
  13750. }
  13751. return false;
  13752. }
  13753. maybeParseExportNamespaceSpecifier(node) {
  13754. if (this.isContextual(93)) {
  13755. if (!node.specifiers) node.specifiers = [];
  13756. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13757. this.next();
  13758. specifier.exported = this.parseModuleExportName();
  13759. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13760. return true;
  13761. }
  13762. return false;
  13763. }
  13764. maybeParseExportNamedSpecifiers(node) {
  13765. if (this.match(5)) {
  13766. if (!node.specifiers) node.specifiers = [];
  13767. const isTypeExport = node.exportKind === "type";
  13768. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13769. node.source = null;
  13770. node.declaration = null;
  13771. if (this.hasPlugin("importAssertions")) {
  13772. node.assertions = [];
  13773. }
  13774. return true;
  13775. }
  13776. return false;
  13777. }
  13778. maybeParseExportDeclaration(node) {
  13779. if (this.shouldParseExportDeclaration()) {
  13780. node.specifiers = [];
  13781. node.source = null;
  13782. if (this.hasPlugin("importAssertions")) {
  13783. node.assertions = [];
  13784. }
  13785. node.declaration = this.parseExportDeclaration(node);
  13786. return true;
  13787. }
  13788. return false;
  13789. }
  13790. isAsyncFunction() {
  13791. if (!this.isContextual(95)) return false;
  13792. const next = this.nextTokenInLineStart();
  13793. return this.isUnparsedContextual(next, "function");
  13794. }
  13795. parseExportDefaultExpression() {
  13796. const expr = this.startNode();
  13797. if (this.match(68)) {
  13798. this.next();
  13799. return this.parseFunction(expr, 1 | 4);
  13800. } else if (this.isAsyncFunction()) {
  13801. this.next();
  13802. this.next();
  13803. return this.parseFunction(expr, 1 | 4 | 8);
  13804. }
  13805. if (this.match(80)) {
  13806. return this.parseClass(expr, true, true);
  13807. }
  13808. if (this.match(26)) {
  13809. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13810. this.raise(Errors.DecoratorBeforeExport, {
  13811. at: this.state.startLoc
  13812. });
  13813. }
  13814. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13815. }
  13816. if (this.match(75) || this.match(74) || this.isLet()) {
  13817. throw this.raise(Errors.UnsupportedDefaultExport, {
  13818. at: this.state.startLoc
  13819. });
  13820. }
  13821. const res = this.parseMaybeAssignAllowIn();
  13822. this.semicolon();
  13823. return res;
  13824. }
  13825. parseExportDeclaration(node) {
  13826. if (this.match(80)) {
  13827. const node = this.parseClass(this.startNode(), true, false);
  13828. return node;
  13829. }
  13830. return this.parseStatementListItem();
  13831. }
  13832. isExportDefaultSpecifier() {
  13833. const {
  13834. type
  13835. } = this.state;
  13836. if (tokenIsIdentifier(type)) {
  13837. if (type === 95 && !this.state.containsEsc || type === 99) {
  13838. return false;
  13839. }
  13840. if ((type === 128 || type === 127) && !this.state.containsEsc) {
  13841. const {
  13842. type: nextType
  13843. } = this.lookahead();
  13844. if (tokenIsIdentifier(nextType) && nextType !== 97 || nextType === 5) {
  13845. this.expectOnePlugin(["flow", "typescript"]);
  13846. return false;
  13847. }
  13848. }
  13849. } else if (!this.match(65)) {
  13850. return false;
  13851. }
  13852. const next = this.nextTokenStart();
  13853. const hasFrom = this.isUnparsedContextual(next, "from");
  13854. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13855. return true;
  13856. }
  13857. if (this.match(65) && hasFrom) {
  13858. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13859. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13860. }
  13861. return false;
  13862. }
  13863. parseExportFrom(node, expect) {
  13864. if (this.eatContextual(97)) {
  13865. node.source = this.parseImportSource();
  13866. this.checkExport(node);
  13867. this.maybeParseImportAttributes(node);
  13868. this.checkJSONModuleImport(node);
  13869. } else if (expect) {
  13870. this.unexpected();
  13871. }
  13872. this.semicolon();
  13873. }
  13874. shouldParseExportDeclaration() {
  13875. const {
  13876. type
  13877. } = this.state;
  13878. if (type === 26) {
  13879. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13880. if (this.hasPlugin("decorators")) {
  13881. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13882. this.raise(Errors.DecoratorBeforeExport, {
  13883. at: this.state.startLoc
  13884. });
  13885. }
  13886. return true;
  13887. }
  13888. }
  13889. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13890. }
  13891. checkExport(node, checkNames, isDefault, isFrom) {
  13892. if (checkNames) {
  13893. if (isDefault) {
  13894. this.checkDuplicateExports(node, "default");
  13895. if (this.hasPlugin("exportDefaultFrom")) {
  13896. var _declaration$extra;
  13897. const declaration = node.declaration;
  13898. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13899. this.raise(Errors.ExportDefaultFromAsIdentifier, {
  13900. at: declaration
  13901. });
  13902. }
  13903. }
  13904. } else if (node.specifiers && node.specifiers.length) {
  13905. for (const specifier of node.specifiers) {
  13906. const {
  13907. exported
  13908. } = specifier;
  13909. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13910. this.checkDuplicateExports(specifier, exportName);
  13911. if (!isFrom && specifier.local) {
  13912. const {
  13913. local
  13914. } = specifier;
  13915. if (local.type !== "Identifier") {
  13916. this.raise(Errors.ExportBindingIsString, {
  13917. at: specifier,
  13918. localName: local.value,
  13919. exportName
  13920. });
  13921. } else {
  13922. this.checkReservedWord(local.name, local.loc.start, true, false);
  13923. this.scope.checkLocalExport(local);
  13924. }
  13925. }
  13926. }
  13927. } else if (node.declaration) {
  13928. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  13929. const id = node.declaration.id;
  13930. if (!id) throw new Error("Assertion failure");
  13931. this.checkDuplicateExports(node, id.name);
  13932. } else if (node.declaration.type === "VariableDeclaration") {
  13933. for (const declaration of node.declaration.declarations) {
  13934. this.checkDeclaration(declaration.id);
  13935. }
  13936. }
  13937. }
  13938. }
  13939. }
  13940. checkDeclaration(node) {
  13941. if (node.type === "Identifier") {
  13942. this.checkDuplicateExports(node, node.name);
  13943. } else if (node.type === "ObjectPattern") {
  13944. for (const prop of node.properties) {
  13945. this.checkDeclaration(prop);
  13946. }
  13947. } else if (node.type === "ArrayPattern") {
  13948. for (const elem of node.elements) {
  13949. if (elem) {
  13950. this.checkDeclaration(elem);
  13951. }
  13952. }
  13953. } else if (node.type === "ObjectProperty") {
  13954. this.checkDeclaration(node.value);
  13955. } else if (node.type === "RestElement") {
  13956. this.checkDeclaration(node.argument);
  13957. } else if (node.type === "AssignmentPattern") {
  13958. this.checkDeclaration(node.left);
  13959. }
  13960. }
  13961. checkDuplicateExports(node, exportName) {
  13962. if (this.exportedIdentifiers.has(exportName)) {
  13963. if (exportName === "default") {
  13964. this.raise(Errors.DuplicateDefaultExport, {
  13965. at: node
  13966. });
  13967. } else {
  13968. this.raise(Errors.DuplicateExport, {
  13969. at: node,
  13970. exportName
  13971. });
  13972. }
  13973. }
  13974. this.exportedIdentifiers.add(exportName);
  13975. }
  13976. parseExportSpecifiers(isInTypeExport) {
  13977. const nodes = [];
  13978. let first = true;
  13979. this.expect(5);
  13980. while (!this.eat(8)) {
  13981. if (first) {
  13982. first = false;
  13983. } else {
  13984. this.expect(12);
  13985. if (this.eat(8)) break;
  13986. }
  13987. const isMaybeTypeOnly = this.isContextual(128);
  13988. const isString = this.match(131);
  13989. const node = this.startNode();
  13990. node.local = this.parseModuleExportName();
  13991. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13992. }
  13993. return nodes;
  13994. }
  13995. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  13996. if (this.eatContextual(93)) {
  13997. node.exported = this.parseModuleExportName();
  13998. } else if (isString) {
  13999. node.exported = cloneStringLiteral(node.local);
  14000. } else if (!node.exported) {
  14001. node.exported = cloneIdentifier(node.local);
  14002. }
  14003. return this.finishNode(node, "ExportSpecifier");
  14004. }
  14005. parseModuleExportName() {
  14006. if (this.match(131)) {
  14007. const result = this.parseStringLiteral(this.state.value);
  14008. const surrogate = result.value.match(loneSurrogate);
  14009. if (surrogate) {
  14010. this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
  14011. at: result,
  14012. surrogateCharCode: surrogate[0].charCodeAt(0)
  14013. });
  14014. }
  14015. return result;
  14016. }
  14017. return this.parseIdentifier(true);
  14018. }
  14019. isJSONModuleImport(node) {
  14020. if (node.assertions != null) {
  14021. return node.assertions.some(({
  14022. key,
  14023. value
  14024. }) => {
  14025. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14026. });
  14027. }
  14028. return false;
  14029. }
  14030. checkImportReflection(node) {
  14031. if (node.module) {
  14032. var _node$assertions;
  14033. if (node.specifiers.length !== 1 || node.specifiers[0].type !== "ImportDefaultSpecifier") {
  14034. this.raise(Errors.ImportReflectionNotBinding, {
  14035. at: node.specifiers[0].loc.start
  14036. });
  14037. }
  14038. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14039. this.raise(Errors.ImportReflectionHasAssertion, {
  14040. at: node.specifiers[0].loc.start
  14041. });
  14042. }
  14043. }
  14044. }
  14045. checkJSONModuleImport(node) {
  14046. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14047. const {
  14048. specifiers
  14049. } = node;
  14050. if (specifiers != null) {
  14051. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14052. let imported;
  14053. if (specifier.type === "ExportSpecifier") {
  14054. imported = specifier.local;
  14055. } else if (specifier.type === "ImportSpecifier") {
  14056. imported = specifier.imported;
  14057. }
  14058. if (imported !== undefined) {
  14059. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14060. }
  14061. });
  14062. if (nonDefaultNamedSpecifier !== undefined) {
  14063. this.raise(Errors.ImportJSONBindingNotDefault, {
  14064. at: nonDefaultNamedSpecifier.loc.start
  14065. });
  14066. }
  14067. }
  14068. }
  14069. }
  14070. isPotentialImportPhase(isExport) {
  14071. return !isExport && this.isContextual(125);
  14072. }
  14073. applyImportPhase(node, isExport, phase, loc) {
  14074. if (isExport) {
  14075. return;
  14076. }
  14077. if (phase === "module") {
  14078. this.expectPlugin("importReflection", loc);
  14079. node.module = true;
  14080. } else if (this.hasPlugin("importReflection")) {
  14081. node.module = false;
  14082. }
  14083. }
  14084. parseMaybeImportPhase(node, isExport) {
  14085. if (!this.isPotentialImportPhase(isExport)) {
  14086. this.applyImportPhase(node, isExport, null);
  14087. return null;
  14088. }
  14089. const phaseIdentifier = this.parseIdentifier(true);
  14090. const {
  14091. type
  14092. } = this.state;
  14093. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 97 || this.lookaheadCharCode() === 102 : type !== 12;
  14094. if (isImportPhase) {
  14095. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  14096. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  14097. return null;
  14098. } else {
  14099. this.applyImportPhase(node, isExport, null);
  14100. return phaseIdentifier;
  14101. }
  14102. }
  14103. isPrecedingIdImportPhase(phase) {
  14104. const {
  14105. type
  14106. } = this.state;
  14107. return tokenIsIdentifier(type) ? type !== 97 || this.lookaheadCharCode() === 102 : type !== 12;
  14108. }
  14109. parseImport(node) {
  14110. if (this.match(131)) {
  14111. return this.parseImportSourceAndAttributes(node);
  14112. }
  14113. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14114. }
  14115. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14116. node.specifiers = [];
  14117. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14118. const parseNext = !hasDefault || this.eat(12);
  14119. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14120. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14121. this.expectContextual(97);
  14122. return this.parseImportSourceAndAttributes(node);
  14123. }
  14124. parseImportSourceAndAttributes(node) {
  14125. var _node$specifiers;
  14126. (_node$specifiers = node.specifiers) != null ? _node$specifiers : node.specifiers = [];
  14127. node.source = this.parseImportSource();
  14128. this.maybeParseImportAttributes(node);
  14129. this.checkImportReflection(node);
  14130. this.checkJSONModuleImport(node);
  14131. this.semicolon();
  14132. return this.finishNode(node, "ImportDeclaration");
  14133. }
  14134. parseImportSource() {
  14135. if (!this.match(131)) this.unexpected();
  14136. return this.parseExprAtom();
  14137. }
  14138. parseImportSpecifierLocal(node, specifier, type) {
  14139. specifier.local = this.parseIdentifier();
  14140. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14141. }
  14142. finishImportSpecifier(specifier, type, bindingType = BIND_LEXICAL) {
  14143. this.checkLVal(specifier.local, {
  14144. in: {
  14145. type
  14146. },
  14147. binding: bindingType
  14148. });
  14149. return this.finishNode(specifier, type);
  14150. }
  14151. parseImportAttributes() {
  14152. this.expect(5);
  14153. const attrs = [];
  14154. const attrNames = new Set();
  14155. do {
  14156. if (this.match(8)) {
  14157. break;
  14158. }
  14159. const node = this.startNode();
  14160. const keyName = this.state.value;
  14161. if (attrNames.has(keyName)) {
  14162. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14163. at: this.state.startLoc,
  14164. key: keyName
  14165. });
  14166. }
  14167. attrNames.add(keyName);
  14168. if (this.match(131)) {
  14169. node.key = this.parseStringLiteral(keyName);
  14170. } else {
  14171. node.key = this.parseIdentifier(true);
  14172. }
  14173. this.expect(14);
  14174. if (!this.match(131)) {
  14175. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14176. at: this.state.startLoc
  14177. });
  14178. }
  14179. node.value = this.parseStringLiteral(this.state.value);
  14180. attrs.push(this.finishNode(node, "ImportAttribute"));
  14181. } while (this.eat(12));
  14182. this.expect(8);
  14183. return attrs;
  14184. }
  14185. parseModuleAttributes() {
  14186. const attrs = [];
  14187. const attributes = new Set();
  14188. do {
  14189. const node = this.startNode();
  14190. node.key = this.parseIdentifier(true);
  14191. if (node.key.name !== "type") {
  14192. this.raise(Errors.ModuleAttributeDifferentFromType, {
  14193. at: node.key
  14194. });
  14195. }
  14196. if (attributes.has(node.key.name)) {
  14197. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14198. at: node.key,
  14199. key: node.key.name
  14200. });
  14201. }
  14202. attributes.add(node.key.name);
  14203. this.expect(14);
  14204. if (!this.match(131)) {
  14205. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14206. at: this.state.startLoc
  14207. });
  14208. }
  14209. node.value = this.parseStringLiteral(this.state.value);
  14210. attrs.push(this.finishNode(node, "ImportAttribute"));
  14211. } while (this.eat(12));
  14212. return attrs;
  14213. }
  14214. maybeParseImportAttributes(node) {
  14215. let attributes;
  14216. let useWith = false;
  14217. if (this.match(76)) {
  14218. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14219. return;
  14220. }
  14221. this.next();
  14222. {
  14223. if (this.hasPlugin("moduleAttributes")) {
  14224. attributes = this.parseModuleAttributes();
  14225. } else {
  14226. this.expectImportAttributesPlugin();
  14227. attributes = this.parseImportAttributes();
  14228. }
  14229. }
  14230. useWith = true;
  14231. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14232. if (this.hasPlugin("importAttributes")) {
  14233. if (this.getPluginOption("importAttributes", "deprecatedAssertSyntax") !== true) {
  14234. this.raise(Errors.ImportAttributesUseAssert, {
  14235. at: this.state.startLoc
  14236. });
  14237. }
  14238. this.addExtra(node, "deprecatedAssertSyntax", true);
  14239. } else {
  14240. this.expectOnePlugin(["importAttributes", "importAssertions"]);
  14241. }
  14242. this.next();
  14243. attributes = this.parseImportAttributes();
  14244. } else if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  14245. attributes = [];
  14246. } else {
  14247. if (this.hasPlugin("moduleAttributes")) {
  14248. attributes = [];
  14249. } else return;
  14250. }
  14251. if (!useWith && this.hasPlugin("importAssertions")) {
  14252. node.assertions = attributes;
  14253. } else {
  14254. node.attributes = attributes;
  14255. }
  14256. }
  14257. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14258. if (maybeDefaultIdentifier) {
  14259. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14260. specifier.local = maybeDefaultIdentifier;
  14261. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14262. return true;
  14263. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14264. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14265. return true;
  14266. }
  14267. return false;
  14268. }
  14269. maybeParseStarImportSpecifier(node) {
  14270. if (this.match(55)) {
  14271. const specifier = this.startNode();
  14272. this.next();
  14273. this.expectContextual(93);
  14274. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14275. return true;
  14276. }
  14277. return false;
  14278. }
  14279. parseNamedImportSpecifiers(node) {
  14280. let first = true;
  14281. this.expect(5);
  14282. while (!this.eat(8)) {
  14283. if (first) {
  14284. first = false;
  14285. } else {
  14286. if (this.eat(14)) {
  14287. throw this.raise(Errors.DestructureNamedImport, {
  14288. at: this.state.startLoc
  14289. });
  14290. }
  14291. this.expect(12);
  14292. if (this.eat(8)) break;
  14293. }
  14294. const specifier = this.startNode();
  14295. const importedIsString = this.match(131);
  14296. const isMaybeTypeOnly = this.isContextual(128);
  14297. specifier.imported = this.parseModuleExportName();
  14298. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14299. node.specifiers.push(importSpecifier);
  14300. }
  14301. }
  14302. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14303. if (this.eatContextual(93)) {
  14304. specifier.local = this.parseIdentifier();
  14305. } else {
  14306. const {
  14307. imported
  14308. } = specifier;
  14309. if (importedIsString) {
  14310. throw this.raise(Errors.ImportBindingIsString, {
  14311. at: specifier,
  14312. importName: imported.value
  14313. });
  14314. }
  14315. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14316. if (!specifier.local) {
  14317. specifier.local = cloneIdentifier(imported);
  14318. }
  14319. }
  14320. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14321. }
  14322. isThisParam(param) {
  14323. return param.type === "Identifier" && param.name === "this";
  14324. }
  14325. }
  14326. class Parser extends StatementParser {
  14327. constructor(options, input) {
  14328. options = getOptions(options);
  14329. super(options, input);
  14330. this.options = options;
  14331. this.initializeScopes();
  14332. this.plugins = pluginsMap(this.options.plugins);
  14333. this.filename = options.sourceFilename;
  14334. }
  14335. getScopeHandler() {
  14336. return ScopeHandler;
  14337. }
  14338. parse() {
  14339. this.enterInitialScopes();
  14340. const file = this.startNode();
  14341. const program = this.startNode();
  14342. this.nextToken();
  14343. file.errors = null;
  14344. this.parseTopLevel(file, program);
  14345. file.errors = this.state.errors;
  14346. return file;
  14347. }
  14348. }
  14349. function pluginsMap(plugins) {
  14350. const pluginMap = new Map();
  14351. for (const plugin of plugins) {
  14352. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  14353. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  14354. }
  14355. return pluginMap;
  14356. }
  14357. function parse(input, options) {
  14358. var _options;
  14359. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14360. options = Object.assign({}, options);
  14361. try {
  14362. options.sourceType = "module";
  14363. const parser = getParser(options, input);
  14364. const ast = parser.parse();
  14365. if (parser.sawUnambiguousESM) {
  14366. return ast;
  14367. }
  14368. if (parser.ambiguousScriptDifferentAst) {
  14369. try {
  14370. options.sourceType = "script";
  14371. return getParser(options, input).parse();
  14372. } catch (_unused) {}
  14373. } else {
  14374. ast.program.sourceType = "script";
  14375. }
  14376. return ast;
  14377. } catch (moduleError) {
  14378. try {
  14379. options.sourceType = "script";
  14380. return getParser(options, input).parse();
  14381. } catch (_unused2) {}
  14382. throw moduleError;
  14383. }
  14384. } else {
  14385. return getParser(options, input).parse();
  14386. }
  14387. }
  14388. function parseExpression(input, options) {
  14389. const parser = getParser(options, input);
  14390. if (parser.options.strictMode) {
  14391. parser.state.strict = true;
  14392. }
  14393. return parser.getExpression();
  14394. }
  14395. function generateExportedTokenTypes(internalTokenTypes) {
  14396. const tokenTypes = {};
  14397. for (const typeName of Object.keys(internalTokenTypes)) {
  14398. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14399. }
  14400. return tokenTypes;
  14401. }
  14402. const tokTypes = generateExportedTokenTypes(tt);
  14403. function getParser(options, input) {
  14404. let cls = Parser;
  14405. if (options != null && options.plugins) {
  14406. validatePlugins(options.plugins);
  14407. cls = getParserClass(options.plugins);
  14408. }
  14409. return new cls(options, input);
  14410. }
  14411. const parserClassCache = {};
  14412. function getParserClass(pluginsFromOptions) {
  14413. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  14414. const key = pluginList.join("/");
  14415. let cls = parserClassCache[key];
  14416. if (!cls) {
  14417. cls = Parser;
  14418. for (const plugin of pluginList) {
  14419. cls = mixinPlugins[plugin](cls);
  14420. }
  14421. parserClassCache[key] = cls;
  14422. }
  14423. return cls;
  14424. }
  14425. exports.parse = parse;
  14426. exports.parseExpression = parseExpression;
  14427. exports.tokTypes = tokTypes;
  14428. //# sourceMappingURL=index.js.map