index.js 475 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. function _objectWithoutPropertiesLoose(r, e) {
  6. if (null == r) return {};
  7. var t = {};
  8. for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
  9. if (e.includes(n)) continue;
  10. t[n] = r[n];
  11. }
  12. return t;
  13. }
  14. class Position {
  15. constructor(line, col, index) {
  16. this.line = void 0;
  17. this.column = void 0;
  18. this.index = void 0;
  19. this.line = line;
  20. this.column = col;
  21. this.index = index;
  22. }
  23. }
  24. class SourceLocation {
  25. constructor(start, end) {
  26. this.start = void 0;
  27. this.end = void 0;
  28. this.filename = void 0;
  29. this.identifierName = void 0;
  30. this.start = start;
  31. this.end = end;
  32. }
  33. }
  34. function createPositionWithColumnOffset(position, columnOffset) {
  35. const {
  36. line,
  37. column,
  38. index
  39. } = position;
  40. return new Position(line, column + columnOffset, index + columnOffset);
  41. }
  42. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  43. var ModuleErrors = {
  44. ImportMetaOutsideModule: {
  45. message: `import.meta may appear only with 'sourceType: "module"'`,
  46. code
  47. },
  48. ImportOutsideModule: {
  49. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  50. code
  51. }
  52. };
  53. const NodeDescriptions = {
  54. ArrayPattern: "array destructuring pattern",
  55. AssignmentExpression: "assignment expression",
  56. AssignmentPattern: "assignment expression",
  57. ArrowFunctionExpression: "arrow function expression",
  58. ConditionalExpression: "conditional expression",
  59. CatchClause: "catch clause",
  60. ForOfStatement: "for-of statement",
  61. ForInStatement: "for-in statement",
  62. ForStatement: "for-loop",
  63. FormalParameters: "function parameter list",
  64. Identifier: "identifier",
  65. ImportSpecifier: "import specifier",
  66. ImportDefaultSpecifier: "import default specifier",
  67. ImportNamespaceSpecifier: "import namespace specifier",
  68. ObjectPattern: "object destructuring pattern",
  69. ParenthesizedExpression: "parenthesized expression",
  70. RestElement: "rest element",
  71. UpdateExpression: {
  72. true: "prefix operation",
  73. false: "postfix operation"
  74. },
  75. VariableDeclarator: "variable declaration",
  76. YieldExpression: "yield expression"
  77. };
  78. const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type];
  79. var StandardErrors = {
  80. AccessorIsGenerator: ({
  81. kind
  82. }) => `A ${kind}ter cannot be a generator.`,
  83. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  84. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  85. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  86. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  87. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  88. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  89. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  90. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  91. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  92. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  93. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  94. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  95. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  96. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  97. ConstructorIsAsync: "Constructor can't be an async function.",
  98. ConstructorIsGenerator: "Constructor can't be a generator.",
  99. DeclarationMissingInitializer: ({
  100. kind
  101. }) => `Missing initializer in ${kind} declaration.`,
  102. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  103. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  104. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  105. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  106. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  107. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  108. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  109. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  110. DeletePrivateField: "Deleting a private field is not allowed.",
  111. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  112. DuplicateConstructor: "Duplicate constructor in the same class.",
  113. DuplicateDefaultExport: "Only one default export allowed per module.",
  114. DuplicateExport: ({
  115. exportName
  116. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  117. DuplicateProto: "Redefinition of __proto__ property.",
  118. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  119. DynamicImportPhaseRequiresImportExpressions: ({
  120. phase
  121. }) => `'import.${phase}(...)' can only be parsed when using the 'createImportExpressions' option.`,
  122. ElementAfterRest: "Rest element must be last element.",
  123. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  124. ExportBindingIsString: ({
  125. localName,
  126. exportName
  127. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  128. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  129. ForInOfLoopInitializer: ({
  130. type
  131. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  132. ForInUsing: "For-in loop may not start with 'using' declaration.",
  133. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  134. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  135. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  136. IllegalBreakContinue: ({
  137. type
  138. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  139. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  140. IllegalReturn: "'return' outside of function.",
  141. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedImportAssert` parser plugin to suppress this error.",
  142. ImportBindingIsString: ({
  143. importName
  144. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  145. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  146. ImportCallNotNewExpression: "Cannot use new with import(...).",
  147. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  148. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  149. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  150. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  151. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  152. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  153. InvalidCodePoint: "Code point out of bounds.",
  154. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  155. InvalidDecimal: "Invalid decimal.",
  156. InvalidDigit: ({
  157. radix
  158. }) => `Expected number in radix ${radix}.`,
  159. InvalidEscapeSequence: "Bad character escape sequence.",
  160. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  161. InvalidEscapedReservedWord: ({
  162. reservedWord
  163. }) => `Escape sequence in keyword ${reservedWord}.`,
  164. InvalidIdentifier: ({
  165. identifierName
  166. }) => `Invalid identifier ${identifierName}.`,
  167. InvalidLhs: ({
  168. ancestor
  169. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  170. InvalidLhsBinding: ({
  171. ancestor
  172. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  173. InvalidLhsOptionalChaining: ({
  174. ancestor
  175. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  176. InvalidNumber: "Invalid number.",
  177. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  178. InvalidOrUnexpectedToken: ({
  179. unexpected
  180. }) => `Unexpected character '${unexpected}'.`,
  181. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  182. InvalidPrivateFieldResolution: ({
  183. identifierName
  184. }) => `Private name #${identifierName} is not defined.`,
  185. InvalidPropertyBindingPattern: "Binding member expression.",
  186. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  187. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  188. LabelRedeclaration: ({
  189. labelName
  190. }) => `Label '${labelName}' is already declared.`,
  191. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  192. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  193. MalformedRegExpFlags: "Invalid regular expression flag.",
  194. MissingClassName: "A class name is required.",
  195. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  196. MissingSemicolon: "Missing semicolon.",
  197. MissingPlugin: ({
  198. missingPlugin
  199. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  200. MissingOneOfPlugins: ({
  201. missingPlugin
  202. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  203. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  204. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  205. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  206. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  207. ModuleAttributesWithDuplicateKeys: ({
  208. key
  209. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  210. ModuleExportNameHasLoneSurrogate: ({
  211. surrogateCharCode
  212. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  213. ModuleExportUndefined: ({
  214. localName
  215. }) => `Export '${localName}' is not defined.`,
  216. MultipleDefaultsInSwitch: "Multiple default clauses.",
  217. NewlineAfterThrow: "Illegal newline after throw.",
  218. NoCatchOrFinally: "Missing catch or finally clause.",
  219. NumberIdentifier: "Identifier directly after number.",
  220. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  221. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  222. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  223. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  224. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  225. ParamDupe: "Argument name clash.",
  226. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  227. PatternHasMethod: "Object pattern can't contain methods.",
  228. PrivateInExpectedIn: ({
  229. identifierName
  230. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  231. PrivateNameRedeclaration: ({
  232. identifierName
  233. }) => `Duplicate private name #${identifierName}.`,
  234. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  235. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  236. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  237. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  238. RestTrailingComma: "Unexpected trailing comma after rest element.",
  239. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  240. 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.",
  241. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  242. StaticPrototype: "Classes may not have static property named prototype.",
  243. 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?",
  244. SuperPrivateField: "Private fields can't be accessed on super.",
  245. TrailingDecorator: "Decorators must be attached to a class element.",
  246. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  247. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  248. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  249. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  250. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  251. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  252. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  253. UnexpectedKeyword: ({
  254. keyword
  255. }) => `Unexpected keyword '${keyword}'.`,
  256. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  257. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  258. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  259. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  260. UnexpectedPrivateField: "Unexpected private name.",
  261. UnexpectedReservedWord: ({
  262. reservedWord
  263. }) => `Unexpected reserved word '${reservedWord}'.`,
  264. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  265. UnexpectedToken: ({
  266. expected,
  267. unexpected
  268. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  269. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  270. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  271. UnsupportedBind: "Binding should be performed on object property.",
  272. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  273. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  274. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  275. UnsupportedMetaProperty: ({
  276. target,
  277. onlyValidPropertyName
  278. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  279. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  280. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  281. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  282. UnterminatedComment: "Unterminated comment.",
  283. UnterminatedRegExp: "Unterminated regular expression.",
  284. UnterminatedString: "Unterminated string constant.",
  285. UnterminatedTemplate: "Unterminated template.",
  286. UsingDeclarationExport: "Using declaration cannot be exported.",
  287. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  288. VarRedeclaration: ({
  289. identifierName
  290. }) => `Identifier '${identifierName}' has already been declared.`,
  291. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  292. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  293. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  294. };
  295. var StrictModeErrors = {
  296. StrictDelete: "Deleting local variable in strict mode.",
  297. StrictEvalArguments: ({
  298. referenceName
  299. }) => `Assigning to '${referenceName}' in strict mode.`,
  300. StrictEvalArgumentsBinding: ({
  301. bindingName
  302. }) => `Binding '${bindingName}' in strict mode.`,
  303. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  304. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  305. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  306. StrictWith: "'with' in strict mode."
  307. };
  308. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  309. var PipelineOperatorErrors = {
  310. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  311. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  312. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  313. PipeTopicUnconfiguredToken: ({
  314. token
  315. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  316. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  317. PipeUnparenthesizedBody: ({
  318. type
  319. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  320. type
  321. })}; please wrap it in parentheses.`,
  322. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  323. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  324. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  325. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  326. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  327. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  328. };
  329. const _excluded = ["message"];
  330. function defineHidden(obj, key, value) {
  331. Object.defineProperty(obj, key, {
  332. enumerable: false,
  333. configurable: true,
  334. value
  335. });
  336. }
  337. function toParseErrorConstructor({
  338. toMessage,
  339. code,
  340. reasonCode,
  341. syntaxPlugin
  342. }) {
  343. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  344. {
  345. const oldReasonCodes = {
  346. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  347. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  348. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  349. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  350. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  351. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  352. };
  353. if (oldReasonCodes[reasonCode]) {
  354. reasonCode = oldReasonCodes[reasonCode];
  355. }
  356. }
  357. return function constructor(loc, details) {
  358. const error = new SyntaxError();
  359. error.code = code;
  360. error.reasonCode = reasonCode;
  361. error.loc = loc;
  362. error.pos = loc.index;
  363. error.syntaxPlugin = syntaxPlugin;
  364. if (hasMissingPlugin) {
  365. error.missingPlugin = details.missingPlugin;
  366. }
  367. defineHidden(error, "clone", function clone(overrides = {}) {
  368. var _overrides$loc;
  369. const {
  370. line,
  371. column,
  372. index
  373. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  374. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  375. });
  376. defineHidden(error, "details", details);
  377. Object.defineProperty(error, "message", {
  378. configurable: true,
  379. get() {
  380. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  381. this.message = message;
  382. return message;
  383. },
  384. set(value) {
  385. Object.defineProperty(this, "message", {
  386. value,
  387. writable: true
  388. });
  389. }
  390. });
  391. return error;
  392. };
  393. }
  394. function ParseErrorEnum(argument, syntaxPlugin) {
  395. if (Array.isArray(argument)) {
  396. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  397. }
  398. const ParseErrorConstructors = {};
  399. for (const reasonCode of Object.keys(argument)) {
  400. const template = argument[reasonCode];
  401. const _ref = typeof template === "string" ? {
  402. message: () => template
  403. } : typeof template === "function" ? {
  404. message: template
  405. } : template,
  406. {
  407. message
  408. } = _ref,
  409. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  410. const toMessage = typeof message === "string" ? () => message : message;
  411. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  412. code: "BABEL_PARSER_SYNTAX_ERROR",
  413. reasonCode,
  414. toMessage
  415. }, syntaxPlugin ? {
  416. syntaxPlugin
  417. } : {}, rest));
  418. }
  419. return ParseErrorConstructors;
  420. }
  421. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  422. const {
  423. defineProperty
  424. } = Object;
  425. const toUnenumerable = (object, key) => {
  426. if (object) {
  427. defineProperty(object, key, {
  428. enumerable: false,
  429. value: object[key]
  430. });
  431. }
  432. };
  433. function toESTreeLocation(node) {
  434. toUnenumerable(node.loc.start, "index");
  435. toUnenumerable(node.loc.end, "index");
  436. return node;
  437. }
  438. var estree = superClass => class ESTreeParserMixin extends superClass {
  439. parse() {
  440. const file = toESTreeLocation(super.parse());
  441. if (this.options.tokens) {
  442. file.tokens = file.tokens.map(toESTreeLocation);
  443. }
  444. return file;
  445. }
  446. parseRegExpLiteral({
  447. pattern,
  448. flags
  449. }) {
  450. let regex = null;
  451. try {
  452. regex = new RegExp(pattern, flags);
  453. } catch (_) {}
  454. const node = this.estreeParseLiteral(regex);
  455. node.regex = {
  456. pattern,
  457. flags
  458. };
  459. return node;
  460. }
  461. parseBigIntLiteral(value) {
  462. let bigInt;
  463. try {
  464. bigInt = BigInt(value);
  465. } catch (_unused) {
  466. bigInt = null;
  467. }
  468. const node = this.estreeParseLiteral(bigInt);
  469. node.bigint = String(node.value || value);
  470. return node;
  471. }
  472. parseDecimalLiteral(value) {
  473. const decimal = null;
  474. const node = this.estreeParseLiteral(decimal);
  475. node.decimal = String(node.value || value);
  476. return node;
  477. }
  478. estreeParseLiteral(value) {
  479. return this.parseLiteral(value, "Literal");
  480. }
  481. parseStringLiteral(value) {
  482. return this.estreeParseLiteral(value);
  483. }
  484. parseNumericLiteral(value) {
  485. return this.estreeParseLiteral(value);
  486. }
  487. parseNullLiteral() {
  488. return this.estreeParseLiteral(null);
  489. }
  490. parseBooleanLiteral(value) {
  491. return this.estreeParseLiteral(value);
  492. }
  493. directiveToStmt(directive) {
  494. const expression = directive.value;
  495. delete directive.value;
  496. expression.type = "Literal";
  497. expression.raw = expression.extra.raw;
  498. expression.value = expression.extra.expressionValue;
  499. const stmt = directive;
  500. stmt.type = "ExpressionStatement";
  501. stmt.expression = expression;
  502. stmt.directive = expression.extra.rawValue;
  503. delete expression.extra;
  504. return stmt;
  505. }
  506. initFunction(node, isAsync) {
  507. super.initFunction(node, isAsync);
  508. node.expression = false;
  509. }
  510. checkDeclaration(node) {
  511. if (node != null && this.isObjectProperty(node)) {
  512. this.checkDeclaration(node.value);
  513. } else {
  514. super.checkDeclaration(node);
  515. }
  516. }
  517. getObjectOrClassMethodParams(method) {
  518. return method.value.params;
  519. }
  520. isValidDirective(stmt) {
  521. var _stmt$expression$extr;
  522. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  523. }
  524. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  525. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  526. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  527. node.body = directiveStatements.concat(node.body);
  528. delete node.directives;
  529. }
  530. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  531. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  532. if (method.typeParameters) {
  533. method.value.typeParameters = method.typeParameters;
  534. delete method.typeParameters;
  535. }
  536. classBody.body.push(method);
  537. }
  538. parsePrivateName() {
  539. const node = super.parsePrivateName();
  540. {
  541. if (!this.getPluginOption("estree", "classFeatures")) {
  542. return node;
  543. }
  544. }
  545. return this.convertPrivateNameToPrivateIdentifier(node);
  546. }
  547. convertPrivateNameToPrivateIdentifier(node) {
  548. const name = super.getPrivateNameSV(node);
  549. node = node;
  550. delete node.id;
  551. node.name = name;
  552. node.type = "PrivateIdentifier";
  553. return node;
  554. }
  555. isPrivateName(node) {
  556. {
  557. if (!this.getPluginOption("estree", "classFeatures")) {
  558. return super.isPrivateName(node);
  559. }
  560. }
  561. return node.type === "PrivateIdentifier";
  562. }
  563. getPrivateNameSV(node) {
  564. {
  565. if (!this.getPluginOption("estree", "classFeatures")) {
  566. return super.getPrivateNameSV(node);
  567. }
  568. }
  569. return node.name;
  570. }
  571. parseLiteral(value, type) {
  572. const node = super.parseLiteral(value, type);
  573. node.raw = node.extra.raw;
  574. delete node.extra;
  575. return node;
  576. }
  577. parseFunctionBody(node, allowExpression, isMethod = false) {
  578. super.parseFunctionBody(node, allowExpression, isMethod);
  579. node.expression = node.body.type !== "BlockStatement";
  580. }
  581. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  582. let funcNode = this.startNode();
  583. funcNode.kind = node.kind;
  584. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  585. funcNode.type = "FunctionExpression";
  586. delete funcNode.kind;
  587. node.value = funcNode;
  588. if (type === "ClassPrivateMethod") {
  589. node.computed = false;
  590. }
  591. return this.finishNode(node, "MethodDefinition");
  592. }
  593. nameIsConstructor(key) {
  594. if (key.type === "Literal") return key.value === "constructor";
  595. return super.nameIsConstructor(key);
  596. }
  597. parseClassProperty(...args) {
  598. const propertyNode = super.parseClassProperty(...args);
  599. {
  600. if (!this.getPluginOption("estree", "classFeatures")) {
  601. return propertyNode;
  602. }
  603. }
  604. propertyNode.type = "PropertyDefinition";
  605. return propertyNode;
  606. }
  607. parseClassPrivateProperty(...args) {
  608. const propertyNode = super.parseClassPrivateProperty(...args);
  609. {
  610. if (!this.getPluginOption("estree", "classFeatures")) {
  611. return propertyNode;
  612. }
  613. }
  614. propertyNode.type = "PropertyDefinition";
  615. propertyNode.computed = false;
  616. return propertyNode;
  617. }
  618. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  619. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  620. if (node) {
  621. node.type = "Property";
  622. if (node.kind === "method") {
  623. node.kind = "init";
  624. }
  625. node.shorthand = false;
  626. }
  627. return node;
  628. }
  629. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  630. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  631. if (node) {
  632. node.kind = "init";
  633. node.type = "Property";
  634. }
  635. return node;
  636. }
  637. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  638. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  639. }
  640. isAssignable(node, isBinding) {
  641. if (node != null && this.isObjectProperty(node)) {
  642. return this.isAssignable(node.value, isBinding);
  643. }
  644. return super.isAssignable(node, isBinding);
  645. }
  646. toAssignable(node, isLHS = false) {
  647. if (node != null && this.isObjectProperty(node)) {
  648. const {
  649. key,
  650. value
  651. } = node;
  652. if (this.isPrivateName(key)) {
  653. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  654. }
  655. this.toAssignable(value, isLHS);
  656. } else {
  657. super.toAssignable(node, isLHS);
  658. }
  659. }
  660. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  661. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  662. this.raise(Errors.PatternHasAccessor, prop.key);
  663. } else if (prop.type === "Property" && prop.method) {
  664. this.raise(Errors.PatternHasMethod, prop.key);
  665. } else {
  666. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  667. }
  668. }
  669. finishCallExpression(unfinished, optional) {
  670. const node = super.finishCallExpression(unfinished, optional);
  671. if (node.callee.type === "Import") {
  672. var _ref, _ref2;
  673. node.type = "ImportExpression";
  674. node.source = node.arguments[0];
  675. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  676. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  677. delete node.arguments;
  678. delete node.callee;
  679. }
  680. return node;
  681. }
  682. toReferencedArguments(node) {
  683. if (node.type === "ImportExpression") {
  684. return;
  685. }
  686. super.toReferencedArguments(node);
  687. }
  688. parseExport(unfinished, decorators) {
  689. const exportStartLoc = this.state.lastTokStartLoc;
  690. const node = super.parseExport(unfinished, decorators);
  691. switch (node.type) {
  692. case "ExportAllDeclaration":
  693. node.exported = null;
  694. break;
  695. case "ExportNamedDeclaration":
  696. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  697. node.type = "ExportAllDeclaration";
  698. node.exported = node.specifiers[0].exported;
  699. delete node.specifiers;
  700. }
  701. case "ExportDefaultDeclaration":
  702. {
  703. var _declaration$decorato;
  704. const {
  705. declaration
  706. } = node;
  707. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  708. this.resetStartLocation(node, exportStartLoc);
  709. }
  710. }
  711. break;
  712. }
  713. return node;
  714. }
  715. parseSubscript(base, startLoc, noCalls, state) {
  716. const node = super.parseSubscript(base, startLoc, noCalls, state);
  717. if (state.optionalChainMember) {
  718. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  719. node.type = node.type.substring(8);
  720. }
  721. if (state.stop) {
  722. const chain = this.startNodeAtNode(node);
  723. chain.expression = node;
  724. return this.finishNode(chain, "ChainExpression");
  725. }
  726. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  727. node.optional = false;
  728. }
  729. return node;
  730. }
  731. isOptionalMemberExpression(node) {
  732. if (node.type === "ChainExpression") {
  733. return node.expression.type === "MemberExpression";
  734. }
  735. return super.isOptionalMemberExpression(node);
  736. }
  737. hasPropertyAsPrivateName(node) {
  738. if (node.type === "ChainExpression") {
  739. node = node.expression;
  740. }
  741. return super.hasPropertyAsPrivateName(node);
  742. }
  743. isObjectProperty(node) {
  744. return node.type === "Property" && node.kind === "init" && !node.method;
  745. }
  746. isObjectMethod(node) {
  747. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  748. }
  749. finishNodeAt(node, type, endLoc) {
  750. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  751. }
  752. resetStartLocation(node, startLoc) {
  753. super.resetStartLocation(node, startLoc);
  754. toESTreeLocation(node);
  755. }
  756. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  757. super.resetEndLocation(node, endLoc);
  758. toESTreeLocation(node);
  759. }
  760. };
  761. class TokContext {
  762. constructor(token, preserveSpace) {
  763. this.token = void 0;
  764. this.preserveSpace = void 0;
  765. this.token = token;
  766. this.preserveSpace = !!preserveSpace;
  767. }
  768. }
  769. const types = {
  770. brace: new TokContext("{"),
  771. j_oTag: new TokContext("<tag"),
  772. j_cTag: new TokContext("</tag"),
  773. j_expr: new TokContext("<tag>...</tag>", true)
  774. };
  775. {
  776. types.template = new TokContext("`", true);
  777. }
  778. const beforeExpr = true;
  779. const startsExpr = true;
  780. const isLoop = true;
  781. const isAssign = true;
  782. const prefix = true;
  783. const postfix = true;
  784. class ExportedTokenType {
  785. constructor(label, conf = {}) {
  786. this.label = void 0;
  787. this.keyword = void 0;
  788. this.beforeExpr = void 0;
  789. this.startsExpr = void 0;
  790. this.rightAssociative = void 0;
  791. this.isLoop = void 0;
  792. this.isAssign = void 0;
  793. this.prefix = void 0;
  794. this.postfix = void 0;
  795. this.binop = void 0;
  796. this.label = label;
  797. this.keyword = conf.keyword;
  798. this.beforeExpr = !!conf.beforeExpr;
  799. this.startsExpr = !!conf.startsExpr;
  800. this.rightAssociative = !!conf.rightAssociative;
  801. this.isLoop = !!conf.isLoop;
  802. this.isAssign = !!conf.isAssign;
  803. this.prefix = !!conf.prefix;
  804. this.postfix = !!conf.postfix;
  805. this.binop = conf.binop != null ? conf.binop : null;
  806. {
  807. this.updateContext = null;
  808. }
  809. }
  810. }
  811. const keywords$1 = new Map();
  812. function createKeyword(name, options = {}) {
  813. options.keyword = name;
  814. const token = createToken(name, options);
  815. keywords$1.set(name, token);
  816. return token;
  817. }
  818. function createBinop(name, binop) {
  819. return createToken(name, {
  820. beforeExpr,
  821. binop
  822. });
  823. }
  824. let tokenTypeCounter = -1;
  825. const tokenTypes = [];
  826. const tokenLabels = [];
  827. const tokenBinops = [];
  828. const tokenBeforeExprs = [];
  829. const tokenStartsExprs = [];
  830. const tokenPrefixes = [];
  831. function createToken(name, options = {}) {
  832. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  833. ++tokenTypeCounter;
  834. tokenLabels.push(name);
  835. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  836. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  837. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  838. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  839. tokenTypes.push(new ExportedTokenType(name, options));
  840. return tokenTypeCounter;
  841. }
  842. function createKeywordLike(name, options = {}) {
  843. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  844. ++tokenTypeCounter;
  845. keywords$1.set(name, tokenTypeCounter);
  846. tokenLabels.push(name);
  847. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  848. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  849. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  850. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  851. tokenTypes.push(new ExportedTokenType("name", options));
  852. return tokenTypeCounter;
  853. }
  854. const tt = {
  855. bracketL: createToken("[", {
  856. beforeExpr,
  857. startsExpr
  858. }),
  859. bracketHashL: createToken("#[", {
  860. beforeExpr,
  861. startsExpr
  862. }),
  863. bracketBarL: createToken("[|", {
  864. beforeExpr,
  865. startsExpr
  866. }),
  867. bracketR: createToken("]"),
  868. bracketBarR: createToken("|]"),
  869. braceL: createToken("{", {
  870. beforeExpr,
  871. startsExpr
  872. }),
  873. braceBarL: createToken("{|", {
  874. beforeExpr,
  875. startsExpr
  876. }),
  877. braceHashL: createToken("#{", {
  878. beforeExpr,
  879. startsExpr
  880. }),
  881. braceR: createToken("}"),
  882. braceBarR: createToken("|}"),
  883. parenL: createToken("(", {
  884. beforeExpr,
  885. startsExpr
  886. }),
  887. parenR: createToken(")"),
  888. comma: createToken(",", {
  889. beforeExpr
  890. }),
  891. semi: createToken(";", {
  892. beforeExpr
  893. }),
  894. colon: createToken(":", {
  895. beforeExpr
  896. }),
  897. doubleColon: createToken("::", {
  898. beforeExpr
  899. }),
  900. dot: createToken("."),
  901. question: createToken("?", {
  902. beforeExpr
  903. }),
  904. questionDot: createToken("?."),
  905. arrow: createToken("=>", {
  906. beforeExpr
  907. }),
  908. template: createToken("template"),
  909. ellipsis: createToken("...", {
  910. beforeExpr
  911. }),
  912. backQuote: createToken("`", {
  913. startsExpr
  914. }),
  915. dollarBraceL: createToken("${", {
  916. beforeExpr,
  917. startsExpr
  918. }),
  919. templateTail: createToken("...`", {
  920. startsExpr
  921. }),
  922. templateNonTail: createToken("...${", {
  923. beforeExpr,
  924. startsExpr
  925. }),
  926. at: createToken("@"),
  927. hash: createToken("#", {
  928. startsExpr
  929. }),
  930. interpreterDirective: createToken("#!..."),
  931. eq: createToken("=", {
  932. beforeExpr,
  933. isAssign
  934. }),
  935. assign: createToken("_=", {
  936. beforeExpr,
  937. isAssign
  938. }),
  939. slashAssign: createToken("_=", {
  940. beforeExpr,
  941. isAssign
  942. }),
  943. xorAssign: createToken("_=", {
  944. beforeExpr,
  945. isAssign
  946. }),
  947. moduloAssign: createToken("_=", {
  948. beforeExpr,
  949. isAssign
  950. }),
  951. incDec: createToken("++/--", {
  952. prefix,
  953. postfix,
  954. startsExpr
  955. }),
  956. bang: createToken("!", {
  957. beforeExpr,
  958. prefix,
  959. startsExpr
  960. }),
  961. tilde: createToken("~", {
  962. beforeExpr,
  963. prefix,
  964. startsExpr
  965. }),
  966. doubleCaret: createToken("^^", {
  967. startsExpr
  968. }),
  969. doubleAt: createToken("@@", {
  970. startsExpr
  971. }),
  972. pipeline: createBinop("|>", 0),
  973. nullishCoalescing: createBinop("??", 1),
  974. logicalOR: createBinop("||", 1),
  975. logicalAND: createBinop("&&", 2),
  976. bitwiseOR: createBinop("|", 3),
  977. bitwiseXOR: createBinop("^", 4),
  978. bitwiseAND: createBinop("&", 5),
  979. equality: createBinop("==/!=/===/!==", 6),
  980. lt: createBinop("</>/<=/>=", 7),
  981. gt: createBinop("</>/<=/>=", 7),
  982. relational: createBinop("</>/<=/>=", 7),
  983. bitShift: createBinop("<</>>/>>>", 8),
  984. bitShiftL: createBinop("<</>>/>>>", 8),
  985. bitShiftR: createBinop("<</>>/>>>", 8),
  986. plusMin: createToken("+/-", {
  987. beforeExpr,
  988. binop: 9,
  989. prefix,
  990. startsExpr
  991. }),
  992. modulo: createToken("%", {
  993. binop: 10,
  994. startsExpr
  995. }),
  996. star: createToken("*", {
  997. binop: 10
  998. }),
  999. slash: createBinop("/", 10),
  1000. exponent: createToken("**", {
  1001. beforeExpr,
  1002. binop: 11,
  1003. rightAssociative: true
  1004. }),
  1005. _in: createKeyword("in", {
  1006. beforeExpr,
  1007. binop: 7
  1008. }),
  1009. _instanceof: createKeyword("instanceof", {
  1010. beforeExpr,
  1011. binop: 7
  1012. }),
  1013. _break: createKeyword("break"),
  1014. _case: createKeyword("case", {
  1015. beforeExpr
  1016. }),
  1017. _catch: createKeyword("catch"),
  1018. _continue: createKeyword("continue"),
  1019. _debugger: createKeyword("debugger"),
  1020. _default: createKeyword("default", {
  1021. beforeExpr
  1022. }),
  1023. _else: createKeyword("else", {
  1024. beforeExpr
  1025. }),
  1026. _finally: createKeyword("finally"),
  1027. _function: createKeyword("function", {
  1028. startsExpr
  1029. }),
  1030. _if: createKeyword("if"),
  1031. _return: createKeyword("return", {
  1032. beforeExpr
  1033. }),
  1034. _switch: createKeyword("switch"),
  1035. _throw: createKeyword("throw", {
  1036. beforeExpr,
  1037. prefix,
  1038. startsExpr
  1039. }),
  1040. _try: createKeyword("try"),
  1041. _var: createKeyword("var"),
  1042. _const: createKeyword("const"),
  1043. _with: createKeyword("with"),
  1044. _new: createKeyword("new", {
  1045. beforeExpr,
  1046. startsExpr
  1047. }),
  1048. _this: createKeyword("this", {
  1049. startsExpr
  1050. }),
  1051. _super: createKeyword("super", {
  1052. startsExpr
  1053. }),
  1054. _class: createKeyword("class", {
  1055. startsExpr
  1056. }),
  1057. _extends: createKeyword("extends", {
  1058. beforeExpr
  1059. }),
  1060. _export: createKeyword("export"),
  1061. _import: createKeyword("import", {
  1062. startsExpr
  1063. }),
  1064. _null: createKeyword("null", {
  1065. startsExpr
  1066. }),
  1067. _true: createKeyword("true", {
  1068. startsExpr
  1069. }),
  1070. _false: createKeyword("false", {
  1071. startsExpr
  1072. }),
  1073. _typeof: createKeyword("typeof", {
  1074. beforeExpr,
  1075. prefix,
  1076. startsExpr
  1077. }),
  1078. _void: createKeyword("void", {
  1079. beforeExpr,
  1080. prefix,
  1081. startsExpr
  1082. }),
  1083. _delete: createKeyword("delete", {
  1084. beforeExpr,
  1085. prefix,
  1086. startsExpr
  1087. }),
  1088. _do: createKeyword("do", {
  1089. isLoop,
  1090. beforeExpr
  1091. }),
  1092. _for: createKeyword("for", {
  1093. isLoop
  1094. }),
  1095. _while: createKeyword("while", {
  1096. isLoop
  1097. }),
  1098. _as: createKeywordLike("as", {
  1099. startsExpr
  1100. }),
  1101. _assert: createKeywordLike("assert", {
  1102. startsExpr
  1103. }),
  1104. _async: createKeywordLike("async", {
  1105. startsExpr
  1106. }),
  1107. _await: createKeywordLike("await", {
  1108. startsExpr
  1109. }),
  1110. _defer: createKeywordLike("defer", {
  1111. startsExpr
  1112. }),
  1113. _from: createKeywordLike("from", {
  1114. startsExpr
  1115. }),
  1116. _get: createKeywordLike("get", {
  1117. startsExpr
  1118. }),
  1119. _let: createKeywordLike("let", {
  1120. startsExpr
  1121. }),
  1122. _meta: createKeywordLike("meta", {
  1123. startsExpr
  1124. }),
  1125. _of: createKeywordLike("of", {
  1126. startsExpr
  1127. }),
  1128. _sent: createKeywordLike("sent", {
  1129. startsExpr
  1130. }),
  1131. _set: createKeywordLike("set", {
  1132. startsExpr
  1133. }),
  1134. _source: createKeywordLike("source", {
  1135. startsExpr
  1136. }),
  1137. _static: createKeywordLike("static", {
  1138. startsExpr
  1139. }),
  1140. _using: createKeywordLike("using", {
  1141. startsExpr
  1142. }),
  1143. _yield: createKeywordLike("yield", {
  1144. startsExpr
  1145. }),
  1146. _asserts: createKeywordLike("asserts", {
  1147. startsExpr
  1148. }),
  1149. _checks: createKeywordLike("checks", {
  1150. startsExpr
  1151. }),
  1152. _exports: createKeywordLike("exports", {
  1153. startsExpr
  1154. }),
  1155. _global: createKeywordLike("global", {
  1156. startsExpr
  1157. }),
  1158. _implements: createKeywordLike("implements", {
  1159. startsExpr
  1160. }),
  1161. _intrinsic: createKeywordLike("intrinsic", {
  1162. startsExpr
  1163. }),
  1164. _infer: createKeywordLike("infer", {
  1165. startsExpr
  1166. }),
  1167. _is: createKeywordLike("is", {
  1168. startsExpr
  1169. }),
  1170. _mixins: createKeywordLike("mixins", {
  1171. startsExpr
  1172. }),
  1173. _proto: createKeywordLike("proto", {
  1174. startsExpr
  1175. }),
  1176. _require: createKeywordLike("require", {
  1177. startsExpr
  1178. }),
  1179. _satisfies: createKeywordLike("satisfies", {
  1180. startsExpr
  1181. }),
  1182. _keyof: createKeywordLike("keyof", {
  1183. startsExpr
  1184. }),
  1185. _readonly: createKeywordLike("readonly", {
  1186. startsExpr
  1187. }),
  1188. _unique: createKeywordLike("unique", {
  1189. startsExpr
  1190. }),
  1191. _abstract: createKeywordLike("abstract", {
  1192. startsExpr
  1193. }),
  1194. _declare: createKeywordLike("declare", {
  1195. startsExpr
  1196. }),
  1197. _enum: createKeywordLike("enum", {
  1198. startsExpr
  1199. }),
  1200. _module: createKeywordLike("module", {
  1201. startsExpr
  1202. }),
  1203. _namespace: createKeywordLike("namespace", {
  1204. startsExpr
  1205. }),
  1206. _interface: createKeywordLike("interface", {
  1207. startsExpr
  1208. }),
  1209. _type: createKeywordLike("type", {
  1210. startsExpr
  1211. }),
  1212. _opaque: createKeywordLike("opaque", {
  1213. startsExpr
  1214. }),
  1215. name: createToken("name", {
  1216. startsExpr
  1217. }),
  1218. string: createToken("string", {
  1219. startsExpr
  1220. }),
  1221. num: createToken("num", {
  1222. startsExpr
  1223. }),
  1224. bigint: createToken("bigint", {
  1225. startsExpr
  1226. }),
  1227. decimal: createToken("decimal", {
  1228. startsExpr
  1229. }),
  1230. regexp: createToken("regexp", {
  1231. startsExpr
  1232. }),
  1233. privateName: createToken("#name", {
  1234. startsExpr
  1235. }),
  1236. eof: createToken("eof"),
  1237. jsxName: createToken("jsxName"),
  1238. jsxText: createToken("jsxText", {
  1239. beforeExpr: true
  1240. }),
  1241. jsxTagStart: createToken("jsxTagStart", {
  1242. startsExpr: true
  1243. }),
  1244. jsxTagEnd: createToken("jsxTagEnd"),
  1245. placeholder: createToken("%%", {
  1246. startsExpr: true
  1247. })
  1248. };
  1249. function tokenIsIdentifier(token) {
  1250. return token >= 93 && token <= 132;
  1251. }
  1252. function tokenKeywordOrIdentifierIsKeyword(token) {
  1253. return token <= 92;
  1254. }
  1255. function tokenIsKeywordOrIdentifier(token) {
  1256. return token >= 58 && token <= 132;
  1257. }
  1258. function tokenIsLiteralPropertyName(token) {
  1259. return token >= 58 && token <= 136;
  1260. }
  1261. function tokenComesBeforeExpression(token) {
  1262. return tokenBeforeExprs[token];
  1263. }
  1264. function tokenCanStartExpression(token) {
  1265. return tokenStartsExprs[token];
  1266. }
  1267. function tokenIsAssignment(token) {
  1268. return token >= 29 && token <= 33;
  1269. }
  1270. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1271. return token >= 129 && token <= 131;
  1272. }
  1273. function tokenIsLoop(token) {
  1274. return token >= 90 && token <= 92;
  1275. }
  1276. function tokenIsKeyword(token) {
  1277. return token >= 58 && token <= 92;
  1278. }
  1279. function tokenIsOperator(token) {
  1280. return token >= 39 && token <= 59;
  1281. }
  1282. function tokenIsPostfix(token) {
  1283. return token === 34;
  1284. }
  1285. function tokenIsPrefix(token) {
  1286. return tokenPrefixes[token];
  1287. }
  1288. function tokenIsTSTypeOperator(token) {
  1289. return token >= 121 && token <= 123;
  1290. }
  1291. function tokenIsTSDeclarationStart(token) {
  1292. return token >= 124 && token <= 130;
  1293. }
  1294. function tokenLabelName(token) {
  1295. return tokenLabels[token];
  1296. }
  1297. function tokenOperatorPrecedence(token) {
  1298. return tokenBinops[token];
  1299. }
  1300. function tokenIsRightAssociative(token) {
  1301. return token === 57;
  1302. }
  1303. function tokenIsTemplate(token) {
  1304. return token >= 24 && token <= 25;
  1305. }
  1306. function getExportedToken(token) {
  1307. return tokenTypes[token];
  1308. }
  1309. {
  1310. tokenTypes[8].updateContext = context => {
  1311. context.pop();
  1312. };
  1313. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1314. context.push(types.brace);
  1315. };
  1316. tokenTypes[22].updateContext = context => {
  1317. if (context[context.length - 1] === types.template) {
  1318. context.pop();
  1319. } else {
  1320. context.push(types.template);
  1321. }
  1322. };
  1323. tokenTypes[142].updateContext = context => {
  1324. context.push(types.j_expr, types.j_oTag);
  1325. };
  1326. }
  1327. 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-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7cd\ua7d0\ua7d1\ua7d3\ua7d5-\ua7dc\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";
  1328. let nonASCIIidentifierChars = "\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\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";
  1329. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1330. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1331. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1332. const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 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, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 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, 229, 29, 3, 0, 496, 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];
  1333. const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1334. function isInAstralSet(code, set) {
  1335. let pos = 0x10000;
  1336. for (let i = 0, length = set.length; i < length; i += 2) {
  1337. pos += set[i];
  1338. if (pos > code) return false;
  1339. pos += set[i + 1];
  1340. if (pos >= code) return true;
  1341. }
  1342. return false;
  1343. }
  1344. function isIdentifierStart(code) {
  1345. if (code < 65) return code === 36;
  1346. if (code <= 90) return true;
  1347. if (code < 97) return code === 95;
  1348. if (code <= 122) return true;
  1349. if (code <= 0xffff) {
  1350. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1351. }
  1352. return isInAstralSet(code, astralIdentifierStartCodes);
  1353. }
  1354. function isIdentifierChar(code) {
  1355. if (code < 48) return code === 36;
  1356. if (code < 58) return true;
  1357. if (code < 65) return false;
  1358. if (code <= 90) return true;
  1359. if (code < 97) return code === 95;
  1360. if (code <= 122) return true;
  1361. if (code <= 0xffff) {
  1362. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1363. }
  1364. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1365. }
  1366. const reservedWords = {
  1367. 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"],
  1368. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1369. strictBind: ["eval", "arguments"]
  1370. };
  1371. const keywords = new Set(reservedWords.keyword);
  1372. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1373. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1374. function isReservedWord(word, inModule) {
  1375. return inModule && word === "await" || word === "enum";
  1376. }
  1377. function isStrictReservedWord(word, inModule) {
  1378. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1379. }
  1380. function isStrictBindOnlyReservedWord(word) {
  1381. return reservedWordsStrictBindSet.has(word);
  1382. }
  1383. function isStrictBindReservedWord(word, inModule) {
  1384. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1385. }
  1386. function isKeyword(word) {
  1387. return keywords.has(word);
  1388. }
  1389. function isIteratorStart(current, next, next2) {
  1390. return current === 64 && next === 64 && isIdentifierStart(next2);
  1391. }
  1392. 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"]);
  1393. function canBeReservedWord(word) {
  1394. return reservedWordLikeSet.has(word);
  1395. }
  1396. class Scope {
  1397. constructor(flags) {
  1398. this.flags = 0;
  1399. this.names = new Map();
  1400. this.firstLexicalName = "";
  1401. this.flags = flags;
  1402. }
  1403. }
  1404. class ScopeHandler {
  1405. constructor(parser, inModule) {
  1406. this.parser = void 0;
  1407. this.scopeStack = [];
  1408. this.inModule = void 0;
  1409. this.undefinedExports = new Map();
  1410. this.parser = parser;
  1411. this.inModule = inModule;
  1412. }
  1413. get inTopLevel() {
  1414. return (this.currentScope().flags & 1) > 0;
  1415. }
  1416. get inFunction() {
  1417. return (this.currentVarScopeFlags() & 2) > 0;
  1418. }
  1419. get allowSuper() {
  1420. return (this.currentThisScopeFlags() & 16) > 0;
  1421. }
  1422. get allowDirectSuper() {
  1423. return (this.currentThisScopeFlags() & 32) > 0;
  1424. }
  1425. get inClass() {
  1426. return (this.currentThisScopeFlags() & 64) > 0;
  1427. }
  1428. get inClassAndNotInNonArrowFunction() {
  1429. const flags = this.currentThisScopeFlags();
  1430. return (flags & 64) > 0 && (flags & 2) === 0;
  1431. }
  1432. get inStaticBlock() {
  1433. for (let i = this.scopeStack.length - 1;; i--) {
  1434. const {
  1435. flags
  1436. } = this.scopeStack[i];
  1437. if (flags & 128) {
  1438. return true;
  1439. }
  1440. if (flags & (387 | 64)) {
  1441. return false;
  1442. }
  1443. }
  1444. }
  1445. get inNonArrowFunction() {
  1446. return (this.currentThisScopeFlags() & 2) > 0;
  1447. }
  1448. get treatFunctionsAsVar() {
  1449. return this.treatFunctionsAsVarInScope(this.currentScope());
  1450. }
  1451. createScope(flags) {
  1452. return new Scope(flags);
  1453. }
  1454. enter(flags) {
  1455. this.scopeStack.push(this.createScope(flags));
  1456. }
  1457. exit() {
  1458. const scope = this.scopeStack.pop();
  1459. return scope.flags;
  1460. }
  1461. treatFunctionsAsVarInScope(scope) {
  1462. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1463. }
  1464. declareName(name, bindingType, loc) {
  1465. let scope = this.currentScope();
  1466. if (bindingType & 8 || bindingType & 16) {
  1467. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1468. let type = scope.names.get(name) || 0;
  1469. if (bindingType & 16) {
  1470. type = type | 4;
  1471. } else {
  1472. if (!scope.firstLexicalName) {
  1473. scope.firstLexicalName = name;
  1474. }
  1475. type = type | 2;
  1476. }
  1477. scope.names.set(name, type);
  1478. if (bindingType & 8) {
  1479. this.maybeExportDefined(scope, name);
  1480. }
  1481. } else if (bindingType & 4) {
  1482. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1483. scope = this.scopeStack[i];
  1484. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1485. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1486. this.maybeExportDefined(scope, name);
  1487. if (scope.flags & 387) break;
  1488. }
  1489. }
  1490. if (this.parser.inModule && scope.flags & 1) {
  1491. this.undefinedExports.delete(name);
  1492. }
  1493. }
  1494. maybeExportDefined(scope, name) {
  1495. if (this.parser.inModule && scope.flags & 1) {
  1496. this.undefinedExports.delete(name);
  1497. }
  1498. }
  1499. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1500. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1501. this.parser.raise(Errors.VarRedeclaration, loc, {
  1502. identifierName: name
  1503. });
  1504. }
  1505. }
  1506. isRedeclaredInScope(scope, name, bindingType) {
  1507. if (!(bindingType & 1)) return false;
  1508. if (bindingType & 8) {
  1509. return scope.names.has(name);
  1510. }
  1511. const type = scope.names.get(name);
  1512. if (bindingType & 16) {
  1513. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1514. }
  1515. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1516. }
  1517. checkLocalExport(id) {
  1518. const {
  1519. name
  1520. } = id;
  1521. const topLevelScope = this.scopeStack[0];
  1522. if (!topLevelScope.names.has(name)) {
  1523. this.undefinedExports.set(name, id.loc.start);
  1524. }
  1525. }
  1526. currentScope() {
  1527. return this.scopeStack[this.scopeStack.length - 1];
  1528. }
  1529. currentVarScopeFlags() {
  1530. for (let i = this.scopeStack.length - 1;; i--) {
  1531. const {
  1532. flags
  1533. } = this.scopeStack[i];
  1534. if (flags & 387) {
  1535. return flags;
  1536. }
  1537. }
  1538. }
  1539. currentThisScopeFlags() {
  1540. for (let i = this.scopeStack.length - 1;; i--) {
  1541. const {
  1542. flags
  1543. } = this.scopeStack[i];
  1544. if (flags & (387 | 64) && !(flags & 4)) {
  1545. return flags;
  1546. }
  1547. }
  1548. }
  1549. }
  1550. class FlowScope extends Scope {
  1551. constructor(...args) {
  1552. super(...args);
  1553. this.declareFunctions = new Set();
  1554. }
  1555. }
  1556. class FlowScopeHandler extends ScopeHandler {
  1557. createScope(flags) {
  1558. return new FlowScope(flags);
  1559. }
  1560. declareName(name, bindingType, loc) {
  1561. const scope = this.currentScope();
  1562. if (bindingType & 2048) {
  1563. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1564. this.maybeExportDefined(scope, name);
  1565. scope.declareFunctions.add(name);
  1566. return;
  1567. }
  1568. super.declareName(name, bindingType, loc);
  1569. }
  1570. isRedeclaredInScope(scope, name, bindingType) {
  1571. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1572. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1573. const type = scope.names.get(name);
  1574. return (type & 4) > 0 || (type & 2) > 0;
  1575. }
  1576. return false;
  1577. }
  1578. checkLocalExport(id) {
  1579. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1580. super.checkLocalExport(id);
  1581. }
  1582. }
  1583. }
  1584. class BaseParser {
  1585. constructor() {
  1586. this.sawUnambiguousESM = false;
  1587. this.ambiguousScriptDifferentAst = false;
  1588. }
  1589. sourceToOffsetPos(sourcePos) {
  1590. return sourcePos + this.startIndex;
  1591. }
  1592. offsetToSourcePos(offsetPos) {
  1593. return offsetPos - this.startIndex;
  1594. }
  1595. hasPlugin(pluginConfig) {
  1596. if (typeof pluginConfig === "string") {
  1597. return this.plugins.has(pluginConfig);
  1598. } else {
  1599. const [pluginName, pluginOptions] = pluginConfig;
  1600. if (!this.hasPlugin(pluginName)) {
  1601. return false;
  1602. }
  1603. const actualOptions = this.plugins.get(pluginName);
  1604. for (const key of Object.keys(pluginOptions)) {
  1605. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1606. return false;
  1607. }
  1608. }
  1609. return true;
  1610. }
  1611. }
  1612. getPluginOption(plugin, name) {
  1613. var _this$plugins$get;
  1614. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1615. }
  1616. }
  1617. function setTrailingComments(node, comments) {
  1618. if (node.trailingComments === undefined) {
  1619. node.trailingComments = comments;
  1620. } else {
  1621. node.trailingComments.unshift(...comments);
  1622. }
  1623. }
  1624. function setLeadingComments(node, comments) {
  1625. if (node.leadingComments === undefined) {
  1626. node.leadingComments = comments;
  1627. } else {
  1628. node.leadingComments.unshift(...comments);
  1629. }
  1630. }
  1631. function setInnerComments(node, comments) {
  1632. if (node.innerComments === undefined) {
  1633. node.innerComments = comments;
  1634. } else {
  1635. node.innerComments.unshift(...comments);
  1636. }
  1637. }
  1638. function adjustInnerComments(node, elements, commentWS) {
  1639. let lastElement = null;
  1640. let i = elements.length;
  1641. while (lastElement === null && i > 0) {
  1642. lastElement = elements[--i];
  1643. }
  1644. if (lastElement === null || lastElement.start > commentWS.start) {
  1645. setInnerComments(node, commentWS.comments);
  1646. } else {
  1647. setTrailingComments(lastElement, commentWS.comments);
  1648. }
  1649. }
  1650. class CommentsParser extends BaseParser {
  1651. addComment(comment) {
  1652. if (this.filename) comment.loc.filename = this.filename;
  1653. const {
  1654. commentsLen
  1655. } = this.state;
  1656. if (this.comments.length !== commentsLen) {
  1657. this.comments.length = commentsLen;
  1658. }
  1659. this.comments.push(comment);
  1660. this.state.commentsLen++;
  1661. }
  1662. processComment(node) {
  1663. const {
  1664. commentStack
  1665. } = this.state;
  1666. const commentStackLength = commentStack.length;
  1667. if (commentStackLength === 0) return;
  1668. let i = commentStackLength - 1;
  1669. const lastCommentWS = commentStack[i];
  1670. if (lastCommentWS.start === node.end) {
  1671. lastCommentWS.leadingNode = node;
  1672. i--;
  1673. }
  1674. const {
  1675. start: nodeStart
  1676. } = node;
  1677. for (; i >= 0; i--) {
  1678. const commentWS = commentStack[i];
  1679. const commentEnd = commentWS.end;
  1680. if (commentEnd > nodeStart) {
  1681. commentWS.containingNode = node;
  1682. this.finalizeComment(commentWS);
  1683. commentStack.splice(i, 1);
  1684. } else {
  1685. if (commentEnd === nodeStart) {
  1686. commentWS.trailingNode = node;
  1687. }
  1688. break;
  1689. }
  1690. }
  1691. }
  1692. finalizeComment(commentWS) {
  1693. const {
  1694. comments
  1695. } = commentWS;
  1696. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1697. if (commentWS.leadingNode !== null) {
  1698. setTrailingComments(commentWS.leadingNode, comments);
  1699. }
  1700. if (commentWS.trailingNode !== null) {
  1701. setLeadingComments(commentWS.trailingNode, comments);
  1702. }
  1703. } else {
  1704. const {
  1705. containingNode: node,
  1706. start: commentStart
  1707. } = commentWS;
  1708. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  1709. switch (node.type) {
  1710. case "ObjectExpression":
  1711. case "ObjectPattern":
  1712. case "RecordExpression":
  1713. adjustInnerComments(node, node.properties, commentWS);
  1714. break;
  1715. case "CallExpression":
  1716. case "OptionalCallExpression":
  1717. adjustInnerComments(node, node.arguments, commentWS);
  1718. break;
  1719. case "FunctionDeclaration":
  1720. case "FunctionExpression":
  1721. case "ArrowFunctionExpression":
  1722. case "ObjectMethod":
  1723. case "ClassMethod":
  1724. case "ClassPrivateMethod":
  1725. adjustInnerComments(node, node.params, commentWS);
  1726. break;
  1727. case "ArrayExpression":
  1728. case "ArrayPattern":
  1729. case "TupleExpression":
  1730. adjustInnerComments(node, node.elements, commentWS);
  1731. break;
  1732. case "ExportNamedDeclaration":
  1733. case "ImportDeclaration":
  1734. adjustInnerComments(node, node.specifiers, commentWS);
  1735. break;
  1736. default:
  1737. {
  1738. setInnerComments(node, comments);
  1739. }
  1740. }
  1741. } else {
  1742. setInnerComments(node, comments);
  1743. }
  1744. }
  1745. }
  1746. finalizeRemainingComments() {
  1747. const {
  1748. commentStack
  1749. } = this.state;
  1750. for (let i = commentStack.length - 1; i >= 0; i--) {
  1751. this.finalizeComment(commentStack[i]);
  1752. }
  1753. this.state.commentStack = [];
  1754. }
  1755. resetPreviousNodeTrailingComments(node) {
  1756. const {
  1757. commentStack
  1758. } = this.state;
  1759. const {
  1760. length
  1761. } = commentStack;
  1762. if (length === 0) return;
  1763. const commentWS = commentStack[length - 1];
  1764. if (commentWS.leadingNode === node) {
  1765. commentWS.leadingNode = null;
  1766. }
  1767. }
  1768. resetPreviousIdentifierLeadingComments(node) {
  1769. const {
  1770. commentStack
  1771. } = this.state;
  1772. const {
  1773. length
  1774. } = commentStack;
  1775. if (length === 0) return;
  1776. if (commentStack[length - 1].trailingNode === node) {
  1777. commentStack[length - 1].trailingNode = null;
  1778. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  1779. commentStack[length - 2].trailingNode = null;
  1780. }
  1781. }
  1782. takeSurroundingComments(node, start, end) {
  1783. const {
  1784. commentStack
  1785. } = this.state;
  1786. const commentStackLength = commentStack.length;
  1787. if (commentStackLength === 0) return;
  1788. let i = commentStackLength - 1;
  1789. for (; i >= 0; i--) {
  1790. const commentWS = commentStack[i];
  1791. const commentEnd = commentWS.end;
  1792. const commentStart = commentWS.start;
  1793. if (commentStart === end) {
  1794. commentWS.leadingNode = node;
  1795. } else if (commentEnd === start) {
  1796. commentWS.trailingNode = node;
  1797. } else if (commentEnd < start) {
  1798. break;
  1799. }
  1800. }
  1801. }
  1802. }
  1803. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  1804. const lineBreakG = new RegExp(lineBreak.source, "g");
  1805. function isNewLine(code) {
  1806. switch (code) {
  1807. case 10:
  1808. case 13:
  1809. case 8232:
  1810. case 8233:
  1811. return true;
  1812. default:
  1813. return false;
  1814. }
  1815. }
  1816. function hasNewLine(input, start, end) {
  1817. for (let i = start; i < end; i++) {
  1818. if (isNewLine(input.charCodeAt(i))) {
  1819. return true;
  1820. }
  1821. }
  1822. return false;
  1823. }
  1824. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1825. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1826. function isWhitespace(code) {
  1827. switch (code) {
  1828. case 0x0009:
  1829. case 0x000b:
  1830. case 0x000c:
  1831. case 32:
  1832. case 160:
  1833. case 5760:
  1834. case 0x2000:
  1835. case 0x2001:
  1836. case 0x2002:
  1837. case 0x2003:
  1838. case 0x2004:
  1839. case 0x2005:
  1840. case 0x2006:
  1841. case 0x2007:
  1842. case 0x2008:
  1843. case 0x2009:
  1844. case 0x200a:
  1845. case 0x202f:
  1846. case 0x205f:
  1847. case 0x3000:
  1848. case 0xfeff:
  1849. return true;
  1850. default:
  1851. return false;
  1852. }
  1853. }
  1854. class State {
  1855. constructor() {
  1856. this.flags = 1024;
  1857. this.startIndex = void 0;
  1858. this.curLine = void 0;
  1859. this.lineStart = void 0;
  1860. this.startLoc = void 0;
  1861. this.endLoc = void 0;
  1862. this.errors = [];
  1863. this.potentialArrowAt = -1;
  1864. this.noArrowAt = [];
  1865. this.noArrowParamsConversionAt = [];
  1866. this.topicContext = {
  1867. maxNumOfResolvableTopics: 0,
  1868. maxTopicIndex: null
  1869. };
  1870. this.labels = [];
  1871. this.commentsLen = 0;
  1872. this.commentStack = [];
  1873. this.pos = 0;
  1874. this.type = 139;
  1875. this.value = null;
  1876. this.start = 0;
  1877. this.end = 0;
  1878. this.lastTokEndLoc = null;
  1879. this.lastTokStartLoc = null;
  1880. this.context = [types.brace];
  1881. this.firstInvalidTemplateEscapePos = null;
  1882. this.strictErrors = new Map();
  1883. this.tokensLength = 0;
  1884. }
  1885. get strict() {
  1886. return (this.flags & 1) > 0;
  1887. }
  1888. set strict(v) {
  1889. if (v) this.flags |= 1;else this.flags &= -2;
  1890. }
  1891. init({
  1892. strictMode,
  1893. sourceType,
  1894. startIndex,
  1895. startLine,
  1896. startColumn
  1897. }) {
  1898. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1899. this.startIndex = startIndex;
  1900. this.curLine = startLine;
  1901. this.lineStart = -startColumn;
  1902. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  1903. }
  1904. get maybeInArrowParameters() {
  1905. return (this.flags & 2) > 0;
  1906. }
  1907. set maybeInArrowParameters(v) {
  1908. if (v) this.flags |= 2;else this.flags &= -3;
  1909. }
  1910. get inType() {
  1911. return (this.flags & 4) > 0;
  1912. }
  1913. set inType(v) {
  1914. if (v) this.flags |= 4;else this.flags &= -5;
  1915. }
  1916. get noAnonFunctionType() {
  1917. return (this.flags & 8) > 0;
  1918. }
  1919. set noAnonFunctionType(v) {
  1920. if (v) this.flags |= 8;else this.flags &= -9;
  1921. }
  1922. get hasFlowComment() {
  1923. return (this.flags & 16) > 0;
  1924. }
  1925. set hasFlowComment(v) {
  1926. if (v) this.flags |= 16;else this.flags &= -17;
  1927. }
  1928. get isAmbientContext() {
  1929. return (this.flags & 32) > 0;
  1930. }
  1931. set isAmbientContext(v) {
  1932. if (v) this.flags |= 32;else this.flags &= -33;
  1933. }
  1934. get inAbstractClass() {
  1935. return (this.flags & 64) > 0;
  1936. }
  1937. set inAbstractClass(v) {
  1938. if (v) this.flags |= 64;else this.flags &= -65;
  1939. }
  1940. get inDisallowConditionalTypesContext() {
  1941. return (this.flags & 128) > 0;
  1942. }
  1943. set inDisallowConditionalTypesContext(v) {
  1944. if (v) this.flags |= 128;else this.flags &= -129;
  1945. }
  1946. get soloAwait() {
  1947. return (this.flags & 256) > 0;
  1948. }
  1949. set soloAwait(v) {
  1950. if (v) this.flags |= 256;else this.flags &= -257;
  1951. }
  1952. get inFSharpPipelineDirectBody() {
  1953. return (this.flags & 512) > 0;
  1954. }
  1955. set inFSharpPipelineDirectBody(v) {
  1956. if (v) this.flags |= 512;else this.flags &= -513;
  1957. }
  1958. get canStartJSXElement() {
  1959. return (this.flags & 1024) > 0;
  1960. }
  1961. set canStartJSXElement(v) {
  1962. if (v) this.flags |= 1024;else this.flags &= -1025;
  1963. }
  1964. get containsEsc() {
  1965. return (this.flags & 2048) > 0;
  1966. }
  1967. set containsEsc(v) {
  1968. if (v) this.flags |= 2048;else this.flags &= -2049;
  1969. }
  1970. get hasTopLevelAwait() {
  1971. return (this.flags & 4096) > 0;
  1972. }
  1973. set hasTopLevelAwait(v) {
  1974. if (v) this.flags |= 4096;else this.flags &= -4097;
  1975. }
  1976. curPosition() {
  1977. const index = this.startIndex + this.pos;
  1978. return new Position(this.curLine, index - this.lineStart, index);
  1979. }
  1980. clone() {
  1981. const state = new State();
  1982. state.flags = this.flags;
  1983. state.startIndex = this.startIndex;
  1984. state.curLine = this.curLine;
  1985. state.lineStart = this.lineStart;
  1986. state.startLoc = this.startLoc;
  1987. state.endLoc = this.endLoc;
  1988. state.errors = this.errors.slice();
  1989. state.potentialArrowAt = this.potentialArrowAt;
  1990. state.noArrowAt = this.noArrowAt.slice();
  1991. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  1992. state.topicContext = this.topicContext;
  1993. state.labels = this.labels.slice();
  1994. state.commentsLen = this.commentsLen;
  1995. state.commentStack = this.commentStack.slice();
  1996. state.pos = this.pos;
  1997. state.type = this.type;
  1998. state.value = this.value;
  1999. state.start = this.start;
  2000. state.end = this.end;
  2001. state.lastTokEndLoc = this.lastTokEndLoc;
  2002. state.lastTokStartLoc = this.lastTokStartLoc;
  2003. state.context = this.context.slice();
  2004. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  2005. state.strictErrors = this.strictErrors;
  2006. state.tokensLength = this.tokensLength;
  2007. return state;
  2008. }
  2009. }
  2010. var _isDigit = function isDigit(code) {
  2011. return code >= 48 && code <= 57;
  2012. };
  2013. const forbiddenNumericSeparatorSiblings = {
  2014. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  2015. hex: new Set([46, 88, 95, 120])
  2016. };
  2017. const isAllowedNumericSeparatorSibling = {
  2018. bin: ch => ch === 48 || ch === 49,
  2019. oct: ch => ch >= 48 && ch <= 55,
  2020. dec: ch => ch >= 48 && ch <= 57,
  2021. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  2022. };
  2023. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  2024. const initialPos = pos;
  2025. const initialLineStart = lineStart;
  2026. const initialCurLine = curLine;
  2027. let out = "";
  2028. let firstInvalidLoc = null;
  2029. let chunkStart = pos;
  2030. const {
  2031. length
  2032. } = input;
  2033. for (;;) {
  2034. if (pos >= length) {
  2035. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2036. out += input.slice(chunkStart, pos);
  2037. break;
  2038. }
  2039. const ch = input.charCodeAt(pos);
  2040. if (isStringEnd(type, ch, input, pos)) {
  2041. out += input.slice(chunkStart, pos);
  2042. break;
  2043. }
  2044. if (ch === 92) {
  2045. out += input.slice(chunkStart, pos);
  2046. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  2047. if (res.ch === null && !firstInvalidLoc) {
  2048. firstInvalidLoc = {
  2049. pos,
  2050. lineStart,
  2051. curLine
  2052. };
  2053. } else {
  2054. out += res.ch;
  2055. }
  2056. ({
  2057. pos,
  2058. lineStart,
  2059. curLine
  2060. } = res);
  2061. chunkStart = pos;
  2062. } else if (ch === 8232 || ch === 8233) {
  2063. ++pos;
  2064. ++curLine;
  2065. lineStart = pos;
  2066. } else if (ch === 10 || ch === 13) {
  2067. if (type === "template") {
  2068. out += input.slice(chunkStart, pos) + "\n";
  2069. ++pos;
  2070. if (ch === 13 && input.charCodeAt(pos) === 10) {
  2071. ++pos;
  2072. }
  2073. ++curLine;
  2074. chunkStart = lineStart = pos;
  2075. } else {
  2076. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2077. }
  2078. } else {
  2079. ++pos;
  2080. }
  2081. }
  2082. return {
  2083. pos,
  2084. str: out,
  2085. firstInvalidLoc,
  2086. lineStart,
  2087. curLine,
  2088. containsInvalid: !!firstInvalidLoc
  2089. };
  2090. }
  2091. function isStringEnd(type, ch, input, pos) {
  2092. if (type === "template") {
  2093. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2094. }
  2095. return ch === (type === "double" ? 34 : 39);
  2096. }
  2097. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2098. const throwOnInvalid = !inTemplate;
  2099. pos++;
  2100. const res = ch => ({
  2101. pos,
  2102. ch,
  2103. lineStart,
  2104. curLine
  2105. });
  2106. const ch = input.charCodeAt(pos++);
  2107. switch (ch) {
  2108. case 110:
  2109. return res("\n");
  2110. case 114:
  2111. return res("\r");
  2112. case 120:
  2113. {
  2114. let code;
  2115. ({
  2116. code,
  2117. pos
  2118. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2119. return res(code === null ? null : String.fromCharCode(code));
  2120. }
  2121. case 117:
  2122. {
  2123. let code;
  2124. ({
  2125. code,
  2126. pos
  2127. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2128. return res(code === null ? null : String.fromCodePoint(code));
  2129. }
  2130. case 116:
  2131. return res("\t");
  2132. case 98:
  2133. return res("\b");
  2134. case 118:
  2135. return res("\u000b");
  2136. case 102:
  2137. return res("\f");
  2138. case 13:
  2139. if (input.charCodeAt(pos) === 10) {
  2140. ++pos;
  2141. }
  2142. case 10:
  2143. lineStart = pos;
  2144. ++curLine;
  2145. case 8232:
  2146. case 8233:
  2147. return res("");
  2148. case 56:
  2149. case 57:
  2150. if (inTemplate) {
  2151. return res(null);
  2152. } else {
  2153. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2154. }
  2155. default:
  2156. if (ch >= 48 && ch <= 55) {
  2157. const startPos = pos - 1;
  2158. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  2159. let octalStr = match[0];
  2160. let octal = parseInt(octalStr, 8);
  2161. if (octal > 255) {
  2162. octalStr = octalStr.slice(0, -1);
  2163. octal = parseInt(octalStr, 8);
  2164. }
  2165. pos += octalStr.length - 1;
  2166. const next = input.charCodeAt(pos);
  2167. if (octalStr !== "0" || next === 56 || next === 57) {
  2168. if (inTemplate) {
  2169. return res(null);
  2170. } else {
  2171. errors.strictNumericEscape(startPos, lineStart, curLine);
  2172. }
  2173. }
  2174. return res(String.fromCharCode(octal));
  2175. }
  2176. return res(String.fromCharCode(ch));
  2177. }
  2178. }
  2179. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2180. const initialPos = pos;
  2181. let n;
  2182. ({
  2183. n,
  2184. pos
  2185. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2186. if (n === null) {
  2187. if (throwOnInvalid) {
  2188. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2189. } else {
  2190. pos = initialPos - 1;
  2191. }
  2192. }
  2193. return {
  2194. code: n,
  2195. pos
  2196. };
  2197. }
  2198. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2199. const start = pos;
  2200. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2201. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2202. let invalid = false;
  2203. let total = 0;
  2204. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2205. const code = input.charCodeAt(pos);
  2206. let val;
  2207. if (code === 95 && allowNumSeparator !== "bail") {
  2208. const prev = input.charCodeAt(pos - 1);
  2209. const next = input.charCodeAt(pos + 1);
  2210. if (!allowNumSeparator) {
  2211. if (bailOnError) return {
  2212. n: null,
  2213. pos
  2214. };
  2215. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2216. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2217. if (bailOnError) return {
  2218. n: null,
  2219. pos
  2220. };
  2221. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2222. }
  2223. ++pos;
  2224. continue;
  2225. }
  2226. if (code >= 97) {
  2227. val = code - 97 + 10;
  2228. } else if (code >= 65) {
  2229. val = code - 65 + 10;
  2230. } else if (_isDigit(code)) {
  2231. val = code - 48;
  2232. } else {
  2233. val = Infinity;
  2234. }
  2235. if (val >= radix) {
  2236. if (val <= 9 && bailOnError) {
  2237. return {
  2238. n: null,
  2239. pos
  2240. };
  2241. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2242. val = 0;
  2243. } else if (forceLen) {
  2244. val = 0;
  2245. invalid = true;
  2246. } else {
  2247. break;
  2248. }
  2249. }
  2250. ++pos;
  2251. total = total * radix + val;
  2252. }
  2253. if (pos === start || len != null && pos - start !== len || invalid) {
  2254. return {
  2255. n: null,
  2256. pos
  2257. };
  2258. }
  2259. return {
  2260. n: total,
  2261. pos
  2262. };
  2263. }
  2264. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2265. const ch = input.charCodeAt(pos);
  2266. let code;
  2267. if (ch === 123) {
  2268. ++pos;
  2269. ({
  2270. code,
  2271. pos
  2272. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2273. ++pos;
  2274. if (code !== null && code > 0x10ffff) {
  2275. if (throwOnInvalid) {
  2276. errors.invalidCodePoint(pos, lineStart, curLine);
  2277. } else {
  2278. return {
  2279. code: null,
  2280. pos
  2281. };
  2282. }
  2283. }
  2284. } else {
  2285. ({
  2286. code,
  2287. pos
  2288. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2289. }
  2290. return {
  2291. code,
  2292. pos
  2293. };
  2294. }
  2295. function buildPosition(pos, lineStart, curLine) {
  2296. return new Position(curLine, pos - lineStart, pos);
  2297. }
  2298. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2299. class Token {
  2300. constructor(state) {
  2301. this.type = state.type;
  2302. this.value = state.value;
  2303. this.start = state.start;
  2304. this.end = state.end;
  2305. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2306. }
  2307. }
  2308. class Tokenizer extends CommentsParser {
  2309. constructor(options, input) {
  2310. super();
  2311. this.isLookahead = void 0;
  2312. this.tokens = [];
  2313. this.errorHandlers_readInt = {
  2314. invalidDigit: (pos, lineStart, curLine, radix) => {
  2315. if (!this.options.errorRecovery) return false;
  2316. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  2317. radix
  2318. });
  2319. return true;
  2320. },
  2321. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2322. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2323. };
  2324. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2325. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2326. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2327. });
  2328. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2329. strictNumericEscape: (pos, lineStart, curLine) => {
  2330. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  2331. },
  2332. unterminated: (pos, lineStart, curLine) => {
  2333. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  2334. }
  2335. });
  2336. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2337. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2338. unterminated: (pos, lineStart, curLine) => {
  2339. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  2340. }
  2341. });
  2342. this.state = new State();
  2343. this.state.init(options);
  2344. this.input = input;
  2345. this.length = input.length;
  2346. this.comments = [];
  2347. this.isLookahead = false;
  2348. }
  2349. pushToken(token) {
  2350. this.tokens.length = this.state.tokensLength;
  2351. this.tokens.push(token);
  2352. ++this.state.tokensLength;
  2353. }
  2354. next() {
  2355. this.checkKeywordEscapes();
  2356. if (this.options.tokens) {
  2357. this.pushToken(new Token(this.state));
  2358. }
  2359. this.state.lastTokEndLoc = this.state.endLoc;
  2360. this.state.lastTokStartLoc = this.state.startLoc;
  2361. this.nextToken();
  2362. }
  2363. eat(type) {
  2364. if (this.match(type)) {
  2365. this.next();
  2366. return true;
  2367. } else {
  2368. return false;
  2369. }
  2370. }
  2371. match(type) {
  2372. return this.state.type === type;
  2373. }
  2374. createLookaheadState(state) {
  2375. return {
  2376. pos: state.pos,
  2377. value: null,
  2378. type: state.type,
  2379. start: state.start,
  2380. end: state.end,
  2381. context: [this.curContext()],
  2382. inType: state.inType,
  2383. startLoc: state.startLoc,
  2384. lastTokEndLoc: state.lastTokEndLoc,
  2385. curLine: state.curLine,
  2386. lineStart: state.lineStart,
  2387. curPosition: state.curPosition
  2388. };
  2389. }
  2390. lookahead() {
  2391. const old = this.state;
  2392. this.state = this.createLookaheadState(old);
  2393. this.isLookahead = true;
  2394. this.nextToken();
  2395. this.isLookahead = false;
  2396. const curr = this.state;
  2397. this.state = old;
  2398. return curr;
  2399. }
  2400. nextTokenStart() {
  2401. return this.nextTokenStartSince(this.state.pos);
  2402. }
  2403. nextTokenStartSince(pos) {
  2404. skipWhiteSpace.lastIndex = pos;
  2405. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2406. }
  2407. lookaheadCharCode() {
  2408. return this.input.charCodeAt(this.nextTokenStart());
  2409. }
  2410. nextTokenInLineStart() {
  2411. return this.nextTokenInLineStartSince(this.state.pos);
  2412. }
  2413. nextTokenInLineStartSince(pos) {
  2414. skipWhiteSpaceInLine.lastIndex = pos;
  2415. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2416. }
  2417. lookaheadInLineCharCode() {
  2418. return this.input.charCodeAt(this.nextTokenInLineStart());
  2419. }
  2420. codePointAtPos(pos) {
  2421. let cp = this.input.charCodeAt(pos);
  2422. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2423. const trail = this.input.charCodeAt(pos);
  2424. if ((trail & 0xfc00) === 0xdc00) {
  2425. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2426. }
  2427. }
  2428. return cp;
  2429. }
  2430. setStrict(strict) {
  2431. this.state.strict = strict;
  2432. if (strict) {
  2433. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  2434. this.state.strictErrors.clear();
  2435. }
  2436. }
  2437. curContext() {
  2438. return this.state.context[this.state.context.length - 1];
  2439. }
  2440. nextToken() {
  2441. this.skipSpace();
  2442. this.state.start = this.state.pos;
  2443. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2444. if (this.state.pos >= this.length) {
  2445. this.finishToken(139);
  2446. return;
  2447. }
  2448. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2449. }
  2450. skipBlockComment(commentEnd) {
  2451. let startLoc;
  2452. if (!this.isLookahead) startLoc = this.state.curPosition();
  2453. const start = this.state.pos;
  2454. const end = this.input.indexOf(commentEnd, start + 2);
  2455. if (end === -1) {
  2456. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  2457. }
  2458. this.state.pos = end + commentEnd.length;
  2459. lineBreakG.lastIndex = start + 2;
  2460. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2461. ++this.state.curLine;
  2462. this.state.lineStart = lineBreakG.lastIndex;
  2463. }
  2464. if (this.isLookahead) return;
  2465. const comment = {
  2466. type: "CommentBlock",
  2467. value: this.input.slice(start + 2, end),
  2468. start,
  2469. end: end + commentEnd.length,
  2470. loc: new SourceLocation(startLoc, this.state.curPosition())
  2471. };
  2472. if (this.options.tokens) this.pushToken(comment);
  2473. return comment;
  2474. }
  2475. skipLineComment(startSkip) {
  2476. const start = this.state.pos;
  2477. let startLoc;
  2478. if (!this.isLookahead) startLoc = this.state.curPosition();
  2479. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2480. if (this.state.pos < this.length) {
  2481. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2482. ch = this.input.charCodeAt(this.state.pos);
  2483. }
  2484. }
  2485. if (this.isLookahead) return;
  2486. const end = this.state.pos;
  2487. const value = this.input.slice(start + startSkip, end);
  2488. const comment = {
  2489. type: "CommentLine",
  2490. value,
  2491. start,
  2492. end,
  2493. loc: new SourceLocation(startLoc, this.state.curPosition())
  2494. };
  2495. if (this.options.tokens) this.pushToken(comment);
  2496. return comment;
  2497. }
  2498. skipSpace() {
  2499. const spaceStart = this.state.pos;
  2500. const comments = [];
  2501. loop: while (this.state.pos < this.length) {
  2502. const ch = this.input.charCodeAt(this.state.pos);
  2503. switch (ch) {
  2504. case 32:
  2505. case 160:
  2506. case 9:
  2507. ++this.state.pos;
  2508. break;
  2509. case 13:
  2510. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2511. ++this.state.pos;
  2512. }
  2513. case 10:
  2514. case 8232:
  2515. case 8233:
  2516. ++this.state.pos;
  2517. ++this.state.curLine;
  2518. this.state.lineStart = this.state.pos;
  2519. break;
  2520. case 47:
  2521. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2522. case 42:
  2523. {
  2524. const comment = this.skipBlockComment("*/");
  2525. if (comment !== undefined) {
  2526. this.addComment(comment);
  2527. if (this.options.attachComment) comments.push(comment);
  2528. }
  2529. break;
  2530. }
  2531. case 47:
  2532. {
  2533. const comment = this.skipLineComment(2);
  2534. if (comment !== undefined) {
  2535. this.addComment(comment);
  2536. if (this.options.attachComment) comments.push(comment);
  2537. }
  2538. break;
  2539. }
  2540. default:
  2541. break loop;
  2542. }
  2543. break;
  2544. default:
  2545. if (isWhitespace(ch)) {
  2546. ++this.state.pos;
  2547. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  2548. const pos = this.state.pos;
  2549. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2550. const comment = this.skipLineComment(3);
  2551. if (comment !== undefined) {
  2552. this.addComment(comment);
  2553. if (this.options.attachComment) comments.push(comment);
  2554. }
  2555. } else {
  2556. break loop;
  2557. }
  2558. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  2559. const pos = this.state.pos;
  2560. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2561. const comment = this.skipLineComment(4);
  2562. if (comment !== undefined) {
  2563. this.addComment(comment);
  2564. if (this.options.attachComment) comments.push(comment);
  2565. }
  2566. } else {
  2567. break loop;
  2568. }
  2569. } else {
  2570. break loop;
  2571. }
  2572. }
  2573. }
  2574. if (comments.length > 0) {
  2575. const end = this.state.pos;
  2576. const commentWhitespace = {
  2577. start: this.sourceToOffsetPos(spaceStart),
  2578. end: this.sourceToOffsetPos(end),
  2579. comments,
  2580. leadingNode: null,
  2581. trailingNode: null,
  2582. containingNode: null
  2583. };
  2584. this.state.commentStack.push(commentWhitespace);
  2585. }
  2586. }
  2587. finishToken(type, val) {
  2588. this.state.end = this.state.pos;
  2589. this.state.endLoc = this.state.curPosition();
  2590. const prevType = this.state.type;
  2591. this.state.type = type;
  2592. this.state.value = val;
  2593. if (!this.isLookahead) {
  2594. this.updateContext(prevType);
  2595. }
  2596. }
  2597. replaceToken(type) {
  2598. this.state.type = type;
  2599. this.updateContext();
  2600. }
  2601. readToken_numberSign() {
  2602. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2603. return;
  2604. }
  2605. const nextPos = this.state.pos + 1;
  2606. const next = this.codePointAtPos(nextPos);
  2607. if (next >= 48 && next <= 57) {
  2608. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  2609. }
  2610. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2611. this.expectPlugin("recordAndTuple");
  2612. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2613. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  2614. }
  2615. this.state.pos += 2;
  2616. if (next === 123) {
  2617. this.finishToken(7);
  2618. } else {
  2619. this.finishToken(1);
  2620. }
  2621. } else if (isIdentifierStart(next)) {
  2622. ++this.state.pos;
  2623. this.finishToken(138, this.readWord1(next));
  2624. } else if (next === 92) {
  2625. ++this.state.pos;
  2626. this.finishToken(138, this.readWord1());
  2627. } else {
  2628. this.finishOp(27, 1);
  2629. }
  2630. }
  2631. readToken_dot() {
  2632. const next = this.input.charCodeAt(this.state.pos + 1);
  2633. if (next >= 48 && next <= 57) {
  2634. this.readNumber(true);
  2635. return;
  2636. }
  2637. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2638. this.state.pos += 3;
  2639. this.finishToken(21);
  2640. } else {
  2641. ++this.state.pos;
  2642. this.finishToken(16);
  2643. }
  2644. }
  2645. readToken_slash() {
  2646. const next = this.input.charCodeAt(this.state.pos + 1);
  2647. if (next === 61) {
  2648. this.finishOp(31, 2);
  2649. } else {
  2650. this.finishOp(56, 1);
  2651. }
  2652. }
  2653. readToken_interpreter() {
  2654. if (this.state.pos !== 0 || this.length < 2) return false;
  2655. let ch = this.input.charCodeAt(this.state.pos + 1);
  2656. if (ch !== 33) return false;
  2657. const start = this.state.pos;
  2658. this.state.pos += 1;
  2659. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2660. ch = this.input.charCodeAt(this.state.pos);
  2661. }
  2662. const value = this.input.slice(start + 2, this.state.pos);
  2663. this.finishToken(28, value);
  2664. return true;
  2665. }
  2666. readToken_mult_modulo(code) {
  2667. let type = code === 42 ? 55 : 54;
  2668. let width = 1;
  2669. let next = this.input.charCodeAt(this.state.pos + 1);
  2670. if (code === 42 && next === 42) {
  2671. width++;
  2672. next = this.input.charCodeAt(this.state.pos + 2);
  2673. type = 57;
  2674. }
  2675. if (next === 61 && !this.state.inType) {
  2676. width++;
  2677. type = code === 37 ? 33 : 30;
  2678. }
  2679. this.finishOp(type, width);
  2680. }
  2681. readToken_pipe_amp(code) {
  2682. const next = this.input.charCodeAt(this.state.pos + 1);
  2683. if (next === code) {
  2684. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2685. this.finishOp(30, 3);
  2686. } else {
  2687. this.finishOp(code === 124 ? 41 : 42, 2);
  2688. }
  2689. return;
  2690. }
  2691. if (code === 124) {
  2692. if (next === 62) {
  2693. this.finishOp(39, 2);
  2694. return;
  2695. }
  2696. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2697. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2698. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2699. }
  2700. this.state.pos += 2;
  2701. this.finishToken(9);
  2702. return;
  2703. }
  2704. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2705. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2706. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2707. }
  2708. this.state.pos += 2;
  2709. this.finishToken(4);
  2710. return;
  2711. }
  2712. }
  2713. if (next === 61) {
  2714. this.finishOp(30, 2);
  2715. return;
  2716. }
  2717. this.finishOp(code === 124 ? 43 : 45, 1);
  2718. }
  2719. readToken_caret() {
  2720. const next = this.input.charCodeAt(this.state.pos + 1);
  2721. if (next === 61 && !this.state.inType) {
  2722. this.finishOp(32, 2);
  2723. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2724. proposal: "hack",
  2725. topicToken: "^^"
  2726. }])) {
  2727. this.finishOp(37, 2);
  2728. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2729. if (lookaheadCh === 94) {
  2730. this.unexpected();
  2731. }
  2732. } else {
  2733. this.finishOp(44, 1);
  2734. }
  2735. }
  2736. readToken_atSign() {
  2737. const next = this.input.charCodeAt(this.state.pos + 1);
  2738. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2739. proposal: "hack",
  2740. topicToken: "@@"
  2741. }])) {
  2742. this.finishOp(38, 2);
  2743. } else {
  2744. this.finishOp(26, 1);
  2745. }
  2746. }
  2747. readToken_plus_min(code) {
  2748. const next = this.input.charCodeAt(this.state.pos + 1);
  2749. if (next === code) {
  2750. this.finishOp(34, 2);
  2751. return;
  2752. }
  2753. if (next === 61) {
  2754. this.finishOp(30, 2);
  2755. } else {
  2756. this.finishOp(53, 1);
  2757. }
  2758. }
  2759. readToken_lt() {
  2760. const {
  2761. pos
  2762. } = this.state;
  2763. const next = this.input.charCodeAt(pos + 1);
  2764. if (next === 60) {
  2765. if (this.input.charCodeAt(pos + 2) === 61) {
  2766. this.finishOp(30, 3);
  2767. return;
  2768. }
  2769. this.finishOp(51, 2);
  2770. return;
  2771. }
  2772. if (next === 61) {
  2773. this.finishOp(49, 2);
  2774. return;
  2775. }
  2776. this.finishOp(47, 1);
  2777. }
  2778. readToken_gt() {
  2779. const {
  2780. pos
  2781. } = this.state;
  2782. const next = this.input.charCodeAt(pos + 1);
  2783. if (next === 62) {
  2784. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2785. if (this.input.charCodeAt(pos + size) === 61) {
  2786. this.finishOp(30, size + 1);
  2787. return;
  2788. }
  2789. this.finishOp(52, size);
  2790. return;
  2791. }
  2792. if (next === 61) {
  2793. this.finishOp(49, 2);
  2794. return;
  2795. }
  2796. this.finishOp(48, 1);
  2797. }
  2798. readToken_eq_excl(code) {
  2799. const next = this.input.charCodeAt(this.state.pos + 1);
  2800. if (next === 61) {
  2801. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2802. return;
  2803. }
  2804. if (code === 61 && next === 62) {
  2805. this.state.pos += 2;
  2806. this.finishToken(19);
  2807. return;
  2808. }
  2809. this.finishOp(code === 61 ? 29 : 35, 1);
  2810. }
  2811. readToken_question() {
  2812. const next = this.input.charCodeAt(this.state.pos + 1);
  2813. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2814. if (next === 63) {
  2815. if (next2 === 61) {
  2816. this.finishOp(30, 3);
  2817. } else {
  2818. this.finishOp(40, 2);
  2819. }
  2820. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2821. this.state.pos += 2;
  2822. this.finishToken(18);
  2823. } else {
  2824. ++this.state.pos;
  2825. this.finishToken(17);
  2826. }
  2827. }
  2828. getTokenFromCode(code) {
  2829. switch (code) {
  2830. case 46:
  2831. this.readToken_dot();
  2832. return;
  2833. case 40:
  2834. ++this.state.pos;
  2835. this.finishToken(10);
  2836. return;
  2837. case 41:
  2838. ++this.state.pos;
  2839. this.finishToken(11);
  2840. return;
  2841. case 59:
  2842. ++this.state.pos;
  2843. this.finishToken(13);
  2844. return;
  2845. case 44:
  2846. ++this.state.pos;
  2847. this.finishToken(12);
  2848. return;
  2849. case 91:
  2850. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2851. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2852. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2853. }
  2854. this.state.pos += 2;
  2855. this.finishToken(2);
  2856. } else {
  2857. ++this.state.pos;
  2858. this.finishToken(0);
  2859. }
  2860. return;
  2861. case 93:
  2862. ++this.state.pos;
  2863. this.finishToken(3);
  2864. return;
  2865. case 123:
  2866. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2867. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2868. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2869. }
  2870. this.state.pos += 2;
  2871. this.finishToken(6);
  2872. } else {
  2873. ++this.state.pos;
  2874. this.finishToken(5);
  2875. }
  2876. return;
  2877. case 125:
  2878. ++this.state.pos;
  2879. this.finishToken(8);
  2880. return;
  2881. case 58:
  2882. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2883. this.finishOp(15, 2);
  2884. } else {
  2885. ++this.state.pos;
  2886. this.finishToken(14);
  2887. }
  2888. return;
  2889. case 63:
  2890. this.readToken_question();
  2891. return;
  2892. case 96:
  2893. this.readTemplateToken();
  2894. return;
  2895. case 48:
  2896. {
  2897. const next = this.input.charCodeAt(this.state.pos + 1);
  2898. if (next === 120 || next === 88) {
  2899. this.readRadixNumber(16);
  2900. return;
  2901. }
  2902. if (next === 111 || next === 79) {
  2903. this.readRadixNumber(8);
  2904. return;
  2905. }
  2906. if (next === 98 || next === 66) {
  2907. this.readRadixNumber(2);
  2908. return;
  2909. }
  2910. }
  2911. case 49:
  2912. case 50:
  2913. case 51:
  2914. case 52:
  2915. case 53:
  2916. case 54:
  2917. case 55:
  2918. case 56:
  2919. case 57:
  2920. this.readNumber(false);
  2921. return;
  2922. case 34:
  2923. case 39:
  2924. this.readString(code);
  2925. return;
  2926. case 47:
  2927. this.readToken_slash();
  2928. return;
  2929. case 37:
  2930. case 42:
  2931. this.readToken_mult_modulo(code);
  2932. return;
  2933. case 124:
  2934. case 38:
  2935. this.readToken_pipe_amp(code);
  2936. return;
  2937. case 94:
  2938. this.readToken_caret();
  2939. return;
  2940. case 43:
  2941. case 45:
  2942. this.readToken_plus_min(code);
  2943. return;
  2944. case 60:
  2945. this.readToken_lt();
  2946. return;
  2947. case 62:
  2948. this.readToken_gt();
  2949. return;
  2950. case 61:
  2951. case 33:
  2952. this.readToken_eq_excl(code);
  2953. return;
  2954. case 126:
  2955. this.finishOp(36, 1);
  2956. return;
  2957. case 64:
  2958. this.readToken_atSign();
  2959. return;
  2960. case 35:
  2961. this.readToken_numberSign();
  2962. return;
  2963. case 92:
  2964. this.readWord();
  2965. return;
  2966. default:
  2967. if (isIdentifierStart(code)) {
  2968. this.readWord(code);
  2969. return;
  2970. }
  2971. }
  2972. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  2973. unexpected: String.fromCodePoint(code)
  2974. });
  2975. }
  2976. finishOp(type, size) {
  2977. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2978. this.state.pos += size;
  2979. this.finishToken(type, str);
  2980. }
  2981. readRegexp() {
  2982. const startLoc = this.state.startLoc;
  2983. const start = this.state.start + 1;
  2984. let escaped, inClass;
  2985. let {
  2986. pos
  2987. } = this.state;
  2988. for (;; ++pos) {
  2989. if (pos >= this.length) {
  2990. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  2991. }
  2992. const ch = this.input.charCodeAt(pos);
  2993. if (isNewLine(ch)) {
  2994. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  2995. }
  2996. if (escaped) {
  2997. escaped = false;
  2998. } else {
  2999. if (ch === 91) {
  3000. inClass = true;
  3001. } else if (ch === 93 && inClass) {
  3002. inClass = false;
  3003. } else if (ch === 47 && !inClass) {
  3004. break;
  3005. }
  3006. escaped = ch === 92;
  3007. }
  3008. }
  3009. const content = this.input.slice(start, pos);
  3010. ++pos;
  3011. let mods = "";
  3012. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  3013. while (pos < this.length) {
  3014. const cp = this.codePointAtPos(pos);
  3015. const char = String.fromCharCode(cp);
  3016. if (VALID_REGEX_FLAGS.has(cp)) {
  3017. if (cp === 118) {
  3018. if (mods.includes("u")) {
  3019. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3020. }
  3021. } else if (cp === 117) {
  3022. if (mods.includes("v")) {
  3023. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3024. }
  3025. }
  3026. if (mods.includes(char)) {
  3027. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  3028. }
  3029. } else if (isIdentifierChar(cp) || cp === 92) {
  3030. this.raise(Errors.MalformedRegExpFlags, nextPos());
  3031. } else {
  3032. break;
  3033. }
  3034. ++pos;
  3035. mods += char;
  3036. }
  3037. this.state.pos = pos;
  3038. this.finishToken(137, {
  3039. pattern: content,
  3040. flags: mods
  3041. });
  3042. }
  3043. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  3044. const {
  3045. n,
  3046. pos
  3047. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  3048. this.state.pos = pos;
  3049. return n;
  3050. }
  3051. readRadixNumber(radix) {
  3052. const start = this.state.pos;
  3053. const startLoc = this.state.curPosition();
  3054. let isBigInt = false;
  3055. this.state.pos += 2;
  3056. const val = this.readInt(radix);
  3057. if (val == null) {
  3058. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  3059. radix
  3060. });
  3061. }
  3062. const next = this.input.charCodeAt(this.state.pos);
  3063. if (next === 110) {
  3064. ++this.state.pos;
  3065. isBigInt = true;
  3066. } else if (next === 109) {
  3067. throw this.raise(Errors.InvalidDecimal, startLoc);
  3068. }
  3069. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3070. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3071. }
  3072. if (isBigInt) {
  3073. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  3074. this.finishToken(135, str);
  3075. return;
  3076. }
  3077. this.finishToken(134, val);
  3078. }
  3079. readNumber(startsWithDot) {
  3080. const start = this.state.pos;
  3081. const startLoc = this.state.curPosition();
  3082. let isFloat = false;
  3083. let isBigInt = false;
  3084. let hasExponent = false;
  3085. let isOctal = false;
  3086. if (!startsWithDot && this.readInt(10) === null) {
  3087. this.raise(Errors.InvalidNumber, this.state.curPosition());
  3088. }
  3089. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3090. if (hasLeadingZero) {
  3091. const integer = this.input.slice(start, this.state.pos);
  3092. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  3093. if (!this.state.strict) {
  3094. const underscorePos = integer.indexOf("_");
  3095. if (underscorePos > 0) {
  3096. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  3097. }
  3098. }
  3099. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3100. }
  3101. let next = this.input.charCodeAt(this.state.pos);
  3102. if (next === 46 && !isOctal) {
  3103. ++this.state.pos;
  3104. this.readInt(10);
  3105. isFloat = true;
  3106. next = this.input.charCodeAt(this.state.pos);
  3107. }
  3108. if ((next === 69 || next === 101) && !isOctal) {
  3109. next = this.input.charCodeAt(++this.state.pos);
  3110. if (next === 43 || next === 45) {
  3111. ++this.state.pos;
  3112. }
  3113. if (this.readInt(10) === null) {
  3114. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  3115. }
  3116. isFloat = true;
  3117. hasExponent = true;
  3118. next = this.input.charCodeAt(this.state.pos);
  3119. }
  3120. if (next === 110) {
  3121. if (isFloat || hasLeadingZero) {
  3122. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  3123. }
  3124. ++this.state.pos;
  3125. isBigInt = true;
  3126. }
  3127. if (next === 109) {
  3128. this.expectPlugin("decimal", this.state.curPosition());
  3129. if (hasExponent || hasLeadingZero) {
  3130. this.raise(Errors.InvalidDecimal, startLoc);
  3131. }
  3132. ++this.state.pos;
  3133. var isDecimal = true;
  3134. }
  3135. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3136. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3137. }
  3138. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3139. if (isBigInt) {
  3140. this.finishToken(135, str);
  3141. return;
  3142. }
  3143. if (isDecimal) {
  3144. this.finishToken(136, str);
  3145. return;
  3146. }
  3147. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3148. this.finishToken(134, val);
  3149. }
  3150. readCodePoint(throwOnInvalid) {
  3151. const {
  3152. code,
  3153. pos
  3154. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3155. this.state.pos = pos;
  3156. return code;
  3157. }
  3158. readString(quote) {
  3159. const {
  3160. str,
  3161. pos,
  3162. curLine,
  3163. lineStart
  3164. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3165. this.state.pos = pos + 1;
  3166. this.state.lineStart = lineStart;
  3167. this.state.curLine = curLine;
  3168. this.finishToken(133, str);
  3169. }
  3170. readTemplateContinuation() {
  3171. if (!this.match(8)) {
  3172. this.unexpected(null, 8);
  3173. }
  3174. this.state.pos--;
  3175. this.readTemplateToken();
  3176. }
  3177. readTemplateToken() {
  3178. const opening = this.input[this.state.pos];
  3179. const {
  3180. str,
  3181. firstInvalidLoc,
  3182. pos,
  3183. curLine,
  3184. lineStart
  3185. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3186. this.state.pos = pos + 1;
  3187. this.state.lineStart = lineStart;
  3188. this.state.curLine = curLine;
  3189. if (firstInvalidLoc) {
  3190. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3191. }
  3192. if (this.input.codePointAt(pos) === 96) {
  3193. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3194. } else {
  3195. this.state.pos++;
  3196. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3197. }
  3198. }
  3199. recordStrictModeErrors(toParseError, at) {
  3200. const index = at.index;
  3201. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3202. this.raise(toParseError, at);
  3203. } else {
  3204. this.state.strictErrors.set(index, [toParseError, at]);
  3205. }
  3206. }
  3207. readWord1(firstCode) {
  3208. this.state.containsEsc = false;
  3209. let word = "";
  3210. const start = this.state.pos;
  3211. let chunkStart = this.state.pos;
  3212. if (firstCode !== undefined) {
  3213. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3214. }
  3215. while (this.state.pos < this.length) {
  3216. const ch = this.codePointAtPos(this.state.pos);
  3217. if (isIdentifierChar(ch)) {
  3218. this.state.pos += ch <= 0xffff ? 1 : 2;
  3219. } else if (ch === 92) {
  3220. this.state.containsEsc = true;
  3221. word += this.input.slice(chunkStart, this.state.pos);
  3222. const escStart = this.state.curPosition();
  3223. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3224. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3225. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  3226. chunkStart = this.state.pos - 1;
  3227. continue;
  3228. }
  3229. ++this.state.pos;
  3230. const esc = this.readCodePoint(true);
  3231. if (esc !== null) {
  3232. if (!identifierCheck(esc)) {
  3233. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  3234. }
  3235. word += String.fromCodePoint(esc);
  3236. }
  3237. chunkStart = this.state.pos;
  3238. } else {
  3239. break;
  3240. }
  3241. }
  3242. return word + this.input.slice(chunkStart, this.state.pos);
  3243. }
  3244. readWord(firstCode) {
  3245. const word = this.readWord1(firstCode);
  3246. const type = keywords$1.get(word);
  3247. if (type !== undefined) {
  3248. this.finishToken(type, tokenLabelName(type));
  3249. } else {
  3250. this.finishToken(132, word);
  3251. }
  3252. }
  3253. checkKeywordEscapes() {
  3254. const {
  3255. type
  3256. } = this.state;
  3257. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3258. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  3259. reservedWord: tokenLabelName(type)
  3260. });
  3261. }
  3262. }
  3263. raise(toParseError, at, details = {}) {
  3264. const loc = at instanceof Position ? at : at.loc.start;
  3265. const error = toParseError(loc, details);
  3266. if (!this.options.errorRecovery) throw error;
  3267. if (!this.isLookahead) this.state.errors.push(error);
  3268. return error;
  3269. }
  3270. raiseOverwrite(toParseError, at, details = {}) {
  3271. const loc = at instanceof Position ? at : at.loc.start;
  3272. const pos = loc.index;
  3273. const errors = this.state.errors;
  3274. for (let i = errors.length - 1; i >= 0; i--) {
  3275. const error = errors[i];
  3276. if (error.loc.index === pos) {
  3277. return errors[i] = toParseError(loc, details);
  3278. }
  3279. if (error.loc.index < pos) break;
  3280. }
  3281. return this.raise(toParseError, at, details);
  3282. }
  3283. updateContext(prevType) {}
  3284. unexpected(loc, type) {
  3285. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  3286. expected: type ? tokenLabelName(type) : null
  3287. });
  3288. }
  3289. expectPlugin(pluginName, loc) {
  3290. if (this.hasPlugin(pluginName)) {
  3291. return true;
  3292. }
  3293. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  3294. missingPlugin: [pluginName]
  3295. });
  3296. }
  3297. expectOnePlugin(pluginNames) {
  3298. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3299. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  3300. missingPlugin: pluginNames
  3301. });
  3302. }
  3303. }
  3304. errorBuilder(error) {
  3305. return (pos, lineStart, curLine) => {
  3306. this.raise(error, buildPosition(pos, lineStart, curLine));
  3307. };
  3308. }
  3309. }
  3310. class ClassScope {
  3311. constructor() {
  3312. this.privateNames = new Set();
  3313. this.loneAccessors = new Map();
  3314. this.undefinedPrivateNames = new Map();
  3315. }
  3316. }
  3317. class ClassScopeHandler {
  3318. constructor(parser) {
  3319. this.parser = void 0;
  3320. this.stack = [];
  3321. this.undefinedPrivateNames = new Map();
  3322. this.parser = parser;
  3323. }
  3324. current() {
  3325. return this.stack[this.stack.length - 1];
  3326. }
  3327. enter() {
  3328. this.stack.push(new ClassScope());
  3329. }
  3330. exit() {
  3331. const oldClassScope = this.stack.pop();
  3332. const current = this.current();
  3333. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3334. if (current) {
  3335. if (!current.undefinedPrivateNames.has(name)) {
  3336. current.undefinedPrivateNames.set(name, loc);
  3337. }
  3338. } else {
  3339. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3340. identifierName: name
  3341. });
  3342. }
  3343. }
  3344. }
  3345. declarePrivateName(name, elementType, loc) {
  3346. const {
  3347. privateNames,
  3348. loneAccessors,
  3349. undefinedPrivateNames
  3350. } = this.current();
  3351. let redefined = privateNames.has(name);
  3352. if (elementType & 3) {
  3353. const accessor = redefined && loneAccessors.get(name);
  3354. if (accessor) {
  3355. const oldStatic = accessor & 4;
  3356. const newStatic = elementType & 4;
  3357. const oldKind = accessor & 3;
  3358. const newKind = elementType & 3;
  3359. redefined = oldKind === newKind || oldStatic !== newStatic;
  3360. if (!redefined) loneAccessors.delete(name);
  3361. } else if (!redefined) {
  3362. loneAccessors.set(name, elementType);
  3363. }
  3364. }
  3365. if (redefined) {
  3366. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  3367. identifierName: name
  3368. });
  3369. }
  3370. privateNames.add(name);
  3371. undefinedPrivateNames.delete(name);
  3372. }
  3373. usePrivateName(name, loc) {
  3374. let classScope;
  3375. for (classScope of this.stack) {
  3376. if (classScope.privateNames.has(name)) return;
  3377. }
  3378. if (classScope) {
  3379. classScope.undefinedPrivateNames.set(name, loc);
  3380. } else {
  3381. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3382. identifierName: name
  3383. });
  3384. }
  3385. }
  3386. }
  3387. class ExpressionScope {
  3388. constructor(type = 0) {
  3389. this.type = type;
  3390. }
  3391. canBeArrowParameterDeclaration() {
  3392. return this.type === 2 || this.type === 1;
  3393. }
  3394. isCertainlyParameterDeclaration() {
  3395. return this.type === 3;
  3396. }
  3397. }
  3398. class ArrowHeadParsingScope extends ExpressionScope {
  3399. constructor(type) {
  3400. super(type);
  3401. this.declarationErrors = new Map();
  3402. }
  3403. recordDeclarationError(ParsingErrorClass, at) {
  3404. const index = at.index;
  3405. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3406. }
  3407. clearDeclarationError(index) {
  3408. this.declarationErrors.delete(index);
  3409. }
  3410. iterateErrors(iterator) {
  3411. this.declarationErrors.forEach(iterator);
  3412. }
  3413. }
  3414. class ExpressionScopeHandler {
  3415. constructor(parser) {
  3416. this.parser = void 0;
  3417. this.stack = [new ExpressionScope()];
  3418. this.parser = parser;
  3419. }
  3420. enter(scope) {
  3421. this.stack.push(scope);
  3422. }
  3423. exit() {
  3424. this.stack.pop();
  3425. }
  3426. recordParameterInitializerError(toParseError, node) {
  3427. const origin = node.loc.start;
  3428. const {
  3429. stack
  3430. } = this;
  3431. let i = stack.length - 1;
  3432. let scope = stack[i];
  3433. while (!scope.isCertainlyParameterDeclaration()) {
  3434. if (scope.canBeArrowParameterDeclaration()) {
  3435. scope.recordDeclarationError(toParseError, origin);
  3436. } else {
  3437. return;
  3438. }
  3439. scope = stack[--i];
  3440. }
  3441. this.parser.raise(toParseError, origin);
  3442. }
  3443. recordArrowParameterBindingError(error, node) {
  3444. const {
  3445. stack
  3446. } = this;
  3447. const scope = stack[stack.length - 1];
  3448. const origin = node.loc.start;
  3449. if (scope.isCertainlyParameterDeclaration()) {
  3450. this.parser.raise(error, origin);
  3451. } else if (scope.canBeArrowParameterDeclaration()) {
  3452. scope.recordDeclarationError(error, origin);
  3453. } else {
  3454. return;
  3455. }
  3456. }
  3457. recordAsyncArrowParametersError(at) {
  3458. const {
  3459. stack
  3460. } = this;
  3461. let i = stack.length - 1;
  3462. let scope = stack[i];
  3463. while (scope.canBeArrowParameterDeclaration()) {
  3464. if (scope.type === 2) {
  3465. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  3466. }
  3467. scope = stack[--i];
  3468. }
  3469. }
  3470. validateAsPattern() {
  3471. const {
  3472. stack
  3473. } = this;
  3474. const currentScope = stack[stack.length - 1];
  3475. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3476. currentScope.iterateErrors(([toParseError, loc]) => {
  3477. this.parser.raise(toParseError, loc);
  3478. let i = stack.length - 2;
  3479. let scope = stack[i];
  3480. while (scope.canBeArrowParameterDeclaration()) {
  3481. scope.clearDeclarationError(loc.index);
  3482. scope = stack[--i];
  3483. }
  3484. });
  3485. }
  3486. }
  3487. function newParameterDeclarationScope() {
  3488. return new ExpressionScope(3);
  3489. }
  3490. function newArrowHeadScope() {
  3491. return new ArrowHeadParsingScope(1);
  3492. }
  3493. function newAsyncArrowScope() {
  3494. return new ArrowHeadParsingScope(2);
  3495. }
  3496. function newExpressionScope() {
  3497. return new ExpressionScope();
  3498. }
  3499. class ProductionParameterHandler {
  3500. constructor() {
  3501. this.stacks = [];
  3502. }
  3503. enter(flags) {
  3504. this.stacks.push(flags);
  3505. }
  3506. exit() {
  3507. this.stacks.pop();
  3508. }
  3509. currentFlags() {
  3510. return this.stacks[this.stacks.length - 1];
  3511. }
  3512. get hasAwait() {
  3513. return (this.currentFlags() & 2) > 0;
  3514. }
  3515. get hasYield() {
  3516. return (this.currentFlags() & 1) > 0;
  3517. }
  3518. get hasReturn() {
  3519. return (this.currentFlags() & 4) > 0;
  3520. }
  3521. get hasIn() {
  3522. return (this.currentFlags() & 8) > 0;
  3523. }
  3524. }
  3525. function functionFlags(isAsync, isGenerator) {
  3526. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  3527. }
  3528. class UtilParser extends Tokenizer {
  3529. addExtra(node, key, value, enumerable = true) {
  3530. if (!node) return;
  3531. let {
  3532. extra
  3533. } = node;
  3534. if (extra == null) {
  3535. extra = {};
  3536. node.extra = extra;
  3537. }
  3538. if (enumerable) {
  3539. extra[key] = value;
  3540. } else {
  3541. Object.defineProperty(extra, key, {
  3542. enumerable,
  3543. value
  3544. });
  3545. }
  3546. }
  3547. isContextual(token) {
  3548. return this.state.type === token && !this.state.containsEsc;
  3549. }
  3550. isUnparsedContextual(nameStart, name) {
  3551. const nameEnd = nameStart + name.length;
  3552. if (this.input.slice(nameStart, nameEnd) === name) {
  3553. const nextCh = this.input.charCodeAt(nameEnd);
  3554. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3555. }
  3556. return false;
  3557. }
  3558. isLookaheadContextual(name) {
  3559. const next = this.nextTokenStart();
  3560. return this.isUnparsedContextual(next, name);
  3561. }
  3562. eatContextual(token) {
  3563. if (this.isContextual(token)) {
  3564. this.next();
  3565. return true;
  3566. }
  3567. return false;
  3568. }
  3569. expectContextual(token, toParseError) {
  3570. if (!this.eatContextual(token)) {
  3571. if (toParseError != null) {
  3572. throw this.raise(toParseError, this.state.startLoc);
  3573. }
  3574. this.unexpected(null, token);
  3575. }
  3576. }
  3577. canInsertSemicolon() {
  3578. return this.match(139) || this.match(8) || this.hasPrecedingLineBreak();
  3579. }
  3580. hasPrecedingLineBreak() {
  3581. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  3582. }
  3583. hasFollowingLineBreak() {
  3584. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  3585. }
  3586. isLineTerminator() {
  3587. return this.eat(13) || this.canInsertSemicolon();
  3588. }
  3589. semicolon(allowAsi = true) {
  3590. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3591. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  3592. }
  3593. expect(type, loc) {
  3594. if (!this.eat(type)) {
  3595. this.unexpected(loc, type);
  3596. }
  3597. }
  3598. tryParse(fn, oldState = this.state.clone()) {
  3599. const abortSignal = {
  3600. node: null
  3601. };
  3602. try {
  3603. const node = fn((node = null) => {
  3604. abortSignal.node = node;
  3605. throw abortSignal;
  3606. });
  3607. if (this.state.errors.length > oldState.errors.length) {
  3608. const failState = this.state;
  3609. this.state = oldState;
  3610. this.state.tokensLength = failState.tokensLength;
  3611. return {
  3612. node,
  3613. error: failState.errors[oldState.errors.length],
  3614. thrown: false,
  3615. aborted: false,
  3616. failState
  3617. };
  3618. }
  3619. return {
  3620. node,
  3621. error: null,
  3622. thrown: false,
  3623. aborted: false,
  3624. failState: null
  3625. };
  3626. } catch (error) {
  3627. const failState = this.state;
  3628. this.state = oldState;
  3629. if (error instanceof SyntaxError) {
  3630. return {
  3631. node: null,
  3632. error,
  3633. thrown: true,
  3634. aborted: false,
  3635. failState
  3636. };
  3637. }
  3638. if (error === abortSignal) {
  3639. return {
  3640. node: abortSignal.node,
  3641. error: null,
  3642. thrown: false,
  3643. aborted: true,
  3644. failState
  3645. };
  3646. }
  3647. throw error;
  3648. }
  3649. }
  3650. checkExpressionErrors(refExpressionErrors, andThrow) {
  3651. if (!refExpressionErrors) return false;
  3652. const {
  3653. shorthandAssignLoc,
  3654. doubleProtoLoc,
  3655. privateKeyLoc,
  3656. optionalParametersLoc
  3657. } = refExpressionErrors;
  3658. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3659. if (!andThrow) {
  3660. return hasErrors;
  3661. }
  3662. if (shorthandAssignLoc != null) {
  3663. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  3664. }
  3665. if (doubleProtoLoc != null) {
  3666. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  3667. }
  3668. if (privateKeyLoc != null) {
  3669. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  3670. }
  3671. if (optionalParametersLoc != null) {
  3672. this.unexpected(optionalParametersLoc);
  3673. }
  3674. }
  3675. isLiteralPropertyName() {
  3676. return tokenIsLiteralPropertyName(this.state.type);
  3677. }
  3678. isPrivateName(node) {
  3679. return node.type === "PrivateName";
  3680. }
  3681. getPrivateNameSV(node) {
  3682. return node.id.name;
  3683. }
  3684. hasPropertyAsPrivateName(node) {
  3685. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3686. }
  3687. isObjectProperty(node) {
  3688. return node.type === "ObjectProperty";
  3689. }
  3690. isObjectMethod(node) {
  3691. return node.type === "ObjectMethod";
  3692. }
  3693. initializeScopes(inModule = this.options.sourceType === "module") {
  3694. const oldLabels = this.state.labels;
  3695. this.state.labels = [];
  3696. const oldExportedIdentifiers = this.exportedIdentifiers;
  3697. this.exportedIdentifiers = new Set();
  3698. const oldInModule = this.inModule;
  3699. this.inModule = inModule;
  3700. const oldScope = this.scope;
  3701. const ScopeHandler = this.getScopeHandler();
  3702. this.scope = new ScopeHandler(this, inModule);
  3703. const oldProdParam = this.prodParam;
  3704. this.prodParam = new ProductionParameterHandler();
  3705. const oldClassScope = this.classScope;
  3706. this.classScope = new ClassScopeHandler(this);
  3707. const oldExpressionScope = this.expressionScope;
  3708. this.expressionScope = new ExpressionScopeHandler(this);
  3709. return () => {
  3710. this.state.labels = oldLabels;
  3711. this.exportedIdentifiers = oldExportedIdentifiers;
  3712. this.inModule = oldInModule;
  3713. this.scope = oldScope;
  3714. this.prodParam = oldProdParam;
  3715. this.classScope = oldClassScope;
  3716. this.expressionScope = oldExpressionScope;
  3717. };
  3718. }
  3719. enterInitialScopes() {
  3720. let paramFlags = 0;
  3721. if (this.inModule) {
  3722. paramFlags |= 2;
  3723. }
  3724. this.scope.enter(1);
  3725. this.prodParam.enter(paramFlags);
  3726. }
  3727. checkDestructuringPrivate(refExpressionErrors) {
  3728. const {
  3729. privateKeyLoc
  3730. } = refExpressionErrors;
  3731. if (privateKeyLoc !== null) {
  3732. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3733. }
  3734. }
  3735. }
  3736. class ExpressionErrors {
  3737. constructor() {
  3738. this.shorthandAssignLoc = null;
  3739. this.doubleProtoLoc = null;
  3740. this.privateKeyLoc = null;
  3741. this.optionalParametersLoc = null;
  3742. }
  3743. }
  3744. class Node {
  3745. constructor(parser, pos, loc) {
  3746. this.type = "";
  3747. this.start = pos;
  3748. this.end = 0;
  3749. this.loc = new SourceLocation(loc);
  3750. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3751. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3752. }
  3753. }
  3754. const NodePrototype = Node.prototype;
  3755. {
  3756. NodePrototype.__clone = function () {
  3757. const newNode = new Node(undefined, this.start, this.loc.start);
  3758. const keys = Object.keys(this);
  3759. for (let i = 0, length = keys.length; i < length; i++) {
  3760. const key = keys[i];
  3761. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3762. newNode[key] = this[key];
  3763. }
  3764. }
  3765. return newNode;
  3766. };
  3767. }
  3768. function clonePlaceholder(node) {
  3769. return cloneIdentifier(node);
  3770. }
  3771. function cloneIdentifier(node) {
  3772. const {
  3773. type,
  3774. start,
  3775. end,
  3776. loc,
  3777. range,
  3778. extra,
  3779. name
  3780. } = node;
  3781. const cloned = Object.create(NodePrototype);
  3782. cloned.type = type;
  3783. cloned.start = start;
  3784. cloned.end = end;
  3785. cloned.loc = loc;
  3786. cloned.range = range;
  3787. cloned.extra = extra;
  3788. cloned.name = name;
  3789. if (type === "Placeholder") {
  3790. cloned.expectedNode = node.expectedNode;
  3791. }
  3792. return cloned;
  3793. }
  3794. function cloneStringLiteral(node) {
  3795. const {
  3796. type,
  3797. start,
  3798. end,
  3799. loc,
  3800. range,
  3801. extra
  3802. } = node;
  3803. if (type === "Placeholder") {
  3804. return clonePlaceholder(node);
  3805. }
  3806. const cloned = Object.create(NodePrototype);
  3807. cloned.type = type;
  3808. cloned.start = start;
  3809. cloned.end = end;
  3810. cloned.loc = loc;
  3811. cloned.range = range;
  3812. if (node.raw !== undefined) {
  3813. cloned.raw = node.raw;
  3814. } else {
  3815. cloned.extra = extra;
  3816. }
  3817. cloned.value = node.value;
  3818. return cloned;
  3819. }
  3820. class NodeUtils extends UtilParser {
  3821. startNode() {
  3822. const loc = this.state.startLoc;
  3823. return new Node(this, loc.index, loc);
  3824. }
  3825. startNodeAt(loc) {
  3826. return new Node(this, loc.index, loc);
  3827. }
  3828. startNodeAtNode(type) {
  3829. return this.startNodeAt(type.loc.start);
  3830. }
  3831. finishNode(node, type) {
  3832. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3833. }
  3834. finishNodeAt(node, type, endLoc) {
  3835. node.type = type;
  3836. node.end = endLoc.index;
  3837. node.loc.end = endLoc;
  3838. if (this.options.ranges) node.range[1] = endLoc.index;
  3839. if (this.options.attachComment) this.processComment(node);
  3840. return node;
  3841. }
  3842. resetStartLocation(node, startLoc) {
  3843. node.start = startLoc.index;
  3844. node.loc.start = startLoc;
  3845. if (this.options.ranges) node.range[0] = startLoc.index;
  3846. }
  3847. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3848. node.end = endLoc.index;
  3849. node.loc.end = endLoc;
  3850. if (this.options.ranges) node.range[1] = endLoc.index;
  3851. }
  3852. resetStartLocationFromNode(node, locationNode) {
  3853. this.resetStartLocation(node, locationNode.loc.start);
  3854. }
  3855. }
  3856. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3857. const FlowErrors = ParseErrorEnum`flow`({
  3858. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3859. 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.",
  3860. AssignReservedType: ({
  3861. reservedType
  3862. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3863. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3864. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3865. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3866. EnumBooleanMemberNotInitialized: ({
  3867. memberName,
  3868. enumName
  3869. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3870. EnumDuplicateMemberName: ({
  3871. memberName,
  3872. enumName
  3873. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3874. EnumInconsistentMemberValues: ({
  3875. enumName
  3876. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3877. EnumInvalidExplicitType: ({
  3878. invalidEnumType,
  3879. enumName
  3880. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3881. EnumInvalidExplicitTypeUnknownSupplied: ({
  3882. enumName
  3883. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3884. EnumInvalidMemberInitializerPrimaryType: ({
  3885. enumName,
  3886. memberName,
  3887. explicitType
  3888. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3889. EnumInvalidMemberInitializerSymbolType: ({
  3890. enumName,
  3891. memberName
  3892. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3893. EnumInvalidMemberInitializerUnknownType: ({
  3894. enumName,
  3895. memberName
  3896. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3897. EnumInvalidMemberName: ({
  3898. enumName,
  3899. memberName,
  3900. suggestion
  3901. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3902. EnumNumberMemberNotInitialized: ({
  3903. enumName,
  3904. memberName
  3905. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3906. EnumStringMemberInconsistentlyInitialized: ({
  3907. enumName
  3908. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3909. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3910. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3911. 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.",
  3912. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3913. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3914. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3915. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3916. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3917. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3918. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3919. PatternIsOptional: Object.assign({
  3920. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3921. }, {
  3922. reasonCode: "OptionalBindingPattern"
  3923. }),
  3924. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3925. SpreadVariance: "Spread properties cannot have variance.",
  3926. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3927. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3928. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3929. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3930. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3931. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3932. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3933. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3934. UnexpectedReservedType: ({
  3935. reservedType
  3936. }) => `Unexpected reserved type ${reservedType}.`,
  3937. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3938. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3939. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3940. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3941. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3942. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3943. UnsupportedDeclareExportKind: ({
  3944. unsupportedExportKind,
  3945. suggestion
  3946. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  3947. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3948. UnterminatedFlowComment: "Unterminated flow-comment."
  3949. });
  3950. function isEsModuleType(bodyElement) {
  3951. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3952. }
  3953. function hasTypeImportKind(node) {
  3954. return node.importKind === "type" || node.importKind === "typeof";
  3955. }
  3956. const exportSuggestions = {
  3957. const: "declare export var",
  3958. let: "declare export var",
  3959. type: "export type",
  3960. interface: "export interface"
  3961. };
  3962. function partition(list, test) {
  3963. const list1 = [];
  3964. const list2 = [];
  3965. for (let i = 0; i < list.length; i++) {
  3966. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  3967. }
  3968. return [list1, list2];
  3969. }
  3970. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  3971. var flow = superClass => class FlowParserMixin extends superClass {
  3972. constructor(...args) {
  3973. super(...args);
  3974. this.flowPragma = undefined;
  3975. }
  3976. getScopeHandler() {
  3977. return FlowScopeHandler;
  3978. }
  3979. shouldParseTypes() {
  3980. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  3981. }
  3982. finishToken(type, val) {
  3983. if (type !== 133 && type !== 13 && type !== 28) {
  3984. if (this.flowPragma === undefined) {
  3985. this.flowPragma = null;
  3986. }
  3987. }
  3988. super.finishToken(type, val);
  3989. }
  3990. addComment(comment) {
  3991. if (this.flowPragma === undefined) {
  3992. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  3993. if (!matches) ;else if (matches[1] === "flow") {
  3994. this.flowPragma = "flow";
  3995. } else if (matches[1] === "noflow") {
  3996. this.flowPragma = "noflow";
  3997. } else {
  3998. throw new Error("Unexpected flow pragma");
  3999. }
  4000. }
  4001. super.addComment(comment);
  4002. }
  4003. flowParseTypeInitialiser(tok) {
  4004. const oldInType = this.state.inType;
  4005. this.state.inType = true;
  4006. this.expect(tok || 14);
  4007. const type = this.flowParseType();
  4008. this.state.inType = oldInType;
  4009. return type;
  4010. }
  4011. flowParsePredicate() {
  4012. const node = this.startNode();
  4013. const moduloLoc = this.state.startLoc;
  4014. this.next();
  4015. this.expectContextual(110);
  4016. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  4017. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  4018. }
  4019. if (this.eat(10)) {
  4020. node.value = super.parseExpression();
  4021. this.expect(11);
  4022. return this.finishNode(node, "DeclaredPredicate");
  4023. } else {
  4024. return this.finishNode(node, "InferredPredicate");
  4025. }
  4026. }
  4027. flowParseTypeAndPredicateInitialiser() {
  4028. const oldInType = this.state.inType;
  4029. this.state.inType = true;
  4030. this.expect(14);
  4031. let type = null;
  4032. let predicate = null;
  4033. if (this.match(54)) {
  4034. this.state.inType = oldInType;
  4035. predicate = this.flowParsePredicate();
  4036. } else {
  4037. type = this.flowParseType();
  4038. this.state.inType = oldInType;
  4039. if (this.match(54)) {
  4040. predicate = this.flowParsePredicate();
  4041. }
  4042. }
  4043. return [type, predicate];
  4044. }
  4045. flowParseDeclareClass(node) {
  4046. this.next();
  4047. this.flowParseInterfaceish(node, true);
  4048. return this.finishNode(node, "DeclareClass");
  4049. }
  4050. flowParseDeclareFunction(node) {
  4051. this.next();
  4052. const id = node.id = this.parseIdentifier();
  4053. const typeNode = this.startNode();
  4054. const typeContainer = this.startNode();
  4055. if (this.match(47)) {
  4056. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4057. } else {
  4058. typeNode.typeParameters = null;
  4059. }
  4060. this.expect(10);
  4061. const tmp = this.flowParseFunctionTypeParams();
  4062. typeNode.params = tmp.params;
  4063. typeNode.rest = tmp.rest;
  4064. typeNode.this = tmp._this;
  4065. this.expect(11);
  4066. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4067. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4068. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4069. this.resetEndLocation(id);
  4070. this.semicolon();
  4071. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4072. return this.finishNode(node, "DeclareFunction");
  4073. }
  4074. flowParseDeclare(node, insideModule) {
  4075. if (this.match(80)) {
  4076. return this.flowParseDeclareClass(node);
  4077. } else if (this.match(68)) {
  4078. return this.flowParseDeclareFunction(node);
  4079. } else if (this.match(74)) {
  4080. return this.flowParseDeclareVariable(node);
  4081. } else if (this.eatContextual(127)) {
  4082. if (this.match(16)) {
  4083. return this.flowParseDeclareModuleExports(node);
  4084. } else {
  4085. if (insideModule) {
  4086. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  4087. }
  4088. return this.flowParseDeclareModule(node);
  4089. }
  4090. } else if (this.isContextual(130)) {
  4091. return this.flowParseDeclareTypeAlias(node);
  4092. } else if (this.isContextual(131)) {
  4093. return this.flowParseDeclareOpaqueType(node);
  4094. } else if (this.isContextual(129)) {
  4095. return this.flowParseDeclareInterface(node);
  4096. } else if (this.match(82)) {
  4097. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4098. } else {
  4099. this.unexpected();
  4100. }
  4101. }
  4102. flowParseDeclareVariable(node) {
  4103. this.next();
  4104. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4105. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4106. this.semicolon();
  4107. return this.finishNode(node, "DeclareVariable");
  4108. }
  4109. flowParseDeclareModule(node) {
  4110. this.scope.enter(0);
  4111. if (this.match(133)) {
  4112. node.id = super.parseExprAtom();
  4113. } else {
  4114. node.id = this.parseIdentifier();
  4115. }
  4116. const bodyNode = node.body = this.startNode();
  4117. const body = bodyNode.body = [];
  4118. this.expect(5);
  4119. while (!this.match(8)) {
  4120. let bodyNode = this.startNode();
  4121. if (this.match(83)) {
  4122. this.next();
  4123. if (!this.isContextual(130) && !this.match(87)) {
  4124. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  4125. }
  4126. super.parseImport(bodyNode);
  4127. } else {
  4128. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4129. bodyNode = this.flowParseDeclare(bodyNode, true);
  4130. }
  4131. body.push(bodyNode);
  4132. }
  4133. this.scope.exit();
  4134. this.expect(8);
  4135. this.finishNode(bodyNode, "BlockStatement");
  4136. let kind = null;
  4137. let hasModuleExport = false;
  4138. body.forEach(bodyElement => {
  4139. if (isEsModuleType(bodyElement)) {
  4140. if (kind === "CommonJS") {
  4141. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4142. }
  4143. kind = "ES";
  4144. } else if (bodyElement.type === "DeclareModuleExports") {
  4145. if (hasModuleExport) {
  4146. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  4147. }
  4148. if (kind === "ES") {
  4149. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4150. }
  4151. kind = "CommonJS";
  4152. hasModuleExport = true;
  4153. }
  4154. });
  4155. node.kind = kind || "CommonJS";
  4156. return this.finishNode(node, "DeclareModule");
  4157. }
  4158. flowParseDeclareExportDeclaration(node, insideModule) {
  4159. this.expect(82);
  4160. if (this.eat(65)) {
  4161. if (this.match(68) || this.match(80)) {
  4162. node.declaration = this.flowParseDeclare(this.startNode());
  4163. } else {
  4164. node.declaration = this.flowParseType();
  4165. this.semicolon();
  4166. }
  4167. node.default = true;
  4168. return this.finishNode(node, "DeclareExportDeclaration");
  4169. } else {
  4170. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4171. const label = this.state.value;
  4172. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  4173. unsupportedExportKind: label,
  4174. suggestion: exportSuggestions[label]
  4175. });
  4176. }
  4177. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4178. node.declaration = this.flowParseDeclare(this.startNode());
  4179. node.default = false;
  4180. return this.finishNode(node, "DeclareExportDeclaration");
  4181. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4182. node = this.parseExport(node, null);
  4183. if (node.type === "ExportNamedDeclaration") {
  4184. node.type = "ExportDeclaration";
  4185. node.default = false;
  4186. delete node.exportKind;
  4187. }
  4188. node.type = "Declare" + node.type;
  4189. return node;
  4190. }
  4191. }
  4192. this.unexpected();
  4193. }
  4194. flowParseDeclareModuleExports(node) {
  4195. this.next();
  4196. this.expectContextual(111);
  4197. node.typeAnnotation = this.flowParseTypeAnnotation();
  4198. this.semicolon();
  4199. return this.finishNode(node, "DeclareModuleExports");
  4200. }
  4201. flowParseDeclareTypeAlias(node) {
  4202. this.next();
  4203. const finished = this.flowParseTypeAlias(node);
  4204. finished.type = "DeclareTypeAlias";
  4205. return finished;
  4206. }
  4207. flowParseDeclareOpaqueType(node) {
  4208. this.next();
  4209. const finished = this.flowParseOpaqueType(node, true);
  4210. finished.type = "DeclareOpaqueType";
  4211. return finished;
  4212. }
  4213. flowParseDeclareInterface(node) {
  4214. this.next();
  4215. this.flowParseInterfaceish(node, false);
  4216. return this.finishNode(node, "DeclareInterface");
  4217. }
  4218. flowParseInterfaceish(node, isClass) {
  4219. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4220. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4221. if (this.match(47)) {
  4222. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4223. } else {
  4224. node.typeParameters = null;
  4225. }
  4226. node.extends = [];
  4227. if (this.eat(81)) {
  4228. do {
  4229. node.extends.push(this.flowParseInterfaceExtends());
  4230. } while (!isClass && this.eat(12));
  4231. }
  4232. if (isClass) {
  4233. node.implements = [];
  4234. node.mixins = [];
  4235. if (this.eatContextual(117)) {
  4236. do {
  4237. node.mixins.push(this.flowParseInterfaceExtends());
  4238. } while (this.eat(12));
  4239. }
  4240. if (this.eatContextual(113)) {
  4241. do {
  4242. node.implements.push(this.flowParseInterfaceExtends());
  4243. } while (this.eat(12));
  4244. }
  4245. }
  4246. node.body = this.flowParseObjectType({
  4247. allowStatic: isClass,
  4248. allowExact: false,
  4249. allowSpread: false,
  4250. allowProto: isClass,
  4251. allowInexact: false
  4252. });
  4253. }
  4254. flowParseInterfaceExtends() {
  4255. const node = this.startNode();
  4256. node.id = this.flowParseQualifiedTypeIdentifier();
  4257. if (this.match(47)) {
  4258. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4259. } else {
  4260. node.typeParameters = null;
  4261. }
  4262. return this.finishNode(node, "InterfaceExtends");
  4263. }
  4264. flowParseInterface(node) {
  4265. this.flowParseInterfaceish(node, false);
  4266. return this.finishNode(node, "InterfaceDeclaration");
  4267. }
  4268. checkNotUnderscore(word) {
  4269. if (word === "_") {
  4270. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  4271. }
  4272. }
  4273. checkReservedType(word, startLoc, declaration) {
  4274. if (!reservedTypes.has(word)) return;
  4275. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  4276. reservedType: word
  4277. });
  4278. }
  4279. flowParseRestrictedIdentifier(liberal, declaration) {
  4280. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4281. return this.parseIdentifier(liberal);
  4282. }
  4283. flowParseTypeAlias(node) {
  4284. node.id = this.flowParseRestrictedIdentifier(false, true);
  4285. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4286. if (this.match(47)) {
  4287. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4288. } else {
  4289. node.typeParameters = null;
  4290. }
  4291. node.right = this.flowParseTypeInitialiser(29);
  4292. this.semicolon();
  4293. return this.finishNode(node, "TypeAlias");
  4294. }
  4295. flowParseOpaqueType(node, declare) {
  4296. this.expectContextual(130);
  4297. node.id = this.flowParseRestrictedIdentifier(true, true);
  4298. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4299. if (this.match(47)) {
  4300. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4301. } else {
  4302. node.typeParameters = null;
  4303. }
  4304. node.supertype = null;
  4305. if (this.match(14)) {
  4306. node.supertype = this.flowParseTypeInitialiser(14);
  4307. }
  4308. node.impltype = null;
  4309. if (!declare) {
  4310. node.impltype = this.flowParseTypeInitialiser(29);
  4311. }
  4312. this.semicolon();
  4313. return this.finishNode(node, "OpaqueType");
  4314. }
  4315. flowParseTypeParameter(requireDefault = false) {
  4316. const nodeStartLoc = this.state.startLoc;
  4317. const node = this.startNode();
  4318. const variance = this.flowParseVariance();
  4319. const ident = this.flowParseTypeAnnotatableIdentifier();
  4320. node.name = ident.name;
  4321. node.variance = variance;
  4322. node.bound = ident.typeAnnotation;
  4323. if (this.match(29)) {
  4324. this.eat(29);
  4325. node.default = this.flowParseType();
  4326. } else {
  4327. if (requireDefault) {
  4328. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  4329. }
  4330. }
  4331. return this.finishNode(node, "TypeParameter");
  4332. }
  4333. flowParseTypeParameterDeclaration() {
  4334. const oldInType = this.state.inType;
  4335. const node = this.startNode();
  4336. node.params = [];
  4337. this.state.inType = true;
  4338. if (this.match(47) || this.match(142)) {
  4339. this.next();
  4340. } else {
  4341. this.unexpected();
  4342. }
  4343. let defaultRequired = false;
  4344. do {
  4345. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4346. node.params.push(typeParameter);
  4347. if (typeParameter.default) {
  4348. defaultRequired = true;
  4349. }
  4350. if (!this.match(48)) {
  4351. this.expect(12);
  4352. }
  4353. } while (!this.match(48));
  4354. this.expect(48);
  4355. this.state.inType = oldInType;
  4356. return this.finishNode(node, "TypeParameterDeclaration");
  4357. }
  4358. flowParseTypeParameterInstantiation() {
  4359. const node = this.startNode();
  4360. const oldInType = this.state.inType;
  4361. node.params = [];
  4362. this.state.inType = true;
  4363. this.expect(47);
  4364. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4365. this.state.noAnonFunctionType = false;
  4366. while (!this.match(48)) {
  4367. node.params.push(this.flowParseType());
  4368. if (!this.match(48)) {
  4369. this.expect(12);
  4370. }
  4371. }
  4372. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4373. this.expect(48);
  4374. this.state.inType = oldInType;
  4375. return this.finishNode(node, "TypeParameterInstantiation");
  4376. }
  4377. flowParseTypeParameterInstantiationCallOrNew() {
  4378. const node = this.startNode();
  4379. const oldInType = this.state.inType;
  4380. node.params = [];
  4381. this.state.inType = true;
  4382. this.expect(47);
  4383. while (!this.match(48)) {
  4384. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4385. if (!this.match(48)) {
  4386. this.expect(12);
  4387. }
  4388. }
  4389. this.expect(48);
  4390. this.state.inType = oldInType;
  4391. return this.finishNode(node, "TypeParameterInstantiation");
  4392. }
  4393. flowParseInterfaceType() {
  4394. const node = this.startNode();
  4395. this.expectContextual(129);
  4396. node.extends = [];
  4397. if (this.eat(81)) {
  4398. do {
  4399. node.extends.push(this.flowParseInterfaceExtends());
  4400. } while (this.eat(12));
  4401. }
  4402. node.body = this.flowParseObjectType({
  4403. allowStatic: false,
  4404. allowExact: false,
  4405. allowSpread: false,
  4406. allowProto: false,
  4407. allowInexact: false
  4408. });
  4409. return this.finishNode(node, "InterfaceTypeAnnotation");
  4410. }
  4411. flowParseObjectPropertyKey() {
  4412. return this.match(134) || this.match(133) ? super.parseExprAtom() : this.parseIdentifier(true);
  4413. }
  4414. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4415. node.static = isStatic;
  4416. if (this.lookahead().type === 14) {
  4417. node.id = this.flowParseObjectPropertyKey();
  4418. node.key = this.flowParseTypeInitialiser();
  4419. } else {
  4420. node.id = null;
  4421. node.key = this.flowParseType();
  4422. }
  4423. this.expect(3);
  4424. node.value = this.flowParseTypeInitialiser();
  4425. node.variance = variance;
  4426. return this.finishNode(node, "ObjectTypeIndexer");
  4427. }
  4428. flowParseObjectTypeInternalSlot(node, isStatic) {
  4429. node.static = isStatic;
  4430. node.id = this.flowParseObjectPropertyKey();
  4431. this.expect(3);
  4432. this.expect(3);
  4433. if (this.match(47) || this.match(10)) {
  4434. node.method = true;
  4435. node.optional = false;
  4436. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4437. } else {
  4438. node.method = false;
  4439. if (this.eat(17)) {
  4440. node.optional = true;
  4441. }
  4442. node.value = this.flowParseTypeInitialiser();
  4443. }
  4444. return this.finishNode(node, "ObjectTypeInternalSlot");
  4445. }
  4446. flowParseObjectTypeMethodish(node) {
  4447. node.params = [];
  4448. node.rest = null;
  4449. node.typeParameters = null;
  4450. node.this = null;
  4451. if (this.match(47)) {
  4452. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4453. }
  4454. this.expect(10);
  4455. if (this.match(78)) {
  4456. node.this = this.flowParseFunctionTypeParam(true);
  4457. node.this.name = null;
  4458. if (!this.match(11)) {
  4459. this.expect(12);
  4460. }
  4461. }
  4462. while (!this.match(11) && !this.match(21)) {
  4463. node.params.push(this.flowParseFunctionTypeParam(false));
  4464. if (!this.match(11)) {
  4465. this.expect(12);
  4466. }
  4467. }
  4468. if (this.eat(21)) {
  4469. node.rest = this.flowParseFunctionTypeParam(false);
  4470. }
  4471. this.expect(11);
  4472. node.returnType = this.flowParseTypeInitialiser();
  4473. return this.finishNode(node, "FunctionTypeAnnotation");
  4474. }
  4475. flowParseObjectTypeCallProperty(node, isStatic) {
  4476. const valueNode = this.startNode();
  4477. node.static = isStatic;
  4478. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4479. return this.finishNode(node, "ObjectTypeCallProperty");
  4480. }
  4481. flowParseObjectType({
  4482. allowStatic,
  4483. allowExact,
  4484. allowSpread,
  4485. allowProto,
  4486. allowInexact
  4487. }) {
  4488. const oldInType = this.state.inType;
  4489. this.state.inType = true;
  4490. const nodeStart = this.startNode();
  4491. nodeStart.callProperties = [];
  4492. nodeStart.properties = [];
  4493. nodeStart.indexers = [];
  4494. nodeStart.internalSlots = [];
  4495. let endDelim;
  4496. let exact;
  4497. let inexact = false;
  4498. if (allowExact && this.match(6)) {
  4499. this.expect(6);
  4500. endDelim = 9;
  4501. exact = true;
  4502. } else {
  4503. this.expect(5);
  4504. endDelim = 8;
  4505. exact = false;
  4506. }
  4507. nodeStart.exact = exact;
  4508. while (!this.match(endDelim)) {
  4509. let isStatic = false;
  4510. let protoStartLoc = null;
  4511. let inexactStartLoc = null;
  4512. const node = this.startNode();
  4513. if (allowProto && this.isContextual(118)) {
  4514. const lookahead = this.lookahead();
  4515. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4516. this.next();
  4517. protoStartLoc = this.state.startLoc;
  4518. allowStatic = false;
  4519. }
  4520. }
  4521. if (allowStatic && this.isContextual(106)) {
  4522. const lookahead = this.lookahead();
  4523. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4524. this.next();
  4525. isStatic = true;
  4526. }
  4527. }
  4528. const variance = this.flowParseVariance();
  4529. if (this.eat(0)) {
  4530. if (protoStartLoc != null) {
  4531. this.unexpected(protoStartLoc);
  4532. }
  4533. if (this.eat(0)) {
  4534. if (variance) {
  4535. this.unexpected(variance.loc.start);
  4536. }
  4537. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4538. } else {
  4539. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4540. }
  4541. } else if (this.match(10) || this.match(47)) {
  4542. if (protoStartLoc != null) {
  4543. this.unexpected(protoStartLoc);
  4544. }
  4545. if (variance) {
  4546. this.unexpected(variance.loc.start);
  4547. }
  4548. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4549. } else {
  4550. let kind = "init";
  4551. if (this.isContextual(99) || this.isContextual(104)) {
  4552. const lookahead = this.lookahead();
  4553. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4554. kind = this.state.value;
  4555. this.next();
  4556. }
  4557. }
  4558. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4559. if (propOrInexact === null) {
  4560. inexact = true;
  4561. inexactStartLoc = this.state.lastTokStartLoc;
  4562. } else {
  4563. nodeStart.properties.push(propOrInexact);
  4564. }
  4565. }
  4566. this.flowObjectTypeSemicolon();
  4567. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4568. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  4569. }
  4570. }
  4571. this.expect(endDelim);
  4572. if (allowSpread) {
  4573. nodeStart.inexact = inexact;
  4574. }
  4575. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4576. this.state.inType = oldInType;
  4577. return out;
  4578. }
  4579. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4580. if (this.eat(21)) {
  4581. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4582. if (isInexactToken) {
  4583. if (!allowSpread) {
  4584. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  4585. } else if (!allowInexact) {
  4586. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  4587. }
  4588. if (variance) {
  4589. this.raise(FlowErrors.InexactVariance, variance);
  4590. }
  4591. return null;
  4592. }
  4593. if (!allowSpread) {
  4594. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  4595. }
  4596. if (protoStartLoc != null) {
  4597. this.unexpected(protoStartLoc);
  4598. }
  4599. if (variance) {
  4600. this.raise(FlowErrors.SpreadVariance, variance);
  4601. }
  4602. node.argument = this.flowParseType();
  4603. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4604. } else {
  4605. node.key = this.flowParseObjectPropertyKey();
  4606. node.static = isStatic;
  4607. node.proto = protoStartLoc != null;
  4608. node.kind = kind;
  4609. let optional = false;
  4610. if (this.match(47) || this.match(10)) {
  4611. node.method = true;
  4612. if (protoStartLoc != null) {
  4613. this.unexpected(protoStartLoc);
  4614. }
  4615. if (variance) {
  4616. this.unexpected(variance.loc.start);
  4617. }
  4618. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4619. if (kind === "get" || kind === "set") {
  4620. this.flowCheckGetterSetterParams(node);
  4621. }
  4622. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4623. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  4624. }
  4625. } else {
  4626. if (kind !== "init") this.unexpected();
  4627. node.method = false;
  4628. if (this.eat(17)) {
  4629. optional = true;
  4630. }
  4631. node.value = this.flowParseTypeInitialiser();
  4632. node.variance = variance;
  4633. }
  4634. node.optional = optional;
  4635. return this.finishNode(node, "ObjectTypeProperty");
  4636. }
  4637. }
  4638. flowCheckGetterSetterParams(property) {
  4639. const paramCount = property.kind === "get" ? 0 : 1;
  4640. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4641. if (property.value.this) {
  4642. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  4643. }
  4644. if (length !== paramCount) {
  4645. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  4646. }
  4647. if (property.kind === "set" && property.value.rest) {
  4648. this.raise(Errors.BadSetterRestParameter, property);
  4649. }
  4650. }
  4651. flowObjectTypeSemicolon() {
  4652. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4653. this.unexpected();
  4654. }
  4655. }
  4656. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4657. var _startLoc;
  4658. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4659. let node = id || this.flowParseRestrictedIdentifier(true);
  4660. while (this.eat(16)) {
  4661. const node2 = this.startNodeAt(startLoc);
  4662. node2.qualification = node;
  4663. node2.id = this.flowParseRestrictedIdentifier(true);
  4664. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4665. }
  4666. return node;
  4667. }
  4668. flowParseGenericType(startLoc, id) {
  4669. const node = this.startNodeAt(startLoc);
  4670. node.typeParameters = null;
  4671. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4672. if (this.match(47)) {
  4673. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4674. }
  4675. return this.finishNode(node, "GenericTypeAnnotation");
  4676. }
  4677. flowParseTypeofType() {
  4678. const node = this.startNode();
  4679. this.expect(87);
  4680. node.argument = this.flowParsePrimaryType();
  4681. return this.finishNode(node, "TypeofTypeAnnotation");
  4682. }
  4683. flowParseTupleType() {
  4684. const node = this.startNode();
  4685. node.types = [];
  4686. this.expect(0);
  4687. while (this.state.pos < this.length && !this.match(3)) {
  4688. node.types.push(this.flowParseType());
  4689. if (this.match(3)) break;
  4690. this.expect(12);
  4691. }
  4692. this.expect(3);
  4693. return this.finishNode(node, "TupleTypeAnnotation");
  4694. }
  4695. flowParseFunctionTypeParam(first) {
  4696. let name = null;
  4697. let optional = false;
  4698. let typeAnnotation = null;
  4699. const node = this.startNode();
  4700. const lh = this.lookahead();
  4701. const isThis = this.state.type === 78;
  4702. if (lh.type === 14 || lh.type === 17) {
  4703. if (isThis && !first) {
  4704. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  4705. }
  4706. name = this.parseIdentifier(isThis);
  4707. if (this.eat(17)) {
  4708. optional = true;
  4709. if (isThis) {
  4710. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  4711. }
  4712. }
  4713. typeAnnotation = this.flowParseTypeInitialiser();
  4714. } else {
  4715. typeAnnotation = this.flowParseType();
  4716. }
  4717. node.name = name;
  4718. node.optional = optional;
  4719. node.typeAnnotation = typeAnnotation;
  4720. return this.finishNode(node, "FunctionTypeParam");
  4721. }
  4722. reinterpretTypeAsFunctionTypeParam(type) {
  4723. const node = this.startNodeAt(type.loc.start);
  4724. node.name = null;
  4725. node.optional = false;
  4726. node.typeAnnotation = type;
  4727. return this.finishNode(node, "FunctionTypeParam");
  4728. }
  4729. flowParseFunctionTypeParams(params = []) {
  4730. let rest = null;
  4731. let _this = null;
  4732. if (this.match(78)) {
  4733. _this = this.flowParseFunctionTypeParam(true);
  4734. _this.name = null;
  4735. if (!this.match(11)) {
  4736. this.expect(12);
  4737. }
  4738. }
  4739. while (!this.match(11) && !this.match(21)) {
  4740. params.push(this.flowParseFunctionTypeParam(false));
  4741. if (!this.match(11)) {
  4742. this.expect(12);
  4743. }
  4744. }
  4745. if (this.eat(21)) {
  4746. rest = this.flowParseFunctionTypeParam(false);
  4747. }
  4748. return {
  4749. params,
  4750. rest,
  4751. _this
  4752. };
  4753. }
  4754. flowIdentToTypeAnnotation(startLoc, node, id) {
  4755. switch (id.name) {
  4756. case "any":
  4757. return this.finishNode(node, "AnyTypeAnnotation");
  4758. case "bool":
  4759. case "boolean":
  4760. return this.finishNode(node, "BooleanTypeAnnotation");
  4761. case "mixed":
  4762. return this.finishNode(node, "MixedTypeAnnotation");
  4763. case "empty":
  4764. return this.finishNode(node, "EmptyTypeAnnotation");
  4765. case "number":
  4766. return this.finishNode(node, "NumberTypeAnnotation");
  4767. case "string":
  4768. return this.finishNode(node, "StringTypeAnnotation");
  4769. case "symbol":
  4770. return this.finishNode(node, "SymbolTypeAnnotation");
  4771. default:
  4772. this.checkNotUnderscore(id.name);
  4773. return this.flowParseGenericType(startLoc, id);
  4774. }
  4775. }
  4776. flowParsePrimaryType() {
  4777. const startLoc = this.state.startLoc;
  4778. const node = this.startNode();
  4779. let tmp;
  4780. let type;
  4781. let isGroupedType = false;
  4782. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4783. switch (this.state.type) {
  4784. case 5:
  4785. return this.flowParseObjectType({
  4786. allowStatic: false,
  4787. allowExact: false,
  4788. allowSpread: true,
  4789. allowProto: false,
  4790. allowInexact: true
  4791. });
  4792. case 6:
  4793. return this.flowParseObjectType({
  4794. allowStatic: false,
  4795. allowExact: true,
  4796. allowSpread: true,
  4797. allowProto: false,
  4798. allowInexact: false
  4799. });
  4800. case 0:
  4801. this.state.noAnonFunctionType = false;
  4802. type = this.flowParseTupleType();
  4803. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4804. return type;
  4805. case 47:
  4806. {
  4807. const node = this.startNode();
  4808. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4809. this.expect(10);
  4810. tmp = this.flowParseFunctionTypeParams();
  4811. node.params = tmp.params;
  4812. node.rest = tmp.rest;
  4813. node.this = tmp._this;
  4814. this.expect(11);
  4815. this.expect(19);
  4816. node.returnType = this.flowParseType();
  4817. return this.finishNode(node, "FunctionTypeAnnotation");
  4818. }
  4819. case 10:
  4820. {
  4821. const node = this.startNode();
  4822. this.next();
  4823. if (!this.match(11) && !this.match(21)) {
  4824. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4825. const token = this.lookahead().type;
  4826. isGroupedType = token !== 17 && token !== 14;
  4827. } else {
  4828. isGroupedType = true;
  4829. }
  4830. }
  4831. if (isGroupedType) {
  4832. this.state.noAnonFunctionType = false;
  4833. type = this.flowParseType();
  4834. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4835. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4836. this.expect(11);
  4837. return type;
  4838. } else {
  4839. this.eat(12);
  4840. }
  4841. }
  4842. if (type) {
  4843. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4844. } else {
  4845. tmp = this.flowParseFunctionTypeParams();
  4846. }
  4847. node.params = tmp.params;
  4848. node.rest = tmp.rest;
  4849. node.this = tmp._this;
  4850. this.expect(11);
  4851. this.expect(19);
  4852. node.returnType = this.flowParseType();
  4853. node.typeParameters = null;
  4854. return this.finishNode(node, "FunctionTypeAnnotation");
  4855. }
  4856. case 133:
  4857. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4858. case 85:
  4859. case 86:
  4860. node.value = this.match(85);
  4861. this.next();
  4862. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4863. case 53:
  4864. if (this.state.value === "-") {
  4865. this.next();
  4866. if (this.match(134)) {
  4867. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4868. }
  4869. if (this.match(135)) {
  4870. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4871. }
  4872. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  4873. }
  4874. this.unexpected();
  4875. return;
  4876. case 134:
  4877. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4878. case 135:
  4879. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4880. case 88:
  4881. this.next();
  4882. return this.finishNode(node, "VoidTypeAnnotation");
  4883. case 84:
  4884. this.next();
  4885. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4886. case 78:
  4887. this.next();
  4888. return this.finishNode(node, "ThisTypeAnnotation");
  4889. case 55:
  4890. this.next();
  4891. return this.finishNode(node, "ExistsTypeAnnotation");
  4892. case 87:
  4893. return this.flowParseTypeofType();
  4894. default:
  4895. if (tokenIsKeyword(this.state.type)) {
  4896. const label = tokenLabelName(this.state.type);
  4897. this.next();
  4898. return super.createIdentifier(node, label);
  4899. } else if (tokenIsIdentifier(this.state.type)) {
  4900. if (this.isContextual(129)) {
  4901. return this.flowParseInterfaceType();
  4902. }
  4903. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4904. }
  4905. }
  4906. this.unexpected();
  4907. }
  4908. flowParsePostfixType() {
  4909. const startLoc = this.state.startLoc;
  4910. let type = this.flowParsePrimaryType();
  4911. let seenOptionalIndexedAccess = false;
  4912. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4913. const node = this.startNodeAt(startLoc);
  4914. const optional = this.eat(18);
  4915. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  4916. this.expect(0);
  4917. if (!optional && this.match(3)) {
  4918. node.elementType = type;
  4919. this.next();
  4920. type = this.finishNode(node, "ArrayTypeAnnotation");
  4921. } else {
  4922. node.objectType = type;
  4923. node.indexType = this.flowParseType();
  4924. this.expect(3);
  4925. if (seenOptionalIndexedAccess) {
  4926. node.optional = optional;
  4927. type = this.finishNode(node, "OptionalIndexedAccessType");
  4928. } else {
  4929. type = this.finishNode(node, "IndexedAccessType");
  4930. }
  4931. }
  4932. }
  4933. return type;
  4934. }
  4935. flowParsePrefixType() {
  4936. const node = this.startNode();
  4937. if (this.eat(17)) {
  4938. node.typeAnnotation = this.flowParsePrefixType();
  4939. return this.finishNode(node, "NullableTypeAnnotation");
  4940. } else {
  4941. return this.flowParsePostfixType();
  4942. }
  4943. }
  4944. flowParseAnonFunctionWithoutParens() {
  4945. const param = this.flowParsePrefixType();
  4946. if (!this.state.noAnonFunctionType && this.eat(19)) {
  4947. const node = this.startNodeAt(param.loc.start);
  4948. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  4949. node.rest = null;
  4950. node.this = null;
  4951. node.returnType = this.flowParseType();
  4952. node.typeParameters = null;
  4953. return this.finishNode(node, "FunctionTypeAnnotation");
  4954. }
  4955. return param;
  4956. }
  4957. flowParseIntersectionType() {
  4958. const node = this.startNode();
  4959. this.eat(45);
  4960. const type = this.flowParseAnonFunctionWithoutParens();
  4961. node.types = [type];
  4962. while (this.eat(45)) {
  4963. node.types.push(this.flowParseAnonFunctionWithoutParens());
  4964. }
  4965. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  4966. }
  4967. flowParseUnionType() {
  4968. const node = this.startNode();
  4969. this.eat(43);
  4970. const type = this.flowParseIntersectionType();
  4971. node.types = [type];
  4972. while (this.eat(43)) {
  4973. node.types.push(this.flowParseIntersectionType());
  4974. }
  4975. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  4976. }
  4977. flowParseType() {
  4978. const oldInType = this.state.inType;
  4979. this.state.inType = true;
  4980. const type = this.flowParseUnionType();
  4981. this.state.inType = oldInType;
  4982. return type;
  4983. }
  4984. flowParseTypeOrImplicitInstantiation() {
  4985. if (this.state.type === 132 && this.state.value === "_") {
  4986. const startLoc = this.state.startLoc;
  4987. const node = this.parseIdentifier();
  4988. return this.flowParseGenericType(startLoc, node);
  4989. } else {
  4990. return this.flowParseType();
  4991. }
  4992. }
  4993. flowParseTypeAnnotation() {
  4994. const node = this.startNode();
  4995. node.typeAnnotation = this.flowParseTypeInitialiser();
  4996. return this.finishNode(node, "TypeAnnotation");
  4997. }
  4998. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  4999. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5000. if (this.match(14)) {
  5001. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5002. this.resetEndLocation(ident);
  5003. }
  5004. return ident;
  5005. }
  5006. typeCastToParameter(node) {
  5007. node.expression.typeAnnotation = node.typeAnnotation;
  5008. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5009. return node.expression;
  5010. }
  5011. flowParseVariance() {
  5012. let variance = null;
  5013. if (this.match(53)) {
  5014. variance = this.startNode();
  5015. if (this.state.value === "+") {
  5016. variance.kind = "plus";
  5017. } else {
  5018. variance.kind = "minus";
  5019. }
  5020. this.next();
  5021. return this.finishNode(variance, "Variance");
  5022. }
  5023. return variance;
  5024. }
  5025. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5026. if (allowExpressionBody) {
  5027. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5028. return;
  5029. }
  5030. super.parseFunctionBody(node, false, isMethod);
  5031. }
  5032. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5033. if (this.match(14)) {
  5034. const typeNode = this.startNode();
  5035. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5036. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5037. }
  5038. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5039. }
  5040. parseStatementLike(flags) {
  5041. if (this.state.strict && this.isContextual(129)) {
  5042. const lookahead = this.lookahead();
  5043. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5044. const node = this.startNode();
  5045. this.next();
  5046. return this.flowParseInterface(node);
  5047. }
  5048. } else if (this.isContextual(126)) {
  5049. const node = this.startNode();
  5050. this.next();
  5051. return this.flowParseEnumDeclaration(node);
  5052. }
  5053. const stmt = super.parseStatementLike(flags);
  5054. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5055. this.flowPragma = null;
  5056. }
  5057. return stmt;
  5058. }
  5059. parseExpressionStatement(node, expr, decorators) {
  5060. if (expr.type === "Identifier") {
  5061. if (expr.name === "declare") {
  5062. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5063. return this.flowParseDeclare(node);
  5064. }
  5065. } else if (tokenIsIdentifier(this.state.type)) {
  5066. if (expr.name === "interface") {
  5067. return this.flowParseInterface(node);
  5068. } else if (expr.name === "type") {
  5069. return this.flowParseTypeAlias(node);
  5070. } else if (expr.name === "opaque") {
  5071. return this.flowParseOpaqueType(node, false);
  5072. }
  5073. }
  5074. }
  5075. return super.parseExpressionStatement(node, expr, decorators);
  5076. }
  5077. shouldParseExportDeclaration() {
  5078. const {
  5079. type
  5080. } = this.state;
  5081. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5082. return !this.state.containsEsc;
  5083. }
  5084. return super.shouldParseExportDeclaration();
  5085. }
  5086. isExportDefaultSpecifier() {
  5087. const {
  5088. type
  5089. } = this.state;
  5090. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5091. return this.state.containsEsc;
  5092. }
  5093. return super.isExportDefaultSpecifier();
  5094. }
  5095. parseExportDefaultExpression() {
  5096. if (this.isContextual(126)) {
  5097. const node = this.startNode();
  5098. this.next();
  5099. return this.flowParseEnumDeclaration(node);
  5100. }
  5101. return super.parseExportDefaultExpression();
  5102. }
  5103. parseConditional(expr, startLoc, refExpressionErrors) {
  5104. if (!this.match(17)) return expr;
  5105. if (this.state.maybeInArrowParameters) {
  5106. const nextCh = this.lookaheadCharCode();
  5107. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5108. this.setOptionalParametersError(refExpressionErrors);
  5109. return expr;
  5110. }
  5111. }
  5112. this.expect(17);
  5113. const state = this.state.clone();
  5114. const originalNoArrowAt = this.state.noArrowAt;
  5115. const node = this.startNodeAt(startLoc);
  5116. let {
  5117. consequent,
  5118. failed
  5119. } = this.tryParseConditionalConsequent();
  5120. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5121. if (failed || invalid.length > 0) {
  5122. const noArrowAt = [...originalNoArrowAt];
  5123. if (invalid.length > 0) {
  5124. this.state = state;
  5125. this.state.noArrowAt = noArrowAt;
  5126. for (let i = 0; i < invalid.length; i++) {
  5127. noArrowAt.push(invalid[i].start);
  5128. }
  5129. ({
  5130. consequent,
  5131. failed
  5132. } = this.tryParseConditionalConsequent());
  5133. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5134. }
  5135. if (failed && valid.length > 1) {
  5136. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  5137. }
  5138. if (failed && valid.length === 1) {
  5139. this.state = state;
  5140. noArrowAt.push(valid[0].start);
  5141. this.state.noArrowAt = noArrowAt;
  5142. ({
  5143. consequent,
  5144. failed
  5145. } = this.tryParseConditionalConsequent());
  5146. }
  5147. }
  5148. this.getArrowLikeExpressions(consequent, true);
  5149. this.state.noArrowAt = originalNoArrowAt;
  5150. this.expect(14);
  5151. node.test = expr;
  5152. node.consequent = consequent;
  5153. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5154. return this.finishNode(node, "ConditionalExpression");
  5155. }
  5156. tryParseConditionalConsequent() {
  5157. this.state.noArrowParamsConversionAt.push(this.state.start);
  5158. const consequent = this.parseMaybeAssignAllowIn();
  5159. const failed = !this.match(14);
  5160. this.state.noArrowParamsConversionAt.pop();
  5161. return {
  5162. consequent,
  5163. failed
  5164. };
  5165. }
  5166. getArrowLikeExpressions(node, disallowInvalid) {
  5167. const stack = [node];
  5168. const arrows = [];
  5169. while (stack.length !== 0) {
  5170. const node = stack.pop();
  5171. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  5172. if (node.typeParameters || !node.returnType) {
  5173. this.finishArrowValidation(node);
  5174. } else {
  5175. arrows.push(node);
  5176. }
  5177. stack.push(node.body);
  5178. } else if (node.type === "ConditionalExpression") {
  5179. stack.push(node.consequent);
  5180. stack.push(node.alternate);
  5181. }
  5182. }
  5183. if (disallowInvalid) {
  5184. arrows.forEach(node => this.finishArrowValidation(node));
  5185. return [arrows, []];
  5186. }
  5187. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5188. }
  5189. finishArrowValidation(node) {
  5190. var _node$extra;
  5191. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5192. this.scope.enter(2 | 4);
  5193. super.checkParams(node, false, true);
  5194. this.scope.exit();
  5195. }
  5196. forwardNoArrowParamsConversionAt(node, parse) {
  5197. let result;
  5198. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5199. this.state.noArrowParamsConversionAt.push(this.state.start);
  5200. result = parse();
  5201. this.state.noArrowParamsConversionAt.pop();
  5202. } else {
  5203. result = parse();
  5204. }
  5205. return result;
  5206. }
  5207. parseParenItem(node, startLoc) {
  5208. const newNode = super.parseParenItem(node, startLoc);
  5209. if (this.eat(17)) {
  5210. newNode.optional = true;
  5211. this.resetEndLocation(node);
  5212. }
  5213. if (this.match(14)) {
  5214. const typeCastNode = this.startNodeAt(startLoc);
  5215. typeCastNode.expression = newNode;
  5216. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5217. return this.finishNode(typeCastNode, "TypeCastExpression");
  5218. }
  5219. return newNode;
  5220. }
  5221. assertModuleNodeAllowed(node) {
  5222. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5223. return;
  5224. }
  5225. super.assertModuleNodeAllowed(node);
  5226. }
  5227. parseExportDeclaration(node) {
  5228. if (this.isContextual(130)) {
  5229. node.exportKind = "type";
  5230. const declarationNode = this.startNode();
  5231. this.next();
  5232. if (this.match(5)) {
  5233. node.specifiers = this.parseExportSpecifiers(true);
  5234. super.parseExportFrom(node);
  5235. return null;
  5236. } else {
  5237. return this.flowParseTypeAlias(declarationNode);
  5238. }
  5239. } else if (this.isContextual(131)) {
  5240. node.exportKind = "type";
  5241. const declarationNode = this.startNode();
  5242. this.next();
  5243. return this.flowParseOpaqueType(declarationNode, false);
  5244. } else if (this.isContextual(129)) {
  5245. node.exportKind = "type";
  5246. const declarationNode = this.startNode();
  5247. this.next();
  5248. return this.flowParseInterface(declarationNode);
  5249. } else if (this.isContextual(126)) {
  5250. node.exportKind = "value";
  5251. const declarationNode = this.startNode();
  5252. this.next();
  5253. return this.flowParseEnumDeclaration(declarationNode);
  5254. } else {
  5255. return super.parseExportDeclaration(node);
  5256. }
  5257. }
  5258. eatExportStar(node) {
  5259. if (super.eatExportStar(node)) return true;
  5260. if (this.isContextual(130) && this.lookahead().type === 55) {
  5261. node.exportKind = "type";
  5262. this.next();
  5263. this.next();
  5264. return true;
  5265. }
  5266. return false;
  5267. }
  5268. maybeParseExportNamespaceSpecifier(node) {
  5269. const {
  5270. startLoc
  5271. } = this.state;
  5272. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5273. if (hasNamespace && node.exportKind === "type") {
  5274. this.unexpected(startLoc);
  5275. }
  5276. return hasNamespace;
  5277. }
  5278. parseClassId(node, isStatement, optionalId) {
  5279. super.parseClassId(node, isStatement, optionalId);
  5280. if (this.match(47)) {
  5281. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5282. }
  5283. }
  5284. parseClassMember(classBody, member, state) {
  5285. const {
  5286. startLoc
  5287. } = this.state;
  5288. if (this.isContextual(125)) {
  5289. if (super.parseClassMemberFromModifier(classBody, member)) {
  5290. return;
  5291. }
  5292. member.declare = true;
  5293. }
  5294. super.parseClassMember(classBody, member, state);
  5295. if (member.declare) {
  5296. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5297. this.raise(FlowErrors.DeclareClassElement, startLoc);
  5298. } else if (member.value) {
  5299. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  5300. }
  5301. }
  5302. }
  5303. isIterator(word) {
  5304. return word === "iterator" || word === "asyncIterator";
  5305. }
  5306. readIterator() {
  5307. const word = super.readWord1();
  5308. const fullWord = "@@" + word;
  5309. if (!this.isIterator(word) || !this.state.inType) {
  5310. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  5311. identifierName: fullWord
  5312. });
  5313. }
  5314. this.finishToken(132, fullWord);
  5315. }
  5316. getTokenFromCode(code) {
  5317. const next = this.input.charCodeAt(this.state.pos + 1);
  5318. if (code === 123 && next === 124) {
  5319. this.finishOp(6, 2);
  5320. } else if (this.state.inType && (code === 62 || code === 60)) {
  5321. this.finishOp(code === 62 ? 48 : 47, 1);
  5322. } else if (this.state.inType && code === 63) {
  5323. if (next === 46) {
  5324. this.finishOp(18, 2);
  5325. } else {
  5326. this.finishOp(17, 1);
  5327. }
  5328. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5329. this.state.pos += 2;
  5330. this.readIterator();
  5331. } else {
  5332. super.getTokenFromCode(code);
  5333. }
  5334. }
  5335. isAssignable(node, isBinding) {
  5336. if (node.type === "TypeCastExpression") {
  5337. return this.isAssignable(node.expression, isBinding);
  5338. } else {
  5339. return super.isAssignable(node, isBinding);
  5340. }
  5341. }
  5342. toAssignable(node, isLHS = false) {
  5343. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5344. node.left = this.typeCastToParameter(node.left);
  5345. }
  5346. super.toAssignable(node, isLHS);
  5347. }
  5348. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5349. for (let i = 0; i < exprList.length; i++) {
  5350. const expr = exprList[i];
  5351. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5352. exprList[i] = this.typeCastToParameter(expr);
  5353. }
  5354. }
  5355. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5356. }
  5357. toReferencedList(exprList, isParenthesizedExpr) {
  5358. for (let i = 0; i < exprList.length; i++) {
  5359. var _expr$extra;
  5360. const expr = exprList[i];
  5361. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5362. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  5363. }
  5364. }
  5365. return exprList;
  5366. }
  5367. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5368. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5369. if (canBePattern && !this.state.maybeInArrowParameters) {
  5370. this.toReferencedList(node.elements);
  5371. }
  5372. return node;
  5373. }
  5374. isValidLVal(type, isParenthesized, binding) {
  5375. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5376. }
  5377. parseClassProperty(node) {
  5378. if (this.match(14)) {
  5379. node.typeAnnotation = this.flowParseTypeAnnotation();
  5380. }
  5381. return super.parseClassProperty(node);
  5382. }
  5383. parseClassPrivateProperty(node) {
  5384. if (this.match(14)) {
  5385. node.typeAnnotation = this.flowParseTypeAnnotation();
  5386. }
  5387. return super.parseClassPrivateProperty(node);
  5388. }
  5389. isClassMethod() {
  5390. return this.match(47) || super.isClassMethod();
  5391. }
  5392. isClassProperty() {
  5393. return this.match(14) || super.isClassProperty();
  5394. }
  5395. isNonstaticConstructor(method) {
  5396. return !this.match(14) && super.isNonstaticConstructor(method);
  5397. }
  5398. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5399. if (method.variance) {
  5400. this.unexpected(method.variance.loc.start);
  5401. }
  5402. delete method.variance;
  5403. if (this.match(47)) {
  5404. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5405. }
  5406. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5407. if (method.params && isConstructor) {
  5408. const params = method.params;
  5409. if (params.length > 0 && this.isThisParam(params[0])) {
  5410. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5411. }
  5412. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5413. const params = method.value.params;
  5414. if (params.length > 0 && this.isThisParam(params[0])) {
  5415. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5416. }
  5417. }
  5418. }
  5419. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5420. if (method.variance) {
  5421. this.unexpected(method.variance.loc.start);
  5422. }
  5423. delete method.variance;
  5424. if (this.match(47)) {
  5425. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5426. }
  5427. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5428. }
  5429. parseClassSuper(node) {
  5430. super.parseClassSuper(node);
  5431. if (node.superClass && this.match(47)) {
  5432. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  5433. }
  5434. if (this.isContextual(113)) {
  5435. this.next();
  5436. const implemented = node.implements = [];
  5437. do {
  5438. const node = this.startNode();
  5439. node.id = this.flowParseRestrictedIdentifier(true);
  5440. if (this.match(47)) {
  5441. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5442. } else {
  5443. node.typeParameters = null;
  5444. }
  5445. implemented.push(this.finishNode(node, "ClassImplements"));
  5446. } while (this.eat(12));
  5447. }
  5448. }
  5449. checkGetterSetterParams(method) {
  5450. super.checkGetterSetterParams(method);
  5451. const params = this.getObjectOrClassMethodParams(method);
  5452. if (params.length > 0) {
  5453. const param = params[0];
  5454. if (this.isThisParam(param) && method.kind === "get") {
  5455. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  5456. } else if (this.isThisParam(param)) {
  5457. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  5458. }
  5459. }
  5460. }
  5461. parsePropertyNamePrefixOperator(node) {
  5462. node.variance = this.flowParseVariance();
  5463. }
  5464. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5465. if (prop.variance) {
  5466. this.unexpected(prop.variance.loc.start);
  5467. }
  5468. delete prop.variance;
  5469. let typeParameters;
  5470. if (this.match(47) && !isAccessor) {
  5471. typeParameters = this.flowParseTypeParameterDeclaration();
  5472. if (!this.match(10)) this.unexpected();
  5473. }
  5474. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5475. if (typeParameters) {
  5476. (result.value || result).typeParameters = typeParameters;
  5477. }
  5478. return result;
  5479. }
  5480. parseFunctionParamType(param) {
  5481. if (this.eat(17)) {
  5482. if (param.type !== "Identifier") {
  5483. this.raise(FlowErrors.PatternIsOptional, param);
  5484. }
  5485. if (this.isThisParam(param)) {
  5486. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  5487. }
  5488. param.optional = true;
  5489. }
  5490. if (this.match(14)) {
  5491. param.typeAnnotation = this.flowParseTypeAnnotation();
  5492. } else if (this.isThisParam(param)) {
  5493. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  5494. }
  5495. if (this.match(29) && this.isThisParam(param)) {
  5496. this.raise(FlowErrors.ThisParamNoDefault, param);
  5497. }
  5498. this.resetEndLocation(param);
  5499. return param;
  5500. }
  5501. parseMaybeDefault(startLoc, left) {
  5502. const node = super.parseMaybeDefault(startLoc, left);
  5503. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5504. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  5505. }
  5506. return node;
  5507. }
  5508. checkImportReflection(node) {
  5509. super.checkImportReflection(node);
  5510. if (node.module && node.importKind !== "value") {
  5511. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  5512. }
  5513. }
  5514. parseImportSpecifierLocal(node, specifier, type) {
  5515. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5516. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5517. }
  5518. isPotentialImportPhase(isExport) {
  5519. if (super.isPotentialImportPhase(isExport)) return true;
  5520. if (this.isContextual(130)) {
  5521. if (!isExport) return true;
  5522. const ch = this.lookaheadCharCode();
  5523. return ch === 123 || ch === 42;
  5524. }
  5525. return !isExport && this.isContextual(87);
  5526. }
  5527. applyImportPhase(node, isExport, phase, loc) {
  5528. super.applyImportPhase(node, isExport, phase, loc);
  5529. if (isExport) {
  5530. if (!phase && this.match(65)) {
  5531. return;
  5532. }
  5533. node.exportKind = phase === "type" ? phase : "value";
  5534. } else {
  5535. if (phase === "type" && this.match(55)) this.unexpected();
  5536. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5537. }
  5538. }
  5539. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5540. const firstIdent = specifier.imported;
  5541. let specifierTypeKind = null;
  5542. if (firstIdent.type === "Identifier") {
  5543. if (firstIdent.name === "type") {
  5544. specifierTypeKind = "type";
  5545. } else if (firstIdent.name === "typeof") {
  5546. specifierTypeKind = "typeof";
  5547. }
  5548. }
  5549. let isBinding = false;
  5550. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5551. const as_ident = this.parseIdentifier(true);
  5552. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5553. specifier.imported = as_ident;
  5554. specifier.importKind = specifierTypeKind;
  5555. specifier.local = cloneIdentifier(as_ident);
  5556. } else {
  5557. specifier.imported = firstIdent;
  5558. specifier.importKind = null;
  5559. specifier.local = this.parseIdentifier();
  5560. }
  5561. } else {
  5562. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5563. specifier.imported = this.parseIdentifier(true);
  5564. specifier.importKind = specifierTypeKind;
  5565. } else {
  5566. if (importedIsString) {
  5567. throw this.raise(Errors.ImportBindingIsString, specifier, {
  5568. importName: firstIdent.value
  5569. });
  5570. }
  5571. specifier.imported = firstIdent;
  5572. specifier.importKind = null;
  5573. }
  5574. if (this.eatContextual(93)) {
  5575. specifier.local = this.parseIdentifier();
  5576. } else {
  5577. isBinding = true;
  5578. specifier.local = cloneIdentifier(specifier.imported);
  5579. }
  5580. }
  5581. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5582. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5583. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  5584. }
  5585. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5586. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5587. }
  5588. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5589. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5590. }
  5591. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5592. }
  5593. parseBindingAtom() {
  5594. switch (this.state.type) {
  5595. case 78:
  5596. return this.parseIdentifier(true);
  5597. default:
  5598. return super.parseBindingAtom();
  5599. }
  5600. }
  5601. parseFunctionParams(node, isConstructor) {
  5602. const kind = node.kind;
  5603. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5604. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5605. }
  5606. super.parseFunctionParams(node, isConstructor);
  5607. }
  5608. parseVarId(decl, kind) {
  5609. super.parseVarId(decl, kind);
  5610. if (this.match(14)) {
  5611. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5612. this.resetEndLocation(decl.id);
  5613. }
  5614. }
  5615. parseAsyncArrowFromCallExpression(node, call) {
  5616. if (this.match(14)) {
  5617. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5618. this.state.noAnonFunctionType = true;
  5619. node.returnType = this.flowParseTypeAnnotation();
  5620. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5621. }
  5622. return super.parseAsyncArrowFromCallExpression(node, call);
  5623. }
  5624. shouldParseAsyncArrow() {
  5625. return this.match(14) || super.shouldParseAsyncArrow();
  5626. }
  5627. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5628. var _jsx;
  5629. let state = null;
  5630. let jsx;
  5631. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  5632. state = this.state.clone();
  5633. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5634. if (!jsx.error) return jsx.node;
  5635. const {
  5636. context
  5637. } = this.state;
  5638. const currentContext = context[context.length - 1];
  5639. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5640. context.pop();
  5641. }
  5642. }
  5643. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5644. var _jsx2, _jsx3;
  5645. state = state || this.state.clone();
  5646. let typeParameters;
  5647. const arrow = this.tryParse(abort => {
  5648. var _arrowExpression$extr;
  5649. typeParameters = this.flowParseTypeParameterDeclaration();
  5650. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5651. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5652. this.resetStartLocationFromNode(result, typeParameters);
  5653. return result;
  5654. });
  5655. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5656. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5657. if (expr.type !== "ArrowFunctionExpression") abort();
  5658. expr.typeParameters = typeParameters;
  5659. this.resetStartLocationFromNode(expr, typeParameters);
  5660. return arrowExpression;
  5661. }, state);
  5662. let arrowExpression = null;
  5663. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5664. if (!arrow.error && !arrow.aborted) {
  5665. if (arrow.node.async) {
  5666. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  5667. }
  5668. return arrow.node;
  5669. }
  5670. arrowExpression = arrow.node;
  5671. }
  5672. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5673. this.state = jsx.failState;
  5674. return jsx.node;
  5675. }
  5676. if (arrowExpression) {
  5677. this.state = arrow.failState;
  5678. return arrowExpression;
  5679. }
  5680. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5681. if (arrow.thrown) throw arrow.error;
  5682. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  5683. }
  5684. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5685. }
  5686. parseArrow(node) {
  5687. if (this.match(14)) {
  5688. const result = this.tryParse(() => {
  5689. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5690. this.state.noAnonFunctionType = true;
  5691. const typeNode = this.startNode();
  5692. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5693. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5694. if (this.canInsertSemicolon()) this.unexpected();
  5695. if (!this.match(19)) this.unexpected();
  5696. return typeNode;
  5697. });
  5698. if (result.thrown) return null;
  5699. if (result.error) this.state = result.failState;
  5700. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5701. }
  5702. return super.parseArrow(node);
  5703. }
  5704. shouldParseArrow(params) {
  5705. return this.match(14) || super.shouldParseArrow(params);
  5706. }
  5707. setArrowFunctionParameters(node, params) {
  5708. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5709. node.params = params;
  5710. } else {
  5711. super.setArrowFunctionParameters(node, params);
  5712. }
  5713. }
  5714. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5715. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5716. return;
  5717. }
  5718. for (let i = 0; i < node.params.length; i++) {
  5719. if (this.isThisParam(node.params[i]) && i > 0) {
  5720. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  5721. }
  5722. }
  5723. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5724. }
  5725. parseParenAndDistinguishExpression(canBeArrow) {
  5726. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  5727. }
  5728. parseSubscripts(base, startLoc, noCalls) {
  5729. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  5730. this.next();
  5731. const node = this.startNodeAt(startLoc);
  5732. node.callee = base;
  5733. node.arguments = super.parseCallExpressionArguments(11);
  5734. base = this.finishNode(node, "CallExpression");
  5735. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5736. const state = this.state.clone();
  5737. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5738. if (!arrow.error && !arrow.aborted) return arrow.node;
  5739. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5740. if (result.node && !result.error) return result.node;
  5741. if (arrow.node) {
  5742. this.state = arrow.failState;
  5743. return arrow.node;
  5744. }
  5745. if (result.node) {
  5746. this.state = result.failState;
  5747. return result.node;
  5748. }
  5749. throw arrow.error || result.error;
  5750. }
  5751. return super.parseSubscripts(base, startLoc, noCalls);
  5752. }
  5753. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5754. if (this.match(18) && this.isLookaheadToken_lt()) {
  5755. subscriptState.optionalChainMember = true;
  5756. if (noCalls) {
  5757. subscriptState.stop = true;
  5758. return base;
  5759. }
  5760. this.next();
  5761. const node = this.startNodeAt(startLoc);
  5762. node.callee = base;
  5763. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5764. this.expect(10);
  5765. node.arguments = this.parseCallExpressionArguments(11);
  5766. node.optional = true;
  5767. return this.finishCallExpression(node, true);
  5768. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  5769. const node = this.startNodeAt(startLoc);
  5770. node.callee = base;
  5771. const result = this.tryParse(() => {
  5772. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5773. this.expect(10);
  5774. node.arguments = super.parseCallExpressionArguments(11);
  5775. if (subscriptState.optionalChainMember) {
  5776. node.optional = false;
  5777. }
  5778. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5779. });
  5780. if (result.node) {
  5781. if (result.error) this.state = result.failState;
  5782. return result.node;
  5783. }
  5784. }
  5785. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5786. }
  5787. parseNewCallee(node) {
  5788. super.parseNewCallee(node);
  5789. let targs = null;
  5790. if (this.shouldParseTypes() && this.match(47)) {
  5791. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5792. }
  5793. node.typeArguments = targs;
  5794. }
  5795. parseAsyncArrowWithTypeParameters(startLoc) {
  5796. const node = this.startNodeAt(startLoc);
  5797. this.parseFunctionParams(node, false);
  5798. if (!this.parseArrow(node)) return;
  5799. return super.parseArrowExpression(node, undefined, true);
  5800. }
  5801. readToken_mult_modulo(code) {
  5802. const next = this.input.charCodeAt(this.state.pos + 1);
  5803. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5804. this.state.hasFlowComment = false;
  5805. this.state.pos += 2;
  5806. this.nextToken();
  5807. return;
  5808. }
  5809. super.readToken_mult_modulo(code);
  5810. }
  5811. readToken_pipe_amp(code) {
  5812. const next = this.input.charCodeAt(this.state.pos + 1);
  5813. if (code === 124 && next === 125) {
  5814. this.finishOp(9, 2);
  5815. return;
  5816. }
  5817. super.readToken_pipe_amp(code);
  5818. }
  5819. parseTopLevel(file, program) {
  5820. const fileNode = super.parseTopLevel(file, program);
  5821. if (this.state.hasFlowComment) {
  5822. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  5823. }
  5824. return fileNode;
  5825. }
  5826. skipBlockComment() {
  5827. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5828. if (this.state.hasFlowComment) {
  5829. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  5830. }
  5831. this.hasFlowCommentCompletion();
  5832. const commentSkip = this.skipFlowComment();
  5833. if (commentSkip) {
  5834. this.state.pos += commentSkip;
  5835. this.state.hasFlowComment = true;
  5836. }
  5837. return;
  5838. }
  5839. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5840. }
  5841. skipFlowComment() {
  5842. const {
  5843. pos
  5844. } = this.state;
  5845. let shiftToFirstNonWhiteSpace = 2;
  5846. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5847. shiftToFirstNonWhiteSpace++;
  5848. }
  5849. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5850. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5851. if (ch2 === 58 && ch3 === 58) {
  5852. return shiftToFirstNonWhiteSpace + 2;
  5853. }
  5854. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5855. return shiftToFirstNonWhiteSpace + 12;
  5856. }
  5857. if (ch2 === 58 && ch3 !== 58) {
  5858. return shiftToFirstNonWhiteSpace;
  5859. }
  5860. return false;
  5861. }
  5862. hasFlowCommentCompletion() {
  5863. const end = this.input.indexOf("*/", this.state.pos);
  5864. if (end === -1) {
  5865. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5866. }
  5867. }
  5868. flowEnumErrorBooleanMemberNotInitialized(loc, {
  5869. enumName,
  5870. memberName
  5871. }) {
  5872. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  5873. memberName,
  5874. enumName
  5875. });
  5876. }
  5877. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  5878. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  5879. }
  5880. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  5881. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  5882. }
  5883. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  5884. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  5885. }
  5886. flowEnumMemberInit() {
  5887. const startLoc = this.state.startLoc;
  5888. const endOfInit = () => this.match(12) || this.match(8);
  5889. switch (this.state.type) {
  5890. case 134:
  5891. {
  5892. const literal = this.parseNumericLiteral(this.state.value);
  5893. if (endOfInit()) {
  5894. return {
  5895. type: "number",
  5896. loc: literal.loc.start,
  5897. value: literal
  5898. };
  5899. }
  5900. return {
  5901. type: "invalid",
  5902. loc: startLoc
  5903. };
  5904. }
  5905. case 133:
  5906. {
  5907. const literal = this.parseStringLiteral(this.state.value);
  5908. if (endOfInit()) {
  5909. return {
  5910. type: "string",
  5911. loc: literal.loc.start,
  5912. value: literal
  5913. };
  5914. }
  5915. return {
  5916. type: "invalid",
  5917. loc: startLoc
  5918. };
  5919. }
  5920. case 85:
  5921. case 86:
  5922. {
  5923. const literal = this.parseBooleanLiteral(this.match(85));
  5924. if (endOfInit()) {
  5925. return {
  5926. type: "boolean",
  5927. loc: literal.loc.start,
  5928. value: literal
  5929. };
  5930. }
  5931. return {
  5932. type: "invalid",
  5933. loc: startLoc
  5934. };
  5935. }
  5936. default:
  5937. return {
  5938. type: "invalid",
  5939. loc: startLoc
  5940. };
  5941. }
  5942. }
  5943. flowEnumMemberRaw() {
  5944. const loc = this.state.startLoc;
  5945. const id = this.parseIdentifier(true);
  5946. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  5947. type: "none",
  5948. loc
  5949. };
  5950. return {
  5951. id,
  5952. init
  5953. };
  5954. }
  5955. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  5956. const {
  5957. explicitType
  5958. } = context;
  5959. if (explicitType === null) {
  5960. return;
  5961. }
  5962. if (explicitType !== expectedType) {
  5963. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  5964. }
  5965. }
  5966. flowEnumMembers({
  5967. enumName,
  5968. explicitType
  5969. }) {
  5970. const seenNames = new Set();
  5971. const members = {
  5972. booleanMembers: [],
  5973. numberMembers: [],
  5974. stringMembers: [],
  5975. defaultedMembers: []
  5976. };
  5977. let hasUnknownMembers = false;
  5978. while (!this.match(8)) {
  5979. if (this.eat(21)) {
  5980. hasUnknownMembers = true;
  5981. break;
  5982. }
  5983. const memberNode = this.startNode();
  5984. const {
  5985. id,
  5986. init
  5987. } = this.flowEnumMemberRaw();
  5988. const memberName = id.name;
  5989. if (memberName === "") {
  5990. continue;
  5991. }
  5992. if (/^[a-z]/.test(memberName)) {
  5993. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  5994. memberName,
  5995. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  5996. enumName
  5997. });
  5998. }
  5999. if (seenNames.has(memberName)) {
  6000. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  6001. memberName,
  6002. enumName
  6003. });
  6004. }
  6005. seenNames.add(memberName);
  6006. const context = {
  6007. enumName,
  6008. explicitType,
  6009. memberName
  6010. };
  6011. memberNode.id = id;
  6012. switch (init.type) {
  6013. case "boolean":
  6014. {
  6015. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6016. memberNode.init = init.value;
  6017. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6018. break;
  6019. }
  6020. case "number":
  6021. {
  6022. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6023. memberNode.init = init.value;
  6024. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6025. break;
  6026. }
  6027. case "string":
  6028. {
  6029. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6030. memberNode.init = init.value;
  6031. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6032. break;
  6033. }
  6034. case "invalid":
  6035. {
  6036. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6037. }
  6038. case "none":
  6039. {
  6040. switch (explicitType) {
  6041. case "boolean":
  6042. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6043. break;
  6044. case "number":
  6045. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6046. break;
  6047. default:
  6048. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6049. }
  6050. }
  6051. }
  6052. if (!this.match(8)) {
  6053. this.expect(12);
  6054. }
  6055. }
  6056. return {
  6057. members,
  6058. hasUnknownMembers
  6059. };
  6060. }
  6061. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6062. enumName
  6063. }) {
  6064. if (initializedMembers.length === 0) {
  6065. return defaultedMembers;
  6066. } else if (defaultedMembers.length === 0) {
  6067. return initializedMembers;
  6068. } else if (defaultedMembers.length > initializedMembers.length) {
  6069. for (const member of initializedMembers) {
  6070. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6071. enumName
  6072. });
  6073. }
  6074. return defaultedMembers;
  6075. } else {
  6076. for (const member of defaultedMembers) {
  6077. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6078. enumName
  6079. });
  6080. }
  6081. return initializedMembers;
  6082. }
  6083. }
  6084. flowEnumParseExplicitType({
  6085. enumName
  6086. }) {
  6087. if (!this.eatContextual(102)) return null;
  6088. if (!tokenIsIdentifier(this.state.type)) {
  6089. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  6090. enumName
  6091. });
  6092. }
  6093. const {
  6094. value
  6095. } = this.state;
  6096. this.next();
  6097. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6098. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  6099. enumName,
  6100. invalidEnumType: value
  6101. });
  6102. }
  6103. return value;
  6104. }
  6105. flowEnumBody(node, id) {
  6106. const enumName = id.name;
  6107. const nameLoc = id.loc.start;
  6108. const explicitType = this.flowEnumParseExplicitType({
  6109. enumName
  6110. });
  6111. this.expect(5);
  6112. const {
  6113. members,
  6114. hasUnknownMembers
  6115. } = this.flowEnumMembers({
  6116. enumName,
  6117. explicitType
  6118. });
  6119. node.hasUnknownMembers = hasUnknownMembers;
  6120. switch (explicitType) {
  6121. case "boolean":
  6122. node.explicitType = true;
  6123. node.members = members.booleanMembers;
  6124. this.expect(8);
  6125. return this.finishNode(node, "EnumBooleanBody");
  6126. case "number":
  6127. node.explicitType = true;
  6128. node.members = members.numberMembers;
  6129. this.expect(8);
  6130. return this.finishNode(node, "EnumNumberBody");
  6131. case "string":
  6132. node.explicitType = true;
  6133. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6134. enumName
  6135. });
  6136. this.expect(8);
  6137. return this.finishNode(node, "EnumStringBody");
  6138. case "symbol":
  6139. node.members = members.defaultedMembers;
  6140. this.expect(8);
  6141. return this.finishNode(node, "EnumSymbolBody");
  6142. default:
  6143. {
  6144. const empty = () => {
  6145. node.members = [];
  6146. this.expect(8);
  6147. return this.finishNode(node, "EnumStringBody");
  6148. };
  6149. node.explicitType = false;
  6150. const boolsLen = members.booleanMembers.length;
  6151. const numsLen = members.numberMembers.length;
  6152. const strsLen = members.stringMembers.length;
  6153. const defaultedLen = members.defaultedMembers.length;
  6154. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6155. return empty();
  6156. } else if (!boolsLen && !numsLen) {
  6157. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6158. enumName
  6159. });
  6160. this.expect(8);
  6161. return this.finishNode(node, "EnumStringBody");
  6162. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6163. for (const member of members.defaultedMembers) {
  6164. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6165. enumName,
  6166. memberName: member.id.name
  6167. });
  6168. }
  6169. node.members = members.booleanMembers;
  6170. this.expect(8);
  6171. return this.finishNode(node, "EnumBooleanBody");
  6172. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6173. for (const member of members.defaultedMembers) {
  6174. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6175. enumName,
  6176. memberName: member.id.name
  6177. });
  6178. }
  6179. node.members = members.numberMembers;
  6180. this.expect(8);
  6181. return this.finishNode(node, "EnumNumberBody");
  6182. } else {
  6183. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  6184. enumName
  6185. });
  6186. return empty();
  6187. }
  6188. }
  6189. }
  6190. }
  6191. flowParseEnumDeclaration(node) {
  6192. const id = this.parseIdentifier();
  6193. node.id = id;
  6194. node.body = this.flowEnumBody(this.startNode(), id);
  6195. return this.finishNode(node, "EnumDeclaration");
  6196. }
  6197. isLookaheadToken_lt() {
  6198. const next = this.nextTokenStart();
  6199. if (this.input.charCodeAt(next) === 60) {
  6200. const afterNext = this.input.charCodeAt(next + 1);
  6201. return afterNext !== 60 && afterNext !== 61;
  6202. }
  6203. return false;
  6204. }
  6205. maybeUnwrapTypeCastExpression(node) {
  6206. return node.type === "TypeCastExpression" ? node.expression : node;
  6207. }
  6208. };
  6209. const entities = {
  6210. __proto__: null,
  6211. quot: "\u0022",
  6212. amp: "&",
  6213. apos: "\u0027",
  6214. lt: "<",
  6215. gt: ">",
  6216. nbsp: "\u00A0",
  6217. iexcl: "\u00A1",
  6218. cent: "\u00A2",
  6219. pound: "\u00A3",
  6220. curren: "\u00A4",
  6221. yen: "\u00A5",
  6222. brvbar: "\u00A6",
  6223. sect: "\u00A7",
  6224. uml: "\u00A8",
  6225. copy: "\u00A9",
  6226. ordf: "\u00AA",
  6227. laquo: "\u00AB",
  6228. not: "\u00AC",
  6229. shy: "\u00AD",
  6230. reg: "\u00AE",
  6231. macr: "\u00AF",
  6232. deg: "\u00B0",
  6233. plusmn: "\u00B1",
  6234. sup2: "\u00B2",
  6235. sup3: "\u00B3",
  6236. acute: "\u00B4",
  6237. micro: "\u00B5",
  6238. para: "\u00B6",
  6239. middot: "\u00B7",
  6240. cedil: "\u00B8",
  6241. sup1: "\u00B9",
  6242. ordm: "\u00BA",
  6243. raquo: "\u00BB",
  6244. frac14: "\u00BC",
  6245. frac12: "\u00BD",
  6246. frac34: "\u00BE",
  6247. iquest: "\u00BF",
  6248. Agrave: "\u00C0",
  6249. Aacute: "\u00C1",
  6250. Acirc: "\u00C2",
  6251. Atilde: "\u00C3",
  6252. Auml: "\u00C4",
  6253. Aring: "\u00C5",
  6254. AElig: "\u00C6",
  6255. Ccedil: "\u00C7",
  6256. Egrave: "\u00C8",
  6257. Eacute: "\u00C9",
  6258. Ecirc: "\u00CA",
  6259. Euml: "\u00CB",
  6260. Igrave: "\u00CC",
  6261. Iacute: "\u00CD",
  6262. Icirc: "\u00CE",
  6263. Iuml: "\u00CF",
  6264. ETH: "\u00D0",
  6265. Ntilde: "\u00D1",
  6266. Ograve: "\u00D2",
  6267. Oacute: "\u00D3",
  6268. Ocirc: "\u00D4",
  6269. Otilde: "\u00D5",
  6270. Ouml: "\u00D6",
  6271. times: "\u00D7",
  6272. Oslash: "\u00D8",
  6273. Ugrave: "\u00D9",
  6274. Uacute: "\u00DA",
  6275. Ucirc: "\u00DB",
  6276. Uuml: "\u00DC",
  6277. Yacute: "\u00DD",
  6278. THORN: "\u00DE",
  6279. szlig: "\u00DF",
  6280. agrave: "\u00E0",
  6281. aacute: "\u00E1",
  6282. acirc: "\u00E2",
  6283. atilde: "\u00E3",
  6284. auml: "\u00E4",
  6285. aring: "\u00E5",
  6286. aelig: "\u00E6",
  6287. ccedil: "\u00E7",
  6288. egrave: "\u00E8",
  6289. eacute: "\u00E9",
  6290. ecirc: "\u00EA",
  6291. euml: "\u00EB",
  6292. igrave: "\u00EC",
  6293. iacute: "\u00ED",
  6294. icirc: "\u00EE",
  6295. iuml: "\u00EF",
  6296. eth: "\u00F0",
  6297. ntilde: "\u00F1",
  6298. ograve: "\u00F2",
  6299. oacute: "\u00F3",
  6300. ocirc: "\u00F4",
  6301. otilde: "\u00F5",
  6302. ouml: "\u00F6",
  6303. divide: "\u00F7",
  6304. oslash: "\u00F8",
  6305. ugrave: "\u00F9",
  6306. uacute: "\u00FA",
  6307. ucirc: "\u00FB",
  6308. uuml: "\u00FC",
  6309. yacute: "\u00FD",
  6310. thorn: "\u00FE",
  6311. yuml: "\u00FF",
  6312. OElig: "\u0152",
  6313. oelig: "\u0153",
  6314. Scaron: "\u0160",
  6315. scaron: "\u0161",
  6316. Yuml: "\u0178",
  6317. fnof: "\u0192",
  6318. circ: "\u02C6",
  6319. tilde: "\u02DC",
  6320. Alpha: "\u0391",
  6321. Beta: "\u0392",
  6322. Gamma: "\u0393",
  6323. Delta: "\u0394",
  6324. Epsilon: "\u0395",
  6325. Zeta: "\u0396",
  6326. Eta: "\u0397",
  6327. Theta: "\u0398",
  6328. Iota: "\u0399",
  6329. Kappa: "\u039A",
  6330. Lambda: "\u039B",
  6331. Mu: "\u039C",
  6332. Nu: "\u039D",
  6333. Xi: "\u039E",
  6334. Omicron: "\u039F",
  6335. Pi: "\u03A0",
  6336. Rho: "\u03A1",
  6337. Sigma: "\u03A3",
  6338. Tau: "\u03A4",
  6339. Upsilon: "\u03A5",
  6340. Phi: "\u03A6",
  6341. Chi: "\u03A7",
  6342. Psi: "\u03A8",
  6343. Omega: "\u03A9",
  6344. alpha: "\u03B1",
  6345. beta: "\u03B2",
  6346. gamma: "\u03B3",
  6347. delta: "\u03B4",
  6348. epsilon: "\u03B5",
  6349. zeta: "\u03B6",
  6350. eta: "\u03B7",
  6351. theta: "\u03B8",
  6352. iota: "\u03B9",
  6353. kappa: "\u03BA",
  6354. lambda: "\u03BB",
  6355. mu: "\u03BC",
  6356. nu: "\u03BD",
  6357. xi: "\u03BE",
  6358. omicron: "\u03BF",
  6359. pi: "\u03C0",
  6360. rho: "\u03C1",
  6361. sigmaf: "\u03C2",
  6362. sigma: "\u03C3",
  6363. tau: "\u03C4",
  6364. upsilon: "\u03C5",
  6365. phi: "\u03C6",
  6366. chi: "\u03C7",
  6367. psi: "\u03C8",
  6368. omega: "\u03C9",
  6369. thetasym: "\u03D1",
  6370. upsih: "\u03D2",
  6371. piv: "\u03D6",
  6372. ensp: "\u2002",
  6373. emsp: "\u2003",
  6374. thinsp: "\u2009",
  6375. zwnj: "\u200C",
  6376. zwj: "\u200D",
  6377. lrm: "\u200E",
  6378. rlm: "\u200F",
  6379. ndash: "\u2013",
  6380. mdash: "\u2014",
  6381. lsquo: "\u2018",
  6382. rsquo: "\u2019",
  6383. sbquo: "\u201A",
  6384. ldquo: "\u201C",
  6385. rdquo: "\u201D",
  6386. bdquo: "\u201E",
  6387. dagger: "\u2020",
  6388. Dagger: "\u2021",
  6389. bull: "\u2022",
  6390. hellip: "\u2026",
  6391. permil: "\u2030",
  6392. prime: "\u2032",
  6393. Prime: "\u2033",
  6394. lsaquo: "\u2039",
  6395. rsaquo: "\u203A",
  6396. oline: "\u203E",
  6397. frasl: "\u2044",
  6398. euro: "\u20AC",
  6399. image: "\u2111",
  6400. weierp: "\u2118",
  6401. real: "\u211C",
  6402. trade: "\u2122",
  6403. alefsym: "\u2135",
  6404. larr: "\u2190",
  6405. uarr: "\u2191",
  6406. rarr: "\u2192",
  6407. darr: "\u2193",
  6408. harr: "\u2194",
  6409. crarr: "\u21B5",
  6410. lArr: "\u21D0",
  6411. uArr: "\u21D1",
  6412. rArr: "\u21D2",
  6413. dArr: "\u21D3",
  6414. hArr: "\u21D4",
  6415. forall: "\u2200",
  6416. part: "\u2202",
  6417. exist: "\u2203",
  6418. empty: "\u2205",
  6419. nabla: "\u2207",
  6420. isin: "\u2208",
  6421. notin: "\u2209",
  6422. ni: "\u220B",
  6423. prod: "\u220F",
  6424. sum: "\u2211",
  6425. minus: "\u2212",
  6426. lowast: "\u2217",
  6427. radic: "\u221A",
  6428. prop: "\u221D",
  6429. infin: "\u221E",
  6430. ang: "\u2220",
  6431. and: "\u2227",
  6432. or: "\u2228",
  6433. cap: "\u2229",
  6434. cup: "\u222A",
  6435. int: "\u222B",
  6436. there4: "\u2234",
  6437. sim: "\u223C",
  6438. cong: "\u2245",
  6439. asymp: "\u2248",
  6440. ne: "\u2260",
  6441. equiv: "\u2261",
  6442. le: "\u2264",
  6443. ge: "\u2265",
  6444. sub: "\u2282",
  6445. sup: "\u2283",
  6446. nsub: "\u2284",
  6447. sube: "\u2286",
  6448. supe: "\u2287",
  6449. oplus: "\u2295",
  6450. otimes: "\u2297",
  6451. perp: "\u22A5",
  6452. sdot: "\u22C5",
  6453. lceil: "\u2308",
  6454. rceil: "\u2309",
  6455. lfloor: "\u230A",
  6456. rfloor: "\u230B",
  6457. lang: "\u2329",
  6458. rang: "\u232A",
  6459. loz: "\u25CA",
  6460. spades: "\u2660",
  6461. clubs: "\u2663",
  6462. hearts: "\u2665",
  6463. diams: "\u2666"
  6464. };
  6465. const JsxErrors = ParseErrorEnum`jsx`({
  6466. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6467. MissingClosingTagElement: ({
  6468. openingTagName
  6469. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6470. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6471. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6472. UnexpectedToken: ({
  6473. unexpected,
  6474. HTMLEntity
  6475. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6476. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6477. UnterminatedJsxContent: "Unterminated JSX contents.",
  6478. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6479. });
  6480. function isFragment(object) {
  6481. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6482. }
  6483. function getQualifiedJSXName(object) {
  6484. if (object.type === "JSXIdentifier") {
  6485. return object.name;
  6486. }
  6487. if (object.type === "JSXNamespacedName") {
  6488. return object.namespace.name + ":" + object.name.name;
  6489. }
  6490. if (object.type === "JSXMemberExpression") {
  6491. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6492. }
  6493. throw new Error("Node had unexpected type: " + object.type);
  6494. }
  6495. var jsx = superClass => class JSXParserMixin extends superClass {
  6496. jsxReadToken() {
  6497. let out = "";
  6498. let chunkStart = this.state.pos;
  6499. for (;;) {
  6500. if (this.state.pos >= this.length) {
  6501. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  6502. }
  6503. const ch = this.input.charCodeAt(this.state.pos);
  6504. switch (ch) {
  6505. case 60:
  6506. case 123:
  6507. if (this.state.pos === this.state.start) {
  6508. if (ch === 60 && this.state.canStartJSXElement) {
  6509. ++this.state.pos;
  6510. this.finishToken(142);
  6511. } else {
  6512. super.getTokenFromCode(ch);
  6513. }
  6514. return;
  6515. }
  6516. out += this.input.slice(chunkStart, this.state.pos);
  6517. this.finishToken(141, out);
  6518. return;
  6519. case 38:
  6520. out += this.input.slice(chunkStart, this.state.pos);
  6521. out += this.jsxReadEntity();
  6522. chunkStart = this.state.pos;
  6523. break;
  6524. case 62:
  6525. case 125:
  6526. default:
  6527. if (isNewLine(ch)) {
  6528. out += this.input.slice(chunkStart, this.state.pos);
  6529. out += this.jsxReadNewLine(true);
  6530. chunkStart = this.state.pos;
  6531. } else {
  6532. ++this.state.pos;
  6533. }
  6534. }
  6535. }
  6536. }
  6537. jsxReadNewLine(normalizeCRLF) {
  6538. const ch = this.input.charCodeAt(this.state.pos);
  6539. let out;
  6540. ++this.state.pos;
  6541. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6542. ++this.state.pos;
  6543. out = normalizeCRLF ? "\n" : "\r\n";
  6544. } else {
  6545. out = String.fromCharCode(ch);
  6546. }
  6547. ++this.state.curLine;
  6548. this.state.lineStart = this.state.pos;
  6549. return out;
  6550. }
  6551. jsxReadString(quote) {
  6552. let out = "";
  6553. let chunkStart = ++this.state.pos;
  6554. for (;;) {
  6555. if (this.state.pos >= this.length) {
  6556. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  6557. }
  6558. const ch = this.input.charCodeAt(this.state.pos);
  6559. if (ch === quote) break;
  6560. if (ch === 38) {
  6561. out += this.input.slice(chunkStart, this.state.pos);
  6562. out += this.jsxReadEntity();
  6563. chunkStart = this.state.pos;
  6564. } else if (isNewLine(ch)) {
  6565. out += this.input.slice(chunkStart, this.state.pos);
  6566. out += this.jsxReadNewLine(false);
  6567. chunkStart = this.state.pos;
  6568. } else {
  6569. ++this.state.pos;
  6570. }
  6571. }
  6572. out += this.input.slice(chunkStart, this.state.pos++);
  6573. this.finishToken(133, out);
  6574. }
  6575. jsxReadEntity() {
  6576. const startPos = ++this.state.pos;
  6577. if (this.codePointAtPos(this.state.pos) === 35) {
  6578. ++this.state.pos;
  6579. let radix = 10;
  6580. if (this.codePointAtPos(this.state.pos) === 120) {
  6581. radix = 16;
  6582. ++this.state.pos;
  6583. }
  6584. const codePoint = this.readInt(radix, undefined, false, "bail");
  6585. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6586. ++this.state.pos;
  6587. return String.fromCodePoint(codePoint);
  6588. }
  6589. } else {
  6590. let count = 0;
  6591. let semi = false;
  6592. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  6593. ++this.state.pos;
  6594. }
  6595. if (semi) {
  6596. const desc = this.input.slice(startPos, this.state.pos);
  6597. const entity = entities[desc];
  6598. ++this.state.pos;
  6599. if (entity) {
  6600. return entity;
  6601. }
  6602. }
  6603. }
  6604. this.state.pos = startPos;
  6605. return "&";
  6606. }
  6607. jsxReadWord() {
  6608. let ch;
  6609. const start = this.state.pos;
  6610. do {
  6611. ch = this.input.charCodeAt(++this.state.pos);
  6612. } while (isIdentifierChar(ch) || ch === 45);
  6613. this.finishToken(140, this.input.slice(start, this.state.pos));
  6614. }
  6615. jsxParseIdentifier() {
  6616. const node = this.startNode();
  6617. if (this.match(140)) {
  6618. node.name = this.state.value;
  6619. } else if (tokenIsKeyword(this.state.type)) {
  6620. node.name = tokenLabelName(this.state.type);
  6621. } else {
  6622. this.unexpected();
  6623. }
  6624. this.next();
  6625. return this.finishNode(node, "JSXIdentifier");
  6626. }
  6627. jsxParseNamespacedName() {
  6628. const startLoc = this.state.startLoc;
  6629. const name = this.jsxParseIdentifier();
  6630. if (!this.eat(14)) return name;
  6631. const node = this.startNodeAt(startLoc);
  6632. node.namespace = name;
  6633. node.name = this.jsxParseIdentifier();
  6634. return this.finishNode(node, "JSXNamespacedName");
  6635. }
  6636. jsxParseElementName() {
  6637. const startLoc = this.state.startLoc;
  6638. let node = this.jsxParseNamespacedName();
  6639. if (node.type === "JSXNamespacedName") {
  6640. return node;
  6641. }
  6642. while (this.eat(16)) {
  6643. const newNode = this.startNodeAt(startLoc);
  6644. newNode.object = node;
  6645. newNode.property = this.jsxParseIdentifier();
  6646. node = this.finishNode(newNode, "JSXMemberExpression");
  6647. }
  6648. return node;
  6649. }
  6650. jsxParseAttributeValue() {
  6651. let node;
  6652. switch (this.state.type) {
  6653. case 5:
  6654. node = this.startNode();
  6655. this.setContext(types.brace);
  6656. this.next();
  6657. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6658. if (node.expression.type === "JSXEmptyExpression") {
  6659. this.raise(JsxErrors.AttributeIsEmpty, node);
  6660. }
  6661. return node;
  6662. case 142:
  6663. case 133:
  6664. return this.parseExprAtom();
  6665. default:
  6666. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  6667. }
  6668. }
  6669. jsxParseEmptyExpression() {
  6670. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6671. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6672. }
  6673. jsxParseSpreadChild(node) {
  6674. this.next();
  6675. node.expression = this.parseExpression();
  6676. this.setContext(types.j_expr);
  6677. this.state.canStartJSXElement = true;
  6678. this.expect(8);
  6679. return this.finishNode(node, "JSXSpreadChild");
  6680. }
  6681. jsxParseExpressionContainer(node, previousContext) {
  6682. if (this.match(8)) {
  6683. node.expression = this.jsxParseEmptyExpression();
  6684. } else {
  6685. const expression = this.parseExpression();
  6686. node.expression = expression;
  6687. }
  6688. this.setContext(previousContext);
  6689. this.state.canStartJSXElement = true;
  6690. this.expect(8);
  6691. return this.finishNode(node, "JSXExpressionContainer");
  6692. }
  6693. jsxParseAttribute() {
  6694. const node = this.startNode();
  6695. if (this.match(5)) {
  6696. this.setContext(types.brace);
  6697. this.next();
  6698. this.expect(21);
  6699. node.argument = this.parseMaybeAssignAllowIn();
  6700. this.setContext(types.j_oTag);
  6701. this.state.canStartJSXElement = true;
  6702. this.expect(8);
  6703. return this.finishNode(node, "JSXSpreadAttribute");
  6704. }
  6705. node.name = this.jsxParseNamespacedName();
  6706. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6707. return this.finishNode(node, "JSXAttribute");
  6708. }
  6709. jsxParseOpeningElementAt(startLoc) {
  6710. const node = this.startNodeAt(startLoc);
  6711. if (this.eat(143)) {
  6712. return this.finishNode(node, "JSXOpeningFragment");
  6713. }
  6714. node.name = this.jsxParseElementName();
  6715. return this.jsxParseOpeningElementAfterName(node);
  6716. }
  6717. jsxParseOpeningElementAfterName(node) {
  6718. const attributes = [];
  6719. while (!this.match(56) && !this.match(143)) {
  6720. attributes.push(this.jsxParseAttribute());
  6721. }
  6722. node.attributes = attributes;
  6723. node.selfClosing = this.eat(56);
  6724. this.expect(143);
  6725. return this.finishNode(node, "JSXOpeningElement");
  6726. }
  6727. jsxParseClosingElementAt(startLoc) {
  6728. const node = this.startNodeAt(startLoc);
  6729. if (this.eat(143)) {
  6730. return this.finishNode(node, "JSXClosingFragment");
  6731. }
  6732. node.name = this.jsxParseElementName();
  6733. this.expect(143);
  6734. return this.finishNode(node, "JSXClosingElement");
  6735. }
  6736. jsxParseElementAt(startLoc) {
  6737. const node = this.startNodeAt(startLoc);
  6738. const children = [];
  6739. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6740. let closingElement = null;
  6741. if (!openingElement.selfClosing) {
  6742. contents: for (;;) {
  6743. switch (this.state.type) {
  6744. case 142:
  6745. startLoc = this.state.startLoc;
  6746. this.next();
  6747. if (this.eat(56)) {
  6748. closingElement = this.jsxParseClosingElementAt(startLoc);
  6749. break contents;
  6750. }
  6751. children.push(this.jsxParseElementAt(startLoc));
  6752. break;
  6753. case 141:
  6754. children.push(this.parseLiteral(this.state.value, "JSXText"));
  6755. break;
  6756. case 5:
  6757. {
  6758. const node = this.startNode();
  6759. this.setContext(types.brace);
  6760. this.next();
  6761. if (this.match(21)) {
  6762. children.push(this.jsxParseSpreadChild(node));
  6763. } else {
  6764. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6765. }
  6766. break;
  6767. }
  6768. default:
  6769. this.unexpected();
  6770. }
  6771. }
  6772. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6773. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  6774. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6775. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  6776. openingTagName: getQualifiedJSXName(openingElement.name)
  6777. });
  6778. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6779. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6780. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  6781. openingTagName: getQualifiedJSXName(openingElement.name)
  6782. });
  6783. }
  6784. }
  6785. }
  6786. if (isFragment(openingElement)) {
  6787. node.openingFragment = openingElement;
  6788. node.closingFragment = closingElement;
  6789. } else {
  6790. node.openingElement = openingElement;
  6791. node.closingElement = closingElement;
  6792. }
  6793. node.children = children;
  6794. if (this.match(47)) {
  6795. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  6796. }
  6797. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6798. }
  6799. jsxParseElement() {
  6800. const startLoc = this.state.startLoc;
  6801. this.next();
  6802. return this.jsxParseElementAt(startLoc);
  6803. }
  6804. setContext(newContext) {
  6805. const {
  6806. context
  6807. } = this.state;
  6808. context[context.length - 1] = newContext;
  6809. }
  6810. parseExprAtom(refExpressionErrors) {
  6811. if (this.match(142)) {
  6812. return this.jsxParseElement();
  6813. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  6814. this.replaceToken(142);
  6815. return this.jsxParseElement();
  6816. } else {
  6817. return super.parseExprAtom(refExpressionErrors);
  6818. }
  6819. }
  6820. skipSpace() {
  6821. const curContext = this.curContext();
  6822. if (!curContext.preserveSpace) super.skipSpace();
  6823. }
  6824. getTokenFromCode(code) {
  6825. const context = this.curContext();
  6826. if (context === types.j_expr) {
  6827. this.jsxReadToken();
  6828. return;
  6829. }
  6830. if (context === types.j_oTag || context === types.j_cTag) {
  6831. if (isIdentifierStart(code)) {
  6832. this.jsxReadWord();
  6833. return;
  6834. }
  6835. if (code === 62) {
  6836. ++this.state.pos;
  6837. this.finishToken(143);
  6838. return;
  6839. }
  6840. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6841. this.jsxReadString(code);
  6842. return;
  6843. }
  6844. }
  6845. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  6846. ++this.state.pos;
  6847. this.finishToken(142);
  6848. return;
  6849. }
  6850. super.getTokenFromCode(code);
  6851. }
  6852. updateContext(prevType) {
  6853. const {
  6854. context,
  6855. type
  6856. } = this.state;
  6857. if (type === 56 && prevType === 142) {
  6858. context.splice(-2, 2, types.j_cTag);
  6859. this.state.canStartJSXElement = false;
  6860. } else if (type === 142) {
  6861. context.push(types.j_oTag);
  6862. } else if (type === 143) {
  6863. const out = context[context.length - 1];
  6864. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  6865. context.pop();
  6866. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  6867. } else {
  6868. this.setContext(types.j_expr);
  6869. this.state.canStartJSXElement = true;
  6870. }
  6871. } else {
  6872. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  6873. }
  6874. }
  6875. };
  6876. class TypeScriptScope extends Scope {
  6877. constructor(...args) {
  6878. super(...args);
  6879. this.tsNames = new Map();
  6880. }
  6881. }
  6882. class TypeScriptScopeHandler extends ScopeHandler {
  6883. constructor(...args) {
  6884. super(...args);
  6885. this.importsStack = [];
  6886. }
  6887. createScope(flags) {
  6888. this.importsStack.push(new Set());
  6889. return new TypeScriptScope(flags);
  6890. }
  6891. enter(flags) {
  6892. if (flags === 256) {
  6893. this.importsStack.push(new Set());
  6894. }
  6895. super.enter(flags);
  6896. }
  6897. exit() {
  6898. const flags = super.exit();
  6899. if (flags === 256) {
  6900. this.importsStack.pop();
  6901. }
  6902. return flags;
  6903. }
  6904. hasImport(name, allowShadow) {
  6905. const len = this.importsStack.length;
  6906. if (this.importsStack[len - 1].has(name)) {
  6907. return true;
  6908. }
  6909. if (!allowShadow && len > 1) {
  6910. for (let i = 0; i < len - 1; i++) {
  6911. if (this.importsStack[i].has(name)) return true;
  6912. }
  6913. }
  6914. return false;
  6915. }
  6916. declareName(name, bindingType, loc) {
  6917. if (bindingType & 4096) {
  6918. if (this.hasImport(name, true)) {
  6919. this.parser.raise(Errors.VarRedeclaration, loc, {
  6920. identifierName: name
  6921. });
  6922. }
  6923. this.importsStack[this.importsStack.length - 1].add(name);
  6924. return;
  6925. }
  6926. const scope = this.currentScope();
  6927. let type = scope.tsNames.get(name) || 0;
  6928. if (bindingType & 1024) {
  6929. this.maybeExportDefined(scope, name);
  6930. scope.tsNames.set(name, type | 16);
  6931. return;
  6932. }
  6933. super.declareName(name, bindingType, loc);
  6934. if (bindingType & 2) {
  6935. if (!(bindingType & 1)) {
  6936. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  6937. this.maybeExportDefined(scope, name);
  6938. }
  6939. type = type | 1;
  6940. }
  6941. if (bindingType & 256) {
  6942. type = type | 2;
  6943. }
  6944. if (bindingType & 512) {
  6945. type = type | 4;
  6946. }
  6947. if (bindingType & 128) {
  6948. type = type | 8;
  6949. }
  6950. if (type) scope.tsNames.set(name, type);
  6951. }
  6952. isRedeclaredInScope(scope, name, bindingType) {
  6953. const type = scope.tsNames.get(name);
  6954. if ((type & 2) > 0) {
  6955. if (bindingType & 256) {
  6956. const isConst = !!(bindingType & 512);
  6957. const wasConst = (type & 4) > 0;
  6958. return isConst !== wasConst;
  6959. }
  6960. return true;
  6961. }
  6962. if (bindingType & 128 && (type & 8) > 0) {
  6963. if (scope.names.get(name) & 2) {
  6964. return !!(bindingType & 1);
  6965. } else {
  6966. return false;
  6967. }
  6968. }
  6969. if (bindingType & 2 && (type & 1) > 0) {
  6970. return true;
  6971. }
  6972. return super.isRedeclaredInScope(scope, name, bindingType);
  6973. }
  6974. checkLocalExport(id) {
  6975. const {
  6976. name
  6977. } = id;
  6978. if (this.hasImport(name)) return;
  6979. const len = this.scopeStack.length;
  6980. for (let i = len - 1; i >= 0; i--) {
  6981. const scope = this.scopeStack[i];
  6982. const type = scope.tsNames.get(name);
  6983. if ((type & 1) > 0 || (type & 16) > 0) {
  6984. return;
  6985. }
  6986. }
  6987. super.checkLocalExport(id);
  6988. }
  6989. }
  6990. const unwrapParenthesizedExpression = node => {
  6991. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  6992. };
  6993. class LValParser extends NodeUtils {
  6994. toAssignable(node, isLHS = false) {
  6995. var _node$extra, _node$extra3;
  6996. let parenthesized = undefined;
  6997. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  6998. parenthesized = unwrapParenthesizedExpression(node);
  6999. if (isLHS) {
  7000. if (parenthesized.type === "Identifier") {
  7001. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7002. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7003. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7004. }
  7005. } else {
  7006. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7007. }
  7008. }
  7009. switch (node.type) {
  7010. case "Identifier":
  7011. case "ObjectPattern":
  7012. case "ArrayPattern":
  7013. case "AssignmentPattern":
  7014. case "RestElement":
  7015. break;
  7016. case "ObjectExpression":
  7017. node.type = "ObjectPattern";
  7018. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7019. var _node$extra2;
  7020. const prop = node.properties[i];
  7021. const isLast = i === last;
  7022. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7023. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7024. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7025. }
  7026. }
  7027. break;
  7028. case "ObjectProperty":
  7029. {
  7030. const {
  7031. key,
  7032. value
  7033. } = node;
  7034. if (this.isPrivateName(key)) {
  7035. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7036. }
  7037. this.toAssignable(value, isLHS);
  7038. break;
  7039. }
  7040. case "SpreadElement":
  7041. {
  7042. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7043. }
  7044. case "ArrayExpression":
  7045. node.type = "ArrayPattern";
  7046. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7047. break;
  7048. case "AssignmentExpression":
  7049. if (node.operator !== "=") {
  7050. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7051. }
  7052. node.type = "AssignmentPattern";
  7053. delete node.operator;
  7054. this.toAssignable(node.left, isLHS);
  7055. break;
  7056. case "ParenthesizedExpression":
  7057. this.toAssignable(parenthesized, isLHS);
  7058. break;
  7059. }
  7060. }
  7061. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7062. if (prop.type === "ObjectMethod") {
  7063. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7064. } else if (prop.type === "SpreadElement") {
  7065. prop.type = "RestElement";
  7066. const arg = prop.argument;
  7067. this.checkToRestConversion(arg, false);
  7068. this.toAssignable(arg, isLHS);
  7069. if (!isLast) {
  7070. this.raise(Errors.RestTrailingComma, prop);
  7071. }
  7072. } else {
  7073. this.toAssignable(prop, isLHS);
  7074. }
  7075. }
  7076. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7077. const end = exprList.length - 1;
  7078. for (let i = 0; i <= end; i++) {
  7079. const elt = exprList[i];
  7080. if (!elt) continue;
  7081. if (elt.type === "SpreadElement") {
  7082. elt.type = "RestElement";
  7083. const arg = elt.argument;
  7084. this.checkToRestConversion(arg, true);
  7085. this.toAssignable(arg, isLHS);
  7086. } else {
  7087. this.toAssignable(elt, isLHS);
  7088. }
  7089. if (elt.type === "RestElement") {
  7090. if (i < end) {
  7091. this.raise(Errors.RestTrailingComma, elt);
  7092. } else if (trailingCommaLoc) {
  7093. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7094. }
  7095. }
  7096. }
  7097. }
  7098. isAssignable(node, isBinding) {
  7099. switch (node.type) {
  7100. case "Identifier":
  7101. case "ObjectPattern":
  7102. case "ArrayPattern":
  7103. case "AssignmentPattern":
  7104. case "RestElement":
  7105. return true;
  7106. case "ObjectExpression":
  7107. {
  7108. const last = node.properties.length - 1;
  7109. return node.properties.every((prop, i) => {
  7110. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7111. });
  7112. }
  7113. case "ObjectProperty":
  7114. return this.isAssignable(node.value);
  7115. case "SpreadElement":
  7116. return this.isAssignable(node.argument);
  7117. case "ArrayExpression":
  7118. return node.elements.every(element => element === null || this.isAssignable(element));
  7119. case "AssignmentExpression":
  7120. return node.operator === "=";
  7121. case "ParenthesizedExpression":
  7122. return this.isAssignable(node.expression);
  7123. case "MemberExpression":
  7124. case "OptionalMemberExpression":
  7125. return !isBinding;
  7126. default:
  7127. return false;
  7128. }
  7129. }
  7130. toReferencedList(exprList, isParenthesizedExpr) {
  7131. return exprList;
  7132. }
  7133. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7134. this.toReferencedList(exprList, isParenthesizedExpr);
  7135. for (const expr of exprList) {
  7136. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7137. this.toReferencedListDeep(expr.elements);
  7138. }
  7139. }
  7140. }
  7141. parseSpread(refExpressionErrors) {
  7142. const node = this.startNode();
  7143. this.next();
  7144. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7145. return this.finishNode(node, "SpreadElement");
  7146. }
  7147. parseRestBinding() {
  7148. const node = this.startNode();
  7149. this.next();
  7150. node.argument = this.parseBindingAtom();
  7151. return this.finishNode(node, "RestElement");
  7152. }
  7153. parseBindingAtom() {
  7154. switch (this.state.type) {
  7155. case 0:
  7156. {
  7157. const node = this.startNode();
  7158. this.next();
  7159. node.elements = this.parseBindingList(3, 93, 1);
  7160. return this.finishNode(node, "ArrayPattern");
  7161. }
  7162. case 5:
  7163. return this.parseObjectLike(8, true);
  7164. }
  7165. return this.parseIdentifier();
  7166. }
  7167. parseBindingList(close, closeCharCode, flags) {
  7168. const allowEmpty = flags & 1;
  7169. const elts = [];
  7170. let first = true;
  7171. while (!this.eat(close)) {
  7172. if (first) {
  7173. first = false;
  7174. } else {
  7175. this.expect(12);
  7176. }
  7177. if (allowEmpty && this.match(12)) {
  7178. elts.push(null);
  7179. } else if (this.eat(close)) {
  7180. break;
  7181. } else if (this.match(21)) {
  7182. let rest = this.parseRestBinding();
  7183. if (this.hasPlugin("flow") || flags & 2) {
  7184. rest = this.parseFunctionParamType(rest);
  7185. }
  7186. elts.push(rest);
  7187. if (!this.checkCommaAfterRest(closeCharCode)) {
  7188. this.expect(close);
  7189. break;
  7190. }
  7191. } else {
  7192. const decorators = [];
  7193. if (this.match(26) && this.hasPlugin("decorators")) {
  7194. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7195. }
  7196. while (this.match(26)) {
  7197. decorators.push(this.parseDecorator());
  7198. }
  7199. elts.push(this.parseAssignableListItem(flags, decorators));
  7200. }
  7201. }
  7202. return elts;
  7203. }
  7204. parseBindingRestProperty(prop) {
  7205. this.next();
  7206. prop.argument = this.parseIdentifier();
  7207. this.checkCommaAfterRest(125);
  7208. return this.finishNode(prop, "RestElement");
  7209. }
  7210. parseBindingProperty() {
  7211. const {
  7212. type,
  7213. startLoc
  7214. } = this.state;
  7215. if (type === 21) {
  7216. return this.parseBindingRestProperty(this.startNode());
  7217. }
  7218. const prop = this.startNode();
  7219. if (type === 138) {
  7220. this.expectPlugin("destructuringPrivate", startLoc);
  7221. this.classScope.usePrivateName(this.state.value, startLoc);
  7222. prop.key = this.parsePrivateName();
  7223. } else {
  7224. this.parsePropertyName(prop);
  7225. }
  7226. prop.method = false;
  7227. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7228. }
  7229. parseAssignableListItem(flags, decorators) {
  7230. const left = this.parseMaybeDefault();
  7231. if (this.hasPlugin("flow") || flags & 2) {
  7232. this.parseFunctionParamType(left);
  7233. }
  7234. const elt = this.parseMaybeDefault(left.loc.start, left);
  7235. if (decorators.length) {
  7236. left.decorators = decorators;
  7237. }
  7238. return elt;
  7239. }
  7240. parseFunctionParamType(param) {
  7241. return param;
  7242. }
  7243. parseMaybeDefault(startLoc, left) {
  7244. var _startLoc, _left;
  7245. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  7246. left = (_left = left) != null ? _left : this.parseBindingAtom();
  7247. if (!this.eat(29)) return left;
  7248. const node = this.startNodeAt(startLoc);
  7249. node.left = left;
  7250. node.right = this.parseMaybeAssignAllowIn();
  7251. return this.finishNode(node, "AssignmentPattern");
  7252. }
  7253. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7254. switch (type) {
  7255. case "AssignmentPattern":
  7256. return "left";
  7257. case "RestElement":
  7258. return "argument";
  7259. case "ObjectProperty":
  7260. return "value";
  7261. case "ParenthesizedExpression":
  7262. return "expression";
  7263. case "ArrayPattern":
  7264. return "elements";
  7265. case "ObjectPattern":
  7266. return "properties";
  7267. }
  7268. return false;
  7269. }
  7270. isOptionalMemberExpression(expression) {
  7271. return expression.type === "OptionalMemberExpression";
  7272. }
  7273. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false) {
  7274. var _expression$extra;
  7275. const type = expression.type;
  7276. if (this.isObjectMethod(expression)) return;
  7277. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7278. if (isOptionalMemberExpression || type === "MemberExpression") {
  7279. if (isOptionalMemberExpression) {
  7280. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7281. if (ancestor.type !== "AssignmentExpression") {
  7282. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7283. ancestor
  7284. });
  7285. }
  7286. }
  7287. if (binding !== 64) {
  7288. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7289. }
  7290. return;
  7291. }
  7292. if (type === "Identifier") {
  7293. this.checkIdentifier(expression, binding, strictModeChanged);
  7294. const {
  7295. name
  7296. } = expression;
  7297. if (checkClashes) {
  7298. if (checkClashes.has(name)) {
  7299. this.raise(Errors.ParamDupe, expression);
  7300. } else {
  7301. checkClashes.add(name);
  7302. }
  7303. }
  7304. return;
  7305. }
  7306. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7307. if (validity === true) return;
  7308. if (validity === false) {
  7309. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7310. this.raise(ParseErrorClass, expression, {
  7311. ancestor
  7312. });
  7313. return;
  7314. }
  7315. let key, isParenthesizedExpression;
  7316. if (typeof validity === "string") {
  7317. key = validity;
  7318. isParenthesizedExpression = type === "ParenthesizedExpression";
  7319. } else {
  7320. [key, isParenthesizedExpression] = validity;
  7321. }
  7322. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7323. type
  7324. } : ancestor;
  7325. const val = expression[key];
  7326. if (Array.isArray(val)) {
  7327. for (const child of val) {
  7328. if (child) {
  7329. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  7330. }
  7331. }
  7332. } else if (val) {
  7333. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  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. function nonNull(x) {
  7382. if (x == null) {
  7383. throw new Error(`Unexpected ${x} value.`);
  7384. }
  7385. return x;
  7386. }
  7387. function assert(x) {
  7388. if (!x) {
  7389. throw new Error("Assert fail");
  7390. }
  7391. }
  7392. const TSErrors = ParseErrorEnum`typescript`({
  7393. AbstractMethodHasImplementation: ({
  7394. methodName
  7395. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7396. AbstractPropertyHasInitializer: ({
  7397. propertyName
  7398. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7399. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7400. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7401. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7402. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7403. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7404. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7405. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7406. DeclareAccessor: ({
  7407. kind
  7408. }) => `'declare' is not allowed in ${kind}ters.`,
  7409. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7410. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7411. DuplicateAccessibilityModifier: ({
  7412. modifier
  7413. }) => `Accessibility modifier already seen.`,
  7414. DuplicateModifier: ({
  7415. modifier
  7416. }) => `Duplicate modifier: '${modifier}'.`,
  7417. EmptyHeritageClauseType: ({
  7418. token
  7419. }) => `'${token}' list cannot be empty.`,
  7420. EmptyTypeArguments: "Type argument list cannot be empty.",
  7421. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7422. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7423. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7424. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7425. IncompatibleModifiers: ({
  7426. modifiers
  7427. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7428. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7429. IndexSignatureHasAccessibility: ({
  7430. modifier
  7431. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7432. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7433. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7434. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7435. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7436. InvalidModifierOnTypeMember: ({
  7437. modifier
  7438. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7439. InvalidModifierOnTypeParameter: ({
  7440. modifier
  7441. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7442. InvalidModifierOnTypeParameterPositions: ({
  7443. modifier
  7444. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7445. InvalidModifiersOrder: ({
  7446. orderedModifiers
  7447. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7448. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7449. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7450. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7451. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7452. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7453. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7454. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7455. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7456. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7457. PrivateElementHasAccessibility: ({
  7458. modifier
  7459. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7460. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7461. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7462. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7463. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7464. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7465. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7466. SingleTypeParameterWithoutTrailingComma: ({
  7467. typeParameterName
  7468. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7469. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7470. 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?`).",
  7471. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7472. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7473. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7474. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7475. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7476. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7477. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7478. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7479. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7480. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7481. UnsupportedSignatureParameterKind: ({
  7482. type
  7483. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7484. });
  7485. function keywordTypeFromName(value) {
  7486. switch (value) {
  7487. case "any":
  7488. return "TSAnyKeyword";
  7489. case "boolean":
  7490. return "TSBooleanKeyword";
  7491. case "bigint":
  7492. return "TSBigIntKeyword";
  7493. case "never":
  7494. return "TSNeverKeyword";
  7495. case "number":
  7496. return "TSNumberKeyword";
  7497. case "object":
  7498. return "TSObjectKeyword";
  7499. case "string":
  7500. return "TSStringKeyword";
  7501. case "symbol":
  7502. return "TSSymbolKeyword";
  7503. case "undefined":
  7504. return "TSUndefinedKeyword";
  7505. case "unknown":
  7506. return "TSUnknownKeyword";
  7507. default:
  7508. return undefined;
  7509. }
  7510. }
  7511. function tsIsAccessModifier(modifier) {
  7512. return modifier === "private" || modifier === "public" || modifier === "protected";
  7513. }
  7514. function tsIsVarianceAnnotations(modifier) {
  7515. return modifier === "in" || modifier === "out";
  7516. }
  7517. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7518. constructor(...args) {
  7519. super(...args);
  7520. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7521. allowedModifiers: ["in", "out"],
  7522. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7523. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7524. });
  7525. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7526. allowedModifiers: ["const"],
  7527. disallowedModifiers: ["in", "out"],
  7528. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7529. });
  7530. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7531. allowedModifiers: ["in", "out", "const"],
  7532. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7533. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7534. });
  7535. }
  7536. getScopeHandler() {
  7537. return TypeScriptScopeHandler;
  7538. }
  7539. tsIsIdentifier() {
  7540. return tokenIsIdentifier(this.state.type);
  7541. }
  7542. tsTokenCanFollowModifier() {
  7543. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(138) || this.isLiteralPropertyName();
  7544. }
  7545. tsNextTokenOnSameLineAndCanFollowModifier() {
  7546. this.next();
  7547. if (this.hasPrecedingLineBreak()) {
  7548. return false;
  7549. }
  7550. return this.tsTokenCanFollowModifier();
  7551. }
  7552. tsNextTokenCanFollowModifier() {
  7553. if (this.match(106)) {
  7554. this.next();
  7555. return this.tsTokenCanFollowModifier();
  7556. }
  7557. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  7558. }
  7559. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7560. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7561. return undefined;
  7562. }
  7563. const modifier = this.state.value;
  7564. if (allowedModifiers.includes(modifier)) {
  7565. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7566. return undefined;
  7567. }
  7568. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7569. return modifier;
  7570. }
  7571. }
  7572. return undefined;
  7573. }
  7574. tsParseModifiers({
  7575. allowedModifiers,
  7576. disallowedModifiers,
  7577. stopOnStartOfClassStaticBlock,
  7578. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7579. }, modified) {
  7580. const enforceOrder = (loc, modifier, before, after) => {
  7581. if (modifier === before && modified[after]) {
  7582. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7583. orderedModifiers: [before, after]
  7584. });
  7585. }
  7586. };
  7587. const incompatible = (loc, modifier, mod1, mod2) => {
  7588. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7589. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7590. modifiers: [mod1, mod2]
  7591. });
  7592. }
  7593. };
  7594. for (;;) {
  7595. const {
  7596. startLoc
  7597. } = this.state;
  7598. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7599. if (!modifier) break;
  7600. if (tsIsAccessModifier(modifier)) {
  7601. if (modified.accessibility) {
  7602. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7603. modifier
  7604. });
  7605. } else {
  7606. enforceOrder(startLoc, modifier, modifier, "override");
  7607. enforceOrder(startLoc, modifier, modifier, "static");
  7608. enforceOrder(startLoc, modifier, modifier, "readonly");
  7609. modified.accessibility = modifier;
  7610. }
  7611. } else if (tsIsVarianceAnnotations(modifier)) {
  7612. if (modified[modifier]) {
  7613. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7614. modifier
  7615. });
  7616. }
  7617. modified[modifier] = true;
  7618. enforceOrder(startLoc, modifier, "in", "out");
  7619. } else {
  7620. if (hasOwnProperty.call(modified, modifier)) {
  7621. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7622. modifier
  7623. });
  7624. } else {
  7625. enforceOrder(startLoc, modifier, "static", "readonly");
  7626. enforceOrder(startLoc, modifier, "static", "override");
  7627. enforceOrder(startLoc, modifier, "override", "readonly");
  7628. enforceOrder(startLoc, modifier, "abstract", "override");
  7629. incompatible(startLoc, modifier, "declare", "override");
  7630. incompatible(startLoc, modifier, "static", "abstract");
  7631. }
  7632. modified[modifier] = true;
  7633. }
  7634. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7635. this.raise(errorTemplate, startLoc, {
  7636. modifier
  7637. });
  7638. }
  7639. }
  7640. }
  7641. tsIsListTerminator(kind) {
  7642. switch (kind) {
  7643. case "EnumMembers":
  7644. case "TypeMembers":
  7645. return this.match(8);
  7646. case "HeritageClauseElement":
  7647. return this.match(5);
  7648. case "TupleElementTypes":
  7649. return this.match(3);
  7650. case "TypeParametersOrArguments":
  7651. return this.match(48);
  7652. }
  7653. }
  7654. tsParseList(kind, parseElement) {
  7655. const result = [];
  7656. while (!this.tsIsListTerminator(kind)) {
  7657. result.push(parseElement());
  7658. }
  7659. return result;
  7660. }
  7661. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7662. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7663. }
  7664. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7665. const result = [];
  7666. let trailingCommaPos = -1;
  7667. for (;;) {
  7668. if (this.tsIsListTerminator(kind)) {
  7669. break;
  7670. }
  7671. trailingCommaPos = -1;
  7672. const element = parseElement();
  7673. if (element == null) {
  7674. return undefined;
  7675. }
  7676. result.push(element);
  7677. if (this.eat(12)) {
  7678. trailingCommaPos = this.state.lastTokStartLoc.index;
  7679. continue;
  7680. }
  7681. if (this.tsIsListTerminator(kind)) {
  7682. break;
  7683. }
  7684. if (expectSuccess) {
  7685. this.expect(12);
  7686. }
  7687. return undefined;
  7688. }
  7689. if (refTrailingCommaPos) {
  7690. refTrailingCommaPos.value = trailingCommaPos;
  7691. }
  7692. return result;
  7693. }
  7694. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7695. if (!skipFirstToken) {
  7696. if (bracket) {
  7697. this.expect(0);
  7698. } else {
  7699. this.expect(47);
  7700. }
  7701. }
  7702. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7703. if (bracket) {
  7704. this.expect(3);
  7705. } else {
  7706. this.expect(48);
  7707. }
  7708. return result;
  7709. }
  7710. tsParseImportType() {
  7711. const node = this.startNode();
  7712. this.expect(83);
  7713. this.expect(10);
  7714. if (!this.match(133)) {
  7715. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7716. }
  7717. node.argument = super.parseExprAtom();
  7718. if (this.eat(12) && !this.match(11)) {
  7719. node.options = super.parseMaybeAssignAllowIn();
  7720. this.eat(12);
  7721. } else {
  7722. node.options = null;
  7723. }
  7724. this.expect(11);
  7725. if (this.eat(16)) {
  7726. node.qualifier = this.tsParseEntityName();
  7727. }
  7728. if (this.match(47)) {
  7729. node.typeParameters = this.tsParseTypeArguments();
  7730. }
  7731. return this.finishNode(node, "TSImportType");
  7732. }
  7733. tsParseEntityName(allowReservedWords = true) {
  7734. let entity = this.parseIdentifier(allowReservedWords);
  7735. while (this.eat(16)) {
  7736. const node = this.startNodeAtNode(entity);
  7737. node.left = entity;
  7738. node.right = this.parseIdentifier(allowReservedWords);
  7739. entity = this.finishNode(node, "TSQualifiedName");
  7740. }
  7741. return entity;
  7742. }
  7743. tsParseTypeReference() {
  7744. const node = this.startNode();
  7745. node.typeName = this.tsParseEntityName();
  7746. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7747. node.typeParameters = this.tsParseTypeArguments();
  7748. }
  7749. return this.finishNode(node, "TSTypeReference");
  7750. }
  7751. tsParseThisTypePredicate(lhs) {
  7752. this.next();
  7753. const node = this.startNodeAtNode(lhs);
  7754. node.parameterName = lhs;
  7755. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7756. node.asserts = false;
  7757. return this.finishNode(node, "TSTypePredicate");
  7758. }
  7759. tsParseThisTypeNode() {
  7760. const node = this.startNode();
  7761. this.next();
  7762. return this.finishNode(node, "TSThisType");
  7763. }
  7764. tsParseTypeQuery() {
  7765. const node = this.startNode();
  7766. this.expect(87);
  7767. if (this.match(83)) {
  7768. node.exprName = this.tsParseImportType();
  7769. } else {
  7770. node.exprName = this.tsParseEntityName();
  7771. }
  7772. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7773. node.typeParameters = this.tsParseTypeArguments();
  7774. }
  7775. return this.finishNode(node, "TSTypeQuery");
  7776. }
  7777. tsParseTypeParameter(parseModifiers) {
  7778. const node = this.startNode();
  7779. parseModifiers(node);
  7780. node.name = this.tsParseTypeParameterName();
  7781. node.constraint = this.tsEatThenParseType(81);
  7782. node.default = this.tsEatThenParseType(29);
  7783. return this.finishNode(node, "TSTypeParameter");
  7784. }
  7785. tsTryParseTypeParameters(parseModifiers) {
  7786. if (this.match(47)) {
  7787. return this.tsParseTypeParameters(parseModifiers);
  7788. }
  7789. }
  7790. tsParseTypeParameters(parseModifiers) {
  7791. const node = this.startNode();
  7792. if (this.match(47) || this.match(142)) {
  7793. this.next();
  7794. } else {
  7795. this.unexpected();
  7796. }
  7797. const refTrailingCommaPos = {
  7798. value: -1
  7799. };
  7800. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7801. if (node.params.length === 0) {
  7802. this.raise(TSErrors.EmptyTypeParameters, node);
  7803. }
  7804. if (refTrailingCommaPos.value !== -1) {
  7805. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7806. }
  7807. return this.finishNode(node, "TSTypeParameterDeclaration");
  7808. }
  7809. tsFillSignature(returnToken, signature) {
  7810. const returnTokenRequired = returnToken === 19;
  7811. const paramsKey = "parameters";
  7812. const returnTypeKey = "typeAnnotation";
  7813. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  7814. this.expect(10);
  7815. signature[paramsKey] = this.tsParseBindingListForSignature();
  7816. if (returnTokenRequired) {
  7817. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7818. } else if (this.match(returnToken)) {
  7819. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7820. }
  7821. }
  7822. tsParseBindingListForSignature() {
  7823. const list = super.parseBindingList(11, 41, 2);
  7824. for (const pattern of list) {
  7825. const {
  7826. type
  7827. } = pattern;
  7828. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  7829. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  7830. type
  7831. });
  7832. }
  7833. }
  7834. return list;
  7835. }
  7836. tsParseTypeMemberSemicolon() {
  7837. if (!this.eat(12) && !this.isLineTerminator()) {
  7838. this.expect(13);
  7839. }
  7840. }
  7841. tsParseSignatureMember(kind, node) {
  7842. this.tsFillSignature(14, node);
  7843. this.tsParseTypeMemberSemicolon();
  7844. return this.finishNode(node, kind);
  7845. }
  7846. tsIsUnambiguouslyIndexSignature() {
  7847. this.next();
  7848. if (tokenIsIdentifier(this.state.type)) {
  7849. this.next();
  7850. return this.match(14);
  7851. }
  7852. return false;
  7853. }
  7854. tsTryParseIndexSignature(node) {
  7855. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  7856. return;
  7857. }
  7858. this.expect(0);
  7859. const id = this.parseIdentifier();
  7860. id.typeAnnotation = this.tsParseTypeAnnotation();
  7861. this.resetEndLocation(id);
  7862. this.expect(3);
  7863. node.parameters = [id];
  7864. const type = this.tsTryParseTypeAnnotation();
  7865. if (type) node.typeAnnotation = type;
  7866. this.tsParseTypeMemberSemicolon();
  7867. return this.finishNode(node, "TSIndexSignature");
  7868. }
  7869. tsParsePropertyOrMethodSignature(node, readonly) {
  7870. if (this.eat(17)) node.optional = true;
  7871. const nodeAny = node;
  7872. if (this.match(10) || this.match(47)) {
  7873. if (readonly) {
  7874. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  7875. }
  7876. const method = nodeAny;
  7877. if (method.kind && this.match(47)) {
  7878. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  7879. }
  7880. this.tsFillSignature(14, method);
  7881. this.tsParseTypeMemberSemicolon();
  7882. const paramsKey = "parameters";
  7883. const returnTypeKey = "typeAnnotation";
  7884. if (method.kind === "get") {
  7885. if (method[paramsKey].length > 0) {
  7886. this.raise(Errors.BadGetterArity, this.state.curPosition());
  7887. if (this.isThisParam(method[paramsKey][0])) {
  7888. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  7889. }
  7890. }
  7891. } else if (method.kind === "set") {
  7892. if (method[paramsKey].length !== 1) {
  7893. this.raise(Errors.BadSetterArity, this.state.curPosition());
  7894. } else {
  7895. const firstParameter = method[paramsKey][0];
  7896. if (this.isThisParam(firstParameter)) {
  7897. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  7898. }
  7899. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  7900. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  7901. }
  7902. if (firstParameter.type === "RestElement") {
  7903. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  7904. }
  7905. }
  7906. if (method[returnTypeKey]) {
  7907. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  7908. }
  7909. } else {
  7910. method.kind = "method";
  7911. }
  7912. return this.finishNode(method, "TSMethodSignature");
  7913. } else {
  7914. const property = nodeAny;
  7915. if (readonly) property.readonly = true;
  7916. const type = this.tsTryParseTypeAnnotation();
  7917. if (type) property.typeAnnotation = type;
  7918. this.tsParseTypeMemberSemicolon();
  7919. return this.finishNode(property, "TSPropertySignature");
  7920. }
  7921. }
  7922. tsParseTypeMember() {
  7923. const node = this.startNode();
  7924. if (this.match(10) || this.match(47)) {
  7925. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  7926. }
  7927. if (this.match(77)) {
  7928. const id = this.startNode();
  7929. this.next();
  7930. if (this.match(10) || this.match(47)) {
  7931. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  7932. } else {
  7933. node.key = this.createIdentifier(id, "new");
  7934. return this.tsParsePropertyOrMethodSignature(node, false);
  7935. }
  7936. }
  7937. this.tsParseModifiers({
  7938. allowedModifiers: ["readonly"],
  7939. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  7940. }, node);
  7941. const idx = this.tsTryParseIndexSignature(node);
  7942. if (idx) {
  7943. return idx;
  7944. }
  7945. super.parsePropertyName(node);
  7946. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  7947. node.kind = node.key.name;
  7948. super.parsePropertyName(node);
  7949. }
  7950. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  7951. }
  7952. tsParseTypeLiteral() {
  7953. const node = this.startNode();
  7954. node.members = this.tsParseObjectTypeMembers();
  7955. return this.finishNode(node, "TSTypeLiteral");
  7956. }
  7957. tsParseObjectTypeMembers() {
  7958. this.expect(5);
  7959. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  7960. this.expect(8);
  7961. return members;
  7962. }
  7963. tsIsStartOfMappedType() {
  7964. this.next();
  7965. if (this.eat(53)) {
  7966. return this.isContextual(122);
  7967. }
  7968. if (this.isContextual(122)) {
  7969. this.next();
  7970. }
  7971. if (!this.match(0)) {
  7972. return false;
  7973. }
  7974. this.next();
  7975. if (!this.tsIsIdentifier()) {
  7976. return false;
  7977. }
  7978. this.next();
  7979. return this.match(58);
  7980. }
  7981. tsParseMappedType() {
  7982. const node = this.startNode();
  7983. this.expect(5);
  7984. if (this.match(53)) {
  7985. node.readonly = this.state.value;
  7986. this.next();
  7987. this.expectContextual(122);
  7988. } else if (this.eatContextual(122)) {
  7989. node.readonly = true;
  7990. }
  7991. this.expect(0);
  7992. {
  7993. const typeParameter = this.startNode();
  7994. typeParameter.name = this.tsParseTypeParameterName();
  7995. typeParameter.constraint = this.tsExpectThenParseType(58);
  7996. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  7997. }
  7998. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  7999. this.expect(3);
  8000. if (this.match(53)) {
  8001. node.optional = this.state.value;
  8002. this.next();
  8003. this.expect(17);
  8004. } else if (this.eat(17)) {
  8005. node.optional = true;
  8006. }
  8007. node.typeAnnotation = this.tsTryParseType();
  8008. this.semicolon();
  8009. this.expect(8);
  8010. return this.finishNode(node, "TSMappedType");
  8011. }
  8012. tsParseTupleType() {
  8013. const node = this.startNode();
  8014. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8015. let seenOptionalElement = false;
  8016. node.elementTypes.forEach(elementNode => {
  8017. const {
  8018. type
  8019. } = elementNode;
  8020. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8021. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8022. }
  8023. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8024. });
  8025. return this.finishNode(node, "TSTupleType");
  8026. }
  8027. tsParseTupleElementType() {
  8028. const {
  8029. startLoc
  8030. } = this.state;
  8031. const rest = this.eat(21);
  8032. let labeled;
  8033. let label;
  8034. let optional;
  8035. let type;
  8036. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8037. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8038. if (chAfterWord === 58) {
  8039. labeled = true;
  8040. optional = false;
  8041. label = this.parseIdentifier(true);
  8042. this.expect(14);
  8043. type = this.tsParseType();
  8044. } else if (chAfterWord === 63) {
  8045. optional = true;
  8046. const startLoc = this.state.startLoc;
  8047. const wordName = this.state.value;
  8048. const typeOrLabel = this.tsParseNonArrayType();
  8049. if (this.lookaheadCharCode() === 58) {
  8050. labeled = true;
  8051. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8052. this.expect(17);
  8053. this.expect(14);
  8054. type = this.tsParseType();
  8055. } else {
  8056. labeled = false;
  8057. type = typeOrLabel;
  8058. this.expect(17);
  8059. }
  8060. } else {
  8061. type = this.tsParseType();
  8062. optional = this.eat(17);
  8063. labeled = this.eat(14);
  8064. }
  8065. if (labeled) {
  8066. let labeledNode;
  8067. if (label) {
  8068. labeledNode = this.startNodeAtNode(label);
  8069. labeledNode.optional = optional;
  8070. labeledNode.label = label;
  8071. labeledNode.elementType = type;
  8072. if (this.eat(17)) {
  8073. labeledNode.optional = true;
  8074. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8075. }
  8076. } else {
  8077. labeledNode = this.startNodeAtNode(type);
  8078. labeledNode.optional = optional;
  8079. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8080. labeledNode.label = type;
  8081. labeledNode.elementType = this.tsParseType();
  8082. }
  8083. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8084. } else if (optional) {
  8085. const optionalTypeNode = this.startNodeAtNode(type);
  8086. optionalTypeNode.typeAnnotation = type;
  8087. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8088. }
  8089. if (rest) {
  8090. const restNode = this.startNodeAt(startLoc);
  8091. restNode.typeAnnotation = type;
  8092. type = this.finishNode(restNode, "TSRestType");
  8093. }
  8094. return type;
  8095. }
  8096. tsParseParenthesizedType() {
  8097. const node = this.startNode();
  8098. this.expect(10);
  8099. node.typeAnnotation = this.tsParseType();
  8100. this.expect(11);
  8101. return this.finishNode(node, "TSParenthesizedType");
  8102. }
  8103. tsParseFunctionOrConstructorType(type, abstract) {
  8104. const node = this.startNode();
  8105. if (type === "TSConstructorType") {
  8106. node.abstract = !!abstract;
  8107. if (abstract) this.next();
  8108. this.next();
  8109. }
  8110. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8111. return this.finishNode(node, type);
  8112. }
  8113. tsParseLiteralTypeNode() {
  8114. const node = this.startNode();
  8115. switch (this.state.type) {
  8116. case 134:
  8117. case 135:
  8118. case 133:
  8119. case 85:
  8120. case 86:
  8121. node.literal = super.parseExprAtom();
  8122. break;
  8123. default:
  8124. this.unexpected();
  8125. }
  8126. return this.finishNode(node, "TSLiteralType");
  8127. }
  8128. tsParseTemplateLiteralType() {
  8129. const node = this.startNode();
  8130. node.literal = super.parseTemplate(false);
  8131. return this.finishNode(node, "TSLiteralType");
  8132. }
  8133. parseTemplateSubstitution() {
  8134. if (this.state.inType) return this.tsParseType();
  8135. return super.parseTemplateSubstitution();
  8136. }
  8137. tsParseThisTypeOrThisTypePredicate() {
  8138. const thisKeyword = this.tsParseThisTypeNode();
  8139. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8140. return this.tsParseThisTypePredicate(thisKeyword);
  8141. } else {
  8142. return thisKeyword;
  8143. }
  8144. }
  8145. tsParseNonArrayType() {
  8146. switch (this.state.type) {
  8147. case 133:
  8148. case 134:
  8149. case 135:
  8150. case 85:
  8151. case 86:
  8152. return this.tsParseLiteralTypeNode();
  8153. case 53:
  8154. if (this.state.value === "-") {
  8155. const node = this.startNode();
  8156. const nextToken = this.lookahead();
  8157. if (nextToken.type !== 134 && nextToken.type !== 135) {
  8158. this.unexpected();
  8159. }
  8160. node.literal = this.parseMaybeUnary();
  8161. return this.finishNode(node, "TSLiteralType");
  8162. }
  8163. break;
  8164. case 78:
  8165. return this.tsParseThisTypeOrThisTypePredicate();
  8166. case 87:
  8167. return this.tsParseTypeQuery();
  8168. case 83:
  8169. return this.tsParseImportType();
  8170. case 5:
  8171. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8172. case 0:
  8173. return this.tsParseTupleType();
  8174. case 10:
  8175. return this.tsParseParenthesizedType();
  8176. case 25:
  8177. case 24:
  8178. return this.tsParseTemplateLiteralType();
  8179. default:
  8180. {
  8181. const {
  8182. type
  8183. } = this.state;
  8184. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8185. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8186. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8187. const node = this.startNode();
  8188. this.next();
  8189. return this.finishNode(node, nodeType);
  8190. }
  8191. return this.tsParseTypeReference();
  8192. }
  8193. }
  8194. }
  8195. this.unexpected();
  8196. }
  8197. tsParseArrayTypeOrHigher() {
  8198. let type = this.tsParseNonArrayType();
  8199. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8200. if (this.match(3)) {
  8201. const node = this.startNodeAtNode(type);
  8202. node.elementType = type;
  8203. this.expect(3);
  8204. type = this.finishNode(node, "TSArrayType");
  8205. } else {
  8206. const node = this.startNodeAtNode(type);
  8207. node.objectType = type;
  8208. node.indexType = this.tsParseType();
  8209. this.expect(3);
  8210. type = this.finishNode(node, "TSIndexedAccessType");
  8211. }
  8212. }
  8213. return type;
  8214. }
  8215. tsParseTypeOperator() {
  8216. const node = this.startNode();
  8217. const operator = this.state.value;
  8218. this.next();
  8219. node.operator = operator;
  8220. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8221. if (operator === "readonly") {
  8222. this.tsCheckTypeAnnotationForReadOnly(node);
  8223. }
  8224. return this.finishNode(node, "TSTypeOperator");
  8225. }
  8226. tsCheckTypeAnnotationForReadOnly(node) {
  8227. switch (node.typeAnnotation.type) {
  8228. case "TSTupleType":
  8229. case "TSArrayType":
  8230. return;
  8231. default:
  8232. this.raise(TSErrors.UnexpectedReadonly, node);
  8233. }
  8234. }
  8235. tsParseInferType() {
  8236. const node = this.startNode();
  8237. this.expectContextual(115);
  8238. const typeParameter = this.startNode();
  8239. typeParameter.name = this.tsParseTypeParameterName();
  8240. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8241. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8242. return this.finishNode(node, "TSInferType");
  8243. }
  8244. tsParseConstraintForInferType() {
  8245. if (this.eat(81)) {
  8246. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8247. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8248. return constraint;
  8249. }
  8250. }
  8251. }
  8252. tsParseTypeOperatorOrHigher() {
  8253. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8254. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8255. }
  8256. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8257. const node = this.startNode();
  8258. const hasLeadingOperator = this.eat(operator);
  8259. const types = [];
  8260. do {
  8261. types.push(parseConstituentType());
  8262. } while (this.eat(operator));
  8263. if (types.length === 1 && !hasLeadingOperator) {
  8264. return types[0];
  8265. }
  8266. node.types = types;
  8267. return this.finishNode(node, kind);
  8268. }
  8269. tsParseIntersectionTypeOrHigher() {
  8270. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8271. }
  8272. tsParseUnionTypeOrHigher() {
  8273. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8274. }
  8275. tsIsStartOfFunctionType() {
  8276. if (this.match(47)) {
  8277. return true;
  8278. }
  8279. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8280. }
  8281. tsSkipParameterStart() {
  8282. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8283. this.next();
  8284. return true;
  8285. }
  8286. if (this.match(5)) {
  8287. const {
  8288. errors
  8289. } = this.state;
  8290. const previousErrorCount = errors.length;
  8291. try {
  8292. this.parseObjectLike(8, true);
  8293. return errors.length === previousErrorCount;
  8294. } catch (_unused) {
  8295. return false;
  8296. }
  8297. }
  8298. if (this.match(0)) {
  8299. this.next();
  8300. const {
  8301. errors
  8302. } = this.state;
  8303. const previousErrorCount = errors.length;
  8304. try {
  8305. super.parseBindingList(3, 93, 1);
  8306. return errors.length === previousErrorCount;
  8307. } catch (_unused2) {
  8308. return false;
  8309. }
  8310. }
  8311. return false;
  8312. }
  8313. tsIsUnambiguouslyStartOfFunctionType() {
  8314. this.next();
  8315. if (this.match(11) || this.match(21)) {
  8316. return true;
  8317. }
  8318. if (this.tsSkipParameterStart()) {
  8319. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8320. return true;
  8321. }
  8322. if (this.match(11)) {
  8323. this.next();
  8324. if (this.match(19)) {
  8325. return true;
  8326. }
  8327. }
  8328. }
  8329. return false;
  8330. }
  8331. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8332. return this.tsInType(() => {
  8333. const t = this.startNode();
  8334. this.expect(returnToken);
  8335. const node = this.startNode();
  8336. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8337. if (asserts && this.match(78)) {
  8338. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8339. if (thisTypePredicate.type === "TSThisType") {
  8340. node.parameterName = thisTypePredicate;
  8341. node.asserts = true;
  8342. node.typeAnnotation = null;
  8343. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8344. } else {
  8345. this.resetStartLocationFromNode(thisTypePredicate, node);
  8346. thisTypePredicate.asserts = true;
  8347. }
  8348. t.typeAnnotation = thisTypePredicate;
  8349. return this.finishNode(t, "TSTypeAnnotation");
  8350. }
  8351. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8352. if (!typePredicateVariable) {
  8353. if (!asserts) {
  8354. return this.tsParseTypeAnnotation(false, t);
  8355. }
  8356. node.parameterName = this.parseIdentifier();
  8357. node.asserts = asserts;
  8358. node.typeAnnotation = null;
  8359. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8360. return this.finishNode(t, "TSTypeAnnotation");
  8361. }
  8362. const type = this.tsParseTypeAnnotation(false);
  8363. node.parameterName = typePredicateVariable;
  8364. node.typeAnnotation = type;
  8365. node.asserts = asserts;
  8366. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8367. return this.finishNode(t, "TSTypeAnnotation");
  8368. });
  8369. }
  8370. tsTryParseTypeOrTypePredicateAnnotation() {
  8371. if (this.match(14)) {
  8372. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8373. }
  8374. }
  8375. tsTryParseTypeAnnotation() {
  8376. if (this.match(14)) {
  8377. return this.tsParseTypeAnnotation();
  8378. }
  8379. }
  8380. tsTryParseType() {
  8381. return this.tsEatThenParseType(14);
  8382. }
  8383. tsParseTypePredicatePrefix() {
  8384. const id = this.parseIdentifier();
  8385. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8386. this.next();
  8387. return id;
  8388. }
  8389. }
  8390. tsParseTypePredicateAsserts() {
  8391. if (this.state.type !== 109) {
  8392. return false;
  8393. }
  8394. const containsEsc = this.state.containsEsc;
  8395. this.next();
  8396. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8397. return false;
  8398. }
  8399. if (containsEsc) {
  8400. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8401. reservedWord: "asserts"
  8402. });
  8403. }
  8404. return true;
  8405. }
  8406. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8407. this.tsInType(() => {
  8408. if (eatColon) this.expect(14);
  8409. t.typeAnnotation = this.tsParseType();
  8410. });
  8411. return this.finishNode(t, "TSTypeAnnotation");
  8412. }
  8413. tsParseType() {
  8414. assert(this.state.inType);
  8415. const type = this.tsParseNonConditionalType();
  8416. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8417. return type;
  8418. }
  8419. const node = this.startNodeAtNode(type);
  8420. node.checkType = type;
  8421. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8422. this.expect(17);
  8423. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8424. this.expect(14);
  8425. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8426. return this.finishNode(node, "TSConditionalType");
  8427. }
  8428. isAbstractConstructorSignature() {
  8429. return this.isContextual(124) && this.lookahead().type === 77;
  8430. }
  8431. tsParseNonConditionalType() {
  8432. if (this.tsIsStartOfFunctionType()) {
  8433. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8434. }
  8435. if (this.match(77)) {
  8436. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8437. } else if (this.isAbstractConstructorSignature()) {
  8438. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8439. }
  8440. return this.tsParseUnionTypeOrHigher();
  8441. }
  8442. tsParseTypeAssertion() {
  8443. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8444. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8445. }
  8446. const node = this.startNode();
  8447. node.typeAnnotation = this.tsInType(() => {
  8448. this.next();
  8449. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8450. });
  8451. this.expect(48);
  8452. node.expression = this.parseMaybeUnary();
  8453. return this.finishNode(node, "TSTypeAssertion");
  8454. }
  8455. tsParseHeritageClause(token) {
  8456. const originalStartLoc = this.state.startLoc;
  8457. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8458. const node = this.startNode();
  8459. node.expression = this.tsParseEntityName();
  8460. if (this.match(47)) {
  8461. node.typeParameters = this.tsParseTypeArguments();
  8462. }
  8463. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8464. });
  8465. if (!delimitedList.length) {
  8466. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8467. token
  8468. });
  8469. }
  8470. return delimitedList;
  8471. }
  8472. tsParseInterfaceDeclaration(node, properties = {}) {
  8473. if (this.hasFollowingLineBreak()) return null;
  8474. this.expectContextual(129);
  8475. if (properties.declare) node.declare = true;
  8476. if (tokenIsIdentifier(this.state.type)) {
  8477. node.id = this.parseIdentifier();
  8478. this.checkIdentifier(node.id, 130);
  8479. } else {
  8480. node.id = null;
  8481. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8482. }
  8483. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8484. if (this.eat(81)) {
  8485. node.extends = this.tsParseHeritageClause("extends");
  8486. }
  8487. const body = this.startNode();
  8488. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8489. node.body = this.finishNode(body, "TSInterfaceBody");
  8490. return this.finishNode(node, "TSInterfaceDeclaration");
  8491. }
  8492. tsParseTypeAliasDeclaration(node) {
  8493. node.id = this.parseIdentifier();
  8494. this.checkIdentifier(node.id, 2);
  8495. node.typeAnnotation = this.tsInType(() => {
  8496. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8497. this.expect(29);
  8498. if (this.isContextual(114) && this.lookahead().type !== 16) {
  8499. const node = this.startNode();
  8500. this.next();
  8501. return this.finishNode(node, "TSIntrinsicKeyword");
  8502. }
  8503. return this.tsParseType();
  8504. });
  8505. this.semicolon();
  8506. return this.finishNode(node, "TSTypeAliasDeclaration");
  8507. }
  8508. tsInNoContext(cb) {
  8509. const oldContext = this.state.context;
  8510. this.state.context = [oldContext[0]];
  8511. try {
  8512. return cb();
  8513. } finally {
  8514. this.state.context = oldContext;
  8515. }
  8516. }
  8517. tsInType(cb) {
  8518. const oldInType = this.state.inType;
  8519. this.state.inType = true;
  8520. try {
  8521. return cb();
  8522. } finally {
  8523. this.state.inType = oldInType;
  8524. }
  8525. }
  8526. tsInDisallowConditionalTypesContext(cb) {
  8527. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8528. this.state.inDisallowConditionalTypesContext = true;
  8529. try {
  8530. return cb();
  8531. } finally {
  8532. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8533. }
  8534. }
  8535. tsInAllowConditionalTypesContext(cb) {
  8536. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8537. this.state.inDisallowConditionalTypesContext = false;
  8538. try {
  8539. return cb();
  8540. } finally {
  8541. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8542. }
  8543. }
  8544. tsEatThenParseType(token) {
  8545. if (this.match(token)) {
  8546. return this.tsNextThenParseType();
  8547. }
  8548. }
  8549. tsExpectThenParseType(token) {
  8550. return this.tsInType(() => {
  8551. this.expect(token);
  8552. return this.tsParseType();
  8553. });
  8554. }
  8555. tsNextThenParseType() {
  8556. return this.tsInType(() => {
  8557. this.next();
  8558. return this.tsParseType();
  8559. });
  8560. }
  8561. tsParseEnumMember() {
  8562. const node = this.startNode();
  8563. node.id = this.match(133) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8564. if (this.eat(29)) {
  8565. node.initializer = super.parseMaybeAssignAllowIn();
  8566. }
  8567. return this.finishNode(node, "TSEnumMember");
  8568. }
  8569. tsParseEnumDeclaration(node, properties = {}) {
  8570. if (properties.const) node.const = true;
  8571. if (properties.declare) node.declare = true;
  8572. this.expectContextual(126);
  8573. node.id = this.parseIdentifier();
  8574. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8575. this.expect(5);
  8576. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8577. this.expect(8);
  8578. return this.finishNode(node, "TSEnumDeclaration");
  8579. }
  8580. tsParseModuleBlock() {
  8581. const node = this.startNode();
  8582. this.scope.enter(0);
  8583. this.expect(5);
  8584. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8585. this.scope.exit();
  8586. return this.finishNode(node, "TSModuleBlock");
  8587. }
  8588. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8589. node.id = this.parseIdentifier();
  8590. if (!nested) {
  8591. this.checkIdentifier(node.id, 1024);
  8592. }
  8593. if (this.eat(16)) {
  8594. const inner = this.startNode();
  8595. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8596. node.body = inner;
  8597. } else {
  8598. this.scope.enter(256);
  8599. this.prodParam.enter(0);
  8600. node.body = this.tsParseModuleBlock();
  8601. this.prodParam.exit();
  8602. this.scope.exit();
  8603. }
  8604. return this.finishNode(node, "TSModuleDeclaration");
  8605. }
  8606. tsParseAmbientExternalModuleDeclaration(node) {
  8607. if (this.isContextual(112)) {
  8608. node.kind = "global";
  8609. node.global = true;
  8610. node.id = this.parseIdentifier();
  8611. } else if (this.match(133)) {
  8612. node.kind = "module";
  8613. node.id = super.parseStringLiteral(this.state.value);
  8614. } else {
  8615. this.unexpected();
  8616. }
  8617. if (this.match(5)) {
  8618. this.scope.enter(256);
  8619. this.prodParam.enter(0);
  8620. node.body = this.tsParseModuleBlock();
  8621. this.prodParam.exit();
  8622. this.scope.exit();
  8623. } else {
  8624. this.semicolon();
  8625. }
  8626. return this.finishNode(node, "TSModuleDeclaration");
  8627. }
  8628. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8629. node.isExport = isExport || false;
  8630. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8631. this.checkIdentifier(node.id, 4096);
  8632. this.expect(29);
  8633. const moduleReference = this.tsParseModuleReference();
  8634. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8635. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8636. }
  8637. node.moduleReference = moduleReference;
  8638. this.semicolon();
  8639. return this.finishNode(node, "TSImportEqualsDeclaration");
  8640. }
  8641. tsIsExternalModuleReference() {
  8642. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8643. }
  8644. tsParseModuleReference() {
  8645. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  8646. }
  8647. tsParseExternalModuleReference() {
  8648. const node = this.startNode();
  8649. this.expectContextual(119);
  8650. this.expect(10);
  8651. if (!this.match(133)) {
  8652. this.unexpected();
  8653. }
  8654. node.expression = super.parseExprAtom();
  8655. this.expect(11);
  8656. this.sawUnambiguousESM = true;
  8657. return this.finishNode(node, "TSExternalModuleReference");
  8658. }
  8659. tsLookAhead(f) {
  8660. const state = this.state.clone();
  8661. const res = f();
  8662. this.state = state;
  8663. return res;
  8664. }
  8665. tsTryParseAndCatch(f) {
  8666. const result = this.tryParse(abort => f() || abort());
  8667. if (result.aborted || !result.node) return;
  8668. if (result.error) this.state = result.failState;
  8669. return result.node;
  8670. }
  8671. tsTryParse(f) {
  8672. const state = this.state.clone();
  8673. const result = f();
  8674. if (result !== undefined && result !== false) {
  8675. return result;
  8676. }
  8677. this.state = state;
  8678. }
  8679. tsTryParseDeclare(nany) {
  8680. if (this.isLineTerminator()) {
  8681. return;
  8682. }
  8683. let startType = this.state.type;
  8684. let kind;
  8685. if (this.isContextual(100)) {
  8686. startType = 74;
  8687. kind = "let";
  8688. }
  8689. return this.tsInAmbientContext(() => {
  8690. switch (startType) {
  8691. case 68:
  8692. nany.declare = true;
  8693. return super.parseFunctionStatement(nany, false, false);
  8694. case 80:
  8695. nany.declare = true;
  8696. return this.parseClass(nany, true, false);
  8697. case 126:
  8698. return this.tsParseEnumDeclaration(nany, {
  8699. declare: true
  8700. });
  8701. case 112:
  8702. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8703. case 75:
  8704. case 74:
  8705. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8706. nany.declare = true;
  8707. return this.parseVarStatement(nany, kind || this.state.value, true);
  8708. }
  8709. this.expect(75);
  8710. return this.tsParseEnumDeclaration(nany, {
  8711. const: true,
  8712. declare: true
  8713. });
  8714. case 129:
  8715. {
  8716. const result = this.tsParseInterfaceDeclaration(nany, {
  8717. declare: true
  8718. });
  8719. if (result) return result;
  8720. }
  8721. default:
  8722. if (tokenIsIdentifier(startType)) {
  8723. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8724. }
  8725. }
  8726. });
  8727. }
  8728. tsTryParseExportDeclaration() {
  8729. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  8730. }
  8731. tsParseExpressionStatement(node, expr, decorators) {
  8732. switch (expr.name) {
  8733. case "declare":
  8734. {
  8735. const declaration = this.tsTryParseDeclare(node);
  8736. if (declaration) {
  8737. declaration.declare = true;
  8738. }
  8739. return declaration;
  8740. }
  8741. case "global":
  8742. if (this.match(5)) {
  8743. this.scope.enter(256);
  8744. this.prodParam.enter(0);
  8745. const mod = node;
  8746. mod.kind = "global";
  8747. mod.global = true;
  8748. mod.id = expr;
  8749. mod.body = this.tsParseModuleBlock();
  8750. this.scope.exit();
  8751. this.prodParam.exit();
  8752. return this.finishNode(mod, "TSModuleDeclaration");
  8753. }
  8754. break;
  8755. default:
  8756. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8757. }
  8758. }
  8759. tsParseDeclaration(node, value, next, decorators) {
  8760. switch (value) {
  8761. case "abstract":
  8762. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8763. return this.tsParseAbstractDeclaration(node, decorators);
  8764. }
  8765. break;
  8766. case "module":
  8767. if (this.tsCheckLineTerminator(next)) {
  8768. if (this.match(133)) {
  8769. return this.tsParseAmbientExternalModuleDeclaration(node);
  8770. } else if (tokenIsIdentifier(this.state.type)) {
  8771. node.kind = "module";
  8772. return this.tsParseModuleOrNamespaceDeclaration(node);
  8773. }
  8774. }
  8775. break;
  8776. case "namespace":
  8777. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8778. node.kind = "namespace";
  8779. return this.tsParseModuleOrNamespaceDeclaration(node);
  8780. }
  8781. break;
  8782. case "type":
  8783. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8784. return this.tsParseTypeAliasDeclaration(node);
  8785. }
  8786. break;
  8787. }
  8788. }
  8789. tsCheckLineTerminator(next) {
  8790. if (next) {
  8791. if (this.hasFollowingLineBreak()) return false;
  8792. this.next();
  8793. return true;
  8794. }
  8795. return !this.isLineTerminator();
  8796. }
  8797. tsTryParseGenericAsyncArrowFunction(startLoc) {
  8798. if (!this.match(47)) return;
  8799. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8800. this.state.maybeInArrowParameters = true;
  8801. const res = this.tsTryParseAndCatch(() => {
  8802. const node = this.startNodeAt(startLoc);
  8803. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  8804. super.parseFunctionParams(node);
  8805. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  8806. this.expect(19);
  8807. return node;
  8808. });
  8809. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  8810. if (!res) return;
  8811. return super.parseArrowExpression(res, null, true);
  8812. }
  8813. tsParseTypeArgumentsInExpression() {
  8814. if (this.reScan_lt() !== 47) return;
  8815. return this.tsParseTypeArguments();
  8816. }
  8817. tsParseTypeArguments() {
  8818. const node = this.startNode();
  8819. node.params = this.tsInType(() => this.tsInNoContext(() => {
  8820. this.expect(47);
  8821. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  8822. }));
  8823. if (node.params.length === 0) {
  8824. this.raise(TSErrors.EmptyTypeArguments, node);
  8825. } else if (!this.state.inType && this.curContext() === types.brace) {
  8826. this.reScan_lt_gt();
  8827. }
  8828. this.expect(48);
  8829. return this.finishNode(node, "TSTypeParameterInstantiation");
  8830. }
  8831. tsIsDeclarationStart() {
  8832. return tokenIsTSDeclarationStart(this.state.type);
  8833. }
  8834. isExportDefaultSpecifier() {
  8835. if (this.tsIsDeclarationStart()) return false;
  8836. return super.isExportDefaultSpecifier();
  8837. }
  8838. parseAssignableListItem(flags, decorators) {
  8839. const startLoc = this.state.startLoc;
  8840. const modified = {};
  8841. this.tsParseModifiers({
  8842. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  8843. }, modified);
  8844. const accessibility = modified.accessibility;
  8845. const override = modified.override;
  8846. const readonly = modified.readonly;
  8847. if (!(flags & 4) && (accessibility || readonly || override)) {
  8848. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  8849. }
  8850. const left = this.parseMaybeDefault();
  8851. if (flags & 2) {
  8852. this.parseFunctionParamType(left);
  8853. }
  8854. const elt = this.parseMaybeDefault(left.loc.start, left);
  8855. if (accessibility || readonly || override) {
  8856. const pp = this.startNodeAt(startLoc);
  8857. if (decorators.length) {
  8858. pp.decorators = decorators;
  8859. }
  8860. if (accessibility) pp.accessibility = accessibility;
  8861. if (readonly) pp.readonly = readonly;
  8862. if (override) pp.override = override;
  8863. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  8864. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  8865. }
  8866. pp.parameter = elt;
  8867. return this.finishNode(pp, "TSParameterProperty");
  8868. }
  8869. if (decorators.length) {
  8870. left.decorators = decorators;
  8871. }
  8872. return elt;
  8873. }
  8874. isSimpleParameter(node) {
  8875. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  8876. }
  8877. tsDisallowOptionalPattern(node) {
  8878. for (const param of node.params) {
  8879. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  8880. this.raise(TSErrors.PatternIsOptional, param);
  8881. }
  8882. }
  8883. }
  8884. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  8885. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  8886. this.tsDisallowOptionalPattern(node);
  8887. }
  8888. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  8889. if (this.match(14)) {
  8890. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  8891. }
  8892. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  8893. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  8894. return this.finishNode(node, bodilessType);
  8895. }
  8896. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  8897. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  8898. if (node.declare) {
  8899. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  8900. }
  8901. }
  8902. this.tsDisallowOptionalPattern(node);
  8903. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  8904. }
  8905. registerFunctionStatementId(node) {
  8906. if (!node.body && node.id) {
  8907. this.checkIdentifier(node.id, 1024);
  8908. } else {
  8909. super.registerFunctionStatementId(node);
  8910. }
  8911. }
  8912. tsCheckForInvalidTypeCasts(items) {
  8913. items.forEach(node => {
  8914. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  8915. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  8916. }
  8917. });
  8918. }
  8919. toReferencedList(exprList, isInParens) {
  8920. this.tsCheckForInvalidTypeCasts(exprList);
  8921. return exprList;
  8922. }
  8923. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  8924. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  8925. if (node.type === "ArrayExpression") {
  8926. this.tsCheckForInvalidTypeCasts(node.elements);
  8927. }
  8928. return node;
  8929. }
  8930. parseSubscript(base, startLoc, noCalls, state) {
  8931. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  8932. this.state.canStartJSXElement = false;
  8933. this.next();
  8934. const nonNullExpression = this.startNodeAt(startLoc);
  8935. nonNullExpression.expression = base;
  8936. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  8937. }
  8938. let isOptionalCall = false;
  8939. if (this.match(18) && this.lookaheadCharCode() === 60) {
  8940. if (noCalls) {
  8941. state.stop = true;
  8942. return base;
  8943. }
  8944. state.optionalChainMember = isOptionalCall = true;
  8945. this.next();
  8946. }
  8947. if (this.match(47) || this.match(51)) {
  8948. let missingParenErrorLoc;
  8949. const result = this.tsTryParseAndCatch(() => {
  8950. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  8951. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  8952. if (asyncArrowFn) {
  8953. return asyncArrowFn;
  8954. }
  8955. }
  8956. const typeArguments = this.tsParseTypeArgumentsInExpression();
  8957. if (!typeArguments) return;
  8958. if (isOptionalCall && !this.match(10)) {
  8959. missingParenErrorLoc = this.state.curPosition();
  8960. return;
  8961. }
  8962. if (tokenIsTemplate(this.state.type)) {
  8963. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  8964. result.typeParameters = typeArguments;
  8965. return result;
  8966. }
  8967. if (!noCalls && this.eat(10)) {
  8968. const node = this.startNodeAt(startLoc);
  8969. node.callee = base;
  8970. node.arguments = this.parseCallExpressionArguments(11);
  8971. this.tsCheckForInvalidTypeCasts(node.arguments);
  8972. node.typeParameters = typeArguments;
  8973. if (state.optionalChainMember) {
  8974. node.optional = isOptionalCall;
  8975. }
  8976. return this.finishCallExpression(node, state.optionalChainMember);
  8977. }
  8978. const tokenType = this.state.type;
  8979. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  8980. return;
  8981. }
  8982. const node = this.startNodeAt(startLoc);
  8983. node.expression = base;
  8984. node.typeParameters = typeArguments;
  8985. return this.finishNode(node, "TSInstantiationExpression");
  8986. });
  8987. if (missingParenErrorLoc) {
  8988. this.unexpected(missingParenErrorLoc, 10);
  8989. }
  8990. if (result) {
  8991. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  8992. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  8993. }
  8994. return result;
  8995. }
  8996. }
  8997. return super.parseSubscript(base, startLoc, noCalls, state);
  8998. }
  8999. parseNewCallee(node) {
  9000. var _callee$extra;
  9001. super.parseNewCallee(node);
  9002. const {
  9003. callee
  9004. } = node;
  9005. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9006. node.typeParameters = callee.typeParameters;
  9007. node.callee = callee.expression;
  9008. }
  9009. }
  9010. parseExprOp(left, leftStartLoc, minPrec) {
  9011. let isSatisfies;
  9012. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9013. const node = this.startNodeAt(leftStartLoc);
  9014. node.expression = left;
  9015. node.typeAnnotation = this.tsInType(() => {
  9016. this.next();
  9017. if (this.match(75)) {
  9018. if (isSatisfies) {
  9019. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9020. keyword: "const"
  9021. });
  9022. }
  9023. return this.tsParseTypeReference();
  9024. }
  9025. return this.tsParseType();
  9026. });
  9027. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9028. this.reScan_lt_gt();
  9029. return this.parseExprOp(node, leftStartLoc, minPrec);
  9030. }
  9031. return super.parseExprOp(left, leftStartLoc, minPrec);
  9032. }
  9033. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9034. if (!this.state.isAmbientContext) {
  9035. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9036. }
  9037. }
  9038. checkImportReflection(node) {
  9039. super.checkImportReflection(node);
  9040. if (node.module && node.importKind !== "value") {
  9041. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9042. }
  9043. }
  9044. checkDuplicateExports() {}
  9045. isPotentialImportPhase(isExport) {
  9046. if (super.isPotentialImportPhase(isExport)) return true;
  9047. if (this.isContextual(130)) {
  9048. const ch = this.lookaheadCharCode();
  9049. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9050. }
  9051. return !isExport && this.isContextual(87);
  9052. }
  9053. applyImportPhase(node, isExport, phase, loc) {
  9054. super.applyImportPhase(node, isExport, phase, loc);
  9055. if (isExport) {
  9056. node.exportKind = phase === "type" ? "type" : "value";
  9057. } else {
  9058. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9059. }
  9060. }
  9061. parseImport(node) {
  9062. if (this.match(133)) {
  9063. node.importKind = "value";
  9064. return super.parseImport(node);
  9065. }
  9066. let importNode;
  9067. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9068. node.importKind = "value";
  9069. return this.tsParseImportEqualsDeclaration(node);
  9070. } else if (this.isContextual(130)) {
  9071. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9072. if (this.lookaheadCharCode() === 61) {
  9073. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9074. } else {
  9075. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9076. }
  9077. } else {
  9078. importNode = super.parseImport(node);
  9079. }
  9080. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9081. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9082. }
  9083. return importNode;
  9084. }
  9085. parseExport(node, decorators) {
  9086. if (this.match(83)) {
  9087. this.next();
  9088. const nodeImportEquals = node;
  9089. let maybeDefaultIdentifier = null;
  9090. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9091. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9092. } else {
  9093. nodeImportEquals.importKind = "value";
  9094. }
  9095. return this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9096. } else if (this.eat(29)) {
  9097. const assign = node;
  9098. assign.expression = super.parseExpression();
  9099. this.semicolon();
  9100. this.sawUnambiguousESM = true;
  9101. return this.finishNode(assign, "TSExportAssignment");
  9102. } else if (this.eatContextual(93)) {
  9103. const decl = node;
  9104. this.expectContextual(128);
  9105. decl.id = this.parseIdentifier();
  9106. this.semicolon();
  9107. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9108. } else {
  9109. return super.parseExport(node, decorators);
  9110. }
  9111. }
  9112. isAbstractClass() {
  9113. return this.isContextual(124) && this.lookahead().type === 80;
  9114. }
  9115. parseExportDefaultExpression() {
  9116. if (this.isAbstractClass()) {
  9117. const cls = this.startNode();
  9118. this.next();
  9119. cls.abstract = true;
  9120. return this.parseClass(cls, true, true);
  9121. }
  9122. if (this.match(129)) {
  9123. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9124. if (result) return result;
  9125. }
  9126. return super.parseExportDefaultExpression();
  9127. }
  9128. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9129. const {
  9130. isAmbientContext
  9131. } = this.state;
  9132. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9133. if (!isAmbientContext) return declaration;
  9134. for (const {
  9135. id,
  9136. init
  9137. } of declaration.declarations) {
  9138. if (!init) continue;
  9139. if (kind !== "const" || !!id.typeAnnotation) {
  9140. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9141. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9142. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9143. }
  9144. }
  9145. return declaration;
  9146. }
  9147. parseStatementContent(flags, decorators) {
  9148. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9149. const node = this.startNode();
  9150. this.expect(75);
  9151. return this.tsParseEnumDeclaration(node, {
  9152. const: true
  9153. });
  9154. }
  9155. if (this.isContextual(126)) {
  9156. return this.tsParseEnumDeclaration(this.startNode());
  9157. }
  9158. if (this.isContextual(129)) {
  9159. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9160. if (result) return result;
  9161. }
  9162. return super.parseStatementContent(flags, decorators);
  9163. }
  9164. parseAccessModifier() {
  9165. return this.tsParseModifier(["public", "protected", "private"]);
  9166. }
  9167. tsHasSomeModifiers(member, modifiers) {
  9168. return modifiers.some(modifier => {
  9169. if (tsIsAccessModifier(modifier)) {
  9170. return member.accessibility === modifier;
  9171. }
  9172. return !!member[modifier];
  9173. });
  9174. }
  9175. tsIsStartOfStaticBlocks() {
  9176. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9177. }
  9178. parseClassMember(classBody, member, state) {
  9179. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9180. this.tsParseModifiers({
  9181. allowedModifiers: modifiers,
  9182. disallowedModifiers: ["in", "out"],
  9183. stopOnStartOfClassStaticBlock: true,
  9184. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9185. }, member);
  9186. const callParseClassMemberWithIsStatic = () => {
  9187. if (this.tsIsStartOfStaticBlocks()) {
  9188. this.next();
  9189. this.next();
  9190. if (this.tsHasSomeModifiers(member, modifiers)) {
  9191. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9192. }
  9193. super.parseClassStaticBlock(classBody, member);
  9194. } else {
  9195. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9196. }
  9197. };
  9198. if (member.declare) {
  9199. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9200. } else {
  9201. callParseClassMemberWithIsStatic();
  9202. }
  9203. }
  9204. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9205. const idx = this.tsTryParseIndexSignature(member);
  9206. if (idx) {
  9207. classBody.body.push(idx);
  9208. if (member.abstract) {
  9209. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9210. }
  9211. if (member.accessibility) {
  9212. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9213. modifier: member.accessibility
  9214. });
  9215. }
  9216. if (member.declare) {
  9217. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9218. }
  9219. if (member.override) {
  9220. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9221. }
  9222. return;
  9223. }
  9224. if (!this.state.inAbstractClass && member.abstract) {
  9225. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9226. }
  9227. if (member.override) {
  9228. if (!state.hadSuperClass) {
  9229. this.raise(TSErrors.OverrideNotInSubClass, member);
  9230. }
  9231. }
  9232. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9233. }
  9234. parsePostMemberNameModifiers(methodOrProp) {
  9235. const optional = this.eat(17);
  9236. if (optional) methodOrProp.optional = true;
  9237. if (methodOrProp.readonly && this.match(10)) {
  9238. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9239. }
  9240. if (methodOrProp.declare && this.match(10)) {
  9241. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9242. }
  9243. }
  9244. parseExpressionStatement(node, expr, decorators) {
  9245. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9246. return decl || super.parseExpressionStatement(node, expr, decorators);
  9247. }
  9248. shouldParseExportDeclaration() {
  9249. if (this.tsIsDeclarationStart()) return true;
  9250. return super.shouldParseExportDeclaration();
  9251. }
  9252. parseConditional(expr, startLoc, refExpressionErrors) {
  9253. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9254. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9255. }
  9256. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9257. if (!result.node) {
  9258. if (result.error) {
  9259. super.setOptionalParametersError(refExpressionErrors, result.error);
  9260. }
  9261. return expr;
  9262. }
  9263. if (result.error) this.state = result.failState;
  9264. return result.node;
  9265. }
  9266. parseParenItem(node, startLoc) {
  9267. const newNode = super.parseParenItem(node, startLoc);
  9268. if (this.eat(17)) {
  9269. newNode.optional = true;
  9270. this.resetEndLocation(node);
  9271. }
  9272. if (this.match(14)) {
  9273. const typeCastNode = this.startNodeAt(startLoc);
  9274. typeCastNode.expression = node;
  9275. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9276. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9277. }
  9278. return node;
  9279. }
  9280. parseExportDeclaration(node) {
  9281. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9282. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9283. }
  9284. const startLoc = this.state.startLoc;
  9285. const isDeclare = this.eatContextual(125);
  9286. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9287. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9288. }
  9289. const isIdentifier = tokenIsIdentifier(this.state.type);
  9290. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9291. if (!declaration) return null;
  9292. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9293. node.exportKind = "type";
  9294. }
  9295. if (isDeclare) {
  9296. this.resetStartLocation(declaration, startLoc);
  9297. declaration.declare = true;
  9298. }
  9299. return declaration;
  9300. }
  9301. parseClassId(node, isStatement, optionalId, bindingType) {
  9302. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9303. return;
  9304. }
  9305. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9306. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9307. if (typeParameters) node.typeParameters = typeParameters;
  9308. }
  9309. parseClassPropertyAnnotation(node) {
  9310. if (!node.optional) {
  9311. if (this.eat(35)) {
  9312. node.definite = true;
  9313. } else if (this.eat(17)) {
  9314. node.optional = true;
  9315. }
  9316. }
  9317. const type = this.tsTryParseTypeAnnotation();
  9318. if (type) node.typeAnnotation = type;
  9319. }
  9320. parseClassProperty(node) {
  9321. this.parseClassPropertyAnnotation(node);
  9322. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9323. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9324. }
  9325. if (node.abstract && this.match(29)) {
  9326. const {
  9327. key
  9328. } = node;
  9329. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9330. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9331. });
  9332. }
  9333. return super.parseClassProperty(node);
  9334. }
  9335. parseClassPrivateProperty(node) {
  9336. if (node.abstract) {
  9337. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9338. }
  9339. if (node.accessibility) {
  9340. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9341. modifier: node.accessibility
  9342. });
  9343. }
  9344. this.parseClassPropertyAnnotation(node);
  9345. return super.parseClassPrivateProperty(node);
  9346. }
  9347. parseClassAccessorProperty(node) {
  9348. this.parseClassPropertyAnnotation(node);
  9349. if (node.optional) {
  9350. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9351. }
  9352. return super.parseClassAccessorProperty(node);
  9353. }
  9354. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9355. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9356. if (typeParameters && isConstructor) {
  9357. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9358. }
  9359. const {
  9360. declare = false,
  9361. kind
  9362. } = method;
  9363. if (declare && (kind === "get" || kind === "set")) {
  9364. this.raise(TSErrors.DeclareAccessor, method, {
  9365. kind
  9366. });
  9367. }
  9368. if (typeParameters) method.typeParameters = typeParameters;
  9369. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9370. }
  9371. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9372. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9373. if (typeParameters) method.typeParameters = typeParameters;
  9374. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9375. }
  9376. declareClassPrivateMethodInScope(node, kind) {
  9377. if (node.type === "TSDeclareMethod") return;
  9378. if (node.type === "MethodDefinition" && !hasOwnProperty.call(node.value, "body")) {
  9379. return;
  9380. }
  9381. super.declareClassPrivateMethodInScope(node, kind);
  9382. }
  9383. parseClassSuper(node) {
  9384. super.parseClassSuper(node);
  9385. if (node.superClass && (this.match(47) || this.match(51))) {
  9386. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9387. }
  9388. if (this.eatContextual(113)) {
  9389. node.implements = this.tsParseHeritageClause("implements");
  9390. }
  9391. }
  9392. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9393. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9394. if (typeParameters) prop.typeParameters = typeParameters;
  9395. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9396. }
  9397. parseFunctionParams(node, isConstructor) {
  9398. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9399. if (typeParameters) node.typeParameters = typeParameters;
  9400. super.parseFunctionParams(node, isConstructor);
  9401. }
  9402. parseVarId(decl, kind) {
  9403. super.parseVarId(decl, kind);
  9404. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9405. decl.definite = true;
  9406. }
  9407. const type = this.tsTryParseTypeAnnotation();
  9408. if (type) {
  9409. decl.id.typeAnnotation = type;
  9410. this.resetEndLocation(decl.id);
  9411. }
  9412. }
  9413. parseAsyncArrowFromCallExpression(node, call) {
  9414. if (this.match(14)) {
  9415. node.returnType = this.tsParseTypeAnnotation();
  9416. }
  9417. return super.parseAsyncArrowFromCallExpression(node, call);
  9418. }
  9419. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9420. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9421. let state;
  9422. let jsx;
  9423. let typeCast;
  9424. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  9425. state = this.state.clone();
  9426. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9427. if (!jsx.error) return jsx.node;
  9428. const {
  9429. context
  9430. } = this.state;
  9431. const currentContext = context[context.length - 1];
  9432. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9433. context.pop();
  9434. }
  9435. }
  9436. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9437. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9438. }
  9439. if (!state || state === this.state) state = this.state.clone();
  9440. let typeParameters;
  9441. const arrow = this.tryParse(abort => {
  9442. var _expr$extra, _typeParameters;
  9443. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9444. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9445. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9446. abort();
  9447. }
  9448. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9449. this.resetStartLocationFromNode(expr, typeParameters);
  9450. }
  9451. expr.typeParameters = typeParameters;
  9452. return expr;
  9453. }, state);
  9454. if (!arrow.error && !arrow.aborted) {
  9455. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9456. return arrow.node;
  9457. }
  9458. if (!jsx) {
  9459. assert(!this.hasPlugin("jsx"));
  9460. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9461. if (!typeCast.error) return typeCast.node;
  9462. }
  9463. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9464. this.state = jsx.failState;
  9465. return jsx.node;
  9466. }
  9467. if (arrow.node) {
  9468. this.state = arrow.failState;
  9469. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9470. return arrow.node;
  9471. }
  9472. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9473. this.state = typeCast.failState;
  9474. return typeCast.node;
  9475. }
  9476. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9477. }
  9478. reportReservedArrowTypeParam(node) {
  9479. var _node$extra;
  9480. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9481. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9482. }
  9483. }
  9484. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9485. if (!this.hasPlugin("jsx") && this.match(47)) {
  9486. return this.tsParseTypeAssertion();
  9487. }
  9488. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9489. }
  9490. parseArrow(node) {
  9491. if (this.match(14)) {
  9492. const result = this.tryParse(abort => {
  9493. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9494. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9495. return returnType;
  9496. });
  9497. if (result.aborted) return;
  9498. if (!result.thrown) {
  9499. if (result.error) this.state = result.failState;
  9500. node.returnType = result.node;
  9501. }
  9502. }
  9503. return super.parseArrow(node);
  9504. }
  9505. parseFunctionParamType(param) {
  9506. if (this.eat(17)) {
  9507. param.optional = true;
  9508. }
  9509. const type = this.tsTryParseTypeAnnotation();
  9510. if (type) param.typeAnnotation = type;
  9511. this.resetEndLocation(param);
  9512. return param;
  9513. }
  9514. isAssignable(node, isBinding) {
  9515. switch (node.type) {
  9516. case "TSTypeCastExpression":
  9517. return this.isAssignable(node.expression, isBinding);
  9518. case "TSParameterProperty":
  9519. return true;
  9520. default:
  9521. return super.isAssignable(node, isBinding);
  9522. }
  9523. }
  9524. toAssignable(node, isLHS = false) {
  9525. switch (node.type) {
  9526. case "ParenthesizedExpression":
  9527. this.toAssignableParenthesizedExpression(node, isLHS);
  9528. break;
  9529. case "TSAsExpression":
  9530. case "TSSatisfiesExpression":
  9531. case "TSNonNullExpression":
  9532. case "TSTypeAssertion":
  9533. if (isLHS) {
  9534. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9535. } else {
  9536. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9537. }
  9538. this.toAssignable(node.expression, isLHS);
  9539. break;
  9540. case "AssignmentExpression":
  9541. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9542. node.left = this.typeCastToParameter(node.left);
  9543. }
  9544. default:
  9545. super.toAssignable(node, isLHS);
  9546. }
  9547. }
  9548. toAssignableParenthesizedExpression(node, isLHS) {
  9549. switch (node.expression.type) {
  9550. case "TSAsExpression":
  9551. case "TSSatisfiesExpression":
  9552. case "TSNonNullExpression":
  9553. case "TSTypeAssertion":
  9554. case "ParenthesizedExpression":
  9555. this.toAssignable(node.expression, isLHS);
  9556. break;
  9557. default:
  9558. super.toAssignable(node, isLHS);
  9559. }
  9560. }
  9561. checkToRestConversion(node, allowPattern) {
  9562. switch (node.type) {
  9563. case "TSAsExpression":
  9564. case "TSSatisfiesExpression":
  9565. case "TSTypeAssertion":
  9566. case "TSNonNullExpression":
  9567. this.checkToRestConversion(node.expression, false);
  9568. break;
  9569. default:
  9570. super.checkToRestConversion(node, allowPattern);
  9571. }
  9572. }
  9573. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9574. switch (type) {
  9575. case "TSTypeCastExpression":
  9576. return true;
  9577. case "TSParameterProperty":
  9578. return "parameter";
  9579. case "TSNonNullExpression":
  9580. case "TSInstantiationExpression":
  9581. return "expression";
  9582. case "TSAsExpression":
  9583. case "TSSatisfiesExpression":
  9584. case "TSTypeAssertion":
  9585. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  9586. default:
  9587. return super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9588. }
  9589. }
  9590. parseBindingAtom() {
  9591. if (this.state.type === 78) {
  9592. return this.parseIdentifier(true);
  9593. }
  9594. return super.parseBindingAtom();
  9595. }
  9596. parseMaybeDecoratorArguments(expr) {
  9597. if (this.match(47) || this.match(51)) {
  9598. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9599. if (this.match(10)) {
  9600. const call = super.parseMaybeDecoratorArguments(expr);
  9601. call.typeParameters = typeArguments;
  9602. return call;
  9603. }
  9604. this.unexpected(null, 10);
  9605. }
  9606. return super.parseMaybeDecoratorArguments(expr);
  9607. }
  9608. checkCommaAfterRest(close) {
  9609. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9610. this.next();
  9611. return false;
  9612. }
  9613. return super.checkCommaAfterRest(close);
  9614. }
  9615. isClassMethod() {
  9616. return this.match(47) || super.isClassMethod();
  9617. }
  9618. isClassProperty() {
  9619. return this.match(35) || this.match(14) || super.isClassProperty();
  9620. }
  9621. parseMaybeDefault(startLoc, left) {
  9622. const node = super.parseMaybeDefault(startLoc, left);
  9623. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9624. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  9625. }
  9626. return node;
  9627. }
  9628. getTokenFromCode(code) {
  9629. if (this.state.inType) {
  9630. if (code === 62) {
  9631. this.finishOp(48, 1);
  9632. return;
  9633. }
  9634. if (code === 60) {
  9635. this.finishOp(47, 1);
  9636. return;
  9637. }
  9638. }
  9639. super.getTokenFromCode(code);
  9640. }
  9641. reScan_lt_gt() {
  9642. const {
  9643. type
  9644. } = this.state;
  9645. if (type === 47) {
  9646. this.state.pos -= 1;
  9647. this.readToken_lt();
  9648. } else if (type === 48) {
  9649. this.state.pos -= 1;
  9650. this.readToken_gt();
  9651. }
  9652. }
  9653. reScan_lt() {
  9654. const {
  9655. type
  9656. } = this.state;
  9657. if (type === 51) {
  9658. this.state.pos -= 2;
  9659. this.finishOp(47, 1);
  9660. return 47;
  9661. }
  9662. return type;
  9663. }
  9664. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9665. for (let i = 0; i < exprList.length; i++) {
  9666. const expr = exprList[i];
  9667. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9668. exprList[i] = this.typeCastToParameter(expr);
  9669. }
  9670. }
  9671. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9672. }
  9673. typeCastToParameter(node) {
  9674. node.expression.typeAnnotation = node.typeAnnotation;
  9675. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9676. return node.expression;
  9677. }
  9678. shouldParseArrow(params) {
  9679. if (this.match(14)) {
  9680. return params.every(expr => this.isAssignable(expr, true));
  9681. }
  9682. return super.shouldParseArrow(params);
  9683. }
  9684. shouldParseAsyncArrow() {
  9685. return this.match(14) || super.shouldParseAsyncArrow();
  9686. }
  9687. canHaveLeadingDecorator() {
  9688. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9689. }
  9690. jsxParseOpeningElementAfterName(node) {
  9691. if (this.match(47) || this.match(51)) {
  9692. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9693. if (typeArguments) node.typeParameters = typeArguments;
  9694. }
  9695. return super.jsxParseOpeningElementAfterName(node);
  9696. }
  9697. getGetterSetterExpectedParamCount(method) {
  9698. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9699. const params = this.getObjectOrClassMethodParams(method);
  9700. const firstParam = params[0];
  9701. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9702. return hasContextParam ? baseCount + 1 : baseCount;
  9703. }
  9704. parseCatchClauseParam() {
  9705. const param = super.parseCatchClauseParam();
  9706. const type = this.tsTryParseTypeAnnotation();
  9707. if (type) {
  9708. param.typeAnnotation = type;
  9709. this.resetEndLocation(param);
  9710. }
  9711. return param;
  9712. }
  9713. tsInAmbientContext(cb) {
  9714. const {
  9715. isAmbientContext: oldIsAmbientContext,
  9716. strict: oldStrict
  9717. } = this.state;
  9718. this.state.isAmbientContext = true;
  9719. this.state.strict = false;
  9720. try {
  9721. return cb();
  9722. } finally {
  9723. this.state.isAmbientContext = oldIsAmbientContext;
  9724. this.state.strict = oldStrict;
  9725. }
  9726. }
  9727. parseClass(node, isStatement, optionalId) {
  9728. const oldInAbstractClass = this.state.inAbstractClass;
  9729. this.state.inAbstractClass = !!node.abstract;
  9730. try {
  9731. return super.parseClass(node, isStatement, optionalId);
  9732. } finally {
  9733. this.state.inAbstractClass = oldInAbstractClass;
  9734. }
  9735. }
  9736. tsParseAbstractDeclaration(node, decorators) {
  9737. if (this.match(80)) {
  9738. node.abstract = true;
  9739. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  9740. } else if (this.isContextual(129)) {
  9741. if (!this.hasFollowingLineBreak()) {
  9742. node.abstract = true;
  9743. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, node);
  9744. return this.tsParseInterfaceDeclaration(node);
  9745. }
  9746. } else {
  9747. this.unexpected(null, 80);
  9748. }
  9749. }
  9750. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  9751. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  9752. if (method.abstract) {
  9753. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  9754. if (hasBody) {
  9755. const {
  9756. key
  9757. } = method;
  9758. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  9759. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9760. });
  9761. }
  9762. }
  9763. return method;
  9764. }
  9765. tsParseTypeParameterName() {
  9766. const typeName = this.parseIdentifier();
  9767. return typeName.name;
  9768. }
  9769. shouldParseAsAmbientContext() {
  9770. return !!this.getPluginOption("typescript", "dts");
  9771. }
  9772. parse() {
  9773. if (this.shouldParseAsAmbientContext()) {
  9774. this.state.isAmbientContext = true;
  9775. }
  9776. return super.parse();
  9777. }
  9778. getExpression() {
  9779. if (this.shouldParseAsAmbientContext()) {
  9780. this.state.isAmbientContext = true;
  9781. }
  9782. return super.getExpression();
  9783. }
  9784. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  9785. if (!isString && isMaybeTypeOnly) {
  9786. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  9787. return this.finishNode(node, "ExportSpecifier");
  9788. }
  9789. node.exportKind = "value";
  9790. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  9791. }
  9792. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  9793. if (!importedIsString && isMaybeTypeOnly) {
  9794. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  9795. return this.finishNode(specifier, "ImportSpecifier");
  9796. }
  9797. specifier.importKind = "value";
  9798. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  9799. }
  9800. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  9801. const leftOfAsKey = isImport ? "imported" : "local";
  9802. const rightOfAsKey = isImport ? "local" : "exported";
  9803. let leftOfAs = node[leftOfAsKey];
  9804. let rightOfAs;
  9805. let hasTypeSpecifier = false;
  9806. let canParseAsKeyword = true;
  9807. const loc = leftOfAs.loc.start;
  9808. if (this.isContextual(93)) {
  9809. const firstAs = this.parseIdentifier();
  9810. if (this.isContextual(93)) {
  9811. const secondAs = this.parseIdentifier();
  9812. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9813. hasTypeSpecifier = true;
  9814. leftOfAs = firstAs;
  9815. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9816. canParseAsKeyword = false;
  9817. } else {
  9818. rightOfAs = secondAs;
  9819. canParseAsKeyword = false;
  9820. }
  9821. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9822. canParseAsKeyword = false;
  9823. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9824. } else {
  9825. hasTypeSpecifier = true;
  9826. leftOfAs = firstAs;
  9827. }
  9828. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9829. hasTypeSpecifier = true;
  9830. if (isImport) {
  9831. leftOfAs = this.parseIdentifier(true);
  9832. if (!this.isContextual(93)) {
  9833. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  9834. }
  9835. } else {
  9836. leftOfAs = this.parseModuleExportName();
  9837. }
  9838. }
  9839. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  9840. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  9841. }
  9842. node[leftOfAsKey] = leftOfAs;
  9843. node[rightOfAsKey] = rightOfAs;
  9844. const kindKey = isImport ? "importKind" : "exportKind";
  9845. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  9846. if (canParseAsKeyword && this.eatContextual(93)) {
  9847. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9848. }
  9849. if (!node[rightOfAsKey]) {
  9850. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  9851. }
  9852. if (isImport) {
  9853. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  9854. }
  9855. }
  9856. };
  9857. function isPossiblyLiteralEnum(expression) {
  9858. if (expression.type !== "MemberExpression") return false;
  9859. const {
  9860. computed,
  9861. property
  9862. } = expression;
  9863. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  9864. return false;
  9865. }
  9866. return isUncomputedMemberExpressionChain(expression.object);
  9867. }
  9868. function isValidAmbientConstInitializer(expression, estree) {
  9869. var _expression$extra;
  9870. const {
  9871. type
  9872. } = expression;
  9873. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  9874. return false;
  9875. }
  9876. if (estree) {
  9877. if (type === "Literal") {
  9878. const {
  9879. value
  9880. } = expression;
  9881. if (typeof value === "string" || typeof value === "boolean") {
  9882. return true;
  9883. }
  9884. }
  9885. } else {
  9886. if (type === "StringLiteral" || type === "BooleanLiteral") {
  9887. return true;
  9888. }
  9889. }
  9890. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  9891. return true;
  9892. }
  9893. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  9894. return true;
  9895. }
  9896. if (isPossiblyLiteralEnum(expression)) {
  9897. return true;
  9898. }
  9899. return false;
  9900. }
  9901. function isNumber(expression, estree) {
  9902. if (estree) {
  9903. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  9904. }
  9905. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  9906. }
  9907. function isNegativeNumber(expression, estree) {
  9908. if (expression.type === "UnaryExpression") {
  9909. const {
  9910. operator,
  9911. argument
  9912. } = expression;
  9913. if (operator === "-" && isNumber(argument, estree)) {
  9914. return true;
  9915. }
  9916. }
  9917. return false;
  9918. }
  9919. function isUncomputedMemberExpressionChain(expression) {
  9920. if (expression.type === "Identifier") return true;
  9921. if (expression.type !== "MemberExpression" || expression.computed) {
  9922. return false;
  9923. }
  9924. return isUncomputedMemberExpressionChain(expression.object);
  9925. }
  9926. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  9927. ClassNameIsRequired: "A class name is required.",
  9928. UnexpectedSpace: "Unexpected space in placeholder."
  9929. });
  9930. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  9931. parsePlaceholder(expectedNode) {
  9932. if (this.match(144)) {
  9933. const node = this.startNode();
  9934. this.next();
  9935. this.assertNoSpace();
  9936. node.name = super.parseIdentifier(true);
  9937. this.assertNoSpace();
  9938. this.expect(144);
  9939. return this.finishPlaceholder(node, expectedNode);
  9940. }
  9941. }
  9942. finishPlaceholder(node, expectedNode) {
  9943. let placeholder = node;
  9944. if (!placeholder.expectedNode || !placeholder.type) {
  9945. placeholder = this.finishNode(placeholder, "Placeholder");
  9946. }
  9947. placeholder.expectedNode = expectedNode;
  9948. return placeholder;
  9949. }
  9950. getTokenFromCode(code) {
  9951. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  9952. this.finishOp(144, 2);
  9953. } else {
  9954. super.getTokenFromCode(code);
  9955. }
  9956. }
  9957. parseExprAtom(refExpressionErrors) {
  9958. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  9959. }
  9960. parseIdentifier(liberal) {
  9961. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  9962. }
  9963. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9964. if (word !== undefined) {
  9965. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9966. }
  9967. }
  9968. parseBindingAtom() {
  9969. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  9970. }
  9971. isValidLVal(type, isParenthesized, binding) {
  9972. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  9973. }
  9974. toAssignable(node, isLHS) {
  9975. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  9976. node.expectedNode = "Pattern";
  9977. } else {
  9978. super.toAssignable(node, isLHS);
  9979. }
  9980. }
  9981. chStartsBindingIdentifier(ch, pos) {
  9982. if (super.chStartsBindingIdentifier(ch, pos)) {
  9983. return true;
  9984. }
  9985. const nextToken = this.lookahead();
  9986. if (nextToken.type === 144) {
  9987. return true;
  9988. }
  9989. return false;
  9990. }
  9991. verifyBreakContinue(node, isBreak) {
  9992. if (node.label && node.label.type === "Placeholder") return;
  9993. super.verifyBreakContinue(node, isBreak);
  9994. }
  9995. parseExpressionStatement(node, expr) {
  9996. var _expr$extra;
  9997. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9998. return super.parseExpressionStatement(node, expr);
  9999. }
  10000. if (this.match(14)) {
  10001. const stmt = node;
  10002. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10003. this.next();
  10004. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10005. return this.finishNode(stmt, "LabeledStatement");
  10006. }
  10007. this.semicolon();
  10008. const stmtPlaceholder = node;
  10009. stmtPlaceholder.name = expr.name;
  10010. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  10011. }
  10012. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10013. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10014. }
  10015. parseFunctionId(requireId) {
  10016. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10017. }
  10018. parseClass(node, isStatement, optionalId) {
  10019. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10020. this.next();
  10021. const oldStrict = this.state.strict;
  10022. const placeholder = this.parsePlaceholder("Identifier");
  10023. if (placeholder) {
  10024. if (this.match(81) || this.match(144) || this.match(5)) {
  10025. node.id = placeholder;
  10026. } else if (optionalId || !isStatement) {
  10027. node.id = null;
  10028. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10029. return this.finishNode(node, type);
  10030. } else {
  10031. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10032. }
  10033. } else {
  10034. this.parseClassId(node, isStatement, optionalId);
  10035. }
  10036. super.parseClassSuper(node);
  10037. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10038. return this.finishNode(node, type);
  10039. }
  10040. parseExport(node, decorators) {
  10041. const placeholder = this.parsePlaceholder("Identifier");
  10042. if (!placeholder) return super.parseExport(node, decorators);
  10043. const node2 = node;
  10044. if (!this.isContextual(98) && !this.match(12)) {
  10045. node2.specifiers = [];
  10046. node2.source = null;
  10047. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10048. return this.finishNode(node2, "ExportNamedDeclaration");
  10049. }
  10050. this.expectPlugin("exportDefaultFrom");
  10051. const specifier = this.startNode();
  10052. specifier.exported = placeholder;
  10053. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10054. return super.parseExport(node2, decorators);
  10055. }
  10056. isExportDefaultSpecifier() {
  10057. if (this.match(65)) {
  10058. const next = this.nextTokenStart();
  10059. if (this.isUnparsedContextual(next, "from")) {
  10060. if (this.input.startsWith(tokenLabelName(144), this.nextTokenStartSince(next + 4))) {
  10061. return true;
  10062. }
  10063. }
  10064. }
  10065. return super.isExportDefaultSpecifier();
  10066. }
  10067. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10068. var _specifiers;
  10069. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10070. return true;
  10071. }
  10072. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10073. }
  10074. checkExport(node) {
  10075. const {
  10076. specifiers
  10077. } = node;
  10078. if (specifiers != null && specifiers.length) {
  10079. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10080. }
  10081. super.checkExport(node);
  10082. node.specifiers = specifiers;
  10083. }
  10084. parseImport(node) {
  10085. const placeholder = this.parsePlaceholder("Identifier");
  10086. if (!placeholder) return super.parseImport(node);
  10087. node.specifiers = [];
  10088. if (!this.isContextual(98) && !this.match(12)) {
  10089. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10090. this.semicolon();
  10091. return this.finishNode(node, "ImportDeclaration");
  10092. }
  10093. const specifier = this.startNodeAtNode(placeholder);
  10094. specifier.local = placeholder;
  10095. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10096. if (this.eat(12)) {
  10097. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10098. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10099. }
  10100. this.expectContextual(98);
  10101. node.source = this.parseImportSource();
  10102. this.semicolon();
  10103. return this.finishNode(node, "ImportDeclaration");
  10104. }
  10105. parseImportSource() {
  10106. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10107. }
  10108. assertNoSpace() {
  10109. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  10110. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10111. }
  10112. }
  10113. };
  10114. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10115. parseV8Intrinsic() {
  10116. if (this.match(54)) {
  10117. const v8IntrinsicStartLoc = this.state.startLoc;
  10118. const node = this.startNode();
  10119. this.next();
  10120. if (tokenIsIdentifier(this.state.type)) {
  10121. const name = this.parseIdentifierName();
  10122. const identifier = this.createIdentifier(node, name);
  10123. identifier.type = "V8IntrinsicIdentifier";
  10124. if (this.match(10)) {
  10125. return identifier;
  10126. }
  10127. }
  10128. this.unexpected(v8IntrinsicStartLoc);
  10129. }
  10130. }
  10131. parseExprAtom(refExpressionErrors) {
  10132. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10133. }
  10134. };
  10135. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10136. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10137. function validatePlugins(pluginsMap) {
  10138. if (pluginsMap.has("decorators")) {
  10139. if (pluginsMap.has("decorators-legacy")) {
  10140. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10141. }
  10142. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  10143. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10144. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10145. }
  10146. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  10147. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10148. throw new Error("'allowCallParenthesized' must be a boolean.");
  10149. }
  10150. }
  10151. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  10152. throw new Error("Cannot combine flow and typescript plugins.");
  10153. }
  10154. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  10155. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10156. }
  10157. if (pluginsMap.has("pipelineOperator")) {
  10158. var _pluginsMap$get;
  10159. const proposal = pluginsMap.get("pipelineOperator").proposal;
  10160. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10161. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10162. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10163. }
  10164. const tupleSyntaxIsHash = ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash";
  10165. if (proposal === "hack") {
  10166. if (pluginsMap.has("placeholders")) {
  10167. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10168. }
  10169. if (pluginsMap.has("v8intrinsic")) {
  10170. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10171. }
  10172. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  10173. if (!TOPIC_TOKENS.includes(topicToken)) {
  10174. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10175. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10176. }
  10177. if (topicToken === "#" && tupleSyntaxIsHash) {
  10178. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10179. }
  10180. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  10181. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10182. }
  10183. }
  10184. if (pluginsMap.has("moduleAttributes")) {
  10185. {
  10186. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  10187. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  10188. }
  10189. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  10190. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10191. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10192. }
  10193. }
  10194. }
  10195. if (pluginsMap.has("importAssertions")) {
  10196. if (pluginsMap.has("deprecatedImportAssert")) {
  10197. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  10198. }
  10199. }
  10200. if (!pluginsMap.has("deprecatedImportAssert") && pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  10201. {
  10202. pluginsMap.set("deprecatedImportAssert", {});
  10203. }
  10204. }
  10205. if (pluginsMap.has("recordAndTuple")) {
  10206. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  10207. if (syntaxType != null) {
  10208. {
  10209. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10210. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  10211. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10212. }
  10213. }
  10214. }
  10215. }
  10216. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  10217. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10218. error.missingPlugins = "doExpressions";
  10219. throw error;
  10220. }
  10221. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  10222. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10223. }
  10224. }
  10225. const mixinPlugins = {
  10226. estree,
  10227. jsx,
  10228. flow,
  10229. typescript,
  10230. v8intrinsic,
  10231. placeholders
  10232. };
  10233. const mixinPluginNames = Object.keys(mixinPlugins);
  10234. function createDefaultOptions() {
  10235. return {
  10236. sourceType: "script",
  10237. sourceFilename: undefined,
  10238. startIndex: 0,
  10239. startColumn: 0,
  10240. startLine: 1,
  10241. allowAwaitOutsideFunction: false,
  10242. allowReturnOutsideFunction: false,
  10243. allowNewTargetOutsideFunction: false,
  10244. allowImportExportEverywhere: false,
  10245. allowSuperOutsideMethod: false,
  10246. allowUndeclaredExports: false,
  10247. plugins: [],
  10248. strictMode: null,
  10249. ranges: false,
  10250. tokens: false,
  10251. createImportExpressions: false,
  10252. createParenthesizedExpressions: false,
  10253. errorRecovery: false,
  10254. attachComment: true,
  10255. annexB: true
  10256. };
  10257. }
  10258. function getOptions(opts) {
  10259. const options = createDefaultOptions();
  10260. if (opts == null) {
  10261. return options;
  10262. }
  10263. if (opts.annexB != null && opts.annexB !== false) {
  10264. throw new Error("The `annexB` option can only be set to `false`.");
  10265. }
  10266. for (const key of Object.keys(options)) {
  10267. if (opts[key] != null) options[key] = opts[key];
  10268. }
  10269. if (options.startLine === 1) {
  10270. if (opts.startIndex == null && options.startColumn > 0) {
  10271. options.startIndex = options.startColumn;
  10272. } else if (opts.startColumn == null && options.startIndex > 0) {
  10273. options.startColumn = options.startIndex;
  10274. }
  10275. } else if (opts.startColumn == null || opts.startIndex == null) {
  10276. if (opts.startIndex != null) {
  10277. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  10278. }
  10279. }
  10280. return options;
  10281. }
  10282. class ExpressionParser extends LValParser {
  10283. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10284. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10285. return;
  10286. }
  10287. const key = prop.key;
  10288. const name = key.type === "Identifier" ? key.name : key.value;
  10289. if (name === "__proto__") {
  10290. if (isRecord) {
  10291. this.raise(Errors.RecordNoProto, key);
  10292. return;
  10293. }
  10294. if (protoRef.used) {
  10295. if (refExpressionErrors) {
  10296. if (refExpressionErrors.doubleProtoLoc === null) {
  10297. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10298. }
  10299. } else {
  10300. this.raise(Errors.DuplicateProto, key);
  10301. }
  10302. }
  10303. protoRef.used = true;
  10304. }
  10305. }
  10306. shouldExitDescending(expr, potentialArrowAt) {
  10307. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  10308. }
  10309. getExpression() {
  10310. this.enterInitialScopes();
  10311. this.nextToken();
  10312. const expr = this.parseExpression();
  10313. if (!this.match(139)) {
  10314. this.unexpected();
  10315. }
  10316. this.finalizeRemainingComments();
  10317. expr.comments = this.comments;
  10318. expr.errors = this.state.errors;
  10319. if (this.options.tokens) {
  10320. expr.tokens = this.tokens;
  10321. }
  10322. return expr;
  10323. }
  10324. parseExpression(disallowIn, refExpressionErrors) {
  10325. if (disallowIn) {
  10326. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10327. }
  10328. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10329. }
  10330. parseExpressionBase(refExpressionErrors) {
  10331. const startLoc = this.state.startLoc;
  10332. const expr = this.parseMaybeAssign(refExpressionErrors);
  10333. if (this.match(12)) {
  10334. const node = this.startNodeAt(startLoc);
  10335. node.expressions = [expr];
  10336. while (this.eat(12)) {
  10337. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10338. }
  10339. this.toReferencedList(node.expressions);
  10340. return this.finishNode(node, "SequenceExpression");
  10341. }
  10342. return expr;
  10343. }
  10344. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10345. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10346. }
  10347. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10348. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10349. }
  10350. setOptionalParametersError(refExpressionErrors, resultError) {
  10351. var _resultError$loc;
  10352. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10353. }
  10354. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10355. const startLoc = this.state.startLoc;
  10356. if (this.isContextual(108)) {
  10357. if (this.prodParam.hasYield) {
  10358. let left = this.parseYield();
  10359. if (afterLeftParse) {
  10360. left = afterLeftParse.call(this, left, startLoc);
  10361. }
  10362. return left;
  10363. }
  10364. }
  10365. let ownExpressionErrors;
  10366. if (refExpressionErrors) {
  10367. ownExpressionErrors = false;
  10368. } else {
  10369. refExpressionErrors = new ExpressionErrors();
  10370. ownExpressionErrors = true;
  10371. }
  10372. const {
  10373. type
  10374. } = this.state;
  10375. if (type === 10 || tokenIsIdentifier(type)) {
  10376. this.state.potentialArrowAt = this.state.start;
  10377. }
  10378. let left = this.parseMaybeConditional(refExpressionErrors);
  10379. if (afterLeftParse) {
  10380. left = afterLeftParse.call(this, left, startLoc);
  10381. }
  10382. if (tokenIsAssignment(this.state.type)) {
  10383. const node = this.startNodeAt(startLoc);
  10384. const operator = this.state.value;
  10385. node.operator = operator;
  10386. if (this.match(29)) {
  10387. this.toAssignable(left, true);
  10388. node.left = left;
  10389. const startIndex = startLoc.index;
  10390. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10391. refExpressionErrors.doubleProtoLoc = null;
  10392. }
  10393. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10394. refExpressionErrors.shorthandAssignLoc = null;
  10395. }
  10396. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10397. this.checkDestructuringPrivate(refExpressionErrors);
  10398. refExpressionErrors.privateKeyLoc = null;
  10399. }
  10400. } else {
  10401. node.left = left;
  10402. }
  10403. this.next();
  10404. node.right = this.parseMaybeAssign();
  10405. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"));
  10406. return node;
  10407. } else if (ownExpressionErrors) {
  10408. this.checkExpressionErrors(refExpressionErrors, true);
  10409. }
  10410. return left;
  10411. }
  10412. parseMaybeConditional(refExpressionErrors) {
  10413. const startLoc = this.state.startLoc;
  10414. const potentialArrowAt = this.state.potentialArrowAt;
  10415. const expr = this.parseExprOps(refExpressionErrors);
  10416. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10417. return expr;
  10418. }
  10419. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10420. }
  10421. parseConditional(expr, startLoc, refExpressionErrors) {
  10422. if (this.eat(17)) {
  10423. const node = this.startNodeAt(startLoc);
  10424. node.test = expr;
  10425. node.consequent = this.parseMaybeAssignAllowIn();
  10426. this.expect(14);
  10427. node.alternate = this.parseMaybeAssign();
  10428. return this.finishNode(node, "ConditionalExpression");
  10429. }
  10430. return expr;
  10431. }
  10432. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10433. return this.match(138) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10434. }
  10435. parseExprOps(refExpressionErrors) {
  10436. const startLoc = this.state.startLoc;
  10437. const potentialArrowAt = this.state.potentialArrowAt;
  10438. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10439. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10440. return expr;
  10441. }
  10442. return this.parseExprOp(expr, startLoc, -1);
  10443. }
  10444. parseExprOp(left, leftStartLoc, minPrec) {
  10445. if (this.isPrivateName(left)) {
  10446. const value = this.getPrivateNameSV(left);
  10447. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10448. this.raise(Errors.PrivateInExpectedIn, left, {
  10449. identifierName: value
  10450. });
  10451. }
  10452. this.classScope.usePrivateName(value, left.loc.start);
  10453. }
  10454. const op = this.state.type;
  10455. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10456. let prec = tokenOperatorPrecedence(op);
  10457. if (prec > minPrec) {
  10458. if (op === 39) {
  10459. this.expectPlugin("pipelineOperator");
  10460. if (this.state.inFSharpPipelineDirectBody) {
  10461. return left;
  10462. }
  10463. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10464. }
  10465. const node = this.startNodeAt(leftStartLoc);
  10466. node.left = left;
  10467. node.operator = this.state.value;
  10468. const logical = op === 41 || op === 42;
  10469. const coalesce = op === 40;
  10470. if (coalesce) {
  10471. prec = tokenOperatorPrecedence(42);
  10472. }
  10473. this.next();
  10474. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10475. proposal: "minimal"
  10476. }])) {
  10477. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10478. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  10479. }
  10480. }
  10481. node.right = this.parseExprOpRightExpr(op, prec);
  10482. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10483. const nextOp = this.state.type;
  10484. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10485. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  10486. }
  10487. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10488. }
  10489. }
  10490. return left;
  10491. }
  10492. parseExprOpRightExpr(op, prec) {
  10493. const startLoc = this.state.startLoc;
  10494. switch (op) {
  10495. case 39:
  10496. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10497. case "hack":
  10498. return this.withTopicBindingContext(() => {
  10499. return this.parseHackPipeBody();
  10500. });
  10501. case "smart":
  10502. return this.withTopicBindingContext(() => {
  10503. if (this.prodParam.hasYield && this.isContextual(108)) {
  10504. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  10505. }
  10506. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10507. });
  10508. case "fsharp":
  10509. return this.withSoloAwaitPermittingContext(() => {
  10510. return this.parseFSharpPipelineBody(prec);
  10511. });
  10512. }
  10513. default:
  10514. return this.parseExprOpBaseRightExpr(op, prec);
  10515. }
  10516. }
  10517. parseExprOpBaseRightExpr(op, prec) {
  10518. const startLoc = this.state.startLoc;
  10519. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10520. }
  10521. parseHackPipeBody() {
  10522. var _body$extra;
  10523. const {
  10524. startLoc
  10525. } = this.state;
  10526. const body = this.parseMaybeAssign();
  10527. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10528. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10529. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  10530. type: body.type
  10531. });
  10532. }
  10533. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10534. this.raise(Errors.PipeTopicUnused, startLoc);
  10535. }
  10536. return body;
  10537. }
  10538. checkExponentialAfterUnary(node) {
  10539. if (this.match(57)) {
  10540. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  10541. }
  10542. }
  10543. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10544. const startLoc = this.state.startLoc;
  10545. const isAwait = this.isContextual(96);
  10546. if (isAwait && this.recordAwaitIfAllowed()) {
  10547. this.next();
  10548. const expr = this.parseAwait(startLoc);
  10549. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10550. return expr;
  10551. }
  10552. const update = this.match(34);
  10553. const node = this.startNode();
  10554. if (tokenIsPrefix(this.state.type)) {
  10555. node.operator = this.state.value;
  10556. node.prefix = true;
  10557. if (this.match(72)) {
  10558. this.expectPlugin("throwExpressions");
  10559. }
  10560. const isDelete = this.match(89);
  10561. this.next();
  10562. node.argument = this.parseMaybeUnary(null, true);
  10563. this.checkExpressionErrors(refExpressionErrors, true);
  10564. if (this.state.strict && isDelete) {
  10565. const arg = node.argument;
  10566. if (arg.type === "Identifier") {
  10567. this.raise(Errors.StrictDelete, node);
  10568. } else if (this.hasPropertyAsPrivateName(arg)) {
  10569. this.raise(Errors.DeletePrivateField, node);
  10570. }
  10571. }
  10572. if (!update) {
  10573. if (!sawUnary) {
  10574. this.checkExponentialAfterUnary(node);
  10575. }
  10576. return this.finishNode(node, "UnaryExpression");
  10577. }
  10578. }
  10579. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10580. if (isAwait) {
  10581. const {
  10582. type
  10583. } = this.state;
  10584. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10585. if (startsExpr && !this.isAmbiguousAwait()) {
  10586. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  10587. return this.parseAwait(startLoc);
  10588. }
  10589. }
  10590. return expr;
  10591. }
  10592. parseUpdate(node, update, refExpressionErrors) {
  10593. if (update) {
  10594. const updateExpressionNode = node;
  10595. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  10596. return node;
  10597. }
  10598. const startLoc = this.state.startLoc;
  10599. let expr = this.parseExprSubscripts(refExpressionErrors);
  10600. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10601. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10602. const node = this.startNodeAt(startLoc);
  10603. node.operator = this.state.value;
  10604. node.prefix = false;
  10605. node.argument = expr;
  10606. this.next();
  10607. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  10608. }
  10609. return expr;
  10610. }
  10611. parseExprSubscripts(refExpressionErrors) {
  10612. const startLoc = this.state.startLoc;
  10613. const potentialArrowAt = this.state.potentialArrowAt;
  10614. const expr = this.parseExprAtom(refExpressionErrors);
  10615. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10616. return expr;
  10617. }
  10618. return this.parseSubscripts(expr, startLoc);
  10619. }
  10620. parseSubscripts(base, startLoc, noCalls) {
  10621. const state = {
  10622. optionalChainMember: false,
  10623. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10624. stop: false
  10625. };
  10626. do {
  10627. base = this.parseSubscript(base, startLoc, noCalls, state);
  10628. state.maybeAsyncArrow = false;
  10629. } while (!state.stop);
  10630. return base;
  10631. }
  10632. parseSubscript(base, startLoc, noCalls, state) {
  10633. const {
  10634. type
  10635. } = this.state;
  10636. if (!noCalls && type === 15) {
  10637. return this.parseBind(base, startLoc, noCalls, state);
  10638. } else if (tokenIsTemplate(type)) {
  10639. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10640. }
  10641. let optional = false;
  10642. if (type === 18) {
  10643. if (noCalls) {
  10644. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  10645. if (this.lookaheadCharCode() === 40) {
  10646. state.stop = true;
  10647. return base;
  10648. }
  10649. }
  10650. state.optionalChainMember = optional = true;
  10651. this.next();
  10652. }
  10653. if (!noCalls && this.match(10)) {
  10654. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10655. } else {
  10656. const computed = this.eat(0);
  10657. if (computed || optional || this.eat(16)) {
  10658. return this.parseMember(base, startLoc, state, computed, optional);
  10659. } else {
  10660. state.stop = true;
  10661. return base;
  10662. }
  10663. }
  10664. }
  10665. parseMember(base, startLoc, state, computed, optional) {
  10666. const node = this.startNodeAt(startLoc);
  10667. node.object = base;
  10668. node.computed = computed;
  10669. if (computed) {
  10670. node.property = this.parseExpression();
  10671. this.expect(3);
  10672. } else if (this.match(138)) {
  10673. if (base.type === "Super") {
  10674. this.raise(Errors.SuperPrivateField, startLoc);
  10675. }
  10676. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10677. node.property = this.parsePrivateName();
  10678. } else {
  10679. node.property = this.parseIdentifier(true);
  10680. }
  10681. if (state.optionalChainMember) {
  10682. node.optional = optional;
  10683. return this.finishNode(node, "OptionalMemberExpression");
  10684. } else {
  10685. return this.finishNode(node, "MemberExpression");
  10686. }
  10687. }
  10688. parseBind(base, startLoc, noCalls, state) {
  10689. const node = this.startNodeAt(startLoc);
  10690. node.object = base;
  10691. this.next();
  10692. node.callee = this.parseNoCallExpr();
  10693. state.stop = true;
  10694. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10695. }
  10696. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10697. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10698. let refExpressionErrors = null;
  10699. this.state.maybeInArrowParameters = true;
  10700. this.next();
  10701. const node = this.startNodeAt(startLoc);
  10702. node.callee = base;
  10703. const {
  10704. maybeAsyncArrow,
  10705. optionalChainMember
  10706. } = state;
  10707. if (maybeAsyncArrow) {
  10708. this.expressionScope.enter(newAsyncArrowScope());
  10709. refExpressionErrors = new ExpressionErrors();
  10710. }
  10711. if (optionalChainMember) {
  10712. node.optional = optional;
  10713. }
  10714. if (optional) {
  10715. node.arguments = this.parseCallExpressionArguments(11);
  10716. } else {
  10717. node.arguments = this.parseCallExpressionArguments(11, base.type !== "Super", node, refExpressionErrors);
  10718. }
  10719. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10720. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10721. state.stop = true;
  10722. this.checkDestructuringPrivate(refExpressionErrors);
  10723. this.expressionScope.validateAsPattern();
  10724. this.expressionScope.exit();
  10725. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  10726. } else {
  10727. if (maybeAsyncArrow) {
  10728. this.checkExpressionErrors(refExpressionErrors, true);
  10729. this.expressionScope.exit();
  10730. }
  10731. this.toReferencedArguments(finishedNode);
  10732. }
  10733. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10734. return finishedNode;
  10735. }
  10736. toReferencedArguments(node, isParenthesizedExpr) {
  10737. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  10738. }
  10739. parseTaggedTemplateExpression(base, startLoc, state) {
  10740. const node = this.startNodeAt(startLoc);
  10741. node.tag = base;
  10742. node.quasi = this.parseTemplate(true);
  10743. if (state.optionalChainMember) {
  10744. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  10745. }
  10746. return this.finishNode(node, "TaggedTemplateExpression");
  10747. }
  10748. atPossibleAsyncArrow(base) {
  10749. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && this.offsetToSourcePos(base.start) === this.state.potentialArrowAt;
  10750. }
  10751. finishCallExpression(node, optional) {
  10752. if (node.callee.type === "Import") {
  10753. if (node.arguments.length === 0 || node.arguments.length > 2) {
  10754. this.raise(Errors.ImportCallArity, node);
  10755. } else {
  10756. for (const arg of node.arguments) {
  10757. if (arg.type === "SpreadElement") {
  10758. this.raise(Errors.ImportCallSpreadArgument, arg);
  10759. }
  10760. }
  10761. }
  10762. }
  10763. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  10764. }
  10765. parseCallExpressionArguments(close, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  10766. const elts = [];
  10767. let first = true;
  10768. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10769. this.state.inFSharpPipelineDirectBody = false;
  10770. while (!this.eat(close)) {
  10771. if (first) {
  10772. first = false;
  10773. } else {
  10774. this.expect(12);
  10775. if (this.match(close)) {
  10776. if (nodeForExtra) {
  10777. this.addTrailingCommaExtraToNode(nodeForExtra);
  10778. }
  10779. this.next();
  10780. break;
  10781. }
  10782. }
  10783. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  10784. }
  10785. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  10786. return elts;
  10787. }
  10788. shouldParseAsyncArrow() {
  10789. return this.match(19) && !this.canInsertSemicolon();
  10790. }
  10791. parseAsyncArrowFromCallExpression(node, call) {
  10792. var _call$extra;
  10793. this.resetPreviousNodeTrailingComments(call);
  10794. this.expect(19);
  10795. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  10796. if (call.innerComments) {
  10797. setInnerComments(node, call.innerComments);
  10798. }
  10799. if (call.callee.trailingComments) {
  10800. setInnerComments(node, call.callee.trailingComments);
  10801. }
  10802. return node;
  10803. }
  10804. parseNoCallExpr() {
  10805. const startLoc = this.state.startLoc;
  10806. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  10807. }
  10808. parseExprAtom(refExpressionErrors) {
  10809. let node;
  10810. let decorators = null;
  10811. const {
  10812. type
  10813. } = this.state;
  10814. switch (type) {
  10815. case 79:
  10816. return this.parseSuper();
  10817. case 83:
  10818. node = this.startNode();
  10819. this.next();
  10820. if (this.match(16)) {
  10821. return this.parseImportMetaProperty(node);
  10822. }
  10823. if (this.match(10)) {
  10824. if (this.options.createImportExpressions) {
  10825. return this.parseImportCall(node);
  10826. } else {
  10827. return this.finishNode(node, "Import");
  10828. }
  10829. } else {
  10830. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  10831. return this.finishNode(node, "Import");
  10832. }
  10833. case 78:
  10834. node = this.startNode();
  10835. this.next();
  10836. return this.finishNode(node, "ThisExpression");
  10837. case 90:
  10838. {
  10839. return this.parseDo(this.startNode(), false);
  10840. }
  10841. case 56:
  10842. case 31:
  10843. {
  10844. this.readRegexp();
  10845. return this.parseRegExpLiteral(this.state.value);
  10846. }
  10847. case 134:
  10848. return this.parseNumericLiteral(this.state.value);
  10849. case 135:
  10850. return this.parseBigIntLiteral(this.state.value);
  10851. case 133:
  10852. return this.parseStringLiteral(this.state.value);
  10853. case 84:
  10854. return this.parseNullLiteral();
  10855. case 85:
  10856. return this.parseBooleanLiteral(true);
  10857. case 86:
  10858. return this.parseBooleanLiteral(false);
  10859. case 10:
  10860. {
  10861. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  10862. return this.parseParenAndDistinguishExpression(canBeArrow);
  10863. }
  10864. case 2:
  10865. case 1:
  10866. {
  10867. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  10868. }
  10869. case 0:
  10870. {
  10871. return this.parseArrayLike(3, true, false, refExpressionErrors);
  10872. }
  10873. case 6:
  10874. case 7:
  10875. {
  10876. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  10877. }
  10878. case 5:
  10879. {
  10880. return this.parseObjectLike(8, false, false, refExpressionErrors);
  10881. }
  10882. case 68:
  10883. return this.parseFunctionOrFunctionSent();
  10884. case 26:
  10885. decorators = this.parseDecorators();
  10886. case 80:
  10887. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  10888. case 77:
  10889. return this.parseNewOrNewTarget();
  10890. case 25:
  10891. case 24:
  10892. return this.parseTemplate(false);
  10893. case 15:
  10894. {
  10895. node = this.startNode();
  10896. this.next();
  10897. node.object = null;
  10898. const callee = node.callee = this.parseNoCallExpr();
  10899. if (callee.type === "MemberExpression") {
  10900. return this.finishNode(node, "BindExpression");
  10901. } else {
  10902. throw this.raise(Errors.UnsupportedBind, callee);
  10903. }
  10904. }
  10905. case 138:
  10906. {
  10907. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  10908. identifierName: this.state.value
  10909. });
  10910. return this.parsePrivateName();
  10911. }
  10912. case 33:
  10913. {
  10914. return this.parseTopicReferenceThenEqualsSign(54, "%");
  10915. }
  10916. case 32:
  10917. {
  10918. return this.parseTopicReferenceThenEqualsSign(44, "^");
  10919. }
  10920. case 37:
  10921. case 38:
  10922. {
  10923. return this.parseTopicReference("hack");
  10924. }
  10925. case 44:
  10926. case 54:
  10927. case 27:
  10928. {
  10929. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  10930. if (pipeProposal) {
  10931. return this.parseTopicReference(pipeProposal);
  10932. }
  10933. this.unexpected();
  10934. break;
  10935. }
  10936. case 47:
  10937. {
  10938. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  10939. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  10940. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  10941. } else {
  10942. this.unexpected();
  10943. }
  10944. break;
  10945. }
  10946. default:
  10947. if (type === 136) {
  10948. return this.parseDecimalLiteral(this.state.value);
  10949. }
  10950. if (tokenIsIdentifier(type)) {
  10951. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  10952. return this.parseModuleExpression();
  10953. }
  10954. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  10955. const containsEsc = this.state.containsEsc;
  10956. const id = this.parseIdentifier();
  10957. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  10958. const {
  10959. type
  10960. } = this.state;
  10961. if (type === 68) {
  10962. this.resetPreviousNodeTrailingComments(id);
  10963. this.next();
  10964. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  10965. } else if (tokenIsIdentifier(type)) {
  10966. if (this.lookaheadCharCode() === 61) {
  10967. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  10968. } else {
  10969. return id;
  10970. }
  10971. } else if (type === 90) {
  10972. this.resetPreviousNodeTrailingComments(id);
  10973. return this.parseDo(this.startNodeAtNode(id), true);
  10974. }
  10975. }
  10976. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  10977. this.next();
  10978. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  10979. }
  10980. return id;
  10981. } else {
  10982. this.unexpected();
  10983. }
  10984. }
  10985. }
  10986. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  10987. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  10988. if (pipeProposal) {
  10989. this.state.type = topicTokenType;
  10990. this.state.value = topicTokenValue;
  10991. this.state.pos--;
  10992. this.state.end--;
  10993. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  10994. return this.parseTopicReference(pipeProposal);
  10995. } else {
  10996. this.unexpected();
  10997. }
  10998. }
  10999. parseTopicReference(pipeProposal) {
  11000. const node = this.startNode();
  11001. const startLoc = this.state.startLoc;
  11002. const tokenType = this.state.type;
  11003. this.next();
  11004. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11005. }
  11006. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11007. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11008. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11009. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11010. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, startLoc);
  11011. }
  11012. this.registerTopicReference();
  11013. return this.finishNode(node, nodeType);
  11014. } else {
  11015. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11016. token: tokenLabelName(tokenType)
  11017. });
  11018. }
  11019. }
  11020. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11021. switch (pipeProposal) {
  11022. case "hack":
  11023. {
  11024. return this.hasPlugin(["pipelineOperator", {
  11025. topicToken: tokenLabelName(tokenType)
  11026. }]);
  11027. }
  11028. case "smart":
  11029. return tokenType === 27;
  11030. default:
  11031. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11032. }
  11033. }
  11034. parseAsyncArrowUnaryFunction(node) {
  11035. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11036. const params = [this.parseIdentifier()];
  11037. this.prodParam.exit();
  11038. if (this.hasPrecedingLineBreak()) {
  11039. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11040. }
  11041. this.expect(19);
  11042. return this.parseArrowExpression(node, params, true);
  11043. }
  11044. parseDo(node, isAsync) {
  11045. this.expectPlugin("doExpressions");
  11046. if (isAsync) {
  11047. this.expectPlugin("asyncDoExpressions");
  11048. }
  11049. node.async = isAsync;
  11050. this.next();
  11051. const oldLabels = this.state.labels;
  11052. this.state.labels = [];
  11053. if (isAsync) {
  11054. this.prodParam.enter(2);
  11055. node.body = this.parseBlock();
  11056. this.prodParam.exit();
  11057. } else {
  11058. node.body = this.parseBlock();
  11059. }
  11060. this.state.labels = oldLabels;
  11061. return this.finishNode(node, "DoExpression");
  11062. }
  11063. parseSuper() {
  11064. const node = this.startNode();
  11065. this.next();
  11066. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  11067. this.raise(Errors.SuperNotAllowed, node);
  11068. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  11069. this.raise(Errors.UnexpectedSuper, node);
  11070. }
  11071. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11072. this.raise(Errors.UnsupportedSuper, node);
  11073. }
  11074. return this.finishNode(node, "Super");
  11075. }
  11076. parsePrivateName() {
  11077. const node = this.startNode();
  11078. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11079. const name = this.state.value;
  11080. this.next();
  11081. node.id = this.createIdentifier(id, name);
  11082. return this.finishNode(node, "PrivateName");
  11083. }
  11084. parseFunctionOrFunctionSent() {
  11085. const node = this.startNode();
  11086. this.next();
  11087. if (this.prodParam.hasYield && this.match(16)) {
  11088. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11089. this.next();
  11090. if (this.match(103)) {
  11091. this.expectPlugin("functionSent");
  11092. } else if (!this.hasPlugin("functionSent")) {
  11093. this.unexpected();
  11094. }
  11095. return this.parseMetaProperty(node, meta, "sent");
  11096. }
  11097. return this.parseFunction(node);
  11098. }
  11099. parseMetaProperty(node, meta, propertyName) {
  11100. node.meta = meta;
  11101. const containsEsc = this.state.containsEsc;
  11102. node.property = this.parseIdentifier(true);
  11103. if (node.property.name !== propertyName || containsEsc) {
  11104. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11105. target: meta.name,
  11106. onlyValidPropertyName: propertyName
  11107. });
  11108. }
  11109. return this.finishNode(node, "MetaProperty");
  11110. }
  11111. parseImportMetaProperty(node) {
  11112. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11113. this.next();
  11114. if (this.isContextual(101)) {
  11115. if (!this.inModule) {
  11116. this.raise(Errors.ImportMetaOutsideModule, id);
  11117. }
  11118. this.sawUnambiguousESM = true;
  11119. } else if (this.isContextual(105) || this.isContextual(97)) {
  11120. const isSource = this.isContextual(105);
  11121. if (!isSource) this.unexpected();
  11122. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11123. if (!this.options.createImportExpressions) {
  11124. throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, this.state.startLoc, {
  11125. phase: this.state.value
  11126. });
  11127. }
  11128. this.next();
  11129. node.phase = isSource ? "source" : "defer";
  11130. return this.parseImportCall(node);
  11131. }
  11132. return this.parseMetaProperty(node, id, "meta");
  11133. }
  11134. parseLiteralAtNode(value, type, node) {
  11135. this.addExtra(node, "rawValue", value);
  11136. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11137. node.value = value;
  11138. this.next();
  11139. return this.finishNode(node, type);
  11140. }
  11141. parseLiteral(value, type) {
  11142. const node = this.startNode();
  11143. return this.parseLiteralAtNode(value, type, node);
  11144. }
  11145. parseStringLiteral(value) {
  11146. return this.parseLiteral(value, "StringLiteral");
  11147. }
  11148. parseNumericLiteral(value) {
  11149. return this.parseLiteral(value, "NumericLiteral");
  11150. }
  11151. parseBigIntLiteral(value) {
  11152. return this.parseLiteral(value, "BigIntLiteral");
  11153. }
  11154. parseDecimalLiteral(value) {
  11155. return this.parseLiteral(value, "DecimalLiteral");
  11156. }
  11157. parseRegExpLiteral(value) {
  11158. const node = this.startNode();
  11159. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11160. node.pattern = value.pattern;
  11161. node.flags = value.flags;
  11162. this.next();
  11163. return this.finishNode(node, "RegExpLiteral");
  11164. }
  11165. parseBooleanLiteral(value) {
  11166. const node = this.startNode();
  11167. node.value = value;
  11168. this.next();
  11169. return this.finishNode(node, "BooleanLiteral");
  11170. }
  11171. parseNullLiteral() {
  11172. const node = this.startNode();
  11173. this.next();
  11174. return this.finishNode(node, "NullLiteral");
  11175. }
  11176. parseParenAndDistinguishExpression(canBeArrow) {
  11177. const startLoc = this.state.startLoc;
  11178. let val;
  11179. this.next();
  11180. this.expressionScope.enter(newArrowHeadScope());
  11181. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11182. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11183. this.state.maybeInArrowParameters = true;
  11184. this.state.inFSharpPipelineDirectBody = false;
  11185. const innerStartLoc = this.state.startLoc;
  11186. const exprList = [];
  11187. const refExpressionErrors = new ExpressionErrors();
  11188. let first = true;
  11189. let spreadStartLoc;
  11190. let optionalCommaStartLoc;
  11191. while (!this.match(11)) {
  11192. if (first) {
  11193. first = false;
  11194. } else {
  11195. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11196. if (this.match(11)) {
  11197. optionalCommaStartLoc = this.state.startLoc;
  11198. break;
  11199. }
  11200. }
  11201. if (this.match(21)) {
  11202. const spreadNodeStartLoc = this.state.startLoc;
  11203. spreadStartLoc = this.state.startLoc;
  11204. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11205. if (!this.checkCommaAfterRest(41)) {
  11206. break;
  11207. }
  11208. } else {
  11209. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11210. }
  11211. }
  11212. const innerEndLoc = this.state.lastTokEndLoc;
  11213. this.expect(11);
  11214. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11215. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11216. let arrowNode = this.startNodeAt(startLoc);
  11217. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11218. this.checkDestructuringPrivate(refExpressionErrors);
  11219. this.expressionScope.validateAsPattern();
  11220. this.expressionScope.exit();
  11221. this.parseArrowExpression(arrowNode, exprList, false);
  11222. return arrowNode;
  11223. }
  11224. this.expressionScope.exit();
  11225. if (!exprList.length) {
  11226. this.unexpected(this.state.lastTokStartLoc);
  11227. }
  11228. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11229. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11230. this.checkExpressionErrors(refExpressionErrors, true);
  11231. this.toReferencedListDeep(exprList, true);
  11232. if (exprList.length > 1) {
  11233. val = this.startNodeAt(innerStartLoc);
  11234. val.expressions = exprList;
  11235. this.finishNode(val, "SequenceExpression");
  11236. this.resetEndLocation(val, innerEndLoc);
  11237. } else {
  11238. val = exprList[0];
  11239. }
  11240. return this.wrapParenthesis(startLoc, val);
  11241. }
  11242. wrapParenthesis(startLoc, expression) {
  11243. if (!this.options.createParenthesizedExpressions) {
  11244. this.addExtra(expression, "parenthesized", true);
  11245. this.addExtra(expression, "parenStart", startLoc.index);
  11246. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11247. return expression;
  11248. }
  11249. const parenExpression = this.startNodeAt(startLoc);
  11250. parenExpression.expression = expression;
  11251. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11252. }
  11253. shouldParseArrow(params) {
  11254. return !this.canInsertSemicolon();
  11255. }
  11256. parseArrow(node) {
  11257. if (this.eat(19)) {
  11258. return node;
  11259. }
  11260. }
  11261. parseParenItem(node, startLoc) {
  11262. return node;
  11263. }
  11264. parseNewOrNewTarget() {
  11265. const node = this.startNode();
  11266. this.next();
  11267. if (this.match(16)) {
  11268. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11269. this.next();
  11270. const metaProp = this.parseMetaProperty(node, meta, "target");
  11271. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
  11272. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11273. }
  11274. return metaProp;
  11275. }
  11276. return this.parseNew(node);
  11277. }
  11278. parseNew(node) {
  11279. this.parseNewCallee(node);
  11280. if (this.eat(10)) {
  11281. const args = this.parseExprList(11);
  11282. this.toReferencedList(args);
  11283. node.arguments = args;
  11284. } else {
  11285. node.arguments = [];
  11286. }
  11287. return this.finishNode(node, "NewExpression");
  11288. }
  11289. parseNewCallee(node) {
  11290. const isImport = this.match(83);
  11291. const callee = this.parseNoCallExpr();
  11292. node.callee = callee;
  11293. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11294. this.raise(Errors.ImportCallNotNewExpression, callee);
  11295. }
  11296. }
  11297. parseTemplateElement(isTagged) {
  11298. const {
  11299. start,
  11300. startLoc,
  11301. end,
  11302. value
  11303. } = this.state;
  11304. const elemStart = start + 1;
  11305. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11306. if (value === null) {
  11307. if (!isTagged) {
  11308. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11309. }
  11310. }
  11311. const isTail = this.match(24);
  11312. const endOffset = isTail ? -1 : -2;
  11313. const elemEnd = end + endOffset;
  11314. elem.value = {
  11315. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11316. cooked: value === null ? null : value.slice(1, endOffset)
  11317. };
  11318. elem.tail = isTail;
  11319. this.next();
  11320. const finishedNode = this.finishNode(elem, "TemplateElement");
  11321. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11322. return finishedNode;
  11323. }
  11324. parseTemplate(isTagged) {
  11325. const node = this.startNode();
  11326. let curElt = this.parseTemplateElement(isTagged);
  11327. const quasis = [curElt];
  11328. const substitutions = [];
  11329. while (!curElt.tail) {
  11330. substitutions.push(this.parseTemplateSubstitution());
  11331. this.readTemplateContinuation();
  11332. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11333. }
  11334. node.expressions = substitutions;
  11335. node.quasis = quasis;
  11336. return this.finishNode(node, "TemplateLiteral");
  11337. }
  11338. parseTemplateSubstitution() {
  11339. return this.parseExpression();
  11340. }
  11341. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11342. if (isRecord) {
  11343. this.expectPlugin("recordAndTuple");
  11344. }
  11345. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11346. this.state.inFSharpPipelineDirectBody = false;
  11347. const propHash = Object.create(null);
  11348. let first = true;
  11349. const node = this.startNode();
  11350. node.properties = [];
  11351. this.next();
  11352. while (!this.match(close)) {
  11353. if (first) {
  11354. first = false;
  11355. } else {
  11356. this.expect(12);
  11357. if (this.match(close)) {
  11358. this.addTrailingCommaExtraToNode(node);
  11359. break;
  11360. }
  11361. }
  11362. let prop;
  11363. if (isPattern) {
  11364. prop = this.parseBindingProperty();
  11365. } else {
  11366. prop = this.parsePropertyDefinition(refExpressionErrors);
  11367. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11368. }
  11369. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11370. this.raise(Errors.InvalidRecordProperty, prop);
  11371. }
  11372. {
  11373. if (prop.shorthand) {
  11374. this.addExtra(prop, "shorthand", true);
  11375. }
  11376. }
  11377. node.properties.push(prop);
  11378. }
  11379. this.next();
  11380. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11381. let type = "ObjectExpression";
  11382. if (isPattern) {
  11383. type = "ObjectPattern";
  11384. } else if (isRecord) {
  11385. type = "RecordExpression";
  11386. }
  11387. return this.finishNode(node, type);
  11388. }
  11389. addTrailingCommaExtraToNode(node) {
  11390. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11391. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11392. }
  11393. maybeAsyncOrAccessorProp(prop) {
  11394. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11395. }
  11396. parsePropertyDefinition(refExpressionErrors) {
  11397. let decorators = [];
  11398. if (this.match(26)) {
  11399. if (this.hasPlugin("decorators")) {
  11400. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11401. }
  11402. while (this.match(26)) {
  11403. decorators.push(this.parseDecorator());
  11404. }
  11405. }
  11406. const prop = this.startNode();
  11407. let isAsync = false;
  11408. let isAccessor = false;
  11409. let startLoc;
  11410. if (this.match(21)) {
  11411. if (decorators.length) this.unexpected();
  11412. return this.parseSpread();
  11413. }
  11414. if (decorators.length) {
  11415. prop.decorators = decorators;
  11416. decorators = [];
  11417. }
  11418. prop.method = false;
  11419. if (refExpressionErrors) {
  11420. startLoc = this.state.startLoc;
  11421. }
  11422. let isGenerator = this.eat(55);
  11423. this.parsePropertyNamePrefixOperator(prop);
  11424. const containsEsc = this.state.containsEsc;
  11425. this.parsePropertyName(prop, refExpressionErrors);
  11426. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11427. const {
  11428. key
  11429. } = prop;
  11430. const keyName = key.name;
  11431. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11432. isAsync = true;
  11433. this.resetPreviousNodeTrailingComments(key);
  11434. isGenerator = this.eat(55);
  11435. this.parsePropertyName(prop);
  11436. }
  11437. if (keyName === "get" || keyName === "set") {
  11438. isAccessor = true;
  11439. this.resetPreviousNodeTrailingComments(key);
  11440. prop.kind = keyName;
  11441. if (this.match(55)) {
  11442. isGenerator = true;
  11443. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11444. kind: keyName
  11445. });
  11446. this.next();
  11447. }
  11448. this.parsePropertyName(prop);
  11449. }
  11450. }
  11451. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11452. }
  11453. getGetterSetterExpectedParamCount(method) {
  11454. return method.kind === "get" ? 0 : 1;
  11455. }
  11456. getObjectOrClassMethodParams(method) {
  11457. return method.params;
  11458. }
  11459. checkGetterSetterParams(method) {
  11460. var _params;
  11461. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11462. const params = this.getObjectOrClassMethodParams(method);
  11463. if (params.length !== paramCount) {
  11464. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  11465. }
  11466. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11467. this.raise(Errors.BadSetterRestParameter, method);
  11468. }
  11469. }
  11470. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11471. if (isAccessor) {
  11472. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11473. this.checkGetterSetterParams(finishedProp);
  11474. return finishedProp;
  11475. }
  11476. if (isAsync || isGenerator || this.match(10)) {
  11477. if (isPattern) this.unexpected();
  11478. prop.kind = "method";
  11479. prop.method = true;
  11480. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11481. }
  11482. }
  11483. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11484. prop.shorthand = false;
  11485. if (this.eat(14)) {
  11486. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11487. return this.finishNode(prop, "ObjectProperty");
  11488. }
  11489. if (!prop.computed && prop.key.type === "Identifier") {
  11490. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11491. if (isPattern) {
  11492. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11493. } else if (this.match(29)) {
  11494. const shorthandAssignLoc = this.state.startLoc;
  11495. if (refExpressionErrors != null) {
  11496. if (refExpressionErrors.shorthandAssignLoc === null) {
  11497. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11498. }
  11499. } else {
  11500. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11501. }
  11502. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11503. } else {
  11504. prop.value = cloneIdentifier(prop.key);
  11505. }
  11506. prop.shorthand = true;
  11507. return this.finishNode(prop, "ObjectProperty");
  11508. }
  11509. }
  11510. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11511. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11512. if (!node) this.unexpected();
  11513. return node;
  11514. }
  11515. parsePropertyName(prop, refExpressionErrors) {
  11516. if (this.eat(0)) {
  11517. prop.computed = true;
  11518. prop.key = this.parseMaybeAssignAllowIn();
  11519. this.expect(3);
  11520. } else {
  11521. const {
  11522. type,
  11523. value
  11524. } = this.state;
  11525. let key;
  11526. if (tokenIsKeywordOrIdentifier(type)) {
  11527. key = this.parseIdentifier(true);
  11528. } else {
  11529. switch (type) {
  11530. case 134:
  11531. key = this.parseNumericLiteral(value);
  11532. break;
  11533. case 133:
  11534. key = this.parseStringLiteral(value);
  11535. break;
  11536. case 135:
  11537. key = this.parseBigIntLiteral(value);
  11538. break;
  11539. case 138:
  11540. {
  11541. const privateKeyLoc = this.state.startLoc;
  11542. if (refExpressionErrors != null) {
  11543. if (refExpressionErrors.privateKeyLoc === null) {
  11544. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11545. }
  11546. } else {
  11547. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  11548. }
  11549. key = this.parsePrivateName();
  11550. break;
  11551. }
  11552. default:
  11553. if (type === 136) {
  11554. key = this.parseDecimalLiteral(value);
  11555. break;
  11556. }
  11557. this.unexpected();
  11558. }
  11559. }
  11560. prop.key = key;
  11561. if (type !== 138) {
  11562. prop.computed = false;
  11563. }
  11564. }
  11565. }
  11566. initFunction(node, isAsync) {
  11567. node.id = null;
  11568. node.generator = false;
  11569. node.async = isAsync;
  11570. }
  11571. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11572. this.initFunction(node, isAsync);
  11573. node.generator = isGenerator;
  11574. this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
  11575. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11576. this.parseFunctionParams(node, isConstructor);
  11577. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11578. this.prodParam.exit();
  11579. this.scope.exit();
  11580. return finishedNode;
  11581. }
  11582. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11583. if (isTuple) {
  11584. this.expectPlugin("recordAndTuple");
  11585. }
  11586. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11587. this.state.inFSharpPipelineDirectBody = false;
  11588. const node = this.startNode();
  11589. this.next();
  11590. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11591. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11592. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11593. }
  11594. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11595. this.scope.enter(2 | 4);
  11596. let flags = functionFlags(isAsync, false);
  11597. if (!this.match(5) && this.prodParam.hasIn) {
  11598. flags |= 8;
  11599. }
  11600. this.prodParam.enter(flags);
  11601. this.initFunction(node, isAsync);
  11602. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11603. if (params) {
  11604. this.state.maybeInArrowParameters = true;
  11605. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11606. }
  11607. this.state.maybeInArrowParameters = false;
  11608. this.parseFunctionBody(node, true);
  11609. this.prodParam.exit();
  11610. this.scope.exit();
  11611. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11612. return this.finishNode(node, "ArrowFunctionExpression");
  11613. }
  11614. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11615. this.toAssignableList(params, trailingCommaLoc, false);
  11616. node.params = params;
  11617. }
  11618. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11619. this.parseFunctionBody(node, false, isMethod);
  11620. return this.finishNode(node, type);
  11621. }
  11622. parseFunctionBody(node, allowExpression, isMethod = false) {
  11623. const isExpression = allowExpression && !this.match(5);
  11624. this.expressionScope.enter(newExpressionScope());
  11625. if (isExpression) {
  11626. node.body = this.parseMaybeAssign();
  11627. this.checkParams(node, false, allowExpression, false);
  11628. } else {
  11629. const oldStrict = this.state.strict;
  11630. const oldLabels = this.state.labels;
  11631. this.state.labels = [];
  11632. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  11633. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11634. const nonSimple = !this.isSimpleParamList(node.params);
  11635. if (hasStrictModeDirective && nonSimple) {
  11636. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  11637. }
  11638. const strictModeChanged = !oldStrict && this.state.strict;
  11639. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11640. if (this.state.strict && node.id) {
  11641. this.checkIdentifier(node.id, 65, strictModeChanged);
  11642. }
  11643. });
  11644. this.prodParam.exit();
  11645. this.state.labels = oldLabels;
  11646. }
  11647. this.expressionScope.exit();
  11648. }
  11649. isSimpleParameter(node) {
  11650. return node.type === "Identifier";
  11651. }
  11652. isSimpleParamList(params) {
  11653. for (let i = 0, len = params.length; i < len; i++) {
  11654. if (!this.isSimpleParameter(params[i])) return false;
  11655. }
  11656. return true;
  11657. }
  11658. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11659. const checkClashes = !allowDuplicates && new Set();
  11660. const formalParameters = {
  11661. type: "FormalParameters"
  11662. };
  11663. for (const param of node.params) {
  11664. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  11665. }
  11666. }
  11667. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11668. const elts = [];
  11669. let first = true;
  11670. while (!this.eat(close)) {
  11671. if (first) {
  11672. first = false;
  11673. } else {
  11674. this.expect(12);
  11675. if (this.match(close)) {
  11676. if (nodeForExtra) {
  11677. this.addTrailingCommaExtraToNode(nodeForExtra);
  11678. }
  11679. this.next();
  11680. break;
  11681. }
  11682. }
  11683. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11684. }
  11685. return elts;
  11686. }
  11687. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  11688. let elt;
  11689. if (this.match(12)) {
  11690. if (!allowEmpty) {
  11691. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  11692. unexpected: ","
  11693. });
  11694. }
  11695. elt = null;
  11696. } else if (this.match(21)) {
  11697. const spreadNodeStartLoc = this.state.startLoc;
  11698. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  11699. } else if (this.match(17)) {
  11700. this.expectPlugin("partialApplication");
  11701. if (!allowPlaceholder) {
  11702. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  11703. }
  11704. const node = this.startNode();
  11705. this.next();
  11706. elt = this.finishNode(node, "ArgumentPlaceholder");
  11707. } else {
  11708. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  11709. }
  11710. return elt;
  11711. }
  11712. parseIdentifier(liberal) {
  11713. const node = this.startNode();
  11714. const name = this.parseIdentifierName(liberal);
  11715. return this.createIdentifier(node, name);
  11716. }
  11717. createIdentifier(node, name) {
  11718. node.name = name;
  11719. node.loc.identifierName = name;
  11720. return this.finishNode(node, "Identifier");
  11721. }
  11722. parseIdentifierName(liberal) {
  11723. let name;
  11724. const {
  11725. startLoc,
  11726. type
  11727. } = this.state;
  11728. if (tokenIsKeywordOrIdentifier(type)) {
  11729. name = this.state.value;
  11730. } else {
  11731. this.unexpected();
  11732. }
  11733. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  11734. if (liberal) {
  11735. if (tokenIsKeyword) {
  11736. this.replaceToken(132);
  11737. }
  11738. } else {
  11739. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  11740. }
  11741. this.next();
  11742. return name;
  11743. }
  11744. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  11745. if (word.length > 10) {
  11746. return;
  11747. }
  11748. if (!canBeReservedWord(word)) {
  11749. return;
  11750. }
  11751. if (checkKeywords && isKeyword(word)) {
  11752. this.raise(Errors.UnexpectedKeyword, startLoc, {
  11753. keyword: word
  11754. });
  11755. return;
  11756. }
  11757. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  11758. if (reservedTest(word, this.inModule)) {
  11759. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  11760. reservedWord: word
  11761. });
  11762. return;
  11763. } else if (word === "yield") {
  11764. if (this.prodParam.hasYield) {
  11765. this.raise(Errors.YieldBindingIdentifier, startLoc);
  11766. return;
  11767. }
  11768. } else if (word === "await") {
  11769. if (this.prodParam.hasAwait) {
  11770. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  11771. return;
  11772. }
  11773. if (this.scope.inStaticBlock) {
  11774. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  11775. return;
  11776. }
  11777. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  11778. } else if (word === "arguments") {
  11779. if (this.scope.inClassAndNotInNonArrowFunction) {
  11780. this.raise(Errors.ArgumentsInClass, startLoc);
  11781. return;
  11782. }
  11783. }
  11784. }
  11785. recordAwaitIfAllowed() {
  11786. const isAwaitAllowed = this.prodParam.hasAwait || this.options.allowAwaitOutsideFunction && !this.scope.inFunction;
  11787. if (isAwaitAllowed && !this.scope.inFunction) {
  11788. this.state.hasTopLevelAwait = true;
  11789. }
  11790. return isAwaitAllowed;
  11791. }
  11792. parseAwait(startLoc) {
  11793. const node = this.startNodeAt(startLoc);
  11794. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  11795. if (this.eat(55)) {
  11796. this.raise(Errors.ObsoleteAwaitStar, node);
  11797. }
  11798. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  11799. if (this.isAmbiguousAwait()) {
  11800. this.ambiguousScriptDifferentAst = true;
  11801. } else {
  11802. this.sawUnambiguousESM = true;
  11803. }
  11804. }
  11805. if (!this.state.soloAwait) {
  11806. node.argument = this.parseMaybeUnary(null, true);
  11807. }
  11808. return this.finishNode(node, "AwaitExpression");
  11809. }
  11810. isAmbiguousAwait() {
  11811. if (this.hasPrecedingLineBreak()) return true;
  11812. const {
  11813. type
  11814. } = this.state;
  11815. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 137 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  11816. }
  11817. parseYield() {
  11818. const node = this.startNode();
  11819. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  11820. this.next();
  11821. let delegating = false;
  11822. let argument = null;
  11823. if (!this.hasPrecedingLineBreak()) {
  11824. delegating = this.eat(55);
  11825. switch (this.state.type) {
  11826. case 13:
  11827. case 139:
  11828. case 8:
  11829. case 11:
  11830. case 3:
  11831. case 9:
  11832. case 14:
  11833. case 12:
  11834. if (!delegating) break;
  11835. default:
  11836. argument = this.parseMaybeAssign();
  11837. }
  11838. }
  11839. node.delegate = delegating;
  11840. node.argument = argument;
  11841. return this.finishNode(node, "YieldExpression");
  11842. }
  11843. parseImportCall(node) {
  11844. this.next();
  11845. node.source = this.parseMaybeAssignAllowIn();
  11846. node.options = null;
  11847. if (this.eat(12)) {
  11848. if (!this.match(11)) {
  11849. node.options = this.parseMaybeAssignAllowIn();
  11850. if (this.eat(12) && !this.match(11)) {
  11851. do {
  11852. this.parseMaybeAssignAllowIn();
  11853. } while (this.eat(12) && !this.match(11));
  11854. this.raise(Errors.ImportCallArity, node);
  11855. }
  11856. }
  11857. }
  11858. this.expect(11);
  11859. return this.finishNode(node, "ImportExpression");
  11860. }
  11861. checkPipelineAtInfixOperator(left, leftStartLoc) {
  11862. if (this.hasPlugin(["pipelineOperator", {
  11863. proposal: "smart"
  11864. }])) {
  11865. if (left.type === "SequenceExpression") {
  11866. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  11867. }
  11868. }
  11869. }
  11870. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  11871. if (this.isSimpleReference(childExpr)) {
  11872. const bodyNode = this.startNodeAt(startLoc);
  11873. bodyNode.callee = childExpr;
  11874. return this.finishNode(bodyNode, "PipelineBareFunction");
  11875. } else {
  11876. const bodyNode = this.startNodeAt(startLoc);
  11877. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  11878. bodyNode.expression = childExpr;
  11879. return this.finishNode(bodyNode, "PipelineTopicExpression");
  11880. }
  11881. }
  11882. isSimpleReference(expression) {
  11883. switch (expression.type) {
  11884. case "MemberExpression":
  11885. return !expression.computed && this.isSimpleReference(expression.object);
  11886. case "Identifier":
  11887. return true;
  11888. default:
  11889. return false;
  11890. }
  11891. }
  11892. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  11893. if (this.match(19)) {
  11894. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  11895. }
  11896. if (!this.topicReferenceWasUsedInCurrentContext()) {
  11897. this.raise(Errors.PipelineTopicUnused, startLoc);
  11898. }
  11899. }
  11900. withTopicBindingContext(callback) {
  11901. const outerContextTopicState = this.state.topicContext;
  11902. this.state.topicContext = {
  11903. maxNumOfResolvableTopics: 1,
  11904. maxTopicIndex: null
  11905. };
  11906. try {
  11907. return callback();
  11908. } finally {
  11909. this.state.topicContext = outerContextTopicState;
  11910. }
  11911. }
  11912. withSmartMixTopicForbiddingContext(callback) {
  11913. if (this.hasPlugin(["pipelineOperator", {
  11914. proposal: "smart"
  11915. }])) {
  11916. const outerContextTopicState = this.state.topicContext;
  11917. this.state.topicContext = {
  11918. maxNumOfResolvableTopics: 0,
  11919. maxTopicIndex: null
  11920. };
  11921. try {
  11922. return callback();
  11923. } finally {
  11924. this.state.topicContext = outerContextTopicState;
  11925. }
  11926. } else {
  11927. return callback();
  11928. }
  11929. }
  11930. withSoloAwaitPermittingContext(callback) {
  11931. const outerContextSoloAwaitState = this.state.soloAwait;
  11932. this.state.soloAwait = true;
  11933. try {
  11934. return callback();
  11935. } finally {
  11936. this.state.soloAwait = outerContextSoloAwaitState;
  11937. }
  11938. }
  11939. allowInAnd(callback) {
  11940. const flags = this.prodParam.currentFlags();
  11941. const prodParamToSet = 8 & ~flags;
  11942. if (prodParamToSet) {
  11943. this.prodParam.enter(flags | 8);
  11944. try {
  11945. return callback();
  11946. } finally {
  11947. this.prodParam.exit();
  11948. }
  11949. }
  11950. return callback();
  11951. }
  11952. disallowInAnd(callback) {
  11953. const flags = this.prodParam.currentFlags();
  11954. const prodParamToClear = 8 & flags;
  11955. if (prodParamToClear) {
  11956. this.prodParam.enter(flags & ~8);
  11957. try {
  11958. return callback();
  11959. } finally {
  11960. this.prodParam.exit();
  11961. }
  11962. }
  11963. return callback();
  11964. }
  11965. registerTopicReference() {
  11966. this.state.topicContext.maxTopicIndex = 0;
  11967. }
  11968. topicReferenceIsAllowedInCurrentContext() {
  11969. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  11970. }
  11971. topicReferenceWasUsedInCurrentContext() {
  11972. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  11973. }
  11974. parseFSharpPipelineBody(prec) {
  11975. const startLoc = this.state.startLoc;
  11976. this.state.potentialArrowAt = this.state.start;
  11977. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11978. this.state.inFSharpPipelineDirectBody = true;
  11979. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  11980. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11981. return ret;
  11982. }
  11983. parseModuleExpression() {
  11984. this.expectPlugin("moduleBlocks");
  11985. const node = this.startNode();
  11986. this.next();
  11987. if (!this.match(5)) {
  11988. this.unexpected(null, 5);
  11989. }
  11990. const program = this.startNodeAt(this.state.endLoc);
  11991. this.next();
  11992. const revertScopes = this.initializeScopes(true);
  11993. this.enterInitialScopes();
  11994. try {
  11995. node.body = this.parseProgram(program, 8, "module");
  11996. } finally {
  11997. revertScopes();
  11998. }
  11999. return this.finishNode(node, "ModuleExpression");
  12000. }
  12001. parsePropertyNamePrefixOperator(prop) {}
  12002. }
  12003. const loopLabel = {
  12004. kind: 1
  12005. },
  12006. switchLabel = {
  12007. kind: 2
  12008. };
  12009. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12010. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12011. function babel7CompatTokens(tokens, input) {
  12012. for (let i = 0; i < tokens.length; i++) {
  12013. const token = tokens[i];
  12014. const {
  12015. type
  12016. } = token;
  12017. if (typeof type === "number") {
  12018. {
  12019. if (type === 138) {
  12020. const {
  12021. loc,
  12022. start,
  12023. value,
  12024. end
  12025. } = token;
  12026. const hashEndPos = start + 1;
  12027. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12028. tokens.splice(i, 1, new Token({
  12029. type: getExportedToken(27),
  12030. value: "#",
  12031. start: start,
  12032. end: hashEndPos,
  12033. startLoc: loc.start,
  12034. endLoc: hashEndLoc
  12035. }), new Token({
  12036. type: getExportedToken(132),
  12037. value: value,
  12038. start: hashEndPos,
  12039. end: end,
  12040. startLoc: hashEndLoc,
  12041. endLoc: loc.end
  12042. }));
  12043. i++;
  12044. continue;
  12045. }
  12046. if (tokenIsTemplate(type)) {
  12047. const {
  12048. loc,
  12049. start,
  12050. value,
  12051. end
  12052. } = token;
  12053. const backquoteEnd = start + 1;
  12054. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12055. let startToken;
  12056. if (input.charCodeAt(start) === 96) {
  12057. startToken = new Token({
  12058. type: getExportedToken(22),
  12059. value: "`",
  12060. start: start,
  12061. end: backquoteEnd,
  12062. startLoc: loc.start,
  12063. endLoc: backquoteEndLoc
  12064. });
  12065. } else {
  12066. startToken = new Token({
  12067. type: getExportedToken(8),
  12068. value: "}",
  12069. start: start,
  12070. end: backquoteEnd,
  12071. startLoc: loc.start,
  12072. endLoc: backquoteEndLoc
  12073. });
  12074. }
  12075. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12076. if (type === 24) {
  12077. templateElementEnd = end - 1;
  12078. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12079. templateValue = value === null ? null : value.slice(1, -1);
  12080. endToken = new Token({
  12081. type: getExportedToken(22),
  12082. value: "`",
  12083. start: templateElementEnd,
  12084. end: end,
  12085. startLoc: templateElementEndLoc,
  12086. endLoc: loc.end
  12087. });
  12088. } else {
  12089. templateElementEnd = end - 2;
  12090. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12091. templateValue = value === null ? null : value.slice(1, -2);
  12092. endToken = new Token({
  12093. type: getExportedToken(23),
  12094. value: "${",
  12095. start: templateElementEnd,
  12096. end: end,
  12097. startLoc: templateElementEndLoc,
  12098. endLoc: loc.end
  12099. });
  12100. }
  12101. tokens.splice(i, 1, startToken, new Token({
  12102. type: getExportedToken(20),
  12103. value: templateValue,
  12104. start: backquoteEnd,
  12105. end: templateElementEnd,
  12106. startLoc: backquoteEndLoc,
  12107. endLoc: templateElementEndLoc
  12108. }), endToken);
  12109. i += 2;
  12110. continue;
  12111. }
  12112. }
  12113. token.type = getExportedToken(type);
  12114. }
  12115. }
  12116. return tokens;
  12117. }
  12118. class StatementParser extends ExpressionParser {
  12119. parseTopLevel(file, program) {
  12120. file.program = this.parseProgram(program);
  12121. file.comments = this.comments;
  12122. if (this.options.tokens) {
  12123. file.tokens = babel7CompatTokens(this.tokens, this.input);
  12124. }
  12125. return this.finishNode(file, "File");
  12126. }
  12127. parseProgram(program, end = 139, sourceType = this.options.sourceType) {
  12128. program.sourceType = sourceType;
  12129. program.interpreter = this.parseInterpreterDirective();
  12130. this.parseBlockBody(program, true, true, end);
  12131. if (this.inModule) {
  12132. if (!this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  12133. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12134. this.raise(Errors.ModuleExportUndefined, at, {
  12135. localName
  12136. });
  12137. }
  12138. }
  12139. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  12140. }
  12141. let finishedProgram;
  12142. if (end === 139) {
  12143. finishedProgram = this.finishNode(program, "Program");
  12144. } else {
  12145. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12146. }
  12147. return finishedProgram;
  12148. }
  12149. stmtToDirective(stmt) {
  12150. const directive = stmt;
  12151. directive.type = "Directive";
  12152. directive.value = directive.expression;
  12153. delete directive.expression;
  12154. const directiveLiteral = directive.value;
  12155. const expressionValue = directiveLiteral.value;
  12156. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  12157. const val = directiveLiteral.value = raw.slice(1, -1);
  12158. this.addExtra(directiveLiteral, "raw", raw);
  12159. this.addExtra(directiveLiteral, "rawValue", val);
  12160. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12161. directiveLiteral.type = "DirectiveLiteral";
  12162. return directive;
  12163. }
  12164. parseInterpreterDirective() {
  12165. if (!this.match(28)) {
  12166. return null;
  12167. }
  12168. const node = this.startNode();
  12169. node.value = this.state.value;
  12170. this.next();
  12171. return this.finishNode(node, "InterpreterDirective");
  12172. }
  12173. isLet() {
  12174. if (!this.isContextual(100)) {
  12175. return false;
  12176. }
  12177. return this.hasFollowingBindingAtom();
  12178. }
  12179. chStartsBindingIdentifier(ch, pos) {
  12180. if (isIdentifierStart(ch)) {
  12181. keywordRelationalOperator.lastIndex = pos;
  12182. if (keywordRelationalOperator.test(this.input)) {
  12183. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12184. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12185. return false;
  12186. }
  12187. }
  12188. return true;
  12189. } else if (ch === 92) {
  12190. return true;
  12191. } else {
  12192. return false;
  12193. }
  12194. }
  12195. chStartsBindingPattern(ch) {
  12196. return ch === 91 || ch === 123;
  12197. }
  12198. hasFollowingBindingAtom() {
  12199. const next = this.nextTokenStart();
  12200. const nextCh = this.codePointAtPos(next);
  12201. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12202. }
  12203. hasInLineFollowingBindingIdentifierOrBrace() {
  12204. const next = this.nextTokenInLineStart();
  12205. const nextCh = this.codePointAtPos(next);
  12206. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  12207. }
  12208. startsUsingForOf() {
  12209. const {
  12210. type,
  12211. containsEsc
  12212. } = this.lookahead();
  12213. if (type === 102 && !containsEsc) {
  12214. return false;
  12215. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12216. this.expectPlugin("explicitResourceManagement");
  12217. return true;
  12218. }
  12219. }
  12220. startsAwaitUsing() {
  12221. let next = this.nextTokenInLineStart();
  12222. if (this.isUnparsedContextual(next, "using")) {
  12223. next = this.nextTokenInLineStartSince(next + 5);
  12224. const nextCh = this.codePointAtPos(next);
  12225. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12226. this.expectPlugin("explicitResourceManagement");
  12227. return true;
  12228. }
  12229. }
  12230. return false;
  12231. }
  12232. parseModuleItem() {
  12233. return this.parseStatementLike(1 | 2 | 4 | 8);
  12234. }
  12235. parseStatementListItem() {
  12236. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12237. }
  12238. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12239. let flags = 0;
  12240. if (this.options.annexB && !this.state.strict) {
  12241. flags |= 4;
  12242. if (allowLabeledFunction) {
  12243. flags |= 8;
  12244. }
  12245. }
  12246. return this.parseStatementLike(flags);
  12247. }
  12248. parseStatement() {
  12249. return this.parseStatementLike(0);
  12250. }
  12251. parseStatementLike(flags) {
  12252. let decorators = null;
  12253. if (this.match(26)) {
  12254. decorators = this.parseDecorators(true);
  12255. }
  12256. return this.parseStatementContent(flags, decorators);
  12257. }
  12258. parseStatementContent(flags, decorators) {
  12259. const startType = this.state.type;
  12260. const node = this.startNode();
  12261. const allowDeclaration = !!(flags & 2);
  12262. const allowFunctionDeclaration = !!(flags & 4);
  12263. const topLevel = flags & 1;
  12264. switch (startType) {
  12265. case 60:
  12266. return this.parseBreakContinueStatement(node, true);
  12267. case 63:
  12268. return this.parseBreakContinueStatement(node, false);
  12269. case 64:
  12270. return this.parseDebuggerStatement(node);
  12271. case 90:
  12272. return this.parseDoWhileStatement(node);
  12273. case 91:
  12274. return this.parseForStatement(node);
  12275. case 68:
  12276. if (this.lookaheadCharCode() === 46) break;
  12277. if (!allowFunctionDeclaration) {
  12278. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12279. }
  12280. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12281. case 80:
  12282. if (!allowDeclaration) this.unexpected();
  12283. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12284. case 69:
  12285. return this.parseIfStatement(node);
  12286. case 70:
  12287. return this.parseReturnStatement(node);
  12288. case 71:
  12289. return this.parseSwitchStatement(node);
  12290. case 72:
  12291. return this.parseThrowStatement(node);
  12292. case 73:
  12293. return this.parseTryStatement(node);
  12294. case 96:
  12295. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  12296. if (!this.recordAwaitIfAllowed()) {
  12297. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12298. } else if (!allowDeclaration) {
  12299. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12300. }
  12301. this.next();
  12302. return this.parseVarStatement(node, "await using");
  12303. }
  12304. break;
  12305. case 107:
  12306. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  12307. break;
  12308. }
  12309. this.expectPlugin("explicitResourceManagement");
  12310. if (!this.scope.inModule && this.scope.inTopLevel) {
  12311. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12312. } else if (!allowDeclaration) {
  12313. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12314. }
  12315. return this.parseVarStatement(node, "using");
  12316. case 100:
  12317. {
  12318. if (this.state.containsEsc) {
  12319. break;
  12320. }
  12321. const next = this.nextTokenStart();
  12322. const nextCh = this.codePointAtPos(next);
  12323. if (nextCh !== 91) {
  12324. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12325. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12326. break;
  12327. }
  12328. }
  12329. }
  12330. case 75:
  12331. {
  12332. if (!allowDeclaration) {
  12333. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12334. }
  12335. }
  12336. case 74:
  12337. {
  12338. const kind = this.state.value;
  12339. return this.parseVarStatement(node, kind);
  12340. }
  12341. case 92:
  12342. return this.parseWhileStatement(node);
  12343. case 76:
  12344. return this.parseWithStatement(node);
  12345. case 5:
  12346. return this.parseBlock();
  12347. case 13:
  12348. return this.parseEmptyStatement(node);
  12349. case 83:
  12350. {
  12351. const nextTokenCharCode = this.lookaheadCharCode();
  12352. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12353. break;
  12354. }
  12355. }
  12356. case 82:
  12357. {
  12358. if (!this.options.allowImportExportEverywhere && !topLevel) {
  12359. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12360. }
  12361. this.next();
  12362. let result;
  12363. if (startType === 83) {
  12364. result = this.parseImport(node);
  12365. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12366. this.sawUnambiguousESM = true;
  12367. }
  12368. } else {
  12369. result = this.parseExport(node, decorators);
  12370. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12371. this.sawUnambiguousESM = true;
  12372. }
  12373. }
  12374. this.assertModuleNodeAllowed(result);
  12375. return result;
  12376. }
  12377. default:
  12378. {
  12379. if (this.isAsyncFunction()) {
  12380. if (!allowDeclaration) {
  12381. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12382. }
  12383. this.next();
  12384. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12385. }
  12386. }
  12387. }
  12388. const maybeName = this.state.value;
  12389. const expr = this.parseExpression();
  12390. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  12391. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12392. } else {
  12393. return this.parseExpressionStatement(node, expr, decorators);
  12394. }
  12395. }
  12396. assertModuleNodeAllowed(node) {
  12397. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  12398. this.raise(Errors.ImportOutsideModule, node);
  12399. }
  12400. }
  12401. decoratorsEnabledBeforeExport() {
  12402. if (this.hasPlugin("decorators-legacy")) return true;
  12403. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12404. }
  12405. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12406. if (maybeDecorators) {
  12407. if (classNode.decorators && classNode.decorators.length > 0) {
  12408. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12409. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12410. }
  12411. classNode.decorators.unshift(...maybeDecorators);
  12412. } else {
  12413. classNode.decorators = maybeDecorators;
  12414. }
  12415. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12416. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12417. }
  12418. return classNode;
  12419. }
  12420. canHaveLeadingDecorator() {
  12421. return this.match(80);
  12422. }
  12423. parseDecorators(allowExport) {
  12424. const decorators = [];
  12425. do {
  12426. decorators.push(this.parseDecorator());
  12427. } while (this.match(26));
  12428. if (this.match(82)) {
  12429. if (!allowExport) {
  12430. this.unexpected();
  12431. }
  12432. if (!this.decoratorsEnabledBeforeExport()) {
  12433. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  12434. }
  12435. } else if (!this.canHaveLeadingDecorator()) {
  12436. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  12437. }
  12438. return decorators;
  12439. }
  12440. parseDecorator() {
  12441. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12442. const node = this.startNode();
  12443. this.next();
  12444. if (this.hasPlugin("decorators")) {
  12445. const startLoc = this.state.startLoc;
  12446. let expr;
  12447. if (this.match(10)) {
  12448. const startLoc = this.state.startLoc;
  12449. this.next();
  12450. expr = this.parseExpression();
  12451. this.expect(11);
  12452. expr = this.wrapParenthesis(startLoc, expr);
  12453. const paramsStartLoc = this.state.startLoc;
  12454. node.expression = this.parseMaybeDecoratorArguments(expr);
  12455. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12456. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  12457. }
  12458. } else {
  12459. expr = this.parseIdentifier(false);
  12460. while (this.eat(16)) {
  12461. const node = this.startNodeAt(startLoc);
  12462. node.object = expr;
  12463. if (this.match(138)) {
  12464. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12465. node.property = this.parsePrivateName();
  12466. } else {
  12467. node.property = this.parseIdentifier(true);
  12468. }
  12469. node.computed = false;
  12470. expr = this.finishNode(node, "MemberExpression");
  12471. }
  12472. node.expression = this.parseMaybeDecoratorArguments(expr);
  12473. }
  12474. } else {
  12475. node.expression = this.parseExprSubscripts();
  12476. }
  12477. return this.finishNode(node, "Decorator");
  12478. }
  12479. parseMaybeDecoratorArguments(expr) {
  12480. if (this.eat(10)) {
  12481. const node = this.startNodeAtNode(expr);
  12482. node.callee = expr;
  12483. node.arguments = this.parseCallExpressionArguments(11);
  12484. this.toReferencedList(node.arguments);
  12485. return this.finishNode(node, "CallExpression");
  12486. }
  12487. return expr;
  12488. }
  12489. parseBreakContinueStatement(node, isBreak) {
  12490. this.next();
  12491. if (this.isLineTerminator()) {
  12492. node.label = null;
  12493. } else {
  12494. node.label = this.parseIdentifier();
  12495. this.semicolon();
  12496. }
  12497. this.verifyBreakContinue(node, isBreak);
  12498. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12499. }
  12500. verifyBreakContinue(node, isBreak) {
  12501. let i;
  12502. for (i = 0; i < this.state.labels.length; ++i) {
  12503. const lab = this.state.labels[i];
  12504. if (node.label == null || lab.name === node.label.name) {
  12505. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  12506. break;
  12507. }
  12508. if (node.label && isBreak) break;
  12509. }
  12510. }
  12511. if (i === this.state.labels.length) {
  12512. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12513. this.raise(Errors.IllegalBreakContinue, node, {
  12514. type
  12515. });
  12516. }
  12517. }
  12518. parseDebuggerStatement(node) {
  12519. this.next();
  12520. this.semicolon();
  12521. return this.finishNode(node, "DebuggerStatement");
  12522. }
  12523. parseHeaderExpression() {
  12524. this.expect(10);
  12525. const val = this.parseExpression();
  12526. this.expect(11);
  12527. return val;
  12528. }
  12529. parseDoWhileStatement(node) {
  12530. this.next();
  12531. this.state.labels.push(loopLabel);
  12532. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12533. this.state.labels.pop();
  12534. this.expect(92);
  12535. node.test = this.parseHeaderExpression();
  12536. this.eat(13);
  12537. return this.finishNode(node, "DoWhileStatement");
  12538. }
  12539. parseForStatement(node) {
  12540. this.next();
  12541. this.state.labels.push(loopLabel);
  12542. let awaitAt = null;
  12543. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  12544. awaitAt = this.state.startLoc;
  12545. this.next();
  12546. }
  12547. this.scope.enter(0);
  12548. this.expect(10);
  12549. if (this.match(13)) {
  12550. if (awaitAt !== null) {
  12551. this.unexpected(awaitAt);
  12552. }
  12553. return this.parseFor(node, null);
  12554. }
  12555. const startsWithLet = this.isContextual(100);
  12556. {
  12557. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  12558. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(107) && this.startsUsingForOf();
  12559. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  12560. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12561. const initNode = this.startNode();
  12562. let kind;
  12563. if (startsWithAwaitUsing) {
  12564. kind = "await using";
  12565. if (!this.recordAwaitIfAllowed()) {
  12566. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  12567. }
  12568. this.next();
  12569. } else {
  12570. kind = this.state.value;
  12571. }
  12572. this.next();
  12573. this.parseVar(initNode, true, kind);
  12574. const init = this.finishNode(initNode, "VariableDeclaration");
  12575. const isForIn = this.match(58);
  12576. if (isForIn && starsWithUsingDeclaration) {
  12577. this.raise(Errors.ForInUsing, init);
  12578. }
  12579. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  12580. return this.parseForIn(node, init, awaitAt);
  12581. }
  12582. if (awaitAt !== null) {
  12583. this.unexpected(awaitAt);
  12584. }
  12585. return this.parseFor(node, init);
  12586. }
  12587. }
  12588. const startsWithAsync = this.isContextual(95);
  12589. const refExpressionErrors = new ExpressionErrors();
  12590. const init = this.parseExpression(true, refExpressionErrors);
  12591. const isForOf = this.isContextual(102);
  12592. if (isForOf) {
  12593. if (startsWithLet) {
  12594. this.raise(Errors.ForOfLet, init);
  12595. }
  12596. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12597. this.raise(Errors.ForOfAsync, init);
  12598. }
  12599. }
  12600. if (isForOf || this.match(58)) {
  12601. this.checkDestructuringPrivate(refExpressionErrors);
  12602. this.toAssignable(init, true);
  12603. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12604. this.checkLVal(init, {
  12605. type
  12606. });
  12607. return this.parseForIn(node, init, awaitAt);
  12608. } else {
  12609. this.checkExpressionErrors(refExpressionErrors, true);
  12610. }
  12611. if (awaitAt !== null) {
  12612. this.unexpected(awaitAt);
  12613. }
  12614. return this.parseFor(node, init);
  12615. }
  12616. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12617. this.next();
  12618. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  12619. }
  12620. parseIfStatement(node) {
  12621. this.next();
  12622. node.test = this.parseHeaderExpression();
  12623. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12624. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  12625. return this.finishNode(node, "IfStatement");
  12626. }
  12627. parseReturnStatement(node) {
  12628. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  12629. this.raise(Errors.IllegalReturn, this.state.startLoc);
  12630. }
  12631. this.next();
  12632. if (this.isLineTerminator()) {
  12633. node.argument = null;
  12634. } else {
  12635. node.argument = this.parseExpression();
  12636. this.semicolon();
  12637. }
  12638. return this.finishNode(node, "ReturnStatement");
  12639. }
  12640. parseSwitchStatement(node) {
  12641. this.next();
  12642. node.discriminant = this.parseHeaderExpression();
  12643. const cases = node.cases = [];
  12644. this.expect(5);
  12645. this.state.labels.push(switchLabel);
  12646. this.scope.enter(0);
  12647. let cur;
  12648. for (let sawDefault; !this.match(8);) {
  12649. if (this.match(61) || this.match(65)) {
  12650. const isCase = this.match(61);
  12651. if (cur) this.finishNode(cur, "SwitchCase");
  12652. cases.push(cur = this.startNode());
  12653. cur.consequent = [];
  12654. this.next();
  12655. if (isCase) {
  12656. cur.test = this.parseExpression();
  12657. } else {
  12658. if (sawDefault) {
  12659. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  12660. }
  12661. sawDefault = true;
  12662. cur.test = null;
  12663. }
  12664. this.expect(14);
  12665. } else {
  12666. if (cur) {
  12667. cur.consequent.push(this.parseStatementListItem());
  12668. } else {
  12669. this.unexpected();
  12670. }
  12671. }
  12672. }
  12673. this.scope.exit();
  12674. if (cur) this.finishNode(cur, "SwitchCase");
  12675. this.next();
  12676. this.state.labels.pop();
  12677. return this.finishNode(node, "SwitchStatement");
  12678. }
  12679. parseThrowStatement(node) {
  12680. this.next();
  12681. if (this.hasPrecedingLineBreak()) {
  12682. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  12683. }
  12684. node.argument = this.parseExpression();
  12685. this.semicolon();
  12686. return this.finishNode(node, "ThrowStatement");
  12687. }
  12688. parseCatchClauseParam() {
  12689. const param = this.parseBindingAtom();
  12690. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  12691. this.checkLVal(param, {
  12692. type: "CatchClause"
  12693. }, 9);
  12694. return param;
  12695. }
  12696. parseTryStatement(node) {
  12697. this.next();
  12698. node.block = this.parseBlock();
  12699. node.handler = null;
  12700. if (this.match(62)) {
  12701. const clause = this.startNode();
  12702. this.next();
  12703. if (this.match(10)) {
  12704. this.expect(10);
  12705. clause.param = this.parseCatchClauseParam();
  12706. this.expect(11);
  12707. } else {
  12708. clause.param = null;
  12709. this.scope.enter(0);
  12710. }
  12711. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  12712. this.scope.exit();
  12713. node.handler = this.finishNode(clause, "CatchClause");
  12714. }
  12715. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  12716. if (!node.handler && !node.finalizer) {
  12717. this.raise(Errors.NoCatchOrFinally, node);
  12718. }
  12719. return this.finishNode(node, "TryStatement");
  12720. }
  12721. parseVarStatement(node, kind, allowMissingInitializer = false) {
  12722. this.next();
  12723. this.parseVar(node, false, kind, allowMissingInitializer);
  12724. this.semicolon();
  12725. return this.finishNode(node, "VariableDeclaration");
  12726. }
  12727. parseWhileStatement(node) {
  12728. this.next();
  12729. node.test = this.parseHeaderExpression();
  12730. this.state.labels.push(loopLabel);
  12731. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12732. this.state.labels.pop();
  12733. return this.finishNode(node, "WhileStatement");
  12734. }
  12735. parseWithStatement(node) {
  12736. if (this.state.strict) {
  12737. this.raise(Errors.StrictWith, this.state.startLoc);
  12738. }
  12739. this.next();
  12740. node.object = this.parseHeaderExpression();
  12741. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12742. return this.finishNode(node, "WithStatement");
  12743. }
  12744. parseEmptyStatement(node) {
  12745. this.next();
  12746. return this.finishNode(node, "EmptyStatement");
  12747. }
  12748. parseLabeledStatement(node, maybeName, expr, flags) {
  12749. for (const label of this.state.labels) {
  12750. if (label.name === maybeName) {
  12751. this.raise(Errors.LabelRedeclaration, expr, {
  12752. labelName: maybeName
  12753. });
  12754. }
  12755. }
  12756. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  12757. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  12758. const label = this.state.labels[i];
  12759. if (label.statementStart === node.start) {
  12760. label.statementStart = this.sourceToOffsetPos(this.state.start);
  12761. label.kind = kind;
  12762. } else {
  12763. break;
  12764. }
  12765. }
  12766. this.state.labels.push({
  12767. name: maybeName,
  12768. kind: kind,
  12769. statementStart: this.sourceToOffsetPos(this.state.start)
  12770. });
  12771. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  12772. this.state.labels.pop();
  12773. node.label = expr;
  12774. return this.finishNode(node, "LabeledStatement");
  12775. }
  12776. parseExpressionStatement(node, expr, decorators) {
  12777. node.expression = expr;
  12778. this.semicolon();
  12779. return this.finishNode(node, "ExpressionStatement");
  12780. }
  12781. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  12782. const node = this.startNode();
  12783. if (allowDirectives) {
  12784. this.state.strictErrors.clear();
  12785. }
  12786. this.expect(5);
  12787. if (createNewLexicalScope) {
  12788. this.scope.enter(0);
  12789. }
  12790. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  12791. if (createNewLexicalScope) {
  12792. this.scope.exit();
  12793. }
  12794. return this.finishNode(node, "BlockStatement");
  12795. }
  12796. isValidDirective(stmt) {
  12797. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  12798. }
  12799. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  12800. const body = node.body = [];
  12801. const directives = node.directives = [];
  12802. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  12803. }
  12804. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  12805. const oldStrict = this.state.strict;
  12806. let hasStrictModeDirective = false;
  12807. let parsedNonDirective = false;
  12808. while (!this.match(end)) {
  12809. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  12810. if (directives && !parsedNonDirective) {
  12811. if (this.isValidDirective(stmt)) {
  12812. const directive = this.stmtToDirective(stmt);
  12813. directives.push(directive);
  12814. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  12815. hasStrictModeDirective = true;
  12816. this.setStrict(true);
  12817. }
  12818. continue;
  12819. }
  12820. parsedNonDirective = true;
  12821. this.state.strictErrors.clear();
  12822. }
  12823. body.push(stmt);
  12824. }
  12825. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  12826. if (!oldStrict) {
  12827. this.setStrict(false);
  12828. }
  12829. this.next();
  12830. }
  12831. parseFor(node, init) {
  12832. node.init = init;
  12833. this.semicolon(false);
  12834. node.test = this.match(13) ? null : this.parseExpression();
  12835. this.semicolon(false);
  12836. node.update = this.match(11) ? null : this.parseExpression();
  12837. this.expect(11);
  12838. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12839. this.scope.exit();
  12840. this.state.labels.pop();
  12841. return this.finishNode(node, "ForStatement");
  12842. }
  12843. parseForIn(node, init, awaitAt) {
  12844. const isForIn = this.match(58);
  12845. this.next();
  12846. if (isForIn) {
  12847. if (awaitAt !== null) this.unexpected(awaitAt);
  12848. } else {
  12849. node.await = awaitAt !== null;
  12850. }
  12851. 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")) {
  12852. this.raise(Errors.ForInOfLoopInitializer, init, {
  12853. type: isForIn ? "ForInStatement" : "ForOfStatement"
  12854. });
  12855. }
  12856. if (init.type === "AssignmentPattern") {
  12857. this.raise(Errors.InvalidLhs, init, {
  12858. ancestor: {
  12859. type: "ForStatement"
  12860. }
  12861. });
  12862. }
  12863. node.left = init;
  12864. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  12865. this.expect(11);
  12866. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12867. this.scope.exit();
  12868. this.state.labels.pop();
  12869. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  12870. }
  12871. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  12872. const declarations = node.declarations = [];
  12873. node.kind = kind;
  12874. for (;;) {
  12875. const decl = this.startNode();
  12876. this.parseVarId(decl, kind);
  12877. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  12878. if (decl.init === null && !allowMissingInitializer) {
  12879. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  12880. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  12881. kind: "destructuring"
  12882. });
  12883. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  12884. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  12885. kind
  12886. });
  12887. }
  12888. }
  12889. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  12890. if (!this.eat(12)) break;
  12891. }
  12892. return node;
  12893. }
  12894. parseVarId(decl, kind) {
  12895. const id = this.parseBindingAtom();
  12896. if (kind === "using" || kind === "await using") {
  12897. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  12898. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  12899. }
  12900. }
  12901. this.checkLVal(id, {
  12902. type: "VariableDeclarator"
  12903. }, kind === "var" ? 5 : 8201);
  12904. decl.id = id;
  12905. }
  12906. parseAsyncFunctionExpression(node) {
  12907. return this.parseFunction(node, 8);
  12908. }
  12909. parseFunction(node, flags = 0) {
  12910. const hangingDeclaration = flags & 2;
  12911. const isDeclaration = !!(flags & 1);
  12912. const requireId = isDeclaration && !(flags & 4);
  12913. const isAsync = !!(flags & 8);
  12914. this.initFunction(node, isAsync);
  12915. if (this.match(55)) {
  12916. if (hangingDeclaration) {
  12917. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  12918. }
  12919. this.next();
  12920. node.generator = true;
  12921. }
  12922. if (isDeclaration) {
  12923. node.id = this.parseFunctionId(requireId);
  12924. }
  12925. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12926. this.state.maybeInArrowParameters = false;
  12927. this.scope.enter(2);
  12928. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12929. if (!isDeclaration) {
  12930. node.id = this.parseFunctionId();
  12931. }
  12932. this.parseFunctionParams(node, false);
  12933. this.withSmartMixTopicForbiddingContext(() => {
  12934. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  12935. });
  12936. this.prodParam.exit();
  12937. this.scope.exit();
  12938. if (isDeclaration && !hangingDeclaration) {
  12939. this.registerFunctionStatementId(node);
  12940. }
  12941. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12942. return node;
  12943. }
  12944. parseFunctionId(requireId) {
  12945. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  12946. }
  12947. parseFunctionParams(node, isConstructor) {
  12948. this.expect(10);
  12949. this.expressionScope.enter(newParameterDeclarationScope());
  12950. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  12951. this.expressionScope.exit();
  12952. }
  12953. registerFunctionStatementId(node) {
  12954. if (!node.id) return;
  12955. 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);
  12956. }
  12957. parseClass(node, isStatement, optionalId) {
  12958. this.next();
  12959. const oldStrict = this.state.strict;
  12960. this.state.strict = true;
  12961. this.parseClassId(node, isStatement, optionalId);
  12962. this.parseClassSuper(node);
  12963. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  12964. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  12965. }
  12966. isClassProperty() {
  12967. return this.match(29) || this.match(13) || this.match(8);
  12968. }
  12969. isClassMethod() {
  12970. return this.match(10);
  12971. }
  12972. nameIsConstructor(key) {
  12973. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  12974. }
  12975. isNonstaticConstructor(method) {
  12976. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  12977. }
  12978. parseClassBody(hadSuperClass, oldStrict) {
  12979. this.classScope.enter();
  12980. const state = {
  12981. hadConstructor: false,
  12982. hadSuperClass
  12983. };
  12984. let decorators = [];
  12985. const classBody = this.startNode();
  12986. classBody.body = [];
  12987. this.expect(5);
  12988. this.withSmartMixTopicForbiddingContext(() => {
  12989. while (!this.match(8)) {
  12990. if (this.eat(13)) {
  12991. if (decorators.length > 0) {
  12992. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  12993. }
  12994. continue;
  12995. }
  12996. if (this.match(26)) {
  12997. decorators.push(this.parseDecorator());
  12998. continue;
  12999. }
  13000. const member = this.startNode();
  13001. if (decorators.length) {
  13002. member.decorators = decorators;
  13003. this.resetStartLocationFromNode(member, decorators[0]);
  13004. decorators = [];
  13005. }
  13006. this.parseClassMember(classBody, member, state);
  13007. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13008. this.raise(Errors.DecoratorConstructor, member);
  13009. }
  13010. }
  13011. });
  13012. this.state.strict = oldStrict;
  13013. this.next();
  13014. if (decorators.length) {
  13015. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13016. }
  13017. this.classScope.exit();
  13018. return this.finishNode(classBody, "ClassBody");
  13019. }
  13020. parseClassMemberFromModifier(classBody, member) {
  13021. const key = this.parseIdentifier(true);
  13022. if (this.isClassMethod()) {
  13023. const method = member;
  13024. method.kind = "method";
  13025. method.computed = false;
  13026. method.key = key;
  13027. method.static = false;
  13028. this.pushClassMethod(classBody, method, false, false, false, false);
  13029. return true;
  13030. } else if (this.isClassProperty()) {
  13031. const prop = member;
  13032. prop.computed = false;
  13033. prop.key = key;
  13034. prop.static = false;
  13035. classBody.body.push(this.parseClassProperty(prop));
  13036. return true;
  13037. }
  13038. this.resetPreviousNodeTrailingComments(key);
  13039. return false;
  13040. }
  13041. parseClassMember(classBody, member, state) {
  13042. const isStatic = this.isContextual(106);
  13043. if (isStatic) {
  13044. if (this.parseClassMemberFromModifier(classBody, member)) {
  13045. return;
  13046. }
  13047. if (this.eat(5)) {
  13048. this.parseClassStaticBlock(classBody, member);
  13049. return;
  13050. }
  13051. }
  13052. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13053. }
  13054. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13055. const publicMethod = member;
  13056. const privateMethod = member;
  13057. const publicProp = member;
  13058. const privateProp = member;
  13059. const accessorProp = member;
  13060. const method = publicMethod;
  13061. const publicMember = publicMethod;
  13062. member.static = isStatic;
  13063. this.parsePropertyNamePrefixOperator(member);
  13064. if (this.eat(55)) {
  13065. method.kind = "method";
  13066. const isPrivateName = this.match(138);
  13067. this.parseClassElementName(method);
  13068. if (isPrivateName) {
  13069. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13070. return;
  13071. }
  13072. if (this.isNonstaticConstructor(publicMethod)) {
  13073. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13074. }
  13075. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13076. return;
  13077. }
  13078. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13079. const key = this.parseClassElementName(member);
  13080. const maybeContextualKw = isContextual ? key.name : null;
  13081. const isPrivate = this.isPrivateName(key);
  13082. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13083. this.parsePostMemberNameModifiers(publicMember);
  13084. if (this.isClassMethod()) {
  13085. method.kind = "method";
  13086. if (isPrivate) {
  13087. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13088. return;
  13089. }
  13090. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13091. let allowsDirectSuper = false;
  13092. if (isConstructor) {
  13093. publicMethod.kind = "constructor";
  13094. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13095. this.raise(Errors.DuplicateConstructor, key);
  13096. }
  13097. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13098. this.raise(Errors.OverrideOnConstructor, key);
  13099. }
  13100. state.hadConstructor = true;
  13101. allowsDirectSuper = state.hadSuperClass;
  13102. }
  13103. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13104. } else if (this.isClassProperty()) {
  13105. if (isPrivate) {
  13106. this.pushClassPrivateProperty(classBody, privateProp);
  13107. } else {
  13108. this.pushClassProperty(classBody, publicProp);
  13109. }
  13110. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13111. this.resetPreviousNodeTrailingComments(key);
  13112. const isGenerator = this.eat(55);
  13113. if (publicMember.optional) {
  13114. this.unexpected(maybeQuestionTokenStartLoc);
  13115. }
  13116. method.kind = "method";
  13117. const isPrivate = this.match(138);
  13118. this.parseClassElementName(method);
  13119. this.parsePostMemberNameModifiers(publicMember);
  13120. if (isPrivate) {
  13121. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13122. } else {
  13123. if (this.isNonstaticConstructor(publicMethod)) {
  13124. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13125. }
  13126. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13127. }
  13128. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13129. this.resetPreviousNodeTrailingComments(key);
  13130. method.kind = maybeContextualKw;
  13131. const isPrivate = this.match(138);
  13132. this.parseClassElementName(publicMethod);
  13133. if (isPrivate) {
  13134. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13135. } else {
  13136. if (this.isNonstaticConstructor(publicMethod)) {
  13137. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13138. }
  13139. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13140. }
  13141. this.checkGetterSetterParams(publicMethod);
  13142. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13143. this.expectPlugin("decoratorAutoAccessors");
  13144. this.resetPreviousNodeTrailingComments(key);
  13145. const isPrivate = this.match(138);
  13146. this.parseClassElementName(publicProp);
  13147. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13148. } else if (this.isLineTerminator()) {
  13149. if (isPrivate) {
  13150. this.pushClassPrivateProperty(classBody, privateProp);
  13151. } else {
  13152. this.pushClassProperty(classBody, publicProp);
  13153. }
  13154. } else {
  13155. this.unexpected();
  13156. }
  13157. }
  13158. parseClassElementName(member) {
  13159. const {
  13160. type,
  13161. value
  13162. } = this.state;
  13163. if ((type === 132 || type === 133) && member.static && value === "prototype") {
  13164. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13165. }
  13166. if (type === 138) {
  13167. if (value === "constructor") {
  13168. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13169. }
  13170. const key = this.parsePrivateName();
  13171. member.key = key;
  13172. return key;
  13173. }
  13174. this.parsePropertyName(member);
  13175. return member.key;
  13176. }
  13177. parseClassStaticBlock(classBody, member) {
  13178. var _member$decorators;
  13179. this.scope.enter(64 | 128 | 16);
  13180. const oldLabels = this.state.labels;
  13181. this.state.labels = [];
  13182. this.prodParam.enter(0);
  13183. const body = member.body = [];
  13184. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13185. this.prodParam.exit();
  13186. this.scope.exit();
  13187. this.state.labels = oldLabels;
  13188. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13189. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13190. this.raise(Errors.DecoratorStaticBlock, member);
  13191. }
  13192. }
  13193. pushClassProperty(classBody, prop) {
  13194. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13195. this.raise(Errors.ConstructorClassField, prop.key);
  13196. }
  13197. classBody.body.push(this.parseClassProperty(prop));
  13198. }
  13199. pushClassPrivateProperty(classBody, prop) {
  13200. const node = this.parseClassPrivateProperty(prop);
  13201. classBody.body.push(node);
  13202. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13203. }
  13204. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13205. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13206. this.raise(Errors.ConstructorClassField, prop.key);
  13207. }
  13208. const node = this.parseClassAccessorProperty(prop);
  13209. classBody.body.push(node);
  13210. if (isPrivate) {
  13211. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13212. }
  13213. }
  13214. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13215. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13216. }
  13217. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13218. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13219. classBody.body.push(node);
  13220. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13221. this.declareClassPrivateMethodInScope(node, kind);
  13222. }
  13223. declareClassPrivateMethodInScope(node, kind) {
  13224. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13225. }
  13226. parsePostMemberNameModifiers(methodOrProp) {}
  13227. parseClassPrivateProperty(node) {
  13228. this.parseInitializer(node);
  13229. this.semicolon();
  13230. return this.finishNode(node, "ClassPrivateProperty");
  13231. }
  13232. parseClassProperty(node) {
  13233. this.parseInitializer(node);
  13234. this.semicolon();
  13235. return this.finishNode(node, "ClassProperty");
  13236. }
  13237. parseClassAccessorProperty(node) {
  13238. this.parseInitializer(node);
  13239. this.semicolon();
  13240. return this.finishNode(node, "ClassAccessorProperty");
  13241. }
  13242. parseInitializer(node) {
  13243. this.scope.enter(64 | 16);
  13244. this.expressionScope.enter(newExpressionScope());
  13245. this.prodParam.enter(0);
  13246. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13247. this.expressionScope.exit();
  13248. this.prodParam.exit();
  13249. this.scope.exit();
  13250. }
  13251. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13252. if (tokenIsIdentifier(this.state.type)) {
  13253. node.id = this.parseIdentifier();
  13254. if (isStatement) {
  13255. this.declareNameFromIdentifier(node.id, bindingType);
  13256. }
  13257. } else {
  13258. if (optionalId || !isStatement) {
  13259. node.id = null;
  13260. } else {
  13261. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13262. }
  13263. }
  13264. }
  13265. parseClassSuper(node) {
  13266. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13267. }
  13268. parseExport(node, decorators) {
  13269. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13270. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13271. const parseAfterDefault = !hasDefault || this.eat(12);
  13272. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13273. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13274. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13275. const isFromRequired = hasDefault || hasStar;
  13276. if (hasStar && !hasNamespace) {
  13277. if (hasDefault) this.unexpected();
  13278. if (decorators) {
  13279. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13280. }
  13281. this.parseExportFrom(node, true);
  13282. return this.finishNode(node, "ExportAllDeclaration");
  13283. }
  13284. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13285. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13286. this.unexpected(null, 5);
  13287. }
  13288. if (hasNamespace && parseAfterNamespace) {
  13289. this.unexpected(null, 98);
  13290. }
  13291. let hasDeclaration;
  13292. if (isFromRequired || hasSpecifiers) {
  13293. hasDeclaration = false;
  13294. if (decorators) {
  13295. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13296. }
  13297. this.parseExportFrom(node, isFromRequired);
  13298. } else {
  13299. hasDeclaration = this.maybeParseExportDeclaration(node);
  13300. }
  13301. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13302. var _node2$declaration;
  13303. const node2 = node;
  13304. this.checkExport(node2, true, false, !!node2.source);
  13305. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13306. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13307. } else if (decorators) {
  13308. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13309. }
  13310. return this.finishNode(node2, "ExportNamedDeclaration");
  13311. }
  13312. if (this.eat(65)) {
  13313. const node2 = node;
  13314. const decl = this.parseExportDefaultExpression();
  13315. node2.declaration = decl;
  13316. if (decl.type === "ClassDeclaration") {
  13317. this.maybeTakeDecorators(decorators, decl, node2);
  13318. } else if (decorators) {
  13319. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13320. }
  13321. this.checkExport(node2, true, true);
  13322. return this.finishNode(node2, "ExportDefaultDeclaration");
  13323. }
  13324. this.unexpected(null, 5);
  13325. }
  13326. eatExportStar(node) {
  13327. return this.eat(55);
  13328. }
  13329. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13330. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13331. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13332. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13333. const specifier = this.startNodeAtNode(id);
  13334. specifier.exported = id;
  13335. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13336. return true;
  13337. }
  13338. return false;
  13339. }
  13340. maybeParseExportNamespaceSpecifier(node) {
  13341. if (this.isContextual(93)) {
  13342. var _ref, _ref$specifiers;
  13343. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13344. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13345. this.next();
  13346. specifier.exported = this.parseModuleExportName();
  13347. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13348. return true;
  13349. }
  13350. return false;
  13351. }
  13352. maybeParseExportNamedSpecifiers(node) {
  13353. if (this.match(5)) {
  13354. const node2 = node;
  13355. if (!node2.specifiers) node2.specifiers = [];
  13356. const isTypeExport = node2.exportKind === "type";
  13357. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13358. node2.source = null;
  13359. node2.declaration = null;
  13360. if (this.hasPlugin("importAssertions")) {
  13361. node2.assertions = [];
  13362. }
  13363. return true;
  13364. }
  13365. return false;
  13366. }
  13367. maybeParseExportDeclaration(node) {
  13368. if (this.shouldParseExportDeclaration()) {
  13369. node.specifiers = [];
  13370. node.source = null;
  13371. if (this.hasPlugin("importAssertions")) {
  13372. node.assertions = [];
  13373. }
  13374. node.declaration = this.parseExportDeclaration(node);
  13375. return true;
  13376. }
  13377. return false;
  13378. }
  13379. isAsyncFunction() {
  13380. if (!this.isContextual(95)) return false;
  13381. const next = this.nextTokenInLineStart();
  13382. return this.isUnparsedContextual(next, "function");
  13383. }
  13384. parseExportDefaultExpression() {
  13385. const expr = this.startNode();
  13386. if (this.match(68)) {
  13387. this.next();
  13388. return this.parseFunction(expr, 1 | 4);
  13389. } else if (this.isAsyncFunction()) {
  13390. this.next();
  13391. this.next();
  13392. return this.parseFunction(expr, 1 | 4 | 8);
  13393. }
  13394. if (this.match(80)) {
  13395. return this.parseClass(expr, true, true);
  13396. }
  13397. if (this.match(26)) {
  13398. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13399. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13400. }
  13401. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13402. }
  13403. if (this.match(75) || this.match(74) || this.isLet()) {
  13404. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13405. }
  13406. const res = this.parseMaybeAssignAllowIn();
  13407. this.semicolon();
  13408. return res;
  13409. }
  13410. parseExportDeclaration(node) {
  13411. if (this.match(80)) {
  13412. const node = this.parseClass(this.startNode(), true, false);
  13413. return node;
  13414. }
  13415. return this.parseStatementListItem();
  13416. }
  13417. isExportDefaultSpecifier() {
  13418. const {
  13419. type
  13420. } = this.state;
  13421. if (tokenIsIdentifier(type)) {
  13422. if (type === 95 && !this.state.containsEsc || type === 100) {
  13423. return false;
  13424. }
  13425. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13426. const {
  13427. type: nextType
  13428. } = this.lookahead();
  13429. if (tokenIsIdentifier(nextType) && nextType !== 98 || nextType === 5) {
  13430. this.expectOnePlugin(["flow", "typescript"]);
  13431. return false;
  13432. }
  13433. }
  13434. } else if (!this.match(65)) {
  13435. return false;
  13436. }
  13437. const next = this.nextTokenStart();
  13438. const hasFrom = this.isUnparsedContextual(next, "from");
  13439. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13440. return true;
  13441. }
  13442. if (this.match(65) && hasFrom) {
  13443. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13444. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13445. }
  13446. return false;
  13447. }
  13448. parseExportFrom(node, expect) {
  13449. if (this.eatContextual(98)) {
  13450. node.source = this.parseImportSource();
  13451. this.checkExport(node);
  13452. this.maybeParseImportAttributes(node);
  13453. this.checkJSONModuleImport(node);
  13454. } else if (expect) {
  13455. this.unexpected();
  13456. }
  13457. this.semicolon();
  13458. }
  13459. shouldParseExportDeclaration() {
  13460. const {
  13461. type
  13462. } = this.state;
  13463. if (type === 26) {
  13464. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13465. if (this.hasPlugin("decorators")) {
  13466. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13467. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13468. }
  13469. return true;
  13470. }
  13471. }
  13472. if (this.isContextual(107)) {
  13473. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13474. return true;
  13475. }
  13476. if (this.isContextual(96) && this.startsAwaitUsing()) {
  13477. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13478. return true;
  13479. }
  13480. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13481. }
  13482. checkExport(node, checkNames, isDefault, isFrom) {
  13483. if (checkNames) {
  13484. var _node$specifiers;
  13485. if (isDefault) {
  13486. this.checkDuplicateExports(node, "default");
  13487. if (this.hasPlugin("exportDefaultFrom")) {
  13488. var _declaration$extra;
  13489. const declaration = node.declaration;
  13490. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13491. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  13492. }
  13493. }
  13494. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  13495. for (const specifier of node.specifiers) {
  13496. const {
  13497. exported
  13498. } = specifier;
  13499. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13500. this.checkDuplicateExports(specifier, exportName);
  13501. if (!isFrom && specifier.local) {
  13502. const {
  13503. local
  13504. } = specifier;
  13505. if (local.type !== "Identifier") {
  13506. this.raise(Errors.ExportBindingIsString, specifier, {
  13507. localName: local.value,
  13508. exportName
  13509. });
  13510. } else {
  13511. this.checkReservedWord(local.name, local.loc.start, true, false);
  13512. this.scope.checkLocalExport(local);
  13513. }
  13514. }
  13515. }
  13516. } else if (node.declaration) {
  13517. const decl = node.declaration;
  13518. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  13519. const {
  13520. id
  13521. } = decl;
  13522. if (!id) throw new Error("Assertion failure");
  13523. this.checkDuplicateExports(node, id.name);
  13524. } else if (decl.type === "VariableDeclaration") {
  13525. for (const declaration of decl.declarations) {
  13526. this.checkDeclaration(declaration.id);
  13527. }
  13528. }
  13529. }
  13530. }
  13531. }
  13532. checkDeclaration(node) {
  13533. if (node.type === "Identifier") {
  13534. this.checkDuplicateExports(node, node.name);
  13535. } else if (node.type === "ObjectPattern") {
  13536. for (const prop of node.properties) {
  13537. this.checkDeclaration(prop);
  13538. }
  13539. } else if (node.type === "ArrayPattern") {
  13540. for (const elem of node.elements) {
  13541. if (elem) {
  13542. this.checkDeclaration(elem);
  13543. }
  13544. }
  13545. } else if (node.type === "ObjectProperty") {
  13546. this.checkDeclaration(node.value);
  13547. } else if (node.type === "RestElement") {
  13548. this.checkDeclaration(node.argument);
  13549. } else if (node.type === "AssignmentPattern") {
  13550. this.checkDeclaration(node.left);
  13551. }
  13552. }
  13553. checkDuplicateExports(node, exportName) {
  13554. if (this.exportedIdentifiers.has(exportName)) {
  13555. if (exportName === "default") {
  13556. this.raise(Errors.DuplicateDefaultExport, node);
  13557. } else {
  13558. this.raise(Errors.DuplicateExport, node, {
  13559. exportName
  13560. });
  13561. }
  13562. }
  13563. this.exportedIdentifiers.add(exportName);
  13564. }
  13565. parseExportSpecifiers(isInTypeExport) {
  13566. const nodes = [];
  13567. let first = true;
  13568. this.expect(5);
  13569. while (!this.eat(8)) {
  13570. if (first) {
  13571. first = false;
  13572. } else {
  13573. this.expect(12);
  13574. if (this.eat(8)) break;
  13575. }
  13576. const isMaybeTypeOnly = this.isContextual(130);
  13577. const isString = this.match(133);
  13578. const node = this.startNode();
  13579. node.local = this.parseModuleExportName();
  13580. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13581. }
  13582. return nodes;
  13583. }
  13584. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  13585. if (this.eatContextual(93)) {
  13586. node.exported = this.parseModuleExportName();
  13587. } else if (isString) {
  13588. node.exported = cloneStringLiteral(node.local);
  13589. } else if (!node.exported) {
  13590. node.exported = cloneIdentifier(node.local);
  13591. }
  13592. return this.finishNode(node, "ExportSpecifier");
  13593. }
  13594. parseModuleExportName() {
  13595. if (this.match(133)) {
  13596. const result = this.parseStringLiteral(this.state.value);
  13597. const surrogate = loneSurrogate.exec(result.value);
  13598. if (surrogate) {
  13599. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  13600. surrogateCharCode: surrogate[0].charCodeAt(0)
  13601. });
  13602. }
  13603. return result;
  13604. }
  13605. return this.parseIdentifier(true);
  13606. }
  13607. isJSONModuleImport(node) {
  13608. if (node.assertions != null) {
  13609. return node.assertions.some(({
  13610. key,
  13611. value
  13612. }) => {
  13613. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  13614. });
  13615. }
  13616. return false;
  13617. }
  13618. checkImportReflection(node) {
  13619. const {
  13620. specifiers
  13621. } = node;
  13622. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  13623. if (node.phase === "source") {
  13624. if (singleBindingType !== "ImportDefaultSpecifier") {
  13625. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  13626. }
  13627. } else if (node.phase === "defer") {
  13628. if (singleBindingType !== "ImportNamespaceSpecifier") {
  13629. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  13630. }
  13631. } else if (node.module) {
  13632. var _node$assertions;
  13633. if (singleBindingType !== "ImportDefaultSpecifier") {
  13634. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  13635. }
  13636. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  13637. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  13638. }
  13639. }
  13640. }
  13641. checkJSONModuleImport(node) {
  13642. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  13643. const {
  13644. specifiers
  13645. } = node;
  13646. if (specifiers != null) {
  13647. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  13648. let imported;
  13649. if (specifier.type === "ExportSpecifier") {
  13650. imported = specifier.local;
  13651. } else if (specifier.type === "ImportSpecifier") {
  13652. imported = specifier.imported;
  13653. }
  13654. if (imported !== undefined) {
  13655. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  13656. }
  13657. });
  13658. if (nonDefaultNamedSpecifier !== undefined) {
  13659. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  13660. }
  13661. }
  13662. }
  13663. }
  13664. isPotentialImportPhase(isExport) {
  13665. if (isExport) return false;
  13666. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  13667. }
  13668. applyImportPhase(node, isExport, phase, loc) {
  13669. if (isExport) {
  13670. return;
  13671. }
  13672. if (phase === "module") {
  13673. this.expectPlugin("importReflection", loc);
  13674. node.module = true;
  13675. } else if (this.hasPlugin("importReflection")) {
  13676. node.module = false;
  13677. }
  13678. if (phase === "source") {
  13679. this.expectPlugin("sourcePhaseImports", loc);
  13680. node.phase = "source";
  13681. } else if (phase === "defer") {
  13682. this.expectPlugin("deferredImportEvaluation", loc);
  13683. node.phase = "defer";
  13684. } else if (this.hasPlugin("sourcePhaseImports")) {
  13685. node.phase = null;
  13686. }
  13687. }
  13688. parseMaybeImportPhase(node, isExport) {
  13689. if (!this.isPotentialImportPhase(isExport)) {
  13690. this.applyImportPhase(node, isExport, null);
  13691. return null;
  13692. }
  13693. const phaseIdentifier = this.parseIdentifier(true);
  13694. const {
  13695. type
  13696. } = this.state;
  13697. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  13698. if (isImportPhase) {
  13699. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  13700. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  13701. return null;
  13702. } else {
  13703. this.applyImportPhase(node, isExport, null);
  13704. return phaseIdentifier;
  13705. }
  13706. }
  13707. isPrecedingIdImportPhase(phase) {
  13708. const {
  13709. type
  13710. } = this.state;
  13711. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  13712. }
  13713. parseImport(node) {
  13714. if (this.match(133)) {
  13715. return this.parseImportSourceAndAttributes(node);
  13716. }
  13717. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  13718. }
  13719. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  13720. node.specifiers = [];
  13721. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  13722. const parseNext = !hasDefault || this.eat(12);
  13723. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  13724. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  13725. this.expectContextual(98);
  13726. return this.parseImportSourceAndAttributes(node);
  13727. }
  13728. parseImportSourceAndAttributes(node) {
  13729. var _node$specifiers2;
  13730. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  13731. node.source = this.parseImportSource();
  13732. this.maybeParseImportAttributes(node);
  13733. this.checkImportReflection(node);
  13734. this.checkJSONModuleImport(node);
  13735. this.semicolon();
  13736. return this.finishNode(node, "ImportDeclaration");
  13737. }
  13738. parseImportSource() {
  13739. if (!this.match(133)) this.unexpected();
  13740. return this.parseExprAtom();
  13741. }
  13742. parseImportSpecifierLocal(node, specifier, type) {
  13743. specifier.local = this.parseIdentifier();
  13744. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  13745. }
  13746. finishImportSpecifier(specifier, type, bindingType = 8201) {
  13747. this.checkLVal(specifier.local, {
  13748. type
  13749. }, bindingType);
  13750. return this.finishNode(specifier, type);
  13751. }
  13752. parseImportAttributes() {
  13753. this.expect(5);
  13754. const attrs = [];
  13755. const attrNames = new Set();
  13756. do {
  13757. if (this.match(8)) {
  13758. break;
  13759. }
  13760. const node = this.startNode();
  13761. const keyName = this.state.value;
  13762. if (attrNames.has(keyName)) {
  13763. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  13764. key: keyName
  13765. });
  13766. }
  13767. attrNames.add(keyName);
  13768. if (this.match(133)) {
  13769. node.key = this.parseStringLiteral(keyName);
  13770. } else {
  13771. node.key = this.parseIdentifier(true);
  13772. }
  13773. this.expect(14);
  13774. if (!this.match(133)) {
  13775. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  13776. }
  13777. node.value = this.parseStringLiteral(this.state.value);
  13778. attrs.push(this.finishNode(node, "ImportAttribute"));
  13779. } while (this.eat(12));
  13780. this.expect(8);
  13781. return attrs;
  13782. }
  13783. parseModuleAttributes() {
  13784. const attrs = [];
  13785. const attributes = new Set();
  13786. do {
  13787. const node = this.startNode();
  13788. node.key = this.parseIdentifier(true);
  13789. if (node.key.name !== "type") {
  13790. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  13791. }
  13792. if (attributes.has(node.key.name)) {
  13793. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  13794. key: node.key.name
  13795. });
  13796. }
  13797. attributes.add(node.key.name);
  13798. this.expect(14);
  13799. if (!this.match(133)) {
  13800. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  13801. }
  13802. node.value = this.parseStringLiteral(this.state.value);
  13803. attrs.push(this.finishNode(node, "ImportAttribute"));
  13804. } while (this.eat(12));
  13805. return attrs;
  13806. }
  13807. maybeParseImportAttributes(node) {
  13808. let attributes;
  13809. {
  13810. var useWith = false;
  13811. }
  13812. if (this.match(76)) {
  13813. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  13814. return;
  13815. }
  13816. this.next();
  13817. if (this.hasPlugin("moduleAttributes")) {
  13818. attributes = this.parseModuleAttributes();
  13819. } else {
  13820. attributes = this.parseImportAttributes();
  13821. }
  13822. {
  13823. useWith = true;
  13824. }
  13825. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  13826. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  13827. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  13828. }
  13829. if (!this.hasPlugin("importAssertions")) {
  13830. this.addExtra(node, "deprecatedAssertSyntax", true);
  13831. }
  13832. this.next();
  13833. attributes = this.parseImportAttributes();
  13834. } else {
  13835. attributes = [];
  13836. }
  13837. if (!useWith && this.hasPlugin("importAssertions")) {
  13838. node.assertions = attributes;
  13839. } else {
  13840. node.attributes = attributes;
  13841. }
  13842. }
  13843. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  13844. if (maybeDefaultIdentifier) {
  13845. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  13846. specifier.local = maybeDefaultIdentifier;
  13847. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  13848. return true;
  13849. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  13850. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  13851. return true;
  13852. }
  13853. return false;
  13854. }
  13855. maybeParseStarImportSpecifier(node) {
  13856. if (this.match(55)) {
  13857. const specifier = this.startNode();
  13858. this.next();
  13859. this.expectContextual(93);
  13860. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  13861. return true;
  13862. }
  13863. return false;
  13864. }
  13865. parseNamedImportSpecifiers(node) {
  13866. let first = true;
  13867. this.expect(5);
  13868. while (!this.eat(8)) {
  13869. if (first) {
  13870. first = false;
  13871. } else {
  13872. if (this.eat(14)) {
  13873. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  13874. }
  13875. this.expect(12);
  13876. if (this.eat(8)) break;
  13877. }
  13878. const specifier = this.startNode();
  13879. const importedIsString = this.match(133);
  13880. const isMaybeTypeOnly = this.isContextual(130);
  13881. specifier.imported = this.parseModuleExportName();
  13882. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  13883. node.specifiers.push(importSpecifier);
  13884. }
  13885. }
  13886. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  13887. if (this.eatContextual(93)) {
  13888. specifier.local = this.parseIdentifier();
  13889. } else {
  13890. const {
  13891. imported
  13892. } = specifier;
  13893. if (importedIsString) {
  13894. throw this.raise(Errors.ImportBindingIsString, specifier, {
  13895. importName: imported.value
  13896. });
  13897. }
  13898. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  13899. if (!specifier.local) {
  13900. specifier.local = cloneIdentifier(imported);
  13901. }
  13902. }
  13903. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  13904. }
  13905. isThisParam(param) {
  13906. return param.type === "Identifier" && param.name === "this";
  13907. }
  13908. }
  13909. class Parser extends StatementParser {
  13910. constructor(options, input, pluginsMap) {
  13911. options = getOptions(options);
  13912. super(options, input);
  13913. this.options = options;
  13914. this.initializeScopes();
  13915. this.plugins = pluginsMap;
  13916. this.filename = options.sourceFilename;
  13917. this.startIndex = options.startIndex;
  13918. }
  13919. getScopeHandler() {
  13920. return ScopeHandler;
  13921. }
  13922. parse() {
  13923. this.enterInitialScopes();
  13924. const file = this.startNode();
  13925. const program = this.startNode();
  13926. this.nextToken();
  13927. file.errors = null;
  13928. this.parseTopLevel(file, program);
  13929. file.errors = this.state.errors;
  13930. file.comments.length = this.state.commentsLen;
  13931. return file;
  13932. }
  13933. }
  13934. function parse(input, options) {
  13935. var _options;
  13936. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  13937. options = Object.assign({}, options);
  13938. try {
  13939. options.sourceType = "module";
  13940. const parser = getParser(options, input);
  13941. const ast = parser.parse();
  13942. if (parser.sawUnambiguousESM) {
  13943. return ast;
  13944. }
  13945. if (parser.ambiguousScriptDifferentAst) {
  13946. try {
  13947. options.sourceType = "script";
  13948. return getParser(options, input).parse();
  13949. } catch (_unused) {}
  13950. } else {
  13951. ast.program.sourceType = "script";
  13952. }
  13953. return ast;
  13954. } catch (moduleError) {
  13955. try {
  13956. options.sourceType = "script";
  13957. return getParser(options, input).parse();
  13958. } catch (_unused2) {}
  13959. throw moduleError;
  13960. }
  13961. } else {
  13962. return getParser(options, input).parse();
  13963. }
  13964. }
  13965. function parseExpression(input, options) {
  13966. const parser = getParser(options, input);
  13967. if (parser.options.strictMode) {
  13968. parser.state.strict = true;
  13969. }
  13970. return parser.getExpression();
  13971. }
  13972. function generateExportedTokenTypes(internalTokenTypes) {
  13973. const tokenTypes = {};
  13974. for (const typeName of Object.keys(internalTokenTypes)) {
  13975. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  13976. }
  13977. return tokenTypes;
  13978. }
  13979. const tokTypes = generateExportedTokenTypes(tt);
  13980. function getParser(options, input) {
  13981. let cls = Parser;
  13982. const pluginsMap = new Map();
  13983. if (options != null && options.plugins) {
  13984. for (const plugin of options.plugins) {
  13985. let name, opts;
  13986. if (typeof plugin === "string") {
  13987. name = plugin;
  13988. } else {
  13989. [name, opts] = plugin;
  13990. }
  13991. if (!pluginsMap.has(name)) {
  13992. pluginsMap.set(name, opts || {});
  13993. }
  13994. }
  13995. validatePlugins(pluginsMap);
  13996. cls = getParserClass(pluginsMap);
  13997. }
  13998. return new cls(options, input, pluginsMap);
  13999. }
  14000. const parserClassCache = new Map();
  14001. function getParserClass(pluginsMap) {
  14002. const pluginList = [];
  14003. for (const name of mixinPluginNames) {
  14004. if (pluginsMap.has(name)) {
  14005. pluginList.push(name);
  14006. }
  14007. }
  14008. const key = pluginList.join("|");
  14009. let cls = parserClassCache.get(key);
  14010. if (!cls) {
  14011. cls = Parser;
  14012. for (const plugin of pluginList) {
  14013. cls = mixinPlugins[plugin](cls);
  14014. }
  14015. parserClassCache.set(key, cls);
  14016. }
  14017. return cls;
  14018. }
  14019. exports.parse = parse;
  14020. exports.parseExpression = parseExpression;
  14021. exports.tokTypes = tokTypes;
  14022. //# sourceMappingURL=index.js.map