index.js 475 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. function _objectWithoutPropertiesLoose(source, excluded) {
  6. if (source == null) return {};
  7. var target = {};
  8. var sourceKeys = Object.keys(source);
  9. var key, i;
  10. for (i = 0; i < sourceKeys.length; i++) {
  11. key = sourceKeys[i];
  12. if (excluded.indexOf(key) >= 0) continue;
  13. target[key] = source[key];
  14. }
  15. return target;
  16. }
  17. class Position {
  18. constructor(line, col, index) {
  19. this.line = void 0;
  20. this.column = void 0;
  21. this.index = void 0;
  22. this.line = line;
  23. this.column = col;
  24. this.index = index;
  25. }
  26. }
  27. class SourceLocation {
  28. constructor(start, end) {
  29. this.start = void 0;
  30. this.end = void 0;
  31. this.filename = void 0;
  32. this.identifierName = void 0;
  33. this.start = start;
  34. this.end = end;
  35. }
  36. }
  37. function createPositionWithColumnOffset(position, columnOffset) {
  38. const {
  39. line,
  40. column,
  41. index
  42. } = position;
  43. return new Position(line, column + columnOffset, index + columnOffset);
  44. }
  45. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  46. var ModuleErrors = {
  47. ImportMetaOutsideModule: {
  48. message: `import.meta may appear only with 'sourceType: "module"'`,
  49. code
  50. },
  51. ImportOutsideModule: {
  52. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  53. code
  54. }
  55. };
  56. const NodeDescriptions = {
  57. ArrayPattern: "array destructuring pattern",
  58. AssignmentExpression: "assignment expression",
  59. AssignmentPattern: "assignment expression",
  60. ArrowFunctionExpression: "arrow function expression",
  61. ConditionalExpression: "conditional expression",
  62. CatchClause: "catch clause",
  63. ForOfStatement: "for-of statement",
  64. ForInStatement: "for-in statement",
  65. ForStatement: "for-loop",
  66. FormalParameters: "function parameter list",
  67. Identifier: "identifier",
  68. ImportSpecifier: "import specifier",
  69. ImportDefaultSpecifier: "import default specifier",
  70. ImportNamespaceSpecifier: "import namespace specifier",
  71. ObjectPattern: "object destructuring pattern",
  72. ParenthesizedExpression: "parenthesized expression",
  73. RestElement: "rest element",
  74. UpdateExpression: {
  75. true: "prefix operation",
  76. false: "postfix operation"
  77. },
  78. VariableDeclarator: "variable declaration",
  79. YieldExpression: "yield expression"
  80. };
  81. const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type];
  82. var StandardErrors = {
  83. AccessorIsGenerator: ({
  84. kind
  85. }) => `A ${kind}ter cannot be a generator.`,
  86. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  87. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  88. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  89. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  90. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  91. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  92. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  93. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  94. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  95. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  96. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  97. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  98. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  99. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  100. ConstructorIsAsync: "Constructor can't be an async function.",
  101. ConstructorIsGenerator: "Constructor can't be a generator.",
  102. DeclarationMissingInitializer: ({
  103. kind
  104. }) => `Missing initializer in ${kind} declaration.`,
  105. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  106. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  107. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  108. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  109. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  110. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  111. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  112. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  113. DeletePrivateField: "Deleting a private field is not allowed.",
  114. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  115. DuplicateConstructor: "Duplicate constructor in the same class.",
  116. DuplicateDefaultExport: "Only one default export allowed per module.",
  117. DuplicateExport: ({
  118. exportName
  119. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  120. DuplicateProto: "Redefinition of __proto__ property.",
  121. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  122. DynamicImportPhaseRequiresImportExpressions: ({
  123. phase
  124. }) => `'import.${phase}(...)' can only be parsed when using the 'createImportExpressions' option.`,
  125. ElementAfterRest: "Rest element must be last element.",
  126. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  127. ExportBindingIsString: ({
  128. localName,
  129. exportName
  130. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  131. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  132. ForInOfLoopInitializer: ({
  133. type
  134. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  135. ForInUsing: "For-in loop may not start with 'using' declaration.",
  136. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  137. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  138. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  139. IllegalBreakContinue: ({
  140. type
  141. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  142. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  143. IllegalReturn: "'return' outside of function.",
  144. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedAssertSyntax: true` option in the import attributes plugin to suppress this error.",
  145. ImportBindingIsString: ({
  146. importName
  147. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  148. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  149. ImportCallArity: ({
  150. maxArgumentCount
  151. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
  152. ImportCallNotNewExpression: "Cannot use new with import(...).",
  153. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  154. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  155. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  156. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  157. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  158. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  159. InvalidCodePoint: "Code point out of bounds.",
  160. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  161. InvalidDecimal: "Invalid decimal.",
  162. InvalidDigit: ({
  163. radix
  164. }) => `Expected number in radix ${radix}.`,
  165. InvalidEscapeSequence: "Bad character escape sequence.",
  166. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  167. InvalidEscapedReservedWord: ({
  168. reservedWord
  169. }) => `Escape sequence in keyword ${reservedWord}.`,
  170. InvalidIdentifier: ({
  171. identifierName
  172. }) => `Invalid identifier ${identifierName}.`,
  173. InvalidLhs: ({
  174. ancestor
  175. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  176. InvalidLhsBinding: ({
  177. ancestor
  178. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  179. InvalidLhsOptionalChaining: ({
  180. ancestor
  181. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  182. InvalidNumber: "Invalid number.",
  183. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  184. InvalidOrUnexpectedToken: ({
  185. unexpected
  186. }) => `Unexpected character '${unexpected}'.`,
  187. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  188. InvalidPrivateFieldResolution: ({
  189. identifierName
  190. }) => `Private name #${identifierName} is not defined.`,
  191. InvalidPropertyBindingPattern: "Binding member expression.",
  192. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  193. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  194. LabelRedeclaration: ({
  195. labelName
  196. }) => `Label '${labelName}' is already declared.`,
  197. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  198. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  199. MalformedRegExpFlags: "Invalid regular expression flag.",
  200. MissingClassName: "A class name is required.",
  201. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  202. MissingSemicolon: "Missing semicolon.",
  203. MissingPlugin: ({
  204. missingPlugin
  205. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  206. MissingOneOfPlugins: ({
  207. missingPlugin
  208. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  209. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  210. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  211. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  212. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  213. ModuleAttributesWithDuplicateKeys: ({
  214. key
  215. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  216. ModuleExportNameHasLoneSurrogate: ({
  217. surrogateCharCode
  218. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  219. ModuleExportUndefined: ({
  220. localName
  221. }) => `Export '${localName}' is not defined.`,
  222. MultipleDefaultsInSwitch: "Multiple default clauses.",
  223. NewlineAfterThrow: "Illegal newline after throw.",
  224. NoCatchOrFinally: "Missing catch or finally clause.",
  225. NumberIdentifier: "Identifier directly after number.",
  226. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  227. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  228. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  229. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  230. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  231. ParamDupe: "Argument name clash.",
  232. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  233. PatternHasMethod: "Object pattern can't contain methods.",
  234. PrivateInExpectedIn: ({
  235. identifierName
  236. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  237. PrivateNameRedeclaration: ({
  238. identifierName
  239. }) => `Duplicate private name #${identifierName}.`,
  240. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  241. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  242. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  243. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  244. RestTrailingComma: "Unexpected trailing comma after rest element.",
  245. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  246. 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.",
  247. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  248. StaticPrototype: "Classes may not have static property named prototype.",
  249. 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?",
  250. SuperPrivateField: "Private fields can't be accessed on super.",
  251. TrailingDecorator: "Decorators must be attached to a class element.",
  252. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  253. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  254. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  255. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  256. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  257. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  258. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  259. UnexpectedKeyword: ({
  260. keyword
  261. }) => `Unexpected keyword '${keyword}'.`,
  262. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  263. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  264. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  265. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  266. UnexpectedPrivateField: "Unexpected private name.",
  267. UnexpectedReservedWord: ({
  268. reservedWord
  269. }) => `Unexpected reserved word '${reservedWord}'.`,
  270. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  271. UnexpectedToken: ({
  272. expected,
  273. unexpected
  274. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  275. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  276. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  277. UnsupportedBind: "Binding should be performed on object property.",
  278. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  279. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  280. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  281. UnsupportedMetaProperty: ({
  282. target,
  283. onlyValidPropertyName
  284. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  285. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  286. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  287. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  288. UnterminatedComment: "Unterminated comment.",
  289. UnterminatedRegExp: "Unterminated regular expression.",
  290. UnterminatedString: "Unterminated string constant.",
  291. UnterminatedTemplate: "Unterminated template.",
  292. UsingDeclarationExport: "Using declaration cannot be exported.",
  293. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  294. VarRedeclaration: ({
  295. identifierName
  296. }) => `Identifier '${identifierName}' has already been declared.`,
  297. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  298. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  299. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  300. };
  301. var StrictModeErrors = {
  302. StrictDelete: "Deleting local variable in strict mode.",
  303. StrictEvalArguments: ({
  304. referenceName
  305. }) => `Assigning to '${referenceName}' in strict mode.`,
  306. StrictEvalArgumentsBinding: ({
  307. bindingName
  308. }) => `Binding '${bindingName}' in strict mode.`,
  309. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  310. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  311. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  312. StrictWith: "'with' in strict mode."
  313. };
  314. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  315. var PipelineOperatorErrors = {
  316. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  317. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  318. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  319. PipeTopicUnconfiguredToken: ({
  320. token
  321. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  322. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  323. PipeUnparenthesizedBody: ({
  324. type
  325. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  326. type
  327. })}; please wrap it in parentheses.`,
  328. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  329. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  330. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  331. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  332. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  333. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  334. };
  335. const _excluded = ["toMessage"],
  336. _excluded2 = ["message"];
  337. function defineHidden(obj, key, value) {
  338. Object.defineProperty(obj, key, {
  339. enumerable: false,
  340. configurable: true,
  341. value
  342. });
  343. }
  344. function toParseErrorConstructor(_ref) {
  345. let {
  346. toMessage
  347. } = _ref,
  348. properties = _objectWithoutPropertiesLoose(_ref, _excluded);
  349. return function constructor(loc, details) {
  350. const error = new SyntaxError();
  351. Object.assign(error, properties, {
  352. loc,
  353. pos: loc.index
  354. });
  355. if ("missingPlugin" in details) {
  356. Object.assign(error, {
  357. missingPlugin: details.missingPlugin
  358. });
  359. }
  360. defineHidden(error, "clone", function clone(overrides = {}) {
  361. var _overrides$loc;
  362. const {
  363. line,
  364. column,
  365. index
  366. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  367. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  368. });
  369. defineHidden(error, "details", details);
  370. Object.defineProperty(error, "message", {
  371. configurable: true,
  372. get() {
  373. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  374. this.message = message;
  375. return message;
  376. },
  377. set(value) {
  378. Object.defineProperty(this, "message", {
  379. value,
  380. writable: true
  381. });
  382. }
  383. });
  384. return error;
  385. };
  386. }
  387. function ParseErrorEnum(argument, syntaxPlugin) {
  388. if (Array.isArray(argument)) {
  389. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  390. }
  391. const ParseErrorConstructors = {};
  392. for (const reasonCode of Object.keys(argument)) {
  393. const template = argument[reasonCode];
  394. const _ref2 = typeof template === "string" ? {
  395. message: () => template
  396. } : typeof template === "function" ? {
  397. message: template
  398. } : template,
  399. {
  400. message
  401. } = _ref2,
  402. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2);
  403. const toMessage = typeof message === "string" ? () => message : message;
  404. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  405. code: "BABEL_PARSER_SYNTAX_ERROR",
  406. reasonCode,
  407. toMessage
  408. }, syntaxPlugin ? {
  409. syntaxPlugin
  410. } : {}, rest));
  411. }
  412. return ParseErrorConstructors;
  413. }
  414. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  415. const {
  416. defineProperty
  417. } = Object;
  418. const toUnenumerable = (object, key) => defineProperty(object, key, {
  419. enumerable: false,
  420. value: object[key]
  421. });
  422. function toESTreeLocation(node) {
  423. node.loc.start && toUnenumerable(node.loc.start, "index");
  424. node.loc.end && toUnenumerable(node.loc.end, "index");
  425. return node;
  426. }
  427. var estree = superClass => class ESTreeParserMixin extends superClass {
  428. parse() {
  429. const file = toESTreeLocation(super.parse());
  430. if (this.options.tokens) {
  431. file.tokens = file.tokens.map(toESTreeLocation);
  432. }
  433. return file;
  434. }
  435. parseRegExpLiteral({
  436. pattern,
  437. flags
  438. }) {
  439. let regex = null;
  440. try {
  441. regex = new RegExp(pattern, flags);
  442. } catch (e) {}
  443. const node = this.estreeParseLiteral(regex);
  444. node.regex = {
  445. pattern,
  446. flags
  447. };
  448. return node;
  449. }
  450. parseBigIntLiteral(value) {
  451. let bigInt;
  452. try {
  453. bigInt = BigInt(value);
  454. } catch (_unused) {
  455. bigInt = null;
  456. }
  457. const node = this.estreeParseLiteral(bigInt);
  458. node.bigint = String(node.value || value);
  459. return node;
  460. }
  461. parseDecimalLiteral(value) {
  462. const decimal = null;
  463. const node = this.estreeParseLiteral(decimal);
  464. node.decimal = String(node.value || value);
  465. return node;
  466. }
  467. estreeParseLiteral(value) {
  468. return this.parseLiteral(value, "Literal");
  469. }
  470. parseStringLiteral(value) {
  471. return this.estreeParseLiteral(value);
  472. }
  473. parseNumericLiteral(value) {
  474. return this.estreeParseLiteral(value);
  475. }
  476. parseNullLiteral() {
  477. return this.estreeParseLiteral(null);
  478. }
  479. parseBooleanLiteral(value) {
  480. return this.estreeParseLiteral(value);
  481. }
  482. directiveToStmt(directive) {
  483. const expression = directive.value;
  484. delete directive.value;
  485. expression.type = "Literal";
  486. expression.raw = expression.extra.raw;
  487. expression.value = expression.extra.expressionValue;
  488. const stmt = directive;
  489. stmt.type = "ExpressionStatement";
  490. stmt.expression = expression;
  491. stmt.directive = expression.extra.rawValue;
  492. delete expression.extra;
  493. return stmt;
  494. }
  495. initFunction(node, isAsync) {
  496. super.initFunction(node, isAsync);
  497. node.expression = false;
  498. }
  499. checkDeclaration(node) {
  500. if (node != null && this.isObjectProperty(node)) {
  501. this.checkDeclaration(node.value);
  502. } else {
  503. super.checkDeclaration(node);
  504. }
  505. }
  506. getObjectOrClassMethodParams(method) {
  507. return method.value.params;
  508. }
  509. isValidDirective(stmt) {
  510. var _stmt$expression$extr;
  511. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  512. }
  513. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  514. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  515. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  516. node.body = directiveStatements.concat(node.body);
  517. delete node.directives;
  518. }
  519. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  520. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  521. if (method.typeParameters) {
  522. method.value.typeParameters = method.typeParameters;
  523. delete method.typeParameters;
  524. }
  525. classBody.body.push(method);
  526. }
  527. parsePrivateName() {
  528. const node = super.parsePrivateName();
  529. {
  530. if (!this.getPluginOption("estree", "classFeatures")) {
  531. return node;
  532. }
  533. }
  534. return this.convertPrivateNameToPrivateIdentifier(node);
  535. }
  536. convertPrivateNameToPrivateIdentifier(node) {
  537. const name = super.getPrivateNameSV(node);
  538. node = node;
  539. delete node.id;
  540. node.name = name;
  541. node.type = "PrivateIdentifier";
  542. return node;
  543. }
  544. isPrivateName(node) {
  545. {
  546. if (!this.getPluginOption("estree", "classFeatures")) {
  547. return super.isPrivateName(node);
  548. }
  549. }
  550. return node.type === "PrivateIdentifier";
  551. }
  552. getPrivateNameSV(node) {
  553. {
  554. if (!this.getPluginOption("estree", "classFeatures")) {
  555. return super.getPrivateNameSV(node);
  556. }
  557. }
  558. return node.name;
  559. }
  560. parseLiteral(value, type) {
  561. const node = super.parseLiteral(value, type);
  562. node.raw = node.extra.raw;
  563. delete node.extra;
  564. return node;
  565. }
  566. parseFunctionBody(node, allowExpression, isMethod = false) {
  567. super.parseFunctionBody(node, allowExpression, isMethod);
  568. node.expression = node.body.type !== "BlockStatement";
  569. }
  570. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  571. let funcNode = this.startNode();
  572. funcNode.kind = node.kind;
  573. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  574. funcNode.type = "FunctionExpression";
  575. delete funcNode.kind;
  576. node.value = funcNode;
  577. if (type === "ClassPrivateMethod") {
  578. node.computed = false;
  579. }
  580. return this.finishNode(node, "MethodDefinition");
  581. }
  582. nameIsConstructor(key) {
  583. if (key.type === "Literal") return key.value === "constructor";
  584. return super.nameIsConstructor(key);
  585. }
  586. parseClassProperty(...args) {
  587. const propertyNode = super.parseClassProperty(...args);
  588. {
  589. if (!this.getPluginOption("estree", "classFeatures")) {
  590. return propertyNode;
  591. }
  592. }
  593. propertyNode.type = "PropertyDefinition";
  594. return propertyNode;
  595. }
  596. parseClassPrivateProperty(...args) {
  597. const propertyNode = super.parseClassPrivateProperty(...args);
  598. {
  599. if (!this.getPluginOption("estree", "classFeatures")) {
  600. return propertyNode;
  601. }
  602. }
  603. propertyNode.type = "PropertyDefinition";
  604. propertyNode.computed = false;
  605. return propertyNode;
  606. }
  607. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  608. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  609. if (node) {
  610. node.type = "Property";
  611. if (node.kind === "method") {
  612. node.kind = "init";
  613. }
  614. node.shorthand = false;
  615. }
  616. return node;
  617. }
  618. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  619. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  620. if (node) {
  621. node.kind = "init";
  622. node.type = "Property";
  623. }
  624. return node;
  625. }
  626. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  627. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  628. }
  629. isAssignable(node, isBinding) {
  630. if (node != null && this.isObjectProperty(node)) {
  631. return this.isAssignable(node.value, isBinding);
  632. }
  633. return super.isAssignable(node, isBinding);
  634. }
  635. toAssignable(node, isLHS = false) {
  636. if (node != null && this.isObjectProperty(node)) {
  637. const {
  638. key,
  639. value
  640. } = node;
  641. if (this.isPrivateName(key)) {
  642. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  643. }
  644. this.toAssignable(value, isLHS);
  645. } else {
  646. super.toAssignable(node, isLHS);
  647. }
  648. }
  649. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  650. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  651. this.raise(Errors.PatternHasAccessor, prop.key);
  652. } else if (prop.type === "Property" && prop.method) {
  653. this.raise(Errors.PatternHasMethod, prop.key);
  654. } else {
  655. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  656. }
  657. }
  658. finishCallExpression(unfinished, optional) {
  659. const node = super.finishCallExpression(unfinished, optional);
  660. if (node.callee.type === "Import") {
  661. node.type = "ImportExpression";
  662. node.source = node.arguments[0];
  663. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  664. var _ref, _ref2;
  665. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  666. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  667. }
  668. delete node.arguments;
  669. delete node.callee;
  670. }
  671. return node;
  672. }
  673. toReferencedArguments(node) {
  674. if (node.type === "ImportExpression") {
  675. return;
  676. }
  677. super.toReferencedArguments(node);
  678. }
  679. parseExport(unfinished, decorators) {
  680. const exportStartLoc = this.state.lastTokStartLoc;
  681. const node = super.parseExport(unfinished, decorators);
  682. switch (node.type) {
  683. case "ExportAllDeclaration":
  684. node.exported = null;
  685. break;
  686. case "ExportNamedDeclaration":
  687. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  688. node.type = "ExportAllDeclaration";
  689. node.exported = node.specifiers[0].exported;
  690. delete node.specifiers;
  691. }
  692. case "ExportDefaultDeclaration":
  693. {
  694. var _declaration$decorato;
  695. const {
  696. declaration
  697. } = node;
  698. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  699. this.resetStartLocation(node, exportStartLoc);
  700. }
  701. }
  702. break;
  703. }
  704. return node;
  705. }
  706. parseSubscript(base, startLoc, noCalls, state) {
  707. const node = super.parseSubscript(base, startLoc, noCalls, state);
  708. if (state.optionalChainMember) {
  709. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  710. node.type = node.type.substring(8);
  711. }
  712. if (state.stop) {
  713. const chain = this.startNodeAtNode(node);
  714. chain.expression = node;
  715. return this.finishNode(chain, "ChainExpression");
  716. }
  717. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  718. node.optional = false;
  719. }
  720. return node;
  721. }
  722. isOptionalMemberExpression(node) {
  723. if (node.type === "ChainExpression") {
  724. return node.expression.type === "MemberExpression";
  725. }
  726. return super.isOptionalMemberExpression(node);
  727. }
  728. hasPropertyAsPrivateName(node) {
  729. if (node.type === "ChainExpression") {
  730. node = node.expression;
  731. }
  732. return super.hasPropertyAsPrivateName(node);
  733. }
  734. isObjectProperty(node) {
  735. return node.type === "Property" && node.kind === "init" && !node.method;
  736. }
  737. isObjectMethod(node) {
  738. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  739. }
  740. finishNodeAt(node, type, endLoc) {
  741. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  742. }
  743. resetStartLocation(node, startLoc) {
  744. super.resetStartLocation(node, startLoc);
  745. toESTreeLocation(node);
  746. }
  747. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  748. super.resetEndLocation(node, endLoc);
  749. toESTreeLocation(node);
  750. }
  751. };
  752. class TokContext {
  753. constructor(token, preserveSpace) {
  754. this.token = void 0;
  755. this.preserveSpace = void 0;
  756. this.token = token;
  757. this.preserveSpace = !!preserveSpace;
  758. }
  759. }
  760. const types = {
  761. brace: new TokContext("{"),
  762. j_oTag: new TokContext("<tag"),
  763. j_cTag: new TokContext("</tag"),
  764. j_expr: new TokContext("<tag>...</tag>", true)
  765. };
  766. {
  767. types.template = new TokContext("`", true);
  768. }
  769. const beforeExpr = true;
  770. const startsExpr = true;
  771. const isLoop = true;
  772. const isAssign = true;
  773. const prefix = true;
  774. const postfix = true;
  775. class ExportedTokenType {
  776. constructor(label, conf = {}) {
  777. this.label = void 0;
  778. this.keyword = void 0;
  779. this.beforeExpr = void 0;
  780. this.startsExpr = void 0;
  781. this.rightAssociative = void 0;
  782. this.isLoop = void 0;
  783. this.isAssign = void 0;
  784. this.prefix = void 0;
  785. this.postfix = void 0;
  786. this.binop = void 0;
  787. this.label = label;
  788. this.keyword = conf.keyword;
  789. this.beforeExpr = !!conf.beforeExpr;
  790. this.startsExpr = !!conf.startsExpr;
  791. this.rightAssociative = !!conf.rightAssociative;
  792. this.isLoop = !!conf.isLoop;
  793. this.isAssign = !!conf.isAssign;
  794. this.prefix = !!conf.prefix;
  795. this.postfix = !!conf.postfix;
  796. this.binop = conf.binop != null ? conf.binop : null;
  797. {
  798. this.updateContext = null;
  799. }
  800. }
  801. }
  802. const keywords$1 = new Map();
  803. function createKeyword(name, options = {}) {
  804. options.keyword = name;
  805. const token = createToken(name, options);
  806. keywords$1.set(name, token);
  807. return token;
  808. }
  809. function createBinop(name, binop) {
  810. return createToken(name, {
  811. beforeExpr,
  812. binop
  813. });
  814. }
  815. let tokenTypeCounter = -1;
  816. const tokenTypes = [];
  817. const tokenLabels = [];
  818. const tokenBinops = [];
  819. const tokenBeforeExprs = [];
  820. const tokenStartsExprs = [];
  821. const tokenPrefixes = [];
  822. function createToken(name, options = {}) {
  823. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  824. ++tokenTypeCounter;
  825. tokenLabels.push(name);
  826. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  827. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  828. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  829. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  830. tokenTypes.push(new ExportedTokenType(name, options));
  831. return tokenTypeCounter;
  832. }
  833. function createKeywordLike(name, options = {}) {
  834. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  835. ++tokenTypeCounter;
  836. keywords$1.set(name, tokenTypeCounter);
  837. tokenLabels.push(name);
  838. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  839. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  840. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  841. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  842. tokenTypes.push(new ExportedTokenType("name", options));
  843. return tokenTypeCounter;
  844. }
  845. const tt = {
  846. bracketL: createToken("[", {
  847. beforeExpr,
  848. startsExpr
  849. }),
  850. bracketHashL: createToken("#[", {
  851. beforeExpr,
  852. startsExpr
  853. }),
  854. bracketBarL: createToken("[|", {
  855. beforeExpr,
  856. startsExpr
  857. }),
  858. bracketR: createToken("]"),
  859. bracketBarR: createToken("|]"),
  860. braceL: createToken("{", {
  861. beforeExpr,
  862. startsExpr
  863. }),
  864. braceBarL: createToken("{|", {
  865. beforeExpr,
  866. startsExpr
  867. }),
  868. braceHashL: createToken("#{", {
  869. beforeExpr,
  870. startsExpr
  871. }),
  872. braceR: createToken("}"),
  873. braceBarR: createToken("|}"),
  874. parenL: createToken("(", {
  875. beforeExpr,
  876. startsExpr
  877. }),
  878. parenR: createToken(")"),
  879. comma: createToken(",", {
  880. beforeExpr
  881. }),
  882. semi: createToken(";", {
  883. beforeExpr
  884. }),
  885. colon: createToken(":", {
  886. beforeExpr
  887. }),
  888. doubleColon: createToken("::", {
  889. beforeExpr
  890. }),
  891. dot: createToken("."),
  892. question: createToken("?", {
  893. beforeExpr
  894. }),
  895. questionDot: createToken("?."),
  896. arrow: createToken("=>", {
  897. beforeExpr
  898. }),
  899. template: createToken("template"),
  900. ellipsis: createToken("...", {
  901. beforeExpr
  902. }),
  903. backQuote: createToken("`", {
  904. startsExpr
  905. }),
  906. dollarBraceL: createToken("${", {
  907. beforeExpr,
  908. startsExpr
  909. }),
  910. templateTail: createToken("...`", {
  911. startsExpr
  912. }),
  913. templateNonTail: createToken("...${", {
  914. beforeExpr,
  915. startsExpr
  916. }),
  917. at: createToken("@"),
  918. hash: createToken("#", {
  919. startsExpr
  920. }),
  921. interpreterDirective: createToken("#!..."),
  922. eq: createToken("=", {
  923. beforeExpr,
  924. isAssign
  925. }),
  926. assign: createToken("_=", {
  927. beforeExpr,
  928. isAssign
  929. }),
  930. slashAssign: createToken("_=", {
  931. beforeExpr,
  932. isAssign
  933. }),
  934. xorAssign: createToken("_=", {
  935. beforeExpr,
  936. isAssign
  937. }),
  938. moduloAssign: createToken("_=", {
  939. beforeExpr,
  940. isAssign
  941. }),
  942. incDec: createToken("++/--", {
  943. prefix,
  944. postfix,
  945. startsExpr
  946. }),
  947. bang: createToken("!", {
  948. beforeExpr,
  949. prefix,
  950. startsExpr
  951. }),
  952. tilde: createToken("~", {
  953. beforeExpr,
  954. prefix,
  955. startsExpr
  956. }),
  957. doubleCaret: createToken("^^", {
  958. startsExpr
  959. }),
  960. doubleAt: createToken("@@", {
  961. startsExpr
  962. }),
  963. pipeline: createBinop("|>", 0),
  964. nullishCoalescing: createBinop("??", 1),
  965. logicalOR: createBinop("||", 1),
  966. logicalAND: createBinop("&&", 2),
  967. bitwiseOR: createBinop("|", 3),
  968. bitwiseXOR: createBinop("^", 4),
  969. bitwiseAND: createBinop("&", 5),
  970. equality: createBinop("==/!=/===/!==", 6),
  971. lt: createBinop("</>/<=/>=", 7),
  972. gt: createBinop("</>/<=/>=", 7),
  973. relational: createBinop("</>/<=/>=", 7),
  974. bitShift: createBinop("<</>>/>>>", 8),
  975. bitShiftL: createBinop("<</>>/>>>", 8),
  976. bitShiftR: createBinop("<</>>/>>>", 8),
  977. plusMin: createToken("+/-", {
  978. beforeExpr,
  979. binop: 9,
  980. prefix,
  981. startsExpr
  982. }),
  983. modulo: createToken("%", {
  984. binop: 10,
  985. startsExpr
  986. }),
  987. star: createToken("*", {
  988. binop: 10
  989. }),
  990. slash: createBinop("/", 10),
  991. exponent: createToken("**", {
  992. beforeExpr,
  993. binop: 11,
  994. rightAssociative: true
  995. }),
  996. _in: createKeyword("in", {
  997. beforeExpr,
  998. binop: 7
  999. }),
  1000. _instanceof: createKeyword("instanceof", {
  1001. beforeExpr,
  1002. binop: 7
  1003. }),
  1004. _break: createKeyword("break"),
  1005. _case: createKeyword("case", {
  1006. beforeExpr
  1007. }),
  1008. _catch: createKeyword("catch"),
  1009. _continue: createKeyword("continue"),
  1010. _debugger: createKeyword("debugger"),
  1011. _default: createKeyword("default", {
  1012. beforeExpr
  1013. }),
  1014. _else: createKeyword("else", {
  1015. beforeExpr
  1016. }),
  1017. _finally: createKeyword("finally"),
  1018. _function: createKeyword("function", {
  1019. startsExpr
  1020. }),
  1021. _if: createKeyword("if"),
  1022. _return: createKeyword("return", {
  1023. beforeExpr
  1024. }),
  1025. _switch: createKeyword("switch"),
  1026. _throw: createKeyword("throw", {
  1027. beforeExpr,
  1028. prefix,
  1029. startsExpr
  1030. }),
  1031. _try: createKeyword("try"),
  1032. _var: createKeyword("var"),
  1033. _const: createKeyword("const"),
  1034. _with: createKeyword("with"),
  1035. _new: createKeyword("new", {
  1036. beforeExpr,
  1037. startsExpr
  1038. }),
  1039. _this: createKeyword("this", {
  1040. startsExpr
  1041. }),
  1042. _super: createKeyword("super", {
  1043. startsExpr
  1044. }),
  1045. _class: createKeyword("class", {
  1046. startsExpr
  1047. }),
  1048. _extends: createKeyword("extends", {
  1049. beforeExpr
  1050. }),
  1051. _export: createKeyword("export"),
  1052. _import: createKeyword("import", {
  1053. startsExpr
  1054. }),
  1055. _null: createKeyword("null", {
  1056. startsExpr
  1057. }),
  1058. _true: createKeyword("true", {
  1059. startsExpr
  1060. }),
  1061. _false: createKeyword("false", {
  1062. startsExpr
  1063. }),
  1064. _typeof: createKeyword("typeof", {
  1065. beforeExpr,
  1066. prefix,
  1067. startsExpr
  1068. }),
  1069. _void: createKeyword("void", {
  1070. beforeExpr,
  1071. prefix,
  1072. startsExpr
  1073. }),
  1074. _delete: createKeyword("delete", {
  1075. beforeExpr,
  1076. prefix,
  1077. startsExpr
  1078. }),
  1079. _do: createKeyword("do", {
  1080. isLoop,
  1081. beforeExpr
  1082. }),
  1083. _for: createKeyword("for", {
  1084. isLoop
  1085. }),
  1086. _while: createKeyword("while", {
  1087. isLoop
  1088. }),
  1089. _as: createKeywordLike("as", {
  1090. startsExpr
  1091. }),
  1092. _assert: createKeywordLike("assert", {
  1093. startsExpr
  1094. }),
  1095. _async: createKeywordLike("async", {
  1096. startsExpr
  1097. }),
  1098. _await: createKeywordLike("await", {
  1099. startsExpr
  1100. }),
  1101. _defer: createKeywordLike("defer", {
  1102. startsExpr
  1103. }),
  1104. _from: createKeywordLike("from", {
  1105. startsExpr
  1106. }),
  1107. _get: createKeywordLike("get", {
  1108. startsExpr
  1109. }),
  1110. _let: createKeywordLike("let", {
  1111. startsExpr
  1112. }),
  1113. _meta: createKeywordLike("meta", {
  1114. startsExpr
  1115. }),
  1116. _of: createKeywordLike("of", {
  1117. startsExpr
  1118. }),
  1119. _sent: createKeywordLike("sent", {
  1120. startsExpr
  1121. }),
  1122. _set: createKeywordLike("set", {
  1123. startsExpr
  1124. }),
  1125. _source: createKeywordLike("source", {
  1126. startsExpr
  1127. }),
  1128. _static: createKeywordLike("static", {
  1129. startsExpr
  1130. }),
  1131. _using: createKeywordLike("using", {
  1132. startsExpr
  1133. }),
  1134. _yield: createKeywordLike("yield", {
  1135. startsExpr
  1136. }),
  1137. _asserts: createKeywordLike("asserts", {
  1138. startsExpr
  1139. }),
  1140. _checks: createKeywordLike("checks", {
  1141. startsExpr
  1142. }),
  1143. _exports: createKeywordLike("exports", {
  1144. startsExpr
  1145. }),
  1146. _global: createKeywordLike("global", {
  1147. startsExpr
  1148. }),
  1149. _implements: createKeywordLike("implements", {
  1150. startsExpr
  1151. }),
  1152. _intrinsic: createKeywordLike("intrinsic", {
  1153. startsExpr
  1154. }),
  1155. _infer: createKeywordLike("infer", {
  1156. startsExpr
  1157. }),
  1158. _is: createKeywordLike("is", {
  1159. startsExpr
  1160. }),
  1161. _mixins: createKeywordLike("mixins", {
  1162. startsExpr
  1163. }),
  1164. _proto: createKeywordLike("proto", {
  1165. startsExpr
  1166. }),
  1167. _require: createKeywordLike("require", {
  1168. startsExpr
  1169. }),
  1170. _satisfies: createKeywordLike("satisfies", {
  1171. startsExpr
  1172. }),
  1173. _keyof: createKeywordLike("keyof", {
  1174. startsExpr
  1175. }),
  1176. _readonly: createKeywordLike("readonly", {
  1177. startsExpr
  1178. }),
  1179. _unique: createKeywordLike("unique", {
  1180. startsExpr
  1181. }),
  1182. _abstract: createKeywordLike("abstract", {
  1183. startsExpr
  1184. }),
  1185. _declare: createKeywordLike("declare", {
  1186. startsExpr
  1187. }),
  1188. _enum: createKeywordLike("enum", {
  1189. startsExpr
  1190. }),
  1191. _module: createKeywordLike("module", {
  1192. startsExpr
  1193. }),
  1194. _namespace: createKeywordLike("namespace", {
  1195. startsExpr
  1196. }),
  1197. _interface: createKeywordLike("interface", {
  1198. startsExpr
  1199. }),
  1200. _type: createKeywordLike("type", {
  1201. startsExpr
  1202. }),
  1203. _opaque: createKeywordLike("opaque", {
  1204. startsExpr
  1205. }),
  1206. name: createToken("name", {
  1207. startsExpr
  1208. }),
  1209. string: createToken("string", {
  1210. startsExpr
  1211. }),
  1212. num: createToken("num", {
  1213. startsExpr
  1214. }),
  1215. bigint: createToken("bigint", {
  1216. startsExpr
  1217. }),
  1218. decimal: createToken("decimal", {
  1219. startsExpr
  1220. }),
  1221. regexp: createToken("regexp", {
  1222. startsExpr
  1223. }),
  1224. privateName: createToken("#name", {
  1225. startsExpr
  1226. }),
  1227. eof: createToken("eof"),
  1228. jsxName: createToken("jsxName"),
  1229. jsxText: createToken("jsxText", {
  1230. beforeExpr: true
  1231. }),
  1232. jsxTagStart: createToken("jsxTagStart", {
  1233. startsExpr: true
  1234. }),
  1235. jsxTagEnd: createToken("jsxTagEnd"),
  1236. placeholder: createToken("%%", {
  1237. startsExpr: true
  1238. })
  1239. };
  1240. function tokenIsIdentifier(token) {
  1241. return token >= 93 && token <= 132;
  1242. }
  1243. function tokenKeywordOrIdentifierIsKeyword(token) {
  1244. return token <= 92;
  1245. }
  1246. function tokenIsKeywordOrIdentifier(token) {
  1247. return token >= 58 && token <= 132;
  1248. }
  1249. function tokenIsLiteralPropertyName(token) {
  1250. return token >= 58 && token <= 136;
  1251. }
  1252. function tokenComesBeforeExpression(token) {
  1253. return tokenBeforeExprs[token];
  1254. }
  1255. function tokenCanStartExpression(token) {
  1256. return tokenStartsExprs[token];
  1257. }
  1258. function tokenIsAssignment(token) {
  1259. return token >= 29 && token <= 33;
  1260. }
  1261. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1262. return token >= 129 && token <= 131;
  1263. }
  1264. function tokenIsLoop(token) {
  1265. return token >= 90 && token <= 92;
  1266. }
  1267. function tokenIsKeyword(token) {
  1268. return token >= 58 && token <= 92;
  1269. }
  1270. function tokenIsOperator(token) {
  1271. return token >= 39 && token <= 59;
  1272. }
  1273. function tokenIsPostfix(token) {
  1274. return token === 34;
  1275. }
  1276. function tokenIsPrefix(token) {
  1277. return tokenPrefixes[token];
  1278. }
  1279. function tokenIsTSTypeOperator(token) {
  1280. return token >= 121 && token <= 123;
  1281. }
  1282. function tokenIsTSDeclarationStart(token) {
  1283. return token >= 124 && token <= 130;
  1284. }
  1285. function tokenLabelName(token) {
  1286. return tokenLabels[token];
  1287. }
  1288. function tokenOperatorPrecedence(token) {
  1289. return tokenBinops[token];
  1290. }
  1291. function tokenIsRightAssociative(token) {
  1292. return token === 57;
  1293. }
  1294. function tokenIsTemplate(token) {
  1295. return token >= 24 && token <= 25;
  1296. }
  1297. function getExportedToken(token) {
  1298. return tokenTypes[token];
  1299. }
  1300. {
  1301. tokenTypes[8].updateContext = context => {
  1302. context.pop();
  1303. };
  1304. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1305. context.push(types.brace);
  1306. };
  1307. tokenTypes[22].updateContext = context => {
  1308. if (context[context.length - 1] === types.template) {
  1309. context.pop();
  1310. } else {
  1311. context.push(types.template);
  1312. }
  1313. };
  1314. tokenTypes[142].updateContext = context => {
  1315. context.push(types.j_expr, types.j_oTag);
  1316. };
  1317. }
  1318. 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";
  1319. let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0898-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
  1320. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1321. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1322. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1323. const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 68, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 4026, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 757, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
  1324. 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];
  1325. function isInAstralSet(code, set) {
  1326. let pos = 0x10000;
  1327. for (let i = 0, length = set.length; i < length; i += 2) {
  1328. pos += set[i];
  1329. if (pos > code) return false;
  1330. pos += set[i + 1];
  1331. if (pos >= code) return true;
  1332. }
  1333. return false;
  1334. }
  1335. function isIdentifierStart(code) {
  1336. if (code < 65) return code === 36;
  1337. if (code <= 90) return true;
  1338. if (code < 97) return code === 95;
  1339. if (code <= 122) return true;
  1340. if (code <= 0xffff) {
  1341. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1342. }
  1343. return isInAstralSet(code, astralIdentifierStartCodes);
  1344. }
  1345. function isIdentifierChar(code) {
  1346. if (code < 48) return code === 36;
  1347. if (code < 58) return true;
  1348. if (code < 65) return false;
  1349. if (code <= 90) return true;
  1350. if (code < 97) return code === 95;
  1351. if (code <= 122) return true;
  1352. if (code <= 0xffff) {
  1353. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1354. }
  1355. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1356. }
  1357. const reservedWords = {
  1358. 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"],
  1359. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1360. strictBind: ["eval", "arguments"]
  1361. };
  1362. const keywords = new Set(reservedWords.keyword);
  1363. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1364. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1365. function isReservedWord(word, inModule) {
  1366. return inModule && word === "await" || word === "enum";
  1367. }
  1368. function isStrictReservedWord(word, inModule) {
  1369. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1370. }
  1371. function isStrictBindOnlyReservedWord(word) {
  1372. return reservedWordsStrictBindSet.has(word);
  1373. }
  1374. function isStrictBindReservedWord(word, inModule) {
  1375. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1376. }
  1377. function isKeyword(word) {
  1378. return keywords.has(word);
  1379. }
  1380. function isIteratorStart(current, next, next2) {
  1381. return current === 64 && next === 64 && isIdentifierStart(next2);
  1382. }
  1383. 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"]);
  1384. function canBeReservedWord(word) {
  1385. return reservedWordLikeSet.has(word);
  1386. }
  1387. class Scope {
  1388. constructor(flags) {
  1389. this.flags = 0;
  1390. this.names = new Map();
  1391. this.firstLexicalName = "";
  1392. this.flags = flags;
  1393. }
  1394. }
  1395. class ScopeHandler {
  1396. constructor(parser, inModule) {
  1397. this.parser = void 0;
  1398. this.scopeStack = [];
  1399. this.inModule = void 0;
  1400. this.undefinedExports = new Map();
  1401. this.parser = parser;
  1402. this.inModule = inModule;
  1403. }
  1404. get inTopLevel() {
  1405. return (this.currentScope().flags & 1) > 0;
  1406. }
  1407. get inFunction() {
  1408. return (this.currentVarScopeFlags() & 2) > 0;
  1409. }
  1410. get allowSuper() {
  1411. return (this.currentThisScopeFlags() & 16) > 0;
  1412. }
  1413. get allowDirectSuper() {
  1414. return (this.currentThisScopeFlags() & 32) > 0;
  1415. }
  1416. get inClass() {
  1417. return (this.currentThisScopeFlags() & 64) > 0;
  1418. }
  1419. get inClassAndNotInNonArrowFunction() {
  1420. const flags = this.currentThisScopeFlags();
  1421. return (flags & 64) > 0 && (flags & 2) === 0;
  1422. }
  1423. get inStaticBlock() {
  1424. for (let i = this.scopeStack.length - 1;; i--) {
  1425. const {
  1426. flags
  1427. } = this.scopeStack[i];
  1428. if (flags & 128) {
  1429. return true;
  1430. }
  1431. if (flags & (387 | 64)) {
  1432. return false;
  1433. }
  1434. }
  1435. }
  1436. get inNonArrowFunction() {
  1437. return (this.currentThisScopeFlags() & 2) > 0;
  1438. }
  1439. get treatFunctionsAsVar() {
  1440. return this.treatFunctionsAsVarInScope(this.currentScope());
  1441. }
  1442. createScope(flags) {
  1443. return new Scope(flags);
  1444. }
  1445. enter(flags) {
  1446. this.scopeStack.push(this.createScope(flags));
  1447. }
  1448. exit() {
  1449. const scope = this.scopeStack.pop();
  1450. return scope.flags;
  1451. }
  1452. treatFunctionsAsVarInScope(scope) {
  1453. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1454. }
  1455. declareName(name, bindingType, loc) {
  1456. let scope = this.currentScope();
  1457. if (bindingType & 8 || bindingType & 16) {
  1458. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1459. let type = scope.names.get(name) || 0;
  1460. if (bindingType & 16) {
  1461. type = type | 4;
  1462. } else {
  1463. if (!scope.firstLexicalName) {
  1464. scope.firstLexicalName = name;
  1465. }
  1466. type = type | 2;
  1467. }
  1468. scope.names.set(name, type);
  1469. if (bindingType & 8) {
  1470. this.maybeExportDefined(scope, name);
  1471. }
  1472. } else if (bindingType & 4) {
  1473. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1474. scope = this.scopeStack[i];
  1475. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1476. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1477. this.maybeExportDefined(scope, name);
  1478. if (scope.flags & 387) break;
  1479. }
  1480. }
  1481. if (this.parser.inModule && scope.flags & 1) {
  1482. this.undefinedExports.delete(name);
  1483. }
  1484. }
  1485. maybeExportDefined(scope, name) {
  1486. if (this.parser.inModule && scope.flags & 1) {
  1487. this.undefinedExports.delete(name);
  1488. }
  1489. }
  1490. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1491. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1492. this.parser.raise(Errors.VarRedeclaration, loc, {
  1493. identifierName: name
  1494. });
  1495. }
  1496. }
  1497. isRedeclaredInScope(scope, name, bindingType) {
  1498. if (!(bindingType & 1)) return false;
  1499. if (bindingType & 8) {
  1500. return scope.names.has(name);
  1501. }
  1502. const type = scope.names.get(name);
  1503. if (bindingType & 16) {
  1504. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1505. }
  1506. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1507. }
  1508. checkLocalExport(id) {
  1509. const {
  1510. name
  1511. } = id;
  1512. const topLevelScope = this.scopeStack[0];
  1513. if (!topLevelScope.names.has(name)) {
  1514. this.undefinedExports.set(name, id.loc.start);
  1515. }
  1516. }
  1517. currentScope() {
  1518. return this.scopeStack[this.scopeStack.length - 1];
  1519. }
  1520. currentVarScopeFlags() {
  1521. for (let i = this.scopeStack.length - 1;; i--) {
  1522. const {
  1523. flags
  1524. } = this.scopeStack[i];
  1525. if (flags & 387) {
  1526. return flags;
  1527. }
  1528. }
  1529. }
  1530. currentThisScopeFlags() {
  1531. for (let i = this.scopeStack.length - 1;; i--) {
  1532. const {
  1533. flags
  1534. } = this.scopeStack[i];
  1535. if (flags & (387 | 64) && !(flags & 4)) {
  1536. return flags;
  1537. }
  1538. }
  1539. }
  1540. }
  1541. class FlowScope extends Scope {
  1542. constructor(...args) {
  1543. super(...args);
  1544. this.declareFunctions = new Set();
  1545. }
  1546. }
  1547. class FlowScopeHandler extends ScopeHandler {
  1548. createScope(flags) {
  1549. return new FlowScope(flags);
  1550. }
  1551. declareName(name, bindingType, loc) {
  1552. const scope = this.currentScope();
  1553. if (bindingType & 2048) {
  1554. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1555. this.maybeExportDefined(scope, name);
  1556. scope.declareFunctions.add(name);
  1557. return;
  1558. }
  1559. super.declareName(name, bindingType, loc);
  1560. }
  1561. isRedeclaredInScope(scope, name, bindingType) {
  1562. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1563. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1564. const type = scope.names.get(name);
  1565. return (type & 4) > 0 || (type & 2) > 0;
  1566. }
  1567. return false;
  1568. }
  1569. checkLocalExport(id) {
  1570. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1571. super.checkLocalExport(id);
  1572. }
  1573. }
  1574. }
  1575. class BaseParser {
  1576. constructor() {
  1577. this.sawUnambiguousESM = false;
  1578. this.ambiguousScriptDifferentAst = false;
  1579. }
  1580. hasPlugin(pluginConfig) {
  1581. if (typeof pluginConfig === "string") {
  1582. return this.plugins.has(pluginConfig);
  1583. } else {
  1584. const [pluginName, pluginOptions] = pluginConfig;
  1585. if (!this.hasPlugin(pluginName)) {
  1586. return false;
  1587. }
  1588. const actualOptions = this.plugins.get(pluginName);
  1589. for (const key of Object.keys(pluginOptions)) {
  1590. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1591. return false;
  1592. }
  1593. }
  1594. return true;
  1595. }
  1596. }
  1597. getPluginOption(plugin, name) {
  1598. var _this$plugins$get;
  1599. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1600. }
  1601. }
  1602. function setTrailingComments(node, comments) {
  1603. if (node.trailingComments === undefined) {
  1604. node.trailingComments = comments;
  1605. } else {
  1606. node.trailingComments.unshift(...comments);
  1607. }
  1608. }
  1609. function setLeadingComments(node, comments) {
  1610. if (node.leadingComments === undefined) {
  1611. node.leadingComments = comments;
  1612. } else {
  1613. node.leadingComments.unshift(...comments);
  1614. }
  1615. }
  1616. function setInnerComments(node, comments) {
  1617. if (node.innerComments === undefined) {
  1618. node.innerComments = comments;
  1619. } else {
  1620. node.innerComments.unshift(...comments);
  1621. }
  1622. }
  1623. function adjustInnerComments(node, elements, commentWS) {
  1624. let lastElement = null;
  1625. let i = elements.length;
  1626. while (lastElement === null && i > 0) {
  1627. lastElement = elements[--i];
  1628. }
  1629. if (lastElement === null || lastElement.start > commentWS.start) {
  1630. setInnerComments(node, commentWS.comments);
  1631. } else {
  1632. setTrailingComments(lastElement, commentWS.comments);
  1633. }
  1634. }
  1635. class CommentsParser extends BaseParser {
  1636. addComment(comment) {
  1637. if (this.filename) comment.loc.filename = this.filename;
  1638. const {
  1639. commentsLen
  1640. } = this.state;
  1641. if (this.comments.length !== commentsLen) {
  1642. this.comments.length = commentsLen;
  1643. }
  1644. this.comments.push(comment);
  1645. this.state.commentsLen++;
  1646. }
  1647. processComment(node) {
  1648. const {
  1649. commentStack
  1650. } = this.state;
  1651. const commentStackLength = commentStack.length;
  1652. if (commentStackLength === 0) return;
  1653. let i = commentStackLength - 1;
  1654. const lastCommentWS = commentStack[i];
  1655. if (lastCommentWS.start === node.end) {
  1656. lastCommentWS.leadingNode = node;
  1657. i--;
  1658. }
  1659. const {
  1660. start: nodeStart
  1661. } = node;
  1662. for (; i >= 0; i--) {
  1663. const commentWS = commentStack[i];
  1664. const commentEnd = commentWS.end;
  1665. if (commentEnd > nodeStart) {
  1666. commentWS.containingNode = node;
  1667. this.finalizeComment(commentWS);
  1668. commentStack.splice(i, 1);
  1669. } else {
  1670. if (commentEnd === nodeStart) {
  1671. commentWS.trailingNode = node;
  1672. }
  1673. break;
  1674. }
  1675. }
  1676. }
  1677. finalizeComment(commentWS) {
  1678. const {
  1679. comments
  1680. } = commentWS;
  1681. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1682. if (commentWS.leadingNode !== null) {
  1683. setTrailingComments(commentWS.leadingNode, comments);
  1684. }
  1685. if (commentWS.trailingNode !== null) {
  1686. setLeadingComments(commentWS.trailingNode, comments);
  1687. }
  1688. } else {
  1689. const {
  1690. containingNode: node,
  1691. start: commentStart
  1692. } = commentWS;
  1693. if (this.input.charCodeAt(commentStart - 1) === 44) {
  1694. switch (node.type) {
  1695. case "ObjectExpression":
  1696. case "ObjectPattern":
  1697. case "RecordExpression":
  1698. adjustInnerComments(node, node.properties, commentWS);
  1699. break;
  1700. case "CallExpression":
  1701. case "OptionalCallExpression":
  1702. adjustInnerComments(node, node.arguments, commentWS);
  1703. break;
  1704. case "FunctionDeclaration":
  1705. case "FunctionExpression":
  1706. case "ArrowFunctionExpression":
  1707. case "ObjectMethod":
  1708. case "ClassMethod":
  1709. case "ClassPrivateMethod":
  1710. adjustInnerComments(node, node.params, commentWS);
  1711. break;
  1712. case "ArrayExpression":
  1713. case "ArrayPattern":
  1714. case "TupleExpression":
  1715. adjustInnerComments(node, node.elements, commentWS);
  1716. break;
  1717. case "ExportNamedDeclaration":
  1718. case "ImportDeclaration":
  1719. adjustInnerComments(node, node.specifiers, commentWS);
  1720. break;
  1721. default:
  1722. {
  1723. setInnerComments(node, comments);
  1724. }
  1725. }
  1726. } else {
  1727. setInnerComments(node, comments);
  1728. }
  1729. }
  1730. }
  1731. finalizeRemainingComments() {
  1732. const {
  1733. commentStack
  1734. } = this.state;
  1735. for (let i = commentStack.length - 1; i >= 0; i--) {
  1736. this.finalizeComment(commentStack[i]);
  1737. }
  1738. this.state.commentStack = [];
  1739. }
  1740. resetPreviousNodeTrailingComments(node) {
  1741. const {
  1742. commentStack
  1743. } = this.state;
  1744. const {
  1745. length
  1746. } = commentStack;
  1747. if (length === 0) return;
  1748. const commentWS = commentStack[length - 1];
  1749. if (commentWS.leadingNode === node) {
  1750. commentWS.leadingNode = null;
  1751. }
  1752. }
  1753. resetPreviousIdentifierLeadingComments(node) {
  1754. const {
  1755. commentStack
  1756. } = this.state;
  1757. const {
  1758. length
  1759. } = commentStack;
  1760. if (length === 0) return;
  1761. if (commentStack[length - 1].trailingNode === node) {
  1762. commentStack[length - 1].trailingNode = null;
  1763. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  1764. commentStack[length - 2].trailingNode = null;
  1765. }
  1766. }
  1767. takeSurroundingComments(node, start, end) {
  1768. const {
  1769. commentStack
  1770. } = this.state;
  1771. const commentStackLength = commentStack.length;
  1772. if (commentStackLength === 0) return;
  1773. let i = commentStackLength - 1;
  1774. for (; i >= 0; i--) {
  1775. const commentWS = commentStack[i];
  1776. const commentEnd = commentWS.end;
  1777. const commentStart = commentWS.start;
  1778. if (commentStart === end) {
  1779. commentWS.leadingNode = node;
  1780. } else if (commentEnd === start) {
  1781. commentWS.trailingNode = node;
  1782. } else if (commentEnd < start) {
  1783. break;
  1784. }
  1785. }
  1786. }
  1787. }
  1788. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  1789. const lineBreakG = new RegExp(lineBreak.source, "g");
  1790. function isNewLine(code) {
  1791. switch (code) {
  1792. case 10:
  1793. case 13:
  1794. case 8232:
  1795. case 8233:
  1796. return true;
  1797. default:
  1798. return false;
  1799. }
  1800. }
  1801. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1802. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1803. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  1804. function isWhitespace(code) {
  1805. switch (code) {
  1806. case 0x0009:
  1807. case 0x000b:
  1808. case 0x000c:
  1809. case 32:
  1810. case 160:
  1811. case 5760:
  1812. case 0x2000:
  1813. case 0x2001:
  1814. case 0x2002:
  1815. case 0x2003:
  1816. case 0x2004:
  1817. case 0x2005:
  1818. case 0x2006:
  1819. case 0x2007:
  1820. case 0x2008:
  1821. case 0x2009:
  1822. case 0x200a:
  1823. case 0x202f:
  1824. case 0x205f:
  1825. case 0x3000:
  1826. case 0xfeff:
  1827. return true;
  1828. default:
  1829. return false;
  1830. }
  1831. }
  1832. class State {
  1833. constructor() {
  1834. this.flags = 1024;
  1835. this.curLine = void 0;
  1836. this.lineStart = void 0;
  1837. this.startLoc = void 0;
  1838. this.endLoc = void 0;
  1839. this.errors = [];
  1840. this.potentialArrowAt = -1;
  1841. this.noArrowAt = [];
  1842. this.noArrowParamsConversionAt = [];
  1843. this.topicContext = {
  1844. maxNumOfResolvableTopics: 0,
  1845. maxTopicIndex: null
  1846. };
  1847. this.labels = [];
  1848. this.commentsLen = 0;
  1849. this.commentStack = [];
  1850. this.pos = 0;
  1851. this.type = 139;
  1852. this.value = null;
  1853. this.start = 0;
  1854. this.end = 0;
  1855. this.lastTokEndLoc = null;
  1856. this.lastTokStartLoc = null;
  1857. this.context = [types.brace];
  1858. this.firstInvalidTemplateEscapePos = null;
  1859. this.strictErrors = new Map();
  1860. this.tokensLength = 0;
  1861. }
  1862. get strict() {
  1863. return (this.flags & 1) > 0;
  1864. }
  1865. set strict(value) {
  1866. if (value) {
  1867. this.flags |= 1;
  1868. } else {
  1869. this.flags &= ~1;
  1870. }
  1871. }
  1872. init({
  1873. strictMode,
  1874. sourceType,
  1875. startLine,
  1876. startColumn
  1877. }) {
  1878. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1879. this.curLine = startLine;
  1880. this.lineStart = -startColumn;
  1881. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  1882. }
  1883. get maybeInArrowParameters() {
  1884. return (this.flags & 2) > 0;
  1885. }
  1886. set maybeInArrowParameters(value) {
  1887. if (value) {
  1888. this.flags |= 2;
  1889. } else {
  1890. this.flags &= ~2;
  1891. }
  1892. }
  1893. get inType() {
  1894. return (this.flags & 4) > 0;
  1895. }
  1896. set inType(value) {
  1897. if (value) {
  1898. this.flags |= 4;
  1899. } else {
  1900. this.flags &= ~4;
  1901. }
  1902. }
  1903. get noAnonFunctionType() {
  1904. return (this.flags & 8) > 0;
  1905. }
  1906. set noAnonFunctionType(value) {
  1907. if (value) {
  1908. this.flags |= 8;
  1909. } else {
  1910. this.flags &= ~8;
  1911. }
  1912. }
  1913. get hasFlowComment() {
  1914. return (this.flags & 16) > 0;
  1915. }
  1916. set hasFlowComment(value) {
  1917. if (value) {
  1918. this.flags |= 16;
  1919. } else {
  1920. this.flags &= ~16;
  1921. }
  1922. }
  1923. get isAmbientContext() {
  1924. return (this.flags & 32) > 0;
  1925. }
  1926. set isAmbientContext(value) {
  1927. if (value) {
  1928. this.flags |= 32;
  1929. } else {
  1930. this.flags &= ~32;
  1931. }
  1932. }
  1933. get inAbstractClass() {
  1934. return (this.flags & 64) > 0;
  1935. }
  1936. set inAbstractClass(value) {
  1937. if (value) {
  1938. this.flags |= 64;
  1939. } else {
  1940. this.flags &= ~64;
  1941. }
  1942. }
  1943. get inDisallowConditionalTypesContext() {
  1944. return (this.flags & 128) > 0;
  1945. }
  1946. set inDisallowConditionalTypesContext(value) {
  1947. if (value) {
  1948. this.flags |= 128;
  1949. } else {
  1950. this.flags &= ~128;
  1951. }
  1952. }
  1953. get soloAwait() {
  1954. return (this.flags & 256) > 0;
  1955. }
  1956. set soloAwait(value) {
  1957. if (value) {
  1958. this.flags |= 256;
  1959. } else {
  1960. this.flags &= ~256;
  1961. }
  1962. }
  1963. get inFSharpPipelineDirectBody() {
  1964. return (this.flags & 512) > 0;
  1965. }
  1966. set inFSharpPipelineDirectBody(value) {
  1967. if (value) {
  1968. this.flags |= 512;
  1969. } else {
  1970. this.flags &= ~512;
  1971. }
  1972. }
  1973. get canStartJSXElement() {
  1974. return (this.flags & 1024) > 0;
  1975. }
  1976. set canStartJSXElement(value) {
  1977. if (value) {
  1978. this.flags |= 1024;
  1979. } else {
  1980. this.flags &= ~1024;
  1981. }
  1982. }
  1983. get containsEsc() {
  1984. return (this.flags & 2048) > 0;
  1985. }
  1986. set containsEsc(value) {
  1987. if (value) {
  1988. this.flags |= 2048;
  1989. } else {
  1990. this.flags &= ~2048;
  1991. }
  1992. }
  1993. curPosition() {
  1994. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  1995. }
  1996. clone() {
  1997. const state = new State();
  1998. state.flags = this.flags;
  1999. state.curLine = this.curLine;
  2000. state.lineStart = this.lineStart;
  2001. state.startLoc = this.startLoc;
  2002. state.endLoc = this.endLoc;
  2003. state.errors = this.errors.slice();
  2004. state.potentialArrowAt = this.potentialArrowAt;
  2005. state.noArrowAt = this.noArrowAt.slice();
  2006. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  2007. state.topicContext = this.topicContext;
  2008. state.labels = this.labels.slice();
  2009. state.commentsLen = this.commentsLen;
  2010. state.commentStack = this.commentStack.slice();
  2011. state.pos = this.pos;
  2012. state.type = this.type;
  2013. state.value = this.value;
  2014. state.start = this.start;
  2015. state.end = this.end;
  2016. state.lastTokEndLoc = this.lastTokEndLoc;
  2017. state.lastTokStartLoc = this.lastTokStartLoc;
  2018. state.context = this.context.slice();
  2019. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  2020. state.strictErrors = this.strictErrors;
  2021. state.tokensLength = this.tokensLength;
  2022. return state;
  2023. }
  2024. }
  2025. var _isDigit = function isDigit(code) {
  2026. return code >= 48 && code <= 57;
  2027. };
  2028. const forbiddenNumericSeparatorSiblings = {
  2029. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  2030. hex: new Set([46, 88, 95, 120])
  2031. };
  2032. const isAllowedNumericSeparatorSibling = {
  2033. bin: ch => ch === 48 || ch === 49,
  2034. oct: ch => ch >= 48 && ch <= 55,
  2035. dec: ch => ch >= 48 && ch <= 57,
  2036. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  2037. };
  2038. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  2039. const initialPos = pos;
  2040. const initialLineStart = lineStart;
  2041. const initialCurLine = curLine;
  2042. let out = "";
  2043. let firstInvalidLoc = null;
  2044. let chunkStart = pos;
  2045. const {
  2046. length
  2047. } = input;
  2048. for (;;) {
  2049. if (pos >= length) {
  2050. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2051. out += input.slice(chunkStart, pos);
  2052. break;
  2053. }
  2054. const ch = input.charCodeAt(pos);
  2055. if (isStringEnd(type, ch, input, pos)) {
  2056. out += input.slice(chunkStart, pos);
  2057. break;
  2058. }
  2059. if (ch === 92) {
  2060. out += input.slice(chunkStart, pos);
  2061. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  2062. if (res.ch === null && !firstInvalidLoc) {
  2063. firstInvalidLoc = {
  2064. pos,
  2065. lineStart,
  2066. curLine
  2067. };
  2068. } else {
  2069. out += res.ch;
  2070. }
  2071. ({
  2072. pos,
  2073. lineStart,
  2074. curLine
  2075. } = res);
  2076. chunkStart = pos;
  2077. } else if (ch === 8232 || ch === 8233) {
  2078. ++pos;
  2079. ++curLine;
  2080. lineStart = pos;
  2081. } else if (ch === 10 || ch === 13) {
  2082. if (type === "template") {
  2083. out += input.slice(chunkStart, pos) + "\n";
  2084. ++pos;
  2085. if (ch === 13 && input.charCodeAt(pos) === 10) {
  2086. ++pos;
  2087. }
  2088. ++curLine;
  2089. chunkStart = lineStart = pos;
  2090. } else {
  2091. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2092. }
  2093. } else {
  2094. ++pos;
  2095. }
  2096. }
  2097. return {
  2098. pos,
  2099. str: out,
  2100. firstInvalidLoc,
  2101. lineStart,
  2102. curLine,
  2103. containsInvalid: !!firstInvalidLoc
  2104. };
  2105. }
  2106. function isStringEnd(type, ch, input, pos) {
  2107. if (type === "template") {
  2108. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2109. }
  2110. return ch === (type === "double" ? 34 : 39);
  2111. }
  2112. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2113. const throwOnInvalid = !inTemplate;
  2114. pos++;
  2115. const res = ch => ({
  2116. pos,
  2117. ch,
  2118. lineStart,
  2119. curLine
  2120. });
  2121. const ch = input.charCodeAt(pos++);
  2122. switch (ch) {
  2123. case 110:
  2124. return res("\n");
  2125. case 114:
  2126. return res("\r");
  2127. case 120:
  2128. {
  2129. let code;
  2130. ({
  2131. code,
  2132. pos
  2133. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2134. return res(code === null ? null : String.fromCharCode(code));
  2135. }
  2136. case 117:
  2137. {
  2138. let code;
  2139. ({
  2140. code,
  2141. pos
  2142. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2143. return res(code === null ? null : String.fromCodePoint(code));
  2144. }
  2145. case 116:
  2146. return res("\t");
  2147. case 98:
  2148. return res("\b");
  2149. case 118:
  2150. return res("\u000b");
  2151. case 102:
  2152. return res("\f");
  2153. case 13:
  2154. if (input.charCodeAt(pos) === 10) {
  2155. ++pos;
  2156. }
  2157. case 10:
  2158. lineStart = pos;
  2159. ++curLine;
  2160. case 8232:
  2161. case 8233:
  2162. return res("");
  2163. case 56:
  2164. case 57:
  2165. if (inTemplate) {
  2166. return res(null);
  2167. } else {
  2168. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2169. }
  2170. default:
  2171. if (ch >= 48 && ch <= 55) {
  2172. const startPos = pos - 1;
  2173. const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
  2174. let octalStr = match[0];
  2175. let octal = parseInt(octalStr, 8);
  2176. if (octal > 255) {
  2177. octalStr = octalStr.slice(0, -1);
  2178. octal = parseInt(octalStr, 8);
  2179. }
  2180. pos += octalStr.length - 1;
  2181. const next = input.charCodeAt(pos);
  2182. if (octalStr !== "0" || next === 56 || next === 57) {
  2183. if (inTemplate) {
  2184. return res(null);
  2185. } else {
  2186. errors.strictNumericEscape(startPos, lineStart, curLine);
  2187. }
  2188. }
  2189. return res(String.fromCharCode(octal));
  2190. }
  2191. return res(String.fromCharCode(ch));
  2192. }
  2193. }
  2194. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2195. const initialPos = pos;
  2196. let n;
  2197. ({
  2198. n,
  2199. pos
  2200. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2201. if (n === null) {
  2202. if (throwOnInvalid) {
  2203. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2204. } else {
  2205. pos = initialPos - 1;
  2206. }
  2207. }
  2208. return {
  2209. code: n,
  2210. pos
  2211. };
  2212. }
  2213. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2214. const start = pos;
  2215. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2216. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2217. let invalid = false;
  2218. let total = 0;
  2219. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2220. const code = input.charCodeAt(pos);
  2221. let val;
  2222. if (code === 95 && allowNumSeparator !== "bail") {
  2223. const prev = input.charCodeAt(pos - 1);
  2224. const next = input.charCodeAt(pos + 1);
  2225. if (!allowNumSeparator) {
  2226. if (bailOnError) return {
  2227. n: null,
  2228. pos
  2229. };
  2230. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2231. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2232. if (bailOnError) return {
  2233. n: null,
  2234. pos
  2235. };
  2236. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2237. }
  2238. ++pos;
  2239. continue;
  2240. }
  2241. if (code >= 97) {
  2242. val = code - 97 + 10;
  2243. } else if (code >= 65) {
  2244. val = code - 65 + 10;
  2245. } else if (_isDigit(code)) {
  2246. val = code - 48;
  2247. } else {
  2248. val = Infinity;
  2249. }
  2250. if (val >= radix) {
  2251. if (val <= 9 && bailOnError) {
  2252. return {
  2253. n: null,
  2254. pos
  2255. };
  2256. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2257. val = 0;
  2258. } else if (forceLen) {
  2259. val = 0;
  2260. invalid = true;
  2261. } else {
  2262. break;
  2263. }
  2264. }
  2265. ++pos;
  2266. total = total * radix + val;
  2267. }
  2268. if (pos === start || len != null && pos - start !== len || invalid) {
  2269. return {
  2270. n: null,
  2271. pos
  2272. };
  2273. }
  2274. return {
  2275. n: total,
  2276. pos
  2277. };
  2278. }
  2279. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2280. const ch = input.charCodeAt(pos);
  2281. let code;
  2282. if (ch === 123) {
  2283. ++pos;
  2284. ({
  2285. code,
  2286. pos
  2287. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2288. ++pos;
  2289. if (code !== null && code > 0x10ffff) {
  2290. if (throwOnInvalid) {
  2291. errors.invalidCodePoint(pos, lineStart, curLine);
  2292. } else {
  2293. return {
  2294. code: null,
  2295. pos
  2296. };
  2297. }
  2298. }
  2299. } else {
  2300. ({
  2301. code,
  2302. pos
  2303. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2304. }
  2305. return {
  2306. code,
  2307. pos
  2308. };
  2309. }
  2310. function buildPosition(pos, lineStart, curLine) {
  2311. return new Position(curLine, pos - lineStart, pos);
  2312. }
  2313. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2314. class Token {
  2315. constructor(state) {
  2316. this.type = state.type;
  2317. this.value = state.value;
  2318. this.start = state.start;
  2319. this.end = state.end;
  2320. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2321. }
  2322. }
  2323. class Tokenizer extends CommentsParser {
  2324. constructor(options, input) {
  2325. super();
  2326. this.isLookahead = void 0;
  2327. this.tokens = [];
  2328. this.errorHandlers_readInt = {
  2329. invalidDigit: (pos, lineStart, curLine, radix) => {
  2330. if (!this.options.errorRecovery) return false;
  2331. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  2332. radix
  2333. });
  2334. return true;
  2335. },
  2336. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2337. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2338. };
  2339. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2340. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2341. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2342. });
  2343. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2344. strictNumericEscape: (pos, lineStart, curLine) => {
  2345. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  2346. },
  2347. unterminated: (pos, lineStart, curLine) => {
  2348. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  2349. }
  2350. });
  2351. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2352. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2353. unterminated: (pos, lineStart, curLine) => {
  2354. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  2355. }
  2356. });
  2357. this.state = new State();
  2358. this.state.init(options);
  2359. this.input = input;
  2360. this.length = input.length;
  2361. this.comments = [];
  2362. this.isLookahead = false;
  2363. }
  2364. pushToken(token) {
  2365. this.tokens.length = this.state.tokensLength;
  2366. this.tokens.push(token);
  2367. ++this.state.tokensLength;
  2368. }
  2369. next() {
  2370. this.checkKeywordEscapes();
  2371. if (this.options.tokens) {
  2372. this.pushToken(new Token(this.state));
  2373. }
  2374. this.state.lastTokEndLoc = this.state.endLoc;
  2375. this.state.lastTokStartLoc = this.state.startLoc;
  2376. this.nextToken();
  2377. }
  2378. eat(type) {
  2379. if (this.match(type)) {
  2380. this.next();
  2381. return true;
  2382. } else {
  2383. return false;
  2384. }
  2385. }
  2386. match(type) {
  2387. return this.state.type === type;
  2388. }
  2389. createLookaheadState(state) {
  2390. return {
  2391. pos: state.pos,
  2392. value: null,
  2393. type: state.type,
  2394. start: state.start,
  2395. end: state.end,
  2396. context: [this.curContext()],
  2397. inType: state.inType,
  2398. startLoc: state.startLoc,
  2399. lastTokEndLoc: state.lastTokEndLoc,
  2400. curLine: state.curLine,
  2401. lineStart: state.lineStart,
  2402. curPosition: state.curPosition
  2403. };
  2404. }
  2405. lookahead() {
  2406. const old = this.state;
  2407. this.state = this.createLookaheadState(old);
  2408. this.isLookahead = true;
  2409. this.nextToken();
  2410. this.isLookahead = false;
  2411. const curr = this.state;
  2412. this.state = old;
  2413. return curr;
  2414. }
  2415. nextTokenStart() {
  2416. return this.nextTokenStartSince(this.state.pos);
  2417. }
  2418. nextTokenStartSince(pos) {
  2419. skipWhiteSpace.lastIndex = pos;
  2420. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2421. }
  2422. lookaheadCharCode() {
  2423. return this.input.charCodeAt(this.nextTokenStart());
  2424. }
  2425. nextTokenInLineStart() {
  2426. return this.nextTokenInLineStartSince(this.state.pos);
  2427. }
  2428. nextTokenInLineStartSince(pos) {
  2429. skipWhiteSpaceInLine.lastIndex = pos;
  2430. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2431. }
  2432. lookaheadInLineCharCode() {
  2433. return this.input.charCodeAt(this.nextTokenInLineStart());
  2434. }
  2435. codePointAtPos(pos) {
  2436. let cp = this.input.charCodeAt(pos);
  2437. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2438. const trail = this.input.charCodeAt(pos);
  2439. if ((trail & 0xfc00) === 0xdc00) {
  2440. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2441. }
  2442. }
  2443. return cp;
  2444. }
  2445. setStrict(strict) {
  2446. this.state.strict = strict;
  2447. if (strict) {
  2448. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  2449. this.state.strictErrors.clear();
  2450. }
  2451. }
  2452. curContext() {
  2453. return this.state.context[this.state.context.length - 1];
  2454. }
  2455. nextToken() {
  2456. this.skipSpace();
  2457. this.state.start = this.state.pos;
  2458. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2459. if (this.state.pos >= this.length) {
  2460. this.finishToken(139);
  2461. return;
  2462. }
  2463. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2464. }
  2465. skipBlockComment(commentEnd) {
  2466. let startLoc;
  2467. if (!this.isLookahead) startLoc = this.state.curPosition();
  2468. const start = this.state.pos;
  2469. const end = this.input.indexOf(commentEnd, start + 2);
  2470. if (end === -1) {
  2471. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  2472. }
  2473. this.state.pos = end + commentEnd.length;
  2474. lineBreakG.lastIndex = start + 2;
  2475. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2476. ++this.state.curLine;
  2477. this.state.lineStart = lineBreakG.lastIndex;
  2478. }
  2479. if (this.isLookahead) return;
  2480. const comment = {
  2481. type: "CommentBlock",
  2482. value: this.input.slice(start + 2, end),
  2483. start,
  2484. end: end + commentEnd.length,
  2485. loc: new SourceLocation(startLoc, this.state.curPosition())
  2486. };
  2487. if (this.options.tokens) this.pushToken(comment);
  2488. return comment;
  2489. }
  2490. skipLineComment(startSkip) {
  2491. const start = this.state.pos;
  2492. let startLoc;
  2493. if (!this.isLookahead) startLoc = this.state.curPosition();
  2494. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2495. if (this.state.pos < this.length) {
  2496. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2497. ch = this.input.charCodeAt(this.state.pos);
  2498. }
  2499. }
  2500. if (this.isLookahead) return;
  2501. const end = this.state.pos;
  2502. const value = this.input.slice(start + startSkip, end);
  2503. const comment = {
  2504. type: "CommentLine",
  2505. value,
  2506. start,
  2507. end,
  2508. loc: new SourceLocation(startLoc, this.state.curPosition())
  2509. };
  2510. if (this.options.tokens) this.pushToken(comment);
  2511. return comment;
  2512. }
  2513. skipSpace() {
  2514. const spaceStart = this.state.pos;
  2515. const comments = [];
  2516. loop: while (this.state.pos < this.length) {
  2517. const ch = this.input.charCodeAt(this.state.pos);
  2518. switch (ch) {
  2519. case 32:
  2520. case 160:
  2521. case 9:
  2522. ++this.state.pos;
  2523. break;
  2524. case 13:
  2525. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2526. ++this.state.pos;
  2527. }
  2528. case 10:
  2529. case 8232:
  2530. case 8233:
  2531. ++this.state.pos;
  2532. ++this.state.curLine;
  2533. this.state.lineStart = this.state.pos;
  2534. break;
  2535. case 47:
  2536. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2537. case 42:
  2538. {
  2539. const comment = this.skipBlockComment("*/");
  2540. if (comment !== undefined) {
  2541. this.addComment(comment);
  2542. if (this.options.attachComment) comments.push(comment);
  2543. }
  2544. break;
  2545. }
  2546. case 47:
  2547. {
  2548. const comment = this.skipLineComment(2);
  2549. if (comment !== undefined) {
  2550. this.addComment(comment);
  2551. if (this.options.attachComment) comments.push(comment);
  2552. }
  2553. break;
  2554. }
  2555. default:
  2556. break loop;
  2557. }
  2558. break;
  2559. default:
  2560. if (isWhitespace(ch)) {
  2561. ++this.state.pos;
  2562. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  2563. const pos = this.state.pos;
  2564. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2565. const comment = this.skipLineComment(3);
  2566. if (comment !== undefined) {
  2567. this.addComment(comment);
  2568. if (this.options.attachComment) comments.push(comment);
  2569. }
  2570. } else {
  2571. break loop;
  2572. }
  2573. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  2574. const pos = this.state.pos;
  2575. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2576. const comment = this.skipLineComment(4);
  2577. if (comment !== undefined) {
  2578. this.addComment(comment);
  2579. if (this.options.attachComment) comments.push(comment);
  2580. }
  2581. } else {
  2582. break loop;
  2583. }
  2584. } else {
  2585. break loop;
  2586. }
  2587. }
  2588. }
  2589. if (comments.length > 0) {
  2590. const end = this.state.pos;
  2591. const commentWhitespace = {
  2592. start: spaceStart,
  2593. end,
  2594. comments,
  2595. leadingNode: null,
  2596. trailingNode: null,
  2597. containingNode: null
  2598. };
  2599. this.state.commentStack.push(commentWhitespace);
  2600. }
  2601. }
  2602. finishToken(type, val) {
  2603. this.state.end = this.state.pos;
  2604. this.state.endLoc = this.state.curPosition();
  2605. const prevType = this.state.type;
  2606. this.state.type = type;
  2607. this.state.value = val;
  2608. if (!this.isLookahead) {
  2609. this.updateContext(prevType);
  2610. }
  2611. }
  2612. replaceToken(type) {
  2613. this.state.type = type;
  2614. this.updateContext();
  2615. }
  2616. readToken_numberSign() {
  2617. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2618. return;
  2619. }
  2620. const nextPos = this.state.pos + 1;
  2621. const next = this.codePointAtPos(nextPos);
  2622. if (next >= 48 && next <= 57) {
  2623. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  2624. }
  2625. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2626. this.expectPlugin("recordAndTuple");
  2627. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2628. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  2629. }
  2630. this.state.pos += 2;
  2631. if (next === 123) {
  2632. this.finishToken(7);
  2633. } else {
  2634. this.finishToken(1);
  2635. }
  2636. } else if (isIdentifierStart(next)) {
  2637. ++this.state.pos;
  2638. this.finishToken(138, this.readWord1(next));
  2639. } else if (next === 92) {
  2640. ++this.state.pos;
  2641. this.finishToken(138, this.readWord1());
  2642. } else {
  2643. this.finishOp(27, 1);
  2644. }
  2645. }
  2646. readToken_dot() {
  2647. const next = this.input.charCodeAt(this.state.pos + 1);
  2648. if (next >= 48 && next <= 57) {
  2649. this.readNumber(true);
  2650. return;
  2651. }
  2652. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2653. this.state.pos += 3;
  2654. this.finishToken(21);
  2655. } else {
  2656. ++this.state.pos;
  2657. this.finishToken(16);
  2658. }
  2659. }
  2660. readToken_slash() {
  2661. const next = this.input.charCodeAt(this.state.pos + 1);
  2662. if (next === 61) {
  2663. this.finishOp(31, 2);
  2664. } else {
  2665. this.finishOp(56, 1);
  2666. }
  2667. }
  2668. readToken_interpreter() {
  2669. if (this.state.pos !== 0 || this.length < 2) return false;
  2670. let ch = this.input.charCodeAt(this.state.pos + 1);
  2671. if (ch !== 33) return false;
  2672. const start = this.state.pos;
  2673. this.state.pos += 1;
  2674. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2675. ch = this.input.charCodeAt(this.state.pos);
  2676. }
  2677. const value = this.input.slice(start + 2, this.state.pos);
  2678. this.finishToken(28, value);
  2679. return true;
  2680. }
  2681. readToken_mult_modulo(code) {
  2682. let type = code === 42 ? 55 : 54;
  2683. let width = 1;
  2684. let next = this.input.charCodeAt(this.state.pos + 1);
  2685. if (code === 42 && next === 42) {
  2686. width++;
  2687. next = this.input.charCodeAt(this.state.pos + 2);
  2688. type = 57;
  2689. }
  2690. if (next === 61 && !this.state.inType) {
  2691. width++;
  2692. type = code === 37 ? 33 : 30;
  2693. }
  2694. this.finishOp(type, width);
  2695. }
  2696. readToken_pipe_amp(code) {
  2697. const next = this.input.charCodeAt(this.state.pos + 1);
  2698. if (next === code) {
  2699. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2700. this.finishOp(30, 3);
  2701. } else {
  2702. this.finishOp(code === 124 ? 41 : 42, 2);
  2703. }
  2704. return;
  2705. }
  2706. if (code === 124) {
  2707. if (next === 62) {
  2708. this.finishOp(39, 2);
  2709. return;
  2710. }
  2711. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2712. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2713. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2714. }
  2715. this.state.pos += 2;
  2716. this.finishToken(9);
  2717. return;
  2718. }
  2719. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2720. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2721. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2722. }
  2723. this.state.pos += 2;
  2724. this.finishToken(4);
  2725. return;
  2726. }
  2727. }
  2728. if (next === 61) {
  2729. this.finishOp(30, 2);
  2730. return;
  2731. }
  2732. this.finishOp(code === 124 ? 43 : 45, 1);
  2733. }
  2734. readToken_caret() {
  2735. const next = this.input.charCodeAt(this.state.pos + 1);
  2736. if (next === 61 && !this.state.inType) {
  2737. this.finishOp(32, 2);
  2738. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2739. proposal: "hack",
  2740. topicToken: "^^"
  2741. }])) {
  2742. this.finishOp(37, 2);
  2743. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2744. if (lookaheadCh === 94) {
  2745. this.unexpected();
  2746. }
  2747. } else {
  2748. this.finishOp(44, 1);
  2749. }
  2750. }
  2751. readToken_atSign() {
  2752. const next = this.input.charCodeAt(this.state.pos + 1);
  2753. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2754. proposal: "hack",
  2755. topicToken: "@@"
  2756. }])) {
  2757. this.finishOp(38, 2);
  2758. } else {
  2759. this.finishOp(26, 1);
  2760. }
  2761. }
  2762. readToken_plus_min(code) {
  2763. const next = this.input.charCodeAt(this.state.pos + 1);
  2764. if (next === code) {
  2765. this.finishOp(34, 2);
  2766. return;
  2767. }
  2768. if (next === 61) {
  2769. this.finishOp(30, 2);
  2770. } else {
  2771. this.finishOp(53, 1);
  2772. }
  2773. }
  2774. readToken_lt() {
  2775. const {
  2776. pos
  2777. } = this.state;
  2778. const next = this.input.charCodeAt(pos + 1);
  2779. if (next === 60) {
  2780. if (this.input.charCodeAt(pos + 2) === 61) {
  2781. this.finishOp(30, 3);
  2782. return;
  2783. }
  2784. this.finishOp(51, 2);
  2785. return;
  2786. }
  2787. if (next === 61) {
  2788. this.finishOp(49, 2);
  2789. return;
  2790. }
  2791. this.finishOp(47, 1);
  2792. }
  2793. readToken_gt() {
  2794. const {
  2795. pos
  2796. } = this.state;
  2797. const next = this.input.charCodeAt(pos + 1);
  2798. if (next === 62) {
  2799. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2800. if (this.input.charCodeAt(pos + size) === 61) {
  2801. this.finishOp(30, size + 1);
  2802. return;
  2803. }
  2804. this.finishOp(52, size);
  2805. return;
  2806. }
  2807. if (next === 61) {
  2808. this.finishOp(49, 2);
  2809. return;
  2810. }
  2811. this.finishOp(48, 1);
  2812. }
  2813. readToken_eq_excl(code) {
  2814. const next = this.input.charCodeAt(this.state.pos + 1);
  2815. if (next === 61) {
  2816. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2817. return;
  2818. }
  2819. if (code === 61 && next === 62) {
  2820. this.state.pos += 2;
  2821. this.finishToken(19);
  2822. return;
  2823. }
  2824. this.finishOp(code === 61 ? 29 : 35, 1);
  2825. }
  2826. readToken_question() {
  2827. const next = this.input.charCodeAt(this.state.pos + 1);
  2828. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2829. if (next === 63) {
  2830. if (next2 === 61) {
  2831. this.finishOp(30, 3);
  2832. } else {
  2833. this.finishOp(40, 2);
  2834. }
  2835. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2836. this.state.pos += 2;
  2837. this.finishToken(18);
  2838. } else {
  2839. ++this.state.pos;
  2840. this.finishToken(17);
  2841. }
  2842. }
  2843. getTokenFromCode(code) {
  2844. switch (code) {
  2845. case 46:
  2846. this.readToken_dot();
  2847. return;
  2848. case 40:
  2849. ++this.state.pos;
  2850. this.finishToken(10);
  2851. return;
  2852. case 41:
  2853. ++this.state.pos;
  2854. this.finishToken(11);
  2855. return;
  2856. case 59:
  2857. ++this.state.pos;
  2858. this.finishToken(13);
  2859. return;
  2860. case 44:
  2861. ++this.state.pos;
  2862. this.finishToken(12);
  2863. return;
  2864. case 91:
  2865. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2866. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2867. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2868. }
  2869. this.state.pos += 2;
  2870. this.finishToken(2);
  2871. } else {
  2872. ++this.state.pos;
  2873. this.finishToken(0);
  2874. }
  2875. return;
  2876. case 93:
  2877. ++this.state.pos;
  2878. this.finishToken(3);
  2879. return;
  2880. case 123:
  2881. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2882. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2883. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2884. }
  2885. this.state.pos += 2;
  2886. this.finishToken(6);
  2887. } else {
  2888. ++this.state.pos;
  2889. this.finishToken(5);
  2890. }
  2891. return;
  2892. case 125:
  2893. ++this.state.pos;
  2894. this.finishToken(8);
  2895. return;
  2896. case 58:
  2897. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2898. this.finishOp(15, 2);
  2899. } else {
  2900. ++this.state.pos;
  2901. this.finishToken(14);
  2902. }
  2903. return;
  2904. case 63:
  2905. this.readToken_question();
  2906. return;
  2907. case 96:
  2908. this.readTemplateToken();
  2909. return;
  2910. case 48:
  2911. {
  2912. const next = this.input.charCodeAt(this.state.pos + 1);
  2913. if (next === 120 || next === 88) {
  2914. this.readRadixNumber(16);
  2915. return;
  2916. }
  2917. if (next === 111 || next === 79) {
  2918. this.readRadixNumber(8);
  2919. return;
  2920. }
  2921. if (next === 98 || next === 66) {
  2922. this.readRadixNumber(2);
  2923. return;
  2924. }
  2925. }
  2926. case 49:
  2927. case 50:
  2928. case 51:
  2929. case 52:
  2930. case 53:
  2931. case 54:
  2932. case 55:
  2933. case 56:
  2934. case 57:
  2935. this.readNumber(false);
  2936. return;
  2937. case 34:
  2938. case 39:
  2939. this.readString(code);
  2940. return;
  2941. case 47:
  2942. this.readToken_slash();
  2943. return;
  2944. case 37:
  2945. case 42:
  2946. this.readToken_mult_modulo(code);
  2947. return;
  2948. case 124:
  2949. case 38:
  2950. this.readToken_pipe_amp(code);
  2951. return;
  2952. case 94:
  2953. this.readToken_caret();
  2954. return;
  2955. case 43:
  2956. case 45:
  2957. this.readToken_plus_min(code);
  2958. return;
  2959. case 60:
  2960. this.readToken_lt();
  2961. return;
  2962. case 62:
  2963. this.readToken_gt();
  2964. return;
  2965. case 61:
  2966. case 33:
  2967. this.readToken_eq_excl(code);
  2968. return;
  2969. case 126:
  2970. this.finishOp(36, 1);
  2971. return;
  2972. case 64:
  2973. this.readToken_atSign();
  2974. return;
  2975. case 35:
  2976. this.readToken_numberSign();
  2977. return;
  2978. case 92:
  2979. this.readWord();
  2980. return;
  2981. default:
  2982. if (isIdentifierStart(code)) {
  2983. this.readWord(code);
  2984. return;
  2985. }
  2986. }
  2987. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  2988. unexpected: String.fromCodePoint(code)
  2989. });
  2990. }
  2991. finishOp(type, size) {
  2992. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2993. this.state.pos += size;
  2994. this.finishToken(type, str);
  2995. }
  2996. readRegexp() {
  2997. const startLoc = this.state.startLoc;
  2998. const start = this.state.start + 1;
  2999. let escaped, inClass;
  3000. let {
  3001. pos
  3002. } = this.state;
  3003. for (;; ++pos) {
  3004. if (pos >= this.length) {
  3005. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  3006. }
  3007. const ch = this.input.charCodeAt(pos);
  3008. if (isNewLine(ch)) {
  3009. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  3010. }
  3011. if (escaped) {
  3012. escaped = false;
  3013. } else {
  3014. if (ch === 91) {
  3015. inClass = true;
  3016. } else if (ch === 93 && inClass) {
  3017. inClass = false;
  3018. } else if (ch === 47 && !inClass) {
  3019. break;
  3020. }
  3021. escaped = ch === 92;
  3022. }
  3023. }
  3024. const content = this.input.slice(start, pos);
  3025. ++pos;
  3026. let mods = "";
  3027. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  3028. while (pos < this.length) {
  3029. const cp = this.codePointAtPos(pos);
  3030. const char = String.fromCharCode(cp);
  3031. if (VALID_REGEX_FLAGS.has(cp)) {
  3032. if (cp === 118) {
  3033. if (mods.includes("u")) {
  3034. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3035. }
  3036. } else if (cp === 117) {
  3037. if (mods.includes("v")) {
  3038. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3039. }
  3040. }
  3041. if (mods.includes(char)) {
  3042. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  3043. }
  3044. } else if (isIdentifierChar(cp) || cp === 92) {
  3045. this.raise(Errors.MalformedRegExpFlags, nextPos());
  3046. } else {
  3047. break;
  3048. }
  3049. ++pos;
  3050. mods += char;
  3051. }
  3052. this.state.pos = pos;
  3053. this.finishToken(137, {
  3054. pattern: content,
  3055. flags: mods
  3056. });
  3057. }
  3058. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  3059. const {
  3060. n,
  3061. pos
  3062. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  3063. this.state.pos = pos;
  3064. return n;
  3065. }
  3066. readRadixNumber(radix) {
  3067. const startLoc = this.state.curPosition();
  3068. let isBigInt = false;
  3069. this.state.pos += 2;
  3070. const val = this.readInt(radix);
  3071. if (val == null) {
  3072. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  3073. radix
  3074. });
  3075. }
  3076. const next = this.input.charCodeAt(this.state.pos);
  3077. if (next === 110) {
  3078. ++this.state.pos;
  3079. isBigInt = true;
  3080. } else if (next === 109) {
  3081. throw this.raise(Errors.InvalidDecimal, startLoc);
  3082. }
  3083. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3084. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3085. }
  3086. if (isBigInt) {
  3087. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  3088. this.finishToken(135, str);
  3089. return;
  3090. }
  3091. this.finishToken(134, val);
  3092. }
  3093. readNumber(startsWithDot) {
  3094. const start = this.state.pos;
  3095. const startLoc = this.state.curPosition();
  3096. let isFloat = false;
  3097. let isBigInt = false;
  3098. let isDecimal = false;
  3099. let hasExponent = false;
  3100. let isOctal = false;
  3101. if (!startsWithDot && this.readInt(10) === null) {
  3102. this.raise(Errors.InvalidNumber, this.state.curPosition());
  3103. }
  3104. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3105. if (hasLeadingZero) {
  3106. const integer = this.input.slice(start, this.state.pos);
  3107. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  3108. if (!this.state.strict) {
  3109. const underscorePos = integer.indexOf("_");
  3110. if (underscorePos > 0) {
  3111. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  3112. }
  3113. }
  3114. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3115. }
  3116. let next = this.input.charCodeAt(this.state.pos);
  3117. if (next === 46 && !isOctal) {
  3118. ++this.state.pos;
  3119. this.readInt(10);
  3120. isFloat = true;
  3121. next = this.input.charCodeAt(this.state.pos);
  3122. }
  3123. if ((next === 69 || next === 101) && !isOctal) {
  3124. next = this.input.charCodeAt(++this.state.pos);
  3125. if (next === 43 || next === 45) {
  3126. ++this.state.pos;
  3127. }
  3128. if (this.readInt(10) === null) {
  3129. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  3130. }
  3131. isFloat = true;
  3132. hasExponent = true;
  3133. next = this.input.charCodeAt(this.state.pos);
  3134. }
  3135. if (next === 110) {
  3136. if (isFloat || hasLeadingZero) {
  3137. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  3138. }
  3139. ++this.state.pos;
  3140. isBigInt = true;
  3141. }
  3142. if (next === 109) {
  3143. this.expectPlugin("decimal", this.state.curPosition());
  3144. if (hasExponent || hasLeadingZero) {
  3145. this.raise(Errors.InvalidDecimal, startLoc);
  3146. }
  3147. ++this.state.pos;
  3148. isDecimal = true;
  3149. }
  3150. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3151. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3152. }
  3153. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3154. if (isBigInt) {
  3155. this.finishToken(135, str);
  3156. return;
  3157. }
  3158. if (isDecimal) {
  3159. this.finishToken(136, str);
  3160. return;
  3161. }
  3162. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3163. this.finishToken(134, val);
  3164. }
  3165. readCodePoint(throwOnInvalid) {
  3166. const {
  3167. code,
  3168. pos
  3169. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3170. this.state.pos = pos;
  3171. return code;
  3172. }
  3173. readString(quote) {
  3174. const {
  3175. str,
  3176. pos,
  3177. curLine,
  3178. lineStart
  3179. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3180. this.state.pos = pos + 1;
  3181. this.state.lineStart = lineStart;
  3182. this.state.curLine = curLine;
  3183. this.finishToken(133, str);
  3184. }
  3185. readTemplateContinuation() {
  3186. if (!this.match(8)) {
  3187. this.unexpected(null, 8);
  3188. }
  3189. this.state.pos--;
  3190. this.readTemplateToken();
  3191. }
  3192. readTemplateToken() {
  3193. const opening = this.input[this.state.pos];
  3194. const {
  3195. str,
  3196. firstInvalidLoc,
  3197. pos,
  3198. curLine,
  3199. lineStart
  3200. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3201. this.state.pos = pos + 1;
  3202. this.state.lineStart = lineStart;
  3203. this.state.curLine = curLine;
  3204. if (firstInvalidLoc) {
  3205. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3206. }
  3207. if (this.input.codePointAt(pos) === 96) {
  3208. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3209. } else {
  3210. this.state.pos++;
  3211. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3212. }
  3213. }
  3214. recordStrictModeErrors(toParseError, at) {
  3215. const index = at.index;
  3216. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3217. this.raise(toParseError, at);
  3218. } else {
  3219. this.state.strictErrors.set(index, [toParseError, at]);
  3220. }
  3221. }
  3222. readWord1(firstCode) {
  3223. this.state.containsEsc = false;
  3224. let word = "";
  3225. const start = this.state.pos;
  3226. let chunkStart = this.state.pos;
  3227. if (firstCode !== undefined) {
  3228. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3229. }
  3230. while (this.state.pos < this.length) {
  3231. const ch = this.codePointAtPos(this.state.pos);
  3232. if (isIdentifierChar(ch)) {
  3233. this.state.pos += ch <= 0xffff ? 1 : 2;
  3234. } else if (ch === 92) {
  3235. this.state.containsEsc = true;
  3236. word += this.input.slice(chunkStart, this.state.pos);
  3237. const escStart = this.state.curPosition();
  3238. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3239. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3240. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  3241. chunkStart = this.state.pos - 1;
  3242. continue;
  3243. }
  3244. ++this.state.pos;
  3245. const esc = this.readCodePoint(true);
  3246. if (esc !== null) {
  3247. if (!identifierCheck(esc)) {
  3248. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  3249. }
  3250. word += String.fromCodePoint(esc);
  3251. }
  3252. chunkStart = this.state.pos;
  3253. } else {
  3254. break;
  3255. }
  3256. }
  3257. return word + this.input.slice(chunkStart, this.state.pos);
  3258. }
  3259. readWord(firstCode) {
  3260. const word = this.readWord1(firstCode);
  3261. const type = keywords$1.get(word);
  3262. if (type !== undefined) {
  3263. this.finishToken(type, tokenLabelName(type));
  3264. } else {
  3265. this.finishToken(132, word);
  3266. }
  3267. }
  3268. checkKeywordEscapes() {
  3269. const {
  3270. type
  3271. } = this.state;
  3272. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3273. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  3274. reservedWord: tokenLabelName(type)
  3275. });
  3276. }
  3277. }
  3278. raise(toParseError, at, details = {}) {
  3279. const loc = at instanceof Position ? at : at.loc.start;
  3280. const error = toParseError(loc, details);
  3281. if (!this.options.errorRecovery) throw error;
  3282. if (!this.isLookahead) this.state.errors.push(error);
  3283. return error;
  3284. }
  3285. raiseOverwrite(toParseError, at, details = {}) {
  3286. const loc = at instanceof Position ? at : at.loc.start;
  3287. const pos = loc.index;
  3288. const errors = this.state.errors;
  3289. for (let i = errors.length - 1; i >= 0; i--) {
  3290. const error = errors[i];
  3291. if (error.loc.index === pos) {
  3292. return errors[i] = toParseError(loc, details);
  3293. }
  3294. if (error.loc.index < pos) break;
  3295. }
  3296. return this.raise(toParseError, at, details);
  3297. }
  3298. updateContext(prevType) {}
  3299. unexpected(loc, type) {
  3300. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  3301. expected: type ? tokenLabelName(type) : null
  3302. });
  3303. }
  3304. expectPlugin(pluginName, loc) {
  3305. if (this.hasPlugin(pluginName)) {
  3306. return true;
  3307. }
  3308. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  3309. missingPlugin: [pluginName]
  3310. });
  3311. }
  3312. expectOnePlugin(pluginNames) {
  3313. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3314. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  3315. missingPlugin: pluginNames
  3316. });
  3317. }
  3318. }
  3319. errorBuilder(error) {
  3320. return (pos, lineStart, curLine) => {
  3321. this.raise(error, buildPosition(pos, lineStart, curLine));
  3322. };
  3323. }
  3324. }
  3325. class ClassScope {
  3326. constructor() {
  3327. this.privateNames = new Set();
  3328. this.loneAccessors = new Map();
  3329. this.undefinedPrivateNames = new Map();
  3330. }
  3331. }
  3332. class ClassScopeHandler {
  3333. constructor(parser) {
  3334. this.parser = void 0;
  3335. this.stack = [];
  3336. this.undefinedPrivateNames = new Map();
  3337. this.parser = parser;
  3338. }
  3339. current() {
  3340. return this.stack[this.stack.length - 1];
  3341. }
  3342. enter() {
  3343. this.stack.push(new ClassScope());
  3344. }
  3345. exit() {
  3346. const oldClassScope = this.stack.pop();
  3347. const current = this.current();
  3348. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3349. if (current) {
  3350. if (!current.undefinedPrivateNames.has(name)) {
  3351. current.undefinedPrivateNames.set(name, loc);
  3352. }
  3353. } else {
  3354. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3355. identifierName: name
  3356. });
  3357. }
  3358. }
  3359. }
  3360. declarePrivateName(name, elementType, loc) {
  3361. const {
  3362. privateNames,
  3363. loneAccessors,
  3364. undefinedPrivateNames
  3365. } = this.current();
  3366. let redefined = privateNames.has(name);
  3367. if (elementType & 3) {
  3368. const accessor = redefined && loneAccessors.get(name);
  3369. if (accessor) {
  3370. const oldStatic = accessor & 4;
  3371. const newStatic = elementType & 4;
  3372. const oldKind = accessor & 3;
  3373. const newKind = elementType & 3;
  3374. redefined = oldKind === newKind || oldStatic !== newStatic;
  3375. if (!redefined) loneAccessors.delete(name);
  3376. } else if (!redefined) {
  3377. loneAccessors.set(name, elementType);
  3378. }
  3379. }
  3380. if (redefined) {
  3381. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  3382. identifierName: name
  3383. });
  3384. }
  3385. privateNames.add(name);
  3386. undefinedPrivateNames.delete(name);
  3387. }
  3388. usePrivateName(name, loc) {
  3389. let classScope;
  3390. for (classScope of this.stack) {
  3391. if (classScope.privateNames.has(name)) return;
  3392. }
  3393. if (classScope) {
  3394. classScope.undefinedPrivateNames.set(name, loc);
  3395. } else {
  3396. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3397. identifierName: name
  3398. });
  3399. }
  3400. }
  3401. }
  3402. class ExpressionScope {
  3403. constructor(type = 0) {
  3404. this.type = type;
  3405. }
  3406. canBeArrowParameterDeclaration() {
  3407. return this.type === 2 || this.type === 1;
  3408. }
  3409. isCertainlyParameterDeclaration() {
  3410. return this.type === 3;
  3411. }
  3412. }
  3413. class ArrowHeadParsingScope extends ExpressionScope {
  3414. constructor(type) {
  3415. super(type);
  3416. this.declarationErrors = new Map();
  3417. }
  3418. recordDeclarationError(ParsingErrorClass, at) {
  3419. const index = at.index;
  3420. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3421. }
  3422. clearDeclarationError(index) {
  3423. this.declarationErrors.delete(index);
  3424. }
  3425. iterateErrors(iterator) {
  3426. this.declarationErrors.forEach(iterator);
  3427. }
  3428. }
  3429. class ExpressionScopeHandler {
  3430. constructor(parser) {
  3431. this.parser = void 0;
  3432. this.stack = [new ExpressionScope()];
  3433. this.parser = parser;
  3434. }
  3435. enter(scope) {
  3436. this.stack.push(scope);
  3437. }
  3438. exit() {
  3439. this.stack.pop();
  3440. }
  3441. recordParameterInitializerError(toParseError, node) {
  3442. const origin = node.loc.start;
  3443. const {
  3444. stack
  3445. } = this;
  3446. let i = stack.length - 1;
  3447. let scope = stack[i];
  3448. while (!scope.isCertainlyParameterDeclaration()) {
  3449. if (scope.canBeArrowParameterDeclaration()) {
  3450. scope.recordDeclarationError(toParseError, origin);
  3451. } else {
  3452. return;
  3453. }
  3454. scope = stack[--i];
  3455. }
  3456. this.parser.raise(toParseError, origin);
  3457. }
  3458. recordArrowParameterBindingError(error, node) {
  3459. const {
  3460. stack
  3461. } = this;
  3462. const scope = stack[stack.length - 1];
  3463. const origin = node.loc.start;
  3464. if (scope.isCertainlyParameterDeclaration()) {
  3465. this.parser.raise(error, origin);
  3466. } else if (scope.canBeArrowParameterDeclaration()) {
  3467. scope.recordDeclarationError(error, origin);
  3468. } else {
  3469. return;
  3470. }
  3471. }
  3472. recordAsyncArrowParametersError(at) {
  3473. const {
  3474. stack
  3475. } = this;
  3476. let i = stack.length - 1;
  3477. let scope = stack[i];
  3478. while (scope.canBeArrowParameterDeclaration()) {
  3479. if (scope.type === 2) {
  3480. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  3481. }
  3482. scope = stack[--i];
  3483. }
  3484. }
  3485. validateAsPattern() {
  3486. const {
  3487. stack
  3488. } = this;
  3489. const currentScope = stack[stack.length - 1];
  3490. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3491. currentScope.iterateErrors(([toParseError, loc]) => {
  3492. this.parser.raise(toParseError, loc);
  3493. let i = stack.length - 2;
  3494. let scope = stack[i];
  3495. while (scope.canBeArrowParameterDeclaration()) {
  3496. scope.clearDeclarationError(loc.index);
  3497. scope = stack[--i];
  3498. }
  3499. });
  3500. }
  3501. }
  3502. function newParameterDeclarationScope() {
  3503. return new ExpressionScope(3);
  3504. }
  3505. function newArrowHeadScope() {
  3506. return new ArrowHeadParsingScope(1);
  3507. }
  3508. function newAsyncArrowScope() {
  3509. return new ArrowHeadParsingScope(2);
  3510. }
  3511. function newExpressionScope() {
  3512. return new ExpressionScope();
  3513. }
  3514. class ProductionParameterHandler {
  3515. constructor() {
  3516. this.stacks = [];
  3517. }
  3518. enter(flags) {
  3519. this.stacks.push(flags);
  3520. }
  3521. exit() {
  3522. this.stacks.pop();
  3523. }
  3524. currentFlags() {
  3525. return this.stacks[this.stacks.length - 1];
  3526. }
  3527. get hasAwait() {
  3528. return (this.currentFlags() & 2) > 0;
  3529. }
  3530. get hasYield() {
  3531. return (this.currentFlags() & 1) > 0;
  3532. }
  3533. get hasReturn() {
  3534. return (this.currentFlags() & 4) > 0;
  3535. }
  3536. get hasIn() {
  3537. return (this.currentFlags() & 8) > 0;
  3538. }
  3539. }
  3540. function functionFlags(isAsync, isGenerator) {
  3541. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  3542. }
  3543. class UtilParser extends Tokenizer {
  3544. addExtra(node, key, value, enumerable = true) {
  3545. if (!node) return;
  3546. const extra = node.extra = node.extra || {};
  3547. if (enumerable) {
  3548. extra[key] = value;
  3549. } else {
  3550. Object.defineProperty(extra, key, {
  3551. enumerable,
  3552. value
  3553. });
  3554. }
  3555. }
  3556. isContextual(token) {
  3557. return this.state.type === token && !this.state.containsEsc;
  3558. }
  3559. isUnparsedContextual(nameStart, name) {
  3560. const nameEnd = nameStart + name.length;
  3561. if (this.input.slice(nameStart, nameEnd) === name) {
  3562. const nextCh = this.input.charCodeAt(nameEnd);
  3563. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3564. }
  3565. return false;
  3566. }
  3567. isLookaheadContextual(name) {
  3568. const next = this.nextTokenStart();
  3569. return this.isUnparsedContextual(next, name);
  3570. }
  3571. eatContextual(token) {
  3572. if (this.isContextual(token)) {
  3573. this.next();
  3574. return true;
  3575. }
  3576. return false;
  3577. }
  3578. expectContextual(token, toParseError) {
  3579. if (!this.eatContextual(token)) {
  3580. if (toParseError != null) {
  3581. throw this.raise(toParseError, this.state.startLoc);
  3582. }
  3583. this.unexpected(null, token);
  3584. }
  3585. }
  3586. canInsertSemicolon() {
  3587. return this.match(139) || this.match(8) || this.hasPrecedingLineBreak();
  3588. }
  3589. hasPrecedingLineBreak() {
  3590. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  3591. }
  3592. hasFollowingLineBreak() {
  3593. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  3594. return skipWhiteSpaceToLineBreak.test(this.input);
  3595. }
  3596. isLineTerminator() {
  3597. return this.eat(13) || this.canInsertSemicolon();
  3598. }
  3599. semicolon(allowAsi = true) {
  3600. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3601. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  3602. }
  3603. expect(type, loc) {
  3604. this.eat(type) || this.unexpected(loc, type);
  3605. }
  3606. tryParse(fn, oldState = this.state.clone()) {
  3607. const abortSignal = {
  3608. node: null
  3609. };
  3610. try {
  3611. const node = fn((node = null) => {
  3612. abortSignal.node = node;
  3613. throw abortSignal;
  3614. });
  3615. if (this.state.errors.length > oldState.errors.length) {
  3616. const failState = this.state;
  3617. this.state = oldState;
  3618. this.state.tokensLength = failState.tokensLength;
  3619. return {
  3620. node,
  3621. error: failState.errors[oldState.errors.length],
  3622. thrown: false,
  3623. aborted: false,
  3624. failState
  3625. };
  3626. }
  3627. return {
  3628. node,
  3629. error: null,
  3630. thrown: false,
  3631. aborted: false,
  3632. failState: null
  3633. };
  3634. } catch (error) {
  3635. const failState = this.state;
  3636. this.state = oldState;
  3637. if (error instanceof SyntaxError) {
  3638. return {
  3639. node: null,
  3640. error,
  3641. thrown: true,
  3642. aborted: false,
  3643. failState
  3644. };
  3645. }
  3646. if (error === abortSignal) {
  3647. return {
  3648. node: abortSignal.node,
  3649. error: null,
  3650. thrown: false,
  3651. aborted: true,
  3652. failState
  3653. };
  3654. }
  3655. throw error;
  3656. }
  3657. }
  3658. checkExpressionErrors(refExpressionErrors, andThrow) {
  3659. if (!refExpressionErrors) return false;
  3660. const {
  3661. shorthandAssignLoc,
  3662. doubleProtoLoc,
  3663. privateKeyLoc,
  3664. optionalParametersLoc
  3665. } = refExpressionErrors;
  3666. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3667. if (!andThrow) {
  3668. return hasErrors;
  3669. }
  3670. if (shorthandAssignLoc != null) {
  3671. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  3672. }
  3673. if (doubleProtoLoc != null) {
  3674. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  3675. }
  3676. if (privateKeyLoc != null) {
  3677. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  3678. }
  3679. if (optionalParametersLoc != null) {
  3680. this.unexpected(optionalParametersLoc);
  3681. }
  3682. }
  3683. isLiteralPropertyName() {
  3684. return tokenIsLiteralPropertyName(this.state.type);
  3685. }
  3686. isPrivateName(node) {
  3687. return node.type === "PrivateName";
  3688. }
  3689. getPrivateNameSV(node) {
  3690. return node.id.name;
  3691. }
  3692. hasPropertyAsPrivateName(node) {
  3693. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3694. }
  3695. isObjectProperty(node) {
  3696. return node.type === "ObjectProperty";
  3697. }
  3698. isObjectMethod(node) {
  3699. return node.type === "ObjectMethod";
  3700. }
  3701. initializeScopes(inModule = this.options.sourceType === "module") {
  3702. const oldLabels = this.state.labels;
  3703. this.state.labels = [];
  3704. const oldExportedIdentifiers = this.exportedIdentifiers;
  3705. this.exportedIdentifiers = new Set();
  3706. const oldInModule = this.inModule;
  3707. this.inModule = inModule;
  3708. const oldScope = this.scope;
  3709. const ScopeHandler = this.getScopeHandler();
  3710. this.scope = new ScopeHandler(this, inModule);
  3711. const oldProdParam = this.prodParam;
  3712. this.prodParam = new ProductionParameterHandler();
  3713. const oldClassScope = this.classScope;
  3714. this.classScope = new ClassScopeHandler(this);
  3715. const oldExpressionScope = this.expressionScope;
  3716. this.expressionScope = new ExpressionScopeHandler(this);
  3717. return () => {
  3718. this.state.labels = oldLabels;
  3719. this.exportedIdentifiers = oldExportedIdentifiers;
  3720. this.inModule = oldInModule;
  3721. this.scope = oldScope;
  3722. this.prodParam = oldProdParam;
  3723. this.classScope = oldClassScope;
  3724. this.expressionScope = oldExpressionScope;
  3725. };
  3726. }
  3727. enterInitialScopes() {
  3728. let paramFlags = 0;
  3729. if (this.inModule) {
  3730. paramFlags |= 2;
  3731. }
  3732. this.scope.enter(1);
  3733. this.prodParam.enter(paramFlags);
  3734. }
  3735. checkDestructuringPrivate(refExpressionErrors) {
  3736. const {
  3737. privateKeyLoc
  3738. } = refExpressionErrors;
  3739. if (privateKeyLoc !== null) {
  3740. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3741. }
  3742. }
  3743. }
  3744. class ExpressionErrors {
  3745. constructor() {
  3746. this.shorthandAssignLoc = null;
  3747. this.doubleProtoLoc = null;
  3748. this.privateKeyLoc = null;
  3749. this.optionalParametersLoc = null;
  3750. }
  3751. }
  3752. class Node {
  3753. constructor(parser, pos, loc) {
  3754. this.type = "";
  3755. this.start = pos;
  3756. this.end = 0;
  3757. this.loc = new SourceLocation(loc);
  3758. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3759. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3760. }
  3761. }
  3762. const NodePrototype = Node.prototype;
  3763. {
  3764. NodePrototype.__clone = function () {
  3765. const newNode = new Node(undefined, this.start, this.loc.start);
  3766. const keys = Object.keys(this);
  3767. for (let i = 0, length = keys.length; i < length; i++) {
  3768. const key = keys[i];
  3769. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3770. newNode[key] = this[key];
  3771. }
  3772. }
  3773. return newNode;
  3774. };
  3775. }
  3776. function clonePlaceholder(node) {
  3777. return cloneIdentifier(node);
  3778. }
  3779. function cloneIdentifier(node) {
  3780. const {
  3781. type,
  3782. start,
  3783. end,
  3784. loc,
  3785. range,
  3786. extra,
  3787. name
  3788. } = node;
  3789. const cloned = Object.create(NodePrototype);
  3790. cloned.type = type;
  3791. cloned.start = start;
  3792. cloned.end = end;
  3793. cloned.loc = loc;
  3794. cloned.range = range;
  3795. cloned.extra = extra;
  3796. cloned.name = name;
  3797. if (type === "Placeholder") {
  3798. cloned.expectedNode = node.expectedNode;
  3799. }
  3800. return cloned;
  3801. }
  3802. function cloneStringLiteral(node) {
  3803. const {
  3804. type,
  3805. start,
  3806. end,
  3807. loc,
  3808. range,
  3809. extra
  3810. } = node;
  3811. if (type === "Placeholder") {
  3812. return clonePlaceholder(node);
  3813. }
  3814. const cloned = Object.create(NodePrototype);
  3815. cloned.type = type;
  3816. cloned.start = start;
  3817. cloned.end = end;
  3818. cloned.loc = loc;
  3819. cloned.range = range;
  3820. if (node.raw !== undefined) {
  3821. cloned.raw = node.raw;
  3822. } else {
  3823. cloned.extra = extra;
  3824. }
  3825. cloned.value = node.value;
  3826. return cloned;
  3827. }
  3828. class NodeUtils extends UtilParser {
  3829. startNode() {
  3830. const loc = this.state.startLoc;
  3831. return new Node(this, loc.index, loc);
  3832. }
  3833. startNodeAt(loc) {
  3834. return new Node(this, loc.index, loc);
  3835. }
  3836. startNodeAtNode(type) {
  3837. return this.startNodeAt(type.loc.start);
  3838. }
  3839. finishNode(node, type) {
  3840. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3841. }
  3842. finishNodeAt(node, type, endLoc) {
  3843. node.type = type;
  3844. node.end = endLoc.index;
  3845. node.loc.end = endLoc;
  3846. if (this.options.ranges) node.range[1] = endLoc.index;
  3847. if (this.options.attachComment) this.processComment(node);
  3848. return node;
  3849. }
  3850. resetStartLocation(node, startLoc) {
  3851. node.start = startLoc.index;
  3852. node.loc.start = startLoc;
  3853. if (this.options.ranges) node.range[0] = startLoc.index;
  3854. }
  3855. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3856. node.end = endLoc.index;
  3857. node.loc.end = endLoc;
  3858. if (this.options.ranges) node.range[1] = endLoc.index;
  3859. }
  3860. resetStartLocationFromNode(node, locationNode) {
  3861. this.resetStartLocation(node, locationNode.loc.start);
  3862. }
  3863. }
  3864. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3865. const FlowErrors = ParseErrorEnum`flow`({
  3866. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3867. 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.",
  3868. AssignReservedType: ({
  3869. reservedType
  3870. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3871. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3872. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3873. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3874. EnumBooleanMemberNotInitialized: ({
  3875. memberName,
  3876. enumName
  3877. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3878. EnumDuplicateMemberName: ({
  3879. memberName,
  3880. enumName
  3881. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3882. EnumInconsistentMemberValues: ({
  3883. enumName
  3884. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3885. EnumInvalidExplicitType: ({
  3886. invalidEnumType,
  3887. enumName
  3888. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3889. EnumInvalidExplicitTypeUnknownSupplied: ({
  3890. enumName
  3891. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3892. EnumInvalidMemberInitializerPrimaryType: ({
  3893. enumName,
  3894. memberName,
  3895. explicitType
  3896. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3897. EnumInvalidMemberInitializerSymbolType: ({
  3898. enumName,
  3899. memberName
  3900. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3901. EnumInvalidMemberInitializerUnknownType: ({
  3902. enumName,
  3903. memberName
  3904. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3905. EnumInvalidMemberName: ({
  3906. enumName,
  3907. memberName,
  3908. suggestion
  3909. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3910. EnumNumberMemberNotInitialized: ({
  3911. enumName,
  3912. memberName
  3913. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3914. EnumStringMemberInconsistentlyInitialized: ({
  3915. enumName
  3916. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3917. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3918. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3919. 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.",
  3920. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3921. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3922. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3923. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3924. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3925. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3926. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3927. PatternIsOptional: Object.assign({
  3928. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3929. }, {
  3930. reasonCode: "OptionalBindingPattern"
  3931. }),
  3932. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3933. SpreadVariance: "Spread properties cannot have variance.",
  3934. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3935. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3936. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3937. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3938. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3939. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3940. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3941. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3942. UnexpectedReservedType: ({
  3943. reservedType
  3944. }) => `Unexpected reserved type ${reservedType}.`,
  3945. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3946. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3947. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3948. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3949. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3950. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3951. UnsupportedDeclareExportKind: ({
  3952. unsupportedExportKind,
  3953. suggestion
  3954. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  3955. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3956. UnterminatedFlowComment: "Unterminated flow-comment."
  3957. });
  3958. function isEsModuleType(bodyElement) {
  3959. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3960. }
  3961. function hasTypeImportKind(node) {
  3962. return node.importKind === "type" || node.importKind === "typeof";
  3963. }
  3964. const exportSuggestions = {
  3965. const: "declare export var",
  3966. let: "declare export var",
  3967. type: "export type",
  3968. interface: "export interface"
  3969. };
  3970. function partition(list, test) {
  3971. const list1 = [];
  3972. const list2 = [];
  3973. for (let i = 0; i < list.length; i++) {
  3974. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  3975. }
  3976. return [list1, list2];
  3977. }
  3978. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  3979. var flow = superClass => class FlowParserMixin extends superClass {
  3980. constructor(...args) {
  3981. super(...args);
  3982. this.flowPragma = undefined;
  3983. }
  3984. getScopeHandler() {
  3985. return FlowScopeHandler;
  3986. }
  3987. shouldParseTypes() {
  3988. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  3989. }
  3990. shouldParseEnums() {
  3991. return !!this.getPluginOption("flow", "enums");
  3992. }
  3993. finishToken(type, val) {
  3994. if (type !== 133 && type !== 13 && type !== 28) {
  3995. if (this.flowPragma === undefined) {
  3996. this.flowPragma = null;
  3997. }
  3998. }
  3999. super.finishToken(type, val);
  4000. }
  4001. addComment(comment) {
  4002. if (this.flowPragma === undefined) {
  4003. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4004. if (!matches) ;else if (matches[1] === "flow") {
  4005. this.flowPragma = "flow";
  4006. } else if (matches[1] === "noflow") {
  4007. this.flowPragma = "noflow";
  4008. } else {
  4009. throw new Error("Unexpected flow pragma");
  4010. }
  4011. }
  4012. super.addComment(comment);
  4013. }
  4014. flowParseTypeInitialiser(tok) {
  4015. const oldInType = this.state.inType;
  4016. this.state.inType = true;
  4017. this.expect(tok || 14);
  4018. const type = this.flowParseType();
  4019. this.state.inType = oldInType;
  4020. return type;
  4021. }
  4022. flowParsePredicate() {
  4023. const node = this.startNode();
  4024. const moduloLoc = this.state.startLoc;
  4025. this.next();
  4026. this.expectContextual(110);
  4027. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  4028. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  4029. }
  4030. if (this.eat(10)) {
  4031. node.value = super.parseExpression();
  4032. this.expect(11);
  4033. return this.finishNode(node, "DeclaredPredicate");
  4034. } else {
  4035. return this.finishNode(node, "InferredPredicate");
  4036. }
  4037. }
  4038. flowParseTypeAndPredicateInitialiser() {
  4039. const oldInType = this.state.inType;
  4040. this.state.inType = true;
  4041. this.expect(14);
  4042. let type = null;
  4043. let predicate = null;
  4044. if (this.match(54)) {
  4045. this.state.inType = oldInType;
  4046. predicate = this.flowParsePredicate();
  4047. } else {
  4048. type = this.flowParseType();
  4049. this.state.inType = oldInType;
  4050. if (this.match(54)) {
  4051. predicate = this.flowParsePredicate();
  4052. }
  4053. }
  4054. return [type, predicate];
  4055. }
  4056. flowParseDeclareClass(node) {
  4057. this.next();
  4058. this.flowParseInterfaceish(node, true);
  4059. return this.finishNode(node, "DeclareClass");
  4060. }
  4061. flowParseDeclareFunction(node) {
  4062. this.next();
  4063. const id = node.id = this.parseIdentifier();
  4064. const typeNode = this.startNode();
  4065. const typeContainer = this.startNode();
  4066. if (this.match(47)) {
  4067. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4068. } else {
  4069. typeNode.typeParameters = null;
  4070. }
  4071. this.expect(10);
  4072. const tmp = this.flowParseFunctionTypeParams();
  4073. typeNode.params = tmp.params;
  4074. typeNode.rest = tmp.rest;
  4075. typeNode.this = tmp._this;
  4076. this.expect(11);
  4077. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4078. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4079. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4080. this.resetEndLocation(id);
  4081. this.semicolon();
  4082. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4083. return this.finishNode(node, "DeclareFunction");
  4084. }
  4085. flowParseDeclare(node, insideModule) {
  4086. if (this.match(80)) {
  4087. return this.flowParseDeclareClass(node);
  4088. } else if (this.match(68)) {
  4089. return this.flowParseDeclareFunction(node);
  4090. } else if (this.match(74)) {
  4091. return this.flowParseDeclareVariable(node);
  4092. } else if (this.eatContextual(127)) {
  4093. if (this.match(16)) {
  4094. return this.flowParseDeclareModuleExports(node);
  4095. } else {
  4096. if (insideModule) {
  4097. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  4098. }
  4099. return this.flowParseDeclareModule(node);
  4100. }
  4101. } else if (this.isContextual(130)) {
  4102. return this.flowParseDeclareTypeAlias(node);
  4103. } else if (this.isContextual(131)) {
  4104. return this.flowParseDeclareOpaqueType(node);
  4105. } else if (this.isContextual(129)) {
  4106. return this.flowParseDeclareInterface(node);
  4107. } else if (this.match(82)) {
  4108. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4109. } else {
  4110. this.unexpected();
  4111. }
  4112. }
  4113. flowParseDeclareVariable(node) {
  4114. this.next();
  4115. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4116. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4117. this.semicolon();
  4118. return this.finishNode(node, "DeclareVariable");
  4119. }
  4120. flowParseDeclareModule(node) {
  4121. this.scope.enter(0);
  4122. if (this.match(133)) {
  4123. node.id = super.parseExprAtom();
  4124. } else {
  4125. node.id = this.parseIdentifier();
  4126. }
  4127. const bodyNode = node.body = this.startNode();
  4128. const body = bodyNode.body = [];
  4129. this.expect(5);
  4130. while (!this.match(8)) {
  4131. let bodyNode = this.startNode();
  4132. if (this.match(83)) {
  4133. this.next();
  4134. if (!this.isContextual(130) && !this.match(87)) {
  4135. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  4136. }
  4137. super.parseImport(bodyNode);
  4138. } else {
  4139. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4140. bodyNode = this.flowParseDeclare(bodyNode, true);
  4141. }
  4142. body.push(bodyNode);
  4143. }
  4144. this.scope.exit();
  4145. this.expect(8);
  4146. this.finishNode(bodyNode, "BlockStatement");
  4147. let kind = null;
  4148. let hasModuleExport = false;
  4149. body.forEach(bodyElement => {
  4150. if (isEsModuleType(bodyElement)) {
  4151. if (kind === "CommonJS") {
  4152. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4153. }
  4154. kind = "ES";
  4155. } else if (bodyElement.type === "DeclareModuleExports") {
  4156. if (hasModuleExport) {
  4157. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  4158. }
  4159. if (kind === "ES") {
  4160. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4161. }
  4162. kind = "CommonJS";
  4163. hasModuleExport = true;
  4164. }
  4165. });
  4166. node.kind = kind || "CommonJS";
  4167. return this.finishNode(node, "DeclareModule");
  4168. }
  4169. flowParseDeclareExportDeclaration(node, insideModule) {
  4170. this.expect(82);
  4171. if (this.eat(65)) {
  4172. if (this.match(68) || this.match(80)) {
  4173. node.declaration = this.flowParseDeclare(this.startNode());
  4174. } else {
  4175. node.declaration = this.flowParseType();
  4176. this.semicolon();
  4177. }
  4178. node.default = true;
  4179. return this.finishNode(node, "DeclareExportDeclaration");
  4180. } else {
  4181. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4182. const label = this.state.value;
  4183. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  4184. unsupportedExportKind: label,
  4185. suggestion: exportSuggestions[label]
  4186. });
  4187. }
  4188. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4189. node.declaration = this.flowParseDeclare(this.startNode());
  4190. node.default = false;
  4191. return this.finishNode(node, "DeclareExportDeclaration");
  4192. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4193. node = this.parseExport(node, null);
  4194. if (node.type === "ExportNamedDeclaration") {
  4195. node.type = "ExportDeclaration";
  4196. node.default = false;
  4197. delete node.exportKind;
  4198. }
  4199. node.type = "Declare" + node.type;
  4200. return node;
  4201. }
  4202. }
  4203. this.unexpected();
  4204. }
  4205. flowParseDeclareModuleExports(node) {
  4206. this.next();
  4207. this.expectContextual(111);
  4208. node.typeAnnotation = this.flowParseTypeAnnotation();
  4209. this.semicolon();
  4210. return this.finishNode(node, "DeclareModuleExports");
  4211. }
  4212. flowParseDeclareTypeAlias(node) {
  4213. this.next();
  4214. const finished = this.flowParseTypeAlias(node);
  4215. finished.type = "DeclareTypeAlias";
  4216. return finished;
  4217. }
  4218. flowParseDeclareOpaqueType(node) {
  4219. this.next();
  4220. const finished = this.flowParseOpaqueType(node, true);
  4221. finished.type = "DeclareOpaqueType";
  4222. return finished;
  4223. }
  4224. flowParseDeclareInterface(node) {
  4225. this.next();
  4226. this.flowParseInterfaceish(node, false);
  4227. return this.finishNode(node, "DeclareInterface");
  4228. }
  4229. flowParseInterfaceish(node, isClass) {
  4230. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4231. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4232. if (this.match(47)) {
  4233. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4234. } else {
  4235. node.typeParameters = null;
  4236. }
  4237. node.extends = [];
  4238. if (this.eat(81)) {
  4239. do {
  4240. node.extends.push(this.flowParseInterfaceExtends());
  4241. } while (!isClass && this.eat(12));
  4242. }
  4243. if (isClass) {
  4244. node.implements = [];
  4245. node.mixins = [];
  4246. if (this.eatContextual(117)) {
  4247. do {
  4248. node.mixins.push(this.flowParseInterfaceExtends());
  4249. } while (this.eat(12));
  4250. }
  4251. if (this.eatContextual(113)) {
  4252. do {
  4253. node.implements.push(this.flowParseInterfaceExtends());
  4254. } while (this.eat(12));
  4255. }
  4256. }
  4257. node.body = this.flowParseObjectType({
  4258. allowStatic: isClass,
  4259. allowExact: false,
  4260. allowSpread: false,
  4261. allowProto: isClass,
  4262. allowInexact: false
  4263. });
  4264. }
  4265. flowParseInterfaceExtends() {
  4266. const node = this.startNode();
  4267. node.id = this.flowParseQualifiedTypeIdentifier();
  4268. if (this.match(47)) {
  4269. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4270. } else {
  4271. node.typeParameters = null;
  4272. }
  4273. return this.finishNode(node, "InterfaceExtends");
  4274. }
  4275. flowParseInterface(node) {
  4276. this.flowParseInterfaceish(node, false);
  4277. return this.finishNode(node, "InterfaceDeclaration");
  4278. }
  4279. checkNotUnderscore(word) {
  4280. if (word === "_") {
  4281. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  4282. }
  4283. }
  4284. checkReservedType(word, startLoc, declaration) {
  4285. if (!reservedTypes.has(word)) return;
  4286. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  4287. reservedType: word
  4288. });
  4289. }
  4290. flowParseRestrictedIdentifier(liberal, declaration) {
  4291. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4292. return this.parseIdentifier(liberal);
  4293. }
  4294. flowParseTypeAlias(node) {
  4295. node.id = this.flowParseRestrictedIdentifier(false, true);
  4296. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4297. if (this.match(47)) {
  4298. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4299. } else {
  4300. node.typeParameters = null;
  4301. }
  4302. node.right = this.flowParseTypeInitialiser(29);
  4303. this.semicolon();
  4304. return this.finishNode(node, "TypeAlias");
  4305. }
  4306. flowParseOpaqueType(node, declare) {
  4307. this.expectContextual(130);
  4308. node.id = this.flowParseRestrictedIdentifier(true, true);
  4309. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4310. if (this.match(47)) {
  4311. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4312. } else {
  4313. node.typeParameters = null;
  4314. }
  4315. node.supertype = null;
  4316. if (this.match(14)) {
  4317. node.supertype = this.flowParseTypeInitialiser(14);
  4318. }
  4319. node.impltype = null;
  4320. if (!declare) {
  4321. node.impltype = this.flowParseTypeInitialiser(29);
  4322. }
  4323. this.semicolon();
  4324. return this.finishNode(node, "OpaqueType");
  4325. }
  4326. flowParseTypeParameter(requireDefault = false) {
  4327. const nodeStartLoc = this.state.startLoc;
  4328. const node = this.startNode();
  4329. const variance = this.flowParseVariance();
  4330. const ident = this.flowParseTypeAnnotatableIdentifier();
  4331. node.name = ident.name;
  4332. node.variance = variance;
  4333. node.bound = ident.typeAnnotation;
  4334. if (this.match(29)) {
  4335. this.eat(29);
  4336. node.default = this.flowParseType();
  4337. } else {
  4338. if (requireDefault) {
  4339. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  4340. }
  4341. }
  4342. return this.finishNode(node, "TypeParameter");
  4343. }
  4344. flowParseTypeParameterDeclaration() {
  4345. const oldInType = this.state.inType;
  4346. const node = this.startNode();
  4347. node.params = [];
  4348. this.state.inType = true;
  4349. if (this.match(47) || this.match(142)) {
  4350. this.next();
  4351. } else {
  4352. this.unexpected();
  4353. }
  4354. let defaultRequired = false;
  4355. do {
  4356. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4357. node.params.push(typeParameter);
  4358. if (typeParameter.default) {
  4359. defaultRequired = true;
  4360. }
  4361. if (!this.match(48)) {
  4362. this.expect(12);
  4363. }
  4364. } while (!this.match(48));
  4365. this.expect(48);
  4366. this.state.inType = oldInType;
  4367. return this.finishNode(node, "TypeParameterDeclaration");
  4368. }
  4369. flowParseTypeParameterInstantiation() {
  4370. const node = this.startNode();
  4371. const oldInType = this.state.inType;
  4372. node.params = [];
  4373. this.state.inType = true;
  4374. this.expect(47);
  4375. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4376. this.state.noAnonFunctionType = false;
  4377. while (!this.match(48)) {
  4378. node.params.push(this.flowParseType());
  4379. if (!this.match(48)) {
  4380. this.expect(12);
  4381. }
  4382. }
  4383. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4384. this.expect(48);
  4385. this.state.inType = oldInType;
  4386. return this.finishNode(node, "TypeParameterInstantiation");
  4387. }
  4388. flowParseTypeParameterInstantiationCallOrNew() {
  4389. const node = this.startNode();
  4390. const oldInType = this.state.inType;
  4391. node.params = [];
  4392. this.state.inType = true;
  4393. this.expect(47);
  4394. while (!this.match(48)) {
  4395. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4396. if (!this.match(48)) {
  4397. this.expect(12);
  4398. }
  4399. }
  4400. this.expect(48);
  4401. this.state.inType = oldInType;
  4402. return this.finishNode(node, "TypeParameterInstantiation");
  4403. }
  4404. flowParseInterfaceType() {
  4405. const node = this.startNode();
  4406. this.expectContextual(129);
  4407. node.extends = [];
  4408. if (this.eat(81)) {
  4409. do {
  4410. node.extends.push(this.flowParseInterfaceExtends());
  4411. } while (this.eat(12));
  4412. }
  4413. node.body = this.flowParseObjectType({
  4414. allowStatic: false,
  4415. allowExact: false,
  4416. allowSpread: false,
  4417. allowProto: false,
  4418. allowInexact: false
  4419. });
  4420. return this.finishNode(node, "InterfaceTypeAnnotation");
  4421. }
  4422. flowParseObjectPropertyKey() {
  4423. return this.match(134) || this.match(133) ? super.parseExprAtom() : this.parseIdentifier(true);
  4424. }
  4425. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4426. node.static = isStatic;
  4427. if (this.lookahead().type === 14) {
  4428. node.id = this.flowParseObjectPropertyKey();
  4429. node.key = this.flowParseTypeInitialiser();
  4430. } else {
  4431. node.id = null;
  4432. node.key = this.flowParseType();
  4433. }
  4434. this.expect(3);
  4435. node.value = this.flowParseTypeInitialiser();
  4436. node.variance = variance;
  4437. return this.finishNode(node, "ObjectTypeIndexer");
  4438. }
  4439. flowParseObjectTypeInternalSlot(node, isStatic) {
  4440. node.static = isStatic;
  4441. node.id = this.flowParseObjectPropertyKey();
  4442. this.expect(3);
  4443. this.expect(3);
  4444. if (this.match(47) || this.match(10)) {
  4445. node.method = true;
  4446. node.optional = false;
  4447. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4448. } else {
  4449. node.method = false;
  4450. if (this.eat(17)) {
  4451. node.optional = true;
  4452. }
  4453. node.value = this.flowParseTypeInitialiser();
  4454. }
  4455. return this.finishNode(node, "ObjectTypeInternalSlot");
  4456. }
  4457. flowParseObjectTypeMethodish(node) {
  4458. node.params = [];
  4459. node.rest = null;
  4460. node.typeParameters = null;
  4461. node.this = null;
  4462. if (this.match(47)) {
  4463. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4464. }
  4465. this.expect(10);
  4466. if (this.match(78)) {
  4467. node.this = this.flowParseFunctionTypeParam(true);
  4468. node.this.name = null;
  4469. if (!this.match(11)) {
  4470. this.expect(12);
  4471. }
  4472. }
  4473. while (!this.match(11) && !this.match(21)) {
  4474. node.params.push(this.flowParseFunctionTypeParam(false));
  4475. if (!this.match(11)) {
  4476. this.expect(12);
  4477. }
  4478. }
  4479. if (this.eat(21)) {
  4480. node.rest = this.flowParseFunctionTypeParam(false);
  4481. }
  4482. this.expect(11);
  4483. node.returnType = this.flowParseTypeInitialiser();
  4484. return this.finishNode(node, "FunctionTypeAnnotation");
  4485. }
  4486. flowParseObjectTypeCallProperty(node, isStatic) {
  4487. const valueNode = this.startNode();
  4488. node.static = isStatic;
  4489. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4490. return this.finishNode(node, "ObjectTypeCallProperty");
  4491. }
  4492. flowParseObjectType({
  4493. allowStatic,
  4494. allowExact,
  4495. allowSpread,
  4496. allowProto,
  4497. allowInexact
  4498. }) {
  4499. const oldInType = this.state.inType;
  4500. this.state.inType = true;
  4501. const nodeStart = this.startNode();
  4502. nodeStart.callProperties = [];
  4503. nodeStart.properties = [];
  4504. nodeStart.indexers = [];
  4505. nodeStart.internalSlots = [];
  4506. let endDelim;
  4507. let exact;
  4508. let inexact = false;
  4509. if (allowExact && this.match(6)) {
  4510. this.expect(6);
  4511. endDelim = 9;
  4512. exact = true;
  4513. } else {
  4514. this.expect(5);
  4515. endDelim = 8;
  4516. exact = false;
  4517. }
  4518. nodeStart.exact = exact;
  4519. while (!this.match(endDelim)) {
  4520. let isStatic = false;
  4521. let protoStartLoc = null;
  4522. let inexactStartLoc = null;
  4523. const node = this.startNode();
  4524. if (allowProto && this.isContextual(118)) {
  4525. const lookahead = this.lookahead();
  4526. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4527. this.next();
  4528. protoStartLoc = this.state.startLoc;
  4529. allowStatic = false;
  4530. }
  4531. }
  4532. if (allowStatic && this.isContextual(106)) {
  4533. const lookahead = this.lookahead();
  4534. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4535. this.next();
  4536. isStatic = true;
  4537. }
  4538. }
  4539. const variance = this.flowParseVariance();
  4540. if (this.eat(0)) {
  4541. if (protoStartLoc != null) {
  4542. this.unexpected(protoStartLoc);
  4543. }
  4544. if (this.eat(0)) {
  4545. if (variance) {
  4546. this.unexpected(variance.loc.start);
  4547. }
  4548. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4549. } else {
  4550. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4551. }
  4552. } else if (this.match(10) || this.match(47)) {
  4553. if (protoStartLoc != null) {
  4554. this.unexpected(protoStartLoc);
  4555. }
  4556. if (variance) {
  4557. this.unexpected(variance.loc.start);
  4558. }
  4559. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4560. } else {
  4561. let kind = "init";
  4562. if (this.isContextual(99) || this.isContextual(104)) {
  4563. const lookahead = this.lookahead();
  4564. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4565. kind = this.state.value;
  4566. this.next();
  4567. }
  4568. }
  4569. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4570. if (propOrInexact === null) {
  4571. inexact = true;
  4572. inexactStartLoc = this.state.lastTokStartLoc;
  4573. } else {
  4574. nodeStart.properties.push(propOrInexact);
  4575. }
  4576. }
  4577. this.flowObjectTypeSemicolon();
  4578. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4579. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  4580. }
  4581. }
  4582. this.expect(endDelim);
  4583. if (allowSpread) {
  4584. nodeStart.inexact = inexact;
  4585. }
  4586. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4587. this.state.inType = oldInType;
  4588. return out;
  4589. }
  4590. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4591. if (this.eat(21)) {
  4592. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4593. if (isInexactToken) {
  4594. if (!allowSpread) {
  4595. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  4596. } else if (!allowInexact) {
  4597. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  4598. }
  4599. if (variance) {
  4600. this.raise(FlowErrors.InexactVariance, variance);
  4601. }
  4602. return null;
  4603. }
  4604. if (!allowSpread) {
  4605. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  4606. }
  4607. if (protoStartLoc != null) {
  4608. this.unexpected(protoStartLoc);
  4609. }
  4610. if (variance) {
  4611. this.raise(FlowErrors.SpreadVariance, variance);
  4612. }
  4613. node.argument = this.flowParseType();
  4614. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4615. } else {
  4616. node.key = this.flowParseObjectPropertyKey();
  4617. node.static = isStatic;
  4618. node.proto = protoStartLoc != null;
  4619. node.kind = kind;
  4620. let optional = false;
  4621. if (this.match(47) || this.match(10)) {
  4622. node.method = true;
  4623. if (protoStartLoc != null) {
  4624. this.unexpected(protoStartLoc);
  4625. }
  4626. if (variance) {
  4627. this.unexpected(variance.loc.start);
  4628. }
  4629. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4630. if (kind === "get" || kind === "set") {
  4631. this.flowCheckGetterSetterParams(node);
  4632. }
  4633. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4634. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  4635. }
  4636. } else {
  4637. if (kind !== "init") this.unexpected();
  4638. node.method = false;
  4639. if (this.eat(17)) {
  4640. optional = true;
  4641. }
  4642. node.value = this.flowParseTypeInitialiser();
  4643. node.variance = variance;
  4644. }
  4645. node.optional = optional;
  4646. return this.finishNode(node, "ObjectTypeProperty");
  4647. }
  4648. }
  4649. flowCheckGetterSetterParams(property) {
  4650. const paramCount = property.kind === "get" ? 0 : 1;
  4651. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4652. if (property.value.this) {
  4653. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  4654. }
  4655. if (length !== paramCount) {
  4656. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  4657. }
  4658. if (property.kind === "set" && property.value.rest) {
  4659. this.raise(Errors.BadSetterRestParameter, property);
  4660. }
  4661. }
  4662. flowObjectTypeSemicolon() {
  4663. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4664. this.unexpected();
  4665. }
  4666. }
  4667. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4668. var _startLoc;
  4669. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4670. let node = id || this.flowParseRestrictedIdentifier(true);
  4671. while (this.eat(16)) {
  4672. const node2 = this.startNodeAt(startLoc);
  4673. node2.qualification = node;
  4674. node2.id = this.flowParseRestrictedIdentifier(true);
  4675. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4676. }
  4677. return node;
  4678. }
  4679. flowParseGenericType(startLoc, id) {
  4680. const node = this.startNodeAt(startLoc);
  4681. node.typeParameters = null;
  4682. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4683. if (this.match(47)) {
  4684. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4685. }
  4686. return this.finishNode(node, "GenericTypeAnnotation");
  4687. }
  4688. flowParseTypeofType() {
  4689. const node = this.startNode();
  4690. this.expect(87);
  4691. node.argument = this.flowParsePrimaryType();
  4692. return this.finishNode(node, "TypeofTypeAnnotation");
  4693. }
  4694. flowParseTupleType() {
  4695. const node = this.startNode();
  4696. node.types = [];
  4697. this.expect(0);
  4698. while (this.state.pos < this.length && !this.match(3)) {
  4699. node.types.push(this.flowParseType());
  4700. if (this.match(3)) break;
  4701. this.expect(12);
  4702. }
  4703. this.expect(3);
  4704. return this.finishNode(node, "TupleTypeAnnotation");
  4705. }
  4706. flowParseFunctionTypeParam(first) {
  4707. let name = null;
  4708. let optional = false;
  4709. let typeAnnotation = null;
  4710. const node = this.startNode();
  4711. const lh = this.lookahead();
  4712. const isThis = this.state.type === 78;
  4713. if (lh.type === 14 || lh.type === 17) {
  4714. if (isThis && !first) {
  4715. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  4716. }
  4717. name = this.parseIdentifier(isThis);
  4718. if (this.eat(17)) {
  4719. optional = true;
  4720. if (isThis) {
  4721. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  4722. }
  4723. }
  4724. typeAnnotation = this.flowParseTypeInitialiser();
  4725. } else {
  4726. typeAnnotation = this.flowParseType();
  4727. }
  4728. node.name = name;
  4729. node.optional = optional;
  4730. node.typeAnnotation = typeAnnotation;
  4731. return this.finishNode(node, "FunctionTypeParam");
  4732. }
  4733. reinterpretTypeAsFunctionTypeParam(type) {
  4734. const node = this.startNodeAt(type.loc.start);
  4735. node.name = null;
  4736. node.optional = false;
  4737. node.typeAnnotation = type;
  4738. return this.finishNode(node, "FunctionTypeParam");
  4739. }
  4740. flowParseFunctionTypeParams(params = []) {
  4741. let rest = null;
  4742. let _this = null;
  4743. if (this.match(78)) {
  4744. _this = this.flowParseFunctionTypeParam(true);
  4745. _this.name = null;
  4746. if (!this.match(11)) {
  4747. this.expect(12);
  4748. }
  4749. }
  4750. while (!this.match(11) && !this.match(21)) {
  4751. params.push(this.flowParseFunctionTypeParam(false));
  4752. if (!this.match(11)) {
  4753. this.expect(12);
  4754. }
  4755. }
  4756. if (this.eat(21)) {
  4757. rest = this.flowParseFunctionTypeParam(false);
  4758. }
  4759. return {
  4760. params,
  4761. rest,
  4762. _this
  4763. };
  4764. }
  4765. flowIdentToTypeAnnotation(startLoc, node, id) {
  4766. switch (id.name) {
  4767. case "any":
  4768. return this.finishNode(node, "AnyTypeAnnotation");
  4769. case "bool":
  4770. case "boolean":
  4771. return this.finishNode(node, "BooleanTypeAnnotation");
  4772. case "mixed":
  4773. return this.finishNode(node, "MixedTypeAnnotation");
  4774. case "empty":
  4775. return this.finishNode(node, "EmptyTypeAnnotation");
  4776. case "number":
  4777. return this.finishNode(node, "NumberTypeAnnotation");
  4778. case "string":
  4779. return this.finishNode(node, "StringTypeAnnotation");
  4780. case "symbol":
  4781. return this.finishNode(node, "SymbolTypeAnnotation");
  4782. default:
  4783. this.checkNotUnderscore(id.name);
  4784. return this.flowParseGenericType(startLoc, id);
  4785. }
  4786. }
  4787. flowParsePrimaryType() {
  4788. const startLoc = this.state.startLoc;
  4789. const node = this.startNode();
  4790. let tmp;
  4791. let type;
  4792. let isGroupedType = false;
  4793. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4794. switch (this.state.type) {
  4795. case 5:
  4796. return this.flowParseObjectType({
  4797. allowStatic: false,
  4798. allowExact: false,
  4799. allowSpread: true,
  4800. allowProto: false,
  4801. allowInexact: true
  4802. });
  4803. case 6:
  4804. return this.flowParseObjectType({
  4805. allowStatic: false,
  4806. allowExact: true,
  4807. allowSpread: true,
  4808. allowProto: false,
  4809. allowInexact: false
  4810. });
  4811. case 0:
  4812. this.state.noAnonFunctionType = false;
  4813. type = this.flowParseTupleType();
  4814. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4815. return type;
  4816. case 47:
  4817. {
  4818. const node = this.startNode();
  4819. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4820. this.expect(10);
  4821. tmp = this.flowParseFunctionTypeParams();
  4822. node.params = tmp.params;
  4823. node.rest = tmp.rest;
  4824. node.this = tmp._this;
  4825. this.expect(11);
  4826. this.expect(19);
  4827. node.returnType = this.flowParseType();
  4828. return this.finishNode(node, "FunctionTypeAnnotation");
  4829. }
  4830. case 10:
  4831. {
  4832. const node = this.startNode();
  4833. this.next();
  4834. if (!this.match(11) && !this.match(21)) {
  4835. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4836. const token = this.lookahead().type;
  4837. isGroupedType = token !== 17 && token !== 14;
  4838. } else {
  4839. isGroupedType = true;
  4840. }
  4841. }
  4842. if (isGroupedType) {
  4843. this.state.noAnonFunctionType = false;
  4844. type = this.flowParseType();
  4845. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4846. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4847. this.expect(11);
  4848. return type;
  4849. } else {
  4850. this.eat(12);
  4851. }
  4852. }
  4853. if (type) {
  4854. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4855. } else {
  4856. tmp = this.flowParseFunctionTypeParams();
  4857. }
  4858. node.params = tmp.params;
  4859. node.rest = tmp.rest;
  4860. node.this = tmp._this;
  4861. this.expect(11);
  4862. this.expect(19);
  4863. node.returnType = this.flowParseType();
  4864. node.typeParameters = null;
  4865. return this.finishNode(node, "FunctionTypeAnnotation");
  4866. }
  4867. case 133:
  4868. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4869. case 85:
  4870. case 86:
  4871. node.value = this.match(85);
  4872. this.next();
  4873. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4874. case 53:
  4875. if (this.state.value === "-") {
  4876. this.next();
  4877. if (this.match(134)) {
  4878. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4879. }
  4880. if (this.match(135)) {
  4881. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4882. }
  4883. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  4884. }
  4885. this.unexpected();
  4886. return;
  4887. case 134:
  4888. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4889. case 135:
  4890. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4891. case 88:
  4892. this.next();
  4893. return this.finishNode(node, "VoidTypeAnnotation");
  4894. case 84:
  4895. this.next();
  4896. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4897. case 78:
  4898. this.next();
  4899. return this.finishNode(node, "ThisTypeAnnotation");
  4900. case 55:
  4901. this.next();
  4902. return this.finishNode(node, "ExistsTypeAnnotation");
  4903. case 87:
  4904. return this.flowParseTypeofType();
  4905. default:
  4906. if (tokenIsKeyword(this.state.type)) {
  4907. const label = tokenLabelName(this.state.type);
  4908. this.next();
  4909. return super.createIdentifier(node, label);
  4910. } else if (tokenIsIdentifier(this.state.type)) {
  4911. if (this.isContextual(129)) {
  4912. return this.flowParseInterfaceType();
  4913. }
  4914. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4915. }
  4916. }
  4917. this.unexpected();
  4918. }
  4919. flowParsePostfixType() {
  4920. const startLoc = this.state.startLoc;
  4921. let type = this.flowParsePrimaryType();
  4922. let seenOptionalIndexedAccess = false;
  4923. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4924. const node = this.startNodeAt(startLoc);
  4925. const optional = this.eat(18);
  4926. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  4927. this.expect(0);
  4928. if (!optional && this.match(3)) {
  4929. node.elementType = type;
  4930. this.next();
  4931. type = this.finishNode(node, "ArrayTypeAnnotation");
  4932. } else {
  4933. node.objectType = type;
  4934. node.indexType = this.flowParseType();
  4935. this.expect(3);
  4936. if (seenOptionalIndexedAccess) {
  4937. node.optional = optional;
  4938. type = this.finishNode(node, "OptionalIndexedAccessType");
  4939. } else {
  4940. type = this.finishNode(node, "IndexedAccessType");
  4941. }
  4942. }
  4943. }
  4944. return type;
  4945. }
  4946. flowParsePrefixType() {
  4947. const node = this.startNode();
  4948. if (this.eat(17)) {
  4949. node.typeAnnotation = this.flowParsePrefixType();
  4950. return this.finishNode(node, "NullableTypeAnnotation");
  4951. } else {
  4952. return this.flowParsePostfixType();
  4953. }
  4954. }
  4955. flowParseAnonFunctionWithoutParens() {
  4956. const param = this.flowParsePrefixType();
  4957. if (!this.state.noAnonFunctionType && this.eat(19)) {
  4958. const node = this.startNodeAt(param.loc.start);
  4959. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  4960. node.rest = null;
  4961. node.this = null;
  4962. node.returnType = this.flowParseType();
  4963. node.typeParameters = null;
  4964. return this.finishNode(node, "FunctionTypeAnnotation");
  4965. }
  4966. return param;
  4967. }
  4968. flowParseIntersectionType() {
  4969. const node = this.startNode();
  4970. this.eat(45);
  4971. const type = this.flowParseAnonFunctionWithoutParens();
  4972. node.types = [type];
  4973. while (this.eat(45)) {
  4974. node.types.push(this.flowParseAnonFunctionWithoutParens());
  4975. }
  4976. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  4977. }
  4978. flowParseUnionType() {
  4979. const node = this.startNode();
  4980. this.eat(43);
  4981. const type = this.flowParseIntersectionType();
  4982. node.types = [type];
  4983. while (this.eat(43)) {
  4984. node.types.push(this.flowParseIntersectionType());
  4985. }
  4986. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  4987. }
  4988. flowParseType() {
  4989. const oldInType = this.state.inType;
  4990. this.state.inType = true;
  4991. const type = this.flowParseUnionType();
  4992. this.state.inType = oldInType;
  4993. return type;
  4994. }
  4995. flowParseTypeOrImplicitInstantiation() {
  4996. if (this.state.type === 132 && this.state.value === "_") {
  4997. const startLoc = this.state.startLoc;
  4998. const node = this.parseIdentifier();
  4999. return this.flowParseGenericType(startLoc, node);
  5000. } else {
  5001. return this.flowParseType();
  5002. }
  5003. }
  5004. flowParseTypeAnnotation() {
  5005. const node = this.startNode();
  5006. node.typeAnnotation = this.flowParseTypeInitialiser();
  5007. return this.finishNode(node, "TypeAnnotation");
  5008. }
  5009. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5010. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5011. if (this.match(14)) {
  5012. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5013. this.resetEndLocation(ident);
  5014. }
  5015. return ident;
  5016. }
  5017. typeCastToParameter(node) {
  5018. node.expression.typeAnnotation = node.typeAnnotation;
  5019. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5020. return node.expression;
  5021. }
  5022. flowParseVariance() {
  5023. let variance = null;
  5024. if (this.match(53)) {
  5025. variance = this.startNode();
  5026. if (this.state.value === "+") {
  5027. variance.kind = "plus";
  5028. } else {
  5029. variance.kind = "minus";
  5030. }
  5031. this.next();
  5032. return this.finishNode(variance, "Variance");
  5033. }
  5034. return variance;
  5035. }
  5036. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5037. if (allowExpressionBody) {
  5038. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5039. return;
  5040. }
  5041. super.parseFunctionBody(node, false, isMethod);
  5042. }
  5043. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5044. if (this.match(14)) {
  5045. const typeNode = this.startNode();
  5046. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5047. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5048. }
  5049. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5050. }
  5051. parseStatementLike(flags) {
  5052. if (this.state.strict && this.isContextual(129)) {
  5053. const lookahead = this.lookahead();
  5054. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5055. const node = this.startNode();
  5056. this.next();
  5057. return this.flowParseInterface(node);
  5058. }
  5059. } else if (this.shouldParseEnums() && this.isContextual(126)) {
  5060. const node = this.startNode();
  5061. this.next();
  5062. return this.flowParseEnumDeclaration(node);
  5063. }
  5064. const stmt = super.parseStatementLike(flags);
  5065. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5066. this.flowPragma = null;
  5067. }
  5068. return stmt;
  5069. }
  5070. parseExpressionStatement(node, expr, decorators) {
  5071. if (expr.type === "Identifier") {
  5072. if (expr.name === "declare") {
  5073. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5074. return this.flowParseDeclare(node);
  5075. }
  5076. } else if (tokenIsIdentifier(this.state.type)) {
  5077. if (expr.name === "interface") {
  5078. return this.flowParseInterface(node);
  5079. } else if (expr.name === "type") {
  5080. return this.flowParseTypeAlias(node);
  5081. } else if (expr.name === "opaque") {
  5082. return this.flowParseOpaqueType(node, false);
  5083. }
  5084. }
  5085. }
  5086. return super.parseExpressionStatement(node, expr, decorators);
  5087. }
  5088. shouldParseExportDeclaration() {
  5089. const {
  5090. type
  5091. } = this.state;
  5092. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 126) {
  5093. return !this.state.containsEsc;
  5094. }
  5095. return super.shouldParseExportDeclaration();
  5096. }
  5097. isExportDefaultSpecifier() {
  5098. const {
  5099. type
  5100. } = this.state;
  5101. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 126) {
  5102. return this.state.containsEsc;
  5103. }
  5104. return super.isExportDefaultSpecifier();
  5105. }
  5106. parseExportDefaultExpression() {
  5107. if (this.shouldParseEnums() && this.isContextual(126)) {
  5108. const node = this.startNode();
  5109. this.next();
  5110. return this.flowParseEnumDeclaration(node);
  5111. }
  5112. return super.parseExportDefaultExpression();
  5113. }
  5114. parseConditional(expr, startLoc, refExpressionErrors) {
  5115. if (!this.match(17)) return expr;
  5116. if (this.state.maybeInArrowParameters) {
  5117. const nextCh = this.lookaheadCharCode();
  5118. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5119. this.setOptionalParametersError(refExpressionErrors);
  5120. return expr;
  5121. }
  5122. }
  5123. this.expect(17);
  5124. const state = this.state.clone();
  5125. const originalNoArrowAt = this.state.noArrowAt;
  5126. const node = this.startNodeAt(startLoc);
  5127. let {
  5128. consequent,
  5129. failed
  5130. } = this.tryParseConditionalConsequent();
  5131. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5132. if (failed || invalid.length > 0) {
  5133. const noArrowAt = [...originalNoArrowAt];
  5134. if (invalid.length > 0) {
  5135. this.state = state;
  5136. this.state.noArrowAt = noArrowAt;
  5137. for (let i = 0; i < invalid.length; i++) {
  5138. noArrowAt.push(invalid[i].start);
  5139. }
  5140. ({
  5141. consequent,
  5142. failed
  5143. } = this.tryParseConditionalConsequent());
  5144. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5145. }
  5146. if (failed && valid.length > 1) {
  5147. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  5148. }
  5149. if (failed && valid.length === 1) {
  5150. this.state = state;
  5151. noArrowAt.push(valid[0].start);
  5152. this.state.noArrowAt = noArrowAt;
  5153. ({
  5154. consequent,
  5155. failed
  5156. } = this.tryParseConditionalConsequent());
  5157. }
  5158. }
  5159. this.getArrowLikeExpressions(consequent, true);
  5160. this.state.noArrowAt = originalNoArrowAt;
  5161. this.expect(14);
  5162. node.test = expr;
  5163. node.consequent = consequent;
  5164. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5165. return this.finishNode(node, "ConditionalExpression");
  5166. }
  5167. tryParseConditionalConsequent() {
  5168. this.state.noArrowParamsConversionAt.push(this.state.start);
  5169. const consequent = this.parseMaybeAssignAllowIn();
  5170. const failed = !this.match(14);
  5171. this.state.noArrowParamsConversionAt.pop();
  5172. return {
  5173. consequent,
  5174. failed
  5175. };
  5176. }
  5177. getArrowLikeExpressions(node, disallowInvalid) {
  5178. const stack = [node];
  5179. const arrows = [];
  5180. while (stack.length !== 0) {
  5181. const node = stack.pop();
  5182. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  5183. if (node.typeParameters || !node.returnType) {
  5184. this.finishArrowValidation(node);
  5185. } else {
  5186. arrows.push(node);
  5187. }
  5188. stack.push(node.body);
  5189. } else if (node.type === "ConditionalExpression") {
  5190. stack.push(node.consequent);
  5191. stack.push(node.alternate);
  5192. }
  5193. }
  5194. if (disallowInvalid) {
  5195. arrows.forEach(node => this.finishArrowValidation(node));
  5196. return [arrows, []];
  5197. }
  5198. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5199. }
  5200. finishArrowValidation(node) {
  5201. var _node$extra;
  5202. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5203. this.scope.enter(2 | 4);
  5204. super.checkParams(node, false, true);
  5205. this.scope.exit();
  5206. }
  5207. forwardNoArrowParamsConversionAt(node, parse) {
  5208. let result;
  5209. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5210. this.state.noArrowParamsConversionAt.push(this.state.start);
  5211. result = parse();
  5212. this.state.noArrowParamsConversionAt.pop();
  5213. } else {
  5214. result = parse();
  5215. }
  5216. return result;
  5217. }
  5218. parseParenItem(node, startLoc) {
  5219. const newNode = super.parseParenItem(node, startLoc);
  5220. if (this.eat(17)) {
  5221. newNode.optional = true;
  5222. this.resetEndLocation(node);
  5223. }
  5224. if (this.match(14)) {
  5225. const typeCastNode = this.startNodeAt(startLoc);
  5226. typeCastNode.expression = newNode;
  5227. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5228. return this.finishNode(typeCastNode, "TypeCastExpression");
  5229. }
  5230. return newNode;
  5231. }
  5232. assertModuleNodeAllowed(node) {
  5233. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5234. return;
  5235. }
  5236. super.assertModuleNodeAllowed(node);
  5237. }
  5238. parseExportDeclaration(node) {
  5239. if (this.isContextual(130)) {
  5240. node.exportKind = "type";
  5241. const declarationNode = this.startNode();
  5242. this.next();
  5243. if (this.match(5)) {
  5244. node.specifiers = this.parseExportSpecifiers(true);
  5245. super.parseExportFrom(node);
  5246. return null;
  5247. } else {
  5248. return this.flowParseTypeAlias(declarationNode);
  5249. }
  5250. } else if (this.isContextual(131)) {
  5251. node.exportKind = "type";
  5252. const declarationNode = this.startNode();
  5253. this.next();
  5254. return this.flowParseOpaqueType(declarationNode, false);
  5255. } else if (this.isContextual(129)) {
  5256. node.exportKind = "type";
  5257. const declarationNode = this.startNode();
  5258. this.next();
  5259. return this.flowParseInterface(declarationNode);
  5260. } else if (this.shouldParseEnums() && this.isContextual(126)) {
  5261. node.exportKind = "value";
  5262. const declarationNode = this.startNode();
  5263. this.next();
  5264. return this.flowParseEnumDeclaration(declarationNode);
  5265. } else {
  5266. return super.parseExportDeclaration(node);
  5267. }
  5268. }
  5269. eatExportStar(node) {
  5270. if (super.eatExportStar(node)) return true;
  5271. if (this.isContextual(130) && this.lookahead().type === 55) {
  5272. node.exportKind = "type";
  5273. this.next();
  5274. this.next();
  5275. return true;
  5276. }
  5277. return false;
  5278. }
  5279. maybeParseExportNamespaceSpecifier(node) {
  5280. const {
  5281. startLoc
  5282. } = this.state;
  5283. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5284. if (hasNamespace && node.exportKind === "type") {
  5285. this.unexpected(startLoc);
  5286. }
  5287. return hasNamespace;
  5288. }
  5289. parseClassId(node, isStatement, optionalId) {
  5290. super.parseClassId(node, isStatement, optionalId);
  5291. if (this.match(47)) {
  5292. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5293. }
  5294. }
  5295. parseClassMember(classBody, member, state) {
  5296. const {
  5297. startLoc
  5298. } = this.state;
  5299. if (this.isContextual(125)) {
  5300. if (super.parseClassMemberFromModifier(classBody, member)) {
  5301. return;
  5302. }
  5303. member.declare = true;
  5304. }
  5305. super.parseClassMember(classBody, member, state);
  5306. if (member.declare) {
  5307. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5308. this.raise(FlowErrors.DeclareClassElement, startLoc);
  5309. } else if (member.value) {
  5310. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  5311. }
  5312. }
  5313. }
  5314. isIterator(word) {
  5315. return word === "iterator" || word === "asyncIterator";
  5316. }
  5317. readIterator() {
  5318. const word = super.readWord1();
  5319. const fullWord = "@@" + word;
  5320. if (!this.isIterator(word) || !this.state.inType) {
  5321. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  5322. identifierName: fullWord
  5323. });
  5324. }
  5325. this.finishToken(132, fullWord);
  5326. }
  5327. getTokenFromCode(code) {
  5328. const next = this.input.charCodeAt(this.state.pos + 1);
  5329. if (code === 123 && next === 124) {
  5330. this.finishOp(6, 2);
  5331. } else if (this.state.inType && (code === 62 || code === 60)) {
  5332. this.finishOp(code === 62 ? 48 : 47, 1);
  5333. } else if (this.state.inType && code === 63) {
  5334. if (next === 46) {
  5335. this.finishOp(18, 2);
  5336. } else {
  5337. this.finishOp(17, 1);
  5338. }
  5339. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5340. this.state.pos += 2;
  5341. this.readIterator();
  5342. } else {
  5343. super.getTokenFromCode(code);
  5344. }
  5345. }
  5346. isAssignable(node, isBinding) {
  5347. if (node.type === "TypeCastExpression") {
  5348. return this.isAssignable(node.expression, isBinding);
  5349. } else {
  5350. return super.isAssignable(node, isBinding);
  5351. }
  5352. }
  5353. toAssignable(node, isLHS = false) {
  5354. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5355. node.left = this.typeCastToParameter(node.left);
  5356. }
  5357. super.toAssignable(node, isLHS);
  5358. }
  5359. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5360. for (let i = 0; i < exprList.length; i++) {
  5361. const expr = exprList[i];
  5362. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5363. exprList[i] = this.typeCastToParameter(expr);
  5364. }
  5365. }
  5366. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5367. }
  5368. toReferencedList(exprList, isParenthesizedExpr) {
  5369. for (let i = 0; i < exprList.length; i++) {
  5370. var _expr$extra;
  5371. const expr = exprList[i];
  5372. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5373. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  5374. }
  5375. }
  5376. return exprList;
  5377. }
  5378. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5379. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5380. if (canBePattern && !this.state.maybeInArrowParameters) {
  5381. this.toReferencedList(node.elements);
  5382. }
  5383. return node;
  5384. }
  5385. isValidLVal(type, isParenthesized, binding) {
  5386. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5387. }
  5388. parseClassProperty(node) {
  5389. if (this.match(14)) {
  5390. node.typeAnnotation = this.flowParseTypeAnnotation();
  5391. }
  5392. return super.parseClassProperty(node);
  5393. }
  5394. parseClassPrivateProperty(node) {
  5395. if (this.match(14)) {
  5396. node.typeAnnotation = this.flowParseTypeAnnotation();
  5397. }
  5398. return super.parseClassPrivateProperty(node);
  5399. }
  5400. isClassMethod() {
  5401. return this.match(47) || super.isClassMethod();
  5402. }
  5403. isClassProperty() {
  5404. return this.match(14) || super.isClassProperty();
  5405. }
  5406. isNonstaticConstructor(method) {
  5407. return !this.match(14) && super.isNonstaticConstructor(method);
  5408. }
  5409. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5410. if (method.variance) {
  5411. this.unexpected(method.variance.loc.start);
  5412. }
  5413. delete method.variance;
  5414. if (this.match(47)) {
  5415. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5416. }
  5417. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5418. if (method.params && isConstructor) {
  5419. const params = method.params;
  5420. if (params.length > 0 && this.isThisParam(params[0])) {
  5421. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5422. }
  5423. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5424. const params = method.value.params;
  5425. if (params.length > 0 && this.isThisParam(params[0])) {
  5426. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5427. }
  5428. }
  5429. }
  5430. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5431. if (method.variance) {
  5432. this.unexpected(method.variance.loc.start);
  5433. }
  5434. delete method.variance;
  5435. if (this.match(47)) {
  5436. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5437. }
  5438. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5439. }
  5440. parseClassSuper(node) {
  5441. super.parseClassSuper(node);
  5442. if (node.superClass && this.match(47)) {
  5443. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  5444. }
  5445. if (this.isContextual(113)) {
  5446. this.next();
  5447. const implemented = node.implements = [];
  5448. do {
  5449. const node = this.startNode();
  5450. node.id = this.flowParseRestrictedIdentifier(true);
  5451. if (this.match(47)) {
  5452. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5453. } else {
  5454. node.typeParameters = null;
  5455. }
  5456. implemented.push(this.finishNode(node, "ClassImplements"));
  5457. } while (this.eat(12));
  5458. }
  5459. }
  5460. checkGetterSetterParams(method) {
  5461. super.checkGetterSetterParams(method);
  5462. const params = this.getObjectOrClassMethodParams(method);
  5463. if (params.length > 0) {
  5464. const param = params[0];
  5465. if (this.isThisParam(param) && method.kind === "get") {
  5466. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  5467. } else if (this.isThisParam(param)) {
  5468. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  5469. }
  5470. }
  5471. }
  5472. parsePropertyNamePrefixOperator(node) {
  5473. node.variance = this.flowParseVariance();
  5474. }
  5475. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5476. if (prop.variance) {
  5477. this.unexpected(prop.variance.loc.start);
  5478. }
  5479. delete prop.variance;
  5480. let typeParameters;
  5481. if (this.match(47) && !isAccessor) {
  5482. typeParameters = this.flowParseTypeParameterDeclaration();
  5483. if (!this.match(10)) this.unexpected();
  5484. }
  5485. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5486. if (typeParameters) {
  5487. (result.value || result).typeParameters = typeParameters;
  5488. }
  5489. return result;
  5490. }
  5491. parseAssignableListItemTypes(param) {
  5492. if (this.eat(17)) {
  5493. if (param.type !== "Identifier") {
  5494. this.raise(FlowErrors.PatternIsOptional, param);
  5495. }
  5496. if (this.isThisParam(param)) {
  5497. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  5498. }
  5499. param.optional = true;
  5500. }
  5501. if (this.match(14)) {
  5502. param.typeAnnotation = this.flowParseTypeAnnotation();
  5503. } else if (this.isThisParam(param)) {
  5504. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  5505. }
  5506. if (this.match(29) && this.isThisParam(param)) {
  5507. this.raise(FlowErrors.ThisParamNoDefault, param);
  5508. }
  5509. this.resetEndLocation(param);
  5510. return param;
  5511. }
  5512. parseMaybeDefault(startLoc, left) {
  5513. const node = super.parseMaybeDefault(startLoc, left);
  5514. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5515. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  5516. }
  5517. return node;
  5518. }
  5519. checkImportReflection(node) {
  5520. super.checkImportReflection(node);
  5521. if (node.module && node.importKind !== "value") {
  5522. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  5523. }
  5524. }
  5525. parseImportSpecifierLocal(node, specifier, type) {
  5526. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5527. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5528. }
  5529. isPotentialImportPhase(isExport) {
  5530. if (super.isPotentialImportPhase(isExport)) return true;
  5531. if (this.isContextual(130)) {
  5532. if (!isExport) return true;
  5533. const ch = this.lookaheadCharCode();
  5534. return ch === 123 || ch === 42;
  5535. }
  5536. return !isExport && this.isContextual(87);
  5537. }
  5538. applyImportPhase(node, isExport, phase, loc) {
  5539. super.applyImportPhase(node, isExport, phase, loc);
  5540. if (isExport) {
  5541. if (!phase && this.match(65)) {
  5542. return;
  5543. }
  5544. node.exportKind = phase === "type" ? phase : "value";
  5545. } else {
  5546. if (phase === "type" && this.match(55)) this.unexpected();
  5547. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5548. }
  5549. }
  5550. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5551. const firstIdent = specifier.imported;
  5552. let specifierTypeKind = null;
  5553. if (firstIdent.type === "Identifier") {
  5554. if (firstIdent.name === "type") {
  5555. specifierTypeKind = "type";
  5556. } else if (firstIdent.name === "typeof") {
  5557. specifierTypeKind = "typeof";
  5558. }
  5559. }
  5560. let isBinding = false;
  5561. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5562. const as_ident = this.parseIdentifier(true);
  5563. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5564. specifier.imported = as_ident;
  5565. specifier.importKind = specifierTypeKind;
  5566. specifier.local = cloneIdentifier(as_ident);
  5567. } else {
  5568. specifier.imported = firstIdent;
  5569. specifier.importKind = null;
  5570. specifier.local = this.parseIdentifier();
  5571. }
  5572. } else {
  5573. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5574. specifier.imported = this.parseIdentifier(true);
  5575. specifier.importKind = specifierTypeKind;
  5576. } else {
  5577. if (importedIsString) {
  5578. throw this.raise(Errors.ImportBindingIsString, specifier, {
  5579. importName: firstIdent.value
  5580. });
  5581. }
  5582. specifier.imported = firstIdent;
  5583. specifier.importKind = null;
  5584. }
  5585. if (this.eatContextual(93)) {
  5586. specifier.local = this.parseIdentifier();
  5587. } else {
  5588. isBinding = true;
  5589. specifier.local = cloneIdentifier(specifier.imported);
  5590. }
  5591. }
  5592. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5593. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5594. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  5595. }
  5596. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5597. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5598. }
  5599. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5600. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5601. }
  5602. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5603. }
  5604. parseBindingAtom() {
  5605. switch (this.state.type) {
  5606. case 78:
  5607. return this.parseIdentifier(true);
  5608. default:
  5609. return super.parseBindingAtom();
  5610. }
  5611. }
  5612. parseFunctionParams(node, isConstructor) {
  5613. const kind = node.kind;
  5614. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5615. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5616. }
  5617. super.parseFunctionParams(node, isConstructor);
  5618. }
  5619. parseVarId(decl, kind) {
  5620. super.parseVarId(decl, kind);
  5621. if (this.match(14)) {
  5622. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5623. this.resetEndLocation(decl.id);
  5624. }
  5625. }
  5626. parseAsyncArrowFromCallExpression(node, call) {
  5627. if (this.match(14)) {
  5628. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5629. this.state.noAnonFunctionType = true;
  5630. node.returnType = this.flowParseTypeAnnotation();
  5631. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5632. }
  5633. return super.parseAsyncArrowFromCallExpression(node, call);
  5634. }
  5635. shouldParseAsyncArrow() {
  5636. return this.match(14) || super.shouldParseAsyncArrow();
  5637. }
  5638. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5639. var _jsx;
  5640. let state = null;
  5641. let jsx;
  5642. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  5643. state = this.state.clone();
  5644. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5645. if (!jsx.error) return jsx.node;
  5646. const {
  5647. context
  5648. } = this.state;
  5649. const currentContext = context[context.length - 1];
  5650. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5651. context.pop();
  5652. }
  5653. }
  5654. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5655. var _jsx2, _jsx3;
  5656. state = state || this.state.clone();
  5657. let typeParameters;
  5658. const arrow = this.tryParse(abort => {
  5659. var _arrowExpression$extr;
  5660. typeParameters = this.flowParseTypeParameterDeclaration();
  5661. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5662. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5663. this.resetStartLocationFromNode(result, typeParameters);
  5664. return result;
  5665. });
  5666. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5667. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5668. if (expr.type !== "ArrowFunctionExpression") abort();
  5669. expr.typeParameters = typeParameters;
  5670. this.resetStartLocationFromNode(expr, typeParameters);
  5671. return arrowExpression;
  5672. }, state);
  5673. let arrowExpression = null;
  5674. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5675. if (!arrow.error && !arrow.aborted) {
  5676. if (arrow.node.async) {
  5677. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  5678. }
  5679. return arrow.node;
  5680. }
  5681. arrowExpression = arrow.node;
  5682. }
  5683. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5684. this.state = jsx.failState;
  5685. return jsx.node;
  5686. }
  5687. if (arrowExpression) {
  5688. this.state = arrow.failState;
  5689. return arrowExpression;
  5690. }
  5691. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5692. if (arrow.thrown) throw arrow.error;
  5693. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  5694. }
  5695. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5696. }
  5697. parseArrow(node) {
  5698. if (this.match(14)) {
  5699. const result = this.tryParse(() => {
  5700. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5701. this.state.noAnonFunctionType = true;
  5702. const typeNode = this.startNode();
  5703. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5704. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5705. if (this.canInsertSemicolon()) this.unexpected();
  5706. if (!this.match(19)) this.unexpected();
  5707. return typeNode;
  5708. });
  5709. if (result.thrown) return null;
  5710. if (result.error) this.state = result.failState;
  5711. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5712. }
  5713. return super.parseArrow(node);
  5714. }
  5715. shouldParseArrow(params) {
  5716. return this.match(14) || super.shouldParseArrow(params);
  5717. }
  5718. setArrowFunctionParameters(node, params) {
  5719. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5720. node.params = params;
  5721. } else {
  5722. super.setArrowFunctionParameters(node, params);
  5723. }
  5724. }
  5725. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5726. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5727. return;
  5728. }
  5729. for (let i = 0; i < node.params.length; i++) {
  5730. if (this.isThisParam(node.params[i]) && i > 0) {
  5731. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  5732. }
  5733. }
  5734. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5735. }
  5736. parseParenAndDistinguishExpression(canBeArrow) {
  5737. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  5738. }
  5739. parseSubscripts(base, startLoc, noCalls) {
  5740. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
  5741. this.next();
  5742. const node = this.startNodeAt(startLoc);
  5743. node.callee = base;
  5744. node.arguments = super.parseCallExpressionArguments(11, false);
  5745. base = this.finishNode(node, "CallExpression");
  5746. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5747. const state = this.state.clone();
  5748. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5749. if (!arrow.error && !arrow.aborted) return arrow.node;
  5750. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5751. if (result.node && !result.error) return result.node;
  5752. if (arrow.node) {
  5753. this.state = arrow.failState;
  5754. return arrow.node;
  5755. }
  5756. if (result.node) {
  5757. this.state = result.failState;
  5758. return result.node;
  5759. }
  5760. throw arrow.error || result.error;
  5761. }
  5762. return super.parseSubscripts(base, startLoc, noCalls);
  5763. }
  5764. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5765. if (this.match(18) && this.isLookaheadToken_lt()) {
  5766. subscriptState.optionalChainMember = true;
  5767. if (noCalls) {
  5768. subscriptState.stop = true;
  5769. return base;
  5770. }
  5771. this.next();
  5772. const node = this.startNodeAt(startLoc);
  5773. node.callee = base;
  5774. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5775. this.expect(10);
  5776. node.arguments = this.parseCallExpressionArguments(11, false);
  5777. node.optional = true;
  5778. return this.finishCallExpression(node, true);
  5779. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  5780. const node = this.startNodeAt(startLoc);
  5781. node.callee = base;
  5782. const result = this.tryParse(() => {
  5783. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5784. this.expect(10);
  5785. node.arguments = super.parseCallExpressionArguments(11, false);
  5786. if (subscriptState.optionalChainMember) {
  5787. node.optional = false;
  5788. }
  5789. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5790. });
  5791. if (result.node) {
  5792. if (result.error) this.state = result.failState;
  5793. return result.node;
  5794. }
  5795. }
  5796. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5797. }
  5798. parseNewCallee(node) {
  5799. super.parseNewCallee(node);
  5800. let targs = null;
  5801. if (this.shouldParseTypes() && this.match(47)) {
  5802. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5803. }
  5804. node.typeArguments = targs;
  5805. }
  5806. parseAsyncArrowWithTypeParameters(startLoc) {
  5807. const node = this.startNodeAt(startLoc);
  5808. this.parseFunctionParams(node, false);
  5809. if (!this.parseArrow(node)) return;
  5810. return super.parseArrowExpression(node, undefined, true);
  5811. }
  5812. readToken_mult_modulo(code) {
  5813. const next = this.input.charCodeAt(this.state.pos + 1);
  5814. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5815. this.state.hasFlowComment = false;
  5816. this.state.pos += 2;
  5817. this.nextToken();
  5818. return;
  5819. }
  5820. super.readToken_mult_modulo(code);
  5821. }
  5822. readToken_pipe_amp(code) {
  5823. const next = this.input.charCodeAt(this.state.pos + 1);
  5824. if (code === 124 && next === 125) {
  5825. this.finishOp(9, 2);
  5826. return;
  5827. }
  5828. super.readToken_pipe_amp(code);
  5829. }
  5830. parseTopLevel(file, program) {
  5831. const fileNode = super.parseTopLevel(file, program);
  5832. if (this.state.hasFlowComment) {
  5833. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  5834. }
  5835. return fileNode;
  5836. }
  5837. skipBlockComment() {
  5838. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5839. if (this.state.hasFlowComment) {
  5840. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  5841. }
  5842. this.hasFlowCommentCompletion();
  5843. const commentSkip = this.skipFlowComment();
  5844. if (commentSkip) {
  5845. this.state.pos += commentSkip;
  5846. this.state.hasFlowComment = true;
  5847. }
  5848. return;
  5849. }
  5850. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5851. }
  5852. skipFlowComment() {
  5853. const {
  5854. pos
  5855. } = this.state;
  5856. let shiftToFirstNonWhiteSpace = 2;
  5857. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5858. shiftToFirstNonWhiteSpace++;
  5859. }
  5860. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5861. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5862. if (ch2 === 58 && ch3 === 58) {
  5863. return shiftToFirstNonWhiteSpace + 2;
  5864. }
  5865. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5866. return shiftToFirstNonWhiteSpace + 12;
  5867. }
  5868. if (ch2 === 58 && ch3 !== 58) {
  5869. return shiftToFirstNonWhiteSpace;
  5870. }
  5871. return false;
  5872. }
  5873. hasFlowCommentCompletion() {
  5874. const end = this.input.indexOf("*/", this.state.pos);
  5875. if (end === -1) {
  5876. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5877. }
  5878. }
  5879. flowEnumErrorBooleanMemberNotInitialized(loc, {
  5880. enumName,
  5881. memberName
  5882. }) {
  5883. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  5884. memberName,
  5885. enumName
  5886. });
  5887. }
  5888. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  5889. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  5890. }
  5891. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  5892. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  5893. }
  5894. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  5895. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  5896. }
  5897. flowEnumMemberInit() {
  5898. const startLoc = this.state.startLoc;
  5899. const endOfInit = () => this.match(12) || this.match(8);
  5900. switch (this.state.type) {
  5901. case 134:
  5902. {
  5903. const literal = this.parseNumericLiteral(this.state.value);
  5904. if (endOfInit()) {
  5905. return {
  5906. type: "number",
  5907. loc: literal.loc.start,
  5908. value: literal
  5909. };
  5910. }
  5911. return {
  5912. type: "invalid",
  5913. loc: startLoc
  5914. };
  5915. }
  5916. case 133:
  5917. {
  5918. const literal = this.parseStringLiteral(this.state.value);
  5919. if (endOfInit()) {
  5920. return {
  5921. type: "string",
  5922. loc: literal.loc.start,
  5923. value: literal
  5924. };
  5925. }
  5926. return {
  5927. type: "invalid",
  5928. loc: startLoc
  5929. };
  5930. }
  5931. case 85:
  5932. case 86:
  5933. {
  5934. const literal = this.parseBooleanLiteral(this.match(85));
  5935. if (endOfInit()) {
  5936. return {
  5937. type: "boolean",
  5938. loc: literal.loc.start,
  5939. value: literal
  5940. };
  5941. }
  5942. return {
  5943. type: "invalid",
  5944. loc: startLoc
  5945. };
  5946. }
  5947. default:
  5948. return {
  5949. type: "invalid",
  5950. loc: startLoc
  5951. };
  5952. }
  5953. }
  5954. flowEnumMemberRaw() {
  5955. const loc = this.state.startLoc;
  5956. const id = this.parseIdentifier(true);
  5957. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  5958. type: "none",
  5959. loc
  5960. };
  5961. return {
  5962. id,
  5963. init
  5964. };
  5965. }
  5966. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  5967. const {
  5968. explicitType
  5969. } = context;
  5970. if (explicitType === null) {
  5971. return;
  5972. }
  5973. if (explicitType !== expectedType) {
  5974. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  5975. }
  5976. }
  5977. flowEnumMembers({
  5978. enumName,
  5979. explicitType
  5980. }) {
  5981. const seenNames = new Set();
  5982. const members = {
  5983. booleanMembers: [],
  5984. numberMembers: [],
  5985. stringMembers: [],
  5986. defaultedMembers: []
  5987. };
  5988. let hasUnknownMembers = false;
  5989. while (!this.match(8)) {
  5990. if (this.eat(21)) {
  5991. hasUnknownMembers = true;
  5992. break;
  5993. }
  5994. const memberNode = this.startNode();
  5995. const {
  5996. id,
  5997. init
  5998. } = this.flowEnumMemberRaw();
  5999. const memberName = id.name;
  6000. if (memberName === "") {
  6001. continue;
  6002. }
  6003. if (/^[a-z]/.test(memberName)) {
  6004. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  6005. memberName,
  6006. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6007. enumName
  6008. });
  6009. }
  6010. if (seenNames.has(memberName)) {
  6011. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  6012. memberName,
  6013. enumName
  6014. });
  6015. }
  6016. seenNames.add(memberName);
  6017. const context = {
  6018. enumName,
  6019. explicitType,
  6020. memberName
  6021. };
  6022. memberNode.id = id;
  6023. switch (init.type) {
  6024. case "boolean":
  6025. {
  6026. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6027. memberNode.init = init.value;
  6028. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6029. break;
  6030. }
  6031. case "number":
  6032. {
  6033. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6034. memberNode.init = init.value;
  6035. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6036. break;
  6037. }
  6038. case "string":
  6039. {
  6040. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6041. memberNode.init = init.value;
  6042. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6043. break;
  6044. }
  6045. case "invalid":
  6046. {
  6047. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6048. }
  6049. case "none":
  6050. {
  6051. switch (explicitType) {
  6052. case "boolean":
  6053. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6054. break;
  6055. case "number":
  6056. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6057. break;
  6058. default:
  6059. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6060. }
  6061. }
  6062. }
  6063. if (!this.match(8)) {
  6064. this.expect(12);
  6065. }
  6066. }
  6067. return {
  6068. members,
  6069. hasUnknownMembers
  6070. };
  6071. }
  6072. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6073. enumName
  6074. }) {
  6075. if (initializedMembers.length === 0) {
  6076. return defaultedMembers;
  6077. } else if (defaultedMembers.length === 0) {
  6078. return initializedMembers;
  6079. } else if (defaultedMembers.length > initializedMembers.length) {
  6080. for (const member of initializedMembers) {
  6081. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6082. enumName
  6083. });
  6084. }
  6085. return defaultedMembers;
  6086. } else {
  6087. for (const member of defaultedMembers) {
  6088. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6089. enumName
  6090. });
  6091. }
  6092. return initializedMembers;
  6093. }
  6094. }
  6095. flowEnumParseExplicitType({
  6096. enumName
  6097. }) {
  6098. if (!this.eatContextual(102)) return null;
  6099. if (!tokenIsIdentifier(this.state.type)) {
  6100. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  6101. enumName
  6102. });
  6103. }
  6104. const {
  6105. value
  6106. } = this.state;
  6107. this.next();
  6108. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6109. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  6110. enumName,
  6111. invalidEnumType: value
  6112. });
  6113. }
  6114. return value;
  6115. }
  6116. flowEnumBody(node, id) {
  6117. const enumName = id.name;
  6118. const nameLoc = id.loc.start;
  6119. const explicitType = this.flowEnumParseExplicitType({
  6120. enumName
  6121. });
  6122. this.expect(5);
  6123. const {
  6124. members,
  6125. hasUnknownMembers
  6126. } = this.flowEnumMembers({
  6127. enumName,
  6128. explicitType
  6129. });
  6130. node.hasUnknownMembers = hasUnknownMembers;
  6131. switch (explicitType) {
  6132. case "boolean":
  6133. node.explicitType = true;
  6134. node.members = members.booleanMembers;
  6135. this.expect(8);
  6136. return this.finishNode(node, "EnumBooleanBody");
  6137. case "number":
  6138. node.explicitType = true;
  6139. node.members = members.numberMembers;
  6140. this.expect(8);
  6141. return this.finishNode(node, "EnumNumberBody");
  6142. case "string":
  6143. node.explicitType = true;
  6144. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6145. enumName
  6146. });
  6147. this.expect(8);
  6148. return this.finishNode(node, "EnumStringBody");
  6149. case "symbol":
  6150. node.members = members.defaultedMembers;
  6151. this.expect(8);
  6152. return this.finishNode(node, "EnumSymbolBody");
  6153. default:
  6154. {
  6155. const empty = () => {
  6156. node.members = [];
  6157. this.expect(8);
  6158. return this.finishNode(node, "EnumStringBody");
  6159. };
  6160. node.explicitType = false;
  6161. const boolsLen = members.booleanMembers.length;
  6162. const numsLen = members.numberMembers.length;
  6163. const strsLen = members.stringMembers.length;
  6164. const defaultedLen = members.defaultedMembers.length;
  6165. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6166. return empty();
  6167. } else if (!boolsLen && !numsLen) {
  6168. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6169. enumName
  6170. });
  6171. this.expect(8);
  6172. return this.finishNode(node, "EnumStringBody");
  6173. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6174. for (const member of members.defaultedMembers) {
  6175. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6176. enumName,
  6177. memberName: member.id.name
  6178. });
  6179. }
  6180. node.members = members.booleanMembers;
  6181. this.expect(8);
  6182. return this.finishNode(node, "EnumBooleanBody");
  6183. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6184. for (const member of members.defaultedMembers) {
  6185. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6186. enumName,
  6187. memberName: member.id.name
  6188. });
  6189. }
  6190. node.members = members.numberMembers;
  6191. this.expect(8);
  6192. return this.finishNode(node, "EnumNumberBody");
  6193. } else {
  6194. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  6195. enumName
  6196. });
  6197. return empty();
  6198. }
  6199. }
  6200. }
  6201. }
  6202. flowParseEnumDeclaration(node) {
  6203. const id = this.parseIdentifier();
  6204. node.id = id;
  6205. node.body = this.flowEnumBody(this.startNode(), id);
  6206. return this.finishNode(node, "EnumDeclaration");
  6207. }
  6208. isLookaheadToken_lt() {
  6209. const next = this.nextTokenStart();
  6210. if (this.input.charCodeAt(next) === 60) {
  6211. const afterNext = this.input.charCodeAt(next + 1);
  6212. return afterNext !== 60 && afterNext !== 61;
  6213. }
  6214. return false;
  6215. }
  6216. maybeUnwrapTypeCastExpression(node) {
  6217. return node.type === "TypeCastExpression" ? node.expression : node;
  6218. }
  6219. };
  6220. const entities = {
  6221. __proto__: null,
  6222. quot: "\u0022",
  6223. amp: "&",
  6224. apos: "\u0027",
  6225. lt: "<",
  6226. gt: ">",
  6227. nbsp: "\u00A0",
  6228. iexcl: "\u00A1",
  6229. cent: "\u00A2",
  6230. pound: "\u00A3",
  6231. curren: "\u00A4",
  6232. yen: "\u00A5",
  6233. brvbar: "\u00A6",
  6234. sect: "\u00A7",
  6235. uml: "\u00A8",
  6236. copy: "\u00A9",
  6237. ordf: "\u00AA",
  6238. laquo: "\u00AB",
  6239. not: "\u00AC",
  6240. shy: "\u00AD",
  6241. reg: "\u00AE",
  6242. macr: "\u00AF",
  6243. deg: "\u00B0",
  6244. plusmn: "\u00B1",
  6245. sup2: "\u00B2",
  6246. sup3: "\u00B3",
  6247. acute: "\u00B4",
  6248. micro: "\u00B5",
  6249. para: "\u00B6",
  6250. middot: "\u00B7",
  6251. cedil: "\u00B8",
  6252. sup1: "\u00B9",
  6253. ordm: "\u00BA",
  6254. raquo: "\u00BB",
  6255. frac14: "\u00BC",
  6256. frac12: "\u00BD",
  6257. frac34: "\u00BE",
  6258. iquest: "\u00BF",
  6259. Agrave: "\u00C0",
  6260. Aacute: "\u00C1",
  6261. Acirc: "\u00C2",
  6262. Atilde: "\u00C3",
  6263. Auml: "\u00C4",
  6264. Aring: "\u00C5",
  6265. AElig: "\u00C6",
  6266. Ccedil: "\u00C7",
  6267. Egrave: "\u00C8",
  6268. Eacute: "\u00C9",
  6269. Ecirc: "\u00CA",
  6270. Euml: "\u00CB",
  6271. Igrave: "\u00CC",
  6272. Iacute: "\u00CD",
  6273. Icirc: "\u00CE",
  6274. Iuml: "\u00CF",
  6275. ETH: "\u00D0",
  6276. Ntilde: "\u00D1",
  6277. Ograve: "\u00D2",
  6278. Oacute: "\u00D3",
  6279. Ocirc: "\u00D4",
  6280. Otilde: "\u00D5",
  6281. Ouml: "\u00D6",
  6282. times: "\u00D7",
  6283. Oslash: "\u00D8",
  6284. Ugrave: "\u00D9",
  6285. Uacute: "\u00DA",
  6286. Ucirc: "\u00DB",
  6287. Uuml: "\u00DC",
  6288. Yacute: "\u00DD",
  6289. THORN: "\u00DE",
  6290. szlig: "\u00DF",
  6291. agrave: "\u00E0",
  6292. aacute: "\u00E1",
  6293. acirc: "\u00E2",
  6294. atilde: "\u00E3",
  6295. auml: "\u00E4",
  6296. aring: "\u00E5",
  6297. aelig: "\u00E6",
  6298. ccedil: "\u00E7",
  6299. egrave: "\u00E8",
  6300. eacute: "\u00E9",
  6301. ecirc: "\u00EA",
  6302. euml: "\u00EB",
  6303. igrave: "\u00EC",
  6304. iacute: "\u00ED",
  6305. icirc: "\u00EE",
  6306. iuml: "\u00EF",
  6307. eth: "\u00F0",
  6308. ntilde: "\u00F1",
  6309. ograve: "\u00F2",
  6310. oacute: "\u00F3",
  6311. ocirc: "\u00F4",
  6312. otilde: "\u00F5",
  6313. ouml: "\u00F6",
  6314. divide: "\u00F7",
  6315. oslash: "\u00F8",
  6316. ugrave: "\u00F9",
  6317. uacute: "\u00FA",
  6318. ucirc: "\u00FB",
  6319. uuml: "\u00FC",
  6320. yacute: "\u00FD",
  6321. thorn: "\u00FE",
  6322. yuml: "\u00FF",
  6323. OElig: "\u0152",
  6324. oelig: "\u0153",
  6325. Scaron: "\u0160",
  6326. scaron: "\u0161",
  6327. Yuml: "\u0178",
  6328. fnof: "\u0192",
  6329. circ: "\u02C6",
  6330. tilde: "\u02DC",
  6331. Alpha: "\u0391",
  6332. Beta: "\u0392",
  6333. Gamma: "\u0393",
  6334. Delta: "\u0394",
  6335. Epsilon: "\u0395",
  6336. Zeta: "\u0396",
  6337. Eta: "\u0397",
  6338. Theta: "\u0398",
  6339. Iota: "\u0399",
  6340. Kappa: "\u039A",
  6341. Lambda: "\u039B",
  6342. Mu: "\u039C",
  6343. Nu: "\u039D",
  6344. Xi: "\u039E",
  6345. Omicron: "\u039F",
  6346. Pi: "\u03A0",
  6347. Rho: "\u03A1",
  6348. Sigma: "\u03A3",
  6349. Tau: "\u03A4",
  6350. Upsilon: "\u03A5",
  6351. Phi: "\u03A6",
  6352. Chi: "\u03A7",
  6353. Psi: "\u03A8",
  6354. Omega: "\u03A9",
  6355. alpha: "\u03B1",
  6356. beta: "\u03B2",
  6357. gamma: "\u03B3",
  6358. delta: "\u03B4",
  6359. epsilon: "\u03B5",
  6360. zeta: "\u03B6",
  6361. eta: "\u03B7",
  6362. theta: "\u03B8",
  6363. iota: "\u03B9",
  6364. kappa: "\u03BA",
  6365. lambda: "\u03BB",
  6366. mu: "\u03BC",
  6367. nu: "\u03BD",
  6368. xi: "\u03BE",
  6369. omicron: "\u03BF",
  6370. pi: "\u03C0",
  6371. rho: "\u03C1",
  6372. sigmaf: "\u03C2",
  6373. sigma: "\u03C3",
  6374. tau: "\u03C4",
  6375. upsilon: "\u03C5",
  6376. phi: "\u03C6",
  6377. chi: "\u03C7",
  6378. psi: "\u03C8",
  6379. omega: "\u03C9",
  6380. thetasym: "\u03D1",
  6381. upsih: "\u03D2",
  6382. piv: "\u03D6",
  6383. ensp: "\u2002",
  6384. emsp: "\u2003",
  6385. thinsp: "\u2009",
  6386. zwnj: "\u200C",
  6387. zwj: "\u200D",
  6388. lrm: "\u200E",
  6389. rlm: "\u200F",
  6390. ndash: "\u2013",
  6391. mdash: "\u2014",
  6392. lsquo: "\u2018",
  6393. rsquo: "\u2019",
  6394. sbquo: "\u201A",
  6395. ldquo: "\u201C",
  6396. rdquo: "\u201D",
  6397. bdquo: "\u201E",
  6398. dagger: "\u2020",
  6399. Dagger: "\u2021",
  6400. bull: "\u2022",
  6401. hellip: "\u2026",
  6402. permil: "\u2030",
  6403. prime: "\u2032",
  6404. Prime: "\u2033",
  6405. lsaquo: "\u2039",
  6406. rsaquo: "\u203A",
  6407. oline: "\u203E",
  6408. frasl: "\u2044",
  6409. euro: "\u20AC",
  6410. image: "\u2111",
  6411. weierp: "\u2118",
  6412. real: "\u211C",
  6413. trade: "\u2122",
  6414. alefsym: "\u2135",
  6415. larr: "\u2190",
  6416. uarr: "\u2191",
  6417. rarr: "\u2192",
  6418. darr: "\u2193",
  6419. harr: "\u2194",
  6420. crarr: "\u21B5",
  6421. lArr: "\u21D0",
  6422. uArr: "\u21D1",
  6423. rArr: "\u21D2",
  6424. dArr: "\u21D3",
  6425. hArr: "\u21D4",
  6426. forall: "\u2200",
  6427. part: "\u2202",
  6428. exist: "\u2203",
  6429. empty: "\u2205",
  6430. nabla: "\u2207",
  6431. isin: "\u2208",
  6432. notin: "\u2209",
  6433. ni: "\u220B",
  6434. prod: "\u220F",
  6435. sum: "\u2211",
  6436. minus: "\u2212",
  6437. lowast: "\u2217",
  6438. radic: "\u221A",
  6439. prop: "\u221D",
  6440. infin: "\u221E",
  6441. ang: "\u2220",
  6442. and: "\u2227",
  6443. or: "\u2228",
  6444. cap: "\u2229",
  6445. cup: "\u222A",
  6446. int: "\u222B",
  6447. there4: "\u2234",
  6448. sim: "\u223C",
  6449. cong: "\u2245",
  6450. asymp: "\u2248",
  6451. ne: "\u2260",
  6452. equiv: "\u2261",
  6453. le: "\u2264",
  6454. ge: "\u2265",
  6455. sub: "\u2282",
  6456. sup: "\u2283",
  6457. nsub: "\u2284",
  6458. sube: "\u2286",
  6459. supe: "\u2287",
  6460. oplus: "\u2295",
  6461. otimes: "\u2297",
  6462. perp: "\u22A5",
  6463. sdot: "\u22C5",
  6464. lceil: "\u2308",
  6465. rceil: "\u2309",
  6466. lfloor: "\u230A",
  6467. rfloor: "\u230B",
  6468. lang: "\u2329",
  6469. rang: "\u232A",
  6470. loz: "\u25CA",
  6471. spades: "\u2660",
  6472. clubs: "\u2663",
  6473. hearts: "\u2665",
  6474. diams: "\u2666"
  6475. };
  6476. const JsxErrors = ParseErrorEnum`jsx`({
  6477. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6478. MissingClosingTagElement: ({
  6479. openingTagName
  6480. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6481. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6482. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6483. UnexpectedToken: ({
  6484. unexpected,
  6485. HTMLEntity
  6486. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6487. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6488. UnterminatedJsxContent: "Unterminated JSX contents.",
  6489. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6490. });
  6491. function isFragment(object) {
  6492. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6493. }
  6494. function getQualifiedJSXName(object) {
  6495. if (object.type === "JSXIdentifier") {
  6496. return object.name;
  6497. }
  6498. if (object.type === "JSXNamespacedName") {
  6499. return object.namespace.name + ":" + object.name.name;
  6500. }
  6501. if (object.type === "JSXMemberExpression") {
  6502. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6503. }
  6504. throw new Error("Node had unexpected type: " + object.type);
  6505. }
  6506. var jsx = superClass => class JSXParserMixin extends superClass {
  6507. jsxReadToken() {
  6508. let out = "";
  6509. let chunkStart = this.state.pos;
  6510. for (;;) {
  6511. if (this.state.pos >= this.length) {
  6512. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  6513. }
  6514. const ch = this.input.charCodeAt(this.state.pos);
  6515. switch (ch) {
  6516. case 60:
  6517. case 123:
  6518. if (this.state.pos === this.state.start) {
  6519. if (ch === 60 && this.state.canStartJSXElement) {
  6520. ++this.state.pos;
  6521. this.finishToken(142);
  6522. } else {
  6523. super.getTokenFromCode(ch);
  6524. }
  6525. return;
  6526. }
  6527. out += this.input.slice(chunkStart, this.state.pos);
  6528. this.finishToken(141, out);
  6529. return;
  6530. case 38:
  6531. out += this.input.slice(chunkStart, this.state.pos);
  6532. out += this.jsxReadEntity();
  6533. chunkStart = this.state.pos;
  6534. break;
  6535. case 62:
  6536. case 125:
  6537. default:
  6538. if (isNewLine(ch)) {
  6539. out += this.input.slice(chunkStart, this.state.pos);
  6540. out += this.jsxReadNewLine(true);
  6541. chunkStart = this.state.pos;
  6542. } else {
  6543. ++this.state.pos;
  6544. }
  6545. }
  6546. }
  6547. }
  6548. jsxReadNewLine(normalizeCRLF) {
  6549. const ch = this.input.charCodeAt(this.state.pos);
  6550. let out;
  6551. ++this.state.pos;
  6552. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6553. ++this.state.pos;
  6554. out = normalizeCRLF ? "\n" : "\r\n";
  6555. } else {
  6556. out = String.fromCharCode(ch);
  6557. }
  6558. ++this.state.curLine;
  6559. this.state.lineStart = this.state.pos;
  6560. return out;
  6561. }
  6562. jsxReadString(quote) {
  6563. let out = "";
  6564. let chunkStart = ++this.state.pos;
  6565. for (;;) {
  6566. if (this.state.pos >= this.length) {
  6567. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  6568. }
  6569. const ch = this.input.charCodeAt(this.state.pos);
  6570. if (ch === quote) break;
  6571. if (ch === 38) {
  6572. out += this.input.slice(chunkStart, this.state.pos);
  6573. out += this.jsxReadEntity();
  6574. chunkStart = this.state.pos;
  6575. } else if (isNewLine(ch)) {
  6576. out += this.input.slice(chunkStart, this.state.pos);
  6577. out += this.jsxReadNewLine(false);
  6578. chunkStart = this.state.pos;
  6579. } else {
  6580. ++this.state.pos;
  6581. }
  6582. }
  6583. out += this.input.slice(chunkStart, this.state.pos++);
  6584. this.finishToken(133, out);
  6585. }
  6586. jsxReadEntity() {
  6587. const startPos = ++this.state.pos;
  6588. if (this.codePointAtPos(this.state.pos) === 35) {
  6589. ++this.state.pos;
  6590. let radix = 10;
  6591. if (this.codePointAtPos(this.state.pos) === 120) {
  6592. radix = 16;
  6593. ++this.state.pos;
  6594. }
  6595. const codePoint = this.readInt(radix, undefined, false, "bail");
  6596. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6597. ++this.state.pos;
  6598. return String.fromCodePoint(codePoint);
  6599. }
  6600. } else {
  6601. let count = 0;
  6602. let semi = false;
  6603. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  6604. ++this.state.pos;
  6605. }
  6606. if (semi) {
  6607. const desc = this.input.slice(startPos, this.state.pos);
  6608. const entity = entities[desc];
  6609. ++this.state.pos;
  6610. if (entity) {
  6611. return entity;
  6612. }
  6613. }
  6614. }
  6615. this.state.pos = startPos;
  6616. return "&";
  6617. }
  6618. jsxReadWord() {
  6619. let ch;
  6620. const start = this.state.pos;
  6621. do {
  6622. ch = this.input.charCodeAt(++this.state.pos);
  6623. } while (isIdentifierChar(ch) || ch === 45);
  6624. this.finishToken(140, this.input.slice(start, this.state.pos));
  6625. }
  6626. jsxParseIdentifier() {
  6627. const node = this.startNode();
  6628. if (this.match(140)) {
  6629. node.name = this.state.value;
  6630. } else if (tokenIsKeyword(this.state.type)) {
  6631. node.name = tokenLabelName(this.state.type);
  6632. } else {
  6633. this.unexpected();
  6634. }
  6635. this.next();
  6636. return this.finishNode(node, "JSXIdentifier");
  6637. }
  6638. jsxParseNamespacedName() {
  6639. const startLoc = this.state.startLoc;
  6640. const name = this.jsxParseIdentifier();
  6641. if (!this.eat(14)) return name;
  6642. const node = this.startNodeAt(startLoc);
  6643. node.namespace = name;
  6644. node.name = this.jsxParseIdentifier();
  6645. return this.finishNode(node, "JSXNamespacedName");
  6646. }
  6647. jsxParseElementName() {
  6648. const startLoc = this.state.startLoc;
  6649. let node = this.jsxParseNamespacedName();
  6650. if (node.type === "JSXNamespacedName") {
  6651. return node;
  6652. }
  6653. while (this.eat(16)) {
  6654. const newNode = this.startNodeAt(startLoc);
  6655. newNode.object = node;
  6656. newNode.property = this.jsxParseIdentifier();
  6657. node = this.finishNode(newNode, "JSXMemberExpression");
  6658. }
  6659. return node;
  6660. }
  6661. jsxParseAttributeValue() {
  6662. let node;
  6663. switch (this.state.type) {
  6664. case 5:
  6665. node = this.startNode();
  6666. this.setContext(types.brace);
  6667. this.next();
  6668. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6669. if (node.expression.type === "JSXEmptyExpression") {
  6670. this.raise(JsxErrors.AttributeIsEmpty, node);
  6671. }
  6672. return node;
  6673. case 142:
  6674. case 133:
  6675. return this.parseExprAtom();
  6676. default:
  6677. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  6678. }
  6679. }
  6680. jsxParseEmptyExpression() {
  6681. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6682. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6683. }
  6684. jsxParseSpreadChild(node) {
  6685. this.next();
  6686. node.expression = this.parseExpression();
  6687. this.setContext(types.j_expr);
  6688. this.state.canStartJSXElement = true;
  6689. this.expect(8);
  6690. return this.finishNode(node, "JSXSpreadChild");
  6691. }
  6692. jsxParseExpressionContainer(node, previousContext) {
  6693. if (this.match(8)) {
  6694. node.expression = this.jsxParseEmptyExpression();
  6695. } else {
  6696. const expression = this.parseExpression();
  6697. node.expression = expression;
  6698. }
  6699. this.setContext(previousContext);
  6700. this.state.canStartJSXElement = true;
  6701. this.expect(8);
  6702. return this.finishNode(node, "JSXExpressionContainer");
  6703. }
  6704. jsxParseAttribute() {
  6705. const node = this.startNode();
  6706. if (this.match(5)) {
  6707. this.setContext(types.brace);
  6708. this.next();
  6709. this.expect(21);
  6710. node.argument = this.parseMaybeAssignAllowIn();
  6711. this.setContext(types.j_oTag);
  6712. this.state.canStartJSXElement = true;
  6713. this.expect(8);
  6714. return this.finishNode(node, "JSXSpreadAttribute");
  6715. }
  6716. node.name = this.jsxParseNamespacedName();
  6717. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6718. return this.finishNode(node, "JSXAttribute");
  6719. }
  6720. jsxParseOpeningElementAt(startLoc) {
  6721. const node = this.startNodeAt(startLoc);
  6722. if (this.eat(143)) {
  6723. return this.finishNode(node, "JSXOpeningFragment");
  6724. }
  6725. node.name = this.jsxParseElementName();
  6726. return this.jsxParseOpeningElementAfterName(node);
  6727. }
  6728. jsxParseOpeningElementAfterName(node) {
  6729. const attributes = [];
  6730. while (!this.match(56) && !this.match(143)) {
  6731. attributes.push(this.jsxParseAttribute());
  6732. }
  6733. node.attributes = attributes;
  6734. node.selfClosing = this.eat(56);
  6735. this.expect(143);
  6736. return this.finishNode(node, "JSXOpeningElement");
  6737. }
  6738. jsxParseClosingElementAt(startLoc) {
  6739. const node = this.startNodeAt(startLoc);
  6740. if (this.eat(143)) {
  6741. return this.finishNode(node, "JSXClosingFragment");
  6742. }
  6743. node.name = this.jsxParseElementName();
  6744. this.expect(143);
  6745. return this.finishNode(node, "JSXClosingElement");
  6746. }
  6747. jsxParseElementAt(startLoc) {
  6748. const node = this.startNodeAt(startLoc);
  6749. const children = [];
  6750. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6751. let closingElement = null;
  6752. if (!openingElement.selfClosing) {
  6753. contents: for (;;) {
  6754. switch (this.state.type) {
  6755. case 142:
  6756. startLoc = this.state.startLoc;
  6757. this.next();
  6758. if (this.eat(56)) {
  6759. closingElement = this.jsxParseClosingElementAt(startLoc);
  6760. break contents;
  6761. }
  6762. children.push(this.jsxParseElementAt(startLoc));
  6763. break;
  6764. case 141:
  6765. children.push(this.parseLiteral(this.state.value, "JSXText"));
  6766. break;
  6767. case 5:
  6768. {
  6769. const node = this.startNode();
  6770. this.setContext(types.brace);
  6771. this.next();
  6772. if (this.match(21)) {
  6773. children.push(this.jsxParseSpreadChild(node));
  6774. } else {
  6775. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6776. }
  6777. break;
  6778. }
  6779. default:
  6780. this.unexpected();
  6781. }
  6782. }
  6783. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6784. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  6785. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6786. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  6787. openingTagName: getQualifiedJSXName(openingElement.name)
  6788. });
  6789. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6790. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6791. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  6792. openingTagName: getQualifiedJSXName(openingElement.name)
  6793. });
  6794. }
  6795. }
  6796. }
  6797. if (isFragment(openingElement)) {
  6798. node.openingFragment = openingElement;
  6799. node.closingFragment = closingElement;
  6800. } else {
  6801. node.openingElement = openingElement;
  6802. node.closingElement = closingElement;
  6803. }
  6804. node.children = children;
  6805. if (this.match(47)) {
  6806. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  6807. }
  6808. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6809. }
  6810. jsxParseElement() {
  6811. const startLoc = this.state.startLoc;
  6812. this.next();
  6813. return this.jsxParseElementAt(startLoc);
  6814. }
  6815. setContext(newContext) {
  6816. const {
  6817. context
  6818. } = this.state;
  6819. context[context.length - 1] = newContext;
  6820. }
  6821. parseExprAtom(refExpressionErrors) {
  6822. if (this.match(142)) {
  6823. return this.jsxParseElement();
  6824. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  6825. this.replaceToken(142);
  6826. return this.jsxParseElement();
  6827. } else {
  6828. return super.parseExprAtom(refExpressionErrors);
  6829. }
  6830. }
  6831. skipSpace() {
  6832. const curContext = this.curContext();
  6833. if (!curContext.preserveSpace) super.skipSpace();
  6834. }
  6835. getTokenFromCode(code) {
  6836. const context = this.curContext();
  6837. if (context === types.j_expr) {
  6838. this.jsxReadToken();
  6839. return;
  6840. }
  6841. if (context === types.j_oTag || context === types.j_cTag) {
  6842. if (isIdentifierStart(code)) {
  6843. this.jsxReadWord();
  6844. return;
  6845. }
  6846. if (code === 62) {
  6847. ++this.state.pos;
  6848. this.finishToken(143);
  6849. return;
  6850. }
  6851. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6852. this.jsxReadString(code);
  6853. return;
  6854. }
  6855. }
  6856. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  6857. ++this.state.pos;
  6858. this.finishToken(142);
  6859. return;
  6860. }
  6861. super.getTokenFromCode(code);
  6862. }
  6863. updateContext(prevType) {
  6864. const {
  6865. context,
  6866. type
  6867. } = this.state;
  6868. if (type === 56 && prevType === 142) {
  6869. context.splice(-2, 2, types.j_cTag);
  6870. this.state.canStartJSXElement = false;
  6871. } else if (type === 142) {
  6872. context.push(types.j_oTag);
  6873. } else if (type === 143) {
  6874. const out = context[context.length - 1];
  6875. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  6876. context.pop();
  6877. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  6878. } else {
  6879. this.setContext(types.j_expr);
  6880. this.state.canStartJSXElement = true;
  6881. }
  6882. } else {
  6883. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  6884. }
  6885. }
  6886. };
  6887. class TypeScriptScope extends Scope {
  6888. constructor(...args) {
  6889. super(...args);
  6890. this.tsNames = new Map();
  6891. }
  6892. }
  6893. class TypeScriptScopeHandler extends ScopeHandler {
  6894. constructor(...args) {
  6895. super(...args);
  6896. this.importsStack = [];
  6897. }
  6898. createScope(flags) {
  6899. this.importsStack.push(new Set());
  6900. return new TypeScriptScope(flags);
  6901. }
  6902. enter(flags) {
  6903. if (flags === 256) {
  6904. this.importsStack.push(new Set());
  6905. }
  6906. super.enter(flags);
  6907. }
  6908. exit() {
  6909. const flags = super.exit();
  6910. if (flags === 256) {
  6911. this.importsStack.pop();
  6912. }
  6913. return flags;
  6914. }
  6915. hasImport(name, allowShadow) {
  6916. const len = this.importsStack.length;
  6917. if (this.importsStack[len - 1].has(name)) {
  6918. return true;
  6919. }
  6920. if (!allowShadow && len > 1) {
  6921. for (let i = 0; i < len - 1; i++) {
  6922. if (this.importsStack[i].has(name)) return true;
  6923. }
  6924. }
  6925. return false;
  6926. }
  6927. declareName(name, bindingType, loc) {
  6928. if (bindingType & 4096) {
  6929. if (this.hasImport(name, true)) {
  6930. this.parser.raise(Errors.VarRedeclaration, loc, {
  6931. identifierName: name
  6932. });
  6933. }
  6934. this.importsStack[this.importsStack.length - 1].add(name);
  6935. return;
  6936. }
  6937. const scope = this.currentScope();
  6938. let type = scope.tsNames.get(name) || 0;
  6939. if (bindingType & 1024) {
  6940. this.maybeExportDefined(scope, name);
  6941. scope.tsNames.set(name, type | 16);
  6942. return;
  6943. }
  6944. super.declareName(name, bindingType, loc);
  6945. if (bindingType & 2) {
  6946. if (!(bindingType & 1)) {
  6947. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  6948. this.maybeExportDefined(scope, name);
  6949. }
  6950. type = type | 1;
  6951. }
  6952. if (bindingType & 256) {
  6953. type = type | 2;
  6954. }
  6955. if (bindingType & 512) {
  6956. type = type | 4;
  6957. }
  6958. if (bindingType & 128) {
  6959. type = type | 8;
  6960. }
  6961. if (type) scope.tsNames.set(name, type);
  6962. }
  6963. isRedeclaredInScope(scope, name, bindingType) {
  6964. const type = scope.tsNames.get(name);
  6965. if ((type & 2) > 0) {
  6966. if (bindingType & 256) {
  6967. const isConst = !!(bindingType & 512);
  6968. const wasConst = (type & 4) > 0;
  6969. return isConst !== wasConst;
  6970. }
  6971. return true;
  6972. }
  6973. if (bindingType & 128 && (type & 8) > 0) {
  6974. if (scope.names.get(name) & 2) {
  6975. return !!(bindingType & 1);
  6976. } else {
  6977. return false;
  6978. }
  6979. }
  6980. if (bindingType & 2 && (type & 1) > 0) {
  6981. return true;
  6982. }
  6983. return super.isRedeclaredInScope(scope, name, bindingType);
  6984. }
  6985. checkLocalExport(id) {
  6986. const {
  6987. name
  6988. } = id;
  6989. if (this.hasImport(name)) return;
  6990. const len = this.scopeStack.length;
  6991. for (let i = len - 1; i >= 0; i--) {
  6992. const scope = this.scopeStack[i];
  6993. const type = scope.tsNames.get(name);
  6994. if ((type & 1) > 0 || (type & 16) > 0) {
  6995. return;
  6996. }
  6997. }
  6998. super.checkLocalExport(id);
  6999. }
  7000. }
  7001. const getOwn$1 = (object, key) => hasOwnProperty.call(object, key) && object[key];
  7002. const unwrapParenthesizedExpression = node => {
  7003. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7004. };
  7005. class LValParser extends NodeUtils {
  7006. toAssignable(node, isLHS = false) {
  7007. var _node$extra, _node$extra3;
  7008. let parenthesized = undefined;
  7009. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7010. parenthesized = unwrapParenthesizedExpression(node);
  7011. if (isLHS) {
  7012. if (parenthesized.type === "Identifier") {
  7013. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7014. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7015. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7016. }
  7017. } else {
  7018. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7019. }
  7020. }
  7021. switch (node.type) {
  7022. case "Identifier":
  7023. case "ObjectPattern":
  7024. case "ArrayPattern":
  7025. case "AssignmentPattern":
  7026. case "RestElement":
  7027. break;
  7028. case "ObjectExpression":
  7029. node.type = "ObjectPattern";
  7030. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7031. var _node$extra2;
  7032. const prop = node.properties[i];
  7033. const isLast = i === last;
  7034. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7035. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7036. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7037. }
  7038. }
  7039. break;
  7040. case "ObjectProperty":
  7041. {
  7042. const {
  7043. key,
  7044. value
  7045. } = node;
  7046. if (this.isPrivateName(key)) {
  7047. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7048. }
  7049. this.toAssignable(value, isLHS);
  7050. break;
  7051. }
  7052. case "SpreadElement":
  7053. {
  7054. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7055. }
  7056. case "ArrayExpression":
  7057. node.type = "ArrayPattern";
  7058. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7059. break;
  7060. case "AssignmentExpression":
  7061. if (node.operator !== "=") {
  7062. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7063. }
  7064. node.type = "AssignmentPattern";
  7065. delete node.operator;
  7066. this.toAssignable(node.left, isLHS);
  7067. break;
  7068. case "ParenthesizedExpression":
  7069. this.toAssignable(parenthesized, isLHS);
  7070. break;
  7071. }
  7072. }
  7073. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7074. if (prop.type === "ObjectMethod") {
  7075. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7076. } else if (prop.type === "SpreadElement") {
  7077. prop.type = "RestElement";
  7078. const arg = prop.argument;
  7079. this.checkToRestConversion(arg, false);
  7080. this.toAssignable(arg, isLHS);
  7081. if (!isLast) {
  7082. this.raise(Errors.RestTrailingComma, prop);
  7083. }
  7084. } else {
  7085. this.toAssignable(prop, isLHS);
  7086. }
  7087. }
  7088. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7089. const end = exprList.length - 1;
  7090. for (let i = 0; i <= end; i++) {
  7091. const elt = exprList[i];
  7092. if (!elt) continue;
  7093. if (elt.type === "SpreadElement") {
  7094. elt.type = "RestElement";
  7095. const arg = elt.argument;
  7096. this.checkToRestConversion(arg, true);
  7097. this.toAssignable(arg, isLHS);
  7098. } else {
  7099. this.toAssignable(elt, isLHS);
  7100. }
  7101. if (elt.type === "RestElement") {
  7102. if (i < end) {
  7103. this.raise(Errors.RestTrailingComma, elt);
  7104. } else if (trailingCommaLoc) {
  7105. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7106. }
  7107. }
  7108. }
  7109. }
  7110. isAssignable(node, isBinding) {
  7111. switch (node.type) {
  7112. case "Identifier":
  7113. case "ObjectPattern":
  7114. case "ArrayPattern":
  7115. case "AssignmentPattern":
  7116. case "RestElement":
  7117. return true;
  7118. case "ObjectExpression":
  7119. {
  7120. const last = node.properties.length - 1;
  7121. return node.properties.every((prop, i) => {
  7122. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7123. });
  7124. }
  7125. case "ObjectProperty":
  7126. return this.isAssignable(node.value);
  7127. case "SpreadElement":
  7128. return this.isAssignable(node.argument);
  7129. case "ArrayExpression":
  7130. return node.elements.every(element => element === null || this.isAssignable(element));
  7131. case "AssignmentExpression":
  7132. return node.operator === "=";
  7133. case "ParenthesizedExpression":
  7134. return this.isAssignable(node.expression);
  7135. case "MemberExpression":
  7136. case "OptionalMemberExpression":
  7137. return !isBinding;
  7138. default:
  7139. return false;
  7140. }
  7141. }
  7142. toReferencedList(exprList, isParenthesizedExpr) {
  7143. return exprList;
  7144. }
  7145. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7146. this.toReferencedList(exprList, isParenthesizedExpr);
  7147. for (const expr of exprList) {
  7148. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7149. this.toReferencedListDeep(expr.elements);
  7150. }
  7151. }
  7152. }
  7153. parseSpread(refExpressionErrors) {
  7154. const node = this.startNode();
  7155. this.next();
  7156. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7157. return this.finishNode(node, "SpreadElement");
  7158. }
  7159. parseRestBinding() {
  7160. const node = this.startNode();
  7161. this.next();
  7162. node.argument = this.parseBindingAtom();
  7163. return this.finishNode(node, "RestElement");
  7164. }
  7165. parseBindingAtom() {
  7166. switch (this.state.type) {
  7167. case 0:
  7168. {
  7169. const node = this.startNode();
  7170. this.next();
  7171. node.elements = this.parseBindingList(3, 93, 1);
  7172. return this.finishNode(node, "ArrayPattern");
  7173. }
  7174. case 5:
  7175. return this.parseObjectLike(8, true);
  7176. }
  7177. return this.parseIdentifier();
  7178. }
  7179. parseBindingList(close, closeCharCode, flags) {
  7180. const allowEmpty = flags & 1;
  7181. const elts = [];
  7182. let first = true;
  7183. while (!this.eat(close)) {
  7184. if (first) {
  7185. first = false;
  7186. } else {
  7187. this.expect(12);
  7188. }
  7189. if (allowEmpty && this.match(12)) {
  7190. elts.push(null);
  7191. } else if (this.eat(close)) {
  7192. break;
  7193. } else if (this.match(21)) {
  7194. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
  7195. if (!this.checkCommaAfterRest(closeCharCode)) {
  7196. this.expect(close);
  7197. break;
  7198. }
  7199. } else {
  7200. const decorators = [];
  7201. if (this.match(26) && this.hasPlugin("decorators")) {
  7202. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7203. }
  7204. while (this.match(26)) {
  7205. decorators.push(this.parseDecorator());
  7206. }
  7207. elts.push(this.parseAssignableListItem(flags, decorators));
  7208. }
  7209. }
  7210. return elts;
  7211. }
  7212. parseBindingRestProperty(prop) {
  7213. this.next();
  7214. prop.argument = this.parseIdentifier();
  7215. this.checkCommaAfterRest(125);
  7216. return this.finishNode(prop, "RestElement");
  7217. }
  7218. parseBindingProperty() {
  7219. const {
  7220. type,
  7221. startLoc
  7222. } = this.state;
  7223. if (type === 21) {
  7224. return this.parseBindingRestProperty(this.startNode());
  7225. }
  7226. const prop = this.startNode();
  7227. if (type === 138) {
  7228. this.expectPlugin("destructuringPrivate", startLoc);
  7229. this.classScope.usePrivateName(this.state.value, startLoc);
  7230. prop.key = this.parsePrivateName();
  7231. } else {
  7232. this.parsePropertyName(prop);
  7233. }
  7234. prop.method = false;
  7235. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7236. }
  7237. parseAssignableListItem(flags, decorators) {
  7238. const left = this.parseMaybeDefault();
  7239. this.parseAssignableListItemTypes(left, flags);
  7240. const elt = this.parseMaybeDefault(left.loc.start, left);
  7241. if (decorators.length) {
  7242. left.decorators = decorators;
  7243. }
  7244. return elt;
  7245. }
  7246. parseAssignableListItemTypes(param, flags) {
  7247. return param;
  7248. }
  7249. parseMaybeDefault(startLoc, left) {
  7250. var _startLoc, _left;
  7251. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  7252. left = (_left = left) != null ? _left : this.parseBindingAtom();
  7253. if (!this.eat(29)) return left;
  7254. const node = this.startNodeAt(startLoc);
  7255. node.left = left;
  7256. node.right = this.parseMaybeAssignAllowIn();
  7257. return this.finishNode(node, "AssignmentPattern");
  7258. }
  7259. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7260. return getOwn$1({
  7261. AssignmentPattern: "left",
  7262. RestElement: "argument",
  7263. ObjectProperty: "value",
  7264. ParenthesizedExpression: "expression",
  7265. ArrayPattern: "elements",
  7266. ObjectPattern: "properties"
  7267. }, type);
  7268. }
  7269. isOptionalMemberExpression(expression) {
  7270. return expression.type === "OptionalMemberExpression";
  7271. }
  7272. checkLVal(expression, {
  7273. in: ancestor,
  7274. binding = 64,
  7275. checkClashes = false,
  7276. strictModeChanged = false,
  7277. hasParenthesizedAncestor = false
  7278. }) {
  7279. var _expression$extra;
  7280. const type = expression.type;
  7281. if (this.isObjectMethod(expression)) return;
  7282. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7283. if (isOptionalMemberExpression || type === "MemberExpression") {
  7284. if (isOptionalMemberExpression) {
  7285. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7286. if (ancestor.type !== "AssignmentExpression") {
  7287. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7288. ancestor
  7289. });
  7290. }
  7291. }
  7292. if (binding !== 64) {
  7293. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7294. }
  7295. return;
  7296. }
  7297. if (type === "Identifier") {
  7298. this.checkIdentifier(expression, binding, strictModeChanged);
  7299. const {
  7300. name
  7301. } = expression;
  7302. if (checkClashes) {
  7303. if (checkClashes.has(name)) {
  7304. this.raise(Errors.ParamDupe, expression);
  7305. } else {
  7306. checkClashes.add(name);
  7307. }
  7308. }
  7309. return;
  7310. }
  7311. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7312. if (validity === true) return;
  7313. if (validity === false) {
  7314. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7315. this.raise(ParseErrorClass, expression, {
  7316. ancestor
  7317. });
  7318. return;
  7319. }
  7320. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  7321. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7322. type
  7323. } : ancestor;
  7324. for (const child of [].concat(expression[key])) {
  7325. if (child) {
  7326. this.checkLVal(child, {
  7327. in: nextAncestor,
  7328. binding,
  7329. checkClashes,
  7330. strictModeChanged,
  7331. hasParenthesizedAncestor: isParenthesizedExpression
  7332. });
  7333. }
  7334. }
  7335. }
  7336. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7337. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7338. if (bindingType === 64) {
  7339. this.raise(Errors.StrictEvalArguments, at, {
  7340. referenceName: at.name
  7341. });
  7342. } else {
  7343. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  7344. bindingName: at.name
  7345. });
  7346. }
  7347. }
  7348. if (bindingType & 8192 && at.name === "let") {
  7349. this.raise(Errors.LetInLexicalBinding, at);
  7350. }
  7351. if (!(bindingType & 64)) {
  7352. this.declareNameFromIdentifier(at, bindingType);
  7353. }
  7354. }
  7355. declareNameFromIdentifier(identifier, binding) {
  7356. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7357. }
  7358. checkToRestConversion(node, allowPattern) {
  7359. switch (node.type) {
  7360. case "ParenthesizedExpression":
  7361. this.checkToRestConversion(node.expression, allowPattern);
  7362. break;
  7363. case "Identifier":
  7364. case "MemberExpression":
  7365. break;
  7366. case "ArrayExpression":
  7367. case "ObjectExpression":
  7368. if (allowPattern) break;
  7369. default:
  7370. this.raise(Errors.InvalidRestAssignmentPattern, node);
  7371. }
  7372. }
  7373. checkCommaAfterRest(close) {
  7374. if (!this.match(12)) {
  7375. return false;
  7376. }
  7377. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  7378. return true;
  7379. }
  7380. }
  7381. const getOwn = (object, key) => hasOwnProperty.call(object, key) && object[key];
  7382. function nonNull(x) {
  7383. if (x == null) {
  7384. throw new Error(`Unexpected ${x} value.`);
  7385. }
  7386. return x;
  7387. }
  7388. function assert(x) {
  7389. if (!x) {
  7390. throw new Error("Assert fail");
  7391. }
  7392. }
  7393. const TSErrors = ParseErrorEnum`typescript`({
  7394. AbstractMethodHasImplementation: ({
  7395. methodName
  7396. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7397. AbstractPropertyHasInitializer: ({
  7398. propertyName
  7399. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7400. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7401. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7402. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7403. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7404. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7405. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7406. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7407. DeclareAccessor: ({
  7408. kind
  7409. }) => `'declare' is not allowed in ${kind}ters.`,
  7410. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7411. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7412. DuplicateAccessibilityModifier: ({
  7413. modifier
  7414. }) => `Accessibility modifier already seen.`,
  7415. DuplicateModifier: ({
  7416. modifier
  7417. }) => `Duplicate modifier: '${modifier}'.`,
  7418. EmptyHeritageClauseType: ({
  7419. token
  7420. }) => `'${token}' list cannot be empty.`,
  7421. EmptyTypeArguments: "Type argument list cannot be empty.",
  7422. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7423. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7424. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7425. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7426. IncompatibleModifiers: ({
  7427. modifiers
  7428. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7429. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7430. IndexSignatureHasAccessibility: ({
  7431. modifier
  7432. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7433. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7434. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7435. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7436. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7437. InvalidModifierOnTypeMember: ({
  7438. modifier
  7439. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7440. InvalidModifierOnTypeParameter: ({
  7441. modifier
  7442. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7443. InvalidModifierOnTypeParameterPositions: ({
  7444. modifier
  7445. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7446. InvalidModifiersOrder: ({
  7447. orderedModifiers
  7448. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7449. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7450. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7451. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7452. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7453. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7454. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7455. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7456. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7457. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7458. PrivateElementHasAccessibility: ({
  7459. modifier
  7460. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7461. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7462. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7463. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7464. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7465. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7466. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7467. SingleTypeParameterWithoutTrailingComma: ({
  7468. typeParameterName
  7469. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7470. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7471. 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?`).",
  7472. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7473. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7474. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7475. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7476. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7477. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7478. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7479. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7480. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7481. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7482. UnsupportedSignatureParameterKind: ({
  7483. type
  7484. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7485. });
  7486. function keywordTypeFromName(value) {
  7487. switch (value) {
  7488. case "any":
  7489. return "TSAnyKeyword";
  7490. case "boolean":
  7491. return "TSBooleanKeyword";
  7492. case "bigint":
  7493. return "TSBigIntKeyword";
  7494. case "never":
  7495. return "TSNeverKeyword";
  7496. case "number":
  7497. return "TSNumberKeyword";
  7498. case "object":
  7499. return "TSObjectKeyword";
  7500. case "string":
  7501. return "TSStringKeyword";
  7502. case "symbol":
  7503. return "TSSymbolKeyword";
  7504. case "undefined":
  7505. return "TSUndefinedKeyword";
  7506. case "unknown":
  7507. return "TSUnknownKeyword";
  7508. default:
  7509. return undefined;
  7510. }
  7511. }
  7512. function tsIsAccessModifier(modifier) {
  7513. return modifier === "private" || modifier === "public" || modifier === "protected";
  7514. }
  7515. function tsIsVarianceAnnotations(modifier) {
  7516. return modifier === "in" || modifier === "out";
  7517. }
  7518. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7519. constructor(...args) {
  7520. super(...args);
  7521. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7522. allowedModifiers: ["in", "out"],
  7523. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7524. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7525. });
  7526. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7527. allowedModifiers: ["const"],
  7528. disallowedModifiers: ["in", "out"],
  7529. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7530. });
  7531. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7532. allowedModifiers: ["in", "out", "const"],
  7533. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7534. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7535. });
  7536. }
  7537. getScopeHandler() {
  7538. return TypeScriptScopeHandler;
  7539. }
  7540. tsIsIdentifier() {
  7541. return tokenIsIdentifier(this.state.type);
  7542. }
  7543. tsTokenCanFollowModifier() {
  7544. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(138) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  7545. }
  7546. tsNextTokenCanFollowModifier() {
  7547. this.next();
  7548. return this.tsTokenCanFollowModifier();
  7549. }
  7550. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7551. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7552. return undefined;
  7553. }
  7554. const modifier = this.state.value;
  7555. if (allowedModifiers.indexOf(modifier) !== -1) {
  7556. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7557. return undefined;
  7558. }
  7559. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7560. return modifier;
  7561. }
  7562. }
  7563. return undefined;
  7564. }
  7565. tsParseModifiers({
  7566. allowedModifiers,
  7567. disallowedModifiers,
  7568. stopOnStartOfClassStaticBlock,
  7569. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7570. }, modified) {
  7571. const enforceOrder = (loc, modifier, before, after) => {
  7572. if (modifier === before && modified[after]) {
  7573. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7574. orderedModifiers: [before, after]
  7575. });
  7576. }
  7577. };
  7578. const incompatible = (loc, modifier, mod1, mod2) => {
  7579. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7580. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7581. modifiers: [mod1, mod2]
  7582. });
  7583. }
  7584. };
  7585. for (;;) {
  7586. const {
  7587. startLoc
  7588. } = this.state;
  7589. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7590. if (!modifier) break;
  7591. if (tsIsAccessModifier(modifier)) {
  7592. if (modified.accessibility) {
  7593. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7594. modifier
  7595. });
  7596. } else {
  7597. enforceOrder(startLoc, modifier, modifier, "override");
  7598. enforceOrder(startLoc, modifier, modifier, "static");
  7599. enforceOrder(startLoc, modifier, modifier, "readonly");
  7600. modified.accessibility = modifier;
  7601. }
  7602. } else if (tsIsVarianceAnnotations(modifier)) {
  7603. if (modified[modifier]) {
  7604. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7605. modifier
  7606. });
  7607. }
  7608. modified[modifier] = true;
  7609. enforceOrder(startLoc, modifier, "in", "out");
  7610. } else {
  7611. if (hasOwnProperty.call(modified, modifier)) {
  7612. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7613. modifier
  7614. });
  7615. } else {
  7616. enforceOrder(startLoc, modifier, "static", "readonly");
  7617. enforceOrder(startLoc, modifier, "static", "override");
  7618. enforceOrder(startLoc, modifier, "override", "readonly");
  7619. enforceOrder(startLoc, modifier, "abstract", "override");
  7620. incompatible(startLoc, modifier, "declare", "override");
  7621. incompatible(startLoc, modifier, "static", "abstract");
  7622. }
  7623. modified[modifier] = true;
  7624. }
  7625. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7626. this.raise(errorTemplate, startLoc, {
  7627. modifier
  7628. });
  7629. }
  7630. }
  7631. }
  7632. tsIsListTerminator(kind) {
  7633. switch (kind) {
  7634. case "EnumMembers":
  7635. case "TypeMembers":
  7636. return this.match(8);
  7637. case "HeritageClauseElement":
  7638. return this.match(5);
  7639. case "TupleElementTypes":
  7640. return this.match(3);
  7641. case "TypeParametersOrArguments":
  7642. return this.match(48);
  7643. }
  7644. }
  7645. tsParseList(kind, parseElement) {
  7646. const result = [];
  7647. while (!this.tsIsListTerminator(kind)) {
  7648. result.push(parseElement());
  7649. }
  7650. return result;
  7651. }
  7652. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7653. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7654. }
  7655. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7656. const result = [];
  7657. let trailingCommaPos = -1;
  7658. for (;;) {
  7659. if (this.tsIsListTerminator(kind)) {
  7660. break;
  7661. }
  7662. trailingCommaPos = -1;
  7663. const element = parseElement();
  7664. if (element == null) {
  7665. return undefined;
  7666. }
  7667. result.push(element);
  7668. if (this.eat(12)) {
  7669. trailingCommaPos = this.state.lastTokStartLoc.index;
  7670. continue;
  7671. }
  7672. if (this.tsIsListTerminator(kind)) {
  7673. break;
  7674. }
  7675. if (expectSuccess) {
  7676. this.expect(12);
  7677. }
  7678. return undefined;
  7679. }
  7680. if (refTrailingCommaPos) {
  7681. refTrailingCommaPos.value = trailingCommaPos;
  7682. }
  7683. return result;
  7684. }
  7685. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7686. if (!skipFirstToken) {
  7687. if (bracket) {
  7688. this.expect(0);
  7689. } else {
  7690. this.expect(47);
  7691. }
  7692. }
  7693. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7694. if (bracket) {
  7695. this.expect(3);
  7696. } else {
  7697. this.expect(48);
  7698. }
  7699. return result;
  7700. }
  7701. tsParseImportType() {
  7702. const node = this.startNode();
  7703. this.expect(83);
  7704. this.expect(10);
  7705. if (!this.match(133)) {
  7706. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7707. }
  7708. node.argument = super.parseExprAtom();
  7709. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  7710. node.options = null;
  7711. }
  7712. if (this.eat(12)) {
  7713. this.expectImportAttributesPlugin();
  7714. if (!this.match(11)) {
  7715. node.options = super.parseMaybeAssignAllowIn();
  7716. this.eat(12);
  7717. }
  7718. }
  7719. this.expect(11);
  7720. if (this.eat(16)) {
  7721. node.qualifier = this.tsParseEntityName();
  7722. }
  7723. if (this.match(47)) {
  7724. node.typeParameters = this.tsParseTypeArguments();
  7725. }
  7726. return this.finishNode(node, "TSImportType");
  7727. }
  7728. tsParseEntityName(allowReservedWords = true) {
  7729. let entity = this.parseIdentifier(allowReservedWords);
  7730. while (this.eat(16)) {
  7731. const node = this.startNodeAtNode(entity);
  7732. node.left = entity;
  7733. node.right = this.parseIdentifier(allowReservedWords);
  7734. entity = this.finishNode(node, "TSQualifiedName");
  7735. }
  7736. return entity;
  7737. }
  7738. tsParseTypeReference() {
  7739. const node = this.startNode();
  7740. node.typeName = this.tsParseEntityName();
  7741. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7742. node.typeParameters = this.tsParseTypeArguments();
  7743. }
  7744. return this.finishNode(node, "TSTypeReference");
  7745. }
  7746. tsParseThisTypePredicate(lhs) {
  7747. this.next();
  7748. const node = this.startNodeAtNode(lhs);
  7749. node.parameterName = lhs;
  7750. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7751. node.asserts = false;
  7752. return this.finishNode(node, "TSTypePredicate");
  7753. }
  7754. tsParseThisTypeNode() {
  7755. const node = this.startNode();
  7756. this.next();
  7757. return this.finishNode(node, "TSThisType");
  7758. }
  7759. tsParseTypeQuery() {
  7760. const node = this.startNode();
  7761. this.expect(87);
  7762. if (this.match(83)) {
  7763. node.exprName = this.tsParseImportType();
  7764. } else {
  7765. node.exprName = this.tsParseEntityName();
  7766. }
  7767. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7768. node.typeParameters = this.tsParseTypeArguments();
  7769. }
  7770. return this.finishNode(node, "TSTypeQuery");
  7771. }
  7772. tsParseTypeParameter(parseModifiers) {
  7773. const node = this.startNode();
  7774. parseModifiers(node);
  7775. node.name = this.tsParseTypeParameterName();
  7776. node.constraint = this.tsEatThenParseType(81);
  7777. node.default = this.tsEatThenParseType(29);
  7778. return this.finishNode(node, "TSTypeParameter");
  7779. }
  7780. tsTryParseTypeParameters(parseModifiers) {
  7781. if (this.match(47)) {
  7782. return this.tsParseTypeParameters(parseModifiers);
  7783. }
  7784. }
  7785. tsParseTypeParameters(parseModifiers) {
  7786. const node = this.startNode();
  7787. if (this.match(47) || this.match(142)) {
  7788. this.next();
  7789. } else {
  7790. this.unexpected();
  7791. }
  7792. const refTrailingCommaPos = {
  7793. value: -1
  7794. };
  7795. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7796. if (node.params.length === 0) {
  7797. this.raise(TSErrors.EmptyTypeParameters, node);
  7798. }
  7799. if (refTrailingCommaPos.value !== -1) {
  7800. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7801. }
  7802. return this.finishNode(node, "TSTypeParameterDeclaration");
  7803. }
  7804. tsFillSignature(returnToken, signature) {
  7805. const returnTokenRequired = returnToken === 19;
  7806. const paramsKey = "parameters";
  7807. const returnTypeKey = "typeAnnotation";
  7808. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  7809. this.expect(10);
  7810. signature[paramsKey] = this.tsParseBindingListForSignature();
  7811. if (returnTokenRequired) {
  7812. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7813. } else if (this.match(returnToken)) {
  7814. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7815. }
  7816. }
  7817. tsParseBindingListForSignature() {
  7818. const list = super.parseBindingList(11, 41, 2);
  7819. for (const pattern of list) {
  7820. const {
  7821. type
  7822. } = pattern;
  7823. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  7824. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  7825. type
  7826. });
  7827. }
  7828. }
  7829. return list;
  7830. }
  7831. tsParseTypeMemberSemicolon() {
  7832. if (!this.eat(12) && !this.isLineTerminator()) {
  7833. this.expect(13);
  7834. }
  7835. }
  7836. tsParseSignatureMember(kind, node) {
  7837. this.tsFillSignature(14, node);
  7838. this.tsParseTypeMemberSemicolon();
  7839. return this.finishNode(node, kind);
  7840. }
  7841. tsIsUnambiguouslyIndexSignature() {
  7842. this.next();
  7843. if (tokenIsIdentifier(this.state.type)) {
  7844. this.next();
  7845. return this.match(14);
  7846. }
  7847. return false;
  7848. }
  7849. tsTryParseIndexSignature(node) {
  7850. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  7851. return;
  7852. }
  7853. this.expect(0);
  7854. const id = this.parseIdentifier();
  7855. id.typeAnnotation = this.tsParseTypeAnnotation();
  7856. this.resetEndLocation(id);
  7857. this.expect(3);
  7858. node.parameters = [id];
  7859. const type = this.tsTryParseTypeAnnotation();
  7860. if (type) node.typeAnnotation = type;
  7861. this.tsParseTypeMemberSemicolon();
  7862. return this.finishNode(node, "TSIndexSignature");
  7863. }
  7864. tsParsePropertyOrMethodSignature(node, readonly) {
  7865. if (this.eat(17)) node.optional = true;
  7866. const nodeAny = node;
  7867. if (this.match(10) || this.match(47)) {
  7868. if (readonly) {
  7869. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  7870. }
  7871. const method = nodeAny;
  7872. if (method.kind && this.match(47)) {
  7873. this.raise(TSErrors.AccesorCannotHaveTypeParameters, this.state.curPosition());
  7874. }
  7875. this.tsFillSignature(14, method);
  7876. this.tsParseTypeMemberSemicolon();
  7877. const paramsKey = "parameters";
  7878. const returnTypeKey = "typeAnnotation";
  7879. if (method.kind === "get") {
  7880. if (method[paramsKey].length > 0) {
  7881. this.raise(Errors.BadGetterArity, this.state.curPosition());
  7882. if (this.isThisParam(method[paramsKey][0])) {
  7883. this.raise(TSErrors.AccesorCannotDeclareThisParameter, this.state.curPosition());
  7884. }
  7885. }
  7886. } else if (method.kind === "set") {
  7887. if (method[paramsKey].length !== 1) {
  7888. this.raise(Errors.BadSetterArity, this.state.curPosition());
  7889. } else {
  7890. const firstParameter = method[paramsKey][0];
  7891. if (this.isThisParam(firstParameter)) {
  7892. this.raise(TSErrors.AccesorCannotDeclareThisParameter, this.state.curPosition());
  7893. }
  7894. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  7895. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, this.state.curPosition());
  7896. }
  7897. if (firstParameter.type === "RestElement") {
  7898. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, this.state.curPosition());
  7899. }
  7900. }
  7901. if (method[returnTypeKey]) {
  7902. this.raise(TSErrors.SetAccesorCannotHaveReturnType, method[returnTypeKey]);
  7903. }
  7904. } else {
  7905. method.kind = "method";
  7906. }
  7907. return this.finishNode(method, "TSMethodSignature");
  7908. } else {
  7909. const property = nodeAny;
  7910. if (readonly) property.readonly = true;
  7911. const type = this.tsTryParseTypeAnnotation();
  7912. if (type) property.typeAnnotation = type;
  7913. this.tsParseTypeMemberSemicolon();
  7914. return this.finishNode(property, "TSPropertySignature");
  7915. }
  7916. }
  7917. tsParseTypeMember() {
  7918. const node = this.startNode();
  7919. if (this.match(10) || this.match(47)) {
  7920. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  7921. }
  7922. if (this.match(77)) {
  7923. const id = this.startNode();
  7924. this.next();
  7925. if (this.match(10) || this.match(47)) {
  7926. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  7927. } else {
  7928. node.key = this.createIdentifier(id, "new");
  7929. return this.tsParsePropertyOrMethodSignature(node, false);
  7930. }
  7931. }
  7932. this.tsParseModifiers({
  7933. allowedModifiers: ["readonly"],
  7934. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  7935. }, node);
  7936. const idx = this.tsTryParseIndexSignature(node);
  7937. if (idx) {
  7938. return idx;
  7939. }
  7940. super.parsePropertyName(node);
  7941. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  7942. node.kind = node.key.name;
  7943. super.parsePropertyName(node);
  7944. }
  7945. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  7946. }
  7947. tsParseTypeLiteral() {
  7948. const node = this.startNode();
  7949. node.members = this.tsParseObjectTypeMembers();
  7950. return this.finishNode(node, "TSTypeLiteral");
  7951. }
  7952. tsParseObjectTypeMembers() {
  7953. this.expect(5);
  7954. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  7955. this.expect(8);
  7956. return members;
  7957. }
  7958. tsIsStartOfMappedType() {
  7959. this.next();
  7960. if (this.eat(53)) {
  7961. return this.isContextual(122);
  7962. }
  7963. if (this.isContextual(122)) {
  7964. this.next();
  7965. }
  7966. if (!this.match(0)) {
  7967. return false;
  7968. }
  7969. this.next();
  7970. if (!this.tsIsIdentifier()) {
  7971. return false;
  7972. }
  7973. this.next();
  7974. return this.match(58);
  7975. }
  7976. tsParseMappedTypeParameter() {
  7977. const node = this.startNode();
  7978. node.name = this.tsParseTypeParameterName();
  7979. node.constraint = this.tsExpectThenParseType(58);
  7980. return this.finishNode(node, "TSTypeParameter");
  7981. }
  7982. tsParseMappedType() {
  7983. const node = this.startNode();
  7984. this.expect(5);
  7985. if (this.match(53)) {
  7986. node.readonly = this.state.value;
  7987. this.next();
  7988. this.expectContextual(122);
  7989. } else if (this.eatContextual(122)) {
  7990. node.readonly = true;
  7991. }
  7992. this.expect(0);
  7993. node.typeParameter = this.tsParseMappedTypeParameter();
  7994. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  7995. this.expect(3);
  7996. if (this.match(53)) {
  7997. node.optional = this.state.value;
  7998. this.next();
  7999. this.expect(17);
  8000. } else if (this.eat(17)) {
  8001. node.optional = true;
  8002. }
  8003. node.typeAnnotation = this.tsTryParseType();
  8004. this.semicolon();
  8005. this.expect(8);
  8006. return this.finishNode(node, "TSMappedType");
  8007. }
  8008. tsParseTupleType() {
  8009. const node = this.startNode();
  8010. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8011. let seenOptionalElement = false;
  8012. node.elementTypes.forEach(elementNode => {
  8013. const {
  8014. type
  8015. } = elementNode;
  8016. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8017. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8018. }
  8019. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8020. });
  8021. return this.finishNode(node, "TSTupleType");
  8022. }
  8023. tsParseTupleElementType() {
  8024. const {
  8025. startLoc
  8026. } = this.state;
  8027. const rest = this.eat(21);
  8028. let labeled;
  8029. let label;
  8030. let optional;
  8031. let type;
  8032. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8033. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8034. if (chAfterWord === 58) {
  8035. labeled = true;
  8036. optional = false;
  8037. label = this.parseIdentifier(true);
  8038. this.expect(14);
  8039. type = this.tsParseType();
  8040. } else if (chAfterWord === 63) {
  8041. optional = true;
  8042. const startLoc = this.state.startLoc;
  8043. const wordName = this.state.value;
  8044. const typeOrLabel = this.tsParseNonArrayType();
  8045. if (this.lookaheadCharCode() === 58) {
  8046. labeled = true;
  8047. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8048. this.expect(17);
  8049. this.expect(14);
  8050. type = this.tsParseType();
  8051. } else {
  8052. labeled = false;
  8053. type = typeOrLabel;
  8054. this.expect(17);
  8055. }
  8056. } else {
  8057. type = this.tsParseType();
  8058. optional = this.eat(17);
  8059. labeled = this.eat(14);
  8060. }
  8061. if (labeled) {
  8062. let labeledNode;
  8063. if (label) {
  8064. labeledNode = this.startNodeAtNode(label);
  8065. labeledNode.optional = optional;
  8066. labeledNode.label = label;
  8067. labeledNode.elementType = type;
  8068. if (this.eat(17)) {
  8069. labeledNode.optional = true;
  8070. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8071. }
  8072. } else {
  8073. labeledNode = this.startNodeAtNode(type);
  8074. labeledNode.optional = optional;
  8075. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8076. labeledNode.label = type;
  8077. labeledNode.elementType = this.tsParseType();
  8078. }
  8079. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8080. } else if (optional) {
  8081. const optionalTypeNode = this.startNodeAtNode(type);
  8082. optionalTypeNode.typeAnnotation = type;
  8083. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8084. }
  8085. if (rest) {
  8086. const restNode = this.startNodeAt(startLoc);
  8087. restNode.typeAnnotation = type;
  8088. type = this.finishNode(restNode, "TSRestType");
  8089. }
  8090. return type;
  8091. }
  8092. tsParseParenthesizedType() {
  8093. const node = this.startNode();
  8094. this.expect(10);
  8095. node.typeAnnotation = this.tsParseType();
  8096. this.expect(11);
  8097. return this.finishNode(node, "TSParenthesizedType");
  8098. }
  8099. tsParseFunctionOrConstructorType(type, abstract) {
  8100. const node = this.startNode();
  8101. if (type === "TSConstructorType") {
  8102. node.abstract = !!abstract;
  8103. if (abstract) this.next();
  8104. this.next();
  8105. }
  8106. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8107. return this.finishNode(node, type);
  8108. }
  8109. tsParseLiteralTypeNode() {
  8110. const node = this.startNode();
  8111. switch (this.state.type) {
  8112. case 134:
  8113. case 135:
  8114. case 133:
  8115. case 85:
  8116. case 86:
  8117. node.literal = super.parseExprAtom();
  8118. break;
  8119. default:
  8120. this.unexpected();
  8121. }
  8122. return this.finishNode(node, "TSLiteralType");
  8123. }
  8124. tsParseTemplateLiteralType() {
  8125. const node = this.startNode();
  8126. node.literal = super.parseTemplate(false);
  8127. return this.finishNode(node, "TSLiteralType");
  8128. }
  8129. parseTemplateSubstitution() {
  8130. if (this.state.inType) return this.tsParseType();
  8131. return super.parseTemplateSubstitution();
  8132. }
  8133. tsParseThisTypeOrThisTypePredicate() {
  8134. const thisKeyword = this.tsParseThisTypeNode();
  8135. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8136. return this.tsParseThisTypePredicate(thisKeyword);
  8137. } else {
  8138. return thisKeyword;
  8139. }
  8140. }
  8141. tsParseNonArrayType() {
  8142. switch (this.state.type) {
  8143. case 133:
  8144. case 134:
  8145. case 135:
  8146. case 85:
  8147. case 86:
  8148. return this.tsParseLiteralTypeNode();
  8149. case 53:
  8150. if (this.state.value === "-") {
  8151. const node = this.startNode();
  8152. const nextToken = this.lookahead();
  8153. if (nextToken.type !== 134 && nextToken.type !== 135) {
  8154. this.unexpected();
  8155. }
  8156. node.literal = this.parseMaybeUnary();
  8157. return this.finishNode(node, "TSLiteralType");
  8158. }
  8159. break;
  8160. case 78:
  8161. return this.tsParseThisTypeOrThisTypePredicate();
  8162. case 87:
  8163. return this.tsParseTypeQuery();
  8164. case 83:
  8165. return this.tsParseImportType();
  8166. case 5:
  8167. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8168. case 0:
  8169. return this.tsParseTupleType();
  8170. case 10:
  8171. return this.tsParseParenthesizedType();
  8172. case 25:
  8173. case 24:
  8174. return this.tsParseTemplateLiteralType();
  8175. default:
  8176. {
  8177. const {
  8178. type
  8179. } = this.state;
  8180. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8181. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8182. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8183. const node = this.startNode();
  8184. this.next();
  8185. return this.finishNode(node, nodeType);
  8186. }
  8187. return this.tsParseTypeReference();
  8188. }
  8189. }
  8190. }
  8191. this.unexpected();
  8192. }
  8193. tsParseArrayTypeOrHigher() {
  8194. let type = this.tsParseNonArrayType();
  8195. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8196. if (this.match(3)) {
  8197. const node = this.startNodeAtNode(type);
  8198. node.elementType = type;
  8199. this.expect(3);
  8200. type = this.finishNode(node, "TSArrayType");
  8201. } else {
  8202. const node = this.startNodeAtNode(type);
  8203. node.objectType = type;
  8204. node.indexType = this.tsParseType();
  8205. this.expect(3);
  8206. type = this.finishNode(node, "TSIndexedAccessType");
  8207. }
  8208. }
  8209. return type;
  8210. }
  8211. tsParseTypeOperator() {
  8212. const node = this.startNode();
  8213. const operator = this.state.value;
  8214. this.next();
  8215. node.operator = operator;
  8216. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8217. if (operator === "readonly") {
  8218. this.tsCheckTypeAnnotationForReadOnly(node);
  8219. }
  8220. return this.finishNode(node, "TSTypeOperator");
  8221. }
  8222. tsCheckTypeAnnotationForReadOnly(node) {
  8223. switch (node.typeAnnotation.type) {
  8224. case "TSTupleType":
  8225. case "TSArrayType":
  8226. return;
  8227. default:
  8228. this.raise(TSErrors.UnexpectedReadonly, node);
  8229. }
  8230. }
  8231. tsParseInferType() {
  8232. const node = this.startNode();
  8233. this.expectContextual(115);
  8234. const typeParameter = this.startNode();
  8235. typeParameter.name = this.tsParseTypeParameterName();
  8236. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8237. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8238. return this.finishNode(node, "TSInferType");
  8239. }
  8240. tsParseConstraintForInferType() {
  8241. if (this.eat(81)) {
  8242. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8243. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8244. return constraint;
  8245. }
  8246. }
  8247. }
  8248. tsParseTypeOperatorOrHigher() {
  8249. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8250. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8251. }
  8252. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8253. const node = this.startNode();
  8254. const hasLeadingOperator = this.eat(operator);
  8255. const types = [];
  8256. do {
  8257. types.push(parseConstituentType());
  8258. } while (this.eat(operator));
  8259. if (types.length === 1 && !hasLeadingOperator) {
  8260. return types[0];
  8261. }
  8262. node.types = types;
  8263. return this.finishNode(node, kind);
  8264. }
  8265. tsParseIntersectionTypeOrHigher() {
  8266. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8267. }
  8268. tsParseUnionTypeOrHigher() {
  8269. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8270. }
  8271. tsIsStartOfFunctionType() {
  8272. if (this.match(47)) {
  8273. return true;
  8274. }
  8275. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8276. }
  8277. tsSkipParameterStart() {
  8278. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8279. this.next();
  8280. return true;
  8281. }
  8282. if (this.match(5)) {
  8283. const {
  8284. errors
  8285. } = this.state;
  8286. const previousErrorCount = errors.length;
  8287. try {
  8288. this.parseObjectLike(8, true);
  8289. return errors.length === previousErrorCount;
  8290. } catch (_unused) {
  8291. return false;
  8292. }
  8293. }
  8294. if (this.match(0)) {
  8295. this.next();
  8296. const {
  8297. errors
  8298. } = this.state;
  8299. const previousErrorCount = errors.length;
  8300. try {
  8301. super.parseBindingList(3, 93, 1);
  8302. return errors.length === previousErrorCount;
  8303. } catch (_unused2) {
  8304. return false;
  8305. }
  8306. }
  8307. return false;
  8308. }
  8309. tsIsUnambiguouslyStartOfFunctionType() {
  8310. this.next();
  8311. if (this.match(11) || this.match(21)) {
  8312. return true;
  8313. }
  8314. if (this.tsSkipParameterStart()) {
  8315. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8316. return true;
  8317. }
  8318. if (this.match(11)) {
  8319. this.next();
  8320. if (this.match(19)) {
  8321. return true;
  8322. }
  8323. }
  8324. }
  8325. return false;
  8326. }
  8327. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8328. return this.tsInType(() => {
  8329. const t = this.startNode();
  8330. this.expect(returnToken);
  8331. const node = this.startNode();
  8332. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8333. if (asserts && this.match(78)) {
  8334. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8335. if (thisTypePredicate.type === "TSThisType") {
  8336. node.parameterName = thisTypePredicate;
  8337. node.asserts = true;
  8338. node.typeAnnotation = null;
  8339. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8340. } else {
  8341. this.resetStartLocationFromNode(thisTypePredicate, node);
  8342. thisTypePredicate.asserts = true;
  8343. }
  8344. t.typeAnnotation = thisTypePredicate;
  8345. return this.finishNode(t, "TSTypeAnnotation");
  8346. }
  8347. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8348. if (!typePredicateVariable) {
  8349. if (!asserts) {
  8350. return this.tsParseTypeAnnotation(false, t);
  8351. }
  8352. node.parameterName = this.parseIdentifier();
  8353. node.asserts = asserts;
  8354. node.typeAnnotation = null;
  8355. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8356. return this.finishNode(t, "TSTypeAnnotation");
  8357. }
  8358. const type = this.tsParseTypeAnnotation(false);
  8359. node.parameterName = typePredicateVariable;
  8360. node.typeAnnotation = type;
  8361. node.asserts = asserts;
  8362. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8363. return this.finishNode(t, "TSTypeAnnotation");
  8364. });
  8365. }
  8366. tsTryParseTypeOrTypePredicateAnnotation() {
  8367. if (this.match(14)) {
  8368. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8369. }
  8370. }
  8371. tsTryParseTypeAnnotation() {
  8372. if (this.match(14)) {
  8373. return this.tsParseTypeAnnotation();
  8374. }
  8375. }
  8376. tsTryParseType() {
  8377. return this.tsEatThenParseType(14);
  8378. }
  8379. tsParseTypePredicatePrefix() {
  8380. const id = this.parseIdentifier();
  8381. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8382. this.next();
  8383. return id;
  8384. }
  8385. }
  8386. tsParseTypePredicateAsserts() {
  8387. if (this.state.type !== 109) {
  8388. return false;
  8389. }
  8390. const containsEsc = this.state.containsEsc;
  8391. this.next();
  8392. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8393. return false;
  8394. }
  8395. if (containsEsc) {
  8396. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8397. reservedWord: "asserts"
  8398. });
  8399. }
  8400. return true;
  8401. }
  8402. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8403. this.tsInType(() => {
  8404. if (eatColon) this.expect(14);
  8405. t.typeAnnotation = this.tsParseType();
  8406. });
  8407. return this.finishNode(t, "TSTypeAnnotation");
  8408. }
  8409. tsParseType() {
  8410. assert(this.state.inType);
  8411. const type = this.tsParseNonConditionalType();
  8412. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8413. return type;
  8414. }
  8415. const node = this.startNodeAtNode(type);
  8416. node.checkType = type;
  8417. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8418. this.expect(17);
  8419. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8420. this.expect(14);
  8421. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8422. return this.finishNode(node, "TSConditionalType");
  8423. }
  8424. isAbstractConstructorSignature() {
  8425. return this.isContextual(124) && this.lookahead().type === 77;
  8426. }
  8427. tsParseNonConditionalType() {
  8428. if (this.tsIsStartOfFunctionType()) {
  8429. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8430. }
  8431. if (this.match(77)) {
  8432. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8433. } else if (this.isAbstractConstructorSignature()) {
  8434. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8435. }
  8436. return this.tsParseUnionTypeOrHigher();
  8437. }
  8438. tsParseTypeAssertion() {
  8439. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8440. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8441. }
  8442. const node = this.startNode();
  8443. node.typeAnnotation = this.tsInType(() => {
  8444. this.next();
  8445. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8446. });
  8447. this.expect(48);
  8448. node.expression = this.parseMaybeUnary();
  8449. return this.finishNode(node, "TSTypeAssertion");
  8450. }
  8451. tsParseHeritageClause(token) {
  8452. const originalStartLoc = this.state.startLoc;
  8453. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8454. const node = this.startNode();
  8455. node.expression = this.tsParseEntityName();
  8456. if (this.match(47)) {
  8457. node.typeParameters = this.tsParseTypeArguments();
  8458. }
  8459. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8460. });
  8461. if (!delimitedList.length) {
  8462. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8463. token
  8464. });
  8465. }
  8466. return delimitedList;
  8467. }
  8468. tsParseInterfaceDeclaration(node, properties = {}) {
  8469. if (this.hasFollowingLineBreak()) return null;
  8470. this.expectContextual(129);
  8471. if (properties.declare) node.declare = true;
  8472. if (tokenIsIdentifier(this.state.type)) {
  8473. node.id = this.parseIdentifier();
  8474. this.checkIdentifier(node.id, 130);
  8475. } else {
  8476. node.id = null;
  8477. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8478. }
  8479. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8480. if (this.eat(81)) {
  8481. node.extends = this.tsParseHeritageClause("extends");
  8482. }
  8483. const body = this.startNode();
  8484. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8485. node.body = this.finishNode(body, "TSInterfaceBody");
  8486. return this.finishNode(node, "TSInterfaceDeclaration");
  8487. }
  8488. tsParseTypeAliasDeclaration(node) {
  8489. node.id = this.parseIdentifier();
  8490. this.checkIdentifier(node.id, 2);
  8491. node.typeAnnotation = this.tsInType(() => {
  8492. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8493. this.expect(29);
  8494. if (this.isContextual(114) && this.lookahead().type !== 16) {
  8495. const node = this.startNode();
  8496. this.next();
  8497. return this.finishNode(node, "TSIntrinsicKeyword");
  8498. }
  8499. return this.tsParseType();
  8500. });
  8501. this.semicolon();
  8502. return this.finishNode(node, "TSTypeAliasDeclaration");
  8503. }
  8504. tsInNoContext(cb) {
  8505. const oldContext = this.state.context;
  8506. this.state.context = [oldContext[0]];
  8507. try {
  8508. return cb();
  8509. } finally {
  8510. this.state.context = oldContext;
  8511. }
  8512. }
  8513. tsInType(cb) {
  8514. const oldInType = this.state.inType;
  8515. this.state.inType = true;
  8516. try {
  8517. return cb();
  8518. } finally {
  8519. this.state.inType = oldInType;
  8520. }
  8521. }
  8522. tsInDisallowConditionalTypesContext(cb) {
  8523. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8524. this.state.inDisallowConditionalTypesContext = true;
  8525. try {
  8526. return cb();
  8527. } finally {
  8528. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8529. }
  8530. }
  8531. tsInAllowConditionalTypesContext(cb) {
  8532. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8533. this.state.inDisallowConditionalTypesContext = false;
  8534. try {
  8535. return cb();
  8536. } finally {
  8537. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8538. }
  8539. }
  8540. tsEatThenParseType(token) {
  8541. if (this.match(token)) {
  8542. return this.tsNextThenParseType();
  8543. }
  8544. }
  8545. tsExpectThenParseType(token) {
  8546. return this.tsInType(() => {
  8547. this.expect(token);
  8548. return this.tsParseType();
  8549. });
  8550. }
  8551. tsNextThenParseType() {
  8552. return this.tsInType(() => {
  8553. this.next();
  8554. return this.tsParseType();
  8555. });
  8556. }
  8557. tsParseEnumMember() {
  8558. const node = this.startNode();
  8559. node.id = this.match(133) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8560. if (this.eat(29)) {
  8561. node.initializer = super.parseMaybeAssignAllowIn();
  8562. }
  8563. return this.finishNode(node, "TSEnumMember");
  8564. }
  8565. tsParseEnumDeclaration(node, properties = {}) {
  8566. if (properties.const) node.const = true;
  8567. if (properties.declare) node.declare = true;
  8568. this.expectContextual(126);
  8569. node.id = this.parseIdentifier();
  8570. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8571. this.expect(5);
  8572. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8573. this.expect(8);
  8574. return this.finishNode(node, "TSEnumDeclaration");
  8575. }
  8576. tsParseModuleBlock() {
  8577. const node = this.startNode();
  8578. this.scope.enter(0);
  8579. this.expect(5);
  8580. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8581. this.scope.exit();
  8582. return this.finishNode(node, "TSModuleBlock");
  8583. }
  8584. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8585. node.id = this.parseIdentifier();
  8586. if (!nested) {
  8587. this.checkIdentifier(node.id, 1024);
  8588. }
  8589. if (this.eat(16)) {
  8590. const inner = this.startNode();
  8591. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8592. node.body = inner;
  8593. } else {
  8594. this.scope.enter(256);
  8595. this.prodParam.enter(0);
  8596. node.body = this.tsParseModuleBlock();
  8597. this.prodParam.exit();
  8598. this.scope.exit();
  8599. }
  8600. return this.finishNode(node, "TSModuleDeclaration");
  8601. }
  8602. tsParseAmbientExternalModuleDeclaration(node) {
  8603. if (this.isContextual(112)) {
  8604. node.global = true;
  8605. node.id = this.parseIdentifier();
  8606. } else if (this.match(133)) {
  8607. node.id = super.parseStringLiteral(this.state.value);
  8608. } else {
  8609. this.unexpected();
  8610. }
  8611. if (this.match(5)) {
  8612. this.scope.enter(256);
  8613. this.prodParam.enter(0);
  8614. node.body = this.tsParseModuleBlock();
  8615. this.prodParam.exit();
  8616. this.scope.exit();
  8617. } else {
  8618. this.semicolon();
  8619. }
  8620. return this.finishNode(node, "TSModuleDeclaration");
  8621. }
  8622. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8623. node.isExport = isExport || false;
  8624. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8625. this.checkIdentifier(node.id, 4096);
  8626. this.expect(29);
  8627. const moduleReference = this.tsParseModuleReference();
  8628. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8629. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8630. }
  8631. node.moduleReference = moduleReference;
  8632. this.semicolon();
  8633. return this.finishNode(node, "TSImportEqualsDeclaration");
  8634. }
  8635. tsIsExternalModuleReference() {
  8636. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8637. }
  8638. tsParseModuleReference() {
  8639. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  8640. }
  8641. tsParseExternalModuleReference() {
  8642. const node = this.startNode();
  8643. this.expectContextual(119);
  8644. this.expect(10);
  8645. if (!this.match(133)) {
  8646. this.unexpected();
  8647. }
  8648. node.expression = super.parseExprAtom();
  8649. this.expect(11);
  8650. this.sawUnambiguousESM = true;
  8651. return this.finishNode(node, "TSExternalModuleReference");
  8652. }
  8653. tsLookAhead(f) {
  8654. const state = this.state.clone();
  8655. const res = f();
  8656. this.state = state;
  8657. return res;
  8658. }
  8659. tsTryParseAndCatch(f) {
  8660. const result = this.tryParse(abort => f() || abort());
  8661. if (result.aborted || !result.node) return;
  8662. if (result.error) this.state = result.failState;
  8663. return result.node;
  8664. }
  8665. tsTryParse(f) {
  8666. const state = this.state.clone();
  8667. const result = f();
  8668. if (result !== undefined && result !== false) {
  8669. return result;
  8670. }
  8671. this.state = state;
  8672. }
  8673. tsTryParseDeclare(nany) {
  8674. if (this.isLineTerminator()) {
  8675. return;
  8676. }
  8677. let startType = this.state.type;
  8678. let kind;
  8679. if (this.isContextual(100)) {
  8680. startType = 74;
  8681. kind = "let";
  8682. }
  8683. return this.tsInAmbientContext(() => {
  8684. switch (startType) {
  8685. case 68:
  8686. nany.declare = true;
  8687. return super.parseFunctionStatement(nany, false, false);
  8688. case 80:
  8689. nany.declare = true;
  8690. return this.parseClass(nany, true, false);
  8691. case 126:
  8692. return this.tsParseEnumDeclaration(nany, {
  8693. declare: true
  8694. });
  8695. case 112:
  8696. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8697. case 75:
  8698. case 74:
  8699. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8700. nany.declare = true;
  8701. return this.parseVarStatement(nany, kind || this.state.value, true);
  8702. }
  8703. this.expect(75);
  8704. return this.tsParseEnumDeclaration(nany, {
  8705. const: true,
  8706. declare: true
  8707. });
  8708. case 129:
  8709. {
  8710. const result = this.tsParseInterfaceDeclaration(nany, {
  8711. declare: true
  8712. });
  8713. if (result) return result;
  8714. }
  8715. default:
  8716. if (tokenIsIdentifier(startType)) {
  8717. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8718. }
  8719. }
  8720. });
  8721. }
  8722. tsTryParseExportDeclaration() {
  8723. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  8724. }
  8725. tsParseExpressionStatement(node, expr, decorators) {
  8726. switch (expr.name) {
  8727. case "declare":
  8728. {
  8729. const declaration = this.tsTryParseDeclare(node);
  8730. if (declaration) {
  8731. declaration.declare = true;
  8732. }
  8733. return declaration;
  8734. }
  8735. case "global":
  8736. if (this.match(5)) {
  8737. this.scope.enter(256);
  8738. this.prodParam.enter(0);
  8739. const mod = node;
  8740. mod.global = true;
  8741. mod.id = expr;
  8742. mod.body = this.tsParseModuleBlock();
  8743. this.scope.exit();
  8744. this.prodParam.exit();
  8745. return this.finishNode(mod, "TSModuleDeclaration");
  8746. }
  8747. break;
  8748. default:
  8749. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8750. }
  8751. }
  8752. tsParseDeclaration(node, value, next, decorators) {
  8753. switch (value) {
  8754. case "abstract":
  8755. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8756. return this.tsParseAbstractDeclaration(node, decorators);
  8757. }
  8758. break;
  8759. case "module":
  8760. if (this.tsCheckLineTerminator(next)) {
  8761. if (this.match(133)) {
  8762. return this.tsParseAmbientExternalModuleDeclaration(node);
  8763. } else if (tokenIsIdentifier(this.state.type)) {
  8764. return this.tsParseModuleOrNamespaceDeclaration(node);
  8765. }
  8766. }
  8767. break;
  8768. case "namespace":
  8769. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8770. return this.tsParseModuleOrNamespaceDeclaration(node);
  8771. }
  8772. break;
  8773. case "type":
  8774. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8775. return this.tsParseTypeAliasDeclaration(node);
  8776. }
  8777. break;
  8778. }
  8779. }
  8780. tsCheckLineTerminator(next) {
  8781. if (next) {
  8782. if (this.hasFollowingLineBreak()) return false;
  8783. this.next();
  8784. return true;
  8785. }
  8786. return !this.isLineTerminator();
  8787. }
  8788. tsTryParseGenericAsyncArrowFunction(startLoc) {
  8789. if (!this.match(47)) return;
  8790. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8791. this.state.maybeInArrowParameters = true;
  8792. const res = this.tsTryParseAndCatch(() => {
  8793. const node = this.startNodeAt(startLoc);
  8794. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  8795. super.parseFunctionParams(node);
  8796. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  8797. this.expect(19);
  8798. return node;
  8799. });
  8800. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  8801. if (!res) return;
  8802. return super.parseArrowExpression(res, null, true);
  8803. }
  8804. tsParseTypeArgumentsInExpression() {
  8805. if (this.reScan_lt() !== 47) return;
  8806. return this.tsParseTypeArguments();
  8807. }
  8808. tsParseTypeArguments() {
  8809. const node = this.startNode();
  8810. node.params = this.tsInType(() => this.tsInNoContext(() => {
  8811. this.expect(47);
  8812. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  8813. }));
  8814. if (node.params.length === 0) {
  8815. this.raise(TSErrors.EmptyTypeArguments, node);
  8816. } else if (!this.state.inType && this.curContext() === types.brace) {
  8817. this.reScan_lt_gt();
  8818. }
  8819. this.expect(48);
  8820. return this.finishNode(node, "TSTypeParameterInstantiation");
  8821. }
  8822. tsIsDeclarationStart() {
  8823. return tokenIsTSDeclarationStart(this.state.type);
  8824. }
  8825. isExportDefaultSpecifier() {
  8826. if (this.tsIsDeclarationStart()) return false;
  8827. return super.isExportDefaultSpecifier();
  8828. }
  8829. parseAssignableListItem(flags, decorators) {
  8830. const startLoc = this.state.startLoc;
  8831. const modified = {};
  8832. this.tsParseModifiers({
  8833. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  8834. }, modified);
  8835. const accessibility = modified.accessibility;
  8836. const override = modified.override;
  8837. const readonly = modified.readonly;
  8838. if (!(flags & 4) && (accessibility || readonly || override)) {
  8839. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  8840. }
  8841. const left = this.parseMaybeDefault();
  8842. this.parseAssignableListItemTypes(left, flags);
  8843. const elt = this.parseMaybeDefault(left.loc.start, left);
  8844. if (accessibility || readonly || override) {
  8845. const pp = this.startNodeAt(startLoc);
  8846. if (decorators.length) {
  8847. pp.decorators = decorators;
  8848. }
  8849. if (accessibility) pp.accessibility = accessibility;
  8850. if (readonly) pp.readonly = readonly;
  8851. if (override) pp.override = override;
  8852. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  8853. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  8854. }
  8855. pp.parameter = elt;
  8856. return this.finishNode(pp, "TSParameterProperty");
  8857. }
  8858. if (decorators.length) {
  8859. left.decorators = decorators;
  8860. }
  8861. return elt;
  8862. }
  8863. isSimpleParameter(node) {
  8864. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  8865. }
  8866. tsDisallowOptionalPattern(node) {
  8867. for (const param of node.params) {
  8868. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  8869. this.raise(TSErrors.PatternIsOptional, param);
  8870. }
  8871. }
  8872. }
  8873. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  8874. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  8875. this.tsDisallowOptionalPattern(node);
  8876. }
  8877. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  8878. if (this.match(14)) {
  8879. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  8880. }
  8881. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  8882. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  8883. return this.finishNode(node, bodilessType);
  8884. }
  8885. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  8886. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  8887. if (node.declare) {
  8888. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  8889. }
  8890. }
  8891. this.tsDisallowOptionalPattern(node);
  8892. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  8893. }
  8894. registerFunctionStatementId(node) {
  8895. if (!node.body && node.id) {
  8896. this.checkIdentifier(node.id, 1024);
  8897. } else {
  8898. super.registerFunctionStatementId(node);
  8899. }
  8900. }
  8901. tsCheckForInvalidTypeCasts(items) {
  8902. items.forEach(node => {
  8903. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  8904. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  8905. }
  8906. });
  8907. }
  8908. toReferencedList(exprList, isInParens) {
  8909. this.tsCheckForInvalidTypeCasts(exprList);
  8910. return exprList;
  8911. }
  8912. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  8913. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  8914. if (node.type === "ArrayExpression") {
  8915. this.tsCheckForInvalidTypeCasts(node.elements);
  8916. }
  8917. return node;
  8918. }
  8919. parseSubscript(base, startLoc, noCalls, state) {
  8920. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  8921. this.state.canStartJSXElement = false;
  8922. this.next();
  8923. const nonNullExpression = this.startNodeAt(startLoc);
  8924. nonNullExpression.expression = base;
  8925. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  8926. }
  8927. let isOptionalCall = false;
  8928. if (this.match(18) && this.lookaheadCharCode() === 60) {
  8929. if (noCalls) {
  8930. state.stop = true;
  8931. return base;
  8932. }
  8933. state.optionalChainMember = isOptionalCall = true;
  8934. this.next();
  8935. }
  8936. if (this.match(47) || this.match(51)) {
  8937. let missingParenErrorLoc;
  8938. const result = this.tsTryParseAndCatch(() => {
  8939. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  8940. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  8941. if (asyncArrowFn) {
  8942. return asyncArrowFn;
  8943. }
  8944. }
  8945. const typeArguments = this.tsParseTypeArgumentsInExpression();
  8946. if (!typeArguments) return;
  8947. if (isOptionalCall && !this.match(10)) {
  8948. missingParenErrorLoc = this.state.curPosition();
  8949. return;
  8950. }
  8951. if (tokenIsTemplate(this.state.type)) {
  8952. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  8953. result.typeParameters = typeArguments;
  8954. return result;
  8955. }
  8956. if (!noCalls && this.eat(10)) {
  8957. const node = this.startNodeAt(startLoc);
  8958. node.callee = base;
  8959. node.arguments = this.parseCallExpressionArguments(11, false);
  8960. this.tsCheckForInvalidTypeCasts(node.arguments);
  8961. node.typeParameters = typeArguments;
  8962. if (state.optionalChainMember) {
  8963. node.optional = isOptionalCall;
  8964. }
  8965. return this.finishCallExpression(node, state.optionalChainMember);
  8966. }
  8967. const tokenType = this.state.type;
  8968. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  8969. return;
  8970. }
  8971. const node = this.startNodeAt(startLoc);
  8972. node.expression = base;
  8973. node.typeParameters = typeArguments;
  8974. return this.finishNode(node, "TSInstantiationExpression");
  8975. });
  8976. if (missingParenErrorLoc) {
  8977. this.unexpected(missingParenErrorLoc, 10);
  8978. }
  8979. if (result) {
  8980. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  8981. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  8982. }
  8983. return result;
  8984. }
  8985. }
  8986. return super.parseSubscript(base, startLoc, noCalls, state);
  8987. }
  8988. parseNewCallee(node) {
  8989. var _callee$extra;
  8990. super.parseNewCallee(node);
  8991. const {
  8992. callee
  8993. } = node;
  8994. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  8995. node.typeParameters = callee.typeParameters;
  8996. node.callee = callee.expression;
  8997. }
  8998. }
  8999. parseExprOp(left, leftStartLoc, minPrec) {
  9000. let isSatisfies;
  9001. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9002. const node = this.startNodeAt(leftStartLoc);
  9003. node.expression = left;
  9004. node.typeAnnotation = this.tsInType(() => {
  9005. this.next();
  9006. if (this.match(75)) {
  9007. if (isSatisfies) {
  9008. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9009. keyword: "const"
  9010. });
  9011. }
  9012. return this.tsParseTypeReference();
  9013. }
  9014. return this.tsParseType();
  9015. });
  9016. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9017. this.reScan_lt_gt();
  9018. return this.parseExprOp(node, leftStartLoc, minPrec);
  9019. }
  9020. return super.parseExprOp(left, leftStartLoc, minPrec);
  9021. }
  9022. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9023. if (!this.state.isAmbientContext) {
  9024. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9025. }
  9026. }
  9027. checkImportReflection(node) {
  9028. super.checkImportReflection(node);
  9029. if (node.module && node.importKind !== "value") {
  9030. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9031. }
  9032. }
  9033. checkDuplicateExports() {}
  9034. isPotentialImportPhase(isExport) {
  9035. if (super.isPotentialImportPhase(isExport)) return true;
  9036. if (this.isContextual(130)) {
  9037. const ch = this.lookaheadCharCode();
  9038. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9039. }
  9040. return !isExport && this.isContextual(87);
  9041. }
  9042. applyImportPhase(node, isExport, phase, loc) {
  9043. super.applyImportPhase(node, isExport, phase, loc);
  9044. if (isExport) {
  9045. node.exportKind = phase === "type" ? "type" : "value";
  9046. } else {
  9047. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9048. }
  9049. }
  9050. parseImport(node) {
  9051. if (this.match(133)) {
  9052. node.importKind = "value";
  9053. return super.parseImport(node);
  9054. }
  9055. let importNode;
  9056. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9057. node.importKind = "value";
  9058. return this.tsParseImportEqualsDeclaration(node);
  9059. } else if (this.isContextual(130)) {
  9060. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9061. if (this.lookaheadCharCode() === 61) {
  9062. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9063. } else {
  9064. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9065. }
  9066. } else {
  9067. importNode = super.parseImport(node);
  9068. }
  9069. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9070. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9071. }
  9072. return importNode;
  9073. }
  9074. parseExport(node, decorators) {
  9075. if (this.match(83)) {
  9076. this.next();
  9077. const nodeImportEquals = node;
  9078. let maybeDefaultIdentifier = null;
  9079. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9080. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9081. } else {
  9082. nodeImportEquals.importKind = "value";
  9083. }
  9084. return this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9085. } else if (this.eat(29)) {
  9086. const assign = node;
  9087. assign.expression = super.parseExpression();
  9088. this.semicolon();
  9089. this.sawUnambiguousESM = true;
  9090. return this.finishNode(assign, "TSExportAssignment");
  9091. } else if (this.eatContextual(93)) {
  9092. const decl = node;
  9093. this.expectContextual(128);
  9094. decl.id = this.parseIdentifier();
  9095. this.semicolon();
  9096. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9097. } else {
  9098. return super.parseExport(node, decorators);
  9099. }
  9100. }
  9101. isAbstractClass() {
  9102. return this.isContextual(124) && this.lookahead().type === 80;
  9103. }
  9104. parseExportDefaultExpression() {
  9105. if (this.isAbstractClass()) {
  9106. const cls = this.startNode();
  9107. this.next();
  9108. cls.abstract = true;
  9109. return this.parseClass(cls, true, true);
  9110. }
  9111. if (this.match(129)) {
  9112. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9113. if (result) return result;
  9114. }
  9115. return super.parseExportDefaultExpression();
  9116. }
  9117. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9118. const {
  9119. isAmbientContext
  9120. } = this.state;
  9121. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9122. if (!isAmbientContext) return declaration;
  9123. for (const {
  9124. id,
  9125. init
  9126. } of declaration.declarations) {
  9127. if (!init) continue;
  9128. if (kind !== "const" || !!id.typeAnnotation) {
  9129. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9130. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9131. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9132. }
  9133. }
  9134. return declaration;
  9135. }
  9136. parseStatementContent(flags, decorators) {
  9137. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9138. const node = this.startNode();
  9139. this.expect(75);
  9140. return this.tsParseEnumDeclaration(node, {
  9141. const: true
  9142. });
  9143. }
  9144. if (this.isContextual(126)) {
  9145. return this.tsParseEnumDeclaration(this.startNode());
  9146. }
  9147. if (this.isContextual(129)) {
  9148. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9149. if (result) return result;
  9150. }
  9151. return super.parseStatementContent(flags, decorators);
  9152. }
  9153. parseAccessModifier() {
  9154. return this.tsParseModifier(["public", "protected", "private"]);
  9155. }
  9156. tsHasSomeModifiers(member, modifiers) {
  9157. return modifiers.some(modifier => {
  9158. if (tsIsAccessModifier(modifier)) {
  9159. return member.accessibility === modifier;
  9160. }
  9161. return !!member[modifier];
  9162. });
  9163. }
  9164. tsIsStartOfStaticBlocks() {
  9165. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9166. }
  9167. parseClassMember(classBody, member, state) {
  9168. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9169. this.tsParseModifiers({
  9170. allowedModifiers: modifiers,
  9171. disallowedModifiers: ["in", "out"],
  9172. stopOnStartOfClassStaticBlock: true,
  9173. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9174. }, member);
  9175. const callParseClassMemberWithIsStatic = () => {
  9176. if (this.tsIsStartOfStaticBlocks()) {
  9177. this.next();
  9178. this.next();
  9179. if (this.tsHasSomeModifiers(member, modifiers)) {
  9180. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9181. }
  9182. super.parseClassStaticBlock(classBody, member);
  9183. } else {
  9184. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9185. }
  9186. };
  9187. if (member.declare) {
  9188. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9189. } else {
  9190. callParseClassMemberWithIsStatic();
  9191. }
  9192. }
  9193. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9194. const idx = this.tsTryParseIndexSignature(member);
  9195. if (idx) {
  9196. classBody.body.push(idx);
  9197. if (member.abstract) {
  9198. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9199. }
  9200. if (member.accessibility) {
  9201. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9202. modifier: member.accessibility
  9203. });
  9204. }
  9205. if (member.declare) {
  9206. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9207. }
  9208. if (member.override) {
  9209. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9210. }
  9211. return;
  9212. }
  9213. if (!this.state.inAbstractClass && member.abstract) {
  9214. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9215. }
  9216. if (member.override) {
  9217. if (!state.hadSuperClass) {
  9218. this.raise(TSErrors.OverrideNotInSubClass, member);
  9219. }
  9220. }
  9221. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9222. }
  9223. parsePostMemberNameModifiers(methodOrProp) {
  9224. const optional = this.eat(17);
  9225. if (optional) methodOrProp.optional = true;
  9226. if (methodOrProp.readonly && this.match(10)) {
  9227. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9228. }
  9229. if (methodOrProp.declare && this.match(10)) {
  9230. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9231. }
  9232. }
  9233. parseExpressionStatement(node, expr, decorators) {
  9234. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9235. return decl || super.parseExpressionStatement(node, expr, decorators);
  9236. }
  9237. shouldParseExportDeclaration() {
  9238. if (this.tsIsDeclarationStart()) return true;
  9239. return super.shouldParseExportDeclaration();
  9240. }
  9241. parseConditional(expr, startLoc, refExpressionErrors) {
  9242. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9243. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9244. }
  9245. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9246. if (!result.node) {
  9247. if (result.error) {
  9248. super.setOptionalParametersError(refExpressionErrors, result.error);
  9249. }
  9250. return expr;
  9251. }
  9252. if (result.error) this.state = result.failState;
  9253. return result.node;
  9254. }
  9255. parseParenItem(node, startLoc) {
  9256. const newNode = super.parseParenItem(node, startLoc);
  9257. if (this.eat(17)) {
  9258. newNode.optional = true;
  9259. this.resetEndLocation(node);
  9260. }
  9261. if (this.match(14)) {
  9262. const typeCastNode = this.startNodeAt(startLoc);
  9263. typeCastNode.expression = node;
  9264. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9265. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9266. }
  9267. return node;
  9268. }
  9269. parseExportDeclaration(node) {
  9270. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9271. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9272. }
  9273. const startLoc = this.state.startLoc;
  9274. const isDeclare = this.eatContextual(125);
  9275. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9276. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9277. }
  9278. const isIdentifier = tokenIsIdentifier(this.state.type);
  9279. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9280. if (!declaration) return null;
  9281. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9282. node.exportKind = "type";
  9283. }
  9284. if (isDeclare) {
  9285. this.resetStartLocation(declaration, startLoc);
  9286. declaration.declare = true;
  9287. }
  9288. return declaration;
  9289. }
  9290. parseClassId(node, isStatement, optionalId, bindingType) {
  9291. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9292. return;
  9293. }
  9294. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9295. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9296. if (typeParameters) node.typeParameters = typeParameters;
  9297. }
  9298. parseClassPropertyAnnotation(node) {
  9299. if (!node.optional) {
  9300. if (this.eat(35)) {
  9301. node.definite = true;
  9302. } else if (this.eat(17)) {
  9303. node.optional = true;
  9304. }
  9305. }
  9306. const type = this.tsTryParseTypeAnnotation();
  9307. if (type) node.typeAnnotation = type;
  9308. }
  9309. parseClassProperty(node) {
  9310. this.parseClassPropertyAnnotation(node);
  9311. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9312. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9313. }
  9314. if (node.abstract && this.match(29)) {
  9315. const {
  9316. key
  9317. } = node;
  9318. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9319. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9320. });
  9321. }
  9322. return super.parseClassProperty(node);
  9323. }
  9324. parseClassPrivateProperty(node) {
  9325. if (node.abstract) {
  9326. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9327. }
  9328. if (node.accessibility) {
  9329. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9330. modifier: node.accessibility
  9331. });
  9332. }
  9333. this.parseClassPropertyAnnotation(node);
  9334. return super.parseClassPrivateProperty(node);
  9335. }
  9336. parseClassAccessorProperty(node) {
  9337. this.parseClassPropertyAnnotation(node);
  9338. if (node.optional) {
  9339. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9340. }
  9341. return super.parseClassAccessorProperty(node);
  9342. }
  9343. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9344. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9345. if (typeParameters && isConstructor) {
  9346. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9347. }
  9348. const {
  9349. declare = false,
  9350. kind
  9351. } = method;
  9352. if (declare && (kind === "get" || kind === "set")) {
  9353. this.raise(TSErrors.DeclareAccessor, method, {
  9354. kind
  9355. });
  9356. }
  9357. if (typeParameters) method.typeParameters = typeParameters;
  9358. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9359. }
  9360. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9361. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9362. if (typeParameters) method.typeParameters = typeParameters;
  9363. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9364. }
  9365. declareClassPrivateMethodInScope(node, kind) {
  9366. if (node.type === "TSDeclareMethod") return;
  9367. if (node.type === "MethodDefinition" && !hasOwnProperty.call(node.value, "body")) {
  9368. return;
  9369. }
  9370. super.declareClassPrivateMethodInScope(node, kind);
  9371. }
  9372. parseClassSuper(node) {
  9373. super.parseClassSuper(node);
  9374. if (node.superClass && (this.match(47) || this.match(51))) {
  9375. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9376. }
  9377. if (this.eatContextual(113)) {
  9378. node.implements = this.tsParseHeritageClause("implements");
  9379. }
  9380. }
  9381. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9382. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9383. if (typeParameters) prop.typeParameters = typeParameters;
  9384. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9385. }
  9386. parseFunctionParams(node, isConstructor) {
  9387. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9388. if (typeParameters) node.typeParameters = typeParameters;
  9389. super.parseFunctionParams(node, isConstructor);
  9390. }
  9391. parseVarId(decl, kind) {
  9392. super.parseVarId(decl, kind);
  9393. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9394. decl.definite = true;
  9395. }
  9396. const type = this.tsTryParseTypeAnnotation();
  9397. if (type) {
  9398. decl.id.typeAnnotation = type;
  9399. this.resetEndLocation(decl.id);
  9400. }
  9401. }
  9402. parseAsyncArrowFromCallExpression(node, call) {
  9403. if (this.match(14)) {
  9404. node.returnType = this.tsParseTypeAnnotation();
  9405. }
  9406. return super.parseAsyncArrowFromCallExpression(node, call);
  9407. }
  9408. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9409. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9410. let state;
  9411. let jsx;
  9412. let typeCast;
  9413. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  9414. state = this.state.clone();
  9415. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9416. if (!jsx.error) return jsx.node;
  9417. const {
  9418. context
  9419. } = this.state;
  9420. const currentContext = context[context.length - 1];
  9421. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9422. context.pop();
  9423. }
  9424. }
  9425. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9426. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9427. }
  9428. if (!state || state === this.state) state = this.state.clone();
  9429. let typeParameters;
  9430. const arrow = this.tryParse(abort => {
  9431. var _expr$extra, _typeParameters;
  9432. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9433. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9434. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9435. abort();
  9436. }
  9437. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9438. this.resetStartLocationFromNode(expr, typeParameters);
  9439. }
  9440. expr.typeParameters = typeParameters;
  9441. return expr;
  9442. }, state);
  9443. if (!arrow.error && !arrow.aborted) {
  9444. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9445. return arrow.node;
  9446. }
  9447. if (!jsx) {
  9448. assert(!this.hasPlugin("jsx"));
  9449. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9450. if (!typeCast.error) return typeCast.node;
  9451. }
  9452. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9453. this.state = jsx.failState;
  9454. return jsx.node;
  9455. }
  9456. if (arrow.node) {
  9457. this.state = arrow.failState;
  9458. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9459. return arrow.node;
  9460. }
  9461. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9462. this.state = typeCast.failState;
  9463. return typeCast.node;
  9464. }
  9465. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9466. }
  9467. reportReservedArrowTypeParam(node) {
  9468. var _node$extra;
  9469. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9470. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9471. }
  9472. }
  9473. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9474. if (!this.hasPlugin("jsx") && this.match(47)) {
  9475. return this.tsParseTypeAssertion();
  9476. }
  9477. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9478. }
  9479. parseArrow(node) {
  9480. if (this.match(14)) {
  9481. const result = this.tryParse(abort => {
  9482. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9483. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9484. return returnType;
  9485. });
  9486. if (result.aborted) return;
  9487. if (!result.thrown) {
  9488. if (result.error) this.state = result.failState;
  9489. node.returnType = result.node;
  9490. }
  9491. }
  9492. return super.parseArrow(node);
  9493. }
  9494. parseAssignableListItemTypes(param, flags) {
  9495. if (!(flags & 2)) return param;
  9496. if (this.eat(17)) {
  9497. param.optional = true;
  9498. }
  9499. const type = this.tsTryParseTypeAnnotation();
  9500. if (type) param.typeAnnotation = type;
  9501. this.resetEndLocation(param);
  9502. return param;
  9503. }
  9504. isAssignable(node, isBinding) {
  9505. switch (node.type) {
  9506. case "TSTypeCastExpression":
  9507. return this.isAssignable(node.expression, isBinding);
  9508. case "TSParameterProperty":
  9509. return true;
  9510. default:
  9511. return super.isAssignable(node, isBinding);
  9512. }
  9513. }
  9514. toAssignable(node, isLHS = false) {
  9515. switch (node.type) {
  9516. case "ParenthesizedExpression":
  9517. this.toAssignableParenthesizedExpression(node, isLHS);
  9518. break;
  9519. case "TSAsExpression":
  9520. case "TSSatisfiesExpression":
  9521. case "TSNonNullExpression":
  9522. case "TSTypeAssertion":
  9523. if (isLHS) {
  9524. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9525. } else {
  9526. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9527. }
  9528. this.toAssignable(node.expression, isLHS);
  9529. break;
  9530. case "AssignmentExpression":
  9531. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9532. node.left = this.typeCastToParameter(node.left);
  9533. }
  9534. default:
  9535. super.toAssignable(node, isLHS);
  9536. }
  9537. }
  9538. toAssignableParenthesizedExpression(node, isLHS) {
  9539. switch (node.expression.type) {
  9540. case "TSAsExpression":
  9541. case "TSSatisfiesExpression":
  9542. case "TSNonNullExpression":
  9543. case "TSTypeAssertion":
  9544. case "ParenthesizedExpression":
  9545. this.toAssignable(node.expression, isLHS);
  9546. break;
  9547. default:
  9548. super.toAssignable(node, isLHS);
  9549. }
  9550. }
  9551. checkToRestConversion(node, allowPattern) {
  9552. switch (node.type) {
  9553. case "TSAsExpression":
  9554. case "TSSatisfiesExpression":
  9555. case "TSTypeAssertion":
  9556. case "TSNonNullExpression":
  9557. this.checkToRestConversion(node.expression, false);
  9558. break;
  9559. default:
  9560. super.checkToRestConversion(node, allowPattern);
  9561. }
  9562. }
  9563. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9564. return getOwn({
  9565. TSTypeCastExpression: true,
  9566. TSParameterProperty: "parameter",
  9567. TSNonNullExpression: "expression",
  9568. TSAsExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  9569. TSSatisfiesExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  9570. TSTypeAssertion: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true]
  9571. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9572. }
  9573. parseBindingAtom() {
  9574. if (this.state.type === 78) {
  9575. return this.parseIdentifier(true);
  9576. }
  9577. return super.parseBindingAtom();
  9578. }
  9579. parseMaybeDecoratorArguments(expr) {
  9580. if (this.match(47) || this.match(51)) {
  9581. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9582. if (this.match(10)) {
  9583. const call = super.parseMaybeDecoratorArguments(expr);
  9584. call.typeParameters = typeArguments;
  9585. return call;
  9586. }
  9587. this.unexpected(null, 10);
  9588. }
  9589. return super.parseMaybeDecoratorArguments(expr);
  9590. }
  9591. checkCommaAfterRest(close) {
  9592. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9593. this.next();
  9594. return false;
  9595. }
  9596. return super.checkCommaAfterRest(close);
  9597. }
  9598. isClassMethod() {
  9599. return this.match(47) || super.isClassMethod();
  9600. }
  9601. isClassProperty() {
  9602. return this.match(35) || this.match(14) || super.isClassProperty();
  9603. }
  9604. parseMaybeDefault(startLoc, left) {
  9605. const node = super.parseMaybeDefault(startLoc, left);
  9606. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9607. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  9608. }
  9609. return node;
  9610. }
  9611. getTokenFromCode(code) {
  9612. if (this.state.inType) {
  9613. if (code === 62) {
  9614. this.finishOp(48, 1);
  9615. return;
  9616. }
  9617. if (code === 60) {
  9618. this.finishOp(47, 1);
  9619. return;
  9620. }
  9621. }
  9622. super.getTokenFromCode(code);
  9623. }
  9624. reScan_lt_gt() {
  9625. const {
  9626. type
  9627. } = this.state;
  9628. if (type === 47) {
  9629. this.state.pos -= 1;
  9630. this.readToken_lt();
  9631. } else if (type === 48) {
  9632. this.state.pos -= 1;
  9633. this.readToken_gt();
  9634. }
  9635. }
  9636. reScan_lt() {
  9637. const {
  9638. type
  9639. } = this.state;
  9640. if (type === 51) {
  9641. this.state.pos -= 2;
  9642. this.finishOp(47, 1);
  9643. return 47;
  9644. }
  9645. return type;
  9646. }
  9647. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9648. for (let i = 0; i < exprList.length; i++) {
  9649. const expr = exprList[i];
  9650. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9651. exprList[i] = this.typeCastToParameter(expr);
  9652. }
  9653. }
  9654. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9655. }
  9656. typeCastToParameter(node) {
  9657. node.expression.typeAnnotation = node.typeAnnotation;
  9658. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9659. return node.expression;
  9660. }
  9661. shouldParseArrow(params) {
  9662. if (this.match(14)) {
  9663. return params.every(expr => this.isAssignable(expr, true));
  9664. }
  9665. return super.shouldParseArrow(params);
  9666. }
  9667. shouldParseAsyncArrow() {
  9668. return this.match(14) || super.shouldParseAsyncArrow();
  9669. }
  9670. canHaveLeadingDecorator() {
  9671. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9672. }
  9673. jsxParseOpeningElementAfterName(node) {
  9674. if (this.match(47) || this.match(51)) {
  9675. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9676. if (typeArguments) node.typeParameters = typeArguments;
  9677. }
  9678. return super.jsxParseOpeningElementAfterName(node);
  9679. }
  9680. getGetterSetterExpectedParamCount(method) {
  9681. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9682. const params = this.getObjectOrClassMethodParams(method);
  9683. const firstParam = params[0];
  9684. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9685. return hasContextParam ? baseCount + 1 : baseCount;
  9686. }
  9687. parseCatchClauseParam() {
  9688. const param = super.parseCatchClauseParam();
  9689. const type = this.tsTryParseTypeAnnotation();
  9690. if (type) {
  9691. param.typeAnnotation = type;
  9692. this.resetEndLocation(param);
  9693. }
  9694. return param;
  9695. }
  9696. tsInAmbientContext(cb) {
  9697. const oldIsAmbientContext = this.state.isAmbientContext;
  9698. this.state.isAmbientContext = true;
  9699. try {
  9700. return cb();
  9701. } finally {
  9702. this.state.isAmbientContext = oldIsAmbientContext;
  9703. }
  9704. }
  9705. parseClass(node, isStatement, optionalId) {
  9706. const oldInAbstractClass = this.state.inAbstractClass;
  9707. this.state.inAbstractClass = !!node.abstract;
  9708. try {
  9709. return super.parseClass(node, isStatement, optionalId);
  9710. } finally {
  9711. this.state.inAbstractClass = oldInAbstractClass;
  9712. }
  9713. }
  9714. tsParseAbstractDeclaration(node, decorators) {
  9715. if (this.match(80)) {
  9716. node.abstract = true;
  9717. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  9718. } else if (this.isContextual(129)) {
  9719. if (!this.hasFollowingLineBreak()) {
  9720. node.abstract = true;
  9721. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, node);
  9722. return this.tsParseInterfaceDeclaration(node);
  9723. }
  9724. } else {
  9725. this.unexpected(null, 80);
  9726. }
  9727. }
  9728. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  9729. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  9730. if (method.abstract) {
  9731. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  9732. if (hasBody) {
  9733. const {
  9734. key
  9735. } = method;
  9736. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  9737. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9738. });
  9739. }
  9740. }
  9741. return method;
  9742. }
  9743. tsParseTypeParameterName() {
  9744. const typeName = this.parseIdentifier();
  9745. return typeName.name;
  9746. }
  9747. shouldParseAsAmbientContext() {
  9748. return !!this.getPluginOption("typescript", "dts");
  9749. }
  9750. parse() {
  9751. if (this.shouldParseAsAmbientContext()) {
  9752. this.state.isAmbientContext = true;
  9753. }
  9754. return super.parse();
  9755. }
  9756. getExpression() {
  9757. if (this.shouldParseAsAmbientContext()) {
  9758. this.state.isAmbientContext = true;
  9759. }
  9760. return super.getExpression();
  9761. }
  9762. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  9763. if (!isString && isMaybeTypeOnly) {
  9764. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  9765. return this.finishNode(node, "ExportSpecifier");
  9766. }
  9767. node.exportKind = "value";
  9768. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  9769. }
  9770. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  9771. if (!importedIsString && isMaybeTypeOnly) {
  9772. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  9773. return this.finishNode(specifier, "ImportSpecifier");
  9774. }
  9775. specifier.importKind = "value";
  9776. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  9777. }
  9778. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  9779. const leftOfAsKey = isImport ? "imported" : "local";
  9780. const rightOfAsKey = isImport ? "local" : "exported";
  9781. let leftOfAs = node[leftOfAsKey];
  9782. let rightOfAs;
  9783. let hasTypeSpecifier = false;
  9784. let canParseAsKeyword = true;
  9785. const loc = leftOfAs.loc.start;
  9786. if (this.isContextual(93)) {
  9787. const firstAs = this.parseIdentifier();
  9788. if (this.isContextual(93)) {
  9789. const secondAs = this.parseIdentifier();
  9790. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9791. hasTypeSpecifier = true;
  9792. leftOfAs = firstAs;
  9793. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9794. canParseAsKeyword = false;
  9795. } else {
  9796. rightOfAs = secondAs;
  9797. canParseAsKeyword = false;
  9798. }
  9799. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9800. canParseAsKeyword = false;
  9801. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9802. } else {
  9803. hasTypeSpecifier = true;
  9804. leftOfAs = firstAs;
  9805. }
  9806. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9807. hasTypeSpecifier = true;
  9808. if (isImport) {
  9809. leftOfAs = this.parseIdentifier(true);
  9810. if (!this.isContextual(93)) {
  9811. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  9812. }
  9813. } else {
  9814. leftOfAs = this.parseModuleExportName();
  9815. }
  9816. }
  9817. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  9818. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  9819. }
  9820. node[leftOfAsKey] = leftOfAs;
  9821. node[rightOfAsKey] = rightOfAs;
  9822. const kindKey = isImport ? "importKind" : "exportKind";
  9823. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  9824. if (canParseAsKeyword && this.eatContextual(93)) {
  9825. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9826. }
  9827. if (!node[rightOfAsKey]) {
  9828. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  9829. }
  9830. if (isImport) {
  9831. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  9832. }
  9833. }
  9834. };
  9835. function isPossiblyLiteralEnum(expression) {
  9836. if (expression.type !== "MemberExpression") return false;
  9837. const {
  9838. computed,
  9839. property
  9840. } = expression;
  9841. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  9842. return false;
  9843. }
  9844. return isUncomputedMemberExpressionChain(expression.object);
  9845. }
  9846. function isValidAmbientConstInitializer(expression, estree) {
  9847. var _expression$extra;
  9848. const {
  9849. type
  9850. } = expression;
  9851. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  9852. return false;
  9853. }
  9854. if (estree) {
  9855. if (type === "Literal") {
  9856. const {
  9857. value
  9858. } = expression;
  9859. if (typeof value === "string" || typeof value === "boolean") {
  9860. return true;
  9861. }
  9862. }
  9863. } else {
  9864. if (type === "StringLiteral" || type === "BooleanLiteral") {
  9865. return true;
  9866. }
  9867. }
  9868. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  9869. return true;
  9870. }
  9871. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  9872. return true;
  9873. }
  9874. if (isPossiblyLiteralEnum(expression)) {
  9875. return true;
  9876. }
  9877. return false;
  9878. }
  9879. function isNumber(expression, estree) {
  9880. if (estree) {
  9881. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  9882. }
  9883. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  9884. }
  9885. function isNegativeNumber(expression, estree) {
  9886. if (expression.type === "UnaryExpression") {
  9887. const {
  9888. operator,
  9889. argument
  9890. } = expression;
  9891. if (operator === "-" && isNumber(argument, estree)) {
  9892. return true;
  9893. }
  9894. }
  9895. return false;
  9896. }
  9897. function isUncomputedMemberExpressionChain(expression) {
  9898. if (expression.type === "Identifier") return true;
  9899. if (expression.type !== "MemberExpression" || expression.computed) {
  9900. return false;
  9901. }
  9902. return isUncomputedMemberExpressionChain(expression.object);
  9903. }
  9904. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  9905. ClassNameIsRequired: "A class name is required.",
  9906. UnexpectedSpace: "Unexpected space in placeholder."
  9907. });
  9908. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  9909. parsePlaceholder(expectedNode) {
  9910. if (this.match(144)) {
  9911. const node = this.startNode();
  9912. this.next();
  9913. this.assertNoSpace();
  9914. node.name = super.parseIdentifier(true);
  9915. this.assertNoSpace();
  9916. this.expect(144);
  9917. return this.finishPlaceholder(node, expectedNode);
  9918. }
  9919. }
  9920. finishPlaceholder(node, expectedNode) {
  9921. let placeholder = node;
  9922. if (!placeholder.expectedNode || !placeholder.type) {
  9923. placeholder = this.finishNode(placeholder, "Placeholder");
  9924. }
  9925. placeholder.expectedNode = expectedNode;
  9926. return placeholder;
  9927. }
  9928. getTokenFromCode(code) {
  9929. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  9930. this.finishOp(144, 2);
  9931. } else {
  9932. super.getTokenFromCode(code);
  9933. }
  9934. }
  9935. parseExprAtom(refExpressionErrors) {
  9936. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  9937. }
  9938. parseIdentifier(liberal) {
  9939. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  9940. }
  9941. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9942. if (word !== undefined) {
  9943. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9944. }
  9945. }
  9946. parseBindingAtom() {
  9947. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  9948. }
  9949. isValidLVal(type, isParenthesized, binding) {
  9950. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  9951. }
  9952. toAssignable(node, isLHS) {
  9953. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  9954. node.expectedNode = "Pattern";
  9955. } else {
  9956. super.toAssignable(node, isLHS);
  9957. }
  9958. }
  9959. chStartsBindingIdentifier(ch, pos) {
  9960. if (super.chStartsBindingIdentifier(ch, pos)) {
  9961. return true;
  9962. }
  9963. const nextToken = this.lookahead();
  9964. if (nextToken.type === 144) {
  9965. return true;
  9966. }
  9967. return false;
  9968. }
  9969. verifyBreakContinue(node, isBreak) {
  9970. if (node.label && node.label.type === "Placeholder") return;
  9971. super.verifyBreakContinue(node, isBreak);
  9972. }
  9973. parseExpressionStatement(node, expr) {
  9974. var _expr$extra;
  9975. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9976. return super.parseExpressionStatement(node, expr);
  9977. }
  9978. if (this.match(14)) {
  9979. const stmt = node;
  9980. stmt.label = this.finishPlaceholder(expr, "Identifier");
  9981. this.next();
  9982. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  9983. return this.finishNode(stmt, "LabeledStatement");
  9984. }
  9985. this.semicolon();
  9986. const stmtPlaceholder = node;
  9987. stmtPlaceholder.name = expr.name;
  9988. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  9989. }
  9990. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  9991. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  9992. }
  9993. parseFunctionId(requireId) {
  9994. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  9995. }
  9996. parseClass(node, isStatement, optionalId) {
  9997. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  9998. this.next();
  9999. const oldStrict = this.state.strict;
  10000. const placeholder = this.parsePlaceholder("Identifier");
  10001. if (placeholder) {
  10002. if (this.match(81) || this.match(144) || this.match(5)) {
  10003. node.id = placeholder;
  10004. } else if (optionalId || !isStatement) {
  10005. node.id = null;
  10006. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10007. return this.finishNode(node, type);
  10008. } else {
  10009. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10010. }
  10011. } else {
  10012. this.parseClassId(node, isStatement, optionalId);
  10013. }
  10014. super.parseClassSuper(node);
  10015. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10016. return this.finishNode(node, type);
  10017. }
  10018. parseExport(node, decorators) {
  10019. const placeholder = this.parsePlaceholder("Identifier");
  10020. if (!placeholder) return super.parseExport(node, decorators);
  10021. const node2 = node;
  10022. if (!this.isContextual(98) && !this.match(12)) {
  10023. node2.specifiers = [];
  10024. node2.source = null;
  10025. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10026. return this.finishNode(node2, "ExportNamedDeclaration");
  10027. }
  10028. this.expectPlugin("exportDefaultFrom");
  10029. const specifier = this.startNode();
  10030. specifier.exported = placeholder;
  10031. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10032. return super.parseExport(node2, decorators);
  10033. }
  10034. isExportDefaultSpecifier() {
  10035. if (this.match(65)) {
  10036. const next = this.nextTokenStart();
  10037. if (this.isUnparsedContextual(next, "from")) {
  10038. if (this.input.startsWith(tokenLabelName(144), this.nextTokenStartSince(next + 4))) {
  10039. return true;
  10040. }
  10041. }
  10042. }
  10043. return super.isExportDefaultSpecifier();
  10044. }
  10045. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10046. var _specifiers;
  10047. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10048. return true;
  10049. }
  10050. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10051. }
  10052. checkExport(node) {
  10053. const {
  10054. specifiers
  10055. } = node;
  10056. if (specifiers != null && specifiers.length) {
  10057. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10058. }
  10059. super.checkExport(node);
  10060. node.specifiers = specifiers;
  10061. }
  10062. parseImport(node) {
  10063. const placeholder = this.parsePlaceholder("Identifier");
  10064. if (!placeholder) return super.parseImport(node);
  10065. node.specifiers = [];
  10066. if (!this.isContextual(98) && !this.match(12)) {
  10067. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10068. this.semicolon();
  10069. return this.finishNode(node, "ImportDeclaration");
  10070. }
  10071. const specifier = this.startNodeAtNode(placeholder);
  10072. specifier.local = placeholder;
  10073. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10074. if (this.eat(12)) {
  10075. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10076. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10077. }
  10078. this.expectContextual(98);
  10079. node.source = this.parseImportSource();
  10080. this.semicolon();
  10081. return this.finishNode(node, "ImportDeclaration");
  10082. }
  10083. parseImportSource() {
  10084. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10085. }
  10086. assertNoSpace() {
  10087. if (this.state.start > this.state.lastTokEndLoc.index) {
  10088. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10089. }
  10090. }
  10091. };
  10092. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10093. parseV8Intrinsic() {
  10094. if (this.match(54)) {
  10095. const v8IntrinsicStartLoc = this.state.startLoc;
  10096. const node = this.startNode();
  10097. this.next();
  10098. if (tokenIsIdentifier(this.state.type)) {
  10099. const name = this.parseIdentifierName();
  10100. const identifier = this.createIdentifier(node, name);
  10101. identifier.type = "V8IntrinsicIdentifier";
  10102. if (this.match(10)) {
  10103. return identifier;
  10104. }
  10105. }
  10106. this.unexpected(v8IntrinsicStartLoc);
  10107. }
  10108. }
  10109. parseExprAtom(refExpressionErrors) {
  10110. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10111. }
  10112. };
  10113. function hasPlugin(plugins, expectedConfig) {
  10114. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  10115. const expectedKeys = Object.keys(expectedOptions);
  10116. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  10117. return plugins.some(p => {
  10118. if (typeof p === "string") {
  10119. return expectedOptionsIsEmpty && p === expectedName;
  10120. } else {
  10121. const [pluginName, pluginOptions] = p;
  10122. if (pluginName !== expectedName) {
  10123. return false;
  10124. }
  10125. for (const key of expectedKeys) {
  10126. if (pluginOptions[key] !== expectedOptions[key]) {
  10127. return false;
  10128. }
  10129. }
  10130. return true;
  10131. }
  10132. });
  10133. }
  10134. function getPluginOption(plugins, name, option) {
  10135. const plugin = plugins.find(plugin => {
  10136. if (Array.isArray(plugin)) {
  10137. return plugin[0] === name;
  10138. } else {
  10139. return plugin === name;
  10140. }
  10141. });
  10142. if (plugin && Array.isArray(plugin) && plugin.length > 1) {
  10143. return plugin[1][option];
  10144. }
  10145. return null;
  10146. }
  10147. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10148. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10149. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10150. function validatePlugins(plugins) {
  10151. if (hasPlugin(plugins, "decorators")) {
  10152. if (hasPlugin(plugins, "decorators-legacy")) {
  10153. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10154. }
  10155. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  10156. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10157. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10158. }
  10159. const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
  10160. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10161. throw new Error("'allowCallParenthesized' must be a boolean.");
  10162. }
  10163. }
  10164. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  10165. throw new Error("Cannot combine flow and typescript plugins.");
  10166. }
  10167. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  10168. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10169. }
  10170. if (hasPlugin(plugins, "pipelineOperator")) {
  10171. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  10172. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10173. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10174. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10175. }
  10176. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  10177. syntaxType: "hash"
  10178. }]);
  10179. if (proposal === "hack") {
  10180. if (hasPlugin(plugins, "placeholders")) {
  10181. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10182. }
  10183. if (hasPlugin(plugins, "v8intrinsic")) {
  10184. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10185. }
  10186. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  10187. if (!TOPIC_TOKENS.includes(topicToken)) {
  10188. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10189. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10190. }
  10191. if (topicToken === "#" && tupleSyntaxIsHash) {
  10192. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10193. }
  10194. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  10195. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10196. }
  10197. }
  10198. if (hasPlugin(plugins, "moduleAttributes")) {
  10199. {
  10200. if (hasPlugin(plugins, "importAssertions") || hasPlugin(plugins, "importAttributes")) {
  10201. throw new Error("Cannot combine importAssertions, importAttributes and moduleAttributes plugins.");
  10202. }
  10203. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  10204. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10205. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10206. }
  10207. }
  10208. }
  10209. if (hasPlugin(plugins, "importAssertions") && hasPlugin(plugins, "importAttributes")) {
  10210. throw new Error("Cannot combine importAssertions and importAttributes plugins.");
  10211. }
  10212. if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  10213. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10214. }
  10215. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  10216. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10217. error.missingPlugins = "doExpressions";
  10218. throw error;
  10219. }
  10220. if (hasPlugin(plugins, "optionalChainingAssign") && getPluginOption(plugins, "optionalChainingAssign", "version") !== "2023-07") {
  10221. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10222. }
  10223. }
  10224. const mixinPlugins = {
  10225. estree,
  10226. jsx,
  10227. flow,
  10228. typescript,
  10229. v8intrinsic,
  10230. placeholders
  10231. };
  10232. const mixinPluginNames = Object.keys(mixinPlugins);
  10233. const defaultOptions = {
  10234. sourceType: "script",
  10235. sourceFilename: undefined,
  10236. startColumn: 0,
  10237. startLine: 1,
  10238. allowAwaitOutsideFunction: false,
  10239. allowReturnOutsideFunction: false,
  10240. allowNewTargetOutsideFunction: false,
  10241. allowImportExportEverywhere: false,
  10242. allowSuperOutsideMethod: false,
  10243. allowUndeclaredExports: false,
  10244. plugins: [],
  10245. strictMode: null,
  10246. ranges: false,
  10247. tokens: false,
  10248. createImportExpressions: false,
  10249. createParenthesizedExpressions: false,
  10250. errorRecovery: false,
  10251. attachComment: true,
  10252. annexB: true
  10253. };
  10254. function getOptions(opts) {
  10255. if (opts == null) {
  10256. return Object.assign({}, defaultOptions);
  10257. }
  10258. if (opts.annexB != null && opts.annexB !== false) {
  10259. throw new Error("The `annexB` option can only be set to `false`.");
  10260. }
  10261. const options = {};
  10262. for (const key of Object.keys(defaultOptions)) {
  10263. var _opts$key;
  10264. options[key] = (_opts$key = opts[key]) != null ? _opts$key : defaultOptions[key];
  10265. }
  10266. return options;
  10267. }
  10268. class ExpressionParser extends LValParser {
  10269. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10270. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10271. return;
  10272. }
  10273. const key = prop.key;
  10274. const name = key.type === "Identifier" ? key.name : key.value;
  10275. if (name === "__proto__") {
  10276. if (isRecord) {
  10277. this.raise(Errors.RecordNoProto, key);
  10278. return;
  10279. }
  10280. if (protoRef.used) {
  10281. if (refExpressionErrors) {
  10282. if (refExpressionErrors.doubleProtoLoc === null) {
  10283. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10284. }
  10285. } else {
  10286. this.raise(Errors.DuplicateProto, key);
  10287. }
  10288. }
  10289. protoRef.used = true;
  10290. }
  10291. }
  10292. shouldExitDescending(expr, potentialArrowAt) {
  10293. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  10294. }
  10295. getExpression() {
  10296. this.enterInitialScopes();
  10297. this.nextToken();
  10298. const expr = this.parseExpression();
  10299. if (!this.match(139)) {
  10300. this.unexpected();
  10301. }
  10302. this.finalizeRemainingComments();
  10303. expr.comments = this.comments;
  10304. expr.errors = this.state.errors;
  10305. if (this.options.tokens) {
  10306. expr.tokens = this.tokens;
  10307. }
  10308. return expr;
  10309. }
  10310. parseExpression(disallowIn, refExpressionErrors) {
  10311. if (disallowIn) {
  10312. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10313. }
  10314. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10315. }
  10316. parseExpressionBase(refExpressionErrors) {
  10317. const startLoc = this.state.startLoc;
  10318. const expr = this.parseMaybeAssign(refExpressionErrors);
  10319. if (this.match(12)) {
  10320. const node = this.startNodeAt(startLoc);
  10321. node.expressions = [expr];
  10322. while (this.eat(12)) {
  10323. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10324. }
  10325. this.toReferencedList(node.expressions);
  10326. return this.finishNode(node, "SequenceExpression");
  10327. }
  10328. return expr;
  10329. }
  10330. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10331. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10332. }
  10333. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10334. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10335. }
  10336. setOptionalParametersError(refExpressionErrors, resultError) {
  10337. var _resultError$loc;
  10338. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10339. }
  10340. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10341. const startLoc = this.state.startLoc;
  10342. if (this.isContextual(108)) {
  10343. if (this.prodParam.hasYield) {
  10344. let left = this.parseYield();
  10345. if (afterLeftParse) {
  10346. left = afterLeftParse.call(this, left, startLoc);
  10347. }
  10348. return left;
  10349. }
  10350. }
  10351. let ownExpressionErrors;
  10352. if (refExpressionErrors) {
  10353. ownExpressionErrors = false;
  10354. } else {
  10355. refExpressionErrors = new ExpressionErrors();
  10356. ownExpressionErrors = true;
  10357. }
  10358. const {
  10359. type
  10360. } = this.state;
  10361. if (type === 10 || tokenIsIdentifier(type)) {
  10362. this.state.potentialArrowAt = this.state.start;
  10363. }
  10364. let left = this.parseMaybeConditional(refExpressionErrors);
  10365. if (afterLeftParse) {
  10366. left = afterLeftParse.call(this, left, startLoc);
  10367. }
  10368. if (tokenIsAssignment(this.state.type)) {
  10369. const node = this.startNodeAt(startLoc);
  10370. const operator = this.state.value;
  10371. node.operator = operator;
  10372. if (this.match(29)) {
  10373. this.toAssignable(left, true);
  10374. node.left = left;
  10375. const startIndex = startLoc.index;
  10376. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10377. refExpressionErrors.doubleProtoLoc = null;
  10378. }
  10379. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10380. refExpressionErrors.shorthandAssignLoc = null;
  10381. }
  10382. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10383. this.checkDestructuringPrivate(refExpressionErrors);
  10384. refExpressionErrors.privateKeyLoc = null;
  10385. }
  10386. } else {
  10387. node.left = left;
  10388. }
  10389. this.next();
  10390. node.right = this.parseMaybeAssign();
  10391. this.checkLVal(left, {
  10392. in: this.finishNode(node, "AssignmentExpression")
  10393. });
  10394. return node;
  10395. } else if (ownExpressionErrors) {
  10396. this.checkExpressionErrors(refExpressionErrors, true);
  10397. }
  10398. return left;
  10399. }
  10400. parseMaybeConditional(refExpressionErrors) {
  10401. const startLoc = this.state.startLoc;
  10402. const potentialArrowAt = this.state.potentialArrowAt;
  10403. const expr = this.parseExprOps(refExpressionErrors);
  10404. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10405. return expr;
  10406. }
  10407. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10408. }
  10409. parseConditional(expr, startLoc, refExpressionErrors) {
  10410. if (this.eat(17)) {
  10411. const node = this.startNodeAt(startLoc);
  10412. node.test = expr;
  10413. node.consequent = this.parseMaybeAssignAllowIn();
  10414. this.expect(14);
  10415. node.alternate = this.parseMaybeAssign();
  10416. return this.finishNode(node, "ConditionalExpression");
  10417. }
  10418. return expr;
  10419. }
  10420. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10421. return this.match(138) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10422. }
  10423. parseExprOps(refExpressionErrors) {
  10424. const startLoc = this.state.startLoc;
  10425. const potentialArrowAt = this.state.potentialArrowAt;
  10426. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10427. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10428. return expr;
  10429. }
  10430. return this.parseExprOp(expr, startLoc, -1);
  10431. }
  10432. parseExprOp(left, leftStartLoc, minPrec) {
  10433. if (this.isPrivateName(left)) {
  10434. const value = this.getPrivateNameSV(left);
  10435. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10436. this.raise(Errors.PrivateInExpectedIn, left, {
  10437. identifierName: value
  10438. });
  10439. }
  10440. this.classScope.usePrivateName(value, left.loc.start);
  10441. }
  10442. const op = this.state.type;
  10443. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10444. let prec = tokenOperatorPrecedence(op);
  10445. if (prec > minPrec) {
  10446. if (op === 39) {
  10447. this.expectPlugin("pipelineOperator");
  10448. if (this.state.inFSharpPipelineDirectBody) {
  10449. return left;
  10450. }
  10451. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10452. }
  10453. const node = this.startNodeAt(leftStartLoc);
  10454. node.left = left;
  10455. node.operator = this.state.value;
  10456. const logical = op === 41 || op === 42;
  10457. const coalesce = op === 40;
  10458. if (coalesce) {
  10459. prec = tokenOperatorPrecedence(42);
  10460. }
  10461. this.next();
  10462. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10463. proposal: "minimal"
  10464. }])) {
  10465. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10466. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  10467. }
  10468. }
  10469. node.right = this.parseExprOpRightExpr(op, prec);
  10470. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10471. const nextOp = this.state.type;
  10472. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10473. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  10474. }
  10475. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10476. }
  10477. }
  10478. return left;
  10479. }
  10480. parseExprOpRightExpr(op, prec) {
  10481. const startLoc = this.state.startLoc;
  10482. switch (op) {
  10483. case 39:
  10484. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10485. case "hack":
  10486. return this.withTopicBindingContext(() => {
  10487. return this.parseHackPipeBody();
  10488. });
  10489. case "smart":
  10490. return this.withTopicBindingContext(() => {
  10491. if (this.prodParam.hasYield && this.isContextual(108)) {
  10492. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  10493. }
  10494. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10495. });
  10496. case "fsharp":
  10497. return this.withSoloAwaitPermittingContext(() => {
  10498. return this.parseFSharpPipelineBody(prec);
  10499. });
  10500. }
  10501. default:
  10502. return this.parseExprOpBaseRightExpr(op, prec);
  10503. }
  10504. }
  10505. parseExprOpBaseRightExpr(op, prec) {
  10506. const startLoc = this.state.startLoc;
  10507. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10508. }
  10509. parseHackPipeBody() {
  10510. var _body$extra;
  10511. const {
  10512. startLoc
  10513. } = this.state;
  10514. const body = this.parseMaybeAssign();
  10515. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10516. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10517. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  10518. type: body.type
  10519. });
  10520. }
  10521. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10522. this.raise(Errors.PipeTopicUnused, startLoc);
  10523. }
  10524. return body;
  10525. }
  10526. checkExponentialAfterUnary(node) {
  10527. if (this.match(57)) {
  10528. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  10529. }
  10530. }
  10531. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10532. const startLoc = this.state.startLoc;
  10533. const isAwait = this.isContextual(96);
  10534. if (isAwait && this.isAwaitAllowed()) {
  10535. this.next();
  10536. const expr = this.parseAwait(startLoc);
  10537. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10538. return expr;
  10539. }
  10540. const update = this.match(34);
  10541. const node = this.startNode();
  10542. if (tokenIsPrefix(this.state.type)) {
  10543. node.operator = this.state.value;
  10544. node.prefix = true;
  10545. if (this.match(72)) {
  10546. this.expectPlugin("throwExpressions");
  10547. }
  10548. const isDelete = this.match(89);
  10549. this.next();
  10550. node.argument = this.parseMaybeUnary(null, true);
  10551. this.checkExpressionErrors(refExpressionErrors, true);
  10552. if (this.state.strict && isDelete) {
  10553. const arg = node.argument;
  10554. if (arg.type === "Identifier") {
  10555. this.raise(Errors.StrictDelete, node);
  10556. } else if (this.hasPropertyAsPrivateName(arg)) {
  10557. this.raise(Errors.DeletePrivateField, node);
  10558. }
  10559. }
  10560. if (!update) {
  10561. if (!sawUnary) {
  10562. this.checkExponentialAfterUnary(node);
  10563. }
  10564. return this.finishNode(node, "UnaryExpression");
  10565. }
  10566. }
  10567. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10568. if (isAwait) {
  10569. const {
  10570. type
  10571. } = this.state;
  10572. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10573. if (startsExpr && !this.isAmbiguousAwait()) {
  10574. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  10575. return this.parseAwait(startLoc);
  10576. }
  10577. }
  10578. return expr;
  10579. }
  10580. parseUpdate(node, update, refExpressionErrors) {
  10581. if (update) {
  10582. const updateExpressionNode = node;
  10583. this.checkLVal(updateExpressionNode.argument, {
  10584. in: this.finishNode(updateExpressionNode, "UpdateExpression")
  10585. });
  10586. return node;
  10587. }
  10588. const startLoc = this.state.startLoc;
  10589. let expr = this.parseExprSubscripts(refExpressionErrors);
  10590. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10591. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10592. const node = this.startNodeAt(startLoc);
  10593. node.operator = this.state.value;
  10594. node.prefix = false;
  10595. node.argument = expr;
  10596. this.next();
  10597. this.checkLVal(expr, {
  10598. in: expr = this.finishNode(node, "UpdateExpression")
  10599. });
  10600. }
  10601. return expr;
  10602. }
  10603. parseExprSubscripts(refExpressionErrors) {
  10604. const startLoc = this.state.startLoc;
  10605. const potentialArrowAt = this.state.potentialArrowAt;
  10606. const expr = this.parseExprAtom(refExpressionErrors);
  10607. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10608. return expr;
  10609. }
  10610. return this.parseSubscripts(expr, startLoc);
  10611. }
  10612. parseSubscripts(base, startLoc, noCalls) {
  10613. const state = {
  10614. optionalChainMember: false,
  10615. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10616. stop: false
  10617. };
  10618. do {
  10619. base = this.parseSubscript(base, startLoc, noCalls, state);
  10620. state.maybeAsyncArrow = false;
  10621. } while (!state.stop);
  10622. return base;
  10623. }
  10624. parseSubscript(base, startLoc, noCalls, state) {
  10625. const {
  10626. type
  10627. } = this.state;
  10628. if (!noCalls && type === 15) {
  10629. return this.parseBind(base, startLoc, noCalls, state);
  10630. } else if (tokenIsTemplate(type)) {
  10631. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10632. }
  10633. let optional = false;
  10634. if (type === 18) {
  10635. if (noCalls) {
  10636. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  10637. if (this.lookaheadCharCode() === 40) {
  10638. state.stop = true;
  10639. return base;
  10640. }
  10641. }
  10642. state.optionalChainMember = optional = true;
  10643. this.next();
  10644. }
  10645. if (!noCalls && this.match(10)) {
  10646. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10647. } else {
  10648. const computed = this.eat(0);
  10649. if (computed || optional || this.eat(16)) {
  10650. return this.parseMember(base, startLoc, state, computed, optional);
  10651. } else {
  10652. state.stop = true;
  10653. return base;
  10654. }
  10655. }
  10656. }
  10657. parseMember(base, startLoc, state, computed, optional) {
  10658. const node = this.startNodeAt(startLoc);
  10659. node.object = base;
  10660. node.computed = computed;
  10661. if (computed) {
  10662. node.property = this.parseExpression();
  10663. this.expect(3);
  10664. } else if (this.match(138)) {
  10665. if (base.type === "Super") {
  10666. this.raise(Errors.SuperPrivateField, startLoc);
  10667. }
  10668. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10669. node.property = this.parsePrivateName();
  10670. } else {
  10671. node.property = this.parseIdentifier(true);
  10672. }
  10673. if (state.optionalChainMember) {
  10674. node.optional = optional;
  10675. return this.finishNode(node, "OptionalMemberExpression");
  10676. } else {
  10677. return this.finishNode(node, "MemberExpression");
  10678. }
  10679. }
  10680. parseBind(base, startLoc, noCalls, state) {
  10681. const node = this.startNodeAt(startLoc);
  10682. node.object = base;
  10683. this.next();
  10684. node.callee = this.parseNoCallExpr();
  10685. state.stop = true;
  10686. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10687. }
  10688. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10689. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10690. let refExpressionErrors = null;
  10691. this.state.maybeInArrowParameters = true;
  10692. this.next();
  10693. const node = this.startNodeAt(startLoc);
  10694. node.callee = base;
  10695. const {
  10696. maybeAsyncArrow,
  10697. optionalChainMember
  10698. } = state;
  10699. if (maybeAsyncArrow) {
  10700. this.expressionScope.enter(newAsyncArrowScope());
  10701. refExpressionErrors = new ExpressionErrors();
  10702. }
  10703. if (optionalChainMember) {
  10704. node.optional = optional;
  10705. }
  10706. if (optional) {
  10707. node.arguments = this.parseCallExpressionArguments(11);
  10708. } else {
  10709. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  10710. }
  10711. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10712. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10713. state.stop = true;
  10714. this.checkDestructuringPrivate(refExpressionErrors);
  10715. this.expressionScope.validateAsPattern();
  10716. this.expressionScope.exit();
  10717. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  10718. } else {
  10719. if (maybeAsyncArrow) {
  10720. this.checkExpressionErrors(refExpressionErrors, true);
  10721. this.expressionScope.exit();
  10722. }
  10723. this.toReferencedArguments(finishedNode);
  10724. }
  10725. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10726. return finishedNode;
  10727. }
  10728. toReferencedArguments(node, isParenthesizedExpr) {
  10729. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  10730. }
  10731. parseTaggedTemplateExpression(base, startLoc, state) {
  10732. const node = this.startNodeAt(startLoc);
  10733. node.tag = base;
  10734. node.quasi = this.parseTemplate(true);
  10735. if (state.optionalChainMember) {
  10736. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  10737. }
  10738. return this.finishNode(node, "TaggedTemplateExpression");
  10739. }
  10740. atPossibleAsyncArrow(base) {
  10741. 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;
  10742. }
  10743. expectImportAttributesPlugin() {
  10744. if (!this.hasPlugin("importAssertions")) {
  10745. this.expectPlugin("importAttributes");
  10746. }
  10747. }
  10748. finishCallExpression(node, optional) {
  10749. if (node.callee.type === "Import") {
  10750. if (node.arguments.length === 2) {
  10751. {
  10752. if (!this.hasPlugin("moduleAttributes")) {
  10753. this.expectImportAttributesPlugin();
  10754. }
  10755. }
  10756. }
  10757. if (node.arguments.length === 0 || node.arguments.length > 2) {
  10758. this.raise(Errors.ImportCallArity, node, {
  10759. maxArgumentCount: this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  10760. });
  10761. } else {
  10762. for (const arg of node.arguments) {
  10763. if (arg.type === "SpreadElement") {
  10764. this.raise(Errors.ImportCallSpreadArgument, arg);
  10765. }
  10766. }
  10767. }
  10768. }
  10769. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  10770. }
  10771. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  10772. const elts = [];
  10773. let first = true;
  10774. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10775. this.state.inFSharpPipelineDirectBody = false;
  10776. while (!this.eat(close)) {
  10777. if (first) {
  10778. first = false;
  10779. } else {
  10780. this.expect(12);
  10781. if (this.match(close)) {
  10782. if (dynamicImport && !this.hasPlugin("importAttributes") && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  10783. this.raise(Errors.ImportCallArgumentTrailingComma, this.state.lastTokStartLoc);
  10784. }
  10785. if (nodeForExtra) {
  10786. this.addTrailingCommaExtraToNode(nodeForExtra);
  10787. }
  10788. this.next();
  10789. break;
  10790. }
  10791. }
  10792. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  10793. }
  10794. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  10795. return elts;
  10796. }
  10797. shouldParseAsyncArrow() {
  10798. return this.match(19) && !this.canInsertSemicolon();
  10799. }
  10800. parseAsyncArrowFromCallExpression(node, call) {
  10801. var _call$extra;
  10802. this.resetPreviousNodeTrailingComments(call);
  10803. this.expect(19);
  10804. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  10805. if (call.innerComments) {
  10806. setInnerComments(node, call.innerComments);
  10807. }
  10808. if (call.callee.trailingComments) {
  10809. setInnerComments(node, call.callee.trailingComments);
  10810. }
  10811. return node;
  10812. }
  10813. parseNoCallExpr() {
  10814. const startLoc = this.state.startLoc;
  10815. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  10816. }
  10817. parseExprAtom(refExpressionErrors) {
  10818. let node;
  10819. let decorators = null;
  10820. const {
  10821. type
  10822. } = this.state;
  10823. switch (type) {
  10824. case 79:
  10825. return this.parseSuper();
  10826. case 83:
  10827. node = this.startNode();
  10828. this.next();
  10829. if (this.match(16)) {
  10830. return this.parseImportMetaProperty(node);
  10831. }
  10832. if (this.match(10)) {
  10833. if (this.options.createImportExpressions) {
  10834. return this.parseImportCall(node);
  10835. } else {
  10836. return this.finishNode(node, "Import");
  10837. }
  10838. } else {
  10839. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  10840. return this.finishNode(node, "Import");
  10841. }
  10842. case 78:
  10843. node = this.startNode();
  10844. this.next();
  10845. return this.finishNode(node, "ThisExpression");
  10846. case 90:
  10847. {
  10848. return this.parseDo(this.startNode(), false);
  10849. }
  10850. case 56:
  10851. case 31:
  10852. {
  10853. this.readRegexp();
  10854. return this.parseRegExpLiteral(this.state.value);
  10855. }
  10856. case 134:
  10857. return this.parseNumericLiteral(this.state.value);
  10858. case 135:
  10859. return this.parseBigIntLiteral(this.state.value);
  10860. case 136:
  10861. return this.parseDecimalLiteral(this.state.value);
  10862. case 133:
  10863. return this.parseStringLiteral(this.state.value);
  10864. case 84:
  10865. return this.parseNullLiteral();
  10866. case 85:
  10867. return this.parseBooleanLiteral(true);
  10868. case 86:
  10869. return this.parseBooleanLiteral(false);
  10870. case 10:
  10871. {
  10872. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  10873. return this.parseParenAndDistinguishExpression(canBeArrow);
  10874. }
  10875. case 2:
  10876. case 1:
  10877. {
  10878. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  10879. }
  10880. case 0:
  10881. {
  10882. return this.parseArrayLike(3, true, false, refExpressionErrors);
  10883. }
  10884. case 6:
  10885. case 7:
  10886. {
  10887. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  10888. }
  10889. case 5:
  10890. {
  10891. return this.parseObjectLike(8, false, false, refExpressionErrors);
  10892. }
  10893. case 68:
  10894. return this.parseFunctionOrFunctionSent();
  10895. case 26:
  10896. decorators = this.parseDecorators();
  10897. case 80:
  10898. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  10899. case 77:
  10900. return this.parseNewOrNewTarget();
  10901. case 25:
  10902. case 24:
  10903. return this.parseTemplate(false);
  10904. case 15:
  10905. {
  10906. node = this.startNode();
  10907. this.next();
  10908. node.object = null;
  10909. const callee = node.callee = this.parseNoCallExpr();
  10910. if (callee.type === "MemberExpression") {
  10911. return this.finishNode(node, "BindExpression");
  10912. } else {
  10913. throw this.raise(Errors.UnsupportedBind, callee);
  10914. }
  10915. }
  10916. case 138:
  10917. {
  10918. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  10919. identifierName: this.state.value
  10920. });
  10921. return this.parsePrivateName();
  10922. }
  10923. case 33:
  10924. {
  10925. return this.parseTopicReferenceThenEqualsSign(54, "%");
  10926. }
  10927. case 32:
  10928. {
  10929. return this.parseTopicReferenceThenEqualsSign(44, "^");
  10930. }
  10931. case 37:
  10932. case 38:
  10933. {
  10934. return this.parseTopicReference("hack");
  10935. }
  10936. case 44:
  10937. case 54:
  10938. case 27:
  10939. {
  10940. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  10941. if (pipeProposal) {
  10942. return this.parseTopicReference(pipeProposal);
  10943. }
  10944. this.unexpected();
  10945. break;
  10946. }
  10947. case 47:
  10948. {
  10949. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  10950. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  10951. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  10952. } else {
  10953. this.unexpected();
  10954. }
  10955. break;
  10956. }
  10957. default:
  10958. if (tokenIsIdentifier(type)) {
  10959. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  10960. return this.parseModuleExpression();
  10961. }
  10962. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  10963. const containsEsc = this.state.containsEsc;
  10964. const id = this.parseIdentifier();
  10965. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  10966. const {
  10967. type
  10968. } = this.state;
  10969. if (type === 68) {
  10970. this.resetPreviousNodeTrailingComments(id);
  10971. this.next();
  10972. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  10973. } else if (tokenIsIdentifier(type)) {
  10974. if (this.lookaheadCharCode() === 61) {
  10975. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  10976. } else {
  10977. return id;
  10978. }
  10979. } else if (type === 90) {
  10980. this.resetPreviousNodeTrailingComments(id);
  10981. return this.parseDo(this.startNodeAtNode(id), true);
  10982. }
  10983. }
  10984. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  10985. this.next();
  10986. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  10987. }
  10988. return id;
  10989. } else {
  10990. this.unexpected();
  10991. }
  10992. }
  10993. }
  10994. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  10995. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  10996. if (pipeProposal) {
  10997. this.state.type = topicTokenType;
  10998. this.state.value = topicTokenValue;
  10999. this.state.pos--;
  11000. this.state.end--;
  11001. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11002. return this.parseTopicReference(pipeProposal);
  11003. } else {
  11004. this.unexpected();
  11005. }
  11006. }
  11007. parseTopicReference(pipeProposal) {
  11008. const node = this.startNode();
  11009. const startLoc = this.state.startLoc;
  11010. const tokenType = this.state.type;
  11011. this.next();
  11012. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11013. }
  11014. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11015. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11016. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11017. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11018. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, startLoc);
  11019. }
  11020. this.registerTopicReference();
  11021. return this.finishNode(node, nodeType);
  11022. } else {
  11023. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11024. token: tokenLabelName(tokenType)
  11025. });
  11026. }
  11027. }
  11028. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11029. switch (pipeProposal) {
  11030. case "hack":
  11031. {
  11032. return this.hasPlugin(["pipelineOperator", {
  11033. topicToken: tokenLabelName(tokenType)
  11034. }]);
  11035. }
  11036. case "smart":
  11037. return tokenType === 27;
  11038. default:
  11039. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11040. }
  11041. }
  11042. parseAsyncArrowUnaryFunction(node) {
  11043. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11044. const params = [this.parseIdentifier()];
  11045. this.prodParam.exit();
  11046. if (this.hasPrecedingLineBreak()) {
  11047. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11048. }
  11049. this.expect(19);
  11050. return this.parseArrowExpression(node, params, true);
  11051. }
  11052. parseDo(node, isAsync) {
  11053. this.expectPlugin("doExpressions");
  11054. if (isAsync) {
  11055. this.expectPlugin("asyncDoExpressions");
  11056. }
  11057. node.async = isAsync;
  11058. this.next();
  11059. const oldLabels = this.state.labels;
  11060. this.state.labels = [];
  11061. if (isAsync) {
  11062. this.prodParam.enter(2);
  11063. node.body = this.parseBlock();
  11064. this.prodParam.exit();
  11065. } else {
  11066. node.body = this.parseBlock();
  11067. }
  11068. this.state.labels = oldLabels;
  11069. return this.finishNode(node, "DoExpression");
  11070. }
  11071. parseSuper() {
  11072. const node = this.startNode();
  11073. this.next();
  11074. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  11075. this.raise(Errors.SuperNotAllowed, node);
  11076. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  11077. this.raise(Errors.UnexpectedSuper, node);
  11078. }
  11079. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11080. this.raise(Errors.UnsupportedSuper, node);
  11081. }
  11082. return this.finishNode(node, "Super");
  11083. }
  11084. parsePrivateName() {
  11085. const node = this.startNode();
  11086. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11087. const name = this.state.value;
  11088. this.next();
  11089. node.id = this.createIdentifier(id, name);
  11090. return this.finishNode(node, "PrivateName");
  11091. }
  11092. parseFunctionOrFunctionSent() {
  11093. const node = this.startNode();
  11094. this.next();
  11095. if (this.prodParam.hasYield && this.match(16)) {
  11096. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11097. this.next();
  11098. if (this.match(103)) {
  11099. this.expectPlugin("functionSent");
  11100. } else if (!this.hasPlugin("functionSent")) {
  11101. this.unexpected();
  11102. }
  11103. return this.parseMetaProperty(node, meta, "sent");
  11104. }
  11105. return this.parseFunction(node);
  11106. }
  11107. parseMetaProperty(node, meta, propertyName) {
  11108. node.meta = meta;
  11109. const containsEsc = this.state.containsEsc;
  11110. node.property = this.parseIdentifier(true);
  11111. if (node.property.name !== propertyName || containsEsc) {
  11112. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11113. target: meta.name,
  11114. onlyValidPropertyName: propertyName
  11115. });
  11116. }
  11117. return this.finishNode(node, "MetaProperty");
  11118. }
  11119. parseImportMetaProperty(node) {
  11120. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11121. this.next();
  11122. if (this.isContextual(101)) {
  11123. if (!this.inModule) {
  11124. this.raise(Errors.ImportMetaOutsideModule, id);
  11125. }
  11126. this.sawUnambiguousESM = true;
  11127. } else if (this.isContextual(105) || this.isContextual(97)) {
  11128. const isSource = this.isContextual(105);
  11129. if (!isSource) this.unexpected();
  11130. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11131. if (!this.options.createImportExpressions) {
  11132. throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, this.state.startLoc, {
  11133. phase: this.state.value
  11134. });
  11135. }
  11136. this.next();
  11137. node.phase = isSource ? "source" : "defer";
  11138. return this.parseImportCall(node);
  11139. }
  11140. return this.parseMetaProperty(node, id, "meta");
  11141. }
  11142. parseLiteralAtNode(value, type, node) {
  11143. this.addExtra(node, "rawValue", value);
  11144. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  11145. node.value = value;
  11146. this.next();
  11147. return this.finishNode(node, type);
  11148. }
  11149. parseLiteral(value, type) {
  11150. const node = this.startNode();
  11151. return this.parseLiteralAtNode(value, type, node);
  11152. }
  11153. parseStringLiteral(value) {
  11154. return this.parseLiteral(value, "StringLiteral");
  11155. }
  11156. parseNumericLiteral(value) {
  11157. return this.parseLiteral(value, "NumericLiteral");
  11158. }
  11159. parseBigIntLiteral(value) {
  11160. return this.parseLiteral(value, "BigIntLiteral");
  11161. }
  11162. parseDecimalLiteral(value) {
  11163. return this.parseLiteral(value, "DecimalLiteral");
  11164. }
  11165. parseRegExpLiteral(value) {
  11166. const node = this.parseLiteral(value.value, "RegExpLiteral");
  11167. node.pattern = value.pattern;
  11168. node.flags = value.flags;
  11169. return node;
  11170. }
  11171. parseBooleanLiteral(value) {
  11172. const node = this.startNode();
  11173. node.value = value;
  11174. this.next();
  11175. return this.finishNode(node, "BooleanLiteral");
  11176. }
  11177. parseNullLiteral() {
  11178. const node = this.startNode();
  11179. this.next();
  11180. return this.finishNode(node, "NullLiteral");
  11181. }
  11182. parseParenAndDistinguishExpression(canBeArrow) {
  11183. const startLoc = this.state.startLoc;
  11184. let val;
  11185. this.next();
  11186. this.expressionScope.enter(newArrowHeadScope());
  11187. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11188. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11189. this.state.maybeInArrowParameters = true;
  11190. this.state.inFSharpPipelineDirectBody = false;
  11191. const innerStartLoc = this.state.startLoc;
  11192. const exprList = [];
  11193. const refExpressionErrors = new ExpressionErrors();
  11194. let first = true;
  11195. let spreadStartLoc;
  11196. let optionalCommaStartLoc;
  11197. while (!this.match(11)) {
  11198. if (first) {
  11199. first = false;
  11200. } else {
  11201. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11202. if (this.match(11)) {
  11203. optionalCommaStartLoc = this.state.startLoc;
  11204. break;
  11205. }
  11206. }
  11207. if (this.match(21)) {
  11208. const spreadNodeStartLoc = this.state.startLoc;
  11209. spreadStartLoc = this.state.startLoc;
  11210. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11211. if (!this.checkCommaAfterRest(41)) {
  11212. break;
  11213. }
  11214. } else {
  11215. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11216. }
  11217. }
  11218. const innerEndLoc = this.state.lastTokEndLoc;
  11219. this.expect(11);
  11220. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11221. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11222. let arrowNode = this.startNodeAt(startLoc);
  11223. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11224. this.checkDestructuringPrivate(refExpressionErrors);
  11225. this.expressionScope.validateAsPattern();
  11226. this.expressionScope.exit();
  11227. this.parseArrowExpression(arrowNode, exprList, false);
  11228. return arrowNode;
  11229. }
  11230. this.expressionScope.exit();
  11231. if (!exprList.length) {
  11232. this.unexpected(this.state.lastTokStartLoc);
  11233. }
  11234. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11235. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11236. this.checkExpressionErrors(refExpressionErrors, true);
  11237. this.toReferencedListDeep(exprList, true);
  11238. if (exprList.length > 1) {
  11239. val = this.startNodeAt(innerStartLoc);
  11240. val.expressions = exprList;
  11241. this.finishNode(val, "SequenceExpression");
  11242. this.resetEndLocation(val, innerEndLoc);
  11243. } else {
  11244. val = exprList[0];
  11245. }
  11246. return this.wrapParenthesis(startLoc, val);
  11247. }
  11248. wrapParenthesis(startLoc, expression) {
  11249. if (!this.options.createParenthesizedExpressions) {
  11250. this.addExtra(expression, "parenthesized", true);
  11251. this.addExtra(expression, "parenStart", startLoc.index);
  11252. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11253. return expression;
  11254. }
  11255. const parenExpression = this.startNodeAt(startLoc);
  11256. parenExpression.expression = expression;
  11257. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11258. }
  11259. shouldParseArrow(params) {
  11260. return !this.canInsertSemicolon();
  11261. }
  11262. parseArrow(node) {
  11263. if (this.eat(19)) {
  11264. return node;
  11265. }
  11266. }
  11267. parseParenItem(node, startLoc) {
  11268. return node;
  11269. }
  11270. parseNewOrNewTarget() {
  11271. const node = this.startNode();
  11272. this.next();
  11273. if (this.match(16)) {
  11274. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11275. this.next();
  11276. const metaProp = this.parseMetaProperty(node, meta, "target");
  11277. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
  11278. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11279. }
  11280. return metaProp;
  11281. }
  11282. return this.parseNew(node);
  11283. }
  11284. parseNew(node) {
  11285. this.parseNewCallee(node);
  11286. if (this.eat(10)) {
  11287. const args = this.parseExprList(11);
  11288. this.toReferencedList(args);
  11289. node.arguments = args;
  11290. } else {
  11291. node.arguments = [];
  11292. }
  11293. return this.finishNode(node, "NewExpression");
  11294. }
  11295. parseNewCallee(node) {
  11296. const isImport = this.match(83);
  11297. const callee = this.parseNoCallExpr();
  11298. node.callee = callee;
  11299. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11300. this.raise(Errors.ImportCallNotNewExpression, callee);
  11301. }
  11302. }
  11303. parseTemplateElement(isTagged) {
  11304. const {
  11305. start,
  11306. startLoc,
  11307. end,
  11308. value
  11309. } = this.state;
  11310. const elemStart = start + 1;
  11311. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11312. if (value === null) {
  11313. if (!isTagged) {
  11314. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11315. }
  11316. }
  11317. const isTail = this.match(24);
  11318. const endOffset = isTail ? -1 : -2;
  11319. const elemEnd = end + endOffset;
  11320. elem.value = {
  11321. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11322. cooked: value === null ? null : value.slice(1, endOffset)
  11323. };
  11324. elem.tail = isTail;
  11325. this.next();
  11326. const finishedNode = this.finishNode(elem, "TemplateElement");
  11327. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11328. return finishedNode;
  11329. }
  11330. parseTemplate(isTagged) {
  11331. const node = this.startNode();
  11332. let curElt = this.parseTemplateElement(isTagged);
  11333. const quasis = [curElt];
  11334. const substitutions = [];
  11335. while (!curElt.tail) {
  11336. substitutions.push(this.parseTemplateSubstitution());
  11337. this.readTemplateContinuation();
  11338. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11339. }
  11340. node.expressions = substitutions;
  11341. node.quasis = quasis;
  11342. return this.finishNode(node, "TemplateLiteral");
  11343. }
  11344. parseTemplateSubstitution() {
  11345. return this.parseExpression();
  11346. }
  11347. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11348. if (isRecord) {
  11349. this.expectPlugin("recordAndTuple");
  11350. }
  11351. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11352. this.state.inFSharpPipelineDirectBody = false;
  11353. const propHash = Object.create(null);
  11354. let first = true;
  11355. const node = this.startNode();
  11356. node.properties = [];
  11357. this.next();
  11358. while (!this.match(close)) {
  11359. if (first) {
  11360. first = false;
  11361. } else {
  11362. this.expect(12);
  11363. if (this.match(close)) {
  11364. this.addTrailingCommaExtraToNode(node);
  11365. break;
  11366. }
  11367. }
  11368. let prop;
  11369. if (isPattern) {
  11370. prop = this.parseBindingProperty();
  11371. } else {
  11372. prop = this.parsePropertyDefinition(refExpressionErrors);
  11373. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11374. }
  11375. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11376. this.raise(Errors.InvalidRecordProperty, prop);
  11377. }
  11378. if (prop.shorthand) {
  11379. this.addExtra(prop, "shorthand", true);
  11380. }
  11381. node.properties.push(prop);
  11382. }
  11383. this.next();
  11384. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11385. let type = "ObjectExpression";
  11386. if (isPattern) {
  11387. type = "ObjectPattern";
  11388. } else if (isRecord) {
  11389. type = "RecordExpression";
  11390. }
  11391. return this.finishNode(node, type);
  11392. }
  11393. addTrailingCommaExtraToNode(node) {
  11394. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11395. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11396. }
  11397. maybeAsyncOrAccessorProp(prop) {
  11398. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11399. }
  11400. parsePropertyDefinition(refExpressionErrors) {
  11401. let decorators = [];
  11402. if (this.match(26)) {
  11403. if (this.hasPlugin("decorators")) {
  11404. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11405. }
  11406. while (this.match(26)) {
  11407. decorators.push(this.parseDecorator());
  11408. }
  11409. }
  11410. const prop = this.startNode();
  11411. let isAsync = false;
  11412. let isAccessor = false;
  11413. let startLoc;
  11414. if (this.match(21)) {
  11415. if (decorators.length) this.unexpected();
  11416. return this.parseSpread();
  11417. }
  11418. if (decorators.length) {
  11419. prop.decorators = decorators;
  11420. decorators = [];
  11421. }
  11422. prop.method = false;
  11423. if (refExpressionErrors) {
  11424. startLoc = this.state.startLoc;
  11425. }
  11426. let isGenerator = this.eat(55);
  11427. this.parsePropertyNamePrefixOperator(prop);
  11428. const containsEsc = this.state.containsEsc;
  11429. this.parsePropertyName(prop, refExpressionErrors);
  11430. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11431. const {
  11432. key
  11433. } = prop;
  11434. const keyName = key.name;
  11435. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11436. isAsync = true;
  11437. this.resetPreviousNodeTrailingComments(key);
  11438. isGenerator = this.eat(55);
  11439. this.parsePropertyName(prop);
  11440. }
  11441. if (keyName === "get" || keyName === "set") {
  11442. isAccessor = true;
  11443. this.resetPreviousNodeTrailingComments(key);
  11444. prop.kind = keyName;
  11445. if (this.match(55)) {
  11446. isGenerator = true;
  11447. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11448. kind: keyName
  11449. });
  11450. this.next();
  11451. }
  11452. this.parsePropertyName(prop);
  11453. }
  11454. }
  11455. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11456. }
  11457. getGetterSetterExpectedParamCount(method) {
  11458. return method.kind === "get" ? 0 : 1;
  11459. }
  11460. getObjectOrClassMethodParams(method) {
  11461. return method.params;
  11462. }
  11463. checkGetterSetterParams(method) {
  11464. var _params;
  11465. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11466. const params = this.getObjectOrClassMethodParams(method);
  11467. if (params.length !== paramCount) {
  11468. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  11469. }
  11470. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11471. this.raise(Errors.BadSetterRestParameter, method);
  11472. }
  11473. }
  11474. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11475. if (isAccessor) {
  11476. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11477. this.checkGetterSetterParams(finishedProp);
  11478. return finishedProp;
  11479. }
  11480. if (isAsync || isGenerator || this.match(10)) {
  11481. if (isPattern) this.unexpected();
  11482. prop.kind = "method";
  11483. prop.method = true;
  11484. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11485. }
  11486. }
  11487. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11488. prop.shorthand = false;
  11489. if (this.eat(14)) {
  11490. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11491. return this.finishNode(prop, "ObjectProperty");
  11492. }
  11493. if (!prop.computed && prop.key.type === "Identifier") {
  11494. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11495. if (isPattern) {
  11496. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11497. } else if (this.match(29)) {
  11498. const shorthandAssignLoc = this.state.startLoc;
  11499. if (refExpressionErrors != null) {
  11500. if (refExpressionErrors.shorthandAssignLoc === null) {
  11501. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11502. }
  11503. } else {
  11504. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11505. }
  11506. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11507. } else {
  11508. prop.value = cloneIdentifier(prop.key);
  11509. }
  11510. prop.shorthand = true;
  11511. return this.finishNode(prop, "ObjectProperty");
  11512. }
  11513. }
  11514. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11515. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11516. if (!node) this.unexpected();
  11517. return node;
  11518. }
  11519. parsePropertyName(prop, refExpressionErrors) {
  11520. if (this.eat(0)) {
  11521. prop.computed = true;
  11522. prop.key = this.parseMaybeAssignAllowIn();
  11523. this.expect(3);
  11524. } else {
  11525. const {
  11526. type,
  11527. value
  11528. } = this.state;
  11529. let key;
  11530. if (tokenIsKeywordOrIdentifier(type)) {
  11531. key = this.parseIdentifier(true);
  11532. } else {
  11533. switch (type) {
  11534. case 134:
  11535. key = this.parseNumericLiteral(value);
  11536. break;
  11537. case 133:
  11538. key = this.parseStringLiteral(value);
  11539. break;
  11540. case 135:
  11541. key = this.parseBigIntLiteral(value);
  11542. break;
  11543. case 136:
  11544. key = this.parseDecimalLiteral(value);
  11545. break;
  11546. case 138:
  11547. {
  11548. const privateKeyLoc = this.state.startLoc;
  11549. if (refExpressionErrors != null) {
  11550. if (refExpressionErrors.privateKeyLoc === null) {
  11551. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11552. }
  11553. } else {
  11554. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  11555. }
  11556. key = this.parsePrivateName();
  11557. break;
  11558. }
  11559. default:
  11560. this.unexpected();
  11561. }
  11562. }
  11563. prop.key = key;
  11564. if (type !== 138) {
  11565. prop.computed = false;
  11566. }
  11567. }
  11568. }
  11569. initFunction(node, isAsync) {
  11570. node.id = null;
  11571. node.generator = false;
  11572. node.async = isAsync;
  11573. }
  11574. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11575. this.initFunction(node, isAsync);
  11576. node.generator = isGenerator;
  11577. this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
  11578. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11579. this.parseFunctionParams(node, isConstructor);
  11580. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11581. this.prodParam.exit();
  11582. this.scope.exit();
  11583. return finishedNode;
  11584. }
  11585. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11586. if (isTuple) {
  11587. this.expectPlugin("recordAndTuple");
  11588. }
  11589. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11590. this.state.inFSharpPipelineDirectBody = false;
  11591. const node = this.startNode();
  11592. this.next();
  11593. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11594. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11595. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11596. }
  11597. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11598. this.scope.enter(2 | 4);
  11599. let flags = functionFlags(isAsync, false);
  11600. if (!this.match(5) && this.prodParam.hasIn) {
  11601. flags |= 8;
  11602. }
  11603. this.prodParam.enter(flags);
  11604. this.initFunction(node, isAsync);
  11605. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11606. if (params) {
  11607. this.state.maybeInArrowParameters = true;
  11608. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11609. }
  11610. this.state.maybeInArrowParameters = false;
  11611. this.parseFunctionBody(node, true);
  11612. this.prodParam.exit();
  11613. this.scope.exit();
  11614. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11615. return this.finishNode(node, "ArrowFunctionExpression");
  11616. }
  11617. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11618. this.toAssignableList(params, trailingCommaLoc, false);
  11619. node.params = params;
  11620. }
  11621. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11622. this.parseFunctionBody(node, false, isMethod);
  11623. return this.finishNode(node, type);
  11624. }
  11625. parseFunctionBody(node, allowExpression, isMethod = false) {
  11626. const isExpression = allowExpression && !this.match(5);
  11627. this.expressionScope.enter(newExpressionScope());
  11628. if (isExpression) {
  11629. node.body = this.parseMaybeAssign();
  11630. this.checkParams(node, false, allowExpression, false);
  11631. } else {
  11632. const oldStrict = this.state.strict;
  11633. const oldLabels = this.state.labels;
  11634. this.state.labels = [];
  11635. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  11636. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11637. const nonSimple = !this.isSimpleParamList(node.params);
  11638. if (hasStrictModeDirective && nonSimple) {
  11639. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  11640. }
  11641. const strictModeChanged = !oldStrict && this.state.strict;
  11642. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11643. if (this.state.strict && node.id) {
  11644. this.checkIdentifier(node.id, 65, strictModeChanged);
  11645. }
  11646. });
  11647. this.prodParam.exit();
  11648. this.state.labels = oldLabels;
  11649. }
  11650. this.expressionScope.exit();
  11651. }
  11652. isSimpleParameter(node) {
  11653. return node.type === "Identifier";
  11654. }
  11655. isSimpleParamList(params) {
  11656. for (let i = 0, len = params.length; i < len; i++) {
  11657. if (!this.isSimpleParameter(params[i])) return false;
  11658. }
  11659. return true;
  11660. }
  11661. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11662. const checkClashes = !allowDuplicates && new Set();
  11663. const formalParameters = {
  11664. type: "FormalParameters"
  11665. };
  11666. for (const param of node.params) {
  11667. this.checkLVal(param, {
  11668. in: formalParameters,
  11669. binding: 5,
  11670. checkClashes,
  11671. strictModeChanged
  11672. });
  11673. }
  11674. }
  11675. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11676. const elts = [];
  11677. let first = true;
  11678. while (!this.eat(close)) {
  11679. if (first) {
  11680. first = false;
  11681. } else {
  11682. this.expect(12);
  11683. if (this.match(close)) {
  11684. if (nodeForExtra) {
  11685. this.addTrailingCommaExtraToNode(nodeForExtra);
  11686. }
  11687. this.next();
  11688. break;
  11689. }
  11690. }
  11691. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11692. }
  11693. return elts;
  11694. }
  11695. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  11696. let elt;
  11697. if (this.match(12)) {
  11698. if (!allowEmpty) {
  11699. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  11700. unexpected: ","
  11701. });
  11702. }
  11703. elt = null;
  11704. } else if (this.match(21)) {
  11705. const spreadNodeStartLoc = this.state.startLoc;
  11706. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  11707. } else if (this.match(17)) {
  11708. this.expectPlugin("partialApplication");
  11709. if (!allowPlaceholder) {
  11710. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  11711. }
  11712. const node = this.startNode();
  11713. this.next();
  11714. elt = this.finishNode(node, "ArgumentPlaceholder");
  11715. } else {
  11716. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  11717. }
  11718. return elt;
  11719. }
  11720. parseIdentifier(liberal) {
  11721. const node = this.startNode();
  11722. const name = this.parseIdentifierName(liberal);
  11723. return this.createIdentifier(node, name);
  11724. }
  11725. createIdentifier(node, name) {
  11726. node.name = name;
  11727. node.loc.identifierName = name;
  11728. return this.finishNode(node, "Identifier");
  11729. }
  11730. parseIdentifierName(liberal) {
  11731. let name;
  11732. const {
  11733. startLoc,
  11734. type
  11735. } = this.state;
  11736. if (tokenIsKeywordOrIdentifier(type)) {
  11737. name = this.state.value;
  11738. } else {
  11739. this.unexpected();
  11740. }
  11741. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  11742. if (liberal) {
  11743. if (tokenIsKeyword) {
  11744. this.replaceToken(132);
  11745. }
  11746. } else {
  11747. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  11748. }
  11749. this.next();
  11750. return name;
  11751. }
  11752. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  11753. if (word.length > 10) {
  11754. return;
  11755. }
  11756. if (!canBeReservedWord(word)) {
  11757. return;
  11758. }
  11759. if (checkKeywords && isKeyword(word)) {
  11760. this.raise(Errors.UnexpectedKeyword, startLoc, {
  11761. keyword: word
  11762. });
  11763. return;
  11764. }
  11765. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  11766. if (reservedTest(word, this.inModule)) {
  11767. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  11768. reservedWord: word
  11769. });
  11770. return;
  11771. } else if (word === "yield") {
  11772. if (this.prodParam.hasYield) {
  11773. this.raise(Errors.YieldBindingIdentifier, startLoc);
  11774. return;
  11775. }
  11776. } else if (word === "await") {
  11777. if (this.prodParam.hasAwait) {
  11778. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  11779. return;
  11780. }
  11781. if (this.scope.inStaticBlock) {
  11782. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  11783. return;
  11784. }
  11785. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  11786. } else if (word === "arguments") {
  11787. if (this.scope.inClassAndNotInNonArrowFunction) {
  11788. this.raise(Errors.ArgumentsInClass, startLoc);
  11789. return;
  11790. }
  11791. }
  11792. }
  11793. isAwaitAllowed() {
  11794. if (this.prodParam.hasAwait) return true;
  11795. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  11796. return true;
  11797. }
  11798. return false;
  11799. }
  11800. parseAwait(startLoc) {
  11801. const node = this.startNodeAt(startLoc);
  11802. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  11803. if (this.eat(55)) {
  11804. this.raise(Errors.ObsoleteAwaitStar, node);
  11805. }
  11806. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  11807. if (this.isAmbiguousAwait()) {
  11808. this.ambiguousScriptDifferentAst = true;
  11809. } else {
  11810. this.sawUnambiguousESM = true;
  11811. }
  11812. }
  11813. if (!this.state.soloAwait) {
  11814. node.argument = this.parseMaybeUnary(null, true);
  11815. }
  11816. return this.finishNode(node, "AwaitExpression");
  11817. }
  11818. isAmbiguousAwait() {
  11819. if (this.hasPrecedingLineBreak()) return true;
  11820. const {
  11821. type
  11822. } = this.state;
  11823. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 137 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  11824. }
  11825. parseYield() {
  11826. const node = this.startNode();
  11827. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  11828. this.next();
  11829. let delegating = false;
  11830. let argument = null;
  11831. if (!this.hasPrecedingLineBreak()) {
  11832. delegating = this.eat(55);
  11833. switch (this.state.type) {
  11834. case 13:
  11835. case 139:
  11836. case 8:
  11837. case 11:
  11838. case 3:
  11839. case 9:
  11840. case 14:
  11841. case 12:
  11842. if (!delegating) break;
  11843. default:
  11844. argument = this.parseMaybeAssign();
  11845. }
  11846. }
  11847. node.delegate = delegating;
  11848. node.argument = argument;
  11849. return this.finishNode(node, "YieldExpression");
  11850. }
  11851. parseImportCall(node) {
  11852. this.next();
  11853. node.source = this.parseMaybeAssignAllowIn();
  11854. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  11855. node.options = null;
  11856. }
  11857. if (this.eat(12)) {
  11858. this.expectImportAttributesPlugin();
  11859. if (!this.match(11)) {
  11860. node.options = this.parseMaybeAssignAllowIn();
  11861. this.eat(12);
  11862. }
  11863. }
  11864. this.expect(11);
  11865. return this.finishNode(node, "ImportExpression");
  11866. }
  11867. checkPipelineAtInfixOperator(left, leftStartLoc) {
  11868. if (this.hasPlugin(["pipelineOperator", {
  11869. proposal: "smart"
  11870. }])) {
  11871. if (left.type === "SequenceExpression") {
  11872. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  11873. }
  11874. }
  11875. }
  11876. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  11877. if (this.isSimpleReference(childExpr)) {
  11878. const bodyNode = this.startNodeAt(startLoc);
  11879. bodyNode.callee = childExpr;
  11880. return this.finishNode(bodyNode, "PipelineBareFunction");
  11881. } else {
  11882. const bodyNode = this.startNodeAt(startLoc);
  11883. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  11884. bodyNode.expression = childExpr;
  11885. return this.finishNode(bodyNode, "PipelineTopicExpression");
  11886. }
  11887. }
  11888. isSimpleReference(expression) {
  11889. switch (expression.type) {
  11890. case "MemberExpression":
  11891. return !expression.computed && this.isSimpleReference(expression.object);
  11892. case "Identifier":
  11893. return true;
  11894. default:
  11895. return false;
  11896. }
  11897. }
  11898. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  11899. if (this.match(19)) {
  11900. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  11901. }
  11902. if (!this.topicReferenceWasUsedInCurrentContext()) {
  11903. this.raise(Errors.PipelineTopicUnused, startLoc);
  11904. }
  11905. }
  11906. withTopicBindingContext(callback) {
  11907. const outerContextTopicState = this.state.topicContext;
  11908. this.state.topicContext = {
  11909. maxNumOfResolvableTopics: 1,
  11910. maxTopicIndex: null
  11911. };
  11912. try {
  11913. return callback();
  11914. } finally {
  11915. this.state.topicContext = outerContextTopicState;
  11916. }
  11917. }
  11918. withSmartMixTopicForbiddingContext(callback) {
  11919. if (this.hasPlugin(["pipelineOperator", {
  11920. proposal: "smart"
  11921. }])) {
  11922. const outerContextTopicState = this.state.topicContext;
  11923. this.state.topicContext = {
  11924. maxNumOfResolvableTopics: 0,
  11925. maxTopicIndex: null
  11926. };
  11927. try {
  11928. return callback();
  11929. } finally {
  11930. this.state.topicContext = outerContextTopicState;
  11931. }
  11932. } else {
  11933. return callback();
  11934. }
  11935. }
  11936. withSoloAwaitPermittingContext(callback) {
  11937. const outerContextSoloAwaitState = this.state.soloAwait;
  11938. this.state.soloAwait = true;
  11939. try {
  11940. return callback();
  11941. } finally {
  11942. this.state.soloAwait = outerContextSoloAwaitState;
  11943. }
  11944. }
  11945. allowInAnd(callback) {
  11946. const flags = this.prodParam.currentFlags();
  11947. const prodParamToSet = 8 & ~flags;
  11948. if (prodParamToSet) {
  11949. this.prodParam.enter(flags | 8);
  11950. try {
  11951. return callback();
  11952. } finally {
  11953. this.prodParam.exit();
  11954. }
  11955. }
  11956. return callback();
  11957. }
  11958. disallowInAnd(callback) {
  11959. const flags = this.prodParam.currentFlags();
  11960. const prodParamToClear = 8 & flags;
  11961. if (prodParamToClear) {
  11962. this.prodParam.enter(flags & ~8);
  11963. try {
  11964. return callback();
  11965. } finally {
  11966. this.prodParam.exit();
  11967. }
  11968. }
  11969. return callback();
  11970. }
  11971. registerTopicReference() {
  11972. this.state.topicContext.maxTopicIndex = 0;
  11973. }
  11974. topicReferenceIsAllowedInCurrentContext() {
  11975. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  11976. }
  11977. topicReferenceWasUsedInCurrentContext() {
  11978. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  11979. }
  11980. parseFSharpPipelineBody(prec) {
  11981. const startLoc = this.state.startLoc;
  11982. this.state.potentialArrowAt = this.state.start;
  11983. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11984. this.state.inFSharpPipelineDirectBody = true;
  11985. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  11986. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11987. return ret;
  11988. }
  11989. parseModuleExpression() {
  11990. this.expectPlugin("moduleBlocks");
  11991. const node = this.startNode();
  11992. this.next();
  11993. if (!this.match(5)) {
  11994. this.unexpected(null, 5);
  11995. }
  11996. const program = this.startNodeAt(this.state.endLoc);
  11997. this.next();
  11998. const revertScopes = this.initializeScopes(true);
  11999. this.enterInitialScopes();
  12000. try {
  12001. node.body = this.parseProgram(program, 8, "module");
  12002. } finally {
  12003. revertScopes();
  12004. }
  12005. return this.finishNode(node, "ModuleExpression");
  12006. }
  12007. parsePropertyNamePrefixOperator(prop) {}
  12008. }
  12009. const loopLabel = {
  12010. kind: 1
  12011. },
  12012. switchLabel = {
  12013. kind: 2
  12014. };
  12015. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12016. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12017. function babel7CompatTokens(tokens, input) {
  12018. for (let i = 0; i < tokens.length; i++) {
  12019. const token = tokens[i];
  12020. const {
  12021. type
  12022. } = token;
  12023. if (typeof type === "number") {
  12024. {
  12025. if (type === 138) {
  12026. const {
  12027. loc,
  12028. start,
  12029. value,
  12030. end
  12031. } = token;
  12032. const hashEndPos = start + 1;
  12033. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12034. tokens.splice(i, 1, new Token({
  12035. type: getExportedToken(27),
  12036. value: "#",
  12037. start: start,
  12038. end: hashEndPos,
  12039. startLoc: loc.start,
  12040. endLoc: hashEndLoc
  12041. }), new Token({
  12042. type: getExportedToken(132),
  12043. value: value,
  12044. start: hashEndPos,
  12045. end: end,
  12046. startLoc: hashEndLoc,
  12047. endLoc: loc.end
  12048. }));
  12049. i++;
  12050. continue;
  12051. }
  12052. if (tokenIsTemplate(type)) {
  12053. const {
  12054. loc,
  12055. start,
  12056. value,
  12057. end
  12058. } = token;
  12059. const backquoteEnd = start + 1;
  12060. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12061. let startToken;
  12062. if (input.charCodeAt(start) === 96) {
  12063. startToken = new Token({
  12064. type: getExportedToken(22),
  12065. value: "`",
  12066. start: start,
  12067. end: backquoteEnd,
  12068. startLoc: loc.start,
  12069. endLoc: backquoteEndLoc
  12070. });
  12071. } else {
  12072. startToken = new Token({
  12073. type: getExportedToken(8),
  12074. value: "}",
  12075. start: start,
  12076. end: backquoteEnd,
  12077. startLoc: loc.start,
  12078. endLoc: backquoteEndLoc
  12079. });
  12080. }
  12081. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12082. if (type === 24) {
  12083. templateElementEnd = end - 1;
  12084. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12085. templateValue = value === null ? null : value.slice(1, -1);
  12086. endToken = new Token({
  12087. type: getExportedToken(22),
  12088. value: "`",
  12089. start: templateElementEnd,
  12090. end: end,
  12091. startLoc: templateElementEndLoc,
  12092. endLoc: loc.end
  12093. });
  12094. } else {
  12095. templateElementEnd = end - 2;
  12096. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12097. templateValue = value === null ? null : value.slice(1, -2);
  12098. endToken = new Token({
  12099. type: getExportedToken(23),
  12100. value: "${",
  12101. start: templateElementEnd,
  12102. end: end,
  12103. startLoc: templateElementEndLoc,
  12104. endLoc: loc.end
  12105. });
  12106. }
  12107. tokens.splice(i, 1, startToken, new Token({
  12108. type: getExportedToken(20),
  12109. value: templateValue,
  12110. start: backquoteEnd,
  12111. end: templateElementEnd,
  12112. startLoc: backquoteEndLoc,
  12113. endLoc: templateElementEndLoc
  12114. }), endToken);
  12115. i += 2;
  12116. continue;
  12117. }
  12118. }
  12119. token.type = getExportedToken(type);
  12120. }
  12121. }
  12122. return tokens;
  12123. }
  12124. class StatementParser extends ExpressionParser {
  12125. parseTopLevel(file, program) {
  12126. file.program = this.parseProgram(program);
  12127. file.comments = this.comments;
  12128. if (this.options.tokens) {
  12129. file.tokens = babel7CompatTokens(this.tokens, this.input);
  12130. }
  12131. return this.finishNode(file, "File");
  12132. }
  12133. parseProgram(program, end = 139, sourceType = this.options.sourceType) {
  12134. program.sourceType = sourceType;
  12135. program.interpreter = this.parseInterpreterDirective();
  12136. this.parseBlockBody(program, true, true, end);
  12137. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  12138. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12139. this.raise(Errors.ModuleExportUndefined, at, {
  12140. localName
  12141. });
  12142. }
  12143. }
  12144. let finishedProgram;
  12145. if (end === 139) {
  12146. finishedProgram = this.finishNode(program, "Program");
  12147. } else {
  12148. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12149. }
  12150. return finishedProgram;
  12151. }
  12152. stmtToDirective(stmt) {
  12153. const directive = stmt;
  12154. directive.type = "Directive";
  12155. directive.value = directive.expression;
  12156. delete directive.expression;
  12157. const directiveLiteral = directive.value;
  12158. const expressionValue = directiveLiteral.value;
  12159. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  12160. const val = directiveLiteral.value = raw.slice(1, -1);
  12161. this.addExtra(directiveLiteral, "raw", raw);
  12162. this.addExtra(directiveLiteral, "rawValue", val);
  12163. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12164. directiveLiteral.type = "DirectiveLiteral";
  12165. return directive;
  12166. }
  12167. parseInterpreterDirective() {
  12168. if (!this.match(28)) {
  12169. return null;
  12170. }
  12171. const node = this.startNode();
  12172. node.value = this.state.value;
  12173. this.next();
  12174. return this.finishNode(node, "InterpreterDirective");
  12175. }
  12176. isLet() {
  12177. if (!this.isContextual(100)) {
  12178. return false;
  12179. }
  12180. return this.hasFollowingBindingAtom();
  12181. }
  12182. chStartsBindingIdentifier(ch, pos) {
  12183. if (isIdentifierStart(ch)) {
  12184. keywordRelationalOperator.lastIndex = pos;
  12185. if (keywordRelationalOperator.test(this.input)) {
  12186. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12187. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12188. return false;
  12189. }
  12190. }
  12191. return true;
  12192. } else if (ch === 92) {
  12193. return true;
  12194. } else {
  12195. return false;
  12196. }
  12197. }
  12198. chStartsBindingPattern(ch) {
  12199. return ch === 91 || ch === 123;
  12200. }
  12201. hasFollowingBindingAtom() {
  12202. const next = this.nextTokenStart();
  12203. const nextCh = this.codePointAtPos(next);
  12204. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12205. }
  12206. hasInLineFollowingBindingIdentifier() {
  12207. const next = this.nextTokenInLineStart();
  12208. const nextCh = this.codePointAtPos(next);
  12209. return this.chStartsBindingIdentifier(nextCh, next);
  12210. }
  12211. startsUsingForOf() {
  12212. const {
  12213. type,
  12214. containsEsc
  12215. } = this.lookahead();
  12216. if (type === 102 && !containsEsc) {
  12217. return false;
  12218. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12219. this.expectPlugin("explicitResourceManagement");
  12220. return true;
  12221. }
  12222. }
  12223. startsAwaitUsing() {
  12224. let next = this.nextTokenInLineStart();
  12225. if (this.isUnparsedContextual(next, "using")) {
  12226. next = this.nextTokenInLineStartSince(next + 5);
  12227. const nextCh = this.codePointAtPos(next);
  12228. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12229. this.expectPlugin("explicitResourceManagement");
  12230. return true;
  12231. }
  12232. }
  12233. return false;
  12234. }
  12235. parseModuleItem() {
  12236. return this.parseStatementLike(1 | 2 | 4 | 8);
  12237. }
  12238. parseStatementListItem() {
  12239. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12240. }
  12241. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12242. let flags = 0;
  12243. if (this.options.annexB && !this.state.strict) {
  12244. flags |= 4;
  12245. if (allowLabeledFunction) {
  12246. flags |= 8;
  12247. }
  12248. }
  12249. return this.parseStatementLike(flags);
  12250. }
  12251. parseStatement() {
  12252. return this.parseStatementLike(0);
  12253. }
  12254. parseStatementLike(flags) {
  12255. let decorators = null;
  12256. if (this.match(26)) {
  12257. decorators = this.parseDecorators(true);
  12258. }
  12259. return this.parseStatementContent(flags, decorators);
  12260. }
  12261. parseStatementContent(flags, decorators) {
  12262. const starttype = this.state.type;
  12263. const node = this.startNode();
  12264. const allowDeclaration = !!(flags & 2);
  12265. const allowFunctionDeclaration = !!(flags & 4);
  12266. const topLevel = flags & 1;
  12267. switch (starttype) {
  12268. case 60:
  12269. return this.parseBreakContinueStatement(node, true);
  12270. case 63:
  12271. return this.parseBreakContinueStatement(node, false);
  12272. case 64:
  12273. return this.parseDebuggerStatement(node);
  12274. case 90:
  12275. return this.parseDoWhileStatement(node);
  12276. case 91:
  12277. return this.parseForStatement(node);
  12278. case 68:
  12279. if (this.lookaheadCharCode() === 46) break;
  12280. if (!allowFunctionDeclaration) {
  12281. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12282. }
  12283. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12284. case 80:
  12285. if (!allowDeclaration) this.unexpected();
  12286. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12287. case 69:
  12288. return this.parseIfStatement(node);
  12289. case 70:
  12290. return this.parseReturnStatement(node);
  12291. case 71:
  12292. return this.parseSwitchStatement(node);
  12293. case 72:
  12294. return this.parseThrowStatement(node);
  12295. case 73:
  12296. return this.parseTryStatement(node);
  12297. case 96:
  12298. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  12299. if (!this.isAwaitAllowed()) {
  12300. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12301. } else if (!allowDeclaration) {
  12302. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12303. }
  12304. this.next();
  12305. return this.parseVarStatement(node, "await using");
  12306. }
  12307. break;
  12308. case 107:
  12309. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifier()) {
  12310. break;
  12311. }
  12312. this.expectPlugin("explicitResourceManagement");
  12313. if (!this.scope.inModule && this.scope.inTopLevel) {
  12314. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12315. } else if (!allowDeclaration) {
  12316. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12317. }
  12318. return this.parseVarStatement(node, "using");
  12319. case 100:
  12320. {
  12321. if (this.state.containsEsc) {
  12322. break;
  12323. }
  12324. const next = this.nextTokenStart();
  12325. const nextCh = this.codePointAtPos(next);
  12326. if (nextCh !== 91) {
  12327. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12328. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12329. break;
  12330. }
  12331. }
  12332. }
  12333. case 75:
  12334. {
  12335. if (!allowDeclaration) {
  12336. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12337. }
  12338. }
  12339. case 74:
  12340. {
  12341. const kind = this.state.value;
  12342. return this.parseVarStatement(node, kind);
  12343. }
  12344. case 92:
  12345. return this.parseWhileStatement(node);
  12346. case 76:
  12347. return this.parseWithStatement(node);
  12348. case 5:
  12349. return this.parseBlock();
  12350. case 13:
  12351. return this.parseEmptyStatement(node);
  12352. case 83:
  12353. {
  12354. const nextTokenCharCode = this.lookaheadCharCode();
  12355. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12356. break;
  12357. }
  12358. }
  12359. case 82:
  12360. {
  12361. if (!this.options.allowImportExportEverywhere && !topLevel) {
  12362. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12363. }
  12364. this.next();
  12365. let result;
  12366. if (starttype === 83) {
  12367. result = this.parseImport(node);
  12368. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12369. this.sawUnambiguousESM = true;
  12370. }
  12371. } else {
  12372. result = this.parseExport(node, decorators);
  12373. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12374. this.sawUnambiguousESM = true;
  12375. }
  12376. }
  12377. this.assertModuleNodeAllowed(result);
  12378. return result;
  12379. }
  12380. default:
  12381. {
  12382. if (this.isAsyncFunction()) {
  12383. if (!allowDeclaration) {
  12384. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12385. }
  12386. this.next();
  12387. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12388. }
  12389. }
  12390. }
  12391. const maybeName = this.state.value;
  12392. const expr = this.parseExpression();
  12393. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  12394. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12395. } else {
  12396. return this.parseExpressionStatement(node, expr, decorators);
  12397. }
  12398. }
  12399. assertModuleNodeAllowed(node) {
  12400. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  12401. this.raise(Errors.ImportOutsideModule, node);
  12402. }
  12403. }
  12404. decoratorsEnabledBeforeExport() {
  12405. if (this.hasPlugin("decorators-legacy")) return true;
  12406. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12407. }
  12408. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12409. if (maybeDecorators) {
  12410. if (classNode.decorators && classNode.decorators.length > 0) {
  12411. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12412. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12413. }
  12414. classNode.decorators.unshift(...maybeDecorators);
  12415. } else {
  12416. classNode.decorators = maybeDecorators;
  12417. }
  12418. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12419. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12420. }
  12421. return classNode;
  12422. }
  12423. canHaveLeadingDecorator() {
  12424. return this.match(80);
  12425. }
  12426. parseDecorators(allowExport) {
  12427. const decorators = [];
  12428. do {
  12429. decorators.push(this.parseDecorator());
  12430. } while (this.match(26));
  12431. if (this.match(82)) {
  12432. if (!allowExport) {
  12433. this.unexpected();
  12434. }
  12435. if (!this.decoratorsEnabledBeforeExport()) {
  12436. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  12437. }
  12438. } else if (!this.canHaveLeadingDecorator()) {
  12439. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  12440. }
  12441. return decorators;
  12442. }
  12443. parseDecorator() {
  12444. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12445. const node = this.startNode();
  12446. this.next();
  12447. if (this.hasPlugin("decorators")) {
  12448. const startLoc = this.state.startLoc;
  12449. let expr;
  12450. if (this.match(10)) {
  12451. const startLoc = this.state.startLoc;
  12452. this.next();
  12453. expr = this.parseExpression();
  12454. this.expect(11);
  12455. expr = this.wrapParenthesis(startLoc, expr);
  12456. const paramsStartLoc = this.state.startLoc;
  12457. node.expression = this.parseMaybeDecoratorArguments(expr);
  12458. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12459. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  12460. }
  12461. } else {
  12462. expr = this.parseIdentifier(false);
  12463. while (this.eat(16)) {
  12464. const node = this.startNodeAt(startLoc);
  12465. node.object = expr;
  12466. if (this.match(138)) {
  12467. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12468. node.property = this.parsePrivateName();
  12469. } else {
  12470. node.property = this.parseIdentifier(true);
  12471. }
  12472. node.computed = false;
  12473. expr = this.finishNode(node, "MemberExpression");
  12474. }
  12475. node.expression = this.parseMaybeDecoratorArguments(expr);
  12476. }
  12477. } else {
  12478. node.expression = this.parseExprSubscripts();
  12479. }
  12480. return this.finishNode(node, "Decorator");
  12481. }
  12482. parseMaybeDecoratorArguments(expr) {
  12483. if (this.eat(10)) {
  12484. const node = this.startNodeAtNode(expr);
  12485. node.callee = expr;
  12486. node.arguments = this.parseCallExpressionArguments(11, false);
  12487. this.toReferencedList(node.arguments);
  12488. return this.finishNode(node, "CallExpression");
  12489. }
  12490. return expr;
  12491. }
  12492. parseBreakContinueStatement(node, isBreak) {
  12493. this.next();
  12494. if (this.isLineTerminator()) {
  12495. node.label = null;
  12496. } else {
  12497. node.label = this.parseIdentifier();
  12498. this.semicolon();
  12499. }
  12500. this.verifyBreakContinue(node, isBreak);
  12501. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12502. }
  12503. verifyBreakContinue(node, isBreak) {
  12504. let i;
  12505. for (i = 0; i < this.state.labels.length; ++i) {
  12506. const lab = this.state.labels[i];
  12507. if (node.label == null || lab.name === node.label.name) {
  12508. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  12509. break;
  12510. }
  12511. if (node.label && isBreak) break;
  12512. }
  12513. }
  12514. if (i === this.state.labels.length) {
  12515. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12516. this.raise(Errors.IllegalBreakContinue, node, {
  12517. type
  12518. });
  12519. }
  12520. }
  12521. parseDebuggerStatement(node) {
  12522. this.next();
  12523. this.semicolon();
  12524. return this.finishNode(node, "DebuggerStatement");
  12525. }
  12526. parseHeaderExpression() {
  12527. this.expect(10);
  12528. const val = this.parseExpression();
  12529. this.expect(11);
  12530. return val;
  12531. }
  12532. parseDoWhileStatement(node) {
  12533. this.next();
  12534. this.state.labels.push(loopLabel);
  12535. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12536. this.state.labels.pop();
  12537. this.expect(92);
  12538. node.test = this.parseHeaderExpression();
  12539. this.eat(13);
  12540. return this.finishNode(node, "DoWhileStatement");
  12541. }
  12542. parseForStatement(node) {
  12543. this.next();
  12544. this.state.labels.push(loopLabel);
  12545. let awaitAt = null;
  12546. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  12547. awaitAt = this.state.lastTokStartLoc;
  12548. }
  12549. this.scope.enter(0);
  12550. this.expect(10);
  12551. if (this.match(13)) {
  12552. if (awaitAt !== null) {
  12553. this.unexpected(awaitAt);
  12554. }
  12555. return this.parseFor(node, null);
  12556. }
  12557. const startsWithLet = this.isContextual(100);
  12558. {
  12559. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  12560. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(107) && this.startsUsingForOf();
  12561. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  12562. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12563. const initNode = this.startNode();
  12564. let kind;
  12565. if (startsWithAwaitUsing) {
  12566. kind = "await using";
  12567. if (!this.isAwaitAllowed()) {
  12568. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  12569. }
  12570. this.next();
  12571. } else {
  12572. kind = this.state.value;
  12573. }
  12574. this.next();
  12575. this.parseVar(initNode, true, kind);
  12576. const init = this.finishNode(initNode, "VariableDeclaration");
  12577. const isForIn = this.match(58);
  12578. if (isForIn && starsWithUsingDeclaration) {
  12579. this.raise(Errors.ForInUsing, init);
  12580. }
  12581. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  12582. return this.parseForIn(node, init, awaitAt);
  12583. }
  12584. if (awaitAt !== null) {
  12585. this.unexpected(awaitAt);
  12586. }
  12587. return this.parseFor(node, init);
  12588. }
  12589. }
  12590. const startsWithAsync = this.isContextual(95);
  12591. const refExpressionErrors = new ExpressionErrors();
  12592. const init = this.parseExpression(true, refExpressionErrors);
  12593. const isForOf = this.isContextual(102);
  12594. if (isForOf) {
  12595. if (startsWithLet) {
  12596. this.raise(Errors.ForOfLet, init);
  12597. }
  12598. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12599. this.raise(Errors.ForOfAsync, init);
  12600. }
  12601. }
  12602. if (isForOf || this.match(58)) {
  12603. this.checkDestructuringPrivate(refExpressionErrors);
  12604. this.toAssignable(init, true);
  12605. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12606. this.checkLVal(init, {
  12607. in: {
  12608. type
  12609. }
  12610. });
  12611. return this.parseForIn(node, init, awaitAt);
  12612. } else {
  12613. this.checkExpressionErrors(refExpressionErrors, true);
  12614. }
  12615. if (awaitAt !== null) {
  12616. this.unexpected(awaitAt);
  12617. }
  12618. return this.parseFor(node, init);
  12619. }
  12620. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12621. this.next();
  12622. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  12623. }
  12624. parseIfStatement(node) {
  12625. this.next();
  12626. node.test = this.parseHeaderExpression();
  12627. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12628. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  12629. return this.finishNode(node, "IfStatement");
  12630. }
  12631. parseReturnStatement(node) {
  12632. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  12633. this.raise(Errors.IllegalReturn, this.state.startLoc);
  12634. }
  12635. this.next();
  12636. if (this.isLineTerminator()) {
  12637. node.argument = null;
  12638. } else {
  12639. node.argument = this.parseExpression();
  12640. this.semicolon();
  12641. }
  12642. return this.finishNode(node, "ReturnStatement");
  12643. }
  12644. parseSwitchStatement(node) {
  12645. this.next();
  12646. node.discriminant = this.parseHeaderExpression();
  12647. const cases = node.cases = [];
  12648. this.expect(5);
  12649. this.state.labels.push(switchLabel);
  12650. this.scope.enter(0);
  12651. let cur;
  12652. for (let sawDefault; !this.match(8);) {
  12653. if (this.match(61) || this.match(65)) {
  12654. const isCase = this.match(61);
  12655. if (cur) this.finishNode(cur, "SwitchCase");
  12656. cases.push(cur = this.startNode());
  12657. cur.consequent = [];
  12658. this.next();
  12659. if (isCase) {
  12660. cur.test = this.parseExpression();
  12661. } else {
  12662. if (sawDefault) {
  12663. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  12664. }
  12665. sawDefault = true;
  12666. cur.test = null;
  12667. }
  12668. this.expect(14);
  12669. } else {
  12670. if (cur) {
  12671. cur.consequent.push(this.parseStatementListItem());
  12672. } else {
  12673. this.unexpected();
  12674. }
  12675. }
  12676. }
  12677. this.scope.exit();
  12678. if (cur) this.finishNode(cur, "SwitchCase");
  12679. this.next();
  12680. this.state.labels.pop();
  12681. return this.finishNode(node, "SwitchStatement");
  12682. }
  12683. parseThrowStatement(node) {
  12684. this.next();
  12685. if (this.hasPrecedingLineBreak()) {
  12686. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  12687. }
  12688. node.argument = this.parseExpression();
  12689. this.semicolon();
  12690. return this.finishNode(node, "ThrowStatement");
  12691. }
  12692. parseCatchClauseParam() {
  12693. const param = this.parseBindingAtom();
  12694. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  12695. this.checkLVal(param, {
  12696. in: {
  12697. type: "CatchClause"
  12698. },
  12699. binding: 9
  12700. });
  12701. return param;
  12702. }
  12703. parseTryStatement(node) {
  12704. this.next();
  12705. node.block = this.parseBlock();
  12706. node.handler = null;
  12707. if (this.match(62)) {
  12708. const clause = this.startNode();
  12709. this.next();
  12710. if (this.match(10)) {
  12711. this.expect(10);
  12712. clause.param = this.parseCatchClauseParam();
  12713. this.expect(11);
  12714. } else {
  12715. clause.param = null;
  12716. this.scope.enter(0);
  12717. }
  12718. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  12719. this.scope.exit();
  12720. node.handler = this.finishNode(clause, "CatchClause");
  12721. }
  12722. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  12723. if (!node.handler && !node.finalizer) {
  12724. this.raise(Errors.NoCatchOrFinally, node);
  12725. }
  12726. return this.finishNode(node, "TryStatement");
  12727. }
  12728. parseVarStatement(node, kind, allowMissingInitializer = false) {
  12729. this.next();
  12730. this.parseVar(node, false, kind, allowMissingInitializer);
  12731. this.semicolon();
  12732. return this.finishNode(node, "VariableDeclaration");
  12733. }
  12734. parseWhileStatement(node) {
  12735. this.next();
  12736. node.test = this.parseHeaderExpression();
  12737. this.state.labels.push(loopLabel);
  12738. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12739. this.state.labels.pop();
  12740. return this.finishNode(node, "WhileStatement");
  12741. }
  12742. parseWithStatement(node) {
  12743. if (this.state.strict) {
  12744. this.raise(Errors.StrictWith, this.state.startLoc);
  12745. }
  12746. this.next();
  12747. node.object = this.parseHeaderExpression();
  12748. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12749. return this.finishNode(node, "WithStatement");
  12750. }
  12751. parseEmptyStatement(node) {
  12752. this.next();
  12753. return this.finishNode(node, "EmptyStatement");
  12754. }
  12755. parseLabeledStatement(node, maybeName, expr, flags) {
  12756. for (const label of this.state.labels) {
  12757. if (label.name === maybeName) {
  12758. this.raise(Errors.LabelRedeclaration, expr, {
  12759. labelName: maybeName
  12760. });
  12761. }
  12762. }
  12763. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  12764. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  12765. const label = this.state.labels[i];
  12766. if (label.statementStart === node.start) {
  12767. label.statementStart = this.state.start;
  12768. label.kind = kind;
  12769. } else {
  12770. break;
  12771. }
  12772. }
  12773. this.state.labels.push({
  12774. name: maybeName,
  12775. kind: kind,
  12776. statementStart: this.state.start
  12777. });
  12778. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  12779. this.state.labels.pop();
  12780. node.label = expr;
  12781. return this.finishNode(node, "LabeledStatement");
  12782. }
  12783. parseExpressionStatement(node, expr, decorators) {
  12784. node.expression = expr;
  12785. this.semicolon();
  12786. return this.finishNode(node, "ExpressionStatement");
  12787. }
  12788. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  12789. const node = this.startNode();
  12790. if (allowDirectives) {
  12791. this.state.strictErrors.clear();
  12792. }
  12793. this.expect(5);
  12794. if (createNewLexicalScope) {
  12795. this.scope.enter(0);
  12796. }
  12797. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  12798. if (createNewLexicalScope) {
  12799. this.scope.exit();
  12800. }
  12801. return this.finishNode(node, "BlockStatement");
  12802. }
  12803. isValidDirective(stmt) {
  12804. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  12805. }
  12806. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  12807. const body = node.body = [];
  12808. const directives = node.directives = [];
  12809. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  12810. }
  12811. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  12812. const oldStrict = this.state.strict;
  12813. let hasStrictModeDirective = false;
  12814. let parsedNonDirective = false;
  12815. while (!this.match(end)) {
  12816. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  12817. if (directives && !parsedNonDirective) {
  12818. if (this.isValidDirective(stmt)) {
  12819. const directive = this.stmtToDirective(stmt);
  12820. directives.push(directive);
  12821. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  12822. hasStrictModeDirective = true;
  12823. this.setStrict(true);
  12824. }
  12825. continue;
  12826. }
  12827. parsedNonDirective = true;
  12828. this.state.strictErrors.clear();
  12829. }
  12830. body.push(stmt);
  12831. }
  12832. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  12833. if (!oldStrict) {
  12834. this.setStrict(false);
  12835. }
  12836. this.next();
  12837. }
  12838. parseFor(node, init) {
  12839. node.init = init;
  12840. this.semicolon(false);
  12841. node.test = this.match(13) ? null : this.parseExpression();
  12842. this.semicolon(false);
  12843. node.update = this.match(11) ? null : this.parseExpression();
  12844. this.expect(11);
  12845. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12846. this.scope.exit();
  12847. this.state.labels.pop();
  12848. return this.finishNode(node, "ForStatement");
  12849. }
  12850. parseForIn(node, init, awaitAt) {
  12851. const isForIn = this.match(58);
  12852. this.next();
  12853. if (isForIn) {
  12854. if (awaitAt !== null) this.unexpected(awaitAt);
  12855. } else {
  12856. node.await = awaitAt !== null;
  12857. }
  12858. 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")) {
  12859. this.raise(Errors.ForInOfLoopInitializer, init, {
  12860. type: isForIn ? "ForInStatement" : "ForOfStatement"
  12861. });
  12862. }
  12863. if (init.type === "AssignmentPattern") {
  12864. this.raise(Errors.InvalidLhs, init, {
  12865. ancestor: {
  12866. type: "ForStatement"
  12867. }
  12868. });
  12869. }
  12870. node.left = init;
  12871. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  12872. this.expect(11);
  12873. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12874. this.scope.exit();
  12875. this.state.labels.pop();
  12876. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  12877. }
  12878. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  12879. const declarations = node.declarations = [];
  12880. node.kind = kind;
  12881. for (;;) {
  12882. const decl = this.startNode();
  12883. this.parseVarId(decl, kind);
  12884. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  12885. if (decl.init === null && !allowMissingInitializer) {
  12886. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  12887. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  12888. kind: "destructuring"
  12889. });
  12890. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  12891. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  12892. kind
  12893. });
  12894. }
  12895. }
  12896. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  12897. if (!this.eat(12)) break;
  12898. }
  12899. return node;
  12900. }
  12901. parseVarId(decl, kind) {
  12902. const id = this.parseBindingAtom();
  12903. this.checkLVal(id, {
  12904. in: {
  12905. type: "VariableDeclarator"
  12906. },
  12907. binding: kind === "var" ? 5 : 8201
  12908. });
  12909. decl.id = id;
  12910. }
  12911. parseAsyncFunctionExpression(node) {
  12912. return this.parseFunction(node, 8);
  12913. }
  12914. parseFunction(node, flags = 0) {
  12915. const hangingDeclaration = flags & 2;
  12916. const isDeclaration = !!(flags & 1);
  12917. const requireId = isDeclaration && !(flags & 4);
  12918. const isAsync = !!(flags & 8);
  12919. this.initFunction(node, isAsync);
  12920. if (this.match(55)) {
  12921. if (hangingDeclaration) {
  12922. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  12923. }
  12924. this.next();
  12925. node.generator = true;
  12926. }
  12927. if (isDeclaration) {
  12928. node.id = this.parseFunctionId(requireId);
  12929. }
  12930. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12931. this.state.maybeInArrowParameters = false;
  12932. this.scope.enter(2);
  12933. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12934. if (!isDeclaration) {
  12935. node.id = this.parseFunctionId();
  12936. }
  12937. this.parseFunctionParams(node, false);
  12938. this.withSmartMixTopicForbiddingContext(() => {
  12939. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  12940. });
  12941. this.prodParam.exit();
  12942. this.scope.exit();
  12943. if (isDeclaration && !hangingDeclaration) {
  12944. this.registerFunctionStatementId(node);
  12945. }
  12946. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12947. return node;
  12948. }
  12949. parseFunctionId(requireId) {
  12950. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  12951. }
  12952. parseFunctionParams(node, isConstructor) {
  12953. this.expect(10);
  12954. this.expressionScope.enter(newParameterDeclarationScope());
  12955. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  12956. this.expressionScope.exit();
  12957. }
  12958. registerFunctionStatementId(node) {
  12959. if (!node.id) return;
  12960. this.scope.declareName(node.id.name, !this.options.annexB || this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? 5 : 8201 : 17, node.id.loc.start);
  12961. }
  12962. parseClass(node, isStatement, optionalId) {
  12963. this.next();
  12964. const oldStrict = this.state.strict;
  12965. this.state.strict = true;
  12966. this.parseClassId(node, isStatement, optionalId);
  12967. this.parseClassSuper(node);
  12968. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  12969. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  12970. }
  12971. isClassProperty() {
  12972. return this.match(29) || this.match(13) || this.match(8);
  12973. }
  12974. isClassMethod() {
  12975. return this.match(10);
  12976. }
  12977. nameIsConstructor(key) {
  12978. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  12979. }
  12980. isNonstaticConstructor(method) {
  12981. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  12982. }
  12983. parseClassBody(hadSuperClass, oldStrict) {
  12984. this.classScope.enter();
  12985. const state = {
  12986. hadConstructor: false,
  12987. hadSuperClass
  12988. };
  12989. let decorators = [];
  12990. const classBody = this.startNode();
  12991. classBody.body = [];
  12992. this.expect(5);
  12993. this.withSmartMixTopicForbiddingContext(() => {
  12994. while (!this.match(8)) {
  12995. if (this.eat(13)) {
  12996. if (decorators.length > 0) {
  12997. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  12998. }
  12999. continue;
  13000. }
  13001. if (this.match(26)) {
  13002. decorators.push(this.parseDecorator());
  13003. continue;
  13004. }
  13005. const member = this.startNode();
  13006. if (decorators.length) {
  13007. member.decorators = decorators;
  13008. this.resetStartLocationFromNode(member, decorators[0]);
  13009. decorators = [];
  13010. }
  13011. this.parseClassMember(classBody, member, state);
  13012. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13013. this.raise(Errors.DecoratorConstructor, member);
  13014. }
  13015. }
  13016. });
  13017. this.state.strict = oldStrict;
  13018. this.next();
  13019. if (decorators.length) {
  13020. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13021. }
  13022. this.classScope.exit();
  13023. return this.finishNode(classBody, "ClassBody");
  13024. }
  13025. parseClassMemberFromModifier(classBody, member) {
  13026. const key = this.parseIdentifier(true);
  13027. if (this.isClassMethod()) {
  13028. const method = member;
  13029. method.kind = "method";
  13030. method.computed = false;
  13031. method.key = key;
  13032. method.static = false;
  13033. this.pushClassMethod(classBody, method, false, false, false, false);
  13034. return true;
  13035. } else if (this.isClassProperty()) {
  13036. const prop = member;
  13037. prop.computed = false;
  13038. prop.key = key;
  13039. prop.static = false;
  13040. classBody.body.push(this.parseClassProperty(prop));
  13041. return true;
  13042. }
  13043. this.resetPreviousNodeTrailingComments(key);
  13044. return false;
  13045. }
  13046. parseClassMember(classBody, member, state) {
  13047. const isStatic = this.isContextual(106);
  13048. if (isStatic) {
  13049. if (this.parseClassMemberFromModifier(classBody, member)) {
  13050. return;
  13051. }
  13052. if (this.eat(5)) {
  13053. this.parseClassStaticBlock(classBody, member);
  13054. return;
  13055. }
  13056. }
  13057. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13058. }
  13059. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13060. const publicMethod = member;
  13061. const privateMethod = member;
  13062. const publicProp = member;
  13063. const privateProp = member;
  13064. const accessorProp = member;
  13065. const method = publicMethod;
  13066. const publicMember = publicMethod;
  13067. member.static = isStatic;
  13068. this.parsePropertyNamePrefixOperator(member);
  13069. if (this.eat(55)) {
  13070. method.kind = "method";
  13071. const isPrivateName = this.match(138);
  13072. this.parseClassElementName(method);
  13073. if (isPrivateName) {
  13074. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13075. return;
  13076. }
  13077. if (this.isNonstaticConstructor(publicMethod)) {
  13078. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13079. }
  13080. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13081. return;
  13082. }
  13083. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13084. const key = this.parseClassElementName(member);
  13085. const maybeContextualKw = isContextual ? key.name : null;
  13086. const isPrivate = this.isPrivateName(key);
  13087. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13088. this.parsePostMemberNameModifiers(publicMember);
  13089. if (this.isClassMethod()) {
  13090. method.kind = "method";
  13091. if (isPrivate) {
  13092. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13093. return;
  13094. }
  13095. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13096. let allowsDirectSuper = false;
  13097. if (isConstructor) {
  13098. publicMethod.kind = "constructor";
  13099. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13100. this.raise(Errors.DuplicateConstructor, key);
  13101. }
  13102. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13103. this.raise(Errors.OverrideOnConstructor, key);
  13104. }
  13105. state.hadConstructor = true;
  13106. allowsDirectSuper = state.hadSuperClass;
  13107. }
  13108. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13109. } else if (this.isClassProperty()) {
  13110. if (isPrivate) {
  13111. this.pushClassPrivateProperty(classBody, privateProp);
  13112. } else {
  13113. this.pushClassProperty(classBody, publicProp);
  13114. }
  13115. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13116. this.resetPreviousNodeTrailingComments(key);
  13117. const isGenerator = this.eat(55);
  13118. if (publicMember.optional) {
  13119. this.unexpected(maybeQuestionTokenStartLoc);
  13120. }
  13121. method.kind = "method";
  13122. const isPrivate = this.match(138);
  13123. this.parseClassElementName(method);
  13124. this.parsePostMemberNameModifiers(publicMember);
  13125. if (isPrivate) {
  13126. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13127. } else {
  13128. if (this.isNonstaticConstructor(publicMethod)) {
  13129. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13130. }
  13131. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13132. }
  13133. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13134. this.resetPreviousNodeTrailingComments(key);
  13135. method.kind = maybeContextualKw;
  13136. const isPrivate = this.match(138);
  13137. this.parseClassElementName(publicMethod);
  13138. if (isPrivate) {
  13139. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13140. } else {
  13141. if (this.isNonstaticConstructor(publicMethod)) {
  13142. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13143. }
  13144. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13145. }
  13146. this.checkGetterSetterParams(publicMethod);
  13147. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13148. this.expectPlugin("decoratorAutoAccessors");
  13149. this.resetPreviousNodeTrailingComments(key);
  13150. const isPrivate = this.match(138);
  13151. this.parseClassElementName(publicProp);
  13152. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13153. } else if (this.isLineTerminator()) {
  13154. if (isPrivate) {
  13155. this.pushClassPrivateProperty(classBody, privateProp);
  13156. } else {
  13157. this.pushClassProperty(classBody, publicProp);
  13158. }
  13159. } else {
  13160. this.unexpected();
  13161. }
  13162. }
  13163. parseClassElementName(member) {
  13164. const {
  13165. type,
  13166. value
  13167. } = this.state;
  13168. if ((type === 132 || type === 133) && member.static && value === "prototype") {
  13169. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13170. }
  13171. if (type === 138) {
  13172. if (value === "constructor") {
  13173. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13174. }
  13175. const key = this.parsePrivateName();
  13176. member.key = key;
  13177. return key;
  13178. }
  13179. this.parsePropertyName(member);
  13180. return member.key;
  13181. }
  13182. parseClassStaticBlock(classBody, member) {
  13183. var _member$decorators;
  13184. this.scope.enter(64 | 128 | 16);
  13185. const oldLabels = this.state.labels;
  13186. this.state.labels = [];
  13187. this.prodParam.enter(0);
  13188. const body = member.body = [];
  13189. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13190. this.prodParam.exit();
  13191. this.scope.exit();
  13192. this.state.labels = oldLabels;
  13193. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13194. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13195. this.raise(Errors.DecoratorStaticBlock, member);
  13196. }
  13197. }
  13198. pushClassProperty(classBody, prop) {
  13199. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13200. this.raise(Errors.ConstructorClassField, prop.key);
  13201. }
  13202. classBody.body.push(this.parseClassProperty(prop));
  13203. }
  13204. pushClassPrivateProperty(classBody, prop) {
  13205. const node = this.parseClassPrivateProperty(prop);
  13206. classBody.body.push(node);
  13207. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13208. }
  13209. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13210. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13211. this.raise(Errors.ConstructorClassField, prop.key);
  13212. }
  13213. const node = this.parseClassAccessorProperty(prop);
  13214. classBody.body.push(node);
  13215. if (isPrivate) {
  13216. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13217. }
  13218. }
  13219. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13220. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13221. }
  13222. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13223. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13224. classBody.body.push(node);
  13225. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13226. this.declareClassPrivateMethodInScope(node, kind);
  13227. }
  13228. declareClassPrivateMethodInScope(node, kind) {
  13229. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13230. }
  13231. parsePostMemberNameModifiers(methodOrProp) {}
  13232. parseClassPrivateProperty(node) {
  13233. this.parseInitializer(node);
  13234. this.semicolon();
  13235. return this.finishNode(node, "ClassPrivateProperty");
  13236. }
  13237. parseClassProperty(node) {
  13238. this.parseInitializer(node);
  13239. this.semicolon();
  13240. return this.finishNode(node, "ClassProperty");
  13241. }
  13242. parseClassAccessorProperty(node) {
  13243. this.parseInitializer(node);
  13244. this.semicolon();
  13245. return this.finishNode(node, "ClassAccessorProperty");
  13246. }
  13247. parseInitializer(node) {
  13248. this.scope.enter(64 | 16);
  13249. this.expressionScope.enter(newExpressionScope());
  13250. this.prodParam.enter(0);
  13251. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13252. this.expressionScope.exit();
  13253. this.prodParam.exit();
  13254. this.scope.exit();
  13255. }
  13256. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13257. if (tokenIsIdentifier(this.state.type)) {
  13258. node.id = this.parseIdentifier();
  13259. if (isStatement) {
  13260. this.declareNameFromIdentifier(node.id, bindingType);
  13261. }
  13262. } else {
  13263. if (optionalId || !isStatement) {
  13264. node.id = null;
  13265. } else {
  13266. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13267. }
  13268. }
  13269. }
  13270. parseClassSuper(node) {
  13271. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13272. }
  13273. parseExport(node, decorators) {
  13274. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13275. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13276. const parseAfterDefault = !hasDefault || this.eat(12);
  13277. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13278. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13279. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13280. const isFromRequired = hasDefault || hasStar;
  13281. if (hasStar && !hasNamespace) {
  13282. if (hasDefault) this.unexpected();
  13283. if (decorators) {
  13284. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13285. }
  13286. this.parseExportFrom(node, true);
  13287. return this.finishNode(node, "ExportAllDeclaration");
  13288. }
  13289. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13290. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13291. this.unexpected(null, 5);
  13292. }
  13293. if (hasNamespace && parseAfterNamespace) {
  13294. this.unexpected(null, 98);
  13295. }
  13296. let hasDeclaration;
  13297. if (isFromRequired || hasSpecifiers) {
  13298. hasDeclaration = false;
  13299. if (decorators) {
  13300. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13301. }
  13302. this.parseExportFrom(node, isFromRequired);
  13303. } else {
  13304. hasDeclaration = this.maybeParseExportDeclaration(node);
  13305. }
  13306. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13307. var _node2$declaration;
  13308. const node2 = node;
  13309. this.checkExport(node2, true, false, !!node2.source);
  13310. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13311. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13312. } else if (decorators) {
  13313. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13314. }
  13315. return this.finishNode(node2, "ExportNamedDeclaration");
  13316. }
  13317. if (this.eat(65)) {
  13318. const node2 = node;
  13319. const decl = this.parseExportDefaultExpression();
  13320. node2.declaration = decl;
  13321. if (decl.type === "ClassDeclaration") {
  13322. this.maybeTakeDecorators(decorators, decl, node2);
  13323. } else if (decorators) {
  13324. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13325. }
  13326. this.checkExport(node2, true, true);
  13327. return this.finishNode(node2, "ExportDefaultDeclaration");
  13328. }
  13329. this.unexpected(null, 5);
  13330. }
  13331. eatExportStar(node) {
  13332. return this.eat(55);
  13333. }
  13334. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13335. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13336. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13337. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13338. const specifier = this.startNodeAtNode(id);
  13339. specifier.exported = id;
  13340. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13341. return true;
  13342. }
  13343. return false;
  13344. }
  13345. maybeParseExportNamespaceSpecifier(node) {
  13346. if (this.isContextual(93)) {
  13347. var _ref, _ref$specifiers;
  13348. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13349. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13350. this.next();
  13351. specifier.exported = this.parseModuleExportName();
  13352. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13353. return true;
  13354. }
  13355. return false;
  13356. }
  13357. maybeParseExportNamedSpecifiers(node) {
  13358. if (this.match(5)) {
  13359. const node2 = node;
  13360. if (!node2.specifiers) node2.specifiers = [];
  13361. const isTypeExport = node2.exportKind === "type";
  13362. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13363. node2.source = null;
  13364. node2.declaration = null;
  13365. if (this.hasPlugin("importAssertions")) {
  13366. node2.assertions = [];
  13367. }
  13368. return true;
  13369. }
  13370. return false;
  13371. }
  13372. maybeParseExportDeclaration(node) {
  13373. if (this.shouldParseExportDeclaration()) {
  13374. node.specifiers = [];
  13375. node.source = null;
  13376. if (this.hasPlugin("importAssertions")) {
  13377. node.assertions = [];
  13378. }
  13379. node.declaration = this.parseExportDeclaration(node);
  13380. return true;
  13381. }
  13382. return false;
  13383. }
  13384. isAsyncFunction() {
  13385. if (!this.isContextual(95)) return false;
  13386. const next = this.nextTokenInLineStart();
  13387. return this.isUnparsedContextual(next, "function");
  13388. }
  13389. parseExportDefaultExpression() {
  13390. const expr = this.startNode();
  13391. if (this.match(68)) {
  13392. this.next();
  13393. return this.parseFunction(expr, 1 | 4);
  13394. } else if (this.isAsyncFunction()) {
  13395. this.next();
  13396. this.next();
  13397. return this.parseFunction(expr, 1 | 4 | 8);
  13398. }
  13399. if (this.match(80)) {
  13400. return this.parseClass(expr, true, true);
  13401. }
  13402. if (this.match(26)) {
  13403. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13404. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13405. }
  13406. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13407. }
  13408. if (this.match(75) || this.match(74) || this.isLet()) {
  13409. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13410. }
  13411. const res = this.parseMaybeAssignAllowIn();
  13412. this.semicolon();
  13413. return res;
  13414. }
  13415. parseExportDeclaration(node) {
  13416. if (this.match(80)) {
  13417. const node = this.parseClass(this.startNode(), true, false);
  13418. return node;
  13419. }
  13420. return this.parseStatementListItem();
  13421. }
  13422. isExportDefaultSpecifier() {
  13423. const {
  13424. type
  13425. } = this.state;
  13426. if (tokenIsIdentifier(type)) {
  13427. if (type === 95 && !this.state.containsEsc || type === 100) {
  13428. return false;
  13429. }
  13430. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13431. const {
  13432. type: nextType
  13433. } = this.lookahead();
  13434. if (tokenIsIdentifier(nextType) && nextType !== 98 || nextType === 5) {
  13435. this.expectOnePlugin(["flow", "typescript"]);
  13436. return false;
  13437. }
  13438. }
  13439. } else if (!this.match(65)) {
  13440. return false;
  13441. }
  13442. const next = this.nextTokenStart();
  13443. const hasFrom = this.isUnparsedContextual(next, "from");
  13444. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13445. return true;
  13446. }
  13447. if (this.match(65) && hasFrom) {
  13448. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13449. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13450. }
  13451. return false;
  13452. }
  13453. parseExportFrom(node, expect) {
  13454. if (this.eatContextual(98)) {
  13455. node.source = this.parseImportSource();
  13456. this.checkExport(node);
  13457. this.maybeParseImportAttributes(node);
  13458. this.checkJSONModuleImport(node);
  13459. } else if (expect) {
  13460. this.unexpected();
  13461. }
  13462. this.semicolon();
  13463. }
  13464. shouldParseExportDeclaration() {
  13465. const {
  13466. type
  13467. } = this.state;
  13468. if (type === 26) {
  13469. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13470. if (this.hasPlugin("decorators")) {
  13471. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13472. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13473. }
  13474. return true;
  13475. }
  13476. }
  13477. if (this.isContextual(107)) {
  13478. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13479. return true;
  13480. }
  13481. if (this.isContextual(96) && this.startsAwaitUsing()) {
  13482. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13483. return true;
  13484. }
  13485. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13486. }
  13487. checkExport(node, checkNames, isDefault, isFrom) {
  13488. if (checkNames) {
  13489. var _node$specifiers;
  13490. if (isDefault) {
  13491. this.checkDuplicateExports(node, "default");
  13492. if (this.hasPlugin("exportDefaultFrom")) {
  13493. var _declaration$extra;
  13494. const declaration = node.declaration;
  13495. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13496. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  13497. }
  13498. }
  13499. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  13500. for (const specifier of node.specifiers) {
  13501. const {
  13502. exported
  13503. } = specifier;
  13504. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13505. this.checkDuplicateExports(specifier, exportName);
  13506. if (!isFrom && specifier.local) {
  13507. const {
  13508. local
  13509. } = specifier;
  13510. if (local.type !== "Identifier") {
  13511. this.raise(Errors.ExportBindingIsString, specifier, {
  13512. localName: local.value,
  13513. exportName
  13514. });
  13515. } else {
  13516. this.checkReservedWord(local.name, local.loc.start, true, false);
  13517. this.scope.checkLocalExport(local);
  13518. }
  13519. }
  13520. }
  13521. } else if (node.declaration) {
  13522. const decl = node.declaration;
  13523. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  13524. const {
  13525. id
  13526. } = decl;
  13527. if (!id) throw new Error("Assertion failure");
  13528. this.checkDuplicateExports(node, id.name);
  13529. } else if (decl.type === "VariableDeclaration") {
  13530. for (const declaration of decl.declarations) {
  13531. this.checkDeclaration(declaration.id);
  13532. }
  13533. }
  13534. }
  13535. }
  13536. }
  13537. checkDeclaration(node) {
  13538. if (node.type === "Identifier") {
  13539. this.checkDuplicateExports(node, node.name);
  13540. } else if (node.type === "ObjectPattern") {
  13541. for (const prop of node.properties) {
  13542. this.checkDeclaration(prop);
  13543. }
  13544. } else if (node.type === "ArrayPattern") {
  13545. for (const elem of node.elements) {
  13546. if (elem) {
  13547. this.checkDeclaration(elem);
  13548. }
  13549. }
  13550. } else if (node.type === "ObjectProperty") {
  13551. this.checkDeclaration(node.value);
  13552. } else if (node.type === "RestElement") {
  13553. this.checkDeclaration(node.argument);
  13554. } else if (node.type === "AssignmentPattern") {
  13555. this.checkDeclaration(node.left);
  13556. }
  13557. }
  13558. checkDuplicateExports(node, exportName) {
  13559. if (this.exportedIdentifiers.has(exportName)) {
  13560. if (exportName === "default") {
  13561. this.raise(Errors.DuplicateDefaultExport, node);
  13562. } else {
  13563. this.raise(Errors.DuplicateExport, node, {
  13564. exportName
  13565. });
  13566. }
  13567. }
  13568. this.exportedIdentifiers.add(exportName);
  13569. }
  13570. parseExportSpecifiers(isInTypeExport) {
  13571. const nodes = [];
  13572. let first = true;
  13573. this.expect(5);
  13574. while (!this.eat(8)) {
  13575. if (first) {
  13576. first = false;
  13577. } else {
  13578. this.expect(12);
  13579. if (this.eat(8)) break;
  13580. }
  13581. const isMaybeTypeOnly = this.isContextual(130);
  13582. const isString = this.match(133);
  13583. const node = this.startNode();
  13584. node.local = this.parseModuleExportName();
  13585. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13586. }
  13587. return nodes;
  13588. }
  13589. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  13590. if (this.eatContextual(93)) {
  13591. node.exported = this.parseModuleExportName();
  13592. } else if (isString) {
  13593. node.exported = cloneStringLiteral(node.local);
  13594. } else if (!node.exported) {
  13595. node.exported = cloneIdentifier(node.local);
  13596. }
  13597. return this.finishNode(node, "ExportSpecifier");
  13598. }
  13599. parseModuleExportName() {
  13600. if (this.match(133)) {
  13601. const result = this.parseStringLiteral(this.state.value);
  13602. const surrogate = result.value.match(loneSurrogate);
  13603. if (surrogate) {
  13604. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  13605. surrogateCharCode: surrogate[0].charCodeAt(0)
  13606. });
  13607. }
  13608. return result;
  13609. }
  13610. return this.parseIdentifier(true);
  13611. }
  13612. isJSONModuleImport(node) {
  13613. if (node.assertions != null) {
  13614. return node.assertions.some(({
  13615. key,
  13616. value
  13617. }) => {
  13618. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  13619. });
  13620. }
  13621. return false;
  13622. }
  13623. checkImportReflection(node) {
  13624. const {
  13625. specifiers
  13626. } = node;
  13627. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  13628. if (node.phase === "source") {
  13629. if (singleBindingType !== "ImportDefaultSpecifier") {
  13630. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  13631. }
  13632. } else if (node.phase === "defer") {
  13633. if (singleBindingType !== "ImportNamespaceSpecifier") {
  13634. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  13635. }
  13636. } else if (node.module) {
  13637. var _node$assertions;
  13638. if (singleBindingType !== "ImportDefaultSpecifier") {
  13639. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  13640. }
  13641. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  13642. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  13643. }
  13644. }
  13645. }
  13646. checkJSONModuleImport(node) {
  13647. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  13648. const {
  13649. specifiers
  13650. } = node;
  13651. if (specifiers != null) {
  13652. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  13653. let imported;
  13654. if (specifier.type === "ExportSpecifier") {
  13655. imported = specifier.local;
  13656. } else if (specifier.type === "ImportSpecifier") {
  13657. imported = specifier.imported;
  13658. }
  13659. if (imported !== undefined) {
  13660. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  13661. }
  13662. });
  13663. if (nonDefaultNamedSpecifier !== undefined) {
  13664. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  13665. }
  13666. }
  13667. }
  13668. }
  13669. isPotentialImportPhase(isExport) {
  13670. if (isExport) return false;
  13671. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  13672. }
  13673. applyImportPhase(node, isExport, phase, loc) {
  13674. if (isExport) {
  13675. return;
  13676. }
  13677. if (phase === "module") {
  13678. this.expectPlugin("importReflection", loc);
  13679. node.module = true;
  13680. } else if (this.hasPlugin("importReflection")) {
  13681. node.module = false;
  13682. }
  13683. if (phase === "source") {
  13684. this.expectPlugin("sourcePhaseImports", loc);
  13685. node.phase = "source";
  13686. } else if (phase === "defer") {
  13687. this.expectPlugin("deferredImportEvaluation", loc);
  13688. node.phase = "defer";
  13689. } else if (this.hasPlugin("sourcePhaseImports")) {
  13690. node.phase = null;
  13691. }
  13692. }
  13693. parseMaybeImportPhase(node, isExport) {
  13694. if (!this.isPotentialImportPhase(isExport)) {
  13695. this.applyImportPhase(node, isExport, null);
  13696. return null;
  13697. }
  13698. const phaseIdentifier = this.parseIdentifier(true);
  13699. const {
  13700. type
  13701. } = this.state;
  13702. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  13703. if (isImportPhase) {
  13704. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  13705. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  13706. return null;
  13707. } else {
  13708. this.applyImportPhase(node, isExport, null);
  13709. return phaseIdentifier;
  13710. }
  13711. }
  13712. isPrecedingIdImportPhase(phase) {
  13713. const {
  13714. type
  13715. } = this.state;
  13716. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  13717. }
  13718. parseImport(node) {
  13719. if (this.match(133)) {
  13720. return this.parseImportSourceAndAttributes(node);
  13721. }
  13722. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  13723. }
  13724. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  13725. node.specifiers = [];
  13726. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  13727. const parseNext = !hasDefault || this.eat(12);
  13728. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  13729. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  13730. this.expectContextual(98);
  13731. return this.parseImportSourceAndAttributes(node);
  13732. }
  13733. parseImportSourceAndAttributes(node) {
  13734. var _node$specifiers2;
  13735. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  13736. node.source = this.parseImportSource();
  13737. this.maybeParseImportAttributes(node);
  13738. this.checkImportReflection(node);
  13739. this.checkJSONModuleImport(node);
  13740. this.semicolon();
  13741. return this.finishNode(node, "ImportDeclaration");
  13742. }
  13743. parseImportSource() {
  13744. if (!this.match(133)) this.unexpected();
  13745. return this.parseExprAtom();
  13746. }
  13747. parseImportSpecifierLocal(node, specifier, type) {
  13748. specifier.local = this.parseIdentifier();
  13749. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  13750. }
  13751. finishImportSpecifier(specifier, type, bindingType = 8201) {
  13752. this.checkLVal(specifier.local, {
  13753. in: {
  13754. type
  13755. },
  13756. binding: bindingType
  13757. });
  13758. return this.finishNode(specifier, type);
  13759. }
  13760. parseImportAttributes() {
  13761. this.expect(5);
  13762. const attrs = [];
  13763. const attrNames = new Set();
  13764. do {
  13765. if (this.match(8)) {
  13766. break;
  13767. }
  13768. const node = this.startNode();
  13769. const keyName = this.state.value;
  13770. if (attrNames.has(keyName)) {
  13771. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  13772. key: keyName
  13773. });
  13774. }
  13775. attrNames.add(keyName);
  13776. if (this.match(133)) {
  13777. node.key = this.parseStringLiteral(keyName);
  13778. } else {
  13779. node.key = this.parseIdentifier(true);
  13780. }
  13781. this.expect(14);
  13782. if (!this.match(133)) {
  13783. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  13784. }
  13785. node.value = this.parseStringLiteral(this.state.value);
  13786. attrs.push(this.finishNode(node, "ImportAttribute"));
  13787. } while (this.eat(12));
  13788. this.expect(8);
  13789. return attrs;
  13790. }
  13791. parseModuleAttributes() {
  13792. const attrs = [];
  13793. const attributes = new Set();
  13794. do {
  13795. const node = this.startNode();
  13796. node.key = this.parseIdentifier(true);
  13797. if (node.key.name !== "type") {
  13798. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  13799. }
  13800. if (attributes.has(node.key.name)) {
  13801. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  13802. key: node.key.name
  13803. });
  13804. }
  13805. attributes.add(node.key.name);
  13806. this.expect(14);
  13807. if (!this.match(133)) {
  13808. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  13809. }
  13810. node.value = this.parseStringLiteral(this.state.value);
  13811. attrs.push(this.finishNode(node, "ImportAttribute"));
  13812. } while (this.eat(12));
  13813. return attrs;
  13814. }
  13815. maybeParseImportAttributes(node) {
  13816. let attributes;
  13817. let useWith = false;
  13818. if (this.match(76)) {
  13819. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  13820. return;
  13821. }
  13822. this.next();
  13823. {
  13824. if (this.hasPlugin("moduleAttributes")) {
  13825. attributes = this.parseModuleAttributes();
  13826. } else {
  13827. this.expectImportAttributesPlugin();
  13828. attributes = this.parseImportAttributes();
  13829. }
  13830. }
  13831. useWith = true;
  13832. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  13833. if (this.hasPlugin("importAttributes")) {
  13834. if (this.getPluginOption("importAttributes", "deprecatedAssertSyntax") !== true) {
  13835. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  13836. }
  13837. this.addExtra(node, "deprecatedAssertSyntax", true);
  13838. } else {
  13839. this.expectOnePlugin(["importAttributes", "importAssertions"]);
  13840. }
  13841. this.next();
  13842. attributes = this.parseImportAttributes();
  13843. } else if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  13844. attributes = [];
  13845. } else {
  13846. if (this.hasPlugin("moduleAttributes")) {
  13847. attributes = [];
  13848. } else return;
  13849. }
  13850. if (!useWith && this.hasPlugin("importAssertions")) {
  13851. node.assertions = attributes;
  13852. } else {
  13853. node.attributes = attributes;
  13854. }
  13855. }
  13856. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  13857. if (maybeDefaultIdentifier) {
  13858. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  13859. specifier.local = maybeDefaultIdentifier;
  13860. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  13861. return true;
  13862. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  13863. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  13864. return true;
  13865. }
  13866. return false;
  13867. }
  13868. maybeParseStarImportSpecifier(node) {
  13869. if (this.match(55)) {
  13870. const specifier = this.startNode();
  13871. this.next();
  13872. this.expectContextual(93);
  13873. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  13874. return true;
  13875. }
  13876. return false;
  13877. }
  13878. parseNamedImportSpecifiers(node) {
  13879. let first = true;
  13880. this.expect(5);
  13881. while (!this.eat(8)) {
  13882. if (first) {
  13883. first = false;
  13884. } else {
  13885. if (this.eat(14)) {
  13886. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  13887. }
  13888. this.expect(12);
  13889. if (this.eat(8)) break;
  13890. }
  13891. const specifier = this.startNode();
  13892. const importedIsString = this.match(133);
  13893. const isMaybeTypeOnly = this.isContextual(130);
  13894. specifier.imported = this.parseModuleExportName();
  13895. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  13896. node.specifiers.push(importSpecifier);
  13897. }
  13898. }
  13899. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  13900. if (this.eatContextual(93)) {
  13901. specifier.local = this.parseIdentifier();
  13902. } else {
  13903. const {
  13904. imported
  13905. } = specifier;
  13906. if (importedIsString) {
  13907. throw this.raise(Errors.ImportBindingIsString, specifier, {
  13908. importName: imported.value
  13909. });
  13910. }
  13911. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  13912. if (!specifier.local) {
  13913. specifier.local = cloneIdentifier(imported);
  13914. }
  13915. }
  13916. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  13917. }
  13918. isThisParam(param) {
  13919. return param.type === "Identifier" && param.name === "this";
  13920. }
  13921. }
  13922. class Parser extends StatementParser {
  13923. constructor(options, input) {
  13924. options = getOptions(options);
  13925. super(options, input);
  13926. this.options = options;
  13927. this.initializeScopes();
  13928. this.plugins = pluginsMap(this.options.plugins);
  13929. this.filename = options.sourceFilename;
  13930. }
  13931. getScopeHandler() {
  13932. return ScopeHandler;
  13933. }
  13934. parse() {
  13935. this.enterInitialScopes();
  13936. const file = this.startNode();
  13937. const program = this.startNode();
  13938. this.nextToken();
  13939. file.errors = null;
  13940. this.parseTopLevel(file, program);
  13941. file.errors = this.state.errors;
  13942. file.comments.length = this.state.commentsLen;
  13943. return file;
  13944. }
  13945. }
  13946. function pluginsMap(plugins) {
  13947. const pluginMap = new Map();
  13948. for (const plugin of plugins) {
  13949. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  13950. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  13951. }
  13952. return pluginMap;
  13953. }
  13954. function parse(input, options) {
  13955. var _options;
  13956. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  13957. options = Object.assign({}, options);
  13958. try {
  13959. options.sourceType = "module";
  13960. const parser = getParser(options, input);
  13961. const ast = parser.parse();
  13962. if (parser.sawUnambiguousESM) {
  13963. return ast;
  13964. }
  13965. if (parser.ambiguousScriptDifferentAst) {
  13966. try {
  13967. options.sourceType = "script";
  13968. return getParser(options, input).parse();
  13969. } catch (_unused) {}
  13970. } else {
  13971. ast.program.sourceType = "script";
  13972. }
  13973. return ast;
  13974. } catch (moduleError) {
  13975. try {
  13976. options.sourceType = "script";
  13977. return getParser(options, input).parse();
  13978. } catch (_unused2) {}
  13979. throw moduleError;
  13980. }
  13981. } else {
  13982. return getParser(options, input).parse();
  13983. }
  13984. }
  13985. function parseExpression(input, options) {
  13986. const parser = getParser(options, input);
  13987. if (parser.options.strictMode) {
  13988. parser.state.strict = true;
  13989. }
  13990. return parser.getExpression();
  13991. }
  13992. function generateExportedTokenTypes(internalTokenTypes) {
  13993. const tokenTypes = {};
  13994. for (const typeName of Object.keys(internalTokenTypes)) {
  13995. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  13996. }
  13997. return tokenTypes;
  13998. }
  13999. const tokTypes = generateExportedTokenTypes(tt);
  14000. function getParser(options, input) {
  14001. let cls = Parser;
  14002. if (options != null && options.plugins) {
  14003. validatePlugins(options.plugins);
  14004. cls = getParserClass(options.plugins);
  14005. }
  14006. return new cls(options, input);
  14007. }
  14008. const parserClassCache = {};
  14009. function getParserClass(pluginsFromOptions) {
  14010. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  14011. const key = pluginList.join("/");
  14012. let cls = parserClassCache[key];
  14013. if (!cls) {
  14014. cls = Parser;
  14015. for (const plugin of pluginList) {
  14016. cls = mixinPlugins[plugin](cls);
  14017. }
  14018. parserClassCache[key] = cls;
  14019. }
  14020. return cls;
  14021. }
  14022. exports.parse = parse;
  14023. exports.parseExpression = parseExpression;
  14024. exports.tokTypes = tokTypes;
  14025. //# sourceMappingURL=index.js.map