index.js 476 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. const defaultOptions = {
  6. sourceType: "script",
  7. sourceFilename: undefined,
  8. startColumn: 0,
  9. startLine: 1,
  10. allowAwaitOutsideFunction: false,
  11. allowReturnOutsideFunction: false,
  12. allowNewTargetOutsideFunction: false,
  13. allowImportExportEverywhere: false,
  14. allowSuperOutsideMethod: false,
  15. allowUndeclaredExports: false,
  16. plugins: [],
  17. strictMode: null,
  18. ranges: false,
  19. tokens: false,
  20. createParenthesizedExpressions: false,
  21. errorRecovery: false,
  22. attachComment: true,
  23. annexB: true
  24. };
  25. function getOptions(opts) {
  26. if (opts && opts.annexB != null && opts.annexB !== false) {
  27. throw new Error("The `annexB` option can only be set to `false`.");
  28. }
  29. const options = {};
  30. for (const key of Object.keys(defaultOptions)) {
  31. options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key];
  32. }
  33. return options;
  34. }
  35. class TokContext {
  36. constructor(token, preserveSpace) {
  37. this.token = void 0;
  38. this.preserveSpace = void 0;
  39. this.token = token;
  40. this.preserveSpace = !!preserveSpace;
  41. }
  42. }
  43. const types = {
  44. brace: new TokContext("{"),
  45. j_oTag: new TokContext("<tag"),
  46. j_cTag: new TokContext("</tag"),
  47. j_expr: new TokContext("<tag>...</tag>", true)
  48. };
  49. {
  50. types.template = new TokContext("`", true);
  51. }
  52. const beforeExpr = true;
  53. const startsExpr = true;
  54. const isLoop = true;
  55. const isAssign = true;
  56. const prefix = true;
  57. const postfix = true;
  58. class ExportedTokenType {
  59. constructor(label, conf = {}) {
  60. this.label = void 0;
  61. this.keyword = void 0;
  62. this.beforeExpr = void 0;
  63. this.startsExpr = void 0;
  64. this.rightAssociative = void 0;
  65. this.isLoop = void 0;
  66. this.isAssign = void 0;
  67. this.prefix = void 0;
  68. this.postfix = void 0;
  69. this.binop = void 0;
  70. this.label = label;
  71. this.keyword = conf.keyword;
  72. this.beforeExpr = !!conf.beforeExpr;
  73. this.startsExpr = !!conf.startsExpr;
  74. this.rightAssociative = !!conf.rightAssociative;
  75. this.isLoop = !!conf.isLoop;
  76. this.isAssign = !!conf.isAssign;
  77. this.prefix = !!conf.prefix;
  78. this.postfix = !!conf.postfix;
  79. this.binop = conf.binop != null ? conf.binop : null;
  80. {
  81. this.updateContext = null;
  82. }
  83. }
  84. }
  85. const keywords$1 = new Map();
  86. function createKeyword(name, options = {}) {
  87. options.keyword = name;
  88. const token = createToken(name, options);
  89. keywords$1.set(name, token);
  90. return token;
  91. }
  92. function createBinop(name, binop) {
  93. return createToken(name, {
  94. beforeExpr,
  95. binop
  96. });
  97. }
  98. let tokenTypeCounter = -1;
  99. const tokenTypes = [];
  100. const tokenLabels = [];
  101. const tokenBinops = [];
  102. const tokenBeforeExprs = [];
  103. const tokenStartsExprs = [];
  104. const tokenPrefixes = [];
  105. function createToken(name, options = {}) {
  106. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  107. ++tokenTypeCounter;
  108. tokenLabels.push(name);
  109. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  110. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  111. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  112. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  113. tokenTypes.push(new ExportedTokenType(name, options));
  114. return tokenTypeCounter;
  115. }
  116. function createKeywordLike(name, options = {}) {
  117. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  118. ++tokenTypeCounter;
  119. keywords$1.set(name, tokenTypeCounter);
  120. tokenLabels.push(name);
  121. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  122. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  123. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  124. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  125. tokenTypes.push(new ExportedTokenType("name", options));
  126. return tokenTypeCounter;
  127. }
  128. const tt = {
  129. bracketL: createToken("[", {
  130. beforeExpr,
  131. startsExpr
  132. }),
  133. bracketHashL: createToken("#[", {
  134. beforeExpr,
  135. startsExpr
  136. }),
  137. bracketBarL: createToken("[|", {
  138. beforeExpr,
  139. startsExpr
  140. }),
  141. bracketR: createToken("]"),
  142. bracketBarR: createToken("|]"),
  143. braceL: createToken("{", {
  144. beforeExpr,
  145. startsExpr
  146. }),
  147. braceBarL: createToken("{|", {
  148. beforeExpr,
  149. startsExpr
  150. }),
  151. braceHashL: createToken("#{", {
  152. beforeExpr,
  153. startsExpr
  154. }),
  155. braceR: createToken("}"),
  156. braceBarR: createToken("|}"),
  157. parenL: createToken("(", {
  158. beforeExpr,
  159. startsExpr
  160. }),
  161. parenR: createToken(")"),
  162. comma: createToken(",", {
  163. beforeExpr
  164. }),
  165. semi: createToken(";", {
  166. beforeExpr
  167. }),
  168. colon: createToken(":", {
  169. beforeExpr
  170. }),
  171. doubleColon: createToken("::", {
  172. beforeExpr
  173. }),
  174. dot: createToken("."),
  175. question: createToken("?", {
  176. beforeExpr
  177. }),
  178. questionDot: createToken("?."),
  179. arrow: createToken("=>", {
  180. beforeExpr
  181. }),
  182. template: createToken("template"),
  183. ellipsis: createToken("...", {
  184. beforeExpr
  185. }),
  186. backQuote: createToken("`", {
  187. startsExpr
  188. }),
  189. dollarBraceL: createToken("${", {
  190. beforeExpr,
  191. startsExpr
  192. }),
  193. templateTail: createToken("...`", {
  194. startsExpr
  195. }),
  196. templateNonTail: createToken("...${", {
  197. beforeExpr,
  198. startsExpr
  199. }),
  200. at: createToken("@"),
  201. hash: createToken("#", {
  202. startsExpr
  203. }),
  204. interpreterDirective: createToken("#!..."),
  205. eq: createToken("=", {
  206. beforeExpr,
  207. isAssign
  208. }),
  209. assign: createToken("_=", {
  210. beforeExpr,
  211. isAssign
  212. }),
  213. slashAssign: createToken("_=", {
  214. beforeExpr,
  215. isAssign
  216. }),
  217. xorAssign: createToken("_=", {
  218. beforeExpr,
  219. isAssign
  220. }),
  221. moduloAssign: createToken("_=", {
  222. beforeExpr,
  223. isAssign
  224. }),
  225. incDec: createToken("++/--", {
  226. prefix,
  227. postfix,
  228. startsExpr
  229. }),
  230. bang: createToken("!", {
  231. beforeExpr,
  232. prefix,
  233. startsExpr
  234. }),
  235. tilde: createToken("~", {
  236. beforeExpr,
  237. prefix,
  238. startsExpr
  239. }),
  240. doubleCaret: createToken("^^", {
  241. startsExpr
  242. }),
  243. doubleAt: createToken("@@", {
  244. startsExpr
  245. }),
  246. pipeline: createBinop("|>", 0),
  247. nullishCoalescing: createBinop("??", 1),
  248. logicalOR: createBinop("||", 1),
  249. logicalAND: createBinop("&&", 2),
  250. bitwiseOR: createBinop("|", 3),
  251. bitwiseXOR: createBinop("^", 4),
  252. bitwiseAND: createBinop("&", 5),
  253. equality: createBinop("==/!=/===/!==", 6),
  254. lt: createBinop("</>/<=/>=", 7),
  255. gt: createBinop("</>/<=/>=", 7),
  256. relational: createBinop("</>/<=/>=", 7),
  257. bitShift: createBinop("<</>>/>>>", 8),
  258. bitShiftL: createBinop("<</>>/>>>", 8),
  259. bitShiftR: createBinop("<</>>/>>>", 8),
  260. plusMin: createToken("+/-", {
  261. beforeExpr,
  262. binop: 9,
  263. prefix,
  264. startsExpr
  265. }),
  266. modulo: createToken("%", {
  267. binop: 10,
  268. startsExpr
  269. }),
  270. star: createToken("*", {
  271. binop: 10
  272. }),
  273. slash: createBinop("/", 10),
  274. exponent: createToken("**", {
  275. beforeExpr,
  276. binop: 11,
  277. rightAssociative: true
  278. }),
  279. _in: createKeyword("in", {
  280. beforeExpr,
  281. binop: 7
  282. }),
  283. _instanceof: createKeyword("instanceof", {
  284. beforeExpr,
  285. binop: 7
  286. }),
  287. _break: createKeyword("break"),
  288. _case: createKeyword("case", {
  289. beforeExpr
  290. }),
  291. _catch: createKeyword("catch"),
  292. _continue: createKeyword("continue"),
  293. _debugger: createKeyword("debugger"),
  294. _default: createKeyword("default", {
  295. beforeExpr
  296. }),
  297. _else: createKeyword("else", {
  298. beforeExpr
  299. }),
  300. _finally: createKeyword("finally"),
  301. _function: createKeyword("function", {
  302. startsExpr
  303. }),
  304. _if: createKeyword("if"),
  305. _return: createKeyword("return", {
  306. beforeExpr
  307. }),
  308. _switch: createKeyword("switch"),
  309. _throw: createKeyword("throw", {
  310. beforeExpr,
  311. prefix,
  312. startsExpr
  313. }),
  314. _try: createKeyword("try"),
  315. _var: createKeyword("var"),
  316. _const: createKeyword("const"),
  317. _with: createKeyword("with"),
  318. _new: createKeyword("new", {
  319. beforeExpr,
  320. startsExpr
  321. }),
  322. _this: createKeyword("this", {
  323. startsExpr
  324. }),
  325. _super: createKeyword("super", {
  326. startsExpr
  327. }),
  328. _class: createKeyword("class", {
  329. startsExpr
  330. }),
  331. _extends: createKeyword("extends", {
  332. beforeExpr
  333. }),
  334. _export: createKeyword("export"),
  335. _import: createKeyword("import", {
  336. startsExpr
  337. }),
  338. _null: createKeyword("null", {
  339. startsExpr
  340. }),
  341. _true: createKeyword("true", {
  342. startsExpr
  343. }),
  344. _false: createKeyword("false", {
  345. startsExpr
  346. }),
  347. _typeof: createKeyword("typeof", {
  348. beforeExpr,
  349. prefix,
  350. startsExpr
  351. }),
  352. _void: createKeyword("void", {
  353. beforeExpr,
  354. prefix,
  355. startsExpr
  356. }),
  357. _delete: createKeyword("delete", {
  358. beforeExpr,
  359. prefix,
  360. startsExpr
  361. }),
  362. _do: createKeyword("do", {
  363. isLoop,
  364. beforeExpr
  365. }),
  366. _for: createKeyword("for", {
  367. isLoop
  368. }),
  369. _while: createKeyword("while", {
  370. isLoop
  371. }),
  372. _as: createKeywordLike("as", {
  373. startsExpr
  374. }),
  375. _assert: createKeywordLike("assert", {
  376. startsExpr
  377. }),
  378. _async: createKeywordLike("async", {
  379. startsExpr
  380. }),
  381. _await: createKeywordLike("await", {
  382. startsExpr
  383. }),
  384. _from: createKeywordLike("from", {
  385. startsExpr
  386. }),
  387. _get: createKeywordLike("get", {
  388. startsExpr
  389. }),
  390. _let: createKeywordLike("let", {
  391. startsExpr
  392. }),
  393. _meta: createKeywordLike("meta", {
  394. startsExpr
  395. }),
  396. _of: createKeywordLike("of", {
  397. startsExpr
  398. }),
  399. _sent: createKeywordLike("sent", {
  400. startsExpr
  401. }),
  402. _set: createKeywordLike("set", {
  403. startsExpr
  404. }),
  405. _static: createKeywordLike("static", {
  406. startsExpr
  407. }),
  408. _using: createKeywordLike("using", {
  409. startsExpr
  410. }),
  411. _yield: createKeywordLike("yield", {
  412. startsExpr
  413. }),
  414. _asserts: createKeywordLike("asserts", {
  415. startsExpr
  416. }),
  417. _checks: createKeywordLike("checks", {
  418. startsExpr
  419. }),
  420. _exports: createKeywordLike("exports", {
  421. startsExpr
  422. }),
  423. _global: createKeywordLike("global", {
  424. startsExpr
  425. }),
  426. _implements: createKeywordLike("implements", {
  427. startsExpr
  428. }),
  429. _intrinsic: createKeywordLike("intrinsic", {
  430. startsExpr
  431. }),
  432. _infer: createKeywordLike("infer", {
  433. startsExpr
  434. }),
  435. _is: createKeywordLike("is", {
  436. startsExpr
  437. }),
  438. _mixins: createKeywordLike("mixins", {
  439. startsExpr
  440. }),
  441. _proto: createKeywordLike("proto", {
  442. startsExpr
  443. }),
  444. _require: createKeywordLike("require", {
  445. startsExpr
  446. }),
  447. _satisfies: createKeywordLike("satisfies", {
  448. startsExpr
  449. }),
  450. _keyof: createKeywordLike("keyof", {
  451. startsExpr
  452. }),
  453. _readonly: createKeywordLike("readonly", {
  454. startsExpr
  455. }),
  456. _unique: createKeywordLike("unique", {
  457. startsExpr
  458. }),
  459. _abstract: createKeywordLike("abstract", {
  460. startsExpr
  461. }),
  462. _declare: createKeywordLike("declare", {
  463. startsExpr
  464. }),
  465. _enum: createKeywordLike("enum", {
  466. startsExpr
  467. }),
  468. _module: createKeywordLike("module", {
  469. startsExpr
  470. }),
  471. _namespace: createKeywordLike("namespace", {
  472. startsExpr
  473. }),
  474. _interface: createKeywordLike("interface", {
  475. startsExpr
  476. }),
  477. _type: createKeywordLike("type", {
  478. startsExpr
  479. }),
  480. _opaque: createKeywordLike("opaque", {
  481. startsExpr
  482. }),
  483. name: createToken("name", {
  484. startsExpr
  485. }),
  486. string: createToken("string", {
  487. startsExpr
  488. }),
  489. num: createToken("num", {
  490. startsExpr
  491. }),
  492. bigint: createToken("bigint", {
  493. startsExpr
  494. }),
  495. decimal: createToken("decimal", {
  496. startsExpr
  497. }),
  498. regexp: createToken("regexp", {
  499. startsExpr
  500. }),
  501. privateName: createToken("#name", {
  502. startsExpr
  503. }),
  504. eof: createToken("eof"),
  505. jsxName: createToken("jsxName"),
  506. jsxText: createToken("jsxText", {
  507. beforeExpr: true
  508. }),
  509. jsxTagStart: createToken("jsxTagStart", {
  510. startsExpr: true
  511. }),
  512. jsxTagEnd: createToken("jsxTagEnd"),
  513. placeholder: createToken("%%", {
  514. startsExpr: true
  515. })
  516. };
  517. function tokenIsIdentifier(token) {
  518. return token >= 93 && token <= 130;
  519. }
  520. function tokenKeywordOrIdentifierIsKeyword(token) {
  521. return token <= 92;
  522. }
  523. function tokenIsKeywordOrIdentifier(token) {
  524. return token >= 58 && token <= 130;
  525. }
  526. function tokenIsLiteralPropertyName(token) {
  527. return token >= 58 && token <= 134;
  528. }
  529. function tokenComesBeforeExpression(token) {
  530. return tokenBeforeExprs[token];
  531. }
  532. function tokenCanStartExpression(token) {
  533. return tokenStartsExprs[token];
  534. }
  535. function tokenIsAssignment(token) {
  536. return token >= 29 && token <= 33;
  537. }
  538. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  539. return token >= 127 && token <= 129;
  540. }
  541. function tokenIsLoop(token) {
  542. return token >= 90 && token <= 92;
  543. }
  544. function tokenIsKeyword(token) {
  545. return token >= 58 && token <= 92;
  546. }
  547. function tokenIsOperator(token) {
  548. return token >= 39 && token <= 59;
  549. }
  550. function tokenIsPostfix(token) {
  551. return token === 34;
  552. }
  553. function tokenIsPrefix(token) {
  554. return tokenPrefixes[token];
  555. }
  556. function tokenIsTSTypeOperator(token) {
  557. return token >= 119 && token <= 121;
  558. }
  559. function tokenIsTSDeclarationStart(token) {
  560. return token >= 122 && token <= 128;
  561. }
  562. function tokenLabelName(token) {
  563. return tokenLabels[token];
  564. }
  565. function tokenOperatorPrecedence(token) {
  566. return tokenBinops[token];
  567. }
  568. function tokenIsRightAssociative(token) {
  569. return token === 57;
  570. }
  571. function tokenIsTemplate(token) {
  572. return token >= 24 && token <= 25;
  573. }
  574. function getExportedToken(token) {
  575. return tokenTypes[token];
  576. }
  577. {
  578. tokenTypes[8].updateContext = context => {
  579. context.pop();
  580. };
  581. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  582. context.push(types.brace);
  583. };
  584. tokenTypes[22].updateContext = context => {
  585. if (context[context.length - 1] === types.template) {
  586. context.pop();
  587. } else {
  588. context.push(types.template);
  589. }
  590. };
  591. tokenTypes[140].updateContext = context => {
  592. context.push(types.j_expr, types.j_oTag);
  593. };
  594. }
  595. function _objectWithoutPropertiesLoose(source, excluded) {
  596. if (source == null) return {};
  597. var target = {};
  598. var sourceKeys = Object.keys(source);
  599. var key, i;
  600. for (i = 0; i < sourceKeys.length; i++) {
  601. key = sourceKeys[i];
  602. if (excluded.indexOf(key) >= 0) continue;
  603. target[key] = source[key];
  604. }
  605. return target;
  606. }
  607. class Position {
  608. constructor(line, col, index) {
  609. this.line = void 0;
  610. this.column = void 0;
  611. this.index = void 0;
  612. this.line = line;
  613. this.column = col;
  614. this.index = index;
  615. }
  616. }
  617. class SourceLocation {
  618. constructor(start, end) {
  619. this.start = void 0;
  620. this.end = void 0;
  621. this.filename = void 0;
  622. this.identifierName = void 0;
  623. this.start = start;
  624. this.end = end;
  625. }
  626. }
  627. function createPositionWithColumnOffset(position, columnOffset) {
  628. const {
  629. line,
  630. column,
  631. index
  632. } = position;
  633. return new Position(line, column + columnOffset, index + columnOffset);
  634. }
  635. var ParseErrorCode = {
  636. SyntaxError: "BABEL_PARSER_SYNTAX_ERROR",
  637. SourceTypeModuleError: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"
  638. };
  639. const reflect = (keys, last = keys.length - 1) => ({
  640. get() {
  641. return keys.reduce((object, key) => object[key], this);
  642. },
  643. set(value) {
  644. keys.reduce((item, key, i) => i === last ? item[key] = value : item[key], this);
  645. }
  646. });
  647. const instantiate = (constructor, properties, descriptors) => Object.keys(descriptors).map(key => [key, descriptors[key]]).filter(([, descriptor]) => !!descriptor).map(([key, descriptor]) => [key, typeof descriptor === "function" ? {
  648. value: descriptor,
  649. enumerable: false
  650. } : typeof descriptor.reflect === "string" ? Object.assign({}, descriptor, reflect(descriptor.reflect.split("."))) : descriptor]).reduce((instance, [key, descriptor]) => Object.defineProperty(instance, key, Object.assign({
  651. configurable: true
  652. }, descriptor)), Object.assign(new constructor(), properties));
  653. var ModuleErrors = {
  654. ImportMetaOutsideModule: {
  655. message: `import.meta may appear only with 'sourceType: "module"'`,
  656. code: ParseErrorCode.SourceTypeModuleError
  657. },
  658. ImportOutsideModule: {
  659. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  660. code: ParseErrorCode.SourceTypeModuleError
  661. }
  662. };
  663. const NodeDescriptions = {
  664. ArrayPattern: "array destructuring pattern",
  665. AssignmentExpression: "assignment expression",
  666. AssignmentPattern: "assignment expression",
  667. ArrowFunctionExpression: "arrow function expression",
  668. ConditionalExpression: "conditional expression",
  669. CatchClause: "catch clause",
  670. ForOfStatement: "for-of statement",
  671. ForInStatement: "for-in statement",
  672. ForStatement: "for-loop",
  673. FormalParameters: "function parameter list",
  674. Identifier: "identifier",
  675. ImportSpecifier: "import specifier",
  676. ImportDefaultSpecifier: "import default specifier",
  677. ImportNamespaceSpecifier: "import namespace specifier",
  678. ObjectPattern: "object destructuring pattern",
  679. ParenthesizedExpression: "parenthesized expression",
  680. RestElement: "rest element",
  681. UpdateExpression: {
  682. true: "prefix operation",
  683. false: "postfix operation"
  684. },
  685. VariableDeclarator: "variable declaration",
  686. YieldExpression: "yield expression"
  687. };
  688. const toNodeDescription = ({
  689. type,
  690. prefix
  691. }) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
  692. var StandardErrors = {
  693. AccessorIsGenerator: ({
  694. kind
  695. }) => `A ${kind}ter cannot be a generator.`,
  696. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  697. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  698. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  699. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  700. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  701. AwaitInUsingBinding: "'await' is not allowed to be used as a name in 'using' declarations.",
  702. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  703. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  704. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  705. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  706. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  707. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  708. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  709. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  710. ConstructorIsAsync: "Constructor can't be an async function.",
  711. ConstructorIsGenerator: "Constructor can't be a generator.",
  712. DeclarationMissingInitializer: ({
  713. kind
  714. }) => `Missing initializer in ${kind} declaration.`,
  715. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  716. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  717. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  718. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  719. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  720. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  721. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  722. DeletePrivateField: "Deleting a private field is not allowed.",
  723. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  724. DuplicateConstructor: "Duplicate constructor in the same class.",
  725. DuplicateDefaultExport: "Only one default export allowed per module.",
  726. DuplicateExport: ({
  727. exportName
  728. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  729. DuplicateProto: "Redefinition of __proto__ property.",
  730. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  731. ElementAfterRest: "Rest element must be last element.",
  732. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  733. ExportBindingIsString: ({
  734. localName,
  735. exportName
  736. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  737. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  738. ForInOfLoopInitializer: ({
  739. type
  740. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  741. ForInUsing: "For-in loop may not start with 'using' declaration.",
  742. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  743. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  744. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  745. IllegalBreakContinue: ({
  746. type
  747. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  748. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  749. IllegalReturn: "'return' outside of function.",
  750. ImportBindingIsString: ({
  751. importName
  752. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  753. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  754. ImportCallArity: ({
  755. maxArgumentCount
  756. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
  757. ImportCallNotNewExpression: "Cannot use new with import(...).",
  758. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  759. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  760. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  761. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  762. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  763. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  764. InvalidCodePoint: "Code point out of bounds.",
  765. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  766. InvalidDecimal: "Invalid decimal.",
  767. InvalidDigit: ({
  768. radix
  769. }) => `Expected number in radix ${radix}.`,
  770. InvalidEscapeSequence: "Bad character escape sequence.",
  771. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  772. InvalidEscapedReservedWord: ({
  773. reservedWord
  774. }) => `Escape sequence in keyword ${reservedWord}.`,
  775. InvalidIdentifier: ({
  776. identifierName
  777. }) => `Invalid identifier ${identifierName}.`,
  778. InvalidLhs: ({
  779. ancestor
  780. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  781. InvalidLhsBinding: ({
  782. ancestor
  783. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  784. InvalidNumber: "Invalid number.",
  785. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  786. InvalidOrUnexpectedToken: ({
  787. unexpected
  788. }) => `Unexpected character '${unexpected}'.`,
  789. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  790. InvalidPrivateFieldResolution: ({
  791. identifierName
  792. }) => `Private name #${identifierName} is not defined.`,
  793. InvalidPropertyBindingPattern: "Binding member expression.",
  794. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  795. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  796. LabelRedeclaration: ({
  797. labelName
  798. }) => `Label '${labelName}' is already declared.`,
  799. LetInLexicalBinding: "'let' is not allowed to be used as a name in 'let' or 'const' declarations.",
  800. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  801. MalformedRegExpFlags: "Invalid regular expression flag.",
  802. MissingClassName: "A class name is required.",
  803. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  804. MissingSemicolon: "Missing semicolon.",
  805. MissingPlugin: ({
  806. missingPlugin
  807. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  808. MissingOneOfPlugins: ({
  809. missingPlugin
  810. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  811. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  812. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  813. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  814. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  815. ModuleAttributesWithDuplicateKeys: ({
  816. key
  817. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  818. ModuleExportNameHasLoneSurrogate: ({
  819. surrogateCharCode
  820. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  821. ModuleExportUndefined: ({
  822. localName
  823. }) => `Export '${localName}' is not defined.`,
  824. MultipleDefaultsInSwitch: "Multiple default clauses.",
  825. NewlineAfterThrow: "Illegal newline after throw.",
  826. NoCatchOrFinally: "Missing catch or finally clause.",
  827. NumberIdentifier: "Identifier directly after number.",
  828. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  829. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  830. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  831. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  832. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  833. ParamDupe: "Argument name clash.",
  834. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  835. PatternHasMethod: "Object pattern can't contain methods.",
  836. PrivateInExpectedIn: ({
  837. identifierName
  838. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  839. PrivateNameRedeclaration: ({
  840. identifierName
  841. }) => `Duplicate private name #${identifierName}.`,
  842. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  843. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  844. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  845. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  846. RestTrailingComma: "Unexpected trailing comma after rest element.",
  847. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  848. 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.",
  849. StaticPrototype: "Classes may not have static property named prototype.",
  850. 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?",
  851. SuperPrivateField: "Private fields can't be accessed on super.",
  852. TrailingDecorator: "Decorators must be attached to a class element.",
  853. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  854. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  855. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  856. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  857. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  858. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  859. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  860. UnexpectedKeyword: ({
  861. keyword
  862. }) => `Unexpected keyword '${keyword}'.`,
  863. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  864. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  865. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  866. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  867. UnexpectedPrivateField: "Unexpected private name.",
  868. UnexpectedReservedWord: ({
  869. reservedWord
  870. }) => `Unexpected reserved word '${reservedWord}'.`,
  871. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  872. UnexpectedToken: ({
  873. expected,
  874. unexpected
  875. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  876. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  877. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  878. UnsupportedBind: "Binding should be performed on object property.",
  879. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  880. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  881. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  882. UnsupportedMetaProperty: ({
  883. target,
  884. onlyValidPropertyName
  885. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  886. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  887. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  888. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  889. UnterminatedComment: "Unterminated comment.",
  890. UnterminatedRegExp: "Unterminated regular expression.",
  891. UnterminatedString: "Unterminated string constant.",
  892. UnterminatedTemplate: "Unterminated template.",
  893. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  894. VarRedeclaration: ({
  895. identifierName
  896. }) => `Identifier '${identifierName}' has already been declared.`,
  897. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  898. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  899. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  900. };
  901. var StrictModeErrors = {
  902. StrictDelete: "Deleting local variable in strict mode.",
  903. StrictEvalArguments: ({
  904. referenceName
  905. }) => `Assigning to '${referenceName}' in strict mode.`,
  906. StrictEvalArgumentsBinding: ({
  907. bindingName
  908. }) => `Binding '${bindingName}' in strict mode.`,
  909. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  910. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  911. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  912. StrictWith: "'with' in strict mode."
  913. };
  914. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  915. var PipelineOperatorErrors = {
  916. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  917. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  918. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  919. PipeTopicUnconfiguredToken: ({
  920. token
  921. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  922. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  923. PipeUnparenthesizedBody: ({
  924. type
  925. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  926. type
  927. })}; please wrap it in parentheses.`,
  928. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  929. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  930. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  931. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  932. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  933. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  934. };
  935. const _excluded$1 = ["toMessage"],
  936. _excluded2$1 = ["message"];
  937. function toParseErrorConstructor(_ref) {
  938. let {
  939. toMessage
  940. } = _ref,
  941. properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  942. return function constructor({
  943. loc,
  944. details
  945. }) {
  946. return instantiate(SyntaxError, Object.assign({}, properties, {
  947. loc
  948. }), {
  949. clone(overrides = {}) {
  950. const loc = overrides.loc || {};
  951. return constructor({
  952. 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),
  953. details: Object.assign({}, this.details, overrides.details)
  954. });
  955. },
  956. details: {
  957. value: details,
  958. enumerable: false
  959. },
  960. message: {
  961. get() {
  962. return `${toMessage(this.details)} (${this.loc.line}:${this.loc.column})`;
  963. },
  964. set(value) {
  965. Object.defineProperty(this, "message", {
  966. value
  967. });
  968. }
  969. },
  970. pos: {
  971. reflect: "loc.index",
  972. enumerable: true
  973. },
  974. missingPlugin: "missingPlugin" in details && {
  975. reflect: "details.missingPlugin",
  976. enumerable: true
  977. }
  978. });
  979. };
  980. }
  981. function ParseErrorEnum(argument, syntaxPlugin) {
  982. if (Array.isArray(argument)) {
  983. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  984. }
  985. const ParseErrorConstructors = {};
  986. for (const reasonCode of Object.keys(argument)) {
  987. const template = argument[reasonCode];
  988. const _ref2 = typeof template === "string" ? {
  989. message: () => template
  990. } : typeof template === "function" ? {
  991. message: template
  992. } : template,
  993. {
  994. message
  995. } = _ref2,
  996. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
  997. const toMessage = typeof message === "string" ? () => message : message;
  998. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  999. code: ParseErrorCode.SyntaxError,
  1000. reasonCode,
  1001. toMessage
  1002. }, syntaxPlugin ? {
  1003. syntaxPlugin
  1004. } : {}, rest));
  1005. }
  1006. return ParseErrorConstructors;
  1007. }
  1008. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  1009. const {
  1010. defineProperty
  1011. } = Object;
  1012. const toUnenumerable = (object, key) => defineProperty(object, key, {
  1013. enumerable: false,
  1014. value: object[key]
  1015. });
  1016. function toESTreeLocation(node) {
  1017. node.loc.start && toUnenumerable(node.loc.start, "index");
  1018. node.loc.end && toUnenumerable(node.loc.end, "index");
  1019. return node;
  1020. }
  1021. var estree = superClass => class ESTreeParserMixin extends superClass {
  1022. parse() {
  1023. const file = toESTreeLocation(super.parse());
  1024. if (this.options.tokens) {
  1025. file.tokens = file.tokens.map(toESTreeLocation);
  1026. }
  1027. return file;
  1028. }
  1029. parseRegExpLiteral({
  1030. pattern,
  1031. flags
  1032. }) {
  1033. let regex = null;
  1034. try {
  1035. regex = new RegExp(pattern, flags);
  1036. } catch (e) {}
  1037. const node = this.estreeParseLiteral(regex);
  1038. node.regex = {
  1039. pattern,
  1040. flags
  1041. };
  1042. return node;
  1043. }
  1044. parseBigIntLiteral(value) {
  1045. let bigInt;
  1046. try {
  1047. bigInt = BigInt(value);
  1048. } catch (_unused) {
  1049. bigInt = null;
  1050. }
  1051. const node = this.estreeParseLiteral(bigInt);
  1052. node.bigint = String(node.value || value);
  1053. return node;
  1054. }
  1055. parseDecimalLiteral(value) {
  1056. const decimal = null;
  1057. const node = this.estreeParseLiteral(decimal);
  1058. node.decimal = String(node.value || value);
  1059. return node;
  1060. }
  1061. estreeParseLiteral(value) {
  1062. return this.parseLiteral(value, "Literal");
  1063. }
  1064. parseStringLiteral(value) {
  1065. return this.estreeParseLiteral(value);
  1066. }
  1067. parseNumericLiteral(value) {
  1068. return this.estreeParseLiteral(value);
  1069. }
  1070. parseNullLiteral() {
  1071. return this.estreeParseLiteral(null);
  1072. }
  1073. parseBooleanLiteral(value) {
  1074. return this.estreeParseLiteral(value);
  1075. }
  1076. directiveToStmt(directive) {
  1077. const expression = directive.value;
  1078. delete directive.value;
  1079. expression.type = "Literal";
  1080. expression.raw = expression.extra.raw;
  1081. expression.value = expression.extra.expressionValue;
  1082. const stmt = directive;
  1083. stmt.type = "ExpressionStatement";
  1084. stmt.expression = expression;
  1085. stmt.directive = expression.extra.rawValue;
  1086. delete expression.extra;
  1087. return stmt;
  1088. }
  1089. initFunction(node, isAsync) {
  1090. super.initFunction(node, isAsync);
  1091. node.expression = false;
  1092. }
  1093. checkDeclaration(node) {
  1094. if (node != null && this.isObjectProperty(node)) {
  1095. this.checkDeclaration(node.value);
  1096. } else {
  1097. super.checkDeclaration(node);
  1098. }
  1099. }
  1100. getObjectOrClassMethodParams(method) {
  1101. return method.value.params;
  1102. }
  1103. isValidDirective(stmt) {
  1104. var _stmt$expression$extr;
  1105. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  1106. }
  1107. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  1108. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  1109. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  1110. node.body = directiveStatements.concat(node.body);
  1111. delete node.directives;
  1112. }
  1113. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  1114. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  1115. if (method.typeParameters) {
  1116. method.value.typeParameters = method.typeParameters;
  1117. delete method.typeParameters;
  1118. }
  1119. classBody.body.push(method);
  1120. }
  1121. parsePrivateName() {
  1122. const node = super.parsePrivateName();
  1123. {
  1124. if (!this.getPluginOption("estree", "classFeatures")) {
  1125. return node;
  1126. }
  1127. }
  1128. return this.convertPrivateNameToPrivateIdentifier(node);
  1129. }
  1130. convertPrivateNameToPrivateIdentifier(node) {
  1131. const name = super.getPrivateNameSV(node);
  1132. node = node;
  1133. delete node.id;
  1134. node.name = name;
  1135. node.type = "PrivateIdentifier";
  1136. return node;
  1137. }
  1138. isPrivateName(node) {
  1139. {
  1140. if (!this.getPluginOption("estree", "classFeatures")) {
  1141. return super.isPrivateName(node);
  1142. }
  1143. }
  1144. return node.type === "PrivateIdentifier";
  1145. }
  1146. getPrivateNameSV(node) {
  1147. {
  1148. if (!this.getPluginOption("estree", "classFeatures")) {
  1149. return super.getPrivateNameSV(node);
  1150. }
  1151. }
  1152. return node.name;
  1153. }
  1154. parseLiteral(value, type) {
  1155. const node = super.parseLiteral(value, type);
  1156. node.raw = node.extra.raw;
  1157. delete node.extra;
  1158. return node;
  1159. }
  1160. parseFunctionBody(node, allowExpression, isMethod = false) {
  1161. super.parseFunctionBody(node, allowExpression, isMethod);
  1162. node.expression = node.body.type !== "BlockStatement";
  1163. }
  1164. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  1165. let funcNode = this.startNode();
  1166. funcNode.kind = node.kind;
  1167. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  1168. funcNode.type = "FunctionExpression";
  1169. delete funcNode.kind;
  1170. node.value = funcNode;
  1171. if (type === "ClassPrivateMethod") {
  1172. node.computed = false;
  1173. }
  1174. return this.finishNode(node, "MethodDefinition");
  1175. }
  1176. parseClassProperty(...args) {
  1177. const propertyNode = super.parseClassProperty(...args);
  1178. {
  1179. if (!this.getPluginOption("estree", "classFeatures")) {
  1180. return propertyNode;
  1181. }
  1182. }
  1183. propertyNode.type = "PropertyDefinition";
  1184. return propertyNode;
  1185. }
  1186. parseClassPrivateProperty(...args) {
  1187. const propertyNode = super.parseClassPrivateProperty(...args);
  1188. {
  1189. if (!this.getPluginOption("estree", "classFeatures")) {
  1190. return propertyNode;
  1191. }
  1192. }
  1193. propertyNode.type = "PropertyDefinition";
  1194. propertyNode.computed = false;
  1195. return propertyNode;
  1196. }
  1197. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  1198. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  1199. if (node) {
  1200. node.type = "Property";
  1201. if (node.kind === "method") {
  1202. node.kind = "init";
  1203. }
  1204. node.shorthand = false;
  1205. }
  1206. return node;
  1207. }
  1208. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  1209. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  1210. if (node) {
  1211. node.kind = "init";
  1212. node.type = "Property";
  1213. }
  1214. return node;
  1215. }
  1216. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  1217. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  1218. }
  1219. isAssignable(node, isBinding) {
  1220. if (node != null && this.isObjectProperty(node)) {
  1221. return this.isAssignable(node.value, isBinding);
  1222. }
  1223. return super.isAssignable(node, isBinding);
  1224. }
  1225. toAssignable(node, isLHS = false) {
  1226. if (node != null && this.isObjectProperty(node)) {
  1227. const {
  1228. key,
  1229. value
  1230. } = node;
  1231. if (this.isPrivateName(key)) {
  1232. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  1233. }
  1234. this.toAssignable(value, isLHS);
  1235. } else {
  1236. super.toAssignable(node, isLHS);
  1237. }
  1238. }
  1239. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  1240. if (prop.kind === "get" || prop.kind === "set") {
  1241. this.raise(Errors.PatternHasAccessor, {
  1242. at: prop.key
  1243. });
  1244. } else if (prop.method) {
  1245. this.raise(Errors.PatternHasMethod, {
  1246. at: prop.key
  1247. });
  1248. } else {
  1249. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  1250. }
  1251. }
  1252. finishCallExpression(unfinished, optional) {
  1253. const node = super.finishCallExpression(unfinished, optional);
  1254. if (node.callee.type === "Import") {
  1255. node.type = "ImportExpression";
  1256. node.source = node.arguments[0];
  1257. if (this.hasPlugin("importAssertions")) {
  1258. var _node$arguments$;
  1259. node.attributes = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  1260. }
  1261. delete node.arguments;
  1262. delete node.callee;
  1263. }
  1264. return node;
  1265. }
  1266. toReferencedArguments(node) {
  1267. if (node.type === "ImportExpression") {
  1268. return;
  1269. }
  1270. super.toReferencedArguments(node);
  1271. }
  1272. parseExport(unfinished, decorators) {
  1273. const exportStartLoc = this.state.lastTokStartLoc;
  1274. const node = super.parseExport(unfinished, decorators);
  1275. switch (node.type) {
  1276. case "ExportAllDeclaration":
  1277. node.exported = null;
  1278. break;
  1279. case "ExportNamedDeclaration":
  1280. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  1281. node.type = "ExportAllDeclaration";
  1282. node.exported = node.specifiers[0].exported;
  1283. delete node.specifiers;
  1284. }
  1285. case "ExportDefaultDeclaration":
  1286. {
  1287. var _declaration$decorato;
  1288. const {
  1289. declaration
  1290. } = node;
  1291. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  1292. this.resetStartLocation(node, exportStartLoc);
  1293. }
  1294. }
  1295. break;
  1296. }
  1297. return node;
  1298. }
  1299. parseSubscript(base, startLoc, noCalls, state) {
  1300. const node = super.parseSubscript(base, startLoc, noCalls, state);
  1301. if (state.optionalChainMember) {
  1302. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  1303. node.type = node.type.substring(8);
  1304. }
  1305. if (state.stop) {
  1306. const chain = this.startNodeAtNode(node);
  1307. chain.expression = node;
  1308. return this.finishNode(chain, "ChainExpression");
  1309. }
  1310. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  1311. node.optional = false;
  1312. }
  1313. return node;
  1314. }
  1315. hasPropertyAsPrivateName(node) {
  1316. if (node.type === "ChainExpression") {
  1317. node = node.expression;
  1318. }
  1319. return super.hasPropertyAsPrivateName(node);
  1320. }
  1321. isObjectProperty(node) {
  1322. return node.type === "Property" && node.kind === "init" && !node.method;
  1323. }
  1324. isObjectMethod(node) {
  1325. return node.method || node.kind === "get" || node.kind === "set";
  1326. }
  1327. finishNodeAt(node, type, endLoc) {
  1328. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  1329. }
  1330. resetStartLocation(node, startLoc) {
  1331. super.resetStartLocation(node, startLoc);
  1332. toESTreeLocation(node);
  1333. }
  1334. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  1335. super.resetEndLocation(node, endLoc);
  1336. toESTreeLocation(node);
  1337. }
  1338. };
  1339. 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";
  1340. 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";
  1341. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1342. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1343. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1344. 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];
  1345. 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];
  1346. function isInAstralSet(code, set) {
  1347. let pos = 0x10000;
  1348. for (let i = 0, length = set.length; i < length; i += 2) {
  1349. pos += set[i];
  1350. if (pos > code) return false;
  1351. pos += set[i + 1];
  1352. if (pos >= code) return true;
  1353. }
  1354. return false;
  1355. }
  1356. function isIdentifierStart(code) {
  1357. if (code < 65) return code === 36;
  1358. if (code <= 90) return true;
  1359. if (code < 97) return code === 95;
  1360. if (code <= 122) return true;
  1361. if (code <= 0xffff) {
  1362. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1363. }
  1364. return isInAstralSet(code, astralIdentifierStartCodes);
  1365. }
  1366. function isIdentifierChar(code) {
  1367. if (code < 48) return code === 36;
  1368. if (code < 58) return true;
  1369. if (code < 65) return false;
  1370. if (code <= 90) return true;
  1371. if (code < 97) return code === 95;
  1372. if (code <= 122) return true;
  1373. if (code <= 0xffff) {
  1374. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1375. }
  1376. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1377. }
  1378. const reservedWords = {
  1379. 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"],
  1380. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1381. strictBind: ["eval", "arguments"]
  1382. };
  1383. const keywords = new Set(reservedWords.keyword);
  1384. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1385. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1386. function isReservedWord(word, inModule) {
  1387. return inModule && word === "await" || word === "enum";
  1388. }
  1389. function isStrictReservedWord(word, inModule) {
  1390. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1391. }
  1392. function isStrictBindOnlyReservedWord(word) {
  1393. return reservedWordsStrictBindSet.has(word);
  1394. }
  1395. function isStrictBindReservedWord(word, inModule) {
  1396. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1397. }
  1398. function isKeyword(word) {
  1399. return keywords.has(word);
  1400. }
  1401. function isIteratorStart(current, next, next2) {
  1402. return current === 64 && next === 64 && isIdentifierStart(next2);
  1403. }
  1404. 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"]);
  1405. function canBeReservedWord(word) {
  1406. return reservedWordLikeSet.has(word);
  1407. }
  1408. const SCOPE_OTHER = 0b000000000,
  1409. SCOPE_PROGRAM = 0b000000001,
  1410. SCOPE_FUNCTION = 0b000000010,
  1411. SCOPE_ARROW = 0b000000100,
  1412. SCOPE_SIMPLE_CATCH = 0b000001000,
  1413. SCOPE_SUPER = 0b000010000,
  1414. SCOPE_DIRECT_SUPER = 0b000100000,
  1415. SCOPE_CLASS = 0b001000000,
  1416. SCOPE_STATIC_BLOCK = 0b010000000,
  1417. SCOPE_TS_MODULE = 0b100000000,
  1418. SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_STATIC_BLOCK | SCOPE_TS_MODULE;
  1419. const BIND_KIND_VALUE = 0b0000000000001,
  1420. BIND_KIND_TYPE = 0b0000000000010,
  1421. BIND_SCOPE_VAR = 0b0000000000100,
  1422. BIND_SCOPE_LEXICAL = 0b0000000001000,
  1423. BIND_SCOPE_FUNCTION = 0b0000000010000,
  1424. BIND_FLAGS_NONE = 0b00000001000000,
  1425. BIND_FLAGS_CLASS = 0b00000010000000,
  1426. BIND_FLAGS_TS_ENUM = 0b00000100000000,
  1427. BIND_FLAGS_TS_CONST_ENUM = 0b00001000000000,
  1428. BIND_FLAGS_TS_EXPORT_ONLY = 0b00010000000000,
  1429. BIND_FLAGS_FLOW_DECLARE_FN = 0b00100000000000,
  1430. BIND_FLAGS_TS_IMPORT = 0b01000000000000,
  1431. BIND_FLAGS_NO_LET_IN_LEXICAL = 0b10000000000000;
  1432. const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS | BIND_FLAGS_NO_LET_IN_LEXICAL,
  1433. BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | BIND_FLAGS_NO_LET_IN_LEXICAL,
  1434. BIND_CATCH_PARAM = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0,
  1435. BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0,
  1436. BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0,
  1437. BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS,
  1438. BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0,
  1439. BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM | BIND_FLAGS_NO_LET_IN_LEXICAL,
  1440. BIND_TS_AMBIENT = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1441. BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE,
  1442. BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE,
  1443. BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM,
  1444. BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1445. BIND_TS_TYPE_IMPORT = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_TS_IMPORT,
  1446. BIND_FLOW_DECLARE_FN = BIND_FLAGS_FLOW_DECLARE_FN;
  1447. const CLASS_ELEMENT_FLAG_STATIC = 0b100,
  1448. CLASS_ELEMENT_KIND_GETTER = 0b010,
  1449. CLASS_ELEMENT_KIND_SETTER = 0b001,
  1450. CLASS_ELEMENT_KIND_ACCESSOR = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_KIND_SETTER;
  1451. const CLASS_ELEMENT_STATIC_GETTER = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_FLAG_STATIC,
  1452. CLASS_ELEMENT_STATIC_SETTER = CLASS_ELEMENT_KIND_SETTER | CLASS_ELEMENT_FLAG_STATIC,
  1453. CLASS_ELEMENT_INSTANCE_GETTER = CLASS_ELEMENT_KIND_GETTER,
  1454. CLASS_ELEMENT_INSTANCE_SETTER = CLASS_ELEMENT_KIND_SETTER,
  1455. CLASS_ELEMENT_OTHER = 0;
  1456. class Scope {
  1457. constructor(flags) {
  1458. this.var = new Set();
  1459. this.lexical = new Set();
  1460. this.functions = new Set();
  1461. this.flags = flags;
  1462. }
  1463. }
  1464. class ScopeHandler {
  1465. constructor(parser, inModule) {
  1466. this.parser = void 0;
  1467. this.scopeStack = [];
  1468. this.inModule = void 0;
  1469. this.undefinedExports = new Map();
  1470. this.parser = parser;
  1471. this.inModule = inModule;
  1472. }
  1473. get inTopLevel() {
  1474. return (this.currentScope().flags & SCOPE_PROGRAM) > 0;
  1475. }
  1476. get inFunction() {
  1477. return (this.currentVarScopeFlags() & SCOPE_FUNCTION) > 0;
  1478. }
  1479. get allowSuper() {
  1480. return (this.currentThisScopeFlags() & SCOPE_SUPER) > 0;
  1481. }
  1482. get allowDirectSuper() {
  1483. return (this.currentThisScopeFlags() & SCOPE_DIRECT_SUPER) > 0;
  1484. }
  1485. get inClass() {
  1486. return (this.currentThisScopeFlags() & SCOPE_CLASS) > 0;
  1487. }
  1488. get inClassAndNotInNonArrowFunction() {
  1489. const flags = this.currentThisScopeFlags();
  1490. return (flags & SCOPE_CLASS) > 0 && (flags & SCOPE_FUNCTION) === 0;
  1491. }
  1492. get inStaticBlock() {
  1493. for (let i = this.scopeStack.length - 1;; i--) {
  1494. const {
  1495. flags
  1496. } = this.scopeStack[i];
  1497. if (flags & SCOPE_STATIC_BLOCK) {
  1498. return true;
  1499. }
  1500. if (flags & (SCOPE_VAR | SCOPE_CLASS)) {
  1501. return false;
  1502. }
  1503. }
  1504. }
  1505. get inNonArrowFunction() {
  1506. return (this.currentThisScopeFlags() & SCOPE_FUNCTION) > 0;
  1507. }
  1508. get treatFunctionsAsVar() {
  1509. return this.treatFunctionsAsVarInScope(this.currentScope());
  1510. }
  1511. createScope(flags) {
  1512. return new Scope(flags);
  1513. }
  1514. enter(flags) {
  1515. this.scopeStack.push(this.createScope(flags));
  1516. }
  1517. exit() {
  1518. const scope = this.scopeStack.pop();
  1519. return scope.flags;
  1520. }
  1521. treatFunctionsAsVarInScope(scope) {
  1522. return !!(scope.flags & (SCOPE_FUNCTION | SCOPE_STATIC_BLOCK) || !this.parser.inModule && scope.flags & SCOPE_PROGRAM);
  1523. }
  1524. declareName(name, bindingType, loc) {
  1525. let scope = this.currentScope();
  1526. if (bindingType & BIND_SCOPE_LEXICAL || bindingType & BIND_SCOPE_FUNCTION) {
  1527. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1528. if (bindingType & BIND_SCOPE_FUNCTION) {
  1529. scope.functions.add(name);
  1530. } else {
  1531. scope.lexical.add(name);
  1532. }
  1533. if (bindingType & BIND_SCOPE_LEXICAL) {
  1534. this.maybeExportDefined(scope, name);
  1535. }
  1536. } else if (bindingType & BIND_SCOPE_VAR) {
  1537. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1538. scope = this.scopeStack[i];
  1539. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1540. scope.var.add(name);
  1541. this.maybeExportDefined(scope, name);
  1542. if (scope.flags & SCOPE_VAR) break;
  1543. }
  1544. }
  1545. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  1546. this.undefinedExports.delete(name);
  1547. }
  1548. }
  1549. maybeExportDefined(scope, name) {
  1550. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  1551. this.undefinedExports.delete(name);
  1552. }
  1553. }
  1554. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1555. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1556. this.parser.raise(Errors.VarRedeclaration, {
  1557. at: loc,
  1558. identifierName: name
  1559. });
  1560. }
  1561. }
  1562. isRedeclaredInScope(scope, name, bindingType) {
  1563. if (!(bindingType & BIND_KIND_VALUE)) return false;
  1564. if (bindingType & BIND_SCOPE_LEXICAL) {
  1565. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  1566. }
  1567. if (bindingType & BIND_SCOPE_FUNCTION) {
  1568. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  1569. }
  1570. return scope.lexical.has(name) && !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  1571. }
  1572. checkLocalExport(id) {
  1573. const {
  1574. name
  1575. } = id;
  1576. const topLevelScope = this.scopeStack[0];
  1577. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
  1578. this.undefinedExports.set(name, id.loc.start);
  1579. }
  1580. }
  1581. currentScope() {
  1582. return this.scopeStack[this.scopeStack.length - 1];
  1583. }
  1584. currentVarScopeFlags() {
  1585. for (let i = this.scopeStack.length - 1;; i--) {
  1586. const {
  1587. flags
  1588. } = this.scopeStack[i];
  1589. if (flags & SCOPE_VAR) {
  1590. return flags;
  1591. }
  1592. }
  1593. }
  1594. currentThisScopeFlags() {
  1595. for (let i = this.scopeStack.length - 1;; i--) {
  1596. const {
  1597. flags
  1598. } = this.scopeStack[i];
  1599. if (flags & (SCOPE_VAR | SCOPE_CLASS) && !(flags & SCOPE_ARROW)) {
  1600. return flags;
  1601. }
  1602. }
  1603. }
  1604. }
  1605. class FlowScope extends Scope {
  1606. constructor(...args) {
  1607. super(...args);
  1608. this.declareFunctions = new Set();
  1609. }
  1610. }
  1611. class FlowScopeHandler extends ScopeHandler {
  1612. createScope(flags) {
  1613. return new FlowScope(flags);
  1614. }
  1615. declareName(name, bindingType, loc) {
  1616. const scope = this.currentScope();
  1617. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  1618. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1619. this.maybeExportDefined(scope, name);
  1620. scope.declareFunctions.add(name);
  1621. return;
  1622. }
  1623. super.declareName(name, bindingType, loc);
  1624. }
  1625. isRedeclaredInScope(scope, name, bindingType) {
  1626. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1627. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  1628. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  1629. }
  1630. return false;
  1631. }
  1632. checkLocalExport(id) {
  1633. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1634. super.checkLocalExport(id);
  1635. }
  1636. }
  1637. }
  1638. class BaseParser {
  1639. constructor() {
  1640. this.sawUnambiguousESM = false;
  1641. this.ambiguousScriptDifferentAst = false;
  1642. }
  1643. hasPlugin(pluginConfig) {
  1644. if (typeof pluginConfig === "string") {
  1645. return this.plugins.has(pluginConfig);
  1646. } else {
  1647. const [pluginName, pluginOptions] = pluginConfig;
  1648. if (!this.hasPlugin(pluginName)) {
  1649. return false;
  1650. }
  1651. const actualOptions = this.plugins.get(pluginName);
  1652. for (const key of Object.keys(pluginOptions)) {
  1653. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1654. return false;
  1655. }
  1656. }
  1657. return true;
  1658. }
  1659. }
  1660. getPluginOption(plugin, name) {
  1661. var _this$plugins$get;
  1662. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1663. }
  1664. }
  1665. function setTrailingComments(node, comments) {
  1666. if (node.trailingComments === undefined) {
  1667. node.trailingComments = comments;
  1668. } else {
  1669. node.trailingComments.unshift(...comments);
  1670. }
  1671. }
  1672. function setLeadingComments(node, comments) {
  1673. if (node.leadingComments === undefined) {
  1674. node.leadingComments = comments;
  1675. } else {
  1676. node.leadingComments.unshift(...comments);
  1677. }
  1678. }
  1679. function setInnerComments(node, comments) {
  1680. if (node.innerComments === undefined) {
  1681. node.innerComments = comments;
  1682. } else {
  1683. node.innerComments.unshift(...comments);
  1684. }
  1685. }
  1686. function adjustInnerComments(node, elements, commentWS) {
  1687. let lastElement = null;
  1688. let i = elements.length;
  1689. while (lastElement === null && i > 0) {
  1690. lastElement = elements[--i];
  1691. }
  1692. if (lastElement === null || lastElement.start > commentWS.start) {
  1693. setInnerComments(node, commentWS.comments);
  1694. } else {
  1695. setTrailingComments(lastElement, commentWS.comments);
  1696. }
  1697. }
  1698. class CommentsParser extends BaseParser {
  1699. addComment(comment) {
  1700. if (this.filename) comment.loc.filename = this.filename;
  1701. this.state.comments.push(comment);
  1702. }
  1703. processComment(node) {
  1704. const {
  1705. commentStack
  1706. } = this.state;
  1707. const commentStackLength = commentStack.length;
  1708. if (commentStackLength === 0) return;
  1709. let i = commentStackLength - 1;
  1710. const lastCommentWS = commentStack[i];
  1711. if (lastCommentWS.start === node.end) {
  1712. lastCommentWS.leadingNode = node;
  1713. i--;
  1714. }
  1715. const {
  1716. start: nodeStart
  1717. } = node;
  1718. for (; i >= 0; i--) {
  1719. const commentWS = commentStack[i];
  1720. const commentEnd = commentWS.end;
  1721. if (commentEnd > nodeStart) {
  1722. commentWS.containingNode = node;
  1723. this.finalizeComment(commentWS);
  1724. commentStack.splice(i, 1);
  1725. } else {
  1726. if (commentEnd === nodeStart) {
  1727. commentWS.trailingNode = node;
  1728. }
  1729. break;
  1730. }
  1731. }
  1732. }
  1733. finalizeComment(commentWS) {
  1734. const {
  1735. comments
  1736. } = commentWS;
  1737. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1738. if (commentWS.leadingNode !== null) {
  1739. setTrailingComments(commentWS.leadingNode, comments);
  1740. }
  1741. if (commentWS.trailingNode !== null) {
  1742. setLeadingComments(commentWS.trailingNode, comments);
  1743. }
  1744. } else {
  1745. const {
  1746. containingNode: node,
  1747. start: commentStart
  1748. } = commentWS;
  1749. if (this.input.charCodeAt(commentStart - 1) === 44) {
  1750. switch (node.type) {
  1751. case "ObjectExpression":
  1752. case "ObjectPattern":
  1753. case "RecordExpression":
  1754. adjustInnerComments(node, node.properties, commentWS);
  1755. break;
  1756. case "CallExpression":
  1757. case "OptionalCallExpression":
  1758. adjustInnerComments(node, node.arguments, commentWS);
  1759. break;
  1760. case "FunctionDeclaration":
  1761. case "FunctionExpression":
  1762. case "ArrowFunctionExpression":
  1763. case "ObjectMethod":
  1764. case "ClassMethod":
  1765. case "ClassPrivateMethod":
  1766. adjustInnerComments(node, node.params, commentWS);
  1767. break;
  1768. case "ArrayExpression":
  1769. case "ArrayPattern":
  1770. case "TupleExpression":
  1771. adjustInnerComments(node, node.elements, commentWS);
  1772. break;
  1773. case "ExportNamedDeclaration":
  1774. case "ImportDeclaration":
  1775. adjustInnerComments(node, node.specifiers, commentWS);
  1776. break;
  1777. default:
  1778. {
  1779. setInnerComments(node, comments);
  1780. }
  1781. }
  1782. } else {
  1783. setInnerComments(node, comments);
  1784. }
  1785. }
  1786. }
  1787. finalizeRemainingComments() {
  1788. const {
  1789. commentStack
  1790. } = this.state;
  1791. for (let i = commentStack.length - 1; i >= 0; i--) {
  1792. this.finalizeComment(commentStack[i]);
  1793. }
  1794. this.state.commentStack = [];
  1795. }
  1796. resetPreviousNodeTrailingComments(node) {
  1797. const {
  1798. commentStack
  1799. } = this.state;
  1800. const {
  1801. length
  1802. } = commentStack;
  1803. if (length === 0) return;
  1804. const commentWS = commentStack[length - 1];
  1805. if (commentWS.leadingNode === node) {
  1806. commentWS.leadingNode = null;
  1807. }
  1808. }
  1809. takeSurroundingComments(node, start, end) {
  1810. const {
  1811. commentStack
  1812. } = this.state;
  1813. const commentStackLength = commentStack.length;
  1814. if (commentStackLength === 0) return;
  1815. let i = commentStackLength - 1;
  1816. for (; i >= 0; i--) {
  1817. const commentWS = commentStack[i];
  1818. const commentEnd = commentWS.end;
  1819. const commentStart = commentWS.start;
  1820. if (commentStart === end) {
  1821. commentWS.leadingNode = node;
  1822. } else if (commentEnd === start) {
  1823. commentWS.trailingNode = node;
  1824. } else if (commentEnd < start) {
  1825. break;
  1826. }
  1827. }
  1828. }
  1829. }
  1830. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  1831. const lineBreakG = new RegExp(lineBreak.source, "g");
  1832. function isNewLine(code) {
  1833. switch (code) {
  1834. case 10:
  1835. case 13:
  1836. case 8232:
  1837. case 8233:
  1838. return true;
  1839. default:
  1840. return false;
  1841. }
  1842. }
  1843. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1844. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1845. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  1846. function isWhitespace(code) {
  1847. switch (code) {
  1848. case 0x0009:
  1849. case 0x000b:
  1850. case 0x000c:
  1851. case 32:
  1852. case 160:
  1853. case 5760:
  1854. case 0x2000:
  1855. case 0x2001:
  1856. case 0x2002:
  1857. case 0x2003:
  1858. case 0x2004:
  1859. case 0x2005:
  1860. case 0x2006:
  1861. case 0x2007:
  1862. case 0x2008:
  1863. case 0x2009:
  1864. case 0x200a:
  1865. case 0x202f:
  1866. case 0x205f:
  1867. case 0x3000:
  1868. case 0xfeff:
  1869. return true;
  1870. default:
  1871. return false;
  1872. }
  1873. }
  1874. class State {
  1875. constructor() {
  1876. this.strict = void 0;
  1877. this.curLine = void 0;
  1878. this.lineStart = void 0;
  1879. this.startLoc = void 0;
  1880. this.endLoc = void 0;
  1881. this.errors = [];
  1882. this.potentialArrowAt = -1;
  1883. this.noArrowAt = [];
  1884. this.noArrowParamsConversionAt = [];
  1885. this.maybeInArrowParameters = false;
  1886. this.inType = false;
  1887. this.noAnonFunctionType = false;
  1888. this.hasFlowComment = false;
  1889. this.isAmbientContext = false;
  1890. this.inAbstractClass = false;
  1891. this.inDisallowConditionalTypesContext = false;
  1892. this.topicContext = {
  1893. maxNumOfResolvableTopics: 0,
  1894. maxTopicIndex: null
  1895. };
  1896. this.soloAwait = false;
  1897. this.inFSharpPipelineDirectBody = false;
  1898. this.labels = [];
  1899. this.comments = [];
  1900. this.commentStack = [];
  1901. this.pos = 0;
  1902. this.type = 137;
  1903. this.value = null;
  1904. this.start = 0;
  1905. this.end = 0;
  1906. this.lastTokEndLoc = null;
  1907. this.lastTokStartLoc = null;
  1908. this.lastTokStart = 0;
  1909. this.context = [types.brace];
  1910. this.canStartJSXElement = true;
  1911. this.containsEsc = false;
  1912. this.firstInvalidTemplateEscapePos = null;
  1913. this.strictErrors = new Map();
  1914. this.tokensLength = 0;
  1915. }
  1916. init({
  1917. strictMode,
  1918. sourceType,
  1919. startLine,
  1920. startColumn
  1921. }) {
  1922. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1923. this.curLine = startLine;
  1924. this.lineStart = -startColumn;
  1925. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  1926. }
  1927. curPosition() {
  1928. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  1929. }
  1930. clone(skipArrays) {
  1931. const state = new State();
  1932. const keys = Object.keys(this);
  1933. for (let i = 0, length = keys.length; i < length; i++) {
  1934. const key = keys[i];
  1935. let val = this[key];
  1936. if (!skipArrays && Array.isArray(val)) {
  1937. val = val.slice();
  1938. }
  1939. state[key] = val;
  1940. }
  1941. return state;
  1942. }
  1943. }
  1944. var _isDigit = function isDigit(code) {
  1945. return code >= 48 && code <= 57;
  1946. };
  1947. const forbiddenNumericSeparatorSiblings = {
  1948. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  1949. hex: new Set([46, 88, 95, 120])
  1950. };
  1951. const isAllowedNumericSeparatorSibling = {
  1952. bin: ch => ch === 48 || ch === 49,
  1953. oct: ch => ch >= 48 && ch <= 55,
  1954. dec: ch => ch >= 48 && ch <= 57,
  1955. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  1956. };
  1957. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  1958. const initialPos = pos;
  1959. const initialLineStart = lineStart;
  1960. const initialCurLine = curLine;
  1961. let out = "";
  1962. let firstInvalidLoc = null;
  1963. let chunkStart = pos;
  1964. const {
  1965. length
  1966. } = input;
  1967. for (;;) {
  1968. if (pos >= length) {
  1969. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1970. out += input.slice(chunkStart, pos);
  1971. break;
  1972. }
  1973. const ch = input.charCodeAt(pos);
  1974. if (isStringEnd(type, ch, input, pos)) {
  1975. out += input.slice(chunkStart, pos);
  1976. break;
  1977. }
  1978. if (ch === 92) {
  1979. out += input.slice(chunkStart, pos);
  1980. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  1981. if (res.ch === null && !firstInvalidLoc) {
  1982. firstInvalidLoc = {
  1983. pos,
  1984. lineStart,
  1985. curLine
  1986. };
  1987. } else {
  1988. out += res.ch;
  1989. }
  1990. ({
  1991. pos,
  1992. lineStart,
  1993. curLine
  1994. } = res);
  1995. chunkStart = pos;
  1996. } else if (ch === 8232 || ch === 8233) {
  1997. ++pos;
  1998. ++curLine;
  1999. lineStart = pos;
  2000. } else if (ch === 10 || ch === 13) {
  2001. if (type === "template") {
  2002. out += input.slice(chunkStart, pos) + "\n";
  2003. ++pos;
  2004. if (ch === 13 && input.charCodeAt(pos) === 10) {
  2005. ++pos;
  2006. }
  2007. ++curLine;
  2008. chunkStart = lineStart = pos;
  2009. } else {
  2010. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2011. }
  2012. } else {
  2013. ++pos;
  2014. }
  2015. }
  2016. return {
  2017. pos,
  2018. str: out,
  2019. firstInvalidLoc,
  2020. lineStart,
  2021. curLine,
  2022. containsInvalid: !!firstInvalidLoc
  2023. };
  2024. }
  2025. function isStringEnd(type, ch, input, pos) {
  2026. if (type === "template") {
  2027. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2028. }
  2029. return ch === (type === "double" ? 34 : 39);
  2030. }
  2031. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2032. const throwOnInvalid = !inTemplate;
  2033. pos++;
  2034. const res = ch => ({
  2035. pos,
  2036. ch,
  2037. lineStart,
  2038. curLine
  2039. });
  2040. const ch = input.charCodeAt(pos++);
  2041. switch (ch) {
  2042. case 110:
  2043. return res("\n");
  2044. case 114:
  2045. return res("\r");
  2046. case 120:
  2047. {
  2048. let code;
  2049. ({
  2050. code,
  2051. pos
  2052. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2053. return res(code === null ? null : String.fromCharCode(code));
  2054. }
  2055. case 117:
  2056. {
  2057. let code;
  2058. ({
  2059. code,
  2060. pos
  2061. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2062. return res(code === null ? null : String.fromCodePoint(code));
  2063. }
  2064. case 116:
  2065. return res("\t");
  2066. case 98:
  2067. return res("\b");
  2068. case 118:
  2069. return res("\u000b");
  2070. case 102:
  2071. return res("\f");
  2072. case 13:
  2073. if (input.charCodeAt(pos) === 10) {
  2074. ++pos;
  2075. }
  2076. case 10:
  2077. lineStart = pos;
  2078. ++curLine;
  2079. case 8232:
  2080. case 8233:
  2081. return res("");
  2082. case 56:
  2083. case 57:
  2084. if (inTemplate) {
  2085. return res(null);
  2086. } else {
  2087. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2088. }
  2089. default:
  2090. if (ch >= 48 && ch <= 55) {
  2091. const startPos = pos - 1;
  2092. const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
  2093. let octalStr = match[0];
  2094. let octal = parseInt(octalStr, 8);
  2095. if (octal > 255) {
  2096. octalStr = octalStr.slice(0, -1);
  2097. octal = parseInt(octalStr, 8);
  2098. }
  2099. pos += octalStr.length - 1;
  2100. const next = input.charCodeAt(pos);
  2101. if (octalStr !== "0" || next === 56 || next === 57) {
  2102. if (inTemplate) {
  2103. return res(null);
  2104. } else {
  2105. errors.strictNumericEscape(startPos, lineStart, curLine);
  2106. }
  2107. }
  2108. return res(String.fromCharCode(octal));
  2109. }
  2110. return res(String.fromCharCode(ch));
  2111. }
  2112. }
  2113. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2114. const initialPos = pos;
  2115. let n;
  2116. ({
  2117. n,
  2118. pos
  2119. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2120. if (n === null) {
  2121. if (throwOnInvalid) {
  2122. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2123. } else {
  2124. pos = initialPos - 1;
  2125. }
  2126. }
  2127. return {
  2128. code: n,
  2129. pos
  2130. };
  2131. }
  2132. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2133. const start = pos;
  2134. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2135. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2136. let invalid = false;
  2137. let total = 0;
  2138. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2139. const code = input.charCodeAt(pos);
  2140. let val;
  2141. if (code === 95 && allowNumSeparator !== "bail") {
  2142. const prev = input.charCodeAt(pos - 1);
  2143. const next = input.charCodeAt(pos + 1);
  2144. if (!allowNumSeparator) {
  2145. if (bailOnError) return {
  2146. n: null,
  2147. pos
  2148. };
  2149. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2150. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2151. if (bailOnError) return {
  2152. n: null,
  2153. pos
  2154. };
  2155. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2156. }
  2157. ++pos;
  2158. continue;
  2159. }
  2160. if (code >= 97) {
  2161. val = code - 97 + 10;
  2162. } else if (code >= 65) {
  2163. val = code - 65 + 10;
  2164. } else if (_isDigit(code)) {
  2165. val = code - 48;
  2166. } else {
  2167. val = Infinity;
  2168. }
  2169. if (val >= radix) {
  2170. if (val <= 9 && bailOnError) {
  2171. return {
  2172. n: null,
  2173. pos
  2174. };
  2175. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2176. val = 0;
  2177. } else if (forceLen) {
  2178. val = 0;
  2179. invalid = true;
  2180. } else {
  2181. break;
  2182. }
  2183. }
  2184. ++pos;
  2185. total = total * radix + val;
  2186. }
  2187. if (pos === start || len != null && pos - start !== len || invalid) {
  2188. return {
  2189. n: null,
  2190. pos
  2191. };
  2192. }
  2193. return {
  2194. n: total,
  2195. pos
  2196. };
  2197. }
  2198. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2199. const ch = input.charCodeAt(pos);
  2200. let code;
  2201. if (ch === 123) {
  2202. ++pos;
  2203. ({
  2204. code,
  2205. pos
  2206. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2207. ++pos;
  2208. if (code !== null && code > 0x10ffff) {
  2209. if (throwOnInvalid) {
  2210. errors.invalidCodePoint(pos, lineStart, curLine);
  2211. } else {
  2212. return {
  2213. code: null,
  2214. pos
  2215. };
  2216. }
  2217. }
  2218. } else {
  2219. ({
  2220. code,
  2221. pos
  2222. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2223. }
  2224. return {
  2225. code,
  2226. pos
  2227. };
  2228. }
  2229. const _excluded = ["at"],
  2230. _excluded2 = ["at"];
  2231. function buildPosition(pos, lineStart, curLine) {
  2232. return new Position(curLine, pos - lineStart, pos);
  2233. }
  2234. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2235. class Token {
  2236. constructor(state) {
  2237. this.type = state.type;
  2238. this.value = state.value;
  2239. this.start = state.start;
  2240. this.end = state.end;
  2241. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2242. }
  2243. }
  2244. class Tokenizer extends CommentsParser {
  2245. constructor(options, input) {
  2246. super();
  2247. this.isLookahead = void 0;
  2248. this.tokens = [];
  2249. this.errorHandlers_readInt = {
  2250. invalidDigit: (pos, lineStart, curLine, radix) => {
  2251. if (!this.options.errorRecovery) return false;
  2252. this.raise(Errors.InvalidDigit, {
  2253. at: buildPosition(pos, lineStart, curLine),
  2254. radix
  2255. });
  2256. return true;
  2257. },
  2258. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2259. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2260. };
  2261. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2262. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2263. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2264. });
  2265. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2266. strictNumericEscape: (pos, lineStart, curLine) => {
  2267. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2268. at: buildPosition(pos, lineStart, curLine)
  2269. });
  2270. },
  2271. unterminated: (pos, lineStart, curLine) => {
  2272. throw this.raise(Errors.UnterminatedString, {
  2273. at: buildPosition(pos - 1, lineStart, curLine)
  2274. });
  2275. }
  2276. });
  2277. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2278. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2279. unterminated: (pos, lineStart, curLine) => {
  2280. throw this.raise(Errors.UnterminatedTemplate, {
  2281. at: buildPosition(pos, lineStart, curLine)
  2282. });
  2283. }
  2284. });
  2285. this.state = new State();
  2286. this.state.init(options);
  2287. this.input = input;
  2288. this.length = input.length;
  2289. this.isLookahead = false;
  2290. }
  2291. pushToken(token) {
  2292. this.tokens.length = this.state.tokensLength;
  2293. this.tokens.push(token);
  2294. ++this.state.tokensLength;
  2295. }
  2296. next() {
  2297. this.checkKeywordEscapes();
  2298. if (this.options.tokens) {
  2299. this.pushToken(new Token(this.state));
  2300. }
  2301. this.state.lastTokStart = this.state.start;
  2302. this.state.lastTokEndLoc = this.state.endLoc;
  2303. this.state.lastTokStartLoc = this.state.startLoc;
  2304. this.nextToken();
  2305. }
  2306. eat(type) {
  2307. if (this.match(type)) {
  2308. this.next();
  2309. return true;
  2310. } else {
  2311. return false;
  2312. }
  2313. }
  2314. match(type) {
  2315. return this.state.type === type;
  2316. }
  2317. createLookaheadState(state) {
  2318. return {
  2319. pos: state.pos,
  2320. value: null,
  2321. type: state.type,
  2322. start: state.start,
  2323. end: state.end,
  2324. context: [this.curContext()],
  2325. inType: state.inType,
  2326. startLoc: state.startLoc,
  2327. lastTokEndLoc: state.lastTokEndLoc,
  2328. curLine: state.curLine,
  2329. lineStart: state.lineStart,
  2330. curPosition: state.curPosition
  2331. };
  2332. }
  2333. lookahead() {
  2334. const old = this.state;
  2335. this.state = this.createLookaheadState(old);
  2336. this.isLookahead = true;
  2337. this.nextToken();
  2338. this.isLookahead = false;
  2339. const curr = this.state;
  2340. this.state = old;
  2341. return curr;
  2342. }
  2343. nextTokenStart() {
  2344. return this.nextTokenStartSince(this.state.pos);
  2345. }
  2346. nextTokenStartSince(pos) {
  2347. skipWhiteSpace.lastIndex = pos;
  2348. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2349. }
  2350. lookaheadCharCode() {
  2351. return this.input.charCodeAt(this.nextTokenStart());
  2352. }
  2353. nextTokenInLineStart() {
  2354. return this.nextTokenInLineStartSince(this.state.pos);
  2355. }
  2356. nextTokenInLineStartSince(pos) {
  2357. skipWhiteSpaceInLine.lastIndex = pos;
  2358. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2359. }
  2360. lookaheadInLineCharCode() {
  2361. return this.input.charCodeAt(this.nextTokenInLineStart());
  2362. }
  2363. codePointAtPos(pos) {
  2364. let cp = this.input.charCodeAt(pos);
  2365. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2366. const trail = this.input.charCodeAt(pos);
  2367. if ((trail & 0xfc00) === 0xdc00) {
  2368. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2369. }
  2370. }
  2371. return cp;
  2372. }
  2373. setStrict(strict) {
  2374. this.state.strict = strict;
  2375. if (strict) {
  2376. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
  2377. at
  2378. }));
  2379. this.state.strictErrors.clear();
  2380. }
  2381. }
  2382. curContext() {
  2383. return this.state.context[this.state.context.length - 1];
  2384. }
  2385. nextToken() {
  2386. this.skipSpace();
  2387. this.state.start = this.state.pos;
  2388. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2389. if (this.state.pos >= this.length) {
  2390. this.finishToken(137);
  2391. return;
  2392. }
  2393. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2394. }
  2395. skipBlockComment(commentEnd) {
  2396. let startLoc;
  2397. if (!this.isLookahead) startLoc = this.state.curPosition();
  2398. const start = this.state.pos;
  2399. const end = this.input.indexOf(commentEnd, start + 2);
  2400. if (end === -1) {
  2401. throw this.raise(Errors.UnterminatedComment, {
  2402. at: this.state.curPosition()
  2403. });
  2404. }
  2405. this.state.pos = end + commentEnd.length;
  2406. lineBreakG.lastIndex = start + 2;
  2407. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2408. ++this.state.curLine;
  2409. this.state.lineStart = lineBreakG.lastIndex;
  2410. }
  2411. if (this.isLookahead) return;
  2412. const comment = {
  2413. type: "CommentBlock",
  2414. value: this.input.slice(start + 2, end),
  2415. start,
  2416. end: end + commentEnd.length,
  2417. loc: new SourceLocation(startLoc, this.state.curPosition())
  2418. };
  2419. if (this.options.tokens) this.pushToken(comment);
  2420. return comment;
  2421. }
  2422. skipLineComment(startSkip) {
  2423. const start = this.state.pos;
  2424. let startLoc;
  2425. if (!this.isLookahead) startLoc = this.state.curPosition();
  2426. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2427. if (this.state.pos < this.length) {
  2428. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2429. ch = this.input.charCodeAt(this.state.pos);
  2430. }
  2431. }
  2432. if (this.isLookahead) return;
  2433. const end = this.state.pos;
  2434. const value = this.input.slice(start + startSkip, end);
  2435. const comment = {
  2436. type: "CommentLine",
  2437. value,
  2438. start,
  2439. end,
  2440. loc: new SourceLocation(startLoc, this.state.curPosition())
  2441. };
  2442. if (this.options.tokens) this.pushToken(comment);
  2443. return comment;
  2444. }
  2445. skipSpace() {
  2446. const spaceStart = this.state.pos;
  2447. const comments = [];
  2448. loop: while (this.state.pos < this.length) {
  2449. const ch = this.input.charCodeAt(this.state.pos);
  2450. switch (ch) {
  2451. case 32:
  2452. case 160:
  2453. case 9:
  2454. ++this.state.pos;
  2455. break;
  2456. case 13:
  2457. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2458. ++this.state.pos;
  2459. }
  2460. case 10:
  2461. case 8232:
  2462. case 8233:
  2463. ++this.state.pos;
  2464. ++this.state.curLine;
  2465. this.state.lineStart = this.state.pos;
  2466. break;
  2467. case 47:
  2468. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2469. case 42:
  2470. {
  2471. const comment = this.skipBlockComment("*/");
  2472. if (comment !== undefined) {
  2473. this.addComment(comment);
  2474. if (this.options.attachComment) comments.push(comment);
  2475. }
  2476. break;
  2477. }
  2478. case 47:
  2479. {
  2480. const comment = this.skipLineComment(2);
  2481. if (comment !== undefined) {
  2482. this.addComment(comment);
  2483. if (this.options.attachComment) comments.push(comment);
  2484. }
  2485. break;
  2486. }
  2487. default:
  2488. break loop;
  2489. }
  2490. break;
  2491. default:
  2492. if (isWhitespace(ch)) {
  2493. ++this.state.pos;
  2494. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  2495. const pos = this.state.pos;
  2496. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2497. const comment = this.skipLineComment(3);
  2498. if (comment !== undefined) {
  2499. this.addComment(comment);
  2500. if (this.options.attachComment) comments.push(comment);
  2501. }
  2502. } else {
  2503. break loop;
  2504. }
  2505. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  2506. const pos = this.state.pos;
  2507. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2508. const comment = this.skipLineComment(4);
  2509. if (comment !== undefined) {
  2510. this.addComment(comment);
  2511. if (this.options.attachComment) comments.push(comment);
  2512. }
  2513. } else {
  2514. break loop;
  2515. }
  2516. } else {
  2517. break loop;
  2518. }
  2519. }
  2520. }
  2521. if (comments.length > 0) {
  2522. const end = this.state.pos;
  2523. const commentWhitespace = {
  2524. start: spaceStart,
  2525. end,
  2526. comments,
  2527. leadingNode: null,
  2528. trailingNode: null,
  2529. containingNode: null
  2530. };
  2531. this.state.commentStack.push(commentWhitespace);
  2532. }
  2533. }
  2534. finishToken(type, val) {
  2535. this.state.end = this.state.pos;
  2536. this.state.endLoc = this.state.curPosition();
  2537. const prevType = this.state.type;
  2538. this.state.type = type;
  2539. this.state.value = val;
  2540. if (!this.isLookahead) {
  2541. this.updateContext(prevType);
  2542. }
  2543. }
  2544. replaceToken(type) {
  2545. this.state.type = type;
  2546. this.updateContext();
  2547. }
  2548. readToken_numberSign() {
  2549. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2550. return;
  2551. }
  2552. const nextPos = this.state.pos + 1;
  2553. const next = this.codePointAtPos(nextPos);
  2554. if (next >= 48 && next <= 57) {
  2555. throw this.raise(Errors.UnexpectedDigitAfterHash, {
  2556. at: this.state.curPosition()
  2557. });
  2558. }
  2559. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2560. this.expectPlugin("recordAndTuple");
  2561. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2562. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
  2563. at: this.state.curPosition()
  2564. });
  2565. }
  2566. this.state.pos += 2;
  2567. if (next === 123) {
  2568. this.finishToken(7);
  2569. } else {
  2570. this.finishToken(1);
  2571. }
  2572. } else if (isIdentifierStart(next)) {
  2573. ++this.state.pos;
  2574. this.finishToken(136, this.readWord1(next));
  2575. } else if (next === 92) {
  2576. ++this.state.pos;
  2577. this.finishToken(136, this.readWord1());
  2578. } else {
  2579. this.finishOp(27, 1);
  2580. }
  2581. }
  2582. readToken_dot() {
  2583. const next = this.input.charCodeAt(this.state.pos + 1);
  2584. if (next >= 48 && next <= 57) {
  2585. this.readNumber(true);
  2586. return;
  2587. }
  2588. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2589. this.state.pos += 3;
  2590. this.finishToken(21);
  2591. } else {
  2592. ++this.state.pos;
  2593. this.finishToken(16);
  2594. }
  2595. }
  2596. readToken_slash() {
  2597. const next = this.input.charCodeAt(this.state.pos + 1);
  2598. if (next === 61) {
  2599. this.finishOp(31, 2);
  2600. } else {
  2601. this.finishOp(56, 1);
  2602. }
  2603. }
  2604. readToken_interpreter() {
  2605. if (this.state.pos !== 0 || this.length < 2) return false;
  2606. let ch = this.input.charCodeAt(this.state.pos + 1);
  2607. if (ch !== 33) return false;
  2608. const start = this.state.pos;
  2609. this.state.pos += 1;
  2610. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2611. ch = this.input.charCodeAt(this.state.pos);
  2612. }
  2613. const value = this.input.slice(start + 2, this.state.pos);
  2614. this.finishToken(28, value);
  2615. return true;
  2616. }
  2617. readToken_mult_modulo(code) {
  2618. let type = code === 42 ? 55 : 54;
  2619. let width = 1;
  2620. let next = this.input.charCodeAt(this.state.pos + 1);
  2621. if (code === 42 && next === 42) {
  2622. width++;
  2623. next = this.input.charCodeAt(this.state.pos + 2);
  2624. type = 57;
  2625. }
  2626. if (next === 61 && !this.state.inType) {
  2627. width++;
  2628. type = code === 37 ? 33 : 30;
  2629. }
  2630. this.finishOp(type, width);
  2631. }
  2632. readToken_pipe_amp(code) {
  2633. const next = this.input.charCodeAt(this.state.pos + 1);
  2634. if (next === code) {
  2635. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2636. this.finishOp(30, 3);
  2637. } else {
  2638. this.finishOp(code === 124 ? 41 : 42, 2);
  2639. }
  2640. return;
  2641. }
  2642. if (code === 124) {
  2643. if (next === 62) {
  2644. this.finishOp(39, 2);
  2645. return;
  2646. }
  2647. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2648. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2649. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
  2650. at: this.state.curPosition()
  2651. });
  2652. }
  2653. this.state.pos += 2;
  2654. this.finishToken(9);
  2655. return;
  2656. }
  2657. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2658. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2659. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
  2660. at: this.state.curPosition()
  2661. });
  2662. }
  2663. this.state.pos += 2;
  2664. this.finishToken(4);
  2665. return;
  2666. }
  2667. }
  2668. if (next === 61) {
  2669. this.finishOp(30, 2);
  2670. return;
  2671. }
  2672. this.finishOp(code === 124 ? 43 : 45, 1);
  2673. }
  2674. readToken_caret() {
  2675. const next = this.input.charCodeAt(this.state.pos + 1);
  2676. if (next === 61 && !this.state.inType) {
  2677. this.finishOp(32, 2);
  2678. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2679. proposal: "hack",
  2680. topicToken: "^^"
  2681. }])) {
  2682. this.finishOp(37, 2);
  2683. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2684. if (lookaheadCh === 94) {
  2685. this.unexpected();
  2686. }
  2687. } else {
  2688. this.finishOp(44, 1);
  2689. }
  2690. }
  2691. readToken_atSign() {
  2692. const next = this.input.charCodeAt(this.state.pos + 1);
  2693. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2694. proposal: "hack",
  2695. topicToken: "@@"
  2696. }])) {
  2697. this.finishOp(38, 2);
  2698. } else {
  2699. this.finishOp(26, 1);
  2700. }
  2701. }
  2702. readToken_plus_min(code) {
  2703. const next = this.input.charCodeAt(this.state.pos + 1);
  2704. if (next === code) {
  2705. this.finishOp(34, 2);
  2706. return;
  2707. }
  2708. if (next === 61) {
  2709. this.finishOp(30, 2);
  2710. } else {
  2711. this.finishOp(53, 1);
  2712. }
  2713. }
  2714. readToken_lt() {
  2715. const {
  2716. pos
  2717. } = this.state;
  2718. const next = this.input.charCodeAt(pos + 1);
  2719. if (next === 60) {
  2720. if (this.input.charCodeAt(pos + 2) === 61) {
  2721. this.finishOp(30, 3);
  2722. return;
  2723. }
  2724. this.finishOp(51, 2);
  2725. return;
  2726. }
  2727. if (next === 61) {
  2728. this.finishOp(49, 2);
  2729. return;
  2730. }
  2731. this.finishOp(47, 1);
  2732. }
  2733. readToken_gt() {
  2734. const {
  2735. pos
  2736. } = this.state;
  2737. const next = this.input.charCodeAt(pos + 1);
  2738. if (next === 62) {
  2739. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2740. if (this.input.charCodeAt(pos + size) === 61) {
  2741. this.finishOp(30, size + 1);
  2742. return;
  2743. }
  2744. this.finishOp(52, size);
  2745. return;
  2746. }
  2747. if (next === 61) {
  2748. this.finishOp(49, 2);
  2749. return;
  2750. }
  2751. this.finishOp(48, 1);
  2752. }
  2753. readToken_eq_excl(code) {
  2754. const next = this.input.charCodeAt(this.state.pos + 1);
  2755. if (next === 61) {
  2756. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2757. return;
  2758. }
  2759. if (code === 61 && next === 62) {
  2760. this.state.pos += 2;
  2761. this.finishToken(19);
  2762. return;
  2763. }
  2764. this.finishOp(code === 61 ? 29 : 35, 1);
  2765. }
  2766. readToken_question() {
  2767. const next = this.input.charCodeAt(this.state.pos + 1);
  2768. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2769. if (next === 63) {
  2770. if (next2 === 61) {
  2771. this.finishOp(30, 3);
  2772. } else {
  2773. this.finishOp(40, 2);
  2774. }
  2775. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2776. this.state.pos += 2;
  2777. this.finishToken(18);
  2778. } else {
  2779. ++this.state.pos;
  2780. this.finishToken(17);
  2781. }
  2782. }
  2783. getTokenFromCode(code) {
  2784. switch (code) {
  2785. case 46:
  2786. this.readToken_dot();
  2787. return;
  2788. case 40:
  2789. ++this.state.pos;
  2790. this.finishToken(10);
  2791. return;
  2792. case 41:
  2793. ++this.state.pos;
  2794. this.finishToken(11);
  2795. return;
  2796. case 59:
  2797. ++this.state.pos;
  2798. this.finishToken(13);
  2799. return;
  2800. case 44:
  2801. ++this.state.pos;
  2802. this.finishToken(12);
  2803. return;
  2804. case 91:
  2805. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2806. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2807. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
  2808. at: this.state.curPosition()
  2809. });
  2810. }
  2811. this.state.pos += 2;
  2812. this.finishToken(2);
  2813. } else {
  2814. ++this.state.pos;
  2815. this.finishToken(0);
  2816. }
  2817. return;
  2818. case 93:
  2819. ++this.state.pos;
  2820. this.finishToken(3);
  2821. return;
  2822. case 123:
  2823. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2824. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2825. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
  2826. at: this.state.curPosition()
  2827. });
  2828. }
  2829. this.state.pos += 2;
  2830. this.finishToken(6);
  2831. } else {
  2832. ++this.state.pos;
  2833. this.finishToken(5);
  2834. }
  2835. return;
  2836. case 125:
  2837. ++this.state.pos;
  2838. this.finishToken(8);
  2839. return;
  2840. case 58:
  2841. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2842. this.finishOp(15, 2);
  2843. } else {
  2844. ++this.state.pos;
  2845. this.finishToken(14);
  2846. }
  2847. return;
  2848. case 63:
  2849. this.readToken_question();
  2850. return;
  2851. case 96:
  2852. this.readTemplateToken();
  2853. return;
  2854. case 48:
  2855. {
  2856. const next = this.input.charCodeAt(this.state.pos + 1);
  2857. if (next === 120 || next === 88) {
  2858. this.readRadixNumber(16);
  2859. return;
  2860. }
  2861. if (next === 111 || next === 79) {
  2862. this.readRadixNumber(8);
  2863. return;
  2864. }
  2865. if (next === 98 || next === 66) {
  2866. this.readRadixNumber(2);
  2867. return;
  2868. }
  2869. }
  2870. case 49:
  2871. case 50:
  2872. case 51:
  2873. case 52:
  2874. case 53:
  2875. case 54:
  2876. case 55:
  2877. case 56:
  2878. case 57:
  2879. this.readNumber(false);
  2880. return;
  2881. case 34:
  2882. case 39:
  2883. this.readString(code);
  2884. return;
  2885. case 47:
  2886. this.readToken_slash();
  2887. return;
  2888. case 37:
  2889. case 42:
  2890. this.readToken_mult_modulo(code);
  2891. return;
  2892. case 124:
  2893. case 38:
  2894. this.readToken_pipe_amp(code);
  2895. return;
  2896. case 94:
  2897. this.readToken_caret();
  2898. return;
  2899. case 43:
  2900. case 45:
  2901. this.readToken_plus_min(code);
  2902. return;
  2903. case 60:
  2904. this.readToken_lt();
  2905. return;
  2906. case 62:
  2907. this.readToken_gt();
  2908. return;
  2909. case 61:
  2910. case 33:
  2911. this.readToken_eq_excl(code);
  2912. return;
  2913. case 126:
  2914. this.finishOp(36, 1);
  2915. return;
  2916. case 64:
  2917. this.readToken_atSign();
  2918. return;
  2919. case 35:
  2920. this.readToken_numberSign();
  2921. return;
  2922. case 92:
  2923. this.readWord();
  2924. return;
  2925. default:
  2926. if (isIdentifierStart(code)) {
  2927. this.readWord(code);
  2928. return;
  2929. }
  2930. }
  2931. throw this.raise(Errors.InvalidOrUnexpectedToken, {
  2932. at: this.state.curPosition(),
  2933. unexpected: String.fromCodePoint(code)
  2934. });
  2935. }
  2936. finishOp(type, size) {
  2937. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2938. this.state.pos += size;
  2939. this.finishToken(type, str);
  2940. }
  2941. readRegexp() {
  2942. const startLoc = this.state.startLoc;
  2943. const start = this.state.start + 1;
  2944. let escaped, inClass;
  2945. let {
  2946. pos
  2947. } = this.state;
  2948. for (;; ++pos) {
  2949. if (pos >= this.length) {
  2950. throw this.raise(Errors.UnterminatedRegExp, {
  2951. at: createPositionWithColumnOffset(startLoc, 1)
  2952. });
  2953. }
  2954. const ch = this.input.charCodeAt(pos);
  2955. if (isNewLine(ch)) {
  2956. throw this.raise(Errors.UnterminatedRegExp, {
  2957. at: createPositionWithColumnOffset(startLoc, 1)
  2958. });
  2959. }
  2960. if (escaped) {
  2961. escaped = false;
  2962. } else {
  2963. if (ch === 91) {
  2964. inClass = true;
  2965. } else if (ch === 93 && inClass) {
  2966. inClass = false;
  2967. } else if (ch === 47 && !inClass) {
  2968. break;
  2969. }
  2970. escaped = ch === 92;
  2971. }
  2972. }
  2973. const content = this.input.slice(start, pos);
  2974. ++pos;
  2975. let mods = "";
  2976. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  2977. while (pos < this.length) {
  2978. const cp = this.codePointAtPos(pos);
  2979. const char = String.fromCharCode(cp);
  2980. if (VALID_REGEX_FLAGS.has(cp)) {
  2981. if (cp === 118) {
  2982. this.expectPlugin("regexpUnicodeSets", nextPos());
  2983. if (mods.includes("u")) {
  2984. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2985. at: nextPos()
  2986. });
  2987. }
  2988. } else if (cp === 117) {
  2989. if (mods.includes("v")) {
  2990. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2991. at: nextPos()
  2992. });
  2993. }
  2994. }
  2995. if (mods.includes(char)) {
  2996. this.raise(Errors.DuplicateRegExpFlags, {
  2997. at: nextPos()
  2998. });
  2999. }
  3000. } else if (isIdentifierChar(cp) || cp === 92) {
  3001. this.raise(Errors.MalformedRegExpFlags, {
  3002. at: nextPos()
  3003. });
  3004. } else {
  3005. break;
  3006. }
  3007. ++pos;
  3008. mods += char;
  3009. }
  3010. this.state.pos = pos;
  3011. this.finishToken(135, {
  3012. pattern: content,
  3013. flags: mods
  3014. });
  3015. }
  3016. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  3017. const {
  3018. n,
  3019. pos
  3020. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  3021. this.state.pos = pos;
  3022. return n;
  3023. }
  3024. readRadixNumber(radix) {
  3025. const startLoc = this.state.curPosition();
  3026. let isBigInt = false;
  3027. this.state.pos += 2;
  3028. const val = this.readInt(radix);
  3029. if (val == null) {
  3030. this.raise(Errors.InvalidDigit, {
  3031. at: createPositionWithColumnOffset(startLoc, 2),
  3032. radix
  3033. });
  3034. }
  3035. const next = this.input.charCodeAt(this.state.pos);
  3036. if (next === 110) {
  3037. ++this.state.pos;
  3038. isBigInt = true;
  3039. } else if (next === 109) {
  3040. throw this.raise(Errors.InvalidDecimal, {
  3041. at: startLoc
  3042. });
  3043. }
  3044. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3045. throw this.raise(Errors.NumberIdentifier, {
  3046. at: this.state.curPosition()
  3047. });
  3048. }
  3049. if (isBigInt) {
  3050. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  3051. this.finishToken(133, str);
  3052. return;
  3053. }
  3054. this.finishToken(132, val);
  3055. }
  3056. readNumber(startsWithDot) {
  3057. const start = this.state.pos;
  3058. const startLoc = this.state.curPosition();
  3059. let isFloat = false;
  3060. let isBigInt = false;
  3061. let isDecimal = false;
  3062. let hasExponent = false;
  3063. let isOctal = false;
  3064. if (!startsWithDot && this.readInt(10) === null) {
  3065. this.raise(Errors.InvalidNumber, {
  3066. at: this.state.curPosition()
  3067. });
  3068. }
  3069. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3070. if (hasLeadingZero) {
  3071. const integer = this.input.slice(start, this.state.pos);
  3072. this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
  3073. at: startLoc
  3074. });
  3075. if (!this.state.strict) {
  3076. const underscorePos = integer.indexOf("_");
  3077. if (underscorePos > 0) {
  3078. this.raise(Errors.ZeroDigitNumericSeparator, {
  3079. at: createPositionWithColumnOffset(startLoc, underscorePos)
  3080. });
  3081. }
  3082. }
  3083. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3084. }
  3085. let next = this.input.charCodeAt(this.state.pos);
  3086. if (next === 46 && !isOctal) {
  3087. ++this.state.pos;
  3088. this.readInt(10);
  3089. isFloat = true;
  3090. next = this.input.charCodeAt(this.state.pos);
  3091. }
  3092. if ((next === 69 || next === 101) && !isOctal) {
  3093. next = this.input.charCodeAt(++this.state.pos);
  3094. if (next === 43 || next === 45) {
  3095. ++this.state.pos;
  3096. }
  3097. if (this.readInt(10) === null) {
  3098. this.raise(Errors.InvalidOrMissingExponent, {
  3099. at: startLoc
  3100. });
  3101. }
  3102. isFloat = true;
  3103. hasExponent = true;
  3104. next = this.input.charCodeAt(this.state.pos);
  3105. }
  3106. if (next === 110) {
  3107. if (isFloat || hasLeadingZero) {
  3108. this.raise(Errors.InvalidBigIntLiteral, {
  3109. at: startLoc
  3110. });
  3111. }
  3112. ++this.state.pos;
  3113. isBigInt = true;
  3114. }
  3115. if (next === 109) {
  3116. this.expectPlugin("decimal", this.state.curPosition());
  3117. if (hasExponent || hasLeadingZero) {
  3118. this.raise(Errors.InvalidDecimal, {
  3119. at: startLoc
  3120. });
  3121. }
  3122. ++this.state.pos;
  3123. isDecimal = true;
  3124. }
  3125. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3126. throw this.raise(Errors.NumberIdentifier, {
  3127. at: this.state.curPosition()
  3128. });
  3129. }
  3130. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3131. if (isBigInt) {
  3132. this.finishToken(133, str);
  3133. return;
  3134. }
  3135. if (isDecimal) {
  3136. this.finishToken(134, str);
  3137. return;
  3138. }
  3139. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3140. this.finishToken(132, val);
  3141. }
  3142. readCodePoint(throwOnInvalid) {
  3143. const {
  3144. code,
  3145. pos
  3146. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3147. this.state.pos = pos;
  3148. return code;
  3149. }
  3150. readString(quote) {
  3151. const {
  3152. str,
  3153. pos,
  3154. curLine,
  3155. lineStart
  3156. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3157. this.state.pos = pos + 1;
  3158. this.state.lineStart = lineStart;
  3159. this.state.curLine = curLine;
  3160. this.finishToken(131, str);
  3161. }
  3162. readTemplateContinuation() {
  3163. if (!this.match(8)) {
  3164. this.unexpected(null, 8);
  3165. }
  3166. this.state.pos--;
  3167. this.readTemplateToken();
  3168. }
  3169. readTemplateToken() {
  3170. const opening = this.input[this.state.pos];
  3171. const {
  3172. str,
  3173. firstInvalidLoc,
  3174. pos,
  3175. curLine,
  3176. lineStart
  3177. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3178. this.state.pos = pos + 1;
  3179. this.state.lineStart = lineStart;
  3180. this.state.curLine = curLine;
  3181. if (firstInvalidLoc) {
  3182. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3183. }
  3184. if (this.input.codePointAt(pos) === 96) {
  3185. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3186. } else {
  3187. this.state.pos++;
  3188. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3189. }
  3190. }
  3191. recordStrictModeErrors(toParseError, {
  3192. at
  3193. }) {
  3194. const index = at.index;
  3195. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3196. this.raise(toParseError, {
  3197. at
  3198. });
  3199. } else {
  3200. this.state.strictErrors.set(index, [toParseError, at]);
  3201. }
  3202. }
  3203. readWord1(firstCode) {
  3204. this.state.containsEsc = false;
  3205. let word = "";
  3206. const start = this.state.pos;
  3207. let chunkStart = this.state.pos;
  3208. if (firstCode !== undefined) {
  3209. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3210. }
  3211. while (this.state.pos < this.length) {
  3212. const ch = this.codePointAtPos(this.state.pos);
  3213. if (isIdentifierChar(ch)) {
  3214. this.state.pos += ch <= 0xffff ? 1 : 2;
  3215. } else if (ch === 92) {
  3216. this.state.containsEsc = true;
  3217. word += this.input.slice(chunkStart, this.state.pos);
  3218. const escStart = this.state.curPosition();
  3219. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3220. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3221. this.raise(Errors.MissingUnicodeEscape, {
  3222. at: this.state.curPosition()
  3223. });
  3224. chunkStart = this.state.pos - 1;
  3225. continue;
  3226. }
  3227. ++this.state.pos;
  3228. const esc = this.readCodePoint(true);
  3229. if (esc !== null) {
  3230. if (!identifierCheck(esc)) {
  3231. this.raise(Errors.EscapedCharNotAnIdentifier, {
  3232. at: escStart
  3233. });
  3234. }
  3235. word += String.fromCodePoint(esc);
  3236. }
  3237. chunkStart = this.state.pos;
  3238. } else {
  3239. break;
  3240. }
  3241. }
  3242. return word + this.input.slice(chunkStart, this.state.pos);
  3243. }
  3244. readWord(firstCode) {
  3245. const word = this.readWord1(firstCode);
  3246. const type = keywords$1.get(word);
  3247. if (type !== undefined) {
  3248. this.finishToken(type, tokenLabelName(type));
  3249. } else {
  3250. this.finishToken(130, word);
  3251. }
  3252. }
  3253. checkKeywordEscapes() {
  3254. const {
  3255. type
  3256. } = this.state;
  3257. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3258. this.raise(Errors.InvalidEscapedReservedWord, {
  3259. at: this.state.startLoc,
  3260. reservedWord: tokenLabelName(type)
  3261. });
  3262. }
  3263. }
  3264. raise(toParseError, raiseProperties) {
  3265. const {
  3266. at
  3267. } = raiseProperties,
  3268. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
  3269. const loc = at instanceof Position ? at : at.loc.start;
  3270. const error = toParseError({
  3271. loc,
  3272. details
  3273. });
  3274. if (!this.options.errorRecovery) throw error;
  3275. if (!this.isLookahead) this.state.errors.push(error);
  3276. return error;
  3277. }
  3278. raiseOverwrite(toParseError, raiseProperties) {
  3279. const {
  3280. at
  3281. } = raiseProperties,
  3282. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
  3283. const loc = at instanceof Position ? at : at.loc.start;
  3284. const pos = loc.index;
  3285. const errors = this.state.errors;
  3286. for (let i = errors.length - 1; i >= 0; i--) {
  3287. const error = errors[i];
  3288. if (error.loc.index === pos) {
  3289. return errors[i] = toParseError({
  3290. loc,
  3291. details
  3292. });
  3293. }
  3294. if (error.loc.index < pos) break;
  3295. }
  3296. return this.raise(toParseError, raiseProperties);
  3297. }
  3298. updateContext(prevType) {}
  3299. unexpected(loc, type) {
  3300. throw this.raise(Errors.UnexpectedToken, {
  3301. expected: type ? tokenLabelName(type) : null,
  3302. at: loc != null ? loc : this.state.startLoc
  3303. });
  3304. }
  3305. expectPlugin(pluginName, loc) {
  3306. if (this.hasPlugin(pluginName)) {
  3307. return true;
  3308. }
  3309. throw this.raise(Errors.MissingPlugin, {
  3310. at: loc != null ? loc : this.state.startLoc,
  3311. missingPlugin: [pluginName]
  3312. });
  3313. }
  3314. expectOnePlugin(pluginNames) {
  3315. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3316. throw this.raise(Errors.MissingOneOfPlugins, {
  3317. at: this.state.startLoc,
  3318. missingPlugin: pluginNames
  3319. });
  3320. }
  3321. }
  3322. errorBuilder(error) {
  3323. return (pos, lineStart, curLine) => {
  3324. this.raise(error, {
  3325. at: buildPosition(pos, lineStart, curLine)
  3326. });
  3327. };
  3328. }
  3329. }
  3330. class ClassScope {
  3331. constructor() {
  3332. this.privateNames = new Set();
  3333. this.loneAccessors = new Map();
  3334. this.undefinedPrivateNames = new Map();
  3335. }
  3336. }
  3337. class ClassScopeHandler {
  3338. constructor(parser) {
  3339. this.parser = void 0;
  3340. this.stack = [];
  3341. this.undefinedPrivateNames = new Map();
  3342. this.parser = parser;
  3343. }
  3344. current() {
  3345. return this.stack[this.stack.length - 1];
  3346. }
  3347. enter() {
  3348. this.stack.push(new ClassScope());
  3349. }
  3350. exit() {
  3351. const oldClassScope = this.stack.pop();
  3352. const current = this.current();
  3353. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3354. if (current) {
  3355. if (!current.undefinedPrivateNames.has(name)) {
  3356. current.undefinedPrivateNames.set(name, loc);
  3357. }
  3358. } else {
  3359. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3360. at: loc,
  3361. identifierName: name
  3362. });
  3363. }
  3364. }
  3365. }
  3366. declarePrivateName(name, elementType, loc) {
  3367. const {
  3368. privateNames,
  3369. loneAccessors,
  3370. undefinedPrivateNames
  3371. } = this.current();
  3372. let redefined = privateNames.has(name);
  3373. if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) {
  3374. const accessor = redefined && loneAccessors.get(name);
  3375. if (accessor) {
  3376. const oldStatic = accessor & CLASS_ELEMENT_FLAG_STATIC;
  3377. const newStatic = elementType & CLASS_ELEMENT_FLAG_STATIC;
  3378. const oldKind = accessor & CLASS_ELEMENT_KIND_ACCESSOR;
  3379. const newKind = elementType & CLASS_ELEMENT_KIND_ACCESSOR;
  3380. redefined = oldKind === newKind || oldStatic !== newStatic;
  3381. if (!redefined) loneAccessors.delete(name);
  3382. } else if (!redefined) {
  3383. loneAccessors.set(name, elementType);
  3384. }
  3385. }
  3386. if (redefined) {
  3387. this.parser.raise(Errors.PrivateNameRedeclaration, {
  3388. at: loc,
  3389. identifierName: name
  3390. });
  3391. }
  3392. privateNames.add(name);
  3393. undefinedPrivateNames.delete(name);
  3394. }
  3395. usePrivateName(name, loc) {
  3396. let classScope;
  3397. for (classScope of this.stack) {
  3398. if (classScope.privateNames.has(name)) return;
  3399. }
  3400. if (classScope) {
  3401. classScope.undefinedPrivateNames.set(name, loc);
  3402. } else {
  3403. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3404. at: loc,
  3405. identifierName: name
  3406. });
  3407. }
  3408. }
  3409. }
  3410. const kExpression = 0,
  3411. kMaybeArrowParameterDeclaration = 1,
  3412. kMaybeAsyncArrowParameterDeclaration = 2,
  3413. kParameterDeclaration = 3;
  3414. class ExpressionScope {
  3415. constructor(type = kExpression) {
  3416. this.type = void 0;
  3417. this.type = type;
  3418. }
  3419. canBeArrowParameterDeclaration() {
  3420. return this.type === kMaybeAsyncArrowParameterDeclaration || this.type === kMaybeArrowParameterDeclaration;
  3421. }
  3422. isCertainlyParameterDeclaration() {
  3423. return this.type === kParameterDeclaration;
  3424. }
  3425. }
  3426. class ArrowHeadParsingScope extends ExpressionScope {
  3427. constructor(type) {
  3428. super(type);
  3429. this.declarationErrors = new Map();
  3430. }
  3431. recordDeclarationError(ParsingErrorClass, {
  3432. at
  3433. }) {
  3434. const index = at.index;
  3435. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3436. }
  3437. clearDeclarationError(index) {
  3438. this.declarationErrors.delete(index);
  3439. }
  3440. iterateErrors(iterator) {
  3441. this.declarationErrors.forEach(iterator);
  3442. }
  3443. }
  3444. class ExpressionScopeHandler {
  3445. constructor(parser) {
  3446. this.parser = void 0;
  3447. this.stack = [new ExpressionScope()];
  3448. this.parser = parser;
  3449. }
  3450. enter(scope) {
  3451. this.stack.push(scope);
  3452. }
  3453. exit() {
  3454. this.stack.pop();
  3455. }
  3456. recordParameterInitializerError(toParseError, {
  3457. at: node
  3458. }) {
  3459. const origin = {
  3460. at: node.loc.start
  3461. };
  3462. const {
  3463. stack
  3464. } = this;
  3465. let i = stack.length - 1;
  3466. let scope = stack[i];
  3467. while (!scope.isCertainlyParameterDeclaration()) {
  3468. if (scope.canBeArrowParameterDeclaration()) {
  3469. scope.recordDeclarationError(toParseError, origin);
  3470. } else {
  3471. return;
  3472. }
  3473. scope = stack[--i];
  3474. }
  3475. this.parser.raise(toParseError, origin);
  3476. }
  3477. recordArrowParameterBindingError(error, {
  3478. at: node
  3479. }) {
  3480. const {
  3481. stack
  3482. } = this;
  3483. const scope = stack[stack.length - 1];
  3484. const origin = {
  3485. at: node.loc.start
  3486. };
  3487. if (scope.isCertainlyParameterDeclaration()) {
  3488. this.parser.raise(error, origin);
  3489. } else if (scope.canBeArrowParameterDeclaration()) {
  3490. scope.recordDeclarationError(error, origin);
  3491. } else {
  3492. return;
  3493. }
  3494. }
  3495. recordAsyncArrowParametersError({
  3496. at
  3497. }) {
  3498. const {
  3499. stack
  3500. } = this;
  3501. let i = stack.length - 1;
  3502. let scope = stack[i];
  3503. while (scope.canBeArrowParameterDeclaration()) {
  3504. if (scope.type === kMaybeAsyncArrowParameterDeclaration) {
  3505. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
  3506. at
  3507. });
  3508. }
  3509. scope = stack[--i];
  3510. }
  3511. }
  3512. validateAsPattern() {
  3513. const {
  3514. stack
  3515. } = this;
  3516. const currentScope = stack[stack.length - 1];
  3517. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3518. currentScope.iterateErrors(([toParseError, loc]) => {
  3519. this.parser.raise(toParseError, {
  3520. at: loc
  3521. });
  3522. let i = stack.length - 2;
  3523. let scope = stack[i];
  3524. while (scope.canBeArrowParameterDeclaration()) {
  3525. scope.clearDeclarationError(loc.index);
  3526. scope = stack[--i];
  3527. }
  3528. });
  3529. }
  3530. }
  3531. function newParameterDeclarationScope() {
  3532. return new ExpressionScope(kParameterDeclaration);
  3533. }
  3534. function newArrowHeadScope() {
  3535. return new ArrowHeadParsingScope(kMaybeArrowParameterDeclaration);
  3536. }
  3537. function newAsyncArrowScope() {
  3538. return new ArrowHeadParsingScope(kMaybeAsyncArrowParameterDeclaration);
  3539. }
  3540. function newExpressionScope() {
  3541. return new ExpressionScope();
  3542. }
  3543. const PARAM = 0b0000,
  3544. PARAM_YIELD = 0b0001,
  3545. PARAM_AWAIT = 0b0010,
  3546. PARAM_RETURN = 0b0100,
  3547. PARAM_IN = 0b1000;
  3548. class ProductionParameterHandler {
  3549. constructor() {
  3550. this.stacks = [];
  3551. }
  3552. enter(flags) {
  3553. this.stacks.push(flags);
  3554. }
  3555. exit() {
  3556. this.stacks.pop();
  3557. }
  3558. currentFlags() {
  3559. return this.stacks[this.stacks.length - 1];
  3560. }
  3561. get hasAwait() {
  3562. return (this.currentFlags() & PARAM_AWAIT) > 0;
  3563. }
  3564. get hasYield() {
  3565. return (this.currentFlags() & PARAM_YIELD) > 0;
  3566. }
  3567. get hasReturn() {
  3568. return (this.currentFlags() & PARAM_RETURN) > 0;
  3569. }
  3570. get hasIn() {
  3571. return (this.currentFlags() & PARAM_IN) > 0;
  3572. }
  3573. }
  3574. function functionFlags(isAsync, isGenerator) {
  3575. return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
  3576. }
  3577. class UtilParser extends Tokenizer {
  3578. addExtra(node, key, value, enumerable = true) {
  3579. if (!node) return;
  3580. const extra = node.extra = node.extra || {};
  3581. if (enumerable) {
  3582. extra[key] = value;
  3583. } else {
  3584. Object.defineProperty(extra, key, {
  3585. enumerable,
  3586. value
  3587. });
  3588. }
  3589. }
  3590. isContextual(token) {
  3591. return this.state.type === token && !this.state.containsEsc;
  3592. }
  3593. isUnparsedContextual(nameStart, name) {
  3594. const nameEnd = nameStart + name.length;
  3595. if (this.input.slice(nameStart, nameEnd) === name) {
  3596. const nextCh = this.input.charCodeAt(nameEnd);
  3597. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3598. }
  3599. return false;
  3600. }
  3601. isLookaheadContextual(name) {
  3602. const next = this.nextTokenStart();
  3603. return this.isUnparsedContextual(next, name);
  3604. }
  3605. eatContextual(token) {
  3606. if (this.isContextual(token)) {
  3607. this.next();
  3608. return true;
  3609. }
  3610. return false;
  3611. }
  3612. expectContextual(token, toParseError) {
  3613. if (!this.eatContextual(token)) {
  3614. if (toParseError != null) {
  3615. throw this.raise(toParseError, {
  3616. at: this.state.startLoc
  3617. });
  3618. }
  3619. this.unexpected(null, token);
  3620. }
  3621. }
  3622. canInsertSemicolon() {
  3623. return this.match(137) || this.match(8) || this.hasPrecedingLineBreak();
  3624. }
  3625. hasPrecedingLineBreak() {
  3626. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  3627. }
  3628. hasFollowingLineBreak() {
  3629. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  3630. return skipWhiteSpaceToLineBreak.test(this.input);
  3631. }
  3632. isLineTerminator() {
  3633. return this.eat(13) || this.canInsertSemicolon();
  3634. }
  3635. semicolon(allowAsi = true) {
  3636. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3637. this.raise(Errors.MissingSemicolon, {
  3638. at: this.state.lastTokEndLoc
  3639. });
  3640. }
  3641. expect(type, loc) {
  3642. this.eat(type) || this.unexpected(loc, type);
  3643. }
  3644. tryParse(fn, oldState = this.state.clone()) {
  3645. const abortSignal = {
  3646. node: null
  3647. };
  3648. try {
  3649. const node = fn((node = null) => {
  3650. abortSignal.node = node;
  3651. throw abortSignal;
  3652. });
  3653. if (this.state.errors.length > oldState.errors.length) {
  3654. const failState = this.state;
  3655. this.state = oldState;
  3656. this.state.tokensLength = failState.tokensLength;
  3657. return {
  3658. node,
  3659. error: failState.errors[oldState.errors.length],
  3660. thrown: false,
  3661. aborted: false,
  3662. failState
  3663. };
  3664. }
  3665. return {
  3666. node,
  3667. error: null,
  3668. thrown: false,
  3669. aborted: false,
  3670. failState: null
  3671. };
  3672. } catch (error) {
  3673. const failState = this.state;
  3674. this.state = oldState;
  3675. if (error instanceof SyntaxError) {
  3676. return {
  3677. node: null,
  3678. error,
  3679. thrown: true,
  3680. aborted: false,
  3681. failState
  3682. };
  3683. }
  3684. if (error === abortSignal) {
  3685. return {
  3686. node: abortSignal.node,
  3687. error: null,
  3688. thrown: false,
  3689. aborted: true,
  3690. failState
  3691. };
  3692. }
  3693. throw error;
  3694. }
  3695. }
  3696. checkExpressionErrors(refExpressionErrors, andThrow) {
  3697. if (!refExpressionErrors) return false;
  3698. const {
  3699. shorthandAssignLoc,
  3700. doubleProtoLoc,
  3701. privateKeyLoc,
  3702. optionalParametersLoc
  3703. } = refExpressionErrors;
  3704. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3705. if (!andThrow) {
  3706. return hasErrors;
  3707. }
  3708. if (shorthandAssignLoc != null) {
  3709. this.raise(Errors.InvalidCoverInitializedName, {
  3710. at: shorthandAssignLoc
  3711. });
  3712. }
  3713. if (doubleProtoLoc != null) {
  3714. this.raise(Errors.DuplicateProto, {
  3715. at: doubleProtoLoc
  3716. });
  3717. }
  3718. if (privateKeyLoc != null) {
  3719. this.raise(Errors.UnexpectedPrivateField, {
  3720. at: privateKeyLoc
  3721. });
  3722. }
  3723. if (optionalParametersLoc != null) {
  3724. this.unexpected(optionalParametersLoc);
  3725. }
  3726. }
  3727. isLiteralPropertyName() {
  3728. return tokenIsLiteralPropertyName(this.state.type);
  3729. }
  3730. isPrivateName(node) {
  3731. return node.type === "PrivateName";
  3732. }
  3733. getPrivateNameSV(node) {
  3734. return node.id.name;
  3735. }
  3736. hasPropertyAsPrivateName(node) {
  3737. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3738. }
  3739. isObjectProperty(node) {
  3740. return node.type === "ObjectProperty";
  3741. }
  3742. isObjectMethod(node) {
  3743. return node.type === "ObjectMethod";
  3744. }
  3745. initializeScopes(inModule = this.options.sourceType === "module") {
  3746. const oldLabels = this.state.labels;
  3747. this.state.labels = [];
  3748. const oldExportedIdentifiers = this.exportedIdentifiers;
  3749. this.exportedIdentifiers = new Set();
  3750. const oldInModule = this.inModule;
  3751. this.inModule = inModule;
  3752. const oldScope = this.scope;
  3753. const ScopeHandler = this.getScopeHandler();
  3754. this.scope = new ScopeHandler(this, inModule);
  3755. const oldProdParam = this.prodParam;
  3756. this.prodParam = new ProductionParameterHandler();
  3757. const oldClassScope = this.classScope;
  3758. this.classScope = new ClassScopeHandler(this);
  3759. const oldExpressionScope = this.expressionScope;
  3760. this.expressionScope = new ExpressionScopeHandler(this);
  3761. return () => {
  3762. this.state.labels = oldLabels;
  3763. this.exportedIdentifiers = oldExportedIdentifiers;
  3764. this.inModule = oldInModule;
  3765. this.scope = oldScope;
  3766. this.prodParam = oldProdParam;
  3767. this.classScope = oldClassScope;
  3768. this.expressionScope = oldExpressionScope;
  3769. };
  3770. }
  3771. enterInitialScopes() {
  3772. let paramFlags = PARAM;
  3773. if (this.inModule) {
  3774. paramFlags |= PARAM_AWAIT;
  3775. }
  3776. this.scope.enter(SCOPE_PROGRAM);
  3777. this.prodParam.enter(paramFlags);
  3778. }
  3779. checkDestructuringPrivate(refExpressionErrors) {
  3780. const {
  3781. privateKeyLoc
  3782. } = refExpressionErrors;
  3783. if (privateKeyLoc !== null) {
  3784. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3785. }
  3786. }
  3787. }
  3788. class ExpressionErrors {
  3789. constructor() {
  3790. this.shorthandAssignLoc = null;
  3791. this.doubleProtoLoc = null;
  3792. this.privateKeyLoc = null;
  3793. this.optionalParametersLoc = null;
  3794. }
  3795. }
  3796. class Node {
  3797. constructor(parser, pos, loc) {
  3798. this.type = "";
  3799. this.start = pos;
  3800. this.end = 0;
  3801. this.loc = new SourceLocation(loc);
  3802. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3803. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3804. }
  3805. }
  3806. const NodePrototype = Node.prototype;
  3807. {
  3808. NodePrototype.__clone = function () {
  3809. const newNode = new Node(undefined, this.start, this.loc.start);
  3810. const keys = Object.keys(this);
  3811. for (let i = 0, length = keys.length; i < length; i++) {
  3812. const key = keys[i];
  3813. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3814. newNode[key] = this[key];
  3815. }
  3816. }
  3817. return newNode;
  3818. };
  3819. }
  3820. function clonePlaceholder(node) {
  3821. return cloneIdentifier(node);
  3822. }
  3823. function cloneIdentifier(node) {
  3824. const {
  3825. type,
  3826. start,
  3827. end,
  3828. loc,
  3829. range,
  3830. extra,
  3831. name
  3832. } = node;
  3833. const cloned = Object.create(NodePrototype);
  3834. cloned.type = type;
  3835. cloned.start = start;
  3836. cloned.end = end;
  3837. cloned.loc = loc;
  3838. cloned.range = range;
  3839. cloned.extra = extra;
  3840. cloned.name = name;
  3841. if (type === "Placeholder") {
  3842. cloned.expectedNode = node.expectedNode;
  3843. }
  3844. return cloned;
  3845. }
  3846. function cloneStringLiteral(node) {
  3847. const {
  3848. type,
  3849. start,
  3850. end,
  3851. loc,
  3852. range,
  3853. extra
  3854. } = node;
  3855. if (type === "Placeholder") {
  3856. return clonePlaceholder(node);
  3857. }
  3858. const cloned = Object.create(NodePrototype);
  3859. cloned.type = type;
  3860. cloned.start = start;
  3861. cloned.end = end;
  3862. cloned.loc = loc;
  3863. cloned.range = range;
  3864. if (node.raw !== undefined) {
  3865. cloned.raw = node.raw;
  3866. } else {
  3867. cloned.extra = extra;
  3868. }
  3869. cloned.value = node.value;
  3870. return cloned;
  3871. }
  3872. class NodeUtils extends UtilParser {
  3873. startNode() {
  3874. return new Node(this, this.state.start, this.state.startLoc);
  3875. }
  3876. startNodeAt(loc) {
  3877. return new Node(this, loc.index, loc);
  3878. }
  3879. startNodeAtNode(type) {
  3880. return this.startNodeAt(type.loc.start);
  3881. }
  3882. finishNode(node, type) {
  3883. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3884. }
  3885. finishNodeAt(node, type, endLoc) {
  3886. node.type = type;
  3887. node.end = endLoc.index;
  3888. node.loc.end = endLoc;
  3889. if (this.options.ranges) node.range[1] = endLoc.index;
  3890. if (this.options.attachComment) this.processComment(node);
  3891. return node;
  3892. }
  3893. resetStartLocation(node, startLoc) {
  3894. node.start = startLoc.index;
  3895. node.loc.start = startLoc;
  3896. if (this.options.ranges) node.range[0] = startLoc.index;
  3897. }
  3898. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3899. node.end = endLoc.index;
  3900. node.loc.end = endLoc;
  3901. if (this.options.ranges) node.range[1] = endLoc.index;
  3902. }
  3903. resetStartLocationFromNode(node, locationNode) {
  3904. this.resetStartLocation(node, locationNode.loc.start);
  3905. }
  3906. }
  3907. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3908. const FlowErrors = ParseErrorEnum`flow`({
  3909. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3910. 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.",
  3911. AssignReservedType: ({
  3912. reservedType
  3913. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3914. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3915. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3916. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3917. EnumBooleanMemberNotInitialized: ({
  3918. memberName,
  3919. enumName
  3920. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3921. EnumDuplicateMemberName: ({
  3922. memberName,
  3923. enumName
  3924. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3925. EnumInconsistentMemberValues: ({
  3926. enumName
  3927. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3928. EnumInvalidExplicitType: ({
  3929. invalidEnumType,
  3930. enumName
  3931. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3932. EnumInvalidExplicitTypeUnknownSupplied: ({
  3933. enumName
  3934. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3935. EnumInvalidMemberInitializerPrimaryType: ({
  3936. enumName,
  3937. memberName,
  3938. explicitType
  3939. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3940. EnumInvalidMemberInitializerSymbolType: ({
  3941. enumName,
  3942. memberName
  3943. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3944. EnumInvalidMemberInitializerUnknownType: ({
  3945. enumName,
  3946. memberName
  3947. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3948. EnumInvalidMemberName: ({
  3949. enumName,
  3950. memberName,
  3951. suggestion
  3952. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3953. EnumNumberMemberNotInitialized: ({
  3954. enumName,
  3955. memberName
  3956. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3957. EnumStringMemberInconsistentlyInitailized: ({
  3958. enumName
  3959. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3960. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3961. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3962. 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.",
  3963. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3964. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3965. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3966. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3967. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3968. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3969. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3970. PatternIsOptional: Object.assign({
  3971. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3972. }, {
  3973. reasonCode: "OptionalBindingPattern"
  3974. }),
  3975. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3976. SpreadVariance: "Spread properties cannot have variance.",
  3977. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3978. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3979. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3980. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3981. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3982. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3983. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3984. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3985. UnexpectedReservedType: ({
  3986. reservedType
  3987. }) => `Unexpected reserved type ${reservedType}.`,
  3988. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3989. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3990. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3991. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3992. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3993. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3994. UnsupportedDeclareExportKind: ({
  3995. unsupportedExportKind,
  3996. suggestion
  3997. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  3998. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3999. UnterminatedFlowComment: "Unterminated flow-comment."
  4000. });
  4001. function isEsModuleType(bodyElement) {
  4002. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  4003. }
  4004. function hasTypeImportKind(node) {
  4005. return node.importKind === "type" || node.importKind === "typeof";
  4006. }
  4007. function isMaybeDefaultImport(type) {
  4008. return tokenIsKeywordOrIdentifier(type) && type !== 97;
  4009. }
  4010. const exportSuggestions = {
  4011. const: "declare export var",
  4012. let: "declare export var",
  4013. type: "export type",
  4014. interface: "export interface"
  4015. };
  4016. function partition(list, test) {
  4017. const list1 = [];
  4018. const list2 = [];
  4019. for (let i = 0; i < list.length; i++) {
  4020. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  4021. }
  4022. return [list1, list2];
  4023. }
  4024. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  4025. var flow = superClass => class FlowParserMixin extends superClass {
  4026. constructor(...args) {
  4027. super(...args);
  4028. this.flowPragma = undefined;
  4029. }
  4030. getScopeHandler() {
  4031. return FlowScopeHandler;
  4032. }
  4033. shouldParseTypes() {
  4034. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  4035. }
  4036. shouldParseEnums() {
  4037. return !!this.getPluginOption("flow", "enums");
  4038. }
  4039. finishToken(type, val) {
  4040. if (type !== 131 && type !== 13 && type !== 28) {
  4041. if (this.flowPragma === undefined) {
  4042. this.flowPragma = null;
  4043. }
  4044. }
  4045. super.finishToken(type, val);
  4046. }
  4047. addComment(comment) {
  4048. if (this.flowPragma === undefined) {
  4049. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4050. if (!matches) ;else if (matches[1] === "flow") {
  4051. this.flowPragma = "flow";
  4052. } else if (matches[1] === "noflow") {
  4053. this.flowPragma = "noflow";
  4054. } else {
  4055. throw new Error("Unexpected flow pragma");
  4056. }
  4057. }
  4058. super.addComment(comment);
  4059. }
  4060. flowParseTypeInitialiser(tok) {
  4061. const oldInType = this.state.inType;
  4062. this.state.inType = true;
  4063. this.expect(tok || 14);
  4064. const type = this.flowParseType();
  4065. this.state.inType = oldInType;
  4066. return type;
  4067. }
  4068. flowParsePredicate() {
  4069. const node = this.startNode();
  4070. const moduloLoc = this.state.startLoc;
  4071. this.next();
  4072. this.expectContextual(108);
  4073. if (this.state.lastTokStart > moduloLoc.index + 1) {
  4074. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
  4075. at: moduloLoc
  4076. });
  4077. }
  4078. if (this.eat(10)) {
  4079. node.value = super.parseExpression();
  4080. this.expect(11);
  4081. return this.finishNode(node, "DeclaredPredicate");
  4082. } else {
  4083. return this.finishNode(node, "InferredPredicate");
  4084. }
  4085. }
  4086. flowParseTypeAndPredicateInitialiser() {
  4087. const oldInType = this.state.inType;
  4088. this.state.inType = true;
  4089. this.expect(14);
  4090. let type = null;
  4091. let predicate = null;
  4092. if (this.match(54)) {
  4093. this.state.inType = oldInType;
  4094. predicate = this.flowParsePredicate();
  4095. } else {
  4096. type = this.flowParseType();
  4097. this.state.inType = oldInType;
  4098. if (this.match(54)) {
  4099. predicate = this.flowParsePredicate();
  4100. }
  4101. }
  4102. return [type, predicate];
  4103. }
  4104. flowParseDeclareClass(node) {
  4105. this.next();
  4106. this.flowParseInterfaceish(node, true);
  4107. return this.finishNode(node, "DeclareClass");
  4108. }
  4109. flowParseDeclareFunction(node) {
  4110. this.next();
  4111. const id = node.id = this.parseIdentifier();
  4112. const typeNode = this.startNode();
  4113. const typeContainer = this.startNode();
  4114. if (this.match(47)) {
  4115. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4116. } else {
  4117. typeNode.typeParameters = null;
  4118. }
  4119. this.expect(10);
  4120. const tmp = this.flowParseFunctionTypeParams();
  4121. typeNode.params = tmp.params;
  4122. typeNode.rest = tmp.rest;
  4123. typeNode.this = tmp._this;
  4124. this.expect(11);
  4125. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4126. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4127. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4128. this.resetEndLocation(id);
  4129. this.semicolon();
  4130. this.scope.declareName(node.id.name, BIND_FLOW_DECLARE_FN, node.id.loc.start);
  4131. return this.finishNode(node, "DeclareFunction");
  4132. }
  4133. flowParseDeclare(node, insideModule) {
  4134. if (this.match(80)) {
  4135. return this.flowParseDeclareClass(node);
  4136. } else if (this.match(68)) {
  4137. return this.flowParseDeclareFunction(node);
  4138. } else if (this.match(74)) {
  4139. return this.flowParseDeclareVariable(node);
  4140. } else if (this.eatContextual(125)) {
  4141. if (this.match(16)) {
  4142. return this.flowParseDeclareModuleExports(node);
  4143. } else {
  4144. if (insideModule) {
  4145. this.raise(FlowErrors.NestedDeclareModule, {
  4146. at: this.state.lastTokStartLoc
  4147. });
  4148. }
  4149. return this.flowParseDeclareModule(node);
  4150. }
  4151. } else if (this.isContextual(128)) {
  4152. return this.flowParseDeclareTypeAlias(node);
  4153. } else if (this.isContextual(129)) {
  4154. return this.flowParseDeclareOpaqueType(node);
  4155. } else if (this.isContextual(127)) {
  4156. return this.flowParseDeclareInterface(node);
  4157. } else if (this.match(82)) {
  4158. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4159. } else {
  4160. this.unexpected();
  4161. }
  4162. }
  4163. flowParseDeclareVariable(node) {
  4164. this.next();
  4165. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4166. this.scope.declareName(node.id.name, BIND_VAR, node.id.loc.start);
  4167. this.semicolon();
  4168. return this.finishNode(node, "DeclareVariable");
  4169. }
  4170. flowParseDeclareModule(node) {
  4171. this.scope.enter(SCOPE_OTHER);
  4172. if (this.match(131)) {
  4173. node.id = super.parseExprAtom();
  4174. } else {
  4175. node.id = this.parseIdentifier();
  4176. }
  4177. const bodyNode = node.body = this.startNode();
  4178. const body = bodyNode.body = [];
  4179. this.expect(5);
  4180. while (!this.match(8)) {
  4181. let bodyNode = this.startNode();
  4182. if (this.match(83)) {
  4183. this.next();
  4184. if (!this.isContextual(128) && !this.match(87)) {
  4185. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
  4186. at: this.state.lastTokStartLoc
  4187. });
  4188. }
  4189. super.parseImport(bodyNode);
  4190. } else {
  4191. this.expectContextual(123, FlowErrors.UnsupportedStatementInDeclareModule);
  4192. bodyNode = this.flowParseDeclare(bodyNode, true);
  4193. }
  4194. body.push(bodyNode);
  4195. }
  4196. this.scope.exit();
  4197. this.expect(8);
  4198. this.finishNode(bodyNode, "BlockStatement");
  4199. let kind = null;
  4200. let hasModuleExport = false;
  4201. body.forEach(bodyElement => {
  4202. if (isEsModuleType(bodyElement)) {
  4203. if (kind === "CommonJS") {
  4204. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4205. at: bodyElement
  4206. });
  4207. }
  4208. kind = "ES";
  4209. } else if (bodyElement.type === "DeclareModuleExports") {
  4210. if (hasModuleExport) {
  4211. this.raise(FlowErrors.DuplicateDeclareModuleExports, {
  4212. at: bodyElement
  4213. });
  4214. }
  4215. if (kind === "ES") {
  4216. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4217. at: bodyElement
  4218. });
  4219. }
  4220. kind = "CommonJS";
  4221. hasModuleExport = true;
  4222. }
  4223. });
  4224. node.kind = kind || "CommonJS";
  4225. return this.finishNode(node, "DeclareModule");
  4226. }
  4227. flowParseDeclareExportDeclaration(node, insideModule) {
  4228. this.expect(82);
  4229. if (this.eat(65)) {
  4230. if (this.match(68) || this.match(80)) {
  4231. node.declaration = this.flowParseDeclare(this.startNode());
  4232. } else {
  4233. node.declaration = this.flowParseType();
  4234. this.semicolon();
  4235. }
  4236. node.default = true;
  4237. return this.finishNode(node, "DeclareExportDeclaration");
  4238. } else {
  4239. if (this.match(75) || this.isLet() || (this.isContextual(128) || this.isContextual(127)) && !insideModule) {
  4240. const label = this.state.value;
  4241. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
  4242. at: this.state.startLoc,
  4243. unsupportedExportKind: label,
  4244. suggestion: exportSuggestions[label]
  4245. });
  4246. }
  4247. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(129)) {
  4248. node.declaration = this.flowParseDeclare(this.startNode());
  4249. node.default = false;
  4250. return this.finishNode(node, "DeclareExportDeclaration");
  4251. } else if (this.match(55) || this.match(5) || this.isContextual(127) || this.isContextual(128) || this.isContextual(129)) {
  4252. node = this.parseExport(node, null);
  4253. if (node.type === "ExportNamedDeclaration") {
  4254. node.type = "ExportDeclaration";
  4255. node.default = false;
  4256. delete node.exportKind;
  4257. }
  4258. node.type = "Declare" + node.type;
  4259. return node;
  4260. }
  4261. }
  4262. this.unexpected();
  4263. }
  4264. flowParseDeclareModuleExports(node) {
  4265. this.next();
  4266. this.expectContextual(109);
  4267. node.typeAnnotation = this.flowParseTypeAnnotation();
  4268. this.semicolon();
  4269. return this.finishNode(node, "DeclareModuleExports");
  4270. }
  4271. flowParseDeclareTypeAlias(node) {
  4272. this.next();
  4273. const finished = this.flowParseTypeAlias(node);
  4274. finished.type = "DeclareTypeAlias";
  4275. return finished;
  4276. }
  4277. flowParseDeclareOpaqueType(node) {
  4278. this.next();
  4279. const finished = this.flowParseOpaqueType(node, true);
  4280. finished.type = "DeclareOpaqueType";
  4281. return finished;
  4282. }
  4283. flowParseDeclareInterface(node) {
  4284. this.next();
  4285. this.flowParseInterfaceish(node, false);
  4286. return this.finishNode(node, "DeclareInterface");
  4287. }
  4288. flowParseInterfaceish(node, isClass) {
  4289. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4290. this.scope.declareName(node.id.name, isClass ? BIND_FUNCTION : BIND_LEXICAL, node.id.loc.start);
  4291. if (this.match(47)) {
  4292. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4293. } else {
  4294. node.typeParameters = null;
  4295. }
  4296. node.extends = [];
  4297. node.implements = [];
  4298. node.mixins = [];
  4299. if (this.eat(81)) {
  4300. do {
  4301. node.extends.push(this.flowParseInterfaceExtends());
  4302. } while (!isClass && this.eat(12));
  4303. }
  4304. if (isClass) {
  4305. if (this.eatContextual(115)) {
  4306. do {
  4307. node.mixins.push(this.flowParseInterfaceExtends());
  4308. } while (this.eat(12));
  4309. }
  4310. if (this.eatContextual(111)) {
  4311. do {
  4312. node.implements.push(this.flowParseInterfaceExtends());
  4313. } while (this.eat(12));
  4314. }
  4315. }
  4316. node.body = this.flowParseObjectType({
  4317. allowStatic: isClass,
  4318. allowExact: false,
  4319. allowSpread: false,
  4320. allowProto: isClass,
  4321. allowInexact: false
  4322. });
  4323. }
  4324. flowParseInterfaceExtends() {
  4325. const node = this.startNode();
  4326. node.id = this.flowParseQualifiedTypeIdentifier();
  4327. if (this.match(47)) {
  4328. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4329. } else {
  4330. node.typeParameters = null;
  4331. }
  4332. return this.finishNode(node, "InterfaceExtends");
  4333. }
  4334. flowParseInterface(node) {
  4335. this.flowParseInterfaceish(node, false);
  4336. return this.finishNode(node, "InterfaceDeclaration");
  4337. }
  4338. checkNotUnderscore(word) {
  4339. if (word === "_") {
  4340. this.raise(FlowErrors.UnexpectedReservedUnderscore, {
  4341. at: this.state.startLoc
  4342. });
  4343. }
  4344. }
  4345. checkReservedType(word, startLoc, declaration) {
  4346. if (!reservedTypes.has(word)) return;
  4347. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
  4348. at: startLoc,
  4349. reservedType: word
  4350. });
  4351. }
  4352. flowParseRestrictedIdentifier(liberal, declaration) {
  4353. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4354. return this.parseIdentifier(liberal);
  4355. }
  4356. flowParseTypeAlias(node) {
  4357. node.id = this.flowParseRestrictedIdentifier(false, true);
  4358. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  4359. if (this.match(47)) {
  4360. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4361. } else {
  4362. node.typeParameters = null;
  4363. }
  4364. node.right = this.flowParseTypeInitialiser(29);
  4365. this.semicolon();
  4366. return this.finishNode(node, "TypeAlias");
  4367. }
  4368. flowParseOpaqueType(node, declare) {
  4369. this.expectContextual(128);
  4370. node.id = this.flowParseRestrictedIdentifier(true, true);
  4371. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  4372. if (this.match(47)) {
  4373. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4374. } else {
  4375. node.typeParameters = null;
  4376. }
  4377. node.supertype = null;
  4378. if (this.match(14)) {
  4379. node.supertype = this.flowParseTypeInitialiser(14);
  4380. }
  4381. node.impltype = null;
  4382. if (!declare) {
  4383. node.impltype = this.flowParseTypeInitialiser(29);
  4384. }
  4385. this.semicolon();
  4386. return this.finishNode(node, "OpaqueType");
  4387. }
  4388. flowParseTypeParameter(requireDefault = false) {
  4389. const nodeStartLoc = this.state.startLoc;
  4390. const node = this.startNode();
  4391. const variance = this.flowParseVariance();
  4392. const ident = this.flowParseTypeAnnotatableIdentifier();
  4393. node.name = ident.name;
  4394. node.variance = variance;
  4395. node.bound = ident.typeAnnotation;
  4396. if (this.match(29)) {
  4397. this.eat(29);
  4398. node.default = this.flowParseType();
  4399. } else {
  4400. if (requireDefault) {
  4401. this.raise(FlowErrors.MissingTypeParamDefault, {
  4402. at: nodeStartLoc
  4403. });
  4404. }
  4405. }
  4406. return this.finishNode(node, "TypeParameter");
  4407. }
  4408. flowParseTypeParameterDeclaration() {
  4409. const oldInType = this.state.inType;
  4410. const node = this.startNode();
  4411. node.params = [];
  4412. this.state.inType = true;
  4413. if (this.match(47) || this.match(140)) {
  4414. this.next();
  4415. } else {
  4416. this.unexpected();
  4417. }
  4418. let defaultRequired = false;
  4419. do {
  4420. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4421. node.params.push(typeParameter);
  4422. if (typeParameter.default) {
  4423. defaultRequired = true;
  4424. }
  4425. if (!this.match(48)) {
  4426. this.expect(12);
  4427. }
  4428. } while (!this.match(48));
  4429. this.expect(48);
  4430. this.state.inType = oldInType;
  4431. return this.finishNode(node, "TypeParameterDeclaration");
  4432. }
  4433. flowParseTypeParameterInstantiation() {
  4434. const node = this.startNode();
  4435. const oldInType = this.state.inType;
  4436. node.params = [];
  4437. this.state.inType = true;
  4438. this.expect(47);
  4439. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4440. this.state.noAnonFunctionType = false;
  4441. while (!this.match(48)) {
  4442. node.params.push(this.flowParseType());
  4443. if (!this.match(48)) {
  4444. this.expect(12);
  4445. }
  4446. }
  4447. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4448. this.expect(48);
  4449. this.state.inType = oldInType;
  4450. return this.finishNode(node, "TypeParameterInstantiation");
  4451. }
  4452. flowParseTypeParameterInstantiationCallOrNew() {
  4453. const node = this.startNode();
  4454. const oldInType = this.state.inType;
  4455. node.params = [];
  4456. this.state.inType = true;
  4457. this.expect(47);
  4458. while (!this.match(48)) {
  4459. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4460. if (!this.match(48)) {
  4461. this.expect(12);
  4462. }
  4463. }
  4464. this.expect(48);
  4465. this.state.inType = oldInType;
  4466. return this.finishNode(node, "TypeParameterInstantiation");
  4467. }
  4468. flowParseInterfaceType() {
  4469. const node = this.startNode();
  4470. this.expectContextual(127);
  4471. node.extends = [];
  4472. if (this.eat(81)) {
  4473. do {
  4474. node.extends.push(this.flowParseInterfaceExtends());
  4475. } while (this.eat(12));
  4476. }
  4477. node.body = this.flowParseObjectType({
  4478. allowStatic: false,
  4479. allowExact: false,
  4480. allowSpread: false,
  4481. allowProto: false,
  4482. allowInexact: false
  4483. });
  4484. return this.finishNode(node, "InterfaceTypeAnnotation");
  4485. }
  4486. flowParseObjectPropertyKey() {
  4487. return this.match(132) || this.match(131) ? super.parseExprAtom() : this.parseIdentifier(true);
  4488. }
  4489. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4490. node.static = isStatic;
  4491. if (this.lookahead().type === 14) {
  4492. node.id = this.flowParseObjectPropertyKey();
  4493. node.key = this.flowParseTypeInitialiser();
  4494. } else {
  4495. node.id = null;
  4496. node.key = this.flowParseType();
  4497. }
  4498. this.expect(3);
  4499. node.value = this.flowParseTypeInitialiser();
  4500. node.variance = variance;
  4501. return this.finishNode(node, "ObjectTypeIndexer");
  4502. }
  4503. flowParseObjectTypeInternalSlot(node, isStatic) {
  4504. node.static = isStatic;
  4505. node.id = this.flowParseObjectPropertyKey();
  4506. this.expect(3);
  4507. this.expect(3);
  4508. if (this.match(47) || this.match(10)) {
  4509. node.method = true;
  4510. node.optional = false;
  4511. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4512. } else {
  4513. node.method = false;
  4514. if (this.eat(17)) {
  4515. node.optional = true;
  4516. }
  4517. node.value = this.flowParseTypeInitialiser();
  4518. }
  4519. return this.finishNode(node, "ObjectTypeInternalSlot");
  4520. }
  4521. flowParseObjectTypeMethodish(node) {
  4522. node.params = [];
  4523. node.rest = null;
  4524. node.typeParameters = null;
  4525. node.this = null;
  4526. if (this.match(47)) {
  4527. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4528. }
  4529. this.expect(10);
  4530. if (this.match(78)) {
  4531. node.this = this.flowParseFunctionTypeParam(true);
  4532. node.this.name = null;
  4533. if (!this.match(11)) {
  4534. this.expect(12);
  4535. }
  4536. }
  4537. while (!this.match(11) && !this.match(21)) {
  4538. node.params.push(this.flowParseFunctionTypeParam(false));
  4539. if (!this.match(11)) {
  4540. this.expect(12);
  4541. }
  4542. }
  4543. if (this.eat(21)) {
  4544. node.rest = this.flowParseFunctionTypeParam(false);
  4545. }
  4546. this.expect(11);
  4547. node.returnType = this.flowParseTypeInitialiser();
  4548. return this.finishNode(node, "FunctionTypeAnnotation");
  4549. }
  4550. flowParseObjectTypeCallProperty(node, isStatic) {
  4551. const valueNode = this.startNode();
  4552. node.static = isStatic;
  4553. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4554. return this.finishNode(node, "ObjectTypeCallProperty");
  4555. }
  4556. flowParseObjectType({
  4557. allowStatic,
  4558. allowExact,
  4559. allowSpread,
  4560. allowProto,
  4561. allowInexact
  4562. }) {
  4563. const oldInType = this.state.inType;
  4564. this.state.inType = true;
  4565. const nodeStart = this.startNode();
  4566. nodeStart.callProperties = [];
  4567. nodeStart.properties = [];
  4568. nodeStart.indexers = [];
  4569. nodeStart.internalSlots = [];
  4570. let endDelim;
  4571. let exact;
  4572. let inexact = false;
  4573. if (allowExact && this.match(6)) {
  4574. this.expect(6);
  4575. endDelim = 9;
  4576. exact = true;
  4577. } else {
  4578. this.expect(5);
  4579. endDelim = 8;
  4580. exact = false;
  4581. }
  4582. nodeStart.exact = exact;
  4583. while (!this.match(endDelim)) {
  4584. let isStatic = false;
  4585. let protoStartLoc = null;
  4586. let inexactStartLoc = null;
  4587. const node = this.startNode();
  4588. if (allowProto && this.isContextual(116)) {
  4589. const lookahead = this.lookahead();
  4590. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4591. this.next();
  4592. protoStartLoc = this.state.startLoc;
  4593. allowStatic = false;
  4594. }
  4595. }
  4596. if (allowStatic && this.isContextual(104)) {
  4597. const lookahead = this.lookahead();
  4598. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4599. this.next();
  4600. isStatic = true;
  4601. }
  4602. }
  4603. const variance = this.flowParseVariance();
  4604. if (this.eat(0)) {
  4605. if (protoStartLoc != null) {
  4606. this.unexpected(protoStartLoc);
  4607. }
  4608. if (this.eat(0)) {
  4609. if (variance) {
  4610. this.unexpected(variance.loc.start);
  4611. }
  4612. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4613. } else {
  4614. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4615. }
  4616. } else if (this.match(10) || this.match(47)) {
  4617. if (protoStartLoc != null) {
  4618. this.unexpected(protoStartLoc);
  4619. }
  4620. if (variance) {
  4621. this.unexpected(variance.loc.start);
  4622. }
  4623. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4624. } else {
  4625. let kind = "init";
  4626. if (this.isContextual(98) || this.isContextual(103)) {
  4627. const lookahead = this.lookahead();
  4628. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4629. kind = this.state.value;
  4630. this.next();
  4631. }
  4632. }
  4633. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4634. if (propOrInexact === null) {
  4635. inexact = true;
  4636. inexactStartLoc = this.state.lastTokStartLoc;
  4637. } else {
  4638. nodeStart.properties.push(propOrInexact);
  4639. }
  4640. }
  4641. this.flowObjectTypeSemicolon();
  4642. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4643. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
  4644. at: inexactStartLoc
  4645. });
  4646. }
  4647. }
  4648. this.expect(endDelim);
  4649. if (allowSpread) {
  4650. nodeStart.inexact = inexact;
  4651. }
  4652. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4653. this.state.inType = oldInType;
  4654. return out;
  4655. }
  4656. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4657. if (this.eat(21)) {
  4658. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4659. if (isInexactToken) {
  4660. if (!allowSpread) {
  4661. this.raise(FlowErrors.InexactInsideNonObject, {
  4662. at: this.state.lastTokStartLoc
  4663. });
  4664. } else if (!allowInexact) {
  4665. this.raise(FlowErrors.InexactInsideExact, {
  4666. at: this.state.lastTokStartLoc
  4667. });
  4668. }
  4669. if (variance) {
  4670. this.raise(FlowErrors.InexactVariance, {
  4671. at: variance
  4672. });
  4673. }
  4674. return null;
  4675. }
  4676. if (!allowSpread) {
  4677. this.raise(FlowErrors.UnexpectedSpreadType, {
  4678. at: this.state.lastTokStartLoc
  4679. });
  4680. }
  4681. if (protoStartLoc != null) {
  4682. this.unexpected(protoStartLoc);
  4683. }
  4684. if (variance) {
  4685. this.raise(FlowErrors.SpreadVariance, {
  4686. at: variance
  4687. });
  4688. }
  4689. node.argument = this.flowParseType();
  4690. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4691. } else {
  4692. node.key = this.flowParseObjectPropertyKey();
  4693. node.static = isStatic;
  4694. node.proto = protoStartLoc != null;
  4695. node.kind = kind;
  4696. let optional = false;
  4697. if (this.match(47) || this.match(10)) {
  4698. node.method = true;
  4699. if (protoStartLoc != null) {
  4700. this.unexpected(protoStartLoc);
  4701. }
  4702. if (variance) {
  4703. this.unexpected(variance.loc.start);
  4704. }
  4705. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4706. if (kind === "get" || kind === "set") {
  4707. this.flowCheckGetterSetterParams(node);
  4708. }
  4709. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4710. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  4711. at: node.value.this
  4712. });
  4713. }
  4714. } else {
  4715. if (kind !== "init") this.unexpected();
  4716. node.method = false;
  4717. if (this.eat(17)) {
  4718. optional = true;
  4719. }
  4720. node.value = this.flowParseTypeInitialiser();
  4721. node.variance = variance;
  4722. }
  4723. node.optional = optional;
  4724. return this.finishNode(node, "ObjectTypeProperty");
  4725. }
  4726. }
  4727. flowCheckGetterSetterParams(property) {
  4728. const paramCount = property.kind === "get" ? 0 : 1;
  4729. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4730. if (property.value.this) {
  4731. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
  4732. at: property.value.this
  4733. });
  4734. }
  4735. if (length !== paramCount) {
  4736. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  4737. at: property
  4738. });
  4739. }
  4740. if (property.kind === "set" && property.value.rest) {
  4741. this.raise(Errors.BadSetterRestParameter, {
  4742. at: property
  4743. });
  4744. }
  4745. }
  4746. flowObjectTypeSemicolon() {
  4747. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4748. this.unexpected();
  4749. }
  4750. }
  4751. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4752. var _startLoc;
  4753. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4754. let node = id || this.flowParseRestrictedIdentifier(true);
  4755. while (this.eat(16)) {
  4756. const node2 = this.startNodeAt(startLoc);
  4757. node2.qualification = node;
  4758. node2.id = this.flowParseRestrictedIdentifier(true);
  4759. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4760. }
  4761. return node;
  4762. }
  4763. flowParseGenericType(startLoc, id) {
  4764. const node = this.startNodeAt(startLoc);
  4765. node.typeParameters = null;
  4766. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4767. if (this.match(47)) {
  4768. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4769. }
  4770. return this.finishNode(node, "GenericTypeAnnotation");
  4771. }
  4772. flowParseTypeofType() {
  4773. const node = this.startNode();
  4774. this.expect(87);
  4775. node.argument = this.flowParsePrimaryType();
  4776. return this.finishNode(node, "TypeofTypeAnnotation");
  4777. }
  4778. flowParseTupleType() {
  4779. const node = this.startNode();
  4780. node.types = [];
  4781. this.expect(0);
  4782. while (this.state.pos < this.length && !this.match(3)) {
  4783. node.types.push(this.flowParseType());
  4784. if (this.match(3)) break;
  4785. this.expect(12);
  4786. }
  4787. this.expect(3);
  4788. return this.finishNode(node, "TupleTypeAnnotation");
  4789. }
  4790. flowParseFunctionTypeParam(first) {
  4791. let name = null;
  4792. let optional = false;
  4793. let typeAnnotation = null;
  4794. const node = this.startNode();
  4795. const lh = this.lookahead();
  4796. const isThis = this.state.type === 78;
  4797. if (lh.type === 14 || lh.type === 17) {
  4798. if (isThis && !first) {
  4799. this.raise(FlowErrors.ThisParamMustBeFirst, {
  4800. at: node
  4801. });
  4802. }
  4803. name = this.parseIdentifier(isThis);
  4804. if (this.eat(17)) {
  4805. optional = true;
  4806. if (isThis) {
  4807. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  4808. at: node
  4809. });
  4810. }
  4811. }
  4812. typeAnnotation = this.flowParseTypeInitialiser();
  4813. } else {
  4814. typeAnnotation = this.flowParseType();
  4815. }
  4816. node.name = name;
  4817. node.optional = optional;
  4818. node.typeAnnotation = typeAnnotation;
  4819. return this.finishNode(node, "FunctionTypeParam");
  4820. }
  4821. reinterpretTypeAsFunctionTypeParam(type) {
  4822. const node = this.startNodeAt(type.loc.start);
  4823. node.name = null;
  4824. node.optional = false;
  4825. node.typeAnnotation = type;
  4826. return this.finishNode(node, "FunctionTypeParam");
  4827. }
  4828. flowParseFunctionTypeParams(params = []) {
  4829. let rest = null;
  4830. let _this = null;
  4831. if (this.match(78)) {
  4832. _this = this.flowParseFunctionTypeParam(true);
  4833. _this.name = null;
  4834. if (!this.match(11)) {
  4835. this.expect(12);
  4836. }
  4837. }
  4838. while (!this.match(11) && !this.match(21)) {
  4839. params.push(this.flowParseFunctionTypeParam(false));
  4840. if (!this.match(11)) {
  4841. this.expect(12);
  4842. }
  4843. }
  4844. if (this.eat(21)) {
  4845. rest = this.flowParseFunctionTypeParam(false);
  4846. }
  4847. return {
  4848. params,
  4849. rest,
  4850. _this
  4851. };
  4852. }
  4853. flowIdentToTypeAnnotation(startLoc, node, id) {
  4854. switch (id.name) {
  4855. case "any":
  4856. return this.finishNode(node, "AnyTypeAnnotation");
  4857. case "bool":
  4858. case "boolean":
  4859. return this.finishNode(node, "BooleanTypeAnnotation");
  4860. case "mixed":
  4861. return this.finishNode(node, "MixedTypeAnnotation");
  4862. case "empty":
  4863. return this.finishNode(node, "EmptyTypeAnnotation");
  4864. case "number":
  4865. return this.finishNode(node, "NumberTypeAnnotation");
  4866. case "string":
  4867. return this.finishNode(node, "StringTypeAnnotation");
  4868. case "symbol":
  4869. return this.finishNode(node, "SymbolTypeAnnotation");
  4870. default:
  4871. this.checkNotUnderscore(id.name);
  4872. return this.flowParseGenericType(startLoc, id);
  4873. }
  4874. }
  4875. flowParsePrimaryType() {
  4876. const startLoc = this.state.startLoc;
  4877. const node = this.startNode();
  4878. let tmp;
  4879. let type;
  4880. let isGroupedType = false;
  4881. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4882. switch (this.state.type) {
  4883. case 5:
  4884. return this.flowParseObjectType({
  4885. allowStatic: false,
  4886. allowExact: false,
  4887. allowSpread: true,
  4888. allowProto: false,
  4889. allowInexact: true
  4890. });
  4891. case 6:
  4892. return this.flowParseObjectType({
  4893. allowStatic: false,
  4894. allowExact: true,
  4895. allowSpread: true,
  4896. allowProto: false,
  4897. allowInexact: false
  4898. });
  4899. case 0:
  4900. this.state.noAnonFunctionType = false;
  4901. type = this.flowParseTupleType();
  4902. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4903. return type;
  4904. case 47:
  4905. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4906. this.expect(10);
  4907. tmp = this.flowParseFunctionTypeParams();
  4908. node.params = tmp.params;
  4909. node.rest = tmp.rest;
  4910. node.this = tmp._this;
  4911. this.expect(11);
  4912. this.expect(19);
  4913. node.returnType = this.flowParseType();
  4914. return this.finishNode(node, "FunctionTypeAnnotation");
  4915. case 10:
  4916. this.next();
  4917. if (!this.match(11) && !this.match(21)) {
  4918. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4919. const token = this.lookahead().type;
  4920. isGroupedType = token !== 17 && token !== 14;
  4921. } else {
  4922. isGroupedType = true;
  4923. }
  4924. }
  4925. if (isGroupedType) {
  4926. this.state.noAnonFunctionType = false;
  4927. type = this.flowParseType();
  4928. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4929. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4930. this.expect(11);
  4931. return type;
  4932. } else {
  4933. this.eat(12);
  4934. }
  4935. }
  4936. if (type) {
  4937. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4938. } else {
  4939. tmp = this.flowParseFunctionTypeParams();
  4940. }
  4941. node.params = tmp.params;
  4942. node.rest = tmp.rest;
  4943. node.this = tmp._this;
  4944. this.expect(11);
  4945. this.expect(19);
  4946. node.returnType = this.flowParseType();
  4947. node.typeParameters = null;
  4948. return this.finishNode(node, "FunctionTypeAnnotation");
  4949. case 131:
  4950. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4951. case 85:
  4952. case 86:
  4953. node.value = this.match(85);
  4954. this.next();
  4955. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4956. case 53:
  4957. if (this.state.value === "-") {
  4958. this.next();
  4959. if (this.match(132)) {
  4960. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4961. }
  4962. if (this.match(133)) {
  4963. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4964. }
  4965. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
  4966. at: this.state.startLoc
  4967. });
  4968. }
  4969. this.unexpected();
  4970. return;
  4971. case 132:
  4972. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4973. case 133:
  4974. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4975. case 88:
  4976. this.next();
  4977. return this.finishNode(node, "VoidTypeAnnotation");
  4978. case 84:
  4979. this.next();
  4980. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4981. case 78:
  4982. this.next();
  4983. return this.finishNode(node, "ThisTypeAnnotation");
  4984. case 55:
  4985. this.next();
  4986. return this.finishNode(node, "ExistsTypeAnnotation");
  4987. case 87:
  4988. return this.flowParseTypeofType();
  4989. default:
  4990. if (tokenIsKeyword(this.state.type)) {
  4991. const label = tokenLabelName(this.state.type);
  4992. this.next();
  4993. return super.createIdentifier(node, label);
  4994. } else if (tokenIsIdentifier(this.state.type)) {
  4995. if (this.isContextual(127)) {
  4996. return this.flowParseInterfaceType();
  4997. }
  4998. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4999. }
  5000. }
  5001. this.unexpected();
  5002. }
  5003. flowParsePostfixType() {
  5004. const startLoc = this.state.startLoc;
  5005. let type = this.flowParsePrimaryType();
  5006. let seenOptionalIndexedAccess = false;
  5007. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  5008. const node = this.startNodeAt(startLoc);
  5009. const optional = this.eat(18);
  5010. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  5011. this.expect(0);
  5012. if (!optional && this.match(3)) {
  5013. node.elementType = type;
  5014. this.next();
  5015. type = this.finishNode(node, "ArrayTypeAnnotation");
  5016. } else {
  5017. node.objectType = type;
  5018. node.indexType = this.flowParseType();
  5019. this.expect(3);
  5020. if (seenOptionalIndexedAccess) {
  5021. node.optional = optional;
  5022. type = this.finishNode(node, "OptionalIndexedAccessType");
  5023. } else {
  5024. type = this.finishNode(node, "IndexedAccessType");
  5025. }
  5026. }
  5027. }
  5028. return type;
  5029. }
  5030. flowParsePrefixType() {
  5031. const node = this.startNode();
  5032. if (this.eat(17)) {
  5033. node.typeAnnotation = this.flowParsePrefixType();
  5034. return this.finishNode(node, "NullableTypeAnnotation");
  5035. } else {
  5036. return this.flowParsePostfixType();
  5037. }
  5038. }
  5039. flowParseAnonFunctionWithoutParens() {
  5040. const param = this.flowParsePrefixType();
  5041. if (!this.state.noAnonFunctionType && this.eat(19)) {
  5042. const node = this.startNodeAt(param.loc.start);
  5043. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  5044. node.rest = null;
  5045. node.this = null;
  5046. node.returnType = this.flowParseType();
  5047. node.typeParameters = null;
  5048. return this.finishNode(node, "FunctionTypeAnnotation");
  5049. }
  5050. return param;
  5051. }
  5052. flowParseIntersectionType() {
  5053. const node = this.startNode();
  5054. this.eat(45);
  5055. const type = this.flowParseAnonFunctionWithoutParens();
  5056. node.types = [type];
  5057. while (this.eat(45)) {
  5058. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5059. }
  5060. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5061. }
  5062. flowParseUnionType() {
  5063. const node = this.startNode();
  5064. this.eat(43);
  5065. const type = this.flowParseIntersectionType();
  5066. node.types = [type];
  5067. while (this.eat(43)) {
  5068. node.types.push(this.flowParseIntersectionType());
  5069. }
  5070. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5071. }
  5072. flowParseType() {
  5073. const oldInType = this.state.inType;
  5074. this.state.inType = true;
  5075. const type = this.flowParseUnionType();
  5076. this.state.inType = oldInType;
  5077. return type;
  5078. }
  5079. flowParseTypeOrImplicitInstantiation() {
  5080. if (this.state.type === 130 && this.state.value === "_") {
  5081. const startLoc = this.state.startLoc;
  5082. const node = this.parseIdentifier();
  5083. return this.flowParseGenericType(startLoc, node);
  5084. } else {
  5085. return this.flowParseType();
  5086. }
  5087. }
  5088. flowParseTypeAnnotation() {
  5089. const node = this.startNode();
  5090. node.typeAnnotation = this.flowParseTypeInitialiser();
  5091. return this.finishNode(node, "TypeAnnotation");
  5092. }
  5093. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5094. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5095. if (this.match(14)) {
  5096. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5097. this.resetEndLocation(ident);
  5098. }
  5099. return ident;
  5100. }
  5101. typeCastToParameter(node) {
  5102. node.expression.typeAnnotation = node.typeAnnotation;
  5103. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5104. return node.expression;
  5105. }
  5106. flowParseVariance() {
  5107. let variance = null;
  5108. if (this.match(53)) {
  5109. variance = this.startNode();
  5110. if (this.state.value === "+") {
  5111. variance.kind = "plus";
  5112. } else {
  5113. variance.kind = "minus";
  5114. }
  5115. this.next();
  5116. return this.finishNode(variance, "Variance");
  5117. }
  5118. return variance;
  5119. }
  5120. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5121. if (allowExpressionBody) {
  5122. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5123. return;
  5124. }
  5125. super.parseFunctionBody(node, false, isMethod);
  5126. }
  5127. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5128. if (this.match(14)) {
  5129. const typeNode = this.startNode();
  5130. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5131. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5132. }
  5133. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5134. }
  5135. parseStatementLike(flags) {
  5136. if (this.state.strict && this.isContextual(127)) {
  5137. const lookahead = this.lookahead();
  5138. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5139. const node = this.startNode();
  5140. this.next();
  5141. return this.flowParseInterface(node);
  5142. }
  5143. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  5144. const node = this.startNode();
  5145. this.next();
  5146. return this.flowParseEnumDeclaration(node);
  5147. }
  5148. const stmt = super.parseStatementLike(flags);
  5149. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5150. this.flowPragma = null;
  5151. }
  5152. return stmt;
  5153. }
  5154. parseExpressionStatement(node, expr, decorators) {
  5155. if (expr.type === "Identifier") {
  5156. if (expr.name === "declare") {
  5157. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5158. return this.flowParseDeclare(node);
  5159. }
  5160. } else if (tokenIsIdentifier(this.state.type)) {
  5161. if (expr.name === "interface") {
  5162. return this.flowParseInterface(node);
  5163. } else if (expr.name === "type") {
  5164. return this.flowParseTypeAlias(node);
  5165. } else if (expr.name === "opaque") {
  5166. return this.flowParseOpaqueType(node, false);
  5167. }
  5168. }
  5169. }
  5170. return super.parseExpressionStatement(node, expr, decorators);
  5171. }
  5172. shouldParseExportDeclaration() {
  5173. const {
  5174. type
  5175. } = this.state;
  5176. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5177. return !this.state.containsEsc;
  5178. }
  5179. return super.shouldParseExportDeclaration();
  5180. }
  5181. isExportDefaultSpecifier() {
  5182. const {
  5183. type
  5184. } = this.state;
  5185. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5186. return this.state.containsEsc;
  5187. }
  5188. return super.isExportDefaultSpecifier();
  5189. }
  5190. parseExportDefaultExpression() {
  5191. if (this.shouldParseEnums() && this.isContextual(124)) {
  5192. const node = this.startNode();
  5193. this.next();
  5194. return this.flowParseEnumDeclaration(node);
  5195. }
  5196. return super.parseExportDefaultExpression();
  5197. }
  5198. parseConditional(expr, startLoc, refExpressionErrors) {
  5199. if (!this.match(17)) return expr;
  5200. if (this.state.maybeInArrowParameters) {
  5201. const nextCh = this.lookaheadCharCode();
  5202. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5203. this.setOptionalParametersError(refExpressionErrors);
  5204. return expr;
  5205. }
  5206. }
  5207. this.expect(17);
  5208. const state = this.state.clone();
  5209. const originalNoArrowAt = this.state.noArrowAt;
  5210. const node = this.startNodeAt(startLoc);
  5211. let {
  5212. consequent,
  5213. failed
  5214. } = this.tryParseConditionalConsequent();
  5215. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5216. if (failed || invalid.length > 0) {
  5217. const noArrowAt = [...originalNoArrowAt];
  5218. if (invalid.length > 0) {
  5219. this.state = state;
  5220. this.state.noArrowAt = noArrowAt;
  5221. for (let i = 0; i < invalid.length; i++) {
  5222. noArrowAt.push(invalid[i].start);
  5223. }
  5224. ({
  5225. consequent,
  5226. failed
  5227. } = this.tryParseConditionalConsequent());
  5228. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5229. }
  5230. if (failed && valid.length > 1) {
  5231. this.raise(FlowErrors.AmbiguousConditionalArrow, {
  5232. at: state.startLoc
  5233. });
  5234. }
  5235. if (failed && valid.length === 1) {
  5236. this.state = state;
  5237. noArrowAt.push(valid[0].start);
  5238. this.state.noArrowAt = noArrowAt;
  5239. ({
  5240. consequent,
  5241. failed
  5242. } = this.tryParseConditionalConsequent());
  5243. }
  5244. }
  5245. this.getArrowLikeExpressions(consequent, true);
  5246. this.state.noArrowAt = originalNoArrowAt;
  5247. this.expect(14);
  5248. node.test = expr;
  5249. node.consequent = consequent;
  5250. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5251. return this.finishNode(node, "ConditionalExpression");
  5252. }
  5253. tryParseConditionalConsequent() {
  5254. this.state.noArrowParamsConversionAt.push(this.state.start);
  5255. const consequent = this.parseMaybeAssignAllowIn();
  5256. const failed = !this.match(14);
  5257. this.state.noArrowParamsConversionAt.pop();
  5258. return {
  5259. consequent,
  5260. failed
  5261. };
  5262. }
  5263. getArrowLikeExpressions(node, disallowInvalid) {
  5264. const stack = [node];
  5265. const arrows = [];
  5266. while (stack.length !== 0) {
  5267. const node = stack.pop();
  5268. if (node.type === "ArrowFunctionExpression") {
  5269. if (node.typeParameters || !node.returnType) {
  5270. this.finishArrowValidation(node);
  5271. } else {
  5272. arrows.push(node);
  5273. }
  5274. stack.push(node.body);
  5275. } else if (node.type === "ConditionalExpression") {
  5276. stack.push(node.consequent);
  5277. stack.push(node.alternate);
  5278. }
  5279. }
  5280. if (disallowInvalid) {
  5281. arrows.forEach(node => this.finishArrowValidation(node));
  5282. return [arrows, []];
  5283. }
  5284. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5285. }
  5286. finishArrowValidation(node) {
  5287. var _node$extra;
  5288. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5289. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  5290. super.checkParams(node, false, true);
  5291. this.scope.exit();
  5292. }
  5293. forwardNoArrowParamsConversionAt(node, parse) {
  5294. let result;
  5295. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5296. this.state.noArrowParamsConversionAt.push(this.state.start);
  5297. result = parse();
  5298. this.state.noArrowParamsConversionAt.pop();
  5299. } else {
  5300. result = parse();
  5301. }
  5302. return result;
  5303. }
  5304. parseParenItem(node, startLoc) {
  5305. node = super.parseParenItem(node, startLoc);
  5306. if (this.eat(17)) {
  5307. node.optional = true;
  5308. this.resetEndLocation(node);
  5309. }
  5310. if (this.match(14)) {
  5311. const typeCastNode = this.startNodeAt(startLoc);
  5312. typeCastNode.expression = node;
  5313. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5314. return this.finishNode(typeCastNode, "TypeCastExpression");
  5315. }
  5316. return node;
  5317. }
  5318. assertModuleNodeAllowed(node) {
  5319. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5320. return;
  5321. }
  5322. super.assertModuleNodeAllowed(node);
  5323. }
  5324. parseExport(node, decorators) {
  5325. const decl = super.parseExport(node, decorators);
  5326. if (decl.type === "ExportNamedDeclaration" || decl.type === "ExportAllDeclaration") {
  5327. decl.exportKind = decl.exportKind || "value";
  5328. }
  5329. return decl;
  5330. }
  5331. parseExportDeclaration(node) {
  5332. if (this.isContextual(128)) {
  5333. node.exportKind = "type";
  5334. const declarationNode = this.startNode();
  5335. this.next();
  5336. if (this.match(5)) {
  5337. node.specifiers = this.parseExportSpecifiers(true);
  5338. super.parseExportFrom(node);
  5339. return null;
  5340. } else {
  5341. return this.flowParseTypeAlias(declarationNode);
  5342. }
  5343. } else if (this.isContextual(129)) {
  5344. node.exportKind = "type";
  5345. const declarationNode = this.startNode();
  5346. this.next();
  5347. return this.flowParseOpaqueType(declarationNode, false);
  5348. } else if (this.isContextual(127)) {
  5349. node.exportKind = "type";
  5350. const declarationNode = this.startNode();
  5351. this.next();
  5352. return this.flowParseInterface(declarationNode);
  5353. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  5354. node.exportKind = "value";
  5355. const declarationNode = this.startNode();
  5356. this.next();
  5357. return this.flowParseEnumDeclaration(declarationNode);
  5358. } else {
  5359. return super.parseExportDeclaration(node);
  5360. }
  5361. }
  5362. eatExportStar(node) {
  5363. if (super.eatExportStar(node)) return true;
  5364. if (this.isContextual(128) && this.lookahead().type === 55) {
  5365. node.exportKind = "type";
  5366. this.next();
  5367. this.next();
  5368. return true;
  5369. }
  5370. return false;
  5371. }
  5372. maybeParseExportNamespaceSpecifier(node) {
  5373. const {
  5374. startLoc
  5375. } = this.state;
  5376. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5377. if (hasNamespace && node.exportKind === "type") {
  5378. this.unexpected(startLoc);
  5379. }
  5380. return hasNamespace;
  5381. }
  5382. parseClassId(node, isStatement, optionalId) {
  5383. super.parseClassId(node, isStatement, optionalId);
  5384. if (this.match(47)) {
  5385. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5386. }
  5387. }
  5388. parseClassMember(classBody, member, state) {
  5389. const {
  5390. startLoc
  5391. } = this.state;
  5392. if (this.isContextual(123)) {
  5393. if (super.parseClassMemberFromModifier(classBody, member)) {
  5394. return;
  5395. }
  5396. member.declare = true;
  5397. }
  5398. super.parseClassMember(classBody, member, state);
  5399. if (member.declare) {
  5400. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5401. this.raise(FlowErrors.DeclareClassElement, {
  5402. at: startLoc
  5403. });
  5404. } else if (member.value) {
  5405. this.raise(FlowErrors.DeclareClassFieldInitializer, {
  5406. at: member.value
  5407. });
  5408. }
  5409. }
  5410. }
  5411. isIterator(word) {
  5412. return word === "iterator" || word === "asyncIterator";
  5413. }
  5414. readIterator() {
  5415. const word = super.readWord1();
  5416. const fullWord = "@@" + word;
  5417. if (!this.isIterator(word) || !this.state.inType) {
  5418. this.raise(Errors.InvalidIdentifier, {
  5419. at: this.state.curPosition(),
  5420. identifierName: fullWord
  5421. });
  5422. }
  5423. this.finishToken(130, fullWord);
  5424. }
  5425. getTokenFromCode(code) {
  5426. const next = this.input.charCodeAt(this.state.pos + 1);
  5427. if (code === 123 && next === 124) {
  5428. this.finishOp(6, 2);
  5429. } else if (this.state.inType && (code === 62 || code === 60)) {
  5430. this.finishOp(code === 62 ? 48 : 47, 1);
  5431. } else if (this.state.inType && code === 63) {
  5432. if (next === 46) {
  5433. this.finishOp(18, 2);
  5434. } else {
  5435. this.finishOp(17, 1);
  5436. }
  5437. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5438. this.state.pos += 2;
  5439. this.readIterator();
  5440. } else {
  5441. super.getTokenFromCode(code);
  5442. }
  5443. }
  5444. isAssignable(node, isBinding) {
  5445. if (node.type === "TypeCastExpression") {
  5446. return this.isAssignable(node.expression, isBinding);
  5447. } else {
  5448. return super.isAssignable(node, isBinding);
  5449. }
  5450. }
  5451. toAssignable(node, isLHS = false) {
  5452. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5453. node.left = this.typeCastToParameter(node.left);
  5454. }
  5455. super.toAssignable(node, isLHS);
  5456. }
  5457. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5458. for (let i = 0; i < exprList.length; i++) {
  5459. const expr = exprList[i];
  5460. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5461. exprList[i] = this.typeCastToParameter(expr);
  5462. }
  5463. }
  5464. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5465. }
  5466. toReferencedList(exprList, isParenthesizedExpr) {
  5467. for (let i = 0; i < exprList.length; i++) {
  5468. var _expr$extra;
  5469. const expr = exprList[i];
  5470. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5471. this.raise(FlowErrors.TypeCastInPattern, {
  5472. at: expr.typeAnnotation
  5473. });
  5474. }
  5475. }
  5476. return exprList;
  5477. }
  5478. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5479. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5480. if (canBePattern && !this.state.maybeInArrowParameters) {
  5481. this.toReferencedList(node.elements);
  5482. }
  5483. return node;
  5484. }
  5485. isValidLVal(type, isParenthesized, binding) {
  5486. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5487. }
  5488. parseClassProperty(node) {
  5489. if (this.match(14)) {
  5490. node.typeAnnotation = this.flowParseTypeAnnotation();
  5491. }
  5492. return super.parseClassProperty(node);
  5493. }
  5494. parseClassPrivateProperty(node) {
  5495. if (this.match(14)) {
  5496. node.typeAnnotation = this.flowParseTypeAnnotation();
  5497. }
  5498. return super.parseClassPrivateProperty(node);
  5499. }
  5500. isClassMethod() {
  5501. return this.match(47) || super.isClassMethod();
  5502. }
  5503. isClassProperty() {
  5504. return this.match(14) || super.isClassProperty();
  5505. }
  5506. isNonstaticConstructor(method) {
  5507. return !this.match(14) && super.isNonstaticConstructor(method);
  5508. }
  5509. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5510. if (method.variance) {
  5511. this.unexpected(method.variance.loc.start);
  5512. }
  5513. delete method.variance;
  5514. if (this.match(47)) {
  5515. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5516. }
  5517. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5518. if (method.params && isConstructor) {
  5519. const params = method.params;
  5520. if (params.length > 0 && this.isThisParam(params[0])) {
  5521. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5522. at: method
  5523. });
  5524. }
  5525. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5526. const params = method.value.params;
  5527. if (params.length > 0 && this.isThisParam(params[0])) {
  5528. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5529. at: method
  5530. });
  5531. }
  5532. }
  5533. }
  5534. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5535. if (method.variance) {
  5536. this.unexpected(method.variance.loc.start);
  5537. }
  5538. delete method.variance;
  5539. if (this.match(47)) {
  5540. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5541. }
  5542. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5543. }
  5544. parseClassSuper(node) {
  5545. super.parseClassSuper(node);
  5546. if (node.superClass && this.match(47)) {
  5547. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  5548. }
  5549. if (this.isContextual(111)) {
  5550. this.next();
  5551. const implemented = node.implements = [];
  5552. do {
  5553. const node = this.startNode();
  5554. node.id = this.flowParseRestrictedIdentifier(true);
  5555. if (this.match(47)) {
  5556. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5557. } else {
  5558. node.typeParameters = null;
  5559. }
  5560. implemented.push(this.finishNode(node, "ClassImplements"));
  5561. } while (this.eat(12));
  5562. }
  5563. }
  5564. checkGetterSetterParams(method) {
  5565. super.checkGetterSetterParams(method);
  5566. const params = this.getObjectOrClassMethodParams(method);
  5567. if (params.length > 0) {
  5568. const param = params[0];
  5569. if (this.isThisParam(param) && method.kind === "get") {
  5570. this.raise(FlowErrors.GetterMayNotHaveThisParam, {
  5571. at: param
  5572. });
  5573. } else if (this.isThisParam(param)) {
  5574. this.raise(FlowErrors.SetterMayNotHaveThisParam, {
  5575. at: param
  5576. });
  5577. }
  5578. }
  5579. }
  5580. parsePropertyNamePrefixOperator(node) {
  5581. node.variance = this.flowParseVariance();
  5582. }
  5583. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5584. if (prop.variance) {
  5585. this.unexpected(prop.variance.loc.start);
  5586. }
  5587. delete prop.variance;
  5588. let typeParameters;
  5589. if (this.match(47) && !isAccessor) {
  5590. typeParameters = this.flowParseTypeParameterDeclaration();
  5591. if (!this.match(10)) this.unexpected();
  5592. }
  5593. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5594. if (typeParameters) {
  5595. (result.value || result).typeParameters = typeParameters;
  5596. }
  5597. return result;
  5598. }
  5599. parseAssignableListItemTypes(param) {
  5600. if (this.eat(17)) {
  5601. if (param.type !== "Identifier") {
  5602. this.raise(FlowErrors.PatternIsOptional, {
  5603. at: param
  5604. });
  5605. }
  5606. if (this.isThisParam(param)) {
  5607. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  5608. at: param
  5609. });
  5610. }
  5611. param.optional = true;
  5612. }
  5613. if (this.match(14)) {
  5614. param.typeAnnotation = this.flowParseTypeAnnotation();
  5615. } else if (this.isThisParam(param)) {
  5616. this.raise(FlowErrors.ThisParamAnnotationRequired, {
  5617. at: param
  5618. });
  5619. }
  5620. if (this.match(29) && this.isThisParam(param)) {
  5621. this.raise(FlowErrors.ThisParamNoDefault, {
  5622. at: param
  5623. });
  5624. }
  5625. this.resetEndLocation(param);
  5626. return param;
  5627. }
  5628. parseMaybeDefault(startLoc, left) {
  5629. const node = super.parseMaybeDefault(startLoc, left);
  5630. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5631. this.raise(FlowErrors.TypeBeforeInitializer, {
  5632. at: node.typeAnnotation
  5633. });
  5634. }
  5635. return node;
  5636. }
  5637. shouldParseDefaultImport(node) {
  5638. if (!hasTypeImportKind(node)) {
  5639. return super.shouldParseDefaultImport(node);
  5640. }
  5641. return isMaybeDefaultImport(this.state.type);
  5642. }
  5643. checkImportReflection(node) {
  5644. super.checkImportReflection(node);
  5645. if (node.module && node.importKind !== "value") {
  5646. this.raise(FlowErrors.ImportReflectionHasImportType, {
  5647. at: node.specifiers[0].loc.start
  5648. });
  5649. }
  5650. }
  5651. parseImportSpecifierLocal(node, specifier, type) {
  5652. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5653. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5654. }
  5655. maybeParseDefaultImportSpecifier(node) {
  5656. node.importKind = "value";
  5657. let kind = null;
  5658. if (this.match(87)) {
  5659. kind = "typeof";
  5660. } else if (this.isContextual(128)) {
  5661. kind = "type";
  5662. }
  5663. if (kind) {
  5664. const lh = this.lookahead();
  5665. const {
  5666. type
  5667. } = lh;
  5668. if (kind === "type" && type === 55) {
  5669. this.unexpected(null, lh.type);
  5670. }
  5671. if (isMaybeDefaultImport(type) || type === 5 || type === 55) {
  5672. this.next();
  5673. node.importKind = kind;
  5674. }
  5675. }
  5676. return super.maybeParseDefaultImportSpecifier(node);
  5677. }
  5678. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5679. const firstIdent = specifier.imported;
  5680. let specifierTypeKind = null;
  5681. if (firstIdent.type === "Identifier") {
  5682. if (firstIdent.name === "type") {
  5683. specifierTypeKind = "type";
  5684. } else if (firstIdent.name === "typeof") {
  5685. specifierTypeKind = "typeof";
  5686. }
  5687. }
  5688. let isBinding = false;
  5689. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5690. const as_ident = this.parseIdentifier(true);
  5691. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5692. specifier.imported = as_ident;
  5693. specifier.importKind = specifierTypeKind;
  5694. specifier.local = cloneIdentifier(as_ident);
  5695. } else {
  5696. specifier.imported = firstIdent;
  5697. specifier.importKind = null;
  5698. specifier.local = this.parseIdentifier();
  5699. }
  5700. } else {
  5701. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5702. specifier.imported = this.parseIdentifier(true);
  5703. specifier.importKind = specifierTypeKind;
  5704. } else {
  5705. if (importedIsString) {
  5706. throw this.raise(Errors.ImportBindingIsString, {
  5707. at: specifier,
  5708. importName: firstIdent.value
  5709. });
  5710. }
  5711. specifier.imported = firstIdent;
  5712. specifier.importKind = null;
  5713. }
  5714. if (this.eatContextual(93)) {
  5715. specifier.local = this.parseIdentifier();
  5716. } else {
  5717. isBinding = true;
  5718. specifier.local = cloneIdentifier(specifier.imported);
  5719. }
  5720. }
  5721. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5722. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5723. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
  5724. at: specifier
  5725. });
  5726. }
  5727. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5728. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5729. }
  5730. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5731. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5732. }
  5733. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5734. }
  5735. parseBindingAtom() {
  5736. switch (this.state.type) {
  5737. case 78:
  5738. return this.parseIdentifier(true);
  5739. default:
  5740. return super.parseBindingAtom();
  5741. }
  5742. }
  5743. parseFunctionParams(node, isConstructor) {
  5744. const kind = node.kind;
  5745. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5746. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5747. }
  5748. super.parseFunctionParams(node, isConstructor);
  5749. }
  5750. parseVarId(decl, kind) {
  5751. super.parseVarId(decl, kind);
  5752. if (this.match(14)) {
  5753. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5754. this.resetEndLocation(decl.id);
  5755. }
  5756. }
  5757. parseAsyncArrowFromCallExpression(node, call) {
  5758. if (this.match(14)) {
  5759. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5760. this.state.noAnonFunctionType = true;
  5761. node.returnType = this.flowParseTypeAnnotation();
  5762. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5763. }
  5764. return super.parseAsyncArrowFromCallExpression(node, call);
  5765. }
  5766. shouldParseAsyncArrow() {
  5767. return this.match(14) || super.shouldParseAsyncArrow();
  5768. }
  5769. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5770. var _jsx;
  5771. let state = null;
  5772. let jsx;
  5773. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  5774. state = this.state.clone();
  5775. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5776. if (!jsx.error) return jsx.node;
  5777. const {
  5778. context
  5779. } = this.state;
  5780. const currentContext = context[context.length - 1];
  5781. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5782. context.pop();
  5783. }
  5784. }
  5785. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5786. var _jsx2, _jsx3;
  5787. state = state || this.state.clone();
  5788. let typeParameters;
  5789. const arrow = this.tryParse(abort => {
  5790. var _arrowExpression$extr;
  5791. typeParameters = this.flowParseTypeParameterDeclaration();
  5792. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5793. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5794. this.resetStartLocationFromNode(result, typeParameters);
  5795. return result;
  5796. });
  5797. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5798. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5799. if (expr.type !== "ArrowFunctionExpression") abort();
  5800. expr.typeParameters = typeParameters;
  5801. this.resetStartLocationFromNode(expr, typeParameters);
  5802. return arrowExpression;
  5803. }, state);
  5804. let arrowExpression = null;
  5805. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5806. if (!arrow.error && !arrow.aborted) {
  5807. if (arrow.node.async) {
  5808. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
  5809. at: typeParameters
  5810. });
  5811. }
  5812. return arrow.node;
  5813. }
  5814. arrowExpression = arrow.node;
  5815. }
  5816. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5817. this.state = jsx.failState;
  5818. return jsx.node;
  5819. }
  5820. if (arrowExpression) {
  5821. this.state = arrow.failState;
  5822. return arrowExpression;
  5823. }
  5824. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5825. if (arrow.thrown) throw arrow.error;
  5826. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
  5827. at: typeParameters
  5828. });
  5829. }
  5830. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5831. }
  5832. parseArrow(node) {
  5833. if (this.match(14)) {
  5834. const result = this.tryParse(() => {
  5835. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5836. this.state.noAnonFunctionType = true;
  5837. const typeNode = this.startNode();
  5838. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5839. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5840. if (this.canInsertSemicolon()) this.unexpected();
  5841. if (!this.match(19)) this.unexpected();
  5842. return typeNode;
  5843. });
  5844. if (result.thrown) return null;
  5845. if (result.error) this.state = result.failState;
  5846. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5847. }
  5848. return super.parseArrow(node);
  5849. }
  5850. shouldParseArrow(params) {
  5851. return this.match(14) || super.shouldParseArrow(params);
  5852. }
  5853. setArrowFunctionParameters(node, params) {
  5854. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5855. node.params = params;
  5856. } else {
  5857. super.setArrowFunctionParameters(node, params);
  5858. }
  5859. }
  5860. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5861. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5862. return;
  5863. }
  5864. for (let i = 0; i < node.params.length; i++) {
  5865. if (this.isThisParam(node.params[i]) && i > 0) {
  5866. this.raise(FlowErrors.ThisParamMustBeFirst, {
  5867. at: node.params[i]
  5868. });
  5869. }
  5870. }
  5871. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5872. }
  5873. parseParenAndDistinguishExpression(canBeArrow) {
  5874. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  5875. }
  5876. parseSubscripts(base, startLoc, noCalls) {
  5877. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
  5878. this.next();
  5879. const node = this.startNodeAt(startLoc);
  5880. node.callee = base;
  5881. node.arguments = super.parseCallExpressionArguments(11, false);
  5882. base = this.finishNode(node, "CallExpression");
  5883. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5884. const state = this.state.clone();
  5885. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5886. if (!arrow.error && !arrow.aborted) return arrow.node;
  5887. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5888. if (result.node && !result.error) return result.node;
  5889. if (arrow.node) {
  5890. this.state = arrow.failState;
  5891. return arrow.node;
  5892. }
  5893. if (result.node) {
  5894. this.state = result.failState;
  5895. return result.node;
  5896. }
  5897. throw arrow.error || result.error;
  5898. }
  5899. return super.parseSubscripts(base, startLoc, noCalls);
  5900. }
  5901. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5902. if (this.match(18) && this.isLookaheadToken_lt()) {
  5903. subscriptState.optionalChainMember = true;
  5904. if (noCalls) {
  5905. subscriptState.stop = true;
  5906. return base;
  5907. }
  5908. this.next();
  5909. const node = this.startNodeAt(startLoc);
  5910. node.callee = base;
  5911. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5912. this.expect(10);
  5913. node.arguments = this.parseCallExpressionArguments(11, false);
  5914. node.optional = true;
  5915. return this.finishCallExpression(node, true);
  5916. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  5917. const node = this.startNodeAt(startLoc);
  5918. node.callee = base;
  5919. const result = this.tryParse(() => {
  5920. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5921. this.expect(10);
  5922. node.arguments = super.parseCallExpressionArguments(11, false);
  5923. if (subscriptState.optionalChainMember) {
  5924. node.optional = false;
  5925. }
  5926. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5927. });
  5928. if (result.node) {
  5929. if (result.error) this.state = result.failState;
  5930. return result.node;
  5931. }
  5932. }
  5933. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5934. }
  5935. parseNewCallee(node) {
  5936. super.parseNewCallee(node);
  5937. let targs = null;
  5938. if (this.shouldParseTypes() && this.match(47)) {
  5939. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5940. }
  5941. node.typeArguments = targs;
  5942. }
  5943. parseAsyncArrowWithTypeParameters(startLoc) {
  5944. const node = this.startNodeAt(startLoc);
  5945. this.parseFunctionParams(node, false);
  5946. if (!this.parseArrow(node)) return;
  5947. return super.parseArrowExpression(node, undefined, true);
  5948. }
  5949. readToken_mult_modulo(code) {
  5950. const next = this.input.charCodeAt(this.state.pos + 1);
  5951. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5952. this.state.hasFlowComment = false;
  5953. this.state.pos += 2;
  5954. this.nextToken();
  5955. return;
  5956. }
  5957. super.readToken_mult_modulo(code);
  5958. }
  5959. readToken_pipe_amp(code) {
  5960. const next = this.input.charCodeAt(this.state.pos + 1);
  5961. if (code === 124 && next === 125) {
  5962. this.finishOp(9, 2);
  5963. return;
  5964. }
  5965. super.readToken_pipe_amp(code);
  5966. }
  5967. parseTopLevel(file, program) {
  5968. const fileNode = super.parseTopLevel(file, program);
  5969. if (this.state.hasFlowComment) {
  5970. this.raise(FlowErrors.UnterminatedFlowComment, {
  5971. at: this.state.curPosition()
  5972. });
  5973. }
  5974. return fileNode;
  5975. }
  5976. skipBlockComment() {
  5977. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5978. if (this.state.hasFlowComment) {
  5979. throw this.raise(FlowErrors.NestedFlowComment, {
  5980. at: this.state.startLoc
  5981. });
  5982. }
  5983. this.hasFlowCommentCompletion();
  5984. const commentSkip = this.skipFlowComment();
  5985. if (commentSkip) {
  5986. this.state.pos += commentSkip;
  5987. this.state.hasFlowComment = true;
  5988. }
  5989. return;
  5990. }
  5991. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5992. }
  5993. skipFlowComment() {
  5994. const {
  5995. pos
  5996. } = this.state;
  5997. let shiftToFirstNonWhiteSpace = 2;
  5998. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5999. shiftToFirstNonWhiteSpace++;
  6000. }
  6001. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  6002. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  6003. if (ch2 === 58 && ch3 === 58) {
  6004. return shiftToFirstNonWhiteSpace + 2;
  6005. }
  6006. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  6007. return shiftToFirstNonWhiteSpace + 12;
  6008. }
  6009. if (ch2 === 58 && ch3 !== 58) {
  6010. return shiftToFirstNonWhiteSpace;
  6011. }
  6012. return false;
  6013. }
  6014. hasFlowCommentCompletion() {
  6015. const end = this.input.indexOf("*/", this.state.pos);
  6016. if (end === -1) {
  6017. throw this.raise(Errors.UnterminatedComment, {
  6018. at: this.state.curPosition()
  6019. });
  6020. }
  6021. }
  6022. flowEnumErrorBooleanMemberNotInitialized(loc, {
  6023. enumName,
  6024. memberName
  6025. }) {
  6026. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
  6027. at: loc,
  6028. memberName,
  6029. enumName
  6030. });
  6031. }
  6032. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  6033. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
  6034. at: loc
  6035. }, enumContext));
  6036. }
  6037. flowEnumErrorNumberMemberNotInitialized(loc, {
  6038. enumName,
  6039. memberName
  6040. }) {
  6041. this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
  6042. at: loc,
  6043. enumName,
  6044. memberName
  6045. });
  6046. }
  6047. flowEnumErrorStringMemberInconsistentlyInitailized(node, {
  6048. enumName
  6049. }) {
  6050. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitailized, {
  6051. at: node,
  6052. enumName
  6053. });
  6054. }
  6055. flowEnumMemberInit() {
  6056. const startLoc = this.state.startLoc;
  6057. const endOfInit = () => this.match(12) || this.match(8);
  6058. switch (this.state.type) {
  6059. case 132:
  6060. {
  6061. const literal = this.parseNumericLiteral(this.state.value);
  6062. if (endOfInit()) {
  6063. return {
  6064. type: "number",
  6065. loc: literal.loc.start,
  6066. value: literal
  6067. };
  6068. }
  6069. return {
  6070. type: "invalid",
  6071. loc: startLoc
  6072. };
  6073. }
  6074. case 131:
  6075. {
  6076. const literal = this.parseStringLiteral(this.state.value);
  6077. if (endOfInit()) {
  6078. return {
  6079. type: "string",
  6080. loc: literal.loc.start,
  6081. value: literal
  6082. };
  6083. }
  6084. return {
  6085. type: "invalid",
  6086. loc: startLoc
  6087. };
  6088. }
  6089. case 85:
  6090. case 86:
  6091. {
  6092. const literal = this.parseBooleanLiteral(this.match(85));
  6093. if (endOfInit()) {
  6094. return {
  6095. type: "boolean",
  6096. loc: literal.loc.start,
  6097. value: literal
  6098. };
  6099. }
  6100. return {
  6101. type: "invalid",
  6102. loc: startLoc
  6103. };
  6104. }
  6105. default:
  6106. return {
  6107. type: "invalid",
  6108. loc: startLoc
  6109. };
  6110. }
  6111. }
  6112. flowEnumMemberRaw() {
  6113. const loc = this.state.startLoc;
  6114. const id = this.parseIdentifier(true);
  6115. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6116. type: "none",
  6117. loc
  6118. };
  6119. return {
  6120. id,
  6121. init
  6122. };
  6123. }
  6124. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6125. const {
  6126. explicitType
  6127. } = context;
  6128. if (explicitType === null) {
  6129. return;
  6130. }
  6131. if (explicitType !== expectedType) {
  6132. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6133. }
  6134. }
  6135. flowEnumMembers({
  6136. enumName,
  6137. explicitType
  6138. }) {
  6139. const seenNames = new Set();
  6140. const members = {
  6141. booleanMembers: [],
  6142. numberMembers: [],
  6143. stringMembers: [],
  6144. defaultedMembers: []
  6145. };
  6146. let hasUnknownMembers = false;
  6147. while (!this.match(8)) {
  6148. if (this.eat(21)) {
  6149. hasUnknownMembers = true;
  6150. break;
  6151. }
  6152. const memberNode = this.startNode();
  6153. const {
  6154. id,
  6155. init
  6156. } = this.flowEnumMemberRaw();
  6157. const memberName = id.name;
  6158. if (memberName === "") {
  6159. continue;
  6160. }
  6161. if (/^[a-z]/.test(memberName)) {
  6162. this.raise(FlowErrors.EnumInvalidMemberName, {
  6163. at: id,
  6164. memberName,
  6165. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6166. enumName
  6167. });
  6168. }
  6169. if (seenNames.has(memberName)) {
  6170. this.raise(FlowErrors.EnumDuplicateMemberName, {
  6171. at: id,
  6172. memberName,
  6173. enumName
  6174. });
  6175. }
  6176. seenNames.add(memberName);
  6177. const context = {
  6178. enumName,
  6179. explicitType,
  6180. memberName
  6181. };
  6182. memberNode.id = id;
  6183. switch (init.type) {
  6184. case "boolean":
  6185. {
  6186. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6187. memberNode.init = init.value;
  6188. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6189. break;
  6190. }
  6191. case "number":
  6192. {
  6193. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6194. memberNode.init = init.value;
  6195. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6196. break;
  6197. }
  6198. case "string":
  6199. {
  6200. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6201. memberNode.init = init.value;
  6202. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6203. break;
  6204. }
  6205. case "invalid":
  6206. {
  6207. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6208. }
  6209. case "none":
  6210. {
  6211. switch (explicitType) {
  6212. case "boolean":
  6213. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6214. break;
  6215. case "number":
  6216. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6217. break;
  6218. default:
  6219. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6220. }
  6221. }
  6222. }
  6223. if (!this.match(8)) {
  6224. this.expect(12);
  6225. }
  6226. }
  6227. return {
  6228. members,
  6229. hasUnknownMembers
  6230. };
  6231. }
  6232. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6233. enumName
  6234. }) {
  6235. if (initializedMembers.length === 0) {
  6236. return defaultedMembers;
  6237. } else if (defaultedMembers.length === 0) {
  6238. return initializedMembers;
  6239. } else if (defaultedMembers.length > initializedMembers.length) {
  6240. for (const member of initializedMembers) {
  6241. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6242. enumName
  6243. });
  6244. }
  6245. return defaultedMembers;
  6246. } else {
  6247. for (const member of defaultedMembers) {
  6248. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6249. enumName
  6250. });
  6251. }
  6252. return initializedMembers;
  6253. }
  6254. }
  6255. flowEnumParseExplicitType({
  6256. enumName
  6257. }) {
  6258. if (!this.eatContextual(101)) return null;
  6259. if (!tokenIsIdentifier(this.state.type)) {
  6260. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
  6261. at: this.state.startLoc,
  6262. enumName
  6263. });
  6264. }
  6265. const {
  6266. value
  6267. } = this.state;
  6268. this.next();
  6269. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6270. this.raise(FlowErrors.EnumInvalidExplicitType, {
  6271. at: this.state.startLoc,
  6272. enumName,
  6273. invalidEnumType: value
  6274. });
  6275. }
  6276. return value;
  6277. }
  6278. flowEnumBody(node, id) {
  6279. const enumName = id.name;
  6280. const nameLoc = id.loc.start;
  6281. const explicitType = this.flowEnumParseExplicitType({
  6282. enumName
  6283. });
  6284. this.expect(5);
  6285. const {
  6286. members,
  6287. hasUnknownMembers
  6288. } = this.flowEnumMembers({
  6289. enumName,
  6290. explicitType
  6291. });
  6292. node.hasUnknownMembers = hasUnknownMembers;
  6293. switch (explicitType) {
  6294. case "boolean":
  6295. node.explicitType = true;
  6296. node.members = members.booleanMembers;
  6297. this.expect(8);
  6298. return this.finishNode(node, "EnumBooleanBody");
  6299. case "number":
  6300. node.explicitType = true;
  6301. node.members = members.numberMembers;
  6302. this.expect(8);
  6303. return this.finishNode(node, "EnumNumberBody");
  6304. case "string":
  6305. node.explicitType = true;
  6306. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6307. enumName
  6308. });
  6309. this.expect(8);
  6310. return this.finishNode(node, "EnumStringBody");
  6311. case "symbol":
  6312. node.members = members.defaultedMembers;
  6313. this.expect(8);
  6314. return this.finishNode(node, "EnumSymbolBody");
  6315. default:
  6316. {
  6317. const empty = () => {
  6318. node.members = [];
  6319. this.expect(8);
  6320. return this.finishNode(node, "EnumStringBody");
  6321. };
  6322. node.explicitType = false;
  6323. const boolsLen = members.booleanMembers.length;
  6324. const numsLen = members.numberMembers.length;
  6325. const strsLen = members.stringMembers.length;
  6326. const defaultedLen = members.defaultedMembers.length;
  6327. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6328. return empty();
  6329. } else if (!boolsLen && !numsLen) {
  6330. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6331. enumName
  6332. });
  6333. this.expect(8);
  6334. return this.finishNode(node, "EnumStringBody");
  6335. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6336. for (const member of members.defaultedMembers) {
  6337. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6338. enumName,
  6339. memberName: member.id.name
  6340. });
  6341. }
  6342. node.members = members.booleanMembers;
  6343. this.expect(8);
  6344. return this.finishNode(node, "EnumBooleanBody");
  6345. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6346. for (const member of members.defaultedMembers) {
  6347. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6348. enumName,
  6349. memberName: member.id.name
  6350. });
  6351. }
  6352. node.members = members.numberMembers;
  6353. this.expect(8);
  6354. return this.finishNode(node, "EnumNumberBody");
  6355. } else {
  6356. this.raise(FlowErrors.EnumInconsistentMemberValues, {
  6357. at: nameLoc,
  6358. enumName
  6359. });
  6360. return empty();
  6361. }
  6362. }
  6363. }
  6364. }
  6365. flowParseEnumDeclaration(node) {
  6366. const id = this.parseIdentifier();
  6367. node.id = id;
  6368. node.body = this.flowEnumBody(this.startNode(), id);
  6369. return this.finishNode(node, "EnumDeclaration");
  6370. }
  6371. isLookaheadToken_lt() {
  6372. const next = this.nextTokenStart();
  6373. if (this.input.charCodeAt(next) === 60) {
  6374. const afterNext = this.input.charCodeAt(next + 1);
  6375. return afterNext !== 60 && afterNext !== 61;
  6376. }
  6377. return false;
  6378. }
  6379. maybeUnwrapTypeCastExpression(node) {
  6380. return node.type === "TypeCastExpression" ? node.expression : node;
  6381. }
  6382. };
  6383. const entities = {
  6384. __proto__: null,
  6385. quot: "\u0022",
  6386. amp: "&",
  6387. apos: "\u0027",
  6388. lt: "<",
  6389. gt: ">",
  6390. nbsp: "\u00A0",
  6391. iexcl: "\u00A1",
  6392. cent: "\u00A2",
  6393. pound: "\u00A3",
  6394. curren: "\u00A4",
  6395. yen: "\u00A5",
  6396. brvbar: "\u00A6",
  6397. sect: "\u00A7",
  6398. uml: "\u00A8",
  6399. copy: "\u00A9",
  6400. ordf: "\u00AA",
  6401. laquo: "\u00AB",
  6402. not: "\u00AC",
  6403. shy: "\u00AD",
  6404. reg: "\u00AE",
  6405. macr: "\u00AF",
  6406. deg: "\u00B0",
  6407. plusmn: "\u00B1",
  6408. sup2: "\u00B2",
  6409. sup3: "\u00B3",
  6410. acute: "\u00B4",
  6411. micro: "\u00B5",
  6412. para: "\u00B6",
  6413. middot: "\u00B7",
  6414. cedil: "\u00B8",
  6415. sup1: "\u00B9",
  6416. ordm: "\u00BA",
  6417. raquo: "\u00BB",
  6418. frac14: "\u00BC",
  6419. frac12: "\u00BD",
  6420. frac34: "\u00BE",
  6421. iquest: "\u00BF",
  6422. Agrave: "\u00C0",
  6423. Aacute: "\u00C1",
  6424. Acirc: "\u00C2",
  6425. Atilde: "\u00C3",
  6426. Auml: "\u00C4",
  6427. Aring: "\u00C5",
  6428. AElig: "\u00C6",
  6429. Ccedil: "\u00C7",
  6430. Egrave: "\u00C8",
  6431. Eacute: "\u00C9",
  6432. Ecirc: "\u00CA",
  6433. Euml: "\u00CB",
  6434. Igrave: "\u00CC",
  6435. Iacute: "\u00CD",
  6436. Icirc: "\u00CE",
  6437. Iuml: "\u00CF",
  6438. ETH: "\u00D0",
  6439. Ntilde: "\u00D1",
  6440. Ograve: "\u00D2",
  6441. Oacute: "\u00D3",
  6442. Ocirc: "\u00D4",
  6443. Otilde: "\u00D5",
  6444. Ouml: "\u00D6",
  6445. times: "\u00D7",
  6446. Oslash: "\u00D8",
  6447. Ugrave: "\u00D9",
  6448. Uacute: "\u00DA",
  6449. Ucirc: "\u00DB",
  6450. Uuml: "\u00DC",
  6451. Yacute: "\u00DD",
  6452. THORN: "\u00DE",
  6453. szlig: "\u00DF",
  6454. agrave: "\u00E0",
  6455. aacute: "\u00E1",
  6456. acirc: "\u00E2",
  6457. atilde: "\u00E3",
  6458. auml: "\u00E4",
  6459. aring: "\u00E5",
  6460. aelig: "\u00E6",
  6461. ccedil: "\u00E7",
  6462. egrave: "\u00E8",
  6463. eacute: "\u00E9",
  6464. ecirc: "\u00EA",
  6465. euml: "\u00EB",
  6466. igrave: "\u00EC",
  6467. iacute: "\u00ED",
  6468. icirc: "\u00EE",
  6469. iuml: "\u00EF",
  6470. eth: "\u00F0",
  6471. ntilde: "\u00F1",
  6472. ograve: "\u00F2",
  6473. oacute: "\u00F3",
  6474. ocirc: "\u00F4",
  6475. otilde: "\u00F5",
  6476. ouml: "\u00F6",
  6477. divide: "\u00F7",
  6478. oslash: "\u00F8",
  6479. ugrave: "\u00F9",
  6480. uacute: "\u00FA",
  6481. ucirc: "\u00FB",
  6482. uuml: "\u00FC",
  6483. yacute: "\u00FD",
  6484. thorn: "\u00FE",
  6485. yuml: "\u00FF",
  6486. OElig: "\u0152",
  6487. oelig: "\u0153",
  6488. Scaron: "\u0160",
  6489. scaron: "\u0161",
  6490. Yuml: "\u0178",
  6491. fnof: "\u0192",
  6492. circ: "\u02C6",
  6493. tilde: "\u02DC",
  6494. Alpha: "\u0391",
  6495. Beta: "\u0392",
  6496. Gamma: "\u0393",
  6497. Delta: "\u0394",
  6498. Epsilon: "\u0395",
  6499. Zeta: "\u0396",
  6500. Eta: "\u0397",
  6501. Theta: "\u0398",
  6502. Iota: "\u0399",
  6503. Kappa: "\u039A",
  6504. Lambda: "\u039B",
  6505. Mu: "\u039C",
  6506. Nu: "\u039D",
  6507. Xi: "\u039E",
  6508. Omicron: "\u039F",
  6509. Pi: "\u03A0",
  6510. Rho: "\u03A1",
  6511. Sigma: "\u03A3",
  6512. Tau: "\u03A4",
  6513. Upsilon: "\u03A5",
  6514. Phi: "\u03A6",
  6515. Chi: "\u03A7",
  6516. Psi: "\u03A8",
  6517. Omega: "\u03A9",
  6518. alpha: "\u03B1",
  6519. beta: "\u03B2",
  6520. gamma: "\u03B3",
  6521. delta: "\u03B4",
  6522. epsilon: "\u03B5",
  6523. zeta: "\u03B6",
  6524. eta: "\u03B7",
  6525. theta: "\u03B8",
  6526. iota: "\u03B9",
  6527. kappa: "\u03BA",
  6528. lambda: "\u03BB",
  6529. mu: "\u03BC",
  6530. nu: "\u03BD",
  6531. xi: "\u03BE",
  6532. omicron: "\u03BF",
  6533. pi: "\u03C0",
  6534. rho: "\u03C1",
  6535. sigmaf: "\u03C2",
  6536. sigma: "\u03C3",
  6537. tau: "\u03C4",
  6538. upsilon: "\u03C5",
  6539. phi: "\u03C6",
  6540. chi: "\u03C7",
  6541. psi: "\u03C8",
  6542. omega: "\u03C9",
  6543. thetasym: "\u03D1",
  6544. upsih: "\u03D2",
  6545. piv: "\u03D6",
  6546. ensp: "\u2002",
  6547. emsp: "\u2003",
  6548. thinsp: "\u2009",
  6549. zwnj: "\u200C",
  6550. zwj: "\u200D",
  6551. lrm: "\u200E",
  6552. rlm: "\u200F",
  6553. ndash: "\u2013",
  6554. mdash: "\u2014",
  6555. lsquo: "\u2018",
  6556. rsquo: "\u2019",
  6557. sbquo: "\u201A",
  6558. ldquo: "\u201C",
  6559. rdquo: "\u201D",
  6560. bdquo: "\u201E",
  6561. dagger: "\u2020",
  6562. Dagger: "\u2021",
  6563. bull: "\u2022",
  6564. hellip: "\u2026",
  6565. permil: "\u2030",
  6566. prime: "\u2032",
  6567. Prime: "\u2033",
  6568. lsaquo: "\u2039",
  6569. rsaquo: "\u203A",
  6570. oline: "\u203E",
  6571. frasl: "\u2044",
  6572. euro: "\u20AC",
  6573. image: "\u2111",
  6574. weierp: "\u2118",
  6575. real: "\u211C",
  6576. trade: "\u2122",
  6577. alefsym: "\u2135",
  6578. larr: "\u2190",
  6579. uarr: "\u2191",
  6580. rarr: "\u2192",
  6581. darr: "\u2193",
  6582. harr: "\u2194",
  6583. crarr: "\u21B5",
  6584. lArr: "\u21D0",
  6585. uArr: "\u21D1",
  6586. rArr: "\u21D2",
  6587. dArr: "\u21D3",
  6588. hArr: "\u21D4",
  6589. forall: "\u2200",
  6590. part: "\u2202",
  6591. exist: "\u2203",
  6592. empty: "\u2205",
  6593. nabla: "\u2207",
  6594. isin: "\u2208",
  6595. notin: "\u2209",
  6596. ni: "\u220B",
  6597. prod: "\u220F",
  6598. sum: "\u2211",
  6599. minus: "\u2212",
  6600. lowast: "\u2217",
  6601. radic: "\u221A",
  6602. prop: "\u221D",
  6603. infin: "\u221E",
  6604. ang: "\u2220",
  6605. and: "\u2227",
  6606. or: "\u2228",
  6607. cap: "\u2229",
  6608. cup: "\u222A",
  6609. int: "\u222B",
  6610. there4: "\u2234",
  6611. sim: "\u223C",
  6612. cong: "\u2245",
  6613. asymp: "\u2248",
  6614. ne: "\u2260",
  6615. equiv: "\u2261",
  6616. le: "\u2264",
  6617. ge: "\u2265",
  6618. sub: "\u2282",
  6619. sup: "\u2283",
  6620. nsub: "\u2284",
  6621. sube: "\u2286",
  6622. supe: "\u2287",
  6623. oplus: "\u2295",
  6624. otimes: "\u2297",
  6625. perp: "\u22A5",
  6626. sdot: "\u22C5",
  6627. lceil: "\u2308",
  6628. rceil: "\u2309",
  6629. lfloor: "\u230A",
  6630. rfloor: "\u230B",
  6631. lang: "\u2329",
  6632. rang: "\u232A",
  6633. loz: "\u25CA",
  6634. spades: "\u2660",
  6635. clubs: "\u2663",
  6636. hearts: "\u2665",
  6637. diams: "\u2666"
  6638. };
  6639. const JsxErrors = ParseErrorEnum`jsx`({
  6640. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6641. MissingClosingTagElement: ({
  6642. openingTagName
  6643. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6644. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6645. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6646. UnexpectedToken: ({
  6647. unexpected,
  6648. HTMLEntity
  6649. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6650. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6651. UnterminatedJsxContent: "Unterminated JSX contents.",
  6652. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6653. });
  6654. function isFragment(object) {
  6655. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6656. }
  6657. function getQualifiedJSXName(object) {
  6658. if (object.type === "JSXIdentifier") {
  6659. return object.name;
  6660. }
  6661. if (object.type === "JSXNamespacedName") {
  6662. return object.namespace.name + ":" + object.name.name;
  6663. }
  6664. if (object.type === "JSXMemberExpression") {
  6665. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6666. }
  6667. throw new Error("Node had unexpected type: " + object.type);
  6668. }
  6669. var jsx = superClass => class JSXParserMixin extends superClass {
  6670. jsxReadToken() {
  6671. let out = "";
  6672. let chunkStart = this.state.pos;
  6673. for (;;) {
  6674. if (this.state.pos >= this.length) {
  6675. throw this.raise(JsxErrors.UnterminatedJsxContent, {
  6676. at: this.state.startLoc
  6677. });
  6678. }
  6679. const ch = this.input.charCodeAt(this.state.pos);
  6680. switch (ch) {
  6681. case 60:
  6682. case 123:
  6683. if (this.state.pos === this.state.start) {
  6684. if (ch === 60 && this.state.canStartJSXElement) {
  6685. ++this.state.pos;
  6686. this.finishToken(140);
  6687. } else {
  6688. super.getTokenFromCode(ch);
  6689. }
  6690. return;
  6691. }
  6692. out += this.input.slice(chunkStart, this.state.pos);
  6693. this.finishToken(139, out);
  6694. return;
  6695. case 38:
  6696. out += this.input.slice(chunkStart, this.state.pos);
  6697. out += this.jsxReadEntity();
  6698. chunkStart = this.state.pos;
  6699. break;
  6700. case 62:
  6701. case 125:
  6702. default:
  6703. if (isNewLine(ch)) {
  6704. out += this.input.slice(chunkStart, this.state.pos);
  6705. out += this.jsxReadNewLine(true);
  6706. chunkStart = this.state.pos;
  6707. } else {
  6708. ++this.state.pos;
  6709. }
  6710. }
  6711. }
  6712. }
  6713. jsxReadNewLine(normalizeCRLF) {
  6714. const ch = this.input.charCodeAt(this.state.pos);
  6715. let out;
  6716. ++this.state.pos;
  6717. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6718. ++this.state.pos;
  6719. out = normalizeCRLF ? "\n" : "\r\n";
  6720. } else {
  6721. out = String.fromCharCode(ch);
  6722. }
  6723. ++this.state.curLine;
  6724. this.state.lineStart = this.state.pos;
  6725. return out;
  6726. }
  6727. jsxReadString(quote) {
  6728. let out = "";
  6729. let chunkStart = ++this.state.pos;
  6730. for (;;) {
  6731. if (this.state.pos >= this.length) {
  6732. throw this.raise(Errors.UnterminatedString, {
  6733. at: this.state.startLoc
  6734. });
  6735. }
  6736. const ch = this.input.charCodeAt(this.state.pos);
  6737. if (ch === quote) break;
  6738. if (ch === 38) {
  6739. out += this.input.slice(chunkStart, this.state.pos);
  6740. out += this.jsxReadEntity();
  6741. chunkStart = this.state.pos;
  6742. } else if (isNewLine(ch)) {
  6743. out += this.input.slice(chunkStart, this.state.pos);
  6744. out += this.jsxReadNewLine(false);
  6745. chunkStart = this.state.pos;
  6746. } else {
  6747. ++this.state.pos;
  6748. }
  6749. }
  6750. out += this.input.slice(chunkStart, this.state.pos++);
  6751. this.finishToken(131, out);
  6752. }
  6753. jsxReadEntity() {
  6754. const startPos = ++this.state.pos;
  6755. if (this.codePointAtPos(this.state.pos) === 35) {
  6756. ++this.state.pos;
  6757. let radix = 10;
  6758. if (this.codePointAtPos(this.state.pos) === 120) {
  6759. radix = 16;
  6760. ++this.state.pos;
  6761. }
  6762. const codePoint = this.readInt(radix, undefined, false, "bail");
  6763. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6764. ++this.state.pos;
  6765. return String.fromCodePoint(codePoint);
  6766. }
  6767. } else {
  6768. let count = 0;
  6769. let semi = false;
  6770. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
  6771. ++this.state.pos;
  6772. }
  6773. if (semi) {
  6774. const desc = this.input.slice(startPos, this.state.pos);
  6775. const entity = entities[desc];
  6776. ++this.state.pos;
  6777. if (entity) {
  6778. return entity;
  6779. }
  6780. }
  6781. }
  6782. this.state.pos = startPos;
  6783. return "&";
  6784. }
  6785. jsxReadWord() {
  6786. let ch;
  6787. const start = this.state.pos;
  6788. do {
  6789. ch = this.input.charCodeAt(++this.state.pos);
  6790. } while (isIdentifierChar(ch) || ch === 45);
  6791. this.finishToken(138, this.input.slice(start, this.state.pos));
  6792. }
  6793. jsxParseIdentifier() {
  6794. const node = this.startNode();
  6795. if (this.match(138)) {
  6796. node.name = this.state.value;
  6797. } else if (tokenIsKeyword(this.state.type)) {
  6798. node.name = tokenLabelName(this.state.type);
  6799. } else {
  6800. this.unexpected();
  6801. }
  6802. this.next();
  6803. return this.finishNode(node, "JSXIdentifier");
  6804. }
  6805. jsxParseNamespacedName() {
  6806. const startLoc = this.state.startLoc;
  6807. const name = this.jsxParseIdentifier();
  6808. if (!this.eat(14)) return name;
  6809. const node = this.startNodeAt(startLoc);
  6810. node.namespace = name;
  6811. node.name = this.jsxParseIdentifier();
  6812. return this.finishNode(node, "JSXNamespacedName");
  6813. }
  6814. jsxParseElementName() {
  6815. const startLoc = this.state.startLoc;
  6816. let node = this.jsxParseNamespacedName();
  6817. if (node.type === "JSXNamespacedName") {
  6818. return node;
  6819. }
  6820. while (this.eat(16)) {
  6821. const newNode = this.startNodeAt(startLoc);
  6822. newNode.object = node;
  6823. newNode.property = this.jsxParseIdentifier();
  6824. node = this.finishNode(newNode, "JSXMemberExpression");
  6825. }
  6826. return node;
  6827. }
  6828. jsxParseAttributeValue() {
  6829. let node;
  6830. switch (this.state.type) {
  6831. case 5:
  6832. node = this.startNode();
  6833. this.setContext(types.brace);
  6834. this.next();
  6835. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6836. if (node.expression.type === "JSXEmptyExpression") {
  6837. this.raise(JsxErrors.AttributeIsEmpty, {
  6838. at: node
  6839. });
  6840. }
  6841. return node;
  6842. case 140:
  6843. case 131:
  6844. return this.parseExprAtom();
  6845. default:
  6846. throw this.raise(JsxErrors.UnsupportedJsxValue, {
  6847. at: this.state.startLoc
  6848. });
  6849. }
  6850. }
  6851. jsxParseEmptyExpression() {
  6852. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6853. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6854. }
  6855. jsxParseSpreadChild(node) {
  6856. this.next();
  6857. node.expression = this.parseExpression();
  6858. this.setContext(types.j_expr);
  6859. this.state.canStartJSXElement = true;
  6860. this.expect(8);
  6861. return this.finishNode(node, "JSXSpreadChild");
  6862. }
  6863. jsxParseExpressionContainer(node, previousContext) {
  6864. if (this.match(8)) {
  6865. node.expression = this.jsxParseEmptyExpression();
  6866. } else {
  6867. const expression = this.parseExpression();
  6868. node.expression = expression;
  6869. }
  6870. this.setContext(previousContext);
  6871. this.state.canStartJSXElement = true;
  6872. this.expect(8);
  6873. return this.finishNode(node, "JSXExpressionContainer");
  6874. }
  6875. jsxParseAttribute() {
  6876. const node = this.startNode();
  6877. if (this.match(5)) {
  6878. this.setContext(types.brace);
  6879. this.next();
  6880. this.expect(21);
  6881. node.argument = this.parseMaybeAssignAllowIn();
  6882. this.setContext(types.j_oTag);
  6883. this.state.canStartJSXElement = true;
  6884. this.expect(8);
  6885. return this.finishNode(node, "JSXSpreadAttribute");
  6886. }
  6887. node.name = this.jsxParseNamespacedName();
  6888. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6889. return this.finishNode(node, "JSXAttribute");
  6890. }
  6891. jsxParseOpeningElementAt(startLoc) {
  6892. const node = this.startNodeAt(startLoc);
  6893. if (this.eat(141)) {
  6894. return this.finishNode(node, "JSXOpeningFragment");
  6895. }
  6896. node.name = this.jsxParseElementName();
  6897. return this.jsxParseOpeningElementAfterName(node);
  6898. }
  6899. jsxParseOpeningElementAfterName(node) {
  6900. const attributes = [];
  6901. while (!this.match(56) && !this.match(141)) {
  6902. attributes.push(this.jsxParseAttribute());
  6903. }
  6904. node.attributes = attributes;
  6905. node.selfClosing = this.eat(56);
  6906. this.expect(141);
  6907. return this.finishNode(node, "JSXOpeningElement");
  6908. }
  6909. jsxParseClosingElementAt(startLoc) {
  6910. const node = this.startNodeAt(startLoc);
  6911. if (this.eat(141)) {
  6912. return this.finishNode(node, "JSXClosingFragment");
  6913. }
  6914. node.name = this.jsxParseElementName();
  6915. this.expect(141);
  6916. return this.finishNode(node, "JSXClosingElement");
  6917. }
  6918. jsxParseElementAt(startLoc) {
  6919. const node = this.startNodeAt(startLoc);
  6920. const children = [];
  6921. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6922. let closingElement = null;
  6923. if (!openingElement.selfClosing) {
  6924. contents: for (;;) {
  6925. switch (this.state.type) {
  6926. case 140:
  6927. startLoc = this.state.startLoc;
  6928. this.next();
  6929. if (this.eat(56)) {
  6930. closingElement = this.jsxParseClosingElementAt(startLoc);
  6931. break contents;
  6932. }
  6933. children.push(this.jsxParseElementAt(startLoc));
  6934. break;
  6935. case 139:
  6936. children.push(this.parseExprAtom());
  6937. break;
  6938. case 5:
  6939. {
  6940. const node = this.startNode();
  6941. this.setContext(types.brace);
  6942. this.next();
  6943. if (this.match(21)) {
  6944. children.push(this.jsxParseSpreadChild(node));
  6945. } else {
  6946. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6947. }
  6948. break;
  6949. }
  6950. default:
  6951. this.unexpected();
  6952. }
  6953. }
  6954. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6955. this.raise(JsxErrors.MissingClosingTagFragment, {
  6956. at: closingElement
  6957. });
  6958. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6959. this.raise(JsxErrors.MissingClosingTagElement, {
  6960. at: closingElement,
  6961. openingTagName: getQualifiedJSXName(openingElement.name)
  6962. });
  6963. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6964. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6965. this.raise(JsxErrors.MissingClosingTagElement, {
  6966. at: closingElement,
  6967. openingTagName: getQualifiedJSXName(openingElement.name)
  6968. });
  6969. }
  6970. }
  6971. }
  6972. if (isFragment(openingElement)) {
  6973. node.openingFragment = openingElement;
  6974. node.closingFragment = closingElement;
  6975. } else {
  6976. node.openingElement = openingElement;
  6977. node.closingElement = closingElement;
  6978. }
  6979. node.children = children;
  6980. if (this.match(47)) {
  6981. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
  6982. at: this.state.startLoc
  6983. });
  6984. }
  6985. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6986. }
  6987. jsxParseElement() {
  6988. const startLoc = this.state.startLoc;
  6989. this.next();
  6990. return this.jsxParseElementAt(startLoc);
  6991. }
  6992. setContext(newContext) {
  6993. const {
  6994. context
  6995. } = this.state;
  6996. context[context.length - 1] = newContext;
  6997. }
  6998. parseExprAtom(refExpressionErrors) {
  6999. if (this.match(139)) {
  7000. return this.parseLiteral(this.state.value, "JSXText");
  7001. } else if (this.match(140)) {
  7002. return this.jsxParseElement();
  7003. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  7004. this.replaceToken(140);
  7005. return this.jsxParseElement();
  7006. } else {
  7007. return super.parseExprAtom(refExpressionErrors);
  7008. }
  7009. }
  7010. skipSpace() {
  7011. const curContext = this.curContext();
  7012. if (!curContext.preserveSpace) super.skipSpace();
  7013. }
  7014. getTokenFromCode(code) {
  7015. const context = this.curContext();
  7016. if (context === types.j_expr) {
  7017. this.jsxReadToken();
  7018. return;
  7019. }
  7020. if (context === types.j_oTag || context === types.j_cTag) {
  7021. if (isIdentifierStart(code)) {
  7022. this.jsxReadWord();
  7023. return;
  7024. }
  7025. if (code === 62) {
  7026. ++this.state.pos;
  7027. this.finishToken(141);
  7028. return;
  7029. }
  7030. if ((code === 34 || code === 39) && context === types.j_oTag) {
  7031. this.jsxReadString(code);
  7032. return;
  7033. }
  7034. }
  7035. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  7036. ++this.state.pos;
  7037. this.finishToken(140);
  7038. return;
  7039. }
  7040. super.getTokenFromCode(code);
  7041. }
  7042. updateContext(prevType) {
  7043. const {
  7044. context,
  7045. type
  7046. } = this.state;
  7047. if (type === 56 && prevType === 140) {
  7048. context.splice(-2, 2, types.j_cTag);
  7049. this.state.canStartJSXElement = false;
  7050. } else if (type === 140) {
  7051. context.push(types.j_oTag);
  7052. } else if (type === 141) {
  7053. const out = context[context.length - 1];
  7054. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  7055. context.pop();
  7056. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  7057. } else {
  7058. this.setContext(types.j_expr);
  7059. this.state.canStartJSXElement = true;
  7060. }
  7061. } else {
  7062. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  7063. }
  7064. }
  7065. };
  7066. class TypeScriptScope extends Scope {
  7067. constructor(...args) {
  7068. super(...args);
  7069. this.types = new Set();
  7070. this.enums = new Set();
  7071. this.constEnums = new Set();
  7072. this.classes = new Set();
  7073. this.exportOnlyBindings = new Set();
  7074. }
  7075. }
  7076. class TypeScriptScopeHandler extends ScopeHandler {
  7077. constructor(...args) {
  7078. super(...args);
  7079. this.importsStack = [];
  7080. }
  7081. createScope(flags) {
  7082. this.importsStack.push(new Set());
  7083. return new TypeScriptScope(flags);
  7084. }
  7085. enter(flags) {
  7086. if (flags == SCOPE_TS_MODULE) {
  7087. this.importsStack.push(new Set());
  7088. }
  7089. super.enter(flags);
  7090. }
  7091. exit() {
  7092. const flags = super.exit();
  7093. if (flags == SCOPE_TS_MODULE) {
  7094. this.importsStack.pop();
  7095. }
  7096. return flags;
  7097. }
  7098. hasImport(name, allowShadow) {
  7099. const len = this.importsStack.length;
  7100. if (this.importsStack[len - 1].has(name)) {
  7101. return true;
  7102. }
  7103. if (!allowShadow && len > 1) {
  7104. for (let i = 0; i < len - 1; i++) {
  7105. if (this.importsStack[i].has(name)) return true;
  7106. }
  7107. }
  7108. return false;
  7109. }
  7110. declareName(name, bindingType, loc) {
  7111. if (bindingType & BIND_FLAGS_TS_IMPORT) {
  7112. if (this.hasImport(name, true)) {
  7113. this.parser.raise(Errors.VarRedeclaration, {
  7114. at: loc,
  7115. identifierName: name
  7116. });
  7117. }
  7118. this.importsStack[this.importsStack.length - 1].add(name);
  7119. return;
  7120. }
  7121. const scope = this.currentScope();
  7122. if (bindingType & BIND_FLAGS_TS_EXPORT_ONLY) {
  7123. this.maybeExportDefined(scope, name);
  7124. scope.exportOnlyBindings.add(name);
  7125. return;
  7126. }
  7127. super.declareName(name, bindingType, loc);
  7128. if (bindingType & BIND_KIND_TYPE) {
  7129. if (!(bindingType & BIND_KIND_VALUE)) {
  7130. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7131. this.maybeExportDefined(scope, name);
  7132. }
  7133. scope.types.add(name);
  7134. }
  7135. if (bindingType & BIND_FLAGS_TS_ENUM) scope.enums.add(name);
  7136. if (bindingType & BIND_FLAGS_TS_CONST_ENUM) scope.constEnums.add(name);
  7137. if (bindingType & BIND_FLAGS_CLASS) scope.classes.add(name);
  7138. }
  7139. isRedeclaredInScope(scope, name, bindingType) {
  7140. if (scope.enums.has(name)) {
  7141. if (bindingType & BIND_FLAGS_TS_ENUM) {
  7142. const isConst = !!(bindingType & BIND_FLAGS_TS_CONST_ENUM);
  7143. const wasConst = scope.constEnums.has(name);
  7144. return isConst !== wasConst;
  7145. }
  7146. return true;
  7147. }
  7148. if (bindingType & BIND_FLAGS_CLASS && scope.classes.has(name)) {
  7149. if (scope.lexical.has(name)) {
  7150. return !!(bindingType & BIND_KIND_VALUE);
  7151. } else {
  7152. return false;
  7153. }
  7154. }
  7155. if (bindingType & BIND_KIND_TYPE && scope.types.has(name)) {
  7156. return true;
  7157. }
  7158. return super.isRedeclaredInScope(scope, name, bindingType);
  7159. }
  7160. checkLocalExport(id) {
  7161. const {
  7162. name
  7163. } = id;
  7164. if (this.hasImport(name)) return;
  7165. const len = this.scopeStack.length;
  7166. for (let i = len - 1; i >= 0; i--) {
  7167. const scope = this.scopeStack[i];
  7168. if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return;
  7169. }
  7170. super.checkLocalExport(id);
  7171. }
  7172. }
  7173. const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7174. const unwrapParenthesizedExpression = node => {
  7175. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7176. };
  7177. class LValParser extends NodeUtils {
  7178. toAssignable(node, isLHS = false) {
  7179. var _node$extra, _node$extra3;
  7180. let parenthesized = undefined;
  7181. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7182. parenthesized = unwrapParenthesizedExpression(node);
  7183. if (isLHS) {
  7184. if (parenthesized.type === "Identifier") {
  7185. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
  7186. at: node
  7187. });
  7188. } else if (parenthesized.type !== "MemberExpression") {
  7189. this.raise(Errors.InvalidParenthesizedAssignment, {
  7190. at: node
  7191. });
  7192. }
  7193. } else {
  7194. this.raise(Errors.InvalidParenthesizedAssignment, {
  7195. at: node
  7196. });
  7197. }
  7198. }
  7199. switch (node.type) {
  7200. case "Identifier":
  7201. case "ObjectPattern":
  7202. case "ArrayPattern":
  7203. case "AssignmentPattern":
  7204. case "RestElement":
  7205. break;
  7206. case "ObjectExpression":
  7207. node.type = "ObjectPattern";
  7208. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7209. var _node$extra2;
  7210. const prop = node.properties[i];
  7211. const isLast = i === last;
  7212. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7213. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7214. this.raise(Errors.RestTrailingComma, {
  7215. at: node.extra.trailingCommaLoc
  7216. });
  7217. }
  7218. }
  7219. break;
  7220. case "ObjectProperty":
  7221. {
  7222. const {
  7223. key,
  7224. value
  7225. } = node;
  7226. if (this.isPrivateName(key)) {
  7227. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7228. }
  7229. this.toAssignable(value, isLHS);
  7230. break;
  7231. }
  7232. case "SpreadElement":
  7233. {
  7234. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7235. }
  7236. case "ArrayExpression":
  7237. node.type = "ArrayPattern";
  7238. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7239. break;
  7240. case "AssignmentExpression":
  7241. if (node.operator !== "=") {
  7242. this.raise(Errors.MissingEqInAssignment, {
  7243. at: node.left.loc.end
  7244. });
  7245. }
  7246. node.type = "AssignmentPattern";
  7247. delete node.operator;
  7248. this.toAssignable(node.left, isLHS);
  7249. break;
  7250. case "ParenthesizedExpression":
  7251. this.toAssignable(parenthesized, isLHS);
  7252. break;
  7253. }
  7254. }
  7255. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7256. if (prop.type === "ObjectMethod") {
  7257. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
  7258. at: prop.key
  7259. });
  7260. } else if (prop.type === "SpreadElement") {
  7261. prop.type = "RestElement";
  7262. const arg = prop.argument;
  7263. this.checkToRestConversion(arg, false);
  7264. this.toAssignable(arg, isLHS);
  7265. if (!isLast) {
  7266. this.raise(Errors.RestTrailingComma, {
  7267. at: prop
  7268. });
  7269. }
  7270. } else {
  7271. this.toAssignable(prop, isLHS);
  7272. }
  7273. }
  7274. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7275. const end = exprList.length - 1;
  7276. for (let i = 0; i <= end; i++) {
  7277. const elt = exprList[i];
  7278. if (!elt) continue;
  7279. if (elt.type === "SpreadElement") {
  7280. elt.type = "RestElement";
  7281. const arg = elt.argument;
  7282. this.checkToRestConversion(arg, true);
  7283. this.toAssignable(arg, isLHS);
  7284. } else {
  7285. this.toAssignable(elt, isLHS);
  7286. }
  7287. if (elt.type === "RestElement") {
  7288. if (i < end) {
  7289. this.raise(Errors.RestTrailingComma, {
  7290. at: elt
  7291. });
  7292. } else if (trailingCommaLoc) {
  7293. this.raise(Errors.RestTrailingComma, {
  7294. at: trailingCommaLoc
  7295. });
  7296. }
  7297. }
  7298. }
  7299. }
  7300. isAssignable(node, isBinding) {
  7301. switch (node.type) {
  7302. case "Identifier":
  7303. case "ObjectPattern":
  7304. case "ArrayPattern":
  7305. case "AssignmentPattern":
  7306. case "RestElement":
  7307. return true;
  7308. case "ObjectExpression":
  7309. {
  7310. const last = node.properties.length - 1;
  7311. return node.properties.every((prop, i) => {
  7312. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7313. });
  7314. }
  7315. case "ObjectProperty":
  7316. return this.isAssignable(node.value);
  7317. case "SpreadElement":
  7318. return this.isAssignable(node.argument);
  7319. case "ArrayExpression":
  7320. return node.elements.every(element => element === null || this.isAssignable(element));
  7321. case "AssignmentExpression":
  7322. return node.operator === "=";
  7323. case "ParenthesizedExpression":
  7324. return this.isAssignable(node.expression);
  7325. case "MemberExpression":
  7326. case "OptionalMemberExpression":
  7327. return !isBinding;
  7328. default:
  7329. return false;
  7330. }
  7331. }
  7332. toReferencedList(exprList, isParenthesizedExpr) {
  7333. return exprList;
  7334. }
  7335. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7336. this.toReferencedList(exprList, isParenthesizedExpr);
  7337. for (const expr of exprList) {
  7338. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7339. this.toReferencedListDeep(expr.elements);
  7340. }
  7341. }
  7342. }
  7343. parseSpread(refExpressionErrors) {
  7344. const node = this.startNode();
  7345. this.next();
  7346. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7347. return this.finishNode(node, "SpreadElement");
  7348. }
  7349. parseRestBinding() {
  7350. const node = this.startNode();
  7351. this.next();
  7352. node.argument = this.parseBindingAtom();
  7353. return this.finishNode(node, "RestElement");
  7354. }
  7355. parseBindingAtom() {
  7356. switch (this.state.type) {
  7357. case 0:
  7358. {
  7359. const node = this.startNode();
  7360. this.next();
  7361. node.elements = this.parseBindingList(3, 93, 1);
  7362. return this.finishNode(node, "ArrayPattern");
  7363. }
  7364. case 5:
  7365. return this.parseObjectLike(8, true);
  7366. }
  7367. return this.parseIdentifier();
  7368. }
  7369. parseBindingList(close, closeCharCode, flags) {
  7370. const allowEmpty = flags & 1;
  7371. const elts = [];
  7372. let first = true;
  7373. while (!this.eat(close)) {
  7374. if (first) {
  7375. first = false;
  7376. } else {
  7377. this.expect(12);
  7378. }
  7379. if (allowEmpty && this.match(12)) {
  7380. elts.push(null);
  7381. } else if (this.eat(close)) {
  7382. break;
  7383. } else if (this.match(21)) {
  7384. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
  7385. if (!this.checkCommaAfterRest(closeCharCode)) {
  7386. this.expect(close);
  7387. break;
  7388. }
  7389. } else {
  7390. const decorators = [];
  7391. if (this.match(26) && this.hasPlugin("decorators")) {
  7392. this.raise(Errors.UnsupportedParameterDecorator, {
  7393. at: this.state.startLoc
  7394. });
  7395. }
  7396. while (this.match(26)) {
  7397. decorators.push(this.parseDecorator());
  7398. }
  7399. elts.push(this.parseAssignableListItem(flags, decorators));
  7400. }
  7401. }
  7402. return elts;
  7403. }
  7404. parseBindingRestProperty(prop) {
  7405. this.next();
  7406. prop.argument = this.parseIdentifier();
  7407. this.checkCommaAfterRest(125);
  7408. return this.finishNode(prop, "RestElement");
  7409. }
  7410. parseBindingProperty() {
  7411. const prop = this.startNode();
  7412. const {
  7413. type,
  7414. startLoc
  7415. } = this.state;
  7416. if (type === 21) {
  7417. return this.parseBindingRestProperty(prop);
  7418. } else if (type === 136) {
  7419. this.expectPlugin("destructuringPrivate", startLoc);
  7420. this.classScope.usePrivateName(this.state.value, startLoc);
  7421. prop.key = this.parsePrivateName();
  7422. } else {
  7423. this.parsePropertyName(prop);
  7424. }
  7425. prop.method = false;
  7426. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7427. }
  7428. parseAssignableListItem(flags, decorators) {
  7429. const left = this.parseMaybeDefault();
  7430. this.parseAssignableListItemTypes(left, flags);
  7431. const elt = this.parseMaybeDefault(left.loc.start, left);
  7432. if (decorators.length) {
  7433. left.decorators = decorators;
  7434. }
  7435. return elt;
  7436. }
  7437. parseAssignableListItemTypes(param, flags) {
  7438. return param;
  7439. }
  7440. parseMaybeDefault(startLoc, left) {
  7441. var _startLoc, _left;
  7442. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  7443. left = (_left = left) != null ? _left : this.parseBindingAtom();
  7444. if (!this.eat(29)) return left;
  7445. const node = this.startNodeAt(startLoc);
  7446. node.left = left;
  7447. node.right = this.parseMaybeAssignAllowIn();
  7448. return this.finishNode(node, "AssignmentPattern");
  7449. }
  7450. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7451. return getOwn$1({
  7452. AssignmentPattern: "left",
  7453. RestElement: "argument",
  7454. ObjectProperty: "value",
  7455. ParenthesizedExpression: "expression",
  7456. ArrayPattern: "elements",
  7457. ObjectPattern: "properties"
  7458. }, type);
  7459. }
  7460. checkLVal(expression, {
  7461. in: ancestor,
  7462. binding = BIND_NONE,
  7463. checkClashes = false,
  7464. strictModeChanged = false,
  7465. hasParenthesizedAncestor = false
  7466. }) {
  7467. var _expression$extra;
  7468. const type = expression.type;
  7469. if (this.isObjectMethod(expression)) return;
  7470. if (type === "MemberExpression") {
  7471. if (binding !== BIND_NONE) {
  7472. this.raise(Errors.InvalidPropertyBindingPattern, {
  7473. at: expression
  7474. });
  7475. }
  7476. return;
  7477. }
  7478. if (type === "Identifier") {
  7479. this.checkIdentifier(expression, binding, strictModeChanged);
  7480. const {
  7481. name
  7482. } = expression;
  7483. if (checkClashes) {
  7484. if (checkClashes.has(name)) {
  7485. this.raise(Errors.ParamDupe, {
  7486. at: expression
  7487. });
  7488. } else {
  7489. checkClashes.add(name);
  7490. }
  7491. }
  7492. return;
  7493. }
  7494. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7495. if (validity === true) return;
  7496. if (validity === false) {
  7497. const ParseErrorClass = binding === BIND_NONE ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7498. this.raise(ParseErrorClass, {
  7499. at: expression,
  7500. ancestor
  7501. });
  7502. return;
  7503. }
  7504. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  7505. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" || type === "ParenthesizedExpression" ? {
  7506. type
  7507. } : ancestor;
  7508. for (const child of [].concat(expression[key])) {
  7509. if (child) {
  7510. this.checkLVal(child, {
  7511. in: nextAncestor,
  7512. binding,
  7513. checkClashes,
  7514. strictModeChanged,
  7515. hasParenthesizedAncestor: isParenthesizedExpression
  7516. });
  7517. }
  7518. }
  7519. }
  7520. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7521. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7522. if (bindingType === BIND_NONE) {
  7523. this.raise(Errors.StrictEvalArguments, {
  7524. at,
  7525. referenceName: at.name
  7526. });
  7527. } else {
  7528. this.raise(Errors.StrictEvalArgumentsBinding, {
  7529. at,
  7530. bindingName: at.name
  7531. });
  7532. }
  7533. }
  7534. if (bindingType & BIND_FLAGS_NO_LET_IN_LEXICAL && at.name === "let") {
  7535. this.raise(Errors.LetInLexicalBinding, {
  7536. at
  7537. });
  7538. }
  7539. if (!(bindingType & BIND_NONE)) {
  7540. this.declareNameFromIdentifier(at, bindingType);
  7541. }
  7542. }
  7543. declareNameFromIdentifier(identifier, binding) {
  7544. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7545. }
  7546. checkToRestConversion(node, allowPattern) {
  7547. switch (node.type) {
  7548. case "ParenthesizedExpression":
  7549. this.checkToRestConversion(node.expression, allowPattern);
  7550. break;
  7551. case "Identifier":
  7552. case "MemberExpression":
  7553. break;
  7554. case "ArrayExpression":
  7555. case "ObjectExpression":
  7556. if (allowPattern) break;
  7557. default:
  7558. this.raise(Errors.InvalidRestAssignmentPattern, {
  7559. at: node
  7560. });
  7561. }
  7562. }
  7563. checkCommaAfterRest(close) {
  7564. if (!this.match(12)) {
  7565. return false;
  7566. }
  7567. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
  7568. at: this.state.startLoc
  7569. });
  7570. return true;
  7571. }
  7572. }
  7573. const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7574. function nonNull(x) {
  7575. if (x == null) {
  7576. throw new Error(`Unexpected ${x} value.`);
  7577. }
  7578. return x;
  7579. }
  7580. function assert(x) {
  7581. if (!x) {
  7582. throw new Error("Assert fail");
  7583. }
  7584. }
  7585. const TSErrors = ParseErrorEnum`typescript`({
  7586. AbstractMethodHasImplementation: ({
  7587. methodName
  7588. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7589. AbstractPropertyHasInitializer: ({
  7590. propertyName
  7591. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7592. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7593. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7594. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7595. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7596. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7597. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7598. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7599. DeclareAccessor: ({
  7600. kind
  7601. }) => `'declare' is not allowed in ${kind}ters.`,
  7602. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7603. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7604. DuplicateAccessibilityModifier: ({
  7605. modifier
  7606. }) => `Accessibility modifier already seen.`,
  7607. DuplicateModifier: ({
  7608. modifier
  7609. }) => `Duplicate modifier: '${modifier}'.`,
  7610. EmptyHeritageClauseType: ({
  7611. token
  7612. }) => `'${token}' list cannot be empty.`,
  7613. EmptyTypeArguments: "Type argument list cannot be empty.",
  7614. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7615. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7616. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7617. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7618. IncompatibleModifiers: ({
  7619. modifiers
  7620. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7621. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7622. IndexSignatureHasAccessibility: ({
  7623. modifier
  7624. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7625. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7626. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7627. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7628. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7629. InvalidModifierOnTypeMember: ({
  7630. modifier
  7631. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7632. InvalidModifierOnTypeParameter: ({
  7633. modifier
  7634. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7635. InvalidModifierOnTypeParameterPositions: ({
  7636. modifier
  7637. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7638. InvalidModifiersOrder: ({
  7639. orderedModifiers
  7640. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7641. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7642. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7643. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7644. MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
  7645. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7646. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7647. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7648. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7649. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7650. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7651. PrivateElementHasAccessibility: ({
  7652. modifier
  7653. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7654. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7655. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7656. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7657. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7658. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7659. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7660. SingleTypeParameterWithoutTrailingComma: ({
  7661. typeParameterName
  7662. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7663. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7664. 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?`).",
  7665. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7666. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7667. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7668. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7669. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7670. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7671. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7672. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7673. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7674. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7675. UnsupportedSignatureParameterKind: ({
  7676. type
  7677. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7678. });
  7679. function keywordTypeFromName(value) {
  7680. switch (value) {
  7681. case "any":
  7682. return "TSAnyKeyword";
  7683. case "boolean":
  7684. return "TSBooleanKeyword";
  7685. case "bigint":
  7686. return "TSBigIntKeyword";
  7687. case "never":
  7688. return "TSNeverKeyword";
  7689. case "number":
  7690. return "TSNumberKeyword";
  7691. case "object":
  7692. return "TSObjectKeyword";
  7693. case "string":
  7694. return "TSStringKeyword";
  7695. case "symbol":
  7696. return "TSSymbolKeyword";
  7697. case "undefined":
  7698. return "TSUndefinedKeyword";
  7699. case "unknown":
  7700. return "TSUnknownKeyword";
  7701. default:
  7702. return undefined;
  7703. }
  7704. }
  7705. function tsIsAccessModifier(modifier) {
  7706. return modifier === "private" || modifier === "public" || modifier === "protected";
  7707. }
  7708. function tsIsVarianceAnnotations(modifier) {
  7709. return modifier === "in" || modifier === "out";
  7710. }
  7711. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7712. constructor(...args) {
  7713. super(...args);
  7714. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7715. allowedModifiers: ["in", "out"],
  7716. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7717. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7718. });
  7719. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7720. allowedModifiers: ["const"],
  7721. disallowedModifiers: ["in", "out"],
  7722. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7723. });
  7724. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7725. allowedModifiers: ["in", "out", "const"],
  7726. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7727. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7728. });
  7729. }
  7730. getScopeHandler() {
  7731. return TypeScriptScopeHandler;
  7732. }
  7733. tsIsIdentifier() {
  7734. return tokenIsIdentifier(this.state.type);
  7735. }
  7736. tsTokenCanFollowModifier() {
  7737. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(136) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  7738. }
  7739. tsNextTokenCanFollowModifier() {
  7740. this.next();
  7741. return this.tsTokenCanFollowModifier();
  7742. }
  7743. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7744. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7745. return undefined;
  7746. }
  7747. const modifier = this.state.value;
  7748. if (allowedModifiers.indexOf(modifier) !== -1) {
  7749. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7750. return undefined;
  7751. }
  7752. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7753. return modifier;
  7754. }
  7755. }
  7756. return undefined;
  7757. }
  7758. tsParseModifiers({
  7759. allowedModifiers,
  7760. disallowedModifiers,
  7761. stopOnStartOfClassStaticBlock,
  7762. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7763. }, modified) {
  7764. const enforceOrder = (loc, modifier, before, after) => {
  7765. if (modifier === before && modified[after]) {
  7766. this.raise(TSErrors.InvalidModifiersOrder, {
  7767. at: loc,
  7768. orderedModifiers: [before, after]
  7769. });
  7770. }
  7771. };
  7772. const incompatible = (loc, modifier, mod1, mod2) => {
  7773. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7774. this.raise(TSErrors.IncompatibleModifiers, {
  7775. at: loc,
  7776. modifiers: [mod1, mod2]
  7777. });
  7778. }
  7779. };
  7780. for (;;) {
  7781. const {
  7782. startLoc
  7783. } = this.state;
  7784. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7785. if (!modifier) break;
  7786. if (tsIsAccessModifier(modifier)) {
  7787. if (modified.accessibility) {
  7788. this.raise(TSErrors.DuplicateAccessibilityModifier, {
  7789. at: startLoc,
  7790. modifier
  7791. });
  7792. } else {
  7793. enforceOrder(startLoc, modifier, modifier, "override");
  7794. enforceOrder(startLoc, modifier, modifier, "static");
  7795. enforceOrder(startLoc, modifier, modifier, "readonly");
  7796. modified.accessibility = modifier;
  7797. }
  7798. } else if (tsIsVarianceAnnotations(modifier)) {
  7799. if (modified[modifier]) {
  7800. this.raise(TSErrors.DuplicateModifier, {
  7801. at: startLoc,
  7802. modifier
  7803. });
  7804. }
  7805. modified[modifier] = true;
  7806. enforceOrder(startLoc, modifier, "in", "out");
  7807. } else {
  7808. if (Object.hasOwnProperty.call(modified, modifier)) {
  7809. this.raise(TSErrors.DuplicateModifier, {
  7810. at: startLoc,
  7811. modifier
  7812. });
  7813. } else {
  7814. enforceOrder(startLoc, modifier, "static", "readonly");
  7815. enforceOrder(startLoc, modifier, "static", "override");
  7816. enforceOrder(startLoc, modifier, "override", "readonly");
  7817. enforceOrder(startLoc, modifier, "abstract", "override");
  7818. incompatible(startLoc, modifier, "declare", "override");
  7819. incompatible(startLoc, modifier, "static", "abstract");
  7820. }
  7821. modified[modifier] = true;
  7822. }
  7823. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7824. this.raise(errorTemplate, {
  7825. at: startLoc,
  7826. modifier
  7827. });
  7828. }
  7829. }
  7830. }
  7831. tsIsListTerminator(kind) {
  7832. switch (kind) {
  7833. case "EnumMembers":
  7834. case "TypeMembers":
  7835. return this.match(8);
  7836. case "HeritageClauseElement":
  7837. return this.match(5);
  7838. case "TupleElementTypes":
  7839. return this.match(3);
  7840. case "TypeParametersOrArguments":
  7841. return this.match(48);
  7842. }
  7843. }
  7844. tsParseList(kind, parseElement) {
  7845. const result = [];
  7846. while (!this.tsIsListTerminator(kind)) {
  7847. result.push(parseElement());
  7848. }
  7849. return result;
  7850. }
  7851. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7852. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7853. }
  7854. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7855. const result = [];
  7856. let trailingCommaPos = -1;
  7857. for (;;) {
  7858. if (this.tsIsListTerminator(kind)) {
  7859. break;
  7860. }
  7861. trailingCommaPos = -1;
  7862. const element = parseElement();
  7863. if (element == null) {
  7864. return undefined;
  7865. }
  7866. result.push(element);
  7867. if (this.eat(12)) {
  7868. trailingCommaPos = this.state.lastTokStart;
  7869. continue;
  7870. }
  7871. if (this.tsIsListTerminator(kind)) {
  7872. break;
  7873. }
  7874. if (expectSuccess) {
  7875. this.expect(12);
  7876. }
  7877. return undefined;
  7878. }
  7879. if (refTrailingCommaPos) {
  7880. refTrailingCommaPos.value = trailingCommaPos;
  7881. }
  7882. return result;
  7883. }
  7884. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7885. if (!skipFirstToken) {
  7886. if (bracket) {
  7887. this.expect(0);
  7888. } else {
  7889. this.expect(47);
  7890. }
  7891. }
  7892. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7893. if (bracket) {
  7894. this.expect(3);
  7895. } else {
  7896. this.expect(48);
  7897. }
  7898. return result;
  7899. }
  7900. tsParseImportType() {
  7901. const node = this.startNode();
  7902. this.expect(83);
  7903. this.expect(10);
  7904. if (!this.match(131)) {
  7905. this.raise(TSErrors.UnsupportedImportTypeArgument, {
  7906. at: this.state.startLoc
  7907. });
  7908. }
  7909. node.argument = super.parseExprAtom();
  7910. this.expect(11);
  7911. if (this.eat(16)) {
  7912. node.qualifier = this.tsParseEntityName();
  7913. }
  7914. if (this.match(47)) {
  7915. node.typeParameters = this.tsParseTypeArguments();
  7916. }
  7917. return this.finishNode(node, "TSImportType");
  7918. }
  7919. tsParseEntityName(allowReservedWords = true) {
  7920. let entity = this.parseIdentifier(allowReservedWords);
  7921. while (this.eat(16)) {
  7922. const node = this.startNodeAtNode(entity);
  7923. node.left = entity;
  7924. node.right = this.parseIdentifier(allowReservedWords);
  7925. entity = this.finishNode(node, "TSQualifiedName");
  7926. }
  7927. return entity;
  7928. }
  7929. tsParseTypeReference() {
  7930. const node = this.startNode();
  7931. node.typeName = this.tsParseEntityName();
  7932. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7933. node.typeParameters = this.tsParseTypeArguments();
  7934. }
  7935. return this.finishNode(node, "TSTypeReference");
  7936. }
  7937. tsParseThisTypePredicate(lhs) {
  7938. this.next();
  7939. const node = this.startNodeAtNode(lhs);
  7940. node.parameterName = lhs;
  7941. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7942. node.asserts = false;
  7943. return this.finishNode(node, "TSTypePredicate");
  7944. }
  7945. tsParseThisTypeNode() {
  7946. const node = this.startNode();
  7947. this.next();
  7948. return this.finishNode(node, "TSThisType");
  7949. }
  7950. tsParseTypeQuery() {
  7951. const node = this.startNode();
  7952. this.expect(87);
  7953. if (this.match(83)) {
  7954. node.exprName = this.tsParseImportType();
  7955. } else {
  7956. node.exprName = this.tsParseEntityName();
  7957. }
  7958. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7959. node.typeParameters = this.tsParseTypeArguments();
  7960. }
  7961. return this.finishNode(node, "TSTypeQuery");
  7962. }
  7963. tsParseTypeParameter(parseModifiers) {
  7964. const node = this.startNode();
  7965. parseModifiers(node);
  7966. node.name = this.tsParseTypeParameterName();
  7967. node.constraint = this.tsEatThenParseType(81);
  7968. node.default = this.tsEatThenParseType(29);
  7969. return this.finishNode(node, "TSTypeParameter");
  7970. }
  7971. tsTryParseTypeParameters(parseModifiers) {
  7972. if (this.match(47)) {
  7973. return this.tsParseTypeParameters(parseModifiers);
  7974. }
  7975. }
  7976. tsParseTypeParameters(parseModifiers) {
  7977. const node = this.startNode();
  7978. if (this.match(47) || this.match(140)) {
  7979. this.next();
  7980. } else {
  7981. this.unexpected();
  7982. }
  7983. const refTrailingCommaPos = {
  7984. value: -1
  7985. };
  7986. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7987. if (node.params.length === 0) {
  7988. this.raise(TSErrors.EmptyTypeParameters, {
  7989. at: node
  7990. });
  7991. }
  7992. if (refTrailingCommaPos.value !== -1) {
  7993. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7994. }
  7995. return this.finishNode(node, "TSTypeParameterDeclaration");
  7996. }
  7997. tsFillSignature(returnToken, signature) {
  7998. const returnTokenRequired = returnToken === 19;
  7999. const paramsKey = "parameters";
  8000. const returnTypeKey = "typeAnnotation";
  8001. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  8002. this.expect(10);
  8003. signature[paramsKey] = this.tsParseBindingListForSignature();
  8004. if (returnTokenRequired) {
  8005. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8006. } else if (this.match(returnToken)) {
  8007. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8008. }
  8009. }
  8010. tsParseBindingListForSignature() {
  8011. return super.parseBindingList(11, 41, 2).map(pattern => {
  8012. if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") {
  8013. this.raise(TSErrors.UnsupportedSignatureParameterKind, {
  8014. at: pattern,
  8015. type: pattern.type
  8016. });
  8017. }
  8018. return pattern;
  8019. });
  8020. }
  8021. tsParseTypeMemberSemicolon() {
  8022. if (!this.eat(12) && !this.isLineTerminator()) {
  8023. this.expect(13);
  8024. }
  8025. }
  8026. tsParseSignatureMember(kind, node) {
  8027. this.tsFillSignature(14, node);
  8028. this.tsParseTypeMemberSemicolon();
  8029. return this.finishNode(node, kind);
  8030. }
  8031. tsIsUnambiguouslyIndexSignature() {
  8032. this.next();
  8033. if (tokenIsIdentifier(this.state.type)) {
  8034. this.next();
  8035. return this.match(14);
  8036. }
  8037. return false;
  8038. }
  8039. tsTryParseIndexSignature(node) {
  8040. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8041. return undefined;
  8042. }
  8043. this.expect(0);
  8044. const id = this.parseIdentifier();
  8045. id.typeAnnotation = this.tsParseTypeAnnotation();
  8046. this.resetEndLocation(id);
  8047. this.expect(3);
  8048. node.parameters = [id];
  8049. const type = this.tsTryParseTypeAnnotation();
  8050. if (type) node.typeAnnotation = type;
  8051. this.tsParseTypeMemberSemicolon();
  8052. return this.finishNode(node, "TSIndexSignature");
  8053. }
  8054. tsParsePropertyOrMethodSignature(node, readonly) {
  8055. if (this.eat(17)) node.optional = true;
  8056. const nodeAny = node;
  8057. if (this.match(10) || this.match(47)) {
  8058. if (readonly) {
  8059. this.raise(TSErrors.ReadonlyForMethodSignature, {
  8060. at: node
  8061. });
  8062. }
  8063. const method = nodeAny;
  8064. if (method.kind && this.match(47)) {
  8065. this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
  8066. at: this.state.curPosition()
  8067. });
  8068. }
  8069. this.tsFillSignature(14, method);
  8070. this.tsParseTypeMemberSemicolon();
  8071. const paramsKey = "parameters";
  8072. const returnTypeKey = "typeAnnotation";
  8073. if (method.kind === "get") {
  8074. if (method[paramsKey].length > 0) {
  8075. this.raise(Errors.BadGetterArity, {
  8076. at: this.state.curPosition()
  8077. });
  8078. if (this.isThisParam(method[paramsKey][0])) {
  8079. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8080. at: this.state.curPosition()
  8081. });
  8082. }
  8083. }
  8084. } else if (method.kind === "set") {
  8085. if (method[paramsKey].length !== 1) {
  8086. this.raise(Errors.BadSetterArity, {
  8087. at: this.state.curPosition()
  8088. });
  8089. } else {
  8090. const firstParameter = method[paramsKey][0];
  8091. if (this.isThisParam(firstParameter)) {
  8092. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8093. at: this.state.curPosition()
  8094. });
  8095. }
  8096. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8097. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
  8098. at: this.state.curPosition()
  8099. });
  8100. }
  8101. if (firstParameter.type === "RestElement") {
  8102. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
  8103. at: this.state.curPosition()
  8104. });
  8105. }
  8106. }
  8107. if (method[returnTypeKey]) {
  8108. this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
  8109. at: method[returnTypeKey]
  8110. });
  8111. }
  8112. } else {
  8113. method.kind = "method";
  8114. }
  8115. return this.finishNode(method, "TSMethodSignature");
  8116. } else {
  8117. const property = nodeAny;
  8118. if (readonly) property.readonly = true;
  8119. const type = this.tsTryParseTypeAnnotation();
  8120. if (type) property.typeAnnotation = type;
  8121. this.tsParseTypeMemberSemicolon();
  8122. return this.finishNode(property, "TSPropertySignature");
  8123. }
  8124. }
  8125. tsParseTypeMember() {
  8126. const node = this.startNode();
  8127. if (this.match(10) || this.match(47)) {
  8128. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8129. }
  8130. if (this.match(77)) {
  8131. const id = this.startNode();
  8132. this.next();
  8133. if (this.match(10) || this.match(47)) {
  8134. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8135. } else {
  8136. node.key = this.createIdentifier(id, "new");
  8137. return this.tsParsePropertyOrMethodSignature(node, false);
  8138. }
  8139. }
  8140. this.tsParseModifiers({
  8141. allowedModifiers: ["readonly"],
  8142. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8143. }, node);
  8144. const idx = this.tsTryParseIndexSignature(node);
  8145. if (idx) {
  8146. return idx;
  8147. }
  8148. super.parsePropertyName(node);
  8149. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8150. node.kind = node.key.name;
  8151. super.parsePropertyName(node);
  8152. }
  8153. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8154. }
  8155. tsParseTypeLiteral() {
  8156. const node = this.startNode();
  8157. node.members = this.tsParseObjectTypeMembers();
  8158. return this.finishNode(node, "TSTypeLiteral");
  8159. }
  8160. tsParseObjectTypeMembers() {
  8161. this.expect(5);
  8162. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8163. this.expect(8);
  8164. return members;
  8165. }
  8166. tsIsStartOfMappedType() {
  8167. this.next();
  8168. if (this.eat(53)) {
  8169. return this.isContextual(120);
  8170. }
  8171. if (this.isContextual(120)) {
  8172. this.next();
  8173. }
  8174. if (!this.match(0)) {
  8175. return false;
  8176. }
  8177. this.next();
  8178. if (!this.tsIsIdentifier()) {
  8179. return false;
  8180. }
  8181. this.next();
  8182. return this.match(58);
  8183. }
  8184. tsParseMappedTypeParameter() {
  8185. const node = this.startNode();
  8186. node.name = this.tsParseTypeParameterName();
  8187. node.constraint = this.tsExpectThenParseType(58);
  8188. return this.finishNode(node, "TSTypeParameter");
  8189. }
  8190. tsParseMappedType() {
  8191. const node = this.startNode();
  8192. this.expect(5);
  8193. if (this.match(53)) {
  8194. node.readonly = this.state.value;
  8195. this.next();
  8196. this.expectContextual(120);
  8197. } else if (this.eatContextual(120)) {
  8198. node.readonly = true;
  8199. }
  8200. this.expect(0);
  8201. node.typeParameter = this.tsParseMappedTypeParameter();
  8202. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8203. this.expect(3);
  8204. if (this.match(53)) {
  8205. node.optional = this.state.value;
  8206. this.next();
  8207. this.expect(17);
  8208. } else if (this.eat(17)) {
  8209. node.optional = true;
  8210. }
  8211. node.typeAnnotation = this.tsTryParseType();
  8212. this.semicolon();
  8213. this.expect(8);
  8214. return this.finishNode(node, "TSMappedType");
  8215. }
  8216. tsParseTupleType() {
  8217. const node = this.startNode();
  8218. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8219. let seenOptionalElement = false;
  8220. let labeledElements = null;
  8221. node.elementTypes.forEach(elementNode => {
  8222. var _labeledElements;
  8223. const {
  8224. type
  8225. } = elementNode;
  8226. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8227. this.raise(TSErrors.OptionalTypeBeforeRequired, {
  8228. at: elementNode
  8229. });
  8230. }
  8231. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8232. let checkType = type;
  8233. if (type === "TSRestType") {
  8234. elementNode = elementNode.typeAnnotation;
  8235. checkType = elementNode.type;
  8236. }
  8237. const isLabeled = checkType === "TSNamedTupleMember";
  8238. (_labeledElements = labeledElements) != null ? _labeledElements : labeledElements = isLabeled;
  8239. if (labeledElements !== isLabeled) {
  8240. this.raise(TSErrors.MixedLabeledAndUnlabeledElements, {
  8241. at: elementNode
  8242. });
  8243. }
  8244. });
  8245. return this.finishNode(node, "TSTupleType");
  8246. }
  8247. tsParseTupleElementType() {
  8248. const {
  8249. startLoc
  8250. } = this.state;
  8251. const rest = this.eat(21);
  8252. let labeled;
  8253. let label;
  8254. let optional;
  8255. let type;
  8256. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8257. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8258. if (chAfterWord === 58) {
  8259. labeled = true;
  8260. optional = false;
  8261. label = this.parseIdentifier(true);
  8262. this.expect(14);
  8263. type = this.tsParseType();
  8264. } else if (chAfterWord === 63) {
  8265. optional = true;
  8266. const startLoc = this.state.startLoc;
  8267. const wordName = this.state.value;
  8268. const typeOrLabel = this.tsParseNonArrayType();
  8269. if (this.lookaheadCharCode() === 58) {
  8270. labeled = true;
  8271. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8272. this.expect(17);
  8273. this.expect(14);
  8274. type = this.tsParseType();
  8275. } else {
  8276. labeled = false;
  8277. type = typeOrLabel;
  8278. this.expect(17);
  8279. }
  8280. } else {
  8281. type = this.tsParseType();
  8282. optional = this.eat(17);
  8283. labeled = this.eat(14);
  8284. }
  8285. if (labeled) {
  8286. let labeledNode;
  8287. if (label) {
  8288. labeledNode = this.startNodeAtNode(label);
  8289. labeledNode.optional = optional;
  8290. labeledNode.label = label;
  8291. labeledNode.elementType = type;
  8292. if (this.eat(17)) {
  8293. labeledNode.optional = true;
  8294. this.raise(TSErrors.TupleOptionalAfterType, {
  8295. at: this.state.lastTokStartLoc
  8296. });
  8297. }
  8298. } else {
  8299. labeledNode = this.startNodeAtNode(type);
  8300. labeledNode.optional = optional;
  8301. this.raise(TSErrors.InvalidTupleMemberLabel, {
  8302. at: type
  8303. });
  8304. labeledNode.label = type;
  8305. labeledNode.elementType = this.tsParseType();
  8306. }
  8307. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8308. } else if (optional) {
  8309. const optionalTypeNode = this.startNodeAtNode(type);
  8310. optionalTypeNode.typeAnnotation = type;
  8311. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8312. }
  8313. if (rest) {
  8314. const restNode = this.startNodeAt(startLoc);
  8315. restNode.typeAnnotation = type;
  8316. type = this.finishNode(restNode, "TSRestType");
  8317. }
  8318. return type;
  8319. }
  8320. tsParseParenthesizedType() {
  8321. const node = this.startNode();
  8322. this.expect(10);
  8323. node.typeAnnotation = this.tsParseType();
  8324. this.expect(11);
  8325. return this.finishNode(node, "TSParenthesizedType");
  8326. }
  8327. tsParseFunctionOrConstructorType(type, abstract) {
  8328. const node = this.startNode();
  8329. if (type === "TSConstructorType") {
  8330. node.abstract = !!abstract;
  8331. if (abstract) this.next();
  8332. this.next();
  8333. }
  8334. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8335. return this.finishNode(node, type);
  8336. }
  8337. tsParseLiteralTypeNode() {
  8338. const node = this.startNode();
  8339. node.literal = (() => {
  8340. switch (this.state.type) {
  8341. case 132:
  8342. case 133:
  8343. case 131:
  8344. case 85:
  8345. case 86:
  8346. return super.parseExprAtom();
  8347. default:
  8348. this.unexpected();
  8349. }
  8350. })();
  8351. return this.finishNode(node, "TSLiteralType");
  8352. }
  8353. tsParseTemplateLiteralType() {
  8354. const node = this.startNode();
  8355. node.literal = super.parseTemplate(false);
  8356. return this.finishNode(node, "TSLiteralType");
  8357. }
  8358. parseTemplateSubstitution() {
  8359. if (this.state.inType) return this.tsParseType();
  8360. return super.parseTemplateSubstitution();
  8361. }
  8362. tsParseThisTypeOrThisTypePredicate() {
  8363. const thisKeyword = this.tsParseThisTypeNode();
  8364. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  8365. return this.tsParseThisTypePredicate(thisKeyword);
  8366. } else {
  8367. return thisKeyword;
  8368. }
  8369. }
  8370. tsParseNonArrayType() {
  8371. switch (this.state.type) {
  8372. case 131:
  8373. case 132:
  8374. case 133:
  8375. case 85:
  8376. case 86:
  8377. return this.tsParseLiteralTypeNode();
  8378. case 53:
  8379. if (this.state.value === "-") {
  8380. const node = this.startNode();
  8381. const nextToken = this.lookahead();
  8382. if (nextToken.type !== 132 && nextToken.type !== 133) {
  8383. this.unexpected();
  8384. }
  8385. node.literal = this.parseMaybeUnary();
  8386. return this.finishNode(node, "TSLiteralType");
  8387. }
  8388. break;
  8389. case 78:
  8390. return this.tsParseThisTypeOrThisTypePredicate();
  8391. case 87:
  8392. return this.tsParseTypeQuery();
  8393. case 83:
  8394. return this.tsParseImportType();
  8395. case 5:
  8396. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8397. case 0:
  8398. return this.tsParseTupleType();
  8399. case 10:
  8400. return this.tsParseParenthesizedType();
  8401. case 25:
  8402. case 24:
  8403. return this.tsParseTemplateLiteralType();
  8404. default:
  8405. {
  8406. const {
  8407. type
  8408. } = this.state;
  8409. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8410. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8411. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8412. const node = this.startNode();
  8413. this.next();
  8414. return this.finishNode(node, nodeType);
  8415. }
  8416. return this.tsParseTypeReference();
  8417. }
  8418. }
  8419. }
  8420. this.unexpected();
  8421. }
  8422. tsParseArrayTypeOrHigher() {
  8423. let type = this.tsParseNonArrayType();
  8424. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8425. if (this.match(3)) {
  8426. const node = this.startNodeAtNode(type);
  8427. node.elementType = type;
  8428. this.expect(3);
  8429. type = this.finishNode(node, "TSArrayType");
  8430. } else {
  8431. const node = this.startNodeAtNode(type);
  8432. node.objectType = type;
  8433. node.indexType = this.tsParseType();
  8434. this.expect(3);
  8435. type = this.finishNode(node, "TSIndexedAccessType");
  8436. }
  8437. }
  8438. return type;
  8439. }
  8440. tsParseTypeOperator() {
  8441. const node = this.startNode();
  8442. const operator = this.state.value;
  8443. this.next();
  8444. node.operator = operator;
  8445. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8446. if (operator === "readonly") {
  8447. this.tsCheckTypeAnnotationForReadOnly(node);
  8448. }
  8449. return this.finishNode(node, "TSTypeOperator");
  8450. }
  8451. tsCheckTypeAnnotationForReadOnly(node) {
  8452. switch (node.typeAnnotation.type) {
  8453. case "TSTupleType":
  8454. case "TSArrayType":
  8455. return;
  8456. default:
  8457. this.raise(TSErrors.UnexpectedReadonly, {
  8458. at: node
  8459. });
  8460. }
  8461. }
  8462. tsParseInferType() {
  8463. const node = this.startNode();
  8464. this.expectContextual(113);
  8465. const typeParameter = this.startNode();
  8466. typeParameter.name = this.tsParseTypeParameterName();
  8467. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8468. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8469. return this.finishNode(node, "TSInferType");
  8470. }
  8471. tsParseConstraintForInferType() {
  8472. if (this.eat(81)) {
  8473. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8474. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8475. return constraint;
  8476. }
  8477. }
  8478. }
  8479. tsParseTypeOperatorOrHigher() {
  8480. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8481. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(113) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8482. }
  8483. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8484. const node = this.startNode();
  8485. const hasLeadingOperator = this.eat(operator);
  8486. const types = [];
  8487. do {
  8488. types.push(parseConstituentType());
  8489. } while (this.eat(operator));
  8490. if (types.length === 1 && !hasLeadingOperator) {
  8491. return types[0];
  8492. }
  8493. node.types = types;
  8494. return this.finishNode(node, kind);
  8495. }
  8496. tsParseIntersectionTypeOrHigher() {
  8497. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8498. }
  8499. tsParseUnionTypeOrHigher() {
  8500. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8501. }
  8502. tsIsStartOfFunctionType() {
  8503. if (this.match(47)) {
  8504. return true;
  8505. }
  8506. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8507. }
  8508. tsSkipParameterStart() {
  8509. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8510. this.next();
  8511. return true;
  8512. }
  8513. if (this.match(5)) {
  8514. const {
  8515. errors
  8516. } = this.state;
  8517. const previousErrorCount = errors.length;
  8518. try {
  8519. this.parseObjectLike(8, true);
  8520. return errors.length === previousErrorCount;
  8521. } catch (_unused) {
  8522. return false;
  8523. }
  8524. }
  8525. if (this.match(0)) {
  8526. this.next();
  8527. const {
  8528. errors
  8529. } = this.state;
  8530. const previousErrorCount = errors.length;
  8531. try {
  8532. super.parseBindingList(3, 93, 1);
  8533. return errors.length === previousErrorCount;
  8534. } catch (_unused2) {
  8535. return false;
  8536. }
  8537. }
  8538. return false;
  8539. }
  8540. tsIsUnambiguouslyStartOfFunctionType() {
  8541. this.next();
  8542. if (this.match(11) || this.match(21)) {
  8543. return true;
  8544. }
  8545. if (this.tsSkipParameterStart()) {
  8546. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8547. return true;
  8548. }
  8549. if (this.match(11)) {
  8550. this.next();
  8551. if (this.match(19)) {
  8552. return true;
  8553. }
  8554. }
  8555. }
  8556. return false;
  8557. }
  8558. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8559. return this.tsInType(() => {
  8560. const t = this.startNode();
  8561. this.expect(returnToken);
  8562. const node = this.startNode();
  8563. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8564. if (asserts && this.match(78)) {
  8565. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8566. if (thisTypePredicate.type === "TSThisType") {
  8567. node.parameterName = thisTypePredicate;
  8568. node.asserts = true;
  8569. node.typeAnnotation = null;
  8570. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8571. } else {
  8572. this.resetStartLocationFromNode(thisTypePredicate, node);
  8573. thisTypePredicate.asserts = true;
  8574. }
  8575. t.typeAnnotation = thisTypePredicate;
  8576. return this.finishNode(t, "TSTypeAnnotation");
  8577. }
  8578. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8579. if (!typePredicateVariable) {
  8580. if (!asserts) {
  8581. return this.tsParseTypeAnnotation(false, t);
  8582. }
  8583. node.parameterName = this.parseIdentifier();
  8584. node.asserts = asserts;
  8585. node.typeAnnotation = null;
  8586. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8587. return this.finishNode(t, "TSTypeAnnotation");
  8588. }
  8589. const type = this.tsParseTypeAnnotation(false);
  8590. node.parameterName = typePredicateVariable;
  8591. node.typeAnnotation = type;
  8592. node.asserts = asserts;
  8593. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8594. return this.finishNode(t, "TSTypeAnnotation");
  8595. });
  8596. }
  8597. tsTryParseTypeOrTypePredicateAnnotation() {
  8598. return this.match(14) ? this.tsParseTypeOrTypePredicateAnnotation(14) : undefined;
  8599. }
  8600. tsTryParseTypeAnnotation() {
  8601. return this.match(14) ? this.tsParseTypeAnnotation() : undefined;
  8602. }
  8603. tsTryParseType() {
  8604. return this.tsEatThenParseType(14);
  8605. }
  8606. tsParseTypePredicatePrefix() {
  8607. const id = this.parseIdentifier();
  8608. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  8609. this.next();
  8610. return id;
  8611. }
  8612. }
  8613. tsParseTypePredicateAsserts() {
  8614. if (this.state.type !== 107) {
  8615. return false;
  8616. }
  8617. const containsEsc = this.state.containsEsc;
  8618. this.next();
  8619. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8620. return false;
  8621. }
  8622. if (containsEsc) {
  8623. this.raise(Errors.InvalidEscapedReservedWord, {
  8624. at: this.state.lastTokStartLoc,
  8625. reservedWord: "asserts"
  8626. });
  8627. }
  8628. return true;
  8629. }
  8630. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8631. this.tsInType(() => {
  8632. if (eatColon) this.expect(14);
  8633. t.typeAnnotation = this.tsParseType();
  8634. });
  8635. return this.finishNode(t, "TSTypeAnnotation");
  8636. }
  8637. tsParseType() {
  8638. assert(this.state.inType);
  8639. const type = this.tsParseNonConditionalType();
  8640. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8641. return type;
  8642. }
  8643. const node = this.startNodeAtNode(type);
  8644. node.checkType = type;
  8645. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8646. this.expect(17);
  8647. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8648. this.expect(14);
  8649. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8650. return this.finishNode(node, "TSConditionalType");
  8651. }
  8652. isAbstractConstructorSignature() {
  8653. return this.isContextual(122) && this.lookahead().type === 77;
  8654. }
  8655. tsParseNonConditionalType() {
  8656. if (this.tsIsStartOfFunctionType()) {
  8657. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8658. }
  8659. if (this.match(77)) {
  8660. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8661. } else if (this.isAbstractConstructorSignature()) {
  8662. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8663. }
  8664. return this.tsParseUnionTypeOrHigher();
  8665. }
  8666. tsParseTypeAssertion() {
  8667. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8668. this.raise(TSErrors.ReservedTypeAssertion, {
  8669. at: this.state.startLoc
  8670. });
  8671. }
  8672. const node = this.startNode();
  8673. node.typeAnnotation = this.tsInType(() => {
  8674. this.next();
  8675. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8676. });
  8677. this.expect(48);
  8678. node.expression = this.parseMaybeUnary();
  8679. return this.finishNode(node, "TSTypeAssertion");
  8680. }
  8681. tsParseHeritageClause(token) {
  8682. const originalStartLoc = this.state.startLoc;
  8683. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8684. const node = this.startNode();
  8685. node.expression = this.tsParseEntityName();
  8686. if (this.match(47)) {
  8687. node.typeParameters = this.tsParseTypeArguments();
  8688. }
  8689. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8690. });
  8691. if (!delimitedList.length) {
  8692. this.raise(TSErrors.EmptyHeritageClauseType, {
  8693. at: originalStartLoc,
  8694. token
  8695. });
  8696. }
  8697. return delimitedList;
  8698. }
  8699. tsParseInterfaceDeclaration(node, properties = {}) {
  8700. if (this.hasFollowingLineBreak()) return null;
  8701. this.expectContextual(127);
  8702. if (properties.declare) node.declare = true;
  8703. if (tokenIsIdentifier(this.state.type)) {
  8704. node.id = this.parseIdentifier();
  8705. this.checkIdentifier(node.id, BIND_TS_INTERFACE);
  8706. } else {
  8707. node.id = null;
  8708. this.raise(TSErrors.MissingInterfaceName, {
  8709. at: this.state.startLoc
  8710. });
  8711. }
  8712. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8713. if (this.eat(81)) {
  8714. node.extends = this.tsParseHeritageClause("extends");
  8715. }
  8716. const body = this.startNode();
  8717. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8718. node.body = this.finishNode(body, "TSInterfaceBody");
  8719. return this.finishNode(node, "TSInterfaceDeclaration");
  8720. }
  8721. tsParseTypeAliasDeclaration(node) {
  8722. node.id = this.parseIdentifier();
  8723. this.checkIdentifier(node.id, BIND_TS_TYPE);
  8724. node.typeAnnotation = this.tsInType(() => {
  8725. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8726. this.expect(29);
  8727. if (this.isContextual(112) && this.lookahead().type !== 16) {
  8728. const node = this.startNode();
  8729. this.next();
  8730. return this.finishNode(node, "TSIntrinsicKeyword");
  8731. }
  8732. return this.tsParseType();
  8733. });
  8734. this.semicolon();
  8735. return this.finishNode(node, "TSTypeAliasDeclaration");
  8736. }
  8737. tsInNoContext(cb) {
  8738. const oldContext = this.state.context;
  8739. this.state.context = [oldContext[0]];
  8740. try {
  8741. return cb();
  8742. } finally {
  8743. this.state.context = oldContext;
  8744. }
  8745. }
  8746. tsInType(cb) {
  8747. const oldInType = this.state.inType;
  8748. this.state.inType = true;
  8749. try {
  8750. return cb();
  8751. } finally {
  8752. this.state.inType = oldInType;
  8753. }
  8754. }
  8755. tsInDisallowConditionalTypesContext(cb) {
  8756. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8757. this.state.inDisallowConditionalTypesContext = true;
  8758. try {
  8759. return cb();
  8760. } finally {
  8761. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8762. }
  8763. }
  8764. tsInAllowConditionalTypesContext(cb) {
  8765. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8766. this.state.inDisallowConditionalTypesContext = false;
  8767. try {
  8768. return cb();
  8769. } finally {
  8770. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8771. }
  8772. }
  8773. tsEatThenParseType(token) {
  8774. return !this.match(token) ? undefined : this.tsNextThenParseType();
  8775. }
  8776. tsExpectThenParseType(token) {
  8777. return this.tsDoThenParseType(() => this.expect(token));
  8778. }
  8779. tsNextThenParseType() {
  8780. return this.tsDoThenParseType(() => this.next());
  8781. }
  8782. tsDoThenParseType(cb) {
  8783. return this.tsInType(() => {
  8784. cb();
  8785. return this.tsParseType();
  8786. });
  8787. }
  8788. tsParseEnumMember() {
  8789. const node = this.startNode();
  8790. node.id = this.match(131) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8791. if (this.eat(29)) {
  8792. node.initializer = super.parseMaybeAssignAllowIn();
  8793. }
  8794. return this.finishNode(node, "TSEnumMember");
  8795. }
  8796. tsParseEnumDeclaration(node, properties = {}) {
  8797. if (properties.const) node.const = true;
  8798. if (properties.declare) node.declare = true;
  8799. this.expectContextual(124);
  8800. node.id = this.parseIdentifier();
  8801. this.checkIdentifier(node.id, node.const ? BIND_TS_CONST_ENUM : BIND_TS_ENUM);
  8802. this.expect(5);
  8803. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8804. this.expect(8);
  8805. return this.finishNode(node, "TSEnumDeclaration");
  8806. }
  8807. tsParseModuleBlock() {
  8808. const node = this.startNode();
  8809. this.scope.enter(SCOPE_OTHER);
  8810. this.expect(5);
  8811. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8812. this.scope.exit();
  8813. return this.finishNode(node, "TSModuleBlock");
  8814. }
  8815. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8816. node.id = this.parseIdentifier();
  8817. if (!nested) {
  8818. this.checkIdentifier(node.id, BIND_TS_NAMESPACE);
  8819. }
  8820. if (this.eat(16)) {
  8821. const inner = this.startNode();
  8822. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8823. node.body = inner;
  8824. } else {
  8825. this.scope.enter(SCOPE_TS_MODULE);
  8826. this.prodParam.enter(PARAM);
  8827. node.body = this.tsParseModuleBlock();
  8828. this.prodParam.exit();
  8829. this.scope.exit();
  8830. }
  8831. return this.finishNode(node, "TSModuleDeclaration");
  8832. }
  8833. tsParseAmbientExternalModuleDeclaration(node) {
  8834. if (this.isContextual(110)) {
  8835. node.global = true;
  8836. node.id = this.parseIdentifier();
  8837. } else if (this.match(131)) {
  8838. node.id = super.parseStringLiteral(this.state.value);
  8839. } else {
  8840. this.unexpected();
  8841. }
  8842. if (this.match(5)) {
  8843. this.scope.enter(SCOPE_TS_MODULE);
  8844. this.prodParam.enter(PARAM);
  8845. node.body = this.tsParseModuleBlock();
  8846. this.prodParam.exit();
  8847. this.scope.exit();
  8848. } else {
  8849. this.semicolon();
  8850. }
  8851. return this.finishNode(node, "TSModuleDeclaration");
  8852. }
  8853. tsParseImportEqualsDeclaration(node, isExport) {
  8854. node.isExport = isExport || false;
  8855. node.id = this.parseIdentifier();
  8856. this.checkIdentifier(node.id, BIND_FLAGS_TS_IMPORT);
  8857. this.expect(29);
  8858. const moduleReference = this.tsParseModuleReference();
  8859. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8860. this.raise(TSErrors.ImportAliasHasImportType, {
  8861. at: moduleReference
  8862. });
  8863. }
  8864. node.moduleReference = moduleReference;
  8865. this.semicolon();
  8866. return this.finishNode(node, "TSImportEqualsDeclaration");
  8867. }
  8868. tsIsExternalModuleReference() {
  8869. return this.isContextual(117) && this.lookaheadCharCode() === 40;
  8870. }
  8871. tsParseModuleReference() {
  8872. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  8873. }
  8874. tsParseExternalModuleReference() {
  8875. const node = this.startNode();
  8876. this.expectContextual(117);
  8877. this.expect(10);
  8878. if (!this.match(131)) {
  8879. this.unexpected();
  8880. }
  8881. node.expression = super.parseExprAtom();
  8882. this.expect(11);
  8883. return this.finishNode(node, "TSExternalModuleReference");
  8884. }
  8885. tsLookAhead(f) {
  8886. const state = this.state.clone();
  8887. const res = f();
  8888. this.state = state;
  8889. return res;
  8890. }
  8891. tsTryParseAndCatch(f) {
  8892. const result = this.tryParse(abort => f() || abort());
  8893. if (result.aborted || !result.node) return undefined;
  8894. if (result.error) this.state = result.failState;
  8895. return result.node;
  8896. }
  8897. tsTryParse(f) {
  8898. const state = this.state.clone();
  8899. const result = f();
  8900. if (result !== undefined && result !== false) {
  8901. return result;
  8902. } else {
  8903. this.state = state;
  8904. return undefined;
  8905. }
  8906. }
  8907. tsTryParseDeclare(nany) {
  8908. if (this.isLineTerminator()) {
  8909. return;
  8910. }
  8911. let starttype = this.state.type;
  8912. let kind;
  8913. if (this.isContextual(99)) {
  8914. starttype = 74;
  8915. kind = "let";
  8916. }
  8917. return this.tsInAmbientContext(() => {
  8918. if (starttype === 68) {
  8919. nany.declare = true;
  8920. return super.parseFunctionStatement(nany, false, false);
  8921. }
  8922. if (starttype === 80) {
  8923. nany.declare = true;
  8924. return this.parseClass(nany, true, false);
  8925. }
  8926. if (starttype === 124) {
  8927. return this.tsParseEnumDeclaration(nany, {
  8928. declare: true
  8929. });
  8930. }
  8931. if (starttype === 110) {
  8932. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8933. }
  8934. if (starttype === 75 || starttype === 74) {
  8935. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8936. nany.declare = true;
  8937. return this.parseVarStatement(nany, kind || this.state.value, true);
  8938. }
  8939. this.expect(75);
  8940. return this.tsParseEnumDeclaration(nany, {
  8941. const: true,
  8942. declare: true
  8943. });
  8944. }
  8945. if (starttype === 127) {
  8946. const result = this.tsParseInterfaceDeclaration(nany, {
  8947. declare: true
  8948. });
  8949. if (result) return result;
  8950. }
  8951. if (tokenIsIdentifier(starttype)) {
  8952. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8953. }
  8954. });
  8955. }
  8956. tsTryParseExportDeclaration() {
  8957. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  8958. }
  8959. tsParseExpressionStatement(node, expr, decorators) {
  8960. switch (expr.name) {
  8961. case "declare":
  8962. {
  8963. const declaration = this.tsTryParseDeclare(node);
  8964. if (declaration) {
  8965. declaration.declare = true;
  8966. return declaration;
  8967. }
  8968. break;
  8969. }
  8970. case "global":
  8971. if (this.match(5)) {
  8972. this.scope.enter(SCOPE_TS_MODULE);
  8973. this.prodParam.enter(PARAM);
  8974. const mod = node;
  8975. mod.global = true;
  8976. mod.id = expr;
  8977. mod.body = this.tsParseModuleBlock();
  8978. this.scope.exit();
  8979. this.prodParam.exit();
  8980. return this.finishNode(mod, "TSModuleDeclaration");
  8981. }
  8982. break;
  8983. default:
  8984. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8985. }
  8986. }
  8987. tsParseDeclaration(node, value, next, decorators) {
  8988. switch (value) {
  8989. case "abstract":
  8990. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8991. return this.tsParseAbstractDeclaration(node, decorators);
  8992. }
  8993. break;
  8994. case "module":
  8995. if (this.tsCheckLineTerminator(next)) {
  8996. if (this.match(131)) {
  8997. return this.tsParseAmbientExternalModuleDeclaration(node);
  8998. } else if (tokenIsIdentifier(this.state.type)) {
  8999. return this.tsParseModuleOrNamespaceDeclaration(node);
  9000. }
  9001. }
  9002. break;
  9003. case "namespace":
  9004. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9005. return this.tsParseModuleOrNamespaceDeclaration(node);
  9006. }
  9007. break;
  9008. case "type":
  9009. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9010. return this.tsParseTypeAliasDeclaration(node);
  9011. }
  9012. break;
  9013. }
  9014. }
  9015. tsCheckLineTerminator(next) {
  9016. if (next) {
  9017. if (this.hasFollowingLineBreak()) return false;
  9018. this.next();
  9019. return true;
  9020. }
  9021. return !this.isLineTerminator();
  9022. }
  9023. tsTryParseGenericAsyncArrowFunction(startLoc) {
  9024. if (!this.match(47)) {
  9025. return undefined;
  9026. }
  9027. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9028. this.state.maybeInArrowParameters = true;
  9029. const res = this.tsTryParseAndCatch(() => {
  9030. const node = this.startNodeAt(startLoc);
  9031. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9032. super.parseFunctionParams(node);
  9033. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9034. this.expect(19);
  9035. return node;
  9036. });
  9037. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9038. if (!res) {
  9039. return undefined;
  9040. }
  9041. return super.parseArrowExpression(res, null, true);
  9042. }
  9043. tsParseTypeArgumentsInExpression() {
  9044. if (this.reScan_lt() !== 47) {
  9045. return undefined;
  9046. }
  9047. return this.tsParseTypeArguments();
  9048. }
  9049. tsParseTypeArguments() {
  9050. const node = this.startNode();
  9051. node.params = this.tsInType(() => this.tsInNoContext(() => {
  9052. this.expect(47);
  9053. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9054. }));
  9055. if (node.params.length === 0) {
  9056. this.raise(TSErrors.EmptyTypeArguments, {
  9057. at: node
  9058. });
  9059. }
  9060. this.expect(48);
  9061. return this.finishNode(node, "TSTypeParameterInstantiation");
  9062. }
  9063. tsIsDeclarationStart() {
  9064. return tokenIsTSDeclarationStart(this.state.type);
  9065. }
  9066. isExportDefaultSpecifier() {
  9067. if (this.tsIsDeclarationStart()) return false;
  9068. return super.isExportDefaultSpecifier();
  9069. }
  9070. parseAssignableListItem(flags, decorators) {
  9071. const startLoc = this.state.startLoc;
  9072. const modified = {};
  9073. this.tsParseModifiers({
  9074. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9075. }, modified);
  9076. const accessibility = modified.accessibility;
  9077. const override = modified.override;
  9078. const readonly = modified.readonly;
  9079. if (!(flags & 4) && (accessibility || readonly || override)) {
  9080. this.raise(TSErrors.UnexpectedParameterModifier, {
  9081. at: startLoc
  9082. });
  9083. }
  9084. const left = this.parseMaybeDefault();
  9085. this.parseAssignableListItemTypes(left, flags);
  9086. const elt = this.parseMaybeDefault(left.loc.start, left);
  9087. if (accessibility || readonly || override) {
  9088. const pp = this.startNodeAt(startLoc);
  9089. if (decorators.length) {
  9090. pp.decorators = decorators;
  9091. }
  9092. if (accessibility) pp.accessibility = accessibility;
  9093. if (readonly) pp.readonly = readonly;
  9094. if (override) pp.override = override;
  9095. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9096. this.raise(TSErrors.UnsupportedParameterPropertyKind, {
  9097. at: pp
  9098. });
  9099. }
  9100. pp.parameter = elt;
  9101. return this.finishNode(pp, "TSParameterProperty");
  9102. }
  9103. if (decorators.length) {
  9104. left.decorators = decorators;
  9105. }
  9106. return elt;
  9107. }
  9108. isSimpleParameter(node) {
  9109. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9110. }
  9111. tsDisallowOptionalPattern(node) {
  9112. for (const param of node.params) {
  9113. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9114. this.raise(TSErrors.PatternIsOptional, {
  9115. at: param
  9116. });
  9117. }
  9118. }
  9119. }
  9120. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9121. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9122. this.tsDisallowOptionalPattern(node);
  9123. }
  9124. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9125. if (this.match(14)) {
  9126. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9127. }
  9128. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9129. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9130. return this.finishNode(node, bodilessType);
  9131. }
  9132. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9133. this.raise(TSErrors.DeclareFunctionHasImplementation, {
  9134. at: node
  9135. });
  9136. if (node.declare) {
  9137. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9138. }
  9139. }
  9140. this.tsDisallowOptionalPattern(node);
  9141. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9142. }
  9143. registerFunctionStatementId(node) {
  9144. if (!node.body && node.id) {
  9145. this.checkIdentifier(node.id, BIND_TS_AMBIENT);
  9146. } else {
  9147. super.registerFunctionStatementId(node);
  9148. }
  9149. }
  9150. tsCheckForInvalidTypeCasts(items) {
  9151. items.forEach(node => {
  9152. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9153. this.raise(TSErrors.UnexpectedTypeAnnotation, {
  9154. at: node.typeAnnotation
  9155. });
  9156. }
  9157. });
  9158. }
  9159. toReferencedList(exprList, isInParens) {
  9160. this.tsCheckForInvalidTypeCasts(exprList);
  9161. return exprList;
  9162. }
  9163. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9164. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9165. if (node.type === "ArrayExpression") {
  9166. this.tsCheckForInvalidTypeCasts(node.elements);
  9167. }
  9168. return node;
  9169. }
  9170. parseSubscript(base, startLoc, noCalls, state) {
  9171. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9172. this.state.canStartJSXElement = false;
  9173. this.next();
  9174. const nonNullExpression = this.startNodeAt(startLoc);
  9175. nonNullExpression.expression = base;
  9176. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9177. }
  9178. let isOptionalCall = false;
  9179. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9180. if (noCalls) {
  9181. state.stop = true;
  9182. return base;
  9183. }
  9184. state.optionalChainMember = isOptionalCall = true;
  9185. this.next();
  9186. }
  9187. if (this.match(47) || this.match(51)) {
  9188. let missingParenErrorLoc;
  9189. const result = this.tsTryParseAndCatch(() => {
  9190. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9191. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9192. if (asyncArrowFn) {
  9193. return asyncArrowFn;
  9194. }
  9195. }
  9196. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9197. if (!typeArguments) return;
  9198. if (isOptionalCall && !this.match(10)) {
  9199. missingParenErrorLoc = this.state.curPosition();
  9200. return;
  9201. }
  9202. if (tokenIsTemplate(this.state.type)) {
  9203. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9204. result.typeParameters = typeArguments;
  9205. return result;
  9206. }
  9207. if (!noCalls && this.eat(10)) {
  9208. const node = this.startNodeAt(startLoc);
  9209. node.callee = base;
  9210. node.arguments = this.parseCallExpressionArguments(11, false);
  9211. this.tsCheckForInvalidTypeCasts(node.arguments);
  9212. node.typeParameters = typeArguments;
  9213. if (state.optionalChainMember) {
  9214. node.optional = isOptionalCall;
  9215. }
  9216. return this.finishCallExpression(node, state.optionalChainMember);
  9217. }
  9218. const tokenType = this.state.type;
  9219. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9220. return;
  9221. }
  9222. const node = this.startNodeAt(startLoc);
  9223. node.expression = base;
  9224. node.typeParameters = typeArguments;
  9225. return this.finishNode(node, "TSInstantiationExpression");
  9226. });
  9227. if (missingParenErrorLoc) {
  9228. this.unexpected(missingParenErrorLoc, 10);
  9229. }
  9230. if (result) {
  9231. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  9232. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
  9233. at: this.state.startLoc
  9234. });
  9235. }
  9236. return result;
  9237. }
  9238. }
  9239. return super.parseSubscript(base, startLoc, noCalls, state);
  9240. }
  9241. parseNewCallee(node) {
  9242. var _callee$extra;
  9243. super.parseNewCallee(node);
  9244. const {
  9245. callee
  9246. } = node;
  9247. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9248. node.typeParameters = callee.typeParameters;
  9249. node.callee = callee.expression;
  9250. }
  9251. }
  9252. parseExprOp(left, leftStartLoc, minPrec) {
  9253. let isSatisfies;
  9254. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(118)))) {
  9255. const node = this.startNodeAt(leftStartLoc);
  9256. node.expression = left;
  9257. node.typeAnnotation = this.tsInType(() => {
  9258. this.next();
  9259. if (this.match(75)) {
  9260. if (isSatisfies) {
  9261. this.raise(Errors.UnexpectedKeyword, {
  9262. at: this.state.startLoc,
  9263. keyword: "const"
  9264. });
  9265. }
  9266. return this.tsParseTypeReference();
  9267. }
  9268. return this.tsParseType();
  9269. });
  9270. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9271. this.reScan_lt_gt();
  9272. return this.parseExprOp(node, leftStartLoc, minPrec);
  9273. }
  9274. return super.parseExprOp(left, leftStartLoc, minPrec);
  9275. }
  9276. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9277. if (!this.state.isAmbientContext) {
  9278. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9279. }
  9280. }
  9281. checkImportReflection(node) {
  9282. super.checkImportReflection(node);
  9283. if (node.module && node.importKind !== "value") {
  9284. this.raise(TSErrors.ImportReflectionHasImportType, {
  9285. at: node.specifiers[0].loc.start
  9286. });
  9287. }
  9288. }
  9289. checkDuplicateExports() {}
  9290. parseImport(node) {
  9291. node.importKind = "value";
  9292. if (tokenIsIdentifier(this.state.type) || this.match(55) || this.match(5)) {
  9293. let ahead = this.lookahead();
  9294. if (this.isContextual(128) && ahead.type !== 12 && ahead.type !== 97 && ahead.type !== 29) {
  9295. node.importKind = "type";
  9296. this.next();
  9297. ahead = this.lookahead();
  9298. }
  9299. if (tokenIsIdentifier(this.state.type) && ahead.type === 29) {
  9300. return this.tsParseImportEqualsDeclaration(node);
  9301. }
  9302. }
  9303. const importNode = super.parseImport(node);
  9304. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9305. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
  9306. at: importNode
  9307. });
  9308. }
  9309. return importNode;
  9310. }
  9311. parseExport(node, decorators) {
  9312. if (this.match(83)) {
  9313. this.next();
  9314. if (this.isContextual(128) && this.lookaheadCharCode() !== 61) {
  9315. node.importKind = "type";
  9316. this.next();
  9317. } else {
  9318. node.importKind = "value";
  9319. }
  9320. return this.tsParseImportEqualsDeclaration(node, true);
  9321. } else if (this.eat(29)) {
  9322. const assign = node;
  9323. assign.expression = super.parseExpression();
  9324. this.semicolon();
  9325. return this.finishNode(assign, "TSExportAssignment");
  9326. } else if (this.eatContextual(93)) {
  9327. const decl = node;
  9328. this.expectContextual(126);
  9329. decl.id = this.parseIdentifier();
  9330. this.semicolon();
  9331. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9332. } else {
  9333. node.exportKind = "value";
  9334. if (this.isContextual(128)) {
  9335. const ch = this.lookaheadCharCode();
  9336. if (ch === 123 || ch === 42) {
  9337. this.next();
  9338. node.exportKind = "type";
  9339. }
  9340. }
  9341. return super.parseExport(node, decorators);
  9342. }
  9343. }
  9344. isAbstractClass() {
  9345. return this.isContextual(122) && this.lookahead().type === 80;
  9346. }
  9347. parseExportDefaultExpression() {
  9348. if (this.isAbstractClass()) {
  9349. const cls = this.startNode();
  9350. this.next();
  9351. cls.abstract = true;
  9352. return this.parseClass(cls, true, true);
  9353. }
  9354. if (this.match(127)) {
  9355. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9356. if (result) return result;
  9357. }
  9358. return super.parseExportDefaultExpression();
  9359. }
  9360. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9361. const {
  9362. isAmbientContext
  9363. } = this.state;
  9364. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9365. if (!isAmbientContext) return declaration;
  9366. for (const {
  9367. id,
  9368. init
  9369. } of declaration.declarations) {
  9370. if (!init) continue;
  9371. if (kind !== "const" || !!id.typeAnnotation) {
  9372. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
  9373. at: init
  9374. });
  9375. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9376. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
  9377. at: init
  9378. });
  9379. }
  9380. }
  9381. return declaration;
  9382. }
  9383. parseStatementContent(flags, decorators) {
  9384. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9385. const node = this.startNode();
  9386. this.expect(75);
  9387. return this.tsParseEnumDeclaration(node, {
  9388. const: true
  9389. });
  9390. }
  9391. if (this.isContextual(124)) {
  9392. return this.tsParseEnumDeclaration(this.startNode());
  9393. }
  9394. if (this.isContextual(127)) {
  9395. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9396. if (result) return result;
  9397. }
  9398. return super.parseStatementContent(flags, decorators);
  9399. }
  9400. parseAccessModifier() {
  9401. return this.tsParseModifier(["public", "protected", "private"]);
  9402. }
  9403. tsHasSomeModifiers(member, modifiers) {
  9404. return modifiers.some(modifier => {
  9405. if (tsIsAccessModifier(modifier)) {
  9406. return member.accessibility === modifier;
  9407. }
  9408. return !!member[modifier];
  9409. });
  9410. }
  9411. tsIsStartOfStaticBlocks() {
  9412. return this.isContextual(104) && this.lookaheadCharCode() === 123;
  9413. }
  9414. parseClassMember(classBody, member, state) {
  9415. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9416. this.tsParseModifiers({
  9417. allowedModifiers: modifiers,
  9418. disallowedModifiers: ["in", "out"],
  9419. stopOnStartOfClassStaticBlock: true,
  9420. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9421. }, member);
  9422. const callParseClassMemberWithIsStatic = () => {
  9423. if (this.tsIsStartOfStaticBlocks()) {
  9424. this.next();
  9425. this.next();
  9426. if (this.tsHasSomeModifiers(member, modifiers)) {
  9427. this.raise(TSErrors.StaticBlockCannotHaveModifier, {
  9428. at: this.state.curPosition()
  9429. });
  9430. }
  9431. super.parseClassStaticBlock(classBody, member);
  9432. } else {
  9433. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9434. }
  9435. };
  9436. if (member.declare) {
  9437. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9438. } else {
  9439. callParseClassMemberWithIsStatic();
  9440. }
  9441. }
  9442. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9443. const idx = this.tsTryParseIndexSignature(member);
  9444. if (idx) {
  9445. classBody.body.push(idx);
  9446. if (member.abstract) {
  9447. this.raise(TSErrors.IndexSignatureHasAbstract, {
  9448. at: member
  9449. });
  9450. }
  9451. if (member.accessibility) {
  9452. this.raise(TSErrors.IndexSignatureHasAccessibility, {
  9453. at: member,
  9454. modifier: member.accessibility
  9455. });
  9456. }
  9457. if (member.declare) {
  9458. this.raise(TSErrors.IndexSignatureHasDeclare, {
  9459. at: member
  9460. });
  9461. }
  9462. if (member.override) {
  9463. this.raise(TSErrors.IndexSignatureHasOverride, {
  9464. at: member
  9465. });
  9466. }
  9467. return;
  9468. }
  9469. if (!this.state.inAbstractClass && member.abstract) {
  9470. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
  9471. at: member
  9472. });
  9473. }
  9474. if (member.override) {
  9475. if (!state.hadSuperClass) {
  9476. this.raise(TSErrors.OverrideNotInSubClass, {
  9477. at: member
  9478. });
  9479. }
  9480. }
  9481. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9482. }
  9483. parsePostMemberNameModifiers(methodOrProp) {
  9484. const optional = this.eat(17);
  9485. if (optional) methodOrProp.optional = true;
  9486. if (methodOrProp.readonly && this.match(10)) {
  9487. this.raise(TSErrors.ClassMethodHasReadonly, {
  9488. at: methodOrProp
  9489. });
  9490. }
  9491. if (methodOrProp.declare && this.match(10)) {
  9492. this.raise(TSErrors.ClassMethodHasDeclare, {
  9493. at: methodOrProp
  9494. });
  9495. }
  9496. }
  9497. parseExpressionStatement(node, expr, decorators) {
  9498. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9499. return decl || super.parseExpressionStatement(node, expr, decorators);
  9500. }
  9501. shouldParseExportDeclaration() {
  9502. if (this.tsIsDeclarationStart()) return true;
  9503. return super.shouldParseExportDeclaration();
  9504. }
  9505. parseConditional(expr, startLoc, refExpressionErrors) {
  9506. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9507. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9508. }
  9509. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9510. if (!result.node) {
  9511. if (result.error) {
  9512. super.setOptionalParametersError(refExpressionErrors, result.error);
  9513. }
  9514. return expr;
  9515. }
  9516. if (result.error) this.state = result.failState;
  9517. return result.node;
  9518. }
  9519. parseParenItem(node, startLoc) {
  9520. node = super.parseParenItem(node, startLoc);
  9521. if (this.eat(17)) {
  9522. node.optional = true;
  9523. this.resetEndLocation(node);
  9524. }
  9525. if (this.match(14)) {
  9526. const typeCastNode = this.startNodeAt(startLoc);
  9527. typeCastNode.expression = node;
  9528. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9529. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9530. }
  9531. return node;
  9532. }
  9533. parseExportDeclaration(node) {
  9534. if (!this.state.isAmbientContext && this.isContextual(123)) {
  9535. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9536. }
  9537. const startLoc = this.state.startLoc;
  9538. const isDeclare = this.eatContextual(123);
  9539. if (isDeclare && (this.isContextual(123) || !this.shouldParseExportDeclaration())) {
  9540. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
  9541. at: this.state.startLoc
  9542. });
  9543. }
  9544. const isIdentifier = tokenIsIdentifier(this.state.type);
  9545. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9546. if (!declaration) return null;
  9547. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9548. node.exportKind = "type";
  9549. }
  9550. if (isDeclare) {
  9551. this.resetStartLocation(declaration, startLoc);
  9552. declaration.declare = true;
  9553. }
  9554. return declaration;
  9555. }
  9556. parseClassId(node, isStatement, optionalId, bindingType) {
  9557. if ((!isStatement || optionalId) && this.isContextual(111)) {
  9558. return;
  9559. }
  9560. super.parseClassId(node, isStatement, optionalId, node.declare ? BIND_TS_AMBIENT : BIND_CLASS);
  9561. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9562. if (typeParameters) node.typeParameters = typeParameters;
  9563. }
  9564. parseClassPropertyAnnotation(node) {
  9565. if (!node.optional) {
  9566. if (this.eat(35)) {
  9567. node.definite = true;
  9568. } else if (this.eat(17)) {
  9569. node.optional = true;
  9570. }
  9571. }
  9572. const type = this.tsTryParseTypeAnnotation();
  9573. if (type) node.typeAnnotation = type;
  9574. }
  9575. parseClassProperty(node) {
  9576. this.parseClassPropertyAnnotation(node);
  9577. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9578. this.raise(TSErrors.DeclareClassFieldHasInitializer, {
  9579. at: this.state.startLoc
  9580. });
  9581. }
  9582. if (node.abstract && this.match(29)) {
  9583. const {
  9584. key
  9585. } = node;
  9586. this.raise(TSErrors.AbstractPropertyHasInitializer, {
  9587. at: this.state.startLoc,
  9588. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9589. });
  9590. }
  9591. return super.parseClassProperty(node);
  9592. }
  9593. parseClassPrivateProperty(node) {
  9594. if (node.abstract) {
  9595. this.raise(TSErrors.PrivateElementHasAbstract, {
  9596. at: node
  9597. });
  9598. }
  9599. if (node.accessibility) {
  9600. this.raise(TSErrors.PrivateElementHasAccessibility, {
  9601. at: node,
  9602. modifier: node.accessibility
  9603. });
  9604. }
  9605. this.parseClassPropertyAnnotation(node);
  9606. return super.parseClassPrivateProperty(node);
  9607. }
  9608. parseClassAccessorProperty(node) {
  9609. this.parseClassPropertyAnnotation(node);
  9610. if (node.optional) {
  9611. this.raise(TSErrors.AccessorCannotBeOptional, {
  9612. at: node
  9613. });
  9614. }
  9615. return super.parseClassAccessorProperty(node);
  9616. }
  9617. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9618. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9619. if (typeParameters && isConstructor) {
  9620. this.raise(TSErrors.ConstructorHasTypeParameters, {
  9621. at: typeParameters
  9622. });
  9623. }
  9624. const {
  9625. declare = false,
  9626. kind
  9627. } = method;
  9628. if (declare && (kind === "get" || kind === "set")) {
  9629. this.raise(TSErrors.DeclareAccessor, {
  9630. at: method,
  9631. kind
  9632. });
  9633. }
  9634. if (typeParameters) method.typeParameters = typeParameters;
  9635. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9636. }
  9637. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9638. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9639. if (typeParameters) method.typeParameters = typeParameters;
  9640. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9641. }
  9642. declareClassPrivateMethodInScope(node, kind) {
  9643. if (node.type === "TSDeclareMethod") return;
  9644. if (node.type === "MethodDefinition" && !node.value.body) return;
  9645. super.declareClassPrivateMethodInScope(node, kind);
  9646. }
  9647. parseClassSuper(node) {
  9648. super.parseClassSuper(node);
  9649. if (node.superClass && (this.match(47) || this.match(51))) {
  9650. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9651. }
  9652. if (this.eatContextual(111)) {
  9653. node.implements = this.tsParseHeritageClause("implements");
  9654. }
  9655. }
  9656. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9657. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9658. if (typeParameters) prop.typeParameters = typeParameters;
  9659. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9660. }
  9661. parseFunctionParams(node, isConstructor) {
  9662. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9663. if (typeParameters) node.typeParameters = typeParameters;
  9664. super.parseFunctionParams(node, isConstructor);
  9665. }
  9666. parseVarId(decl, kind) {
  9667. super.parseVarId(decl, kind);
  9668. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9669. decl.definite = true;
  9670. }
  9671. const type = this.tsTryParseTypeAnnotation();
  9672. if (type) {
  9673. decl.id.typeAnnotation = type;
  9674. this.resetEndLocation(decl.id);
  9675. }
  9676. }
  9677. parseAsyncArrowFromCallExpression(node, call) {
  9678. if (this.match(14)) {
  9679. node.returnType = this.tsParseTypeAnnotation();
  9680. }
  9681. return super.parseAsyncArrowFromCallExpression(node, call);
  9682. }
  9683. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9684. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2, _jsx4, _typeCast3;
  9685. let state;
  9686. let jsx;
  9687. let typeCast;
  9688. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  9689. state = this.state.clone();
  9690. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9691. if (!jsx.error) return jsx.node;
  9692. const {
  9693. context
  9694. } = this.state;
  9695. const currentContext = context[context.length - 1];
  9696. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9697. context.pop();
  9698. }
  9699. }
  9700. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9701. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9702. }
  9703. if (!state || state === this.state) state = this.state.clone();
  9704. let typeParameters;
  9705. const arrow = this.tryParse(abort => {
  9706. var _expr$extra, _typeParameters;
  9707. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9708. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9709. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9710. abort();
  9711. }
  9712. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9713. this.resetStartLocationFromNode(expr, typeParameters);
  9714. }
  9715. expr.typeParameters = typeParameters;
  9716. return expr;
  9717. }, state);
  9718. if (!arrow.error && !arrow.aborted) {
  9719. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9720. return arrow.node;
  9721. }
  9722. if (!jsx) {
  9723. assert(!this.hasPlugin("jsx"));
  9724. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9725. if (!typeCast.error) return typeCast.node;
  9726. }
  9727. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9728. this.state = jsx.failState;
  9729. return jsx.node;
  9730. }
  9731. if (arrow.node) {
  9732. this.state = arrow.failState;
  9733. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9734. return arrow.node;
  9735. }
  9736. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9737. this.state = typeCast.failState;
  9738. return typeCast.node;
  9739. }
  9740. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  9741. if (arrow.thrown) throw arrow.error;
  9742. if ((_typeCast2 = typeCast) != null && _typeCast2.thrown) throw typeCast.error;
  9743. throw ((_jsx4 = jsx) == null ? void 0 : _jsx4.error) || arrow.error || ((_typeCast3 = typeCast) == null ? void 0 : _typeCast3.error);
  9744. }
  9745. reportReservedArrowTypeParam(node) {
  9746. var _node$extra;
  9747. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9748. this.raise(TSErrors.ReservedArrowTypeParam, {
  9749. at: node
  9750. });
  9751. }
  9752. }
  9753. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9754. if (!this.hasPlugin("jsx") && this.match(47)) {
  9755. return this.tsParseTypeAssertion();
  9756. } else {
  9757. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9758. }
  9759. }
  9760. parseArrow(node) {
  9761. if (this.match(14)) {
  9762. const result = this.tryParse(abort => {
  9763. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9764. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9765. return returnType;
  9766. });
  9767. if (result.aborted) return;
  9768. if (!result.thrown) {
  9769. if (result.error) this.state = result.failState;
  9770. node.returnType = result.node;
  9771. }
  9772. }
  9773. return super.parseArrow(node);
  9774. }
  9775. parseAssignableListItemTypes(param, flags) {
  9776. if (!(flags & 2)) return param;
  9777. if (this.eat(17)) {
  9778. param.optional = true;
  9779. }
  9780. const type = this.tsTryParseTypeAnnotation();
  9781. if (type) param.typeAnnotation = type;
  9782. this.resetEndLocation(param);
  9783. return param;
  9784. }
  9785. isAssignable(node, isBinding) {
  9786. switch (node.type) {
  9787. case "TSTypeCastExpression":
  9788. return this.isAssignable(node.expression, isBinding);
  9789. case "TSParameterProperty":
  9790. return true;
  9791. default:
  9792. return super.isAssignable(node, isBinding);
  9793. }
  9794. }
  9795. toAssignable(node, isLHS = false) {
  9796. switch (node.type) {
  9797. case "ParenthesizedExpression":
  9798. this.toAssignableParenthesizedExpression(node, isLHS);
  9799. break;
  9800. case "TSAsExpression":
  9801. case "TSSatisfiesExpression":
  9802. case "TSNonNullExpression":
  9803. case "TSTypeAssertion":
  9804. if (isLHS) {
  9805. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
  9806. at: node
  9807. });
  9808. } else {
  9809. this.raise(TSErrors.UnexpectedTypeCastInParameter, {
  9810. at: node
  9811. });
  9812. }
  9813. this.toAssignable(node.expression, isLHS);
  9814. break;
  9815. case "AssignmentExpression":
  9816. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9817. node.left = this.typeCastToParameter(node.left);
  9818. }
  9819. default:
  9820. super.toAssignable(node, isLHS);
  9821. }
  9822. }
  9823. toAssignableParenthesizedExpression(node, isLHS) {
  9824. switch (node.expression.type) {
  9825. case "TSAsExpression":
  9826. case "TSSatisfiesExpression":
  9827. case "TSNonNullExpression":
  9828. case "TSTypeAssertion":
  9829. case "ParenthesizedExpression":
  9830. this.toAssignable(node.expression, isLHS);
  9831. break;
  9832. default:
  9833. super.toAssignable(node, isLHS);
  9834. }
  9835. }
  9836. checkToRestConversion(node, allowPattern) {
  9837. switch (node.type) {
  9838. case "TSAsExpression":
  9839. case "TSSatisfiesExpression":
  9840. case "TSTypeAssertion":
  9841. case "TSNonNullExpression":
  9842. this.checkToRestConversion(node.expression, false);
  9843. break;
  9844. default:
  9845. super.checkToRestConversion(node, allowPattern);
  9846. }
  9847. }
  9848. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9849. return getOwn({
  9850. TSTypeCastExpression: true,
  9851. TSParameterProperty: "parameter",
  9852. TSNonNullExpression: "expression",
  9853. TSAsExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
  9854. TSSatisfiesExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
  9855. TSTypeAssertion: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true]
  9856. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9857. }
  9858. parseBindingAtom() {
  9859. switch (this.state.type) {
  9860. case 78:
  9861. return this.parseIdentifier(true);
  9862. default:
  9863. return super.parseBindingAtom();
  9864. }
  9865. }
  9866. parseMaybeDecoratorArguments(expr) {
  9867. if (this.match(47) || this.match(51)) {
  9868. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9869. if (this.match(10)) {
  9870. const call = super.parseMaybeDecoratorArguments(expr);
  9871. call.typeParameters = typeArguments;
  9872. return call;
  9873. }
  9874. this.unexpected(null, 10);
  9875. }
  9876. return super.parseMaybeDecoratorArguments(expr);
  9877. }
  9878. checkCommaAfterRest(close) {
  9879. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9880. this.next();
  9881. return false;
  9882. } else {
  9883. return super.checkCommaAfterRest(close);
  9884. }
  9885. }
  9886. isClassMethod() {
  9887. return this.match(47) || super.isClassMethod();
  9888. }
  9889. isClassProperty() {
  9890. return this.match(35) || this.match(14) || super.isClassProperty();
  9891. }
  9892. parseMaybeDefault(startLoc, left) {
  9893. const node = super.parseMaybeDefault(startLoc, left);
  9894. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9895. this.raise(TSErrors.TypeAnnotationAfterAssign, {
  9896. at: node.typeAnnotation
  9897. });
  9898. }
  9899. return node;
  9900. }
  9901. getTokenFromCode(code) {
  9902. if (this.state.inType) {
  9903. if (code === 62) {
  9904. this.finishOp(48, 1);
  9905. return;
  9906. }
  9907. if (code === 60) {
  9908. this.finishOp(47, 1);
  9909. return;
  9910. }
  9911. }
  9912. super.getTokenFromCode(code);
  9913. }
  9914. reScan_lt_gt() {
  9915. const {
  9916. type
  9917. } = this.state;
  9918. if (type === 47) {
  9919. this.state.pos -= 1;
  9920. this.readToken_lt();
  9921. } else if (type === 48) {
  9922. this.state.pos -= 1;
  9923. this.readToken_gt();
  9924. }
  9925. }
  9926. reScan_lt() {
  9927. const {
  9928. type
  9929. } = this.state;
  9930. if (type === 51) {
  9931. this.state.pos -= 2;
  9932. this.finishOp(47, 1);
  9933. return 47;
  9934. }
  9935. return type;
  9936. }
  9937. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9938. for (let i = 0; i < exprList.length; i++) {
  9939. const expr = exprList[i];
  9940. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9941. exprList[i] = this.typeCastToParameter(expr);
  9942. }
  9943. }
  9944. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9945. }
  9946. typeCastToParameter(node) {
  9947. node.expression.typeAnnotation = node.typeAnnotation;
  9948. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9949. return node.expression;
  9950. }
  9951. shouldParseArrow(params) {
  9952. if (this.match(14)) {
  9953. return params.every(expr => this.isAssignable(expr, true));
  9954. }
  9955. return super.shouldParseArrow(params);
  9956. }
  9957. shouldParseAsyncArrow() {
  9958. return this.match(14) || super.shouldParseAsyncArrow();
  9959. }
  9960. canHaveLeadingDecorator() {
  9961. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9962. }
  9963. jsxParseOpeningElementAfterName(node) {
  9964. if (this.match(47) || this.match(51)) {
  9965. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9966. if (typeArguments) node.typeParameters = typeArguments;
  9967. }
  9968. return super.jsxParseOpeningElementAfterName(node);
  9969. }
  9970. getGetterSetterExpectedParamCount(method) {
  9971. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9972. const params = this.getObjectOrClassMethodParams(method);
  9973. const firstParam = params[0];
  9974. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9975. return hasContextParam ? baseCount + 1 : baseCount;
  9976. }
  9977. parseCatchClauseParam() {
  9978. const param = super.parseCatchClauseParam();
  9979. const type = this.tsTryParseTypeAnnotation();
  9980. if (type) {
  9981. param.typeAnnotation = type;
  9982. this.resetEndLocation(param);
  9983. }
  9984. return param;
  9985. }
  9986. tsInAmbientContext(cb) {
  9987. const oldIsAmbientContext = this.state.isAmbientContext;
  9988. this.state.isAmbientContext = true;
  9989. try {
  9990. return cb();
  9991. } finally {
  9992. this.state.isAmbientContext = oldIsAmbientContext;
  9993. }
  9994. }
  9995. parseClass(node, isStatement, optionalId) {
  9996. const oldInAbstractClass = this.state.inAbstractClass;
  9997. this.state.inAbstractClass = !!node.abstract;
  9998. try {
  9999. return super.parseClass(node, isStatement, optionalId);
  10000. } finally {
  10001. this.state.inAbstractClass = oldInAbstractClass;
  10002. }
  10003. }
  10004. tsParseAbstractDeclaration(node, decorators) {
  10005. if (this.match(80)) {
  10006. node.abstract = true;
  10007. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  10008. } else if (this.isContextual(127)) {
  10009. if (!this.hasFollowingLineBreak()) {
  10010. node.abstract = true;
  10011. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
  10012. at: node
  10013. });
  10014. return this.tsParseInterfaceDeclaration(node);
  10015. }
  10016. } else {
  10017. this.unexpected(null, 80);
  10018. }
  10019. }
  10020. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  10021. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  10022. if (method.abstract) {
  10023. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  10024. if (hasBody) {
  10025. const {
  10026. key
  10027. } = method;
  10028. this.raise(TSErrors.AbstractMethodHasImplementation, {
  10029. at: method,
  10030. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  10031. });
  10032. }
  10033. }
  10034. return method;
  10035. }
  10036. tsParseTypeParameterName() {
  10037. const typeName = this.parseIdentifier();
  10038. return typeName.name;
  10039. }
  10040. shouldParseAsAmbientContext() {
  10041. return !!this.getPluginOption("typescript", "dts");
  10042. }
  10043. parse() {
  10044. if (this.shouldParseAsAmbientContext()) {
  10045. this.state.isAmbientContext = true;
  10046. }
  10047. return super.parse();
  10048. }
  10049. getExpression() {
  10050. if (this.shouldParseAsAmbientContext()) {
  10051. this.state.isAmbientContext = true;
  10052. }
  10053. return super.getExpression();
  10054. }
  10055. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10056. if (!isString && isMaybeTypeOnly) {
  10057. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10058. return this.finishNode(node, "ExportSpecifier");
  10059. }
  10060. node.exportKind = "value";
  10061. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10062. }
  10063. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10064. if (!importedIsString && isMaybeTypeOnly) {
  10065. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10066. return this.finishNode(specifier, "ImportSpecifier");
  10067. }
  10068. specifier.importKind = "value";
  10069. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
  10070. }
  10071. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10072. const leftOfAsKey = isImport ? "imported" : "local";
  10073. const rightOfAsKey = isImport ? "local" : "exported";
  10074. let leftOfAs = node[leftOfAsKey];
  10075. let rightOfAs;
  10076. let hasTypeSpecifier = false;
  10077. let canParseAsKeyword = true;
  10078. const loc = leftOfAs.loc.start;
  10079. if (this.isContextual(93)) {
  10080. const firstAs = this.parseIdentifier();
  10081. if (this.isContextual(93)) {
  10082. const secondAs = this.parseIdentifier();
  10083. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10084. hasTypeSpecifier = true;
  10085. leftOfAs = firstAs;
  10086. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10087. canParseAsKeyword = false;
  10088. } else {
  10089. rightOfAs = secondAs;
  10090. canParseAsKeyword = false;
  10091. }
  10092. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10093. canParseAsKeyword = false;
  10094. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10095. } else {
  10096. hasTypeSpecifier = true;
  10097. leftOfAs = firstAs;
  10098. }
  10099. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10100. hasTypeSpecifier = true;
  10101. if (isImport) {
  10102. leftOfAs = this.parseIdentifier(true);
  10103. if (!this.isContextual(93)) {
  10104. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10105. }
  10106. } else {
  10107. leftOfAs = this.parseModuleExportName();
  10108. }
  10109. }
  10110. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10111. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
  10112. at: loc
  10113. });
  10114. }
  10115. node[leftOfAsKey] = leftOfAs;
  10116. node[rightOfAsKey] = rightOfAs;
  10117. const kindKey = isImport ? "importKind" : "exportKind";
  10118. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10119. if (canParseAsKeyword && this.eatContextual(93)) {
  10120. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10121. }
  10122. if (!node[rightOfAsKey]) {
  10123. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  10124. }
  10125. if (isImport) {
  10126. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
  10127. }
  10128. }
  10129. };
  10130. function isPossiblyLiteralEnum(expression) {
  10131. if (expression.type !== "MemberExpression") return false;
  10132. const {
  10133. computed,
  10134. property
  10135. } = expression;
  10136. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10137. return false;
  10138. }
  10139. return isUncomputedMemberExpressionChain(expression.object);
  10140. }
  10141. function isValidAmbientConstInitializer(expression, estree) {
  10142. var _expression$extra;
  10143. const {
  10144. type
  10145. } = expression;
  10146. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10147. return false;
  10148. }
  10149. if (estree) {
  10150. if (type === "Literal") {
  10151. const {
  10152. value
  10153. } = expression;
  10154. if (typeof value === "string" || typeof value === "boolean") {
  10155. return true;
  10156. }
  10157. }
  10158. } else {
  10159. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10160. return true;
  10161. }
  10162. }
  10163. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10164. return true;
  10165. }
  10166. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10167. return true;
  10168. }
  10169. if (isPossiblyLiteralEnum(expression)) {
  10170. return true;
  10171. }
  10172. return false;
  10173. }
  10174. function isNumber(expression, estree) {
  10175. if (estree) {
  10176. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10177. } else {
  10178. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10179. }
  10180. }
  10181. function isNegativeNumber(expression, estree) {
  10182. if (expression.type === "UnaryExpression") {
  10183. const {
  10184. operator,
  10185. argument
  10186. } = expression;
  10187. if (operator === "-" && isNumber(argument, estree)) {
  10188. return true;
  10189. }
  10190. }
  10191. return false;
  10192. }
  10193. function isUncomputedMemberExpressionChain(expression) {
  10194. if (expression.type === "Identifier") return true;
  10195. if (expression.type !== "MemberExpression") return false;
  10196. if (expression.computed) return false;
  10197. return isUncomputedMemberExpressionChain(expression.object);
  10198. }
  10199. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10200. ClassNameIsRequired: "A class name is required.",
  10201. UnexpectedSpace: "Unexpected space in placeholder."
  10202. });
  10203. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10204. parsePlaceholder(expectedNode) {
  10205. if (this.match(142)) {
  10206. const node = this.startNode();
  10207. this.next();
  10208. this.assertNoSpace();
  10209. node.name = super.parseIdentifier(true);
  10210. this.assertNoSpace();
  10211. this.expect(142);
  10212. return this.finishPlaceholder(node, expectedNode);
  10213. }
  10214. }
  10215. finishPlaceholder(node, expectedNode) {
  10216. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  10217. node.expectedNode = expectedNode;
  10218. return isFinished ? node : this.finishNode(node, "Placeholder");
  10219. }
  10220. getTokenFromCode(code) {
  10221. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10222. this.finishOp(142, 2);
  10223. } else {
  10224. super.getTokenFromCode(code);
  10225. }
  10226. }
  10227. parseExprAtom(refExpressionErrors) {
  10228. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10229. }
  10230. parseIdentifier(liberal) {
  10231. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10232. }
  10233. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10234. if (word !== undefined) {
  10235. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10236. }
  10237. }
  10238. parseBindingAtom() {
  10239. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10240. }
  10241. isValidLVal(type, isParenthesized, binding) {
  10242. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10243. }
  10244. toAssignable(node, isLHS) {
  10245. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10246. node.expectedNode = "Pattern";
  10247. } else {
  10248. super.toAssignable(node, isLHS);
  10249. }
  10250. }
  10251. chStartsBindingIdentifier(ch, pos) {
  10252. if (super.chStartsBindingIdentifier(ch, pos)) {
  10253. return true;
  10254. }
  10255. const nextToken = this.lookahead();
  10256. if (nextToken.type === 142) {
  10257. return true;
  10258. }
  10259. return false;
  10260. }
  10261. verifyBreakContinue(node, isBreak) {
  10262. if (node.label && node.label.type === "Placeholder") return;
  10263. super.verifyBreakContinue(node, isBreak);
  10264. }
  10265. parseExpressionStatement(node, expr) {
  10266. if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) {
  10267. return super.parseExpressionStatement(node, expr);
  10268. }
  10269. if (this.match(14)) {
  10270. const stmt = node;
  10271. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10272. this.next();
  10273. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10274. return this.finishNode(stmt, "LabeledStatement");
  10275. }
  10276. this.semicolon();
  10277. node.name = expr.name;
  10278. return this.finishPlaceholder(node, "Statement");
  10279. }
  10280. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10281. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10282. }
  10283. parseFunctionId(requireId) {
  10284. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10285. }
  10286. parseClass(node, isStatement, optionalId) {
  10287. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10288. this.next();
  10289. const oldStrict = this.state.strict;
  10290. const placeholder = this.parsePlaceholder("Identifier");
  10291. if (placeholder) {
  10292. if (this.match(81) || this.match(142) || this.match(5)) {
  10293. node.id = placeholder;
  10294. } else if (optionalId || !isStatement) {
  10295. node.id = null;
  10296. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10297. return this.finishNode(node, type);
  10298. } else {
  10299. throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
  10300. at: this.state.startLoc
  10301. });
  10302. }
  10303. } else {
  10304. this.parseClassId(node, isStatement, optionalId);
  10305. }
  10306. super.parseClassSuper(node);
  10307. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10308. return this.finishNode(node, type);
  10309. }
  10310. parseExport(node, decorators) {
  10311. const placeholder = this.parsePlaceholder("Identifier");
  10312. if (!placeholder) return super.parseExport(node, decorators);
  10313. if (!this.isContextual(97) && !this.match(12)) {
  10314. node.specifiers = [];
  10315. node.source = null;
  10316. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10317. return this.finishNode(node, "ExportNamedDeclaration");
  10318. }
  10319. this.expectPlugin("exportDefaultFrom");
  10320. const specifier = this.startNode();
  10321. specifier.exported = placeholder;
  10322. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10323. return super.parseExport(node, decorators);
  10324. }
  10325. isExportDefaultSpecifier() {
  10326. if (this.match(65)) {
  10327. const next = this.nextTokenStart();
  10328. if (this.isUnparsedContextual(next, "from")) {
  10329. if (this.input.startsWith(tokenLabelName(142), this.nextTokenStartSince(next + 4))) {
  10330. return true;
  10331. }
  10332. }
  10333. }
  10334. return super.isExportDefaultSpecifier();
  10335. }
  10336. maybeParseExportDefaultSpecifier(node) {
  10337. if (node.specifiers && node.specifiers.length > 0) {
  10338. return true;
  10339. }
  10340. return super.maybeParseExportDefaultSpecifier(node);
  10341. }
  10342. checkExport(node) {
  10343. const {
  10344. specifiers
  10345. } = node;
  10346. if (specifiers != null && specifiers.length) {
  10347. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10348. }
  10349. super.checkExport(node);
  10350. node.specifiers = specifiers;
  10351. }
  10352. parseImport(node) {
  10353. const placeholder = this.parsePlaceholder("Identifier");
  10354. if (!placeholder) return super.parseImport(node);
  10355. node.specifiers = [];
  10356. if (!this.isContextual(97) && !this.match(12)) {
  10357. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10358. this.semicolon();
  10359. return this.finishNode(node, "ImportDeclaration");
  10360. }
  10361. const specifier = this.startNodeAtNode(placeholder);
  10362. specifier.local = placeholder;
  10363. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10364. if (this.eat(12)) {
  10365. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10366. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10367. }
  10368. this.expectContextual(97);
  10369. node.source = this.parseImportSource();
  10370. this.semicolon();
  10371. return this.finishNode(node, "ImportDeclaration");
  10372. }
  10373. parseImportSource() {
  10374. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10375. }
  10376. assertNoSpace() {
  10377. if (this.state.start > this.state.lastTokEndLoc.index) {
  10378. this.raise(PlaceholderErrors.UnexpectedSpace, {
  10379. at: this.state.lastTokEndLoc
  10380. });
  10381. }
  10382. }
  10383. };
  10384. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10385. parseV8Intrinsic() {
  10386. if (this.match(54)) {
  10387. const v8IntrinsicStartLoc = this.state.startLoc;
  10388. const node = this.startNode();
  10389. this.next();
  10390. if (tokenIsIdentifier(this.state.type)) {
  10391. const name = this.parseIdentifierName();
  10392. const identifier = this.createIdentifier(node, name);
  10393. identifier.type = "V8IntrinsicIdentifier";
  10394. if (this.match(10)) {
  10395. return identifier;
  10396. }
  10397. }
  10398. this.unexpected(v8IntrinsicStartLoc);
  10399. }
  10400. }
  10401. parseExprAtom(refExpressionErrors) {
  10402. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10403. }
  10404. };
  10405. function hasPlugin(plugins, expectedConfig) {
  10406. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  10407. const expectedKeys = Object.keys(expectedOptions);
  10408. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  10409. return plugins.some(p => {
  10410. if (typeof p === "string") {
  10411. return expectedOptionsIsEmpty && p === expectedName;
  10412. } else {
  10413. const [pluginName, pluginOptions] = p;
  10414. if (pluginName !== expectedName) {
  10415. return false;
  10416. }
  10417. for (const key of expectedKeys) {
  10418. if (pluginOptions[key] !== expectedOptions[key]) {
  10419. return false;
  10420. }
  10421. }
  10422. return true;
  10423. }
  10424. });
  10425. }
  10426. function getPluginOption(plugins, name, option) {
  10427. const plugin = plugins.find(plugin => {
  10428. if (Array.isArray(plugin)) {
  10429. return plugin[0] === name;
  10430. } else {
  10431. return plugin === name;
  10432. }
  10433. });
  10434. if (plugin && Array.isArray(plugin) && plugin.length > 1) {
  10435. return plugin[1][option];
  10436. }
  10437. return null;
  10438. }
  10439. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10440. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10441. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10442. function validatePlugins(plugins) {
  10443. if (hasPlugin(plugins, "decorators")) {
  10444. if (hasPlugin(plugins, "decorators-legacy")) {
  10445. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10446. }
  10447. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  10448. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10449. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10450. }
  10451. const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
  10452. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10453. throw new Error("'allowCallParenthesized' must be a boolean.");
  10454. }
  10455. }
  10456. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  10457. throw new Error("Cannot combine flow and typescript plugins.");
  10458. }
  10459. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  10460. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10461. }
  10462. if (hasPlugin(plugins, "pipelineOperator")) {
  10463. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  10464. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10465. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10466. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10467. }
  10468. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  10469. syntaxType: "hash"
  10470. }]);
  10471. if (proposal === "hack") {
  10472. if (hasPlugin(plugins, "placeholders")) {
  10473. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10474. }
  10475. if (hasPlugin(plugins, "v8intrinsic")) {
  10476. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10477. }
  10478. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  10479. if (!TOPIC_TOKENS.includes(topicToken)) {
  10480. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10481. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10482. }
  10483. if (topicToken === "#" && tupleSyntaxIsHash) {
  10484. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10485. }
  10486. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  10487. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10488. }
  10489. }
  10490. if (hasPlugin(plugins, "moduleAttributes")) {
  10491. {
  10492. if (hasPlugin(plugins, "importAssertions")) {
  10493. throw new Error("Cannot combine importAssertions and moduleAttributes plugins.");
  10494. }
  10495. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  10496. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10497. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10498. }
  10499. }
  10500. }
  10501. if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  10502. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10503. }
  10504. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  10505. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10506. error.missingPlugins = "doExpressions";
  10507. throw error;
  10508. }
  10509. }
  10510. const mixinPlugins = {
  10511. estree,
  10512. jsx,
  10513. flow,
  10514. typescript,
  10515. v8intrinsic,
  10516. placeholders
  10517. };
  10518. const mixinPluginNames = Object.keys(mixinPlugins);
  10519. class ExpressionParser extends LValParser {
  10520. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10521. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10522. return;
  10523. }
  10524. const key = prop.key;
  10525. const name = key.type === "Identifier" ? key.name : key.value;
  10526. if (name === "__proto__") {
  10527. if (isRecord) {
  10528. this.raise(Errors.RecordNoProto, {
  10529. at: key
  10530. });
  10531. return;
  10532. }
  10533. if (protoRef.used) {
  10534. if (refExpressionErrors) {
  10535. if (refExpressionErrors.doubleProtoLoc === null) {
  10536. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10537. }
  10538. } else {
  10539. this.raise(Errors.DuplicateProto, {
  10540. at: key
  10541. });
  10542. }
  10543. }
  10544. protoRef.used = true;
  10545. }
  10546. }
  10547. shouldExitDescending(expr, potentialArrowAt) {
  10548. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  10549. }
  10550. getExpression() {
  10551. this.enterInitialScopes();
  10552. this.nextToken();
  10553. const expr = this.parseExpression();
  10554. if (!this.match(137)) {
  10555. this.unexpected();
  10556. }
  10557. this.finalizeRemainingComments();
  10558. expr.comments = this.state.comments;
  10559. expr.errors = this.state.errors;
  10560. if (this.options.tokens) {
  10561. expr.tokens = this.tokens;
  10562. }
  10563. return expr;
  10564. }
  10565. parseExpression(disallowIn, refExpressionErrors) {
  10566. if (disallowIn) {
  10567. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10568. }
  10569. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10570. }
  10571. parseExpressionBase(refExpressionErrors) {
  10572. const startLoc = this.state.startLoc;
  10573. const expr = this.parseMaybeAssign(refExpressionErrors);
  10574. if (this.match(12)) {
  10575. const node = this.startNodeAt(startLoc);
  10576. node.expressions = [expr];
  10577. while (this.eat(12)) {
  10578. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10579. }
  10580. this.toReferencedList(node.expressions);
  10581. return this.finishNode(node, "SequenceExpression");
  10582. }
  10583. return expr;
  10584. }
  10585. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10586. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10587. }
  10588. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10589. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10590. }
  10591. setOptionalParametersError(refExpressionErrors, resultError) {
  10592. var _resultError$loc;
  10593. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10594. }
  10595. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10596. const startLoc = this.state.startLoc;
  10597. if (this.isContextual(106)) {
  10598. if (this.prodParam.hasYield) {
  10599. let left = this.parseYield();
  10600. if (afterLeftParse) {
  10601. left = afterLeftParse.call(this, left, startLoc);
  10602. }
  10603. return left;
  10604. }
  10605. }
  10606. let ownExpressionErrors;
  10607. if (refExpressionErrors) {
  10608. ownExpressionErrors = false;
  10609. } else {
  10610. refExpressionErrors = new ExpressionErrors();
  10611. ownExpressionErrors = true;
  10612. }
  10613. const {
  10614. type
  10615. } = this.state;
  10616. if (type === 10 || tokenIsIdentifier(type)) {
  10617. this.state.potentialArrowAt = this.state.start;
  10618. }
  10619. let left = this.parseMaybeConditional(refExpressionErrors);
  10620. if (afterLeftParse) {
  10621. left = afterLeftParse.call(this, left, startLoc);
  10622. }
  10623. if (tokenIsAssignment(this.state.type)) {
  10624. const node = this.startNodeAt(startLoc);
  10625. const operator = this.state.value;
  10626. node.operator = operator;
  10627. if (this.match(29)) {
  10628. this.toAssignable(left, true);
  10629. node.left = left;
  10630. const startIndex = startLoc.index;
  10631. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10632. refExpressionErrors.doubleProtoLoc = null;
  10633. }
  10634. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10635. refExpressionErrors.shorthandAssignLoc = null;
  10636. }
  10637. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10638. this.checkDestructuringPrivate(refExpressionErrors);
  10639. refExpressionErrors.privateKeyLoc = null;
  10640. }
  10641. } else {
  10642. node.left = left;
  10643. }
  10644. this.next();
  10645. node.right = this.parseMaybeAssign();
  10646. this.checkLVal(left, {
  10647. in: this.finishNode(node, "AssignmentExpression")
  10648. });
  10649. return node;
  10650. } else if (ownExpressionErrors) {
  10651. this.checkExpressionErrors(refExpressionErrors, true);
  10652. }
  10653. return left;
  10654. }
  10655. parseMaybeConditional(refExpressionErrors) {
  10656. const startLoc = this.state.startLoc;
  10657. const potentialArrowAt = this.state.potentialArrowAt;
  10658. const expr = this.parseExprOps(refExpressionErrors);
  10659. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10660. return expr;
  10661. }
  10662. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10663. }
  10664. parseConditional(expr, startLoc, refExpressionErrors) {
  10665. if (this.eat(17)) {
  10666. const node = this.startNodeAt(startLoc);
  10667. node.test = expr;
  10668. node.consequent = this.parseMaybeAssignAllowIn();
  10669. this.expect(14);
  10670. node.alternate = this.parseMaybeAssign();
  10671. return this.finishNode(node, "ConditionalExpression");
  10672. }
  10673. return expr;
  10674. }
  10675. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10676. return this.match(136) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10677. }
  10678. parseExprOps(refExpressionErrors) {
  10679. const startLoc = this.state.startLoc;
  10680. const potentialArrowAt = this.state.potentialArrowAt;
  10681. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10682. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10683. return expr;
  10684. }
  10685. return this.parseExprOp(expr, startLoc, -1);
  10686. }
  10687. parseExprOp(left, leftStartLoc, minPrec) {
  10688. if (this.isPrivateName(left)) {
  10689. const value = this.getPrivateNameSV(left);
  10690. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10691. this.raise(Errors.PrivateInExpectedIn, {
  10692. at: left,
  10693. identifierName: value
  10694. });
  10695. }
  10696. this.classScope.usePrivateName(value, left.loc.start);
  10697. }
  10698. const op = this.state.type;
  10699. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10700. let prec = tokenOperatorPrecedence(op);
  10701. if (prec > minPrec) {
  10702. if (op === 39) {
  10703. this.expectPlugin("pipelineOperator");
  10704. if (this.state.inFSharpPipelineDirectBody) {
  10705. return left;
  10706. }
  10707. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10708. }
  10709. const node = this.startNodeAt(leftStartLoc);
  10710. node.left = left;
  10711. node.operator = this.state.value;
  10712. const logical = op === 41 || op === 42;
  10713. const coalesce = op === 40;
  10714. if (coalesce) {
  10715. prec = tokenOperatorPrecedence(42);
  10716. }
  10717. this.next();
  10718. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10719. proposal: "minimal"
  10720. }])) {
  10721. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10722. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
  10723. at: this.state.startLoc
  10724. });
  10725. }
  10726. }
  10727. node.right = this.parseExprOpRightExpr(op, prec);
  10728. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10729. const nextOp = this.state.type;
  10730. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10731. throw this.raise(Errors.MixingCoalesceWithLogical, {
  10732. at: this.state.startLoc
  10733. });
  10734. }
  10735. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10736. }
  10737. }
  10738. return left;
  10739. }
  10740. parseExprOpRightExpr(op, prec) {
  10741. const startLoc = this.state.startLoc;
  10742. switch (op) {
  10743. case 39:
  10744. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10745. case "hack":
  10746. return this.withTopicBindingContext(() => {
  10747. return this.parseHackPipeBody();
  10748. });
  10749. case "smart":
  10750. return this.withTopicBindingContext(() => {
  10751. if (this.prodParam.hasYield && this.isContextual(106)) {
  10752. throw this.raise(Errors.PipeBodyIsTighter, {
  10753. at: this.state.startLoc
  10754. });
  10755. }
  10756. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10757. });
  10758. case "fsharp":
  10759. return this.withSoloAwaitPermittingContext(() => {
  10760. return this.parseFSharpPipelineBody(prec);
  10761. });
  10762. }
  10763. default:
  10764. return this.parseExprOpBaseRightExpr(op, prec);
  10765. }
  10766. }
  10767. parseExprOpBaseRightExpr(op, prec) {
  10768. const startLoc = this.state.startLoc;
  10769. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10770. }
  10771. parseHackPipeBody() {
  10772. var _body$extra;
  10773. const {
  10774. startLoc
  10775. } = this.state;
  10776. const body = this.parseMaybeAssign();
  10777. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10778. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10779. this.raise(Errors.PipeUnparenthesizedBody, {
  10780. at: startLoc,
  10781. type: body.type
  10782. });
  10783. }
  10784. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10785. this.raise(Errors.PipeTopicUnused, {
  10786. at: startLoc
  10787. });
  10788. }
  10789. return body;
  10790. }
  10791. checkExponentialAfterUnary(node) {
  10792. if (this.match(57)) {
  10793. this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
  10794. at: node.argument
  10795. });
  10796. }
  10797. }
  10798. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10799. const startLoc = this.state.startLoc;
  10800. const isAwait = this.isContextual(96);
  10801. if (isAwait && this.isAwaitAllowed()) {
  10802. this.next();
  10803. const expr = this.parseAwait(startLoc);
  10804. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10805. return expr;
  10806. }
  10807. const update = this.match(34);
  10808. const node = this.startNode();
  10809. if (tokenIsPrefix(this.state.type)) {
  10810. node.operator = this.state.value;
  10811. node.prefix = true;
  10812. if (this.match(72)) {
  10813. this.expectPlugin("throwExpressions");
  10814. }
  10815. const isDelete = this.match(89);
  10816. this.next();
  10817. node.argument = this.parseMaybeUnary(null, true);
  10818. this.checkExpressionErrors(refExpressionErrors, true);
  10819. if (this.state.strict && isDelete) {
  10820. const arg = node.argument;
  10821. if (arg.type === "Identifier") {
  10822. this.raise(Errors.StrictDelete, {
  10823. at: node
  10824. });
  10825. } else if (this.hasPropertyAsPrivateName(arg)) {
  10826. this.raise(Errors.DeletePrivateField, {
  10827. at: node
  10828. });
  10829. }
  10830. }
  10831. if (!update) {
  10832. if (!sawUnary) {
  10833. this.checkExponentialAfterUnary(node);
  10834. }
  10835. return this.finishNode(node, "UnaryExpression");
  10836. }
  10837. }
  10838. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10839. if (isAwait) {
  10840. const {
  10841. type
  10842. } = this.state;
  10843. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10844. if (startsExpr && !this.isAmbiguousAwait()) {
  10845. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
  10846. at: startLoc
  10847. });
  10848. return this.parseAwait(startLoc);
  10849. }
  10850. }
  10851. return expr;
  10852. }
  10853. parseUpdate(node, update, refExpressionErrors) {
  10854. if (update) {
  10855. const updateExpressionNode = node;
  10856. this.checkLVal(updateExpressionNode.argument, {
  10857. in: this.finishNode(updateExpressionNode, "UpdateExpression")
  10858. });
  10859. return node;
  10860. }
  10861. const startLoc = this.state.startLoc;
  10862. let expr = this.parseExprSubscripts(refExpressionErrors);
  10863. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10864. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10865. const node = this.startNodeAt(startLoc);
  10866. node.operator = this.state.value;
  10867. node.prefix = false;
  10868. node.argument = expr;
  10869. this.next();
  10870. this.checkLVal(expr, {
  10871. in: expr = this.finishNode(node, "UpdateExpression")
  10872. });
  10873. }
  10874. return expr;
  10875. }
  10876. parseExprSubscripts(refExpressionErrors) {
  10877. const startLoc = this.state.startLoc;
  10878. const potentialArrowAt = this.state.potentialArrowAt;
  10879. const expr = this.parseExprAtom(refExpressionErrors);
  10880. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10881. return expr;
  10882. }
  10883. return this.parseSubscripts(expr, startLoc);
  10884. }
  10885. parseSubscripts(base, startLoc, noCalls) {
  10886. const state = {
  10887. optionalChainMember: false,
  10888. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10889. stop: false
  10890. };
  10891. do {
  10892. base = this.parseSubscript(base, startLoc, noCalls, state);
  10893. state.maybeAsyncArrow = false;
  10894. } while (!state.stop);
  10895. return base;
  10896. }
  10897. parseSubscript(base, startLoc, noCalls, state) {
  10898. const {
  10899. type
  10900. } = this.state;
  10901. if (!noCalls && type === 15) {
  10902. return this.parseBind(base, startLoc, noCalls, state);
  10903. } else if (tokenIsTemplate(type)) {
  10904. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10905. }
  10906. let optional = false;
  10907. if (type === 18) {
  10908. if (noCalls) {
  10909. this.raise(Errors.OptionalChainingNoNew, {
  10910. at: this.state.startLoc
  10911. });
  10912. if (this.lookaheadCharCode() === 40) {
  10913. state.stop = true;
  10914. return base;
  10915. }
  10916. }
  10917. state.optionalChainMember = optional = true;
  10918. this.next();
  10919. }
  10920. if (!noCalls && this.match(10)) {
  10921. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10922. } else {
  10923. const computed = this.eat(0);
  10924. if (computed || optional || this.eat(16)) {
  10925. return this.parseMember(base, startLoc, state, computed, optional);
  10926. } else {
  10927. state.stop = true;
  10928. return base;
  10929. }
  10930. }
  10931. }
  10932. parseMember(base, startLoc, state, computed, optional) {
  10933. const node = this.startNodeAt(startLoc);
  10934. node.object = base;
  10935. node.computed = computed;
  10936. if (computed) {
  10937. node.property = this.parseExpression();
  10938. this.expect(3);
  10939. } else if (this.match(136)) {
  10940. if (base.type === "Super") {
  10941. this.raise(Errors.SuperPrivateField, {
  10942. at: startLoc
  10943. });
  10944. }
  10945. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10946. node.property = this.parsePrivateName();
  10947. } else {
  10948. node.property = this.parseIdentifier(true);
  10949. }
  10950. if (state.optionalChainMember) {
  10951. node.optional = optional;
  10952. return this.finishNode(node, "OptionalMemberExpression");
  10953. } else {
  10954. return this.finishNode(node, "MemberExpression");
  10955. }
  10956. }
  10957. parseBind(base, startLoc, noCalls, state) {
  10958. const node = this.startNodeAt(startLoc);
  10959. node.object = base;
  10960. this.next();
  10961. node.callee = this.parseNoCallExpr();
  10962. state.stop = true;
  10963. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10964. }
  10965. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10966. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10967. let refExpressionErrors = null;
  10968. this.state.maybeInArrowParameters = true;
  10969. this.next();
  10970. const node = this.startNodeAt(startLoc);
  10971. node.callee = base;
  10972. const {
  10973. maybeAsyncArrow,
  10974. optionalChainMember
  10975. } = state;
  10976. if (maybeAsyncArrow) {
  10977. this.expressionScope.enter(newAsyncArrowScope());
  10978. refExpressionErrors = new ExpressionErrors();
  10979. }
  10980. if (optionalChainMember) {
  10981. node.optional = optional;
  10982. }
  10983. if (optional) {
  10984. node.arguments = this.parseCallExpressionArguments(11);
  10985. } else {
  10986. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  10987. }
  10988. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10989. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10990. state.stop = true;
  10991. this.checkDestructuringPrivate(refExpressionErrors);
  10992. this.expressionScope.validateAsPattern();
  10993. this.expressionScope.exit();
  10994. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  10995. } else {
  10996. if (maybeAsyncArrow) {
  10997. this.checkExpressionErrors(refExpressionErrors, true);
  10998. this.expressionScope.exit();
  10999. }
  11000. this.toReferencedArguments(finishedNode);
  11001. }
  11002. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11003. return finishedNode;
  11004. }
  11005. toReferencedArguments(node, isParenthesizedExpr) {
  11006. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11007. }
  11008. parseTaggedTemplateExpression(base, startLoc, state) {
  11009. const node = this.startNodeAt(startLoc);
  11010. node.tag = base;
  11011. node.quasi = this.parseTemplate(true);
  11012. if (state.optionalChainMember) {
  11013. this.raise(Errors.OptionalChainingNoTemplate, {
  11014. at: startLoc
  11015. });
  11016. }
  11017. return this.finishNode(node, "TaggedTemplateExpression");
  11018. }
  11019. atPossibleAsyncArrow(base) {
  11020. 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;
  11021. }
  11022. finishCallExpression(node, optional) {
  11023. if (node.callee.type === "Import") {
  11024. if (node.arguments.length === 2) {
  11025. {
  11026. if (!this.hasPlugin("moduleAttributes")) {
  11027. this.expectPlugin("importAssertions");
  11028. }
  11029. }
  11030. }
  11031. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11032. this.raise(Errors.ImportCallArity, {
  11033. at: node,
  11034. maxArgumentCount: this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  11035. });
  11036. } else {
  11037. for (const arg of node.arguments) {
  11038. if (arg.type === "SpreadElement") {
  11039. this.raise(Errors.ImportCallSpreadArgument, {
  11040. at: arg
  11041. });
  11042. }
  11043. }
  11044. }
  11045. }
  11046. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11047. }
  11048. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11049. const elts = [];
  11050. let first = true;
  11051. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11052. this.state.inFSharpPipelineDirectBody = false;
  11053. while (!this.eat(close)) {
  11054. if (first) {
  11055. first = false;
  11056. } else {
  11057. this.expect(12);
  11058. if (this.match(close)) {
  11059. if (dynamicImport && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  11060. this.raise(Errors.ImportCallArgumentTrailingComma, {
  11061. at: this.state.lastTokStartLoc
  11062. });
  11063. }
  11064. if (nodeForExtra) {
  11065. this.addTrailingCommaExtraToNode(nodeForExtra);
  11066. }
  11067. this.next();
  11068. break;
  11069. }
  11070. }
  11071. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  11072. }
  11073. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11074. return elts;
  11075. }
  11076. shouldParseAsyncArrow() {
  11077. return this.match(19) && !this.canInsertSemicolon();
  11078. }
  11079. parseAsyncArrowFromCallExpression(node, call) {
  11080. var _call$extra;
  11081. this.resetPreviousNodeTrailingComments(call);
  11082. this.expect(19);
  11083. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11084. if (call.innerComments) {
  11085. setInnerComments(node, call.innerComments);
  11086. }
  11087. if (call.callee.trailingComments) {
  11088. setInnerComments(node, call.callee.trailingComments);
  11089. }
  11090. return node;
  11091. }
  11092. parseNoCallExpr() {
  11093. const startLoc = this.state.startLoc;
  11094. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11095. }
  11096. parseExprAtom(refExpressionErrors) {
  11097. let node;
  11098. let decorators = null;
  11099. const {
  11100. type
  11101. } = this.state;
  11102. switch (type) {
  11103. case 79:
  11104. return this.parseSuper();
  11105. case 83:
  11106. node = this.startNode();
  11107. this.next();
  11108. if (this.match(16)) {
  11109. return this.parseImportMetaProperty(node);
  11110. }
  11111. if (!this.match(10)) {
  11112. this.raise(Errors.UnsupportedImport, {
  11113. at: this.state.lastTokStartLoc
  11114. });
  11115. }
  11116. return this.finishNode(node, "Import");
  11117. case 78:
  11118. node = this.startNode();
  11119. this.next();
  11120. return this.finishNode(node, "ThisExpression");
  11121. case 90:
  11122. {
  11123. return this.parseDo(this.startNode(), false);
  11124. }
  11125. case 56:
  11126. case 31:
  11127. {
  11128. this.readRegexp();
  11129. return this.parseRegExpLiteral(this.state.value);
  11130. }
  11131. case 132:
  11132. return this.parseNumericLiteral(this.state.value);
  11133. case 133:
  11134. return this.parseBigIntLiteral(this.state.value);
  11135. case 134:
  11136. return this.parseDecimalLiteral(this.state.value);
  11137. case 131:
  11138. return this.parseStringLiteral(this.state.value);
  11139. case 84:
  11140. return this.parseNullLiteral();
  11141. case 85:
  11142. return this.parseBooleanLiteral(true);
  11143. case 86:
  11144. return this.parseBooleanLiteral(false);
  11145. case 10:
  11146. {
  11147. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11148. return this.parseParenAndDistinguishExpression(canBeArrow);
  11149. }
  11150. case 2:
  11151. case 1:
  11152. {
  11153. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11154. }
  11155. case 0:
  11156. {
  11157. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11158. }
  11159. case 6:
  11160. case 7:
  11161. {
  11162. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11163. }
  11164. case 5:
  11165. {
  11166. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11167. }
  11168. case 68:
  11169. return this.parseFunctionOrFunctionSent();
  11170. case 26:
  11171. decorators = this.parseDecorators();
  11172. case 80:
  11173. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11174. case 77:
  11175. return this.parseNewOrNewTarget();
  11176. case 25:
  11177. case 24:
  11178. return this.parseTemplate(false);
  11179. case 15:
  11180. {
  11181. node = this.startNode();
  11182. this.next();
  11183. node.object = null;
  11184. const callee = node.callee = this.parseNoCallExpr();
  11185. if (callee.type === "MemberExpression") {
  11186. return this.finishNode(node, "BindExpression");
  11187. } else {
  11188. throw this.raise(Errors.UnsupportedBind, {
  11189. at: callee
  11190. });
  11191. }
  11192. }
  11193. case 136:
  11194. {
  11195. this.raise(Errors.PrivateInExpectedIn, {
  11196. at: this.state.startLoc,
  11197. identifierName: this.state.value
  11198. });
  11199. return this.parsePrivateName();
  11200. }
  11201. case 33:
  11202. {
  11203. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11204. }
  11205. case 32:
  11206. {
  11207. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11208. }
  11209. case 37:
  11210. case 38:
  11211. {
  11212. return this.parseTopicReference("hack");
  11213. }
  11214. case 44:
  11215. case 54:
  11216. case 27:
  11217. {
  11218. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11219. if (pipeProposal) {
  11220. return this.parseTopicReference(pipeProposal);
  11221. }
  11222. this.unexpected();
  11223. break;
  11224. }
  11225. case 47:
  11226. {
  11227. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11228. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11229. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11230. } else {
  11231. this.unexpected();
  11232. }
  11233. break;
  11234. }
  11235. default:
  11236. if (tokenIsIdentifier(type)) {
  11237. if (this.isContextual(125) && this.lookaheadInLineCharCode() === 123) {
  11238. return this.parseModuleExpression();
  11239. }
  11240. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11241. const containsEsc = this.state.containsEsc;
  11242. const id = this.parseIdentifier();
  11243. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11244. const {
  11245. type
  11246. } = this.state;
  11247. if (type === 68) {
  11248. this.resetPreviousNodeTrailingComments(id);
  11249. this.next();
  11250. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11251. } else if (tokenIsIdentifier(type)) {
  11252. if (this.lookaheadCharCode() === 61) {
  11253. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11254. } else {
  11255. return id;
  11256. }
  11257. } else if (type === 90) {
  11258. this.resetPreviousNodeTrailingComments(id);
  11259. return this.parseDo(this.startNodeAtNode(id), true);
  11260. }
  11261. }
  11262. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11263. this.next();
  11264. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11265. }
  11266. return id;
  11267. } else {
  11268. this.unexpected();
  11269. }
  11270. }
  11271. }
  11272. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11273. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11274. if (pipeProposal) {
  11275. this.state.type = topicTokenType;
  11276. this.state.value = topicTokenValue;
  11277. this.state.pos--;
  11278. this.state.end--;
  11279. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11280. return this.parseTopicReference(pipeProposal);
  11281. } else {
  11282. this.unexpected();
  11283. }
  11284. }
  11285. parseTopicReference(pipeProposal) {
  11286. const node = this.startNode();
  11287. const startLoc = this.state.startLoc;
  11288. const tokenType = this.state.type;
  11289. this.next();
  11290. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11291. }
  11292. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11293. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11294. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11295. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11296. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, {
  11297. at: startLoc
  11298. });
  11299. }
  11300. this.registerTopicReference();
  11301. return this.finishNode(node, nodeType);
  11302. } else {
  11303. throw this.raise(Errors.PipeTopicUnconfiguredToken, {
  11304. at: startLoc,
  11305. token: tokenLabelName(tokenType)
  11306. });
  11307. }
  11308. }
  11309. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11310. switch (pipeProposal) {
  11311. case "hack":
  11312. {
  11313. return this.hasPlugin(["pipelineOperator", {
  11314. topicToken: tokenLabelName(tokenType)
  11315. }]);
  11316. }
  11317. case "smart":
  11318. return tokenType === 27;
  11319. default:
  11320. throw this.raise(Errors.PipeTopicRequiresHackPipes, {
  11321. at: startLoc
  11322. });
  11323. }
  11324. }
  11325. parseAsyncArrowUnaryFunction(node) {
  11326. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11327. const params = [this.parseIdentifier()];
  11328. this.prodParam.exit();
  11329. if (this.hasPrecedingLineBreak()) {
  11330. this.raise(Errors.LineTerminatorBeforeArrow, {
  11331. at: this.state.curPosition()
  11332. });
  11333. }
  11334. this.expect(19);
  11335. return this.parseArrowExpression(node, params, true);
  11336. }
  11337. parseDo(node, isAsync) {
  11338. this.expectPlugin("doExpressions");
  11339. if (isAsync) {
  11340. this.expectPlugin("asyncDoExpressions");
  11341. }
  11342. node.async = isAsync;
  11343. this.next();
  11344. const oldLabels = this.state.labels;
  11345. this.state.labels = [];
  11346. if (isAsync) {
  11347. this.prodParam.enter(PARAM_AWAIT);
  11348. node.body = this.parseBlock();
  11349. this.prodParam.exit();
  11350. } else {
  11351. node.body = this.parseBlock();
  11352. }
  11353. this.state.labels = oldLabels;
  11354. return this.finishNode(node, "DoExpression");
  11355. }
  11356. parseSuper() {
  11357. const node = this.startNode();
  11358. this.next();
  11359. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  11360. this.raise(Errors.SuperNotAllowed, {
  11361. at: node
  11362. });
  11363. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  11364. this.raise(Errors.UnexpectedSuper, {
  11365. at: node
  11366. });
  11367. }
  11368. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11369. this.raise(Errors.UnsupportedSuper, {
  11370. at: node
  11371. });
  11372. }
  11373. return this.finishNode(node, "Super");
  11374. }
  11375. parsePrivateName() {
  11376. const node = this.startNode();
  11377. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11378. const name = this.state.value;
  11379. this.next();
  11380. node.id = this.createIdentifier(id, name);
  11381. return this.finishNode(node, "PrivateName");
  11382. }
  11383. parseFunctionOrFunctionSent() {
  11384. const node = this.startNode();
  11385. this.next();
  11386. if (this.prodParam.hasYield && this.match(16)) {
  11387. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11388. this.next();
  11389. if (this.match(102)) {
  11390. this.expectPlugin("functionSent");
  11391. } else if (!this.hasPlugin("functionSent")) {
  11392. this.unexpected();
  11393. }
  11394. return this.parseMetaProperty(node, meta, "sent");
  11395. }
  11396. return this.parseFunction(node);
  11397. }
  11398. parseMetaProperty(node, meta, propertyName) {
  11399. node.meta = meta;
  11400. const containsEsc = this.state.containsEsc;
  11401. node.property = this.parseIdentifier(true);
  11402. if (node.property.name !== propertyName || containsEsc) {
  11403. this.raise(Errors.UnsupportedMetaProperty, {
  11404. at: node.property,
  11405. target: meta.name,
  11406. onlyValidPropertyName: propertyName
  11407. });
  11408. }
  11409. return this.finishNode(node, "MetaProperty");
  11410. }
  11411. parseImportMetaProperty(node) {
  11412. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11413. this.next();
  11414. if (this.isContextual(100)) {
  11415. if (!this.inModule) {
  11416. this.raise(Errors.ImportMetaOutsideModule, {
  11417. at: id
  11418. });
  11419. }
  11420. this.sawUnambiguousESM = true;
  11421. }
  11422. return this.parseMetaProperty(node, id, "meta");
  11423. }
  11424. parseLiteralAtNode(value, type, node) {
  11425. this.addExtra(node, "rawValue", value);
  11426. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  11427. node.value = value;
  11428. this.next();
  11429. return this.finishNode(node, type);
  11430. }
  11431. parseLiteral(value, type) {
  11432. const node = this.startNode();
  11433. return this.parseLiteralAtNode(value, type, node);
  11434. }
  11435. parseStringLiteral(value) {
  11436. return this.parseLiteral(value, "StringLiteral");
  11437. }
  11438. parseNumericLiteral(value) {
  11439. return this.parseLiteral(value, "NumericLiteral");
  11440. }
  11441. parseBigIntLiteral(value) {
  11442. return this.parseLiteral(value, "BigIntLiteral");
  11443. }
  11444. parseDecimalLiteral(value) {
  11445. return this.parseLiteral(value, "DecimalLiteral");
  11446. }
  11447. parseRegExpLiteral(value) {
  11448. const node = this.parseLiteral(value.value, "RegExpLiteral");
  11449. node.pattern = value.pattern;
  11450. node.flags = value.flags;
  11451. return node;
  11452. }
  11453. parseBooleanLiteral(value) {
  11454. const node = this.startNode();
  11455. node.value = value;
  11456. this.next();
  11457. return this.finishNode(node, "BooleanLiteral");
  11458. }
  11459. parseNullLiteral() {
  11460. const node = this.startNode();
  11461. this.next();
  11462. return this.finishNode(node, "NullLiteral");
  11463. }
  11464. parseParenAndDistinguishExpression(canBeArrow) {
  11465. const startLoc = this.state.startLoc;
  11466. let val;
  11467. this.next();
  11468. this.expressionScope.enter(newArrowHeadScope());
  11469. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11470. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11471. this.state.maybeInArrowParameters = true;
  11472. this.state.inFSharpPipelineDirectBody = false;
  11473. const innerStartLoc = this.state.startLoc;
  11474. const exprList = [];
  11475. const refExpressionErrors = new ExpressionErrors();
  11476. let first = true;
  11477. let spreadStartLoc;
  11478. let optionalCommaStartLoc;
  11479. while (!this.match(11)) {
  11480. if (first) {
  11481. first = false;
  11482. } else {
  11483. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11484. if (this.match(11)) {
  11485. optionalCommaStartLoc = this.state.startLoc;
  11486. break;
  11487. }
  11488. }
  11489. if (this.match(21)) {
  11490. const spreadNodeStartLoc = this.state.startLoc;
  11491. spreadStartLoc = this.state.startLoc;
  11492. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11493. if (!this.checkCommaAfterRest(41)) {
  11494. break;
  11495. }
  11496. } else {
  11497. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11498. }
  11499. }
  11500. const innerEndLoc = this.state.lastTokEndLoc;
  11501. this.expect(11);
  11502. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11503. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11504. let arrowNode = this.startNodeAt(startLoc);
  11505. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11506. this.checkDestructuringPrivate(refExpressionErrors);
  11507. this.expressionScope.validateAsPattern();
  11508. this.expressionScope.exit();
  11509. this.parseArrowExpression(arrowNode, exprList, false);
  11510. return arrowNode;
  11511. }
  11512. this.expressionScope.exit();
  11513. if (!exprList.length) {
  11514. this.unexpected(this.state.lastTokStartLoc);
  11515. }
  11516. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11517. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11518. this.checkExpressionErrors(refExpressionErrors, true);
  11519. this.toReferencedListDeep(exprList, true);
  11520. if (exprList.length > 1) {
  11521. val = this.startNodeAt(innerStartLoc);
  11522. val.expressions = exprList;
  11523. this.finishNode(val, "SequenceExpression");
  11524. this.resetEndLocation(val, innerEndLoc);
  11525. } else {
  11526. val = exprList[0];
  11527. }
  11528. return this.wrapParenthesis(startLoc, val);
  11529. }
  11530. wrapParenthesis(startLoc, expression) {
  11531. if (!this.options.createParenthesizedExpressions) {
  11532. this.addExtra(expression, "parenthesized", true);
  11533. this.addExtra(expression, "parenStart", startLoc.index);
  11534. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11535. return expression;
  11536. }
  11537. const parenExpression = this.startNodeAt(startLoc);
  11538. parenExpression.expression = expression;
  11539. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11540. }
  11541. shouldParseArrow(params) {
  11542. return !this.canInsertSemicolon();
  11543. }
  11544. parseArrow(node) {
  11545. if (this.eat(19)) {
  11546. return node;
  11547. }
  11548. }
  11549. parseParenItem(node, startLoc) {
  11550. return node;
  11551. }
  11552. parseNewOrNewTarget() {
  11553. const node = this.startNode();
  11554. this.next();
  11555. if (this.match(16)) {
  11556. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11557. this.next();
  11558. const metaProp = this.parseMetaProperty(node, meta, "target");
  11559. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
  11560. this.raise(Errors.UnexpectedNewTarget, {
  11561. at: metaProp
  11562. });
  11563. }
  11564. return metaProp;
  11565. }
  11566. return this.parseNew(node);
  11567. }
  11568. parseNew(node) {
  11569. this.parseNewCallee(node);
  11570. if (this.eat(10)) {
  11571. const args = this.parseExprList(11);
  11572. this.toReferencedList(args);
  11573. node.arguments = args;
  11574. } else {
  11575. node.arguments = [];
  11576. }
  11577. return this.finishNode(node, "NewExpression");
  11578. }
  11579. parseNewCallee(node) {
  11580. node.callee = this.parseNoCallExpr();
  11581. if (node.callee.type === "Import") {
  11582. this.raise(Errors.ImportCallNotNewExpression, {
  11583. at: node.callee
  11584. });
  11585. }
  11586. }
  11587. parseTemplateElement(isTagged) {
  11588. const {
  11589. start,
  11590. startLoc,
  11591. end,
  11592. value
  11593. } = this.state;
  11594. const elemStart = start + 1;
  11595. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11596. if (value === null) {
  11597. if (!isTagged) {
  11598. this.raise(Errors.InvalidEscapeSequenceTemplate, {
  11599. at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)
  11600. });
  11601. }
  11602. }
  11603. const isTail = this.match(24);
  11604. const endOffset = isTail ? -1 : -2;
  11605. const elemEnd = end + endOffset;
  11606. elem.value = {
  11607. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11608. cooked: value === null ? null : value.slice(1, endOffset)
  11609. };
  11610. elem.tail = isTail;
  11611. this.next();
  11612. const finishedNode = this.finishNode(elem, "TemplateElement");
  11613. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11614. return finishedNode;
  11615. }
  11616. parseTemplate(isTagged) {
  11617. const node = this.startNode();
  11618. node.expressions = [];
  11619. let curElt = this.parseTemplateElement(isTagged);
  11620. node.quasis = [curElt];
  11621. while (!curElt.tail) {
  11622. node.expressions.push(this.parseTemplateSubstitution());
  11623. this.readTemplateContinuation();
  11624. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  11625. }
  11626. return this.finishNode(node, "TemplateLiteral");
  11627. }
  11628. parseTemplateSubstitution() {
  11629. return this.parseExpression();
  11630. }
  11631. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11632. if (isRecord) {
  11633. this.expectPlugin("recordAndTuple");
  11634. }
  11635. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11636. this.state.inFSharpPipelineDirectBody = false;
  11637. const propHash = Object.create(null);
  11638. let first = true;
  11639. const node = this.startNode();
  11640. node.properties = [];
  11641. this.next();
  11642. while (!this.match(close)) {
  11643. if (first) {
  11644. first = false;
  11645. } else {
  11646. this.expect(12);
  11647. if (this.match(close)) {
  11648. this.addTrailingCommaExtraToNode(node);
  11649. break;
  11650. }
  11651. }
  11652. let prop;
  11653. if (isPattern) {
  11654. prop = this.parseBindingProperty();
  11655. } else {
  11656. prop = this.parsePropertyDefinition(refExpressionErrors);
  11657. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11658. }
  11659. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11660. this.raise(Errors.InvalidRecordProperty, {
  11661. at: prop
  11662. });
  11663. }
  11664. if (prop.shorthand) {
  11665. this.addExtra(prop, "shorthand", true);
  11666. }
  11667. node.properties.push(prop);
  11668. }
  11669. this.next();
  11670. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11671. let type = "ObjectExpression";
  11672. if (isPattern) {
  11673. type = "ObjectPattern";
  11674. } else if (isRecord) {
  11675. type = "RecordExpression";
  11676. }
  11677. return this.finishNode(node, type);
  11678. }
  11679. addTrailingCommaExtraToNode(node) {
  11680. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  11681. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11682. }
  11683. maybeAsyncOrAccessorProp(prop) {
  11684. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11685. }
  11686. parsePropertyDefinition(refExpressionErrors) {
  11687. let decorators = [];
  11688. if (this.match(26)) {
  11689. if (this.hasPlugin("decorators")) {
  11690. this.raise(Errors.UnsupportedPropertyDecorator, {
  11691. at: this.state.startLoc
  11692. });
  11693. }
  11694. while (this.match(26)) {
  11695. decorators.push(this.parseDecorator());
  11696. }
  11697. }
  11698. const prop = this.startNode();
  11699. let isAsync = false;
  11700. let isAccessor = false;
  11701. let startLoc;
  11702. if (this.match(21)) {
  11703. if (decorators.length) this.unexpected();
  11704. return this.parseSpread();
  11705. }
  11706. if (decorators.length) {
  11707. prop.decorators = decorators;
  11708. decorators = [];
  11709. }
  11710. prop.method = false;
  11711. if (refExpressionErrors) {
  11712. startLoc = this.state.startLoc;
  11713. }
  11714. let isGenerator = this.eat(55);
  11715. this.parsePropertyNamePrefixOperator(prop);
  11716. const containsEsc = this.state.containsEsc;
  11717. const key = this.parsePropertyName(prop, refExpressionErrors);
  11718. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11719. const keyName = key.name;
  11720. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11721. isAsync = true;
  11722. this.resetPreviousNodeTrailingComments(key);
  11723. isGenerator = this.eat(55);
  11724. this.parsePropertyName(prop);
  11725. }
  11726. if (keyName === "get" || keyName === "set") {
  11727. isAccessor = true;
  11728. this.resetPreviousNodeTrailingComments(key);
  11729. prop.kind = keyName;
  11730. if (this.match(55)) {
  11731. isGenerator = true;
  11732. this.raise(Errors.AccessorIsGenerator, {
  11733. at: this.state.curPosition(),
  11734. kind: keyName
  11735. });
  11736. this.next();
  11737. }
  11738. this.parsePropertyName(prop);
  11739. }
  11740. }
  11741. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11742. }
  11743. getGetterSetterExpectedParamCount(method) {
  11744. return method.kind === "get" ? 0 : 1;
  11745. }
  11746. getObjectOrClassMethodParams(method) {
  11747. return method.params;
  11748. }
  11749. checkGetterSetterParams(method) {
  11750. var _params;
  11751. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11752. const params = this.getObjectOrClassMethodParams(method);
  11753. if (params.length !== paramCount) {
  11754. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  11755. at: method
  11756. });
  11757. }
  11758. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11759. this.raise(Errors.BadSetterRestParameter, {
  11760. at: method
  11761. });
  11762. }
  11763. }
  11764. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11765. if (isAccessor) {
  11766. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11767. this.checkGetterSetterParams(finishedProp);
  11768. return finishedProp;
  11769. }
  11770. if (isAsync || isGenerator || this.match(10)) {
  11771. if (isPattern) this.unexpected();
  11772. prop.kind = "method";
  11773. prop.method = true;
  11774. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11775. }
  11776. }
  11777. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11778. prop.shorthand = false;
  11779. if (this.eat(14)) {
  11780. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11781. return this.finishNode(prop, "ObjectProperty");
  11782. }
  11783. if (!prop.computed && prop.key.type === "Identifier") {
  11784. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11785. if (isPattern) {
  11786. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11787. } else if (this.match(29)) {
  11788. const shorthandAssignLoc = this.state.startLoc;
  11789. if (refExpressionErrors != null) {
  11790. if (refExpressionErrors.shorthandAssignLoc === null) {
  11791. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11792. }
  11793. } else {
  11794. this.raise(Errors.InvalidCoverInitializedName, {
  11795. at: shorthandAssignLoc
  11796. });
  11797. }
  11798. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11799. } else {
  11800. prop.value = cloneIdentifier(prop.key);
  11801. }
  11802. prop.shorthand = true;
  11803. return this.finishNode(prop, "ObjectProperty");
  11804. }
  11805. }
  11806. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11807. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11808. if (!node) this.unexpected();
  11809. return node;
  11810. }
  11811. parsePropertyName(prop, refExpressionErrors) {
  11812. if (this.eat(0)) {
  11813. prop.computed = true;
  11814. prop.key = this.parseMaybeAssignAllowIn();
  11815. this.expect(3);
  11816. } else {
  11817. const {
  11818. type,
  11819. value
  11820. } = this.state;
  11821. let key;
  11822. if (tokenIsKeywordOrIdentifier(type)) {
  11823. key = this.parseIdentifier(true);
  11824. } else {
  11825. switch (type) {
  11826. case 132:
  11827. key = this.parseNumericLiteral(value);
  11828. break;
  11829. case 131:
  11830. key = this.parseStringLiteral(value);
  11831. break;
  11832. case 133:
  11833. key = this.parseBigIntLiteral(value);
  11834. break;
  11835. case 134:
  11836. key = this.parseDecimalLiteral(value);
  11837. break;
  11838. case 136:
  11839. {
  11840. const privateKeyLoc = this.state.startLoc;
  11841. if (refExpressionErrors != null) {
  11842. if (refExpressionErrors.privateKeyLoc === null) {
  11843. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11844. }
  11845. } else {
  11846. this.raise(Errors.UnexpectedPrivateField, {
  11847. at: privateKeyLoc
  11848. });
  11849. }
  11850. key = this.parsePrivateName();
  11851. break;
  11852. }
  11853. default:
  11854. this.unexpected();
  11855. }
  11856. }
  11857. prop.key = key;
  11858. if (type !== 136) {
  11859. prop.computed = false;
  11860. }
  11861. }
  11862. return prop.key;
  11863. }
  11864. initFunction(node, isAsync) {
  11865. node.id = null;
  11866. node.generator = false;
  11867. node.async = isAsync;
  11868. }
  11869. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11870. this.initFunction(node, isAsync);
  11871. node.generator = isGenerator;
  11872. this.scope.enter(SCOPE_FUNCTION | SCOPE_SUPER | (inClassScope ? SCOPE_CLASS : 0) | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  11873. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11874. this.parseFunctionParams(node, isConstructor);
  11875. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11876. this.prodParam.exit();
  11877. this.scope.exit();
  11878. return finishedNode;
  11879. }
  11880. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11881. if (isTuple) {
  11882. this.expectPlugin("recordAndTuple");
  11883. }
  11884. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11885. this.state.inFSharpPipelineDirectBody = false;
  11886. const node = this.startNode();
  11887. this.next();
  11888. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11889. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11890. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11891. }
  11892. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11893. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  11894. let flags = functionFlags(isAsync, false);
  11895. if (!this.match(5) && this.prodParam.hasIn) {
  11896. flags |= PARAM_IN;
  11897. }
  11898. this.prodParam.enter(flags);
  11899. this.initFunction(node, isAsync);
  11900. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11901. if (params) {
  11902. this.state.maybeInArrowParameters = true;
  11903. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11904. }
  11905. this.state.maybeInArrowParameters = false;
  11906. this.parseFunctionBody(node, true);
  11907. this.prodParam.exit();
  11908. this.scope.exit();
  11909. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11910. return this.finishNode(node, "ArrowFunctionExpression");
  11911. }
  11912. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11913. this.toAssignableList(params, trailingCommaLoc, false);
  11914. node.params = params;
  11915. }
  11916. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11917. this.parseFunctionBody(node, false, isMethod);
  11918. return this.finishNode(node, type);
  11919. }
  11920. parseFunctionBody(node, allowExpression, isMethod = false) {
  11921. const isExpression = allowExpression && !this.match(5);
  11922. this.expressionScope.enter(newExpressionScope());
  11923. if (isExpression) {
  11924. node.body = this.parseMaybeAssign();
  11925. this.checkParams(node, false, allowExpression, false);
  11926. } else {
  11927. const oldStrict = this.state.strict;
  11928. const oldLabels = this.state.labels;
  11929. this.state.labels = [];
  11930. this.prodParam.enter(this.prodParam.currentFlags() | PARAM_RETURN);
  11931. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11932. const nonSimple = !this.isSimpleParamList(node.params);
  11933. if (hasStrictModeDirective && nonSimple) {
  11934. this.raise(Errors.IllegalLanguageModeDirective, {
  11935. at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node
  11936. });
  11937. }
  11938. const strictModeChanged = !oldStrict && this.state.strict;
  11939. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11940. if (this.state.strict && node.id) {
  11941. this.checkIdentifier(node.id, BIND_OUTSIDE, strictModeChanged);
  11942. }
  11943. });
  11944. this.prodParam.exit();
  11945. this.state.labels = oldLabels;
  11946. }
  11947. this.expressionScope.exit();
  11948. }
  11949. isSimpleParameter(node) {
  11950. return node.type === "Identifier";
  11951. }
  11952. isSimpleParamList(params) {
  11953. for (let i = 0, len = params.length; i < len; i++) {
  11954. if (!this.isSimpleParameter(params[i])) return false;
  11955. }
  11956. return true;
  11957. }
  11958. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11959. const checkClashes = !allowDuplicates && new Set();
  11960. const formalParameters = {
  11961. type: "FormalParameters"
  11962. };
  11963. for (const param of node.params) {
  11964. this.checkLVal(param, {
  11965. in: formalParameters,
  11966. binding: BIND_VAR,
  11967. checkClashes,
  11968. strictModeChanged
  11969. });
  11970. }
  11971. }
  11972. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11973. const elts = [];
  11974. let first = true;
  11975. while (!this.eat(close)) {
  11976. if (first) {
  11977. first = false;
  11978. } else {
  11979. this.expect(12);
  11980. if (this.match(close)) {
  11981. if (nodeForExtra) {
  11982. this.addTrailingCommaExtraToNode(nodeForExtra);
  11983. }
  11984. this.next();
  11985. break;
  11986. }
  11987. }
  11988. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11989. }
  11990. return elts;
  11991. }
  11992. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  11993. let elt;
  11994. if (this.match(12)) {
  11995. if (!allowEmpty) {
  11996. this.raise(Errors.UnexpectedToken, {
  11997. at: this.state.curPosition(),
  11998. unexpected: ","
  11999. });
  12000. }
  12001. elt = null;
  12002. } else if (this.match(21)) {
  12003. const spreadNodeStartLoc = this.state.startLoc;
  12004. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12005. } else if (this.match(17)) {
  12006. this.expectPlugin("partialApplication");
  12007. if (!allowPlaceholder) {
  12008. this.raise(Errors.UnexpectedArgumentPlaceholder, {
  12009. at: this.state.startLoc
  12010. });
  12011. }
  12012. const node = this.startNode();
  12013. this.next();
  12014. elt = this.finishNode(node, "ArgumentPlaceholder");
  12015. } else {
  12016. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  12017. }
  12018. return elt;
  12019. }
  12020. parseIdentifier(liberal) {
  12021. const node = this.startNode();
  12022. const name = this.parseIdentifierName(liberal);
  12023. return this.createIdentifier(node, name);
  12024. }
  12025. createIdentifier(node, name) {
  12026. node.name = name;
  12027. node.loc.identifierName = name;
  12028. return this.finishNode(node, "Identifier");
  12029. }
  12030. parseIdentifierName(liberal) {
  12031. let name;
  12032. const {
  12033. startLoc,
  12034. type
  12035. } = this.state;
  12036. if (tokenIsKeywordOrIdentifier(type)) {
  12037. name = this.state.value;
  12038. } else {
  12039. this.unexpected();
  12040. }
  12041. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12042. if (liberal) {
  12043. if (tokenIsKeyword) {
  12044. this.replaceToken(130);
  12045. }
  12046. } else {
  12047. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12048. }
  12049. this.next();
  12050. return name;
  12051. }
  12052. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12053. if (word.length > 10) {
  12054. return;
  12055. }
  12056. if (!canBeReservedWord(word)) {
  12057. return;
  12058. }
  12059. if (checkKeywords && isKeyword(word)) {
  12060. this.raise(Errors.UnexpectedKeyword, {
  12061. at: startLoc,
  12062. keyword: word
  12063. });
  12064. return;
  12065. }
  12066. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12067. if (reservedTest(word, this.inModule)) {
  12068. this.raise(Errors.UnexpectedReservedWord, {
  12069. at: startLoc,
  12070. reservedWord: word
  12071. });
  12072. return;
  12073. } else if (word === "yield") {
  12074. if (this.prodParam.hasYield) {
  12075. this.raise(Errors.YieldBindingIdentifier, {
  12076. at: startLoc
  12077. });
  12078. return;
  12079. }
  12080. } else if (word === "await") {
  12081. if (this.prodParam.hasAwait) {
  12082. this.raise(Errors.AwaitBindingIdentifier, {
  12083. at: startLoc
  12084. });
  12085. return;
  12086. }
  12087. if (this.scope.inStaticBlock) {
  12088. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
  12089. at: startLoc
  12090. });
  12091. return;
  12092. }
  12093. this.expressionScope.recordAsyncArrowParametersError({
  12094. at: startLoc
  12095. });
  12096. } else if (word === "arguments") {
  12097. if (this.scope.inClassAndNotInNonArrowFunction) {
  12098. this.raise(Errors.ArgumentsInClass, {
  12099. at: startLoc
  12100. });
  12101. return;
  12102. }
  12103. }
  12104. }
  12105. isAwaitAllowed() {
  12106. if (this.prodParam.hasAwait) return true;
  12107. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  12108. return true;
  12109. }
  12110. return false;
  12111. }
  12112. parseAwait(startLoc) {
  12113. const node = this.startNodeAt(startLoc);
  12114. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
  12115. at: node
  12116. });
  12117. if (this.eat(55)) {
  12118. this.raise(Errors.ObsoleteAwaitStar, {
  12119. at: node
  12120. });
  12121. }
  12122. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  12123. if (this.isAmbiguousAwait()) {
  12124. this.ambiguousScriptDifferentAst = true;
  12125. } else {
  12126. this.sawUnambiguousESM = true;
  12127. }
  12128. }
  12129. if (!this.state.soloAwait) {
  12130. node.argument = this.parseMaybeUnary(null, true);
  12131. }
  12132. return this.finishNode(node, "AwaitExpression");
  12133. }
  12134. isAmbiguousAwait() {
  12135. if (this.hasPrecedingLineBreak()) return true;
  12136. const {
  12137. type
  12138. } = this.state;
  12139. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 101 && !this.state.containsEsc || type === 135 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12140. }
  12141. parseYield() {
  12142. const node = this.startNode();
  12143. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
  12144. at: node
  12145. });
  12146. this.next();
  12147. let delegating = false;
  12148. let argument = null;
  12149. if (!this.hasPrecedingLineBreak()) {
  12150. delegating = this.eat(55);
  12151. switch (this.state.type) {
  12152. case 13:
  12153. case 137:
  12154. case 8:
  12155. case 11:
  12156. case 3:
  12157. case 9:
  12158. case 14:
  12159. case 12:
  12160. if (!delegating) break;
  12161. default:
  12162. argument = this.parseMaybeAssign();
  12163. }
  12164. }
  12165. node.delegate = delegating;
  12166. node.argument = argument;
  12167. return this.finishNode(node, "YieldExpression");
  12168. }
  12169. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12170. if (this.hasPlugin(["pipelineOperator", {
  12171. proposal: "smart"
  12172. }])) {
  12173. if (left.type === "SequenceExpression") {
  12174. this.raise(Errors.PipelineHeadSequenceExpression, {
  12175. at: leftStartLoc
  12176. });
  12177. }
  12178. }
  12179. }
  12180. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12181. if (this.isSimpleReference(childExpr)) {
  12182. const bodyNode = this.startNodeAt(startLoc);
  12183. bodyNode.callee = childExpr;
  12184. return this.finishNode(bodyNode, "PipelineBareFunction");
  12185. } else {
  12186. const bodyNode = this.startNodeAt(startLoc);
  12187. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12188. bodyNode.expression = childExpr;
  12189. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12190. }
  12191. }
  12192. isSimpleReference(expression) {
  12193. switch (expression.type) {
  12194. case "MemberExpression":
  12195. return !expression.computed && this.isSimpleReference(expression.object);
  12196. case "Identifier":
  12197. return true;
  12198. default:
  12199. return false;
  12200. }
  12201. }
  12202. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12203. if (this.match(19)) {
  12204. throw this.raise(Errors.PipelineBodyNoArrow, {
  12205. at: this.state.startLoc
  12206. });
  12207. }
  12208. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12209. this.raise(Errors.PipelineTopicUnused, {
  12210. at: startLoc
  12211. });
  12212. }
  12213. }
  12214. withTopicBindingContext(callback) {
  12215. const outerContextTopicState = this.state.topicContext;
  12216. this.state.topicContext = {
  12217. maxNumOfResolvableTopics: 1,
  12218. maxTopicIndex: null
  12219. };
  12220. try {
  12221. return callback();
  12222. } finally {
  12223. this.state.topicContext = outerContextTopicState;
  12224. }
  12225. }
  12226. withSmartMixTopicForbiddingContext(callback) {
  12227. if (this.hasPlugin(["pipelineOperator", {
  12228. proposal: "smart"
  12229. }])) {
  12230. const outerContextTopicState = this.state.topicContext;
  12231. this.state.topicContext = {
  12232. maxNumOfResolvableTopics: 0,
  12233. maxTopicIndex: null
  12234. };
  12235. try {
  12236. return callback();
  12237. } finally {
  12238. this.state.topicContext = outerContextTopicState;
  12239. }
  12240. } else {
  12241. return callback();
  12242. }
  12243. }
  12244. withSoloAwaitPermittingContext(callback) {
  12245. const outerContextSoloAwaitState = this.state.soloAwait;
  12246. this.state.soloAwait = true;
  12247. try {
  12248. return callback();
  12249. } finally {
  12250. this.state.soloAwait = outerContextSoloAwaitState;
  12251. }
  12252. }
  12253. allowInAnd(callback) {
  12254. const flags = this.prodParam.currentFlags();
  12255. const prodParamToSet = PARAM_IN & ~flags;
  12256. if (prodParamToSet) {
  12257. this.prodParam.enter(flags | PARAM_IN);
  12258. try {
  12259. return callback();
  12260. } finally {
  12261. this.prodParam.exit();
  12262. }
  12263. }
  12264. return callback();
  12265. }
  12266. disallowInAnd(callback) {
  12267. const flags = this.prodParam.currentFlags();
  12268. const prodParamToClear = PARAM_IN & flags;
  12269. if (prodParamToClear) {
  12270. this.prodParam.enter(flags & ~PARAM_IN);
  12271. try {
  12272. return callback();
  12273. } finally {
  12274. this.prodParam.exit();
  12275. }
  12276. }
  12277. return callback();
  12278. }
  12279. registerTopicReference() {
  12280. this.state.topicContext.maxTopicIndex = 0;
  12281. }
  12282. topicReferenceIsAllowedInCurrentContext() {
  12283. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12284. }
  12285. topicReferenceWasUsedInCurrentContext() {
  12286. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12287. }
  12288. parseFSharpPipelineBody(prec) {
  12289. const startLoc = this.state.startLoc;
  12290. this.state.potentialArrowAt = this.state.start;
  12291. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12292. this.state.inFSharpPipelineDirectBody = true;
  12293. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12294. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12295. return ret;
  12296. }
  12297. parseModuleExpression() {
  12298. this.expectPlugin("moduleBlocks");
  12299. const node = this.startNode();
  12300. this.next();
  12301. if (!this.match(5)) {
  12302. this.unexpected(null, 5);
  12303. }
  12304. const program = this.startNodeAt(this.state.endLoc);
  12305. this.next();
  12306. const revertScopes = this.initializeScopes(true);
  12307. this.enterInitialScopes();
  12308. try {
  12309. node.body = this.parseProgram(program, 8, "module");
  12310. } finally {
  12311. revertScopes();
  12312. }
  12313. return this.finishNode(node, "ModuleExpression");
  12314. }
  12315. parsePropertyNamePrefixOperator(prop) {}
  12316. }
  12317. const loopLabel = {
  12318. kind: "loop"
  12319. },
  12320. switchLabel = {
  12321. kind: "switch"
  12322. };
  12323. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12324. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12325. function babel7CompatTokens(tokens, input) {
  12326. for (let i = 0; i < tokens.length; i++) {
  12327. const token = tokens[i];
  12328. const {
  12329. type
  12330. } = token;
  12331. if (typeof type === "number") {
  12332. {
  12333. if (type === 136) {
  12334. const {
  12335. loc,
  12336. start,
  12337. value,
  12338. end
  12339. } = token;
  12340. const hashEndPos = start + 1;
  12341. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12342. tokens.splice(i, 1, new Token({
  12343. type: getExportedToken(27),
  12344. value: "#",
  12345. start: start,
  12346. end: hashEndPos,
  12347. startLoc: loc.start,
  12348. endLoc: hashEndLoc
  12349. }), new Token({
  12350. type: getExportedToken(130),
  12351. value: value,
  12352. start: hashEndPos,
  12353. end: end,
  12354. startLoc: hashEndLoc,
  12355. endLoc: loc.end
  12356. }));
  12357. i++;
  12358. continue;
  12359. }
  12360. if (tokenIsTemplate(type)) {
  12361. const {
  12362. loc,
  12363. start,
  12364. value,
  12365. end
  12366. } = token;
  12367. const backquoteEnd = start + 1;
  12368. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12369. let startToken;
  12370. if (input.charCodeAt(start) === 96) {
  12371. startToken = new Token({
  12372. type: getExportedToken(22),
  12373. value: "`",
  12374. start: start,
  12375. end: backquoteEnd,
  12376. startLoc: loc.start,
  12377. endLoc: backquoteEndLoc
  12378. });
  12379. } else {
  12380. startToken = new Token({
  12381. type: getExportedToken(8),
  12382. value: "}",
  12383. start: start,
  12384. end: backquoteEnd,
  12385. startLoc: loc.start,
  12386. endLoc: backquoteEndLoc
  12387. });
  12388. }
  12389. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12390. if (type === 24) {
  12391. templateElementEnd = end - 1;
  12392. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12393. templateValue = value === null ? null : value.slice(1, -1);
  12394. endToken = new Token({
  12395. type: getExportedToken(22),
  12396. value: "`",
  12397. start: templateElementEnd,
  12398. end: end,
  12399. startLoc: templateElementEndLoc,
  12400. endLoc: loc.end
  12401. });
  12402. } else {
  12403. templateElementEnd = end - 2;
  12404. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12405. templateValue = value === null ? null : value.slice(1, -2);
  12406. endToken = new Token({
  12407. type: getExportedToken(23),
  12408. value: "${",
  12409. start: templateElementEnd,
  12410. end: end,
  12411. startLoc: templateElementEndLoc,
  12412. endLoc: loc.end
  12413. });
  12414. }
  12415. tokens.splice(i, 1, startToken, new Token({
  12416. type: getExportedToken(20),
  12417. value: templateValue,
  12418. start: backquoteEnd,
  12419. end: templateElementEnd,
  12420. startLoc: backquoteEndLoc,
  12421. endLoc: templateElementEndLoc
  12422. }), endToken);
  12423. i += 2;
  12424. continue;
  12425. }
  12426. }
  12427. token.type = getExportedToken(type);
  12428. }
  12429. }
  12430. return tokens;
  12431. }
  12432. class StatementParser extends ExpressionParser {
  12433. parseTopLevel(file, program) {
  12434. file.program = this.parseProgram(program);
  12435. file.comments = this.state.comments;
  12436. if (this.options.tokens) {
  12437. file.tokens = babel7CompatTokens(this.tokens, this.input);
  12438. }
  12439. return this.finishNode(file, "File");
  12440. }
  12441. parseProgram(program, end = 137, sourceType = this.options.sourceType) {
  12442. program.sourceType = sourceType;
  12443. program.interpreter = this.parseInterpreterDirective();
  12444. this.parseBlockBody(program, true, true, end);
  12445. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  12446. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12447. this.raise(Errors.ModuleExportUndefined, {
  12448. at,
  12449. localName
  12450. });
  12451. }
  12452. }
  12453. let finishedProgram;
  12454. if (end === 137) {
  12455. finishedProgram = this.finishNode(program, "Program");
  12456. } else {
  12457. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12458. }
  12459. return finishedProgram;
  12460. }
  12461. stmtToDirective(stmt) {
  12462. const directive = stmt;
  12463. directive.type = "Directive";
  12464. directive.value = directive.expression;
  12465. delete directive.expression;
  12466. const directiveLiteral = directive.value;
  12467. const expressionValue = directiveLiteral.value;
  12468. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  12469. const val = directiveLiteral.value = raw.slice(1, -1);
  12470. this.addExtra(directiveLiteral, "raw", raw);
  12471. this.addExtra(directiveLiteral, "rawValue", val);
  12472. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12473. directiveLiteral.type = "DirectiveLiteral";
  12474. return directive;
  12475. }
  12476. parseInterpreterDirective() {
  12477. if (!this.match(28)) {
  12478. return null;
  12479. }
  12480. const node = this.startNode();
  12481. node.value = this.state.value;
  12482. this.next();
  12483. return this.finishNode(node, "InterpreterDirective");
  12484. }
  12485. isLet() {
  12486. if (!this.isContextual(99)) {
  12487. return false;
  12488. }
  12489. return this.hasFollowingBindingAtom();
  12490. }
  12491. chStartsBindingIdentifier(ch, pos) {
  12492. if (isIdentifierStart(ch)) {
  12493. keywordRelationalOperator.lastIndex = pos;
  12494. if (keywordRelationalOperator.test(this.input)) {
  12495. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12496. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12497. return false;
  12498. }
  12499. }
  12500. return true;
  12501. } else if (ch === 92) {
  12502. return true;
  12503. } else {
  12504. return false;
  12505. }
  12506. }
  12507. chStartsBindingPattern(ch) {
  12508. return ch === 91 || ch === 123;
  12509. }
  12510. hasFollowingBindingAtom() {
  12511. const next = this.nextTokenStart();
  12512. const nextCh = this.codePointAtPos(next);
  12513. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12514. }
  12515. hasInLineFollowingBindingIdentifier() {
  12516. const next = this.nextTokenInLineStart();
  12517. const nextCh = this.codePointAtPos(next);
  12518. return this.chStartsBindingIdentifier(nextCh, next);
  12519. }
  12520. startsUsingForOf() {
  12521. const {
  12522. type,
  12523. containsEsc
  12524. } = this.lookahead();
  12525. if (type === 101 && !containsEsc) {
  12526. return false;
  12527. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12528. this.expectPlugin("explicitResourceManagement");
  12529. return true;
  12530. }
  12531. }
  12532. parseModuleItem() {
  12533. return this.parseStatementLike(1 | 2 | 4 | 8);
  12534. }
  12535. parseStatementListItem() {
  12536. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12537. }
  12538. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12539. let flags = 0;
  12540. if (this.options.annexB && !this.state.strict) {
  12541. flags |= 4;
  12542. if (allowLabeledFunction) {
  12543. flags |= 8;
  12544. }
  12545. }
  12546. return this.parseStatementLike(flags);
  12547. }
  12548. parseStatement() {
  12549. return this.parseStatementLike(0);
  12550. }
  12551. parseStatementLike(flags) {
  12552. let decorators = null;
  12553. if (this.match(26)) {
  12554. decorators = this.parseDecorators(true);
  12555. }
  12556. return this.parseStatementContent(flags, decorators);
  12557. }
  12558. parseStatementContent(flags, decorators) {
  12559. const starttype = this.state.type;
  12560. const node = this.startNode();
  12561. const allowDeclaration = !!(flags & 2);
  12562. const allowFunctionDeclaration = !!(flags & 4);
  12563. const topLevel = flags & 1;
  12564. switch (starttype) {
  12565. case 60:
  12566. return this.parseBreakContinueStatement(node, true);
  12567. case 63:
  12568. return this.parseBreakContinueStatement(node, false);
  12569. case 64:
  12570. return this.parseDebuggerStatement(node);
  12571. case 90:
  12572. return this.parseDoWhileStatement(node);
  12573. case 91:
  12574. return this.parseForStatement(node);
  12575. case 68:
  12576. if (this.lookaheadCharCode() === 46) break;
  12577. if (!allowFunctionDeclaration) {
  12578. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, {
  12579. at: this.state.startLoc
  12580. });
  12581. }
  12582. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12583. case 80:
  12584. if (!allowDeclaration) this.unexpected();
  12585. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12586. case 69:
  12587. return this.parseIfStatement(node);
  12588. case 70:
  12589. return this.parseReturnStatement(node);
  12590. case 71:
  12591. return this.parseSwitchStatement(node);
  12592. case 72:
  12593. return this.parseThrowStatement(node);
  12594. case 73:
  12595. return this.parseTryStatement(node);
  12596. case 105:
  12597. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifier()) {
  12598. break;
  12599. }
  12600. this.expectPlugin("explicitResourceManagement");
  12601. if (!this.scope.inModule && this.scope.inTopLevel) {
  12602. this.raise(Errors.UnexpectedUsingDeclaration, {
  12603. at: this.state.startLoc
  12604. });
  12605. } else if (!allowDeclaration) {
  12606. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12607. at: this.state.startLoc
  12608. });
  12609. }
  12610. return this.parseVarStatement(node, "using");
  12611. case 99:
  12612. {
  12613. if (this.state.containsEsc) {
  12614. break;
  12615. }
  12616. const next = this.nextTokenStart();
  12617. const nextCh = this.codePointAtPos(next);
  12618. if (nextCh !== 91) {
  12619. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12620. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12621. break;
  12622. }
  12623. }
  12624. }
  12625. case 75:
  12626. {
  12627. if (!allowDeclaration) {
  12628. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12629. at: this.state.startLoc
  12630. });
  12631. }
  12632. }
  12633. case 74:
  12634. {
  12635. const kind = this.state.value;
  12636. return this.parseVarStatement(node, kind);
  12637. }
  12638. case 92:
  12639. return this.parseWhileStatement(node);
  12640. case 76:
  12641. return this.parseWithStatement(node);
  12642. case 5:
  12643. return this.parseBlock();
  12644. case 13:
  12645. return this.parseEmptyStatement(node);
  12646. case 83:
  12647. {
  12648. const nextTokenCharCode = this.lookaheadCharCode();
  12649. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12650. break;
  12651. }
  12652. }
  12653. case 82:
  12654. {
  12655. if (!this.options.allowImportExportEverywhere && !topLevel) {
  12656. this.raise(Errors.UnexpectedImportExport, {
  12657. at: this.state.startLoc
  12658. });
  12659. }
  12660. this.next();
  12661. let result;
  12662. if (starttype === 83) {
  12663. result = this.parseImport(node);
  12664. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12665. this.sawUnambiguousESM = true;
  12666. }
  12667. } else {
  12668. result = this.parseExport(node, decorators);
  12669. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12670. this.sawUnambiguousESM = true;
  12671. }
  12672. }
  12673. this.assertModuleNodeAllowed(result);
  12674. return result;
  12675. }
  12676. default:
  12677. {
  12678. if (this.isAsyncFunction()) {
  12679. if (!allowDeclaration) {
  12680. this.raise(Errors.AsyncFunctionInSingleStatementContext, {
  12681. at: this.state.startLoc
  12682. });
  12683. }
  12684. this.next();
  12685. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12686. }
  12687. }
  12688. }
  12689. const maybeName = this.state.value;
  12690. const expr = this.parseExpression();
  12691. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  12692. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12693. } else {
  12694. return this.parseExpressionStatement(node, expr, decorators);
  12695. }
  12696. }
  12697. assertModuleNodeAllowed(node) {
  12698. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  12699. this.raise(Errors.ImportOutsideModule, {
  12700. at: node
  12701. });
  12702. }
  12703. }
  12704. decoratorsEnabledBeforeExport() {
  12705. if (this.hasPlugin("decorators-legacy")) return true;
  12706. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12707. }
  12708. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12709. if (maybeDecorators) {
  12710. if (classNode.decorators && classNode.decorators.length > 0) {
  12711. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12712. this.raise(Errors.DecoratorsBeforeAfterExport, {
  12713. at: classNode.decorators[0]
  12714. });
  12715. }
  12716. classNode.decorators.unshift(...maybeDecorators);
  12717. } else {
  12718. classNode.decorators = maybeDecorators;
  12719. }
  12720. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12721. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12722. }
  12723. return classNode;
  12724. }
  12725. canHaveLeadingDecorator() {
  12726. return this.match(80);
  12727. }
  12728. parseDecorators(allowExport) {
  12729. const decorators = [];
  12730. do {
  12731. decorators.push(this.parseDecorator());
  12732. } while (this.match(26));
  12733. if (this.match(82)) {
  12734. if (!allowExport) {
  12735. this.unexpected();
  12736. }
  12737. if (!this.decoratorsEnabledBeforeExport()) {
  12738. this.raise(Errors.DecoratorExportClass, {
  12739. at: this.state.startLoc
  12740. });
  12741. }
  12742. } else if (!this.canHaveLeadingDecorator()) {
  12743. throw this.raise(Errors.UnexpectedLeadingDecorator, {
  12744. at: this.state.startLoc
  12745. });
  12746. }
  12747. return decorators;
  12748. }
  12749. parseDecorator() {
  12750. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12751. const node = this.startNode();
  12752. this.next();
  12753. if (this.hasPlugin("decorators")) {
  12754. const startLoc = this.state.startLoc;
  12755. let expr;
  12756. if (this.match(10)) {
  12757. const startLoc = this.state.startLoc;
  12758. this.next();
  12759. expr = this.parseExpression();
  12760. this.expect(11);
  12761. expr = this.wrapParenthesis(startLoc, expr);
  12762. const paramsStartLoc = this.state.startLoc;
  12763. node.expression = this.parseMaybeDecoratorArguments(expr);
  12764. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12765. this.raise(Errors.DecoratorArgumentsOutsideParentheses, {
  12766. at: paramsStartLoc
  12767. });
  12768. }
  12769. } else {
  12770. expr = this.parseIdentifier(false);
  12771. while (this.eat(16)) {
  12772. const node = this.startNodeAt(startLoc);
  12773. node.object = expr;
  12774. if (this.match(136)) {
  12775. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12776. node.property = this.parsePrivateName();
  12777. } else {
  12778. node.property = this.parseIdentifier(true);
  12779. }
  12780. node.computed = false;
  12781. expr = this.finishNode(node, "MemberExpression");
  12782. }
  12783. node.expression = this.parseMaybeDecoratorArguments(expr);
  12784. }
  12785. } else {
  12786. node.expression = this.parseExprSubscripts();
  12787. }
  12788. return this.finishNode(node, "Decorator");
  12789. }
  12790. parseMaybeDecoratorArguments(expr) {
  12791. if (this.eat(10)) {
  12792. const node = this.startNodeAtNode(expr);
  12793. node.callee = expr;
  12794. node.arguments = this.parseCallExpressionArguments(11, false);
  12795. this.toReferencedList(node.arguments);
  12796. return this.finishNode(node, "CallExpression");
  12797. }
  12798. return expr;
  12799. }
  12800. parseBreakContinueStatement(node, isBreak) {
  12801. this.next();
  12802. if (this.isLineTerminator()) {
  12803. node.label = null;
  12804. } else {
  12805. node.label = this.parseIdentifier();
  12806. this.semicolon();
  12807. }
  12808. this.verifyBreakContinue(node, isBreak);
  12809. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12810. }
  12811. verifyBreakContinue(node, isBreak) {
  12812. let i;
  12813. for (i = 0; i < this.state.labels.length; ++i) {
  12814. const lab = this.state.labels[i];
  12815. if (node.label == null || lab.name === node.label.name) {
  12816. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  12817. if (node.label && isBreak) break;
  12818. }
  12819. }
  12820. if (i === this.state.labels.length) {
  12821. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12822. this.raise(Errors.IllegalBreakContinue, {
  12823. at: node,
  12824. type
  12825. });
  12826. }
  12827. }
  12828. parseDebuggerStatement(node) {
  12829. this.next();
  12830. this.semicolon();
  12831. return this.finishNode(node, "DebuggerStatement");
  12832. }
  12833. parseHeaderExpression() {
  12834. this.expect(10);
  12835. const val = this.parseExpression();
  12836. this.expect(11);
  12837. return val;
  12838. }
  12839. parseDoWhileStatement(node) {
  12840. this.next();
  12841. this.state.labels.push(loopLabel);
  12842. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12843. this.state.labels.pop();
  12844. this.expect(92);
  12845. node.test = this.parseHeaderExpression();
  12846. this.eat(13);
  12847. return this.finishNode(node, "DoWhileStatement");
  12848. }
  12849. parseForStatement(node) {
  12850. this.next();
  12851. this.state.labels.push(loopLabel);
  12852. let awaitAt = null;
  12853. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  12854. awaitAt = this.state.lastTokStartLoc;
  12855. }
  12856. this.scope.enter(SCOPE_OTHER);
  12857. this.expect(10);
  12858. if (this.match(13)) {
  12859. if (awaitAt !== null) {
  12860. this.unexpected(awaitAt);
  12861. }
  12862. return this.parseFor(node, null);
  12863. }
  12864. const startsWithLet = this.isContextual(99);
  12865. const startsWithUsing = this.isContextual(105);
  12866. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || startsWithUsing && this.startsUsingForOf();
  12867. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12868. const initNode = this.startNode();
  12869. const kind = this.state.value;
  12870. this.next();
  12871. this.parseVar(initNode, true, kind);
  12872. const init = this.finishNode(initNode, "VariableDeclaration");
  12873. const isForIn = this.match(58);
  12874. if (isForIn && startsWithUsing) {
  12875. this.raise(Errors.ForInUsing, {
  12876. at: init
  12877. });
  12878. }
  12879. if ((isForIn || this.isContextual(101)) && init.declarations.length === 1) {
  12880. return this.parseForIn(node, init, awaitAt);
  12881. }
  12882. if (awaitAt !== null) {
  12883. this.unexpected(awaitAt);
  12884. }
  12885. return this.parseFor(node, init);
  12886. }
  12887. const startsWithAsync = this.isContextual(95);
  12888. const refExpressionErrors = new ExpressionErrors();
  12889. const init = this.parseExpression(true, refExpressionErrors);
  12890. const isForOf = this.isContextual(101);
  12891. if (isForOf) {
  12892. if (startsWithLet) {
  12893. this.raise(Errors.ForOfLet, {
  12894. at: init
  12895. });
  12896. }
  12897. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12898. this.raise(Errors.ForOfAsync, {
  12899. at: init
  12900. });
  12901. }
  12902. }
  12903. if (isForOf || this.match(58)) {
  12904. this.checkDestructuringPrivate(refExpressionErrors);
  12905. this.toAssignable(init, true);
  12906. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12907. this.checkLVal(init, {
  12908. in: {
  12909. type
  12910. }
  12911. });
  12912. return this.parseForIn(node, init, awaitAt);
  12913. } else {
  12914. this.checkExpressionErrors(refExpressionErrors, true);
  12915. }
  12916. if (awaitAt !== null) {
  12917. this.unexpected(awaitAt);
  12918. }
  12919. return this.parseFor(node, init);
  12920. }
  12921. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12922. this.next();
  12923. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  12924. }
  12925. parseIfStatement(node) {
  12926. this.next();
  12927. node.test = this.parseHeaderExpression();
  12928. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12929. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  12930. return this.finishNode(node, "IfStatement");
  12931. }
  12932. parseReturnStatement(node) {
  12933. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  12934. this.raise(Errors.IllegalReturn, {
  12935. at: this.state.startLoc
  12936. });
  12937. }
  12938. this.next();
  12939. if (this.isLineTerminator()) {
  12940. node.argument = null;
  12941. } else {
  12942. node.argument = this.parseExpression();
  12943. this.semicolon();
  12944. }
  12945. return this.finishNode(node, "ReturnStatement");
  12946. }
  12947. parseSwitchStatement(node) {
  12948. this.next();
  12949. node.discriminant = this.parseHeaderExpression();
  12950. const cases = node.cases = [];
  12951. this.expect(5);
  12952. this.state.labels.push(switchLabel);
  12953. this.scope.enter(SCOPE_OTHER);
  12954. let cur;
  12955. for (let sawDefault; !this.match(8);) {
  12956. if (this.match(61) || this.match(65)) {
  12957. const isCase = this.match(61);
  12958. if (cur) this.finishNode(cur, "SwitchCase");
  12959. cases.push(cur = this.startNode());
  12960. cur.consequent = [];
  12961. this.next();
  12962. if (isCase) {
  12963. cur.test = this.parseExpression();
  12964. } else {
  12965. if (sawDefault) {
  12966. this.raise(Errors.MultipleDefaultsInSwitch, {
  12967. at: this.state.lastTokStartLoc
  12968. });
  12969. }
  12970. sawDefault = true;
  12971. cur.test = null;
  12972. }
  12973. this.expect(14);
  12974. } else {
  12975. if (cur) {
  12976. cur.consequent.push(this.parseStatementListItem());
  12977. } else {
  12978. this.unexpected();
  12979. }
  12980. }
  12981. }
  12982. this.scope.exit();
  12983. if (cur) this.finishNode(cur, "SwitchCase");
  12984. this.next();
  12985. this.state.labels.pop();
  12986. return this.finishNode(node, "SwitchStatement");
  12987. }
  12988. parseThrowStatement(node) {
  12989. this.next();
  12990. if (this.hasPrecedingLineBreak()) {
  12991. this.raise(Errors.NewlineAfterThrow, {
  12992. at: this.state.lastTokEndLoc
  12993. });
  12994. }
  12995. node.argument = this.parseExpression();
  12996. this.semicolon();
  12997. return this.finishNode(node, "ThrowStatement");
  12998. }
  12999. parseCatchClauseParam() {
  13000. const param = this.parseBindingAtom();
  13001. this.scope.enter(this.options.annexB && param.type === "Identifier" ? SCOPE_SIMPLE_CATCH : 0);
  13002. this.checkLVal(param, {
  13003. in: {
  13004. type: "CatchClause"
  13005. },
  13006. binding: BIND_CATCH_PARAM
  13007. });
  13008. return param;
  13009. }
  13010. parseTryStatement(node) {
  13011. this.next();
  13012. node.block = this.parseBlock();
  13013. node.handler = null;
  13014. if (this.match(62)) {
  13015. const clause = this.startNode();
  13016. this.next();
  13017. if (this.match(10)) {
  13018. this.expect(10);
  13019. clause.param = this.parseCatchClauseParam();
  13020. this.expect(11);
  13021. } else {
  13022. clause.param = null;
  13023. this.scope.enter(SCOPE_OTHER);
  13024. }
  13025. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13026. this.scope.exit();
  13027. node.handler = this.finishNode(clause, "CatchClause");
  13028. }
  13029. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13030. if (!node.handler && !node.finalizer) {
  13031. this.raise(Errors.NoCatchOrFinally, {
  13032. at: node
  13033. });
  13034. }
  13035. return this.finishNode(node, "TryStatement");
  13036. }
  13037. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13038. this.next();
  13039. this.parseVar(node, false, kind, allowMissingInitializer);
  13040. this.semicolon();
  13041. return this.finishNode(node, "VariableDeclaration");
  13042. }
  13043. parseWhileStatement(node) {
  13044. this.next();
  13045. node.test = this.parseHeaderExpression();
  13046. this.state.labels.push(loopLabel);
  13047. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13048. this.state.labels.pop();
  13049. return this.finishNode(node, "WhileStatement");
  13050. }
  13051. parseWithStatement(node) {
  13052. if (this.state.strict) {
  13053. this.raise(Errors.StrictWith, {
  13054. at: this.state.startLoc
  13055. });
  13056. }
  13057. this.next();
  13058. node.object = this.parseHeaderExpression();
  13059. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13060. return this.finishNode(node, "WithStatement");
  13061. }
  13062. parseEmptyStatement(node) {
  13063. this.next();
  13064. return this.finishNode(node, "EmptyStatement");
  13065. }
  13066. parseLabeledStatement(node, maybeName, expr, flags) {
  13067. for (const label of this.state.labels) {
  13068. if (label.name === maybeName) {
  13069. this.raise(Errors.LabelRedeclaration, {
  13070. at: expr,
  13071. labelName: maybeName
  13072. });
  13073. }
  13074. }
  13075. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
  13076. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13077. const label = this.state.labels[i];
  13078. if (label.statementStart === node.start) {
  13079. label.statementStart = this.state.start;
  13080. label.kind = kind;
  13081. } else {
  13082. break;
  13083. }
  13084. }
  13085. this.state.labels.push({
  13086. name: maybeName,
  13087. kind: kind,
  13088. statementStart: this.state.start
  13089. });
  13090. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13091. this.state.labels.pop();
  13092. node.label = expr;
  13093. return this.finishNode(node, "LabeledStatement");
  13094. }
  13095. parseExpressionStatement(node, expr, decorators) {
  13096. node.expression = expr;
  13097. this.semicolon();
  13098. return this.finishNode(node, "ExpressionStatement");
  13099. }
  13100. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13101. const node = this.startNode();
  13102. if (allowDirectives) {
  13103. this.state.strictErrors.clear();
  13104. }
  13105. this.expect(5);
  13106. if (createNewLexicalScope) {
  13107. this.scope.enter(SCOPE_OTHER);
  13108. }
  13109. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13110. if (createNewLexicalScope) {
  13111. this.scope.exit();
  13112. }
  13113. return this.finishNode(node, "BlockStatement");
  13114. }
  13115. isValidDirective(stmt) {
  13116. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13117. }
  13118. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13119. const body = node.body = [];
  13120. const directives = node.directives = [];
  13121. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13122. }
  13123. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13124. const oldStrict = this.state.strict;
  13125. let hasStrictModeDirective = false;
  13126. let parsedNonDirective = false;
  13127. while (!this.match(end)) {
  13128. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13129. if (directives && !parsedNonDirective) {
  13130. if (this.isValidDirective(stmt)) {
  13131. const directive = this.stmtToDirective(stmt);
  13132. directives.push(directive);
  13133. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13134. hasStrictModeDirective = true;
  13135. this.setStrict(true);
  13136. }
  13137. continue;
  13138. }
  13139. parsedNonDirective = true;
  13140. this.state.strictErrors.clear();
  13141. }
  13142. body.push(stmt);
  13143. }
  13144. if (afterBlockParse) {
  13145. afterBlockParse.call(this, hasStrictModeDirective);
  13146. }
  13147. if (!oldStrict) {
  13148. this.setStrict(false);
  13149. }
  13150. this.next();
  13151. }
  13152. parseFor(node, init) {
  13153. node.init = init;
  13154. this.semicolon(false);
  13155. node.test = this.match(13) ? null : this.parseExpression();
  13156. this.semicolon(false);
  13157. node.update = this.match(11) ? null : this.parseExpression();
  13158. this.expect(11);
  13159. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13160. this.scope.exit();
  13161. this.state.labels.pop();
  13162. return this.finishNode(node, "ForStatement");
  13163. }
  13164. parseForIn(node, init, awaitAt) {
  13165. const isForIn = this.match(58);
  13166. this.next();
  13167. if (isForIn) {
  13168. if (awaitAt !== null) this.unexpected(awaitAt);
  13169. } else {
  13170. node.await = awaitAt !== null;
  13171. }
  13172. 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")) {
  13173. this.raise(Errors.ForInOfLoopInitializer, {
  13174. at: init,
  13175. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13176. });
  13177. }
  13178. if (init.type === "AssignmentPattern") {
  13179. this.raise(Errors.InvalidLhs, {
  13180. at: init,
  13181. ancestor: {
  13182. type: "ForStatement"
  13183. }
  13184. });
  13185. }
  13186. node.left = init;
  13187. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13188. this.expect(11);
  13189. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13190. this.scope.exit();
  13191. this.state.labels.pop();
  13192. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13193. }
  13194. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13195. const declarations = node.declarations = [];
  13196. node.kind = kind;
  13197. for (;;) {
  13198. const decl = this.startNode();
  13199. this.parseVarId(decl, kind);
  13200. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13201. if (decl.init === null && !allowMissingInitializer) {
  13202. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(101)))) {
  13203. this.raise(Errors.DeclarationMissingInitializer, {
  13204. at: this.state.lastTokEndLoc,
  13205. kind: "destructuring"
  13206. });
  13207. } else if (kind === "const" && !(this.match(58) || this.isContextual(101))) {
  13208. this.raise(Errors.DeclarationMissingInitializer, {
  13209. at: this.state.lastTokEndLoc,
  13210. kind: "const"
  13211. });
  13212. }
  13213. }
  13214. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13215. if (!this.eat(12)) break;
  13216. }
  13217. return node;
  13218. }
  13219. parseVarId(decl, kind) {
  13220. if (kind === "using" && !this.inModule && this.match(96)) {
  13221. this.raise(Errors.AwaitInUsingBinding, {
  13222. at: this.state.startLoc
  13223. });
  13224. }
  13225. const id = this.parseBindingAtom();
  13226. this.checkLVal(id, {
  13227. in: {
  13228. type: "VariableDeclarator"
  13229. },
  13230. binding: kind === "var" ? BIND_VAR : BIND_LEXICAL
  13231. });
  13232. decl.id = id;
  13233. }
  13234. parseAsyncFunctionExpression(node) {
  13235. return this.parseFunction(node, 8);
  13236. }
  13237. parseFunction(node, flags = 0) {
  13238. const hangingDeclaration = flags & 2;
  13239. const isDeclaration = !!(flags & 1);
  13240. const requireId = isDeclaration && !(flags & 4);
  13241. const isAsync = !!(flags & 8);
  13242. this.initFunction(node, isAsync);
  13243. if (this.match(55)) {
  13244. if (hangingDeclaration) {
  13245. this.raise(Errors.GeneratorInSingleStatementContext, {
  13246. at: this.state.startLoc
  13247. });
  13248. }
  13249. this.next();
  13250. node.generator = true;
  13251. }
  13252. if (isDeclaration) {
  13253. node.id = this.parseFunctionId(requireId);
  13254. }
  13255. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13256. this.state.maybeInArrowParameters = false;
  13257. this.scope.enter(SCOPE_FUNCTION);
  13258. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13259. if (!isDeclaration) {
  13260. node.id = this.parseFunctionId();
  13261. }
  13262. this.parseFunctionParams(node, false);
  13263. this.withSmartMixTopicForbiddingContext(() => {
  13264. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13265. });
  13266. this.prodParam.exit();
  13267. this.scope.exit();
  13268. if (isDeclaration && !hangingDeclaration) {
  13269. this.registerFunctionStatementId(node);
  13270. }
  13271. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13272. return node;
  13273. }
  13274. parseFunctionId(requireId) {
  13275. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13276. }
  13277. parseFunctionParams(node, isConstructor) {
  13278. this.expect(10);
  13279. this.expressionScope.enter(newParameterDeclarationScope());
  13280. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13281. this.expressionScope.exit();
  13282. }
  13283. registerFunctionStatementId(node) {
  13284. if (!node.id) return;
  13285. 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);
  13286. }
  13287. parseClass(node, isStatement, optionalId) {
  13288. this.next();
  13289. const oldStrict = this.state.strict;
  13290. this.state.strict = true;
  13291. this.parseClassId(node, isStatement, optionalId);
  13292. this.parseClassSuper(node);
  13293. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13294. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13295. }
  13296. isClassProperty() {
  13297. return this.match(29) || this.match(13) || this.match(8);
  13298. }
  13299. isClassMethod() {
  13300. return this.match(10);
  13301. }
  13302. isNonstaticConstructor(method) {
  13303. return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
  13304. }
  13305. parseClassBody(hadSuperClass, oldStrict) {
  13306. this.classScope.enter();
  13307. const state = {
  13308. hadConstructor: false,
  13309. hadSuperClass
  13310. };
  13311. let decorators = [];
  13312. const classBody = this.startNode();
  13313. classBody.body = [];
  13314. this.expect(5);
  13315. this.withSmartMixTopicForbiddingContext(() => {
  13316. while (!this.match(8)) {
  13317. if (this.eat(13)) {
  13318. if (decorators.length > 0) {
  13319. throw this.raise(Errors.DecoratorSemicolon, {
  13320. at: this.state.lastTokEndLoc
  13321. });
  13322. }
  13323. continue;
  13324. }
  13325. if (this.match(26)) {
  13326. decorators.push(this.parseDecorator());
  13327. continue;
  13328. }
  13329. const member = this.startNode();
  13330. if (decorators.length) {
  13331. member.decorators = decorators;
  13332. this.resetStartLocationFromNode(member, decorators[0]);
  13333. decorators = [];
  13334. }
  13335. this.parseClassMember(classBody, member, state);
  13336. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13337. this.raise(Errors.DecoratorConstructor, {
  13338. at: member
  13339. });
  13340. }
  13341. }
  13342. });
  13343. this.state.strict = oldStrict;
  13344. this.next();
  13345. if (decorators.length) {
  13346. throw this.raise(Errors.TrailingDecorator, {
  13347. at: this.state.startLoc
  13348. });
  13349. }
  13350. this.classScope.exit();
  13351. return this.finishNode(classBody, "ClassBody");
  13352. }
  13353. parseClassMemberFromModifier(classBody, member) {
  13354. const key = this.parseIdentifier(true);
  13355. if (this.isClassMethod()) {
  13356. const method = member;
  13357. method.kind = "method";
  13358. method.computed = false;
  13359. method.key = key;
  13360. method.static = false;
  13361. this.pushClassMethod(classBody, method, false, false, false, false);
  13362. return true;
  13363. } else if (this.isClassProperty()) {
  13364. const prop = member;
  13365. prop.computed = false;
  13366. prop.key = key;
  13367. prop.static = false;
  13368. classBody.body.push(this.parseClassProperty(prop));
  13369. return true;
  13370. }
  13371. this.resetPreviousNodeTrailingComments(key);
  13372. return false;
  13373. }
  13374. parseClassMember(classBody, member, state) {
  13375. const isStatic = this.isContextual(104);
  13376. if (isStatic) {
  13377. if (this.parseClassMemberFromModifier(classBody, member)) {
  13378. return;
  13379. }
  13380. if (this.eat(5)) {
  13381. this.parseClassStaticBlock(classBody, member);
  13382. return;
  13383. }
  13384. }
  13385. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13386. }
  13387. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13388. const publicMethod = member;
  13389. const privateMethod = member;
  13390. const publicProp = member;
  13391. const privateProp = member;
  13392. const accessorProp = member;
  13393. const method = publicMethod;
  13394. const publicMember = publicMethod;
  13395. member.static = isStatic;
  13396. this.parsePropertyNamePrefixOperator(member);
  13397. if (this.eat(55)) {
  13398. method.kind = "method";
  13399. const isPrivateName = this.match(136);
  13400. this.parseClassElementName(method);
  13401. if (isPrivateName) {
  13402. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13403. return;
  13404. }
  13405. if (this.isNonstaticConstructor(publicMethod)) {
  13406. this.raise(Errors.ConstructorIsGenerator, {
  13407. at: publicMethod.key
  13408. });
  13409. }
  13410. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13411. return;
  13412. }
  13413. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  13414. const isPrivate = this.match(136);
  13415. const key = this.parseClassElementName(member);
  13416. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13417. this.parsePostMemberNameModifiers(publicMember);
  13418. if (this.isClassMethod()) {
  13419. method.kind = "method";
  13420. if (isPrivate) {
  13421. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13422. return;
  13423. }
  13424. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13425. let allowsDirectSuper = false;
  13426. if (isConstructor) {
  13427. publicMethod.kind = "constructor";
  13428. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13429. this.raise(Errors.DuplicateConstructor, {
  13430. at: key
  13431. });
  13432. }
  13433. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13434. this.raise(Errors.OverrideOnConstructor, {
  13435. at: key
  13436. });
  13437. }
  13438. state.hadConstructor = true;
  13439. allowsDirectSuper = state.hadSuperClass;
  13440. }
  13441. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13442. } else if (this.isClassProperty()) {
  13443. if (isPrivate) {
  13444. this.pushClassPrivateProperty(classBody, privateProp);
  13445. } else {
  13446. this.pushClassProperty(classBody, publicProp);
  13447. }
  13448. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  13449. this.resetPreviousNodeTrailingComments(key);
  13450. const isGenerator = this.eat(55);
  13451. if (publicMember.optional) {
  13452. this.unexpected(maybeQuestionTokenStartLoc);
  13453. }
  13454. method.kind = "method";
  13455. const isPrivate = this.match(136);
  13456. this.parseClassElementName(method);
  13457. this.parsePostMemberNameModifiers(publicMember);
  13458. if (isPrivate) {
  13459. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13460. } else {
  13461. if (this.isNonstaticConstructor(publicMethod)) {
  13462. this.raise(Errors.ConstructorIsAsync, {
  13463. at: publicMethod.key
  13464. });
  13465. }
  13466. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13467. }
  13468. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
  13469. this.resetPreviousNodeTrailingComments(key);
  13470. method.kind = key.name;
  13471. const isPrivate = this.match(136);
  13472. this.parseClassElementName(publicMethod);
  13473. if (isPrivate) {
  13474. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13475. } else {
  13476. if (this.isNonstaticConstructor(publicMethod)) {
  13477. this.raise(Errors.ConstructorIsAccessor, {
  13478. at: publicMethod.key
  13479. });
  13480. }
  13481. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13482. }
  13483. this.checkGetterSetterParams(publicMethod);
  13484. } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
  13485. this.expectPlugin("decoratorAutoAccessors");
  13486. this.resetPreviousNodeTrailingComments(key);
  13487. const isPrivate = this.match(136);
  13488. this.parseClassElementName(publicProp);
  13489. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13490. } else if (this.isLineTerminator()) {
  13491. if (isPrivate) {
  13492. this.pushClassPrivateProperty(classBody, privateProp);
  13493. } else {
  13494. this.pushClassProperty(classBody, publicProp);
  13495. }
  13496. } else {
  13497. this.unexpected();
  13498. }
  13499. }
  13500. parseClassElementName(member) {
  13501. const {
  13502. type,
  13503. value
  13504. } = this.state;
  13505. if ((type === 130 || type === 131) && member.static && value === "prototype") {
  13506. this.raise(Errors.StaticPrototype, {
  13507. at: this.state.startLoc
  13508. });
  13509. }
  13510. if (type === 136) {
  13511. if (value === "constructor") {
  13512. this.raise(Errors.ConstructorClassPrivateField, {
  13513. at: this.state.startLoc
  13514. });
  13515. }
  13516. const key = this.parsePrivateName();
  13517. member.key = key;
  13518. return key;
  13519. }
  13520. return this.parsePropertyName(member);
  13521. }
  13522. parseClassStaticBlock(classBody, member) {
  13523. var _member$decorators;
  13524. this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER);
  13525. const oldLabels = this.state.labels;
  13526. this.state.labels = [];
  13527. this.prodParam.enter(PARAM);
  13528. const body = member.body = [];
  13529. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13530. this.prodParam.exit();
  13531. this.scope.exit();
  13532. this.state.labels = oldLabels;
  13533. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13534. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13535. this.raise(Errors.DecoratorStaticBlock, {
  13536. at: member
  13537. });
  13538. }
  13539. }
  13540. pushClassProperty(classBody, prop) {
  13541. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  13542. this.raise(Errors.ConstructorClassField, {
  13543. at: prop.key
  13544. });
  13545. }
  13546. classBody.body.push(this.parseClassProperty(prop));
  13547. }
  13548. pushClassPrivateProperty(classBody, prop) {
  13549. const node = this.parseClassPrivateProperty(prop);
  13550. classBody.body.push(node);
  13551. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  13552. }
  13553. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13554. if (!isPrivate && !prop.computed) {
  13555. const key = prop.key;
  13556. if (key.name === "constructor" || key.value === "constructor") {
  13557. this.raise(Errors.ConstructorClassField, {
  13558. at: key
  13559. });
  13560. }
  13561. }
  13562. const node = this.parseClassAccessorProperty(prop);
  13563. classBody.body.push(node);
  13564. if (isPrivate) {
  13565. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  13566. }
  13567. }
  13568. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13569. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13570. }
  13571. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13572. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13573. classBody.body.push(node);
  13574. 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;
  13575. this.declareClassPrivateMethodInScope(node, kind);
  13576. }
  13577. declareClassPrivateMethodInScope(node, kind) {
  13578. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13579. }
  13580. parsePostMemberNameModifiers(methodOrProp) {}
  13581. parseClassPrivateProperty(node) {
  13582. this.parseInitializer(node);
  13583. this.semicolon();
  13584. return this.finishNode(node, "ClassPrivateProperty");
  13585. }
  13586. parseClassProperty(node) {
  13587. this.parseInitializer(node);
  13588. this.semicolon();
  13589. return this.finishNode(node, "ClassProperty");
  13590. }
  13591. parseClassAccessorProperty(node) {
  13592. this.parseInitializer(node);
  13593. this.semicolon();
  13594. return this.finishNode(node, "ClassAccessorProperty");
  13595. }
  13596. parseInitializer(node) {
  13597. this.scope.enter(SCOPE_CLASS | SCOPE_SUPER);
  13598. this.expressionScope.enter(newExpressionScope());
  13599. this.prodParam.enter(PARAM);
  13600. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13601. this.expressionScope.exit();
  13602. this.prodParam.exit();
  13603. this.scope.exit();
  13604. }
  13605. parseClassId(node, isStatement, optionalId, bindingType = BIND_CLASS) {
  13606. if (tokenIsIdentifier(this.state.type)) {
  13607. node.id = this.parseIdentifier();
  13608. if (isStatement) {
  13609. this.declareNameFromIdentifier(node.id, bindingType);
  13610. }
  13611. } else {
  13612. if (optionalId || !isStatement) {
  13613. node.id = null;
  13614. } else {
  13615. throw this.raise(Errors.MissingClassName, {
  13616. at: this.state.startLoc
  13617. });
  13618. }
  13619. }
  13620. }
  13621. parseClassSuper(node) {
  13622. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13623. }
  13624. parseExport(node, decorators) {
  13625. const hasDefault = this.maybeParseExportDefaultSpecifier(node);
  13626. const parseAfterDefault = !hasDefault || this.eat(12);
  13627. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13628. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13629. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13630. const isFromRequired = hasDefault || hasStar;
  13631. if (hasStar && !hasNamespace) {
  13632. if (hasDefault) this.unexpected();
  13633. if (decorators) {
  13634. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13635. at: node
  13636. });
  13637. }
  13638. this.parseExportFrom(node, true);
  13639. return this.finishNode(node, "ExportAllDeclaration");
  13640. }
  13641. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13642. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13643. this.unexpected(null, 5);
  13644. }
  13645. if (hasNamespace && parseAfterNamespace) {
  13646. this.unexpected(null, 97);
  13647. }
  13648. let hasDeclaration;
  13649. if (isFromRequired || hasSpecifiers) {
  13650. hasDeclaration = false;
  13651. if (decorators) {
  13652. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13653. at: node
  13654. });
  13655. }
  13656. this.parseExportFrom(node, isFromRequired);
  13657. } else {
  13658. hasDeclaration = this.maybeParseExportDeclaration(node);
  13659. }
  13660. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13661. var _node2$declaration;
  13662. const node2 = node;
  13663. this.checkExport(node2, true, false, !!node2.source);
  13664. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13665. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13666. } else if (decorators) {
  13667. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13668. at: node
  13669. });
  13670. }
  13671. return this.finishNode(node2, "ExportNamedDeclaration");
  13672. }
  13673. if (this.eat(65)) {
  13674. const node2 = node;
  13675. const decl = this.parseExportDefaultExpression();
  13676. node2.declaration = decl;
  13677. if (decl.type === "ClassDeclaration") {
  13678. this.maybeTakeDecorators(decorators, decl, node2);
  13679. } else if (decorators) {
  13680. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13681. at: node
  13682. });
  13683. }
  13684. this.checkExport(node2, true, true);
  13685. return this.finishNode(node2, "ExportDefaultDeclaration");
  13686. }
  13687. this.unexpected(null, 5);
  13688. }
  13689. eatExportStar(node) {
  13690. return this.eat(55);
  13691. }
  13692. maybeParseExportDefaultSpecifier(node) {
  13693. if (this.isExportDefaultSpecifier()) {
  13694. this.expectPlugin("exportDefaultFrom");
  13695. const specifier = this.startNode();
  13696. specifier.exported = this.parseIdentifier(true);
  13697. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13698. return true;
  13699. }
  13700. return false;
  13701. }
  13702. maybeParseExportNamespaceSpecifier(node) {
  13703. if (this.isContextual(93)) {
  13704. if (!node.specifiers) node.specifiers = [];
  13705. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13706. this.next();
  13707. specifier.exported = this.parseModuleExportName();
  13708. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13709. return true;
  13710. }
  13711. return false;
  13712. }
  13713. maybeParseExportNamedSpecifiers(node) {
  13714. if (this.match(5)) {
  13715. if (!node.specifiers) node.specifiers = [];
  13716. const isTypeExport = node.exportKind === "type";
  13717. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13718. node.source = null;
  13719. node.declaration = null;
  13720. if (this.hasPlugin("importAssertions")) {
  13721. node.assertions = [];
  13722. }
  13723. return true;
  13724. }
  13725. return false;
  13726. }
  13727. maybeParseExportDeclaration(node) {
  13728. if (this.shouldParseExportDeclaration()) {
  13729. node.specifiers = [];
  13730. node.source = null;
  13731. if (this.hasPlugin("importAssertions")) {
  13732. node.assertions = [];
  13733. }
  13734. node.declaration = this.parseExportDeclaration(node);
  13735. return true;
  13736. }
  13737. return false;
  13738. }
  13739. isAsyncFunction() {
  13740. if (!this.isContextual(95)) return false;
  13741. const next = this.nextTokenStart();
  13742. return !lineBreak.test(this.input.slice(this.state.pos, next)) && this.isUnparsedContextual(next, "function");
  13743. }
  13744. parseExportDefaultExpression() {
  13745. const expr = this.startNode();
  13746. if (this.match(68)) {
  13747. this.next();
  13748. return this.parseFunction(expr, 1 | 4);
  13749. } else if (this.isAsyncFunction()) {
  13750. this.next();
  13751. this.next();
  13752. return this.parseFunction(expr, 1 | 4 | 8);
  13753. }
  13754. if (this.match(80)) {
  13755. return this.parseClass(expr, true, true);
  13756. }
  13757. if (this.match(26)) {
  13758. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13759. this.raise(Errors.DecoratorBeforeExport, {
  13760. at: this.state.startLoc
  13761. });
  13762. }
  13763. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13764. }
  13765. if (this.match(75) || this.match(74) || this.isLet()) {
  13766. throw this.raise(Errors.UnsupportedDefaultExport, {
  13767. at: this.state.startLoc
  13768. });
  13769. }
  13770. const res = this.parseMaybeAssignAllowIn();
  13771. this.semicolon();
  13772. return res;
  13773. }
  13774. parseExportDeclaration(node) {
  13775. if (this.match(80)) {
  13776. const node = this.parseClass(this.startNode(), true, false);
  13777. return node;
  13778. }
  13779. return this.parseStatementListItem();
  13780. }
  13781. isExportDefaultSpecifier() {
  13782. const {
  13783. type
  13784. } = this.state;
  13785. if (tokenIsIdentifier(type)) {
  13786. if (type === 95 && !this.state.containsEsc || type === 99) {
  13787. return false;
  13788. }
  13789. if ((type === 128 || type === 127) && !this.state.containsEsc) {
  13790. const {
  13791. type: nextType
  13792. } = this.lookahead();
  13793. if (tokenIsIdentifier(nextType) && nextType !== 97 || nextType === 5) {
  13794. this.expectOnePlugin(["flow", "typescript"]);
  13795. return false;
  13796. }
  13797. }
  13798. } else if (!this.match(65)) {
  13799. return false;
  13800. }
  13801. const next = this.nextTokenStart();
  13802. const hasFrom = this.isUnparsedContextual(next, "from");
  13803. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13804. return true;
  13805. }
  13806. if (this.match(65) && hasFrom) {
  13807. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13808. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13809. }
  13810. return false;
  13811. }
  13812. parseExportFrom(node, expect) {
  13813. if (this.eatContextual(97)) {
  13814. node.source = this.parseImportSource();
  13815. this.checkExport(node);
  13816. const assertions = this.maybeParseImportAssertions();
  13817. if (assertions) {
  13818. node.assertions = assertions;
  13819. this.checkJSONModuleImport(node);
  13820. }
  13821. } else if (expect) {
  13822. this.unexpected();
  13823. }
  13824. this.semicolon();
  13825. }
  13826. shouldParseExportDeclaration() {
  13827. const {
  13828. type
  13829. } = this.state;
  13830. if (type === 26) {
  13831. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13832. if (this.hasPlugin("decorators")) {
  13833. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13834. this.raise(Errors.DecoratorBeforeExport, {
  13835. at: this.state.startLoc
  13836. });
  13837. }
  13838. return true;
  13839. }
  13840. }
  13841. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13842. }
  13843. checkExport(node, checkNames, isDefault, isFrom) {
  13844. if (checkNames) {
  13845. if (isDefault) {
  13846. this.checkDuplicateExports(node, "default");
  13847. if (this.hasPlugin("exportDefaultFrom")) {
  13848. var _declaration$extra;
  13849. const declaration = node.declaration;
  13850. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13851. this.raise(Errors.ExportDefaultFromAsIdentifier, {
  13852. at: declaration
  13853. });
  13854. }
  13855. }
  13856. } else if (node.specifiers && node.specifiers.length) {
  13857. for (const specifier of node.specifiers) {
  13858. const {
  13859. exported
  13860. } = specifier;
  13861. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13862. this.checkDuplicateExports(specifier, exportName);
  13863. if (!isFrom && specifier.local) {
  13864. const {
  13865. local
  13866. } = specifier;
  13867. if (local.type !== "Identifier") {
  13868. this.raise(Errors.ExportBindingIsString, {
  13869. at: specifier,
  13870. localName: local.value,
  13871. exportName
  13872. });
  13873. } else {
  13874. this.checkReservedWord(local.name, local.loc.start, true, false);
  13875. this.scope.checkLocalExport(local);
  13876. }
  13877. }
  13878. }
  13879. } else if (node.declaration) {
  13880. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  13881. const id = node.declaration.id;
  13882. if (!id) throw new Error("Assertion failure");
  13883. this.checkDuplicateExports(node, id.name);
  13884. } else if (node.declaration.type === "VariableDeclaration") {
  13885. for (const declaration of node.declaration.declarations) {
  13886. this.checkDeclaration(declaration.id);
  13887. }
  13888. }
  13889. }
  13890. }
  13891. }
  13892. checkDeclaration(node) {
  13893. if (node.type === "Identifier") {
  13894. this.checkDuplicateExports(node, node.name);
  13895. } else if (node.type === "ObjectPattern") {
  13896. for (const prop of node.properties) {
  13897. this.checkDeclaration(prop);
  13898. }
  13899. } else if (node.type === "ArrayPattern") {
  13900. for (const elem of node.elements) {
  13901. if (elem) {
  13902. this.checkDeclaration(elem);
  13903. }
  13904. }
  13905. } else if (node.type === "ObjectProperty") {
  13906. this.checkDeclaration(node.value);
  13907. } else if (node.type === "RestElement") {
  13908. this.checkDeclaration(node.argument);
  13909. } else if (node.type === "AssignmentPattern") {
  13910. this.checkDeclaration(node.left);
  13911. }
  13912. }
  13913. checkDuplicateExports(node, exportName) {
  13914. if (this.exportedIdentifiers.has(exportName)) {
  13915. if (exportName === "default") {
  13916. this.raise(Errors.DuplicateDefaultExport, {
  13917. at: node
  13918. });
  13919. } else {
  13920. this.raise(Errors.DuplicateExport, {
  13921. at: node,
  13922. exportName
  13923. });
  13924. }
  13925. }
  13926. this.exportedIdentifiers.add(exportName);
  13927. }
  13928. parseExportSpecifiers(isInTypeExport) {
  13929. const nodes = [];
  13930. let first = true;
  13931. this.expect(5);
  13932. while (!this.eat(8)) {
  13933. if (first) {
  13934. first = false;
  13935. } else {
  13936. this.expect(12);
  13937. if (this.eat(8)) break;
  13938. }
  13939. const isMaybeTypeOnly = this.isContextual(128);
  13940. const isString = this.match(131);
  13941. const node = this.startNode();
  13942. node.local = this.parseModuleExportName();
  13943. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13944. }
  13945. return nodes;
  13946. }
  13947. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  13948. if (this.eatContextual(93)) {
  13949. node.exported = this.parseModuleExportName();
  13950. } else if (isString) {
  13951. node.exported = cloneStringLiteral(node.local);
  13952. } else if (!node.exported) {
  13953. node.exported = cloneIdentifier(node.local);
  13954. }
  13955. return this.finishNode(node, "ExportSpecifier");
  13956. }
  13957. parseModuleExportName() {
  13958. if (this.match(131)) {
  13959. const result = this.parseStringLiteral(this.state.value);
  13960. const surrogate = result.value.match(loneSurrogate);
  13961. if (surrogate) {
  13962. this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
  13963. at: result,
  13964. surrogateCharCode: surrogate[0].charCodeAt(0)
  13965. });
  13966. }
  13967. return result;
  13968. }
  13969. return this.parseIdentifier(true);
  13970. }
  13971. isJSONModuleImport(node) {
  13972. if (node.assertions != null) {
  13973. return node.assertions.some(({
  13974. key,
  13975. value
  13976. }) => {
  13977. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  13978. });
  13979. }
  13980. return false;
  13981. }
  13982. checkImportReflection(node) {
  13983. if (node.module) {
  13984. var _node$assertions;
  13985. if (node.specifiers.length !== 1 || node.specifiers[0].type !== "ImportDefaultSpecifier") {
  13986. this.raise(Errors.ImportReflectionNotBinding, {
  13987. at: node.specifiers[0].loc.start
  13988. });
  13989. }
  13990. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  13991. this.raise(Errors.ImportReflectionHasAssertion, {
  13992. at: node.specifiers[0].loc.start
  13993. });
  13994. }
  13995. }
  13996. }
  13997. checkJSONModuleImport(node) {
  13998. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  13999. const {
  14000. specifiers
  14001. } = node;
  14002. if (specifiers != null) {
  14003. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14004. let imported;
  14005. if (specifier.type === "ExportSpecifier") {
  14006. imported = specifier.local;
  14007. } else if (specifier.type === "ImportSpecifier") {
  14008. imported = specifier.imported;
  14009. }
  14010. if (imported !== undefined) {
  14011. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14012. }
  14013. });
  14014. if (nonDefaultNamedSpecifier !== undefined) {
  14015. this.raise(Errors.ImportJSONBindingNotDefault, {
  14016. at: nonDefaultNamedSpecifier.loc.start
  14017. });
  14018. }
  14019. }
  14020. }
  14021. }
  14022. parseMaybeImportReflection(node) {
  14023. let isImportReflection = false;
  14024. if (this.isContextual(125)) {
  14025. const lookahead = this.lookahead();
  14026. const nextType = lookahead.type;
  14027. if (tokenIsIdentifier(nextType)) {
  14028. if (nextType !== 97) {
  14029. isImportReflection = true;
  14030. } else {
  14031. const nextNextTokenFirstChar = this.input.charCodeAt(this.nextTokenStartSince(lookahead.end));
  14032. if (nextNextTokenFirstChar === 102) {
  14033. isImportReflection = true;
  14034. }
  14035. }
  14036. } else if (nextType !== 12) {
  14037. isImportReflection = true;
  14038. }
  14039. }
  14040. if (isImportReflection) {
  14041. this.expectPlugin("importReflection");
  14042. this.next();
  14043. node.module = true;
  14044. } else if (this.hasPlugin("importReflection")) {
  14045. node.module = false;
  14046. }
  14047. }
  14048. parseImport(node) {
  14049. node.specifiers = [];
  14050. if (!this.match(131)) {
  14051. this.parseMaybeImportReflection(node);
  14052. const hasDefault = this.maybeParseDefaultImportSpecifier(node);
  14053. const parseNext = !hasDefault || this.eat(12);
  14054. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14055. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14056. this.expectContextual(97);
  14057. }
  14058. node.source = this.parseImportSource();
  14059. const assertions = this.maybeParseImportAssertions();
  14060. if (assertions) {
  14061. node.assertions = assertions;
  14062. } else {
  14063. const attributes = this.maybeParseModuleAttributes();
  14064. if (attributes) {
  14065. node.attributes = attributes;
  14066. }
  14067. }
  14068. this.checkImportReflection(node);
  14069. this.checkJSONModuleImport(node);
  14070. this.semicolon();
  14071. return this.finishNode(node, "ImportDeclaration");
  14072. }
  14073. parseImportSource() {
  14074. if (!this.match(131)) this.unexpected();
  14075. return this.parseExprAtom();
  14076. }
  14077. shouldParseDefaultImport(node) {
  14078. return tokenIsIdentifier(this.state.type);
  14079. }
  14080. parseImportSpecifierLocal(node, specifier, type) {
  14081. specifier.local = this.parseIdentifier();
  14082. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14083. }
  14084. finishImportSpecifier(specifier, type, bindingType = BIND_LEXICAL) {
  14085. this.checkLVal(specifier.local, {
  14086. in: {
  14087. type
  14088. },
  14089. binding: bindingType
  14090. });
  14091. return this.finishNode(specifier, type);
  14092. }
  14093. parseAssertEntries() {
  14094. const attrs = [];
  14095. const attrNames = new Set();
  14096. do {
  14097. if (this.match(8)) {
  14098. break;
  14099. }
  14100. const node = this.startNode();
  14101. const keyName = this.state.value;
  14102. if (attrNames.has(keyName)) {
  14103. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14104. at: this.state.startLoc,
  14105. key: keyName
  14106. });
  14107. }
  14108. attrNames.add(keyName);
  14109. if (this.match(131)) {
  14110. node.key = this.parseStringLiteral(keyName);
  14111. } else {
  14112. node.key = this.parseIdentifier(true);
  14113. }
  14114. this.expect(14);
  14115. if (!this.match(131)) {
  14116. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14117. at: this.state.startLoc
  14118. });
  14119. }
  14120. node.value = this.parseStringLiteral(this.state.value);
  14121. attrs.push(this.finishNode(node, "ImportAttribute"));
  14122. } while (this.eat(12));
  14123. return attrs;
  14124. }
  14125. maybeParseModuleAttributes() {
  14126. if (this.match(76) && !this.hasPrecedingLineBreak()) {
  14127. this.expectPlugin("moduleAttributes");
  14128. this.next();
  14129. } else {
  14130. if (this.hasPlugin("moduleAttributes")) return [];
  14131. return null;
  14132. }
  14133. const attrs = [];
  14134. const attributes = new Set();
  14135. do {
  14136. const node = this.startNode();
  14137. node.key = this.parseIdentifier(true);
  14138. if (node.key.name !== "type") {
  14139. this.raise(Errors.ModuleAttributeDifferentFromType, {
  14140. at: node.key
  14141. });
  14142. }
  14143. if (attributes.has(node.key.name)) {
  14144. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14145. at: node.key,
  14146. key: node.key.name
  14147. });
  14148. }
  14149. attributes.add(node.key.name);
  14150. this.expect(14);
  14151. if (!this.match(131)) {
  14152. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14153. at: this.state.startLoc
  14154. });
  14155. }
  14156. node.value = this.parseStringLiteral(this.state.value);
  14157. this.finishNode(node, "ImportAttribute");
  14158. attrs.push(node);
  14159. } while (this.eat(12));
  14160. return attrs;
  14161. }
  14162. maybeParseImportAssertions() {
  14163. if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14164. this.expectPlugin("importAssertions");
  14165. this.next();
  14166. } else {
  14167. if (this.hasPlugin("importAssertions")) return [];
  14168. return null;
  14169. }
  14170. this.eat(5);
  14171. const attrs = this.parseAssertEntries();
  14172. this.eat(8);
  14173. return attrs;
  14174. }
  14175. maybeParseDefaultImportSpecifier(node) {
  14176. if (this.shouldParseDefaultImport(node)) {
  14177. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14178. return true;
  14179. }
  14180. return false;
  14181. }
  14182. maybeParseStarImportSpecifier(node) {
  14183. if (this.match(55)) {
  14184. const specifier = this.startNode();
  14185. this.next();
  14186. this.expectContextual(93);
  14187. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14188. return true;
  14189. }
  14190. return false;
  14191. }
  14192. parseNamedImportSpecifiers(node) {
  14193. let first = true;
  14194. this.expect(5);
  14195. while (!this.eat(8)) {
  14196. if (first) {
  14197. first = false;
  14198. } else {
  14199. if (this.eat(14)) {
  14200. throw this.raise(Errors.DestructureNamedImport, {
  14201. at: this.state.startLoc
  14202. });
  14203. }
  14204. this.expect(12);
  14205. if (this.eat(8)) break;
  14206. }
  14207. const specifier = this.startNode();
  14208. const importedIsString = this.match(131);
  14209. const isMaybeTypeOnly = this.isContextual(128);
  14210. specifier.imported = this.parseModuleExportName();
  14211. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14212. node.specifiers.push(importSpecifier);
  14213. }
  14214. }
  14215. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14216. if (this.eatContextual(93)) {
  14217. specifier.local = this.parseIdentifier();
  14218. } else {
  14219. const {
  14220. imported
  14221. } = specifier;
  14222. if (importedIsString) {
  14223. throw this.raise(Errors.ImportBindingIsString, {
  14224. at: specifier,
  14225. importName: imported.value
  14226. });
  14227. }
  14228. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14229. if (!specifier.local) {
  14230. specifier.local = cloneIdentifier(imported);
  14231. }
  14232. }
  14233. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14234. }
  14235. isThisParam(param) {
  14236. return param.type === "Identifier" && param.name === "this";
  14237. }
  14238. }
  14239. class Parser extends StatementParser {
  14240. constructor(options, input) {
  14241. options = getOptions(options);
  14242. super(options, input);
  14243. this.options = options;
  14244. this.initializeScopes();
  14245. this.plugins = pluginsMap(this.options.plugins);
  14246. this.filename = options.sourceFilename;
  14247. }
  14248. getScopeHandler() {
  14249. return ScopeHandler;
  14250. }
  14251. parse() {
  14252. this.enterInitialScopes();
  14253. const file = this.startNode();
  14254. const program = this.startNode();
  14255. this.nextToken();
  14256. file.errors = null;
  14257. this.parseTopLevel(file, program);
  14258. file.errors = this.state.errors;
  14259. return file;
  14260. }
  14261. }
  14262. function pluginsMap(plugins) {
  14263. const pluginMap = new Map();
  14264. for (const plugin of plugins) {
  14265. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  14266. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  14267. }
  14268. return pluginMap;
  14269. }
  14270. function parse(input, options) {
  14271. var _options;
  14272. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14273. options = Object.assign({}, options);
  14274. try {
  14275. options.sourceType = "module";
  14276. const parser = getParser(options, input);
  14277. const ast = parser.parse();
  14278. if (parser.sawUnambiguousESM) {
  14279. return ast;
  14280. }
  14281. if (parser.ambiguousScriptDifferentAst) {
  14282. try {
  14283. options.sourceType = "script";
  14284. return getParser(options, input).parse();
  14285. } catch (_unused) {}
  14286. } else {
  14287. ast.program.sourceType = "script";
  14288. }
  14289. return ast;
  14290. } catch (moduleError) {
  14291. try {
  14292. options.sourceType = "script";
  14293. return getParser(options, input).parse();
  14294. } catch (_unused2) {}
  14295. throw moduleError;
  14296. }
  14297. } else {
  14298. return getParser(options, input).parse();
  14299. }
  14300. }
  14301. function parseExpression(input, options) {
  14302. const parser = getParser(options, input);
  14303. if (parser.options.strictMode) {
  14304. parser.state.strict = true;
  14305. }
  14306. return parser.getExpression();
  14307. }
  14308. function generateExportedTokenTypes(internalTokenTypes) {
  14309. const tokenTypes = {};
  14310. for (const typeName of Object.keys(internalTokenTypes)) {
  14311. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14312. }
  14313. return tokenTypes;
  14314. }
  14315. const tokTypes = generateExportedTokenTypes(tt);
  14316. function getParser(options, input) {
  14317. let cls = Parser;
  14318. if (options != null && options.plugins) {
  14319. validatePlugins(options.plugins);
  14320. cls = getParserClass(options.plugins);
  14321. }
  14322. return new cls(options, input);
  14323. }
  14324. const parserClassCache = {};
  14325. function getParserClass(pluginsFromOptions) {
  14326. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  14327. const key = pluginList.join("/");
  14328. let cls = parserClassCache[key];
  14329. if (!cls) {
  14330. cls = Parser;
  14331. for (const plugin of pluginList) {
  14332. cls = mixinPlugins[plugin](cls);
  14333. }
  14334. parserClassCache[key] = cls;
  14335. }
  14336. return cls;
  14337. }
  14338. exports.parse = parse;
  14339. exports.parseExpression = parseExpression;
  14340. exports.tokTypes = tokTypes;
  14341. //# sourceMappingURL=index.js.map